#
luxiaotao1123
2024-04-18 778f20cec7a0e52c8839f4c1bcb788121f157782
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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;