2025-04-05 04:42:28 +00:00
|
|
|
import { useEffect, useRef, useState } from "react";
|
|
|
|
import { useSimulationStates } from "../../../store/store";
|
2025-03-27 10:07:16 +00:00
|
|
|
import PolygonGenerator from "./polygonGenerator";
|
2025-03-26 12:58:14 +00:00
|
|
|
import PathNavigator from "./pathNavigator";
|
2025-03-27 10:07:16 +00:00
|
|
|
import NavMeshDetails from "./navMeshDetails";
|
2025-04-04 11:27:18 +00:00
|
|
|
import * as CONSTANTS from "../../../types/world/worldConstants";
|
2025-04-05 04:42:28 +00:00
|
|
|
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<PathPoints[]>([]);
|
|
|
|
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, },
|
|
|
|
],
|
|
|
|
}));
|
2025-03-27 10:07:16 +00:00
|
|
|
|
2025-04-05 04:42:28 +00:00
|
|
|
setPathPoints(newPathPoints);
|
|
|
|
}
|
|
|
|
}, [simulationStates]);
|
2025-04-02 13:42:14 +00:00
|
|
|
|
2025-04-05 04:42:28 +00:00
|
|
|
return (
|
|
|
|
<>
|
2025-04-02 13:42:14 +00:00
|
|
|
|
2025-04-05 04:42:28 +00:00
|
|
|
<PolygonGenerator groupRef={groupRef} lines={lines} />
|
|
|
|
<NavMeshDetails lines={lines} setNavMesh={setNavMesh} groupRef={groupRef} />
|
2025-04-04 04:16:18 +00:00
|
|
|
|
2025-04-05 04:42:28 +00:00
|
|
|
{pathPoints.map((pair, i) => (
|
|
|
|
<PathNavigator
|
|
|
|
navMesh={navMesh}
|
|
|
|
selectedPoints={pair.points}
|
|
|
|
id={pair.modelUuid}
|
|
|
|
key={i}
|
|
|
|
speed={pair.modelSpeed}
|
|
|
|
bufferTime={pair.bufferTime}
|
|
|
|
hitCount={pair.hitCount}
|
|
|
|
/>
|
|
|
|
))}
|
2025-03-29 12:44:29 +00:00
|
|
|
|
2025-04-05 04:42:28 +00:00
|
|
|
{pathPoints.map((pair, i) => (
|
|
|
|
<group key={i}>
|
|
|
|
<mesh position={[pair.points[1].x, pair.points[1].y, pair.points[1].z,]} >
|
|
|
|
<sphereGeometry args={[0.3, 15, 15]} />
|
|
|
|
<meshStandardMaterial color="red" />
|
|
|
|
</mesh>
|
|
|
|
<mesh position={[pair.points[2].x, pair.points[2].y, pair.points[2].z,]} >
|
|
|
|
<sphereGeometry args={[0.3, 15, 15]} />
|
|
|
|
<meshStandardMaterial color="red" />
|
|
|
|
</mesh>
|
|
|
|
</group>
|
|
|
|
))}
|
2025-03-26 12:58:14 +00:00
|
|
|
|
2025-04-05 04:42:28 +00:00
|
|
|
<group ref={groupRef} visible={false} name="Meshes">
|
|
|
|
<mesh rotation-x={CONSTANTS.planeConfig.rotation} position={CONSTANTS.planeConfig.position3D} name="Plane" receiveShadow>
|
|
|
|
<planeGeometry args={[300, 300]} />
|
|
|
|
<meshBasicMaterial color={CONSTANTS.planeConfig.color} />
|
|
|
|
</mesh>
|
|
|
|
</group>
|
|
|
|
</>
|
|
|
|
);
|
2025-03-27 10:07:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Agv;
|