Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

theatre/r3f: Allow physical lighting in snapshot viewport #114

Merged
merged 4 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions packages/r3f/src/components/DragDetector.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import type {
FC,
ReactNode} from 'react';
import type {FC, ReactNode} from 'react'
import React, {
createContext,
useContext,
Expand Down
24 changes: 18 additions & 6 deletions packages/r3f/src/components/SnapshotEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {useCallback, useLayoutEffect, useMemo} from 'react'
import {useCallback, useEffect, useLayoutEffect, useMemo} 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 {allRegisteredObjects, useEditorStore} from '../store'
import shallow from 'zustand/shallow'
Expand Down Expand Up @@ -42,13 +42,28 @@ const EditorScene: React.FC<{snapshotEditorSheet: ISheet; paneId: string}> = ({
snapshotEditorSheet,
paneId,
}) => {
const [gl, scene, camera] = useThree(
(store) => [store.gl, store.scene, store.camera] as const,
shallow,
)

const [editorCamera, orbitControlsRef] = useSnapshotEditorCamera(
snapshotEditorSheet,
paneId,
)

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 showGrid = useVal(editorObject?.props.viewport.showGrid) ?? true
Expand Down Expand Up @@ -182,14 +197,11 @@ const SnapshotEditor: React.FC<{paneId: string}> = (props) => {
<>
<CanvasWrapper>
<Canvas
// @ts-ignore
colorManagement
onCreated={({gl}) => {
gl.setClearColor('white')
}}
shadowMap
shadows
dpr={[1, 2]}
fog={'red'}
frameloop="demand"
onPointerMissed={onPointerMissed}
>
Expand Down
4 changes: 2 additions & 2 deletions packages/r3f/src/components/TooltipPortalProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {ReactNode} from 'react';
import React, { useState} from 'react'
import type {ReactNode} from 'react'
import React, {useState} from 'react'
import {PortalContext} from 'reakit'
import styled from 'styled-components'

Expand Down
8 changes: 8 additions & 0 deletions packages/r3f/src/components/editorStuff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ const editorSheetObjectConfig = {
showReferenceWindow: types.boolean(true, {
label: 'Reference',
}),
lighting: types.stringLiteral(
'physical',
{
physical: 'Physical',
legacy: 'Legacy',
},
{as: 'menu', label: 'Lighting'},
),
},
{label: 'Viewport Config'},
),
Expand Down
2 changes: 1 addition & 1 deletion packages/r3f/src/components/useSnapshotEditorCamera.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {MutableRefObject} from 'react'
import {useLayoutEffect, useRef} from 'react'
import React from 'react'
import useRefAndState from './useRefAndState'
import type {IScrub} from '@theatre/studio';
import type {IScrub} from '@theatre/studio'
import studio from '@theatre/studio'
import type {PerspectiveCamera as PerspectiveCameraImpl} from 'three'
import type {ISheet} from '@theatre/core'
Expand Down
3 changes: 1 addition & 2 deletions theatre/core/src/sheets/Sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ type SheetObjectMap = StrictRecord<ObjectAddressKey, SheetObject>
export type ObjectNativeObject = unknown

export default class Sheet {
private readonly _objects: Atom<SheetObjectMap> =
new Atom<SheetObjectMap>({})
private readonly _objects: Atom<SheetObjectMap> = new Atom<SheetObjectMap>({})
private _sequence: undefined | Sequence
readonly address: SheetAddress
readonly publicApi: TheatreSheet
Expand Down