瀏覽代碼

Experimenting with Geometry99.

Mr.doob 11 年之前
父節點
當前提交
d23f1332b4

+ 92 - 0
examples/js/wip/PlaneGeometry99.js

@@ -0,0 +1,92 @@
+/**
+ * @author mrdoob / http://mrdoob.com/
+ */
+
+THREE.PlaneGeometry99 = function ( width, height, widthSegments, heightSegments ) {
+
+	THREE.Geometry99.call( this );
+
+	this.parameters = {
+		width: width,
+		height: height,
+		widthSegments: widthSegments,
+		heightSegments: heightSegments
+	};
+
+	var width_half = width / 2;
+	var height_half = height / 2;
+
+	var gridX = widthSegments || 1;
+	var gridY = heightSegments || 1;
+
+	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;
+
+		}
+
+	}
+
+	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.PlaneGeometry99.prototype = Object.create( THREE.Geometry99.prototype );

+ 10 - 5
examples/misc_geometry2_sandbox.html

@@ -36,6 +36,8 @@
 		<script src="js/wip/PlaneBufferGeometry.js"></script>
 		<script src="js/wip/PlaneGeometry6.js"></script>
 
+		<script src="js/wip/PlaneGeometry99.js"></script>
+
 		<script src="js/libs/stats.min.js"></script>
 
 		<script>
@@ -49,6 +51,8 @@
 			init();
 			animate();
 
+			var test = new THREE.PlaneGeometry99( 200, 200, 200, 200 );
+
 			function init() {
 
 				container = document.createElement( 'div' );
@@ -66,13 +70,14 @@
 
 				//
 
-				addGeometries( 'PlaneGeometry', 'BoxGeometry', 0 );
+				addGeometries( 'PlaneGeometry', 'BoxGeometry', -100 );
 				// addGeometries( 'IndexedPlaneGeometry5', 'BoxGeometry', 0 );
 				// addGeometries( 'PlaneGeometry2', 'BoxGeometry2', 0 );
 				// addGeometries( 'PlaneGeometry3', 'BoxGeometry2', 0 );
-				addGeometries( 'PlaneGeometry5', 'BoxGeometry2', 0 );
+				addGeometries( 'PlaneGeometry5', 'BoxGeometry2', -50 );
 				addGeometries( 'PlaneBufferGeometry', 'BoxGeometry2', 0 );
-				addGeometries( 'PlaneGeometry6', 'BoxGeometry2', 0 );
+				addGeometries( 'PlaneGeometry6', 'BoxGeometry2', 50 );
+				addGeometries( 'PlaneGeometry99', 'BoxGeometry2', 100 );
 
 				//
 
@@ -117,7 +122,7 @@
 
 			}
 
-			function addGeometries( PlaneGeometry, BoxGeometry, x ) {
+			function addGeometries( PlaneGeometry, BoxGeometry, y ) {
 
 				// Plane
 
@@ -130,7 +135,7 @@
 				var material = new THREE.MeshPhongMaterial( { color: 0xff0000/*, wireframe: true*/ } );
 
 				plane = new THREE.Mesh( geometry, material );
-				plane.position.x = x;
+				plane.position.y = y;
 				scene.add( plane );
 
 				/*

+ 31 - 49
src/core/Geometry99.js

@@ -7,19 +7,26 @@ THREE.Geometry99 = function ( ) {
 
 THREE.Geometry99.prototype = Object.create( THREE.BufferGeometry.prototype );
 
-Object.defineProperties(THREE.Geometry99.prototype, {
+Object.defineProperties( THREE.Geometry99.prototype, {
+
 	vertices: { 
+
 		enumerable: true, 
 		get: function() { return this.createVertexProxies(); } 
+
 	},
 	faces: {
+
 		enumerable: true,  
 		get: function() { return this.createFaceProxies() } 
+
 	},
 	faceVertexUvs: {
+
 		enumerable: true,  
 		get: function() { return this.createUvProxies() } 
-	},
+
+	}
 	// TODO - fill in additional proxies:
 	// - colors
 	// - morphColors
@@ -27,7 +34,7 @@ Object.defineProperties(THREE.Geometry99.prototype, {
 	// - morphTargets
 	// - skinIndex
 	// - skinWeights
-});
+} );
 
 THREE.Geometry99.prototype.createVertexProxies = function() {
 
@@ -37,15 +44,15 @@ THREE.Geometry99.prototype.createVertexProxies = function() {
 
 	// If the attribute buffer has already been populated, set up proxy objects
 
-	this.populateProxyFromBuffer(this.vertices, "position", THREE.TypedVector3, 3);
+	this.populateProxyFromBuffer( this.vertices, "position", THREE.ProxyVector3, 3 );
 
 	// Return a reference to the newly-created array
 
 	return this.vertices;
 
-}
+};
 
-THREE.Geometry99.prototype.createFaceProxies = function() {
+THREE.Geometry99.prototype.createFaceProxies = function () {
 
 	// Replace the prototype getter with a local array property
 
@@ -60,8 +67,11 @@ THREE.Geometry99.prototype.createFaceProxies = function() {
 		var attr = this.faces;
 
 		var normalarray = false;
+
 		if (this.attributes[ 'normal' ]) {
+
 			normalarray = this.attributes[ 'normal' ].array;
+
 		}
 
 		for ( var i = 0, l = indexarray.length / size; i < l; i ++ ) {
@@ -73,18 +83,18 @@ THREE.Geometry99.prototype.createFaceProxies = function() {
 			if (normalarray) {
 
 				vertexNormals = [
-					new THREE.TypedVector3(normalarray, indexarray[o] * 3),
-					new THREE.TypedVector3(normalarray, indexarray[o+1] * 3),
-					new THREE.TypedVector3(normalarray, indexarray[o+2] * 3),
+					new THREE.ProxyVector3( normalarray, indexarray[ o     ] * 3 ),
+					new THREE.ProxyVector3( normalarray, indexarray[ o + 1 ] * 3 ),
+					new THREE.ProxyVector3( normalarray, indexarray[ o + 2 ] * 3 )
 				]
 
 			}
 
 			// TODO - do BufferGeometries support face normals?
 
-			var face = new THREE.TypedFace3( indexarray, i * size, vertexNormals );
+			var face = new THREE.ProxyFace3( indexarray, i * size, vertexNormals );
 
-			attr.push(face);
+			attr.push( face );
 
 		}
 
@@ -98,8 +108,9 @@ THREE.Geometry99.prototype.createFaceProxies = function() {
 
 	return this.faces;
 
-}
-THREE.Geometry99.prototype.createUvProxies = function() {
+};
+
+THREE.Geometry99.prototype.createUvProxies = function () {
 
 	// Replace the prototype getter with a local array property
 
@@ -116,9 +127,9 @@ THREE.Geometry99.prototype.createUvProxies = function() {
 			var f = faces[i];
 
 			this.faceVertexUvs[0][i] = [];
-			this.faceVertexUvs[0][i][0] = new THREE.TypedVector2(uvarray, f.a * 2);
-			this.faceVertexUvs[0][i][1] = new THREE.TypedVector2(uvarray, f.b * 2);
-			this.faceVertexUvs[0][i][2] = new THREE.TypedVector2(uvarray, f.c * 2);
+			this.faceVertexUvs[0][i][0] = new THREE.ProxyVector2(uvarray, f.a * 2);
+			this.faceVertexUvs[0][i][1] = new THREE.ProxyVector2(uvarray, f.b * 2);
+			this.faceVertexUvs[0][i][2] = new THREE.ProxyVector2(uvarray, f.c * 2);
 
 		}
 	
@@ -128,8 +139,9 @@ THREE.Geometry99.prototype.createUvProxies = function() {
 
 	return this.faceVertexUvs;
 
-}
-THREE.Geometry99.prototype.populateProxyFromBuffer = function(attr, buffername, proxytype, itemsize, offset, count) {
+};
+
+THREE.Geometry99.prototype.populateProxyFromBuffer = function ( attr, buffername, proxytype, itemsize, offset, count ) {
 
 	if ( this.attributes[ buffername ] ) {
 
@@ -146,34 +158,4 @@ THREE.Geometry99.prototype.populateProxyFromBuffer = function(attr, buffername,
 
 	}
 
-}
-
-THREE.TypedFace3 = function ( array, offset, vertexNormals ) {
-
-	this.array = array;
-	this.offset = offset;
-	this.vertexNormals = vertexNormals;
-
-	//THREE.Face3.call( this, array[offset], array[offset+1], array[offset+2] /*, normal, color, materialIndex */);
-
-}
-
-THREE.TypedFace3.prototype = Object.create( THREE.Face3.prototype );
-
-Object.defineProperties( THREE.TypedFace3.prototype, {
-	'a': {
-		enumerable: true,  
-		get: function () { return this.array[ this.offset ]; },
-		set: function ( v ) { this.array[ this.offset ] = v; }
-	},
-	'b': {
-		enumerable: true,  
-		get: function () { return this.array[ this.offset + 1 ]; },
-		set: function ( v ) { this.array[ this.offset + 1 ] = v; }
-	},
-	'c': {
-		enumerable: true,  
-		get: function () { return this.array[ this.offset + 2 ]; },
-		set: function ( v ) { this.array[ this.offset + 2 ] = v; }
-	},
-} );
+};

+ 33 - 0
src/core/ProxyFace3.js

@@ -0,0 +1,33 @@
+/**
+ * @author mrdoob / http://mrdoob.com/
+ */
+
+THREE.ProxyFace3 = function ( array, offset, vertexNormals ) {
+
+	this.array = array;
+	this.offset = offset;
+	this.vertexNormals = vertexNormals;
+
+	//THREE.Face3.call( this, array[offset], array[offset+1], array[offset+2] /*, normal, color, materialIndex */);
+
+}
+
+THREE.ProxyFace3.prototype = Object.create( THREE.Face3.prototype );
+
+Object.defineProperties( THREE.ProxyFace3.prototype, {
+	'a': {
+		enumerable: true,  
+		get: function () { return this.array[ this.offset ]; },
+		set: function ( v ) { this.array[ this.offset ] = v; }
+	},
+	'b': {
+		enumerable: true,  
+		get: function () { return this.array[ this.offset + 1 ]; },
+		set: function ( v ) { this.array[ this.offset + 1 ] = v; }
+	},
+	'c': {
+		enumerable: true,  
+		get: function () { return this.array[ this.offset + 2 ]; },
+		set: function ( v ) { this.array[ this.offset + 2 ] = v; }
+	},
+} );

+ 0 - 0
src/math/ProxyVector2.js → src/core/ProxyVector2.js


+ 0 - 0
src/math/ProxyVector3.js → src/core/ProxyVector3.js


+ 3 - 2
utils/build/includes/common.json

@@ -5,8 +5,6 @@
 	"src/math/Vector2.js",
 	"src/math/Vector3.js",
 	"src/math/Vector4.js",
-	"src/math/ProxyVector2.js",
-	"src/math/ProxyVector3.js",
 	"src/math/Euler.js",
 	"src/math/Line3.js",
 	"src/math/Box2.js",
@@ -36,6 +34,9 @@
 	"src/core/Geometry2.js",
 	"src/core/Geometry99.js",
 	"src/core/IndexedGeometry2.js",
+	"src/core/ProxyVector2.js",
+	"src/core/ProxyVector3.js",
+	"src/core/ProxyFace3.js",
 	"src/cameras/Camera.js",
 	"src/cameras/OrthographicCamera.js",
 	"src/cameras/PerspectiveCamera.js",