Ver código fonte

Enable MMDPhysics world sharing

Takahiro 8 anos atrás
pai
commit
e09daf6902

+ 2 - 2
examples/js/animation/MMDPhysics.js

@@ -35,7 +35,7 @@ THREE.MMDPhysics = function ( mesh, params ) {
 	this.unitStep = ( params.unitStep !== undefined ) ? params.unitStep : 1 / 65;
 	this.maxStepNum = ( params.maxStepNum !== undefined ) ? params.maxStepNum : 3;
 
-	this.world = null;
+	this.world = params.world !== undefined ? params.world : null;
 	this.bodies = [];
 	this.constraints = [];
 
@@ -67,7 +67,7 @@ THREE.MMDPhysics.prototype = {
 
 		mesh.updateMatrixWorld( true );
 
-		this.initWorld();
+		if ( this.world === null ) this.initWorld();
 		this.initRigidBodies();
 		this.initConstraints();
 

+ 8 - 0
examples/js/loaders/MMDLoader.js

@@ -2281,10 +2281,18 @@ THREE.MMDHelper.prototype = {
 
 	setPhysicses: function ( params ) {
 
+		params = ( params === undefined ) ? {} : Object.assign( {}, params );
+
 		for ( var i = 0; i < this.meshes.length; i++ ) {
 
 			this.setPhysics( this.meshes[ i ], params );
 
+			if ( i === 0 && params.sharePhysicsWorld === true ) {
+
+				params.world = this.meshes[ 0 ].physics.world;
+
+			}
+
 		}
 
 	},