浏览代码

Enable MMDPhysics world sharing

Takahiro 8 年之前
父节点
当前提交
e09daf6902
共有 2 个文件被更改,包括 10 次插入2 次删除
  1. 2 2
      examples/js/animation/MMDPhysics.js
  2. 8 0
      examples/js/loaders/MMDLoader.js

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

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

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