topotopo 0.4.0 → 0.5.0
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 +323 -146
- 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 +196 -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 +44 -5
- package/dist/render/preview.d.ts +15 -4
- package/dist/render/preview.js +6 -4
- package/dist/render/raster.d.ts +66 -5
- package/dist/render/raster.js +506 -138
- 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 +17 -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
package/dist/explain.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// Shape descriptions for LLMs: explain (what a cooked geometry is, in ~30 lines of text) and diff (what changed
|
|
2
|
-
// between two geometries: counts, bbox, attribute schema, groups, Hausdorff distance, an overlay for the
|
|
3
|
-
// Host-agnostic; the MCP tools in src/mcp/verify.ts resolve graphs and render.
|
|
2
|
+
// between two geometries: counts, bbox, attribute schema, groups, volumes, Hausdorff distance, an overlay for the
|
|
3
|
+
// renderer). Host-agnostic; the MCP tools in src/mcp/verify.ts resolve graphs and render.
|
|
4
4
|
import { Geometry } from './core/geometry.js';
|
|
5
5
|
import { buildEdges, primArea } from './core/topology.js';
|
|
6
|
+
import { pointWhere } from './core/report.js';
|
|
6
7
|
import { RayScene, SurfaceQuery, bboxDiagonal, directedDistance, duplicatePoints, fmt, mirrorSymmetry, newNearest, pieceReport, principalAxes, quantile, rayMeasure, sampleSurface, } from './core/analysis.js';
|
|
7
8
|
import { volumeCounts } from './core/heightfield.js';
|
|
8
9
|
/** A length with a unit an LLM reads at a glance: "1.2 m", "3 cm", "0.4 mm". */
|
|
@@ -333,7 +334,86 @@ const delta = (a, b) => {
|
|
|
333
334
|
return d === 0 ? '=' : `${d > 0 ? '+' : ''}${n(d)}`;
|
|
334
335
|
};
|
|
335
336
|
const signed = (x) => (Math.abs(x) < 1e-12 ? '0' : `${x > 0 ? '+' : ''}${fmt(x)}`);
|
|
336
|
-
/**
|
|
337
|
+
/** The largest difference between two sample arrays: 0 when they are equal, Infinity when their lengths differ. */
|
|
338
|
+
function maxDelta(x, y) {
|
|
339
|
+
if (x === y)
|
|
340
|
+
return 0;
|
|
341
|
+
if (x.length !== y.length)
|
|
342
|
+
return Infinity;
|
|
343
|
+
let m = 0;
|
|
344
|
+
for (let i = 0; i < x.length; i++) {
|
|
345
|
+
if (x[i] === y[i])
|
|
346
|
+
continue;
|
|
347
|
+
const d = Math.abs(x[i] - y[i]);
|
|
348
|
+
if (!(d <= m))
|
|
349
|
+
m = Number.isNaN(d) ? Infinity : d;
|
|
350
|
+
}
|
|
351
|
+
return m;
|
|
352
|
+
}
|
|
353
|
+
/** How a volume differs from the one of the same kind and name in b, '' when it does not (or, analytic, cannot be told). */
|
|
354
|
+
function volumeDelta(a, b) {
|
|
355
|
+
const by = (m, metres) => (Number.isFinite(m) ? (metres ? fmtLen(m) : fmt(m)) : 'a lot');
|
|
356
|
+
if (a.kind === 'sdf' || b.kind === 'sdf') {
|
|
357
|
+
const box = (v) => `${v3(v.bounds.min)}..${v3(v.bounds.max)}`;
|
|
358
|
+
return box(a) === box(b) ? '' : `bounds ${box(a)} → ${box(b)}`;
|
|
359
|
+
}
|
|
360
|
+
if (a.kind === 'grid' && b.kind === 'grid') {
|
|
361
|
+
const dims = (v) => `${v.dims.join(' × ')} at ${fmtLen(v.voxel)} from ${v3(v.origin)}`;
|
|
362
|
+
if (dims(a) !== dims(b))
|
|
363
|
+
return `${dims(a)} → ${dims(b)}`;
|
|
364
|
+
const m = maxDelta(a.values, b.values);
|
|
365
|
+
return m ? `distances differ by up to ${by(m, true)}` : '';
|
|
366
|
+
}
|
|
367
|
+
if ((a.kind === 'heightfield' && b.kind === 'heightfield') || (a.kind === 'image' && b.kind === 'image')) {
|
|
368
|
+
const grid = (v) => (v.kind === 'heightfield' ? `${v.width} × ${v.height} cells of ${fmtLen(v.cellSize)} from (${v.origin.map((x) => fmt(x)).join(', ')})` : v.kind === 'image' ? `${v.width} × ${v.height} px` : '');
|
|
369
|
+
if (grid(a) !== grid(b))
|
|
370
|
+
return `${grid(a)} → ${grid(b)}`;
|
|
371
|
+
const parts = [];
|
|
372
|
+
for (const k of b.layers.keys())
|
|
373
|
+
if (!a.layers.has(k))
|
|
374
|
+
parts.push(`+ layer ${k}`);
|
|
375
|
+
for (const k of a.layers.keys())
|
|
376
|
+
if (!b.layers.has(k))
|
|
377
|
+
parts.push(`- layer ${k}`);
|
|
378
|
+
for (const [k, la] of a.layers) {
|
|
379
|
+
const lb = b.layers.get(k), m = lb ? maxDelta(la, lb) : 0;
|
|
380
|
+
if (m)
|
|
381
|
+
parts.push(`layer ${k} by up to ${by(m, a.kind === 'heightfield' && k === 'height')}`);
|
|
382
|
+
}
|
|
383
|
+
return parts.join(', ');
|
|
384
|
+
}
|
|
385
|
+
return '';
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* What changed in the volumes, by kind and name: heightfields, images and SDF grids compared sample by sample, analytic
|
|
389
|
+
* SDFs by their bounds. "+" only in b, "-" only in a, "~" changed.
|
|
390
|
+
*/
|
|
391
|
+
function volumeChanges(a, b) {
|
|
392
|
+
const byName = (g) => {
|
|
393
|
+
const m = new Map(), seen = new Map();
|
|
394
|
+
for (const v of g.volumes) {
|
|
395
|
+
const base = `${v.kind === 'grid' ? 'SDF grid' : v.kind === 'sdf' ? 'SDF' : v.kind} "${v.name}"`;
|
|
396
|
+
const k = (seen.get(base) ?? 0) + 1;
|
|
397
|
+
seen.set(base, k);
|
|
398
|
+
m.set(k > 1 ? `${base} #${k}` : base, v);
|
|
399
|
+
}
|
|
400
|
+
return m;
|
|
401
|
+
};
|
|
402
|
+
const A = byName(a), B = byName(b), out = [];
|
|
403
|
+
for (const k of B.keys())
|
|
404
|
+
if (!A.has(k))
|
|
405
|
+
out.push(`+ ${k}`);
|
|
406
|
+
for (const k of A.keys())
|
|
407
|
+
if (!B.has(k))
|
|
408
|
+
out.push(`- ${k}`);
|
|
409
|
+
for (const [k, v] of A) {
|
|
410
|
+
const w = B.get(k), d = w ? volumeDelta(v, w) : '';
|
|
411
|
+
if (d)
|
|
412
|
+
out.push(`~ ${k}: ${d}`);
|
|
413
|
+
}
|
|
414
|
+
return out;
|
|
415
|
+
}
|
|
416
|
+
/** What changed from a to b: counts, bbox, topology, attribute schema, groups, volumes, sampled Hausdorff and mean distance. */
|
|
337
417
|
export function diffGeometry(a, b, labels = ['a', 'b'], samples = 3000) {
|
|
338
418
|
const out = [`diff a = ${labels[0]} vs b = ${labels[1]}`];
|
|
339
419
|
const ma = primMix(a), mb = primMix(b);
|
|
@@ -386,6 +466,9 @@ export function diffGeometry(a, b, labels = ['a', 'b'], samples = 3000) {
|
|
|
386
466
|
if (gB.has(k) && gB.get(k) !== c)
|
|
387
467
|
grpChanges.push(`~ ${k} ${n(c)} → ${n(gB.get(k))} members`);
|
|
388
468
|
out.push(`groups: ${grpChanges.length ? grpChanges.join('; ') : gA.size ? 'same names and sizes' : 'none'}`);
|
|
469
|
+
const volChanges = a.volumes.length || b.volumes.length ? volumeChanges(a, b) : [];
|
|
470
|
+
if (a.volumes.length || b.volumes.length)
|
|
471
|
+
out.push(`volumes: ${volChanges.length ? volChanges.join('; ') + ' (+ only in b, - only in a, ~ changed)' : `same (${volumeCounts(a)}${a.volumes.some((v) => v.kind === 'sdf') ? '; analytic SDFs by their bounds' : ''})`}`);
|
|
389
472
|
// distances
|
|
390
473
|
let haus = Infinity, mean = Infinity;
|
|
391
474
|
if (a.numPoints && b.numPoints) {
|
|
@@ -413,28 +496,32 @@ export function diffGeometry(a, b, labels = ['a', 'b'], samples = 3000) {
|
|
|
413
496
|
at = i;
|
|
414
497
|
}
|
|
415
498
|
}
|
|
416
|
-
out.push(`points (same count, matched by number): ${n(moved)} of ${n(a.numPoints)} moved; max ${fmtLen(mx)}${mx > 0 ? ` (
|
|
499
|
+
out.push(`points (same count, matched by number): ${n(moved)} of ${n(a.numPoints)} moved; max ${fmtLen(mx)}${mx > 0 ? ` (${pointWhere(a, at)} in a)` : ''}, mean ${fmtLen(sum / a.numPoints)}`);
|
|
417
500
|
}
|
|
418
501
|
const sameCounts = a.numPoints === b.numPoints && a.numPrims === b.numPrims && a.numVertices === b.numVertices;
|
|
419
502
|
const diag = Math.max(bboxDiagonal(a), bboxDiagonal(b));
|
|
420
|
-
const identical = sameCounts && !attrChanges.length && !grpChanges.length && (a.numPoints === 0 || haus <= 1e-9 * Math.max(1, diag));
|
|
503
|
+
const identical = sameCounts && !attrChanges.length && !grpChanges.length && !volChanges.length && (a.numPoints === 0 || haus <= 1e-9 * Math.max(1, diag));
|
|
504
|
+
const vols = volChanges.length ? '; the volumes changed' : '';
|
|
421
505
|
let verdict;
|
|
422
506
|
if (identical)
|
|
423
|
-
verdict =
|
|
507
|
+
verdict = `no geometric change (same counts, schema${a.volumes.length ? ', volumes' : ''} and shape within 1e-9)`;
|
|
508
|
+
else if (!a.numPoints && !b.numPoints)
|
|
509
|
+
verdict = (a.volumes.length || b.volumes.length ? 'no points on either side' : 'both empty') + vols;
|
|
424
510
|
else if (!a.numPoints || !b.numPoints)
|
|
425
|
-
verdict =
|
|
511
|
+
verdict = `${!a.numPoints ? 'a' : 'b'} is empty${vols}`;
|
|
426
512
|
else if (haus <= 1e-9 * Math.max(1, diag))
|
|
427
|
-
verdict = 'same shape; ' + (sameCounts ?
|
|
513
|
+
verdict = 'same shape; ' + (!sameCounts ? `topology / tessellation differs${vols}` : attrChanges.length || grpChanges.length ? `only attributes/groups differ${vols}` : 'only the volumes differ');
|
|
428
514
|
else
|
|
429
|
-
verdict = `shape changed by up to ${fmtLen(haus)} (${fmt((100 * haus) / Math.max(1e-12, diag))}% of the bbox diagonal)${sameCounts ? '' : ', and the topology differs'}`;
|
|
515
|
+
verdict = `shape changed by up to ${fmtLen(haus)} (${fmt((100 * haus) / Math.max(1e-12, diag))}% of the bbox diagonal)${sameCounts ? '' : ', and the topology differs'}${vols}`;
|
|
430
516
|
out.push(`verdict: ${verdict}`);
|
|
431
517
|
return { text: out.join('\n'), hausdorff: haus, mean, identical };
|
|
432
518
|
}
|
|
433
519
|
/** Colours of the diff overlay. */
|
|
434
520
|
export const DIFF_COLORS = { same: [0.72, 0.72, 0.72], b: [0.2, 0.5, 1.0], a: [1.0, 0.5, 0.12] };
|
|
435
521
|
/**
|
|
436
|
-
* One geometry for the renderer: b
|
|
437
|
-
*
|
|
522
|
+
* One geometry for the renderer: b (grey where it lies on a, blue where it moved or is new), and in orange the polygons
|
|
523
|
+
* of a that do not lie on b. Those that do are left out, b's grey stands for both there: two coincident surfaces mix
|
|
524
|
+
* their colours in the renderer. So grey = unchanged, blue = only b, orange = only a.
|
|
438
525
|
*/
|
|
439
526
|
export function diffOverlay(a, b) {
|
|
440
527
|
const strip = (g) => {
|
|
@@ -443,7 +530,8 @@ export function diffOverlay(a, b) {
|
|
|
443
530
|
c.table(cls).delete('Cd');
|
|
444
531
|
return c;
|
|
445
532
|
};
|
|
446
|
-
|
|
533
|
+
let A = strip(a);
|
|
534
|
+
const B = strip(b);
|
|
447
535
|
const qa = a.numPoints ? new SurfaceQuery(a) : null;
|
|
448
536
|
const tol = 1e-3 * Math.max(bboxDiagonal(a), bboxDiagonal(b), 1e-9);
|
|
449
537
|
const cB = B.points.add('Cd', 'float', 3).data, out = newNearest(), P = B.P;
|
|
@@ -454,6 +542,35 @@ export function diffOverlay(a, b) {
|
|
|
454
542
|
cB[i * 3 + 1] = c[1];
|
|
455
543
|
cB[i * 3 + 2] = c[2];
|
|
456
544
|
}
|
|
545
|
+
if (b.numPoints && A.numPrims && !A.primKind) {
|
|
546
|
+
// a polygon lies on b when its corners and its centre do
|
|
547
|
+
const qb = new SurfaceQuery(b), PA = A.P, on = new Uint8Array(A.numPoints);
|
|
548
|
+
for (let i = 0; i < A.numPoints; i++)
|
|
549
|
+
on[i] = qb.nearest(PA[i * 3], PA[i * 3 + 1], PA[i * 3 + 2], tol, out) ? 1 : 0;
|
|
550
|
+
const keep = new Uint8Array(A.numPrims), c = [0, 0, 0];
|
|
551
|
+
let kept = 0;
|
|
552
|
+
for (let p = 0; p < A.numPrims; p++) {
|
|
553
|
+
const s = A.primStart[p], e = A.primStart[p + 1];
|
|
554
|
+
let off = false;
|
|
555
|
+
c[0] = c[1] = c[2] = 0;
|
|
556
|
+
for (let v = s; v < e; v++) {
|
|
557
|
+
const i = A.vertexPoint[v];
|
|
558
|
+
if (!on[i]) {
|
|
559
|
+
off = true;
|
|
560
|
+
break;
|
|
561
|
+
}
|
|
562
|
+
c[0] += PA[i * 3];
|
|
563
|
+
c[1] += PA[i * 3 + 1];
|
|
564
|
+
c[2] += PA[i * 3 + 2];
|
|
565
|
+
}
|
|
566
|
+
if (off || (e > s && !qb.nearest(c[0] / (e - s), c[1] / (e - s), c[2] / (e - s), tol, out))) {
|
|
567
|
+
keep[p] = 1;
|
|
568
|
+
kept++;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
if (kept < A.numPrims)
|
|
572
|
+
A = A.subsetPrims(keep);
|
|
573
|
+
}
|
|
457
574
|
const cA = A.points.add('Cd', 'float', 3).data;
|
|
458
575
|
for (let i = 0; i < A.numPoints; i++) {
|
|
459
576
|
cA[i * 3] = DIFF_COLORS.a[0];
|
package/dist/graph/engine.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Geometry } from '../core/geometry.ts';
|
|
2
|
-
import type { Host } from '../host/types.ts';
|
|
2
|
+
import type { Host, StopSignal } from '../host/types.ts';
|
|
3
3
|
import type { TimeState } from './params.ts';
|
|
4
4
|
import type { PoolStats } from './parallel.ts';
|
|
5
|
-
import type {
|
|
5
|
+
import type { AssetEntry, PackageIssue, PackageResolver, Scope } from './scope.ts';
|
|
6
|
+
import { STOPPED } from './types.ts';
|
|
7
|
+
import type { GraphSpec, InputDef, NodeDef, NodeSpec, ParamDef } from './types.ts';
|
|
6
8
|
export type { TimeState } from './params.ts';
|
|
7
9
|
export interface Issue {
|
|
8
10
|
node: string;
|
|
@@ -39,7 +41,28 @@ export interface CookReport {
|
|
|
39
41
|
fps: number;
|
|
40
42
|
/** the target's result depends on time (other than through subgraph inputs) */
|
|
41
43
|
timeDependent: boolean;
|
|
44
|
+
/** the cook was stopped (CookOptions.signal): the node it stopped at */
|
|
45
|
+
stopped?: string;
|
|
42
46
|
}
|
|
47
|
+
export { STOPPED };
|
|
48
|
+
/**
|
|
49
|
+
* A node starting or ending its cook, for CookOptions.onNode (cache hits are not reported), and the steps of a long
|
|
50
|
+
* node between them (ctx.checkpoint: "step", where the host may yield; nothing else to report).
|
|
51
|
+
*/
|
|
52
|
+
export interface NodeProgress {
|
|
53
|
+
phase: 'start' | 'step' | 'end';
|
|
54
|
+
node: string;
|
|
55
|
+
type: string;
|
|
56
|
+
/** 0 for the graph's own nodes; nested cooks (assets, foreach, solver, graph_ref) report theirs deeper */
|
|
57
|
+
depth: number;
|
|
58
|
+
/** the enclosing nodes of a nested cook, outermost first ([] at depth 0) */
|
|
59
|
+
within: readonly string[];
|
|
60
|
+
/** end: the node's cook time in ms */
|
|
61
|
+
ms?: number;
|
|
62
|
+
/** end: its error, when it failed or was stopped */
|
|
63
|
+
error?: string;
|
|
64
|
+
}
|
|
65
|
+
export type { StopSignal };
|
|
43
66
|
export interface SubInput {
|
|
44
67
|
geo: Geometry;
|
|
45
68
|
sig: string;
|
|
@@ -48,6 +71,11 @@ export interface CookOptions {
|
|
|
48
71
|
target?: string;
|
|
49
72
|
vars?: Record<string, any>;
|
|
50
73
|
inputs?: SubInput[];
|
|
74
|
+
/**
|
|
75
|
+
* The scope to cook in (src/graph/scope.ts): node types, the graphs graph_ref reads and the files nodes read.
|
|
76
|
+
* Default: the engine's root scope. Nested cooks (subcook, inputAt) inherit it.
|
|
77
|
+
*/
|
|
78
|
+
scope?: Scope;
|
|
51
79
|
depth?: number;
|
|
52
80
|
/** frame to cook at (default 1). frame 1 = time 0; frame = time * fps + 1 when only time is given */
|
|
53
81
|
frame?: number;
|
|
@@ -62,6 +90,20 @@ export interface CookOptions {
|
|
|
62
90
|
* for an in-flight cook of the same signature when that cook is one of its ancestors (a recursive asset).
|
|
63
91
|
*/
|
|
64
92
|
ancestors?: ReadonlySet<string>;
|
|
93
|
+
/**
|
|
94
|
+
* Progress: called when a node starts cooking and when it ends (cache hits are not reported), for the graph's own
|
|
95
|
+
* nodes and for those of nested cooks. A promise returned for a start is awaited before the node cooks: a host
|
|
96
|
+
* yields to its event loop there, so it can serve requests (a stop among them) while a long cook runs.
|
|
97
|
+
*/
|
|
98
|
+
onNode?: (ev: NodeProgress) => void | Promise<void>;
|
|
99
|
+
/**
|
|
100
|
+
* Stop: once `aborted` is true the cook stops at the next node boundary. The node about to cook fails with STOPPED,
|
|
101
|
+
* the nodes downstream fail as upstream errors, and the report's `stopped` names the node. A node already cooking
|
|
102
|
+
* runs to its end unless it reads ctx.signal itself. Nested cooks (subcook, inputAt) share the signal.
|
|
103
|
+
*/
|
|
104
|
+
signal?: StopSignal;
|
|
105
|
+
/** Internal: the enclosing nodes of a nested cook (NodeProgress.within). */
|
|
106
|
+
within?: readonly string[];
|
|
65
107
|
}
|
|
66
108
|
/** Frame range for cookFrames (end inclusive). */
|
|
67
109
|
export interface FrameRange {
|
|
@@ -69,12 +111,6 @@ export interface FrameRange {
|
|
|
69
111
|
end: number;
|
|
70
112
|
step?: number;
|
|
71
113
|
}
|
|
72
|
-
interface AssetEntry {
|
|
73
|
-
name: string;
|
|
74
|
-
graph: GraphSpec;
|
|
75
|
-
def: NodeDef;
|
|
76
|
-
hash: string;
|
|
77
|
-
}
|
|
78
114
|
declare class GeoCache {
|
|
79
115
|
private map;
|
|
80
116
|
private bytes;
|
|
@@ -101,12 +137,23 @@ export declare function wiringOf(spec: NodeSpec, def: NodeDef): {
|
|
|
101
137
|
list: (string | null)[];
|
|
102
138
|
errors: string[];
|
|
103
139
|
};
|
|
140
|
+
/**
|
|
141
|
+
* A graph as a node type (an asset, a package output): its vars are the params, with their "params" declarations, and
|
|
142
|
+
* its input nodes the inputs, by their index.
|
|
143
|
+
*/
|
|
144
|
+
export declare function graphInterface(graph: GraphSpec): {
|
|
145
|
+
params: Record<string, ParamDef>;
|
|
146
|
+
inputs: InputDef[];
|
|
147
|
+
};
|
|
104
148
|
export declare class Engine {
|
|
105
149
|
host: Host;
|
|
106
150
|
cache: GeoCache;
|
|
107
|
-
|
|
151
|
+
/** the package's scope: the assets, graphs and files of every cook that is not given another (CookOptions.scope) */
|
|
152
|
+
readonly root: Scope;
|
|
108
153
|
/** base signatures of nodes found to depend on time while cooking */
|
|
109
154
|
timeDeps: Set<string>;
|
|
155
|
+
/** signatures (without the scope) of nodes found to read their scope: their results are keyed by the scope's id */
|
|
156
|
+
scopeDeps: Set<string>;
|
|
110
157
|
/** manifold-3d wasm module, loaded by init() */
|
|
111
158
|
manifold: any;
|
|
112
159
|
maxDepth: number;
|
|
@@ -123,39 +170,55 @@ export declare class Engine {
|
|
|
123
170
|
poolStats: PoolStats;
|
|
124
171
|
/** cooks in progress by signature: a second cook of the same signature waits for the first */
|
|
125
172
|
private inflight;
|
|
126
|
-
/** shelf assets as shipped (name → graph), kept so that deleting a workspace override restores them */
|
|
127
|
-
shelf: Map<string, GraphSpec>;
|
|
128
|
-
/** problems found while loading the shelf (unreadable index or files, invalid graphs) */
|
|
129
|
-
shelfErrors: string[];
|
|
130
|
-
private shelfLoaded;
|
|
131
173
|
constructor(host: Host);
|
|
132
174
|
init(): Promise<void>;
|
|
133
175
|
/**
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
* serves the same directory over HTTP. Workspace assets with the same name take precedence: they replace the shelf
|
|
137
|
-
* entry when registered, and a (re)load of the shelf never replaces them.
|
|
176
|
+
* A node type in a scope: its own assets, then the built-in nodes. A name with a slash is a package output, which
|
|
177
|
+
* only the scope's packages resolve (packageIssue says why one does not).
|
|
138
178
|
*/
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
179
|
+
resolveDef(type: string, scope?: Scope): NodeDef | undefined;
|
|
180
|
+
/** Why a name with a slash names no node type in a scope: a package the scope does not use, an unknown output … */
|
|
181
|
+
packageIssue(type: string, scope?: Scope): PackageIssue;
|
|
182
|
+
/**
|
|
183
|
+
* The names a did-you-mean offers in a scope: node types and their aliases, its assets, the package outputs it uses,
|
|
184
|
+
* and those its packages offer (PackageResolver.offered), which a graph's first use adds.
|
|
185
|
+
*/
|
|
186
|
+
allTypeNames(scope?: Scope): string[];
|
|
187
|
+
/**
|
|
188
|
+
* The node types of package outputs for the catalog and help: those a scope uses, then those its packages offer that
|
|
189
|
+
* it does not use yet (PackageResolver.offered: TopoTopo's own, which a graph's first use adds).
|
|
190
|
+
*/
|
|
191
|
+
packageDefs(scope?: Scope): NodeDef[];
|
|
192
|
+
/**
|
|
193
|
+
* A scope for cooks of its own (CookOptions.scope): its id (not "", which is the root's), the folder its relative
|
|
194
|
+
* paths read (absolute, or relative to the host's own; default: the host's files), the graphs graph_ref reads in it
|
|
195
|
+
* and the package outputs its graphs name. Register its assets with registerAsset(name, graph, {scope}), or give it
|
|
196
|
+
* another scope's (`assets`: a scope like that one with other packages).
|
|
197
|
+
*/
|
|
198
|
+
createScope(id: string, opts?: {
|
|
199
|
+
folder?: string;
|
|
200
|
+
graphs?: (name: string) => GraphSpec | undefined;
|
|
201
|
+
packages?: PackageResolver;
|
|
202
|
+
assets?: Map<string, AssetEntry>;
|
|
203
|
+
}): Scope;
|
|
204
|
+
/** The asset a name refers to in a scope: one of the scope's own. */
|
|
205
|
+
asset(name: string, scope?: Scope): AssetEntry | undefined;
|
|
206
|
+
/** The assets a scope has, in the order they were registered. */
|
|
207
|
+
assetsIn(scope?: Scope): AssetEntry[];
|
|
208
|
+
/** Register a graph as a node type, an asset of a scope (default: the root). The graph is validated in that scope. */
|
|
146
209
|
registerAsset(name: string, graph: GraphSpec, opts?: {
|
|
147
|
-
|
|
210
|
+
scope?: Scope;
|
|
148
211
|
}): NodeDef;
|
|
149
|
-
findOutput(graph: GraphSpec): {
|
|
212
|
+
findOutput(graph: GraphSpec, scope?: Scope): {
|
|
150
213
|
name: string;
|
|
151
214
|
note?: string;
|
|
152
215
|
};
|
|
153
|
-
validate(graph: GraphSpec, path?: string): {
|
|
216
|
+
validate(graph: GraphSpec, path?: string, scope?: Scope): {
|
|
154
217
|
errors: Issue[];
|
|
155
218
|
warnings: Issue[];
|
|
156
219
|
};
|
|
157
220
|
/** Validate and resolve all params without cooking. */
|
|
158
|
-
dryRun(graph: GraphSpec, vars?: Record<string, any
|
|
221
|
+
dryRun(graph: GraphSpec, vars?: Record<string, any>, scope?: Scope): {
|
|
159
222
|
errors: Issue[];
|
|
160
223
|
warnings: Issue[];
|
|
161
224
|
notes: string[];
|