feat: Improve trigger processing and static machine status updates in IKAnimationController

This commit is contained in:
Jerald-Golden-B 2025-04-16 10:47:12 +05:30
parent 83f92d4b01
commit 5c24d7ca71
1 changed files with 28 additions and 29 deletions

View File

@ -114,10 +114,38 @@ const IKAnimationController = ({
if (prev.needsInitialMovement !== needsInitialMovement && !needsInitialMovement) {
logStatus(`[Arm ${uuid}] Reached rest position, ready for animation`);
}
if (prev.selectedTrigger !== selectedTrigger) {
logStatus(`[Arm ${uuid}] Processing new trigger: ${selectedTrigger}`);
const currentProcess = process.find(p => p.triggerId === prev.selectedTrigger);
if (currentProcess) {
const triggerId = currentProcess.triggerId;
const endPoint = armBot.actions.processes.find((process) => process.triggerId === triggerId)?.endPoint;
// Search simulationStates for a StaticMachine that has a point matching this endPointId
const matchedStaticMachine = simulationStates.find(
(state) =>
state.type === "StaticMachine" &&
state.points?.uuid === endPoint// check for static machine with matching point uuid
) as any;
if (matchedStaticMachine) {
setStaticMachines((machines) => {
return machines.map((machine) => {
if (machine.uuid === matchedStaticMachine.modeluuid) {
return { ...machine, status: "running" };
} else {
return machine;
}
});
});
}
}
}
// Update previous state
@ -249,35 +277,6 @@ const IKAnimationController = ({
} else if (progress >= startToEndRange[0] && progress < startToEndRange[1]) {
currentSpeed = speed;
currentStatus = "moving"; // Moving between points
if (1 - progress < 0.05) {
// Find the process that matches the current trigger
const currentProcess = process.find(p => p.triggerId === selectedTrigger);
if (currentProcess) {
const triggerId = currentProcess.triggerId;
const endPoint = armBot.actions.processes.find((process) => process.triggerId === triggerId)?.endPoint;
// Search simulationStates for a StaticMachine that has a point matching this endPointId
const matchedStaticMachine = simulationStates.find(
(state) =>
state.type === "StaticMachine" &&
state.points?.uuid === endPoint// check for static machine with matching point uuid
) as any;
if (matchedStaticMachine) {
setStaticMachines((machines) => {
return machines.map((machine) => {
if (machine.uuid === matchedStaticMachine.modeluuid) {
return { ...machine, status: "running" };
} else {
return machine;
}
});
});
}
}
}
} else if (progress >= endToRestRange[0] && progress < 1) {
currentSpeed = restSpeed;
currentStatus = "moving"; // Returning to rest