Hi,
I need to get the previous transform of a mesh bone to do some calculation on it every frame, to apply on my scene.
I want the relative move (position, rotation) of a given bone between each frame.
I am not sure if I want it local or global yet. Local could be easier for my needs though…
The code below ignores the rotation part, because I can’t make it work for translation only.
One step at a time I guess, but a matrix would be better.
let current_set = new Vector3();
let len = mesh.skeleton.bones.length;
let prev_ref_position: Vector3[] = [];
// prefill
for (let v of mesh.skeleton.bones) {
let current_set = new Vector3();
current_set.x = v.getTransformNode().position.x;
current_set.y = v.getTransformNode().position.y;
current_set.z = v.getTransformNode().position.z;
prev_ref_position.push(current_set);
}
scene.registerBeforeRender(() => {
for (let x = 0; x < len; ++x) {
let j = mesh.skeleton.bones[x].getTransformNode().position.clone();
current_set.x = j.x - prev_ref_position[x].x;
current_set.y = j.y - prev_ref_position[x].y;
current_set.z = j.z - prev_ref_position[x].z;
// do something with current_set
...
// set the previous value to the current mesh.skeleton.bones[x] position for next calculation
prev_ref_position[x].x = j.x;
prev_ref_position[x].y = j.y;
prev_ref_position[x].z = j.z;
}
});
The issue is that current_set is always 0, as if mesh.skeleton.bones[x].getTransformNode().position
didn’t have the time to change at the next tick.
Is there a way to make it work ?
Thanks