-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadvanced-composition.js
More file actions
46 lines (42 loc) · 1.49 KB
/
Copy pathadvanced-composition.js
File metadata and controls
46 lines (42 loc) · 1.49 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
/**
* Tutorial: SurfaceComposition API (multi-surface combine).
*
* Evidence: SurfaceComposition.sampleAll merges sampled meshes for registered ops.
* Does not claim full SDF boolean meshing for every surface.
*
* node examples/tutorials/advanced-composition.js
*/
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import {
SurfaceComposition,
OP_UNION,
OP_BLEND,
} from "../../mrs/packages/renderer-core/src/surfaces/composition.js";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const outDir = path.resolve(__dirname, "../../output/examples-export");
fs.mkdirSync(outDir, { recursive: true });
const composition = new SurfaceComposition({ blendRadius: 0.15, mergeWeld: true });
composition
.addOperation(OP_UNION, "tesseract", {})
.addOperation(OP_BLEND, "torus-3d", { resolution: 12 });
const mesh = composition.sampleAll(12);
const report = {
status: "sampleAll-ok",
operations: composition.operations.map((o) => ({
op: o.op,
surfaceId: o.surfaceId,
enabled: o.enabled,
})),
meshSummary: {
vertices: mesh.vertices.length,
faces: mesh.faces.length,
edges: mesh.edges.length,
},
note: "sampleAll merges meshes; OP_BLEND here is recorded on the op list — density blend path is separate (evaluateDensity).",
};
const out = path.join(outDir, "composition-report.json");
fs.writeFileSync(out, JSON.stringify(report, null, 2));
console.log(JSON.stringify(report, null, 2));
console.log(`Wrote ${out}`);