Merge remote-tracking branch 'origin/simulation-agv-v2' into v2
This commit is contained in:
commit
27c7072cc9
|
@ -16,10 +16,10 @@ import addAssetModel from "../geomentries/assets/addAssetModel";
|
||||||
import { getFloorAssets } from "../../../services/factoryBuilder/assest/floorAsset/getFloorItemsApi";
|
import { getFloorAssets } from "../../../services/factoryBuilder/assest/floorAsset/getFloorItemsApi";
|
||||||
import useModuleStore from "../../../store/useModuleStore";
|
import useModuleStore from "../../../store/useModuleStore";
|
||||||
// import { retrieveGLTF } from "../../../utils/indexDB/idbUtils";
|
// import { retrieveGLTF } from "../../../utils/indexDB/idbUtils";
|
||||||
const assetManagerWorker = new Worker(new URL("../../../services/factoryBuilder/webWorkers/assetManagerWorker.js", import.meta.url));
|
|
||||||
const gltfLoaderWorker = new Worker(new URL("../../../services/factoryBuilder/webWorkers/gltfLoaderWorker.js", import.meta.url));
|
|
||||||
|
|
||||||
import { useEventsStore } from "../../../store/simulation/useEventsStore";
|
import { useEventsStore } from "../../../store/simulation/useEventsStore";
|
||||||
|
const assetManagerWorker = new Worker(new URL("../../../services/factoryBuilder/webWorkers/assetManagerWorker.js", import.meta.url));
|
||||||
|
const gltfLoaderWorker = new Worker(new URL("../../../services/factoryBuilder/webWorkers/gltfLoaderWorker.js", import.meta.url));
|
||||||
|
|
||||||
const FloorItemsGroup = ({ itemsGroup, hoveredDeletableFloorItem, AttachedObject, floorGroup, tempLoader, isTempLoader, plane, }: any) => {
|
const FloorItemsGroup = ({ itemsGroup, hoveredDeletableFloorItem, AttachedObject, floorGroup, tempLoader, isTempLoader, plane, }: any) => {
|
||||||
const state: Types.ThreeState = useThree();
|
const state: Types.ThreeState = useThree();
|
||||||
|
|
|
@ -1,6 +1,38 @@
|
||||||
import React from 'react'
|
import { useFrame, useThree } from '@react-three/fiber';
|
||||||
|
import React, { useEffect, useState } from 'react'
|
||||||
|
|
||||||
function VehicleAnimator() {
|
interface VehicleAnimatorProps {
|
||||||
|
path: [number, number, number][];
|
||||||
|
handleCallBack: () => void;
|
||||||
|
currentPhase: string;
|
||||||
|
agvUuid: number
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid }: VehicleAnimatorProps) {
|
||||||
|
|
||||||
|
const [currentPath, setCurrentPath] = useState<[number, number, number][]>([]);
|
||||||
|
const { scene } = useThree();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
|
||||||
|
if (currentPhase === 'stationed-pickup' && path.length > 0) {
|
||||||
|
|
||||||
|
|
||||||
|
setCurrentPath(path);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}, [currentPhase, path])
|
||||||
|
|
||||||
|
useFrame(() => {
|
||||||
|
if (currentPath.length === 0) return;
|
||||||
|
const object = scene.getObjectByProperty("uuid", agvUuid);
|
||||||
|
if (!object) return;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
})
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
</>
|
</>
|
||||||
|
|
|
@ -1,14 +1,67 @@
|
||||||
import React from 'react'
|
import React, { useCallback, useEffect, useState } from 'react'
|
||||||
import VehicleAnimator from '../animator/vehicleAnimator'
|
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) {
|
||||||
return (
|
const { navMesh } = useNavMesh();
|
||||||
<>
|
const { isPlaying } = usePlayButtonStore();
|
||||||
|
const { setVehicleActive, setVehicleState } = useVehicleStore();
|
||||||
|
const [currentPhase, setCurrentPhase] = useState<(string)>("stationed");
|
||||||
|
const [path, setPath] = useState<[number, number, number][]>([]);
|
||||||
|
|
||||||
<VehicleAnimator />
|
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(() => {
|
||||||
|
// 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 (
|
||||||
|
<>
|
||||||
|
|
||||||
|
<VehicleAnimator path={path} handleCallBack={handleCallBack} currentPhase={currentPhase} agvUuid={agvDetails?.modelUUID} />
|
||||||
|
|
||||||
|
</>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default VehicleInstance
|
export default VehicleInstance
|
|
@ -1,11 +1,13 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import VehicleInstance from './instance/vehicleInstance'
|
import VehicleInstance from './instance/vehicleInstance'
|
||||||
|
|
||||||
function VehicleInstances() {
|
function VehicleInstances({ vehicles }: any) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
||||||
<VehicleInstance />
|
{vehicles.map((val: any, i: any) =>
|
||||||
|
<VehicleInstance agvDetails={val} key={i} />
|
||||||
|
)}
|
||||||
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|
|
@ -9,8 +9,8 @@ function Vehicles() {
|
||||||
|
|
||||||
const vehicleStatusSample: VehicleStatus[] = [
|
const vehicleStatusSample: VehicleStatus[] = [
|
||||||
{
|
{
|
||||||
modelUuid: "veh-123",
|
modelUuid: "2c01ed76-359a-485b-83d4-052cfcdb9d89",
|
||||||
modelName: "Autonomous Truck A1",
|
modelName: "AGV",
|
||||||
position: [10, 0, 5],
|
position: [10, 0, 5],
|
||||||
rotation: [0, 0, 0],
|
rotation: [0, 0, 0],
|
||||||
state: "idle",
|
state: "idle",
|
||||||
|
@ -18,7 +18,7 @@ function Vehicles() {
|
||||||
speed: 2.5,
|
speed: 2.5,
|
||||||
point: {
|
point: {
|
||||||
uuid: "point-789",
|
uuid: "point-789",
|
||||||
position: [0, 1, 0],
|
position: [93.42159216649789, 0, 23.790878603572857],
|
||||||
rotation: [0, 0, 0],
|
rotation: [0, 0, 0],
|
||||||
action: {
|
action: {
|
||||||
actionUuid: "action-456",
|
actionUuid: "action-456",
|
||||||
|
@ -59,9 +59,58 @@ function Vehicles() {
|
||||||
distanceTraveled: 0
|
distanceTraveled: 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
modelUuid: "veh-123",
|
modelUuid: "311130b9-4f2e-425a-b3b5-5039cb348806",
|
||||||
modelName: "Autonomous Truck A1",
|
modelName: "AGV",
|
||||||
position: [10, 0, 5],
|
position: [95.69567023145055, 0, 33.18042399595448],
|
||||||
|
rotation: [0, 0, 0],
|
||||||
|
state: "idle",
|
||||||
|
type: "vehicle",
|
||||||
|
speed: 2.5,
|
||||||
|
point: {
|
||||||
|
uuid: "point-789",
|
||||||
|
position: [0, 1, 0],
|
||||||
|
rotation: [0, 0, 0],
|
||||||
|
action: {
|
||||||
|
actionUuid: "action-456",
|
||||||
|
actionName: "Deliver to Zone A",
|
||||||
|
actionType: "travel",
|
||||||
|
material: "crate",
|
||||||
|
unLoadDuration: 15,
|
||||||
|
loadCapacity: 5,
|
||||||
|
pickUpPoint: { x: 5, y: 0, z: 3 },
|
||||||
|
unLoadPoint: { x: 20, y: 0, z: 10 },
|
||||||
|
triggers: [
|
||||||
|
{
|
||||||
|
triggerUuid: "trig-001",
|
||||||
|
triggerName: "Start Travel",
|
||||||
|
triggerType: "onStart",
|
||||||
|
delay: 0,
|
||||||
|
triggeredAsset: {
|
||||||
|
triggeredModel: { modelName: "ArmBot-X", modelUuid: "arm-001" },
|
||||||
|
triggeredPoint: { pointName: "Pickup Arm Point", pointUuid: "arm-point-01" },
|
||||||
|
triggeredAction: { actionName: "Grab Widget", actionUuid: "grab-001" }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
triggerUuid: "trig-002",
|
||||||
|
triggerName: "Complete Travel",
|
||||||
|
triggerType: "onComplete",
|
||||||
|
delay: 2,
|
||||||
|
triggeredAsset: null
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
productId: "prod-890",
|
||||||
|
isActive: false,
|
||||||
|
idleTime: 0,
|
||||||
|
activeTime: 0,
|
||||||
|
currentLoad: 0,
|
||||||
|
distanceTraveled: 0
|
||||||
|
}, {
|
||||||
|
modelUuid: "fa54132c-8333-4832-becb-5281f5e11549",
|
||||||
|
modelName: "AGV",
|
||||||
|
position: [102.71483985219794, 0, 23.66321267938962],
|
||||||
rotation: [0, 0, 0],
|
rotation: [0, 0, 0],
|
||||||
state: "idle",
|
state: "idle",
|
||||||
type: "vehicle",
|
type: "vehicle",
|
||||||
|
@ -114,6 +163,7 @@ function Vehicles() {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
addVehicle('123', vehicleStatusSample[0]);
|
addVehicle('123', vehicleStatusSample[0]);
|
||||||
addVehicle('123', vehicleStatusSample[1]);
|
addVehicle('123', vehicleStatusSample[1]);
|
||||||
|
addVehicle('123', vehicleStatusSample[2]);
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -124,7 +174,7 @@ function Vehicles() {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
||||||
<VehicleInstances />
|
<VehicleInstances vehicles={vehicles} />
|
||||||
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue