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/mcp/inputs.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Session, InputFile } from '../session.ts';
|
|
2
2
|
import type { ToolDef } from './tools.ts';
|
|
3
3
|
/** name prefixes that mark a guide's role (help topic "inputs") */
|
|
4
4
|
export declare const ROLES: readonly ['site', 'path', 'zone', 'volume', 'blockout'];
|
|
@@ -9,20 +9,27 @@ interface Described {
|
|
|
9
9
|
long: string;
|
|
10
10
|
failed: boolean;
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* The path a file node reads an input with: relative to the folder the host resolves paths against (the package folder,
|
|
14
|
+
* host/node.ts packageBaseDir), "inputs/<path>" when the server's folder is the package, as it mostly is.
|
|
15
|
+
*/
|
|
16
|
+
export declare function inputRef(ws: Session, rel: string): string;
|
|
12
17
|
/** inputs/ file → its description, keyed by path and invalidated by the host's file stamp (mtime + size). */
|
|
13
18
|
export declare class InputDescriber {
|
|
14
|
-
ws:
|
|
19
|
+
ws: Session;
|
|
15
20
|
private cache;
|
|
16
|
-
constructor(ws:
|
|
21
|
+
constructor(ws: Session);
|
|
17
22
|
/** Describe one file (cached while its stamp holds). */
|
|
18
23
|
describe(f: InputFile): Promise<Described>;
|
|
19
24
|
/** Whether describe() would answer from the cache. */
|
|
20
25
|
cached(f: InputFile): boolean;
|
|
21
26
|
/** Forget files that are gone. */
|
|
22
27
|
prune(keep: InputFile[]): void;
|
|
23
|
-
/** Cook the one-node graph a file node would be (never a
|
|
28
|
+
/** Cook the one-node graph a file node would be (never a graph of the package) and read the result. */
|
|
24
29
|
private geometry;
|
|
30
|
+
/** An export's sidecar (io/sidecars.ts): what it records and the file it describes, without cooking it. */
|
|
31
|
+
private metadata;
|
|
25
32
|
private image;
|
|
26
33
|
}
|
|
27
|
-
export declare function inputsTool(ws:
|
|
34
|
+
export declare function inputsTool(ws: Session): ToolDef;
|
|
28
35
|
export {};
|
package/dist/mcp/inputs.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
// The human-input layer for agents: the files people drop into <
|
|
1
|
+
// The human-input layer for agents: the files people drop into <package>/inputs (meshes, guide curves and points,
|
|
2
2
|
// PNG masks and heightmaps) and what each one holds: curves vs meshes vs points, bbox, names and roles, attributes,
|
|
3
3
|
// materials. Registered by makeTools in tools.ts; help topic "inputs" (docs.ts) explains the guide conventions.
|
|
4
4
|
import fs from 'node:fs';
|
|
5
5
|
import path from 'node:path';
|
|
6
|
-
import { inputExt, inputKind } from '../
|
|
6
|
+
import { inputExt, inputKind } from '../session.js';
|
|
7
7
|
import { decodePNG } from '../io/png-decode.js';
|
|
8
|
+
import { SIDECAR_NAMES, SIDECAR_TEXT } from '../io/sidecars.js';
|
|
8
9
|
import { imageNameOf } from '../io/textures.js';
|
|
9
10
|
import { readMaterials, MATERIAL_ATTRIB } from '../core/materials.js';
|
|
10
11
|
import { didYouMean } from '../graph/params.js';
|
|
@@ -35,6 +36,15 @@ const OTHER_HINTS = {
|
|
|
35
36
|
blend1: 'a Blender backup file (the .blend next to it is the current one)',
|
|
36
37
|
};
|
|
37
38
|
const READABLE = 'geometry: obj stl ply glb gltf geo bgeo csv json points.json, and blend with Blender installed; images: png';
|
|
39
|
+
/**
|
|
40
|
+
* The path a file node reads an input with: relative to the folder the host resolves paths against (the package folder,
|
|
41
|
+
* host/node.ts packageBaseDir), "inputs/<path>" when the server's folder is the package, as it mostly is.
|
|
42
|
+
*/
|
|
43
|
+
export function inputRef(ws, rel) {
|
|
44
|
+
const base = ws.engine.host.resolvePath('.'), dir = path.relative(base, ws.inputDir);
|
|
45
|
+
const d = !dir ? '' : dir.startsWith('..') || path.isAbsolute(dir) ? ws.inputDir : dir;
|
|
46
|
+
return [d.split(path.sep).join('/'), rel].filter(Boolean).join('/');
|
|
47
|
+
}
|
|
38
48
|
/** inputs/ file → its description, keyed by path and invalidated by the host's file stamp (mtime + size). */
|
|
39
49
|
export class InputDescriber {
|
|
40
50
|
ws;
|
|
@@ -42,12 +52,13 @@ export class InputDescriber {
|
|
|
42
52
|
constructor(ws) { this.ws = ws; }
|
|
43
53
|
/** Describe one file (cached while its stamp holds). */
|
|
44
54
|
describe(f) {
|
|
45
|
-
const rel =
|
|
55
|
+
const rel = inputRef(this.ws, f.path);
|
|
46
56
|
const stamp = this.ws.engine.host.fileStamp(rel);
|
|
47
57
|
const hit = this.cache.get(f.path);
|
|
48
58
|
if (hit && hit.stamp === stamp)
|
|
49
59
|
return hit.d;
|
|
50
|
-
const d = (f.kind === 'geometry' ? this.geometry(rel, f.ext) : f.kind === 'image' ? this.image(rel) :
|
|
60
|
+
const d = (f.kind === 'geometry' ? this.geometry(rel, f.ext) : f.kind === 'image' ? this.image(rel) : f.kind === 'metadata' && f.sidecar ? this.metadata(rel, f.sidecar)
|
|
61
|
+
: Promise.resolve(other(f.ext)))
|
|
51
62
|
.catch((e) => ({ short: `cannot read: ${e?.message ?? e}`, long: `cannot read: ${e?.message ?? e}`, failed: true }));
|
|
52
63
|
this.cache.set(f.path, { stamp, d });
|
|
53
64
|
return d;
|
|
@@ -55,7 +66,7 @@ export class InputDescriber {
|
|
|
55
66
|
/** Whether describe() would answer from the cache. */
|
|
56
67
|
cached(f) {
|
|
57
68
|
const hit = this.cache.get(f.path);
|
|
58
|
-
return !!hit && hit.stamp === this.ws.engine.host.fileStamp(
|
|
69
|
+
return !!hit && hit.stamp === this.ws.engine.host.fileStamp(inputRef(this.ws, f.path));
|
|
59
70
|
}
|
|
60
71
|
/** Forget files that are gone. */
|
|
61
72
|
prune(keep) {
|
|
@@ -64,7 +75,7 @@ export class InputDescriber {
|
|
|
64
75
|
if (!live.has(k))
|
|
65
76
|
this.cache.delete(k);
|
|
66
77
|
}
|
|
67
|
-
/** Cook the one-node graph a file node would be (never a
|
|
78
|
+
/** Cook the one-node graph a file node would be (never a graph of the package) and read the result. */
|
|
68
79
|
async geometry(rel, ext) {
|
|
69
80
|
const r = await this.ws.engine.cook({ nodes: { f: { type: 'file', params: { path: rel } } }, output: 'f' });
|
|
70
81
|
const warnings = r.warnings.map((w) => w.message);
|
|
@@ -76,6 +87,11 @@ export class InputDescriber {
|
|
|
76
87
|
const j = JSON.parse(new TextDecoder().decode(await this.ws.engine.host.readFile(rel)));
|
|
77
88
|
if (j && typeof j === 'object' && !Array.isArray(j) && j.nodes && typeof j.nodes === 'object')
|
|
78
89
|
why = '\nThis JSON is a topotopo graph, not geometry: build it (build {graph}) instead of reading it with a file node.';
|
|
90
|
+
else if (j?.format === 'topotopo-export-source' && j.source && typeof j.source === 'object') {
|
|
91
|
+
// the record an export writes next to its file (io/source.ts): say what it is instead of a cook failure
|
|
92
|
+
const what = `how ${Array.isArray(j.files) ? j.files.join(', ') : 'an export'} was made (graph "${j.source.graph}", frame ${j.source.frame})`;
|
|
93
|
+
return { short: `export source: ${what}, not geometry`, long: `an export's source manifest, not geometry: ${what}. help topic "export" (SOURCE) tells how to make it again.`, failed: false };
|
|
94
|
+
}
|
|
79
95
|
}
|
|
80
96
|
catch { /* not JSON at all: the error says so */ }
|
|
81
97
|
}
|
|
@@ -83,6 +99,27 @@ export class InputDescriber {
|
|
|
83
99
|
}
|
|
84
100
|
return geometryText(r.geo, rel, ext, warnings);
|
|
85
101
|
}
|
|
102
|
+
/** An export's sidecar (io/sidecars.ts): what it records and the file it describes, without cooking it. */
|
|
103
|
+
async metadata(rel, s) {
|
|
104
|
+
const of = s.of === null ? 'an export that is not in inputs/' : `inputs/${s.of}`;
|
|
105
|
+
if (s.role === 'source') {
|
|
106
|
+
try {
|
|
107
|
+
const j = JSON.parse(new TextDecoder().decode(await this.ws.engine.host.readFile(rel)));
|
|
108
|
+
const what = `how ${Array.isArray(j.files) ? j.files.join(', ') : 'an export'} was made (graph "${j.source?.graph}", frame ${j.source?.frame})`;
|
|
109
|
+
return { short: `export source: ${what}, not geometry`, long: `an export's source manifest, not geometry: ${what}. help topic "export" (SOURCE) tells how to make it again.`, failed: false };
|
|
110
|
+
}
|
|
111
|
+
catch { /* unreadable: said as for the other sidecars */ }
|
|
112
|
+
}
|
|
113
|
+
const read = {
|
|
114
|
+
source: 'help topic "export" (SOURCE) tells how to make it again',
|
|
115
|
+
heightmap: s.of?.endsWith('.r16') ? 'the RAW heightmap beside it is for Unreal (a file node reads PNG heightmaps)'
|
|
116
|
+
: 'read the heightmap with heightfield_from_image (height_min / height_max are in this sidecar)',
|
|
117
|
+
meshes: 'read the instance stream (.csv / .points.json) beside it; its Mesh column names these meshes',
|
|
118
|
+
landscape: 'the files it lists are in its folder (help topic "export", UNREAL LANDSCAPE BUNDLE)',
|
|
119
|
+
};
|
|
120
|
+
const what = `${SIDECAR_NAMES[s.role]} of ${of}: ${SIDECAR_TEXT[s.role]}`;
|
|
121
|
+
return { short: `${what}, not geometry`, long: `${what}. Not geometry: ${read[s.role]}.`, failed: false };
|
|
122
|
+
}
|
|
86
123
|
async image(rel) {
|
|
87
124
|
const img = decodePNG(await this.ws.engine.host.readFile(rel));
|
|
88
125
|
const ch = img.channels, names = ['grey', 'grey + alpha', 'RGB', 'RGBA'][ch - 1];
|
|
@@ -107,12 +144,12 @@ export class InputDescriber {
|
|
|
107
144
|
'read it as:',
|
|
108
145
|
` a heightmap {"type":"heightfield_from_image","params":{"path":"${rel}","size":[${w - 1},${h - 1}],"height_min":0,"height_max":20}}`,
|
|
109
146
|
' (size = the extent in metres in X and Z; height_min/max = the heights of black and white; 16-bit greys keep the detail)',
|
|
110
|
-
` a mask layer {"type":"heightfield_from_image","in":["terrain"],"params":{"path":"${rel}","layer":"mask","height_min":0,"height_max":1}}`,
|
|
111
|
-
' (
|
|
147
|
+
` a mask layer {"type":"heightfield_from_image","in":["terrain"],"params":{"path":"${rel}","layer":"mask","height_min":0,"height_max":1,"size":[${w - 1},${h - 1}]}}`,
|
|
148
|
+
' (the image lies at size/center in the world, read at each sample\'s X/Z, so tiles match; fit "field" stretches it over the heightfield instead; then heightfield_scatter, mask_layer, …)',
|
|
112
149
|
` on points {"type":"attribute_from_map","in":["pts"],"params":{"path":"${rel}","projection":"xz","size":[100,100],"name":"mask"}}`,
|
|
113
150
|
' (top view: column along +X, row 0 at min Z; then scatter density_mask, prune, copy_to_points scale_attrib)',
|
|
114
151
|
` a texture {"type":"image_file","params":{"path":"${rel}"}}`,
|
|
115
|
-
` (an image "${imageNameOf(rel)}" for the texture nodes and texture_to_material; a file node reads it
|
|
152
|
+
` (an image named after the node, e.g. a node "${imageNameOf(rel)}", for the texture nodes and texture_to_material; a file node reads it as "${imageNameOf(rel)}")`,
|
|
116
153
|
].join('\n');
|
|
117
154
|
return { short, long, failed: false };
|
|
118
155
|
}
|
|
@@ -329,7 +366,7 @@ export function inputsTool(ws) {
|
|
|
329
366
|
const describer = new InputDescriber(ws);
|
|
330
367
|
return {
|
|
331
368
|
name: 'inputs',
|
|
332
|
-
description: 'The human\'s own material: files people drop into the
|
|
369
|
+
description: 'The human\'s own material: files people drop into the package inputs/ folder (meshes, guide curves and points from Blender/Houdini/Unreal, blockouts, PNG masks and heightmaps). list: every file with kind (geometry/image/metadata/other; metadata = an export\'s sidecar such as a heightmap\'s .json or <file>.source.json), size, date and a summary (counts, curves vs meshes, bbox, object names; PNG size and bit depth). describe {path}: what a file node reads from it: polygons vs open polylines vs loose points vs packed prims, bbox in metres, attributes, groups, every name and role value, materials, warnings. Call list FIRST when building a landscape or scene: guides mark sites, paths, zones, volumes and blockouts (help topic "inputs"). Read a file with {type:"file", params:{path:"inputs/<path>"}}.',
|
|
333
370
|
inputSchema: {
|
|
334
371
|
type: 'object',
|
|
335
372
|
required: ['action'],
|
|
@@ -356,7 +393,7 @@ export function inputsTool(ws) {
|
|
|
356
393
|
let skipped = 0;
|
|
357
394
|
for (const f of files) {
|
|
358
395
|
let summary;
|
|
359
|
-
if (f.kind === 'other' || describer.cached(f) || Date.now() - t0 < LIST_BUDGET_MS)
|
|
396
|
+
if (f.kind === 'other' || f.kind === 'metadata' || describer.cached(f) || Date.now() - t0 < LIST_BUDGET_MS)
|
|
360
397
|
summary = (await describer.describe(f)).short;
|
|
361
398
|
else {
|
|
362
399
|
summary = 'not summarised yet (list time budget): inputs describe reads it';
|
|
@@ -364,12 +401,12 @@ export function inputsTool(ws) {
|
|
|
364
401
|
}
|
|
365
402
|
rows.push(` ${f.path} ${f.kind} ${sizeText(f.size)} ${dateText(f.mtime)} ${summary}`);
|
|
366
403
|
}
|
|
367
|
-
const kinds = ['geometry', 'image', 'other'].map((k) => [k, files.filter((f) => f.kind === k).length]).filter(([, c]) => c);
|
|
404
|
+
const kinds = ['geometry', 'image', 'metadata', 'other'].map((k) => [k, files.filter((f) => f.kind === k).length]).filter(([, c]) => c);
|
|
368
405
|
return text([
|
|
369
406
|
`inputs/ (${ws.inputDir}): ${plural(files.length, 'file')} (${kinds.map(([k, c]) => `${c} ${k}`).join(', ')})`,
|
|
370
407
|
...rows,
|
|
371
408
|
...(skipped ? [`${plural(skipped, 'file')} not summarised within ${LIST_BUDGET_MS / 1000} s; list again (summaries are cached) or describe them one by one.`] : []),
|
|
372
|
-
|
|
409
|
+
`A file node reads one: {"type":"file","params":{"path":"${inputRef(ws, '<path>')}"}} (relative paths read from the package folder: the nearest folder with a .topo file at or above the server's folder, else that folder). inputs {action:"describe", path} shows curves vs meshes, every name and role, attributes and materials; help {topic:"inputs"} explains the guide roles (site, path, zone, volume, blockout) and recipes.`,
|
|
373
410
|
'OBJ/STL from Blender (Up = Z) and Unreal are Z-up: add "up_axis":"z". A .blend needs Blender installed (converted headlessly).',
|
|
374
411
|
].join('\n'));
|
|
375
412
|
},
|
package/dist/mcp/server.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// TopoTopo MCP server (stdio). Exposes the geometry engine as tools for LLM agents.
|
|
3
|
-
// node src/mcp/server.ts [--
|
|
4
|
-
// topotopo mcp [--
|
|
5
|
-
// Env:
|
|
3
|
+
// node src/mcp/server.ts [--package <dir>] [--viewer]
|
|
4
|
+
// topotopo mcp [--package <dir>] [--viewer] (installed package: src/cli.ts dispatches here)
|
|
5
|
+
// Env: TOPOTOPO_PACKAGE, TOPOTOPO_VIEWER=1, TOPOTOPO_PORT, TOPOTOPO_SCRIPT_TIMEOUT_MS, TOPOTOPO_SIM_TIMEOUT_MS, TOPOTOPO_WORKERS
|
|
6
6
|
// stdout carries the MCP protocol — log only to stderr.
|
|
7
|
-
import fs from 'node:fs';
|
|
8
7
|
import path from 'node:path';
|
|
9
8
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
10
9
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
@@ -12,20 +11,36 @@ import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprot
|
|
|
12
11
|
import '../nodes/index.js';
|
|
13
12
|
import { Engine } from '../graph/engine.js';
|
|
14
13
|
import { createNodeHost } from '../host/node.js';
|
|
15
|
-
import {
|
|
14
|
+
import { TOPOTOPO_VERSION } from '../host/version.js';
|
|
16
15
|
import { makeTools } from './tools.js';
|
|
17
|
-
import {
|
|
16
|
+
import { workspaceTool } from './workspace.js';
|
|
18
17
|
import { INSTRUCTIONS } from './docs.js';
|
|
19
18
|
import { startViewer } from '../viewer/server.js';
|
|
19
|
+
import { startPackage, setProgram } from '../package.js';
|
|
20
|
+
import { openPackage } from '../open.js';
|
|
20
21
|
const argv = process.argv.slice(2);
|
|
21
22
|
const argOf = (flag) => { const i = argv.indexOf(flag); return i >= 0 ? argv[i + 1] : undefined; };
|
|
22
|
-
const
|
|
23
|
+
const named = argOf('--package') ?? process.env.TOPOTOPO_PACKAGE;
|
|
23
24
|
const log = (...a) => process.stderr.write('[topotopo] ' + a.join(' ') + '\n');
|
|
24
|
-
//
|
|
25
|
-
|
|
26
|
-
//
|
|
27
|
-
//
|
|
28
|
-
|
|
25
|
+
// hints name the command a person runs: the sources from a clone, or the installed package's
|
|
26
|
+
setProgram(import.meta.url.endsWith('.ts') ? 'node src/cli.ts' : 'topotopo');
|
|
27
|
+
// The folder, named (--package, TOPOTOPO_PACKAGE) or not (<cwd>/topotopo, which takes the name of the folder it
|
|
28
|
+
// is in), becomes a package when the server starts if it is in no package and holds nothing but what TopoTopo makes
|
|
29
|
+
// itself (graphs/, assets/, exports/, inputs/), or nothing at all, as a new one does: then its graphs use packages,
|
|
30
|
+
// TopoTopo's own among them, as they come. A folder in a package works in that package's folder. A folder with
|
|
31
|
+
// anything else in it (a repository, a folder of the person's) stays as it is: workspace {action:"init"} makes it a
|
|
32
|
+
// package when the person says so (startPackage, src/package.ts). The first tool reply says what happened.
|
|
33
|
+
const start = startPackage(path.resolve(named ?? path.join(process.cwd(), 'topotopo')), named ? {} : { title: path.basename(process.cwd()) });
|
|
34
|
+
log(start.log);
|
|
35
|
+
const wsDir = start.dir;
|
|
36
|
+
let firstNote = start.note;
|
|
37
|
+
// The folder can change while the server runs (workspace {action:"open"} opens a package of a library): every tool and
|
|
38
|
+
// the live viewer then work on the new folder. Each session has its own engine (asset registry, base directory,
|
|
39
|
+
// packages, cache); the worker pool is shared by the process. Sessions follow what other processes write into their folders
|
|
40
|
+
// (Session.watch: the web app's editor, a person editing JSON). The packages a session follows (workspace
|
|
41
|
+
// {action:"follow"}) resolve to their working folders as they are at each cook; the live viewer cooks its graphs again
|
|
42
|
+
// when one of those folders changes.
|
|
43
|
+
let engine, ws, packages, tools;
|
|
29
44
|
let viewer = null;
|
|
30
45
|
const ensureViewer = async () => {
|
|
31
46
|
if (!viewer) {
|
|
@@ -34,47 +49,61 @@ const ensureViewer = async () => {
|
|
|
34
49
|
}
|
|
35
50
|
return viewer.url;
|
|
36
51
|
};
|
|
37
|
-
const
|
|
38
|
-
async function
|
|
52
|
+
const workspaceTools = workspaceTool({ session: () => ws, packages: () => packages, open: (dir) => openSession(dir) });
|
|
53
|
+
async function openSession(dir) {
|
|
39
54
|
const e = new Engine(createNodeHost({ baseDir: dir }));
|
|
40
55
|
if (process.env.TOPOTOPO_SCRIPT_TIMEOUT_MS)
|
|
41
56
|
e.scriptTimeoutMs = Number(process.env.TOPOTOPO_SCRIPT_TIMEOUT_MS);
|
|
42
57
|
if (process.env.TOPOTOPO_SIM_TIMEOUT_MS)
|
|
43
58
|
e.simTimeoutMs = Number(process.env.TOPOTOPO_SIM_TIMEOUT_MS);
|
|
44
59
|
await e.init();
|
|
45
|
-
const w =
|
|
46
|
-
|
|
47
|
-
w.watch();
|
|
48
|
-
log(`workspace ${dir}: ${loaded.graphs} graphs, ${loaded.assets} assets, ${loaded.shelf} shelf assets`);
|
|
60
|
+
const { session: w, packages: pk, loaded } = openPackage(e, dir, { watch: true });
|
|
61
|
+
log(`session ${dir}: ${loaded.graphs} graphs, ${loaded.assets} assets${pk.dir ? `; package ${pk.dir}, ${Object.keys(pk.uses()).length} packages used` : '; in no package'}`);
|
|
49
62
|
for (const x of loaded.assetErrors)
|
|
50
63
|
log('asset error:', x);
|
|
64
|
+
for (const x of loaded.graphErrors)
|
|
65
|
+
log('graph not read:', x);
|
|
66
|
+
for (const x of pk.check())
|
|
67
|
+
log('package problem:', x);
|
|
51
68
|
const prev = ws;
|
|
52
69
|
engine = e;
|
|
53
70
|
ws = w;
|
|
54
|
-
|
|
55
|
-
|
|
71
|
+
packages = pk;
|
|
72
|
+
tools = [...makeTools(w, { onPreview: ensureViewer }), workspaceTools];
|
|
73
|
+
viewer?.setSession(w);
|
|
56
74
|
prev?.unwatch();
|
|
57
75
|
return loaded;
|
|
58
76
|
}
|
|
59
|
-
await
|
|
77
|
+
await openSession(wsDir);
|
|
60
78
|
if (argv.includes('--viewer') || process.env.TOPOTOPO_VIEWER === '1')
|
|
61
79
|
await ensureViewer();
|
|
62
|
-
|
|
63
|
-
const pkg = JSON.parse(fs.readFileSync(new URL('../../package.json', import.meta.url), 'utf8'));
|
|
64
|
-
const server = new Server({ name: 'topotopo', version: pkg.version }, { capabilities: { tools: {} }, instructions: INSTRUCTIONS });
|
|
80
|
+
const server = new Server({ name: 'topotopo', version: TOPOTOPO_VERSION }, { capabilities: { tools: {} }, instructions: INSTRUCTIONS });
|
|
65
81
|
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
66
82
|
tools: tools.map((t) => ({ name: t.name, description: t.description, inputSchema: t.inputSchema })),
|
|
67
83
|
}));
|
|
68
|
-
server.setRequestHandler(CallToolRequestSchema, async (req) => {
|
|
84
|
+
server.setRequestHandler(CallToolRequestSchema, async (req, extra) => {
|
|
69
85
|
const t = tools.find((x) => x.name === req.params.name);
|
|
70
86
|
if (!t)
|
|
71
87
|
return { content: [{ type: 'text', text: `unknown tool "${req.params.name}". Tools: ${tools.map((x) => x.name).join(', ')}` }], isError: true };
|
|
88
|
+
// a long call (workspace update) stops when the client cancels it, and says how far it is when the client asks to
|
|
89
|
+
const token = req.params._meta?.progressToken;
|
|
90
|
+
const progress = token === undefined ? undefined : (done, total, message) => {
|
|
91
|
+
extra.sendNotification({ method: 'notifications/progress', params: { progressToken: token, progress: done, total, message } }).catch(() => { });
|
|
92
|
+
};
|
|
93
|
+
// the first reply says where the server works when that is news: a folder that became a package, one left as it is,
|
|
94
|
+
// the package a folder lies in
|
|
95
|
+
const note = firstNote;
|
|
96
|
+
firstNote = null;
|
|
97
|
+
let r;
|
|
72
98
|
try {
|
|
73
|
-
|
|
99
|
+
r = await t.run(req.params.arguments ?? {}, { signal: extra.signal, progress });
|
|
74
100
|
}
|
|
75
101
|
catch (e) {
|
|
76
|
-
|
|
102
|
+
r = { content: [{ type: 'text', text: `error: ${e?.message ?? e}` }], isError: true };
|
|
77
103
|
}
|
|
104
|
+
if (note)
|
|
105
|
+
r.content = [...(r.content ?? []), { type: 'text', text: note }];
|
|
106
|
+
return r;
|
|
78
107
|
});
|
|
79
108
|
// the client closing the pipe (or a signal) ends the session: stop the worker threads and the viewer, then exit
|
|
80
109
|
let closing = false;
|
package/dist/mcp/tools.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Session } from '../session.ts';
|
|
2
2
|
import type { ExportFormat } from '../io/export.ts';
|
|
3
|
-
import type {
|
|
3
|
+
import type { ExportSource } from '../io/source.ts';
|
|
4
|
+
import type { Host, StopSignal } from '../host/types.ts';
|
|
4
5
|
import { Geometry } from '../core/geometry.ts';
|
|
5
6
|
export type Content = {
|
|
6
7
|
type: 'text';
|
|
@@ -14,18 +15,24 @@ export interface ToolResult {
|
|
|
14
15
|
content: Content[];
|
|
15
16
|
isError?: boolean;
|
|
16
17
|
}
|
|
18
|
+
/** What a call brings besides its arguments: the client's stop, and how to tell the client how far a long call is. */
|
|
19
|
+
export interface ToolCall {
|
|
20
|
+
signal?: StopSignal;
|
|
21
|
+
progress?: (done: number, total: number, message: string) => void;
|
|
22
|
+
}
|
|
17
23
|
export interface ToolDef {
|
|
18
24
|
name: string;
|
|
19
25
|
description: string;
|
|
20
26
|
inputSchema: any;
|
|
21
|
-
run: (args: any) => Promise<ToolResult>;
|
|
27
|
+
run: (args: any, call?: ToolCall) => Promise<ToolResult>;
|
|
22
28
|
}
|
|
23
29
|
/**
|
|
24
30
|
* Write every file of an export (heightmap sidecars and layers, instance-stream sidecar and mesh GLBs, the Unreal
|
|
25
|
-
* Landscape bundle, or the single file of other formats)
|
|
26
|
-
* written relative to the output file. Returns the report
|
|
31
|
+
* Landscape bundle, or the single file of other formats) and the record of how it was made (`source`, io/source.ts).
|
|
32
|
+
* Textures are read through the host; USD texture paths are written relative to the output file. Returns the report
|
|
33
|
+
* text.
|
|
27
34
|
*/
|
|
28
|
-
export declare function writeExport(geo: Geometry, format: ExportFormat, p: string, a: any, host: Host, record?: (files: string[]) => void): Promise<string>;
|
|
29
|
-
export declare function makeTools(ws:
|
|
35
|
+
export declare function writeExport(geo: Geometry, format: ExportFormat, p: string, a: any, host: Host, record?: (files: string[]) => void, source?: ExportSource): Promise<string>;
|
|
36
|
+
export declare function makeTools(ws: Session, opts?: {
|
|
30
37
|
onPreview?: () => Promise<string>;
|
|
31
38
|
}): ToolDef[];
|