import {getProject} from '@theatre/core' import * as THREE from 'three' import {useState, useEffect, useRef} from 'react' import {useFrame, Canvas} from '@react-three/fiber' import {Shadow, softShadows} from '@react-three/drei' import React from 'react' import studio from '@theatre/studio' import {editable as e, SheetProvider, extension} from '@theatre/r3f' if (process.env.NODE_ENV === 'development') { studio.extend(extension) studio.initialize() } // Soft shadows are expensive, comment and refresh when it's too slow softShadows() // credit: https://codesandbox.io/s/camera-pan-nsb7f function Button() { const vec = new THREE.Vector3() const light = useRef(undefined) const [active, setActive] = useState(false) const [zoom, set] = useState(true) useEffect( () => void (document.body.style.cursor = active ? 'pointer' : 'auto'), [active], ) useFrame((state) => { const step = 0.1 const camera = state.camera camera.fov = THREE.MathUtils.lerp(camera.fov, zoom ? 10 : 42, step) camera.position.lerp( vec.set(zoom ? 25 : 10, zoom ? 1 : 5, zoom ? 0 : 10), step, ) state.camera.lookAt(0, 0, 0) state.camera.updateProjectionMatrix() light.current.position.lerp( vec.set(zoom ? 4 : 0, zoom ? 3 : 8, zoom ? 3 : 5), step, ) }) return ( set(!zoom)} onPointerOver={() => setActive(true)} onPointerOut={() => setActive(false)} uniqueName="The Button" > ) } function Plane({color, uniqueName, ...props}) { return ( ) } function App() { return (
getProject('Playground - R3F').sheet('R3F-Canvas')} > {/* @ts-ignore */}
) } export default App