From 8472cf259c27aaa317acca3fde27715d4bdfc3c0 Mon Sep 17 00:00:00 2001 From: Aria Minaei Date: Sat, 3 Jul 2021 13:24:39 +0200 Subject: [PATCH] Chore: Moved r3f's showGrid to Theatre --- packages/plugin-r3f/src/components/Editor.tsx | 9 +++++---- .../src/components/ViewportSettings.tsx | 15 ++++++--------- packages/plugin-r3f/src/store.ts | 7 +------ 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/packages/plugin-r3f/src/components/Editor.tsx b/packages/plugin-r3f/src/components/Editor.tsx index 64cc611..2768f4f 100644 --- a/packages/plugin-r3f/src/components/Editor.tsx +++ b/packages/plugin-r3f/src/components/Editor.tsx @@ -17,24 +17,25 @@ const EditorScene = () => { const orbitControlsRef = useRef() const [ + editorObject, selectedHdr, useHdrAsBackground, - showGrid, - showAxes, helpersRoot, setOrbitControlsRef, ] = useEditorStore( (state) => [ + state.editorObject, state.selectedHdr, state.useHdrAsBackground, - state.showGrid, - state.showAxes, state.helpersRoot, state.setOrbitControlsRef, ], shallow, ) + const showGrid = useVal(editorObject?.props.showGrid) ?? true + const showAxes = useVal(editorObject?.props.showAxes) ?? true + useEffect(() => { setOrbitControlsRef(orbitControlsRef) }, [setOrbitControlsRef]) diff --git a/packages/plugin-r3f/src/components/ViewportSettings.tsx b/packages/plugin-r3f/src/components/ViewportSettings.tsx index c3c5992..1d38371 100644 --- a/packages/plugin-r3f/src/components/ViewportSettings.tsx +++ b/packages/plugin-r3f/src/components/ViewportSettings.tsx @@ -11,29 +11,22 @@ const ViewportShadingSettings: VFC = () => { const [ editorObject, showOverlayIcons, - showGrid, - _showAxes, referenceWindowSize, setShowOverlayIcons, - setShowGrid, - // setShowAxes, setReferenceWindowSize, ] = useEditorStore( (state) => [ state.editorObject, state.showOverlayIcons, - state.showGrid, - state.showAxes, state.referenceWindowSize, state.setShowOverlayIcons, - state.setShowGrid, - // state.setShowAxes, state.setReferenceWindowSize, ], shallow, ) const showAxes = useVal(editorObject?.props.showAxes) ?? true + const showGrid = useVal(editorObject?.props.showGrid) ?? true return (
@@ -50,7 +43,11 @@ const ViewportShadingSettings: VFC = () => { setShowGrid(!showGrid)} + onChange={() => + studio.transaction(({set}) => { + set(editorObject!.props.showGrid, !showGrid) + }) + } > Show grid diff --git a/packages/plugin-r3f/src/store.ts b/packages/plugin-r3f/src/store.ts index a42e405..70a8457 100644 --- a/packages/plugin-r3f/src/store.ts +++ b/packages/plugin-r3f/src/store.ts @@ -156,7 +156,6 @@ export type EditorStore = { selectedHdr: string | null showOverlayIcons: boolean useHdrAsBackground: boolean - showGrid: boolean referenceWindowSize: number initialEditorCamera: ContainerProps['camera'] @@ -180,7 +179,6 @@ export type EditorStore = { setViewportShading: (mode: ViewportShading) => void setShowOverlayIcons: (show: boolean) => void setUseHdrAsBackground: (use: boolean) => void - setShowGrid: (show: boolean) => void setReferenceWindowSize: (size: number) => void createSnapshot: () => void setSheetObject: (uniqueName: string, sheetObject: BaseSheetObjectType) => void @@ -226,7 +224,6 @@ const config: StateCreator = (set, get) => { selectedHdr: null, showOverlayIcons: false, useHdrAsBackground: false, - showGrid: true, referenceWindowSize: 120, initialEditorCamera: {}, @@ -322,9 +319,6 @@ const config: StateCreator = (set, get) => { setUseHdrAsBackground: (use) => { set({useHdrAsBackground: use}) }, - setShowGrid: (show) => { - set({showGrid: show}) - }, setReferenceWindowSize: (size) => set({referenceWindowSize: size}), createSnapshot: () => { @@ -359,6 +353,7 @@ const editorSheetObjectConfig = { props: types.compound({ isOpen: types.boolean(false), showAxes: types.boolean(true), + showGrid: types.boolean(true), }), }