Browse Source

Update CCDIKSolver (#9976)

* Update CCDIKSolver

* Update root world matrix in CCDIKSolver
Takahiro 8 năm trước cách đây
mục cha
commit
7dcba9b754
1 tập tin đã thay đổi với 11 bổ sung3 xóa
  1. 11 3
      examples/js/animation/CCDIKSolver.js

+ 11 - 3
examples/js/animation/CCDIKSolver.js

@@ -8,6 +8,7 @@
  *
  * ik parameter example
  *
+ * // target, effector, index in links are bone index in skeleton.
  * ik = {
  *	target: 1,
  *	effector: 2,
@@ -71,9 +72,6 @@ THREE.CCDIKSolver.prototype = {
 
 					var angle = targetVec.dot( effectorVec );
 
-					// TODO: continue (or break) the loop for the performance
-					//       if no longer needs to rotate (angle > 1.0-1e-5 ?)
-
 					if ( angle > 1.0 ) {
 
 						angle = 1.0;
@@ -86,6 +84,14 @@ THREE.CCDIKSolver.prototype = {
 
 					angle = math.acos( angle );
 
+					// skip if changing angle is too small to prevent vibration of bone
+					// Refer to http://www20.atpages.jp/katwat/three.js_r58/examples/mytest37/mmd.three.js
+					if ( angle < 1e-5 ) {
+
+						continue;
+
+					}
+
 					if ( ik.minAngle !== undefined && angle < ik.minAngle ) {
 
 						angle = ik.minAngle;
@@ -129,6 +135,8 @@ THREE.CCDIKSolver.prototype = {
 
 			}
 
+			this.mesh.updateMatrixWorld( true );
+
 		}
 
 	}