-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfigures.js
95 lines (81 loc) · 2.44 KB
/
figures.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
87
88
89
90
91
92
93
94
95
const genererFigures = (hash, anaverse) => {
function xmur3(str) {
for (var i = 0, h = 1779033703 ^ str.length; i < str.length; i++)
(h = Math.imul(h ^ str.charCodeAt(i), 3432918353)),
(h = (h << 13) | (h >>> 19));
return function () {
(h = Math.imul(h ^ (h >>> 16), 2246822507)),
(h = Math.imul(h ^ (h >>> 13), 3266489909));
return (h ^= h >>> 16) >>> 0;
};
}
function sfc32(a, b, c, d) {
return function () {
a |= 0;
b |= 0;
c |= 0;
d |= 0;
var t = (((a + b) | 0) + d) | 0;
d = (d + 1) | 0;
a = b ^ (b >>> 9);
b = (c + (c << 3)) | 0;
c = (c << 21) | (c >>> 11);
c = (c + t) | 0;
return (t >>> 0) / 4294967296;
};
}
const seed = xmur3(hash);
const r = () => sfc32(seed(), seed(), seed(), seed())();
const rint = (n) => Math.floor(r() * n);
const figures = [];
const features = {};
const u = 1;
// Don't modify above this line
features.name = "My great anaverse space"; // this name must be generative too
// below here is your script
// this example is voluntarily extra-naive in its formulation
// feel free to take vanilla JS shortcuts like spread syntax et al
// This function pushes a cube in the figure array
// It takes a pos argument that is a {x,y,z} object.
const cube = (pos) =>
figures.push({
geometry: {
type: "BoxGeometry", // Type of geometry [list here https://threejs.org/docs/index.html?q=geometry]
args: [
// Arguments relevant to the geometry (check THREE API)
(0.1 + r()) * u, // Cube width
(0.1 + r()) * u, // Cube height
(0.1 + r()) * u, // Cube depth
],
},
pos: {
// Position
x: pos.x * u,
y: pos.y * u,
z: pos.z * u,
},
rot: {
// Rotation
x: 0,
y: 0,
z: 0,
},
lines: true, // Display color segments (like wireframe, but faces not triangles)
hatch: true, // Fill with white texture
full: false, // Fill with color texture (in the anaverse, red and cyan)
});
const size = 2;
for (let x = -size; x < size; x++) {
for (let y = -size; y < size; y++) {
for (let z = -size; z < size; z++) {
// set up position
const pos = { x: x, y: y, z: z };
// call the function
cube(pos);
}
}
}
// both are needed
return { figures, features };
};
export { genererFigures };