-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.js
More file actions
51 lines (40 loc) · 1.04 KB
/
test.js
File metadata and controls
51 lines (40 loc) · 1.04 KB
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
const vertices2D = [
{x: 1, y: 1},
{x: 5, y: 1},
{x: 4, y: 4},
// {x: 2, y: 5}
];
const height = 10;
const vertices3D = [];
vertices2D.forEach(vertex => {
vertices3D.push({x: vertex.x, y: vertex.y, z: 0});
vertices3D.push({x: vertex.x, y: vertex.y, z: height});
});
const edges = [];
for (let i = 0; i < vertices2D.length; i++) {
const next = (i + 1) % vertices2D.length;
edges.push([i, next]);
edges.push([i + vertices2D.length, next + vertices2D.length]);
edges.push([i, i + vertices2D.length]);
}
const faces = [];
const bottomFace = [];
for (let i = 0; i < vertices2D.length; i++) {
bottomFace.push(i);
}
faces.push(bottomFace);
const topFace = [];
for (let i = 0; i < vertices2D.length; i++) {
topFace.push(i + vertices2D.length);
}
faces.push(topFace.reverse());
for (let i = 0; i < vertices2D.length; i++) {
const next = (i + 1) % vertices2D.length;
faces.push([i, next, next + vertices2D.length, i + vertices2D.length]);
}
const mesh = {
vertices: vertices3D,
edges: edges,
faces: faces
};
console.log(mesh);