瀏覽代碼

update bone position directly with the rigid body.

we should not calculate the position of the bone with the instantaneous velocity of the rigid body . When the model moves faster, it will lead to the failure of the position constraint. It is better to update the bone position directly with the current position of the rigid body.
Pan Xinmiao 6 年之前
父節點
當前提交
e306b3c760
共有 1 個文件被更改,包括 13 次插入13 次删除
  1. 13 13
      examples/js/animation/MMDPhysics.js

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

@@ -1072,19 +1072,19 @@ THREE.MMDPhysics = ( function () {
 
 			var manager = this.manager;
 
-			var tr = this._getWorldTransformForBone();
-
-			var thV = manager.allocThreeVector3();
-
-			var o = manager.getOrigin( tr );
-			thV.set( o.x(), o.y(), o.z() );
-
-			var v = this.bone.worldToLocal( thV );
-			this.bone.position.add( v );
-
-			manager.freeThreeVector3( thV );
-
-			manager.freeTransform( tr );
+			var tr = this.body.getCenterOfMassTransform();
+			var origin = tr.getOrigin();
+			
+			var matrixInv = manager.allocThreeMatrix4();
+			matrixInv.copy( this.bone.parent.matrixWorld ).getInverse( matrixInv );
+			
+			var pos = manager.allocThreeVector3();
+			pos.set(origin.x(), origin.y(), origin.z()).applyMatrix4(matrixInv);
+
+			this.bone.position.copy(pos);
+
+			manager.freeThreeVector3( pos );
+			manager.freeThreeMatrix4( matrixInv );
 
 		}