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
@@ -1,184 +1,67 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="utf-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1">
6
- <title>TopoTopo Preview</title>
7
- <style>
8
- :root { --bg: #1b1d21; --panel: #23262b; --line: #34383f; --text: #d9dde3; --dim: #8b929c; --accent: #f0a23b; --err: #ff6b6b; }
9
- * { box-sizing: border-box; }
10
- html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 13px/1.4 system-ui, -apple-system, Segoe UI, sans-serif; overflow: hidden; }
11
- #app { display: flex; height: 100%; }
12
- #side { width: 260px; min-width: 200px; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
13
- #side header { padding: 12px; border-bottom: 1px solid var(--line); }
14
- #side h1 { font-size: 14px; margin: 0 0 8px; letter-spacing: .04em; }
15
- select, button { background: #2d3137; color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; font: inherit; }
16
- select { width: 100%; }
17
- #nodes { overflow: auto; flex: 1; padding: 6px; }
18
- .node { padding: 6px 8px; border-radius: 6px; cursor: pointer; display: flex; justify-content: space-between; gap: 6px; }
19
- .node:hover { background: #2c3036; }
20
- .node.sel { background: #3a3f47; }
21
- .node .t { color: var(--dim); font-size: 11px; }
22
- .node.out .n::before { content: '● '; color: var(--accent); }
23
- .node.err .n { color: var(--err); }
24
- #main { flex: 1; position: relative; }
25
- canvas { display: block; }
26
- #bar { position: absolute; top: 10px; left: 10px; display: flex; gap: 6px; }
27
- #info { position: absolute; bottom: 10px; left: 10px; right: 10px; white-space: pre-wrap; font: 12px/1.35 ui-monospace, Consolas, monospace; color: var(--dim); pointer-events: none; text-shadow: 0 1px 2px #000; }
28
- #err { position: absolute; top: 50px; left: 10px; right: 10px; color: var(--err); white-space: pre-wrap; font: 12px ui-monospace, Consolas, monospace; }
29
- #status { font-size: 11px; color: var(--dim); margin-top: 6px; }
30
- button.on { border-color: var(--accent); color: var(--accent); }
31
- </style>
32
- <script type="importmap">{ "imports": { "three": "/vendor/three/build/three.module.js", "three/addons/": "/vendor/three/examples/jsm/" } }</script>
33
- </head>
34
- <body>
35
- <div id="app">
36
- <aside id="side">
37
- <header>
38
- <h1>TOPOTOPO · PREVIEW</h1>
39
- <select id="graph"></select>
40
- <div id="status">connecting…</div>
41
- </header>
42
- <div id="nodes"></div>
43
- </aside>
44
- <main id="main">
45
- <div id="bar">
46
- <button id="follow" class="on" title="show the graph output; otherwise the selected node">follow output</button>
47
- <button id="wire">wireframe</button>
48
- <button id="frame">frame</button>
49
- </div>
50
- <div id="err"></div>
51
- <div id="info"></div>
52
- </main>
53
- </div>
54
- <script type="module">
55
- import * as THREE from 'three';
56
- import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
57
- import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
58
-
59
- const $ = (id) => document.getElementById(id);
60
- const main = $('main');
61
- const renderer = new THREE.WebGLRenderer({ antialias: true });
62
- renderer.setPixelRatio(devicePixelRatio);
63
- main.prepend(renderer.domElement);
64
- const scene = new THREE.Scene();
65
- scene.background = new THREE.Color(0x2a2d33);
66
- const camera = new THREE.PerspectiveCamera(40, 1, 0.01, 5000);
67
- camera.position.set(4, 3, 5);
68
- const controls = new OrbitControls(camera, renderer.domElement);
69
- controls.enableDamping = true;
70
- scene.add(new THREE.HemisphereLight(0xdfe6f0, 0x3b342c, 1.6));
71
- const key = new THREE.DirectionalLight(0xffffff, 2.2); key.position.set(-3, 6, 4); scene.add(key);
72
- const fill = new THREE.DirectionalLight(0xbcd0ff, 0.6); fill.position.set(5, 2, -3); scene.add(fill);
73
- let grid = new THREE.GridHelper(10, 10, 0x666a72, 0x41454c); scene.add(grid);
74
- const axes = new THREE.AxesHelper(0.5); scene.add(axes);
75
-
76
- let state = { graphs: [], graph: null, node: null, follow: true, wire: false, framed: false };
77
- let current = null;
78
- const loader = new GLTFLoader();
79
-
80
- function resize() {
81
- const w = main.clientWidth, h = main.clientHeight;
82
- renderer.setSize(w, h); camera.aspect = w / h; camera.updateProjectionMatrix();
83
- }
84
- addEventListener('resize', resize); resize();
85
- (function loop() { requestAnimationFrame(loop); controls.update(); renderer.render(scene, camera); })();
86
-
87
- function frame(obj) {
88
- const box = new THREE.Box3().setFromObject(obj);
89
- if (box.isEmpty()) return;
90
- const size = box.getSize(new THREE.Vector3()), c = box.getCenter(new THREE.Vector3());
91
- const r = Math.max(size.length() / 2, 1e-3);
92
- const dir = camera.position.clone().sub(controls.target).normalize();
93
- if (!Number.isFinite(dir.x) || dir.length() < 0.5) dir.set(0.6, 0.45, 0.7).normalize();
94
- camera.position.copy(c).addScaledVector(dir, r / Math.sin(THREE.MathUtils.degToRad(camera.fov / 2)) * 1.1);
95
- camera.near = r / 100; camera.far = r * 100; camera.updateProjectionMatrix();
96
- controls.target.copy(c);
97
- scene.remove(grid);
98
- const step = Math.pow(10, Math.floor(Math.log10(r)));
99
- const ext = Math.ceil(r * 3 / step) * step;
100
- grid = new THREE.GridHelper(ext * 2, Math.round(ext * 2 / step), 0x666a72, 0x41454c);
101
- grid.position.set(Math.round(c.x / step) * step, 0, Math.round(c.z / step) * step);
102
- scene.add(grid);
103
- }
104
-
105
- function applyWire(obj) {
106
- obj.traverse((o) => { if (o.isMesh) { o.material.wireframe = state.wire; o.material.side = THREE.DoubleSide; } });
107
- }
108
-
109
- async function loadGeo() {
110
- if (!state.graph) return;
111
- const g = state.graphs.find((x) => x.name === state.graph);
112
- if (!state.follow && !g?.nodes.some((n) => n.name === state.node)) { state.follow = true; state.node = null; $('follow').classList.add('on'); }
113
- const node = state.follow ? '' : state.node ?? '';
114
- const q = `graph=${encodeURIComponent(state.graph)}&node=${encodeURIComponent(node)}`;
115
- $('err').textContent = '';
116
- const res = await fetch('/api/geo?' + q);
117
- if (!res.ok) { const j = await res.json().catch(() => ({})); $('err').textContent = j.error ?? res.statusText; return; }
118
- const buf = await res.arrayBuffer();
119
- loader.parse(buf, '', (gltf) => {
120
- if (current) { scene.remove(current); current.traverse((o) => { o.geometry?.dispose(); o.material?.dispose?.(); }); }
121
- current = gltf.scene;
122
- current.traverse((o) => {
123
- if (o.isPoints) o.material.size = 4, o.material.sizeAttenuation = false;
124
- if (o.isLineSegments) o.material.color?.set(0x4aa3ff);
125
- });
126
- applyWire(current);
127
- scene.add(current);
128
- if (!state.framed) { frame(current); state.framed = true; }
129
- }, (e) => { $('err').textContent = String(e); });
130
- const info = await (await fetch('/api/info?' + q)).json().catch(() => null);
131
- $('info').textContent = info?.summary ? `${state.graph}/${info.target} (${info.ms.toFixed(0)} ms)\n${info.summary}` : '';
132
- }
133
-
134
- function renderNodes() {
135
- const g = state.graphs.find((x) => x.name === state.graph);
136
- const el = $('nodes');
137
- el.innerHTML = '';
138
- if (!g) return;
139
- for (const n of g.nodes) {
140
- const d = document.createElement('div');
141
- d.className = 'node' + (n.name === g.output ? ' out' : '') + (n.error ? ' err' : '') + (!state.follow && n.name === state.node ? ' sel' : '');
142
- d.title = n.error ?? `${n.type}${n.in?.length ? ' ← ' + n.in.filter(Boolean).join(', ') : ''}`;
143
- d.innerHTML = `<span class="n"></span><span class="t"></span>`;
144
- d.querySelector('.n').textContent = n.name;
145
- d.querySelector('.t').textContent = n.type + (n.ms != null ? ` · ${n.ms.toFixed(0)}ms` : '');
146
- d.onclick = () => { state.follow = false; state.node = n.name; $('follow').classList.remove('on'); renderNodes(); loadGeo(); };
147
- el.appendChild(d);
148
- }
149
- }
150
-
151
- async function refreshGraphs() {
152
- state.graphs = await (await fetch('/api/graphs')).json();
153
- const sel = $('graph');
154
- const prev = state.graph;
155
- sel.innerHTML = state.graphs.map((g) => `<option>${g.name}</option>`).join('');
156
- if (!state.graphs.length) { $('status').textContent = 'no graphs yet — build one via MCP'; return; }
157
- state.graph = state.graphs.some((g) => g.name === prev) ? prev : state.graphs[0].name;
158
- sel.value = state.graph;
159
- renderNodes();
160
- }
161
-
162
- $('graph').onchange = (e) => {
163
- state.graph = e.target.value; state.framed = false;
164
- state.follow = true; state.node = null; $('follow').classList.add('on');
165
- renderNodes(); loadGeo();
166
- };
167
- $('follow').onclick = () => { state.follow = true; $('follow').classList.add('on'); renderNodes(); loadGeo(); };
168
- $('wire').onclick = () => { state.wire = !state.wire; $('wire').classList.toggle('on', state.wire); if (current) applyWire(current); };
169
- $('frame').onclick = () => current && frame(current);
170
-
171
- const es = new EventSource('/api/events');
172
- es.onopen = () => { $('status').textContent = 'live — updates on every build/edit'; };
173
- es.onerror = () => { $('status').textContent = 'disconnected (server stopped?)'; };
174
- es.onmessage = async (m) => {
175
- const ev = JSON.parse(m.data);
176
- if (!state.graph) state.graph = ev.graph;
177
- await refreshGraphs();
178
- if (ev.graph === state.graph) loadGeo();
179
- };
180
- await refreshGraphs();
181
- loadGeo();
182
- </script>
183
- </body>
184
- </html>
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>TopoTopo Viewer</title>
7
+ <link rel="icon" href="data:,">
8
+ <!-- the viewer page (docs/design/viewer.md): ES modules from /app/, three.js from /vendor/three/, no build step -->
9
+ <link rel="stylesheet" href="/app/style.css">
10
+ <link rel="stylesheet" href="/app/outputs.css">
11
+ <script type="importmap">{ "imports": { "three": "/vendor/three/build/three.module.js", "three/addons/": "/vendor/three/examples/jsm/" } }</script>
12
+ <script type="module" src="/app/main.js"></script>
13
+ </head>
14
+ <body>
15
+ <div id="app">
16
+ <header id="top">
17
+ <label class="tb" title="the graph shown">graph <select id="graph"></select></label>
18
+ <label class="tb" title="the current view's camera; see ? for active key bindings">view <select id="view-cam"></select></label>
19
+ <label class="tb" title="the current view's shading; see ? for active key bindings">shading <select id="view-shading"></select></label>
20
+ <span class="tb readout" id="step" title="the current view's grid step"></span>
21
+ <button class="tb" id="quad" title="single / quad view">quad</button>
22
+ <span class="grow"></span>
23
+ <button class="tb" id="scene-view" title="back to the whole scene after looking at one output">Scene</button>
24
+ <span class="tb mode" id="mode"></span>
25
+ <label class="tb" title="keyboard and mouse bindings, remembered in this browser">keymap <select id="preset"></select></label>
26
+ <button class="tb" id="help" title="the keymap (?)">?</button>
27
+ </header>
28
+ <aside id="outliner" class="panel">
29
+ <div class="phead tabs" role="tablist" aria-label="Scene, outputs and inputs">
30
+ <button role="tab" id="tab-scene" data-tab="scene" aria-controls="tree">Scene</button>
31
+ <button role="tab" id="tab-outputs" data-tab="outputs" aria-controls="outputs-pane">Outputs <span class="count"></span></button>
32
+ <button role="tab" id="tab-inputs" data-tab="inputs" aria-controls="inputs-pane">Inputs <span class="count"></span></button>
33
+ <button id="thumb-size" title="Cycle thumbnail size" aria-label="Cycle thumbnail size">56 px</button>
34
+ </div>
35
+ <div class="pscroll tabpane" id="tree" data-pane="scene" role="tabpanel" aria-labelledby="tab-scene"></div>
36
+ <div class="pscroll tabpane" id="outputs-pane" data-pane="outputs" role="tabpanel" aria-labelledby="tab-outputs"><div id="outputs"></div></div>
37
+ <div class="pscroll tabpane" id="inputs-pane" data-pane="inputs" role="tabpanel" aria-labelledby="tab-inputs">
38
+ <div class="inputs-bar"><button class="primary" id="add-input">Add input…</button><span class="dim" id="inputs-where"></span></div>
39
+ <input id="input-file" type="file" multiple hidden accept=".glb,.gltf,.obj,.stl,.ply,.geo,.bgeo,.blend,.csv,.json,.png,.jpg,.jpeg,.webp">
40
+ <div id="inputs-list"></div>
41
+ </div>
42
+ <div class="grip v" data-grip="left" title="drag to resize"></div>
43
+ </aside>
44
+ <main id="viewport">
45
+ <canvas id="gl"></canvas>
46
+ <div id="views"></div>
47
+ <div id="boxsel" hidden></div>
48
+ </main>
49
+ <aside id="props" class="panel">
50
+ <div class="grip v" data-grip="right" title="drag to resize"></div>
51
+ <div class="phead">Properties</div>
52
+ <div id="output-details" hidden></div>
53
+ <div class="pscroll" id="props-body"></div>
54
+ <div class="grip h" data-grip="split" title="drag to resize"></div>
55
+ <div class="phead">Controls <span class="count" id="controls-count"></span></div>
56
+ <div class="pscroll" id="controls"></div>
57
+ </aside>
58
+ <footer id="status">
59
+ <span id="msg"></span>
60
+ <span id="ask" hidden><span id="ask-text"></span><button id="ask-yes">Yes</button><button id="ask-no">No</button></span>
61
+ <span class="grow"></span>
62
+ <span id="cook"></span>
63
+ </footer>
64
+ </div>
65
+ <div id="drop">drop files to add them to <span id="drop-where">inputs/</span><br><small>they show in the Inputs tab and as reference layers in the view</small></div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,54 @@
1
+ import type http from 'node:http';
2
+ import type { Workspace } from '../workspace.ts';
3
+ export interface OutputEntry {
4
+ origin?: 'published' | 'saved';
5
+ id: string;
6
+ label: string;
7
+ graph?: string;
8
+ node?: string;
9
+ parent?: string;
10
+ kind: 'geometry' | 'image' | 'file' | 'bundle';
11
+ status: 'loading' | 'ready' | 'error';
12
+ revision: string;
13
+ error?: string;
14
+ summary?: string;
15
+ width?: number;
16
+ height?: number;
17
+ layers?: string[];
18
+ layer?: string;
19
+ image?: string;
20
+ generated?: boolean;
21
+ /** a published output's card has an Export button: `output` is its id (null = the graph's default output) */
22
+ exportable?: boolean;
23
+ output?: string | null;
24
+ /** where it exports (posix path inside exports/, the export tool's options), or null before a first export sets it */
25
+ target?: {
26
+ format: string;
27
+ path: string;
28
+ options: Record<string, unknown>;
29
+ } | null;
30
+ /** its last export to that target: newest file time (ms), total bytes, file count */
31
+ saved?: {
32
+ at: number;
33
+ size: number;
34
+ files: number;
35
+ };
36
+ files?: {
37
+ id: string;
38
+ name: string;
39
+ size: number;
40
+ }[];
41
+ }
42
+ /** Predictable ZIP bytes, retaining the bundle directory structure. */
43
+ export declare function outputZip(files: {
44
+ name: string;
45
+ bytes: Uint8Array;
46
+ }[]): Uint8Array;
47
+ export interface OutputsOptions {
48
+ /** after a target is set in a graph (topotopo view writes it back into the graph file) */
49
+ persistGraph?: (graph: string) => void;
50
+ }
51
+ export declare function createOutputs(ws: Workspace, changed: () => void, opts?: OutputsOptions): {
52
+ close(): void;
53
+ handle(req: http.IncomingMessage, res: http.ServerResponse, u: URL, readJSON: (r: http.IncomingMessage) => Promise<any>): Promise<boolean>;
54
+ };