From 636e7fe82a40b799133fd3584d9478db1ec44a7f Mon Sep 17 00:00:00 2001 From: Aria Minaei Date: Tue, 29 Jun 2021 15:47:27 +0200 Subject: [PATCH] Chore: Simplified object config in r3f --- .../plugin-r3f/src/components/editable.tsx | 7 +-- packages/plugin-r3f/src/store.ts | 49 +++++++------------ 2 files changed, 22 insertions(+), 34 deletions(-) diff --git a/packages/plugin-r3f/src/components/editable.tsx b/packages/plugin-r3f/src/components/editable.tsx index 5633346..3832230 100644 --- a/packages/plugin-r3f/src/components/editable.tsx +++ b/packages/plugin-r3f/src/components/editable.tsx @@ -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 diff --git a/packages/plugin-r3f/src/store.ts b/packages/plugin-r3f/src/store.ts index a25beb5..9472691 100644 --- a/packages/plugin-r3f/src/store.ts +++ b/packages/plugin-r3f/src/store.ts @@ -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), - }), - rotation: compound({ - x: number(0), - y: number(0), - z: number(0), - }), - scale: compound({ - x: number(1), - y: number(1), - z: number(1), - }), +export const baseSheetObjectType = { + props: types.compound({ + position: types.compound({ + x: types.number(0), + y: types.number(0), + z: types.number(0), }), - } + rotation: types.compound({ + x: types.number(0), + y: types.number(0), + z: types.number(0), + }), + scale: types.compound({ + x: types.number(1), + y: types.number(1), + z: types.number(1), + }), + }), } -export const getBaseObjectConfig = (() => { - let base: undefined | ReturnType - return (): ReturnType => { - if (!base) { - base = createBaseObjectConfig() - } - return base! - } -})() - export type BaseSheetObjectType = ISheetObject< - ReturnType['props'] + typeof baseSheetObjectType['props'] > export interface AbstractEditable {