Thanks @Mr_F and @yaustar !
A follow up question to this would be if the animation parser is looking into morphs?
I looked into src/resources/animation.js and found that v4 is creating animation keys for bones:
_parseAnimationV4: function (data) {
var animData = data.animation;
var anim = new pc.Animation();
anim.setName(animData.name);
anim.duration = animData.duration;
for (var i = 0; i < animData.nodes.length; i++) {
var node = new pc.Node();
var n = animData.nodes[i];
node._name = n.name;
var defPos = n.defaults.p;
var defRot = n.defaults.r;
var defScl = n.defaults.s;
for (var j = 0; j < n.keys.length; j++) {
var k = n.keys[j];
var t = k.t;
var p = defPos ? defPos : k.p;
var r = defRot ? defRot : k.r;
var s = defScl ? defScl : k.s;
var pos = new pc.Vec3(p[0], p[1], p[2]);
var rot = new pc.Quat().setFromEulerAngles(r[0], r[1], r[2]);
var scl = new pc.Vec3(s[0], s[1], s[2]);
var key = new pc.Key(t, pos, rot, scl);
node._keys.push(key);
}
anim.addNode(node);
}
return anim;
…but I don’t see it parsing morph information.
I was trying to follow the same format for bone animation in order to recreate it under the morphs node, but I’m not sure if this would be read by any function.
I was trying to avoid depending on .update in order to create a morph animation sequence.
[here’s a condensed version of what I’m doing]
CheckMorphs.prototype.initialize = function () {
this.frames = {
0: {
0 : / *coefficient between 0 and 1 */,
1: / *coefficient between 0 and 1 */,
n: {...}
},
1: {
0 : / *coefficient between 0 and 1 */,
1: / *coefficient between 0 and 1 */,
n: {...}
},
n: {
0 : / *coefficient between 0 and 1 */,
1: / *coefficient between 0 and 1 */,
n: {...}
},
}
};
CheckMorphs.prototype.update = function () {
self = this;
jQuery.each(this.frames, function(i, val){
self.entity.model.meshInstances[0].morphInstance.setWeight(i, val);
}
};
I’ve managed to get the face to move, but it’s incredibly choppy. I can only assume that it’s not interpolating from morph to morph.
Concrete questions:
- Is there a way to integrate a morphs weights keys array into an animation file (even if at this point I have to do it manually)?
- Is there a better way to interpolate between a
.seWeight
and another .setWeight
?
