topotopo 0.1.0 → 0.3.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 (80) hide show
  1. package/README.md +61 -12
  2. package/dist/cli.js +161 -23
  3. package/dist/graph/engine.js +18 -1
  4. package/dist/graph/params.d.ts +7 -1
  5. package/dist/graph/params.js +21 -8
  6. package/dist/graph/types.d.ts +28 -2
  7. package/dist/host/artifacts.d.ts +21 -0
  8. package/dist/host/artifacts.js +58 -0
  9. package/dist/host/export-targets.d.ts +33 -0
  10. package/dist/host/export-targets.js +84 -0
  11. package/dist/host/export_scene.py +200 -0
  12. package/dist/host/node.d.ts +8 -0
  13. package/dist/host/node.js +114 -0
  14. package/dist/host/types.d.ts +5 -0
  15. package/dist/inspect.js +5 -2
  16. package/dist/io/common.d.ts +6 -0
  17. package/dist/io/export.js +7 -4
  18. package/dist/io/gltf.d.ts +1 -1
  19. package/dist/io/gltf.js +167 -32
  20. package/dist/io/heightmap.d.ts +1 -1
  21. package/dist/io/import.d.ts +2 -2
  22. package/dist/io/import.js +10 -3
  23. package/dist/io/png-decode.d.ts +5 -2
  24. package/dist/io/png-decode.js +10 -3
  25. package/dist/io/targets.d.ts +31 -0
  26. package/dist/io/targets.js +75 -0
  27. package/dist/io/textures.d.ts +31 -2
  28. package/dist/io/textures.js +66 -18
  29. package/dist/io/unreal.js +22 -5
  30. package/dist/mcp/docs.d.ts +9 -2
  31. package/dist/mcp/docs.js +126 -2
  32. package/dist/mcp/inputs.d.ts +28 -0
  33. package/dist/mcp/inputs.js +377 -0
  34. package/dist/mcp/server.js +4 -1
  35. package/dist/mcp/tools.d.ts +1 -1
  36. package/dist/mcp/tools.js +118 -51
  37. package/dist/nodes/code.js +34 -6
  38. package/dist/nodes/copy.js +14 -4
  39. package/dist/nodes/flow.js +136 -35
  40. package/dist/nodes/heightfield.js +67 -11
  41. package/dist/nodes/texture.d.ts +1 -1
  42. package/dist/nodes/texture.js +61 -5
  43. package/dist/render/options.js +2 -1
  44. package/dist/render/raster.d.ts +2 -0
  45. package/dist/render/raster.js +3 -3
  46. package/dist/render/texview.d.ts +9 -1
  47. package/dist/render/texview.js +43 -2
  48. package/dist/viewer/app/api.js +64 -0
  49. package/dist/viewer/app/camera.js +250 -0
  50. package/dist/viewer/app/export-popover.js +68 -0
  51. package/dist/viewer/app/grid.js +217 -0
  52. package/dist/viewer/app/guides.js +402 -0
  53. package/dist/viewer/app/image-view.js +114 -0
  54. package/dist/viewer/app/keymap.js +199 -0
  55. package/dist/viewer/app/layers.js +244 -0
  56. package/dist/viewer/app/main.js +646 -0
  57. package/dist/viewer/app/markers.js +206 -0
  58. package/dist/viewer/app/mesh.js +172 -0
  59. package/dist/viewer/app/outliner.js +225 -0
  60. package/dist/viewer/app/outputs.css +73 -0
  61. package/dist/viewer/app/outputs.js +240 -0
  62. package/dist/viewer/app/props.js +432 -0
  63. package/dist/viewer/app/scene.js +529 -0
  64. package/dist/viewer/app/select.js +153 -0
  65. package/dist/viewer/app/selection.js +79 -0
  66. package/dist/viewer/app/status.js +20 -0
  67. package/dist/viewer/app/style.css +173 -0
  68. package/dist/viewer/app/undo.js +49 -0
  69. package/dist/viewer/app/units.js +51 -0
  70. package/dist/viewer/app/vars.js +64 -0
  71. package/dist/viewer/index.html +67 -184
  72. package/dist/viewer/outputs.d.ts +54 -0
  73. package/dist/viewer/outputs.js +436 -0
  74. package/dist/viewer/server.d.ts +47 -1
  75. package/dist/viewer/server.js +480 -17
  76. package/dist/workspace.d.ts +60 -4
  77. package/dist/workspace.js +131 -5
  78. package/package.json +9 -3
  79. package/shelf/brick_wall.json +1 -1
  80. package/shelf/wall_segment.json +2 -2
package/dist/workspace.js CHANGED
@@ -1,11 +1,37 @@
1
- // A workspace: named graphs (persisted as JSON files), saved assets, and the engine
1
+ // A workspace: named graphs (persisted as JSON files), saved assets, the human's input files, and the engine
2
2
  // that cooks them. Shared by the MCP server, the live viewer and the CLI.
3
+ // <dir>/graphs/<name>.json graphs <dir>/assets/<name>.json saved assets
4
+ // <dir>/inputs/… files people drop in (meshes, guide curves, PNG masks), read with file nodes; or a
5
+ // folder given to the constructor (`topotopo view`: inputs/ beside the graph file)
6
+ // <dir>/exports/… export output
3
7
  import fs from 'node:fs';
4
8
  import path from 'node:path';
5
9
  import { Engine, wiringOf } from './graph/engine.js';
6
10
  import { didYouMean, renameExprRefs } from './graph/params.js';
7
11
  import { migrateGraph } from './graph/migrate.js';
8
12
  const NAME_RE = /^[A-Za-z_][\w.-]*$/;
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', 'jpg', 'jpeg', 'webp']);
15
+ /** Lower-case extension of a file name without the dot; ".points.json" is one extension, dot-files have none. */
16
+ export function inputExt(file) {
17
+ const b = file.toLowerCase().replace(/^.*[\\/]/, '');
18
+ if (b.endsWith('.points.json') && b.length > '.points.json'.length)
19
+ return 'points.json';
20
+ const i = b.lastIndexOf('.');
21
+ return i > 0 ? b.slice(i + 1) : '';
22
+ }
23
+ export function inputKind(ext) {
24
+ return GEOMETRY_EXTS.has(ext) ? 'geometry' : IMAGE_EXTS.has(ext) ? 'image' : 'other';
25
+ }
26
+ /** Thrown by Workspace.edit when the edited graph does not validate; the stored graph is unchanged. */
27
+ export class EditRejected extends Error {
28
+ errors;
29
+ constructor(errors) {
30
+ super(`✗ edits rejected (graph unchanged) — ${errors.length} error(s):\n` + errors.map((e) => ` [${e.node}] ${e.message}`).join('\n'));
31
+ this.name = 'EditRejected';
32
+ this.errors = errors;
33
+ }
34
+ }
9
35
  export class Workspace {
10
36
  dir;
11
37
  engine;
@@ -13,16 +39,28 @@ export class Workspace {
13
39
  versions = new Map();
14
40
  lastReport = new Map();
15
41
  listeners = new Set();
16
- constructor(dir, engine) {
42
+ /** the inputs folder given to the constructor (WorkspaceOptions.inputs), if any */
43
+ inputsAt;
44
+ exportsAt;
45
+ constructor(dir, engine, opts = {}) {
17
46
  this.dir = path.resolve(dir);
18
47
  this.engine = engine;
48
+ this.inputsAt = opts.inputs === undefined ? undefined : path.resolve(opts.inputs);
49
+ this.exportsAt = opts.exports === undefined ? undefined : path.resolve(opts.exports);
19
50
  engine.graphResolver = (n) => this.graphs.get(n);
20
51
  }
21
52
  get graphDir() { return path.join(this.dir, 'graphs'); }
22
53
  get assetDir() { return path.join(this.dir, 'assets'); }
23
- get exportDir() { return path.join(this.dir, 'exports'); }
54
+ get exportDir() { return this.exportsAt ?? path.join(this.dir, 'exports'); }
55
+ /**
56
+ * files people drop in: meshes, guide curves and points, PNG masks and heightmaps (read as "inputs/<path>");
57
+ * <dir>/inputs unless the constructor was given another folder
58
+ */
59
+ get inputDir() { return this.inputsAt ?? path.join(this.dir, 'inputs'); }
24
60
  load() {
25
- for (const d of [this.dir, this.graphDir, this.assetDir, this.exportDir])
61
+ // the workspace's own inputs/ is made at once (people open it to drop files in); a folder given to the constructor
62
+ // is made by the first file written into it
63
+ for (const d of [this.dir, this.graphDir, this.assetDir, this.exportDir, ...(this.inputsAt ? [] : [this.inputDir])])
26
64
  fs.mkdirSync(d, { recursive: true });
27
65
  const assetErrors = [];
28
66
  for (const f of fs.readdirSync(this.assetDir).filter((f) => f.endsWith('.json'))) {
@@ -86,6 +124,41 @@ export class Workspace {
86
124
  this.graphs.delete(name);
87
125
  this.persist(name);
88
126
  }
127
+ /** Every file under inputs/, recursively: posix paths relative to it, sorted. Dot-files and dot-folders are skipped. */
128
+ listInputs() {
129
+ const out = [];
130
+ const walk = (dir, rel, depth) => {
131
+ let entries;
132
+ try {
133
+ entries = fs.readdirSync(dir, { withFileTypes: true });
134
+ }
135
+ catch {
136
+ return;
137
+ }
138
+ for (const e of entries) {
139
+ if (e.name.startsWith('.'))
140
+ continue;
141
+ const abs = path.join(dir, e.name), r = rel ? `${rel}/${e.name}` : e.name;
142
+ let st;
143
+ try {
144
+ st = fs.statSync(abs);
145
+ }
146
+ catch {
147
+ continue;
148
+ } // a broken link
149
+ if (st.isDirectory()) {
150
+ if (depth < 32)
151
+ walk(abs, r, depth + 1);
152
+ } // the depth cap stops link cycles
153
+ else if (st.isFile()) {
154
+ const ext = inputExt(e.name);
155
+ out.push({ path: r, kind: inputKind(ext), ext, size: st.size, mtime: Math.round(st.mtimeMs) });
156
+ }
157
+ }
158
+ };
159
+ walk(this.inputDir, '', 0);
160
+ return out.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
161
+ }
89
162
  /** Merge nodes/vars/output of `patch` into an existing graph (upsert). */
90
163
  mergeGraph(name, patch) {
91
164
  patch = migrateGraph(patch);
@@ -97,6 +170,10 @@ export class Workspace {
97
170
  base.params = { ...(base.params ?? {}), ...patch.params };
98
171
  if (patch.output)
99
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;
100
177
  if (patch.description)
101
178
  base.description = patch.description;
102
179
  return base;
@@ -182,6 +259,9 @@ export class Workspace {
182
259
  delete g.nodes[n];
183
260
  if (g.output === n)
184
261
  delete g.output;
262
+ for (const [id, out] of Object.entries(g.outputs ?? {}))
263
+ if (out.node === n)
264
+ delete g.outputs[id];
185
265
  break;
186
266
  }
187
267
  case 'connect': {
@@ -211,6 +291,9 @@ export class Workspace {
211
291
  setRef(r.node, r.idx, op.to);
212
292
  if (g.output === n)
213
293
  g.output = op.to;
294
+ for (const out of Object.values(g.outputs ?? {}))
295
+ if (out.node === n)
296
+ out.node = op.to;
214
297
  // expression references: npoints("old"), ch("old/param") …
215
298
  const touched = [];
216
299
  for (const [k, spec] of Object.entries(g.nodes)) {
@@ -241,6 +324,28 @@ export class Workspace {
241
324
  case 'bypass':
242
325
  g.nodes[need(op.node, where)].bypass = op.value ?? true;
243
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
+ }
244
349
  case 'insert': {
245
350
  const after = need(op.after, `${where} after`);
246
351
  if (!op.node || !NAME_RE.test(op.node) || g.nodes[op.node])
@@ -256,11 +361,32 @@ export class Workspace {
256
361
  notes.push(`inserted "${op.node}" after "${after}"${consumers.length ? `; now feeds ${consumers.map((c) => c.node).join(', ')}` : ''}`);
257
362
  break;
258
363
  }
259
- 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`);
260
365
  }
261
366
  }
262
367
  return { graph: g, notes };
263
368
  }
369
+ /**
370
+ * The one path for an edit, whoever makes it (the MCP edit tool, the viewer's controls): apply the ops, validate
371
+ * (an invalid result throws EditRejected listing the per-node errors and stores nothing), store, cook at `frame`,
372
+ * then notify the listeners. They hear after the cook so that what they read (lastReport, cached geometry) is the
373
+ * new version's; a cook that throws still notifies, since the graph was stored.
374
+ */
375
+ async edit(name, ops, opts = {}) {
376
+ const { graph, notes } = this.applyEdits(name, ops);
377
+ const v = this.engine.validate(graph);
378
+ if (v.errors.length)
379
+ throw new EditRejected(v.errors);
380
+ this.setGraph(name, graph);
381
+ let report;
382
+ try {
383
+ report = await this.cook(name, undefined, opts.frame);
384
+ }
385
+ finally {
386
+ this.bump(name);
387
+ }
388
+ return { graph: this.getGraph(name), notes, report };
389
+ }
264
390
  async cook(name, target, frame) {
265
391
  const g = this.getGraph(name);
266
392
  const r = await this.engine.cook(g, { target, frame });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "topotopo",
3
- "version": "0.1.0",
4
- "description": "A procedural geometry engine: Houdini-style node graphs, headless, deterministic, exports to Unreal, Blender and Houdini",
3
+ "version": "0.3.0",
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",
7
7
  "exports": {
@@ -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/interop.ts && node test/mcp.ts && node test/engine.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/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",
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",
@@ -63,6 +63,7 @@
63
63
  "test:portability": "node test/portability.ts",
64
64
  "test:examples": "node test/examples.ts",
65
65
  "test:interop": "node test/interop.ts",
66
+ "test:viewer": "node test/viewer.ts && node test/viewer-logic.ts && node test/viewer-outputs.ts",
66
67
  "showcase": "node test/showcase.ts",
67
68
  "export:demo": "node scripts/export-demo.ts",
68
69
  "demo:footage": "node scripts/demo-footage.ts",
@@ -98,6 +99,7 @@
98
99
  "@modelcontextprotocol/sdk": "^1.32.0",
99
100
  "d3-delaunay": "^6.0.4",
100
101
  "earcut": "^3.2.4",
102
+ "fflate": "0.8.3",
101
103
  "manifold-3d": "^3.5.4",
102
104
  "meshoptimizer": "^1.3.0",
103
105
  "opentype.js": "^2.0.0",
@@ -124,5 +126,9 @@
124
126
  "bugs": {
125
127
  "url": "https://github.com/topotopo-dev/topotopo/issues"
126
128
  },
129
+ "funding": {
130
+ "type": "github",
131
+ "url": "https://github.com/sponsors/faxlab"
132
+ },
127
133
  "author": "faxcorp <hello@topotopo.dev>"
128
134
  }
@@ -2,7 +2,7 @@
2
2
  "version": 1,
3
3
  "description": "Brick wall from x = 0 to x = length: individual bricks in running, stack, English or Flemish bond, cut to the wall ends and top, with random offset, yaw and tint, standing slightly proud of a recessed mortar core. One wythe deep (headers are drawn as half bricks). Pivot at the start of the wall, on the ground, centred in thickness. Pieces: brick_wall_bricks (brick), brick_wall_mortar (mortar). Every piece is a closed box.",
4
4
  "params": {
5
- "length": { "type": "float", "default": 3, "min": 0.3, "max": 12, "desc": "length along X (m)" },
5
+ "length": { "type": "float", "default": 3, "min": 0.3, "max": 40, "desc": "length along X (m)" },
6
6
  "height": { "type": "float", "default": 1.8, "min": 0.1, "max": 5, "desc": "height (m)" },
7
7
  "brick_length": {
8
8
  "type": "float",
@@ -2,10 +2,10 @@
2
2
  "version": 1,
3
3
  "description": "Straight wall from x = 0 to x = length with window (and an optional door) openings cut by a boolean, filled with the window_frame and door_frame shelf assets. The openings are spread in equal bays; the door takes the middle bay. Modular: segments placed end to end line up. Pivot at the start of the wall, on the ground, centred in thickness (+Z = outside). Pieces: wall (plaster) plus the frames' pieces. Every piece is closed (the wall is one watertight solid).",
4
4
  "params": {
5
- "length": { "type": "float", "default": 4, "min": 0.5, "max": 20, "desc": "length along X (m)" },
5
+ "length": { "type": "float", "default": 4, "min": 0.5, "max": 60, "desc": "length along X (m)" },
6
6
  "height": { "type": "float", "default": 3, "min": 1, "max": 10, "desc": "height (m)" },
7
7
  "thickness": { "type": "float", "default": 0.25, "min": 0.05, "max": 1, "desc": "thickness along Z (m)" },
8
- "windows": { "type": "int", "default": 2, "min": 0, "max": 10, "desc": "number of window openings" },
8
+ "windows": { "type": "int", "default": 2, "min": 0, "max": 24, "desc": "number of window openings" },
9
9
  "window_width": {
10
10
  "type": "float",
11
11
  "default": 1,