2022-05-25 00:37:18 +02:00
|
|
|
import {getProject} from '@theatre/core'
|
2023-07-30 15:41:09 +02:00
|
|
|
import React, {useEffect, useRef} from 'react'
|
2022-09-13 21:37:39 +02:00
|
|
|
import {Canvas} from '@react-three/fiber'
|
2023-07-30 15:41:09 +02:00
|
|
|
import {editable as e, SheetProvider, PerspectiveCamera} from '@theatre/r3f'
|
|
|
|
import state from './state.json'
|
2022-09-13 21:37:39 +02:00
|
|
|
|
|
|
|
// credit: https://codesandbox.io/s/camera-pan-nsb7f
|
|
|
|
|
2023-07-30 15:41:09 +02:00
|
|
|
function Plane({color, theatreKey, ...props}: any) {
|
2022-09-13 21:37:39 +02:00
|
|
|
return (
|
2022-09-14 14:36:49 +02:00
|
|
|
<e.mesh {...props} theatreKey={theatreKey}>
|
2022-09-13 21:37:39 +02:00
|
|
|
<boxBufferGeometry />
|
|
|
|
<meshStandardMaterial color={color} />
|
|
|
|
</e.mesh>
|
|
|
|
)
|
|
|
|
}
|
2022-05-25 00:37:18 +02:00
|
|
|
|
2023-07-30 15:41:09 +02:00
|
|
|
export default function App() {
|
|
|
|
const light2Ref = useRef<any>()
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const interval = setInterval(() => {
|
|
|
|
if (!light2Ref.current) return
|
|
|
|
|
|
|
|
clearInterval(interval)
|
|
|
|
|
|
|
|
const intensityInStateJson = 3
|
|
|
|
const currentIntensity = light2Ref.current.intensity
|
|
|
|
if (currentIntensity !== intensityInStateJson) {
|
|
|
|
console.error(`Test failed: light2.intensity is ${currentIntensity}`)
|
|
|
|
} else {
|
|
|
|
console.log(`Test passed: light2.intensity is ${intensityInStateJson}`)
|
|
|
|
}
|
|
|
|
}, 50)
|
|
|
|
// see the note on <e.pointLight theatreKey="Light 2" /> below to understand why we're doing this
|
|
|
|
}, [])
|
|
|
|
|
2022-09-13 21:37:39 +02:00
|
|
|
return (
|
|
|
|
<Canvas
|
|
|
|
gl={{preserveDrawingBuffer: true}}
|
|
|
|
linear
|
|
|
|
frameloop="demand"
|
|
|
|
dpr={[1.5, 2]}
|
|
|
|
style={{position: 'absolute', top: 0, left: 0}}
|
|
|
|
>
|
2023-07-30 15:41:09 +02:00
|
|
|
<SheetProvider
|
|
|
|
sheet={getProject('Playground - R3F', {state}).sheet('R3F-Canvas')}
|
|
|
|
>
|
2022-09-13 21:37:39 +02:00
|
|
|
{/* @ts-ignore */}
|
2023-07-30 15:41:09 +02:00
|
|
|
<PerspectiveCamera makeDefault theatreKey="Camera" />
|
2022-09-13 21:37:39 +02:00
|
|
|
<ambientLight intensity={0.4} />
|
|
|
|
<e.pointLight
|
|
|
|
position={[-10, -10, 5]}
|
|
|
|
intensity={2}
|
|
|
|
color="#ff20f0"
|
2022-09-14 14:36:49 +02:00
|
|
|
theatreKey="Light 1"
|
2022-09-13 21:37:39 +02:00
|
|
|
/>
|
|
|
|
<e.pointLight
|
|
|
|
position={[0, 0.5, -1]}
|
|
|
|
distance={1}
|
2023-07-30 15:41:09 +02:00
|
|
|
// the intensity is statically set to 2, but in the state.json file we'll set it to 3,
|
|
|
|
// and we'll use that as a test to make sure the state is being loaded correctly
|
2022-09-13 21:37:39 +02:00
|
|
|
intensity={2}
|
|
|
|
color="#e4be00"
|
2022-09-14 14:36:49 +02:00
|
|
|
theatreKey="Light 2"
|
2023-07-30 15:41:09 +02:00
|
|
|
ref={light2Ref}
|
2022-09-13 21:37:39 +02:00
|
|
|
/>
|
2023-07-30 15:41:09 +02:00
|
|
|
|
2022-09-13 21:37:39 +02:00
|
|
|
<group position={[0, -0.9, -3]}>
|
|
|
|
<Plane
|
|
|
|
color="hotpink"
|
|
|
|
rotation-x={-Math.PI / 2}
|
|
|
|
position-z={2}
|
|
|
|
scale={[4, 20, 0.2]}
|
2022-09-14 14:36:49 +02:00
|
|
|
theatreKey="plane1"
|
2022-09-13 21:37:39 +02:00
|
|
|
/>
|
|
|
|
<Plane
|
|
|
|
color="#e4be00"
|
|
|
|
rotation-x={-Math.PI / 2}
|
|
|
|
position-y={1}
|
|
|
|
scale={[4.2, 0.2, 4]}
|
2022-09-14 14:36:49 +02:00
|
|
|
theatreKey="plane2"
|
2022-09-13 21:37:39 +02:00
|
|
|
/>
|
|
|
|
<Plane
|
|
|
|
color="#736fbd"
|
|
|
|
rotation-x={-Math.PI / 2}
|
|
|
|
position={[-1.7, 1, 3.5]}
|
|
|
|
scale={[0.5, 4, 4]}
|
2022-09-14 14:36:49 +02:00
|
|
|
theatreKey="plane3"
|
2022-09-13 21:37:39 +02:00
|
|
|
/>
|
|
|
|
<Plane
|
|
|
|
color="white"
|
|
|
|
rotation-x={-Math.PI / 2}
|
|
|
|
position={[0, 4.5, 3]}
|
|
|
|
scale={[2, 0.03, 4]}
|
2022-09-14 14:36:49 +02:00
|
|
|
theatreKey="plane4"
|
2022-09-13 21:37:39 +02:00
|
|
|
/>
|
|
|
|
</group>
|
|
|
|
</SheetProvider>
|
|
|
|
</Canvas>
|
|
|
|
)
|
|
|
|
}
|