Browse Source

So now Geometry2 basically adds helper arrays to BufferGeometry.

Mr.doob 11 years ago
parent
commit
be4757d0f6
3 changed files with 30 additions and 18 deletions
  1. 28 0
      src/core/Geometry2.js
  2. 1 18
      src/extras/geometries/PlaneGeometry.js
  3. 1 0
      utils/build/includes/common.json

+ 28 - 0
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;
+
+};

+ 1 - 18
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 );

+ 1 - 0
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",