diff --git a/app/src/modules/simulation/vehicle/instances/instance/vehicleInstance.tsx b/app/src/modules/simulation/vehicle/instances/instance/vehicleInstance.tsx
index 6b6bd78..bf767ec 100644
--- a/app/src/modules/simulation/vehicle/instances/instance/vehicleInstance.tsx
+++ b/app/src/modules/simulation/vehicle/instances/instance/vehicleInstance.tsx
@@ -1,56 +1,66 @@
-import React, { useEffect } from 'react'
+import React, { useCallback, useEffect, useState } from 'react'
import VehicleAnimator from '../animator/vehicleAnimator'
+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';
-function VehicleInstance() {
+function VehicleInstance({ agvDetails }: any) {
+ const { navMesh } = useNavMesh();
+ const { isPlaying } = usePlayButtonStore();
+ const { setVehicleActive, setVehicleState } = useVehicleStore();
+ const [currentPhase, setCurrentPhase] = useState<(string)>("stationed");
+ const [path, setPath] = useState<[number, number, number][]>([]);
- useEffect(() => {
- 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 [];
+ const computePath = useCallback((start: any, end: any) => {
+
+
+ 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(() => {
+
+
+ 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([])
+ }
}
- }, [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 (
- <>
+ return (
+ <>
-
+
- >
- )
+ >
+ )
}
export default VehicleInstance
\ No newline at end of file