import { useEffect, useRef, useState } from "react"; import { useSimulationStates } from "../../../store/store"; import PolygonGenerator from "./polygonGenerator"; import PathNavigator from "./pathNavigator"; import NavMeshDetails from "./navMeshDetails"; import * as CONSTANTS from "../../../types/world/worldConstants"; import * as Types from "../../../types/world/worldTypes"; type AgvProps = { lines: Types.RefLines }; type PathPoints = { modelUuid: string; modelSpeed: number; bufferTime: number; points: { x: number; y: number; z: number }[]; hitCount: number; }; const Agv = ({ lines }: AgvProps) => { let groupRef = useRef() as Types.RefGroup; const [pathPoints, setPathPoints] = useState([]); const { simulationStates } = useSimulationStates(); const [navMesh, setNavMesh] = useState(); useEffect(() => { if (simulationStates.length > 0) { const agvModels = simulationStates.filter((val) => val.modelName === "agv" && val.type === "Vehicle"); const newPathPoints = agvModels.filter((model: any) => model.points && model.points.actions && typeof model.points.actions.start === "object" && typeof model.points.actions.end === "object" && "x" in model.points.actions.start && "y" in model.points.actions.start && "x" in model.points.actions.end && "y" in model.points.actions.end) .map((model: any) => ({ modelUuid: model.modeluuid, modelSpeed: model.points.speed, bufferTime: model.points.actions.buffer, hitCount: model.points.actions.hitCount, points: [ { x: model.position[0], y: model.position[1], z: model.position[2], }, { x: model.points.actions.start.x, y: 0, z: model.points.actions.start.y, }, { x: model.points.actions.end.x, y: 0, z: model.points.actions.end.y, }, ], })); setPathPoints(newPathPoints); } }, [simulationStates]); return ( <> {pathPoints.map((pair, i) => ( ))} {pathPoints.map((pair, i) => ( ))} ); }; export default Agv;