Hey. It’s me again. Asking the same questions …
So I’m now utilizing a script that @yqu has provided in his post: ☑ Animation Layering
I’ve altered it to correctly suit my needs for my model, but while there are no errors thrown, the upper body animations do not play…
Here’s the altered script:
const DSkeletonAnimator = pc.createScript('DSkeletonAnimator');
DSkeletonAnimator.attributes.add('skinnedMesh', {type: 'entity', default: 0, title: 'Skinned Mesh'});
let upperLayerAnims=[];
var updateAnim = false;
let upperSkeleton;
DSkeletonAnimator.prototype.initialize = function() {
//mixamorig:Spine
//mixamorig:LeftUpLeg
//mixamorig:RightUpLeg
//
//Get graph for all nodes in skinned mesh
this.boneGraph = this.entity.model.model.getGraph();
//Get the aim idle animation from the skinned mesh animations
//this.aim_animation = this.entity.animation.data.animations.idleAim;
let idleHipAnim = { 'id':'idleHipAim', anim:this.entity.animation.getAnimation("Idle Rifle") };
let idleAimAnim = { 'id':'idleAim', anim:this.entity.animation.getAnimation("Idle Aiming Rifle") };
let firingAnim = {'id':'firingRifle', anim: this.entity.animation.getAnimation("Shoot Rifle") };
upperLayerAnims.push(idleHipAnim);
upperLayerAnims.push(idleAimAnim);
upperLayerAnims.push(firingAnim);
this.frame = 0;
//create a new skeleton and set it to the skinned mesh entity
upperSkeleton = new pc.Skeleton(this.entity);
//set its graph to the nodes from the spine and further down
upperSkeleton.setGraph(this.boneGraph.findByName('mixamorig:Spine'));
//set its new animation clip which will only contain relevant nodes to the spine and further down
this.upperAnimationClip = new pc.Animation();
//grab the nodes from the animation
const aimSkeletonNodes = idleHipAnim.anim._nodes;
//Filter the animation nodes into a new array to be added into the new animation clip array
var relevantFilteredNodes = aimSkeletonNodes.filter(function(node){
return node._name!="mixamorig:LeftLeg"&&node._name!="mixamorig:LeftFoot"&&
node._name!="mixamorig:LeftToeBase"&&node._name!="mixamorig:LeftUpLeg"&&
node._name!="mixamorig:RightUpLeg"&&node._name!="mixamorig:RightLeg"&&
node._name!="mixamorig:RightFoot"&&node._name!="mixamorig:RightToeBase"&&
node._name!="mixamorig:Hips"
});
//Loop through our filtered nodes and add the filtered animation nodes into the new animation clip
for(let index in relevantFilteredNodes) {
let node = relevantFilteredNodes[index];
if(index!="binaryIndexOf"){
this.upperAnimationClip.addNode(node);
}
}
//name the newly created clip
this.upperAnimationClip.name = idleHipAnim.id;
//add its duration
this.upperAnimationClip.duration = idleHipAnim.anim.duration;
//add the newly created clip to the upper body skeleton
upperSkeleton.animation = this.upperAnimationClip;
updateAnim = true;
this.app.on('changeUpperAnim', (anim) => {
updateAnim = false;
let matchedAnim = upperLayerAnims.find((anm)=>{
return anm.id===anim.id;
});
let relevantFilteredNodes = matchedAnim.anim._nodes.filter(function(node){
return node._name!="mixamorig:LeftLeg"&&node._name!="mixamorig:LeftFoot"&&
node._name!="mixamorig:LeftToeBase"&&node._name!="mixamorig:LeftUpLeg"&&
node._name!="mixamorig:RightUpLeg"&&node._name!="mixamorig:RightLeg"&&
node._name!="mixamorig:RightFoot"&&node._name!="mixamorig:RightToeBase"&&
node._name!="mixamorig:Hips"
});
let upperAnimClip = new pc.Animation();
//Loop through our filtered nodes and add the filtered animation nodes into the new animation clip
for(let index in relevantFilteredNodes) {
let node = relevantFilteredNodes[index];
if(index!="binaryIndexOf"){
upperAnimClip.addNode(node);
}
}
//name the newly created clip
upperAnimClip.name = anim.id;
//add its duration
upperAnimClip.duration = matchedAnim.anim.duration;
//add the newly created clip to the upper body skeleton
upperSkeleton.animation = upperAnimClip;
updateAnim = true;
});
};
DSkeletonAnimator.prototype.updateSkeleton = function(dt) {
if(updateAnim) {
if(this.frame > upperSkeleton._animation.duration){
this.frame = 0;
}
else{
this.frame += 0.01;
}
upperSkeleton.addTime(this.frame * dt);
upperSkeleton.updateGraph();
}
};
No matter what I try, I can’t seem to get this script to work, this is my 4th iteration of it… The animations on the upper body simply will not play. Other than the upper body not separating from the lower body, animation of the model as a whole stays the same, and play, as usual, making this even more confusing. Can anyone identify what my issue is here?
Thanks so much guys!