new comit

This commit is contained in:
SreeNath14 2025-04-16 16:08:47 +05:30
parent 0eedbdd58e
commit 496c8b0305
1 changed files with 16 additions and 9 deletions

View File

@ -55,7 +55,6 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
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 [previouslyConnected, setPreviouslyConnected] = useState<any>({});
const currentSpawnedObjectRef = useRef<any>(null);
const { const {
animationStates, animationStates,
@ -124,6 +123,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) => {
@ -163,6 +164,8 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
// Track connection state changes // Track connection state changes
if (wasConnected !== isConnected) { if (wasConnected !== isConnected) {
// Update connection tracking (in a separate useEffect to avoid issues with setState in render)
setTimeout(() => { setTimeout(() => {
setPreviouslyConnected((prev: any) => ({ setPreviouslyConnected((prev: any) => ({
...prev, ...prev,
@ -173,10 +176,11 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
// If just disconnected, reset the spawn timer to allow new spawns // If just disconnected, reset the spawn timer to allow new spawns
if (wasConnected && !isConnected) { if (wasConnected && !isConnected) {
newStates[process.id] = { newStates[process.id] = {
...processState, ...processState,
nextSpawnTime: currentTime + 0.1, nextSpawnTime: currentTime + 0.1, // Start spawning soon after disconnect
hasSpawnedZeroIntervalObject: false, hasSpawnedZeroIntervalObject: false, // Reset for zero interval spawns
}; };
} }
@ -195,6 +199,7 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
const spawnPoint = findSpawnPoint(process); const spawnPoint = findSpawnPoint(process);
if (!spawnPoint || !spawnPoint.actions) { if (!spawnPoint || !spawnPoint.actions) {
return; return;
} }
@ -210,6 +215,8 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
? spawnAction.spawnInterval ? spawnAction.spawnInterval
: parseFloat(spawnAction.spawnInterval || "0") || 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 (
spawnInterval === 0 && spawnInterval === 0 &&
@ -224,6 +231,7 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
); );
if (currentTime >= processState.nextSpawnTime) { if (currentTime >= processState.nextSpawnTime) {
const objectId = `obj-${process.id}-${processState.objectIdCounter}`; const objectId = `obj-${process.id}-${processState.objectIdCounter}`;
const newObject = createSpawnedObject( const newObject = createSpawnedObject(
process, process,
@ -269,8 +277,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;
@ -297,7 +303,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 +326,7 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
currentTime - processState.processDelayStartTime >= currentTime - processState.processDelayStartTime >=
effectiveDelayTime effectiveDelayTime
) { ) {
newStates[process.id] = { newStates[process.id] = {
...processState, ...processState,
isProcessDelaying: false, isProcessDelaying: false,
@ -356,6 +362,7 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
[]; [];
if (path.length < 2) { if (path.length < 2) {
return; return;
} }
@ -370,6 +377,7 @@ 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) {
return; return;
} }
@ -397,6 +405,7 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
stateRef.currentDelayDuration / speedRef.current; stateRef.currentDelayDuration / speedRef.current;
if (currentTime - stateRef.delayStartTime >= effectiveDelayTime) { if (currentTime - stateRef.delayStartTime >= effectiveDelayTime) {
stateRef.isDelaying = false; stateRef.isDelaying = false;
stateRef.delayComplete = true; stateRef.delayComplete = true;
stateRef.isAnimating = true; stateRef.isAnimating = true;
@ -564,9 +573,7 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
// Log if no animation is occurring when it should // Log if no animation is occurring when it should
if (!animationOccurring && !isConnected) { if (!animationOccurring && !isConnected) {
console.log(
`Warning: No animation occurring for process ${process.id} despite not being connected`
);
} }
newStates[process.id] = { newStates[process.id] = {