1 /**
2 * @author oosmoxiecode
3 * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3D/src/away3d/primitives/TorusKnot.as?spec=svn2473&r=2473
4 */
5
6 /**@constructor*/
7 THREE.TorusKnotGeometry = function ( radius, tube, radialSegments, tubularSegments, p, q, heightScale ) {
8
9 THREE.Geometry.call( this );
10
11 var scope = this;
12
13 this.radius = radius || 200;
14 this.tube = tube || 40;
15 this.radialSegments = radialSegments || 64;
16 this.tubularSegments = tubularSegments || 8;
17 this.p = p || 2;
18 this.q = q || 3;
19 this.heightScale = heightScale || 1;
20 this.grid = new Array(this.radialSegments);
21
22 var tang = new THREE.Vector3();
23 var n = new THREE.Vector3();
24 var bitan = new THREE.Vector3();
25
26 for ( var i = 0; i < this.radialSegments; ++ i ) {
27
28 this.grid[ i ] = new Array( this.tubularSegments );
29
30 for ( var j = 0; j < this.tubularSegments; ++ j ) {
31
32 var u = i / this.radialSegments * 2 * this.p * Math.PI;
33 var v = j / this.tubularSegments * 2 * Math.PI;
34 var p1 = getPos( u, v, this.q, this.p, this.radius, this.heightScale );
35 var p2 = getPos( u + 0.01, v, this.q, this.p, this.radius, this.heightScale );
36 var cx, cy;
37
38 tang.sub( p2, p1 );
39 n.add( p2, p1 );
40
41 bitan.cross( tang, n );
42 n.cross( bitan, tang );
43 bitan.normalize();
44 n.normalize();
45
46 cx = - this.tube * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
47 cy = this.tube * Math.sin( v );
48
49 p1.x += cx * n.x + cy * bitan.x;
50 p1.y += cx * n.y + cy * bitan.y;
51 p1.z += cx * n.z + cy * bitan.z;
52
53 this.grid[ i ][ j ] = vert( p1.x, p1.y, p1.z );
54
55 }
56
57 }
58
59 for ( var i = 0; i < this.radialSegments; ++ i ) {
60
61 for ( var j = 0; j < this.tubularSegments; ++ j ) {
62
63 var ip = ( i + 1 ) % this.radialSegments;
64 var jp = ( j + 1 ) % this.tubularSegments;
65
66 var a = this.grid[ i ][ j ];
67 var b = this.grid[ ip ][ j ];
68 var c = this.grid[ ip ][ jp ];
69 var d = this.grid[ i ][ jp ];
70
71 var uva = new THREE.UV( i / this.radialSegments, j / this.tubularSegments );
72 var uvb = new THREE.UV( ( i + 1 ) / this.radialSegments, j / this.tubularSegments );
73 var uvc = new THREE.UV( ( i + 1 ) / this.radialSegments, ( j + 1 ) / this.tubularSegments );
74 var uvd = new THREE.UV( i / this.radialSegments, ( j + 1 ) / this.tubularSegments );
75
76 this.faces.push( new THREE.Face4( a, b, c, d ) );
77 this.faceVertexUvs[ 0 ].push( [ uva,uvb,uvc, uvd ] );
78
79 }
80 }
81
82 this.computeCentroids();
83 this.computeFaceNormals();
84 this.computeVertexNormals();
85
86 function vert( x, y, z ) {
87
88 return scope.vertices.push( new THREE.Vector3( x, y, z ) ) - 1;
89
90 }
91
92 function getPos( u, v, in_q, in_p, radius, heightScale ) {
93
94 var cu = Math.cos( u );
95 var cv = Math.cos( v );
96 var su = Math.sin( u );
97 var quOverP = in_q / in_p * u;
98 var cs = Math.cos( quOverP );
99
100 var tx = radius * ( 2 + cs ) * 0.5 * cu;
101 var ty = radius * ( 2 + cs ) * su * 0.5;
102 var tz = heightScale * radius * Math.sin( quOverP ) * 0.5;
103
104 return new THREE.Vector3( tx, ty, tz );
105
106 }
107
108 };
109
110 THREE.TorusKnotGeometry.prototype = Object.create( THREE.Geometry.prototype );
111
nike free rn
new balance hombre baratas
cinturones gucci
ugg rebajas
cinturon gucci
ray ban baratas
nike cortez
peuterey mujer
christian louboutin madrid
mbt zapatos
gafas ray ban baratas
mbt ofertas
air max blancas
mbt barcelona
nike air max 90
woolrich barcelona
nike mujer
botas ugg
gafas de sol carrera aratas
air max 2016 baratas
oakley baratas
nike air max 2016