Refactor VehicleAnimator and VehicleInstance: remove unused material handling logic and clean up code for improved readability.
This commit is contained in:
parent
bf48793db6
commit
12b12d9eb0
|
@ -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<boolean>(true);
|
||||
const completedRef = useRef<boolean>(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<number>(0);
|
||||
const [restRotation, setRestingRotation] = useState<boolean>(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 && (
|
||||
|
|
|
@ -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 (
|
||||
<>
|
||||
<VehicleAnimator
|
||||
|
|
Loading…
Reference in New Issue