|
@@ -12585,195 +12585,197 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
|
|
|
|
|
|
// BoxGeometry
|
|
|
|
|
|
-function BoxGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
|
|
|
+class BoxGeometry extends Geometry {
|
|
|
|
|
|
- Geometry.call( this );
|
|
|
+ constructor( width, height, depth, widthSegments, heightSegments, depthSegments ) {
|
|
|
|
|
|
- this.type = 'BoxGeometry';
|
|
|
+ super();
|
|
|
|
|
|
- this.parameters = {
|
|
|
- width: width,
|
|
|
- height: height,
|
|
|
- depth: depth,
|
|
|
- widthSegments: widthSegments,
|
|
|
- heightSegments: heightSegments,
|
|
|
- depthSegments: depthSegments
|
|
|
- };
|
|
|
+ this.type = 'BoxGeometry';
|
|
|
|
|
|
- this.fromBufferGeometry( new BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
|
|
|
- this.mergeVertices();
|
|
|
+ this.parameters = {
|
|
|
+ width: width,
|
|
|
+ height: height,
|
|
|
+ depth: depth,
|
|
|
+ widthSegments: widthSegments,
|
|
|
+ heightSegments: heightSegments,
|
|
|
+ depthSegments: depthSegments
|
|
|
+ };
|
|
|
|
|
|
-}
|
|
|
+ this.fromBufferGeometry( new BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
|
|
|
+ this.mergeVertices();
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
-BoxGeometry.prototype = Object.create( Geometry.prototype );
|
|
|
-BoxGeometry.prototype.constructor = BoxGeometry;
|
|
|
+}
|
|
|
|
|
|
// BoxBufferGeometry
|
|
|
|
|
|
-function BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
|
|
|
+class BoxBufferGeometry extends BufferGeometry {
|
|
|
|
|
|
- BufferGeometry.call( this );
|
|
|
+ constructor( width, height, depth, widthSegments, heightSegments, depthSegments ) {
|
|
|
|
|
|
- this.type = 'BoxBufferGeometry';
|
|
|
+ super();
|
|
|
|
|
|
- this.parameters = {
|
|
|
- width: width,
|
|
|
- height: height,
|
|
|
- depth: depth,
|
|
|
- widthSegments: widthSegments,
|
|
|
- heightSegments: heightSegments,
|
|
|
- depthSegments: depthSegments
|
|
|
- };
|
|
|
+ this.type = 'BoxBufferGeometry';
|
|
|
|
|
|
- var scope = this;
|
|
|
+ this.parameters = {
|
|
|
+ width: width,
|
|
|
+ height: height,
|
|
|
+ depth: depth,
|
|
|
+ widthSegments: widthSegments,
|
|
|
+ heightSegments: heightSegments,
|
|
|
+ depthSegments: depthSegments
|
|
|
+ };
|
|
|
|
|
|
- width = width || 1;
|
|
|
- height = height || 1;
|
|
|
- depth = depth || 1;
|
|
|
+ var scope = this;
|
|
|
|
|
|
- // segments
|
|
|
+ width = width || 1;
|
|
|
+ height = height || 1;
|
|
|
+ depth = depth || 1;
|
|
|
|
|
|
- widthSegments = Math.floor( widthSegments ) || 1;
|
|
|
- heightSegments = Math.floor( heightSegments ) || 1;
|
|
|
- depthSegments = Math.floor( depthSegments ) || 1;
|
|
|
+ // segments
|
|
|
|
|
|
- // buffers
|
|
|
+ widthSegments = Math.floor( widthSegments ) || 1;
|
|
|
+ heightSegments = Math.floor( heightSegments ) || 1;
|
|
|
+ depthSegments = Math.floor( depthSegments ) || 1;
|
|
|
|
|
|
- var indices = [];
|
|
|
- var vertices = [];
|
|
|
- var normals = [];
|
|
|
- var uvs = [];
|
|
|
+ // buffers
|
|
|
|
|
|
- // helper variables
|
|
|
+ var indices = [];
|
|
|
+ var vertices = [];
|
|
|
+ var normals = [];
|
|
|
+ var uvs = [];
|
|
|
|
|
|
- var numberOfVertices = 0;
|
|
|
- var groupStart = 0;
|
|
|
+ // helper variables
|
|
|
|
|
|
- // build each side of the box geometry
|
|
|
+ var numberOfVertices = 0;
|
|
|
+ var groupStart = 0;
|
|
|
|
|
|
- buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
|
|
|
- buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
|
|
|
- buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
|
|
|
- buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
|
|
|
- buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
|
|
|
- buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
|
|
|
+ // build each side of the box geometry
|
|
|
|
|
|
- // build geometry
|
|
|
+ buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
|
|
|
+ buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
|
|
|
+ buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
|
|
|
+ buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
|
|
|
+ buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
|
|
|
+ buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
|
|
|
|
|
|
- this.setIndex( indices );
|
|
|
- this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
|
|
- this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
|
|
|
- this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
|
|
|
+ // build geometry
|
|
|
|
|
|
- function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
|
|
|
+ this.setIndex( indices );
|
|
|
+ this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
|
|
+ this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
|
|
|
+ this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
|
|
|
|
|
|
- var segmentWidth = width / gridX;
|
|
|
- var segmentHeight = height / gridY;
|
|
|
+ function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
|
|
|
|
|
|
- var widthHalf = width / 2;
|
|
|
- var heightHalf = height / 2;
|
|
|
- var depthHalf = depth / 2;
|
|
|
+ var segmentWidth = width / gridX;
|
|
|
+ var segmentHeight = height / gridY;
|
|
|
|
|
|
- var gridX1 = gridX + 1;
|
|
|
- var gridY1 = gridY + 1;
|
|
|
+ var widthHalf = width / 2;
|
|
|
+ var heightHalf = height / 2;
|
|
|
+ var depthHalf = depth / 2;
|
|
|
|
|
|
- var vertexCounter = 0;
|
|
|
- var groupCount = 0;
|
|
|
+ var gridX1 = gridX + 1;
|
|
|
+ var gridY1 = gridY + 1;
|
|
|
|
|
|
- var ix, iy;
|
|
|
+ var vertexCounter = 0;
|
|
|
+ var groupCount = 0;
|
|
|
|
|
|
- var vector = new Vector3();
|
|
|
+ var ix, iy;
|
|
|
|
|
|
- // generate vertices, normals and uvs
|
|
|
+ var vector = new Vector3();
|
|
|
+
|
|
|
+ // generate vertices, normals and uvs
|
|
|
+
|
|
|
+ for ( iy = 0; iy < gridY1; iy ++ ) {
|
|
|
|
|
|
- for ( iy = 0; iy < gridY1; iy ++ ) {
|
|
|
+ var y = iy * segmentHeight - heightHalf;
|
|
|
|
|
|
- var y = iy * segmentHeight - heightHalf;
|
|
|
+ for ( ix = 0; ix < gridX1; ix ++ ) {
|
|
|
|
|
|
- for ( ix = 0; ix < gridX1; ix ++ ) {
|
|
|
+ var x = ix * segmentWidth - widthHalf;
|
|
|
|
|
|
- var x = ix * segmentWidth - widthHalf;
|
|
|
+ // set values to correct vector component
|
|
|
|
|
|
- // set values to correct vector component
|
|
|
+ vector[ u ] = x * udir;
|
|
|
+ vector[ v ] = y * vdir;
|
|
|
+ vector[ w ] = depthHalf;
|
|
|
|
|
|
- vector[ u ] = x * udir;
|
|
|
- vector[ v ] = y * vdir;
|
|
|
- vector[ w ] = depthHalf;
|
|
|
+ // now apply vector to vertex buffer
|
|
|
|
|
|
- // now apply vector to vertex buffer
|
|
|
+ vertices.push( vector.x, vector.y, vector.z );
|
|
|
|
|
|
- vertices.push( vector.x, vector.y, vector.z );
|
|
|
+ // set values to correct vector component
|
|
|
|
|
|
- // set values to correct vector component
|
|
|
+ vector[ u ] = 0;
|
|
|
+ vector[ v ] = 0;
|
|
|
+ vector[ w ] = depth > 0 ? 1 : - 1;
|
|
|
|
|
|
- vector[ u ] = 0;
|
|
|
- vector[ v ] = 0;
|
|
|
- vector[ w ] = depth > 0 ? 1 : - 1;
|
|
|
+ // now apply vector to normal buffer
|
|
|
|
|
|
- // now apply vector to normal buffer
|
|
|
+ normals.push( vector.x, vector.y, vector.z );
|
|
|
|
|
|
- normals.push( vector.x, vector.y, vector.z );
|
|
|
+ // uvs
|
|
|
|
|
|
- // uvs
|
|
|
+ uvs.push( ix / gridX );
|
|
|
+ uvs.push( 1 - ( iy / gridY ) );
|
|
|
|
|
|
- uvs.push( ix / gridX );
|
|
|
- uvs.push( 1 - ( iy / gridY ) );
|
|
|
+ // counters
|
|
|
|
|
|
- // counters
|
|
|
+ vertexCounter += 1;
|
|
|
|
|
|
- vertexCounter += 1;
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
+ // indices
|
|
|
|
|
|
- // indices
|
|
|
+ // 1. you need three indices to draw a single face
|
|
|
+ // 2. a single segment consists of two faces
|
|
|
+ // 3. so we need to generate six (2*3) indices per segment
|
|
|
|
|
|
- // 1. you need three indices to draw a single face
|
|
|
- // 2. a single segment consists of two faces
|
|
|
- // 3. so we need to generate six (2*3) indices per segment
|
|
|
+ for ( iy = 0; iy < gridY; iy ++ ) {
|
|
|
|
|
|
- for ( iy = 0; iy < gridY; iy ++ ) {
|
|
|
+ for ( ix = 0; ix < gridX; ix ++ ) {
|
|
|
|
|
|
- for ( ix = 0; ix < gridX; ix ++ ) {
|
|
|
+ var a = numberOfVertices + ix + gridX1 * iy;
|
|
|
+ var b = numberOfVertices + ix + gridX1 * ( iy + 1 );
|
|
|
+ var c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
|
|
|
+ var d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
|
|
|
|
|
|
- var a = numberOfVertices + ix + gridX1 * iy;
|
|
|
- var b = numberOfVertices + ix + gridX1 * ( iy + 1 );
|
|
|
- var c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
|
|
|
- var d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
|
|
|
+ // faces
|
|
|
|
|
|
- // faces
|
|
|
+ indices.push( a, b, d );
|
|
|
+ indices.push( b, c, d );
|
|
|
|
|
|
- indices.push( a, b, d );
|
|
|
- indices.push( b, c, d );
|
|
|
+ // increase counter
|
|
|
|
|
|
- // increase counter
|
|
|
+ groupCount += 6;
|
|
|
|
|
|
- groupCount += 6;
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
+ // add a group to the geometry. this will ensure multi material support
|
|
|
|
|
|
- // add a group to the geometry. this will ensure multi material support
|
|
|
+ scope.addGroup( groupStart, groupCount, materialIndex );
|
|
|
|
|
|
- scope.addGroup( groupStart, groupCount, materialIndex );
|
|
|
+ // calculate new start value for groups
|
|
|
|
|
|
- // calculate new start value for groups
|
|
|
+ groupStart += groupCount;
|
|
|
|
|
|
- groupStart += groupCount;
|
|
|
+ // update total number of vertices
|
|
|
|
|
|
- // update total number of vertices
|
|
|
+ numberOfVertices += vertexCounter;
|
|
|
|
|
|
- numberOfVertices += vertexCounter;
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
-BoxBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
|
|
|
-BoxBufferGeometry.prototype.constructor = BoxBufferGeometry;
|
|
|
-
|
|
|
/**
|
|
|
* Uniform Utilities
|
|
|
*/
|