Prechádzať zdrojové kódy

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 rokov pred
rodič
commit
e306b3c760
1 zmenil súbory, kde vykonal 13 pridanie a 13 odobranie
  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 );
 
 		}