topotopo 0.4.0 → 0.5.1

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 (336) hide show
  1. package/NOTICE +10 -10
  2. package/README.md +460 -117
  3. package/dist/cli.js +327 -147
  4. package/dist/config.d.ts +48 -0
  5. package/dist/config.js +170 -0
  6. package/dist/core/bake.d.ts +14 -3
  7. package/dist/core/bake.js +153 -4
  8. package/dist/core/bevel.d.ts +3 -1
  9. package/dist/core/bevel.js +76 -3
  10. package/dist/core/decimate.d.ts +65 -0
  11. package/dist/core/decimate.js +409 -3
  12. package/dist/core/erosion.d.ts +37 -0
  13. package/dist/core/erosion.js +41 -1
  14. package/dist/core/geometry.d.ts +5 -1
  15. package/dist/core/geometry.js +203 -3
  16. package/dist/core/heightfield.d.ts +27 -4
  17. package/dist/core/heightfield.js +54 -16
  18. package/dist/core/intrinsics.d.ts +7 -0
  19. package/dist/core/intrinsics.js +94 -0
  20. package/dist/core/manifold.d.ts +12 -1
  21. package/dist/core/manifold.js +78 -6
  22. package/dist/core/materials.d.ts +7 -0
  23. package/dist/core/materials.js +45 -0
  24. package/dist/core/noise.d.ts +9 -0
  25. package/dist/core/noise.js +10 -1
  26. package/dist/core/polymerge.d.ts +21 -0
  27. package/dist/core/polymerge.js +327 -0
  28. package/dist/core/repair.d.ts +2 -0
  29. package/dist/core/repair.js +2 -0
  30. package/dist/core/report.d.ts +70 -0
  31. package/dist/core/report.js +275 -0
  32. package/dist/core/scene.js +2 -1
  33. package/dist/core/sha256.d.ts +4 -0
  34. package/dist/core/sha256.js +69 -0
  35. package/dist/core/shapes.d.ts +3 -0
  36. package/dist/core/shapes.js +34 -0
  37. package/dist/core/snippet-lib.d.ts +14 -1
  38. package/dist/core/snippet-lib.js +39 -13
  39. package/dist/core/tangents.d.ts +2 -0
  40. package/dist/core/tangents.js +5 -1
  41. package/dist/core/texnoise.d.ts +6 -1
  42. package/dist/core/texnoise.js +6 -2
  43. package/dist/core/texsdf.d.ts +131 -0
  44. package/dist/core/texsdf.js +637 -0
  45. package/dist/core/texture.d.ts +163 -9
  46. package/dist/core/texture.js +844 -20
  47. package/dist/core/topology.d.ts +10 -0
  48. package/dist/core/topology.js +168 -0
  49. package/dist/core/unwrap.d.ts +72 -0
  50. package/dist/core/unwrap.js +800 -0
  51. package/dist/core/usercode.d.ts +27 -0
  52. package/dist/core/usercode.js +87 -0
  53. package/dist/core/uv.d.ts +4 -18
  54. package/dist/core/uv.js +35 -188
  55. package/dist/core/uvislands.d.ts +62 -0
  56. package/dist/core/uvislands.js +574 -0
  57. package/dist/core/uvoverlap.d.ts +58 -0
  58. package/dist/core/uvoverlap.js +220 -0
  59. package/dist/core/uvpack.d.ts +64 -0
  60. package/dist/core/uvpack.js +628 -0
  61. package/dist/core/uvreport.d.ts +61 -0
  62. package/dist/core/uvreport.js +207 -143
  63. package/dist/core/wrangle.d.ts +6 -1
  64. package/dist/core/wrangle.js +27 -16
  65. package/dist/core/xatlas.d.ts +16 -1
  66. package/dist/core/xatlas.js +66 -62
  67. package/dist/engines.d.ts +63 -0
  68. package/dist/engines.js +180 -0
  69. package/dist/explain.d.ts +4 -3
  70. package/dist/explain.js +129 -12
  71. package/dist/graph/engine.d.ts +92 -29
  72. package/dist/graph/engine.js +298 -148
  73. package/dist/graph/expr.d.ts +6 -3
  74. package/dist/graph/expr.js +18 -8
  75. package/dist/graph/outputs.d.ts +23 -0
  76. package/dist/graph/outputs.js +41 -0
  77. package/dist/graph/packages.d.ts +72 -0
  78. package/dist/graph/packages.js +261 -0
  79. package/dist/graph/parallel.d.ts +3 -1
  80. package/dist/graph/parallel.js +4 -1
  81. package/dist/graph/params.d.ts +6 -0
  82. package/dist/graph/params.js +34 -7
  83. package/dist/graph/scope.d.ts +55 -0
  84. package/dist/graph/scope.js +14 -0
  85. package/dist/graph/types.d.ts +75 -12
  86. package/dist/graph/types.js +4 -2
  87. package/dist/graph/vars.d.ts +16 -0
  88. package/dist/graph/vars.js +80 -0
  89. package/dist/host/artifacts.d.ts +10 -1
  90. package/dist/host/artifacts.js +37 -6
  91. package/dist/host/cook.d.ts +241 -0
  92. package/dist/host/cook.js +844 -0
  93. package/dist/host/export-targets.d.ts +42 -5
  94. package/dist/host/export-targets.js +72 -13
  95. package/dist/host/godot-commands.d.ts +4 -0
  96. package/dist/host/godot-commands.js +21 -0
  97. package/dist/host/godot.d.ts +183 -0
  98. package/dist/host/godot.js +916 -0
  99. package/dist/host/node.d.ts +12 -7
  100. package/dist/host/node.js +27 -9
  101. package/dist/host/pool.js +51 -2
  102. package/dist/host/sidecars.d.ts +8 -0
  103. package/dist/host/sidecars.js +50 -0
  104. package/dist/host/types.d.ts +19 -6
  105. package/dist/host/version.d.ts +1 -0
  106. package/dist/host/version.js +3 -0
  107. package/dist/host/worker.js +5 -2
  108. package/dist/index.d.ts +2 -2
  109. package/dist/index.js +1 -1
  110. package/dist/inspect.d.ts +80 -2
  111. package/dist/inspect.js +265 -30
  112. package/dist/io/common.d.ts +25 -5
  113. package/dist/io/export.js +2 -1
  114. package/dist/io/files.d.ts +23 -4
  115. package/dist/io/files.js +60 -8
  116. package/dist/io/gltf.js +134 -47
  117. package/dist/io/heightmap.d.ts +3 -0
  118. package/dist/io/heightmap.js +1 -0
  119. package/dist/io/import.js +10 -0
  120. package/dist/io/inspect-scene.d.ts +55 -0
  121. package/dist/io/inspect-scene.js +155 -0
  122. package/dist/io/kinds.d.ts +81 -0
  123. package/dist/io/kinds.js +163 -0
  124. package/dist/io/points.d.ts +2 -1
  125. package/dist/io/points.js +3 -1
  126. package/dist/io/sidecars.d.ts +24 -0
  127. package/dist/io/sidecars.js +57 -0
  128. package/dist/io/source.d.ts +65 -0
  129. package/dist/io/source.js +112 -0
  130. package/dist/io/targets.d.ts +47 -3
  131. package/dist/io/targets.js +148 -13
  132. package/dist/io/textures.js +21 -1
  133. package/dist/io/unreal.js +5 -1
  134. package/dist/mcp/docs.d.ts +10 -1
  135. package/dist/mcp/docs.js +786 -143
  136. package/dist/mcp/inputs.d.ts +12 -5
  137. package/dist/mcp/inputs.js +50 -13
  138. package/dist/mcp/server.js +56 -27
  139. package/dist/mcp/tools.d.ts +14 -7
  140. package/dist/mcp/tools.js +198 -103
  141. package/dist/mcp/verify.d.ts +2 -2
  142. package/dist/mcp/verify.js +1 -1
  143. package/dist/mcp/workspace.d.ts +15 -0
  144. package/dist/mcp/workspace.js +349 -0
  145. package/dist/nodes/attributes.js +198 -1
  146. package/dist/nodes/bake.js +151 -47
  147. package/dist/nodes/beam.d.ts +1 -0
  148. package/dist/nodes/beam.js +201 -0
  149. package/dist/nodes/bevel.js +51 -3
  150. package/dist/nodes/cloth.js +2 -0
  151. package/dist/nodes/code.js +21 -9
  152. package/dist/nodes/curves.js +433 -93
  153. package/dist/nodes/flow.js +53 -33
  154. package/dist/nodes/generate.js +12 -38
  155. package/dist/nodes/heightfield.js +248 -77
  156. package/dist/nodes/imageops.js +16 -19
  157. package/dist/nodes/index.d.ts +1 -0
  158. package/dist/nodes/index.js +1 -0
  159. package/dist/nodes/material.js +89 -24
  160. package/dist/nodes/measure.js +43 -17
  161. package/dist/nodes/particles.js +2 -0
  162. package/dist/nodes/pcg.js +6 -5
  163. package/dist/nodes/procedural.js +4 -3
  164. package/dist/nodes/remesh.js +71 -15
  165. package/dist/nodes/scene.js +4 -2
  166. package/dist/nodes/sdf.js +10 -5
  167. package/dist/nodes/solid.js +20 -5
  168. package/dist/nodes/splines.d.ts +15 -1
  169. package/dist/nodes/splines.js +112 -105
  170. package/dist/nodes/texture.d.ts +21 -6
  171. package/dist/nodes/texture.js +1318 -185
  172. package/dist/nodes/topology.d.ts +7 -0
  173. package/dist/nodes/topology.js +133 -6
  174. package/dist/nodes/transform.js +6 -2
  175. package/dist/nodes/uv.js +192 -174
  176. package/dist/nodes/wasmcall.js +5 -1
  177. package/dist/open.d.ts +19 -0
  178. package/dist/open.js +12 -0
  179. package/dist/package.d.ts +288 -0
  180. package/dist/package.js +772 -0
  181. package/dist/packages/check.d.ts +32 -0
  182. package/dist/packages/check.js +169 -0
  183. package/dist/packages/commands.d.ts +57 -0
  184. package/dist/packages/commands.js +537 -0
  185. package/dist/packages/registry.d.ts +796 -0
  186. package/dist/packages/registry.js +2998 -0
  187. package/dist/packages/update.d.ts +124 -0
  188. package/dist/packages/update.js +476 -0
  189. package/dist/render/options.d.ts +2 -0
  190. package/dist/render/options.js +57 -5
  191. package/dist/render/preview.d.ts +17 -4
  192. package/dist/render/preview.js +6 -4
  193. package/dist/render/raster.d.ts +74 -5
  194. package/dist/render/raster.js +527 -143
  195. package/dist/render/texview.d.ts +6 -0
  196. package/dist/render/texview.js +27 -0
  197. package/dist/scan.d.ts +61 -0
  198. package/dist/scan.js +228 -0
  199. package/dist/session.d.ts +311 -0
  200. package/dist/session.js +849 -0
  201. package/dist/viewer/app/api.js +48 -6
  202. package/dist/viewer/app/cooking.js +78 -0
  203. package/dist/viewer/app/embed.js +27 -7
  204. package/dist/viewer/app/export-popover.js +118 -16
  205. package/dist/viewer/app/grid.js +5 -1
  206. package/dist/viewer/app/guides.js +122 -0
  207. package/dist/viewer/app/keymap.js +6 -3
  208. package/dist/viewer/app/layers.js +4 -4
  209. package/dist/viewer/app/main.js +185 -52
  210. package/dist/viewer/app/markers.js +60 -0
  211. package/dist/viewer/app/outliner.js +72 -27
  212. package/dist/viewer/app/output-info.js +45 -0
  213. package/dist/viewer/app/outputs.css +147 -8
  214. package/dist/viewer/app/outputs.js +168 -54
  215. package/dist/viewer/app/packages.js +614 -0
  216. package/dist/viewer/app/props.js +176 -52
  217. package/dist/viewer/app/scene.js +30 -5
  218. package/dist/viewer/app/select.js +4 -3
  219. package/dist/viewer/app/status.js +12 -15
  220. package/dist/viewer/app/style.css +65 -7
  221. package/dist/viewer/app/vars.js +47 -0
  222. package/dist/viewer/app/welcome.js +72 -0
  223. package/dist/viewer/graph-file.d.ts +62 -0
  224. package/dist/viewer/graph-file.js +175 -0
  225. package/dist/viewer/index.html +23 -10
  226. package/dist/viewer/json-edit.d.ts +13 -0
  227. package/dist/viewer/json-edit.js +274 -0
  228. package/dist/viewer/outputs.d.ts +49 -5
  229. package/dist/viewer/outputs.js +264 -56
  230. package/dist/viewer/packages.d.ts +121 -0
  231. package/dist/viewer/packages.js +584 -0
  232. package/dist/viewer/server.d.ts +14 -9
  233. package/dist/viewer/server.js +266 -28
  234. package/dist/web/app/web.css +419 -0
  235. package/dist/web/app/web.js +188 -0
  236. package/dist/{gallery → web}/bake.d.ts +4 -4
  237. package/dist/{gallery → web}/bake.js +24 -15
  238. package/dist/web/folder-page.d.ts +101 -0
  239. package/dist/web/folder-page.js +146 -0
  240. package/dist/web/folders.d.ts +280 -0
  241. package/dist/web/folders.js +970 -0
  242. package/dist/web/library.d.ts +91 -0
  243. package/dist/web/library.js +228 -0
  244. package/dist/web/markdown.d.ts +45 -0
  245. package/dist/web/markdown.js +677 -0
  246. package/dist/web/pages.d.ts +258 -0
  247. package/dist/web/pages.js +301 -0
  248. package/dist/web/server.d.ts +24 -0
  249. package/dist/web/server.js +1068 -0
  250. package/dist/workspace.d.ts +88 -118
  251. package/dist/workspace.js +358 -460
  252. package/integrations/godot/addons/topotopo/LICENSE +202 -0
  253. package/integrations/godot/addons/topotopo/README.md +57 -0
  254. package/integrations/godot/addons/topotopo/context_menu.gd +43 -0
  255. package/integrations/godot/addons/topotopo/dock.gd +266 -0
  256. package/integrations/godot/addons/topotopo/dock.tscn +72 -0
  257. package/integrations/godot/addons/topotopo/export_filter.gd +72 -0
  258. package/integrations/godot/addons/topotopo/gltf_instancing.gd +131 -0
  259. package/integrations/godot/addons/topotopo/icons/topotopo.svg +1 -0
  260. package/integrations/godot/addons/topotopo/inspector.gd +38 -0
  261. package/integrations/godot/addons/topotopo/instances_post_import.gd +111 -0
  262. package/integrations/godot/addons/topotopo/package.gd +23 -0
  263. package/integrations/godot/addons/topotopo/package_importer.gd +187 -0
  264. package/integrations/godot/addons/topotopo/plugin.cfg +7 -0
  265. package/integrations/godot/addons/topotopo/plugin.gd +970 -0
  266. package/integrations/godot/addons/topotopo/record.gd +435 -0
  267. package/integrations/godot/addons/topotopo/runner.gd +458 -0
  268. package/integrations/godot/addons/topotopo/tools/check.gd +42 -0
  269. package/integrations/godot/addons/topotopo/watcher.gd +199 -0
  270. package/kernels/pkg/README.md +2 -1
  271. package/kernels/pkg-simd/README.md +2 -1
  272. package/library/architecture/versions/1.0/architecture.topo +12 -0
  273. package/{shelf → library/architecture/versions/1.0/graphs}/arch.json +3 -3
  274. package/{shelf → library/architecture/versions/1.0/graphs}/beam_truss.json +6 -6
  275. package/{shelf → library/architecture/versions/1.0/graphs}/brick_wall.json +8 -8
  276. package/{shelf → library/architecture/versions/1.0/graphs}/door_frame.json +3 -3
  277. package/{shelf → library/architecture/versions/1.0/graphs}/hex_grid_floor.json +3 -2
  278. package/{shelf → library/architecture/versions/1.0/graphs}/house.json +8 -8
  279. package/library/architecture/versions/1.0/graphs/lineup.json +42 -0
  280. package/{shelf → library/architecture/versions/1.0/graphs}/pillar.json +3 -2
  281. package/{shelf → library/architecture/versions/1.0/graphs}/railing.json +5 -5
  282. package/{shelf → library/architecture/versions/1.0/graphs}/roof_gable.json +2 -2
  283. package/{shelf → library/architecture/versions/1.0/graphs}/roof_hip.json +2 -2
  284. package/{shelf → library/architecture/versions/1.0/graphs}/roof_skeleton.json +2 -1
  285. package/{shelf → library/architecture/versions/1.0/graphs}/scaffold.json +4 -4
  286. package/{shelf → library/architecture/versions/1.0/graphs}/spiral_stairs.json +3 -2
  287. package/{shelf → library/architecture/versions/1.0/graphs}/stairs.json +6 -6
  288. package/{shelf → library/architecture/versions/1.0/graphs}/tile_floor.json +3 -2
  289. package/{shelf → library/architecture/versions/1.0/graphs}/wall_segment.json +10 -10
  290. package/{shelf → library/architecture/versions/1.0/graphs}/window_frame.json +2 -2
  291. package/library/architecture/versions/1.0/version.json +1119 -0
  292. package/{shelf → library/nature/versions/1.0/graphs}/bush.json +2 -2
  293. package/{shelf → library/nature/versions/1.0/graphs}/cliff_block.json +4 -3
  294. package/{shelf → library/nature/versions/1.0/graphs}/forest_patch.json +5 -5
  295. package/{shelf → library/nature/versions/1.0/graphs}/grass_clumps.json +2 -2
  296. package/library/nature/versions/1.0/graphs/lineup.json +24 -0
  297. package/{shelf → library/nature/versions/1.0/graphs}/log.json +6 -6
  298. package/{shelf → library/nature/versions/1.0/graphs}/rock.json +5 -4
  299. package/{shelf → library/nature/versions/1.0/graphs}/scatter_rocks.json +5 -5
  300. package/{shelf → library/nature/versions/1.0/graphs}/tree_lowpoly.json +3 -2
  301. package/library/nature/versions/1.0/nature.topo +12 -0
  302. package/library/nature/versions/1.0/version.json +534 -0
  303. package/{shelf → library/props/versions/1.0/graphs}/barrel.json +5 -4
  304. package/{shelf → library/props/versions/1.0/graphs}/crate.json +3 -3
  305. package/library/props/versions/1.0/graphs/lineup.json +18 -0
  306. package/{shelf → library/props/versions/1.0/graphs}/pallet.json +4 -3
  307. package/{shelf → library/props/versions/1.0/graphs}/pipe_run.json +3 -3
  308. package/{shelf → library/props/versions/1.0/graphs}/sandbag_wall.json +5 -5
  309. package/library/props/versions/1.0/props.topo +12 -0
  310. package/library/props/versions/1.0/version.json +336 -0
  311. package/{shelf → library/street/versions/1.0/graphs}/bench.json +5 -5
  312. package/{shelf → library/street/versions/1.0/graphs}/bollard.json +2 -1
  313. package/{shelf → library/street/versions/1.0/graphs}/cable.json +4 -4
  314. package/{shelf → library/street/versions/1.0/graphs}/fence.json +7 -7
  315. package/{shelf → library/street/versions/1.0/graphs}/lamp_post.json +2 -2
  316. package/library/street/versions/1.0/graphs/lineup.json +22 -0
  317. package/{shelf → library/street/versions/1.0/graphs}/road_strip.json +2 -2
  318. package/{shelf → library/street/versions/1.0/graphs}/sign_post.json +1 -1
  319. package/library/street/versions/1.0/street.topo +12 -0
  320. package/library/street/versions/1.0/version.json +421 -0
  321. package/package.json +13 -8
  322. package/dist/gallery/app/gallery.css +0 -100
  323. package/dist/gallery/app/gallery.js +0 -80
  324. package/dist/gallery/cli.d.ts +0 -4
  325. package/dist/gallery/cli.js +0 -157
  326. package/dist/gallery/library.d.ts +0 -124
  327. package/dist/gallery/library.js +0 -366
  328. package/dist/gallery/pages.d.ts +0 -94
  329. package/dist/gallery/pages.js +0 -148
  330. package/dist/gallery/server.d.ts +0 -21
  331. package/dist/gallery/server.js +0 -391
  332. package/dist/graph/migrate.d.ts +0 -23
  333. package/dist/graph/migrate.js +0 -58
  334. package/dist/mcp/library.d.ts +0 -12
  335. package/dist/mcp/library.js +0 -159
  336. package/shelf/index.json +0 -190
package/dist/cli.js CHANGED
@@ -1,26 +1,58 @@
1
1
  #!/usr/bin/env node
2
2
  // Command line: cook a graph JSON file, then render / export / inspect.
3
- // node src/cli.ts <graph.json> [--node name] [--frame N | --frames A-B[:step]] [--fps 24]
4
- // [--render out.png] [--views quad|quad_uv|turntable|persp|front,top|persp,uv|persp,section] [--checker] [--color-by attr]
3
+ // node src/cli.ts <graph.json> [--node name | --output name] [--var name=value]… [--frame N | --frames A-B[:step]] [--fps 24]
4
+ // [--render out.png] [--views quad|quad_uv|turntable|persp|front_left|front,top|persp,uv|persp,section] [--checker] [--color-by attr]
5
5
  // [--wireframe all|hard|boundary|groups] [--section y:0.5] [--clip x:0.5] [--glyphs N|up|orient|v] [--labels groups,pieces,points,prims,attrib:name]
6
- // [--shading flat|matcap|ao|pbr] [--exposure 0] [--legend] [--size 800] [--render-scale 2] [--export out.glb]
6
+ // [--shading flat|matcap|ao|pbr] [--exposure 0] [--legend] [--size 800|1600x600] [--render-scale 2] [--heightfield-res 256|full]
7
+ // [--transparent] [--no-grid] [--underlay ref.png [--underlay-opacity 0.5] [--underlay-fit bounds|width|height|view]] [--sockets]
8
+ // [--heightfield-layer mask|<layer>|none] [--export out.glb]
7
9
  // [--compress meshopt] [--quantize] [--tangents auto|preserve|none] [--pcg | --pcg-struct] [--attributes P,N,pscale] [--up-axis z] [--scale 100]
8
- // [--instancing packed|expand] [--instances rows|expand] [--no-meshes]
9
- // [--inspect summary|attributes|topology|all|uv [--uv-resolution 1024] [--json]]
10
+ // [--instancing packed|expand] [--instances rows|expand] [--no-meshes] [--custom-attribs | --no-custom-attribs] [--vertex-colors] [--no-materials]
11
+ // [--split-by-name | --no-split-by-name] [--precision 32|64] [--height-min 0 --height-max 100] [--heightfield 0]
12
+ // (every option of the export tool has a flag; booleans take --name / --no-name)
13
+ // [--inspect summary|attributes|topology|all|uv|budget|scene [--uv-resolution 1024] [--json]]
14
+ // --output picks a named output (the graph's "outputs"); --var overrides a graph var for this run (src/graph/vars.ts).
10
15
  // --export formats: .glb .gltf .obj .usda .ply .stl .json .geo (Houdini) .csv .points.json
11
16
  // Packed instances to .csv/.points.json: one row per instance + <name>.meshes.json + <name>_meshes/<Mesh>.glb.
12
17
  // Heightfields: --export terrain.png (16-bit heightmap + terrain.json sidecar for Unreal), .r16/.raw, or
13
18
  // --format mask_png --layers mask,flow; --layer picks the layer;
14
19
  // --format unreal_landscape --export out/level (a directory: heightmap, layers, manifest, objects.glb,
15
20
  // instance stream).
21
+ // Every export records how it was made (src/io/source.ts) in its sidecar or manifest, or in <file>.source.json.
16
22
  // With --frames, --render/--export paths may contain {frame} or {frame:04} (zero-padded);
17
23
  // without a pattern a .0001-style frame number is inserted before the extension.
18
- // node src/cli.ts --catalog | --help-node scatter | --version
19
- // node src/cli.ts mcp [--workspace dir] [--viewer] the MCP server (src/mcp/server.ts) over stdio
24
+ // node src/cli.ts --catalog | --help-node scatter | --help-topic export | --version
25
+ // node src/cli.ts mcp [--package dir] [--viewer] the MCP server (src/mcp/server.ts) over stdio
20
26
  // node src/cli.ts view <graph.json> [--port 7341] live 3D viewer in the browser, re-cooks on every save;
21
27
  // files dropped on the page go to inputs/ beside the graph file
22
- // node src/cli.ts gallery [--port 7340] [--library dir] the gallery website of the libraries (src/gallery/cli.ts)
23
- // node src/cli.ts library add|list|new|bake … libraries and projects; edit <project> opens the live viewer
28
+ // node src/cli.ts web [--port 7340] [--library dir] the web app for the workspaces and libraries (src/packages/commands.ts)
29
+ // node src/cli.ts library add|remove|list|new|bake … registered libraries and packages; edit [folder] opens the
30
+ // live viewer on a package
31
+ // The workspace around packages (src/workspace.ts), a package and the packages it uses (src/packages/commands.ts,
32
+ // src/packages/registry.ts, src/packages/update.ts):
33
+ // node src/cli.ts workspace [folder]
34
+ // node src/cli.ts workspace init [folder] [--name n] [--engine godot:<path>|unreal:<path>|none] [--library <name or folder>] [--follow | --no-follow]
35
+ // node src/cli.ts workspace library add|remove <name or folder> [--workspace <folder>]
36
+ // node src/cli.ts workspace add|list [folder]
37
+ // node src/cli.ts init [folder] [--name owner/name]
38
+ // node src/cli.ts use owner/name [folder] [--version 1.1]
39
+ // node src/cli.ts remove owner/name [folder]
40
+ // node src/cli.ts packages [owner/name] [folder]
41
+ // node src/cli.ts publish [folder] --note "..." [--big] [--dry-run]
42
+ // node src/cli.ts search [words] [folder] [--kind k] [--tag t]
43
+ // node src/cli.ts outdated [folder]
44
+ // node src/cli.ts check [folder]
45
+ // node src/cli.ts update owner/name [folder] [--to 1.4] [--render <folder>]
46
+ // node src/cli.ts update owner/name [folder] --from 1.3 --to 1.4 --apply
47
+ // A graph-file cook adds a package its graph names for the first time (and says so); --locked fails instead, for a
48
+ // build machine. --follow owner/name on a cook or view uses a package's working folder instead of its copy, for
49
+ // looking: exports use the published copy.
50
+ // A package's published outputs cooked into a Godot project, and the Godot plugin (src/host/godot.ts, src/host/cook.ts;
51
+ // integrations/godot/PROTOCOL.md):
52
+ // node src/cli.ts cook <.topo | package folder | folder>... --for godot [--into <folder>] [--flat] [--skip a,b] [--instancing packed|expand] [--adopt] [--force] [--no-cache] [--timeout <s>] [--report <file>] [--progress json] [--quiet]
53
+ // node src/cli.ts cook --jobs <jobs.json> [--force] [--no-cache] [--progress json]
54
+ // node src/cli.ts godot setup <godot project folder> [--no-enable]
55
+ // node src/cli.ts godot status <godot project folder> [--strict] [--json]
24
56
  // Installed from npm the same commands are `topotopo …` (package.json bin → dist/cli.js, built by npm run build).
25
57
  import fs from 'node:fs';
26
58
  import path from 'node:path';
@@ -28,19 +60,29 @@ import zlib from 'node:zlib';
28
60
  import './nodes/index.js';
29
61
  import { Engine } from './graph/engine.js';
30
62
  import { allNodeDefs } from './graph/registry.js';
63
+ import { KINDS } from './graph/outputs.js';
31
64
  import { createNodeHost } from './host/node.js';
32
65
  import { renderGeometryAsync } from './render/raster.js';
33
66
  import { parseViews } from './render/raster.js';
34
67
  import { renderArgs } from './render/options.js';
35
68
  import { encodePNG } from './render/png.js';
36
69
  import { EXPORT_FORMATS, exportFormatFromPath } from './io/export.js';
37
- import { exportFilesAsync } from './io/files.js';
70
+ import { exportSource } from './io/source.js';
71
+ import { packagesUsed } from './graph/packages.js';
72
+ import { PACKAGE_COMMANDS } from './packages/commands.js';
73
+ import { GODOT_COMMANDS } from './host/godot-commands.js';
74
+ import { setProgram } from './package.js';
75
+ import { openPackages } from './packages/registry.js';
38
76
  import { ArtifactStore } from './host/artifacts.js';
39
- import { prepareTarget, writeTargets } from './host/export-targets.js';
40
- import { publishedOutputs } from './io/targets.js';
41
- import { inspect } from './inspect.js';
77
+ import { exportsFolderFor, prepareTarget, serializeExport, writeExportFiles, writeTargets } from './host/export-targets.js';
78
+ import { TOPOTOPO_VERSION } from './host/version.js';
79
+ import { exportOptionsFromFlags, prefixGone, publishedOutputs } from './io/targets.js';
80
+ import { budgetReport, inspect, nodeBudgetInput, summarize } from './inspect.js';
81
+ import { glbSceneReport, sceneReportText } from './io/inspect-scene.js';
42
82
  import { uvReport } from './core/uvreport.js';
43
- import { catalogText, nodeDoc } from './mcp/docs.js';
83
+ import { didYouMean } from './graph/params.js';
84
+ import { parseVarArg, withVars } from './graph/vars.js';
85
+ import { catalogText, nodeDoc, topicList, topicText } from './mcp/docs.js';
44
86
  const argv = process.argv.slice(2);
45
87
  const opt = (f) => { const i = argv.indexOf(f); return i >= 0 ? argv[i + 1] : undefined; };
46
88
  const fail = (msg) => { console.error(msg); process.exit(1); };
@@ -48,120 +90,147 @@ const fail = (msg) => { console.error(msg); process.exit(1); };
48
90
  const graphName = (file) => path.basename(file).replace(/\.json$/i, '').replace(/[^A-Za-z0-9_-]/g, '_').replace(/^[^A-Za-z]/, 'g$&') || 'graph';
49
91
  // the command as the user typed it: the sources from a clone, or the package's bin (dist/cli.js)
50
92
  const prog = import.meta.url.endsWith('.ts') ? 'node src/cli.ts' : 'topotopo';
93
+ // the hints of every command name it so
94
+ setProgram(prog);
51
95
  if (argv.includes('-v') || argv.includes('-V') || argv.includes('--version')) {
52
- // package.json sits one level above both src/cli.ts and dist/cli.js
53
- const pkg = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
54
- console.log(`topotopo ${pkg.version}`);
96
+ console.log(`topotopo ${TOPOTOPO_VERSION}`);
55
97
  process.exit(0);
56
98
  }
57
99
  if (!argv.length || argv.includes('-h') || argv.includes('--help')) {
58
100
  console.log([
59
- `usage: ${prog} <graph.json> [--node n] [--frame N | --frames A-B[:step]] [--fps 24]`,
60
- ' [--render out.png] [--views quad|quad_uv|turntable|persp|front,top|persp,uv|persp,section] [--checker] [--color-by attr] [--export out.glb] [--inspect all|topology|uv] [--uv-resolution 1024] [--json] (uv: overlaps, utilization, texel density; --json: the report as JSON)',
61
- ' [--export-all] (every output with an export target in the graph, into exports/ beside it)',
101
+ `usage: ${prog} <graph.json> [--node n | --output name] [--var name=value]… [--frame N | --frames A-B[:step]] [--fps 24]`,
102
+ ' [--render out.png] [--views quad|quad_uv|turntable|persp|front_left|front,top|persp,uv|persp,section] [--checker] [--color-by attr] [--export out.glb]',
103
+ ' [--inspect summary|attributes|topology|all|uv|budget|scene] [--uv-resolution 1024] [--json]',
104
+ ' summary: one screen (counts, triangles, bbox in mm, parts, materials, images, uv state, closed or open edges)',
105
+ ' topology: a closed solid or why not (open edges after welding seam splits, non-manifold, flipped, inward), with where',
106
+ ' uv: overlaps (in-tile, tiling, across LODs), utilization, texel density; budget: triangles per part, per LOD and per node',
107
+ ' scene: the glb export read back (nodes and parents, meshes, materials, maps, images; takes the export options)',
108
+ ' --json: the uv, budget or scene report as JSON',
109
+ ' [--output name] (a named output, the graph\'s "outputs", instead of the default; render, export and inspect it)',
110
+ ' [--var name=value] (override a graph var for this run; repeat it; numbers, true/false and JSON values are parsed, other text is a string)',
111
+ ' [--export-all] (every output with an export target in the graph, into exports/ of its package folder)',
112
+ ' relative paths in the graph (file nodes, maps) read from its package folder: the nearest folder with a .topo file at or',
113
+ ' above the graph file, else the graph file\'s folder; --render/--export/--underlay paths are relative to the current folder',
114
+ ' [--follow owner/name] (show that package\'s working folder, where the package finds it, instead of its copy, for this run: renders and inspect use it, exports the published copy; repeat it)',
115
+ ' [--locked] (a build machine: a package the graph names that the package does not use, or a copy missing or edited by hand, fails the run instead of being added)',
62
116
  ' render overlays: [--wireframe all|hard|boundary|groups] [--hard-angle 30] [--section y:0.5] [--clip x:0.5[:abs]]',
63
117
  ' [--glyphs N|up|orient|v] [--glyph-attrib a] [--labels groups,pieces,points,prims,attrib:name] [--legend] [--points]',
64
- ' [--shading flat|matcap|ao|pbr] [--exposure 0] [--size 800] [--render-scale 2] [--azimuth 35] [--elevation 25] [--zoom 1] [--look-at x,y,z] [--ortho-scale w]',
118
+ ' [--shading flat|matcap|ao|pbr] [--exposure 0] [--size 800|1600x600] [--render-scale 2]',
119
+ ' views: persp front back left right top bottom front_left front_right back_left back_right uv section texture persp@<az>',
120
+ ' framing: every 3D view fits the bounds; [--zoom 1] is relative to that fit (above 1 only with --look-at or --ortho-scale)',
121
+ ' [--azimuth 35] (degrees around +Y: 0 = camera on +Z at the front, 90 = on +X, the right side) [--elevation 25] (degrees above the horizon)',
122
+ ' [--look-at x,y,z] (world metres, Y up, +Z front) [--ortho-scale 0.5] (metres across an ortho view)',
123
+ ' [--bounds x0,y0,z0,x1,y1,z1] (world metres: every 3D view frames these corners instead of the own box of the geometry, so a sequence shares one camera)',
124
+ ' [--transparent] (PNG with alpha) [--no-grid] [--sockets] (scene empties as labelled dots with orient axes)',
125
+ ' [--underlay ref.png] (a reference PNG behind the 3D views) [--underlay-opacity 0.5] [--underlay-fit bounds|width|height|view]',
65
126
  ' [--textures] (base colour maps on meshes) [--texture name|image/layer|material] (adds the texture view)',
66
127
  ' [--max-triangles 600000] (packed instances drawn; above it an evenly spread subset)',
67
- ' several renders per cook: repeat --render; options after a --render apply to it, options before the first apply to all',
68
- ' e.g. --views top --render h.png --color-by height --render r.png --color-by river',
69
- ' [--no-view-labels] (no view name labels or axis gizmo, e.g. for thumbnails)',
70
- ' export options: [--compress none|meshopt|draco] [--quantize] [--tangents auto|preserve|none] [--pcg | --pcg-struct] [--attributes P,N,pscale] [--up-axis y|z] [--scale 100]',
128
+ ' [--heightfield-res 256|full] (heightfields: quads drawn per side, default 256, said in the footer when a field has more; full = every sample)',
129
+ ' [--heightfield-layer flow] (heightfields: the layer drawn in red, default mask; none draws none)',
130
+ ' [--no-view-labels] (no view name labels or axis gizmo, e.g. for thumbnails) [--no-footer] (no footer strip: the image is the tiles only)',
131
+ ' several renders per cook: repeat --render; the options after a --render apply to that render (up to the next --render),',
132
+ ' options before the first --render apply to every render. Example (both 1200x600):',
133
+ ' --size 1200x600 --render side.png --views front --underlay ref.png --render beauty.png --views front_left --shading pbr',
134
+ ' side.png: the front view over the reference; beauty.png: a pbr three-quarter view. Options after the last of several',
135
+ ' --render apply to it alone (a warning says so)',
136
+ ' export options (every option of the export tool; booleans as --name / --no-name):',
137
+ ' [--compress none|meshopt|draco] [--quantize] [--tangents auto|preserve|none] [--pcg | --pcg-struct] [--attributes P,N,pscale] [--up-axis y|z] [--scale 100]',
138
+ ' [--custom-attribs | --no-custom-attribs] (extra numeric attributes; glTF and USD default off, PLY on) [--materials | --no-materials]',
139
+ ' [--vertex-colors | --no-vertex-colors] (glTF: also write Cd as COLOR_0 on prims with a named material; default off)',
140
+ ' [--split-by-name | --no-split-by-name] [--precision 32|64] (geo) [--layer height] [--height-min 0] [--height-max 100] [--heightfield 0]',
71
141
  ' [--instancing packed|expand] (packed instances: glb/usda/geo keep them by default)',
72
142
  ' [--instances rows|expand] [--no-meshes] (csv/points.json of packed instances: one row per instance + meshes sidecar + GLBs)',
73
143
  ' export formats: .glb .gltf .obj .usda .ply .stl .json .geo (Houdini) .csv .points.json; heightfields .png (png16) .r16,',
74
144
  ' --format mask_png --layers a,b, --format unreal_landscape (a directory bundle; --tile-size 1008 for tiled Landscape);',
75
145
  ' images: --format textures --export out/maps (one PNG per image; --layers a,b or * for extra layers)',
146
+ ' every export records how it was made (graph, graph hash, output, node, frame, fps, vars, seeds, every option with its default, version)',
147
+ ' in its sidecar; replay: --output/--node, --frame, --fps, --var per var, --format and each option as its flag',
148
+ ' (heightmap .json, <name>.meshes.json, landscape.json) or in <file>.source.json beside it; --help-topic export',
76
149
  ' with --frames, output paths may use {frame} or {frame:04}; otherwise out.0001.png style names are written',
77
- ` ${prog} --catalog | --help-node <type> | --version`,
78
- ` ${prog} mcp [--workspace dir] [--viewer] (the MCP server over stdio, for MCP clients)`,
79
- ` ${prog} view <graph.json> [--port 7341] (live 3D viewer in the browser; re-cooks when the file is saved; files dropped on the page go to inputs/ beside it)`,
80
- ` ${prog} gallery [--port 7340] [--library <folder>] [--no-bake] (the gallery website: every library's projects, stable links for a board)`,
81
- ` ${prog} library add <name> <folder> | list | new <library> <folder/name> [--title t] [--tags a,b] | bake <project>|--stale|--all`,
82
- ` ${prog} edit <project folder> [--port 7341] (the live viewer on a gallery project)`,
150
+ ` ${prog} --catalog | --help-node <type> | --help-topic <name> | --version (in a package: the outputs of the packages it uses too, --help-node owner/name/output)`,
151
+ ` ${prog} mcp [--package dir] [--viewer] (the MCP server over stdio, for MCP clients)`,
152
+ ` ${prog} view <graph.json> [--port 7341] [--follow owner/name] (live 3D viewer in the browser; re-cooks when the file is saved; files dropped on the page go to inputs/ beside it)`,
153
+ ` ${prog} web [--port 7340] [--library <folder>] [--no-bake] (the web app: the registered workspaces and every library's packages, stable links for a board)`,
154
+ ` ${prog} library add <name> <folder> | remove <name> | list | new <library or workspace> <folder/name> [--title t] [--tags a,b] | bake <package>|--stale|--all (registered libraries)`,
155
+ ` ${prog} edit [folder] [--port 7341] (the live viewer on a package, default the current folder's)`,
156
+ ' a package and the packages it uses (a folder named must exist; default: the current folder\'s package; kinds: ' + KINDS.join(', ') + '; --help-topic packages):',
157
+ ...PACKAGE_COMMANDS.map((c) => ` ${prog} ${c.usage} (${c.what})`),
158
+ ' Godot (exit 0 ok, 1 an output or package failed, 2 usage or setup; --help-topic godot):',
159
+ ...GODOT_COMMANDS.map((c) => ` ${prog} ${c.usage} (${c.what})`),
83
160
  ].join('\n'));
84
161
  process.exit(0);
85
162
  }
163
+ if (argv.includes('--help-topic')) {
164
+ // the MCP help topics (src/mcp/docs.ts), the same text the help tool returns
165
+ const name = opt('--help-topic');
166
+ const topics = ['overview', ...topicList()];
167
+ if (name === undefined || name.startsWith('-'))
168
+ fail(`--help-topic needs a topic: ${topics.join(', ')}`);
169
+ const text = topicText(name);
170
+ if (text === null) {
171
+ const s = didYouMean(name, topics);
172
+ fail(`unknown topic "${name}"${s.length ? ` (did you mean ${s.join(', ')}?)` : ''}; topics: ${topics.join(', ')}`);
173
+ }
174
+ console.log(text);
175
+ process.exit(0);
176
+ }
86
177
  if (argv.includes('--catalog') || opt('--help-node')) {
87
- // node types plus the shelf assets (house, stairs, …), which the engine registers when it starts
178
+ // node types, the current folder's assets, the outputs of the packages its package uses, and those of TopoTopo's own
179
+ // packages (house, stairs, …) it does not use yet
88
180
  const engine = new Engine(createNodeHost({ baseDir: process.cwd() }));
89
181
  await engine.init();
90
- const defs = [...allNodeDefs(), ...[...engine.assets.values()].map((x) => x.def)];
182
+ const pk = openPackages(engine, process.cwd());
183
+ const defs = [...allNodeDefs(), ...engine.assetsIn().map((x) => x.def), ...engine.packageDefs()];
91
184
  if (argv.includes('--catalog'))
92
- console.log(catalogText(defs));
185
+ console.log(catalogText(defs, { cli: true }));
93
186
  else {
94
- const d = defs.find((x) => x.type === opt('--help-node'));
95
- console.log(d ? nodeDoc(d) : `unknown node "${opt('--help-node')}" (see --catalog)`);
187
+ const name = opt('--help-node');
188
+ // an output of a package this one does not use yet is read where its library holds it (nothing is copied)
189
+ const d = defs.find((x) => x.type === name) ?? (name.includes('/') ? engine.resolveDef(name) ?? pk.describe(name) ?? undefined : undefined);
190
+ // a package output this folder cannot cook as it is (one of TopoTopo's own it does not use, a folder in no package)
191
+ const why = name.includes('/') && !engine.resolveDef(name) ? engine.packageIssue(name) : null;
192
+ const said = why ? `${why.error}${why.hint ? ` (${why.hint})` : ''}` : '';
193
+ console.log(d ? `${nodeDoc(d)}${said ? `\nin this folder: ${said}` : ''}` : said || `unknown node "${name}" (see --catalog)`);
96
194
  }
97
195
  process.exit(0);
98
196
  }
197
+ /** --follow owner/name (repeatable): packages whose working folders a cook uses instead of their copies. */
198
+ const followArgs = argv.flatMap((x, i) => (x === '--follow' ? [argv[i + 1]] : []));
199
+ if (followArgs.some((f) => f === undefined || f.startsWith('--')))
200
+ fail('--follow needs a package: --follow owner/name');
99
201
  if (argv[0] === 'view') {
100
- // `topotopo view <graph.json> [--port 7341]`: cook the file, serve the live 3D viewer, re-cook on every save
202
+ // `topotopo view <graph.json> [--port 7341]`: cook the file, serve the live 3D viewer and follow its saves; the values
203
+ // tuned on the page are session values over the file, written into it on request (src/viewer/graph-file.ts)
101
204
  const file = argv[1];
102
205
  if (!file || file.startsWith('-'))
103
- fail(`usage: ${prog} view <graph.json> [--port 7341]`);
206
+ fail(`usage: ${prog} view <graph.json> [--port 7341] [--follow owner/name]`);
104
207
  if (!fs.existsSync(file))
105
208
  fail(`${prog}: no such graph file "${file}"`);
106
- const os = await import('node:os');
107
- const { Workspace } = await import('./workspace.js');
108
- const { startViewer } = await import('./viewer/server.js');
109
- const dir = path.dirname(path.resolve(file));
110
- const engine = new Engine(createNodeHost({ baseDir: dir }));
111
- await engine.init();
112
- // A scratch workspace holds the graph and assets: the graph file stays the only source. Files dropped on the
113
- // page go to inputs/ beside the graph file instead, made on the first drop: its file nodes read them as
114
- // "inputs/<name>" (the path an MCP workspace uses too), and they outlive the viewer.
115
- const ws = new Workspace(fs.mkdtempSync(path.join(os.tmpdir(), 'topotopo-view-')), engine, { inputs: path.join(dir, 'inputs'), exports: path.join(dir, 'exports') });
116
- ws.load();
117
- const name = graphName(file);
118
- const load = async () => {
119
- let spec;
120
- try {
121
- spec = JSON.parse(fs.readFileSync(file, 'utf8'));
122
- }
123
- catch (e) {
124
- console.error(`${file}: ${e.message} (keeping the last good version)`);
125
- return;
126
- }
127
- ws.setGraph(name, spec);
128
- const r = await ws.cook(name);
129
- console.log(`${r.ok ? 'cooked' : 'FAILED'} ${name} in ${r.ms.toFixed(0)} ms${r.ok ? '' : ': ' + r.errors.map((e) => `${e.node}: ${e.message}`).join('; ')}`);
130
- ws.bump(name);
131
- };
132
- await load();
133
- // an export target set on the page goes into the graph file, the only source here: only "export" keys change
134
- const persistGraph = (g) => {
135
- if (g !== name)
136
- return;
137
- const spec = ws.getGraph(name), raw = JSON.parse(fs.readFileSync(file, 'utf8'));
138
- if (spec.export === undefined)
139
- delete raw.export;
140
- else
141
- raw.export = spec.export;
142
- for (const [id, o] of Object.entries(spec.outputs ?? {})) {
143
- if (!raw.outputs?.[id])
144
- continue;
145
- if (o.export === undefined)
146
- delete raw.outputs[id].export;
147
- else
148
- raw.outputs[id].export = o.export;
149
- }
150
- fs.writeFileSync(file, JSON.stringify(raw, null, 2) + '\n');
151
- };
152
- const v = await startViewer(ws, opt('--port') !== undefined ? Number(opt('--port')) : undefined, { inputsWhere: `beside ${path.basename(file)}`, persistGraph });
153
- console.log(`view: ${v.url} (watching ${file}; files dropped on the page go to ${path.join(path.dirname(file), 'inputs') + path.sep}; Ctrl+C to stop)`);
154
- let timer;
155
- fs.watch(file, () => { clearTimeout(timer); timer = setTimeout(() => { load().catch((e) => console.error(String(e))); }, 150); });
209
+ const { viewGraphFile } = await import('./viewer/graph-file.js');
210
+ try {
211
+ await viewGraphFile(file, { name: graphName(file), port: opt('--port') !== undefined ? Number(opt('--port')) : undefined, follow: followArgs });
212
+ }
213
+ catch (e) {
214
+ fail(`${prog} view: ${e.message}`);
215
+ }
216
+ }
217
+ else if (['web', 'library', 'edit', 'workspace', 'init', 'libraries', 'use', 'remove', 'packages', 'publish', 'search', 'outdated', 'check', 'update'].includes(argv[0])) {
218
+ // the web app, its libraries and its editor; a package and the packages it uses (src/packages/commands.ts). A command that ends
219
+ // gives its exit code; the web app and the editor keep running
220
+ const { commands } = await import('./packages/commands.js');
221
+ const code = await commands[argv[0]](argv.slice(1), prog);
222
+ if (typeof code === 'number')
223
+ process.exit(code);
156
224
  }
157
- else if (argv[0] === 'gallery' || argv[0] === 'library' || argv[0] === 'edit') {
158
- // the gallery website, its libraries and its editor (src/gallery/cli.ts)
159
- const g = await import('./gallery/cli.js');
160
- const run = { gallery: g.galleryCommand, library: g.libraryCommand, edit: g.editCommand }[argv[0]];
161
- await run(argv.slice(1), prog);
225
+ else if (argv[0] === 'cook' || argv[0] === 'godot') {
226
+ // a package's published outputs cooked into a Godot project, and the Godot plugin's setup and status
227
+ // (src/host/godot.ts, src/host/cook.ts): exit 0, 1 (an output or package failed), 2 (usage, setup or protocol)
228
+ const { cookCommand, godotCommand } = await import('./host/godot.js');
229
+ const { consoleIo } = await import('./packages/commands.js');
230
+ process.exit(await (argv[0] === 'cook' ? cookCommand : godotCommand)(argv.slice(1), consoleIo));
162
231
  }
163
232
  else if (argv[0] === 'mcp') {
164
- // `topotopo mcp [--workspace dir] [--viewer]`: the MCP server over stdio; src/mcp/server.ts reads the remaining
233
+ // `topotopo mcp [--package dir] [--viewer]`: the MCP server over stdio; src/mcp/server.ts reads the remaining
165
234
  // arguments from process.argv and runs until the client closes stdin
166
235
  process.argv.splice(2, 1);
167
236
  await import('./mcp/server.js');
@@ -208,9 +277,76 @@ async function cook() {
208
277
  catch (e) {
209
278
  fail(`${prog}: ${file} is not valid JSON: ${e.message}`);
210
279
  }
280
+ // --var name=value (repeatable): the graph's vars for this run; exports record the result, so a manifest replays
281
+ const varArgs = argv.flatMap((x, i) => (x === '--var' ? [argv[i + 1]] : []));
282
+ if (varArgs.some((v) => v === undefined || v.startsWith('--')))
283
+ fail('--var needs name=value (e.g. --var relief=8)');
284
+ try {
285
+ graph = withVars(graph, varArgs.map(parseVarArg));
286
+ }
287
+ catch (e) {
288
+ fail(`--var: ${e.message}`);
289
+ }
290
+ // --output name: a named output (graph.outputs) instead of the default output
291
+ const outputName = opt('--output');
292
+ if (argv.includes('--output') && (outputName === undefined || outputName.startsWith('--')))
293
+ fail('--output needs the name of one of the graph\'s outputs');
294
+ if (outputName !== undefined && opt('--node') !== undefined)
295
+ fail('use either --node or --output, not both');
296
+ let target = opt('--node');
297
+ if (target !== undefined && graph?.nodes && !Object.hasOwn(graph.nodes, target) && graph?.outputs && Object.hasOwn(graph.outputs, target))
298
+ fail(`--node: ${file} has no node "${target}", but an output of that name: --output ${target}`);
299
+ if (outputName !== undefined) {
300
+ const outs = graph?.outputs && typeof graph.outputs === 'object' ? graph.outputs : {};
301
+ const o = Object.hasOwn(outs, outputName) ? outs[outputName] : undefined;
302
+ if (!o || typeof o.node !== 'string') {
303
+ const names = Object.keys(outs), s = didYouMean(outputName, names);
304
+ const isNode = !!graph?.nodes && typeof graph.nodes === 'object' && Object.hasOwn(graph.nodes, outputName);
305
+ fail(`--output: ${file} has no output "${outputName}"${isNode ? `, but a node of that name: --node ${outputName}` : s.length ? ` (did you mean ${s.join(', ')}?)` : ''}; ${names.length ? `its outputs: ${names.join(', ')}` : 'it publishes no "outputs" (--node picks any node)'}`);
306
+ }
307
+ target = o.node;
308
+ }
211
309
  const engine = new Engine(createNodeHost({ baseDir: path.dirname(path.resolve(file)) }));
212
310
  await engine.init();
213
- const target = opt('--node');
311
+ // the packages the file's package uses: one the graph names for the first time is added (said), and
312
+ // --follow uses a package's working folder for this run. A graph that does not validate as a dry run sees it adds
313
+ // nothing: its errors are said and the run ends. --locked (a build machine) adds nothing and changes no file: a
314
+ // package it does not use, or a copy missing or edited by hand, fails the run instead.
315
+ let pk;
316
+ try {
317
+ pk = openPackages(engine, path.dirname(path.resolve(file)), { follow: followArgs });
318
+ }
319
+ catch (e) {
320
+ fail(`--follow: ${e.message}`);
321
+ }
322
+ const dry = pk.dryRun(graph);
323
+ const invalid = engine.validate(graph, '', { ...engine.root, id: dry.id, packages: dry.resolver }).errors;
324
+ if (invalid.length)
325
+ fail(invalid.map((e) => `error [${e.node}] ${e.message}${e.hint ? ` (hint: ${e.hint})` : ''}`).join('\n'));
326
+ if (argv.includes('--locked')) {
327
+ const unlocked = pk.locked(graph);
328
+ if (unlocked.length)
329
+ fail(unlocked.map((x) => `--locked: ${x}`).join('\n'));
330
+ }
331
+ else
332
+ for (const n of pk.addFor(graph))
333
+ console.log(n);
334
+ for (const p of pk.check())
335
+ console.error(`warning: ${p}`);
336
+ for (const f of pk.following())
337
+ console.log(`following ${f.package}: its working folder ${f.dir} instead of its copy, for renders and inspect (exports use the published copy)`);
338
+ // the packages shown live (--follow, a workspace that follows its own) are for looking: an export cooks with their
339
+ // published copies (a cook of its own when the graph names one) and says so
340
+ const exportNote = pk.publishedNote(graph);
341
+ const exportScope = exportNote ? pk.published() : null;
342
+ const forExport = async (r, node = r.target) => {
343
+ if (!exportScope)
344
+ return r;
345
+ const e = await engine.cook(graph, { target: node, frame: r.frame, fps: r.fps, scope: exportScope });
346
+ if (!e.ok || !e.geo)
347
+ fail(`export: with the published copies, ${node} does not cook (${e.errors.map((x) => `${x.node}: ${x.message}`).join('; ') || 'no geometry'}); nothing was written`);
348
+ return e;
349
+ };
214
350
  const fps = opt('--fps') !== undefined ? Number(opt('--fps')) : undefined;
215
351
  const framesArg = opt('--frames');
216
352
  const frameArg = opt('--frame');
@@ -221,26 +357,66 @@ async function cook() {
221
357
  const single = frameArg !== undefined ? Number(frameArg) : undefined;
222
358
  if (single !== undefined && !Number.isFinite(single))
223
359
  fail(`--frame expects a number, got "${frameArg}"`);
360
+ // --inspect <detail>: checked before cooking
361
+ const INSPECT_DETAILS = ['summary', 'attributes', 'topology', 'all', 'uv', 'budget', 'scene'];
362
+ const inspectDetail = opt('--inspect');
363
+ if (argv.includes('--inspect') && (inspectDetail === undefined || !INSPECT_DETAILS.includes(inspectDetail))) {
364
+ const s = inspectDetail ? didYouMean(inspectDetail, INSPECT_DETAILS) : [];
365
+ fail(`--inspect needs one of ${INSPECT_DETAILS.join(', ')}${inspectDetail ? `, got "${inspectDetail}"${s.length ? ` (did you mean ${s.join(', ')}?)` : ''}` : ''}`);
366
+ }
367
+ const uvRes = opt('--uv-resolution') !== undefined ? Number(opt('--uv-resolution')) : undefined;
368
+ /** The --inspect report of a cook: text, or the uv / budget / scene report as JSON with --json. */
369
+ async function inspectText(r) {
370
+ const geo = r.geo, json = argv.includes('--json');
371
+ if (inspectDetail === 'scene') {
372
+ // the glb export with the export options given, read back
373
+ const res = await serializeExport(geo, 'glb', 'scene.glb', exportArgs(), engine.host);
374
+ const glb = res.files.find((f) => /\.glb$/i.test(f.path));
375
+ if (!glb)
376
+ return 'scene: the glb export wrote no file';
377
+ const rep = glbSceneReport(glb.bytes);
378
+ const warn = res.warnings.map((w) => `warning: ${w}`);
379
+ return json ? JSON.stringify(rep, null, 2) : [...sceneReportText(rep), ...warn].join('\n');
380
+ }
381
+ if (inspectDetail === 'uv' && json)
382
+ return JSON.stringify(uvReport(geo, { resolution: uvRes }), null, 2);
383
+ if (inspectDetail === 'budget' && json)
384
+ return JSON.stringify(budgetReport(geo, nodeBudgetInput(graph, r.results)), null, 2);
385
+ return inspect(geo, { detail: inspectDetail, uvResolution: uvRes, nodes: inspectDetail === 'budget' ? nodeBudgetInput(graph, r.results) : undefined });
386
+ }
224
387
  function report(r) {
225
388
  for (const e of r.errors)
226
389
  console.error(`error [${e.node}] ${e.message}${e.hint ? ` (hint: ${e.hint})` : ''}`);
227
390
  for (const w of r.warnings)
228
391
  console.error(`warning [${w.node}] ${w.message}`);
229
392
  }
393
+ /** Every render flag (renderFlags reads them, plus --views, --color-by, --checker). */
394
+ const RENDER_FLAGS = ['--wireframe', '--hard-angle', '--section', '--clip', '--glyphs', '--glyph-attrib', '--glyph-scale', '--max-glyphs', '--labels', '--max-labels',
395
+ '--shading', '--ao-radius', '--size', '--render-scale', '--azimuth', '--elevation', '--zoom', '--look-at', '--bounds', '--ortho-scale', '--texture', '--max-triangles', '--exposure',
396
+ '--heightfield-res', '--heightfield-layer', '--underlay', '--underlay-opacity', '--underlay-fit', '--legend', '--points', '--annotate', '--textures', '--transparent',
397
+ '--sockets', '--no-view-labels', '--no-footer', '--no-grid', '--views', '--color-by', '--checker'];
230
398
  /** Render overlay flags → render tool arguments → RenderOptions (src/render/options.ts). */
231
399
  function renderFlags(get, has) {
232
400
  const a = {};
233
401
  for (const [f, k] of [['--wireframe', 'wireframe'], ['--hard-angle', 'hard_angle'], ['--section', 'section'], ['--clip', 'clip'], ['--glyphs', 'glyphs'],
234
402
  ['--glyph-attrib', 'glyph_attrib'], ['--glyph-scale', 'glyph_scale'], ['--max-glyphs', 'max_glyphs'], ['--labels', 'labels'], ['--max-labels', 'max_labels'],
235
403
  ['--shading', 'shading'], ['--ao-radius', 'ao_radius'], ['--size', 'size'], ['--render-scale', 'scale'], ['--azimuth', 'azimuth'], ['--elevation', 'elevation'],
236
- ['--zoom', 'zoom'], ['--look-at', 'look_at'], ['--ortho-scale', 'ortho_scale'], ['--texture', 'texture'], ['--max-triangles', 'max_triangles'], ['--exposure', 'exposure']])
404
+ ['--zoom', 'zoom'], ['--look-at', 'look_at'], ['--bounds', 'bounds'], ['--ortho-scale', 'ortho_scale'], ['--texture', 'texture'], ['--max-triangles', 'max_triangles'], ['--exposure', 'exposure'],
405
+ ['--heightfield-res', 'heightfield_res'], ['--heightfield-layer', 'heightfield_layer'], ['--underlay-opacity', 'underlay_opacity'], ['--underlay-fit', 'underlay_fit']])
237
406
  if (get(f) !== undefined)
238
407
  a[k] = get(f);
239
- for (const [f, k] of [['--legend', 'legend'], ['--points', 'points'], ['--annotate', 'annotate'], ['--textures', 'textures']])
408
+ for (const [f, k] of [['--legend', 'legend'], ['--points', 'points'], ['--annotate', 'annotate'], ['--textures', 'textures'], ['--transparent', 'transparent'], ['--sockets', 'sockets']])
240
409
  if (has(f))
241
410
  a[k] = true;
242
411
  if (has('--no-view-labels'))
243
412
  a.view_labels = false;
413
+ if (has('--no-grid'))
414
+ a.grid = false;
415
+ if (has('--no-footer'))
416
+ a.footer = false;
417
+ // a reference image path is relative to the current folder, as the output paths are
418
+ if (get('--underlay') !== undefined)
419
+ a.underlay = path.resolve(get('--underlay'));
244
420
  try {
245
421
  return renderArgs(a);
246
422
  }
@@ -252,6 +428,13 @@ async function cook() {
252
428
  // --render; options before the first --render apply to all of them. With one --render this is the old behaviour.
253
429
  const renderAt = argv.flatMap((x, i) => (x === '--render' ? [i] : []));
254
430
  const sharedArgs = argv.slice(0, renderAt.length ? renderAt[0] : argv.length);
431
+ // with several renders, options after the last --render belong to that render only: say so (a person who meant them
432
+ // for every render puts them before the first --render)
433
+ if (renderAt.length > 1) {
434
+ const last = argv.slice(renderAt[renderAt.length - 1] + 2).filter((x) => RENDER_FLAGS.includes(x));
435
+ if (last.length)
436
+ console.error(`warning: ${last.join(' ')} after the last --render apply to ${argv[renderAt[renderAt.length - 1] + 1]} only; options before the first --render apply to every render`);
437
+ }
255
438
  const renders = renderAt.map((start, n) => {
256
439
  const seg = argv.slice(start, n + 1 < renderAt.length ? renderAt[n + 1] : argv.length);
257
440
  if (!seg[1] || seg[1].startsWith('--'))
@@ -262,9 +445,9 @@ async function cook() {
262
445
  async function writeOutputs(r, frame) {
263
446
  const geo = r.geo;
264
447
  const at = (p) => (frame === undefined ? p : framePath(p, frame));
265
- // Receipts for the viewer's saved files, only for files inside exports/ beside the graph: a run whose output goes
266
- // elsewhere leaves no exports/ folder behind (the viewer lists that folder's files without receipts too).
267
- const exportsDir = path.join(path.dirname(path.resolve(file)), 'exports');
448
+ // Receipts for the viewer's saved files, only for files inside the package's exports/ (exportsFolderFor): a run whose
449
+ // output goes elsewhere leaves no exports/ folder behind (the viewer lists that folder's files without receipts too).
450
+ const exportsDir = exportsFolderFor(file);
268
451
  const record = (paths, format) => {
269
452
  const inside = paths.every((p) => { const rel = path.relative(exportsDir, path.resolve(p)); return !!rel && !rel.startsWith('..') && !path.isAbsolute(rel); });
270
453
  if (inside)
@@ -293,40 +476,30 @@ async function cook() {
293
476
  const fmt = ({ png: 'png16', raw: 'r16' }[raw] ?? raw);
294
477
  if (!EXPORT_FORMATS.includes(fmt))
295
478
  fail(`unknown export format "${fmt}" (${EXPORT_FORMATS.join(', ')}); pass --format`);
296
- const up = opt('--up-axis');
297
- if (argv.includes('--tile-size') && opt('--tile-size') === undefined)
298
- fail('--tile-size requires a number of quads (e.g. 1008)');
299
- if (opt('--tangents') !== undefined && !['auto', 'preserve', 'none'].includes(opt('--tangents')))
300
- fail(`--tangents must be auto, preserve or none (got "${opt('--tangents')}")`);
301
- const outDir = fmt === 'unreal_landscape' && !/\.json$/i.test(p) ? path.resolve(p) : path.dirname(path.resolve(p));
302
- const host = engine.host;
303
- const { files, summary } = await exportFilesAsync(geo, fmt, p, {
304
- splitByName: true,
305
- compress: opt('--compress'),
306
- quantize: argv.includes('--quantize') || undefined,
307
- tangents: opt('--tangents'),
308
- pcg: argv.includes('--pcg') || argv.includes('--pcg-struct') || undefined,
309
- pcgStruct: argv.includes('--pcg-struct') || undefined,
310
- attributes: opt('--attributes'),
311
- upAxis: up === 'z' || up === 'y' ? up : undefined,
312
- scale: opt('--scale') !== undefined ? Number(opt('--scale')) : undefined,
313
- instancing: opt('--instancing') === 'expand' ? 'expand' : undefined,
314
- instances: opt('--instances') === 'expand' ? 'expand' : undefined,
315
- meshes: argv.includes('--no-meshes') ? false : undefined,
316
- layer: opt('--layer'), layers: opt('--layers')?.split(','),
317
- tile_size: opt('--tile-size') !== undefined ? Number(opt('--tile-size')) : undefined,
318
- deflate: (d) => zlib.deflateSync(d),
319
- readFile: (t) => host.readFile(t),
320
- texturePath: (t) => { const abs = host.resolvePath(t); return /^[a-z][a-z0-9+.-]*:\/\//i.test(abs) ? abs : path.relative(outDir, abs).split(path.sep).join('/'); },
321
- warn: (m) => console.warn(`warning: ${m}`),
322
- });
323
- for (const f of files) {
324
- fs.mkdirSync(path.dirname(path.resolve(f.path)), { recursive: true });
325
- fs.writeFileSync(f.path, f.bytes);
326
- }
327
- if (files.length)
328
- record(files.map((f) => f.path), fmt);
329
- console.log(`exported ${files.length === 1 ? files[0].path : files.map((f) => f.path).join(', ')}${files.length > 1 || fmt !== 'glb' ? ` — ${summary}` : ''}`);
479
+ // the export tool's options (the MCP export tool and export targets use the same names and code)
480
+ const a = exportArgs();
481
+ const x = await forExport(r);
482
+ const source = exportSource({ graph: graphName(file), spec: graph, node: r.target, output: outputName, frame: r.frame, fps: r.fps, format: fmt, options: a, packages: packagesUsed(engine, graph, exportScope ?? engine.root), version: TOPOTOPO_VERSION });
483
+ const res = await serializeExport(x.geo, fmt, p, a, engine.host, source);
484
+ for (const w of res.warnings)
485
+ console.warn(`warning: ${w}`);
486
+ writeExportFiles(res.files);
487
+ if (res.files.length)
488
+ record(res.files.map((f) => f.path), fmt);
489
+ const files = res.files.filter((f) => f.path !== res.sourceManifest);
490
+ console.log(`exported ${files.length === 1 ? files[0].path : files.map((f) => f.path).join(', ')}${files.length > 1 || fmt !== 'glb' ? ` — ${res.summary}` : ''}${res.sourceFile ? `; source: ${res.sourceFile}` : ''}`);
491
+ if (exportNote)
492
+ console.log(exportNote);
493
+ }
494
+ }
495
+ /** The export flags given, as the export tool's options (snake_case, as export targets and the MCP export tool name them). */
496
+ function exportArgs() {
497
+ // every option of the export tool has a flag: --name value, booleans --name / --no-name (io/targets.ts)
498
+ try {
499
+ return exportOptionsFromFlags(argv);
500
+ }
501
+ catch (e) {
502
+ return fail(`export: ${e.message}`);
330
503
  }
331
504
  }
332
505
  if (framesArg) {
@@ -337,8 +510,8 @@ async function cook() {
337
510
  return;
338
511
  const cooked = [...r.results.values()].filter((n) => !n.cached && !n.error).length;
339
512
  console.log(`frame ${f}: ${r.target} in ${r.ms.toFixed(0)} ms (${cooked} node(s) cooked) — ${r.geo.numPoints} points, ${r.geo.numPrims} prims`);
340
- if (opt('--inspect'))
341
- console.log(inspect(r.geo, { detail: opt('--inspect') }));
513
+ if (inspectDetail)
514
+ console.log(await inspectText(r));
342
515
  await writeOutputs(r, f);
343
516
  }, { target, fps });
344
517
  console.log(`cooked ${file} frames ${range.start}-${range.end}${range.step !== 1 ? `:${range.step}` : ''}: ${res.frames - res.failed.length}/${res.frames} ok`);
@@ -350,37 +523,44 @@ async function cook() {
350
523
  report(r);
351
524
  if (!r.ok || !r.geo)
352
525
  process.exit(1);
353
- console.log(`cooked ${file} → ${r.target}${r.frame !== 1 ? ` at frame ${r.frame}` : ''} in ${r.ms.toFixed(0)} ms`);
354
- if (opt('--inspect') === 'uv' && argv.includes('--json'))
355
- console.log(JSON.stringify(uvReport(r.geo, { resolution: opt('--uv-resolution') !== undefined ? Number(opt('--uv-resolution')) : undefined }), null, 2));
356
- else
357
- console.log(inspect(r.geo, { detail: opt('--inspect') ?? 'summary', uvResolution: opt('--uv-resolution') !== undefined ? Number(opt('--uv-resolution')) : undefined }));
526
+ const vars = varArgs.length ? ` with ${varArgs.map((v) => v.trim()).join(', ')}` : '';
527
+ console.log(`cooked ${file} → ${outputName !== undefined ? `output "${outputName}" (${r.target})` : r.target}${r.frame !== 1 ? ` at frame ${r.frame}` : ''}${vars} in ${r.ms.toFixed(0)} ms`);
528
+ // without --inspect the short summary; --inspect <detail> the report (src/inspect.ts, io/inspect-scene.ts)
529
+ console.log(inspectDetail ? await inspectText(r) : summarize(r.geo));
358
530
  await writeOutputs(r);
359
531
  if (argv.includes('--export-all'))
360
532
  await exportAll();
361
533
  }
362
- /** --export-all: every published output with an export target (io/targets.ts), into exports/ beside the graph. */
534
+ /** --export-all: every published output with an export target (io/targets.ts), into the package's exports/ (exportsFolderFor). */
363
535
  async function exportAll() {
364
- const name = graphName(file), exportsDir = path.join(path.dirname(path.resolve(file)), 'exports');
536
+ const name = graphName(file), exportsDir = exportsFolderFor(file);
365
537
  const published = publishedOutputs(name, graph, engine.findOutput(graph).name);
366
538
  if (!published.some((p) => p.target))
367
539
  fail(`--export-all: no output of ${file} has an export target; add "export": "glb" to the graph (default output) or to an entry of "outputs"`);
368
540
  const prepared = [];
541
+ // a target the export refuses (its path written with a prefix that is gone) fails the run before anything cooks
542
+ const refused = published.find((p) => p.target?.refused);
543
+ if (refused)
544
+ fail(`--export-all: "${refused.label}": ${prefixGone(refused.target.refused)}; nothing was written`);
369
545
  for (const p of published) {
370
546
  if (!p.target)
371
547
  continue;
372
- const r = await engine.cook(graph, { target: p.node, frame: single, fps });
548
+ const r = await engine.cook(graph, { target: p.node, frame: single, fps, ...(exportScope ? { scope: exportScope } : {}) });
373
549
  report(r);
374
550
  if (!r.ok || !r.geo)
375
- fail(`--export-all: "${p.label}" did not cook; nothing was written`);
376
- prepared.push(await prepareTarget(r.geo, name, p, exportsDir, engine.host));
551
+ fail(`--export-all: "${p.label}" did not cook${exportScope ? ' with the published copies' : ''}; nothing was written`);
552
+ prepared.push(await prepareTarget(r.geo, name, p, exportsDir, engine.host, { frame: r.frame, fps: r.fps, packages: packagesUsed(engine, graph, exportScope ?? engine.root) }));
377
553
  }
378
554
  writeTargets(prepared, exportsDir);
555
+ // paths as the person finds them from where they ran the command
556
+ const rel = (f) => path.relative(process.cwd(), f) || f;
379
557
  for (const p of prepared)
380
- console.log(`exported ${p.label} → ${path.join('exports', ...p.target.path.split('/'))} — ${p.summary}`);
558
+ console.log(`exported ${p.label} → ${rel(path.join(p.root, ...p.target.path.split('/')))} — ${p.summary}${p.sourceFile ? `; source: ${rel(p.sourceFile)}` : ''}`);
381
559
  const skipped = published.filter((p) => !p.target).map((p) => p.label);
382
560
  if (skipped.length)
383
561
  console.log(`no export target (skipped): ${skipped.join(', ')}`);
562
+ if (exportNote)
563
+ console.log(exportNote);
384
564
  }
385
565
  // stop the kernel worker threads (idle ones would not hold the process, but a clean exit should not wait on them)
386
566
  await engine.host.pool?.close();