Made plugin-r3f render on demand

This commit is contained in:
Aria Minaei 2021-08-07 21:17:29 +02:00
parent 1f1f464758
commit 7c759f2f6d
4 changed files with 14 additions and 0 deletions

View file

@ -19,6 +19,7 @@ import type {ISheetObject} from '@theatre/core'
import type {$FixMe} from '../types' import type {$FixMe} from '../types'
import {useSelected} from './useSelected' import {useSelected} from './useSelected'
import {useVal} from '@theatre/dataverse-react' import {useVal} from '@theatre/dataverse-react'
import useInvalidate from './useInvalidate'
export interface ProxyManagerProps { export interface ProxyManagerProps {
orbitControlsRef: React.MutableRefObject<OrbitControls | null> orbitControlsRef: React.MutableRefObject<OrbitControls | null>
@ -52,6 +53,8 @@ const ProxyManager: VFC<ProxyManagerProps> = ({orbitControlsRef}) => {
} }
>({}) >({})
const invalidate = useInvalidate()
// set up scene proxies // set up scene proxies
useLayoutEffect(() => { useLayoutEffect(() => {
if (!sceneProxy) { if (!sceneProxy) {
@ -108,6 +111,7 @@ const ProxyManager: VFC<ProxyManagerProps> = ({orbitControlsRef}) => {
newValues.rotation.z, newValues.rotation.z,
) )
object.scale.set(newValues.scale.x, newValues.scale.y, newValues.scale.z) object.scale.set(newValues.scale.x, newValues.scale.y, newValues.scale.z)
invalidate()
} }
setFromTheatre(sheetObject.value) setFromTheatre(sheetObject.value)

View file

@ -159,6 +159,7 @@ const SnapshotEditor: React.FC<{object: ISheetObject<$FixMe>; paneId: string}> =
shadowMap shadowMap
dpr={[1, 2]} dpr={[1, 2]}
fog={'red'} fog={'red'}
frameloop="demand"
onPointerMissed={onPointerMissed} onPointerMissed={onPointerMissed}
> >
<EditorScene <EditorScene

View file

@ -16,6 +16,7 @@ import {useEditorStore} from '../store'
import mergeRefs from 'react-merge-refs' import mergeRefs from 'react-merge-refs'
import type {$FixMe} from '@theatre/shared/utils/types' import type {$FixMe} from '@theatre/shared/utils/types'
import type {ISheetObject} from '@theatre/core' import type {ISheetObject} from '@theatre/core'
import useInvalidate from './useInvalidate'
interface Elements { interface Elements {
group: Group group: Group
@ -54,6 +55,8 @@ const editable = <
undefined | ISheetObject<$FixMe> undefined | ISheetObject<$FixMe>
>(undefined) >(undefined)
const invalidate = useInvalidate()
useLayoutEffect(() => { useLayoutEffect(() => {
if (!sheet) return if (!sheet) return
const sheetObject = sheet.object(uniqueName, {}, baseSheetObjectType) const sheetObject = sheet.object(uniqueName, {}, baseSheetObjectType)
@ -153,6 +156,7 @@ const editable = <
newValues.scale.y, newValues.scale.y,
newValues.scale.z, newValues.scale.z,
) )
invalidate()
} }
setFromTheatre(sheetObject.value) setFromTheatre(sheetObject.value)

View file

@ -0,0 +1,5 @@
import {useThree} from '@react-three/fiber'
export default function useInvalidate() {
return useThree(({invalidate}) => invalidate)
}