r3f fixes (#222)
* Minify r3f extension bundle, because it is expected by the React dead code elimination check, since we bundle React in it * Add children to props, since it is required by React 18 types * Fix getting context attributes for gl in ReferenceWindow * Don't bundle threejs in extension * Fix editor not responding to scene initialization * Fix SnapshotEditor css
This commit is contained in:
parent
16e255fd57
commit
262d7d61d3
5 changed files with 59 additions and 44 deletions
|
@ -58,7 +58,7 @@ async function createBundles() {
|
||||||
'@theatre/studio',
|
'@theatre/studio',
|
||||||
'@theatre/dataverse',
|
'@theatre/dataverse',
|
||||||
'@theatre/r3f',
|
'@theatre/r3f',
|
||||||
// 'three',
|
'three',
|
||||||
// '@react-three/fiber',
|
// '@react-three/fiber',
|
||||||
// '@react-three/drei',
|
// '@react-three/drei',
|
||||||
// 'three-stdlib',
|
// 'three-stdlib',
|
||||||
|
@ -69,6 +69,7 @@ async function createBundles() {
|
||||||
outfile: path.join(__dirname, '../dist/extension/index.js'),
|
outfile: path.join(__dirname, '../dist/extension/index.js'),
|
||||||
format: 'cjs',
|
format: 'cjs',
|
||||||
metafile: true,
|
metafile: true,
|
||||||
|
minify: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await build(esbuildConfig)
|
const result = await build(esbuildConfig)
|
||||||
|
|
|
@ -95,9 +95,7 @@ const ReferenceWindow: VFC<ReferenceWindowProps> = ({maxHeight, maxWidth}) => {
|
||||||
const [ref, bounds] = useMeasure()
|
const [ref, bounds] = useMeasure()
|
||||||
|
|
||||||
const preserveDrawingBuffer =
|
const preserveDrawingBuffer =
|
||||||
(
|
gl?.getContextAttributes()?.preserveDrawingBuffer ?? false
|
||||||
gl?.domElement.getContext('webgl') ?? gl?.domElement.getContext('webgl2')
|
|
||||||
)?.getContextAttributes()?.preserveDrawingBuffer ?? false
|
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
if (gl) {
|
if (gl) {
|
||||||
|
|
|
@ -31,7 +31,6 @@ const GlobalStyle = createGlobalStyle`
|
||||||
* {
|
* {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
font-size: 100%;
|
|
||||||
font: inherit;
|
font: inherit;
|
||||||
vertical-align: baseline;
|
vertical-align: baseline;
|
||||||
list-style: none;
|
list-style: none;
|
||||||
|
@ -91,15 +90,15 @@ const Wrapper = styled.div`
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0px;
|
top: 0;
|
||||||
right: 0px;
|
right: 0;
|
||||||
bottom: 0px;
|
bottom: 0;
|
||||||
left: 0px;
|
left: 0;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
`
|
`
|
||||||
|
|
||||||
const CanvasWrapper = styled.div`
|
const CanvasWrapper = styled.div`
|
||||||
display: relative;
|
position: relative;
|
||||||
z-index: 0;
|
z-index: 0;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
@ -126,6 +125,25 @@ const ReferenceWindowContainer = styled.div`
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const WaitForSceneInitMessage = styled.div<{active?: boolean}>`
|
||||||
|
position: absolute;
|
||||||
|
margin: auto;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
width: 300px;
|
||||||
|
top: 12px;
|
||||||
|
padding: 16px;
|
||||||
|
border-radius: 4px;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.08);
|
||||||
|
|
||||||
|
backdrop-filter: blur(14px);
|
||||||
|
background: rgba(40, 43, 47, 0.8);
|
||||||
|
|
||||||
|
@supports not (backdrop-filter: blur()) {
|
||||||
|
background-color: rgba(40, 43, 47, 0.95);
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
const SnapshotEditor: React.FC<{paneId: string}> = (props) => {
|
const SnapshotEditor: React.FC<{paneId: string}> = (props) => {
|
||||||
const snapshotEditorSheet = getEditorSheet()
|
const snapshotEditorSheet = getEditorSheet()
|
||||||
const paneId = props.paneId
|
const paneId = props.paneId
|
||||||
|
@ -137,20 +155,10 @@ const SnapshotEditor: React.FC<{paneId: string}> = (props) => {
|
||||||
shallow,
|
shallow,
|
||||||
)
|
)
|
||||||
|
|
||||||
const editorOpen = true
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
let timeout: NodeJS.Timeout | undefined
|
// Create a fresh snapshot when the editor is opened
|
||||||
if (editorOpen) {
|
createSnapshot()
|
||||||
// a hack to make sure all the scene's props are
|
}, [])
|
||||||
// applied before we take a snapshot
|
|
||||||
timeout = setTimeout(createSnapshot, 100)
|
|
||||||
}
|
|
||||||
return () => {
|
|
||||||
if (timeout !== undefined) {
|
|
||||||
clearTimeout(timeout)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [editorOpen])
|
|
||||||
|
|
||||||
const onPointerMissed = useCallback(() => {
|
const onPointerMissed = useCallback(() => {
|
||||||
// This callback runs when the user clicks in an empty space inside a SnapshotEditor.
|
// This callback runs when the user clicks in an empty space inside a SnapshotEditor.
|
||||||
|
@ -190,10 +198,14 @@ const SnapshotEditor: React.FC<{paneId: string}> = (props) => {
|
||||||
maxWidth={Math.min(bounds.width * 0.4, 200)}
|
maxWidth={Math.min(bounds.width * 0.4, 200)}
|
||||||
/>
|
/>
|
||||||
</ReferenceWindowContainer>
|
</ReferenceWindowContainer>
|
||||||
|
{!sceneSnapshot && (
|
||||||
|
<WaitForSceneInitMessage>
|
||||||
|
The scene hasn't been initialized yet. It will appear in the
|
||||||
|
editor as soon as it is.
|
||||||
|
</WaitForSceneInitMessage>
|
||||||
|
)}
|
||||||
</Overlay>
|
</Overlay>
|
||||||
|
|
||||||
{sceneSnapshot ? (
|
|
||||||
<>
|
|
||||||
<CanvasWrapper ref={ref}>
|
<CanvasWrapper ref={ref}>
|
||||||
<Canvas
|
<Canvas
|
||||||
onCreated={({gl}) => {
|
onCreated={({gl}) => {
|
||||||
|
@ -210,8 +222,6 @@ const SnapshotEditor: React.FC<{paneId: string}> = (props) => {
|
||||||
/>
|
/>
|
||||||
</Canvas>
|
</Canvas>
|
||||||
</CanvasWrapper>
|
</CanvasWrapper>
|
||||||
</>
|
|
||||||
) : null}
|
|
||||||
</Wrapper>
|
</Wrapper>
|
||||||
</>
|
</>
|
||||||
</StyleSheetManager>
|
</StyleSheetManager>
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import type {ReactNode} from 'react'
|
||||||
import React, {
|
import React, {
|
||||||
createContext,
|
createContext,
|
||||||
useContext,
|
useContext,
|
||||||
|
@ -26,6 +27,7 @@ export const useCurrentSheet = (): ISheet | undefined => {
|
||||||
|
|
||||||
const SheetProvider: React.FC<{
|
const SheetProvider: React.FC<{
|
||||||
sheet: ISheet
|
sheet: ISheet
|
||||||
|
children: ReactNode
|
||||||
}> = ({sheet, children}) => {
|
}> = ({sheet, children}) => {
|
||||||
const {scene, gl} = useThree((s) => ({scene: s.scene, gl: s.gl}))
|
const {scene, gl} = useThree((s) => ({scene: s.scene, gl: s.gl}))
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ export type EditorStore = {
|
||||||
) => void
|
) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const config: StateCreator<EditorStore> = (set) => {
|
const config: StateCreator<EditorStore> = (set, get) => {
|
||||||
return {
|
return {
|
||||||
sheet: null,
|
sheet: null,
|
||||||
editorObject: null,
|
editorObject: null,
|
||||||
|
@ -70,6 +70,10 @@ const config: StateCreator<EditorStore> = (set) => {
|
||||||
scene,
|
scene,
|
||||||
gl,
|
gl,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Create a snapshot, so that if the editor is already open, it gets refreshed
|
||||||
|
// when the scene is initialized
|
||||||
|
get().createSnapshot()
|
||||||
},
|
},
|
||||||
|
|
||||||
addEditable: (uniqueName, editable) => {
|
addEditable: (uniqueName, editable) => {
|
||||||
|
|
Loading…
Reference in a new issue