From c3b18aff78520d7347058c8fa1f5e6a073e88c1b Mon Sep 17 00:00:00 2001 From: Vishnu Date: Thu, 8 May 2025 19:46:54 +0530 Subject: [PATCH] Refactor MaterialAnimator and VehicleInstance: remove unused HTML position and rotation states, and update VehicleInstance prop type for clarity. --- .../instances/animator/materialAnimator.tsx | 14 -------------- .../instances/instance/vehicleInstance.tsx | 15 +++++++-------- 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/app/src/modules/simulation/vehicle/instances/animator/materialAnimator.tsx b/app/src/modules/simulation/vehicle/instances/animator/materialAnimator.tsx index 1fd3716..0f4af22 100644 --- a/app/src/modules/simulation/vehicle/instances/animator/materialAnimator.tsx +++ b/app/src/modules/simulation/vehicle/instances/animator/materialAnimator.tsx @@ -2,7 +2,6 @@ import { useEffect, useRef, useState } from 'react'; import { useThree, useFrame } from '@react-three/fiber'; import * as THREE from 'three'; import { MaterialModel } from '../../../materials/instances/material/materialModel'; -import { Html } from '@react-three/drei'; type MaterialAnimatorProps = { agvDetail: VehicleStatus; @@ -14,8 +13,6 @@ const MaterialAnimator = ({ agvDetail }: MaterialAnimatorProps) => { const [hasLoad, setHasLoad] = useState(false); const { scene } = useThree(); const offset = new THREE.Vector3(0, 0.85, 0); - const [htmlPosition, setHtmlPosition] = useState<[number, number, number]>([0, 0, 0]); - const [htmlRotation, setHtmlRotation] = useState<[number, number, number]>([0, 0, 0]); useEffect(() => { setHasLoad(agvDetail.currentLoad > 0); @@ -28,9 +25,7 @@ const MaterialAnimator = ({ agvDetail }: MaterialAnimatorProps) => { if (agvModel) { const worldPosition = offset.clone().applyMatrix4(agvModel.matrixWorld); meshRef.current.position.copy(worldPosition); - setHtmlPosition([worldPosition.x, worldPosition.y, worldPosition.z]); meshRef.current.rotation.copy(agvModel.rotation); - setHtmlRotation([agvModel.rotation.x, agvModel.rotation.y, agvModel.rotation.z]); } }); @@ -44,15 +39,6 @@ const MaterialAnimator = ({ agvDetail }: MaterialAnimatorProps) => { materialType={agvDetail.currentMaterials[0].materialType || 'Default material'} /> } - - - {agvDetail.currentLoad} - - )} diff --git a/app/src/modules/simulation/vehicle/instances/instance/vehicleInstance.tsx b/app/src/modules/simulation/vehicle/instances/instance/vehicleInstance.tsx index 2b15c26..a97730b 100644 --- a/app/src/modules/simulation/vehicle/instances/instance/vehicleInstance.tsx +++ b/app/src/modules/simulation/vehicle/instances/instance/vehicleInstance.tsx @@ -11,7 +11,7 @@ import { useSelectedProduct } from '../../../../../store/simulation/useSimulatio import { useTriggerHandler } from '../../../triggers/triggerHandler/useTriggerHandler'; import MaterialAnimator from '../animator/materialAnimator'; -function VehicleInstance({ agvDetail }: { agvDetail: VehicleStatus }) { +function VehicleInstance({ agvDetail }: Readonly<{ agvDetail: VehicleStatus }>) { const { navMesh } = useNavMesh(); const { isPlaying } = usePlayButtonStore(); const { removeMaterial } = useMaterialStore(); @@ -109,6 +109,7 @@ function VehicleInstance({ agvDetail }: { agvDetail: VehicleStatus }) { } else { reset() } + // eslint-disable-next-line react-hooks/exhaustive-deps }, [vehicles, currentPhase, path, isPlaying]); function handleCallBack() { @@ -146,14 +147,14 @@ function VehicleInstance({ agvDetail }: { agvDetail: VehicleStatus }) { handleMaterialDropToConveyor(action); } } else if (model.type === 'machine') { - + // } else if (model.type === 'roboticArm') { const action = getActionByUuid(selectedProduct.productId, agvDetail.point.action.actionUuid); if (action) { handleMaterialDropToArmBot(action); } } else if (model.type === 'storageUnit') { - + // } } else { const droppedMaterial = agvDetail.currentLoad; @@ -169,7 +170,7 @@ function VehicleInstance({ agvDetail }: { agvDetail: VehicleStatus }) { function handleMaterialDropToConveyor(action: Action) { if (agvDetail.currentLoad > 1) { - + // } else if (agvDetail.currentLoad === 1 && agvDetail.currentMaterials.length === 1) { triggerPointActions(action, agvDetail.currentMaterials[0].materialId); decrementVehicleLoad(agvDetail.modelUuid, 1); @@ -179,7 +180,7 @@ function VehicleInstance({ agvDetail }: { agvDetail: VehicleStatus }) { function handleMaterialDropToArmBot(action: Action) { if (agvDetail.currentLoad > 1) { - + // } else if (agvDetail.currentLoad === 1 && agvDetail.currentMaterials.length === 1) { triggerPointActions(action, agvDetail.currentMaterials[0].materialId); } @@ -187,9 +188,7 @@ function VehicleInstance({ agvDetail }: { agvDetail: VehicleStatus }) { function handleMaterialDropByDefault(droppedMaterial: number) { if (isPausedRef.current) { - if (!pauseTimeRef.current) { - pauseTimeRef.current = performance.now(); - } + pauseTimeRef.current ??= performance.now(); requestAnimationFrame(() => handleMaterialDropByDefault(droppedMaterial)); return; }