我这边的模型并不是标准的3d模型(不是fbx,gltf等),只能通过代码方式创建模型、蒙皮骨骼动画,但是卡在骨骼动画环节。
发现骨骼动画并不是直接通过clip.tracks实现的,是通过引擎私有的_exoticAnimation: ExoticAnimation 的动画对象实现。
这块我直接通过 js.getClassByName(“cc.animation.ExoticAnimation”); 动态创建来实现没有什么问题。
现在碰到新的问题,骨骼的bindpose的算法,这个里tpos的矩阵是怎么算出来的。
现在有骨骼节点树结构(嵌套关系)。如何计算每一个节点的bindpose矩阵?
是每一个骨骼的本地矩阵向上查找直到根(模型的根)之间的本地矩阵相乘。再取invert吗?
let knightModel = this.knight_model.getComponentInChildren(SkinnedMeshRenderer);
let bone1:Node = this.knight_model.children[0];
let bindpose1:Mat4 = this.getBoneMatrix(bone1, knightModel.skinningRoot)
getBoneMatrix(bone: Node, skinningRoot: Node) {
let matrix = math.mat4();
let temp = math.mat4();
while (bone !== skinningRoot) {
math.Mat4.fromRTS(temp, bone.rotation, bone.position, bone.scale);
math.Mat4.multiply(matrix, temp, matrix);
bone = bone.parent!;
}
return matrix;
}