-
Notifications
You must be signed in to change notification settings - Fork 14
/
Floor.tsx
50 lines (46 loc) · 1.2 KB
/
Floor.tsx
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
46
47
48
49
50
import React from 'react'
import { GroupProps } from '@react-three/fiber'
const BIG_NUM = 2**16
export interface FloorProps extends GroupProps {
visible?: boolean
width?: number
length?: number
noShadow?: boolean
offset: number
}
const Floor: React.FC<FloorProps> = (
{
visible = false,
width,
length,
noShadow = false,
offset = 0,
...otherProps
}
) => {
const position: [number, number, number] = [
(width ?? 0)/2,
(length ?? 0)/2,
-offset
]
const planeArgs: [number, number, number, number] = [
width ?? BIG_NUM,
length ?? BIG_NUM,
Math.floor((width ?? 20) / 20),
Math.floor((length ?? 20) / 20)
]
if (!visible) return null
return (
<group {...otherProps} >
{(width != null) && (length != null) && <mesh receiveShadow={true} position={position}>
<planeGeometry args={planeArgs}/>
<meshStandardMaterial wireframe={true} color={'#777'}/>
</mesh>}
{!noShadow && <mesh receiveShadow={true} position={position}>
<planeGeometry args={planeArgs}/>
<shadowMaterial opacity={0.2}/>
</mesh>}
</group>
)
}
export default Floor