Merge remote-tracking branch 'origin/simulation-animation' into simulation
This commit is contained in:
commit
f7e4f5c580
|
@ -1,10 +1,4 @@
|
||||||
import React, {
|
import React, { useRef, useEffect, useMemo, useCallback } from "react";
|
||||||
useRef,
|
|
||||||
useEffect,
|
|
||||||
useMemo,
|
|
||||||
useCallback,
|
|
||||||
useState,
|
|
||||||
} from "react";
|
|
||||||
import { useLoader, useFrame } from "@react-three/fiber";
|
import { useLoader, useFrame } from "@react-three/fiber";
|
||||||
import { GLTFLoader } from "three-stdlib";
|
import { GLTFLoader } from "three-stdlib";
|
||||||
import * as THREE from "three";
|
import * as THREE from "three";
|
||||||
|
@ -54,8 +48,6 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
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);
|
||||||
const tempStackedObjectsRef = useRef<Record<string, boolean>>({});
|
const tempStackedObjectsRef = useRef<Record<string, boolean>>({});
|
||||||
const [previouslyConnected, setPreviouslyConnected] = useState<any>({});
|
|
||||||
const currentSpawnedObjectRef = useRef<any>(null);
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
animationStates,
|
animationStates,
|
||||||
|
@ -124,6 +116,8 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
});
|
});
|
||||||
}, [animationStates, MaterialRef, agvRef]);
|
}, [animationStates, MaterialRef, agvRef]);
|
||||||
|
|
||||||
|
// 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) => {
|
||||||
|
@ -159,26 +153,6 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
|
|
||||||
// Check connection status
|
// Check connection status
|
||||||
const isConnected = isConnectedToActiveArmBot(process.id);
|
const isConnected = isConnectedToActiveArmBot(process.id);
|
||||||
const wasConnected = previouslyConnected[process.id] || false;
|
|
||||||
|
|
||||||
// Track connection state changes
|
|
||||||
if (wasConnected !== isConnected) {
|
|
||||||
setTimeout(() => {
|
|
||||||
setPreviouslyConnected((prev: any) => ({
|
|
||||||
...prev,
|
|
||||||
[process.id]: isConnected,
|
|
||||||
}));
|
|
||||||
}, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If just disconnected, reset the spawn timer to allow new spawns
|
|
||||||
if (wasConnected && !isConnected) {
|
|
||||||
newStates[process.id] = {
|
|
||||||
...processState,
|
|
||||||
nextSpawnTime: currentTime + 0.1,
|
|
||||||
hasSpawnedZeroIntervalObject: false,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (processState.isProcessDelaying) {
|
if (processState.isProcessDelaying) {
|
||||||
// Existing delay handling logic...
|
// Existing delay handling logic...
|
||||||
|
@ -195,6 +169,9 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
|
|
||||||
const spawnPoint = findSpawnPoint(process);
|
const spawnPoint = findSpawnPoint(process);
|
||||||
if (!spawnPoint || !spawnPoint.actions) {
|
if (!spawnPoint || !spawnPoint.actions) {
|
||||||
|
console.log(
|
||||||
|
`Process ${process.id} has no valid spawn point or actions`
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,10 +195,7 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
return; // Don't spawn more objects for zero interval
|
return; // Don't spawn more objects for zero interval
|
||||||
}
|
}
|
||||||
|
|
||||||
const effectiveSpawnInterval = Math.max(
|
const effectiveSpawnInterval = spawnInterval / speedRef.current;
|
||||||
0.1,
|
|
||||||
spawnInterval / speedRef.current
|
|
||||||
);
|
|
||||||
|
|
||||||
if (currentTime >= processState.nextSpawnTime) {
|
if (currentTime >= processState.nextSpawnTime) {
|
||||||
const objectId = `obj-${process.id}-${processState.objectIdCounter}`;
|
const objectId = `obj-${process.id}-${processState.objectIdCounter}`;
|
||||||
|
@ -242,9 +216,6 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
progress: 0.005, // Start with tiny progress to ensure animation begins
|
progress: 0.005, // Start with tiny progress to ensure animation begins
|
||||||
};
|
};
|
||||||
|
|
||||||
// Calculate next spawn time
|
|
||||||
const nextSpawnAt = currentTime + effectiveSpawnInterval;
|
|
||||||
|
|
||||||
// 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,
|
||||||
|
@ -253,7 +224,7 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
[objectId]: newObject,
|
[objectId]: newObject,
|
||||||
},
|
},
|
||||||
objectIdCounter: processState.objectIdCounter + 1,
|
objectIdCounter: processState.objectIdCounter + 1,
|
||||||
nextSpawnTime: nextSpawnAt,
|
nextSpawnTime: currentTime + effectiveSpawnInterval,
|
||||||
// Mark that we've spawned an object for zero interval case
|
// Mark that we've spawned an object for zero interval case
|
||||||
hasSpawnedZeroIntervalObject:
|
hasSpawnedZeroIntervalObject:
|
||||||
spawnInterval === 0
|
spawnInterval === 0
|
||||||
|
@ -269,8 +240,6 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
|
|
||||||
// Second useFrame for animation logic
|
// Second useFrame for animation logic
|
||||||
useFrame((_, delta) => {
|
useFrame((_, delta) => {
|
||||||
let currentProcessObject: any = null;
|
|
||||||
|
|
||||||
// Animation logic frame
|
// Animation logic frame
|
||||||
const currentTime =
|
const currentTime =
|
||||||
clockRef.current.getElapsedTime() - elapsedBeforePauseRef.current;
|
clockRef.current.getElapsedTime() - elapsedBeforePauseRef.current;
|
||||||
|
@ -284,8 +253,12 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check connection status
|
// Check connection status with debugging
|
||||||
const isConnected = isConnectedToActiveArmBot(process.id);
|
const isConnected = isConnectedToActiveArmBot(process.id);
|
||||||
|
console.log(
|
||||||
|
`Process ${process.id} animation - connected:`,
|
||||||
|
isConnected
|
||||||
|
);
|
||||||
|
|
||||||
if (isConnected) {
|
if (isConnected) {
|
||||||
// Stop all animations when connected to active arm bot
|
// Stop all animations when connected to active arm bot
|
||||||
|
@ -297,7 +270,6 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
[id]: {
|
[id]: {
|
||||||
...obj,
|
...obj,
|
||||||
state: {
|
state: {
|
||||||
visible: true,
|
|
||||||
...obj.state,
|
...obj.state,
|
||||||
isAnimating: false, // Stop animation
|
isAnimating: false, // Stop animation
|
||||||
isDelaying: false, // Clear delays
|
isDelaying: false, // Clear delays
|
||||||
|
@ -321,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,
|
||||||
|
@ -356,6 +331,9 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
[];
|
[];
|
||||||
|
|
||||||
if (path.length < 2) {
|
if (path.length < 2) {
|
||||||
|
console.log(
|
||||||
|
`Process ${process.id} has insufficient path points: ${path.length}`
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -370,6 +348,9 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
|
|
||||||
const currentRef = gltf?.scene ? obj.ref.current : obj.ref.current;
|
const currentRef = gltf?.scene ? obj.ref.current : obj.ref.current;
|
||||||
if (!currentRef) {
|
if (!currentRef) {
|
||||||
|
console.log(
|
||||||
|
`No reference for object ${objectId}, skipping animation`
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,6 +378,9 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
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;
|
||||||
|
@ -424,6 +408,9 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
|
|
||||||
// Skip non-animating objects
|
// Skip non-animating objects
|
||||||
if (!stateRef.isAnimating) {
|
if (!stateRef.isAnimating) {
|
||||||
|
console.log(
|
||||||
|
`Object ${objectId} not animating, skipping animation updates`
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -467,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,
|
||||||
|
@ -527,8 +517,14 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
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
|
// Handle point transition
|
||||||
|
@ -546,8 +542,12 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
||||||
currentTime
|
currentTime
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const newPointData = getPointDataForAnimationIndex(
|
||||||
|
process,
|
||||||
|
stateRef.currentIndex
|
||||||
|
);
|
||||||
|
|
||||||
// No action needed with newPointData here - will be handled in next frame
|
// No action needed with newPointData here - will be handled in next frame
|
||||||
getPointDataForAnimationIndex(process, stateRef.currentIndex);
|
|
||||||
} else {
|
} else {
|
||||||
// Update position with lerp
|
// Update position with lerp
|
||||||
currentRef.position.lerpVectors(
|
currentRef.position.lerpVectors(
|
||||||
|
|
Loading…
Reference in New Issue