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.
- package/NOTICE +30 -0
- package/README.md +54 -16
- package/dist/cli.js +95 -14
- package/dist/core/analysis.d.ts +5 -1
- package/dist/core/analysis.js +8 -3
- package/dist/core/bake.d.ts +2 -5
- package/dist/core/bake.js +12 -25
- package/dist/core/bevel.js +165 -97
- package/dist/core/geometry.js +1 -1
- package/dist/core/imageops.d.ts +6 -0
- package/dist/core/imageops.js +51 -0
- package/dist/core/materials.d.ts +4 -0
- package/dist/core/materials.js +11 -0
- package/dist/core/packed.js +11 -0
- package/dist/core/particles.d.ts +1 -1
- package/dist/core/particles.js +1 -1
- package/dist/core/rbd.js +13 -1
- package/dist/core/scatter.d.ts +1 -1
- package/dist/core/scatter.js +1 -1
- package/dist/core/scene.d.ts +20 -0
- package/dist/core/scene.js +71 -0
- package/dist/core/snippet-lib.d.ts +1 -1
- package/dist/core/snippet-lib.js +1 -1
- package/dist/core/solidify.d.ts +38 -0
- package/dist/core/solidify.js +356 -0
- package/dist/core/tangents.d.ts +52 -0
- package/dist/core/tangents.js +214 -0
- package/dist/core/texcoord.d.ts +4 -0
- package/dist/core/texcoord.js +14 -0
- package/dist/core/topology.d.ts +22 -0
- package/dist/core/topology.js +70 -7
- package/dist/core/traceimage.d.ts +7 -0
- package/dist/core/traceimage.js +221 -0
- package/dist/core/tritri.d.ts +5 -0
- package/dist/core/tritri.js +120 -0
- package/dist/core/uv.d.ts +13 -0
- package/dist/core/uv.js +3 -3
- package/dist/core/uvreport.d.ts +66 -0
- package/dist/core/uvreport.js +308 -0
- package/dist/core/xatlas.js +32 -2
- package/dist/gallery/app/gallery.css +100 -0
- package/dist/gallery/app/gallery.js +80 -0
- package/dist/gallery/bake.d.ts +34 -0
- package/dist/gallery/bake.js +144 -0
- package/dist/gallery/cli.d.ts +4 -0
- package/dist/gallery/cli.js +157 -0
- package/dist/gallery/library.d.ts +124 -0
- package/dist/gallery/library.js +366 -0
- package/dist/gallery/pages.d.ts +94 -0
- package/dist/gallery/pages.js +148 -0
- package/dist/gallery/server.d.ts +21 -0
- package/dist/gallery/server.js +391 -0
- package/dist/graph/engine.js +14 -0
- package/dist/graph/types.d.ts +17 -0
- package/dist/host/artifacts.d.ts +21 -0
- package/dist/host/artifacts.js +58 -0
- package/dist/host/export-targets.d.ts +33 -0
- package/dist/host/export-targets.js +84 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -1
- package/dist/inspect.d.ts +6 -1
- package/dist/inspect.js +13 -1
- package/dist/io/common.d.ts +8 -0
- package/dist/io/gltf.js +236 -19
- package/dist/io/targets.d.ts +31 -0
- package/dist/io/targets.js +75 -0
- package/dist/mcp/docs.d.ts +1 -1
- package/dist/mcp/docs.js +73 -6
- package/dist/mcp/library.d.ts +12 -0
- package/dist/mcp/library.js +159 -0
- package/dist/mcp/server.js +29 -12
- package/dist/mcp/tools.d.ts +1 -1
- package/dist/mcp/tools.js +102 -43
- package/dist/nodes/bake.js +56 -36
- package/dist/nodes/bevel.js +4 -3
- package/dist/nodes/code.js +33 -7
- package/dist/nodes/curves.js +7 -0
- package/dist/nodes/generate.js +1 -1
- package/dist/nodes/imageops.d.ts +1 -0
- package/dist/nodes/imageops.js +206 -0
- package/dist/nodes/index.d.ts +3 -0
- package/dist/nodes/index.js +3 -0
- package/dist/nodes/material.js +3 -0
- package/dist/nodes/measure.js +3 -2
- package/dist/nodes/rbd.js +1 -1
- package/dist/nodes/scene.d.ts +1 -0
- package/dist/nodes/scene.js +53 -0
- package/dist/nodes/solidify.d.ts +1 -0
- package/dist/nodes/solidify.js +52 -0
- package/dist/nodes/transform.js +5 -1
- package/dist/nodes/util.d.ts +1 -1
- package/dist/nodes/wasmcall.js +1 -1
- package/dist/render/options.js +1 -1
- package/dist/render/pbr.d.ts +28 -0
- package/dist/render/pbr.js +378 -0
- package/dist/render/preview.d.ts +58 -0
- package/dist/render/preview.js +24 -0
- package/dist/render/raster.d.ts +12 -2
- package/dist/render/raster.js +98 -11
- package/dist/render/texview.d.ts +1 -1
- package/dist/render/texview.js +7 -2
- package/dist/viewer/app/camera.js +27 -7
- package/dist/viewer/app/embed.js +80 -0
- package/dist/viewer/app/export-popover.js +68 -0
- package/dist/viewer/app/grid.js +1 -1
- package/dist/viewer/app/guides.js +1 -1
- package/dist/viewer/app/image-view.js +114 -0
- package/dist/viewer/app/keymap.js +15 -3
- package/dist/viewer/app/layers.js +24 -5
- package/dist/viewer/app/main.js +71 -15
- package/dist/viewer/app/markers.js +1 -1
- package/dist/viewer/app/outliner.js +56 -15
- package/dist/viewer/app/outputs.css +73 -0
- package/dist/viewer/app/outputs.js +240 -0
- package/dist/viewer/app/props.js +1 -1
- package/dist/viewer/app/scene.js +6 -2
- package/dist/viewer/app/select.js +14 -3
- package/dist/viewer/app/selection.js +1 -1
- package/dist/viewer/app/status.js +20 -0
- package/dist/viewer/app/style.css +2 -1
- package/dist/viewer/app/units.js +1 -1
- package/dist/viewer/app/vars.js +1 -1
- package/dist/viewer/index.html +20 -6
- package/dist/viewer/outputs.d.ts +54 -0
- package/dist/viewer/outputs.js +436 -0
- package/dist/viewer/server.d.ts +19 -2
- package/dist/viewer/server.js +77 -9
- package/dist/workspace.d.ts +21 -2
- package/dist/workspace.js +124 -4
- package/kernels/pkg/README.md +21 -28
- package/kernels/pkg-simd/README.md +21 -28
- package/package.json +11 -4
package/dist/mcp/docs.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { GraphSpec, NodeDef } from '../graph/types.ts';
|
|
2
|
-
export declare const INSTRUCTIONS = "TopoTopo: a procedural geometry engine (Houdini-SOP style) you drive with JSON node graphs.\n\nWORKFLOW\n0. inputs {action:\"list\"} \u2192 the person's own files in the workspace inputs/ folder (guide curves, sites, zones, blockouts, PNG masks). Building a landscape or scene: look there first and build on them (help topic \"inputs\").\n1. catalog \u2192 see node types (100+, Houdini names work as aliases: copytopoints, attribwrangle, polyextrude, mountain\u2026).\n2. help {nodes:[...]} for exact params before using unfamiliar nodes; help {topic:\"wrangle\"|\"graph\"|\"recipes\"\u2026} for concepts.\n3. build {graph} the WHOLE network in one call (dry_run:true validates without cooking). Every response reports errors per node with did-you-mean hints.\n4. render to SEE it (quad view: persp/front/right/top; backfaces are tinted blue = flipped normals; views \"quad_uv\" + checker:true for UVs; overlays for specific questions: wireframe \"hard\"/\"boundary\", views \"section\", glyphs \"N\", label_groups, shading \"matcap\", see help topic \"render\"). inspect for numbers (bbox, attributes, watertightness).\n5. edit {ops} for incremental changes (set params, insert nodes, rewire) \u2014 only downstream nodes re-cook.\n6. export to glb/gltf (materials, textures, meshopt), geo (Houdini), csv (Unreal PCG points / instance rows), points.json, usda, obj/ply/stl/json for Unreal, Blender, Houdini; unreal_landscape = a whole terrain scene for Unreal.\n7. verify: assert nodes guard invariants in the graph (watertight, counts, bbox, expr); explain {graph} reads a result in words; diff {a, b} shows what an edit changed. See help topic \"verify\".\nINSTANCING: copy_to_points {pack:true} / pack make packed instances (millions stay cheap; glb, usda and geo export them as instances, csv/points.json as one row per instance). See help topic \"instancing\".\nPCG: mask \u2192 scatter {density_mask} \u2192 orient \u2192 prune \u2192 copy_to_points {pack, variants, variant_weights}; points_along_curve, cluster, attribute_from_map. See help topic \"pcg\".\nCURVES: bezier / nurbs make spline prims (CVs + order, exact everywhere); convert_curve, resample, fillet_curve, offset_curve_3d, project_curve (roads on terrain), spline_fit, curve_attribs (curveu, frames, ramps). See help topic \"curves\".\nCLOTH: drape {steps} simulates a mesh as cloth over a collider (input 1) and the floor, from pins (pin_group / input 2) and in wind; inflate {pressure} puffs a closed mesh into a cushion or balloon. See help topic \"cloth\".\n\nCONVENTIONS: Y-up, metres, angles in degrees (wrangle trig uses radians). Houdini attribute names (P N Cd uv pscale orient up scale width name class piece). Polygons are closed prims, polylines are open prims.\nGRAPH: {\"nodes\": {\"name\": {\"type\": \"...\", \"in\": [\"upstream\", ...], \"params\": {...}}}, \"output\": \"name\", \"vars\": {\"k\": 1}}. Params accept \"=expr\" using vars (e.g. \"=height*0.5\"), time (frame, time) and other nodes (npoints('pts'), bbox('base').size.y, ch('box1/size')).\nHUMANS TUNE VARS: declare \"params\" for the 3\u20138 vars a person would tune ({\"k\": {type, desc, min, max, options, label, step}}); the live viewer (preview) shows them as sliders and menus. People change vars at any time, so read the graph (graphs {action:\"get\"}) before assuming a var's value. See help topic \"graph\".\nTIME: build/edit/render/inspect/export take \"frame\" (default 1). solver = per-frame feedback (growth, accumulation). See help topic \"time\".\nPARTICLES: particles(emitter points, collision mesh, field) = Houdini POPs in one node: emission, gravity/drag/wind, curl noise, fields, floor and mesh collisions, trails as polylines; steps with the frame. See help topic \"particles\".\nESCAPE HATCHES: wrangle (per-element JS with @P/@Cd syntax), script (whole-geometry JS with the engine library), sdf_expr (signed distance functions). If a node is missing, write it with these.\nTERRAIN: heightfield \u2192 heightfield_noise \u2192 heightfield_erode \u2192 masks / heightfield_path \u2192 heightfield_scatter + copy_to_points, heightfield_to_mesh; export png16 for an Unreal Landscape, or unreal_landscape for the landscape + layers + instances bundle. See help topic \"heightfield\".\nPHYSICS: rbd_settle drops pieces (packed instances) onto a terrain/container/ground until they rest, so scattered rocks and props sit in contact; rbd_stack drops them one at a time into piles. See help topic \"rbd\".";
|
|
2
|
+
export declare const INSTRUCTIONS = "TopoTopo: a procedural geometry engine (Houdini-SOP style) you drive with JSON node graphs.\n\nWORKFLOW\n0. inputs {action:\"list\"} \u2192 the person's own files in the workspace inputs/ folder (guide curves, sites, zones, blockouts, PNG masks). Building a landscape or scene: look there first and build on them (help topic \"inputs\").\n1. catalog \u2192 see node types (100+, Houdini names work as aliases: copytopoints, attribwrangle, polyextrude, mountain\u2026).\n2. help {nodes:[...]} for exact params before using unfamiliar nodes; help {topic:\"wrangle\"|\"graph\"|\"recipes\"\u2026} for concepts.\n3. build {graph} the WHOLE network in one call (dry_run:true validates without cooking). Every response reports errors per node with did-you-mean hints.\n4. render to SEE it (quad view: persp/front/right/top; backfaces are tinted blue = flipped normals; views \"quad_uv\" + checker:true for UVs; overlays for specific questions: wireframe \"hard\"/\"boundary\", views \"section\", glyphs \"N\", label_groups, shading \"matcap\", see help topic \"render\"). inspect for numbers (bbox, attributes, watertightness).\n5. edit {ops} for incremental changes (set params, insert nodes, rewire) \u2014 only downstream nodes re-cook.\n6. export to glb/gltf (materials, textures, meshopt), geo (Houdini), csv (Unreal PCG points / instance rows), points.json, usda, obj/ply/stl/json for Unreal, Blender, Houdini; unreal_landscape = a whole terrain scene for Unreal.\n7. verify: assert nodes guard invariants in the graph (watertight, counts, bbox, expr); explain {graph} reads a result in words; diff {a, b} shows what an edit changed. See help topic \"verify\".\nOUTPUTS: publish intended deliverables in graph.outputs: {\"rotor\":{\"node\":\"rotor_final\",\"label\":\"Rotor\"}}. The default graph.output stays unchanged. The viewer lists every graph and named result, its generated textures and image layers; clicking a result isolates it. Rendered images and exports are saved and visible too. Use descriptive names; keep intermediate work in the node outliner. Rename/remove edits maintain published references.\nINSTANCING: copy_to_points {pack:true} / pack make packed instances (millions stay cheap; glb, usda and geo export them as instances, csv/points.json as one row per instance). See help topic \"instancing\".\nPCG: mask \u2192 scatter {density_mask} \u2192 orient \u2192 prune \u2192 copy_to_points {pack, variants, variant_weights}; points_along_curve, cluster, attribute_from_map. See help topic \"pcg\".\nCURVES: bezier / nurbs make spline prims (CVs + order, exact everywhere); convert_curve, resample, fillet_curve, offset_curve_3d, project_curve (roads on terrain), spline_fit, curve_attribs (curveu, frames, ramps). See help topic \"curves\".\nCLOTH: drape {steps} simulates a mesh as cloth over a collider (input 1) and the floor, from pins (pin_group / input 2) and in wind; inflate {pressure} puffs a closed mesh into a cushion or balloon. See help topic \"cloth\".\n\nCONVENTIONS: Y-up, metres, angles in degrees (wrangle trig uses radians). Houdini attribute names (P N Cd uv pscale orient up scale width name class piece). Polygons are closed prims, polylines are open prims.\nGRAPH: {\"nodes\": {\"name\": {\"type\": \"...\", \"in\": [\"upstream\", ...], \"params\": {...}}}, \"output\": \"name\", \"vars\": {\"k\": 1}}. Params accept \"=expr\" using vars (e.g. \"=height*0.5\"), time (frame, time) and other nodes (npoints('pts'), bbox('base').size.y, ch('box1/size')).\nHUMANS TUNE VARS: declare \"params\" for the 3\u20138 vars a person would tune ({\"k\": {type, desc, min, max, options, label, step}}); the live viewer (preview) shows them as sliders and menus. People change vars at any time, so read the graph (graphs {action:\"get\"}) before assuming a var's value. See help topic \"graph\".\nTIME: build/edit/render/inspect/export take \"frame\" (default 1). solver = per-frame feedback (growth, accumulation). See help topic \"time\".\nPARTICLES: particles(emitter points, collision mesh, field) = Houdini POPs in one node: emission, gravity/drag/wind, curl noise, fields, floor and mesh collisions, trails as polylines; steps with the frame. See help topic \"particles\".\nESCAPE HATCHES: wrangle (per-element JS with @P/@Cd syntax), script (whole-geometry JS with the engine library), sdf_expr (signed distance functions). If a node is missing, write it with these.\nTERRAIN: heightfield \u2192 heightfield_noise \u2192 heightfield_erode \u2192 masks / heightfield_path \u2192 heightfield_scatter + copy_to_points, heightfield_to_mesh; export png16 for an Unreal Landscape, or unreal_landscape for the landscape + layers + instances bundle. See help topic \"heightfield\".\nPHYSICS: rbd_settle drops pieces (packed instances) onto a terrain/container/ground until they rest, so scattered rocks and props sit in contact; rbd_stack drops them one at a time into piles. See help topic \"rbd\".\nLIBRARIES: the person's projects live in libraries the TopoTopo Gallery website shows (their board links to them). library {action:\"list\"} finds one, {action:\"open\"} makes it the workspace of every tool, {action:\"create\"} starts one. See help topic \"library\".";
|
|
3
3
|
/**
|
|
4
4
|
* The complete example of help topic "inputs": guides.glb's path.* curves cut roads into a heightfield and its zone.*
|
|
5
5
|
* areas mask a tree scatter; the vars a person tunes are exposed as params. test/mcp.ts cooks it on a real guides.glb.
|
package/dist/mcp/docs.js
CHANGED
|
@@ -10,6 +10,7 @@ WORKFLOW
|
|
|
10
10
|
5. edit {ops} for incremental changes (set params, insert nodes, rewire) — only downstream nodes re-cook.
|
|
11
11
|
6. export to glb/gltf (materials, textures, meshopt), geo (Houdini), csv (Unreal PCG points / instance rows), points.json, usda, obj/ply/stl/json for Unreal, Blender, Houdini; unreal_landscape = a whole terrain scene for Unreal.
|
|
12
12
|
7. verify: assert nodes guard invariants in the graph (watertight, counts, bbox, expr); explain {graph} reads a result in words; diff {a, b} shows what an edit changed. See help topic "verify".
|
|
13
|
+
OUTPUTS: publish intended deliverables in graph.outputs: {"rotor":{"node":"rotor_final","label":"Rotor"}}. The default graph.output stays unchanged. The viewer lists every graph and named result, its generated textures and image layers; clicking a result isolates it. Rendered images and exports are saved and visible too. Use descriptive names; keep intermediate work in the node outliner. Rename/remove edits maintain published references.
|
|
13
14
|
INSTANCING: copy_to_points {pack:true} / pack make packed instances (millions stay cheap; glb, usda and geo export them as instances, csv/points.json as one row per instance). See help topic "instancing".
|
|
14
15
|
PCG: mask → scatter {density_mask} → orient → prune → copy_to_points {pack, variants, variant_weights}; points_along_curve, cluster, attribute_from_map. See help topic "pcg".
|
|
15
16
|
CURVES: bezier / nurbs make spline prims (CVs + order, exact everywhere); convert_curve, resample, fillet_curve, offset_curve_3d, project_curve (roads on terrain), spline_fit, curve_attribs (curveu, frames, ramps). See help topic "curves".
|
|
@@ -22,7 +23,8 @@ TIME: build/edit/render/inspect/export take "frame" (default 1). solver = per-fr
|
|
|
22
23
|
PARTICLES: particles(emitter points, collision mesh, field) = Houdini POPs in one node: emission, gravity/drag/wind, curl noise, fields, floor and mesh collisions, trails as polylines; steps with the frame. See help topic "particles".
|
|
23
24
|
ESCAPE HATCHES: wrangle (per-element JS with @P/@Cd syntax), script (whole-geometry JS with the engine library), sdf_expr (signed distance functions). If a node is missing, write it with these.
|
|
24
25
|
TERRAIN: heightfield → heightfield_noise → heightfield_erode → masks / heightfield_path → heightfield_scatter + copy_to_points, heightfield_to_mesh; export png16 for an Unreal Landscape, or unreal_landscape for the landscape + layers + instances bundle. See help topic "heightfield".
|
|
25
|
-
PHYSICS: rbd_settle drops pieces (packed instances) onto a terrain/container/ground until they rest, so scattered rocks and props sit in contact; rbd_stack drops them one at a time into piles. See help topic "rbd"
|
|
26
|
+
PHYSICS: rbd_settle drops pieces (packed instances) onto a terrain/container/ground until they rest, so scattered rocks and props sit in contact; rbd_stack drops them one at a time into piles. See help topic "rbd".
|
|
27
|
+
LIBRARIES: the person's projects live in libraries the TopoTopo Gallery website shows (their board links to them). library {action:"list"} finds one, {action:"open"} makes it the workspace of every tool, {action:"create"} starts one. See help topic "library".`;
|
|
26
28
|
/**
|
|
27
29
|
* The complete example of help topic "inputs": guides.glb's path.* curves cut roads into a heightfield and its zone.*
|
|
28
30
|
* areas mask a tree scatter; the vars a person tunes are exposed as params. test/mcp.ts cooks it on a real guides.glb.
|
|
@@ -60,6 +62,28 @@ export function graphLines(g) {
|
|
|
60
62
|
return `{${parts.join(',\n ')}}`;
|
|
61
63
|
}
|
|
62
64
|
export const TOPICS = {
|
|
65
|
+
library: `LIBRARIES AND THE GALLERY
|
|
66
|
+
A library is a folder the person listed (\`topotopo library add <name> <folder>\`, kept in ~/.topotopo/config.json). A
|
|
67
|
+
project is any folder in it holding project.json, and is a workspace of its own:
|
|
68
|
+
props/lantern/project.json {id, title, description, tags, graph:"main", bake:{graph?, node?, frame?}, links:[{label, url}]}
|
|
69
|
+
props/lantern/graphs/ assets/ inputs/ exports/ as in any workspace
|
|
70
|
+
props/lantern/attachments/ concept art, references, source files (shown on the project's gallery page)
|
|
71
|
+
props/lantern/.gallery/ thumb.png, preview.glb, bake.json: derived, never edit
|
|
72
|
+
The parent folders ("props") are the project's collection. The gallery (\`topotopo gallery\`, http://127.0.0.1:7340)
|
|
73
|
+
shows every library as a grid; each project has a page (/p/<library>/<id>), a thumbnail (…/thumb.png) and an
|
|
74
|
+
iframe embed (/embed/<library>/<id>) that the person's board pastes. It bakes the previews by itself after graphs,
|
|
75
|
+
assets or inputs change, from the graph named in "graph" (or "bake": another graph, a node, a frame).
|
|
76
|
+
|
|
77
|
+
WORKING IN A PROJECT
|
|
78
|
+
- library {action:"list", query?, tag?} → find it; library {action:"get", library, id, thumbnail:true} → what it holds.
|
|
79
|
+
- library {action:"open", library, id} → every tool (build, edit, render, export, inputs, assets, preview) now works
|
|
80
|
+
in that folder. Build the project's model into graph "main" (or the manifest's "graph").
|
|
81
|
+
- library {action:"create", library, path:"props/barrel", title, tags, links} → a new project, opened.
|
|
82
|
+
- library {action:"update", tags, links, description, bake:{frame: 48}} → edit project.json (bake.frame for
|
|
83
|
+
simulations that settle after frame 1; bake.node to show one part).
|
|
84
|
+
- library {action:"bake"} → render the previews now and see the thumbnail.
|
|
85
|
+
Put reference images the person gives you in attachments/, guide files in inputs/. Links in "links" point back to the
|
|
86
|
+
board or concept pages, so the gallery page and the board link both ways.`,
|
|
63
87
|
graph: `GRAPH FORMAT
|
|
64
88
|
{
|
|
65
89
|
"nodes": {
|
|
@@ -82,14 +106,24 @@ export const TOPICS = {
|
|
|
82
106
|
keep a value, keep it.
|
|
83
107
|
- "in": ordered input list (null = unconnected), a single name, or {"inputName": node} (names from help).
|
|
84
108
|
- Output node: "output", else a node named out/OUT, else the last unconnected node.
|
|
109
|
+
- Optional "outputs": {"rotor":{"node":"rotor_final","label":"Rotor"}} publishes additional deliverables beside
|
|
110
|
+
the default. Publish complete assets and useful separate parts; the viewer isolates each on click and lists
|
|
111
|
+
its textures/layers. Rename/remove edits maintain references. The latest render of each graph node is saved as
|
|
112
|
+
exports/renders/<graph>-<node>.png (each render overwrites it) unless save_to is supplied; explicit render/export
|
|
113
|
+
destinations are registered in the viewer too.
|
|
114
|
+
- Optional "export" (on the graph for the default output, or on an entry of "outputs") is where that output
|
|
115
|
+
exports: a format ("glb" → exports/<graph or output id>.glb) or {"format":"obj","path":"parts/a.obj","up_axis":"z"}
|
|
116
|
+
(the export tool's options), always inside exports/. The person's Export buttons in the viewer, export {output} /
|
|
117
|
+
export {all:true} and the CLI's --export-all write these targets; set one with edit {op:"export", output?, export}.
|
|
85
118
|
- Node names: letters, digits, _ . - Node types & params are case/underscore-insensitive and accept Houdini-style aliases.
|
|
86
119
|
- "bypass": true passes input 0 through. "note": free text. "ui": {x,y} reserved for the future GUI.
|
|
87
120
|
- Vectors: a single number broadcasts ("size": 2 → [2,2,2]). Colours accept [r,g,b], "#ff8800" or names.
|
|
88
121
|
- build mode "merge" upserts nodes into the existing graph; edit ops: set, add, remove (auto-rewires), connect, rename, output, vars, bypass, replace, insert (after a node, rewiring its consumers).
|
|
89
122
|
- Several graphs can coexist (name param); graph_ref composes them. Graphs persist as JSON in the workspace.`,
|
|
90
123
|
inputs: `HUMAN INPUT (guides, blockouts and masks in the workspace inputs/ folder)
|
|
91
|
-
People feed in their own material by dropping files into <workspace>/inputs/ (or onto the live viewer
|
|
92
|
-
curves and points drawn in Blender, Houdini or Unreal, placeholder blockouts, PNG masks and
|
|
124
|
+
People feed in their own material by dropping files into <workspace>/inputs/ (or onto the live viewer, or with its Add
|
|
125
|
+
input button): meshes, guide curves and points drawn in Blender, Houdini or Unreal, placeholder blockouts, PNG masks and
|
|
126
|
+
heightmaps. Every tool answer ends with a note when inputs/ has files new or changed since your last call. Before building a
|
|
93
127
|
landscape or scene, call inputs {action:"list"}; inputs {action:"describe", path} tells what one holds (polygons, open
|
|
94
128
|
polylines, loose points, packed prims; bbox in metres; attributes; every name and role value; materials). Read a file
|
|
95
129
|
with a file node, the path relative to the workspace: {"type":"file","params":{"path":"inputs/guides.glb"}}.
|
|
@@ -434,6 +468,17 @@ MATERIALS: texture_to_material {material, base_color, normal, roughness, metalli
|
|
|
434
468
|
with uv) + input 1 (merged images): writes "image:<name>" slots into the material table, assigns the material (all
|
|
435
469
|
prims when new, else group) and carries the images. occlusion/metallic images are packed into "<material>_orm".
|
|
436
470
|
The material node's *_map paths accept "image:<name>" as well.
|
|
471
|
+
CUTOUTS: tex_crop extracts a top-left pixel rectangle (all layers), optionally resizes. trace_image reads alpha
|
|
472
|
+
or a selected channel into closed XY curves, including holes; fill builds faces. Restore UVs after fill using
|
|
473
|
+
uv_project {method:"planar",axis:"z",scale:[width,width*imageHeight/imageWidth]} BEFORE deforming.
|
|
474
|
+
tex_pack items:[{name:"leaf",maps:{color:"leaf_color",normal:"leaf_normal"}}] creates aligned atlas images and
|
|
475
|
+
placement points: name, rect [x,y,w,h], uv_offset, uv_scale. In a vertex wrangle, read these from input 1:
|
|
476
|
+
atlasUV = localUV * uv_scale + uv_offset. Output points follow items order. No rotation or automatic downscale.
|
|
477
|
+
tex_dilate pads nearest valid pixels; alpha stays unchanged by default. For grey/data maps supply an explicit
|
|
478
|
+
validity mask (same size). Pack padding reserves empty gutters; dilate supplies the edge values.
|
|
479
|
+
material {alpha_mode:"mask",alpha_cutoff:0.5,double_sided:true} BEFORE texture_to_material enables cutouts.
|
|
480
|
+
Omitted/auto alpha mode retains legacy behaviour; explicit opaque/mask/blend overrides scalar/vertex auto mode.
|
|
481
|
+
Complete example: examples/image_cutouts.json; workflow and layout contract: docs/image-cutouts.md.
|
|
437
482
|
SEE IT: render of a geometry holding only images shows the "texture" view; render {texture:"<image>"|"image/layer"|
|
|
438
483
|
"<material>"} adds the view (a material shows its maps as a labelled strip); render {textures:true} samples base
|
|
439
484
|
colour maps on the mesh (texture × Cd, like glTF). inspect lists every image with size and per-layer ranges.
|
|
@@ -670,6 +715,11 @@ SEE IT: render views "uv" (or "quad_uv" = persp + uv): the 0..1 square with a 0.
|
|
|
670
715
|
by chart/island colour, island borders yellow, overlapping uv in RED (footer/notes give the overlap %).
|
|
671
716
|
render checker:true shades 3D views with an 8×8 uv checker: squares should look square and equal-sized
|
|
672
717
|
(stretch = rectangles, density = cell size, mirrored charts flip the red/green gradient).
|
|
718
|
+
MEASURE IT: inspect {detail:"uv", resolution:1024, json:true}: exact overlaps (triangle pairs, their prims and areas,
|
|
719
|
+
folds inside one chart included; shared edges are not overlaps), collapsed / non-finite / out-of-tile triangles, UDIM
|
|
720
|
+
tiles, charts, mirrored triangles, utilization (exact for a clean atlas in 0..1, else a labelled raster ESTIMATE) and
|
|
721
|
+
per-piece (prim "name") surface, uv area and texel density. An analysis that hits its bounds says INCOMPLETE.
|
|
722
|
+
CLI: --inspect uv --uv-resolution 1024 [--json].
|
|
673
723
|
Export: uv → glTF TEXCOORD_0 (v flipped), OBJ vt, USD primvars:st.`,
|
|
674
724
|
render: `RENDER (pick the overlay that answers your question; everything is off by default)
|
|
675
725
|
render {node?, views, …} returns a PNG; build/edit take the same options as render:{…}. The footer names the active
|
|
@@ -698,13 +748,22 @@ QUESTION → OPTION
|
|
|
698
748
|
What do the colours mean? color_by + legend:true (gradient bar with min/max, or categorical swatches)
|
|
699
749
|
What shape is it? shading:"matcap" (clay, reads form) · "ao" (ambient occlusion: creases and
|
|
700
750
|
cavities darken; ao_radius px) · "flat" (facets, ignores N)
|
|
751
|
+
How do the materials read? Roughness, metal, maps? shading:"pbr": the metallic-roughness material glTF export writes
|
|
752
|
+
(base colour map × vertex colour, tangent-space normal map in the exported MikkTSpace frame, orm or
|
|
753
|
+
roughness map, metallic, emissive, unlit) under a fixed camera-relative studio rig (key, fill, rim and a
|
|
754
|
+
sky/ground environment), GGX specular, ACES, exposure (stops, default 0). Deterministic: the same graph
|
|
755
|
+
gives the same PNG. Texture files are read from disk; transparency is not evaluated (shaded opaque,
|
|
756
|
+
with a note), nor are missing or non-PNG maps (named in the notes).
|
|
701
757
|
Labels never overlap: ones without room are skipped (note says how many; raise size or lower max_labels).
|
|
702
758
|
view_labels:false drops each view's name label and the persp axis gizmo (clean thumbnails, e.g. the shelf's).
|
|
703
759
|
Examples: render {views:["persp","section"], section_axis:"z", wireframe:"hard", label_groups:true}
|
|
704
760
|
render {views:"turntable", shading:"matcap"} · render {glyphs:"N", clip:{axis:"x", offset:0.5}}
|
|
705
761
|
CLI: --wireframe all --section y:0.5 --clip x:0.5 --glyphs N --labels groups,pieces --shading matcap --legend --size 1600 --scale 2
|
|
762
|
+
--shading pbr --exposure 0.5
|
|
706
763
|
--no-view-labels`,
|
|
707
764
|
export: `EXPORT
|
|
765
|
+
export {output:"crate"} / export {} (the default output) / export {all:true}: the graph's export targets (help topic
|
|
766
|
+
"graph": "export" on the graph or an output), written inside exports/, the same files the viewer's Export buttons write.
|
|
708
767
|
export {path:"exports/thing.glb"} — format from the extension:
|
|
709
768
|
glb / gltf glTF 2.0 via gltf-transform (recommended for Unreal, Blender, web)
|
|
710
769
|
geo Houdini JSON geometry: every attribute (all classes), group and polyline, lossless (precision 64 or 32)
|
|
@@ -715,13 +774,21 @@ export {path:"exports/thing.glb"} — format from the extension:
|
|
|
715
774
|
Options: up_axis "y" (default) | "z", scale (100 = m → cm), split_by_name (one mesh per prim "name", default true),
|
|
716
775
|
custom_attribs, materials (default true), compress "none" | "meshopt" (EXT_meshopt_compression + KHR_mesh_quantization,
|
|
717
776
|
~3× smaller; for web engines such as three.js/Babylon.js) | "draco" (only with the optional draco3dgltf package),
|
|
718
|
-
quantize (KHR_mesh_quantization alone), attributes ["P","pscale",…] (csv / points.json), pcg / pcg_struct (csv),
|
|
777
|
+
quantize (KHR_mesh_quantization alone), tangents "auto" | "preserve" | "none" (glTF TANGENT, below), attributes ["P","pscale",…] (csv / points.json), pcg / pcg_struct (csv),
|
|
719
778
|
precision 64 | 32 (geo), instancing "packed" | "expand", instances "rows" | "expand" (csv / points.json of packed
|
|
720
779
|
prims), meshes (instance rows: also write one GLB per source, default true). For Unreal and Blender keep the default
|
|
721
780
|
uncompressed GLB.
|
|
722
781
|
glTF layout: one node+mesh per "name", one primitive per material. Polygons → TRIANGLES, polylines → one LINE_STRIP each
|
|
723
|
-
(LINES above 256 curves), loose points → POINTS with pscale as _PSCALE.
|
|
724
|
-
|
|
782
|
+
(LINES above 256 curves), loose points → POINTS with pscale as _PSCALE. Scene empties (scene_null: isolated points with
|
|
783
|
+
scene_empty 1, name, parent, orient, scale) → meshless nodes (sockets) under their parent: the scene, another empty or
|
|
784
|
+
a uniquely named mesh, with the local TRS that keeps their geometry-space placement; set point attributes → node extras;
|
|
785
|
+
missing, ambiguous or cyclic parents and GPU-instanced parents are errors; import brings them back. N → NORMAL (else computed, 60° cusp),
|
|
786
|
+
uv/uv2 → TEXCOORD_0/1 (V flipped), Cd (+Alpha) → COLOR_0. TANGENT (tangents "auto", the default): MikkTSpace
|
|
787
|
+
tangents (xyz + handedness w) for every primitive whose material has a normal map, computed per corner before
|
|
788
|
+
vertices are welded (uv seams, hard normals and mirrored islands keep their own frames), the same frame bake_normal
|
|
789
|
+
bakes in; a valid point/vertex "tangent" float[4] (from an import) is written on other primitives. "preserve" writes
|
|
790
|
+
the supplied attribute wherever it exists (malformed = error), "none" never writes TANGENT. Collapsed uvs are
|
|
791
|
+
reported. Import reads TANGENT back as point "tangent" (transforms keep it: xyz rotated, w flipped by mirrors). Custom attributes: every other numeric point/vertex attribute
|
|
725
792
|
of size 1-4 → _NAME (upper-cased, float or the smallest int type); mesh extras keep the original names and types.
|
|
726
793
|
MATERIALS: the material node writes prim "material" + the detail table. Vertex colours win: prims whose Cd is not all
|
|
727
794
|
white export baseColor white × COLOR_0 with the material's metallic/roughness/emissive; otherwise baseColor = the
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Workspace } from '../workspace.ts';
|
|
2
|
+
import type { ToolDef } from './tools.ts';
|
|
3
|
+
export interface LibraryToolHost {
|
|
4
|
+
/** the workspace the other tools use now */
|
|
5
|
+
workspace(): Workspace;
|
|
6
|
+
/** make a folder the workspace of every tool (and of the live viewer) */
|
|
7
|
+
open(dir: string): Promise<{
|
|
8
|
+
graphs: number;
|
|
9
|
+
assets: number;
|
|
10
|
+
}>;
|
|
11
|
+
}
|
|
12
|
+
export declare function libraryTool(host: LibraryToolHost): ToolDef;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// The `library` tool: the person's libraries of projects (src/gallery/library.ts). An agent
|
|
2
|
+
// lists and searches every library, reads a project, makes new ones, edits their project.json, bakes previews, and
|
|
3
|
+
// opens a project: the server's workspace becomes that project folder, so build/edit/render/export work on it.
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { createProject, graphNames, isStale, listFiles, loadConfig, parseManifest, projectDirOf, readBakeState, readGraph, readManifest, scanAll, writeManifest, } from '../gallery/library.js';
|
|
7
|
+
const text = (t, isError = false) => ({ content: [{ type: 'text', text: t }], ...(isError ? { isError } : {}) });
|
|
8
|
+
export function libraryTool(host) {
|
|
9
|
+
const scan = () => { const cfg = loadConfig(); return { cfg, scans: scanAll(cfg) }; };
|
|
10
|
+
const urlsOf = (cfg, p) => {
|
|
11
|
+
const b = `http://127.0.0.1:${cfg.gallery.port}`;
|
|
12
|
+
return { page: `${b}/p/${p.lib}/${p.id}`, embed: `${b}/embed/${p.lib}/${p.id}`, thumb: `${b}/p/${p.lib}/${p.id}/thumb.png` };
|
|
13
|
+
};
|
|
14
|
+
const currentDir = () => projectDirOf(host.workspace().dir);
|
|
15
|
+
const statusOf = (p) => { const s = readBakeState(p.dir); return !s ? 'not baked' : !s.ok ? 'bake failed' : isStale(p) ? 'stale' : 'baked'; };
|
|
16
|
+
/** {library, id}, {path}, or nothing (the open project) */
|
|
17
|
+
const pick = (a, scans) => {
|
|
18
|
+
const all = scans.flatMap((s) => s.projects);
|
|
19
|
+
if (a.id) {
|
|
20
|
+
const hits = all.filter((p) => p.id === a.id && (!a.library || p.lib === a.library));
|
|
21
|
+
if (hits.length === 1)
|
|
22
|
+
return hits[0];
|
|
23
|
+
if (hits.length > 1)
|
|
24
|
+
throw new Error(`id "${a.id}" is in several libraries (${hits.map((p) => p.lib).join(', ')}): give "library"`);
|
|
25
|
+
throw new Error(`no project "${a.id}"${a.library ? ` in library "${a.library}"` : ''}. library {action:"list"} lists them`);
|
|
26
|
+
}
|
|
27
|
+
const dir = a.path ? projectDirOf(path.resolve(a.path)) : currentDir();
|
|
28
|
+
if (!dir)
|
|
29
|
+
throw new Error(a.path ? `${a.path}: no project.json there or above` : 'give {library, id}: the open workspace is not a library project');
|
|
30
|
+
const p = all.find((x) => x.dir === dir);
|
|
31
|
+
if (p)
|
|
32
|
+
return p;
|
|
33
|
+
// a project folder outside the configured libraries still works
|
|
34
|
+
const m = readManifest(dir);
|
|
35
|
+
return { lib: '', id: m.id, dir, rel: path.basename(dir), collection: '', manifest: m, updated: 0 };
|
|
36
|
+
};
|
|
37
|
+
return {
|
|
38
|
+
name: 'library',
|
|
39
|
+
description: 'The person\'s libraries of projects (the TopoTopo Gallery website shows them; a board links to them). A library is a folder; a project is a folder in it with project.json (title, description, tags, links to concept art/board pages) and is a workspace of its own (graphs/, assets/, inputs/, exports/, attachments/ for concept art and references). ' +
|
|
40
|
+
'list {query?, tag?, library?}: every project with status and gallery URL. get {library, id} (or the open project): manifest, graphs and vars, attachments, exports, bake state, URLs; thumbnail:true adds the baked image. ' +
|
|
41
|
+
'open {library, id} | {path}: make that project the workspace of every tool and the live viewer, then build/edit/render/export work in it. create {library, path:"props/lantern", title?, description?, tags?, links?}: a new project, opened. ' +
|
|
42
|
+
'update {library?, id?, title?, description?, tags?, links?, graph?, bake?}: edit project.json (graph = the graph the gallery shows; bake = {graph?, node?, frame?} what its preview shows). bake {library?, id?}: render thumb.png and preview.glb now (the gallery also bakes on its own after changes). See help topic "library".',
|
|
43
|
+
inputSchema: {
|
|
44
|
+
type: 'object',
|
|
45
|
+
required: ['action'],
|
|
46
|
+
properties: {
|
|
47
|
+
action: { type: 'string', enum: ['list', 'get', 'open', 'create', 'update', 'bake'] },
|
|
48
|
+
library: { type: 'string', description: 'library name (list shows them)' },
|
|
49
|
+
id: { type: 'string', description: 'project id' },
|
|
50
|
+
path: { type: 'string', description: 'create: folder below the library ("props/lantern"); open/get: a project folder on disk instead of {library, id}' },
|
|
51
|
+
query: { type: 'string', description: 'list: words to match in title, id, collection, description, tags' },
|
|
52
|
+
tag: { type: 'string', description: 'list: only projects with this tag' },
|
|
53
|
+
title: { type: 'string' },
|
|
54
|
+
description: { type: 'string' },
|
|
55
|
+
tags: { type: 'array', items: { type: 'string' } },
|
|
56
|
+
links: { type: 'array', items: { type: 'object', properties: { label: { type: 'string' }, url: { type: 'string' } }, required: ['url'] }, description: 'links back to the board, concept pages, tickets' },
|
|
57
|
+
graph: { type: 'string', description: 'update: the graph the gallery shows and bakes (default "main")' },
|
|
58
|
+
bake: { type: 'object', properties: { graph: { type: 'string' }, node: { type: 'string' }, frame: { type: 'number' } }, description: 'update: what the preview shows instead of the graph output' },
|
|
59
|
+
thumbnail: { type: 'boolean', description: 'get: include the baked thumbnail image' },
|
|
60
|
+
open: { type: 'boolean', description: 'create: open the new project (default true)' },
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
run: async (a) => {
|
|
64
|
+
const { cfg, scans } = scan();
|
|
65
|
+
switch (a.action) {
|
|
66
|
+
case 'list': {
|
|
67
|
+
if (!cfg.libraries.length)
|
|
68
|
+
return text(`no libraries configured (${cfg.file}). The person adds one with \`topotopo library add <name> <folder>\`.`);
|
|
69
|
+
const cur = currentDir();
|
|
70
|
+
const words = String(a.query ?? '').toLowerCase().split(/\s+/).filter(Boolean);
|
|
71
|
+
const lines = [];
|
|
72
|
+
for (const s of scans) {
|
|
73
|
+
if (a.library && s.name !== a.library)
|
|
74
|
+
continue;
|
|
75
|
+
const ps = s.projects.filter((p) => {
|
|
76
|
+
const m = p.manifest, hay = [m.title, p.id, p.collection, m.description, ...m.tags].join(' ').toLowerCase();
|
|
77
|
+
return words.every((w) => hay.includes(w)) && (!a.tag || m.tags.includes(a.tag));
|
|
78
|
+
});
|
|
79
|
+
lines.push(`library "${s.name}" (${s.root}): ${ps.length}${ps.length !== s.projects.length ? ` of ${s.projects.length}` : ''} projects`);
|
|
80
|
+
for (const p of ps)
|
|
81
|
+
lines.push(` ${p.id}${p.dir === cur ? ' (open)' : ''} ${p.rel} "${p.manifest.title}"${p.manifest.tags.length ? ` [${p.manifest.tags.join(', ')}]` : ''} ${statusOf(p)} ${urlsOf(cfg, p).page}`);
|
|
82
|
+
for (const pr of s.problems)
|
|
83
|
+
lines.push(` ! ${pr}`);
|
|
84
|
+
}
|
|
85
|
+
return text(lines.join('\n') || 'no library matches');
|
|
86
|
+
}
|
|
87
|
+
case 'get': {
|
|
88
|
+
const p = pick(a, scans), m = p.manifest, s = readBakeState(p.dir), u = urlsOf(cfg, p);
|
|
89
|
+
const graphs = graphNames(p.dir).map((n) => {
|
|
90
|
+
const g = readGraph(p.dir, n) ?? {};
|
|
91
|
+
const vars = Object.entries(g.vars ?? {}).map(([k, v]) => `${k}=${JSON.stringify(v)}`).join(', ');
|
|
92
|
+
return ` ${n}${n === m.graph ? ' (shown)' : ''}: ${Object.keys(g.nodes ?? {}).length} nodes${vars ? `; vars ${vars}` : ''}`;
|
|
93
|
+
});
|
|
94
|
+
const att = listFiles(path.join(p.dir, 'attachments')), exp = listFiles(path.join(p.dir, 'exports'));
|
|
95
|
+
const lines = [
|
|
96
|
+
`project ${p.lib ? `${p.lib}/` : ''}${p.id}: "${m.title}"${p.dir === currentDir() ? ' (open)' : ''}`,
|
|
97
|
+
`folder ${p.dir}`,
|
|
98
|
+
...(m.description ? [`description: ${m.description}`] : []),
|
|
99
|
+
...(m.tags.length ? [`tags: ${m.tags.join(', ')}`] : []),
|
|
100
|
+
...(m.links.length ? ['links:', ...m.links.map((l) => ` ${l.label}: ${l.url}`)] : []),
|
|
101
|
+
`graphs (${graphs.length}):`, ...(graphs.length ? graphs : [' none yet']),
|
|
102
|
+
...(att.length ? [`attachments/ (${att.length}): ${att.slice(0, 30).map((f) => f.path).join(', ')}${att.length > 30 ? ', …' : ''}`] : []),
|
|
103
|
+
...(exp.length ? [`exports/ (${exp.length}): ${exp.slice(0, 30).map((f) => f.path).join(', ')}${exp.length > 30 ? ', …' : ''}`] : []),
|
|
104
|
+
`preview: ${statusOf(p)}${s ? `, baked ${new Date(s.at).toISOString().slice(0, 16)}` : ''}${s && !s.ok ? `: ${s.error}` : ''}${Object.keys(m.bake).length ? `; bake ${JSON.stringify(m.bake)}` : ''}`,
|
|
105
|
+
`gallery: ${u.page} embed: ${u.embed} thumbnail: ${u.thumb}`,
|
|
106
|
+
];
|
|
107
|
+
const content = [{ type: 'text', text: lines.join('\n') }];
|
|
108
|
+
const thumb = path.join(p.dir, '.gallery', 'thumb.png');
|
|
109
|
+
if (a.thumbnail && fs.existsSync(thumb))
|
|
110
|
+
content.push({ type: 'image', data: fs.readFileSync(thumb).toString('base64'), mimeType: 'image/png' });
|
|
111
|
+
return { content };
|
|
112
|
+
}
|
|
113
|
+
case 'open': {
|
|
114
|
+
const p = pick(a, scans);
|
|
115
|
+
const r = await host.open(p.dir);
|
|
116
|
+
return text(`opened ${p.lib ? `${p.lib}/` : ''}${p.id} ("${p.manifest.title}"): the workspace of every tool is now ${p.dir} (${r.graphs} graphs, ${r.assets} assets). ` +
|
|
117
|
+
`Build into graph "${p.manifest.graph}" (the one the gallery shows); put reference images in attachments/ and guide files in inputs/. Gallery page: ${urlsOf(cfg, p).page}`);
|
|
118
|
+
}
|
|
119
|
+
case 'create': {
|
|
120
|
+
if (!a.library)
|
|
121
|
+
throw new Error(`"library" is required (${cfg.libraries.map((l) => l.name).join(', ') || 'none configured'})`);
|
|
122
|
+
if (!a.path)
|
|
123
|
+
throw new Error('"path" is required: the project folder below the library, e.g. "props/lantern"');
|
|
124
|
+
const lib = cfg.libraries.find((l) => l.name === a.library);
|
|
125
|
+
if (!lib)
|
|
126
|
+
throw new Error(`no library "${a.library}" (${cfg.libraries.map((l) => l.name).join(', ') || `none: the person adds one with \`topotopo library add <name> <folder>\``})`);
|
|
127
|
+
const p = createProject(lib, a.path, { title: a.title, description: a.description, tags: a.tags, links: a.links });
|
|
128
|
+
let opened = '';
|
|
129
|
+
if (a.open !== false) {
|
|
130
|
+
await host.open(p.dir);
|
|
131
|
+
opened = ' and opened it: build/edit now work in it (graph "main" is the one the gallery shows)';
|
|
132
|
+
}
|
|
133
|
+
return text(`created ${p.lib}/${p.id} at ${p.dir}${opened}. Gallery page: ${urlsOf(cfg, p).page}`);
|
|
134
|
+
}
|
|
135
|
+
case 'update': {
|
|
136
|
+
const p = pick(a, scans);
|
|
137
|
+
const m = { ...p.manifest };
|
|
138
|
+
for (const k of ['title', 'description', 'tags', 'links', 'graph', 'bake'])
|
|
139
|
+
if (a[k] !== undefined)
|
|
140
|
+
m[k] = a[k];
|
|
141
|
+
const checked = parseManifest(m, p.id);
|
|
142
|
+
writeManifest(p.dir, checked);
|
|
143
|
+
return text(`updated ${p.lib ? `${p.lib}/` : ''}${p.id}: ${JSON.stringify(checked)}`);
|
|
144
|
+
}
|
|
145
|
+
case 'bake': {
|
|
146
|
+
const p = pick(a, scans);
|
|
147
|
+
const { bakeProject } = await import('../gallery/bake.js');
|
|
148
|
+
const s = await bakeProject(p.dir);
|
|
149
|
+
if (!s.ok)
|
|
150
|
+
return text(`bake of ${p.id} failed: ${s.error}`, true);
|
|
151
|
+
const content = [{ type: 'text', text: `baked ${p.id} in ${s.ms} ms: ${s.points} points, ${s.prims} prims${s.glb ? '' : ' (no preview.glb: too large)'}${s.warnings?.length ? `; warnings: ${s.warnings.slice(0, 5).join('; ')}` : ''}` }];
|
|
152
|
+
content.push({ type: 'image', data: fs.readFileSync(path.join(p.dir, '.gallery', 'thumb.png')).toString('base64'), mimeType: 'image/png' });
|
|
153
|
+
return { content };
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return text(`unknown action "${a.action}": list, get, open, create, update or bake`, true);
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
}
|
package/dist/mcp/server.js
CHANGED
|
@@ -14,23 +14,18 @@ import { Engine } from '../graph/engine.js';
|
|
|
14
14
|
import { createNodeHost } from '../host/node.js';
|
|
15
15
|
import { Workspace } from '../workspace.js';
|
|
16
16
|
import { makeTools } from './tools.js';
|
|
17
|
+
import { libraryTool } from './library.js';
|
|
17
18
|
import { INSTRUCTIONS } from './docs.js';
|
|
18
19
|
import { startViewer } from '../viewer/server.js';
|
|
19
20
|
const argv = process.argv.slice(2);
|
|
20
21
|
const argOf = (flag) => { const i = argv.indexOf(flag); return i >= 0 ? argv[i + 1] : undefined; };
|
|
21
22
|
const wsDir = path.resolve(argOf('--workspace') ?? process.env.TOPOTOPO_WORKSPACE ?? path.join(process.cwd(), 'workspace'));
|
|
22
23
|
const log = (...a) => process.stderr.write('[topotopo] ' + a.join(' ') + '\n');
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
await engine.init();
|
|
29
|
-
const ws = new Workspace(wsDir, engine);
|
|
30
|
-
const loaded = ws.load();
|
|
31
|
-
log(`workspace ${wsDir}: ${loaded.graphs} graphs, ${loaded.assets} assets, ${loaded.shelf} shelf assets`);
|
|
32
|
-
for (const e of loaded.assetErrors)
|
|
33
|
-
log('asset error:', e);
|
|
24
|
+
// The workspace can change while the server runs (library {action:"open"} opens a gallery project): every tool and
|
|
25
|
+
// the live viewer then work on the new folder. Each workspace has its own engine (asset registry, base directory,
|
|
26
|
+
// cache); the worker pool is shared by the process. Workspaces follow what other processes write into them
|
|
27
|
+
// (Workspace.watch: the gallery's editor, a person editing JSON).
|
|
28
|
+
let engine, ws, tools;
|
|
34
29
|
let viewer = null;
|
|
35
30
|
const ensureViewer = async () => {
|
|
36
31
|
if (!viewer) {
|
|
@@ -39,9 +34,31 @@ const ensureViewer = async () => {
|
|
|
39
34
|
}
|
|
40
35
|
return viewer.url;
|
|
41
36
|
};
|
|
37
|
+
const library = libraryTool({ workspace: () => ws, open: (dir) => openWorkspace(dir) });
|
|
38
|
+
async function openWorkspace(dir) {
|
|
39
|
+
const e = new Engine(createNodeHost({ baseDir: dir }));
|
|
40
|
+
if (process.env.TOPOTOPO_SCRIPT_TIMEOUT_MS)
|
|
41
|
+
e.scriptTimeoutMs = Number(process.env.TOPOTOPO_SCRIPT_TIMEOUT_MS);
|
|
42
|
+
if (process.env.TOPOTOPO_SIM_TIMEOUT_MS)
|
|
43
|
+
e.simTimeoutMs = Number(process.env.TOPOTOPO_SIM_TIMEOUT_MS);
|
|
44
|
+
await e.init();
|
|
45
|
+
const w = new Workspace(dir, e);
|
|
46
|
+
const loaded = w.load();
|
|
47
|
+
w.watch();
|
|
48
|
+
log(`workspace ${dir}: ${loaded.graphs} graphs, ${loaded.assets} assets, ${loaded.shelf} shelf assets`);
|
|
49
|
+
for (const x of loaded.assetErrors)
|
|
50
|
+
log('asset error:', x);
|
|
51
|
+
const prev = ws;
|
|
52
|
+
engine = e;
|
|
53
|
+
ws = w;
|
|
54
|
+
tools = [...makeTools(w, { onPreview: ensureViewer }), library];
|
|
55
|
+
viewer?.setWorkspace(w);
|
|
56
|
+
prev?.unwatch();
|
|
57
|
+
return loaded;
|
|
58
|
+
}
|
|
59
|
+
await openWorkspace(wsDir);
|
|
42
60
|
if (argv.includes('--viewer') || process.env.TOPOTOPO_VIEWER === '1')
|
|
43
61
|
await ensureViewer();
|
|
44
|
-
const tools = makeTools(ws, { onPreview: ensureViewer });
|
|
45
62
|
// package.json sits two levels above both src/mcp/server.ts and dist/mcp/server.js
|
|
46
63
|
const pkg = JSON.parse(fs.readFileSync(new URL('../../package.json', import.meta.url), 'utf8'));
|
|
47
64
|
const server = new Server({ name: 'topotopo', version: pkg.version }, { capabilities: { tools: {} }, instructions: INSTRUCTIONS });
|
package/dist/mcp/tools.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export interface ToolDef {
|
|
|
25
25
|
* Landscape bundle, or the single file of other formats). Textures are read through the host; USD texture paths are
|
|
26
26
|
* written relative to the output file. Returns the report text.
|
|
27
27
|
*/
|
|
28
|
-
export declare function writeExport(geo: Geometry, format: ExportFormat, p: string, a: any, host: Host): Promise<string>;
|
|
28
|
+
export declare function writeExport(geo: Geometry, format: ExportFormat, p: string, a: any, host: Host, record?: (files: string[]) => void): Promise<string>;
|
|
29
29
|
export declare function makeTools(ws: Workspace, opts?: {
|
|
30
30
|
onPreview?: () => Promise<string>;
|
|
31
31
|
}): ToolDef[];
|