From 496c8b0305fa7345aae514fd06d1d5f4d23ec5f7 Mon Sep 17 00:00:00 2001 From: SreeNath14 <153710861+SreeNath14@users.noreply.github.com> Date: Wed, 16 Apr 2025 16:08:47 +0530 Subject: [PATCH 1/2] new comit --- .../simulation/process/processAnimator.tsx | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/app/src/modules/simulation/process/processAnimator.tsx b/app/src/modules/simulation/process/processAnimator.tsx index 981846b..408cd37 100644 --- a/app/src/modules/simulation/process/processAnimator.tsx +++ b/app/src/modules/simulation/process/processAnimator.tsx @@ -55,7 +55,6 @@ const ProcessAnimator: React.FC = ({ const groupRef = useRef(null); const tempStackedObjectsRef = useRef>({}); const [previouslyConnected, setPreviouslyConnected] = useState({}); - const currentSpawnedObjectRef = useRef(null); const { animationStates, @@ -124,6 +123,8 @@ const ProcessAnimator: React.FC = ({ }); }, [animationStates, MaterialRef, agvRef]); + // In processAnimator.tsx - only the relevant spawn logic part that needs fixes + // Add this function to ProcessAnimator component const isConnectedToActiveArmBot = useCallback( (processId: any) => { @@ -163,6 +164,8 @@ const ProcessAnimator: React.FC = ({ // Track connection state changes if (wasConnected !== isConnected) { + + // Update connection tracking (in a separate useEffect to avoid issues with setState in render) setTimeout(() => { setPreviouslyConnected((prev: any) => ({ ...prev, @@ -173,10 +176,11 @@ const ProcessAnimator: React.FC = ({ // If just disconnected, reset the spawn timer to allow new spawns if (wasConnected && !isConnected) { + newStates[process.id] = { ...processState, - nextSpawnTime: currentTime + 0.1, - hasSpawnedZeroIntervalObject: false, + nextSpawnTime: currentTime + 0.1, // Start spawning soon after disconnect + hasSpawnedZeroIntervalObject: false, // Reset for zero interval spawns }; } @@ -195,6 +199,7 @@ const ProcessAnimator: React.FC = ({ const spawnPoint = findSpawnPoint(process); if (!spawnPoint || !spawnPoint.actions) { + return; } @@ -210,6 +215,8 @@ const ProcessAnimator: React.FC = ({ ? spawnAction.spawnInterval : parseFloat(spawnAction.spawnInterval || "0") || 0; + + // Check if this is a zero interval spawn and we already spawned an object if ( spawnInterval === 0 && @@ -224,6 +231,7 @@ const ProcessAnimator: React.FC = ({ ); if (currentTime >= processState.nextSpawnTime) { + const objectId = `obj-${process.id}-${processState.objectIdCounter}`; const newObject = createSpawnedObject( process, @@ -269,8 +277,6 @@ const ProcessAnimator: React.FC = ({ // Second useFrame for animation logic useFrame((_, delta) => { - let currentProcessObject: any = null; - // Animation logic frame const currentTime = clockRef.current.getElapsedTime() - elapsedBeforePauseRef.current; @@ -297,7 +303,6 @@ const ProcessAnimator: React.FC = ({ [id]: { ...obj, state: { - visible: true, ...obj.state, isAnimating: false, // Stop animation isDelaying: false, // Clear delays @@ -321,6 +326,7 @@ const ProcessAnimator: React.FC = ({ currentTime - processState.processDelayStartTime >= effectiveDelayTime ) { + newStates[process.id] = { ...processState, isProcessDelaying: false, @@ -356,6 +362,7 @@ const ProcessAnimator: React.FC = ({ []; if (path.length < 2) { + return; } @@ -370,6 +377,7 @@ const ProcessAnimator: React.FC = ({ const currentRef = gltf?.scene ? obj.ref.current : obj.ref.current; if (!currentRef) { + return; } @@ -397,6 +405,7 @@ const ProcessAnimator: React.FC = ({ stateRef.currentDelayDuration / speedRef.current; if (currentTime - stateRef.delayStartTime >= effectiveDelayTime) { + stateRef.isDelaying = false; stateRef.delayComplete = true; stateRef.isAnimating = true; @@ -564,9 +573,7 @@ const ProcessAnimator: React.FC = ({ // 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] = { From 9b9164c6005faf28f62cb8bacf89ff296f951304 Mon Sep 17 00:00:00 2001 From: SreeNath14 <153710861+SreeNath14@users.noreply.github.com> Date: Wed, 16 Apr 2025 16:25:02 +0530 Subject: [PATCH 2/2] minor changes in conveyor box spawn --- .../simulation/process/processAnimator.tsx | 93 +++++++++---------- 1 file changed, 43 insertions(+), 50 deletions(-) diff --git a/app/src/modules/simulation/process/processAnimator.tsx b/app/src/modules/simulation/process/processAnimator.tsx index 408cd37..f6cda0b 100644 --- a/app/src/modules/simulation/process/processAnimator.tsx +++ b/app/src/modules/simulation/process/processAnimator.tsx @@ -1,10 +1,4 @@ -import React, { - useRef, - useEffect, - useMemo, - useCallback, - useState, -} from "react"; +import React, { useRef, useEffect, useMemo, useCallback } from "react"; import { useLoader, useFrame } from "@react-three/fiber"; import { GLTFLoader } from "three-stdlib"; import * as THREE from "three"; @@ -54,7 +48,6 @@ const ProcessAnimator: React.FC = ({ const gltf = useLoader(GLTFLoader, crate) as GLTF; const groupRef = useRef(null); const tempStackedObjectsRef = useRef>({}); - const [previouslyConnected, setPreviouslyConnected] = useState({}); const { animationStates, @@ -160,29 +153,6 @@ const ProcessAnimator: React.FC = ({ // Check connection status const isConnected = isConnectedToActiveArmBot(process.id); - const wasConnected = previouslyConnected[process.id] || false; - - // Track connection state changes - if (wasConnected !== isConnected) { - - // Update connection tracking (in a separate useEffect to avoid issues with setState in render) - 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, // Start spawning soon after disconnect - hasSpawnedZeroIntervalObject: false, // Reset for zero interval spawns - }; - } if (processState.isProcessDelaying) { // Existing delay handling logic... @@ -199,7 +169,9 @@ const ProcessAnimator: React.FC = ({ const spawnPoint = findSpawnPoint(process); if (!spawnPoint || !spawnPoint.actions) { - + console.log( + `Process ${process.id} has no valid spawn point or actions` + ); return; } @@ -215,8 +187,6 @@ const ProcessAnimator: React.FC = ({ ? spawnAction.spawnInterval : parseFloat(spawnAction.spawnInterval || "0") || 0; - - // Check if this is a zero interval spawn and we already spawned an object if ( spawnInterval === 0 && @@ -225,13 +195,9 @@ const ProcessAnimator: React.FC = ({ return; // Don't spawn more objects for zero interval } - const effectiveSpawnInterval = Math.max( - 0.1, - spawnInterval / speedRef.current - ); + const effectiveSpawnInterval = spawnInterval / speedRef.current; if (currentTime >= processState.nextSpawnTime) { - const objectId = `obj-${process.id}-${processState.objectIdCounter}`; const newObject = createSpawnedObject( process, @@ -250,9 +216,6 @@ const ProcessAnimator: React.FC = ({ 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 newStates[process.id] = { ...processState, @@ -261,7 +224,7 @@ const ProcessAnimator: React.FC = ({ [objectId]: newObject, }, objectIdCounter: processState.objectIdCounter + 1, - nextSpawnTime: nextSpawnAt, + nextSpawnTime: currentTime + effectiveSpawnInterval, // Mark that we've spawned an object for zero interval case hasSpawnedZeroIntervalObject: spawnInterval === 0 @@ -290,8 +253,12 @@ const ProcessAnimator: React.FC = ({ return; } - // Check connection status + // 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 @@ -326,7 +293,9 @@ const ProcessAnimator: React.FC = ({ currentTime - processState.processDelayStartTime >= effectiveDelayTime ) { - + console.log( + `Process ${process.id} delay completed, resuming animation` + ); newStates[process.id] = { ...processState, isProcessDelaying: false, @@ -362,7 +331,9 @@ const ProcessAnimator: React.FC = ({ []; if (path.length < 2) { - + console.log( + `Process ${process.id} has insufficient path points: ${path.length}` + ); return; } @@ -377,7 +348,9 @@ const ProcessAnimator: React.FC = ({ const currentRef = gltf?.scene ? obj.ref.current : obj.ref.current; if (!currentRef) { - + console.log( + `No reference for object ${objectId}, skipping animation` + ); return; } @@ -405,7 +378,9 @@ const ProcessAnimator: React.FC = ({ stateRef.currentDelayDuration / speedRef.current; if (currentTime - stateRef.delayStartTime >= effectiveDelayTime) { - + console.log( + `Delay complete for object ${objectId}, resuming animation` + ); stateRef.isDelaying = false; stateRef.delayComplete = true; stateRef.isAnimating = true; @@ -433,6 +408,9 @@ const ProcessAnimator: React.FC = ({ // Skip non-animating objects if (!stateRef.isAnimating) { + console.log( + `Object ${objectId} not animating, skipping animation updates` + ); return; } @@ -476,6 +454,9 @@ const ProcessAnimator: React.FC = ({ if (shouldHide) { if (isAgvPicking) { + console.log( + `AGV picking at last point for object ${objectId}, hiding object` + ); updatedObjects[objectId] = { ...obj, visible: false, @@ -536,8 +517,14 @@ const ProcessAnimator: React.FC = ({ if (stateRef.delayComplete && stateRef.progress < 0.01) { stateRef.progress = 0.05; stateRef.delayComplete = false; + console.log( + `Boosting progress for object ${objectId} after delay` + ); } else { stateRef.progress += movement / distance; + console.log( + `Object ${objectId} progress: ${stateRef.progress.toFixed(3)}` + ); } // Handle point transition @@ -555,8 +542,12 @@ const ProcessAnimator: React.FC = ({ currentTime ); + const newPointData = getPointDataForAnimationIndex( + process, + stateRef.currentIndex + ); + // No action needed with newPointData here - will be handled in next frame - getPointDataForAnimationIndex(process, stateRef.currentIndex); } else { // Update position with lerp currentRef.position.lerpVectors( @@ -573,7 +564,9 @@ const ProcessAnimator: React.FC = ({ // 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] = {