Merge remote-tracking branch 'origin/v2' into simulation-agv-v2

This commit is contained in:
Poovizhi99 2025-05-08 16:59:19 +05:30
commit e61988a2b6
10 changed files with 533 additions and 472 deletions

View File

@ -18,19 +18,19 @@ import Window from "../../assets/gltf-glb/window.glb";
////////// Zustand State Imports ////////// ////////// Zustand State Imports //////////
import { import {
useToggleView, useToggleView,
useDeletePointOrLine, useDeletePointOrLine,
useMovePoint, useMovePoint,
useActiveLayer, useActiveLayer,
useWallVisibility, useWallVisibility,
useRoofVisibility, useRoofVisibility,
useShadows, useShadows,
useUpdateScene, useUpdateScene,
useWalls, useWalls,
useToolMode, useToolMode,
useRefTextUpdate, useRefTextUpdate,
useRenderDistance, useRenderDistance,
useLimitDistance, useLimitDistance,
} from "../../store/store"; } from "../../store/store";
////////// 3D Function Imports ////////// ////////// 3D Function Imports //////////
@ -54,296 +54,295 @@ import MeasurementTool from "../scene/tools/measurementTool";
import NavMesh from "../simulation/vehicle/navMesh/navMesh"; import NavMesh from "../simulation/vehicle/navMesh/navMesh";
export default function Builder() { export default function Builder() {
const state = useThree<Types.ThreeState>(); // Importing the state from the useThree hook, which contains the scene, camera, and other Three.js elements. const state = useThree<Types.ThreeState>(); // Importing the state from the useThree hook, which contains the scene, camera, and other Three.js elements.
const csg = useRef(); // Reference for CSG object, used for 3D modeling. const csg = useRef(); // Reference for CSG object, used for 3D modeling.
const CSGGroup = useRef() as Types.RefMesh; // Reference to a group of CSG objects. const CSGGroup = useRef() as Types.RefMesh; // Reference to a group of CSG objects.
const scene = useRef() as Types.RefScene; // Reference to the scene. const scene = useRef() as Types.RefScene; // Reference to the scene.
const camera = useRef() as Types.RefCamera; // Reference to the camera object. const camera = useRef() as Types.RefCamera; // Reference to the camera object.
const controls = useRef<any>(); // Reference to the controls object. const controls = useRef<any>(); // Reference to the controls object.
const raycaster = useRef() as Types.RefRaycaster; // Reference for raycaster used for detecting objects being pointed at in the scene. const raycaster = useRef() as Types.RefRaycaster; // Reference for raycaster used for detecting objects being pointed at in the scene.
const dragPointControls = useRef() as Types.RefDragControl; // Reference for drag point controls, an array for drag control. const dragPointControls = useRef() as Types.RefDragControl; // Reference for drag point controls, an array for drag control.
// Assigning the scene and camera from the Three.js state to the references. // Assigning the scene and camera from the Three.js state to the references.
scene.current = state.scene; scene.current = state.scene;
camera.current = state.camera; camera.current = state.camera;
controls.current = state.controls; controls.current = state.controls;
raycaster.current = state.raycaster; raycaster.current = state.raycaster;
const plane = useRef<THREE.Mesh>(null); // Reference for a plane object for raycaster reference. const plane = useRef<THREE.Mesh>(null); // Reference for a plane object for raycaster reference.
const grid = useRef() as any; // Reference for a grid object for raycaster reference. const grid = useRef() as any; // Reference for a grid object for raycaster reference.
const snappedPoint = useRef() as Types.RefVector3; // Reference for storing a snapped point at the (end = isSnapped) and (start = ispreSnapped) of the line. const snappedPoint = useRef() as Types.RefVector3; // Reference for storing a snapped point at the (end = isSnapped) and (start = ispreSnapped) of the line.
const isSnapped = useRef(false) as Types.RefBoolean; // Boolean reference to indicate if an object is snapped at the (end). const isSnapped = useRef(false) as Types.RefBoolean; // Boolean reference to indicate if an object is snapped at the (end).
const anglesnappedPoint = useRef() as Types.RefVector3; // Reference for storing an angle-snapped point when the line is in 90 degree etc... const anglesnappedPoint = useRef() as Types.RefVector3; // Reference for storing an angle-snapped point when the line is in 90 degree etc...
const isAngleSnapped = useRef(false) as Types.RefBoolean; // Boolean to indicate if angle snapping is active. const isAngleSnapped = useRef(false) as Types.RefBoolean; // Boolean to indicate if angle snapping is active.
const isSnappedUUID = useRef() as Types.RefString; // UUID reference to identify the snapped point. const isSnappedUUID = useRef() as Types.RefString; // UUID reference to identify the snapped point.
const ispreSnapped = useRef(false) as Types.RefBoolean; // Boolean reference to indicate if an object is snapped at the (start). const ispreSnapped = useRef(false) as Types.RefBoolean; // Boolean reference to indicate if an object is snapped at the (start).
const tempLoader = useRef() as Types.RefMesh; // Reference for a temporary loader for the floor items. const tempLoader = useRef() as Types.RefMesh; // Reference for a temporary loader for the floor items.
const isTempLoader = useRef() as Types.RefBoolean; // Reference to check if a temporary loader is active. const isTempLoader = useRef() as Types.RefBoolean; // Reference to check if a temporary loader is active.
const Tube = useRef() as Types.RefTubeGeometry; // Reference for tubes used for reference line creation and updation. const Tube = useRef() as Types.RefTubeGeometry; // Reference for tubes used for reference line creation and updation.
const line = useRef([]) as Types.RefLine; // Reference for line which stores the current line that is being drawn. const line = useRef([]) as Types.RefLine; // Reference for line which stores the current line that is being drawn.
const lines = useRef([]) as Types.RefLines; // Reference for lines which stores all the lines that are ever drawn. const lines = useRef([]) as Types.RefLines; // Reference for lines which stores all the lines that are ever drawn.
const onlyFloorline = useRef<Types.OnlyFloorLine>([]); // Reference for floor lines which does not have walls or roof and have only floor used to store the current line that is being drawn. const onlyFloorline = useRef<Types.OnlyFloorLine>([]); // Reference for floor lines which does not have walls or roof and have only floor used to store the current line that is being drawn.
const onlyFloorlines = useRef<Types.OnlyFloorLines>([]); // Reference for all the floor lines that are ever drawn. const onlyFloorlines = useRef<Types.OnlyFloorLines>([]); // Reference for all the floor lines that are ever drawn.
const ReferenceLineMesh = useRef() as Types.RefMesh; // Reference for storing the mesh of the reference line for moving it during draw. const ReferenceLineMesh = useRef() as Types.RefMesh; // Reference for storing the mesh of the reference line for moving it during draw.
const LineCreated = useRef(false) as Types.RefBoolean; // Boolean to track whether the reference line is created or not. const LineCreated = useRef(false) as Types.RefBoolean; // Boolean to track whether the reference line is created or not.
const referencePole = useRef() as Types.RefMesh; // Reference for a pole that is used as the reference for the user to show where it is placed. const referencePole = useRef() as Types.RefMesh; // Reference for a pole that is used as the reference for the user to show where it is placed.
const itemsGroup = useRef() as Types.RefGroup; // Reference to the THREE.Group that has the floor items (Gltf). const itemsGroup = useRef() as Types.RefGroup; // Reference to the THREE.Group that has the floor items (Gltf).
const floorGroup = useRef() as Types.RefGroup; // Reference to the THREE.Group that has the roofs and the floors. const floorGroup = useRef() as Types.RefGroup; // Reference to the THREE.Group that has the roofs and the floors.
const AttachedObject = useRef() as Types.RefMesh; // Reference for an object that is attached using dbl click for transform controls rotation. const AttachedObject = useRef() as Types.RefMesh; // Reference for an object that is attached using dbl click for transform controls rotation.
const floorPlanGroup = useRef() as Types.RefGroup; // Reference for a THREE.Group that has the lines group and the points group. const floorPlanGroup = useRef() as Types.RefGroup; // Reference for a THREE.Group that has the lines group and the points group.
const floorPlanGroupLine = useRef() as Types.RefGroup; // Reference for a THREE.Group that has the lines that are drawn. const floorPlanGroupLine = useRef() as Types.RefGroup; // Reference for a THREE.Group that has the lines that are drawn.
const floorPlanGroupPoint = useRef() as Types.RefGroup; // Reference for a THREE.Group that has the points that are created. const floorPlanGroupPoint = useRef() as Types.RefGroup; // Reference for a THREE.Group that has the points that are created.
const floorGroupAisle = useRef() as Types.RefGroup; const floorGroupAisle = useRef() as Types.RefGroup;
const zoneGroup = useRef() as Types.RefGroup; const zoneGroup = useRef() as Types.RefGroup;
const currentLayerPoint = useRef([]) as Types.RefMeshArray; // Reference for points that re in the current layer used to update the points in drag controls. const currentLayerPoint = useRef([]) as Types.RefMeshArray; // Reference for points that re in the current layer used to update the points in drag controls.
const hoveredDeletablePoint = useRef() as Types.RefMesh; // Reference for the currently hovered point that can be deleted. const hoveredDeletablePoint = useRef() as Types.RefMesh; // Reference for the currently hovered point that can be deleted.
const hoveredDeletableLine = useRef() as Types.RefMesh; // Reference for the currently hovered line that can be deleted. const hoveredDeletableLine = useRef() as Types.RefMesh; // Reference for the currently hovered line that can be deleted.
const hoveredDeletableFloorItem = useRef() as Types.RefMesh; // Reference for the currently hovered floor item that can be deleted. const hoveredDeletableFloorItem = useRef() as Types.RefMesh; // Reference for the currently hovered floor item that can be deleted.
const hoveredDeletableWallItem = useRef() as Types.RefMesh; // Reference for the currently hovered wall item that can be deleted. const hoveredDeletableWallItem = useRef() as Types.RefMesh; // Reference for the currently hovered wall item that can be deleted.
const hoveredDeletablePillar = useRef() as Types.RefMesh; // Reference for the currently hovered pillar that can be deleted. const hoveredDeletablePillar = useRef() as Types.RefMesh; // Reference for the currently hovered pillar that can be deleted.
const currentWallItem = useRef() as Types.RefMesh; // Reference for the currently selected wall item that can be scaled, dragged etc... const currentWallItem = useRef() as Types.RefMesh; // Reference for the currently selected wall item that can be scaled, dragged etc...
const cursorPosition = new THREE.Vector3(); // 3D vector for storing the cursor position. const cursorPosition = new THREE.Vector3(); // 3D vector for storing the cursor position.
const [selectedItemsIndex, setSelectedItemsIndex] = const [selectedItemsIndex, setSelectedItemsIndex] = useState<Types.Number | null>(null); // State for tracking the index of the selected item.
useState<Types.Number | null>(null); // State for tracking the index of the selected item. const { activeLayer } = useActiveLayer(); // State that changes based on which layer the user chooses in Layers.jsx.
const { activeLayer } = useActiveLayer(); // State that changes based on which layer the user chooses in Layers.jsx. const { toggleView } = useToggleView(); // State for toggling between 2D and 3D.
const { toggleView } = useToggleView(); // State for toggling between 2D and 3D. const { toolMode, setToolMode } = useToolMode();
const { toolMode, setToolMode } = useToolMode(); const { setMovePoint } = useMovePoint(); // State that stores a boolean which represents whether the move mode is active or not.
const { setMovePoint } = useMovePoint(); // State that stores a boolean which represents whether the move mode is active or not. const { setDeletePointOrLine } = useDeletePointOrLine();
const { setDeletePointOrLine } = useDeletePointOrLine(); const { setRoofVisibility } = useRoofVisibility();
const { setRoofVisibility } = useRoofVisibility(); const { setWallVisibility } = useWallVisibility();
const { setWallVisibility } = useWallVisibility(); const { setShadows } = useShadows();
const { setShadows } = useShadows(); const { setRenderDistance } = useRenderDistance();
const { setRenderDistance } = useRenderDistance(); const { setLimitDistance } = useLimitDistance();
const { setLimitDistance } = useLimitDistance(); const { setUpdateScene } = useUpdateScene();
const { setUpdateScene } = useUpdateScene(); const { setWalls } = useWalls();
const { setWalls } = useWalls(); const { refTextupdate, setRefTextUpdate } = useRefTextUpdate();
const { refTextupdate, setRefTextUpdate } = useRefTextUpdate();
// const loader = new GLTFLoader(); // const loader = new GLTFLoader();
// const dracoLoader = new DRACOLoader(); // const dracoLoader = new DRACOLoader();
// dracoLoader.setDecoderPath('https://cdn.jsdelivr.net/npm/three@0.160.0/examples/jsm/libs/draco/gltf/'); // dracoLoader.setDecoderPath('https://cdn.jsdelivr.net/npm/three@0.160.0/examples/jsm/libs/draco/gltf/');
// loader.setDRACOLoader(dracoLoader); // loader.setDRACOLoader(dracoLoader);
////////// Assest Configuration Values ////////// ////////// Assest Configuration Values //////////
const AssetConfigurations: Types.AssetConfigurations = { const AssetConfigurations: Types.AssetConfigurations = {
arch: { arch: {
modelUrl: arch, modelUrl: arch,
scale: [0.75, 0.75, 0.75], scale: [0.75, 0.75, 0.75],
csgscale: [2, 4, 0.5], csgscale: [2, 4, 0.5],
csgposition: [0, 2, 0], csgposition: [0, 2, 0],
positionY: () => 0, positionY: () => 0,
type: "Fixed-Move", type: "Fixed-Move",
}, },
door: { door: {
modelUrl: door, modelUrl: door,
scale: [0.75, 0.75, 0.75], scale: [0.75, 0.75, 0.75],
csgscale: [2, 4, 0.5], csgscale: [2, 4, 0.5],
csgposition: [0, 2, 0], csgposition: [0, 2, 0],
positionY: () => 0, positionY: () => 0,
type: "Fixed-Move", type: "Fixed-Move",
}, },
window: { window: {
modelUrl: Window, modelUrl: Window,
scale: [0.75, 0.75, 0.75], scale: [0.75, 0.75, 0.75],
csgscale: [5, 3, 0.5], csgscale: [5, 3, 0.5],
csgposition: [0, 1.5, 0], csgposition: [0, 1.5, 0],
positionY: (intersectionPoint) => intersectionPoint.point.y, positionY: (intersectionPoint) => intersectionPoint.point.y,
type: "Free-Move", type: "Free-Move",
}, },
}; };
////////// All Toggle's ////////// ////////// All Toggle's //////////
useEffect(() => { useEffect(() => {
setRefTextUpdate((prevUpdate: number) => prevUpdate - 1); setRefTextUpdate((prevUpdate: number) => prevUpdate - 1);
if (dragPointControls.current) { if (dragPointControls.current) {
dragPointControls.current.enabled = false; dragPointControls.current.enabled = false;
} }
if (toggleView) { if (toggleView) {
Layer2DVisibility( Layer2DVisibility(
activeLayer, activeLayer,
floorPlanGroup, floorPlanGroup,
floorPlanGroupLine, floorPlanGroupLine,
floorPlanGroupPoint, floorPlanGroupPoint,
currentLayerPoint, currentLayerPoint,
dragPointControls dragPointControls
); );
} else { } else {
setToolMode(null); setToolMode(null);
setDeletePointOrLine(false); setDeletePointOrLine(false);
setMovePoint(false); setMovePoint(false);
loadWalls(lines, setWalls); loadWalls(lines, setWalls);
setUpdateScene(true); setUpdateScene(true);
line.current = []; line.current = [];
} }
}, [toggleView]); }, [toggleView]);
useEffect(() => { useEffect(() => {
THREE.Cache.clear(); THREE.Cache.clear();
THREE.Cache.enabled = true; THREE.Cache.enabled = true;
}, []); }, []);
useEffect(() => { useEffect(() => {
const email = localStorage.getItem("email"); const email = localStorage.getItem("email");
const organization = email!.split("@")[1].split(".")[0]; const organization = email!.split("@")[1].split(".")[0];
async function fetchVisibility() { async function fetchVisibility() {
const visibility = await findEnvironment( const visibility = await findEnvironment(
organization, organization,
localStorage.getItem("userId")! localStorage.getItem("userId")!
); );
if (visibility) { if (visibility) {
setRoofVisibility(visibility.roofVisibility); setRoofVisibility(visibility.roofVisibility);
setWallVisibility(visibility.wallVisibility); setWallVisibility(visibility.wallVisibility);
setShadows(visibility.shadowVisibility); setShadows(visibility.shadowVisibility);
setRenderDistance(visibility.renderDistance); setRenderDistance(visibility.renderDistance);
setLimitDistance(visibility.limitDistance); setLimitDistance(visibility.limitDistance);
} }
} }
fetchVisibility(); fetchVisibility();
}, []); }, []);
////////// UseFrame is Here ////////// ////////// UseFrame is Here //////////
useFrame(() => { useFrame(() => {
if (toolMode) { if (toolMode) {
Draw( Draw(
state, state,
plane, plane,
cursorPosition, cursorPosition,
floorPlanGroupPoint, floorPlanGroupPoint,
floorPlanGroupLine, floorPlanGroupLine,
snappedPoint, snappedPoint,
isSnapped, isSnapped,
isSnappedUUID, isSnappedUUID,
line, line,
lines, lines,
ispreSnapped, ispreSnapped,
floorPlanGroup, floorPlanGroup,
ReferenceLineMesh, ReferenceLineMesh,
LineCreated, LineCreated,
setRefTextUpdate, setRefTextUpdate,
Tube, Tube,
anglesnappedPoint, anglesnappedPoint,
isAngleSnapped, isAngleSnapped,
toolMode toolMode
); );
} }
}); });
////////// Return ////////// ////////// Return //////////
return ( return (
<> <>
<Ground grid={grid} plane={plane} /> <Ground grid={grid} plane={plane} />
<DistanceText key={toggleView} /> <DistanceText key={toggleView} />
<ReferenceDistanceText <ReferenceDistanceText
key={refTextupdate} key={refTextupdate}
line={ReferenceLineMesh.current} line={ReferenceLineMesh.current}
/> />
<SocketResponses <SocketResponses
floorPlanGroup={floorPlanGroup} floorPlanGroup={floorPlanGroup}
lines={lines} lines={lines}
floorGroup={floorGroup} floorGroup={floorGroup}
floorGroupAisle={floorGroupAisle} floorGroupAisle={floorGroupAisle}
scene={scene} scene={scene}
onlyFloorlines={onlyFloorlines} onlyFloorlines={onlyFloorlines}
AssetConfigurations={AssetConfigurations} AssetConfigurations={AssetConfigurations}
itemsGroup={itemsGroup} itemsGroup={itemsGroup}
isTempLoader={isTempLoader} isTempLoader={isTempLoader}
tempLoader={tempLoader} tempLoader={tempLoader}
currentLayerPoint={currentLayerPoint} currentLayerPoint={currentLayerPoint}
floorPlanGroupPoint={floorPlanGroupPoint} floorPlanGroupPoint={floorPlanGroupPoint}
floorPlanGroupLine={floorPlanGroupLine} floorPlanGroupLine={floorPlanGroupLine}
zoneGroup={zoneGroup} zoneGroup={zoneGroup}
dragPointControls={dragPointControls} dragPointControls={dragPointControls}
/> />
<WallsAndWallItems <WallsAndWallItems
CSGGroup={CSGGroup} CSGGroup={CSGGroup}
AssetConfigurations={AssetConfigurations} AssetConfigurations={AssetConfigurations}
setSelectedItemsIndex={setSelectedItemsIndex} setSelectedItemsIndex={setSelectedItemsIndex}
selectedItemsIndex={selectedItemsIndex} selectedItemsIndex={selectedItemsIndex}
currentWallItem={currentWallItem} currentWallItem={currentWallItem}
csg={csg} csg={csg}
lines={lines} lines={lines}
hoveredDeletableWallItem={hoveredDeletableWallItem} hoveredDeletableWallItem={hoveredDeletableWallItem}
/> />
<FloorItemsGroup <FloorItemsGroup
itemsGroup={itemsGroup} itemsGroup={itemsGroup}
hoveredDeletableFloorItem={hoveredDeletableFloorItem} hoveredDeletableFloorItem={hoveredDeletableFloorItem}
AttachedObject={AttachedObject} AttachedObject={AttachedObject}
floorGroup={floorGroup} floorGroup={floorGroup}
tempLoader={tempLoader} tempLoader={tempLoader}
isTempLoader={isTempLoader} isTempLoader={isTempLoader}
plane={plane} plane={plane}
/> />
<FloorGroup <FloorGroup
floorGroup={floorGroup} floorGroup={floorGroup}
lines={lines} lines={lines}
referencePole={referencePole} referencePole={referencePole}
hoveredDeletablePillar={hoveredDeletablePillar} hoveredDeletablePillar={hoveredDeletablePillar}
/> />
<FloorPlanGroup <FloorPlanGroup
floorPlanGroup={floorPlanGroup} floorPlanGroup={floorPlanGroup}
floorPlanGroupLine={floorPlanGroupLine} floorPlanGroupLine={floorPlanGroupLine}
floorPlanGroupPoint={floorPlanGroupPoint} floorPlanGroupPoint={floorPlanGroupPoint}
floorGroup={floorGroup} floorGroup={floorGroup}
currentLayerPoint={currentLayerPoint} currentLayerPoint={currentLayerPoint}
dragPointControls={dragPointControls} dragPointControls={dragPointControls}
hoveredDeletablePoint={hoveredDeletablePoint} hoveredDeletablePoint={hoveredDeletablePoint}
hoveredDeletableLine={hoveredDeletableLine} hoveredDeletableLine={hoveredDeletableLine}
plane={plane} plane={plane}
line={line} line={line}
lines={lines} lines={lines}
onlyFloorline={onlyFloorline} onlyFloorline={onlyFloorline}
onlyFloorlines={onlyFloorlines} onlyFloorlines={onlyFloorlines}
ReferenceLineMesh={ReferenceLineMesh} ReferenceLineMesh={ReferenceLineMesh}
LineCreated={LineCreated} LineCreated={LineCreated}
isSnapped={isSnapped} isSnapped={isSnapped}
ispreSnapped={ispreSnapped} ispreSnapped={ispreSnapped}
snappedPoint={snappedPoint} snappedPoint={snappedPoint}
isSnappedUUID={isSnappedUUID} isSnappedUUID={isSnappedUUID}
isAngleSnapped={isAngleSnapped} isAngleSnapped={isAngleSnapped}
anglesnappedPoint={anglesnappedPoint} anglesnappedPoint={anglesnappedPoint}
/> />
<ZoneGroup /> <ZoneGroup />
<FloorGroupAilse <FloorGroupAilse
floorGroupAisle={floorGroupAisle} floorGroupAisle={floorGroupAisle}
plane={plane} plane={plane}
floorPlanGroupLine={floorPlanGroupLine} floorPlanGroupLine={floorPlanGroupLine}
floorPlanGroupPoint={floorPlanGroupPoint} floorPlanGroupPoint={floorPlanGroupPoint}
line={line} line={line}
lines={lines} lines={lines}
currentLayerPoint={currentLayerPoint} currentLayerPoint={currentLayerPoint}
dragPointControls={dragPointControls} dragPointControls={dragPointControls}
floorPlanGroup={floorPlanGroup} floorPlanGroup={floorPlanGroup}
ReferenceLineMesh={ReferenceLineMesh} ReferenceLineMesh={ReferenceLineMesh}
LineCreated={LineCreated} LineCreated={LineCreated}
isSnapped={isSnapped} isSnapped={isSnapped}
ispreSnapped={ispreSnapped} ispreSnapped={ispreSnapped}
snappedPoint={snappedPoint} snappedPoint={snappedPoint}
isSnappedUUID={isSnappedUUID} isSnappedUUID={isSnappedUUID}
isAngleSnapped={isAngleSnapped} isAngleSnapped={isAngleSnapped}
anglesnappedPoint={anglesnappedPoint} anglesnappedPoint={anglesnappedPoint}
/> />
<MeasurementTool /> <MeasurementTool />
<NavMesh lines={lines} /> <NavMesh lines={lines} />
</> </>
); );
} }

View File

@ -2,142 +2,180 @@ import { useEffect, useState } from "react";
import { getLines } from "../../../../../services/factoryBuilder/lines/getLinesApi"; import { getLines } from "../../../../../services/factoryBuilder/lines/getLinesApi";
import * as THREE from "three"; import * as THREE from "three";
import { import {
useActiveLayer, useActiveLayer,
useDeletedLines, useDeletedLines,
useNewLines, useNewLines,
useToggleView, useRoomsState,
useToggleView,
} from "../../../../../store/store"; } from "../../../../../store/store";
import objectLinesToArray from "../lineConvertions/objectLinesToArray"; import objectLinesToArray from "../lineConvertions/objectLinesToArray";
import { Html } from "@react-three/drei"; import { Html } from "@react-three/drei";
import * as Types from "../../../../../types/world/worldTypes"; import * as Types from "../../../../../types/world/worldTypes";
import getRoomsFromLines from "../getRoomsFromLines";
const DistanceText = () => { const DistanceText = () => {
const [lines, setLines] = useState< const [lines, setLines] = useState<
{ {
distance: string; distance: string;
position: THREE.Vector3; position: THREE.Vector3;
userData: Types.Line; userData: Types.Line;
layer: string; layer: string;
}[] }[]
>([]); >([]);
const { activeLayer } = useActiveLayer(); const { activeLayer } = useActiveLayer();
const { toggleView } = useToggleView(); const { toggleView } = useToggleView();
const { newLines, setNewLines } = useNewLines(); const { newLines, setNewLines } = useNewLines();
const { deletedLines, setDeletedLines } = useDeletedLines(); const { deletedLines, setDeletedLines } = useDeletedLines();
const [linesState, setLinesState] = useState<Types.Lines>([]);
const { roomsState, setRoomsState } = useRoomsState();
useEffect(() => { useEffect(() => {
const email = localStorage.getItem("email"); if (linesState.length === 0) return;
if (!email) return; const getLines = async () => {
const organization = email.split("@")[1].split(".")[0];
getLines(organization).then((data) => { if (lines.length > 2) {
data = objectLinesToArray(data); const linesByLayer = linesState.reduce((acc: { [key: number]: any[] }, pair) => {
const layer = pair[0][2];
if (!acc[layer]) acc[layer] = [];
acc[layer].push(pair);
return acc;
}, {});
const lines = data for (const layer in linesByLayer) {
.filter((line: Types.Line) => line[0][2] === activeLayer)
.map((line: Types.Line) => { const rooms: Types.Rooms = await getRoomsFromLines({ current: linesByLayer[layer] });
const point1 = new THREE.Vector3(
line[0][0].x, }
line[0][0].y, }
line[0][0].z }
); getLines();
const point2 = new THREE.Vector3( }, [linesState])
line[1][0].x,
line[1][0].y, useEffect(() => {
line[1][0].z const email = localStorage.getItem("email");
); if (!email) return;
const distance = point1.distanceTo(point2); const organization = email.split("@")[1].split(".")[0];
const midpoint = new THREE.Vector3()
.addVectors(point1, point2) getLines(organization).then((data) => {
.divideScalar(2); data = objectLinesToArray(data);
return { setLinesState(data);
distance: distance.toFixed(1),
position: midpoint, const lines = data
userData: line, .filter((line: Types.Line) => line[0][2] === activeLayer)
layer: activeLayer, .map((line: Types.Line) => {
}; const point1 = new THREE.Vector3(
line[0][0].x,
line[0][0].y,
line[0][0].z
);
const point2 = new THREE.Vector3(
line[1][0].x,
line[1][0].y,
line[1][0].z
);
const distance = point1.distanceTo(point2);
const midpoint = new THREE.Vector3()
.addVectors(point1, point2)
.divideScalar(2);
return {
distance: distance.toFixed(1),
position: midpoint,
userData: line,
layer: activeLayer,
};
});
setLines(lines);
}); });
setLines(lines); }, [activeLayer]);
});
}, [activeLayer]);
useEffect(() => { useEffect(() => {
if (newLines.length > 0) { if (newLines.length > 0) {
if (newLines[0][0][2] !== activeLayer) return; if (newLines[0][0][2] !== activeLayer) return;
const newLinesData = newLines.map((line: Types.Line) => { const newLinesData = newLines.map((line: Types.Line) => {
const point1 = new THREE.Vector3( const point1 = new THREE.Vector3(
line[0][0].x, line[0][0].x,
line[0][0].y, line[0][0].y,
line[0][0].z line[0][0].z
); );
const point2 = new THREE.Vector3( const point2 = new THREE.Vector3(
line[1][0].x, line[1][0].x,
line[1][0].y, line[1][0].y,
line[1][0].z line[1][0].z
); );
const distance = point1.distanceTo(point2); const distance = point1.distanceTo(point2);
const midpoint = new THREE.Vector3() const midpoint = new THREE.Vector3()
.addVectors(point1, point2) .addVectors(point1, point2)
.divideScalar(2); .divideScalar(2);
return { return {
distance: distance.toFixed(1), distance: distance.toFixed(1),
position: midpoint, position: midpoint,
userData: line, userData: line,
layer: activeLayer, layer: activeLayer,
}; };
}); });
setLines((prevLines) => [...prevLines, ...newLinesData]); setLines((prevLines) => [...prevLines, ...newLinesData]);
setNewLines([]); setLinesState((prevLines) => [...prevLines, ...newLines]);
} setNewLines([]);
}, [newLines, activeLayer]); }
}, [newLines, activeLayer]);
useEffect(() => { useEffect(() => {
if ((deletedLines as Types.Lines).length > 0) { if ((deletedLines as Types.Lines).length > 0) {
setLines((prevLines) => setLines((prevLines) =>
prevLines.filter( prevLines.filter(
(line) => (line) =>
!deletedLines.some( !deletedLines.some(
(deletedLine: any) => (deletedLine: any) =>
deletedLine[0][1] === line.userData[0][1] && deletedLine[0][1] === line.userData[0][1] &&
deletedLine[1][1] === line.userData[1][1] deletedLine[1][1] === line.userData[1][1]
) )
) )
); );
setDeletedLines([]);
}
}, [deletedLines]);
return ( setLinesState(prev =>
<> prev.filter(line =>
{toggleView && ( !(deletedLines as Types.Lines).some(
<group name="Distance_Text"> deleted =>
{lines.map((text) => ( line[0][1] === deleted[0][1] && line[1][1] === deleted[1][1]
<Html )
// data )
key={`${text.userData[0][1]}_${text.userData[1][1]}`} );
userData={text.userData}
position={[text.position.x, 1, text.position.z]} setDeletedLines([]);
// class }
wrapperClass="distance-text-wrapper" }, [deletedLines]);
className="distance-text"
// other return (
zIndexRange={[1, 0]} <>
prepend {toggleView && (
sprite <group name="Distance_Text">
> {lines.map((text) => (
<div <Html
key={`${text.userData[0][1]}_${text.userData[1][1]}`} // data
className={`distance line-${text.userData[0][1]}_${text.userData[1][1]}_${text.layer}`} key={`${text.userData[0][1]}_${text.userData[1][1]}`}
> userData={text.userData}
{text.distance} m position={[text.position.x, 1, text.position.z]}
</div> // class
</Html> wrapperClass="distance-text-wrapper"
))} className="distance-text"
</group> // other
)} zIndexRange={[1, 0]}
</> prepend
); sprite
>
<div
key={`${text.userData[0][1]}_${text.userData[1][1]}`}
className={`distance line-${text.userData[0][1]}_${text.userData[1][1]}_${text.layer}`}
>
{text.distance} m
</div>
</Html>
))}
</group>
)}
</>
);
}; };
export default DistanceText; export default DistanceText;

View File

@ -25,7 +25,6 @@ export function useTravelHandler() {
if (!modelUuid) return; if (!modelUuid) return;
incrementVehicleLoad(modelUuid, 1); incrementVehicleLoad(modelUuid, 1);
console.log('material: ', material);
addCurrentMaterial(modelUuid, material.materialType, material.materialId); addCurrentMaterial(modelUuid, material.materialType, material.materialId);
travelLogStatus(material.materialId, `is triggering travel from ${modelUuid}`); travelLogStatus(material.materialId, `is triggering travel from ${modelUuid}`);

View File

@ -85,37 +85,10 @@ function MaterialInstance({ material }: { material: MaterialSchema }) {
const callTrigger = () => { const callTrigger = () => {
if (!material.next) return; if (!material.next) return;
const fromModel = getEventByModelUuid(selectedProduct.productId, material.next.modelUuid); const action = getActionByPointUuid(selectedProduct.productId, material.next.pointUuid);
if (!fromModel) return; if (action) {
const fromPoint = getPointByUuid(selectedProduct.productId, fromModel.modelUuid, material.next.pointUuid); triggerPointActions(action, material.materialId);
if (!fromPoint) return;
if (fromModel.type === 'transfer') {
const toModel = getEventByModelUuid(selectedProduct.productId, material.next.modelUuid);
if (!toModel) return;
if (toModel.type === 'transfer') {
const action = getActionByPointUuid(selectedProduct.productId, material.next.pointUuid);
if (action) {
triggerPointActions(action, material.materialId);
}
} else if (toModel?.type === 'vehicle') {
// Transfer to Vehicle
} else if (toModel?.type === 'machine') {
// Transfer to Machine
} else if (toModel?.type === 'roboticArm') {
// Transfer to Robotic Arm
} else if (toModel?.type === 'storageUnit') {
// Transfer to Storage Unit
}
} else if (fromModel.type === 'vehicle') {
} else if (fromModel.type === 'machine') {
} else if (fromModel.type === 'roboticArm') {
} else if (fromModel.type === 'storageUnit') {
} }
} }
return ( return (

View File

@ -14,7 +14,7 @@ export function useTriggerHandler() {
const { getVehicleById } = useVehicleStore(); const { getVehicleById } = useVehicleStore();
const { setCurrentLocation, setNextLocation, getMaterialById, setIsPaused, setIsVisible, setEndTime } = useMaterialStore(); const { setCurrentLocation, setNextLocation, getMaterialById, setIsPaused, setIsVisible, setEndTime } = useMaterialStore();
const handleTrigger = (trigger: TriggerSchema, action: Action, materialId: string) => { const handleTrigger = (trigger: TriggerSchema, action: Action, materialId?: string) => {
const fromEvent = getEventByTriggerUuid(selectedProduct.productId, trigger.triggerUuid); const fromEvent = getEventByTriggerUuid(selectedProduct.productId, trigger.triggerUuid);
@ -23,7 +23,7 @@ export function useTriggerHandler() {
if (fromEvent?.type === 'transfer') { if (fromEvent?.type === 'transfer') {
if (toEvent?.type === 'transfer') { if (toEvent?.type === 'transfer') {
// Transfer to Transfer // Transfer to Transfer
if (trigger.triggeredAsset && trigger.triggeredAsset.triggeredPoint && trigger.triggeredAsset.triggeredAction) { if (materialId && trigger.triggeredAsset && trigger.triggeredAsset.triggeredPoint && trigger.triggeredAsset.triggeredAction) {
const material = getMaterialById(materialId); const material = getMaterialById(materialId);
if (material) { if (material) {
if (material.next) { if (material.next) {
@ -44,7 +44,7 @@ export function useTriggerHandler() {
} }
} else if (toEvent?.type === 'vehicle') { } else if (toEvent?.type === 'vehicle') {
// Transfer to Vehicle // Transfer to Vehicle
if (trigger.triggeredAsset && trigger.triggeredAsset.triggeredPoint && trigger.triggeredAsset.triggeredAction) { if (materialId && trigger.triggeredAsset && trigger.triggeredAsset.triggeredPoint && trigger.triggeredAsset.triggeredAction) {
const material = getMaterialById(materialId); const material = getMaterialById(materialId);
if (material) { if (material) {
@ -90,7 +90,7 @@ export function useTriggerHandler() {
} else if (toEvent?.type === 'roboticArm') { } else if (toEvent?.type === 'roboticArm') {
// Transfer to Robotic Arm // Transfer to Robotic Arm
if (trigger.triggeredAsset && trigger.triggeredAsset.triggeredPoint && trigger.triggeredAsset.triggeredAction) { if (materialId && trigger.triggeredAsset && trigger.triggeredAsset.triggeredPoint && trigger.triggeredAsset.triggeredAction) {
const material = getMaterialById(materialId); const material = getMaterialById(materialId);
if (material) { if (material) {
@ -136,6 +136,7 @@ export function useTriggerHandler() {
} }
} else if (fromEvent?.type === 'vehicle') { } else if (fromEvent?.type === 'vehicle') {
if (toEvent?.type === 'transfer') { if (toEvent?.type === 'transfer') {
console.log('toEvent: ', toEvent);
// Vehicle to Transfer // Vehicle to Transfer
} else if (toEvent?.type === 'vehicle') { } else if (toEvent?.type === 'vehicle') {
@ -171,7 +172,7 @@ export function useTriggerHandler() {
} else if (fromEvent?.type === 'roboticArm') { } else if (fromEvent?.type === 'roboticArm') {
if (toEvent?.type === 'transfer') { if (toEvent?.type === 'transfer') {
// Robotic Arm to Transfer // Robotic Arm to Transfer
if (trigger.triggeredAsset && trigger.triggeredAsset.triggeredPoint && trigger.triggeredAsset.triggeredAction) { if (materialId && trigger.triggeredAsset && trigger.triggeredAsset.triggeredPoint && trigger.triggeredAsset.triggeredAction) {
const material = getMaterialById(materialId); const material = getMaterialById(materialId);
if (material) { if (material) {
setIsPaused(material.materialId, false); setIsPaused(material.materialId, false);
@ -199,6 +200,41 @@ export function useTriggerHandler() {
} else if (toEvent?.type === 'vehicle') { } else if (toEvent?.type === 'vehicle') {
// Robotic Arm to Vehicle // Robotic Arm to Vehicle
if (materialId && trigger.triggeredAsset && trigger.triggeredAsset.triggeredPoint && trigger.triggeredAsset.triggeredAction) {
const material = getMaterialById(materialId);
if (material) {
const action = getActionByUuid(selectedProduct.productId, trigger.triggeredAsset.triggeredAction.actionUuid);
const vehicle = getVehicleById(trigger.triggeredAsset?.triggeredModel.modelUuid);
setCurrentLocation(material.materialId, {
modelUuid: trigger.triggeredAsset.triggeredModel.modelUuid,
pointUuid: trigger.triggeredAsset.triggeredPoint.pointUuid,
actionUuid: trigger.triggeredAsset?.triggeredAction?.actionUuid,
});
setNextLocation(material.materialId, null);
if (action) {
if (vehicle) {
if (vehicle.isActive === false && vehicle.state === 'idle' && vehicle.currentLoad < vehicle.point.action.loadCapacity) {
setIsVisible(materialId, false);
// Handle current action from vehicle
handleAction(action, materialId);
} else {
// Event Manager Needed
}
}
}
}
}
} else if (toEvent?.type === 'machine') { } else if (toEvent?.type === 'machine') {
// Robotic Arm to Machine // Robotic Arm to Machine
@ -230,18 +266,18 @@ export function useTriggerHandler() {
} }
} }
const handleFinalAction = (action: Action, materialId: string) => { const handleFinalAction = (action: Action, materialId?: string) => {
if (!action) return; if (!action) return;
const modelUuid = getModelUuidByActionUuid(selectedProduct.productId, action.actionUuid); const modelUuid = getModelUuidByActionUuid(selectedProduct.productId, action.actionUuid);
if (!modelUuid) return; if (!modelUuid) return;
const finalModel = getEventByModelUuid(selectedProduct.productId, modelUuid); const finalModel = getEventByModelUuid(selectedProduct.productId, modelUuid);
if (!finalModel) return; if (!finalModel) return;
const material = getMaterialById(materialId);
if (finalModel.type === 'transfer') { if (finalModel.type === 'transfer') {
// Storage Unit to Transfer // Storage Unit to Transfer
if (!materialId) return;
const material = getMaterialById(materialId);
if (material) { if (material) {
const currentTime = performance.now(); const currentTime = performance.now();
@ -274,7 +310,7 @@ export function useTriggerHandler() {
} }
const triggerPointActions = useCallback((action: Action, materialId: string) => { const triggerPointActions = useCallback((action: Action, materialId?: string) => {
if (!action) return; if (!action) return;
if (action.triggers.length > 0) { if (action.triggers.length > 0) {

View File

@ -4,7 +4,6 @@ import * as THREE from 'three';
import { Line } from '@react-three/drei'; import { Line } from '@react-three/drei';
import { useAnimationPlaySpeed, usePauseButtonStore, usePlayButtonStore, useResetButtonStore } from '../../../../../store/usePlayButtonStore'; import { useAnimationPlaySpeed, usePauseButtonStore, usePlayButtonStore, useResetButtonStore } from '../../../../../store/usePlayButtonStore';
import { useVehicleStore } from '../../../../../store/simulation/useVehicleStore'; import { useVehicleStore } from '../../../../../store/simulation/useVehicleStore';
import { useMaterialStore } from '../../../../../store/simulation/useMaterialStore';
interface VehicleAnimatorProps { interface VehicleAnimatorProps {
path: [number, number, number][]; path: [number, number, number][];
@ -17,8 +16,7 @@ interface VehicleAnimatorProps {
} }
function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetail, reset, startUnloadingProcess }: VehicleAnimatorProps) { function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetail, reset, startUnloadingProcess }: VehicleAnimatorProps) {
const { decrementVehicleLoad, getVehicleById, removeLastMaterial } = useVehicleStore(); const { getVehicleById } = useVehicleStore();
const { removeMaterial } = useMaterialStore();
const { isPaused } = usePauseButtonStore(); const { isPaused } = usePauseButtonStore();
const { isPlaying } = usePlayButtonStore(); const { isPlaying } = usePlayButtonStore();
const { speed } = useAnimationPlaySpeed(); const { speed } = useAnimationPlaySpeed();
@ -27,11 +25,9 @@ function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetai
const movingForward = useRef<boolean>(true); const movingForward = useRef<boolean>(true);
const completedRef = useRef<boolean>(false); const completedRef = useRef<boolean>(false);
const [objectRotation, setObjectRotation] = useState<{ x: number; y: number; z: number } | undefined>(agvDetail.point?.action?.pickUpPoint?.rotation || { x: 0, y: 0, z: 0 }) const [objectRotation, setObjectRotation] = useState<{ x: number; y: number; z: number } | undefined>(agvDetail.point?.action?.pickUpPoint?.rotation || { x: 0, y: 0, z: 0 })
const [progress, setProgress] = useState<number>(0);
const [restRotation, setRestingRotation] = useState<boolean>(true); const [restRotation, setRestingRotation] = useState<boolean>(true);
const [currentPath, setCurrentPath] = useState<[number, number, number][]>([]); const [currentPath, setCurrentPath] = useState<[number, number, number][]>([]);
const { scene } = useThree(); const { scene } = useThree();
let coveredDistance = progressRef.current;
useEffect(() => { useEffect(() => {
if (currentPhase === 'stationed-pickup' && path.length > 0) { if (currentPhase === 'stationed-pickup' && path.length > 0) {
@ -47,7 +43,6 @@ function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetai
}, [currentPhase, path, objectRotation]); }, [currentPhase, path, objectRotation]);
useEffect(() => { useEffect(() => {
setProgress(0);
completedRef.current = false; completedRef.current = false;
}, [currentPath]); }, [currentPath]);
@ -55,11 +50,9 @@ function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetai
if (isReset || !isPlaying) { if (isReset || !isPlaying) {
reset(); reset();
setCurrentPath([]); setCurrentPath([]);
setProgress(0);
completedRef.current = false; completedRef.current = false;
movingForward.current = true; movingForward.current = true;
progressRef.current = 0; progressRef.current = 0;
coveredDistance = 0;
setReset(false); setReset(false);
setRestingRotation(true); setRestingRotation(true);
const object = scene.getObjectByProperty('uuid', agvUuid); const object = scene.getObjectByProperty('uuid', agvUuid);
@ -89,7 +82,7 @@ function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetai
totalDistance += segmentDistance; totalDistance += segmentDistance;
} }
while (index < distances.length && coveredDistance > accumulatedDistance + distances[index]) { while (index < distances.length && progressRef.current > accumulatedDistance + distances[index]) {
accumulatedDistance += distances[index]; accumulatedDistance += distances[index];
index++; index++;
} }
@ -115,14 +108,12 @@ function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetai
if (isAligned) { if (isAligned) {
progressRef.current += delta * (speed * agvDetail.speed); progressRef.current += delta * (speed * agvDetail.speed);
coveredDistance = progressRef.current; const t = (progressRef.current - accumulatedDistance) / segmentDistance;
const t = (coveredDistance - accumulatedDistance) / segmentDistance;
const position = start.clone().lerp(end, t); const position = start.clone().lerp(end, t);
object.position.copy(position); object.position.copy(position);
} }
} }
if (progressRef.current >= totalDistance) { if (progressRef.current >= totalDistance) {
if (restRotation && objectRotation) { if (restRotation && objectRotation) {
const targetEuler = new THREE.Euler( const targetEuler = new THREE.Euler(
@ -152,8 +143,6 @@ function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetai
} }
}); });
return ( return (
<> <>
{currentPath.length > 0 && ( {currentPath.length > 0 && (

View File

@ -5,13 +5,19 @@ import { NavMeshQuery } from '@recast-navigation/core';
import { useNavMesh } from '../../../../../store/store'; import { useNavMesh } from '../../../../../store/store';
import { useAnimationPlaySpeed, usePauseButtonStore, usePlayButtonStore } from '../../../../../store/usePlayButtonStore'; import { useAnimationPlaySpeed, usePauseButtonStore, usePlayButtonStore } from '../../../../../store/usePlayButtonStore';
import { useVehicleStore } from '../../../../../store/simulation/useVehicleStore'; import { useVehicleStore } from '../../../../../store/simulation/useVehicleStore';
import MaterialAnimator from '../animator/materialAnimator';
import { useMaterialStore } from '../../../../../store/simulation/useMaterialStore'; import { useMaterialStore } from '../../../../../store/simulation/useMaterialStore';
import { useProductStore } from '../../../../../store/simulation/useProductStore';
import { useSelectedProduct } from '../../../../../store/simulation/useSimulationStore';
import { useTriggerHandler } from '../../../triggers/triggerHandler/useTriggerHandler';
import MaterialAnimator from '../animator/materialAnimator';
function VehicleInstance({ agvDetail }: { agvDetail: VehicleStatus }) { function VehicleInstance({ agvDetail }: { agvDetail: VehicleStatus }) {
const { navMesh } = useNavMesh(); const { navMesh } = useNavMesh();
const { isPlaying } = usePlayButtonStore(); const { isPlaying } = usePlayButtonStore();
const { removeMaterial } = useMaterialStore(); const { removeMaterial } = useMaterialStore();
const { triggerPointActions } = useTriggerHandler();
const { getActionByUuid, getEventByModelUuid, getTriggerByUuid } = useProductStore();
const { selectedProduct } = useSelectedProduct();
const { vehicles, setVehicleActive, setVehicleState, clearCurrentMaterials, setVehicleLoad, decrementVehicleLoad, removeLastMaterial } = useVehicleStore(); const { vehicles, setVehicleActive, setVehicleState, clearCurrentMaterials, setVehicleLoad, decrementVehicleLoad, removeLastMaterial } = useVehicleStore();
const [currentPhase, setCurrentPhase] = useState<string>('stationed'); const [currentPhase, setCurrentPhase] = useState<string>('stationed');
const [path, setPath] = useState<[number, number, number][]>([]); const [path, setPath] = useState<[number, number, number][]>([]);
@ -22,7 +28,6 @@ function VehicleInstance({ agvDetail }: { agvDetail: VehicleStatus }) {
const { speed } = useAnimationPlaySpeed(); const { speed } = useAnimationPlaySpeed();
const { isPaused } = usePauseButtonStore(); const { isPaused } = usePauseButtonStore();
useEffect(() => { useEffect(() => {
isPausedRef.current = isPaused; isPausedRef.current = isPaused;
}, [isPaused]); }, [isPaused]);
@ -44,7 +49,6 @@ function VehicleInstance({ agvDetail }: { agvDetail: VehicleStatus }) {
function vehicleStatus(modelId: string, status: string) { function vehicleStatus(modelId: string, status: string) {
// console.log(`${modelId} , ${status}`); // console.log(`${modelId} , ${status}`);
} }
// Function to reset everything // Function to reset everything
@ -75,11 +79,6 @@ function VehicleInstance({ agvDetail }: { agvDetail: VehicleStatus }) {
vehicleStatus(agvDetail.modelUuid, 'Started from station, heading to pickup'); vehicleStatus(agvDetail.modelUuid, 'Started from station, heading to pickup');
return; return;
} else if (!agvDetail.isActive && agvDetail.state === 'idle' && currentPhase === 'picking') { } else if (!agvDetail.isActive && agvDetail.state === 'idle' && currentPhase === 'picking') {
// setTimeout(() => {
// increment();
// }, 5000);
if (agvDetail.currentLoad === agvDetail.point.action.loadCapacity && agvDetail.currentMaterials.length > 0) { if (agvDetail.currentLoad === agvDetail.point.action.loadCapacity && agvDetail.currentMaterials.length > 0) {
if (agvDetail.point.action.pickUpPoint && agvDetail.point.action.unLoadPoint) { if (agvDetail.point.action.pickUpPoint && agvDetail.point.action.unLoadPoint) {
const toDrop = computePath( const toDrop = computePath(
@ -135,17 +134,44 @@ function VehicleInstance({ agvDetail }: { agvDetail: VehicleStatus }) {
} }
function startUnloadingProcess() { function startUnloadingProcess() {
const droppedMaterial = agvDetail.currentLoad; if (agvDetail.point.action.triggers.length > 0) {
startTime = performance.now(); const trigger = getTriggerByUuid(selectedProduct.productId, agvDetail.point.action.triggers[0].triggerUuid);
handleMaterialDrop(droppedMaterial); const model = getEventByModelUuid(selectedProduct.productId, trigger?.triggeredAsset?.triggeredModel?.modelUuid || '');
if (trigger && model) {
if (model.type === 'transfer') {
const action = getActionByUuid(selectedProduct.productId, agvDetail.point.action.actionUuid);
if (action) {
triggerPointActions(action);
}
} else if (model.type === 'machine') {
} else if (model.type === 'roboticArm') {
} else if (model.type === 'storageUnit') {
}
} else {
const droppedMaterial = agvDetail.currentLoad;
startTime = performance.now();
handleMaterialDropByDefault(droppedMaterial);
}
} else {
const droppedMaterial = agvDetail.currentLoad;
startTime = performance.now();
handleMaterialDropByDefault(droppedMaterial);
}
} }
function handleMaterialDrop(droppedMaterial: number) { function handleMaterialDropToConveyor() { }
function handleMaterialDropByDefault(droppedMaterial: number) {
if (isPausedRef.current) { if (isPausedRef.current) {
if (!pauseTimeRef.current) { if (!pauseTimeRef.current) {
pauseTimeRef.current = performance.now(); pauseTimeRef.current = performance.now();
} }
requestAnimationFrame(() => handleMaterialDrop(droppedMaterial)); requestAnimationFrame(() => handleMaterialDropByDefault(droppedMaterial));
return; return;
} }
@ -168,16 +194,15 @@ function VehicleInstance({ agvDetail }: { agvDetail: VehicleStatus }) {
} }
if (droppedMat > 0) { if (droppedMat > 0) {
startTime = performance.now(); startTime = performance.now();
requestAnimationFrame(() => handleMaterialDrop(droppedMat)); requestAnimationFrame(() => handleMaterialDropByDefault(droppedMat));
} else { } else {
return; return;
} }
} else { } else {
requestAnimationFrame(() => handleMaterialDrop(droppedMaterial)); requestAnimationFrame(() => handleMaterialDropByDefault(droppedMaterial));
} }
} }
return ( return (
<> <>
<VehicleAnimator <VehicleAnimator

View File

@ -7,6 +7,7 @@ export default function ZoneAssets() {
const { zoneAssetId, setZoneAssetId } = useZoneAssetId(); const { zoneAssetId, setZoneAssetId } = useZoneAssetId();
const { setSelectedFloorItem } = useSelectedFloorItem(); const { setSelectedFloorItem } = useSelectedFloorItem();
const { raycaster, controls, scene }: any = useThree(); const { raycaster, controls, scene }: any = useThree();
useEffect(() => { useEffect(() => {
// console.log('zoneAssetId: ', zoneAssetId); // console.log('zoneAssetId: ', zoneAssetId);
if (!zoneAssetId) return if (!zoneAssetId) return
@ -70,8 +71,6 @@ export default function ZoneAssets() {
} }
}, [zoneAssetId, scene, controls]) }, [zoneAssetId, scene, controls])
return ( return (
<> <>
</> </>

View File

@ -13,8 +13,6 @@ export default function ZoneCentreTarget() {
const { zoneTarget, setZoneTarget } = usezoneTarget(); const { zoneTarget, setZoneTarget } = usezoneTarget();
const { Edit, setEdit } = useEditPosition(); const { Edit, setEdit } = useEditPosition();
useEffect(() => { useEffect(() => {
if ( if (
selectedZone.zoneViewPortTarget && selectedZone.zoneViewPortTarget &&

View File

@ -66,6 +66,11 @@ export const useWalls = create<any>((set: any) => ({
setWalls: (x: any) => set(() => ({ walls: x })), setWalls: (x: any) => set(() => ({ walls: x })),
})); }));
export const useRoomsState = create<any>((set: any) => ({
roomsState: [],
setRoomsState: (x: any) => set(() => ({ walls: x })),
}));
export const useZones = create<any>((set: any) => ({ export const useZones = create<any>((set: any) => ({
zones: [], zones: [],
setZones: (callback: any) => setZones: (callback: any) =>