theatre/r3f: Allow physical lighting in snapshot viewport (#114)
Co-authored-by: Andrew Prifer <andrew.prifer@gmail.com>
This commit is contained in:
parent
c15c88fcec
commit
386a8fafac
6 changed files with 31 additions and 14 deletions
|
@ -1,6 +1,4 @@
|
||||||
import type {
|
import type {FC, ReactNode} from 'react'
|
||||||
FC,
|
|
||||||
ReactNode} from 'react';
|
|
||||||
import React, {
|
import React, {
|
||||||
createContext,
|
createContext,
|
||||||
useContext,
|
useContext,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import {useCallback, useLayoutEffect, useMemo} from 'react'
|
import {useCallback, useEffect, useLayoutEffect, useMemo} from 'react'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {Canvas} from '@react-three/fiber'
|
import {Canvas, useThree} from '@react-three/fiber'
|
||||||
import type {BaseSheetObjectType} from '../store'
|
import type {BaseSheetObjectType} from '../store'
|
||||||
import {allRegisteredObjects, useEditorStore} from '../store'
|
import {allRegisteredObjects, useEditorStore} from '../store'
|
||||||
import shallow from 'zustand/shallow'
|
import shallow from 'zustand/shallow'
|
||||||
|
@ -42,6 +42,11 @@ const EditorScene: React.FC<{snapshotEditorSheet: ISheet; paneId: string}> = ({
|
||||||
snapshotEditorSheet,
|
snapshotEditorSheet,
|
||||||
paneId,
|
paneId,
|
||||||
}) => {
|
}) => {
|
||||||
|
const [gl, scene, camera] = useThree(
|
||||||
|
(store) => [store.gl, store.scene, store.camera] as const,
|
||||||
|
shallow,
|
||||||
|
)
|
||||||
|
|
||||||
const [editorCamera, orbitControlsRef] = useSnapshotEditorCamera(
|
const [editorCamera, orbitControlsRef] = useSnapshotEditorCamera(
|
||||||
snapshotEditorSheet,
|
snapshotEditorSheet,
|
||||||
paneId,
|
paneId,
|
||||||
|
@ -49,6 +54,16 @@ const EditorScene: React.FC<{snapshotEditorSheet: ISheet; paneId: string}> = ({
|
||||||
|
|
||||||
const editorObject = getEditorSheetObject()
|
const editorObject = getEditorSheetObject()
|
||||||
|
|
||||||
|
const viewportLighting =
|
||||||
|
useVal(editorObject?.props.viewport.lighting) ?? 'physical'
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (gl && scene && camera) {
|
||||||
|
gl.physicallyCorrectLights = viewportLighting === 'physical'
|
||||||
|
gl.compile(scene, camera)
|
||||||
|
}
|
||||||
|
}, [gl, viewportLighting, scene, camera])
|
||||||
|
|
||||||
const helpersRoot = useEditorStore((state) => state.helpersRoot, shallow)
|
const helpersRoot = useEditorStore((state) => state.helpersRoot, shallow)
|
||||||
|
|
||||||
const showGrid = useVal(editorObject?.props.viewport.showGrid) ?? true
|
const showGrid = useVal(editorObject?.props.viewport.showGrid) ?? true
|
||||||
|
@ -182,14 +197,11 @@ const SnapshotEditor: React.FC<{paneId: string}> = (props) => {
|
||||||
<>
|
<>
|
||||||
<CanvasWrapper>
|
<CanvasWrapper>
|
||||||
<Canvas
|
<Canvas
|
||||||
// @ts-ignore
|
|
||||||
colorManagement
|
|
||||||
onCreated={({gl}) => {
|
onCreated={({gl}) => {
|
||||||
gl.setClearColor('white')
|
gl.setClearColor('white')
|
||||||
}}
|
}}
|
||||||
shadowMap
|
shadows
|
||||||
dpr={[1, 2]}
|
dpr={[1, 2]}
|
||||||
fog={'red'}
|
|
||||||
frameloop="demand"
|
frameloop="demand"
|
||||||
onPointerMissed={onPointerMissed}
|
onPointerMissed={onPointerMissed}
|
||||||
>
|
>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import type {ReactNode} from 'react';
|
import type {ReactNode} from 'react'
|
||||||
import React, {useState} from 'react'
|
import React, {useState} from 'react'
|
||||||
import {PortalContext} from 'reakit'
|
import {PortalContext} from 'reakit'
|
||||||
import styled from 'styled-components'
|
import styled from 'styled-components'
|
||||||
|
|
|
@ -25,6 +25,14 @@ const editorSheetObjectConfig = {
|
||||||
showReferenceWindow: types.boolean(true, {
|
showReferenceWindow: types.boolean(true, {
|
||||||
label: 'Reference',
|
label: 'Reference',
|
||||||
}),
|
}),
|
||||||
|
lighting: types.stringLiteral(
|
||||||
|
'physical',
|
||||||
|
{
|
||||||
|
physical: 'Physical',
|
||||||
|
legacy: 'Legacy',
|
||||||
|
},
|
||||||
|
{as: 'menu', label: 'Lighting'},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
{label: 'Viewport Config'},
|
{label: 'Viewport Config'},
|
||||||
),
|
),
|
||||||
|
|
|
@ -4,7 +4,7 @@ import type {MutableRefObject} from 'react'
|
||||||
import {useLayoutEffect, useRef} from 'react'
|
import {useLayoutEffect, useRef} from 'react'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import useRefAndState from './useRefAndState'
|
import useRefAndState from './useRefAndState'
|
||||||
import type {IScrub} from '@theatre/studio';
|
import type {IScrub} from '@theatre/studio'
|
||||||
import studio from '@theatre/studio'
|
import studio from '@theatre/studio'
|
||||||
import type {PerspectiveCamera as PerspectiveCameraImpl} from 'three'
|
import type {PerspectiveCamera as PerspectiveCameraImpl} from 'three'
|
||||||
import type {ISheet} from '@theatre/core'
|
import type {ISheet} from '@theatre/core'
|
||||||
|
|
|
@ -21,8 +21,7 @@ type SheetObjectMap = StrictRecord<ObjectAddressKey, SheetObject>
|
||||||
export type ObjectNativeObject = unknown
|
export type ObjectNativeObject = unknown
|
||||||
|
|
||||||
export default class Sheet {
|
export default class Sheet {
|
||||||
private readonly _objects: Atom<SheetObjectMap> =
|
private readonly _objects: Atom<SheetObjectMap> = new Atom<SheetObjectMap>({})
|
||||||
new Atom<SheetObjectMap>({})
|
|
||||||
private _sequence: undefined | Sequence
|
private _sequence: undefined | Sequence
|
||||||
readonly address: SheetAddress
|
readonly address: SheetAddress
|
||||||
readonly publicApi: TheatreSheet
|
readonly publicApi: TheatreSheet
|
||||||
|
|
Loading…
Reference in a new issue