From e92345d820b2f6a5469a15b591f4a5df419b73a2 Mon Sep 17 00:00:00 2001 From: Jerald-Golden-B Date: Sat, 5 Apr 2025 10:12:28 +0530 Subject: [PATCH] Refactor simulation paths to simulation states - Updated all instances of `simulationPaths` to `simulationStates` across multiple components including copyPasteControls, duplicationControls, moveControls, rotateControls, selectionControls, and others. - Adjusted related state management hooks in the store to reflect the change from `simulationPaths` to `simulationStates`. - Ensured that all references to simulation paths in the simulation logic and UI components are consistent with the new naming convention. --- .../mechanics/ConveyorMechanics.tsx | 60 ++--- .../mechanics/VehicleMechanics.tsx | 20 +- app/src/components/ui/list/List.tsx | 1 - app/src/modules/builder/agv/agv.tsx | 228 ++++++------------ .../geomentries/assets/addAssetModel.ts | 14 +- .../geomentries/assets/deleteFloorItems.ts | 4 +- .../builder/groups/floorItemsGroup.tsx | 12 +- .../scene/IntialLoad/loadInitialFloorItems.ts | 20 +- .../controls/selection/copyPasteControls.tsx | 10 +- .../selection/duplicationControls.tsx | 10 +- .../scene/controls/selection/moveControls.tsx | 10 +- .../controls/selection/rotateControls.tsx | 10 +- .../controls/selection/selectionControls.tsx | 6 +- .../simulation/behaviour/behaviour.tsx | 6 +- .../modules/simulation/path/pathConnector.tsx | 34 +-- .../modules/simulation/path/pathCreation.tsx | 16 +- .../simulation/process/processCreator.tsx | 20 +- app/src/modules/simulation/simulation.tsx | 8 +- app/src/modules/simulation/simulationUI.tsx | 56 ++--- .../simulationtemp/path/pathCreator.tsx | 28 +-- .../simulation/simulationtemp/simulation.tsx | 6 +- app/src/store/store.ts | 14 +- 22 files changed, 260 insertions(+), 333 deletions(-) diff --git a/app/src/components/layout/sidebarRight/mechanics/ConveyorMechanics.tsx b/app/src/components/layout/sidebarRight/mechanics/ConveyorMechanics.tsx index 8ad0886..fd64db9 100644 --- a/app/src/components/layout/sidebarRight/mechanics/ConveyorMechanics.tsx +++ b/app/src/components/layout/sidebarRight/mechanics/ConveyorMechanics.tsx @@ -13,7 +13,7 @@ import { useFloorItems, useSelectedActionSphere, useSelectedPath, - useSimulationPaths, + useSimulationStates, useSocketStore, } from "../../../../store/store"; import * as THREE from "three"; @@ -25,7 +25,7 @@ import { setEventApi } from "../../../../services/factoryBuilder/assest/floorAss const ConveyorMechanics: React.FC = () => { const { selectedActionSphere } = useSelectedActionSphere(); const { selectedPath, setSelectedPath } = useSelectedPath(); - const { simulationPaths, setSimulationPaths } = useSimulationPaths(); + const { simulationStates, setSimulationStates } = useSimulationStates(); const { floorItems, setFloorItems } = useFloorItems(); const { socket } = useSocketStore(); @@ -34,13 +34,13 @@ const ConveyorMechanics: React.FC = () => { const selectedPoint = useMemo(() => { if (!selectedActionSphere) return null; - return simulationPaths + return simulationStates .filter( (path): path is Types.ConveyorEventsSchema => path.type === "Conveyor" ) .flatMap((path) => path.points) .find((point) => point.uuid === selectedActionSphere.points.uuid); - }, [selectedActionSphere, simulationPaths]); + }, [selectedActionSphere, simulationStates]); const updateBackend = async (updatedPath: Types.ConveyorEventsSchema | undefined) => { if (!updatedPath) return; @@ -66,7 +66,7 @@ const ConveyorMechanics: React.FC = () => { const handleAddAction = () => { if (!selectedActionSphere) return; - const updatedPaths = simulationPaths.map((path) => { + const updatedPaths = simulationStates.map((path) => { if (path.type === "Conveyor") { return { ...path, @@ -101,13 +101,13 @@ const ConveyorMechanics: React.FC = () => { ); updateBackend(updatedPath); - setSimulationPaths(updatedPaths); + setSimulationStates(updatedPaths); }; const handleDeleteAction = (uuid: string) => { if (!selectedActionSphere) return; - const updatedPaths = simulationPaths.map((path) => + const updatedPaths = simulationStates.map((path) => path.type === "Conveyor" ? { ...path, @@ -134,13 +134,13 @@ const ConveyorMechanics: React.FC = () => { ); updateBackend(updatedPath); - setSimulationPaths(updatedPaths); + setSimulationStates(updatedPaths); }; const handleActionSelect = (uuid: string, actionType: string) => { if (!selectedActionSphere) return; - const updatedPaths = simulationPaths.map((path) => + const updatedPaths = simulationStates.map((path) => path.type === "Conveyor" ? { ...path, @@ -182,7 +182,7 @@ const ConveyorMechanics: React.FC = () => { ); updateBackend(updatedPath); - setSimulationPaths(updatedPaths); + setSimulationStates(updatedPaths); // Update the selected item to reflect changes if (selectedItem?.type === "action" && selectedItem.item.uuid === uuid) { @@ -207,7 +207,7 @@ const ConveyorMechanics: React.FC = () => { const handleMaterialSelect = (uuid: string, material: string) => { if (!selectedActionSphere) return; - const updatedPaths = simulationPaths.map((path) => + const updatedPaths = simulationStates.map((path) => path.type === "Conveyor" ? { ...path, @@ -237,7 +237,7 @@ const ConveyorMechanics: React.FC = () => { ); updateBackend(updatedPath); - setSimulationPaths(updatedPaths); + setSimulationStates(updatedPaths); // Update selected item if it's the current action if (selectedItem?.type === "action" && selectedItem.item.uuid === uuid) { @@ -254,7 +254,7 @@ const ConveyorMechanics: React.FC = () => { const handleDelayChange = (uuid: string, delay: number | string) => { if (!selectedActionSphere) return; - const updatedPaths = simulationPaths.map((path) => + const updatedPaths = simulationStates.map((path) => path.type === "Conveyor" ? { ...path, @@ -281,7 +281,7 @@ const ConveyorMechanics: React.FC = () => { ); updateBackend(updatedPath); - setSimulationPaths(updatedPaths); + setSimulationStates(updatedPaths); }; const handleSpawnIntervalChange = ( @@ -290,7 +290,7 @@ const ConveyorMechanics: React.FC = () => { ) => { if (!selectedActionSphere) return; - const updatedPaths = simulationPaths.map((path) => + const updatedPaths = simulationStates.map((path) => path.type === "Conveyor" ? { ...path, @@ -319,13 +319,13 @@ const ConveyorMechanics: React.FC = () => { ); updateBackend(updatedPath); - setSimulationPaths(updatedPaths); + setSimulationStates(updatedPaths); }; const handleSpeedChange = (speed: number | string) => { if (!selectedPath) return; - const updatedPaths = simulationPaths.map((path) => + const updatedPaths = simulationStates.map((path) => path.modeluuid === selectedPath.path.modeluuid ? { ...path, speed } : path ); @@ -338,14 +338,14 @@ const ConveyorMechanics: React.FC = () => { ); updateBackend(updatedPath); - setSimulationPaths(updatedPaths); + setSimulationStates(updatedPaths); setSelectedPath({ ...selectedPath, path: { ...selectedPath.path, speed } }); }; const handleAddTrigger = () => { if (!selectedActionSphere) return; - const updatedPaths = simulationPaths.map((path) => + const updatedPaths = simulationStates.map((path) => path.type === "Conveyor" ? { ...path, @@ -377,13 +377,13 @@ const ConveyorMechanics: React.FC = () => { ); updateBackend(updatedPath); - setSimulationPaths(updatedPaths); + setSimulationStates(updatedPaths); }; const handleDeleteTrigger = (uuid: string) => { if (!selectedActionSphere) return; - const updatedPaths = simulationPaths.map((path) => + const updatedPaths = simulationStates.map((path) => path.type === "Conveyor" ? { ...path, @@ -410,13 +410,13 @@ const ConveyorMechanics: React.FC = () => { ); updateBackend(updatedPath); - setSimulationPaths(updatedPaths); + setSimulationStates(updatedPaths); }; const handleTriggerSelect = (uuid: string, triggerType: string) => { if (!selectedActionSphere) return; - const updatedPaths = simulationPaths.map((path) => + const updatedPaths = simulationStates.map((path) => path.type === "Conveyor" ? { ...path, @@ -445,7 +445,7 @@ const ConveyorMechanics: React.FC = () => { ); updateBackend(updatedPath); - setSimulationPaths(updatedPaths); + setSimulationStates(updatedPaths); // Ensure the selectedItem is updated immediately const updatedTrigger = updatedPaths @@ -461,7 +461,7 @@ const ConveyorMechanics: React.FC = () => { // Update the toggle handlers to immediately update the selected item const handleActionToggle = (uuid: string) => { if (!selectedActionSphere) return; - const updatedPaths = simulationPaths.map((path) => + const updatedPaths = simulationStates.map((path) => path.type === "Conveyor" ? { ...path, @@ -489,7 +489,7 @@ const ConveyorMechanics: React.FC = () => { ); updateBackend(updatedPath); - setSimulationPaths(updatedPaths); + setSimulationStates(updatedPaths); // Immediately update the selected item if it's the one being toggled if (selectedItem?.type === "action" && selectedItem.item.uuid === uuid) { @@ -507,7 +507,7 @@ const ConveyorMechanics: React.FC = () => { const handleTriggerToggle = (uuid: string) => { if (!selectedActionSphere) return; - const updatedPaths = simulationPaths.map((path) => + const updatedPaths = simulationStates.map((path) => path.type === "Conveyor" ? { ...path, @@ -535,7 +535,7 @@ const ConveyorMechanics: React.FC = () => { ); updateBackend(updatedPath); - setSimulationPaths(updatedPaths); + setSimulationStates(updatedPaths); // Immediately update the selected item if it's the one being toggled if (selectedItem?.type === "trigger" && selectedItem.item.uuid === uuid) { @@ -552,7 +552,7 @@ const ConveyorMechanics: React.FC = () => { const handleTriggerBufferTimeChange = (uuid: string, bufferTime: number) => { if (!selectedActionSphere) return; - const updatedPaths = simulationPaths.map((path) => + const updatedPaths = simulationStates.map((path) => path.type === "Conveyor" ? { ...path, @@ -581,7 +581,7 @@ const ConveyorMechanics: React.FC = () => { ); updateBackend(updatedPath); - setSimulationPaths(updatedPaths); + setSimulationStates(updatedPaths); // Immediately update selectedItem if it's the currently selected trigger if (selectedItem?.type === "trigger" && selectedItem.item.uuid === uuid) { diff --git a/app/src/components/layout/sidebarRight/mechanics/VehicleMechanics.tsx b/app/src/components/layout/sidebarRight/mechanics/VehicleMechanics.tsx index e9bd6a2..4db77fe 100644 --- a/app/src/components/layout/sidebarRight/mechanics/VehicleMechanics.tsx +++ b/app/src/components/layout/sidebarRight/mechanics/VehicleMechanics.tsx @@ -1,14 +1,14 @@ import React, { useRef, useMemo } from "react"; import { InfoIcon } from "../../../icons/ExportCommonIcons"; import InputWithDropDown from "../../../ui/inputs/InputWithDropDown"; -import { useEditingPoint, useEyeDropMode, usePreviewPosition, useSelectedActionSphere, useSimulationPaths, useSocketStore } from "../../../../store/store"; +import { useEditingPoint, useEyeDropMode, usePreviewPosition, useSelectedActionSphere, useSimulationStates, useSocketStore } from "../../../../store/store"; import * as Types from '../../../../types/world/worldTypes'; import PositionInput from "../customInput/PositionInputs"; import { setEventApi } from "../../../../services/factoryBuilder/assest/floorAsset/setEventsApt"; const VehicleMechanics: React.FC = () => { const { selectedActionSphere } = useSelectedActionSphere(); - const { simulationPaths, setSimulationPaths } = useSimulationPaths(); + const { simulationStates, setSimulationStates } = useSimulationStates(); const { eyeDropMode, setEyeDropMode } = useEyeDropMode(); const { editingPoint, setEditingPoint } = useEditingPoint(); const { previewPosition, setPreviewPosition } = usePreviewPosition(); @@ -19,7 +19,7 @@ const VehicleMechanics: React.FC = () => { const { selectedPoint, connectedPointUuids } = useMemo(() => { if (!selectedActionSphere?.points?.uuid) return { selectedPoint: null, connectedPointUuids: [] }; - const vehiclePaths = simulationPaths.filter( + const vehiclePaths = simulationStates.filter( (path): path is Types.VehicleEventsSchema => path.type === "Vehicle" ); @@ -40,7 +40,7 @@ const VehicleMechanics: React.FC = () => { selectedPoint: points, connectedPointUuids: connectedUuids }; - }, [selectedActionSphere, simulationPaths]); + }, [selectedActionSphere, simulationStates]); const updateBackend = async (updatedPath: Types.VehicleEventsSchema | undefined) => { if (!updatedPath) return; @@ -66,7 +66,7 @@ const VehicleMechanics: React.FC = () => { const handleActionUpdate = React.useCallback((updatedAction: Partial) => { if (!selectedActionSphere?.points?.uuid) return; - const updatedPaths = simulationPaths.map((path) => { + const updatedPaths = simulationStates.map((path) => { if (path.type === "Vehicle" && path.points.uuid === selectedActionSphere.points.uuid) { return { ...path, @@ -89,8 +89,8 @@ const VehicleMechanics: React.FC = () => { ); updateBackend(updatedPath); - setSimulationPaths(updatedPaths); - }, [selectedActionSphere?.points?.uuid, simulationPaths, setSimulationPaths]); + setSimulationStates(updatedPaths); + }, [selectedActionSphere?.points?.uuid, simulationStates, setSimulationStates]); const handleHitCountChange = React.useCallback((hitCount: number) => { handleActionUpdate({ hitCount }); @@ -103,7 +103,7 @@ const VehicleMechanics: React.FC = () => { const handleSpeedChange = React.useCallback((speed: number) => { if (!selectedActionSphere?.points?.uuid) return; - const updatedPaths = simulationPaths.map((path) => { + const updatedPaths = simulationStates.map((path) => { if (path.type === "Vehicle" && path.points.uuid === selectedActionSphere.points.uuid) { return { ...path, @@ -123,8 +123,8 @@ const VehicleMechanics: React.FC = () => { ); updateBackend(updatedPath); - setSimulationPaths(updatedPaths); - }, [selectedActionSphere?.points?.uuid, simulationPaths, setSimulationPaths]); + setSimulationStates(updatedPaths); + }, [selectedActionSphere?.points?.uuid, simulationStates, setSimulationStates]); const handleStartEyeDropClick = () => { setEditingPoint('start'); diff --git a/app/src/components/ui/list/List.tsx b/app/src/components/ui/list/List.tsx index 7629730..000bc20 100644 --- a/app/src/components/ui/list/List.tsx +++ b/app/src/components/ui/list/List.tsx @@ -31,7 +31,6 @@ interface ListProps { } const List: React.FC = ({ items = [], remove }) => { - console.log("items: ", items); const { activeModule, setActiveModule } = useModuleStore(); const { selectedZone, setSelectedZone } = useSelectedZoneStore(); const { setSubModule } = useSubModuleStore(); diff --git a/app/src/modules/builder/agv/agv.tsx b/app/src/modules/builder/agv/agv.tsx index 24003ea..ad8fcd5 100644 --- a/app/src/modules/builder/agv/agv.tsx +++ b/app/src/modules/builder/agv/agv.tsx @@ -1,163 +1,91 @@ +import { useEffect, useRef, useState } from "react"; +import { useSimulationStates } from "../../../store/store"; import PolygonGenerator from "./polygonGenerator"; -import { useThree } from "@react-three/fiber"; -import { useEffect, useMemo, useRef, useState } from "react"; -import * as THREE from "three"; -import * as Types from "../../../types/world/worldTypes"; import PathNavigator from "./pathNavigator"; import NavMeshDetails from "./navMeshDetails"; -import { - useSelectedActionSphere, - useSimulationPaths, -} from "../../../store/store"; import * as CONSTANTS from "../../../types/world/worldConstants"; +import * as Types from "../../../types/world/worldTypes"; -const Agv = ({ - lines, -}: { - lines: Types.RefLines; -}) => { - const [pathPoints, setPathPoints] = useState< - { - modelUuid: string; - modelSpeed: number; - bufferTime: number; - points: { x: number; y: number; z: number }[]; - hitCount: number; - }[] - >([]); - const { simulationPaths } = useSimulationPaths(); - const { selectedActionSphere } = useSelectedActionSphere(); - useEffect(() => { - if (!Array.isArray(simulationPaths)) { - } else { - let agvModels = simulationPaths.filter( - (val: any) => val.modelName === "agv" - ); +type AgvProps = { + lines: Types.RefLines +}; - - let findMesh = agvModels.filter( - (val: any) => - val.modeluuid === selectedActionSphere?.path?.modeluuid && - val.type === "Vehicle" - ); +type PathPoints = { + modelUuid: string; + modelSpeed: number; + bufferTime: number; + points: { x: number; y: number; z: number }[]; + hitCount: number; +}; - const result = - findMesh.length > 0 && - findMesh[0].type === "Vehicle" && - typeof findMesh[0].points?.actions.start === "object" && - typeof findMesh[0].points?.actions.end === "object" && - "x" in findMesh[0].points.actions.start && - "y" in findMesh[0].points.actions.start && - "x" in findMesh[0].points.actions.end && - "y" in findMesh[0].points.actions.end - ? [ - { - modelUuid: findMesh[0].modeluuid, // Ensure it's a number - modelSpeed: findMesh[0].points.speed, - bufferTime: findMesh[0].points.actions.buffer, - hitCount: findMesh[0].points.actions.hitCount, - points: [ - { - x: findMesh[0].position[0], - y: findMesh[0].position[1], - z: findMesh[0].position[2], - }, - { - x: findMesh[0].points.actions.start.x, - y: 0, - z: findMesh[0].points.actions.start.y, - }, - { - x: findMesh[0].points.actions.end.x, - y: 0, - z: findMesh[0].points.actions.end.y, - }, - ], - }, - ] - : []; - if (result.length > 0) { - // setPathPoints((prev) => [...prev, ...result]); - setPathPoints((prev) => { - const existingIndex = prev.findIndex( - (item) => item.modelUuid === result[0].modelUuid - ); +const Agv = ({ lines }: AgvProps) => { - if (existingIndex !== -1) { - const updatedPathPoints = [...prev]; - updatedPathPoints[existingIndex] = result[0]; - return updatedPathPoints; - } else { - return [...prev, ...result]; - } - }); - } - } - // setPathPoints((prev) => { - // const existingUUIDs = new Set(prev.map((item) => item.uuid)); - // const newItems = result.filter( - // (item) => !existingUUIDs.has(item.uuid) - // ); - // return [...prev, ...newItems]; - // }); - }, [simulationPaths, selectedActionSphere]); + let groupRef = useRef() as Types.RefGroup; + const [pathPoints, setPathPoints] = useState([]); + const { simulationStates } = useSimulationStates(); + const [navMesh, setNavMesh] = useState(); - let groupRef = useRef() as Types.RefGroup; - const [navMesh, setNavMesh] = useState(); + useEffect(() => { + if (simulationStates.length > 0) { - return ( - <> - - - {pathPoints.map((pair, i) => ( - <> - - {/* {pair.points.length > 2 && ( - <> - - - - - - - - - - )} */} - - ))} - - - - - - - - ); + 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; diff --git a/app/src/modules/builder/geomentries/assets/addAssetModel.ts b/app/src/modules/builder/geomentries/assets/addAssetModel.ts index 91c1f12..98aa8fd 100644 --- a/app/src/modules/builder/geomentries/assets/addAssetModel.ts +++ b/app/src/modules/builder/geomentries/assets/addAssetModel.ts @@ -24,7 +24,7 @@ async function addAssetModel( socket: Socket, selectedItem: any, setSelectedItem: any, - setSimulationPaths: any, + setSimulationStates: any, plane: Types.RefMesh, ): Promise { @@ -65,7 +65,7 @@ async function addAssetModel( const cachedModel = THREE.Cache.get(selectedItem.id); if (cachedModel) { // console.log(`[Cache] Fetching ${selectedItem.name}`); - handleModelLoad(cachedModel, intersectPoint!, selectedItem, itemsGroup, tempLoader, isTempLoader, setFloorItems, setSimulationPaths, socket); + handleModelLoad(cachedModel, intersectPoint!, selectedItem, itemsGroup, tempLoader, isTempLoader, setFloorItems, setSimulationStates, socket); return; } else { const cachedModelBlob = await retrieveGLTF(selectedItem.id); @@ -78,7 +78,7 @@ async function addAssetModel( URL.revokeObjectURL(blobUrl); THREE.Cache.remove(blobUrl); THREE.Cache.add(selectedItem.id, gltf); - handleModelLoad(gltf, intersectPoint!, selectedItem, itemsGroup, tempLoader, isTempLoader, setFloorItems, setSimulationPaths, socket); + handleModelLoad(gltf, intersectPoint!, selectedItem, itemsGroup, tempLoader, isTempLoader, setFloorItems, setSimulationStates, socket); }, () => { TempLoader(intersectPoint!, isTempLoader, tempLoader, itemsGroup); @@ -90,7 +90,7 @@ async function addAssetModel( const modelBlob = await fetch(`${url_Backend_dwinzo}/api/v1/AssetFile/${selectedItem.id}`).then((res) => res.blob()); await storeGLTF(selectedItem.id, modelBlob); THREE.Cache.add(selectedItem.id, gltf); - await handleModelLoad(gltf, intersectPoint!, selectedItem, itemsGroup, tempLoader, isTempLoader, setFloorItems, setSimulationPaths, socket); + await handleModelLoad(gltf, intersectPoint!, selectedItem, itemsGroup, tempLoader, isTempLoader, setFloorItems, setSimulationStates, socket); }, () => { TempLoader(intersectPoint!, isTempLoader, tempLoader, itemsGroup); @@ -113,7 +113,7 @@ async function handleModelLoad( tempLoader: Types.RefMesh, isTempLoader: Types.RefBoolean, setFloorItems: Types.setFloorItemSetState, - setSimulationPaths: any, + setSimulationStates: any, socket: Socket ) { const model = gltf.scene.clone(); @@ -219,7 +219,7 @@ async function handleModelLoad( eventData.position = newFloorItem.position; eventData.rotation = [model.rotation.x, model.rotation.y, model.rotation.z]; - setSimulationPaths((prevEvents: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[]) => [ + setSimulationStates((prevEvents: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[]) => [ ...(prevEvents || []), eventData as Types.ConveyorEventsSchema ]); @@ -281,7 +281,7 @@ async function handleModelLoad( return updatedItems; }); - setSimulationPaths((prevEvents: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[]) => [ + setSimulationStates((prevEvents: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[]) => [ ...(prevEvents || []), eventData as Types.VehicleEventsSchema ]); diff --git a/app/src/modules/builder/geomentries/assets/deleteFloorItems.ts b/app/src/modules/builder/geomentries/assets/deleteFloorItems.ts index a71aaea..86500c5 100644 --- a/app/src/modules/builder/geomentries/assets/deleteFloorItems.ts +++ b/app/src/modules/builder/geomentries/assets/deleteFloorItems.ts @@ -10,7 +10,7 @@ async function DeleteFloorItems( itemsGroup: Types.RefGroup, hoveredDeletableFloorItem: Types.RefMesh, setFloorItems: Types.setFloorItemSetState, - setSimulationPaths: any, + setSimulationStates: any, socket: Socket ): Promise { @@ -76,7 +76,7 @@ async function DeleteFloorItems( } setFloorItems(updatedItems); - setSimulationPaths((prevEvents: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[]) => { + setSimulationStates((prevEvents: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[]) => { const updatedEvents = (prevEvents || []).filter(event => event.modeluuid !== removedItem.modeluuid); return updatedEvents; }); diff --git a/app/src/modules/builder/groups/floorItemsGroup.tsx b/app/src/modules/builder/groups/floorItemsGroup.tsx index cef7d74..96f4fad 100644 --- a/app/src/modules/builder/groups/floorItemsGroup.tsx +++ b/app/src/modules/builder/groups/floorItemsGroup.tsx @@ -10,7 +10,7 @@ import { useRenderDistance, useselectedFloorItem, useSelectedItem, - useSimulationPaths, + useSimulationStates, useSocketStore, useToggleView, useTransformMode, @@ -65,7 +65,7 @@ const FloorItemsGroup = ({ const { setselectedFloorItem } = useselectedFloorItem(); const { activeTool } = useActiveTool(); const { selectedItem, setSelectedItem } = useSelectedItem(); - const { simulationPaths, setSimulationPaths } = useSimulationPaths(); + const { simulationStates, setSimulationStates } = useSimulationStates(); const { setLoadingProgress } = useLoadingProgress(); const { activeModule } = useModuleStore(); const { socket } = useSocketStore(); @@ -111,7 +111,7 @@ const FloorItemsGroup = ({ gltfLoaderWorker.postMessage({ floorItems: data }); } else { gltfLoaderWorker.postMessage({ floorItems: [] }); - loadInitialFloorItems(itemsGroup, setFloorItems, setSimulationPaths); + loadInitialFloorItems(itemsGroup, setFloorItems, setSimulationStates); updateLoadingProgress(100); } }); @@ -130,7 +130,7 @@ const FloorItemsGroup = ({ updateLoadingProgress(progress); if (loadedAssets === totalAssets) { - loadInitialFloorItems(itemsGroup, setFloorItems, setSimulationPaths); + loadInitialFloorItems(itemsGroup, setFloorItems, setSimulationStates); updateLoadingProgress(100); } }); @@ -248,7 +248,7 @@ const FloorItemsGroup = ({ itemsGroup, hoveredDeletableFloorItem, setFloorItems, - setSimulationPaths, + setSimulationStates, socket ); } @@ -374,7 +374,7 @@ const FloorItemsGroup = ({ socket, selectedItem, setSelectedItem, - setSimulationPaths, + setSimulationStates, plane ); } diff --git a/app/src/modules/scene/IntialLoad/loadInitialFloorItems.ts b/app/src/modules/scene/IntialLoad/loadInitialFloorItems.ts index 5dd41de..3f68568 100644 --- a/app/src/modules/scene/IntialLoad/loadInitialFloorItems.ts +++ b/app/src/modules/scene/IntialLoad/loadInitialFloorItems.ts @@ -12,7 +12,7 @@ import { getFloorAssets } from '../../../services/factoryBuilder/assest/floorAss async function loadInitialFloorItems( itemsGroup: Types.RefGroup, setFloorItems: Types.setFloorItemSetState, - setSimulationPaths: (paths: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[]) => void + setSimulationStates: (paths: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[]) => void ): Promise { if (!itemsGroup.current) return; let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_MARKETPLACE_URL}`; @@ -71,7 +71,7 @@ async function loadInitialFloorItems( const cachedModel = THREE.Cache.get(item.modelfileID!); if (cachedModel) { // console.log(`[Cache] Fetching ${item.modelname}`); - processLoadedModel(cachedModel.scene.clone(), item, itemsGroup, setFloorItems, setSimulationPaths); + processLoadedModel(cachedModel.scene.clone(), item, itemsGroup, setFloorItems, setSimulationStates); modelsLoaded++; checkLoadingCompletion(modelsLoaded, modelsToLoad, dracoLoader, resolve); return; @@ -88,7 +88,7 @@ async function loadInitialFloorItems( URL.revokeObjectURL(blobUrl); THREE.Cache.remove(blobUrl); THREE.Cache.add(item.modelfileID!, gltf); - processLoadedModel(gltf.scene.clone(), item, itemsGroup, setFloorItems, setSimulationPaths); + processLoadedModel(gltf.scene.clone(), item, itemsGroup, setFloorItems, setSimulationStates); modelsLoaded++; checkLoadingCompletion(modelsLoaded, modelsToLoad, dracoLoader, resolve); }, @@ -111,7 +111,7 @@ async function loadInitialFloorItems( const modelBlob = await fetch(modelUrl).then((res) => res.blob()); await storeGLTF(item.modelfileID!, modelBlob); THREE.Cache.add(item.modelfileID!, gltf); - processLoadedModel(gltf.scene.clone(), item, itemsGroup, setFloorItems, setSimulationPaths); + processLoadedModel(gltf.scene.clone(), item, itemsGroup, setFloorItems, setSimulationStates); modelsLoaded++; checkLoadingCompletion(modelsLoaded, modelsToLoad, dracoLoader, resolve); }, @@ -138,7 +138,7 @@ async function loadInitialFloorItems( ]); if (item.eventData) { - processEventData(item, setSimulationPaths); + processEventData(item, setSimulationStates); } modelsLoaded++; @@ -157,7 +157,7 @@ function processLoadedModel( item: Types.EventData, itemsGroup: Types.RefGroup, setFloorItems: Types.setFloorItemSetState, - setSimulationPaths: (paths: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[]) => void + setSimulationStates: (paths: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[]) => void ) { const model = gltf; model.uuid = item.modeluuid; @@ -193,14 +193,14 @@ function processLoadedModel( ]); if (item.eventData) { - processEventData(item, setSimulationPaths); + processEventData(item, setSimulationStates); } gsap.to(model.position, { y: item.position[1], duration: 1.5, ease: 'power2.out' }); gsap.to(model.scale, { x: 1, y: 1, z: 1, duration: 1.5, ease: 'power2.out' }); } -function processEventData(item: Types.EventData, setSimulationPaths: any) { +function processEventData(item: Types.EventData, setSimulationStates: any) { if (item.eventData?.type === 'Conveyor') { @@ -210,7 +210,7 @@ function processEventData(item: Types.EventData, setSimulationPaths: any) { data.position = item.position; data.rotation = [item.rotation.x, item.rotation.y, item.rotation.z]; - setSimulationPaths((prevEvents: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[]) => [ + setSimulationStates((prevEvents: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[]) => [ ...(prevEvents || []), data as Types.ConveyorEventsSchema ]); @@ -222,7 +222,7 @@ function processEventData(item: Types.EventData, setSimulationPaths: any) { data.modelName = item.modelname; data.position = item.position; - setSimulationPaths((prevEvents: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[]) => [ + setSimulationStates((prevEvents: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[]) => [ ...(prevEvents || []), data as Types.VehicleEventsSchema ]); diff --git a/app/src/modules/scene/controls/selection/copyPasteControls.tsx b/app/src/modules/scene/controls/selection/copyPasteControls.tsx index abcc1b0..25434f6 100644 --- a/app/src/modules/scene/controls/selection/copyPasteControls.tsx +++ b/app/src/modules/scene/controls/selection/copyPasteControls.tsx @@ -1,7 +1,7 @@ import * as THREE from "three"; import { useEffect, useMemo } from "react"; import { useFrame, useThree } from "@react-three/fiber"; -import { useFloorItems, useSelectedAssets, useSimulationPaths, useSocketStore, useToggleView } from "../../../../store/store"; +import { useFloorItems, useSelectedAssets, useSimulationStates, useSocketStore, useToggleView } from "../../../../store/store"; import { toast } from "react-toastify"; // import { setFloorItemApi } from '../../../../services/factoryBuilder/assest/floorAsset/setFloorItemApi'; import * as Types from "../../../../types/world/worldTypes"; @@ -10,7 +10,7 @@ const CopyPasteControls = ({ itemsGroupRef, copiedObjects, setCopiedObjects, pas const { camera, controls, gl, scene, pointer, raycaster } = useThree(); const { toggleView } = useToggleView(); const { selectedAssets, setSelectedAssets } = useSelectedAssets(); - const { simulationPaths, setSimulationPaths } = useSimulationPaths(); + const { simulationStates, setSimulationStates } = useSimulationStates(); const plane = useMemo(() => new THREE.Plane(new THREE.Vector3(0, 1, 0), 0), []); const { floorItems, setFloorItems } = useFloorItems(); const { socket } = useSocketStore() @@ -151,7 +151,7 @@ const CopyPasteControls = ({ itemsGroupRef, copiedObjects, setCopiedObjects, pas return updatedItems; }); - let eventData: Types.ConveyorEventsSchema | Types.VehicleEventsSchema | undefined = simulationPaths.find((events) => events.modeluuid === obj.userData.modeluuid); + let eventData: Types.ConveyorEventsSchema | Types.VehicleEventsSchema | undefined = simulationStates.find((events) => events.modeluuid === obj.userData.modeluuid); const email = localStorage.getItem("email"); const organization = email ? email.split("@")[1].split(".")[0] : "default"; @@ -234,7 +234,7 @@ const CopyPasteControls = ({ itemsGroupRef, copiedObjects, setCopiedObjects, pas newEventData.position = newFloorItem.position; newEventData.rotation = [obj.rotation.x, obj.rotation.y, obj.rotation.z]; - setSimulationPaths((prevEvents: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[]) => [ + setSimulationStates((prevEvents: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[]) => [ ...(prevEvents || []), newEventData as Types.ConveyorEventsSchema ]); @@ -314,7 +314,7 @@ const CopyPasteControls = ({ itemsGroupRef, copiedObjects, setCopiedObjects, pas newEventData.modelName = newFloorItem.modelname; newEventData.position = newFloorItem.position; - setSimulationPaths((prevEvents: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[]) => [ + setSimulationStates((prevEvents: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[]) => [ ...(prevEvents || []), newEventData as Types.VehicleEventsSchema ]); diff --git a/app/src/modules/scene/controls/selection/duplicationControls.tsx b/app/src/modules/scene/controls/selection/duplicationControls.tsx index c28c401..4f65f03 100644 --- a/app/src/modules/scene/controls/selection/duplicationControls.tsx +++ b/app/src/modules/scene/controls/selection/duplicationControls.tsx @@ -1,7 +1,7 @@ import * as THREE from "three"; import { useEffect, useMemo } from "react"; import { useFrame, useThree } from "@react-three/fiber"; -import { useFloorItems, useSelectedAssets, useSimulationPaths, useSocketStore, useToggleView } from "../../../../store/store"; +import { useFloorItems, useSelectedAssets, useSimulationStates, useSocketStore, useToggleView } from "../../../../store/store"; import { toast } from "react-toastify"; // import { setFloorItemApi } from '../../../../services/factoryBuilder/assest/floorAsset/setFloorItemApi'; import * as Types from "../../../../types/world/worldTypes"; @@ -11,7 +11,7 @@ const DuplicationControls = ({ itemsGroupRef, duplicatedObjects, setDuplicatedOb const { camera, controls, gl, scene, pointer, raycaster } = useThree(); const { toggleView } = useToggleView(); const { selectedAssets, setSelectedAssets } = useSelectedAssets(); - const { simulationPaths, setSimulationPaths } = useSimulationPaths(); + const { simulationStates, setSimulationStates } = useSimulationStates(); const plane = useMemo(() => new THREE.Plane(new THREE.Vector3(0, 1, 0), 0), []); const { floorItems, setFloorItems } = useFloorItems(); const { socket } = useSocketStore(); @@ -132,7 +132,7 @@ const DuplicationControls = ({ itemsGroupRef, duplicatedObjects, setDuplicatedOb return updatedItems; }); - let eventData: Types.ConveyorEventsSchema | Types.VehicleEventsSchema | undefined = simulationPaths.find((events) => events.modeluuid === obj.userData.modeluuid); + let eventData: Types.ConveyorEventsSchema | Types.VehicleEventsSchema | undefined = simulationStates.find((events) => events.modeluuid === obj.userData.modeluuid); const email = localStorage.getItem("email"); const organization = email ? email.split("@")[1].split(".")[0] : "default"; @@ -216,7 +216,7 @@ const DuplicationControls = ({ itemsGroupRef, duplicatedObjects, setDuplicatedOb newEventData.position = newFloorItem.position; newEventData.rotation = [obj.rotation.x, obj.rotation.y, obj.rotation.z]; - setSimulationPaths((prevEvents: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[]) => [ + setSimulationStates((prevEvents: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[]) => [ ...(prevEvents || []), newEventData as Types.ConveyorEventsSchema ]); @@ -295,7 +295,7 @@ const DuplicationControls = ({ itemsGroupRef, duplicatedObjects, setDuplicatedOb newEventData.modelName = newFloorItem.modelname; newEventData.position = newFloorItem.position; - setSimulationPaths((prevEvents: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[]) => [ + setSimulationStates((prevEvents: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[]) => [ ...(prevEvents || []), newEventData as Types.VehicleEventsSchema ]); diff --git a/app/src/modules/scene/controls/selection/moveControls.tsx b/app/src/modules/scene/controls/selection/moveControls.tsx index a4340b5..d9300b4 100644 --- a/app/src/modules/scene/controls/selection/moveControls.tsx +++ b/app/src/modules/scene/controls/selection/moveControls.tsx @@ -1,7 +1,7 @@ import * as THREE from "three"; import { useEffect, useMemo, useRef, useState } from "react"; import { useFrame, useThree } from "@react-three/fiber"; -import { useFloorItems, useSelectedAssets, useSimulationPaths, useSocketStore, useToggleView } from "../../../../store/store"; +import { useFloorItems, useSelectedAssets, useSimulationStates, useSocketStore, useToggleView } from "../../../../store/store"; // import { setFloorItemApi } from '../../../../services/factoryBuilder/assest/floorAsset/setFloorItemApi'; import { toast } from "react-toastify"; import * as Types from "../../../../types/world/worldTypes"; @@ -12,7 +12,7 @@ function MoveControls({ movedObjects, setMovedObjects, itemsGroupRef, copiedObje const { toggleView } = useToggleView(); const { selectedAssets, setSelectedAssets } = useSelectedAssets(); - const { simulationPaths, setSimulationPaths } = useSimulationPaths(); + const { simulationStates, setSimulationStates } = useSimulationStates(); const { floorItems, setFloorItems } = useFloorItems(); const { socket } = useSocketStore(); const itemsData = useRef([]); @@ -180,7 +180,7 @@ function MoveControls({ movedObjects, setMovedObjects, itemsGroupRef, copiedObje return updatedItems; }); - let eventData: Types.ConveyorEventsSchema | Types.VehicleEventsSchema | undefined = simulationPaths.find((events) => events.modeluuid === obj.userData.modeluuid); + let eventData: Types.ConveyorEventsSchema | Types.VehicleEventsSchema | undefined = simulationStates.find((events) => events.modeluuid === obj.userData.modeluuid); const email = localStorage.getItem("email"); const organization = email ? email.split("@")[1].split(".")[0] : "default"; @@ -229,7 +229,7 @@ function MoveControls({ movedObjects, setMovedObjects, itemsGroupRef, copiedObje newEventData.position = newFloorItem.position; newEventData.rotation = [obj.rotation.x, obj.rotation.y, obj.rotation.z]; - setSimulationPaths((prevEvents: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[]) => { + setSimulationStates((prevEvents: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[]) => { const updatedEvents = (prevEvents || []).map(event => event.modeluuid === newFloorItem.modeluuid ? { ...event, ...newEventData } @@ -280,7 +280,7 @@ function MoveControls({ movedObjects, setMovedObjects, itemsGroupRef, copiedObje newEventData.modelName = newFloorItem.modelname; newEventData.position = newFloorItem.position; - setSimulationPaths((prevEvents: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[]) => { + setSimulationStates((prevEvents: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[]) => { const updatedEvents = (prevEvents || []).map(event => event.modeluuid === newFloorItem.modeluuid ? { ...event, ...newEventData } diff --git a/app/src/modules/scene/controls/selection/rotateControls.tsx b/app/src/modules/scene/controls/selection/rotateControls.tsx index 708a00a..a47d154 100644 --- a/app/src/modules/scene/controls/selection/rotateControls.tsx +++ b/app/src/modules/scene/controls/selection/rotateControls.tsx @@ -1,7 +1,7 @@ import * as THREE from "three"; import { useEffect, useMemo, useRef, useState } from "react"; import { useFrame, useThree } from "@react-three/fiber"; -import { useFloorItems, useSelectedAssets, useSimulationPaths, useSocketStore, useToggleView } from "../../../../store/store"; +import { useFloorItems, useSelectedAssets, useSimulationStates, useSocketStore, useToggleView } from "../../../../store/store"; // import { setFloorItemApi } from '../../../../services/factoryBuilder/assest/floorAsset/setFloorItemApi'; import { toast } from "react-toastify"; import * as Types from "../../../../types/world/worldTypes"; @@ -13,7 +13,7 @@ function RotateControls({ rotatedObjects, setRotatedObjects, movedObjects, setMo const { toggleView } = useToggleView(); const { selectedAssets, setSelectedAssets } = useSelectedAssets(); - const { simulationPaths, setSimulationPaths } = useSimulationPaths(); + const { simulationStates, setSimulationStates } = useSimulationStates(); const { floorItems, setFloorItems } = useFloorItems(); const { socket } = useSocketStore(); const itemsData = useRef([]); @@ -184,7 +184,7 @@ function RotateControls({ rotatedObjects, setRotatedObjects, movedObjects, setMo return updatedItems; }); - let eventData: Types.ConveyorEventsSchema | Types.VehicleEventsSchema | undefined = simulationPaths.find((events) => events.modeluuid === obj.userData.modeluuid); + let eventData: Types.ConveyorEventsSchema | Types.VehicleEventsSchema | undefined = simulationStates.find((events) => events.modeluuid === obj.userData.modeluuid); const email = localStorage.getItem("email"); const organization = email ? email.split("@")[1].split(".")[0] : "default"; @@ -233,7 +233,7 @@ function RotateControls({ rotatedObjects, setRotatedObjects, movedObjects, setMo newEventData.position = newFloorItem.position; newEventData.rotation = [obj.rotation.x, obj.rotation.y, obj.rotation.z]; - setSimulationPaths((prevEvents: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[]) => { + setSimulationStates((prevEvents: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[]) => { const updatedEvents = (prevEvents || []).map(event => event.modeluuid === newFloorItem.modeluuid ? { ...event, ...newEventData } @@ -285,7 +285,7 @@ function RotateControls({ rotatedObjects, setRotatedObjects, movedObjects, setMo newEventData.modelName = newFloorItem.modelname; newEventData.position = newFloorItem.position; - setSimulationPaths((prevEvents: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[]) => { + setSimulationStates((prevEvents: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[]) => { const updatedEvents = (prevEvents || []).map(event => event.modeluuid === newFloorItem.modeluuid ? { ...event, ...newEventData } diff --git a/app/src/modules/scene/controls/selection/selectionControls.tsx b/app/src/modules/scene/controls/selection/selectionControls.tsx index fd7e19e..5a6426c 100644 --- a/app/src/modules/scene/controls/selection/selectionControls.tsx +++ b/app/src/modules/scene/controls/selection/selectionControls.tsx @@ -3,7 +3,7 @@ import { useEffect, useMemo, useRef, useState } from "react"; import { SelectionBox } from "three/examples/jsm/interactive/SelectionBox"; import { SelectionHelper } from "./selectionHelper"; import { useFrame, useThree } from "@react-three/fiber"; -import { useFloorItems, useSelectedAssets, useSimulationPaths, useSocketStore, useToggleView } from "../../../../store/store"; +import { useFloorItems, useSelectedAssets, useSimulationStates, useSocketStore, useToggleView } from "../../../../store/store"; import BoundingBox from "./boundingBoxHelper"; import { toast } from "react-toastify"; // import { deleteFloorItem } from '../../../../services/factoryBuilder/assest/floorAsset/deleteFloorItemApi'; @@ -20,7 +20,7 @@ const SelectionControls: React.FC = () => { const itemsGroupRef = useRef(undefined); const selectionGroup = useRef() as Types.RefGroup; const { toggleView } = useToggleView(); - const { setSimulationPaths } = useSimulationPaths(); + const { setSimulationStates } = useSimulationStates(); const { selectedAssets, setSelectedAssets } = useSelectedAssets(); const [movedObjects, setMovedObjects] = useState([]); const [rotatedObjects, setRotatedObjects] = useState([]); @@ -240,7 +240,7 @@ const SelectionControls: React.FC = () => { } }); - setSimulationPaths((prevEvents: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[]) => { + setSimulationStates((prevEvents: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[]) => { const updatedEvents = (prevEvents || []).filter(event => event.modeluuid !== selectedMesh.uuid); return updatedEvents; }); diff --git a/app/src/modules/simulation/behaviour/behaviour.tsx b/app/src/modules/simulation/behaviour/behaviour.tsx index 27c791f..4c7e1ed 100644 --- a/app/src/modules/simulation/behaviour/behaviour.tsx +++ b/app/src/modules/simulation/behaviour/behaviour.tsx @@ -1,10 +1,10 @@ -import { useFloorItems, useSimulationPaths } from '../../../store/store'; +import { useFloorItems, useSimulationStates } from '../../../store/store'; import * as THREE from 'three'; import * as Types from '../../../types/world/worldTypes'; import { useEffect } from 'react'; function Behaviour() { - const { setSimulationPaths } = useSimulationPaths(); + const { setSimulationStates } = useSimulationStates(); const { floorItems } = useFloorItems(); useEffect(() => { @@ -78,7 +78,7 @@ function Behaviour() { // } // }); - // setSimulationPaths(newPaths); + // setSimulationStates(newPaths); // console.log('floorItems: ', floorItems); }, [floorItems]); diff --git a/app/src/modules/simulation/path/pathConnector.tsx b/app/src/modules/simulation/path/pathConnector.tsx index 3866a10..2769a98 100644 --- a/app/src/modules/simulation/path/pathConnector.tsx +++ b/app/src/modules/simulation/path/pathConnector.tsx @@ -3,7 +3,7 @@ import React, { useEffect, useState } from 'react'; import * as THREE from 'three'; import * as Types from '../../../types/world/worldTypes'; import { QuadraticBezierLine } from '@react-three/drei'; -import { useIsConnecting, useSimulationPaths } from '../../../store/store'; +import { useIsConnecting, useSimulationStates } from '../../../store/store'; import useModuleStore from '../../../store/useModuleStore'; import { usePlayButtonStore } from '../../../store/usePlayButtonStore'; @@ -11,7 +11,7 @@ function PathConnector({ pathsGroupRef }: { pathsGroupRef: React.MutableRefObjec const { activeModule } = useModuleStore(); const { gl, raycaster, scene, pointer, camera } = useThree(); const { setIsConnecting } = useIsConnecting(); - const { simulationPaths, setSimulationPaths } = useSimulationPaths(); + const { simulationStates, setSimulationStates } = useSimulationStates(); const { isPlaying } = usePlayButtonStore(); const [firstSelected, setFirstSelected] = useState<{ @@ -29,7 +29,7 @@ function PathConnector({ pathsGroupRef }: { pathsGroupRef: React.MutableRefObjec toPathUUID: string, toPointUUID: string ) => { - const updatedPaths = simulationPaths.map(path => { + const updatedPaths = simulationStates.map(path => { if (path.type === 'Conveyor') { if (path.modeluuid === fromPathUUID) { return { @@ -99,7 +99,7 @@ function PathConnector({ pathsGroupRef }: { pathsGroupRef: React.MutableRefObjec const existingTargets = path.points.connections.targets || []; // Check if target is a Conveyor - const toPath = simulationPaths.find(p => p.modeluuid === toPathUUID); + const toPath = simulationStates.find(p => p.modeluuid === toPathUUID); if (toPath?.type !== 'Conveyor') { console.log("Vehicle can only connect to Conveyors"); return path; @@ -136,7 +136,7 @@ function PathConnector({ pathsGroupRef }: { pathsGroupRef: React.MutableRefObjec const existingTargets = path.points.connections.targets || []; // Check if source is a Conveyor - const fromPath = simulationPaths.find(p => p.modeluuid === fromPathUUID); + const fromPath = simulationStates.find(p => p.modeluuid === fromPathUUID); if (fromPath?.type !== 'Conveyor') { console.log("Vehicle can only connect to Conveyors"); return path; @@ -169,7 +169,7 @@ function PathConnector({ pathsGroupRef }: { pathsGroupRef: React.MutableRefObjec return path; }); - setSimulationPaths(updatedPaths); + setSimulationStates(updatedPaths); }; const handleAddConnection = (fromPathUUID: string, fromUUID: string, toPathUUID: string, toUUID: string) => { @@ -227,8 +227,8 @@ function PathConnector({ pathsGroupRef }: { pathsGroupRef: React.MutableRefObjec } if (pathUUID) { - const firstPath = simulationPaths.find(p => p.modeluuid === firstSelected?.pathUUID); - const secondPath = simulationPaths.find(p => p.modeluuid === pathUUID); + const firstPath = simulationStates.find(p => p.modeluuid === firstSelected?.pathUUID); + const secondPath = simulationStates.find(p => p.modeluuid === pathUUID); // Prevent vehicle-to-vehicle connections if (firstPath && secondPath && firstPath.type === 'Vehicle' && secondPath.type === 'Vehicle') { @@ -247,7 +247,7 @@ function PathConnector({ pathsGroupRef }: { pathsGroupRef: React.MutableRefObjec // Check if this specific connection already exists const isDuplicateConnection = firstSelected - ? simulationPaths.some(path => { + ? simulationStates.some(path => { if (path.modeluuid === firstSelected.pathUUID) { if (path.type === 'Conveyor') { const point = path.points.find(p => p.uuid === firstSelected.sphereUUID); @@ -281,7 +281,7 @@ function PathConnector({ pathsGroupRef }: { pathsGroupRef: React.MutableRefObjec // For non-Vehicle paths, check if already connected if (intersected.userData.path.type !== 'Vehicle') { - const isAlreadyConnected = simulationPaths.some(path => { + const isAlreadyConnected = simulationStates.some(path => { if (path.type === 'Conveyor') { return path.points.some(point => point.uuid === sphereUUID && @@ -361,7 +361,7 @@ function PathConnector({ pathsGroupRef }: { pathsGroupRef: React.MutableRefObjec canvasElement.removeEventListener("mousemove", onMouseMove); canvasElement.removeEventListener("contextmenu", onContextMenu); }; - }, [camera, scene, raycaster, firstSelected, simulationPaths]); + }, [camera, scene, raycaster, firstSelected, simulationStates]); useFrame(() => { if (firstSelected) { @@ -397,8 +397,8 @@ function PathConnector({ pathsGroupRef }: { pathsGroupRef: React.MutableRefObjec const pathData = sphere.userData.path; const pathUUID = pathData.modeluuid; - const firstPath = simulationPaths.find(p => p.modeluuid === firstSelected.pathUUID); - const secondPath = simulationPaths.find(p => p.modeluuid === pathUUID); + const firstPath = simulationStates.find(p => p.modeluuid === firstSelected.pathUUID); + const secondPath = simulationStates.find(p => p.modeluuid === pathUUID); const isVehicleToVehicle = firstPath?.type === 'Vehicle' && secondPath?.type === 'Vehicle'; // Inside the useFrame hook, where we check for snapped spheres: @@ -413,7 +413,7 @@ function PathConnector({ pathsGroupRef }: { pathsGroupRef: React.MutableRefObjec !firstSelected.isCorner); // Check for duplicate connection (regardless of path type) - const isDuplicateConnection = simulationPaths.some(path => { + const isDuplicateConnection = simulationStates.some(path => { if (path.modeluuid === firstSelected.pathUUID) { if (path.type === 'Conveyor') { const point = path.points.find(p => p.uuid === firstSelected.sphereUUID); @@ -431,7 +431,7 @@ function PathConnector({ pathsGroupRef }: { pathsGroupRef: React.MutableRefObjec // For non-Vehicle paths, check if already connected const isNonVehicleAlreadyConnected = pathData.type !== 'Vehicle' && - simulationPaths.some(path => { + simulationStates.some(path => { if (path.type === 'Conveyor') { return path.points.some(point => point.uuid === sphereUUID && @@ -505,11 +505,11 @@ function PathConnector({ pathsGroupRef }: { pathsGroupRef: React.MutableRefObjec return ( - {simulationPaths.flatMap(path => { + {simulationStates.flatMap(path => { if (path.type === 'Conveyor') { return path.points.flatMap(point => point.connections.targets.map((target, index) => { - const targetPath = simulationPaths.find(p => p.modeluuid === target.pathUUID); + const targetPath = simulationStates.find(p => p.modeluuid === target.pathUUID); if (targetPath?.type === 'Vehicle') return null; const fromSphere = pathsGroupRef.current?.getObjectByProperty('uuid', point.uuid); diff --git a/app/src/modules/simulation/path/pathCreation.tsx b/app/src/modules/simulation/path/pathCreation.tsx index 619a011..bcb167b 100644 --- a/app/src/modules/simulation/path/pathCreation.tsx +++ b/app/src/modules/simulation/path/pathCreation.tsx @@ -10,7 +10,7 @@ import { useRenderDistance, useSelectedActionSphere, useSelectedPath, - useSimulationPaths, + useSimulationStates, } from "../../../store/store"; import { useFrame, useThree } from "@react-three/fiber"; import { useSubModuleStore } from "../../../store/useModuleStore"; @@ -32,7 +32,7 @@ function PathCreation({ const { raycaster, camera, pointer, gl } = useThree(); const plane = useMemo(() => new THREE.Plane(new THREE.Vector3(0, 1, 0), 0), []); const { setSelectedPath } = useSelectedPath(); - const { simulationPaths, setSimulationPaths } = useSimulationPaths(); + const { simulationStates, setSimulationStates } = useSimulationStates(); const { isConnecting } = useIsConnecting(); const groupRefs = useRef<{ [key: string]: THREE.Group }>({}); @@ -71,7 +71,7 @@ function PathCreation({ const updateSimulationPaths = () => { if (!selectedActionSphere) return; - const updatedPaths = simulationPaths.map((path) => { + const updatedPaths = simulationStates.map((path) => { if (path.type === "Conveyor") { return { ...path, @@ -97,7 +97,7 @@ function PathCreation({ return path; }) as Types.ConveyorEventsSchema[]; - setSimulationPaths(updatedPaths); + setSimulationStates(updatedPaths); }; useFrame(() => { @@ -173,7 +173,7 @@ function PathCreation({ z: number ) => { if (!selectedActionSphere?.points?.uuid) return; - const updatedPaths = simulationPaths.map((path) => { + const updatedPaths = simulationStates.map((path) => { if ( path.type === "Vehicle" && @@ -204,12 +204,12 @@ function PathCreation({ ); updateBackend(updatedPath); - setSimulationPaths(updatedPaths); + setSimulationStates(updatedPaths); }; return ( - - {simulationPaths.map((path) => { + + {simulationStates.map((path) => { if (path.type === "Conveyor") { const points = path.points.map( (point) => new THREE.Vector3(...point.position) diff --git a/app/src/modules/simulation/process/processCreator.tsx b/app/src/modules/simulation/process/processCreator.tsx index f089285..83089c9 100644 --- a/app/src/modules/simulation/process/processCreator.tsx +++ b/app/src/modules/simulation/process/processCreator.tsx @@ -5,7 +5,7 @@ // useCallback, // useRef, // } from "react"; -// import { useSimulationPaths } from "../../../store/store"; +// import { useSimulationStates } from "../../../store/store"; // import * as THREE from "three"; // import { useThree } from "@react-three/fiber"; // import { @@ -312,19 +312,19 @@ // const ProcessCreator: React.FC = React.memo( // ({ onProcessesCreated }) => { -// const { simulationPaths } = useSimulationPaths(); +// const { simulationStates } = useSimulationStates(); // const { createProcessesFromPaths } = useProcessCreation(); // const prevPathsRef = useRef([]); // const prevProcessesRef = useRef([]); // const convertedPaths = useMemo((): SimulationPath[] => { -// if (!simulationPaths) return []; -// return simulationPaths.map((path) => +// if (!simulationStates) return []; +// return simulationStates.map((path) => // convertToSimulationPath( // path as ConveyorEventsSchema | VehicleEventsSchema // ) // ); -// }, [simulationPaths]); +// }, [simulationStates]); // const pathsDependency = useMemo(() => { // if (!convertedPaths) return null; @@ -404,7 +404,7 @@ import React, { useCallback, useRef, } from "react"; -import { useSimulationPaths } from "../../../store/store"; +import { useSimulationStates } from "../../../store/store"; import * as THREE from "three"; import { useThree } from "@react-three/fiber"; import { @@ -737,19 +737,19 @@ export function useProcessCreation() { const ProcessCreator: React.FC = React.memo( ({ onProcessesCreated }) => { - const { simulationPaths } = useSimulationPaths(); + const { simulationStates } = useSimulationStates(); const { createProcessesFromPaths } = useProcessCreation(); const prevPathsRef = useRef([]); const prevProcessesRef = useRef([]); const convertedPaths = useMemo((): SimulationPath[] => { - if (!simulationPaths) return []; - return simulationPaths.map((path) => + if (!simulationStates) return []; + return simulationStates.map((path) => convertToSimulationPath( path as ConveyorEventsSchema | VehicleEventsSchema ) ); - }, [simulationPaths]); + }, [simulationStates]); // Enhanced dependency tracking that includes action types const pathsDependency = useMemo(() => { diff --git a/app/src/modules/simulation/simulation.tsx b/app/src/modules/simulation/simulation.tsx index fd8b520..55dda4b 100644 --- a/app/src/modules/simulation/simulation.tsx +++ b/app/src/modules/simulation/simulation.tsx @@ -2,7 +2,7 @@ import { useState, useEffect, useRef, useMemo } from "react"; import { useSelectedActionSphere, useSelectedPath, - useSimulationPaths, + useSimulationStates, } from "../../store/store"; import * as THREE from "three"; import Behaviour from "./behaviour/behaviour"; @@ -15,12 +15,12 @@ import Agv from "../builder/agv/agv"; function Simulation() { const { activeModule } = useModuleStore(); const pathsGroupRef = useRef() as React.MutableRefObject; - const { simulationPaths, setSimulationPaths } = useSimulationPaths(); + const { simulationStates, setSimulationStates } = useSimulationStates(); const [processes, setProcesses] = useState([]); useEffect(() => { - // console.log('simulationPaths: ', simulationPaths); - }, [simulationPaths]); + // console.log('simulationStates: ', simulationStates); + }, [simulationStates]); // useEffect(() => { // if (selectedActionSphere) { diff --git a/app/src/modules/simulation/simulationUI.tsx b/app/src/modules/simulation/simulationUI.tsx index bff2b20..055fb36 100644 --- a/app/src/modules/simulation/simulationUI.tsx +++ b/app/src/modules/simulation/simulationUI.tsx @@ -1,5 +1,5 @@ // import { useMemo, useState } from 'react'; -// import { useSelectedActionSphere, useToggleView, useSimulationPaths, useSelectedPath, useStartSimulation, useDrawMaterialPath } from '../../store/store'; +// import { useSelectedActionSphere, useToggleView, useSimulationStates, useSelectedPath, useStartSimulation, useDrawMaterialPath } from '../../store/store'; // import * as THREE from 'three'; // import useModuleStore from '../../store/useModuleStore'; @@ -9,14 +9,14 @@ // const { startSimulation, setStartSimulation } = useStartSimulation(); // const { selectedActionSphere } = useSelectedActionSphere(); // const { selectedPath, setSelectedPath } = useSelectedPath(); -// const { simulationPaths, setSimulationPaths } = useSimulationPaths(); +// const { simulationStates, setSimulationStates } = useSimulationStates(); // const { drawMaterialPath, setDrawMaterialPath } = useDrawMaterialPath(); // const [activeButton, setActiveButton] = useState(null); // const handleAddAction = () => { // if (!selectedActionSphere) return; -// const updatedPaths = simulationPaths.map((path) => ({ +// const updatedPaths = simulationStates.map((path) => ({ // ...path, // points: path.points.map((point) => { // if (point.uuid === selectedActionSphere.points.uuid) { @@ -37,13 +37,13 @@ // }), // })); -// setSimulationPaths(updatedPaths); +// setSimulationStates(updatedPaths); // }; // const handleDeleteAction = (uuid: string) => { // if (!selectedActionSphere) return; -// const updatedPaths = simulationPaths.map((path) => ({ +// const updatedPaths = simulationStates.map((path) => ({ // ...path, // points: path.points.map((point) => // point.uuid === selectedActionSphere.points.uuid @@ -52,13 +52,13 @@ // ), // })); -// setSimulationPaths(updatedPaths); +// setSimulationStates(updatedPaths); // }; // const handleActionSelect = (uuid: string, actionType: string) => { // if (!selectedActionSphere) return; -// const updatedPaths = simulationPaths.map((path) => ({ +// const updatedPaths = simulationStates.map((path) => ({ // ...path, // points: path.points.map((point) => // point.uuid === selectedActionSphere.points.uuid @@ -72,13 +72,13 @@ // ), // })); -// setSimulationPaths(updatedPaths); +// setSimulationStates(updatedPaths); // }; // const handleMaterialSelect = (uuid: string, material: string) => { // if (!selectedActionSphere) return; -// const updatedPaths = simulationPaths.map((path) => ({ +// const updatedPaths = simulationStates.map((path) => ({ // ...path, // points: path.points.map((point) => // point.uuid === selectedActionSphere.points.uuid @@ -92,13 +92,13 @@ // ), // })); -// setSimulationPaths(updatedPaths); +// setSimulationStates(updatedPaths); // }; // const handleDelayChange = (uuid: string, delay: number | string) => { // if (!selectedActionSphere) return; -// const updatedPaths = simulationPaths.map((path) => ({ +// const updatedPaths = simulationStates.map((path) => ({ // ...path, // points: path.points.map((point) => // point.uuid === selectedActionSphere.points.uuid @@ -112,13 +112,13 @@ // ), // })); -// setSimulationPaths(updatedPaths); +// setSimulationStates(updatedPaths); // }; // const handleSpawnIntervalChange = (uuid: string, spawnInterval: number | string) => { // if (!selectedActionSphere) return; -// const updatedPaths = simulationPaths.map((path) => ({ +// const updatedPaths = simulationStates.map((path) => ({ // ...path, // points: path.points.map((point) => // point.uuid === selectedActionSphere.points.uuid @@ -132,24 +132,24 @@ // ), // })); -// setSimulationPaths(updatedPaths); +// setSimulationStates(updatedPaths); // }; // const handleSpeedChange = (speed: number) => { // if (!selectedPath) return; -// const updatedPaths = simulationPaths.map((path) => +// const updatedPaths = simulationStates.map((path) => // path.modeluuid === selectedPath.path.modeluuid ? { ...path, speed } : path // ); -// setSimulationPaths(updatedPaths); +// setSimulationStates(updatedPaths); // setSelectedPath({ ...selectedPath, path: { ...selectedPath.path, speed } }); // }; // const handleAddTrigger = () => { // if (!selectedActionSphere) return; -// const updatedPaths = simulationPaths.map((path) => ({ +// const updatedPaths = simulationStates.map((path) => ({ // ...path, // points: path.points.map((point) => { // if (point.uuid === selectedActionSphere.points.uuid) { @@ -167,13 +167,13 @@ // }), // })); -// setSimulationPaths(updatedPaths); +// setSimulationStates(updatedPaths); // }; // const handleDeleteTrigger = (uuid: string) => { // if (!selectedActionSphere) return; -// const updatedPaths = simulationPaths.map((path) => ({ +// const updatedPaths = simulationStates.map((path) => ({ // ...path, // points: path.points.map((point) => // point.uuid === selectedActionSphere.points.uuid @@ -182,13 +182,13 @@ // ), // })); -// setSimulationPaths(updatedPaths); +// setSimulationStates(updatedPaths); // }; // const handleTriggerSelect = (uuid: string, triggerType: string) => { // if (!selectedActionSphere) return; -// const updatedPaths = simulationPaths.map((path) => ({ +// const updatedPaths = simulationStates.map((path) => ({ // ...path, // points: path.points.map((point) => // point.uuid === selectedActionSphere.points.uuid @@ -202,7 +202,7 @@ // ), // })); -// setSimulationPaths(updatedPaths); +// setSimulationStates(updatedPaths); // }; // const handleResetPath = () => { @@ -214,7 +214,7 @@ // const handleActionToggle = (uuid: string) => { // if (!selectedActionSphere) return; -// const updatedPaths = simulationPaths.map((path) => ({ +// const updatedPaths = simulationStates.map((path) => ({ // ...path, // points: path.points.map((point) => // point.uuid === selectedActionSphere.points.uuid @@ -229,13 +229,13 @@ // ), // })); -// setSimulationPaths(updatedPaths); +// setSimulationStates(updatedPaths); // }; // const handleTriggerToggle = (uuid: string) => { // if (!selectedActionSphere) return; -// const updatedPaths = simulationPaths.map((path) => ({ +// const updatedPaths = simulationStates.map((path) => ({ // ...path, // points: path.points.map((point) => // point.uuid === selectedActionSphere.points.uuid @@ -250,13 +250,13 @@ // ), // })); -// setSimulationPaths(updatedPaths); +// setSimulationStates(updatedPaths); // }; // const selectedPoint = useMemo(() => { // if (!selectedActionSphere) return null; -// return simulationPaths.flatMap((path) => path.points).find((point) => point.uuid === selectedActionSphere.points.uuid); -// }, [selectedActionSphere, simulationPaths]); +// return simulationStates.flatMap((path) => path.points).find((point) => point.uuid === selectedActionSphere.points.uuid); +// }, [selectedActionSphere, simulationStates]); // const createPath = () => { // setActiveButton(activeButton !== 'addMaterialPath' ? 'addMaterialPath' : null); diff --git a/app/src/modules/simulation/simulationtemp/path/pathCreator.tsx b/app/src/modules/simulation/simulationtemp/path/pathCreator.tsx index c09b21c..c9dd36b 100644 --- a/app/src/modules/simulation/simulationtemp/path/pathCreator.tsx +++ b/app/src/modules/simulation/simulationtemp/path/pathCreator.tsx @@ -11,13 +11,13 @@ type PathPoint = { }; type PathCreatorProps = { - simulationPaths: PathPoint[][]; - setSimulationPaths: React.Dispatch>; + simulationStates: PathPoint[][]; + setSimulationStates: React.Dispatch>; connections: { start: PathPoint; end: PathPoint }[]; setConnections: React.Dispatch> }; -const PathCreator = ({ simulationPaths, setSimulationPaths, connections, setConnections }: PathCreatorProps) => { +const PathCreator = ({ simulationStates, setSimulationStates, connections, setConnections }: PathCreatorProps) => { const { camera, scene, raycaster, pointer, gl } = useThree(); const { drawMaterialPath } = useDrawMaterialPath(); @@ -71,7 +71,7 @@ const PathCreator = ({ simulationPaths, setSimulationPaths, connections, setConn e.preventDefault(); if (drag || e.button === 0) return; if (currentPath.length > 1) { - setSimulationPaths((prevPaths) => [...prevPaths, currentPath]); + setSimulationStates((prevPaths) => [...prevPaths, currentPath]); } setCurrentPath([]); setTemporaryPoint(null); @@ -125,7 +125,7 @@ const PathCreator = ({ simulationPaths, setSimulationPaths, connections, setConn canvasElement.addEventListener("contextmenu", onContextMenu); } else { if (currentPath.length > 1) { - setSimulationPaths((prevPaths) => [...prevPaths, currentPath]); + setSimulationStates((prevPaths) => [...prevPaths, currentPath]); } setCurrentPath([]); setTemporaryPoint(null); @@ -179,25 +179,25 @@ const PathCreator = ({ simulationPaths, setSimulationPaths, connections, setConn if (selectedPoint) { const updatedPosition = e.target.object.position.clone(); const updatedRotation = e.target.object.quaternion.clone(); - const updatedPaths = simulationPaths.map((path) => + const updatedPaths = simulationStates.map((path) => path.map((p) => p.uuid === selectedPoint.uuid ? { ...p, position: updatedPosition, rotation: updatedRotation } : p ) ); - setSimulationPaths(updatedPaths); + setSimulationStates(updatedPaths); } }; const meshContext = (uuid: string) => { - const pathIndex = simulationPaths.findIndex(path => path.some(point => point.uuid === uuid)); + const pathIndex = simulationStates.findIndex(path => path.some(point => point.uuid === uuid)); if (pathIndex === -1) return; - const clickedPoint = simulationPaths[pathIndex].find(point => point.uuid === uuid); + const clickedPoint = simulationStates[pathIndex].find(point => point.uuid === uuid); if (!clickedPoint) return; - const isStart = simulationPaths[pathIndex][0].uuid === uuid; - const isEnd = simulationPaths[pathIndex][simulationPaths[pathIndex].length - 1].uuid === uuid; + const isStart = simulationStates[pathIndex][0].uuid === uuid; + const isEnd = simulationStates[pathIndex][simulationStates[pathIndex].length - 1].uuid === uuid; if (pathIndex === 0 && isStart) { console.log("The first-ever point is not connectable."); @@ -285,8 +285,8 @@ const PathCreator = ({ simulationPaths, setSimulationPaths, connections, setConn return ( <> - {/* Render finalized simulationPaths */} - {simulationPaths.map((path, pathIndex) => ( + {/* Render finalized simulationStates */} + {simulationStates.map((path, pathIndex) => ( + {simulationStates.map((path) => path.map((point) => ( ([]); + const [simulationStates, setSimulationStates] = useState<{ position: THREE.Vector3; rotation: THREE.Quaternion; uuid: string }[][]>([]); const [connections, setConnections] = useState<{ start: PathPoint; end: PathPoint }[]>([]); return ( <> - - {simulationPaths.map((path, index) => ( + + {simulationStates.map((path, index) => ( ))} diff --git a/app/src/store/store.ts b/app/src/store/store.ts index 365eb97..eb89771 100644 --- a/app/src/store/store.ts +++ b/app/src/store/store.ts @@ -341,8 +341,8 @@ export const useSelectedPath = create((set: any) => ({ })); interface SimulationPathsStore { - simulationPaths: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[]; - setSimulationPaths: ( + simulationStates: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[]; + setSimulationStates: ( paths: | (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[] | ((prev: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema)[] @@ -350,12 +350,12 @@ interface SimulationPathsStore { ) => void; } -export const useSimulationPaths = create((set) => ({ - simulationPaths: [], - setSimulationPaths: (paths) => +export const useSimulationStates = create((set) => ({ + simulationStates: [], + setSimulationStates: (paths) => set((state) => ({ - simulationPaths: - typeof paths === "function" ? paths(state.simulationPaths) : paths, + simulationStates: + typeof paths === "function" ? paths(state.simulationStates) : paths, })), }))