Pārlūkot izejas kodu

Updated cloth example to DynamicGeometry.

Mr.doob 10 gadi atpakaļ
vecāks
revīzija
51ca1bf28a

+ 2 - 6
examples/webgl_animation_cloth.html

@@ -191,8 +191,7 @@
 
 				// cloth geometry
 				clothGeometry = new THREE.ParametricGeometry( clothFunction, cloth.w, cloth.h );
-				clothGeometry.dynamic = true;
-				clothGeometry.computeFaceNormals();
+				clothGeometry = new THREE.DynamicGeometry().fromGeometry( clothGeometry );
 
 				var uniforms = { texture:  { type: "t", value: clothTexture } };
 				var vertexShader = document.getElementById( 'vertexShaderDepth' ).textContent;
@@ -230,7 +229,7 @@
 				groundTexture.wrapS = groundTexture.wrapT = THREE.RepeatWrapping;
 				groundTexture.repeat.set( 25, 25 );
 				groundTexture.anisotropy = 16;
-				
+
 				var groundMaterial = new THREE.MeshPhongMaterial( { color: 0xffffff, specular: 0x111111, map: groundTexture } );
 
 				var mesh = new THREE.Mesh( new THREE.PlaneBufferGeometry( 20000, 20000 ), groundMaterial );
@@ -349,9 +348,6 @@
 
 				}
 
-				clothGeometry.computeFaceNormals();
-				clothGeometry.computeVertexNormals();
-
 				clothGeometry.normalsNeedUpdate = true;
 				clothGeometry.verticesNeedUpdate = true;
 

+ 0 - 2
src/core/BufferGeometry.js

@@ -154,8 +154,6 @@ THREE.BufferGeometry.prototype = {
 
 		var geometry = object.geometry;
 
-		if ( object instanceof THREE.Mesh && geometry instanceof THREE.Geometry ) return;
-
 		if ( geometry.verticesNeedUpdate === true ) {
 
 			var attribute = this.attributes.position;

+ 23 - 1
src/core/DynamicGeometry.js

@@ -45,10 +45,30 @@ THREE.DynamicGeometry = function () {
 
 THREE.DynamicGeometry.prototype = {
 
-	constructor: THREE.Geometry,
+	constructor: THREE.DynamicGeometry,
+
+	computeBoundingBox: THREE.Geometry.prototype.computeBoundingBox,
+	computeBoundingSphere: THREE.Geometry.prototype.computeBoundingSphere,
+
+	computeFaceNormals: function () {
+
+		THREE.warn( 'THREE.DynamicGeometry: computeFaceNormals() is not a method of this type of geometry.' );
+		return this;
+
+	},
+
+	computeVertexNormals: function () {
+
+		THREE.warn( 'THREE.DynamicGeometry: computeVertexNormals	() is not a method of this type of geometry.' );
+		return this;
+
+	},
 
 	fromGeometry: function ( geometry ) {
 
+		this.vertices = geometry.vertices;
+		this.faces = geometry.faces;
+
 		var faces = geometry.faces;
 		var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
 
@@ -81,6 +101,8 @@ THREE.DynamicGeometry.prototype = {
 
 		}
 
+		return this;
+
 	},
 
 	dispose: function () {

+ 0 - 2
src/core/Geometry.js

@@ -35,8 +35,6 @@ THREE.Geometry = function () {
 
 	this.hasTangents = false;
 
-	this.dynamic = true;
-
 	// update flags
 
 	this.verticesNeedUpdate = false;

+ 4 - 5
src/renderers/webgl/WebGLObjects.js

@@ -173,14 +173,13 @@ THREE.WebGLObjects = function ( gl, info ) {
 
 	this.update = function ( object ) {
 
-		if ( geometries[ object.geometry.id ] === undefined ) {
+		var geometry = geometries.get( object );
 
-			initGeometry( object );
+		if ( geometry instanceof THREE.DynamicGeometry ) {
 
-		}
+			geometry.updateFromObject( object );
 
-		var geometry = geometries[ object.geometry.id ];
-		geometry.updateFromObject( object );
+		}
 
 		//