|
@@ -5,89 +5,22 @@
|
|
|
|
|
|
THREE.PlaneGeometry = function ( width, height, widthSegments, heightSegments ) {
|
|
|
|
|
|
- THREE.BufferGeometry.call( this );
|
|
|
+ THREE.PlaneBufferGeometry.call( this, width, height, widthSegments, heightSegments );
|
|
|
|
|
|
- this.parameters = {
|
|
|
- width: width,
|
|
|
- height: height,
|
|
|
- widthSegments: widthSegments,
|
|
|
- heightSegments: heightSegments
|
|
|
- };
|
|
|
+ var length = this.attributes.position.array.length;
|
|
|
|
|
|
- var width_half = width / 2;
|
|
|
- var height_half = height / 2;
|
|
|
+ this.vertices = [];
|
|
|
+ this.normals = [];
|
|
|
+ this.uvs = [];
|
|
|
|
|
|
- var gridX = widthSegments || 1;
|
|
|
- var gridY = heightSegments || 1;
|
|
|
+ for ( var i = 0, l = length / 3; i < l; i ++ ) {
|
|
|
|
|
|
- var gridX1 = gridX + 1;
|
|
|
- var gridY1 = gridY + 1;
|
|
|
-
|
|
|
- var segment_width = width / gridX;
|
|
|
- var segment_height = height / gridY;
|
|
|
-
|
|
|
- var vertices = new Float32Array( gridX1 * gridY1 * 3 );
|
|
|
- var normals = new Float32Array( gridX1 * gridY1 * 3 );
|
|
|
- var uvs = new Float32Array( gridX1 * gridY1 * 2 );
|
|
|
-
|
|
|
- var offset = 0;
|
|
|
- var offset2 = 0;
|
|
|
-
|
|
|
- for ( var iy = 0; iy < gridY1; iy ++ ) {
|
|
|
-
|
|
|
- var y = iy * segment_height - height_half;
|
|
|
-
|
|
|
- for ( var ix = 0; ix < gridX1; ix ++ ) {
|
|
|
-
|
|
|
- var x = ix * segment_width - width_half;
|
|
|
-
|
|
|
- vertices[ offset ] = x;
|
|
|
- vertices[ offset + 1 ] = - y;
|
|
|
-
|
|
|
- normals[ offset + 2 ] = 1;
|
|
|
-
|
|
|
- uvs[ offset2 ] = ix / gridX;
|
|
|
- uvs[ offset2 + 1 ] = 1 - ( iy / gridY );
|
|
|
-
|
|
|
- offset += 3;
|
|
|
- offset2 += 2;
|
|
|
-
|
|
|
- }
|
|
|
+ this.vertices.push( new THREE.TypedVector3( this.attributes.position.array, i * 3 ) );
|
|
|
+ this.normals.push( new THREE.TypedVector3( this.attributes.normal.array, i * 3 ) );
|
|
|
+ this.uvs.push( new THREE.TypedVector2( this.attributes.uv.array, i * 2 ) );
|
|
|
|
|
|
}
|
|
|
|
|
|
- offset = 0;
|
|
|
-
|
|
|
- var indices = new Uint16Array( gridX * gridY * 6 );
|
|
|
-
|
|
|
- for ( var iy = 0; iy < gridY; iy ++ ) {
|
|
|
-
|
|
|
- for ( var ix = 0; ix < gridX; ix ++ ) {
|
|
|
-
|
|
|
- var a = ix + gridX1 * iy;
|
|
|
- var b = ix + gridX1 * ( iy + 1 );
|
|
|
- var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
|
|
|
- var d = ( ix + 1 ) + gridX1 * iy;
|
|
|
-
|
|
|
- indices[ offset ] = a;
|
|
|
- indices[ offset + 1 ] = b;
|
|
|
- indices[ offset + 2 ] = d;
|
|
|
-
|
|
|
- indices[ offset + 3 ] = b;
|
|
|
- indices[ offset + 4 ] = c;
|
|
|
- indices[ offset + 5 ] = d;
|
|
|
-
|
|
|
- offset += 6;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- this.attributes[ 'index' ] = { array: indices, itemSize: 1 };
|
|
|
- this.attributes[ 'position' ] = { array: vertices, itemSize: 3 };
|
|
|
- this.attributes[ 'normal' ] = { array: normals, itemSize: 3 };
|
|
|
- this.attributes[ 'uv' ] = { array: uvs, itemSize: 2 };
|
|
|
-
|
|
|
};
|
|
|
|
|
|
-THREE.PlaneGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
|
|
|
+THREE.PlaneGeometry.prototype = Object.create( THREE.PlaneBufferGeometry.prototype );
|