1 /**
2 * @author mrdoob / http://mrdoob.com/
3 * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Cube.as
4 */
5
6 /**@constructor*/
7 THREE.CubeGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
8
9 THREE.Geometry.call( this );
10
11 var scope = this;
12
13 this.width = width;
14 this.height = height;
15 this.depth = depth;
16
17 this.widthSegments = widthSegments || 1;
18 this.heightSegments = heightSegments || 1;
19 this.depthSegments = depthSegments || 1;
20
21 var width_half = this.width / 2;
22 var height_half = this.height / 2;
23 var depth_half = this.depth / 2;
24
25 buildPlane( 'z', 'y', - 1, - 1, this.depth, this.height, width_half, 0 ); // px
26 buildPlane( 'z', 'y', 1, - 1, this.depth, this.height, - width_half, 1 ); // nx
27 buildPlane( 'x', 'z', 1, 1, this.width, this.depth, height_half, 2 ); // py
28 buildPlane( 'x', 'z', 1, - 1, this.width, this.depth, - height_half, 3 ); // ny
29 buildPlane( 'x', 'y', 1, - 1, this.width, this.height, depth_half, 4 ); // pz
30 buildPlane( 'x', 'y', - 1, - 1, this.width, this.height, - depth_half, 5 ); // nz
31
32 function buildPlane( u, v, udir, vdir, width, height, depth, materialIndex ) {
33
34 var w, ix, iy,
35 gridX = scope.widthSegments,
36 gridY = scope.heightSegments,
37 width_half = width / 2,
38 height_half = height / 2,
39 offset = scope.vertices.length;
40
41 if ( ( u === 'x' && v === 'y' ) || ( u === 'y' && v === 'x' ) ) {
42
43 w = 'z';
44
45 } else if ( ( u === 'x' && v === 'z' ) || ( u === 'z' && v === 'x' ) ) {
46
47 w = 'y';
48 gridY = scope.depthSegments;
49
50 } else if ( ( u === 'z' && v === 'y' ) || ( u === 'y' && v === 'z' ) ) {
51
52 w = 'x';
53 gridX = scope.depthSegments;
54
55 }
56
57 var gridX1 = gridX + 1,
58 gridY1 = gridY + 1,
59 segment_width = width / gridX,
60 segment_height = height / gridY,
61 normal = new THREE.Vector3();
62
63 normal[ w ] = depth > 0 ? 1 : - 1;
64
65 for ( iy = 0; iy < gridY1; iy ++ ) {
66
67 for ( ix = 0; ix < gridX1; ix ++ ) {
68
69 var vector = new THREE.Vector3();
70 vector[ u ] = ( ix * segment_width - width_half ) * udir;
71 vector[ v ] = ( iy * segment_height - height_half ) * vdir;
72 vector[ w ] = depth;
73
74 scope.vertices.push( vector );
75
76 }
77
78 }
79
80 for ( iy = 0; iy < gridY; iy++ ) {
81
82 for ( ix = 0; ix < gridX; ix++ ) {
83
84 var a = ix + gridX1 * iy;
85 var b = ix + gridX1 * ( iy + 1 );
86 var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
87 var d = ( ix + 1 ) + gridX1 * iy;
88
89 var face = new THREE.Face4( a + offset, b + offset, c + offset, d + offset );
90 face.normal.copy( normal );
91 face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone(), normal.clone() );
92 face.materialIndex = materialIndex;
93
94 scope.faces.push( face );
95 scope.faceVertexUvs[ 0 ].push( [
96 new THREE.UV( ix / gridX, 1 - iy / gridY ),
97 new THREE.UV( ix / gridX, 1 - ( iy + 1 ) / gridY ),
98 new THREE.UV( ( ix + 1 ) / gridX, 1- ( iy + 1 ) / gridY ),
99 new THREE.UV( ( ix + 1 ) / gridX, 1 - iy / gridY )
100 ] );
101
102 }
103
104 }
105
106 }
107
108 this.computeCentroids();
109 this.mergeVertices();
110
111 };
112
113 THREE.CubeGeometry.prototype = Object.create( THREE.Geometry.prototype );
114
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