-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlsd.js
86 lines (74 loc) · 2.28 KB
/
lsd.js
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import React, { useRef, useState } from "react";
import { Canvas, useFrame } from "react-three-fiber";
import "../styles.css";
import { PerspectiveCamera } from "three";
class Woodlands extends React.Component {
constructor(props) {
super(props);
this.state = {
map: []
};
}
componentDidMount() {
let mapData = [];
$i = 0;
for (let row = 0; row < 128; row++) {
mapData[row] = [];
for (let block = 0; block < 128; block++) {
let high = $i + 0.5;
let low = $i - 0.5;
calculatedHeight = Math.random() * (0 + high - low + low);
$i = calculatedHeight;
mapData[row].push(calculatedHeight);
}
}
this.setState({ map: mapData });
}
Box(props) {
// This reference will give us direct access to the mesh
const mesh = useRef();
// Set up state for the hovered and active state
const [hovered, setHover] = useState(false);
const [active, setActive] = useState(false);
// Rotate mesh every frame, this is outside of React without overhead
useFrame(() => (hovered ? (mesh.current.scale.y += 0.1) : true));
return (
<mesh
{...props}
ref={mesh}
scale={active ? [1.5, 1.5, 1.5] : [1, 1, 1]}
onClick={e => setActive(!active)}
onPointerOver={e => setHover(true)}
onPointerOut={e => setHover(false)}
>
<boxBufferGeometry attach="geometry" args={[1, 1, 1]} />
<meshStandardMaterial
attach="material"
color={hovered ? "hotpink" : 0x1a171a}
/>
</mesh>
);
}
row(row, z) {
return row.map((y, x) => {
return <this.Box position={[x - 64, y - 8, z - 128]} />;
});
}
roof(row, z) {
return row.map((y, x) => {
return <this.Box position={[x - 64, y + 8, z - 128]} />;
});
}
render() {
return (
<Canvas>
<ambientLight intensity={1} />
{/* <pointLight intensity={0.25} position={[0, 50, 0]} /> */}
<pointLight intensity={0.5} position={[0, 10, -128]} />
<pointLight intensity={0.1} position={[-26, 5, -62]} color={0xff007a} />
{this.state.map.map((row, z) => this.row(row, z))}
</Canvas>
);
}
}
export default Woodlands;