import { useRef, useState } from 'react'
|
import { Canvas, useFrame } from '@react-three/fiber'
|
import { OrbitControls } from '@react-three/drei'
|
import { Environment } from '@react-three/drei'
|
|
const Box = (props) => {
|
|
const ref = useRef()
|
|
const [hovered, hover] = useState(false)
|
const [clicked, click] = useState(false)
|
|
useFrame((state, delta) => (ref.current.rotation.x += delta))
|
|
return (
|
<mesh
|
{...props}
|
ref={ref}
|
scale={clicked ? 1.5 : 1}
|
onClick={(event) => click(!clicked)}
|
onPointerOver={(event) => (event.stopPropagation(), hover(true))}
|
onPointerOut={(event) => hover(false)}>
|
<boxGeometry args={[1, 1, 1]} />
|
<meshStandardMaterial color={hovered ? 'hotpink' : 'orange'} />
|
</mesh>
|
)
|
}
|
|
const Base = () => {
|
return (
|
<div style={{ height: '500px', width: '500px' }}>
|
<Canvas>
|
<ambientLight intensity={Math.PI / 2} />
|
<spotLight position={[10, 10, 10]} angle={0.15} penumbra={1} decay={0} intensity={Math.PI} />
|
<pointLight position={[-10, -10, -10]} decay={0} intensity={Math.PI} />
|
<Box position={[0, 0, 0]} />
|
<OrbitControls />
|
<Environment preset="city" />
|
</Canvas>
|
</div>
|
|
)
|
}
|
|
export default Base;
|