Browse Source

Merge pull request #15122 from WestLangley/dev-cloth

Cloth Animation Example: convert to BufferGeometry
Mr.doob 6 năm trước cách đây
mục cha
commit
843996276b

+ 12 - 8
examples/js/Cloth.js

@@ -243,19 +243,23 @@ function simulate( time ) {
 
 
 	if ( wind ) {
 	if ( wind ) {
 
 
-		var face, faces = clothGeometry.faces, normal;
+		var indx;
+		var normal = new THREE.Vector3();
+		var indices = clothGeometry.index;
+		var normals = clothGeometry.attributes.normal;
 
 
 		particles = cloth.particles;
 		particles = cloth.particles;
 
 
-		for ( i = 0, il = faces.length; i < il; i ++ ) {
+		for ( i = 0, il = indices.count; i < il; i += 3 ) {
 
 
-			face = faces[ i ];
-			normal = face.normal;
+			for ( j = 0; j < 3; j ++ ) {
 
 
-			tmpForce.copy( normal ).normalize().multiplyScalar( normal.dot( windForce ) );
-			particles[ face.a ].addForce( tmpForce );
-			particles[ face.b ].addForce( tmpForce );
-			particles[ face.c ].addForce( tmpForce );
+				indx = indices.getX( i + j );
+				normal.fromBufferAttribute( normals, indx )
+				tmpForce.copy( normal ).normalize().multiplyScalar( normal.dot( windForce ) );
+				particles[ indx ].addForce( tmpForce );
+
+			}
 
 
 		}
 		}
 
 

+ 5 - 4
examples/webgl_animation_cloth.html

@@ -144,7 +144,7 @@
 
 
 				// cloth geometry
 				// cloth geometry
 
 
-				clothGeometry = new THREE.ParametricGeometry( clothFunction, cloth.w, cloth.h );
+				clothGeometry = new THREE.ParametricBufferGeometry( clothFunction, cloth.w, cloth.h );
 
 
 				// cloth mesh
 				// cloth mesh
 
 
@@ -296,13 +296,14 @@
 
 
 				for ( var i = 0, il = p.length; i < il; i ++ ) {
 				for ( var i = 0, il = p.length; i < il; i ++ ) {
 
 
-					clothGeometry.vertices[ i ].copy( p[ i ].position );
+					var v = p[ i ].position;
+
+					clothGeometry.attributes.position.setXYZ( i, v.x, v.y, v.z );
 
 
 				}
 				}
 
 
-				clothGeometry.verticesNeedUpdate = true;
+				clothGeometry.attributes.position.needsUpdate = true;
 
 
-				clothGeometry.computeFaceNormals();
 				clothGeometry.computeVertexNormals();
 				clothGeometry.computeVertexNormals();
 
 
 				sphere.position.copy( ballPosition );
 				sphere.position.copy( ballPosition );