From be4757d0f657cd99fbb9982f9729dd4b83f8fa53 Mon Sep 17 00:00:00 2001 From: "Mr.doob" Date: Tue, 11 Mar 2014 19:45:25 -0400 Subject: [PATCH] So now Geometry2 basically adds helper arrays to BufferGeometry. --- src/core/Geometry2.js | 28 ++++++++++++++++++++++++++ src/extras/geometries/PlaneGeometry.js | 19 +---------------- utils/build/includes/common.json | 1 + 3 files changed, 30 insertions(+), 18 deletions(-) create mode 100644 src/core/Geometry2.js diff --git a/src/core/Geometry2.js b/src/core/Geometry2.js new file mode 100644 index 0000000000..47d433e77c --- /dev/null +++ b/src/core/Geometry2.js @@ -0,0 +1,28 @@ +/** + * @author mrdoob / http://mrdoob.com/ + */ + +THREE.Geometry2 = function ( bufferGeometry ) { + + var vertices = []; + var normals = []; + var uvs = []; + + var attributes = bufferGeometry.attributes; + var length = attributes.position.array.length; + + for ( var i = 0, l = length / 3; i < l; i ++ ) { + + vertices.push( new THREE.TypedVector3( attributes.position.array, i * 3 ) ); + normals.push( new THREE.TypedVector3( attributes.normal.array, i * 3 ) ); + uvs.push( new THREE.TypedVector2( attributes.uv.array, i * 2 ) ); + + } + + bufferGeometry.vertices = vertices; + bufferGeometry.normals = normals; + bufferGeometry.uvs = uvs; + + return bufferGeometry; + +}; \ No newline at end of file diff --git a/src/extras/geometries/PlaneGeometry.js b/src/extras/geometries/PlaneGeometry.js index 869becbd68..da76183d8d 100644 --- a/src/extras/geometries/PlaneGeometry.js +++ b/src/extras/geometries/PlaneGeometry.js @@ -1,26 +1,9 @@ /** * @author mrdoob / http://mrdoob.com/ - * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as */ THREE.PlaneGeometry = function ( width, height, widthSegments, heightSegments ) { - THREE.PlaneBufferGeometry.call( this, width, height, widthSegments, heightSegments ); - - var length = this.attributes.position.array.length; - - this.vertices = []; - this.normals = []; - this.uvs = []; - - for ( var i = 0, l = length / 3; i < l; i ++ ) { - - 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 ) ); - - } + return new THREE.Geometry2( new THREE.PlaneBufferGeometry( width, height, widthSegments, heightSegments ) ); }; - -THREE.PlaneGeometry.prototype = Object.create( THREE.PlaneBufferGeometry.prototype ); diff --git a/utils/build/includes/common.json b/utils/build/includes/common.json index 6fba8af21f..ea39e7f481 100644 --- a/utils/build/includes/common.json +++ b/utils/build/includes/common.json @@ -32,6 +32,7 @@ "src/core/BufferAttribute.js", "src/core/BufferGeometry.js", "src/core/Geometry.js", + "src/core/Geometry2.js", "src/cameras/Camera.js", "src/cameras/OrthographicCamera.js", "src/cameras/PerspectiveCamera.js", -- GitLab