diff --git a/packages/playground/src/shared/r3f-rocket/App.tsx b/packages/playground/src/shared/r3f-rocket/App.tsx index 88cee73..da23f66 100644 --- a/packages/playground/src/shared/r3f-rocket/App.tsx +++ b/packages/playground/src/shared/r3f-rocket/App.tsx @@ -1,10 +1,11 @@ import {editable as e, RefreshSnapshot, SheetProvider} from '@theatre/r3f' -import { Stars} from '@react-three/drei' +import {Stars} from '@react-three/drei' import {getProject} from '@theatre/core' -import React, {Suspense, useState} from 'react' +import React, {Suspense, useMemo, useState} from 'react' import {Canvas} from '@react-three/fiber' import {useGLTF, PerspectiveCamera} from '@react-three/drei' import sceneGLB from './scene.glb' +import {Color} from 'three' document.body.style.backgroundColor = '#171717' @@ -55,7 +56,13 @@ function App() { > getProject('Space').sheet('Scene')}> - + new Color(bg), [bg])} + near={16} + far={30} + uniqueName="Fog" + /> = ({ // Helpers const scene = useThree((state) => state.scene) - const helper = useMemo( - () => editable.objectConfig.createHelper(object), + const helper = useMemo( + () => editable.objectConfig.createHelper?.(object), [object], ) useEffect(() => { + if (helper == undefined) { + return + } + if (selected === uniqueName || hovered) { scene.add(helper) invalidate() @@ -75,6 +79,10 @@ const EditableProxy: VFC = ({ } }, [selected, hovered, helper, scene]) useFrame(() => { + if (helper == undefined) { + return + } + if (helper.update) { helper.update() } diff --git a/packages/r3f/src/defaultEditableFactoryConfig.ts b/packages/r3f/src/defaultEditableFactoryConfig.ts index cdabff9..a893304 100644 --- a/packages/r3f/src/defaultEditableFactoryConfig.ts +++ b/packages/r3f/src/defaultEditableFactoryConfig.ts @@ -1,5 +1,6 @@ import type {EditableFactoryConfig} from './editableFactoryConfigUtils' import { + createColorPropConfig, createNumberPropConfig, createVector, createVectorPropConfig, @@ -100,6 +101,15 @@ const defaultEditableFactoryConfig = { line: baseObjectConfig, lineLoop: baseObjectConfig, lineSegments: baseObjectConfig, + fog: { + props: { + color: createColorPropConfig('color'), + near: createNumberPropConfig('near', 1, {nudgeMultiplier: 0.1}), + far: createNumberPropConfig('far', 1000, {nudgeMultiplier: 0.1}), + }, + useTransformControls: false, + icon: 'cloud' as const, + }, } // Assert that the config is indeed of EditableFactoryConfig without actually diff --git a/packages/r3f/src/editableFactoryConfigUtils.ts b/packages/r3f/src/editableFactoryConfigUtils.ts index c9bc851..f694003 100644 --- a/packages/r3f/src/editableFactoryConfigUtils.ts +++ b/packages/r3f/src/editableFactoryConfigUtils.ts @@ -17,7 +17,7 @@ type Meta = { updateObject?: (object: T) => void icon: IconID dimensionless?: boolean - createHelper: (object: T) => Helper + createHelper?: (object: T) => Helper } export type ObjectConfig = {props: Props} & Meta export type EditableFactoryConfig = Partial< @@ -79,7 +79,7 @@ export const createNumberPropConfig = ( {nudgeMultiplier = 0.01} = {}, ): PropConfig => ({ parse: (props) => { - return props[key] ?? defaultValue ?? 0 + return props[key] ?? defaultValue }, apply: (value, object) => { object[key] = value diff --git a/packages/r3f/src/icons.tsx b/packages/r3f/src/icons.tsx index 1a54e96..abaf4cf 100644 --- a/packages/r3f/src/icons.tsx +++ b/packages/r3f/src/icons.tsx @@ -1,4 +1,8 @@ -import {BsCameraVideoFill, BsFillCollectionFill} from 'react-icons/bs' +import { + BsCameraVideoFill, + BsFillCollectionFill, + BsCloudFill, +} from 'react-icons/bs' import {GiCube, GiLightBulb, GiLightProjector} from 'react-icons/gi' import {BiSun} from 'react-icons/bi' import React from 'react' @@ -10,6 +14,7 @@ const icons = { spotLight: , sun: , camera: , + cloud: , } export type IconID = keyof typeof icons