2
0
Эх сурвалжийг харах

Added DynamicGeometry. See #6377.

Mr.doob 10 жил өмнө
parent
commit
2189bd1a6a

+ 24 - 28
src/core/BufferGeometry.js

@@ -128,13 +128,15 @@ THREE.BufferGeometry.prototype = {
 
 
 		} else if ( object instanceof THREE.Mesh ) {
 		} else if ( object instanceof THREE.Mesh ) {
 
 
-			if ( geometry.isFlattened === false ) {
+			if ( geometry instanceof THREE.DynamicGeometry ) {
 
 
-				geometry.flatten();
+				this.fromDynamicGeometry( geometry );
 
 
-			}
+			} else if ( geometry instanceof THREE.Geometry ) {
+
+				this.fromGeometry( geometry );
 
 
-			this.fromFlattenedGeometry( geometry );
+			}
 
 
 		}
 		}
 
 
@@ -152,38 +154,36 @@ THREE.BufferGeometry.prototype = {
 
 
 		var geometry = object.geometry;
 		var geometry = object.geometry;
 
 
-		if ( object instanceof THREE.PointCloud || object instanceof THREE.Line || object instanceof THREE.Mesh ) {
+		if ( object instanceof THREE.Mesh && geometry instanceof THREE.Geometry ) return;
 
 
-			if ( geometry.verticesNeedUpdate === true ) {
+		if ( geometry.verticesNeedUpdate === true ) {
 
 
-				var attribute = this.attributes.position;
+			var attribute = this.attributes.position;
 
 
-				if ( attribute !== undefined ) {
-
-					attribute.copyVector3sArray( geometry.vertices );
-					attribute.needsUpdate = true;
-
-				}
+			if ( attribute !== undefined ) {
 
 
-				geometry.verticesNeedUpdate = false;
+				attribute.copyVector3sArray( geometry.vertices );
+				attribute.needsUpdate = true;
 
 
 			}
 			}
 
 
-			if ( geometry.colorsNeedUpdate === true ) {
+			geometry.verticesNeedUpdate = false;
 
 
-				var attribute = this.attributes.color;
+		}
 
 
-				if ( attribute !== undefined ) {
+		if ( geometry.colorsNeedUpdate === true ) {
 
 
-					attribute.copyColorsArray( geometry.colors );
-					attribute.needsUpdate = true;
+			var attribute = this.attributes.color;
 
 
-				}
+			if ( attribute !== undefined ) {
 
 
-				geometry.colorsNeedUpdate = false;
+				attribute.copyColorsArray( geometry.colors );
+				attribute.needsUpdate = true;
 
 
 			}
 			}
 
 
+			geometry.colorsNeedUpdate = false;
+
 		}
 		}
 
 
 	},
 	},
@@ -363,7 +363,7 @@ THREE.BufferGeometry.prototype = {
 
 
 	},
 	},
 
 
-	fromFlattenedGeometry: function ( geometry ) {
+	fromDynamicGeometry: function ( geometry ) {
 
 
 		var indices = new Uint16Array( geometry.faces.length * 3 );
 		var indices = new Uint16Array( geometry.faces.length * 3 );
 		this.addAttribute( 'index', new THREE.BufferAttribute( indices, 1 ).copyFacesArray( geometry.faces ) );
 		this.addAttribute( 'index', new THREE.BufferAttribute( indices, 1 ).copyFacesArray( geometry.faces ) );
@@ -371,12 +371,8 @@ THREE.BufferGeometry.prototype = {
 		var positions = new Float32Array( geometry.vertices.length * 3 );
 		var positions = new Float32Array( geometry.vertices.length * 3 );
 		this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
 		this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
 
 
-		if ( geometry.normals.length > 0 ) {
-
-			var normals = new Float32Array( geometry.normals.length * 3 );
-			this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
-
-		}
+		var normals = new Float32Array( geometry.normals.length * 3 );
+		this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
 
 
 		var colors = new Float32Array( geometry.colors.length * 3 );
 		var colors = new Float32Array( geometry.colors.length * 3 );
 		this.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ).copyVector3sArray( geometry.colors ) );
 		this.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ).copyVector3sArray( geometry.colors ) );

+ 94 - 0
src/core/DynamicGeometry.js

@@ -0,0 +1,94 @@
+/**
+ * @author mrdoob / http://mrdoob.com/
+ */
+
+THREE.DynamicGeometry = function () {
+
+	Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
+
+	this.uuid = THREE.Math.generateUUID();
+
+	this.name = '';
+	this.type = 'DynamicGeometry';
+
+	this.vertices = [];
+	this.colors = [];
+	this.normals = [];
+	this.colors = [];
+	this.uvs = [];
+	this.faces = [];
+
+	/*
+
+	this.morphTargets = [];
+	this.morphColors = [];
+	this.morphNormals = [];
+
+	this.skinWeights = [];
+	this.skinIndices = [];
+
+	this.lineDistances = [];
+
+	*/
+
+	this.boundingBox = null;
+	this.boundingSphere = null;
+
+	// update flags
+
+	this.verticesNeedUpdate = false;
+	this.normalsNeedUpdate = false;
+	this.colorsNeedUpdate = false;
+	this.uvsNeedUpdate = false;
+
+};
+
+THREE.DynamicGeometry.prototype = {
+
+	constructor: THREE.Geometry,
+
+	fromGeometry: function ( geometry ) {
+
+		var faces = geometry.faces;
+		var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
+
+		for ( var i = 0, il = faces.length; i < il; i ++ ) {
+
+			var face = faces[ i ];
+			var indices = [ face.a, face.b, face.c ];
+
+			var vertexNormals = face.vertexNormals;
+			var vertexColors = face.vertexColors;
+			var vertexUvs = faceVertexUvs[ i ];
+
+			for ( var j = 0, jl = vertexNormals.length; j < jl; j ++ ) {
+
+				this.normals[ indices[ j ] ] = vertexNormals[ j ];
+
+			}
+
+			for ( var j = 0, jl = vertexColors.length; j < jl; j ++ ) {
+
+				this.colors[ indices[ j ] ] = vertexColors[ j ];
+
+			}
+
+			for ( var j = 0, jl = vertexUvs.length; j < jl; j ++ ) {
+
+				this.uvs[ indices[ j ] ] = vertexUvs[ j ];
+
+			}
+
+		}
+
+	},
+
+	dispose: function () {
+
+		this.dispatchEvent( { type: 'dispose' } );
+
+	}
+
+};
+
+THREE.EventDispatcher.prototype.apply( THREE.DynamicGeometry.prototype );

+ 0 - 48
src/core/Geometry.js

@@ -16,19 +16,9 @@ THREE.Geometry = function () {
 	this.name = '';
 	this.name = '';
 	this.type = 'Geometry';
 	this.type = 'Geometry';
 
 
-	// FlattenedGeometry
-
-	this.isFlattened = false;
-
 	this.vertices = [];
 	this.vertices = [];
 	this.colors = [];
 	this.colors = [];
-	this.normals = [];
-	this.colors = [];
-	this.uvs = [];
 	this.faces = [];
 	this.faces = [];
-
-	//
-
 	this.faceVertexUvs = [ [] ];
 	this.faceVertexUvs = [ [] ];
 
 
 	this.morphTargets = [];
 	this.morphTargets = [];
@@ -106,44 +96,6 @@ THREE.Geometry.prototype = {
 
 
 	},
 	},
 
 
-	flatten: function () {
-
-		var faces = this.faces;
-		var faceVertexUvs = this.faceVertexUvs[ 0 ];
-
-		for ( var i = 0, il = faces.length; i < il; i ++ ) {
-
-			var face = faces[ i ];
-			var indices = [ face.a, face.b, face.c ];
-
-			var vertexNormals = face.vertexNormals;
-			var vertexColors = face.vertexColors;
-			var vertexUvs = faceVertexUvs[ i ];
-
-			for ( var j = 0, jl = vertexNormals.length; j < jl; j ++ ) {
-
-				this.normals[ indices[ j ] ] = vertexNormals[ j ];
-
-			}
-
-			for ( var j = 0, jl = vertexColors.length; j < jl; j ++ ) {
-
-				this.colors[ indices[ j ] ] = vertexColors[ j ];
-
-			}
-
-			for ( var j = 0, jl = vertexUvs.length; j < jl; j ++ ) {
-
-				this.uvs[ indices[ j ] ] = vertexUvs[ j ];
-
-			}
-
-		}
-
-		this.isFlattened = true;
-
-	},
-
 	fromBufferGeometry: function ( geometry ) {
 	fromBufferGeometry: function ( geometry ) {
 
 
 		var scope = this;
 		var scope = this;

+ 1 - 6
src/renderers/webgl/WebGLObjects.js

@@ -180,12 +180,7 @@ THREE.WebGLObjects = function ( gl, info ) {
 		}
 		}
 
 
 		var geometry = geometries[ object.geometry.id ];
 		var geometry = geometries[ object.geometry.id ];
-
-		if ( object.geometry instanceof THREE.Geometry ) {
-
-			geometry.updateFromObject( object );
-
-		}
+		geometry.updateFromObject( object );
 
 
 		//
 		//
 
 

+ 1 - 0
utils/build/includes/common.json

@@ -31,6 +31,7 @@
 	"src/core/InstancedInterleavedBuffer.js",
 	"src/core/InstancedInterleavedBuffer.js",
 	"src/core/InterleavedBufferAttribute.js",
 	"src/core/InterleavedBufferAttribute.js",
 	"src/core/Geometry.js",
 	"src/core/Geometry.js",
+	"src/core/DynamicGeometry.js",
 	"src/core/BufferGeometry.js",
 	"src/core/BufferGeometry.js",
 	"src/core/InstancedBufferGeometry.js",
 	"src/core/InstancedBufferGeometry.js",
 	"src/cameras/Camera.js",
 	"src/cameras/Camera.js",