From 12b12d9eb0317377fdab55fc182ea447b848c4dc Mon Sep 17 00:00:00 2001 From: Jerald-Golden-B Date: Thu, 8 May 2025 15:20:37 +0530 Subject: [PATCH] Refactor VehicleAnimator and VehicleInstance: remove unused material handling logic and clean up code for improved readability. --- .../instances/animator/vehicleAnimator.tsx | 17 +++-------------- .../instances/instance/vehicleInstance.tsx | 10 +--------- 2 files changed, 4 insertions(+), 23 deletions(-) diff --git a/app/src/modules/simulation/vehicle/instances/animator/vehicleAnimator.tsx b/app/src/modules/simulation/vehicle/instances/animator/vehicleAnimator.tsx index f67e22c..ba16302 100644 --- a/app/src/modules/simulation/vehicle/instances/animator/vehicleAnimator.tsx +++ b/app/src/modules/simulation/vehicle/instances/animator/vehicleAnimator.tsx @@ -4,7 +4,6 @@ import * as THREE from 'three'; import { Line } from '@react-three/drei'; import { useAnimationPlaySpeed, usePauseButtonStore, usePlayButtonStore, useResetButtonStore } from '../../../../../store/usePlayButtonStore'; import { useVehicleStore } from '../../../../../store/simulation/useVehicleStore'; -import { useMaterialStore } from '../../../../../store/simulation/useMaterialStore'; interface VehicleAnimatorProps { path: [number, number, number][]; @@ -17,8 +16,7 @@ interface VehicleAnimatorProps { } function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetail, reset, startUnloadingProcess }: VehicleAnimatorProps) { - const { decrementVehicleLoad, getVehicleById, removeLastMaterial } = useVehicleStore(); - const { removeMaterial } = useMaterialStore(); + const { getVehicleById } = useVehicleStore(); const { isPaused } = usePauseButtonStore(); const { isPlaying } = usePlayButtonStore(); const { speed } = useAnimationPlaySpeed(); @@ -27,11 +25,9 @@ function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetai const movingForward = useRef(true); const completedRef = useRef(false); const [objectRotation, setObjectRotation] = useState<{ x: number; y: number; z: number } | undefined>(agvDetail.point?.action?.pickUpPoint?.rotation || { x: 0, y: 0, z: 0 }) - const [progress, setProgress] = useState(0); const [restRotation, setRestingRotation] = useState(true); const [currentPath, setCurrentPath] = useState<[number, number, number][]>([]); const { scene } = useThree(); - let coveredDistance = progressRef.current; useEffect(() => { if (currentPhase === 'stationed-pickup' && path.length > 0) { @@ -47,7 +43,6 @@ function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetai }, [currentPhase, path, objectRotation]); useEffect(() => { - setProgress(0); completedRef.current = false; }, [currentPath]); @@ -55,11 +50,9 @@ function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetai if (isReset || !isPlaying) { reset(); setCurrentPath([]); - setProgress(0); completedRef.current = false; movingForward.current = true; progressRef.current = 0; - coveredDistance = 0; setReset(false); setRestingRotation(true); const object = scene.getObjectByProperty('uuid', agvUuid); @@ -89,7 +82,7 @@ function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetai totalDistance += segmentDistance; } - while (index < distances.length && coveredDistance > accumulatedDistance + distances[index]) { + while (index < distances.length && progressRef.current > accumulatedDistance + distances[index]) { accumulatedDistance += distances[index]; index++; } @@ -115,14 +108,12 @@ function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetai if (isAligned) { progressRef.current += delta * (speed * agvDetail.speed); - coveredDistance = progressRef.current; - const t = (coveredDistance - accumulatedDistance) / segmentDistance; + const t = (progressRef.current - accumulatedDistance) / segmentDistance; const position = start.clone().lerp(end, t); object.position.copy(position); } } - if (progressRef.current >= totalDistance) { if (restRotation && objectRotation) { const targetEuler = new THREE.Euler( @@ -152,8 +143,6 @@ function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetai } }); - - return ( <> {currentPath.length > 0 && ( diff --git a/app/src/modules/simulation/vehicle/instances/instance/vehicleInstance.tsx b/app/src/modules/simulation/vehicle/instances/instance/vehicleInstance.tsx index 28ed64b..1ef79e0 100644 --- a/app/src/modules/simulation/vehicle/instances/instance/vehicleInstance.tsx +++ b/app/src/modules/simulation/vehicle/instances/instance/vehicleInstance.tsx @@ -5,8 +5,8 @@ import { NavMeshQuery } from '@recast-navigation/core'; import { useNavMesh } from '../../../../../store/store'; import { useAnimationPlaySpeed, usePauseButtonStore, usePlayButtonStore } from '../../../../../store/usePlayButtonStore'; import { useVehicleStore } from '../../../../../store/simulation/useVehicleStore'; -import MaterialAnimator from '../animator/materialAnimator'; import { useMaterialStore } from '../../../../../store/simulation/useMaterialStore'; +import MaterialAnimator from '../animator/materialAnimator'; function VehicleInstance({ agvDetail }: { agvDetail: VehicleStatus }) { const { navMesh } = useNavMesh(); @@ -22,7 +22,6 @@ function VehicleInstance({ agvDetail }: { agvDetail: VehicleStatus }) { const { speed } = useAnimationPlaySpeed(); const { isPaused } = usePauseButtonStore(); - useEffect(() => { isPausedRef.current = isPaused; }, [isPaused]); @@ -44,7 +43,6 @@ function VehicleInstance({ agvDetail }: { agvDetail: VehicleStatus }) { function vehicleStatus(modelId: string, status: string) { // console.log(`${modelId} , ${status}`); - } // Function to reset everything @@ -75,11 +73,6 @@ function VehicleInstance({ agvDetail }: { agvDetail: VehicleStatus }) { vehicleStatus(agvDetail.modelUuid, 'Started from station, heading to pickup'); return; } else if (!agvDetail.isActive && agvDetail.state === 'idle' && currentPhase === 'picking') { - - // setTimeout(() => { - // increment(); - // }, 5000); - if (agvDetail.currentLoad === agvDetail.point.action.loadCapacity && agvDetail.currentMaterials.length > 0) { if (agvDetail.point.action.pickUpPoint && agvDetail.point.action.unLoadPoint) { const toDrop = computePath( @@ -177,7 +170,6 @@ function VehicleInstance({ agvDetail }: { agvDetail: VehicleStatus }) { } } - return ( <>