Remove debouncedScrub() from r3f (#147)

This commit is contained in:
Andrew Prifer 2022-05-06 14:07:29 +02:00 committed by GitHub
parent a38201a835
commit a3b1938d43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 11 deletions

View file

@ -6,7 +6,7 @@ import React, {
useRef, useRef,
useState, useState,
} from 'react' } from 'react'
import type {Editable} from '../store'; import type {Editable} from '../store'
import {useEditorStore} from '../store' import {useEditorStore} from '../store'
import {createPortal} from '@react-three/fiber' import {createPortal} from '@react-three/fiber'
import EditableProxy from './EditableProxy' import EditableProxy from './EditableProxy'
@ -15,6 +15,7 @@ import TransformControls from './TransformControls'
import shallow from 'zustand/shallow' import shallow from 'zustand/shallow'
import type {Material, Mesh, Object3D} from 'three' import type {Material, Mesh, Object3D} from 'three'
import {MeshBasicMaterial, MeshPhongMaterial} from 'three' import {MeshBasicMaterial, MeshPhongMaterial} from 'three'
import type {IScrub} from '@theatre/studio';
import studio from '@theatre/studio' import studio from '@theatre/studio'
import {useSelected} from './useSelected' import {useSelected} from './useSelected'
import {useVal} from '@theatre/react' import {useVal} from '@theatre/react'
@ -213,9 +214,7 @@ const ProxyManager: VFC<ProxyManagerProps> = ({orbitControlsRef}) => {
}) })
}, [viewportShading, renderMaterials, sceneProxy]) }, [viewportShading, renderMaterials, sceneProxy])
const scrub = useMemo(() => { const scrub = useRef<IScrub>(undefined!)
return studio.debouncedScrub(1000)
}, [selected, editableProxyOfSelected])
if (!sceneProxy) { if (!sceneProxy) {
return null return null
@ -237,7 +236,7 @@ const ProxyManager: VFC<ProxyManagerProps> = ({orbitControlsRef}) => {
const sheetObject = editableProxyOfSelected.editable.sheetObject const sheetObject = editableProxyOfSelected.editable.sheetObject
const obj = editableProxyOfSelected.object const obj = editableProxyOfSelected.object
scrub.capture(({set}) => { scrub.current.capture(({set}) => {
set(sheetObject.props, { set(sheetObject.props, {
...sheetObject.value, ...sheetObject.value,
position: { position: {
@ -258,7 +257,14 @@ const ProxyManager: VFC<ProxyManagerProps> = ({orbitControlsRef}) => {
}) })
}) })
}} }}
onDraggingChange={(event) => (isBeingEdited.current = event.value)} onDraggingChange={(event) => {
if (event.value) {
scrub.current = studio.scrub()
} else {
scrub.current.commit()
}
return (isBeingEdited.current = event.value)
}}
/> />
)} )}
{Object.values(editableProxies).map( {Object.values(editableProxies).map(

View file

@ -4,6 +4,7 @@ import type {MutableRefObject} from 'react'
import {useLayoutEffect, useRef} from 'react' import {useLayoutEffect, useRef} from 'react'
import React from 'react' import React from 'react'
import useRefAndState from './useRefAndState' import useRefAndState from './useRefAndState'
import type {IScrub} from '@theatre/studio';
import studio from '@theatre/studio' import studio from '@theatre/studio'
import type {PerspectiveCamera as PerspectiveCameraImpl} from 'three' import type {PerspectiveCamera as PerspectiveCameraImpl} from 'three'
import type {ISheet} from '@theatre/core' import type {ISheet} from '@theatre/core'
@ -88,17 +89,18 @@ function usePassValuesFromOrbitControlsToTheatre(
useLayoutEffect(() => { useLayoutEffect(() => {
if (!cam || orbitControls == null) return if (!cam || orbitControls == null) return
let currentScrub: undefined | ReturnType<typeof studio['debouncedScrub']> let currentScrub: undefined | IScrub
let started = false let started = false
const onStart = () => { const onStart = () => {
started = true started = true
if (!currentScrub) { currentScrub = studio.scrub()
currentScrub = studio.debouncedScrub(600)
}
} }
const onEnd = () => { const onEnd = () => {
if (currentScrub) {
currentScrub.commit()
}
started = false started = false
} }