|
@@ -3,7 +3,7 @@ import { Float32BufferAttribute } from '../core/BufferAttribute.js';
|
|
|
|
|
|
class PlaneBufferGeometry extends BufferGeometry {
|
|
|
|
|
|
- constructor( width, height, widthSegments, heightSegments ) {
|
|
|
+ constructor( width = 1, height = 1, widthSegments = 1, heightSegments = 1 ) {
|
|
|
|
|
|
super();
|
|
|
this.type = 'PlaneBufferGeometry';
|
|
@@ -15,14 +15,11 @@ class PlaneBufferGeometry extends BufferGeometry {
|
|
|
heightSegments: heightSegments
|
|
|
};
|
|
|
|
|
|
- width = width || 1;
|
|
|
- height = height || 1;
|
|
|
-
|
|
|
const width_half = width / 2;
|
|
|
const height_half = height / 2;
|
|
|
|
|
|
- const gridX = Math.floor( widthSegments ) || 1;
|
|
|
- const gridY = Math.floor( heightSegments ) || 1;
|
|
|
+ const gridX = Math.floor( widthSegments );
|
|
|
+ const gridY = Math.floor( heightSegments );
|
|
|
|
|
|
const gridX1 = gridX + 1;
|
|
|
const gridY1 = gridY + 1;
|
|
@@ -30,15 +27,13 @@ class PlaneBufferGeometry extends BufferGeometry {
|
|
|
const segment_width = width / gridX;
|
|
|
const segment_height = height / gridY;
|
|
|
|
|
|
- // buffers
|
|
|
+ //
|
|
|
|
|
|
const indices = [];
|
|
|
const vertices = [];
|
|
|
const normals = [];
|
|
|
const uvs = [];
|
|
|
|
|
|
- // generate vertices, normals and uvs
|
|
|
-
|
|
|
for ( let iy = 0; iy < gridY1; iy ++ ) {
|
|
|
|
|
|
const y = iy * segment_height - height_half;
|
|
@@ -58,8 +53,6 @@ class PlaneBufferGeometry extends BufferGeometry {
|
|
|
|
|
|
}
|
|
|
|
|
|
- // indices
|
|
|
-
|
|
|
for ( let iy = 0; iy < gridY; iy ++ ) {
|
|
|
|
|
|
for ( let ix = 0; ix < gridX; ix ++ ) {
|
|
@@ -69,8 +62,6 @@ class PlaneBufferGeometry extends BufferGeometry {
|
|
|
const c = ( ix + 1 ) + gridX1 * ( iy + 1 );
|
|
|
const d = ( ix + 1 ) + gridX1 * iy;
|
|
|
|
|
|
- // faces
|
|
|
-
|
|
|
indices.push( a, b, d );
|
|
|
indices.push( b, c, d );
|
|
|
|
|
@@ -78,8 +69,6 @@ class PlaneBufferGeometry extends BufferGeometry {
|
|
|
|
|
|
}
|
|
|
|
|
|
- // build geometry
|
|
|
-
|
|
|
this.setIndex( indices );
|
|
|
this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
|
|
this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
|
|
@@ -89,5 +78,4 @@ class PlaneBufferGeometry extends BufferGeometry {
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
export { PlaneBufferGeometry };
|