2025-04-23 12:25:52 +05:30
|
|
|
import React, { useCallback, useEffect, useState } from 'react'
|
feat: Implement Zustand stores for machine, simulation, storage unit, vehicle, and visualization management
- Added `useMachineStore` for managing machine statuses, including actions for adding, removing, and updating machines.
- Introduced `useSimulationStore` to handle product and event management with actions for adding, removing, and updating products and events.
- Created `useStorageUnitStore` for managing storage unit statuses, including load tracking and state updates.
- Developed `useVehicleStore` for vehicle management, including load and state updates.
- Implemented `useChartStore` for managing measurement data and visualization settings.
- Added `useDroppedObjectsStore` for handling dropped objects in visualization zones, including object manipulation actions.
- Created `useZone3DWidgetStore` for managing 3D widget data in zones, including position and rotation updates.
- Introduced `useZoneStore` for managing selected zone states and widget configurations.
2025-04-22 14:28:29 +05:30
|
|
|
import VehicleAnimator from '../animator/vehicleAnimator'
|
2025-04-23 12:25:52 +05:30
|
|
|
import * as THREE from "three";
|
|
|
|
|
import { NavMeshQuery } from '@recast-navigation/core';
|
|
|
|
|
import { useNavMesh } from '../../../../../store/store';
|
|
|
|
|
import { usePlayButtonStore } from '../../../../../store/usePlayButtonStore';
|
|
|
|
|
import { useVehicleStore } from '../../../../../store/simulation/useVehicleStore';
|
feat: Implement Zustand stores for machine, simulation, storage unit, vehicle, and visualization management
- Added `useMachineStore` for managing machine statuses, including actions for adding, removing, and updating machines.
- Introduced `useSimulationStore` to handle product and event management with actions for adding, removing, and updating products and events.
- Created `useStorageUnitStore` for managing storage unit statuses, including load tracking and state updates.
- Developed `useVehicleStore` for vehicle management, including load and state updates.
- Implemented `useChartStore` for managing measurement data and visualization settings.
- Added `useDroppedObjectsStore` for handling dropped objects in visualization zones, including object manipulation actions.
- Created `useZone3DWidgetStore` for managing 3D widget data in zones, including position and rotation updates.
- Introduced `useZoneStore` for managing selected zone states and widget configurations.
2025-04-22 14:28:29 +05:30
|
|
|
|
2025-04-23 09:13:33 +05:30
|
|
|
function VehicleInstance({ agvDetails }: any) {
|
2025-04-23 12:25:52 +05:30
|
|
|
const { navMesh } = useNavMesh();
|
|
|
|
|
const { isPlaying } = usePlayButtonStore();
|
|
|
|
|
const { setVehicleActive, setVehicleState } = useVehicleStore();
|
|
|
|
|
const [currentPhase, setCurrentPhase] = useState<(string)>("stationed");
|
|
|
|
|
const [path, setPath] = useState<[number, number, number][]>([]);
|
feat: Implement Zustand stores for machine, simulation, storage unit, vehicle, and visualization management
- Added `useMachineStore` for managing machine statuses, including actions for adding, removing, and updating machines.
- Introduced `useSimulationStore` to handle product and event management with actions for adding, removing, and updating products and events.
- Created `useStorageUnitStore` for managing storage unit statuses, including load tracking and state updates.
- Developed `useVehicleStore` for vehicle management, including load and state updates.
- Implemented `useChartStore` for managing measurement data and visualization settings.
- Added `useDroppedObjectsStore` for handling dropped objects in visualization zones, including object manipulation actions.
- Created `useZone3DWidgetStore` for managing 3D widget data in zones, including position and rotation updates.
- Introduced `useZoneStore` for managing selected zone states and widget configurations.
2025-04-22 14:28:29 +05:30
|
|
|
|
2025-04-23 12:25:52 +05:30
|
|
|
const computePath = useCallback((start: any, end: any) => {
|
feat: Implement Zustand stores for machine, simulation, storage unit, vehicle, and visualization management
- Added `useMachineStore` for managing machine statuses, including actions for adding, removing, and updating machines.
- Introduced `useSimulationStore` to handle product and event management with actions for adding, removing, and updating products and events.
- Created `useStorageUnitStore` for managing storage unit statuses, including load tracking and state updates.
- Developed `useVehicleStore` for vehicle management, including load and state updates.
- Implemented `useChartStore` for managing measurement data and visualization settings.
- Added `useDroppedObjectsStore` for handling dropped objects in visualization zones, including object manipulation actions.
- Created `useZone3DWidgetStore` for managing 3D widget data in zones, including position and rotation updates.
- Introduced `useZoneStore` for managing selected zone states and widget configurations.
2025-04-22 14:28:29 +05:30
|
|
|
|
2025-04-23 12:25:52 +05:30
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const navMeshQuery = new NavMeshQuery(navMesh);
|
|
|
|
|
const { path: segmentPath } = navMeshQuery.computePath(start, end);
|
|
|
|
|
return (
|
|
|
|
|
segmentPath?.map(
|
|
|
|
|
({ x, y, z }) => [x, y + 0.1, z] as [number, number, number]
|
|
|
|
|
) || []
|
|
|
|
|
);
|
|
|
|
|
} catch {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
}, [navMesh]);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
// const pickupToDropPath = computePath(pickup, drop);
|
|
|
|
|
// const dropToPickupPath = computePath(drop, pickup);
|
|
|
|
|
|
|
|
|
|
if (isPlaying) {
|
|
|
|
|
if (!agvDetails.isActive && agvDetails.state == "idle" && currentPhase == "stationed") {
|
|
|
|
|
const toPickupPath = computePath(new THREE.Vector3(agvDetails.position[0], agvDetails.position[1], agvDetails.position[2]), agvDetails.point.action.pickUpPoint);
|
|
|
|
|
setPath(toPickupPath)
|
|
|
|
|
setVehicleActive(agvDetails.modelUuid, true)
|
|
|
|
|
setVehicleState(agvDetails.modelUuid, "running")
|
|
|
|
|
setCurrentPhase("stationed-pickup")
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, [agvDetails, currentPhase, path, isPlaying])
|
|
|
|
|
|
|
|
|
|
function handleCallBack() {
|
|
|
|
|
if (currentPhase === "stationed-pickup") {
|
|
|
|
|
setVehicleActive(agvDetails.modelUuid, false)
|
|
|
|
|
setVehicleState(agvDetails.modelUuid, "idle")
|
|
|
|
|
setCurrentPhase("picking")
|
|
|
|
|
setPath([])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
|
2025-04-23 12:31:37 +05:30
|
|
|
<VehicleAnimator path={path} handleCallBack={handleCallBack} currentPhase={currentPhase} agvUuid={agvDetails?.modelUuid} />
|
2025-04-23 12:25:52 +05:30
|
|
|
|
|
|
|
|
</>
|
|
|
|
|
)
|
feat: Implement Zustand stores for machine, simulation, storage unit, vehicle, and visualization management
- Added `useMachineStore` for managing machine statuses, including actions for adding, removing, and updating machines.
- Introduced `useSimulationStore` to handle product and event management with actions for adding, removing, and updating products and events.
- Created `useStorageUnitStore` for managing storage unit statuses, including load tracking and state updates.
- Developed `useVehicleStore` for vehicle management, including load and state updates.
- Implemented `useChartStore` for managing measurement data and visualization settings.
- Added `useDroppedObjectsStore` for handling dropped objects in visualization zones, including object manipulation actions.
- Created `useZone3DWidgetStore` for managing 3D widget data in zones, including position and rotation updates.
- Introduced `useZoneStore` for managing selected zone states and widget configurations.
2025-04-22 14:28:29 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default VehicleInstance
|