[Jitter, JavaScript] Tracking down the position of gridshape being transferred by jit.anim.node in js api async function
It's unclear for me how to monitor the position of gridshape being transfered by anim.node from one point to another. In the async Promise i have to resolve the function and free memory when animation is done, in other words stop the animation when the end coordinate is reached. Can't find in docs and examples.
I'll share the code snippet I have problems with below, with three of my unsuccessful attempts commented out. I have also tried to use Task for these purposes but it didn't go well either.
function animateImpulse(startCoord, endCoord, speed) {
return new Promise((resolve) => {
post("Calling animateImpulse with:", startCoord, "to", endCoord, "speed:", speed, "\n");
const gridshape = new JitterObject("jit.gl.gridshape", contextName);
gridshape.shape = "cone";
gridshape.color = [Math.random(), Math.random(), Math.random()];
post("Created gridshape");
const animNode = new JitterObject("jit.anim.node");
gridshape.anim = animNode.name;
animNode.movemode = "local";
animNode.scale = impulseScale;
animNode.position = startCoord;
animNode.lookat = endCoord;
animNode.direction = endCoord;
post("Created jit.anim.node");
const animDrive = new JitterObject("jit.anim.drive");
animDrive.targetname = animNode.name;
post("Created jit.anim.drive\n");
// Validate objects before connecting
if (!gridshape || !animDrive || !animNode) {
post("Failed to create gridshape or animDrive or animNode.");
return resolve();
}
animDrive.move(0, 0, speed);
post("\nMoving node")
/* const tsk = new Task(() => {
if (animNode.position[0] >= endCoord[0] &&
animNode.position[1] >= endCoord[1] &&
animNode.position[2] >= endCoord[2]) {
post("\nreached endCoord");
gridshape.freepeer();
animPath.freepeer();
animNode.freepeer();
post("Cleaning and resolving")
resolve();
}
}, this);
tsk.interval = 10; // example val
tsk.repeat(1000) // example val */
/* if (animNode.position[0] === endCoord[0] &&
animNode.position[1] === endCoord[1] &&
animNode.position[2] === endCoord[2]) {
post("\nreached endCoord");
gridshape.freepeer();
animPath.freepeer();
animNode.freepeer();
post("Cleaning and resolving")
resolve();
} */
/* var listener = new JitterListener(animNode.getregisteredname(), callBackResolve);
function callBackResolve(event) {
post(event.eventname);
if(event.subjectname.position = endCoord) {
post("Animation ends")
gridshape.freepeer();
animDrive.freepeer();
animNode.freepeer();
post("Cleaning and resolving")
resolve();
}
} */
});
}
class FloodFill {
async fill(startId, stepsLeft, actionCallback) {
// code omitted
await animateImpulse(
currentVertex.coordinates,
nextVertex.coordinates,
scaleToAnimationSpeed(currentVertex, nextVertex)
);
// code omitted
}
}