-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathsceneBlob.js
67 lines (59 loc) · 1.32 KB
/
sceneBlob.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
import {
Group,
Mesh,
BufferGeometry,
Vector3,
IcosahedronGeometry,
} from "../third_party/three.module.js";
import perlin from "../third_party/perlin.js";
let blob;
const group = new Group();
let material;
const geo = new IcosahedronGeometry(1, 5);
const params = {
scale: 1,
noise: 1,
};
async function generate() {
if (blob) {
group.remove(blob);
}
const v = new Vector3();
const vertices = geo.vertices;
for (let j = 0; j < vertices.length; j++) {
v.copy(vertices[j]);
v.normalize();
const n =
1 +
params.scale +
params.scale *
perlin.simplex3(
params.noise * v.x,
params.noise * v.y,
params.noise * v.z
);
v.multiplyScalar(n);
vertices[j].copy(v);
}
geo.computeVertexNormals();
geo.computeFaceNormals();
blob = new Mesh(new BufferGeometry().fromGeometry(geo), material);
blob.castShadow = blob.receiveShadow = true;
group.add(blob);
}
const obj = {
init: async (m, q, r) => {
material = m;
params.q = q || params.q;
params.r = r || params.r;
await generate();
},
update: () => {},
group,
generate: () => generate(material),
params: (gui) => {
gui.add(params, "scale", 0.1, 2, 0.1).onChange(generate);
gui.add(params, "noise", 0.1, 2, 0.1).onChange(generate);
},
};
export { obj };