Refactor AGV and PathNavigator components; add NavMeshCreator for improved navigation handling and added backend event storage for connections
This commit is contained in:
@@ -1,14 +1,8 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useSimulationStates } from "../../../store/store";
|
||||
import PolygonGenerator from "./polygonGenerator";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Line } from "@react-three/drei";
|
||||
import { useNavMesh, useSimulationStates } from "../../../store/store";
|
||||
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
|
||||
};
|
||||
import { usePlayButtonStore } from "../../../store/usePlayButtonStore";
|
||||
|
||||
type PathPoints = {
|
||||
modelUuid: string;
|
||||
@@ -18,12 +12,11 @@ type PathPoints = {
|
||||
hitCount: number;
|
||||
};
|
||||
|
||||
const Agv = ({ lines }: AgvProps) => {
|
||||
|
||||
let groupRef = useRef() as Types.RefGroup;
|
||||
const Agv = () => {
|
||||
const [pathPoints, setPathPoints] = useState<PathPoints[]>([]);
|
||||
const { simulationStates } = useSimulationStates();
|
||||
const [navMesh, setNavMesh] = useState();
|
||||
const { navMesh } = useNavMesh();
|
||||
const { isPlaying } = usePlayButtonStore();
|
||||
|
||||
useEffect(() => {
|
||||
if (simulationStates.length > 0) {
|
||||
@@ -37,9 +30,9 @@ const Agv = ({ lines }: AgvProps) => {
|
||||
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, },
|
||||
{ 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 },
|
||||
],
|
||||
}));
|
||||
|
||||
@@ -49,41 +42,25 @@ const Agv = ({ lines }: AgvProps) => {
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
<PolygonGenerator groupRef={groupRef} lines={lines} />
|
||||
<NavMeshDetails lines={lines} setNavMesh={setNavMesh} groupRef={groupRef} />
|
||||
|
||||
{pathPoints.map((pair, i) => (
|
||||
<PathNavigator
|
||||
navMesh={navMesh}
|
||||
selectedPoints={pair.points}
|
||||
id={pair.modelUuid}
|
||||
key={i}
|
||||
speed={pair.modelSpeed}
|
||||
bufferTime={pair.bufferTime}
|
||||
hitCount={pair.hitCount}
|
||||
/>
|
||||
))}
|
||||
<group key={i} visible={!isPlaying}>
|
||||
<PathNavigator
|
||||
navMesh={navMesh}
|
||||
pathPoints={pair.points}
|
||||
id={pair.modelUuid}
|
||||
speed={pair.modelSpeed}
|
||||
bufferTime={pair.bufferTime}
|
||||
hitCount={pair.hitCount}
|
||||
/>
|
||||
|
||||
{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>
|
||||
{pair.points.slice(1).map((point, idx) => (
|
||||
<mesh position={[point.x, point.y, point.z]} key={idx}>
|
||||
<sphereGeometry args={[0.3, 15, 15]} />
|
||||
<meshStandardMaterial color="red" />
|
||||
</mesh>
|
||||
))}
|
||||
</group>
|
||||
))}
|
||||
|
||||
<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>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user