-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsurface_lattice_metrics.js
108 lines (100 loc) · 2.4 KB
/
surface_lattice_metrics.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
96
97
98
99
100
101
102
103
104
105
106
107
108
/* Example script demonstrating filling a triangle mesh with a gyroid.
*
* Usage:
* node examples/surface_lattice_metrics.js -t <token> -p <project>
*
* This is a port of the same example in the Metafold SDK for Python:
* https://github.com/Metafold3d/metafold-python/blob/master/examples/surface_lattice_metrics.py
*
* Please refer to the Python example for more details.
*
* Note this example takes advantage of async/await in Javascript to run jobs concurrently.
*/
"use strict"
const { program } = require("commander")
const MetafoldClient = require("../lib/metafold")
const latticeTypes = [
"Gyroid",
"SchwarzD",
"I2Y",
"CI2Y",
"S",
"SD1",
"P",
"F",
"Schwarz",
"D",
"IWP",
"CD",
"CP",
"CY",
"CS",
"W",
"Y",
"C_Y",
"PM_Y",
"CPM_Y",
"FRD",
"SchwarzN",
"SchwarzW",
"SchwarzPW",
]
async function exec(opts) {
const token = opts.token ?? process.env.METAFOLD_ACCESS_TOKEN
if (!token) {
console.error("access token is required")
process.exit(1)
}
const metafold = new MetafoldClient(token, opts.project)
await Promise.allSettled(latticeTypes.map(async (t) => {
console.log(`Running evaluate_metrics (${t}) job...`)
const job = await metafold.jobs.run("evaluate_metrics", {
graph: {
operators: [
{
type: "GenerateSamplePoints",
parameters: {
size: [1.0, 1.0, 1.0],
resolution: [64, 64, 64],
},
},
{
type: "SampleSurfaceLattice",
parameters: {
lattice_type: t,
scale: [1.0, 1.0, 1.0],
},
},
{
type: "Redistance",
parameters: {
size: [1.0, 1.0, 1.0],
},
},
{
type: "Threshold",
parameters: {
width: 0.04,
},
},
],
edges: [
{source: 0, target: [1, "Points"]},
{source: 1, target: [2, "Samples"]},
{source: 2, target: [3, "Samples"]},
],
},
point_source: 0,
})
console.log(`${t}:`)
console.log(job.meta)
}))
}
async function main() {
program
.option("-t, --token <token>", "access token")
.requiredOption("-p, --project <id>", "project id")
.action(exec)
await program.parseAsync(process.argv)
}
main()