Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 53 additions & 4 deletions examples/jsm/animation/MMDAnimationHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -978,20 +978,52 @@ var MMDAnimationHelper = ( function () {
this.mesh = mesh;
this.grants = grants || [];

this.CCDIKSolver = new CCDIKSolver(this.mesh, this.mesh.geometry.userData.MMD.iks);

var bones = this.mesh.skeleton.bones;
// add hasIK userData to IK, IK's parent.
for( var i = 0; i < mesh.geometry.userData.MMD.iks.length; i++ ) {

var ik = mesh.geometry.userData.MMD.iks[i];
var bone = bones[ik.target];
// add hasIK in links

for( var j = 0; j < ik.links.length; j++ ) {

var link = ik.links[j]

if( link && !( link.index && link.enabled )) continue;

var linkBone = bones[link.index];
linkBone.userData.hasIK = true;
// add hasIK to link ~ root
while( linkBone.parent ) {
linkBone.parent.userData.hasIK = true;
linkBone = linkBone.parent;
}
}
// add hasIK to bone ~ root
while ( bone.parent ) {
bone.parent.userData.hasIK = true;
bone = bone.parent;
}
}

}

GrantSolver.prototype = {

constructor: GrantSolver,

/**
* @param {boolean} isRecursion
* @return {GrantSolver}
*/
update: function () {

var quaternion = new Quaternion();

return function () {
return function (isRecursion = false) {

var bones = this.mesh.skeleton.bones;
var grants = this.grants;
Expand Down Expand Up @@ -1023,16 +1055,33 @@ var MMDAnimationHelper = ( function () {

if ( grant.affectRotation ) {

quaternion.set( 0, 0, 0, 1 );
quaternion.slerp( parentBone.quaternion, grant.ratio );
bone.quaternion.multiply( quaternion );
if( isRecursion && bone.userData.hasIK ) continue;

if( isRecursion || bone.userData.hasIK ) {

quaternion.set( 0, 0, 0, 1 );
quaternion.slerp( parentBone.quaternion, grant.ratio );
quaternion.multiply(bone.quaternion);

bone.quaternion.copy(quaternion);

}

}

}

}

if( !isRecursion ) {

this.mesh.updateMatrixWorld( true );
this.CCDIKSolver.update();

this.update(true);

}

return this;

};
Expand Down