diff --git a/packages/plugin-r3f/package.json b/packages/plugin-r3f/package.json index 5143f07..d4f9f41 100644 --- a/packages/plugin-r3f/package.json +++ b/packages/plugin-r3f/package.json @@ -34,6 +34,7 @@ "@types/lodash-es": "^4.17.4", "@types/node": "^15.6.2", "@types/react": "^17.0.9", + "@types/styled-components": "^5.1.9", "typescript": "^4.3.2" }, "dependencies": { @@ -50,6 +51,7 @@ "react-shadow": "^19.0.2", "react-use-measure": "^2.0.4", "reakit": "^1.3.8", + "styled-components": "^5.3.0", "three": "^0.129.0", "zustand": "^3.5.1" } diff --git a/packages/plugin-r3f/src/components/Editor.tsx b/packages/plugin-r3f/src/components/Editor.tsx index cbcadf4..179f5d2 100644 --- a/packages/plugin-r3f/src/components/Editor.tsx +++ b/packages/plugin-r3f/src/components/Editor.tsx @@ -5,12 +5,32 @@ import {Canvas} from '@react-three/fiber' import {useEditorStore} from '../store' import {OrbitControls} from '@react-three/drei' import shallow from 'zustand/shallow' -import root from 'react-shadow' +import root from 'react-shadow/styled-components' import styles from '../bundle.css.txt' import UI from './UI' import ProxyManager from './ProxyManager' import studio from '@theatre/studio' import {useVal} from '@theatre/dataverse-react' +import styled, {createGlobalStyle} from 'styled-components' + +const GlobalStyle = createGlobalStyle` + :host { + contain: strict; + all: initial; + color: white; + font: 11px -apple-system, BlinkMacSystemFont, Segoe WPC, Segoe Editor, + HelveticaNeue-Light, Ubuntu, Droid Sans, sans-serif; + } + + * { + padding: 0; + margin: 0; + font-size: 100%; + font: inherit; + vertical-align: baseline; + list-style: none; + } +` const EditorScene = () => { const orbitControlsRef = useRef() @@ -43,6 +63,27 @@ const EditorScene = () => { ) } +const Wrapper = styled.div<{editorOpen: boolean}>` + tab-size: 4; + line-height: 1.15; /* 1 */ + -webkit-text-size-adjust: 100%; /* 2 */ + margin: 0; + + position: fixed; + top: 0px; + right: 0px; + bottom: 0px; + left: 0px; + z-index: 50; + display: ${(props) => (props.editorOpen ? 'block' : 'none')}; +` + +const CanvasWrapper = styled.div` + display: relative; + z-index: 0; + height: 100%; +` + const Editor: VFC = () => { const [editorObject, sceneSnapshot, initialEditorCamera, createSnapshot] = useEditorStore( @@ -55,7 +96,7 @@ const Editor: VFC = () => { shallow, ) - const editorOpen = useVal(editorObject?.props.isOpen) + const editorOpen = !!useVal(editorObject?.props.isOpen) useLayoutEffect(() => { if (editorOpen) { createSnapshot() @@ -66,43 +107,31 @@ const Editor: VFC = () => { return ( -
- <> + + + {sceneSnapshot ? ( <> -
-
+ { + gl.setClearColor('white') + }} + shadowMap + pixelRatio={window.devicePixelRatio} + onPointerMissed={() => studio.__experimental_setSelection([])} > - {sceneSnapshot ? ( - <> -
- { - gl.setClearColor('white') - }} - shadowMap - pixelRatio={window.devicePixelRatio} - onPointerMissed={() => - studio.__experimental_setSelection([]) - } - > - - -
+ +
+ - - - ) : null} -
-
- - + - -
+ ) : null} + +
) } diff --git a/packages/plugin-r3f/src/components/UI.tsx b/packages/plugin-r3f/src/components/UI.tsx index 8af4969..ba69348 100644 --- a/packages/plugin-r3f/src/components/UI.tsx +++ b/packages/plugin-r3f/src/components/UI.tsx @@ -1,4 +1,5 @@ import type {VFC} from 'react' +import {useState} from 'react' import React from 'react' import TransformControlsModeSelect from './TransformControlsModeSelect' import {useEditorStore} from '../store' @@ -13,6 +14,7 @@ import studio from '@theatre/studio' import {getSelected} from './useSelected' import {useVal} from '@theatre/dataverse-react' import IconButton from './elements/IconButton' +import {PortalContext} from 'reakit' const UI: VFC = () => { const [editorObject] = useEditorStore( @@ -29,114 +31,121 @@ const UI: VFC = () => { const viewportShading = useVal(editorObject?.props.viewportShading) ?? 'rendered' + const [wrapper, setWrapper] = useState(null) + if (!editorObject) return <> return ( -
-
-
-
-
-
- - studio.transaction(({set}) => - set(editorObject!.props.transformControlsMode, value), - ) - } - /> -
-
- { - studio.transaction(({set}) => { - set(editorObject.props.transformControlsSpace, space) - }) - }} - /> -
-
- { - studio.transaction(({set}) => { - set(editorObject.props.viewportShading, shading) - }) - }} - /> -
-
- } - onClick={() => { - const orbitControls = - useEditorStore.getState().orbitControlsRef?.current - const selected = getSelected() - - let focusObject - - if (selected) { - focusObject = - useEditorStore.getState().editablesSnapshot![selected] - .proxyObject - } - - if (orbitControls && focusObject) { - focusObject.getWorldPosition( - // @ts-ignore TODO - orbitControls.target as Vector3, + +
+
+
+
+
+
+ + studio.transaction(({set}) => + set(editorObject!.props.transformControlsMode, value), ) } - }} - /> -
-
- } - onClick={() => { - const camera = ( - useEditorStore.getState().orbitControlsRef - ?.current as $FixMe - )?.object + /> +
+
+ { + studio.transaction(({set}) => { + set(editorObject.props.transformControlsSpace, space) + }) + }} + /> +
+
+ { + studio.transaction(({set}) => { + set(editorObject.props.viewportShading, shading) + }) + }} + /> +
+
+ } + onClick={() => { + const orbitControls = + useEditorStore.getState().orbitControlsRef?.current + const selected = getSelected() - const selected = getSelected() + let focusObject - let proxyObject - - if (selected) { - proxyObject = - useEditorStore.getState().editablesSnapshot![selected] - .proxyObject - - if (proxyObject && camera) { - const direction = new Vector3() - const position = camera.position.clone() - - camera.getWorldDirection(direction) - proxyObject.position.set(0, 0, 0) - proxyObject.lookAt(direction) - - proxyObject.parent!.worldToLocal(position) - proxyObject.position.copy(position) - - proxyObject.updateMatrix() + if (selected) { + focusObject = + useEditorStore.getState().editablesSnapshot![selected] + .proxyObject } - } - }} - /> + + if (orbitControls && focusObject) { + focusObject.getWorldPosition( + // @ts-ignore TODO + orbitControls.target as Vector3, + ) + } + }} + /> +
+
+ } + onClick={() => { + const camera = ( + useEditorStore.getState().orbitControlsRef + ?.current as $FixMe + )?.object + + const selected = getSelected() + + let proxyObject + + if (selected) { + proxyObject = + useEditorStore.getState().editablesSnapshot![selected] + .proxyObject + + if (proxyObject && camera) { + const direction = new Vector3() + const position = camera.position.clone() + + camera.getWorldDirection(direction) + proxyObject.position.set(0, 0, 0) + proxyObject.lookAt(direction) + + proxyObject.parent!.worldToLocal(position) + proxyObject.position.copy(position) + + proxyObject.updateMatrix() + } + } + }} + /> +
+
+
+
-
-
-
-
+ ) } diff --git a/packages/plugin-r3f/src/components/elements/CompactModeSelect.tsx b/packages/plugin-r3f/src/components/elements/CompactModeSelect.tsx index 4827f62..de4b4fa 100644 --- a/packages/plugin-r3f/src/components/elements/CompactModeSelect.tsx +++ b/packages/plugin-r3f/src/components/elements/CompactModeSelect.tsx @@ -2,6 +2,7 @@ import type {ReactElement, ReactNode} from 'react' import React from 'react' import type {IconType} from 'react-icons' import {Group, Button} from 'reakit' +import styled from 'styled-components' import {Tooltip, TooltipReference, useTooltipState} from './Tooltip' interface OptionButtonProps