Chore: Moved r3f's transformControls* to Theatre
This commit is contained in:
parent
4038ad34a4
commit
89913ac51f
3 changed files with 40 additions and 43 deletions
|
@ -18,6 +18,7 @@ import studio from '@theatre/studio'
|
||||||
import type {ISheetObject} from '@theatre/core'
|
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'
|
||||||
|
|
||||||
export interface ProxyManagerProps {
|
export interface ProxyManagerProps {
|
||||||
orbitControlsRef: React.MutableRefObject<typeof OrbitControls | undefined>
|
orbitControlsRef: React.MutableRefObject<typeof OrbitControls | undefined>
|
||||||
|
@ -31,22 +32,22 @@ type IEditableProxy = {
|
||||||
|
|
||||||
const ProxyManager: VFC<ProxyManagerProps> = ({orbitControlsRef}) => {
|
const ProxyManager: VFC<ProxyManagerProps> = ({orbitControlsRef}) => {
|
||||||
const isBeingEdited = useRef(false)
|
const isBeingEdited = useRef(false)
|
||||||
const [
|
const [editorObject, sceneSnapshot, viewportShading, sheetObjects] =
|
||||||
sceneSnapshot,
|
useEditorStore(
|
||||||
transformControlsMode,
|
(state) => [
|
||||||
transformControlsSpace,
|
state.editorObject,
|
||||||
viewportShading,
|
state.sceneSnapshot,
|
||||||
sheetObjects,
|
state.viewportShading,
|
||||||
] = useEditorStore(
|
state.sheetObjects,
|
||||||
(state) => [
|
],
|
||||||
state.sceneSnapshot,
|
shallow,
|
||||||
state.transformControlsMode,
|
)
|
||||||
state.transformControlsSpace,
|
const transformControlsMode =
|
||||||
state.viewportShading,
|
useVal(editorObject?.props.transformControlsMode) ?? 'translate'
|
||||||
state.sheetObjects,
|
|
||||||
],
|
const transformControlsSpace =
|
||||||
shallow,
|
useVal(editorObject?.props.transformControlsSpace) ?? 'world'
|
||||||
)
|
|
||||||
const sceneProxy = useMemo(() => sceneSnapshot?.clone(), [sceneSnapshot])
|
const sceneProxy = useMemo(() => sceneSnapshot?.clone(), [sceneSnapshot])
|
||||||
const [editableProxies, setEditableProxies] = useState<{
|
const [editableProxies, setEditableProxies] = useState<{
|
||||||
[name: string]: IEditableProxy
|
[name: string]: IEditableProxy
|
||||||
|
|
|
@ -16,22 +16,10 @@ import {getSelected} from './useSelected'
|
||||||
import {useVal} from '@theatre/dataverse-react'
|
import {useVal} from '@theatre/dataverse-react'
|
||||||
|
|
||||||
const UI: VFC = () => {
|
const UI: VFC = () => {
|
||||||
const [
|
const [editorObject, viewportShading, setViewportShading] = useEditorStore(
|
||||||
editorObject,
|
|
||||||
transformControlsMode,
|
|
||||||
transformControlsSpace,
|
|
||||||
viewportShading,
|
|
||||||
setTransformControlsMode,
|
|
||||||
setTransformControlsSpace,
|
|
||||||
setViewportShading,
|
|
||||||
] = useEditorStore(
|
|
||||||
(state) => [
|
(state) => [
|
||||||
state.editorObject,
|
state.editorObject,
|
||||||
state.transformControlsMode,
|
|
||||||
state.transformControlsSpace,
|
|
||||||
state.viewportShading,
|
state.viewportShading,
|
||||||
state.setTransformControlsMode,
|
|
||||||
state.setTransformControlsSpace,
|
|
||||||
state.setViewportShading,
|
state.setViewportShading,
|
||||||
],
|
],
|
||||||
shallow,
|
shallow,
|
||||||
|
@ -39,6 +27,10 @@ const UI: VFC = () => {
|
||||||
|
|
||||||
const referenceWindowSize =
|
const referenceWindowSize =
|
||||||
useVal(editorObject?.props.referenceWindowSize) ?? 120
|
useVal(editorObject?.props.referenceWindowSize) ?? 120
|
||||||
|
const transformControlsMode =
|
||||||
|
useVal(editorObject?.props.transformControlsMode) ?? 'translate'
|
||||||
|
const transformControlsSpace =
|
||||||
|
useVal(editorObject?.props.transformControlsSpace) ?? 'world'
|
||||||
|
|
||||||
if (!editorObject) return <></>
|
if (!editorObject) return <></>
|
||||||
|
|
||||||
|
@ -51,13 +43,21 @@ const UI: VFC = () => {
|
||||||
<div className="pointer-events-auto">
|
<div className="pointer-events-auto">
|
||||||
<TransformControlsModeSelect
|
<TransformControlsModeSelect
|
||||||
value={transformControlsMode}
|
value={transformControlsMode}
|
||||||
onChange={(value) => setTransformControlsMode(value)}
|
onChange={(value) =>
|
||||||
|
studio.transaction(({set}) =>
|
||||||
|
set(editorObject!.props.transformControlsMode, value),
|
||||||
|
)
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="pointer-events-auto">
|
<div className="pointer-events-auto">
|
||||||
<TransformControlsSpaceSelect
|
<TransformControlsSpaceSelect
|
||||||
value={transformControlsSpace}
|
value={transformControlsSpace}
|
||||||
onChange={setTransformControlsSpace}
|
onChange={(space) => {
|
||||||
|
studio.transaction(({set}) => {
|
||||||
|
set(editorObject.props.transformControlsSpace, space)
|
||||||
|
})
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="pointer-events-auto">
|
<div className="pointer-events-auto">
|
||||||
|
|
|
@ -147,8 +147,6 @@ export type EditorStore = {
|
||||||
editables: Record<string, Editable>
|
editables: Record<string, Editable>
|
||||||
// this will come in handy when we start supporting multiple canvases
|
// this will come in handy when we start supporting multiple canvases
|
||||||
canvasName: string
|
canvasName: string
|
||||||
transformControlsMode: TransformControlsMode
|
|
||||||
transformControlsSpace: TransformControlsSpace
|
|
||||||
viewportShading: ViewportShading
|
viewportShading: ViewportShading
|
||||||
sceneSnapshot: Scene | null
|
sceneSnapshot: Scene | null
|
||||||
editablesSnapshot: Record<string, EditableSnapshot> | null
|
editablesSnapshot: Record<string, EditableSnapshot> | null
|
||||||
|
@ -172,8 +170,6 @@ export type EditorStore = {
|
||||||
addEditable: <T extends EditableType>(type: T, uniqueName: string) => void
|
addEditable: <T extends EditableType>(type: T, uniqueName: string) => void
|
||||||
removeEditable: (uniqueName: string) => void
|
removeEditable: (uniqueName: string) => void
|
||||||
setSelectedHdr: (hdr: string | null) => void
|
setSelectedHdr: (hdr: string | null) => void
|
||||||
setTransformControlsMode: (mode: TransformControlsMode) => void
|
|
||||||
setTransformControlsSpace: (mode: TransformControlsSpace) => void
|
|
||||||
setViewportShading: (mode: ViewportShading) => void
|
setViewportShading: (mode: ViewportShading) => void
|
||||||
setUseHdrAsBackground: (use: boolean) => void
|
setUseHdrAsBackground: (use: boolean) => void
|
||||||
createSnapshot: () => void
|
createSnapshot: () => void
|
||||||
|
@ -211,8 +207,6 @@ const config: StateCreator<EditorStore> = (set, get) => {
|
||||||
helpersRoot: new Group(),
|
helpersRoot: new Group(),
|
||||||
editables: {},
|
editables: {},
|
||||||
canvasName: 'default',
|
canvasName: 'default',
|
||||||
transformControlsMode: 'translate',
|
|
||||||
transformControlsSpace: 'world',
|
|
||||||
viewportShading: 'rendered',
|
viewportShading: 'rendered',
|
||||||
sceneSnapshot: null,
|
sceneSnapshot: null,
|
||||||
editablesSnapshot: null,
|
editablesSnapshot: null,
|
||||||
|
@ -298,12 +292,6 @@ const config: StateCreator<EditorStore> = (set, get) => {
|
||||||
setSelectedHdr: (hdr) => {
|
setSelectedHdr: (hdr) => {
|
||||||
set({selectedHdr: hdr})
|
set({selectedHdr: hdr})
|
||||||
},
|
},
|
||||||
setTransformControlsMode: (mode) => {
|
|
||||||
set({transformControlsMode: mode})
|
|
||||||
},
|
|
||||||
setTransformControlsSpace: (mode) => {
|
|
||||||
set({transformControlsSpace: mode})
|
|
||||||
},
|
|
||||||
setViewportShading: (mode) => {
|
setViewportShading: (mode) => {
|
||||||
set({viewportShading: mode})
|
set({viewportShading: mode})
|
||||||
},
|
},
|
||||||
|
@ -347,6 +335,14 @@ const editorSheetObjectConfig = {
|
||||||
showGrid: types.boolean(true),
|
showGrid: types.boolean(true),
|
||||||
showOverlayIcons: types.boolean(false),
|
showOverlayIcons: types.boolean(false),
|
||||||
referenceWindowSize: types.number(120, {min: 0, max: 800}),
|
referenceWindowSize: types.number(120, {min: 0, max: 800}),
|
||||||
|
transformControlsMode: types.stringLiteral<TransformControlsMode>(
|
||||||
|
'translate',
|
||||||
|
['translate', 'rotate', 'scale'],
|
||||||
|
),
|
||||||
|
transformControlsSpace: types.stringLiteral<TransformControlsSpace>(
|
||||||
|
'world',
|
||||||
|
['local', 'world'],
|
||||||
|
),
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue