topotopo 0.4.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +10 -10
- package/README.md +460 -117
- package/dist/cli.js +327 -147
- package/dist/config.d.ts +48 -0
- package/dist/config.js +170 -0
- package/dist/core/bake.d.ts +14 -3
- package/dist/core/bake.js +153 -4
- package/dist/core/bevel.d.ts +3 -1
- package/dist/core/bevel.js +76 -3
- package/dist/core/decimate.d.ts +65 -0
- package/dist/core/decimate.js +409 -3
- package/dist/core/erosion.d.ts +37 -0
- package/dist/core/erosion.js +41 -1
- package/dist/core/geometry.d.ts +5 -1
- package/dist/core/geometry.js +203 -3
- package/dist/core/heightfield.d.ts +27 -4
- package/dist/core/heightfield.js +54 -16
- package/dist/core/intrinsics.d.ts +7 -0
- package/dist/core/intrinsics.js +94 -0
- package/dist/core/manifold.d.ts +12 -1
- package/dist/core/manifold.js +78 -6
- package/dist/core/materials.d.ts +7 -0
- package/dist/core/materials.js +45 -0
- package/dist/core/noise.d.ts +9 -0
- package/dist/core/noise.js +10 -1
- package/dist/core/polymerge.d.ts +21 -0
- package/dist/core/polymerge.js +327 -0
- package/dist/core/repair.d.ts +2 -0
- package/dist/core/repair.js +2 -0
- package/dist/core/report.d.ts +70 -0
- package/dist/core/report.js +275 -0
- package/dist/core/scene.js +2 -1
- package/dist/core/sha256.d.ts +4 -0
- package/dist/core/sha256.js +69 -0
- package/dist/core/shapes.d.ts +3 -0
- package/dist/core/shapes.js +34 -0
- package/dist/core/snippet-lib.d.ts +14 -1
- package/dist/core/snippet-lib.js +39 -13
- package/dist/core/tangents.d.ts +2 -0
- package/dist/core/tangents.js +5 -1
- package/dist/core/texnoise.d.ts +6 -1
- package/dist/core/texnoise.js +6 -2
- package/dist/core/texsdf.d.ts +131 -0
- package/dist/core/texsdf.js +637 -0
- package/dist/core/texture.d.ts +163 -9
- package/dist/core/texture.js +844 -20
- package/dist/core/topology.d.ts +10 -0
- package/dist/core/topology.js +168 -0
- package/dist/core/unwrap.d.ts +72 -0
- package/dist/core/unwrap.js +800 -0
- package/dist/core/usercode.d.ts +27 -0
- package/dist/core/usercode.js +87 -0
- package/dist/core/uv.d.ts +4 -18
- package/dist/core/uv.js +35 -188
- package/dist/core/uvislands.d.ts +62 -0
- package/dist/core/uvislands.js +574 -0
- package/dist/core/uvoverlap.d.ts +58 -0
- package/dist/core/uvoverlap.js +220 -0
- package/dist/core/uvpack.d.ts +64 -0
- package/dist/core/uvpack.js +628 -0
- package/dist/core/uvreport.d.ts +61 -0
- package/dist/core/uvreport.js +207 -143
- package/dist/core/wrangle.d.ts +6 -1
- package/dist/core/wrangle.js +27 -16
- package/dist/core/xatlas.d.ts +16 -1
- package/dist/core/xatlas.js +66 -62
- package/dist/engines.d.ts +63 -0
- package/dist/engines.js +180 -0
- package/dist/explain.d.ts +4 -3
- package/dist/explain.js +129 -12
- package/dist/graph/engine.d.ts +92 -29
- package/dist/graph/engine.js +298 -148
- package/dist/graph/expr.d.ts +6 -3
- package/dist/graph/expr.js +18 -8
- package/dist/graph/outputs.d.ts +23 -0
- package/dist/graph/outputs.js +41 -0
- package/dist/graph/packages.d.ts +72 -0
- package/dist/graph/packages.js +261 -0
- package/dist/graph/parallel.d.ts +3 -1
- package/dist/graph/parallel.js +4 -1
- package/dist/graph/params.d.ts +6 -0
- package/dist/graph/params.js +34 -7
- package/dist/graph/scope.d.ts +55 -0
- package/dist/graph/scope.js +14 -0
- package/dist/graph/types.d.ts +75 -12
- package/dist/graph/types.js +4 -2
- package/dist/graph/vars.d.ts +16 -0
- package/dist/graph/vars.js +80 -0
- package/dist/host/artifacts.d.ts +10 -1
- package/dist/host/artifacts.js +37 -6
- package/dist/host/cook.d.ts +241 -0
- package/dist/host/cook.js +844 -0
- package/dist/host/export-targets.d.ts +42 -5
- package/dist/host/export-targets.js +72 -13
- package/dist/host/godot-commands.d.ts +4 -0
- package/dist/host/godot-commands.js +21 -0
- package/dist/host/godot.d.ts +183 -0
- package/dist/host/godot.js +916 -0
- package/dist/host/node.d.ts +12 -7
- package/dist/host/node.js +27 -9
- package/dist/host/pool.js +51 -2
- package/dist/host/sidecars.d.ts +8 -0
- package/dist/host/sidecars.js +50 -0
- package/dist/host/types.d.ts +19 -6
- package/dist/host/version.d.ts +1 -0
- package/dist/host/version.js +3 -0
- package/dist/host/worker.js +5 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/inspect.d.ts +80 -2
- package/dist/inspect.js +265 -30
- package/dist/io/common.d.ts +25 -5
- package/dist/io/export.js +2 -1
- package/dist/io/files.d.ts +23 -4
- package/dist/io/files.js +60 -8
- package/dist/io/gltf.js +134 -47
- package/dist/io/heightmap.d.ts +3 -0
- package/dist/io/heightmap.js +1 -0
- package/dist/io/import.js +10 -0
- package/dist/io/inspect-scene.d.ts +55 -0
- package/dist/io/inspect-scene.js +155 -0
- package/dist/io/kinds.d.ts +81 -0
- package/dist/io/kinds.js +163 -0
- package/dist/io/points.d.ts +2 -1
- package/dist/io/points.js +3 -1
- package/dist/io/sidecars.d.ts +24 -0
- package/dist/io/sidecars.js +57 -0
- package/dist/io/source.d.ts +65 -0
- package/dist/io/source.js +112 -0
- package/dist/io/targets.d.ts +47 -3
- package/dist/io/targets.js +148 -13
- package/dist/io/textures.js +21 -1
- package/dist/io/unreal.js +5 -1
- package/dist/mcp/docs.d.ts +10 -1
- package/dist/mcp/docs.js +786 -143
- package/dist/mcp/inputs.d.ts +12 -5
- package/dist/mcp/inputs.js +50 -13
- package/dist/mcp/server.js +56 -27
- package/dist/mcp/tools.d.ts +14 -7
- package/dist/mcp/tools.js +198 -103
- package/dist/mcp/verify.d.ts +2 -2
- package/dist/mcp/verify.js +1 -1
- package/dist/mcp/workspace.d.ts +15 -0
- package/dist/mcp/workspace.js +349 -0
- package/dist/nodes/attributes.js +198 -1
- package/dist/nodes/bake.js +151 -47
- package/dist/nodes/beam.d.ts +1 -0
- package/dist/nodes/beam.js +201 -0
- package/dist/nodes/bevel.js +51 -3
- package/dist/nodes/cloth.js +2 -0
- package/dist/nodes/code.js +21 -9
- package/dist/nodes/curves.js +433 -93
- package/dist/nodes/flow.js +53 -33
- package/dist/nodes/generate.js +12 -38
- package/dist/nodes/heightfield.js +248 -77
- package/dist/nodes/imageops.js +16 -19
- package/dist/nodes/index.d.ts +1 -0
- package/dist/nodes/index.js +1 -0
- package/dist/nodes/material.js +89 -24
- package/dist/nodes/measure.js +43 -17
- package/dist/nodes/particles.js +2 -0
- package/dist/nodes/pcg.js +6 -5
- package/dist/nodes/procedural.js +4 -3
- package/dist/nodes/remesh.js +71 -15
- package/dist/nodes/scene.js +4 -2
- package/dist/nodes/sdf.js +10 -5
- package/dist/nodes/solid.js +20 -5
- package/dist/nodes/splines.d.ts +15 -1
- package/dist/nodes/splines.js +112 -105
- package/dist/nodes/texture.d.ts +21 -6
- package/dist/nodes/texture.js +1318 -185
- package/dist/nodes/topology.d.ts +7 -0
- package/dist/nodes/topology.js +133 -6
- package/dist/nodes/transform.js +6 -2
- package/dist/nodes/uv.js +192 -174
- package/dist/nodes/wasmcall.js +5 -1
- package/dist/open.d.ts +19 -0
- package/dist/open.js +12 -0
- package/dist/package.d.ts +288 -0
- package/dist/package.js +772 -0
- package/dist/packages/check.d.ts +32 -0
- package/dist/packages/check.js +169 -0
- package/dist/packages/commands.d.ts +57 -0
- package/dist/packages/commands.js +537 -0
- package/dist/packages/registry.d.ts +796 -0
- package/dist/packages/registry.js +2998 -0
- package/dist/packages/update.d.ts +124 -0
- package/dist/packages/update.js +476 -0
- package/dist/render/options.d.ts +2 -0
- package/dist/render/options.js +57 -5
- package/dist/render/preview.d.ts +17 -4
- package/dist/render/preview.js +6 -4
- package/dist/render/raster.d.ts +74 -5
- package/dist/render/raster.js +527 -143
- package/dist/render/texview.d.ts +6 -0
- package/dist/render/texview.js +27 -0
- package/dist/scan.d.ts +61 -0
- package/dist/scan.js +228 -0
- package/dist/session.d.ts +311 -0
- package/dist/session.js +849 -0
- package/dist/viewer/app/api.js +48 -6
- package/dist/viewer/app/cooking.js +78 -0
- package/dist/viewer/app/embed.js +27 -7
- package/dist/viewer/app/export-popover.js +118 -16
- package/dist/viewer/app/grid.js +5 -1
- package/dist/viewer/app/guides.js +122 -0
- package/dist/viewer/app/keymap.js +6 -3
- package/dist/viewer/app/layers.js +4 -4
- package/dist/viewer/app/main.js +185 -52
- package/dist/viewer/app/markers.js +60 -0
- package/dist/viewer/app/outliner.js +72 -27
- package/dist/viewer/app/output-info.js +45 -0
- package/dist/viewer/app/outputs.css +147 -8
- package/dist/viewer/app/outputs.js +168 -54
- package/dist/viewer/app/packages.js +614 -0
- package/dist/viewer/app/props.js +176 -52
- package/dist/viewer/app/scene.js +30 -5
- package/dist/viewer/app/select.js +4 -3
- package/dist/viewer/app/status.js +12 -15
- package/dist/viewer/app/style.css +65 -7
- package/dist/viewer/app/vars.js +47 -0
- package/dist/viewer/app/welcome.js +72 -0
- package/dist/viewer/graph-file.d.ts +62 -0
- package/dist/viewer/graph-file.js +175 -0
- package/dist/viewer/index.html +23 -10
- package/dist/viewer/json-edit.d.ts +13 -0
- package/dist/viewer/json-edit.js +274 -0
- package/dist/viewer/outputs.d.ts +49 -5
- package/dist/viewer/outputs.js +264 -56
- package/dist/viewer/packages.d.ts +121 -0
- package/dist/viewer/packages.js +584 -0
- package/dist/viewer/server.d.ts +14 -9
- package/dist/viewer/server.js +266 -28
- package/dist/web/app/web.css +419 -0
- package/dist/web/app/web.js +188 -0
- package/dist/{gallery → web}/bake.d.ts +4 -4
- package/dist/{gallery → web}/bake.js +24 -15
- package/dist/web/folder-page.d.ts +101 -0
- package/dist/web/folder-page.js +146 -0
- package/dist/web/folders.d.ts +280 -0
- package/dist/web/folders.js +970 -0
- package/dist/web/library.d.ts +91 -0
- package/dist/web/library.js +228 -0
- package/dist/web/markdown.d.ts +45 -0
- package/dist/web/markdown.js +677 -0
- package/dist/web/pages.d.ts +258 -0
- package/dist/web/pages.js +301 -0
- package/dist/web/server.d.ts +24 -0
- package/dist/web/server.js +1068 -0
- package/dist/workspace.d.ts +88 -118
- package/dist/workspace.js +358 -460
- package/integrations/godot/addons/topotopo/LICENSE +202 -0
- package/integrations/godot/addons/topotopo/README.md +57 -0
- package/integrations/godot/addons/topotopo/context_menu.gd +43 -0
- package/integrations/godot/addons/topotopo/dock.gd +266 -0
- package/integrations/godot/addons/topotopo/dock.tscn +72 -0
- package/integrations/godot/addons/topotopo/export_filter.gd +72 -0
- package/integrations/godot/addons/topotopo/gltf_instancing.gd +131 -0
- package/integrations/godot/addons/topotopo/icons/topotopo.svg +1 -0
- package/integrations/godot/addons/topotopo/inspector.gd +38 -0
- package/integrations/godot/addons/topotopo/instances_post_import.gd +111 -0
- package/integrations/godot/addons/topotopo/package.gd +23 -0
- package/integrations/godot/addons/topotopo/package_importer.gd +187 -0
- package/integrations/godot/addons/topotopo/plugin.cfg +7 -0
- package/integrations/godot/addons/topotopo/plugin.gd +970 -0
- package/integrations/godot/addons/topotopo/record.gd +435 -0
- package/integrations/godot/addons/topotopo/runner.gd +458 -0
- package/integrations/godot/addons/topotopo/tools/check.gd +42 -0
- package/integrations/godot/addons/topotopo/watcher.gd +199 -0
- package/kernels/pkg/README.md +2 -1
- package/kernels/pkg-simd/README.md +2 -1
- package/library/architecture/versions/1.0/architecture.topo +12 -0
- package/{shelf → library/architecture/versions/1.0/graphs}/arch.json +3 -3
- package/{shelf → library/architecture/versions/1.0/graphs}/beam_truss.json +6 -6
- package/{shelf → library/architecture/versions/1.0/graphs}/brick_wall.json +8 -8
- package/{shelf → library/architecture/versions/1.0/graphs}/door_frame.json +3 -3
- package/{shelf → library/architecture/versions/1.0/graphs}/hex_grid_floor.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/house.json +8 -8
- package/library/architecture/versions/1.0/graphs/lineup.json +42 -0
- package/{shelf → library/architecture/versions/1.0/graphs}/pillar.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/railing.json +5 -5
- package/{shelf → library/architecture/versions/1.0/graphs}/roof_gable.json +2 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/roof_hip.json +2 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/roof_skeleton.json +2 -1
- package/{shelf → library/architecture/versions/1.0/graphs}/scaffold.json +4 -4
- package/{shelf → library/architecture/versions/1.0/graphs}/spiral_stairs.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/stairs.json +6 -6
- package/{shelf → library/architecture/versions/1.0/graphs}/tile_floor.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/wall_segment.json +10 -10
- package/{shelf → library/architecture/versions/1.0/graphs}/window_frame.json +2 -2
- package/library/architecture/versions/1.0/version.json +1119 -0
- package/{shelf → library/nature/versions/1.0/graphs}/bush.json +2 -2
- package/{shelf → library/nature/versions/1.0/graphs}/cliff_block.json +4 -3
- package/{shelf → library/nature/versions/1.0/graphs}/forest_patch.json +5 -5
- package/{shelf → library/nature/versions/1.0/graphs}/grass_clumps.json +2 -2
- package/library/nature/versions/1.0/graphs/lineup.json +24 -0
- package/{shelf → library/nature/versions/1.0/graphs}/log.json +6 -6
- package/{shelf → library/nature/versions/1.0/graphs}/rock.json +5 -4
- package/{shelf → library/nature/versions/1.0/graphs}/scatter_rocks.json +5 -5
- package/{shelf → library/nature/versions/1.0/graphs}/tree_lowpoly.json +3 -2
- package/library/nature/versions/1.0/nature.topo +12 -0
- package/library/nature/versions/1.0/version.json +534 -0
- package/{shelf → library/props/versions/1.0/graphs}/barrel.json +5 -4
- package/{shelf → library/props/versions/1.0/graphs}/crate.json +3 -3
- package/library/props/versions/1.0/graphs/lineup.json +18 -0
- package/{shelf → library/props/versions/1.0/graphs}/pallet.json +4 -3
- package/{shelf → library/props/versions/1.0/graphs}/pipe_run.json +3 -3
- package/{shelf → library/props/versions/1.0/graphs}/sandbag_wall.json +5 -5
- package/library/props/versions/1.0/props.topo +12 -0
- package/library/props/versions/1.0/version.json +336 -0
- package/{shelf → library/street/versions/1.0/graphs}/bench.json +5 -5
- package/{shelf → library/street/versions/1.0/graphs}/bollard.json +2 -1
- package/{shelf → library/street/versions/1.0/graphs}/cable.json +4 -4
- package/{shelf → library/street/versions/1.0/graphs}/fence.json +7 -7
- package/{shelf → library/street/versions/1.0/graphs}/lamp_post.json +2 -2
- package/library/street/versions/1.0/graphs/lineup.json +22 -0
- package/{shelf → library/street/versions/1.0/graphs}/road_strip.json +2 -2
- package/{shelf → library/street/versions/1.0/graphs}/sign_post.json +1 -1
- package/library/street/versions/1.0/street.topo +12 -0
- package/library/street/versions/1.0/version.json +421 -0
- package/package.json +13 -8
- package/dist/gallery/app/gallery.css +0 -100
- package/dist/gallery/app/gallery.js +0 -80
- package/dist/gallery/cli.d.ts +0 -4
- package/dist/gallery/cli.js +0 -157
- package/dist/gallery/library.d.ts +0 -124
- package/dist/gallery/library.js +0 -366
- package/dist/gallery/pages.d.ts +0 -94
- package/dist/gallery/pages.js +0 -148
- package/dist/gallery/server.d.ts +0 -21
- package/dist/gallery/server.js +0 -391
- package/dist/graph/migrate.d.ts +0 -23
- package/dist/graph/migrate.js +0 -58
- package/dist/mcp/library.d.ts +0 -12
- package/dist/mcp/library.js +0 -159
- package/shelf/index.json +0 -190
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { buildEdges, primArea, triangulate } from './topology.js';
|
|
2
|
+
import { halfEdges } from './halfedge.js';
|
|
3
|
+
/** (x, y, z) in metres at millimetre precision. */
|
|
4
|
+
export function posText(p) {
|
|
5
|
+
const f = (x) => (Number.isFinite(x) ? (Math.abs(x) < 5e-4 ? 0 : x).toFixed(3) : String(x));
|
|
6
|
+
return `(${f(p[0])}, ${f(p[1])}, ${f(p[2])})`;
|
|
7
|
+
}
|
|
8
|
+
/** The centroid of a prim's points. */
|
|
9
|
+
export function primCentroid(g, p) {
|
|
10
|
+
const s = g.primStart[p], e = g.primStart[p + 1], P = g.P;
|
|
11
|
+
let x = 0, y = 0, z = 0;
|
|
12
|
+
for (let v = s; v < e; v++) {
|
|
13
|
+
const i = g.vertexPoint[v] * 3;
|
|
14
|
+
x += P[i];
|
|
15
|
+
y += P[i + 1];
|
|
16
|
+
z += P[i + 2];
|
|
17
|
+
}
|
|
18
|
+
const n = Math.max(1, e - s);
|
|
19
|
+
return [x / n, y / n, z / n];
|
|
20
|
+
}
|
|
21
|
+
/** The prim's part: its "name" (prim string attribute), and up to three prim groups holding it. */
|
|
22
|
+
export function primPart(g, p) {
|
|
23
|
+
const na = g.prims.get('name');
|
|
24
|
+
const name = na && na.type === 'string' ? String(na.get(p) ?? '') : '';
|
|
25
|
+
const groups = [];
|
|
26
|
+
for (const [k, m] of g.primGroups) {
|
|
27
|
+
if (m[p])
|
|
28
|
+
groups.push(k);
|
|
29
|
+
if (groups.length >= 3)
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
return { name, groups };
|
|
33
|
+
}
|
|
34
|
+
/** The point's part: its point "name", else the name of a prim that uses it; up to three point groups. */
|
|
35
|
+
export function pointPart(g, i, prim = -1) {
|
|
36
|
+
const pa = g.points.get('name');
|
|
37
|
+
let name = pa && pa.type === 'string' ? String(pa.get(i) ?? '') : '';
|
|
38
|
+
if (!name && prim >= 0)
|
|
39
|
+
name = primPart(g, prim).name;
|
|
40
|
+
const groups = [];
|
|
41
|
+
for (const [k, m] of g.pointGroups) {
|
|
42
|
+
if (m[i])
|
|
43
|
+
groups.push(k);
|
|
44
|
+
if (groups.length >= 3)
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
return { name, groups };
|
|
48
|
+
}
|
|
49
|
+
const partText = (pt) => `${pt.name ? ` of "${pt.name}"` : ''}${pt.groups.length ? ` (group${pt.groups.length > 1 ? 's' : ''} ${pt.groups.join(', ')})` : ''}`;
|
|
50
|
+
/** "prim 12 of "barrel" (groups front) at (x, y, z)": the prim's part and its centroid (or `at`, a point on it). */
|
|
51
|
+
export function primWhere(g, p, at) {
|
|
52
|
+
return `prim ${p}${partText(primPart(g, p))} at ${posText(at ?? primCentroid(g, p))}`;
|
|
53
|
+
}
|
|
54
|
+
/** "point 7 of "barrel" at (x, y, z)". */
|
|
55
|
+
export function pointWhere(g, i, prim = -1) {
|
|
56
|
+
return `point ${i}${partText(pointPart(g, i, prim))} at ${posText([g.P[i * 3], g.P[i * 3 + 1], g.P[i * 3 + 2]])}`;
|
|
57
|
+
}
|
|
58
|
+
/** "edge 3–7 of "barrel" (prim 12) at (midpoint)": the part of the prim that holds the edge. */
|
|
59
|
+
export function edgeWhere(g, a, b, prim = -1) {
|
|
60
|
+
const P = g.P, m = [(P[a * 3] + P[b * 3]) / 2, (P[a * 3 + 1] + P[b * 3 + 1]) / 2, (P[a * 3 + 2] + P[b * 3 + 2]) / 2];
|
|
61
|
+
const pt = prim >= 0 ? primPart(g, prim) : { name: '', groups: [] };
|
|
62
|
+
return `edge ${a}–${b}${partText(pt)}${prim >= 0 ? ` (prim ${prim})` : ''} at ${posText(m)}`;
|
|
63
|
+
}
|
|
64
|
+
/** The parts (names) a set of prims belongs to, most prims first: `"barrel" 12, "stock" 3`. */
|
|
65
|
+
export function partsOf(g, prims, max = 4) {
|
|
66
|
+
const na = g.prims.get('name');
|
|
67
|
+
if (!na || na.type !== 'string')
|
|
68
|
+
return '';
|
|
69
|
+
const by = new Map();
|
|
70
|
+
for (const p of prims) {
|
|
71
|
+
const k = String(na.get(p) ?? '');
|
|
72
|
+
by.set(k, (by.get(k) ?? 0) + 1);
|
|
73
|
+
}
|
|
74
|
+
const list = [...by].sort((x, y) => y[1] - x[1]);
|
|
75
|
+
return list.slice(0, max).map(([k, n]) => `"${k}" ${n}`).join(', ') + (list.length > max ? `, … ${list.length - max} more` : '');
|
|
76
|
+
}
|
|
77
|
+
/** Whether the mesh is a closed solid, and why not (see the file comment). */
|
|
78
|
+
export function solidReport(g, o = {}) {
|
|
79
|
+
const E = buildEdges(g), P = g.P, np = g.numPoints;
|
|
80
|
+
let polys = 0, degenerate = 0, firstDeg = -1;
|
|
81
|
+
for (let p = 0; p < g.numPrims; p++) {
|
|
82
|
+
if (!g.primClosed[p] || g.isPacked(p) || g.isSpline(p))
|
|
83
|
+
continue;
|
|
84
|
+
polys++;
|
|
85
|
+
if (g.primSize(p) < 3 || primArea(g, p) < 1e-14) {
|
|
86
|
+
degenerate++;
|
|
87
|
+
if (firstDeg < 0)
|
|
88
|
+
firstDeg = p;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// canonical point per position among the points of boundary edges (a seam split always leaves its coincident
|
|
92
|
+
// copies on boundary edges; points elsewhere stay themselves)
|
|
93
|
+
const b = g.bbox();
|
|
94
|
+
const diag = Math.hypot(b.max[0] - b.min[0], b.max[1] - b.min[1], b.max[2] - b.min[2]) || 1;
|
|
95
|
+
const q = diag * 1e-7, canon = Int32Array.from({ length: np }, (_, i) => i), byPos = new Map();
|
|
96
|
+
const onBoundary = new Uint8Array(np);
|
|
97
|
+
for (let e = 0; e < E.a.length; e++)
|
|
98
|
+
if (E.count[e] === 1 && g.primClosed[E.firstPrim[e]]) {
|
|
99
|
+
onBoundary[E.a[e]] = 1;
|
|
100
|
+
onBoundary[E.b[e]] = 1;
|
|
101
|
+
}
|
|
102
|
+
for (let i = 0; i < np; i++) {
|
|
103
|
+
if (!onBoundary[i])
|
|
104
|
+
continue;
|
|
105
|
+
const k = `${Math.round(P[i * 3] / q)},${Math.round(P[i * 3 + 1] / q)},${Math.round(P[i * 3 + 2] / q)}`;
|
|
106
|
+
const c = byPos.get(k);
|
|
107
|
+
if (c === undefined)
|
|
108
|
+
byPos.set(k, i);
|
|
109
|
+
else
|
|
110
|
+
canon[i] = c;
|
|
111
|
+
}
|
|
112
|
+
// boundary edges of polygons, grouped by their welded end points
|
|
113
|
+
let boundary = 0, rawNonManifold = 0, firstNM = -1;
|
|
114
|
+
const groups = new Map();
|
|
115
|
+
for (let e = 0; e < E.a.length; e++) {
|
|
116
|
+
if (!g.primClosed[E.firstPrim[e]])
|
|
117
|
+
continue;
|
|
118
|
+
if (E.count[e] > 2) {
|
|
119
|
+
rawNonManifold++;
|
|
120
|
+
if (firstNM < 0)
|
|
121
|
+
firstNM = e;
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
if (E.count[e] !== 1)
|
|
125
|
+
continue;
|
|
126
|
+
boundary++;
|
|
127
|
+
const ca = canon[E.a[e]], cb = canon[E.b[e]];
|
|
128
|
+
if (ca === cb)
|
|
129
|
+
continue;
|
|
130
|
+
const k = ca < cb ? `${ca},${cb}` : `${cb},${ca}`;
|
|
131
|
+
let l = groups.get(k);
|
|
132
|
+
if (!l)
|
|
133
|
+
groups.set(k, (l = []));
|
|
134
|
+
l.push(e);
|
|
135
|
+
}
|
|
136
|
+
let seam = 0, open = 0, firstOpen = -1, nonManifold = rawNonManifold;
|
|
137
|
+
for (const l of groups.values()) {
|
|
138
|
+
if (l.length === 2)
|
|
139
|
+
seam += 2;
|
|
140
|
+
else if (l.length === 1) {
|
|
141
|
+
open++;
|
|
142
|
+
if (firstOpen < 0 || l[0] < firstOpen)
|
|
143
|
+
firstOpen = l[0];
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
nonManifold += 1;
|
|
147
|
+
if (firstNM < 0)
|
|
148
|
+
firstNM = l[0];
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
// winding flips (as the points are: a seam split separates the two sides anyway)
|
|
152
|
+
const he = o.flips === false ? null : halfEdges(g);
|
|
153
|
+
let firstFlip = -1;
|
|
154
|
+
if (he)
|
|
155
|
+
for (const e of he.flippedEdges) {
|
|
156
|
+
if (firstFlip < 0 || e < firstFlip)
|
|
157
|
+
firstFlip = e;
|
|
158
|
+
}
|
|
159
|
+
// welded pieces: union of canonical points along polygons
|
|
160
|
+
const parent = Int32Array.from({ length: np }, (_, i) => i);
|
|
161
|
+
const find = (x) => { while (parent[x] !== x) {
|
|
162
|
+
parent[x] = parent[parent[x]];
|
|
163
|
+
x = parent[x];
|
|
164
|
+
} return x; };
|
|
165
|
+
for (let p = 0; p < g.numPrims; p++) {
|
|
166
|
+
const s = g.primStart[p], e = g.primStart[p + 1];
|
|
167
|
+
if (e - s < 1)
|
|
168
|
+
continue;
|
|
169
|
+
const r0 = find(canon[g.vertexPoint[s]]);
|
|
170
|
+
for (let v = s + 1; v < e; v++) {
|
|
171
|
+
const r = find(canon[g.vertexPoint[v]]);
|
|
172
|
+
if (r !== r0)
|
|
173
|
+
parent[r] = r0;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
const pieceOf = new Map();
|
|
177
|
+
const primPiece = new Int32Array(g.numPrims).fill(-1);
|
|
178
|
+
for (let p = 0; p < g.numPrims; p++) {
|
|
179
|
+
if (g.primStart[p + 1] === g.primStart[p])
|
|
180
|
+
continue;
|
|
181
|
+
const r = find(canon[g.vertexPoint[g.primStart[p]]]);
|
|
182
|
+
let k = pieceOf.get(r);
|
|
183
|
+
if (k === undefined)
|
|
184
|
+
pieceOf.set(r, (k = pieceOf.size));
|
|
185
|
+
primPiece[p] = k;
|
|
186
|
+
}
|
|
187
|
+
// per welded piece: open after welding?, signed volume, bbox
|
|
188
|
+
const n = pieceOf.size;
|
|
189
|
+
const openPiece = new Uint8Array(n), vol = new Float64Array(n), mn = new Float64Array(n * 3).fill(Infinity), mx = new Float64Array(n * 3).fill(-Infinity);
|
|
190
|
+
for (const l of groups.values())
|
|
191
|
+
if (l.length !== 2)
|
|
192
|
+
for (const e of l)
|
|
193
|
+
openPiece[primPiece[E.firstPrim[e]]] = 1;
|
|
194
|
+
for (let e = 0; e < E.a.length; e++)
|
|
195
|
+
if (E.count[e] > 2 && g.primClosed[E.firstPrim[e]])
|
|
196
|
+
openPiece[primPiece[E.firstPrim[e]]] = 1;
|
|
197
|
+
for (let p = 0; p < g.numPrims; p++)
|
|
198
|
+
if (!g.primClosed[p] && primPiece[p] >= 0)
|
|
199
|
+
openPiece[primPiece[p]] = 1;
|
|
200
|
+
const { tris, triPrim } = o.tri ?? triangulate(g);
|
|
201
|
+
for (let t = 0; t < tris.length; t += 3) {
|
|
202
|
+
const k = primPiece[triPrim[t / 3]];
|
|
203
|
+
if (k < 0)
|
|
204
|
+
continue;
|
|
205
|
+
const a = g.vertexPoint[tris[t]] * 3, c1 = g.vertexPoint[tris[t + 1]] * 3, c2 = g.vertexPoint[tris[t + 2]] * 3;
|
|
206
|
+
vol[k] += (P[a] * (P[c1 + 1] * P[c2 + 2] - P[c1 + 2] * P[c2 + 1]) - P[a + 1] * (P[c1] * P[c2 + 2] - P[c1 + 2] * P[c2]) + P[a + 2] * (P[c1] * P[c2 + 1] - P[c1 + 1] * P[c2])) / 6;
|
|
207
|
+
for (const i of [a, c1, c2])
|
|
208
|
+
for (let d = 0; d < 3; d++) {
|
|
209
|
+
mn[k * 3 + d] = Math.min(mn[k * 3 + d], P[i + d]);
|
|
210
|
+
mx[k * 3 + d] = Math.max(mx[k * 3 + d], P[i + d]);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
let inward = 0, firstInwardPrim = -1;
|
|
214
|
+
for (let k = 0; k < n; k++) {
|
|
215
|
+
if (openPiece[k] || !(vol[k] < 0))
|
|
216
|
+
continue;
|
|
217
|
+
// the wall of a cavity: inside the bbox of a larger outward-facing closed piece
|
|
218
|
+
let cavity = false;
|
|
219
|
+
for (let j = 0; j < n && !cavity; j++) {
|
|
220
|
+
if (j === k || openPiece[j] || !(vol[j] > -vol[k]))
|
|
221
|
+
continue;
|
|
222
|
+
cavity = [0, 1, 2].every((d) => mn[j * 3 + d] <= mn[k * 3 + d] && mx[j * 3 + d] >= mx[k * 3 + d]);
|
|
223
|
+
}
|
|
224
|
+
if (cavity)
|
|
225
|
+
continue;
|
|
226
|
+
inward++;
|
|
227
|
+
if (firstInwardPrim < 0)
|
|
228
|
+
firstInwardPrim = primPiece.indexOf(k);
|
|
229
|
+
}
|
|
230
|
+
const fe = (e) => (e < 0 ? null : edgeWhere(g, E.a[e], E.b[e], E.firstPrim[e]));
|
|
231
|
+
const fl = (e) => {
|
|
232
|
+
if (e < 0 || !he)
|
|
233
|
+
return null;
|
|
234
|
+
const faces = he.edgeFaces(e);
|
|
235
|
+
return edgeWhere(g, he.edgeA[e], he.edgeB[e], faces[0] ?? -1);
|
|
236
|
+
};
|
|
237
|
+
const pieceClosed = new Uint8Array(n);
|
|
238
|
+
for (let k = 0; k < n; k++)
|
|
239
|
+
pieceClosed[k] = openPiece[k] ? 0 : 1;
|
|
240
|
+
return {
|
|
241
|
+
polys, closed: polys > 0 && boundary === 0 && rawNonManifold === 0,
|
|
242
|
+
boundaryEdges: boundary, seamEdges: seam, openEdges: open, firstOpen: fe(firstOpen),
|
|
243
|
+
nonManifoldEdges: nonManifold, firstNonManifold: fe(firstNM),
|
|
244
|
+
flippedEdges: he ? he.flippedEdges.size : 0, firstFlipped: fl(firstFlip),
|
|
245
|
+
inwardPieces: inward, firstInward: firstInwardPrim >= 0 ? primWhere(g, firstInwardPrim) : null,
|
|
246
|
+
degenerate, firstDegenerate: firstDeg >= 0 ? primWhere(g, firstDeg) : null,
|
|
247
|
+
closedAfterWeld: polys > 0 && open === 0 && nonManifold === 0,
|
|
248
|
+
pieces: n, primPiece, pieceClosed,
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
/** "N open edges (after welding seam splits)", with the seam splits said when there are any. */
|
|
252
|
+
export function openEdgesText(r) {
|
|
253
|
+
const seams = r.seamEdges ? `; ${r.seamEdges} boundary edges are uv/normal seam splits` : '';
|
|
254
|
+
return `${r.openEdges} open edge${r.openEdges === 1 ? '' : 's'} (after welding seam splits${seams})`;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Why a mesh is not a closed solid, one line per cause with the count, where the first one is and the fix; [] when
|
|
258
|
+
* it is one (after welding seam splits).
|
|
259
|
+
*/
|
|
260
|
+
export function solidCauses(r) {
|
|
261
|
+
const out = [];
|
|
262
|
+
if (!r.polys)
|
|
263
|
+
return ['no polygons: solid operations need a closed polygon mesh'];
|
|
264
|
+
if (r.openEdges)
|
|
265
|
+
out.push(`${openEdgesText(r)}, first ${r.firstOpen}: fill_holes or fuse (weld points), or cap the open ends`);
|
|
266
|
+
if (r.nonManifoldEdges)
|
|
267
|
+
out.push(`${r.nonManifoldEdges} non-manifold edge${r.nonManifoldEdges === 1 ? '' : 's'} (shared by 3+ polygons), first ${r.firstNonManifold}: separate the touching parts (boolean union) or remove the duplicate faces (clean)`);
|
|
268
|
+
if (r.flippedEdges)
|
|
269
|
+
out.push(`${r.flippedEdges} edge${r.flippedEdges === 1 ? '' : 's'} with inconsistent winding between neighbouring polygons (flipped faces), first ${r.firstFlipped}: clean with fix_winding, or reverse the flipped part`);
|
|
270
|
+
if (r.inwardPieces)
|
|
271
|
+
out.push(`${r.inwardPieces} closed piece${r.inwardPieces === 1 ? '' : 's'} facing inward, first ${r.firstInward}: reverse it`);
|
|
272
|
+
if (r.degenerate)
|
|
273
|
+
out.push(`${r.degenerate} degenerate face${r.degenerate === 1 ? '' : 's'} (no area), first ${r.firstDegenerate}: clean (remove degenerate) or mesh_repair`);
|
|
274
|
+
return out;
|
|
275
|
+
}
|
package/dist/core/scene.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Geometry as Geo, defaultValueFor } from './geometry.js';
|
|
2
|
+
import { posText } from './report.js';
|
|
2
3
|
export const EMPTY_ATTRIB = 'scene_empty';
|
|
3
4
|
export const PARENT_ATTRIB = 'parent';
|
|
4
5
|
/** Point attributes the empty contract owns (not written as extras). */
|
|
@@ -32,7 +33,7 @@ export function sceneEmpties(g) {
|
|
|
32
33
|
if (!flag[i])
|
|
33
34
|
continue;
|
|
34
35
|
if (used[i])
|
|
35
|
-
throw new Error(`scene empty
|
|
36
|
+
throw new Error(`scene empty "${str('name', i)}" (point ${i} at ${posText([g.P[i * 3], g.P[i * 3 + 1], g.P[i * 3 + 2]])}) is marked ${EMPTY_ATTRIB} but used by a primitive; empties must be isolated points`);
|
|
36
37
|
const extras = {};
|
|
37
38
|
for (const [k, a] of g.points.map) {
|
|
38
39
|
if (EMPTY_RESERVED.has(k) || a.isArray)
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// SHA-256 (FIPS 180-4) in plain TypeScript, so a content hash reads the same in every host (export sources, io/source.ts).
|
|
2
|
+
const K = Uint32Array.from([
|
|
3
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
|
4
|
+
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
|
5
|
+
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
6
|
+
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
|
7
|
+
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
|
8
|
+
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
9
|
+
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
|
10
|
+
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
|
|
11
|
+
]);
|
|
12
|
+
/** The 32-byte SHA-256 digest of `data`. */
|
|
13
|
+
export function sha256(data) {
|
|
14
|
+
// message + 0x80 + zero padding + 64-bit big-endian bit length, a multiple of 64 bytes
|
|
15
|
+
const n = data.length, blocks = Math.ceil((n + 9) / 64);
|
|
16
|
+
const msg = new Uint8Array(blocks * 64);
|
|
17
|
+
msg.set(data);
|
|
18
|
+
msg[n] = 0x80;
|
|
19
|
+
const dv = new DataView(msg.buffer);
|
|
20
|
+
dv.setUint32(msg.length - 8, Math.floor(n / 0x20000000));
|
|
21
|
+
dv.setUint32(msg.length - 4, (n * 8) >>> 0);
|
|
22
|
+
const H = Uint32Array.from([0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19]);
|
|
23
|
+
const W = new Uint32Array(64);
|
|
24
|
+
for (let b = 0; b < blocks; b++) {
|
|
25
|
+
for (let t = 0; t < 16; t++)
|
|
26
|
+
W[t] = dv.getUint32(b * 64 + t * 4);
|
|
27
|
+
for (let t = 16; t < 64; t++) {
|
|
28
|
+
const x = W[t - 15], y = W[t - 2];
|
|
29
|
+
const s0 = ((x >>> 7) | (x << 25)) ^ ((x >>> 18) | (x << 14)) ^ (x >>> 3);
|
|
30
|
+
const s1 = ((y >>> 17) | (y << 15)) ^ ((y >>> 19) | (y << 13)) ^ (y >>> 10);
|
|
31
|
+
W[t] = (W[t - 16] + s0 + W[t - 7] + s1) >>> 0;
|
|
32
|
+
}
|
|
33
|
+
let a = H[0], bb = H[1], c = H[2], d = H[3], e = H[4], f = H[5], g = H[6], h = H[7];
|
|
34
|
+
for (let t = 0; t < 64; t++) {
|
|
35
|
+
const S1 = ((e >>> 6) | (e << 26)) ^ ((e >>> 11) | (e << 21)) ^ ((e >>> 25) | (e << 7));
|
|
36
|
+
const t1 = (h + S1 + ((e & f) ^ (~e & g)) + K[t] + W[t]) >>> 0;
|
|
37
|
+
const S0 = ((a >>> 2) | (a << 30)) ^ ((a >>> 13) | (a << 19)) ^ ((a >>> 22) | (a << 10));
|
|
38
|
+
const t2 = (S0 + ((a & bb) ^ (a & c) ^ (bb & c))) >>> 0;
|
|
39
|
+
h = g;
|
|
40
|
+
g = f;
|
|
41
|
+
f = e;
|
|
42
|
+
e = (d + t1) >>> 0;
|
|
43
|
+
d = c;
|
|
44
|
+
c = bb;
|
|
45
|
+
bb = a;
|
|
46
|
+
a = (t1 + t2) >>> 0;
|
|
47
|
+
}
|
|
48
|
+
H[0] = (H[0] + a) >>> 0;
|
|
49
|
+
H[1] = (H[1] + bb) >>> 0;
|
|
50
|
+
H[2] = (H[2] + c) >>> 0;
|
|
51
|
+
H[3] = (H[3] + d) >>> 0;
|
|
52
|
+
H[4] = (H[4] + e) >>> 0;
|
|
53
|
+
H[5] = (H[5] + f) >>> 0;
|
|
54
|
+
H[6] = (H[6] + g) >>> 0;
|
|
55
|
+
H[7] = (H[7] + h) >>> 0;
|
|
56
|
+
}
|
|
57
|
+
const out = new Uint8Array(32), ov = new DataView(out.buffer);
|
|
58
|
+
for (let i = 0; i < 8; i++)
|
|
59
|
+
ov.setUint32(i * 4, H[i]);
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
/** SHA-256 as 64 lower-case hex digits; a string is hashed as its UTF-8 bytes. */
|
|
63
|
+
export function sha256Hex(data) {
|
|
64
|
+
const d = sha256(typeof data === 'string' ? new TextEncoder().encode(data) : data);
|
|
65
|
+
let s = '';
|
|
66
|
+
for (const x of d)
|
|
67
|
+
s += x.toString(16).padStart(2, '0');
|
|
68
|
+
return s;
|
|
69
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Primitive shapes shared by the generator nodes and the previews (render/texview.ts material spheres).
|
|
2
|
+
import { GeoBuilder } from './geometry.js';
|
|
3
|
+
/** Latitude/longitude sphere of radius r around the origin, with vertex uv (u around from +X, v up). */
|
|
4
|
+
export function uvSphere(r, rows, cols) {
|
|
5
|
+
rows = Math.max(2, rows);
|
|
6
|
+
cols = Math.max(3, cols);
|
|
7
|
+
const b = new GeoBuilder();
|
|
8
|
+
const uv = b.attrib('vertex', 'uv', 3);
|
|
9
|
+
const top = b.addPoint(0, r, 0);
|
|
10
|
+
const ring = [];
|
|
11
|
+
for (let i = 1; i < rows; i++) {
|
|
12
|
+
const th = (Math.PI * i) / rows, row = [];
|
|
13
|
+
for (let c = 0; c < cols; c++) {
|
|
14
|
+
const ph = (2 * Math.PI * c) / cols;
|
|
15
|
+
row.push(b.addPoint(r * Math.sin(th) * Math.cos(ph), r * Math.cos(th), -r * Math.sin(th) * Math.sin(ph)));
|
|
16
|
+
}
|
|
17
|
+
ring.push(row);
|
|
18
|
+
}
|
|
19
|
+
const bot = b.addPoint(0, -r, 0);
|
|
20
|
+
const addUV = (us) => { const v0 = b.numVertices - us.length; us.forEach((t, k) => uv.set(v0 + k, [t[0], t[1], 0])); };
|
|
21
|
+
for (let c = 0; c < cols; c++) {
|
|
22
|
+
const c1 = (c + 1) % cols, u0 = c / cols, u1 = (c + 1) / cols;
|
|
23
|
+
b.addPrim([top, ring[0][c], ring[0][c1]]);
|
|
24
|
+
addUV([[(u0 + u1) / 2, 1], [u0, 1 - 1 / rows], [u1, 1 - 1 / rows]]);
|
|
25
|
+
for (let i = 0; i < rows - 2; i++) {
|
|
26
|
+
b.addPrim([ring[i][c], ring[i + 1][c], ring[i + 1][c1], ring[i][c1]]);
|
|
27
|
+
const va = 1 - (i + 1) / rows, vb = 1 - (i + 2) / rows;
|
|
28
|
+
addUV([[u0, va], [u0, vb], [u1, vb], [u1, va]]);
|
|
29
|
+
}
|
|
30
|
+
b.addPrim([ring[rows - 2][c], bot, ring[rows - 2][c1]]);
|
|
31
|
+
addUV([[u0, 1 / rows], [(u0 + u1) / 2, 0], [u1, 1 / rows]]);
|
|
32
|
+
}
|
|
33
|
+
return b.build();
|
|
34
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Host } from '../host/types.ts';
|
|
1
2
|
/**
|
|
2
3
|
* Library functions that go through the wrangle's geometry API (`C()` below): they read other elements or
|
|
3
4
|
* inputs, edit the geometry or log. A point wrangle that calls none of them can run in chunks on worker threads
|
|
@@ -10,15 +11,27 @@ export declare const GEOMETRY_FUNCTIONS: string[];
|
|
|
10
11
|
* global property (a setter that never returns), and the engine sets the API outside the time limit.
|
|
11
12
|
*/
|
|
12
13
|
export declare function installSnippetLib(g: any, host: any): (api: any) => void;
|
|
14
|
+
/** The names the snippet library installs (the helpers of the scripting realm), read off a stand-in global object. */
|
|
15
|
+
export declare const SNIPPET_LIB_NAMES: readonly string[];
|
|
16
|
+
/**
|
|
17
|
+
* What code that still reads graph vars as `vars.height` gets for `vars`: an object whose every use fails with what to
|
|
18
|
+
* write instead ("vars.height: read graph vars by their bare name: height"). Graph vars are bound by their bare name
|
|
19
|
+
* (src/core/usercode.ts). Self-contained like installSnippetLib: each realm compiles it from its source text and calls
|
|
20
|
+
* it before any user code, so it holds that realm's ReferenceError and Proxy.
|
|
21
|
+
*/
|
|
22
|
+
export declare function makeVarsGuard(): object;
|
|
13
23
|
/** Name of the scripting realm's control object (a global `const` declared by SCRIPT_REALM_SETUP). */
|
|
14
24
|
export declare const REALM_CONTROL = "__topotopo";
|
|
25
|
+
/** The scripting realm's `vars` guard (makeVarsGuard), for code that binds graph vars by name. */
|
|
26
|
+
export declare function scriptVarsGuard(host: Host): object;
|
|
15
27
|
/**
|
|
16
28
|
* The script a host runs once in a new scripting realm, before any user code, with its primitives (rand, noise, curl)
|
|
17
29
|
* on the realm's global `__hostApi` (deleted again). It installs the snippet library and declares the realm's control
|
|
18
|
-
* object as a global `const` (REALM_CONTROL), a frozen object of realm functions:
|
|
30
|
+
* object as a global `const` (REALM_CONTROL), a frozen object of realm functions and values:
|
|
19
31
|
* run() calls the current job: the host's timed script is `__topotopo.run()` (Host.runGuarded)
|
|
20
32
|
* setJob(f) sets the current job
|
|
21
33
|
* setCur(api) sets the current wrangle's geometry API (wrangle.ts; null after the run)
|
|
34
|
+
* varsGuard what code gets for `vars` (makeVarsGuard)
|
|
22
35
|
* The host keeps the object and calls setJob/setCur directly, outside the time limit, so they must not run user code:
|
|
23
36
|
* the job and the API are closure variables, the object is frozen (own data properties only) and a global `const`
|
|
24
37
|
* can be neither reassigned nor redefined by later code (user code never runs at the realm's top level, and a
|
package/dist/core/snippet-lib.js
CHANGED
|
@@ -1,20 +1,10 @@
|
|
|
1
|
-
// The function below is stringified and evaluated INSIDE the scripting realm, so it
|
|
2
|
-
// must be completely self-contained: no imports, no references to outer scope.
|
|
3
|
-
// It installs VEX-flavoured helpers as globals. Numeric results cross realms freely;
|
|
4
|
-
// arrays are always created here so they get the realm's Array.prototype accessors
|
|
5
|
-
// (.x .y .z .w / .r .g .b .a / .u .v).
|
|
6
|
-
//
|
|
7
|
-
// `host` supplies number-returning primitives implemented in the engine realm
|
|
8
|
-
// (noise, hashing). Geometry query/edit functions dispatch through the current wrangle's
|
|
9
|
-
// geometry API, a closure variable of the library that the engine sets for each wrangle run
|
|
10
|
-
// through the realm's control object (see SCRIPT_REALM_SETUP).
|
|
11
1
|
/**
|
|
12
2
|
* Library functions that go through the wrangle's geometry API (`C()` below): they read other elements or
|
|
13
3
|
* inputs, edit the geometry or log. A point wrangle that calls none of them can run in chunks on worker threads
|
|
14
4
|
* (wrangle.ts runWrangleParallel); test/pool.ts checks this list against the functions installed below.
|
|
15
5
|
*/
|
|
16
6
|
export const GEOMETRY_FUNCTIONS = [
|
|
17
|
-
'npoints', 'nprims', 'nvertices', 'point', 'prim', 'vertex', 'detail', 'haspointattrib', 'hasprimattrib', 'primpoints',
|
|
7
|
+
'npoints', 'nprims', 'nvertices', 'point', 'prim', 'primintrinsic', 'vertex', 'detail', 'haspointattrib', 'hasprimattrib', 'primpoints',
|
|
18
8
|
'pointprims', 'neighbours', 'neighbors', 'neighbourcount', 'primvertexcount', 'nearpoint', 'nearpoints', 'xyzdist', 'minpos',
|
|
19
9
|
'closest', 'intersect', 'inpointgroup', 'inprimgroup', 'invertexgroup', 'inedgegroup', 'pointattribtype', 'addpoint',
|
|
20
10
|
'addprim', 'removepoint', 'removeprim', 'setpointattrib', 'setprimattrib', 'setvertexattrib', 'setdetailattrib',
|
|
@@ -314,6 +304,8 @@ export function installSnippetLib(g, host) {
|
|
|
314
304
|
L.nvertices = (i = 0) => C().nvertices(i);
|
|
315
305
|
L.point = (i, name, pt) => toArr(C().attr(i, 'point', name, pt));
|
|
316
306
|
L.prim = (i, name, pr) => toArr(C().attr(i, 'prim', name, pr));
|
|
307
|
+
// read-only values computed per prim: bounds, typename, vertexcount, closed; packed: packedbounds, transform, … (intrinsics.ts)
|
|
308
|
+
L.primintrinsic = (i, name, pr) => toArr(C().primintrinsic(i, name, pr));
|
|
317
309
|
L.vertex = (i, name, v) => toArr(C().attr(i, 'vertex', name, v));
|
|
318
310
|
L.detail = (i, name) => toArr(C().attr(i, 'detail', name, 0));
|
|
319
311
|
L.haspointattrib = (i, name) => C().hasattr(i, 'point', name);
|
|
@@ -461,15 +453,48 @@ export function installSnippetLib(g, host) {
|
|
|
461
453
|
g.__snippetLibNames = Object.keys(L).filter((k) => !k.startsWith('__'));
|
|
462
454
|
return (api) => { cur = api; };
|
|
463
455
|
}
|
|
456
|
+
/** The names the snippet library installs (the helpers of the scripting realm), read off a stand-in global object. */
|
|
457
|
+
export const SNIPPET_LIB_NAMES = (() => {
|
|
458
|
+
const g = { Array: { prototype: {} } };
|
|
459
|
+
installSnippetLib(g, {});
|
|
460
|
+
return Object.freeze(g.__snippetLibNames.slice());
|
|
461
|
+
})();
|
|
462
|
+
/**
|
|
463
|
+
* What code that still reads graph vars as `vars.height` gets for `vars`: an object whose every use fails with what to
|
|
464
|
+
* write instead ("vars.height: read graph vars by their bare name: height"). Graph vars are bound by their bare name
|
|
465
|
+
* (src/core/usercode.ts). Self-contained like installSnippetLib: each realm compiles it from its source text and calls
|
|
466
|
+
* it before any user code, so it holds that realm's ReferenceError and Proxy.
|
|
467
|
+
*/
|
|
468
|
+
export function makeVarsGuard() {
|
|
469
|
+
'use strict';
|
|
470
|
+
const RE = ReferenceError;
|
|
471
|
+
const fail = (k) => {
|
|
472
|
+
throw new RE(typeof k === 'string'
|
|
473
|
+
? 'vars.' + k + ': read graph vars by their bare name: ' + k
|
|
474
|
+
: 'vars: read graph vars by their bare name (height, not vars.height)');
|
|
475
|
+
};
|
|
476
|
+
const any = () => fail(undefined);
|
|
477
|
+
const byKey = (_t, k) => fail(k);
|
|
478
|
+
const handler = Object.freeze({
|
|
479
|
+
get: byKey, has: byKey, set: byKey, deleteProperty: byKey, defineProperty: byKey, getOwnPropertyDescriptor: byKey,
|
|
480
|
+
ownKeys: any, getPrototypeOf: any, setPrototypeOf: any, isExtensible: any, preventExtensions: any,
|
|
481
|
+
});
|
|
482
|
+
return new Proxy(Object.freeze(Object.create(null)), handler);
|
|
483
|
+
}
|
|
464
484
|
/** Name of the scripting realm's control object (a global `const` declared by SCRIPT_REALM_SETUP). */
|
|
465
485
|
export const REALM_CONTROL = '__topotopo';
|
|
486
|
+
/** The scripting realm's `vars` guard (makeVarsGuard), for code that binds graph vars by name. */
|
|
487
|
+
export function scriptVarsGuard(host) {
|
|
488
|
+
return host.compile(REALM_CONTROL).varsGuard;
|
|
489
|
+
}
|
|
466
490
|
/**
|
|
467
491
|
* The script a host runs once in a new scripting realm, before any user code, with its primitives (rand, noise, curl)
|
|
468
492
|
* on the realm's global `__hostApi` (deleted again). It installs the snippet library and declares the realm's control
|
|
469
|
-
* object as a global `const` (REALM_CONTROL), a frozen object of realm functions:
|
|
493
|
+
* object as a global `const` (REALM_CONTROL), a frozen object of realm functions and values:
|
|
470
494
|
* run() calls the current job: the host's timed script is `__topotopo.run()` (Host.runGuarded)
|
|
471
495
|
* setJob(f) sets the current job
|
|
472
496
|
* setCur(api) sets the current wrangle's geometry API (wrangle.ts; null after the run)
|
|
497
|
+
* varsGuard what code gets for `vars` (makeVarsGuard)
|
|
473
498
|
* The host keeps the object and calls setJob/setCur directly, outside the time limit, so they must not run user code:
|
|
474
499
|
* the job and the API are closure variables, the object is frozen (own data properties only) and a global `const`
|
|
475
500
|
* can be neither reassigned nor redefined by later code (user code never runs at the realm's top level, and a
|
|
@@ -479,6 +504,7 @@ export const REALM_CONTROL = '__topotopo';
|
|
|
479
504
|
export const SCRIPT_REALM_SETUP = `const ${REALM_CONTROL} = (() => {
|
|
480
505
|
let job;
|
|
481
506
|
const setCur = (${installSnippetLib.toString()})(globalThis, __hostApi);
|
|
482
|
-
|
|
507
|
+
const varsGuard = (${makeVarsGuard.toString()})();
|
|
508
|
+
return Object.freeze({ run: () => job(), setJob: (f) => { job = f; }, setCur, varsGuard });
|
|
483
509
|
})();
|
|
484
510
|
delete globalThis.__hostApi;`;
|
package/dist/core/tangents.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ export interface TangentDiagnostics {
|
|
|
11
11
|
uvDegenerate: number;
|
|
12
12
|
/** corners that received the fallback tangent */
|
|
13
13
|
fallbackCorners: number;
|
|
14
|
+
/** the first triangle with a non-finite or collapsed uv, or -1 (warnings say where it is) */
|
|
15
|
+
firstBad: number;
|
|
14
16
|
}
|
|
15
17
|
/**
|
|
16
18
|
* MikkTSpace tangents for a triangle soup: pos and nrm 9 floats per triangle, uv 6 (TopoTopo convention). Returns 12
|
package/dist/core/tangents.js
CHANGED
|
@@ -36,7 +36,7 @@ export function mikkTangents(pos, nrm, uv) {
|
|
|
36
36
|
if (!mod)
|
|
37
37
|
throw new Error('MikkTSpace is not loaded: await loadMikkTSpace() first (exportGLB, renderPBR and bake_normal do)');
|
|
38
38
|
const nt = Math.floor(pos.length / 9);
|
|
39
|
-
const diag = { triangles: nt, uvNonFinite: 0, uvDegenerate: 0, fallbackCorners: 0 };
|
|
39
|
+
const diag = { triangles: nt, uvNonFinite: 0, uvDegenerate: 0, fallbackCorners: 0, firstBad: -1 };
|
|
40
40
|
const bad = new Uint8Array(nt);
|
|
41
41
|
const P = Float32Array.from(pos), N = Float32Array.from(nrm), T = Float32Array.from(uv);
|
|
42
42
|
for (let t = 0; t < nt; t++) {
|
|
@@ -49,6 +49,8 @@ export function mikkTangents(pos, nrm, uv) {
|
|
|
49
49
|
if (!finite) {
|
|
50
50
|
diag.uvNonFinite++;
|
|
51
51
|
bad[t] = 1;
|
|
52
|
+
if (diag.firstBad < 0)
|
|
53
|
+
diag.firstBad = t;
|
|
52
54
|
continue;
|
|
53
55
|
}
|
|
54
56
|
const u0 = T[t * 6], v0 = T[t * 6 + 1], du1 = T[t * 6 + 2] - u0, dv1 = T[t * 6 + 3] - v0, du2 = T[t * 6 + 4] - u0, dv2 = T[t * 6 + 5] - v0;
|
|
@@ -56,6 +58,8 @@ export function mikkTangents(pos, nrm, uv) {
|
|
|
56
58
|
if (!(Math.abs(du1 * dv2 - du2 * dv1) > UV_DEGENERATE * e2)) {
|
|
57
59
|
diag.uvDegenerate++;
|
|
58
60
|
bad[t] = 1;
|
|
61
|
+
if (diag.firstBad < 0)
|
|
62
|
+
diag.firstBad = t;
|
|
59
63
|
}
|
|
60
64
|
}
|
|
61
65
|
for (let i = 0; i < N.length; i += 3) {
|
package/dist/core/texnoise.d.ts
CHANGED
|
@@ -3,13 +3,18 @@ export type Noise2 = (x: number, y: number) => number;
|
|
|
3
3
|
export declare function perlin2(seed: number, px?: number, py?: number): Noise2;
|
|
4
4
|
/** Value noise in [-1, 1], periodic with period (px, py) cells when > 0. */
|
|
5
5
|
export declare function value2(seed: number, px?: number, py?: number): Noise2;
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* Result of a cellular query: distances to the nearest and second nearest feature point, the nearest cell's hash and
|
|
8
|
+
* (wrapped) lattice cell, and the offset (ex, ey) from the sample to the nearest feature point.
|
|
9
|
+
*/
|
|
7
10
|
export interface CellHit {
|
|
8
11
|
f1: number;
|
|
9
12
|
f2: number;
|
|
10
13
|
id: number;
|
|
11
14
|
cx: number;
|
|
12
15
|
cy: number;
|
|
16
|
+
ex: number;
|
|
17
|
+
ey: number;
|
|
13
18
|
}
|
|
14
19
|
/**
|
|
15
20
|
* Cellular (Worley) noise: one feature point per lattice cell, jittered by `jitter` (0 = regular grid, 1 = anywhere in
|
package/dist/core/texnoise.js
CHANGED
|
@@ -52,7 +52,7 @@ export function cellular2(seed, px = 0, py = 0, jitter = 1, metric = 0) {
|
|
|
52
52
|
const j = Math.max(0, Math.min(1, jitter));
|
|
53
53
|
return (x, y, out) => {
|
|
54
54
|
const xf = Math.floor(x), yf = Math.floor(y);
|
|
55
|
-
let f1 = Infinity, f2 = Infinity, id = 0, bx = 0, by = 0;
|
|
55
|
+
let f1 = Infinity, f2 = Infinity, id = 0, bx = 0, by = 0, oex = 0, oey = 0;
|
|
56
56
|
for (let dy = -1; dy <= 1; dy++)
|
|
57
57
|
for (let dx = -1; dx <= 1; dx++) {
|
|
58
58
|
const cx = xf + dx, cy = yf + dy;
|
|
@@ -67,6 +67,8 @@ export function cellular2(seed, px = 0, py = 0, jitter = 1, metric = 0) {
|
|
|
67
67
|
id = h;
|
|
68
68
|
bx = wrap(cx, px);
|
|
69
69
|
by = wrap(cy, py);
|
|
70
|
+
oex = ex;
|
|
71
|
+
oey = ey;
|
|
70
72
|
}
|
|
71
73
|
else if (d < f2)
|
|
72
74
|
f2 = d;
|
|
@@ -76,6 +78,8 @@ export function cellular2(seed, px = 0, py = 0, jitter = 1, metric = 0) {
|
|
|
76
78
|
out.id = id;
|
|
77
79
|
out.cx = bx;
|
|
78
80
|
out.cy = by;
|
|
81
|
+
out.ex = oex;
|
|
82
|
+
out.ey = oey;
|
|
79
83
|
return out;
|
|
80
84
|
};
|
|
81
85
|
}
|
|
@@ -225,7 +229,7 @@ export function texNoise(o) {
|
|
|
225
229
|
}
|
|
226
230
|
else if (o.noise === 'worley') {
|
|
227
231
|
const c = cellular2(seed, px, py, o.jitter ?? 1);
|
|
228
|
-
const hit = { f1: 0, f2: 0, id: 0, cx: 0, cy: 0 };
|
|
232
|
+
const hit = { f1: 0, f2: 0, id: 0, cx: 0, cy: 0, ex: 0, ey: 0 };
|
|
229
233
|
fns.push((u, v) => Math.min(1, c(u * fx + ox, v * fy + oy, hit).f1 / 0.85) * 2 - 1);
|
|
230
234
|
}
|
|
231
235
|
else {
|