topotopo 0.2.0 → 0.4.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.
Files changed (132) hide show
  1. package/NOTICE +30 -0
  2. package/README.md +54 -16
  3. package/dist/cli.js +95 -14
  4. package/dist/core/analysis.d.ts +5 -1
  5. package/dist/core/analysis.js +8 -3
  6. package/dist/core/bake.d.ts +2 -5
  7. package/dist/core/bake.js +12 -25
  8. package/dist/core/bevel.js +165 -97
  9. package/dist/core/geometry.js +1 -1
  10. package/dist/core/imageops.d.ts +6 -0
  11. package/dist/core/imageops.js +51 -0
  12. package/dist/core/materials.d.ts +4 -0
  13. package/dist/core/materials.js +11 -0
  14. package/dist/core/packed.js +11 -0
  15. package/dist/core/particles.d.ts +1 -1
  16. package/dist/core/particles.js +1 -1
  17. package/dist/core/rbd.js +13 -1
  18. package/dist/core/scatter.d.ts +1 -1
  19. package/dist/core/scatter.js +1 -1
  20. package/dist/core/scene.d.ts +20 -0
  21. package/dist/core/scene.js +71 -0
  22. package/dist/core/snippet-lib.d.ts +1 -1
  23. package/dist/core/snippet-lib.js +1 -1
  24. package/dist/core/solidify.d.ts +38 -0
  25. package/dist/core/solidify.js +356 -0
  26. package/dist/core/tangents.d.ts +52 -0
  27. package/dist/core/tangents.js +214 -0
  28. package/dist/core/texcoord.d.ts +4 -0
  29. package/dist/core/texcoord.js +14 -0
  30. package/dist/core/topology.d.ts +22 -0
  31. package/dist/core/topology.js +70 -7
  32. package/dist/core/traceimage.d.ts +7 -0
  33. package/dist/core/traceimage.js +221 -0
  34. package/dist/core/tritri.d.ts +5 -0
  35. package/dist/core/tritri.js +120 -0
  36. package/dist/core/uv.d.ts +13 -0
  37. package/dist/core/uv.js +3 -3
  38. package/dist/core/uvreport.d.ts +66 -0
  39. package/dist/core/uvreport.js +308 -0
  40. package/dist/core/xatlas.js +32 -2
  41. package/dist/gallery/app/gallery.css +100 -0
  42. package/dist/gallery/app/gallery.js +80 -0
  43. package/dist/gallery/bake.d.ts +34 -0
  44. package/dist/gallery/bake.js +144 -0
  45. package/dist/gallery/cli.d.ts +4 -0
  46. package/dist/gallery/cli.js +157 -0
  47. package/dist/gallery/library.d.ts +124 -0
  48. package/dist/gallery/library.js +366 -0
  49. package/dist/gallery/pages.d.ts +94 -0
  50. package/dist/gallery/pages.js +148 -0
  51. package/dist/gallery/server.d.ts +21 -0
  52. package/dist/gallery/server.js +391 -0
  53. package/dist/graph/engine.js +14 -0
  54. package/dist/graph/types.d.ts +17 -0
  55. package/dist/host/artifacts.d.ts +21 -0
  56. package/dist/host/artifacts.js +58 -0
  57. package/dist/host/export-targets.d.ts +33 -0
  58. package/dist/host/export-targets.js +84 -0
  59. package/dist/index.d.ts +3 -1
  60. package/dist/index.js +2 -1
  61. package/dist/inspect.d.ts +6 -1
  62. package/dist/inspect.js +13 -1
  63. package/dist/io/common.d.ts +8 -0
  64. package/dist/io/gltf.js +236 -19
  65. package/dist/io/targets.d.ts +31 -0
  66. package/dist/io/targets.js +75 -0
  67. package/dist/mcp/docs.d.ts +1 -1
  68. package/dist/mcp/docs.js +73 -6
  69. package/dist/mcp/library.d.ts +12 -0
  70. package/dist/mcp/library.js +159 -0
  71. package/dist/mcp/server.js +29 -12
  72. package/dist/mcp/tools.d.ts +1 -1
  73. package/dist/mcp/tools.js +102 -43
  74. package/dist/nodes/bake.js +56 -36
  75. package/dist/nodes/bevel.js +4 -3
  76. package/dist/nodes/code.js +33 -7
  77. package/dist/nodes/curves.js +7 -0
  78. package/dist/nodes/generate.js +1 -1
  79. package/dist/nodes/imageops.d.ts +1 -0
  80. package/dist/nodes/imageops.js +206 -0
  81. package/dist/nodes/index.d.ts +3 -0
  82. package/dist/nodes/index.js +3 -0
  83. package/dist/nodes/material.js +3 -0
  84. package/dist/nodes/measure.js +3 -2
  85. package/dist/nodes/rbd.js +1 -1
  86. package/dist/nodes/scene.d.ts +1 -0
  87. package/dist/nodes/scene.js +53 -0
  88. package/dist/nodes/solidify.d.ts +1 -0
  89. package/dist/nodes/solidify.js +52 -0
  90. package/dist/nodes/transform.js +5 -1
  91. package/dist/nodes/util.d.ts +1 -1
  92. package/dist/nodes/wasmcall.js +1 -1
  93. package/dist/render/options.js +1 -1
  94. package/dist/render/pbr.d.ts +28 -0
  95. package/dist/render/pbr.js +378 -0
  96. package/dist/render/preview.d.ts +58 -0
  97. package/dist/render/preview.js +24 -0
  98. package/dist/render/raster.d.ts +12 -2
  99. package/dist/render/raster.js +98 -11
  100. package/dist/render/texview.d.ts +1 -1
  101. package/dist/render/texview.js +7 -2
  102. package/dist/viewer/app/camera.js +27 -7
  103. package/dist/viewer/app/embed.js +80 -0
  104. package/dist/viewer/app/export-popover.js +68 -0
  105. package/dist/viewer/app/grid.js +1 -1
  106. package/dist/viewer/app/guides.js +1 -1
  107. package/dist/viewer/app/image-view.js +114 -0
  108. package/dist/viewer/app/keymap.js +15 -3
  109. package/dist/viewer/app/layers.js +24 -5
  110. package/dist/viewer/app/main.js +71 -15
  111. package/dist/viewer/app/markers.js +1 -1
  112. package/dist/viewer/app/outliner.js +56 -15
  113. package/dist/viewer/app/outputs.css +73 -0
  114. package/dist/viewer/app/outputs.js +240 -0
  115. package/dist/viewer/app/props.js +1 -1
  116. package/dist/viewer/app/scene.js +6 -2
  117. package/dist/viewer/app/select.js +14 -3
  118. package/dist/viewer/app/selection.js +1 -1
  119. package/dist/viewer/app/status.js +20 -0
  120. package/dist/viewer/app/style.css +2 -1
  121. package/dist/viewer/app/units.js +1 -1
  122. package/dist/viewer/app/vars.js +1 -1
  123. package/dist/viewer/index.html +20 -6
  124. package/dist/viewer/outputs.d.ts +54 -0
  125. package/dist/viewer/outputs.js +436 -0
  126. package/dist/viewer/server.d.ts +19 -2
  127. package/dist/viewer/server.js +77 -9
  128. package/dist/workspace.d.ts +21 -2
  129. package/dist/workspace.js +124 -4
  130. package/kernels/pkg/README.md +21 -28
  131. package/kernels/pkg-simd/README.md +21 -28
  132. package/package.json +11 -4
@@ -1,9 +1,12 @@
1
1
  import { Engine } from './graph/engine.ts';
2
2
  import type { CookReport, Issue } from './graph/engine.ts';
3
- import type { GraphSpec, NodeSpec } from './graph/types.ts';
3
+ import type { ExportTarget, GraphSpec, NodeSpec } from './graph/types.ts';
4
4
  export interface EditOp {
5
- op: 'set' | 'add' | 'remove' | 'connect' | 'rename' | 'output' | 'vars' | 'bypass' | 'replace' | 'insert';
5
+ op: 'set' | 'add' | 'remove' | 'connect' | 'rename' | 'output' | 'vars' | 'bypass' | 'replace' | 'insert' | 'export';
6
6
  node?: string;
7
+ /** op export: the named output (omitted: the default output) and its target (null removes it) */
8
+ output?: string;
9
+ export?: ExportTarget | null;
7
10
  params?: Record<string, any>;
8
11
  spec?: NodeSpec;
9
12
  type?: string;
@@ -16,6 +19,7 @@ export interface EditOp {
16
19
  value?: boolean;
17
20
  note?: string;
18
21
  }
22
+ export declare const NAME_RE: RegExp;
19
23
  /** A file under <workspace>/inputs. */
20
24
  export interface InputFile {
21
25
  /** posix path relative to inputs/ (a file node reads it as "inputs/" + path) */
@@ -38,6 +42,8 @@ export interface WorkspaceOptions {
38
42
  * graph that never gets a drop leaves no empty inputs/ beside it.
39
43
  */
40
44
  inputs?: string;
45
+ /** Persistent exports directory; view mode places it beside the source graph. */
46
+ exports?: string;
41
47
  }
42
48
  /** Thrown by Workspace.edit when the edited graph does not validate; the stored graph is unchanged. */
43
49
  export declare class EditRejected extends Error {
@@ -56,6 +62,7 @@ export declare class Workspace {
56
62
  }) => void>;
57
63
  /** the inputs folder given to the constructor (WorkspaceOptions.inputs), if any */
58
64
  private inputsAt;
65
+ private exportsAt;
59
66
  constructor(dir: string, engine: Engine, opts?: WorkspaceOptions);
60
67
  get graphDir(): string;
61
68
  get assetDir(): string;
@@ -99,4 +106,16 @@ export declare class Workspace {
99
106
  report: CookReport;
100
107
  }>;
101
108
  cook(name: string, target?: string, frame?: number): Promise<CookReport>;
109
+ private watchers;
110
+ private watchTimers;
111
+ /**
112
+ * Follow what other processes write into graphs/ and assets/ (a second Workspace on the same folder: the gallery's
113
+ * editor next to an MCP server, or a person editing the JSON). A graph file whose content differs from the stored
114
+ * graph replaces it and notifies the listeners; a removed file removes the graph. Our own writes read back equal, so
115
+ * they change nothing. An asset whose content changed is registered again and every graph is notified (any may use
116
+ * it); a removed asset stays registered until the next load(). Two writers to one graph: the last write wins.
117
+ */
118
+ watch(): void;
119
+ /** Stop following the folders (watch()). */
120
+ unwatch(): void;
102
121
  }
package/dist/workspace.js CHANGED
@@ -9,9 +9,9 @@ import path from 'node:path';
9
9
  import { Engine, wiringOf } from './graph/engine.js';
10
10
  import { didYouMean, renameExprRefs } from './graph/params.js';
11
11
  import { migrateGraph } from './graph/migrate.js';
12
- const NAME_RE = /^[A-Za-z_][\w.-]*$/;
12
+ export const NAME_RE = /^[A-Za-z_][\w.-]*$/;
13
13
  const GEOMETRY_EXTS = new Set(['obj', 'stl', 'ply', 'glb', 'gltf', 'geo', 'bgeo', 'blend', 'csv', 'json', 'points.json']);
14
- const IMAGE_EXTS = new Set(['png']);
14
+ const IMAGE_EXTS = new Set(['png', 'jpg', 'jpeg', 'webp']);
15
15
  /** Lower-case extension of a file name without the dot; ".points.json" is one extension, dot-files have none. */
16
16
  export function inputExt(file) {
17
17
  const b = file.toLowerCase().replace(/^.*[\\/]/, '');
@@ -41,15 +41,17 @@ export class Workspace {
41
41
  listeners = new Set();
42
42
  /** the inputs folder given to the constructor (WorkspaceOptions.inputs), if any */
43
43
  inputsAt;
44
+ exportsAt;
44
45
  constructor(dir, engine, opts = {}) {
45
46
  this.dir = path.resolve(dir);
46
47
  this.engine = engine;
47
48
  this.inputsAt = opts.inputs === undefined ? undefined : path.resolve(opts.inputs);
49
+ this.exportsAt = opts.exports === undefined ? undefined : path.resolve(opts.exports);
48
50
  engine.graphResolver = (n) => this.graphs.get(n);
49
51
  }
50
52
  get graphDir() { return path.join(this.dir, 'graphs'); }
51
53
  get assetDir() { return path.join(this.dir, 'assets'); }
52
- get exportDir() { return path.join(this.dir, 'exports'); }
54
+ get exportDir() { return this.exportsAt ?? path.join(this.dir, 'exports'); }
53
55
  /**
54
56
  * files people drop in: meshes, guide curves and points, PNG masks and heightmaps (read as "inputs/<path>");
55
57
  * <dir>/inputs unless the constructor was given another folder
@@ -168,6 +170,10 @@ export class Workspace {
168
170
  base.params = { ...(base.params ?? {}), ...patch.params };
169
171
  if (patch.output)
170
172
  base.output = patch.output;
173
+ if (patch.outputs)
174
+ base.outputs = { ...base.outputs, ...patch.outputs };
175
+ if (patch.export !== undefined)
176
+ base.export = patch.export;
171
177
  if (patch.description)
172
178
  base.description = patch.description;
173
179
  return base;
@@ -253,6 +259,9 @@ export class Workspace {
253
259
  delete g.nodes[n];
254
260
  if (g.output === n)
255
261
  delete g.output;
262
+ for (const [id, out] of Object.entries(g.outputs ?? {}))
263
+ if (out.node === n)
264
+ delete g.outputs[id];
256
265
  break;
257
266
  }
258
267
  case 'connect': {
@@ -282,6 +291,9 @@ export class Workspace {
282
291
  setRef(r.node, r.idx, op.to);
283
292
  if (g.output === n)
284
293
  g.output = op.to;
294
+ for (const out of Object.values(g.outputs ?? {}))
295
+ if (out.node === n)
296
+ out.node = op.to;
285
297
  // expression references: npoints("old"), ch("old/param") …
286
298
  const touched = [];
287
299
  for (const [k, spec] of Object.entries(g.nodes)) {
@@ -312,6 +324,28 @@ export class Workspace {
312
324
  case 'bypass':
313
325
  g.nodes[need(op.node, where)].bypass = op.value ?? true;
314
326
  break;
327
+ case 'export': {
328
+ // the target of the default output, or of a named one; null removes it (validated with the graph)
329
+ if (op.export === undefined)
330
+ throw new Error(`${where}: give "export": a format ("glb"), {format, path?, ...options}, or null`);
331
+ if (op.output === undefined) {
332
+ if (op.export === null)
333
+ delete g.export;
334
+ else
335
+ g.export = op.export;
336
+ break;
337
+ }
338
+ const out = g.outputs?.[op.output];
339
+ if (!out) {
340
+ const s = didYouMean(op.output, Object.keys(g.outputs ?? {}));
341
+ throw new Error(`${where}: no output "${op.output}"${s.length ? ` — did you mean ${s.join(', ')}?` : ''} (publish it in "outputs" first)`);
342
+ }
343
+ if (op.export === null)
344
+ delete out.export;
345
+ else
346
+ out.export = op.export;
347
+ break;
348
+ }
315
349
  case 'insert': {
316
350
  const after = need(op.after, `${where} after`);
317
351
  if (!op.node || !NAME_RE.test(op.node) || g.nodes[op.node])
@@ -327,7 +361,7 @@ export class Workspace {
327
361
  notes.push(`inserted "${op.node}" after "${after}"${consumers.length ? `; now feeds ${consumers.map((c) => c.node).join(', ')}` : ''}`);
328
362
  break;
329
363
  }
330
- default: throw new Error(`${where}: unknown op. Use set, add, remove, connect, rename, output, vars, bypass, replace, insert`);
364
+ default: throw new Error(`${where}: unknown op. Use set, add, remove, connect, rename, output, vars, bypass, replace, insert, export`);
331
365
  }
332
366
  }
333
367
  return { graph: g, notes };
@@ -360,4 +394,90 @@ export class Workspace {
360
394
  this.lastReport.set(name, r);
361
395
  return r;
362
396
  }
397
+ watchers = [];
398
+ watchTimers = new Map();
399
+ /**
400
+ * Follow what other processes write into graphs/ and assets/ (a second Workspace on the same folder: the gallery's
401
+ * editor next to an MCP server, or a person editing the JSON). A graph file whose content differs from the stored
402
+ * graph replaces it and notifies the listeners; a removed file removes the graph. Our own writes read back equal, so
403
+ * they change nothing. An asset whose content changed is registered again and every graph is notified (any may use
404
+ * it); a removed asset stays registered until the next load(). Two writers to one graph: the last write wins.
405
+ */
406
+ watch() {
407
+ if (this.watchers.length)
408
+ return;
409
+ const on = (dir, apply) => {
410
+ try {
411
+ const w = fs.watch(dir, (_ev, f) => {
412
+ const rel = f ? String(f) : '';
413
+ // Windows names a removed folder by its absolute path: stop rather than follow a folder that is gone
414
+ if (path.isAbsolute(rel)) {
415
+ w.close();
416
+ return;
417
+ }
418
+ if (!rel.endsWith('.json') || rel.includes(path.sep) || rel.startsWith('.'))
419
+ return;
420
+ const name = rel.slice(0, -'.json'.length), key = dir + '|' + name;
421
+ clearTimeout(this.watchTimers.get(key));
422
+ // persist() is not atomic: let the writer finish, and read again if the JSON is still half written
423
+ let tries = 0;
424
+ const run = () => {
425
+ this.watchTimers.delete(key);
426
+ try {
427
+ apply(name, path.join(dir, rel));
428
+ }
429
+ catch (e) {
430
+ if (e instanceof SyntaxError && ++tries < 5)
431
+ this.watchTimers.set(key, setTimeout(run, 100).unref());
432
+ }
433
+ };
434
+ this.watchTimers.set(key, setTimeout(run, 150).unref());
435
+ });
436
+ w.on('error', () => w.close());
437
+ w.unref();
438
+ this.watchers.push(w);
439
+ }
440
+ catch { /* no folder: nothing to follow */ }
441
+ };
442
+ on(this.graphDir, (name, file) => {
443
+ if (!NAME_RE.test(name))
444
+ return;
445
+ if (!fs.existsSync(file)) {
446
+ if (this.graphs.delete(name)) {
447
+ this.lastReport.delete(name);
448
+ this.bump(name);
449
+ }
450
+ return;
451
+ }
452
+ const spec = migrateGraph(JSON.parse(fs.readFileSync(file, 'utf8')));
453
+ const cur = this.graphs.get(name);
454
+ if (cur && JSON.stringify(cur) === JSON.stringify(spec))
455
+ return;
456
+ this.graphs.set(name, spec);
457
+ this.lastReport.delete(name);
458
+ this.bump(name);
459
+ });
460
+ on(this.assetDir, (name, file) => {
461
+ if (!fs.existsSync(file))
462
+ return;
463
+ const spec = migrateGraph(JSON.parse(fs.readFileSync(file, 'utf8')));
464
+ const before = this.engine.assets.get(name)?.hash;
465
+ this.engine.registerAsset(name, spec);
466
+ if (this.engine.assets.get(name)?.hash === before)
467
+ return;
468
+ for (const g of this.graphs.keys()) {
469
+ this.lastReport.delete(g);
470
+ this.bump(g);
471
+ }
472
+ });
473
+ }
474
+ /** Stop following the folders (watch()). */
475
+ unwatch() {
476
+ for (const w of this.watchers)
477
+ w.close();
478
+ for (const t of this.watchTimers.values())
479
+ clearTimeout(t);
480
+ this.watchers = [];
481
+ this.watchTimers.clear();
482
+ }
363
483
  }
@@ -6,7 +6,7 @@ SIMD and scalar WebAssembly builds; normal TopoTopo users do not install Rust.
6
6
  The loader feature-detects simd128 and defaults to SIMD, with scalar fallback.
7
7
  See [BUILD.md](https://github.com/topotopo-dev/topotopo/blob/main/kernels/BUILD.md).
8
8
 
9
- ## Scatter selection (sessions 12-13)
9
+ ## Scatter selection
10
10
 
11
11
  `scatter_eliminate(positions, scale, target_count, r_max)` and
12
12
  `scatter_min_distance(positions, order, radius, limit, groups, group_cap)` expose
@@ -62,7 +62,7 @@ positive minimum distances whose squares underflow to zero, and
62
62
  excessive pair lists return errors. Minimum-distance grid coordinates are limited
63
63
  to the exact integer range `abs(position / radius) <= 2^52 - 4`, so hostile tiny
64
64
  radii cannot produce overflowing or nonadvancing cell loops. No dependencies were
65
- added. See [BENCH.md](https://github.com/topotopo-dev/topotopo/blob/main/kernels/BENCH.md) for measured parity, timing and remaining limits.
65
+ added.
66
66
 
67
67
  `scatter_relax` accepts f64 positions, per-point spacing, triangle indices and
68
68
  barycentrics, plus the existing `TriSurface.arrays()` buffers (`T`, `nodes`, `child`,
@@ -87,8 +87,8 @@ with at least three started pool slots, or 500k with two; uniform elimination fr
87
87
  500k candidates with at least four, or 250k with at least eight; and projected
88
88
  relaxation from 50k kept points with at least three. Minimum-distance rejection
89
89
  uses WASM. Cold/disabled pools and stages below a pool threshold use WASM;
90
- counts beyond kernel budgets use JS. See session 13 in BENCH.md for the measured
91
- crossover and its machine-specific scope. Sampling and attribute
90
+ counts beyond kernel budgets use JS. The measured crossover is machine-specific.
91
+ Sampling and attribute
92
92
  interpolation remain in TS; heightfield_scatter retains its TS integration.
93
93
  `cargo bench --manifest-path kernels/Cargo.toml --features profile --bench scatter`
94
94
  prints native KD/search/heap/grid/projection stage timings. `bench/bench.ts` measures
@@ -105,10 +105,10 @@ initializes WASM once per worker on its first such job;
105
105
  the full-stage registry entry rejects split ranges, and an unavailable pool falls
106
106
  back to the loaded main-thread kernel.
107
107
  The pool threshold override can force this path for parity tests. The conservative
108
- default retains session 12's 1M placement cutoff; session 13's 500k measurement
109
- did not support lowering it.
108
+ default keeps a 1M placement cutoff; a 500k measurement did not support lowering
109
+ it.
110
110
 
111
- ## Heightfield erosion (session 4)
111
+ ## Heightfield erosion
112
112
 
113
113
  `src/wasm/kernels.ts` exposes `erode_droplet`, `erode_pipe`, `thermal_erode`, and
114
114
  `flow_accumulation`. Heights and optional hardness/freeze/rain maps are flat row-major
@@ -191,9 +191,7 @@ use f64x2 SIMD while preserving scalar arithmetic and active thermal transfer
191
191
  order. Row bounds are validated
192
192
  before the small unchecked stencil/scatter loops; ordinary pipe and droplet work
193
193
  buffers are allocated before iteration. Filled routing allocates its flood and
194
- drainage buffers when refreshed. See the session 6 and session 15 measurements,
195
- rejected experiments and remaining limits in
196
- [BENCH.md](https://github.com/topotopo-dev/topotopo/blob/main/kernels/BENCH.md).
194
+ drainage buffers when refreshed.
197
195
 
198
196
  `flow_accumulation` offers D8 and triangular-facet D-infinity routing. Accumulation
199
197
  includes each sample's own cell area. Stable height/index ordering fixes the sum
@@ -221,10 +219,9 @@ Scalar/SIMD corpus parity compares every returned byte, with no floating toleran
221
219
  golden and pool tests exercise the default SIMD path. `TOPOTOPO_WASM=scalar|simd`
222
220
  selects an explicit path before import. No dependencies were added; existing crate
223
221
  licences below still apply.
224
- See [BENCH.md](https://github.com/topotopo-dev/topotopo/blob/main/kernels/BENCH.md) for measured acceptance and performance, and
225
- `examples/renders/erosion_models.png` for the four-model comparison.
222
+ See `examples/renders/erosion_models.png` for the four-model comparison.
226
223
 
227
- ## Depression filling and lakes (session 14)
224
+ ## Depression filling and lakes
228
225
 
229
226
  The loader API is `fill_sinks(height, width, heightCount, options?, mask?)`, with
230
227
  `Float32Array` height/mask buffers and options `epsilon`, `maxDepth` and
@@ -303,9 +300,7 @@ filled and deeper lakes retained on the right. Both use the same contributing-ar
303
300
  colour scale; lake surfaces are blue. Its `filled` node is the terrain result;
304
301
  `water_surface` raises only the display mesh by `lake`, keeping water and terrain
305
302
  separate in the actual heightfield. Run `node test/showcase.ts drainage` and inspect
306
- `examples/renders/drainage.png`. See session 14 in
307
- [BENCH.md](https://github.com/topotopo-dev/topotopo/blob/main/kernels/BENCH.md)
308
- for the measured timings, backend parity and remaining limits.
303
+ `examples/renders/drainage.png`.
309
304
 
310
305
  ## API and geometry
311
306
 
@@ -396,7 +391,7 @@ has not been established by an exhaustive platform matrix.
396
391
  Current limits are explicit:
397
392
 
398
393
  - At most 4096 contour vertices. Event search and incidence rebuilding are deliberately
399
- exhaustive (roughly cubic time on typical inputs); this session prioritizes correctness.
394
+ exhaustive (roughly cubic time on typical inputs); correctness comes first.
400
395
  - Adjacent exactly collinear edges with **different** speeds/pitches are rejected with
401
396
  an actionable error. Equal-speed collinear points are supported and keep provenance.
402
397
  - Touching/intersecting contours, nested holes, duplicate points, zero-area rings, all
@@ -413,7 +408,7 @@ Current limits are explicit:
413
408
  the weights and then convert the returned times accordingly. Ordinary roof pitches
414
409
  and the explicit 90-degree gable are covered by tests; pitches extremely close to
415
410
  zero or 90 degrees can encounter the same limit.
416
- - The Rust isotropic remesher and point kernels are not included; sessions 3/4 add quad remeshing and erosion.
411
+ - The Rust isotropic remesher and point kernels are not included; quad remeshing and erosion are separate kernels.
417
412
 
418
413
  ## Tests
419
414
 
@@ -461,9 +456,9 @@ dependency is used. `earcutr` is only used for flat cap triangulation, not skele
461
456
 
462
457
  `unicode-ident` is a compiler-only transitive dependency; its Unicode-3.0 data-table
463
458
  licence is permitted by the repository's build-time licence rule. Its identifier
464
- tables are not linked into the shipped WASM. Sessions 2, 3 and 4 add no dependencies.
459
+ tables are not linked into the shipped WASM. The SDF, remeshing and erosion kernels add no dependencies.
465
460
 
466
- ## Field-aligned quad remeshing (sessions 3 and 7)
461
+ ## Field-aligned quad remeshing
467
462
 
468
463
  ```js
469
464
  const mesh = remesh_quad(positions, tris, {
@@ -548,15 +543,14 @@ also capped at two million triangles. Self-intersecting inputs are not repaired.
548
543
  Face counts remain approximate, especially with locked borders or dense geometric
549
544
  constraints. Local cleanup and bounded integer correction do not establish global
550
545
  integrability or intersection freedom on arbitrary surfaces. Scalar/SIMD parity is
551
- tested on the regression corpus, not an exhaustive operating-system/compiler matrix. Session-7 measured
552
- acceptance, scalar/SIMD comparisons and remaining limits are in [BENCH.md](https://github.com/topotopo-dev/topotopo/blob/main/kernels/BENCH.md).
546
+ tested on the regression corpus, not an exhaustive operating-system/compiler matrix.
553
547
 
554
548
  Run `node test/remeshquad.ts`, `node bench/remeshquad.ts` and
555
549
  `cargo bench --manifest-path kernels/Cargo.toml --bench remesh_quad`.
556
550
  Inspect `examples/renders/quad_remesh.png`: gray inputs and colored results for a
557
551
  noisy sphere, bevelled box, shelf rock and capped tube, with every polygon edge visible.
558
552
 
559
- ## Sampled SDF grids (sessions 2 and 8)
553
+ ## Sampled SDF grids
560
554
 
561
555
  The original skeleton API is unchanged. Additional generated WASM exports are:
562
556
 
@@ -628,9 +622,9 @@ Ambiguous topology and unsafe sharp fits trigger local conservative patches. Sha
628
622
  face connectors make the transition conforming, without unmatched edges or T-junctions.
629
623
  These guards detect risky local configurations, not every possible geometric
630
624
  self-intersection. Runtime validation checks oriented edge incidence; the test corpus
631
- also checks vertex links and proper nonadjacent triangle crossings. See session 8 in
632
- `BENCH.md` for the remaining union-junction accuracy limit.
633
- The explicit `conservative=true` path retains the session-2 minmod gradients and
625
+ also checks vertex links and proper nonadjacent triangle crossings. Union junctions
626
+ remain less accurate (about 0.4 voxel).
627
+ The explicit `conservative=true` path retains the original minmod gradients and
634
628
  cell-local fans byte-for-byte. Signed negative zero at iso zero retains inside sign.
635
629
  Unclamped QEF fits are accepted only when they stay in their cells; otherwise the
636
630
  caller gets a clear enable-clamping error. The construction follows the uniform
@@ -673,5 +667,4 @@ existing `remesh` node and its `remesh_voxel` alias retain their old behavior.
673
667
  Run `node test/sdfgrid.ts` for Node integration, `node bench/sdfgrid.ts` for the 256³
674
668
  box benchmark, and inspect `examples/renders/voxel_remesh.png` (sharp left, smooth
675
669
  middle, dilate/erode/blur right). Existing goldens and render hashes are checked
676
- separately from the new example. Benchmarks and platform verification limits are in
677
- [BENCH.md](https://github.com/topotopo-dev/topotopo/blob/main/kernels/BENCH.md).
670
+ separately from the new example.
@@ -6,7 +6,7 @@ SIMD and scalar WebAssembly builds; normal TopoTopo users do not install Rust.
6
6
  The loader feature-detects simd128 and defaults to SIMD, with scalar fallback.
7
7
  See [BUILD.md](https://github.com/topotopo-dev/topotopo/blob/main/kernels/BUILD.md).
8
8
 
9
- ## Scatter selection (sessions 12-13)
9
+ ## Scatter selection
10
10
 
11
11
  `scatter_eliminate(positions, scale, target_count, r_max)` and
12
12
  `scatter_min_distance(positions, order, radius, limit, groups, group_cap)` expose
@@ -62,7 +62,7 @@ positive minimum distances whose squares underflow to zero, and
62
62
  excessive pair lists return errors. Minimum-distance grid coordinates are limited
63
63
  to the exact integer range `abs(position / radius) <= 2^52 - 4`, so hostile tiny
64
64
  radii cannot produce overflowing or nonadvancing cell loops. No dependencies were
65
- added. See [BENCH.md](https://github.com/topotopo-dev/topotopo/blob/main/kernels/BENCH.md) for measured parity, timing and remaining limits.
65
+ added.
66
66
 
67
67
  `scatter_relax` accepts f64 positions, per-point spacing, triangle indices and
68
68
  barycentrics, plus the existing `TriSurface.arrays()` buffers (`T`, `nodes`, `child`,
@@ -87,8 +87,8 @@ with at least three started pool slots, or 500k with two; uniform elimination fr
87
87
  500k candidates with at least four, or 250k with at least eight; and projected
88
88
  relaxation from 50k kept points with at least three. Minimum-distance rejection
89
89
  uses WASM. Cold/disabled pools and stages below a pool threshold use WASM;
90
- counts beyond kernel budgets use JS. See session 13 in BENCH.md for the measured
91
- crossover and its machine-specific scope. Sampling and attribute
90
+ counts beyond kernel budgets use JS. The measured crossover is machine-specific.
91
+ Sampling and attribute
92
92
  interpolation remain in TS; heightfield_scatter retains its TS integration.
93
93
  `cargo bench --manifest-path kernels/Cargo.toml --features profile --bench scatter`
94
94
  prints native KD/search/heap/grid/projection stage timings. `bench/bench.ts` measures
@@ -105,10 +105,10 @@ initializes WASM once per worker on its first such job;
105
105
  the full-stage registry entry rejects split ranges, and an unavailable pool falls
106
106
  back to the loaded main-thread kernel.
107
107
  The pool threshold override can force this path for parity tests. The conservative
108
- default retains session 12's 1M placement cutoff; session 13's 500k measurement
109
- did not support lowering it.
108
+ default keeps a 1M placement cutoff; a 500k measurement did not support lowering
109
+ it.
110
110
 
111
- ## Heightfield erosion (session 4)
111
+ ## Heightfield erosion
112
112
 
113
113
  `src/wasm/kernels.ts` exposes `erode_droplet`, `erode_pipe`, `thermal_erode`, and
114
114
  `flow_accumulation`. Heights and optional hardness/freeze/rain maps are flat row-major
@@ -191,9 +191,7 @@ use f64x2 SIMD while preserving scalar arithmetic and active thermal transfer
191
191
  order. Row bounds are validated
192
192
  before the small unchecked stencil/scatter loops; ordinary pipe and droplet work
193
193
  buffers are allocated before iteration. Filled routing allocates its flood and
194
- drainage buffers when refreshed. See the session 6 and session 15 measurements,
195
- rejected experiments and remaining limits in
196
- [BENCH.md](https://github.com/topotopo-dev/topotopo/blob/main/kernels/BENCH.md).
194
+ drainage buffers when refreshed.
197
195
 
198
196
  `flow_accumulation` offers D8 and triangular-facet D-infinity routing. Accumulation
199
197
  includes each sample's own cell area. Stable height/index ordering fixes the sum
@@ -221,10 +219,9 @@ Scalar/SIMD corpus parity compares every returned byte, with no floating toleran
221
219
  golden and pool tests exercise the default SIMD path. `TOPOTOPO_WASM=scalar|simd`
222
220
  selects an explicit path before import. No dependencies were added; existing crate
223
221
  licences below still apply.
224
- See [BENCH.md](https://github.com/topotopo-dev/topotopo/blob/main/kernels/BENCH.md) for measured acceptance and performance, and
225
- `examples/renders/erosion_models.png` for the four-model comparison.
222
+ See `examples/renders/erosion_models.png` for the four-model comparison.
226
223
 
227
- ## Depression filling and lakes (session 14)
224
+ ## Depression filling and lakes
228
225
 
229
226
  The loader API is `fill_sinks(height, width, heightCount, options?, mask?)`, with
230
227
  `Float32Array` height/mask buffers and options `epsilon`, `maxDepth` and
@@ -303,9 +300,7 @@ filled and deeper lakes retained on the right. Both use the same contributing-ar
303
300
  colour scale; lake surfaces are blue. Its `filled` node is the terrain result;
304
301
  `water_surface` raises only the display mesh by `lake`, keeping water and terrain
305
302
  separate in the actual heightfield. Run `node test/showcase.ts drainage` and inspect
306
- `examples/renders/drainage.png`. See session 14 in
307
- [BENCH.md](https://github.com/topotopo-dev/topotopo/blob/main/kernels/BENCH.md)
308
- for the measured timings, backend parity and remaining limits.
303
+ `examples/renders/drainage.png`.
309
304
 
310
305
  ## API and geometry
311
306
 
@@ -396,7 +391,7 @@ has not been established by an exhaustive platform matrix.
396
391
  Current limits are explicit:
397
392
 
398
393
  - At most 4096 contour vertices. Event search and incidence rebuilding are deliberately
399
- exhaustive (roughly cubic time on typical inputs); this session prioritizes correctness.
394
+ exhaustive (roughly cubic time on typical inputs); correctness comes first.
400
395
  - Adjacent exactly collinear edges with **different** speeds/pitches are rejected with
401
396
  an actionable error. Equal-speed collinear points are supported and keep provenance.
402
397
  - Touching/intersecting contours, nested holes, duplicate points, zero-area rings, all
@@ -413,7 +408,7 @@ Current limits are explicit:
413
408
  the weights and then convert the returned times accordingly. Ordinary roof pitches
414
409
  and the explicit 90-degree gable are covered by tests; pitches extremely close to
415
410
  zero or 90 degrees can encounter the same limit.
416
- - The Rust isotropic remesher and point kernels are not included; sessions 3/4 add quad remeshing and erosion.
411
+ - The Rust isotropic remesher and point kernels are not included; quad remeshing and erosion are separate kernels.
417
412
 
418
413
  ## Tests
419
414
 
@@ -461,9 +456,9 @@ dependency is used. `earcutr` is only used for flat cap triangulation, not skele
461
456
 
462
457
  `unicode-ident` is a compiler-only transitive dependency; its Unicode-3.0 data-table
463
458
  licence is permitted by the repository's build-time licence rule. Its identifier
464
- tables are not linked into the shipped WASM. Sessions 2, 3 and 4 add no dependencies.
459
+ tables are not linked into the shipped WASM. The SDF, remeshing and erosion kernels add no dependencies.
465
460
 
466
- ## Field-aligned quad remeshing (sessions 3 and 7)
461
+ ## Field-aligned quad remeshing
467
462
 
468
463
  ```js
469
464
  const mesh = remesh_quad(positions, tris, {
@@ -548,15 +543,14 @@ also capped at two million triangles. Self-intersecting inputs are not repaired.
548
543
  Face counts remain approximate, especially with locked borders or dense geometric
549
544
  constraints. Local cleanup and bounded integer correction do not establish global
550
545
  integrability or intersection freedom on arbitrary surfaces. Scalar/SIMD parity is
551
- tested on the regression corpus, not an exhaustive operating-system/compiler matrix. Session-7 measured
552
- acceptance, scalar/SIMD comparisons and remaining limits are in [BENCH.md](https://github.com/topotopo-dev/topotopo/blob/main/kernels/BENCH.md).
546
+ tested on the regression corpus, not an exhaustive operating-system/compiler matrix.
553
547
 
554
548
  Run `node test/remeshquad.ts`, `node bench/remeshquad.ts` and
555
549
  `cargo bench --manifest-path kernels/Cargo.toml --bench remesh_quad`.
556
550
  Inspect `examples/renders/quad_remesh.png`: gray inputs and colored results for a
557
551
  noisy sphere, bevelled box, shelf rock and capped tube, with every polygon edge visible.
558
552
 
559
- ## Sampled SDF grids (sessions 2 and 8)
553
+ ## Sampled SDF grids
560
554
 
561
555
  The original skeleton API is unchanged. Additional generated WASM exports are:
562
556
 
@@ -628,9 +622,9 @@ Ambiguous topology and unsafe sharp fits trigger local conservative patches. Sha
628
622
  face connectors make the transition conforming, without unmatched edges or T-junctions.
629
623
  These guards detect risky local configurations, not every possible geometric
630
624
  self-intersection. Runtime validation checks oriented edge incidence; the test corpus
631
- also checks vertex links and proper nonadjacent triangle crossings. See session 8 in
632
- `BENCH.md` for the remaining union-junction accuracy limit.
633
- The explicit `conservative=true` path retains the session-2 minmod gradients and
625
+ also checks vertex links and proper nonadjacent triangle crossings. Union junctions
626
+ remain less accurate (about 0.4 voxel).
627
+ The explicit `conservative=true` path retains the original minmod gradients and
634
628
  cell-local fans byte-for-byte. Signed negative zero at iso zero retains inside sign.
635
629
  Unclamped QEF fits are accepted only when they stay in their cells; otherwise the
636
630
  caller gets a clear enable-clamping error. The construction follows the uniform
@@ -673,5 +667,4 @@ existing `remesh` node and its `remesh_voxel` alias retain their old behavior.
673
667
  Run `node test/sdfgrid.ts` for Node integration, `node bench/sdfgrid.ts` for the 256³
674
668
  box benchmark, and inspect `examples/renders/voxel_remesh.png` (sharp left, smooth
675
669
  middle, dilate/erode/blur right). Existing goldens and render hashes are checked
676
- separately from the new example. Benchmarks and platform verification limits are in
677
- [BENCH.md](https://github.com/topotopo-dev/topotopo/blob/main/kernels/BENCH.md).
670
+ separately from the new example.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "topotopo",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "An open-source procedural geometry engine: node graphs in JSON, cooked headless and deterministic, exported to Unreal, Blender and Houdini. Built for LLM agents through MCP, and for people through the CLI.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -38,7 +38,7 @@
38
38
  "mcp": "node src/mcp/server.ts",
39
39
  "preview": "node scripts/preview.ts --examples",
40
40
  "cook": "node src/cli.ts",
41
- "test": "node test/smoke.ts && node test/golden.ts && node test/property.ts && node test/fuzz.ts && node test/docs.ts && node test/portability.ts && node test/examples.ts && node scripts/gen-notice.ts --check && node test/io.ts && node test/import.ts && node test/interop.ts && node test/mcp.ts && node test/engine.ts && node test/viewer.ts && node test/viewer-logic.ts && node test/topology.ts && node test/deform.ts && node test/cloth.ts && node test/arrays.ts && node test/bugs.ts && node test/uv.ts && node test/polyedit.ts && node test/bevel.ts && node test/measure.ts && node test/render.ts && node test/packed.ts && node test/heightfield.ts && node test/remesh.ts && node test/pcg.ts && node test/scatterkernel.ts && node test/splines.ts && node test/shelf.ts && node test/textures.ts && node test/pool.ts && node test/kernelsloader.ts && node test/kernels.ts && node test/sdfgrid.ts && node test/remeshquad.ts && node test/erosionkernel.ts && node test/erosionsimd.ts && node test/particles.ts && node test/rbd.ts && node test/limits.ts",
41
+ "test": "node test/smoke.ts && node test/golden.ts && node test/property.ts && node test/fuzz.ts && node test/docs.ts && node test/portability.ts && node test/examples.ts && node scripts/gen-notice.ts --check && node test/io.ts && node test/import.ts && node test/interop.ts && node test/mcp.ts && node test/engine.ts && node test/viewer.ts && node test/viewer-logic.ts && node test/topology.ts && node test/deform.ts && node test/cloth.ts && node test/arrays.ts && node test/bugs.ts && node test/uv.ts && node test/polyedit.ts && node test/bevel.ts && node test/measure.ts && node test/render.ts && node test/packed.ts && node test/heightfield.ts && node test/remesh.ts && node test/pcg.ts && node test/scatterkernel.ts && node test/splines.ts && node test/shelf.ts && node test/textures.ts && node test/imageops.ts && node test/pool.ts && node test/kernelsloader.ts && node test/kernels.ts && node test/sdfgrid.ts && node test/remeshquad.ts && node test/erosionkernel.ts && node test/erosionsimd.ts && node test/particles.ts && node test/rbd.ts && node test/limits.ts && node test/viewer-outputs.ts && node test/library.ts && node test/gallery.ts && node test/tangents.ts && node test/pbr.ts && node test/sockets.ts && node test/uvreport.ts && node test/solidify.ts",
42
42
  "test:limits": "node test/limits.ts",
43
43
  "kernels:build": "node scripts/kernels-build.ts",
44
44
  "test:kernels": "node test/scatterkernel.ts && node test/kernelsloader.ts && node test/kernels.ts && node test/sdfgrid.ts && node test/remeshquad.ts && node test/erosionkernel.ts && node test/erosionsimd.ts",
@@ -48,13 +48,18 @@
48
48
  "test:pool": "node test/pool.ts --golden",
49
49
  "test:particles": "node test/particles.ts",
50
50
  "test:splines": "node test/splines.ts",
51
- "test:uv": "node test/uv.ts",
51
+ "test:uv": "node test/uv.ts && node test/uvreport.ts",
52
+ "test:tangents": "node test/tangents.ts",
53
+ "test:sockets": "node test/sockets.ts",
54
+ "test:solidify": "node test/solidify.ts",
52
55
  "test:render": "node test/render.ts",
56
+ "test:pbr": "node test/pbr.ts",
53
57
  "test:remesh": "node test/remesh.ts",
54
58
  "test:pcg": "node test/pcg.ts",
55
59
  "test:cloth": "node test/cloth.ts",
56
60
  "test:shelf": "node test/shelf.ts",
57
61
  "test:textures": "node test/textures.ts",
62
+ "test:imageops": "node test/imageops.ts",
58
63
  "test:smoke": "node test/smoke.ts",
59
64
  "test:golden": "node test/golden.ts",
60
65
  "test:update": "node test/golden.ts --update",
@@ -63,7 +68,8 @@
63
68
  "test:portability": "node test/portability.ts",
64
69
  "test:examples": "node test/examples.ts",
65
70
  "test:interop": "node test/interop.ts",
66
- "test:viewer": "node test/viewer.ts && node test/viewer-logic.ts",
71
+ "test:gallery": "node test/library.ts && node test/gallery.ts",
72
+ "test:viewer": "node test/viewer.ts && node test/viewer-logic.ts && node test/viewer-outputs.ts",
67
73
  "showcase": "node test/showcase.ts",
68
74
  "export:demo": "node scripts/export-demo.ts",
69
75
  "demo:footage": "node scripts/demo-footage.ts",
@@ -99,6 +105,7 @@
99
105
  "@modelcontextprotocol/sdk": "^1.32.0",
100
106
  "d3-delaunay": "^6.0.4",
101
107
  "earcut": "^3.2.4",
108
+ "fflate": "0.8.3",
102
109
  "manifold-3d": "^3.5.4",
103
110
  "meshoptimizer": "^1.3.0",
104
111
  "opentype.js": "^2.0.0",