import {editable as e, bindToCanvas} from '@theatre/plugin-r3f' import {PerspectiveCamera} from '@react-three/drei' import {getProject} from '@theatre/core' import * as THREE from 'three' import React, {useState, useEffect, useRef} from 'react' import type {Color} from '@react-three/fiber' import {Canvas, useFrame} from '@react-three/fiber' import {softShadows, Shadow} from '@react-three/drei' import type {DirectionalLight} from 'three' import type {$FixMe} from '../../../plugin-r3f/src/types' const ECamera = e(PerspectiveCamera, 'perspectiveCamera') // 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 as any) 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 as THREE.PerspectiveCamera camera.fov = (THREE as $FixMe).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 }: {color: Color; uniqueName: string} & Parameters[0]) { return ( ) } function App() { return (
) } export default App