I did the animation in mesh in which there was one door and I did the animation for all the door nodes, I started something like this.
export async function setupNodeAnimations(session: ISessionApi, viewport: any) {
const doorOutput = session.getOutputByName("Door").find((o) => !!o.material);
const doorNode = session.node.children.find((c) => c.name === doorOutput!.id)!;
const doorNodes = doorNode.children;
const doorNodeMap = new Map(doorNodes.map((node) => [node.id, node]));
doorNodes.forEach((childNode) => {
childNode.data.push(new InteractionData({ select: true }));
childNode.updateVersion();
});
for (let i = 0; i < minLength; i++) {
const doorChildNode = doorNodes[I];
const animationDatum = animationData[i];
const { direction, type, start, end, amplitude } = animationDatum;
if (type === 'rotation') {
const { pivot } = animationDatum;
const { x, y, z } = pivot;
const pivot_animation = vec3.fromValues(x, y, z);
const angle = direction === 'L' ? -Math.PI / 2 : Math.PI / 2;
const quat0 = quat.create();
// console.log('Initial quaternion for door(start):', quat0);
const quat1 = quat.setAxisAngle(quat.create(), vec3.fromValues(0, 0, 1), angle);
// console.log('Final quaternion for door (end):', quat1);
const times = [0, 1, 2, 3];
const values = [
quat0[0], quat0[1], quat0[2], quat0[3],
quat1[0], quat1[1], quat1[2], quat1[3],
quat1[0], quat1[1], quat1[2], quat1[3],
quat0[0], quat0[1], quat0[2], quat0[3],
];
const tracks: IAnimationTrack[] = [
{
times: times,
node: doorChildNode,
values: values,
path: "rotation",
interpolation: "linear",
pivot: pivot_animation
}
];
I did same for the translation animation.
But now the model has shifted to the gltf format and now it has BigDrawer, SmallDrawer, RightShutter, LeftShutter, previously we were checking ig the door has material and then looping for the child nodes of it. In this format the structure/ geometry is different for each type of drawer and shutter. So what will be the logic or the method of mapping the animation data to these doors and drawers separately and then animate them, what will be the syntax or the code for the gltf format.
@MajorMeerkatThe3rd Can you help me out in this?