source: other-projects/playing-in-the-street/summer-2013/trunk/Playing-in-the-Street-WPF/Content/Web/mrdoob-three.js-4862f5f/src/extras/geometries/LatheGeometry.js@ 28897

Last change on this file since 28897 was 28897, checked in by davidb, 10 years ago

GUI front-end to server base plus web page content

File size: 2.1 KB
Line 
1/**
2 * @author astrodud / http://astrodud.isgreat.org/
3 * @author zz85 / https://github.com/zz85
4 * @author bhouston / http://exocortex.com
5 */
6
7// points - to create a closed torus, one must use a set of points
8// like so: [ a, b, c, d, a ], see first is the same as last.
9// segments - the number of circumference segments to create
10// phiStart - the starting radian
11// phiLength - the radian (0 to 2*PI) range of the lathed section
12// 2*pi is a closed lathe, less than 2PI is a portion.
13THREE.LatheGeometry = function ( points, segments, phiStart, phiLength ) {
14
15 THREE.Geometry.call( this );
16
17 segments = segments || 12;
18 phiStart = phiStart || 0;
19 phiLength = phiLength || 2 * Math.PI;
20
21 var inversePointLength = 1.0 / ( points.length - 1 );
22 var inverseSegments = 1.0 / segments;
23
24 for ( var i = 0, il = segments; i <= il; i ++ ) {
25
26 var phi = phiStart + i * inverseSegments * phiLength;
27
28 var c = Math.cos( phi ),
29 s = Math.sin( phi );
30
31 for ( var j = 0, jl = points.length; j < jl; j ++ ) {
32
33 var pt = points[ j ];
34
35 var vertex = new THREE.Vector3();
36
37 vertex.x = c * pt.x - s * pt.y;
38 vertex.y = s * pt.x + c * pt.y;
39 vertex.z = pt.z;
40
41 this.vertices.push( vertex );
42
43 }
44
45 }
46
47 var np = points.length;
48
49 for ( var i = 0, il = segments; i < il; i ++ ) {
50
51 for ( var j = 0, jl = points.length - 1; j < jl; j ++ ) {
52
53 var base = j + np * i;
54 var a = base;
55 var b = base + np;
56 var c = base + 1 + np;
57 var d = base + 1;
58
59 var u0 = i * inverseSegments;
60 var v0 = j * inversePointLength;
61 var u1 = u0 + inverseSegments;
62 var v1 = v0 + inversePointLength;
63
64 this.faces.push( new THREE.Face3( a, b, d ) );
65
66 this.faceVertexUvs[ 0 ].push( [
67
68 new THREE.Vector2( u0, v0 ),
69 new THREE.Vector2( u1, v0 ),
70 new THREE.Vector2( u0, v1 )
71
72 ] );
73
74 this.faces.push( new THREE.Face3( b, c, d ) );
75
76 this.faceVertexUvs[ 0 ].push( [
77
78 new THREE.Vector2( u1, v0 ),
79 new THREE.Vector2( u1, v1 ),
80 new THREE.Vector2( u0, v1 )
81
82 ] );
83
84
85 }
86
87 }
88
89 this.mergeVertices();
90 this.computeCentroids();
91 this.computeFaceNormals();
92 this.computeVertexNormals();
93
94};
95
96THREE.LatheGeometry.prototype = Object.create( THREE.Geometry.prototype );
Note: See TracBrowser for help on using the repository browser.