import type {VFC} from 'react' import {useLayoutEffect} from 'react' import React, {useEffect, useRef, Suspense} from 'react' import {Canvas} from '@react-three/fiber' import {useEditorStore} from '../store' import {OrbitControls, Environment} from '@react-three/drei' import shallow from 'zustand/shallow' import root from 'react-shadow' import styles from '../bundle.css.txt' import UI from './UI' import ProxyManager from './ProxyManager' import {Button, PortalManager, IdProvider} from './elements' import studio from '@theatre/studio' import {useVal} from '@theatre/dataverse-react' const EditorScene = () => { const orbitControlsRef = useRef() const [ editorObject, selectedHdr, useHdrAsBackground, helpersRoot, setOrbitControlsRef, ] = useEditorStore( (state) => [ state.editorObject, state.selectedHdr, state.useHdrAsBackground, state.helpersRoot, state.setOrbitControlsRef, ], shallow, ) const showGrid = useVal(editorObject?.props.showGrid) ?? true const showAxes = useVal(editorObject?.props.showAxes) ?? true useEffect(() => { setOrbitControlsRef(orbitControlsRef) }, [setOrbitControlsRef]) return ( <> {selectedHdr && ( )} {showGrid && } {showAxes && } {/* @ts-ignore */} ) } const Editor: VFC = () => { const [editorObject, sceneSnapshot, initialEditorCamera, createSnapshot] = useEditorStore( (state) => [ state.editorObject, state.sceneSnapshot, state.initialEditorCamera, state.createSnapshot, ], shallow, ) const editorOpen = useVal(editorObject?.props.isOpen) useLayoutEffect(() => { if (editorOpen) { createSnapshot() } }, [editorOpen]) if (!editorObject) return <> return (
{sceneSnapshot ? ( <>
{ gl.setClearColor('white') }} shadowMap pixelRatio={window.devicePixelRatio} onPointerMissed={() => studio.__experimental_setSelection([]) } >
) : null}
{editorOpen || ( )}
) } export default Editor