Chore: Simplified object config in r3f
This commit is contained in:
parent
d416da5a2f
commit
636e7fe82a
2 changed files with 22 additions and 34 deletions
|
@ -11,10 +11,11 @@ import type {
|
|||
} from 'three'
|
||||
import {Vector3} from 'three'
|
||||
import type {EditableType} from '../store'
|
||||
import {getBaseObjectConfig, useEditorStore} from '../store'
|
||||
import {baseSheetObjectType} from '../store'
|
||||
import {useEditorStore} from '../store'
|
||||
import mergeRefs from 'react-merge-refs'
|
||||
import type {$FixMe} from '@theatre/shared/utils/types'
|
||||
import type {ISheetObject} from '../../../../theatre/core/src/sheetObjects/TheatreSheetObject'
|
||||
import type {ISheetObject} from '@theatre/core'
|
||||
|
||||
const log = console.log
|
||||
|
||||
|
@ -57,7 +58,7 @@ const editable = <
|
|||
|
||||
useLayoutEffect(() => {
|
||||
if (!sheet) return
|
||||
const sheetObject = sheet.object(uniqueName, {}, getBaseObjectConfig())
|
||||
const sheetObject = sheet.object(uniqueName, {}, baseSheetObjectType)
|
||||
setSheetObject(sheetObject)
|
||||
|
||||
useEditorStore
|
||||
|
|
|
@ -22,41 +22,28 @@ export type TransformControlsMode = 'translate' | 'rotate' | 'scale'
|
|||
export type TransformControlsSpace = 'world' | 'local'
|
||||
export type ViewportShading = 'wireframe' | 'flat' | 'solid' | 'rendered'
|
||||
|
||||
export const createBaseObjectConfig = () => {
|
||||
const {compound, number} = types
|
||||
return {
|
||||
props: compound({
|
||||
position: compound({
|
||||
x: number(0),
|
||||
y: number(0),
|
||||
z: number(0),
|
||||
export const baseSheetObjectType = {
|
||||
props: types.compound({
|
||||
position: types.compound({
|
||||
x: types.number(0),
|
||||
y: types.number(0),
|
||||
z: types.number(0),
|
||||
}),
|
||||
rotation: compound({
|
||||
x: number(0),
|
||||
y: number(0),
|
||||
z: number(0),
|
||||
rotation: types.compound({
|
||||
x: types.number(0),
|
||||
y: types.number(0),
|
||||
z: types.number(0),
|
||||
}),
|
||||
scale: compound({
|
||||
x: number(1),
|
||||
y: number(1),
|
||||
z: number(1),
|
||||
scale: types.compound({
|
||||
x: types.number(1),
|
||||
y: types.number(1),
|
||||
z: types.number(1),
|
||||
}),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
export const getBaseObjectConfig = (() => {
|
||||
let base: undefined | ReturnType<typeof createBaseObjectConfig>
|
||||
return (): ReturnType<typeof createBaseObjectConfig> => {
|
||||
if (!base) {
|
||||
base = createBaseObjectConfig()
|
||||
}
|
||||
return base!
|
||||
}
|
||||
})()
|
||||
|
||||
export type BaseSheetObjectType = ISheetObject<
|
||||
ReturnType<typeof getBaseObjectConfig>['props']
|
||||
typeof baseSheetObjectType['props']
|
||||
>
|
||||
|
||||
export interface AbstractEditable<T extends EditableType> {
|
||||
|
|
Loading…
Reference in a new issue