diff --git a/app/src/modules/builder/builder.tsx b/app/src/modules/builder/builder.tsx index 9452a61..ed82590 100644 --- a/app/src/modules/builder/builder.tsx +++ b/app/src/modules/builder/builder.tsx @@ -46,6 +46,7 @@ import ZoneGroup from "./groups/zoneGroup"; import MeasurementTool from "../scene/tools/measurementTool"; import NavMesh from "../simulation/vehicle/navMesh/navMesh"; import CalculateAreaGroup from "./groups/calculateAreaGroup"; +import LayoutImage from "./layout/layoutImage"; export default function Builder() { const state = useThree(); // Importing the state from the useThree hook, which contains the scene, camera, and other Three.js elements. @@ -299,8 +300,12 @@ export default function Builder() { /> + + + + ); } diff --git a/app/src/modules/builder/layout/layoutImage.tsx b/app/src/modules/builder/layout/layoutImage.tsx new file mode 100644 index 0000000..1c92978 --- /dev/null +++ b/app/src/modules/builder/layout/layoutImage.tsx @@ -0,0 +1,35 @@ +import { useMemo } from 'react'; +import layout1 from '../../../assets/gltf-glb/layouts/floorplane_1.glb'; +import layout2 from '../../../assets/gltf-glb/layouts/floorplane_2.glb'; +import useLayoutStore from '../../../store/builder/uselayoutStore'; +import { useGLTF } from '@react-three/drei'; +import { useToggleView } from '../../../store/builder/store'; + +const modelPaths: Record = { + 'layout1': layout1, + 'layout2': layout2 +}; + +function LayoutModel() { + const { toggleView } = useToggleView(); + const { currentLayout } = useLayoutStore(); + if (!currentLayout) return null; + + const path = modelPaths[currentLayout]; + const gltf = useGLTF(path); + const cloned = useMemo(() => gltf?.scene?.clone(), [gltf]); + + return ( + <> + {toggleView && + + + + } + + ); +} + +export default LayoutModel; \ No newline at end of file diff --git a/app/src/store/builder/uselayoutStore.ts b/app/src/store/builder/uselayoutStore.ts new file mode 100644 index 0000000..acaeb50 --- /dev/null +++ b/app/src/store/builder/uselayoutStore.ts @@ -0,0 +1,37 @@ +import { create } from 'zustand'; + +type Layout = null | 'layout1' | 'layout2'; + +type LayoutState = { + currentLayout: Layout; + setLayout: (layout: Layout) => void; + resetLayout: () => void; +}; + +const LAYOUT_STORAGE_KEY = 'currentLayout'; + +const useLayoutStore = create((set) => ({ + currentLayout: (() => { + if (typeof window !== 'undefined') { + const storedLayout = localStorage.getItem(LAYOUT_STORAGE_KEY); + return storedLayout ? (JSON.parse(storedLayout) as Layout) : null; + } + return null; + })(), + + setLayout: (layout) => { + if (typeof window !== 'undefined') { + localStorage.setItem(LAYOUT_STORAGE_KEY, JSON.stringify(layout)); + } + set({ currentLayout: layout }); + }, + + resetLayout: () => { + if (typeof window !== 'undefined') { + localStorage.removeItem(LAYOUT_STORAGE_KEY); + } + set({ currentLayout: null }); + }, +})); + +export default useLayoutStore; \ No newline at end of file