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'
|
} from 'three'
|
||||||
import {Vector3} from 'three'
|
import {Vector3} from 'three'
|
||||||
import type {EditableType} from '../store'
|
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 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/src/sheetObjects/TheatreSheetObject'
|
import type {ISheetObject} from '@theatre/core'
|
||||||
|
|
||||||
const log = console.log
|
const log = console.log
|
||||||
|
|
||||||
|
@ -57,7 +58,7 @@ const editable = <
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
if (!sheet) return
|
if (!sheet) return
|
||||||
const sheetObject = sheet.object(uniqueName, {}, getBaseObjectConfig())
|
const sheetObject = sheet.object(uniqueName, {}, baseSheetObjectType)
|
||||||
setSheetObject(sheetObject)
|
setSheetObject(sheetObject)
|
||||||
|
|
||||||
useEditorStore
|
useEditorStore
|
||||||
|
|
|
@ -22,41 +22,28 @@ export type TransformControlsMode = 'translate' | 'rotate' | 'scale'
|
||||||
export type TransformControlsSpace = 'world' | 'local'
|
export type TransformControlsSpace = 'world' | 'local'
|
||||||
export type ViewportShading = 'wireframe' | 'flat' | 'solid' | 'rendered'
|
export type ViewportShading = 'wireframe' | 'flat' | 'solid' | 'rendered'
|
||||||
|
|
||||||
export const createBaseObjectConfig = () => {
|
export const baseSheetObjectType = {
|
||||||
const {compound, number} = types
|
props: types.compound({
|
||||||
return {
|
position: types.compound({
|
||||||
props: compound({
|
x: types.number(0),
|
||||||
position: compound({
|
y: types.number(0),
|
||||||
x: number(0),
|
z: types.number(0),
|
||||||
y: number(0),
|
|
||||||
z: number(0),
|
|
||||||
}),
|
}),
|
||||||
rotation: compound({
|
rotation: types.compound({
|
||||||
x: number(0),
|
x: types.number(0),
|
||||||
y: number(0),
|
y: types.number(0),
|
||||||
z: number(0),
|
z: types.number(0),
|
||||||
}),
|
}),
|
||||||
scale: compound({
|
scale: types.compound({
|
||||||
x: number(1),
|
x: types.number(1),
|
||||||
y: number(1),
|
y: types.number(1),
|
||||||
z: 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<
|
export type BaseSheetObjectType = ISheetObject<
|
||||||
ReturnType<typeof getBaseObjectConfig>['props']
|
typeof baseSheetObjectType['props']
|
||||||
>
|
>
|
||||||
|
|
||||||
export interface AbstractEditable<T extends EditableType> {
|
export interface AbstractEditable<T extends EditableType> {
|
||||||
|
|
Loading…
Reference in a new issue