Jelajahi Sumber

RapierPhysics: Clean up.

Mr.doob 2 tahun lalu
induk
melakukan
46754408eb
1 mengubah file dengan 12 tambahan dan 24 penghapusan
  1. 12 24
      examples/jsm/physics/RapierPhysics.js

+ 12 - 24
examples/jsm/physics/RapierPhysics.js

@@ -117,44 +117,32 @@ async function RapierPhysics() {
 
 	function setMeshPosition( mesh, position, index = 0 ) {
 
-		if ( mesh.isInstancedMesh ) {
-
-			const bodies = meshMap.get( mesh );
-			const body = bodies[ index ];
-
-			body.setAngvel( ZERO );
-			body.setLinvel( ZERO );
-			body.setTranslation( position );
+		let  body = meshMap.get( mesh );
 
-		} else if ( mesh.isMesh ) {
-
-			const body = meshMap.get( mesh );
+		if ( mesh.isInstancedMesh ) {
 
-			body.setAngvel( ZERO );
-			body.setLinvel( ZERO );
-			body.setTranslation( position );
+			body = body[ index ];
 
 		}
 
+		body.setAngvel( ZERO );
+		body.setLinvel( ZERO );
+		body.setTranslation( position );
+
 	}
 
 	function setMeshVelocity( mesh, velocity, index = 0 ) {
 
-		if ( mesh.isInstancedMesh ) {
-
-			const bodies = meshMap.get( mesh );
-			const body = bodies[ index ];
-
-			body.setLinvel( velocity );
+		let  body = meshMap.get( mesh );
 
-		} else if ( mesh.isMesh ) {
-
-			const body = meshMap.get( mesh );
+		if ( mesh.isInstancedMesh ) {
 
-			body.setLinvel( velocity );
+			body = body[ index ];
 
 		}
 
+		body.setLinvel( velocity );
+
 	}
 
 	//