diff --git a/packages/plugin-r3f/src/components/ProxyManager.tsx b/packages/plugin-r3f/src/components/ProxyManager.tsx index 4feae3a..c8a6be5 100644 --- a/packages/plugin-r3f/src/components/ProxyManager.tsx +++ b/packages/plugin-r3f/src/components/ProxyManager.tsx @@ -32,22 +32,19 @@ type IEditableProxy = { const ProxyManager: VFC = ({orbitControlsRef}) => { const isBeingEdited = useRef(false) - const [editorObject, sceneSnapshot, viewportShading, sheetObjects] = - useEditorStore( - (state) => [ - state.editorObject, - state.sceneSnapshot, - state.viewportShading, - state.sheetObjects, - ], - shallow, - ) + const [editorObject, sceneSnapshot, sheetObjects] = useEditorStore( + (state) => [state.editorObject, state.sceneSnapshot, state.sheetObjects], + shallow, + ) const transformControlsMode = useVal(editorObject?.props.transformControlsMode) ?? 'translate' const transformControlsSpace = useVal(editorObject?.props.transformControlsSpace) ?? 'world' + const viewportShading = + useVal(editorObject?.props.viewportShading) ?? 'rendered' + const sceneProxy = useMemo(() => sceneSnapshot?.clone(), [sceneSnapshot]) const [editableProxies, setEditableProxies] = useState<{ [name: string]: IEditableProxy diff --git a/packages/plugin-r3f/src/components/UI.tsx b/packages/plugin-r3f/src/components/UI.tsx index 9ffba3e..e9bc8e6 100644 --- a/packages/plugin-r3f/src/components/UI.tsx +++ b/packages/plugin-r3f/src/components/UI.tsx @@ -16,12 +16,8 @@ import {getSelected} from './useSelected' import {useVal} from '@theatre/dataverse-react' const UI: VFC = () => { - const [editorObject, viewportShading, setViewportShading] = useEditorStore( - (state) => [ - state.editorObject, - state.viewportShading, - state.setViewportShading, - ], + const [editorObject] = useEditorStore( + (state) => [state.editorObject], shallow, ) @@ -31,6 +27,8 @@ const UI: VFC = () => { useVal(editorObject?.props.transformControlsMode) ?? 'translate' const transformControlsSpace = useVal(editorObject?.props.transformControlsSpace) ?? 'world' + const viewportShading = + useVal(editorObject?.props.viewportShading) ?? 'rendered' if (!editorObject) return <> @@ -63,7 +61,11 @@ const UI: VFC = () => {
{ + studio.transaction(({set}) => { + set(editorObject.props.viewportShading, shading) + }) + }} />
diff --git a/packages/plugin-r3f/src/store.ts b/packages/plugin-r3f/src/store.ts index 7f4a668..529a82b 100644 --- a/packages/plugin-r3f/src/store.ts +++ b/packages/plugin-r3f/src/store.ts @@ -147,7 +147,6 @@ export type EditorStore = { editables: Record // this will come in handy when we start supporting multiple canvases canvasName: string - viewportShading: ViewportShading sceneSnapshot: Scene | null editablesSnapshot: Record | null hdrPaths: string[] @@ -170,7 +169,6 @@ export type EditorStore = { addEditable: (type: T, uniqueName: string) => void removeEditable: (uniqueName: string) => void setSelectedHdr: (hdr: string | null) => void - setViewportShading: (mode: ViewportShading) => void setUseHdrAsBackground: (use: boolean) => void createSnapshot: () => void setSheetObject: (uniqueName: string, sheetObject: BaseSheetObjectType) => void @@ -207,7 +205,6 @@ const config: StateCreator = (set, get) => { helpersRoot: new Group(), editables: {}, canvasName: 'default', - viewportShading: 'rendered', sceneSnapshot: null, editablesSnapshot: null, hdrPaths: [], @@ -292,9 +289,6 @@ const config: StateCreator = (set, get) => { setSelectedHdr: (hdr) => { set({selectedHdr: hdr}) }, - setViewportShading: (mode) => { - set({viewportShading: mode}) - }, setUseHdrAsBackground: (use) => { set({useHdrAsBackground: use}) @@ -343,6 +337,12 @@ const editorSheetObjectConfig = { 'world', ['local', 'world'], ), + viewportShading: types.stringLiteral('rendered', [ + 'flat', + 'rendered', + 'solid', + 'wireframe', + ]), }), }