bug fix
This commit is contained in:
parent
b46b468e1c
commit
43d21a522c
|
@ -9,7 +9,6 @@ import { useProcessAnimation } from "./useProcessAnimations";
|
||||||
import ProcessObject from "./processObject";
|
import ProcessObject from "./processObject";
|
||||||
import { ProcessData } from "./types";
|
import { ProcessData } from "./types";
|
||||||
|
|
||||||
|
|
||||||
interface ArmBotState {
|
interface ArmBotState {
|
||||||
uuid: string;
|
uuid: string;
|
||||||
position: [number, number, number];
|
position: [number, number, number];
|
||||||
|
@ -21,7 +20,12 @@ interface ArmBotState {
|
||||||
source: { modelUUID: string; pointUUID: string };
|
source: { modelUUID: string; pointUUID: string };
|
||||||
targets: { modelUUID: string; pointUUID: string }[];
|
targets: { modelUUID: string; pointUUID: string }[];
|
||||||
};
|
};
|
||||||
actions: { uuid: string; name: string; speed: number; processes: { triggerId: string; startPoint: string; endPoint: string }[]; };
|
actions: {
|
||||||
|
uuid: string;
|
||||||
|
name: string;
|
||||||
|
speed: number;
|
||||||
|
processes: { triggerId: string; startPoint: string; endPoint: string }[];
|
||||||
|
};
|
||||||
isActive?: boolean;
|
isActive?: boolean;
|
||||||
}
|
}
|
||||||
interface ProcessContainerProps {
|
interface ProcessContainerProps {
|
||||||
|
@ -39,7 +43,7 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
agvRef,
|
agvRef,
|
||||||
MaterialRef,
|
MaterialRef,
|
||||||
armBots,
|
armBots,
|
||||||
setArmBots
|
setArmBots,
|
||||||
}) => {
|
}) => {
|
||||||
const gltf = useLoader(GLTFLoader, crate) as GLTF;
|
const gltf = useLoader(GLTFLoader, crate) as GLTF;
|
||||||
const groupRef = useRef<THREE.Group>(null);
|
const groupRef = useRef<THREE.Group>(null);
|
||||||
|
@ -114,7 +118,6 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
|
|
||||||
// In processAnimator.tsx - only the relevant spawn logic part that needs fixes
|
// In processAnimator.tsx - only the relevant spawn logic part that needs fixes
|
||||||
|
|
||||||
|
|
||||||
// Add this function to ProcessAnimator component
|
// Add this function to ProcessAnimator component
|
||||||
const isConnectedToActiveArmBot = useCallback(
|
const isConnectedToActiveArmBot = useCallback(
|
||||||
(processId: any) => {
|
(processId: any) => {
|
||||||
|
@ -123,7 +126,7 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
if (!armbot.isActive) return false;
|
if (!armbot.isActive) return false;
|
||||||
|
|
||||||
// Check if this armbot is connected to the process
|
// Check if this armbot is connected to the process
|
||||||
return armbot.connections?.targets?.some((connection: any) => {
|
return armbot.connections?.targets?.some((connection) => {
|
||||||
// Find the process that owns this modelUUID
|
// Find the process that owns this modelUUID
|
||||||
const connectedProcess = processes.find((p) =>
|
const connectedProcess = processes.find((p) =>
|
||||||
p.paths?.some((path) => path.modeluuid === connection.modelUUID)
|
p.paths?.some((path) => path.modeluuid === connection.modelUUID)
|
||||||
|
@ -135,8 +138,7 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
[armBots, processes]
|
[armBots, processes]
|
||||||
);
|
);
|
||||||
|
|
||||||
// In processAnimator.tsx - only the relevant spawn logic part that needs fixes
|
// First useFrame for spawn logic
|
||||||
|
|
||||||
useFrame(() => {
|
useFrame(() => {
|
||||||
// Spawn logic frame
|
// Spawn logic frame
|
||||||
const currentTime =
|
const currentTime =
|
||||||
|
@ -149,12 +151,15 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
const processState = newStates[process.id];
|
const processState = newStates[process.id];
|
||||||
if (!processState) return;
|
if (!processState) return;
|
||||||
|
|
||||||
|
// Check connection status
|
||||||
|
const isConnected = isConnectedToActiveArmBot(process.id);
|
||||||
|
|
||||||
if (processState.isProcessDelaying) {
|
if (processState.isProcessDelaying) {
|
||||||
// Existing delay handling logic...
|
// Existing delay handling logic...
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isConnectedToActiveArmBot(process.id)) {
|
if (isConnected) {
|
||||||
newStates[process.id] = {
|
newStates[process.id] = {
|
||||||
...processState,
|
...processState,
|
||||||
nextSpawnTime: Infinity, // Prevent future spawns
|
nextSpawnTime: Infinity, // Prevent future spawns
|
||||||
|
@ -163,17 +168,24 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
}
|
}
|
||||||
|
|
||||||
const spawnPoint = findSpawnPoint(process);
|
const spawnPoint = findSpawnPoint(process);
|
||||||
if (!spawnPoint || !spawnPoint.actions) return;
|
if (!spawnPoint || !spawnPoint.actions) {
|
||||||
|
console.log(
|
||||||
|
`Process ${process.id} has no valid spawn point or actions`
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const spawnAction = spawnPoint.actions.find(
|
const spawnAction = spawnPoint.actions.find(
|
||||||
(a) => a.isUsed && a.type === "Spawn"
|
(a) => a.isUsed && a.type === "Spawn"
|
||||||
);
|
);
|
||||||
if (!spawnAction) return;
|
if (!spawnAction) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const spawnInterval =
|
const spawnInterval =
|
||||||
typeof spawnAction.spawnInterval === "number"
|
typeof spawnAction.spawnInterval === "number"
|
||||||
? spawnAction.spawnInterval
|
? spawnAction.spawnInterval
|
||||||
: parseFloat(spawnAction.spawnInterval as string) || 0;
|
: parseFloat(spawnAction.spawnInterval || "0") || 0;
|
||||||
|
|
||||||
// Check if this is a zero interval spawn and we already spawned an object
|
// Check if this is a zero interval spawn and we already spawned an object
|
||||||
if (
|
if (
|
||||||
|
@ -195,6 +207,15 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
baseMaterials
|
baseMaterials
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Initialize state properly to ensure animation
|
||||||
|
newObject.state = {
|
||||||
|
...newObject.state,
|
||||||
|
isAnimating: true,
|
||||||
|
isDelaying: false,
|
||||||
|
delayComplete: false,
|
||||||
|
progress: 0.005, // Start with tiny progress to ensure animation begins
|
||||||
|
};
|
||||||
|
|
||||||
// Update state with the new object and flag for zero interval
|
// Update state with the new object and flag for zero interval
|
||||||
newStates[process.id] = {
|
newStates[process.id] = {
|
||||||
...processState,
|
...processState,
|
||||||
|
@ -217,6 +238,7 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Second useFrame for animation logic
|
||||||
useFrame((_, delta) => {
|
useFrame((_, delta) => {
|
||||||
// Animation logic frame
|
// Animation logic frame
|
||||||
const currentTime =
|
const currentTime =
|
||||||
|
@ -227,9 +249,19 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
|
|
||||||
processedProcesses.forEach((process) => {
|
processedProcesses.forEach((process) => {
|
||||||
const processState = newStates[process.id];
|
const processState = newStates[process.id];
|
||||||
if (!processState) return;
|
if (!processState) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (isConnectedToActiveArmBot(process.id)) {
|
// Check connection status with debugging
|
||||||
|
const isConnected = isConnectedToActiveArmBot(process.id);
|
||||||
|
console.log(
|
||||||
|
`Process ${process.id} animation - connected:`,
|
||||||
|
isConnected
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isConnected) {
|
||||||
|
// Stop all animations when connected to active arm bot
|
||||||
newStates[process.id] = {
|
newStates[process.id] = {
|
||||||
...processState,
|
...processState,
|
||||||
spawnedObjects: Object.entries(processState.spawnedObjects).reduce(
|
spawnedObjects: Object.entries(processState.spawnedObjects).reduce(
|
||||||
|
@ -252,6 +284,7 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Process delay handling
|
||||||
if (processState.isProcessDelaying) {
|
if (processState.isProcessDelaying) {
|
||||||
const effectiveDelayTime =
|
const effectiveDelayTime =
|
||||||
processState.processDelayDuration / speedRef.current;
|
processState.processDelayDuration / speedRef.current;
|
||||||
|
@ -260,6 +293,9 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
currentTime - processState.processDelayStartTime >=
|
currentTime - processState.processDelayStartTime >=
|
||||||
effectiveDelayTime
|
effectiveDelayTime
|
||||||
) {
|
) {
|
||||||
|
console.log(
|
||||||
|
`Process ${process.id} delay completed, resuming animation`
|
||||||
|
);
|
||||||
newStates[process.id] = {
|
newStates[process.id] = {
|
||||||
...processState,
|
...processState,
|
||||||
isProcessDelaying: false,
|
isProcessDelaying: false,
|
||||||
|
@ -283,26 +319,42 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
{}
|
{}
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
return newStates;
|
return;
|
||||||
} else {
|
} else {
|
||||||
return newStates;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure we have a valid path to follow
|
||||||
const path =
|
const path =
|
||||||
process.animationPath?.map((p) => new THREE.Vector3(p.x, p.y, p.z)) ||
|
process.animationPath?.map((p) => new THREE.Vector3(p.x, p.y, p.z)) ||
|
||||||
[];
|
[];
|
||||||
if (path.length < 2) return;
|
|
||||||
|
if (path.length < 2) {
|
||||||
|
console.log(
|
||||||
|
`Process ${process.id} has insufficient path points: ${path.length}`
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const updatedObjects = { ...processState.spawnedObjects };
|
const updatedObjects = { ...processState.spawnedObjects };
|
||||||
|
let animationOccurring = false; // Track if any animation is happening
|
||||||
|
|
||||||
Object.entries(processState.spawnedObjects).forEach(
|
Object.entries(processState.spawnedObjects).forEach(
|
||||||
([objectId, obj]) => {
|
([objectId, obj]) => {
|
||||||
if (!obj.visible) return;
|
if (!obj.visible) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const currentRef = gltf?.scene ? obj.ref.current : obj.ref.current;
|
const currentRef = gltf?.scene ? obj.ref.current : obj.ref.current;
|
||||||
if (!currentRef) return;
|
if (!currentRef) {
|
||||||
|
console.log(
|
||||||
|
`No reference for object ${objectId}, skipping animation`
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize position for new objects
|
||||||
if (
|
if (
|
||||||
obj.position &&
|
obj.position &&
|
||||||
obj.state.currentIndex === 0 &&
|
obj.state.currentIndex === 0 &&
|
||||||
|
@ -313,11 +365,22 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
|
|
||||||
const stateRef = obj.state;
|
const stateRef = obj.state;
|
||||||
|
|
||||||
|
// Ensure animation state is properly set for objects
|
||||||
|
if (!stateRef.isAnimating && !stateRef.isDelaying && !isConnected) {
|
||||||
|
stateRef.isAnimating = true;
|
||||||
|
stateRef.progress =
|
||||||
|
stateRef.progress > 0 ? stateRef.progress : 0.005;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle delay logic
|
||||||
if (stateRef.isDelaying) {
|
if (stateRef.isDelaying) {
|
||||||
const effectiveDelayTime =
|
const effectiveDelayTime =
|
||||||
stateRef.currentDelayDuration / speedRef.current;
|
stateRef.currentDelayDuration / speedRef.current;
|
||||||
|
|
||||||
if (currentTime - stateRef.delayStartTime >= effectiveDelayTime) {
|
if (currentTime - stateRef.delayStartTime >= effectiveDelayTime) {
|
||||||
|
console.log(
|
||||||
|
`Delay complete for object ${objectId}, resuming animation`
|
||||||
|
);
|
||||||
stateRef.isDelaying = false;
|
stateRef.isDelaying = false;
|
||||||
stateRef.delayComplete = true;
|
stateRef.delayComplete = true;
|
||||||
stateRef.isAnimating = true;
|
stateRef.isAnimating = true;
|
||||||
|
@ -343,8 +406,17 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!stateRef.isAnimating) return;
|
// Skip non-animating objects
|
||||||
|
if (!stateRef.isAnimating) {
|
||||||
|
console.log(
|
||||||
|
`Object ${objectId} not animating, skipping animation updates`
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
animationOccurring = true; // Mark that animation is happening
|
||||||
|
|
||||||
|
// Handle point actions
|
||||||
const currentPointData = getPointDataForAnimationIndex(
|
const currentPointData = getPointDataForAnimationIndex(
|
||||||
process,
|
process,
|
||||||
stateRef.currentIndex
|
stateRef.currentIndex
|
||||||
|
@ -369,42 +441,7 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
const nextPointIdx = stateRef.currentIndex + 1;
|
const nextPointIdx = stateRef.currentIndex + 1;
|
||||||
const isLastPoint = nextPointIdx >= path.length;
|
const isLastPoint = nextPointIdx >= path.length;
|
||||||
|
|
||||||
// if (isLastPoint) {
|
// Handle objects at the last point
|
||||||
// if (currentPointData?.actions) {
|
|
||||||
// const shouldStop = !hasNonInheritActions(
|
|
||||||
// currentPointData.actions
|
|
||||||
// );
|
|
||||||
// if (shouldStop) {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (isLastPoint) {
|
|
||||||
// if (currentPointData?.actions) {
|
|
||||||
// const hasNonInherit = hasNonInheritActions(
|
|
||||||
// currentPointData.actions
|
|
||||||
// );
|
|
||||||
// if (!hasNonInherit) {
|
|
||||||
// // Remove the object if all actions are inherit
|
|
||||||
// updatedObjects[objectId] = {
|
|
||||||
// ...obj,
|
|
||||||
// visible: false,
|
|
||||||
// state: { ...stateRef, isAnimating: false },
|
|
||||||
// };
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// // No actions at last point - remove the object
|
|
||||||
// updatedObjects[objectId] = {
|
|
||||||
// ...obj,
|
|
||||||
// visible: false,
|
|
||||||
// state: { ...stateRef, isAnimating: false },
|
|
||||||
// };
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (isLastPoint) {
|
if (isLastPoint) {
|
||||||
const isAgvPicking = agvRef.current.some(
|
const isAgvPicking = agvRef.current.some(
|
||||||
(agv: any) =>
|
(agv: any) =>
|
||||||
|
@ -417,6 +454,9 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
|
|
||||||
if (shouldHide) {
|
if (shouldHide) {
|
||||||
if (isAgvPicking) {
|
if (isAgvPicking) {
|
||||||
|
console.log(
|
||||||
|
`AGV picking at last point for object ${objectId}, hiding object`
|
||||||
|
);
|
||||||
updatedObjects[objectId] = {
|
updatedObjects[objectId] = {
|
||||||
...obj,
|
...obj,
|
||||||
visible: false,
|
visible: false,
|
||||||
|
@ -442,6 +482,7 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle stacked objects when AGV picks
|
||||||
if (tempStackedObjectsRef.current[objectId]) {
|
if (tempStackedObjectsRef.current[objectId]) {
|
||||||
const isAgvPicking = agvRef.current.some(
|
const isAgvPicking = agvRef.current.some(
|
||||||
(agv: any) =>
|
(agv: any) =>
|
||||||
|
@ -459,9 +500,12 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
isAnimating: false,
|
isAnimating: false,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle normal animation progress for objects not at last point
|
||||||
if (!isLastPoint) {
|
if (!isLastPoint) {
|
||||||
const nextPoint = path[nextPointIdx];
|
const nextPoint = path[nextPointIdx];
|
||||||
const distance =
|
const distance =
|
||||||
|
@ -469,13 +513,21 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
const effectiveSpeed = stateRef.speed * speedRef.current;
|
const effectiveSpeed = stateRef.speed * speedRef.current;
|
||||||
const movement = effectiveSpeed * delta;
|
const movement = effectiveSpeed * delta;
|
||||||
|
|
||||||
|
// Ensure progress is always moving forward
|
||||||
if (stateRef.delayComplete && stateRef.progress < 0.01) {
|
if (stateRef.delayComplete && stateRef.progress < 0.01) {
|
||||||
stateRef.progress = 0.05;
|
stateRef.progress = 0.05;
|
||||||
stateRef.delayComplete = false;
|
stateRef.delayComplete = false;
|
||||||
|
console.log(
|
||||||
|
`Boosting progress for object ${objectId} after delay`
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
stateRef.progress += movement / distance;
|
stateRef.progress += movement / distance;
|
||||||
|
console.log(
|
||||||
|
`Object ${objectId} progress: ${stateRef.progress.toFixed(3)}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle point transition
|
||||||
if (stateRef.progress >= 1) {
|
if (stateRef.progress >= 1) {
|
||||||
stateRef.currentIndex = nextPointIdx;
|
stateRef.currentIndex = nextPointIdx;
|
||||||
stateRef.progress = 0;
|
stateRef.progress = 0;
|
||||||
|
@ -494,7 +546,10 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
process,
|
process,
|
||||||
stateRef.currentIndex
|
stateRef.currentIndex
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// No action needed with newPointData here - will be handled in next frame
|
||||||
} else {
|
} else {
|
||||||
|
// Update position with lerp
|
||||||
currentRef.position.lerpVectors(
|
currentRef.position.lerpVectors(
|
||||||
path[stateRef.currentIndex],
|
path[stateRef.currentIndex],
|
||||||
nextPoint,
|
nextPoint,
|
||||||
|
@ -507,6 +562,13 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Log if no animation is occurring when it should
|
||||||
|
if (!animationOccurring && !isConnected) {
|
||||||
|
console.log(
|
||||||
|
`Warning: No animation occurring for process ${process.id} despite not being connected`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
newStates[process.id] = {
|
newStates[process.id] = {
|
||||||
...processState,
|
...processState,
|
||||||
spawnedObjects: updatedObjects,
|
spawnedObjects: updatedObjects,
|
||||||
|
@ -516,6 +578,7 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
return newStates;
|
return newStates;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!processedProcesses || processedProcesses.length === 0) {
|
if (!processedProcesses || processedProcesses.length === 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue