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
@@ -0,0 +1,81 @@
1
+ import type { Geometry } from '../core/geometry.ts';
2
+ import type { Kind } from '../graph/outputs.ts';
3
+ import type { ExportFormat } from './export.ts';
4
+ /** What an output can hold, in the order a mixed output names them (its main part first). */
5
+ export declare const OUTPUT_PARTS: readonly ['heightfield', 'mesh', 'instances', 'curves', 'points', 'image', 'material', 'volume'];
6
+ export type OutputPart = (typeof OUTPUT_PARTS)[number];
7
+ /** One part, several (mixed), or nothing. */
8
+ export type OutputKind = OutputPart | 'mixed' | 'empty';
9
+ /**
10
+ * The formats that write each part, best first. json (TopoTopo JSON, lossless) writes everything except analytic
11
+ * SDFs; obj, ply and stl write packed instances expanded into geometry; unreal_landscape writes the prims (meshes,
12
+ * curves, instances) beside the heightfield it needs. Images here are image outputs: glb, gltf and usda also write the
13
+ * textures their materials use.
14
+ */
15
+ export declare const PART_FORMATS: Record<OutputPart, readonly ExportFormat[]>;
16
+ export interface HeightfieldInfo {
17
+ name: string;
18
+ /** samples along X and Z */
19
+ width: number;
20
+ height: number;
21
+ /** sample spacing (metres) */
22
+ cell: number;
23
+ /** every layer with its range */
24
+ layers: {
25
+ name: string;
26
+ min: number;
27
+ max: number;
28
+ }[];
29
+ }
30
+ export interface OutputInfo {
31
+ kind: OutputKind;
32
+ /** its kind in the words everything shows (graph/outputs.ts KINDS: terrain, textures, scene …), null when empty */
33
+ published: Kind | null;
34
+ /** the parts it holds, main first (OUTPUT_PARTS order) */
35
+ parts: OutputPart[];
36
+ /** its size in a few words, beside its kind: "2049 × 2049 samples, 2 m apart"; a scene's parts each by kind */
37
+ text: string;
38
+ /** bounding box size (x, y, z) in metres; null for images alone and for nothing */
39
+ size: [number, number, number] | null;
40
+ /** the first heightfield, and how many there are */
41
+ heightfield?: HeightfieldInfo;
42
+ heightfields: number;
43
+ /** the images it carries (its own and its packed sources'), as an image output or as textures of its parts */
44
+ images: number;
45
+ /** the materials of a material output (none for the other kinds: their materials belong to their parts) */
46
+ materials: number;
47
+ /** sampled SDF grids (TopoTopo JSON stores them; analytic SDFs are functions, which no format writes) */
48
+ grids: number;
49
+ }
50
+ /** What a cooked geometry is. */
51
+ export declare function outputKind(g: Geometry): OutputInfo;
52
+ /**
53
+ * The kind a published output records (src/graph/outputs.ts KINDS): its one part as named, a heightfield a terrain and
54
+ * an image textures; scene for several parts; null for an empty output, which is no kind (publishing blocks it).
55
+ */
56
+ export declare function publishedKind(o: Pick<OutputInfo, 'kind'>): Kind | null;
57
+ /**
58
+ * What an output whose author pinned its kind (graph.outputs[id].kind) says when it cooks to another kind or to
59
+ * nothing (null: it is the kind pinned). Build and the viewer warn with it; publishing blocks.
60
+ */
61
+ export declare function kindMismatch(pinned: string, o: OutputInfo): string | null;
62
+ /** A bounding size in words: "4096 × 312 × 4096 m". */
63
+ export declare const sizeText: (s: readonly number[]) => string;
64
+ export interface FormatFit {
65
+ format: ExportFormat;
66
+ label: string;
67
+ /** the target file's extension ('' for the folder formats) */
68
+ extension: string;
69
+ /** what it writes, in a line */
70
+ writes: string;
71
+ /** the parts of the output it does not write (none: all of it) */
72
+ leaves: OutputPart[];
73
+ /** a download is the file itself (it carries how it was made); otherwise a zip of the files */
74
+ oneFile: boolean;
75
+ }
76
+ /**
77
+ * The formats that write some of the output, best first: those that write all of it, in the order of its main part,
78
+ * then those that write a part, part by part; json (lossless, for TopoTopo itself) last. Nothing for an empty output,
79
+ * or one of analytic SDFs alone (sdf_to_mesh makes them a mesh).
80
+ */
81
+ export declare function fittingFormats(o: OutputInfo): FormatFit[];
@@ -0,0 +1,163 @@
1
+ import { heightfieldsOf, layerStats } from '../core/heightfield.js';
2
+ import { referenceableImages } from '../core/image.js';
3
+ import { readMaterials } from '../core/materials.js';
4
+ import { FORMAT_LABELS, targetExtension } from './targets.js';
5
+ import { SOURCE_INSIDE, formatWrites } from './files.js';
6
+ /** What an output can hold, in the order a mixed output names them (its main part first). */
7
+ export const OUTPUT_PARTS = ['heightfield', 'mesh', 'instances', 'curves', 'points', 'image', 'material', 'volume'];
8
+ /**
9
+ * The formats that write each part, best first. json (TopoTopo JSON, lossless) writes everything except analytic
10
+ * SDFs; obj, ply and stl write packed instances expanded into geometry; unreal_landscape writes the prims (meshes,
11
+ * curves, instances) beside the heightfield it needs. Images here are image outputs: glb, gltf and usda also write the
12
+ * textures their materials use.
13
+ */
14
+ export const PART_FORMATS = {
15
+ heightfield: ['png16', 'r16', 'mask_png', 'unreal_landscape', 'json'],
16
+ instances: ['glb', 'usda', 'csv', 'pointsjson', 'gltf', 'geo', 'unreal_landscape', 'obj', 'ply', 'stl', 'json'],
17
+ mesh: ['glb', 'gltf', 'usda', 'obj', 'ply', 'stl', 'geo', 'unreal_landscape', 'json'],
18
+ curves: ['glb', 'gltf', 'usda', 'obj', 'geo', 'unreal_landscape', 'json'],
19
+ points: ['csv', 'pointsjson', 'ply', 'geo', 'glb', 'gltf', 'usda', 'json'],
20
+ image: ['textures', 'json'],
21
+ material: ['textures', 'json'],
22
+ volume: ['json'],
23
+ };
24
+ const n = (x) => String(Math.round(x)).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
25
+ const count = (x, one, many = one + 's') => `${n(x)} ${x === 1 ? one : many}`;
26
+ /** A length with decimals that suit it: 0.25, 2, 12.5, 4096. */
27
+ const len = (m) => { const a = Math.abs(m); return String(+m.toFixed(a === 0 || a >= 1000 ? 0 : a >= 100 ? 1 : a >= 1 ? 2 : 3)); };
28
+ /** What a cooked geometry is. */
29
+ export function outputKind(g) {
30
+ let polygons = 0, polylines = 0, splines = 0, packed = 0;
31
+ const used = new Uint8Array(g.numPoints);
32
+ for (let p = 0; p < g.numPrims; p++) {
33
+ const k = g.primKind ? g.primKind[p] : 0;
34
+ if (k === 1)
35
+ packed++;
36
+ else if (k === 2 || k === 3)
37
+ splines++;
38
+ else if (g.primClosed[p])
39
+ polygons++;
40
+ else
41
+ polylines++;
42
+ }
43
+ for (let v = 0; v < g.numVertices; v++)
44
+ used[g.vertexPoint[v]] = 1;
45
+ let loose = 0;
46
+ for (let i = 0; i < g.numPoints; i++)
47
+ if (!used[i])
48
+ loose++;
49
+ const fields = heightfieldsOf(g), images = [...referenceableImages(g).values()];
50
+ // materials and their maps with no geometry: a material output (its images are its maps, not an image output)
51
+ const mats = !g.numPoints ? Object.keys(readMaterials(g)) : [];
52
+ const sdfs = g.volumes.filter((v) => v.kind === 'sdf' || v.kind === 'grid'), grids = sdfs.filter((v) => v.kind === 'grid');
53
+ const curves = polylines + splines;
54
+ const has = {
55
+ heightfield: fields.length > 0, instances: packed > 0, mesh: polygons > 0, curves: curves > 0,
56
+ // loose points beside prims are an output's sockets or strays, not a part of their own
57
+ points: loose > 0 && !g.numPrims,
58
+ // images beside other parts are their textures
59
+ image: images.length > 0 && !g.numPoints && !fields.length && !sdfs.length && !mats.length,
60
+ material: mats.length > 0 && !fields.length && !sdfs.length,
61
+ volume: sdfs.length > 0,
62
+ };
63
+ const parts = OUTPUT_PARTS.filter((p) => has[p]);
64
+ const alone = parts.length === 1;
65
+ const hf = fields[0];
66
+ const heightfield = hf && {
67
+ name: hf.name, width: hf.width, height: hf.height, cell: hf.cellSize,
68
+ layers: [...hf.layers].map(([name, a]) => { const s = layerStats(a); return { name, min: s?.min ?? 0, max: s?.max ?? 0 }; }),
69
+ };
70
+ const more = (k) => (k > 1 ? ` (+${n(k - 1)} more)` : '');
71
+ // each part's size: alone, beside its kind; in a scene, named by its kind
72
+ const text = {
73
+ heightfield: () => (alone ? `${hf.width} × ${hf.height} samples, ${len(hf.cellSize)} m apart` : `terrain ${hf.width} × ${hf.height}, ${len(hf.cellSize)} m`) + more(fields.length),
74
+ instances: () => `${count(packed, 'instance')} of ${count(g.packedSources.length, 'source')}`,
75
+ mesh: () => (alone ? `${count(polygons, 'polygon')}, ${count(g.numPoints, 'point')}` : `mesh ${count(polygons, 'polygon')}`),
76
+ curves: () => (alone ? `${count(curves, 'curve')}, ${count(g.numPoints, 'point')}` : count(curves, 'curve')),
77
+ points: () => count(loose, 'point'),
78
+ image: () => `${images[0].width} × ${images[0].height} px${more(images.length)}`,
79
+ material: () => `${count(mats.length, 'material')}${images.length ? `, ${count(images.length, 'map')} (${[...new Set(images.map((im) => `${im.width} × ${im.height}`))].join(', ')} px)` : ''}`,
80
+ volume: () => {
81
+ const v = grids[0];
82
+ return v ? `SDF grid ${v.dims.join(' × ')}${more(sdfs.length)}` : `${count(sdfs.length, 'SDF volume')}`;
83
+ },
84
+ };
85
+ const b = g.bbox(true);
86
+ const size = b.empty || has.image || has.material ? null : [0, 1, 2].map((a) => b.max[a] - b.min[a]);
87
+ const kind = parts.length === 0 ? 'empty' : alone ? parts[0] : 'mixed';
88
+ return {
89
+ kind, published: publishedKind({ kind }),
90
+ parts, text: parts.length ? parts.map((p) => text[p]()).join(' + ') : 'empty', size,
91
+ ...(heightfield ? { heightfield } : {}), heightfields: fields.length, images: images.length, materials: has.material ? mats.length : 0, grids: grids.length,
92
+ };
93
+ }
94
+ /**
95
+ * The kind a published output records (src/graph/outputs.ts KINDS): its one part as named, a heightfield a terrain and
96
+ * an image textures; scene for several parts; null for an empty output, which is no kind (publishing blocks it).
97
+ */
98
+ export function publishedKind(o) {
99
+ switch (o.kind) {
100
+ case 'empty': return null;
101
+ case 'mixed': return 'scene';
102
+ case 'heightfield': return 'terrain';
103
+ case 'image': return 'textures';
104
+ default: return o.kind;
105
+ }
106
+ }
107
+ /**
108
+ * What an output whose author pinned its kind (graph.outputs[id].kind) says when it cooks to another kind or to
109
+ * nothing (null: it is the kind pinned). Build and the viewer warn with it; publishing blocks.
110
+ */
111
+ export function kindMismatch(pinned, o) {
112
+ const k = publishedKind(o);
113
+ if (k === pinned)
114
+ return null;
115
+ return `its "kind" is "${pinned}", and it cooks to ${k ? `${k} (${o.text})` : 'nothing'}: change what it cooks, or its "kind" in the graph's outputs`;
116
+ }
117
+ /** A bounding size in words: "4096 × 312 × 4096 m". */
118
+ export const sizeText = (s) => `${s.map(len).join(' × ')} m`;
119
+ /** What a format needs of the output to export at all (io/heightmap.ts, io/unreal.ts, io/textures.ts). */
120
+ function hasWhatItNeeds(format, o) {
121
+ const layers = new Set(o.heightfield?.layers.map((l) => l.name));
122
+ if (format === 'png16' || format === 'r16' || format === 'unreal_landscape')
123
+ return layers.has('height');
124
+ // mask_png writes the "mask" layer unless the export names its layers
125
+ if (format === 'mask_png')
126
+ return layers.has('mask');
127
+ if (format === 'textures')
128
+ return o.images > 0;
129
+ return true;
130
+ }
131
+ /**
132
+ * The formats that write some of the output, best first: those that write all of it, in the order of its main part,
133
+ * then those that write a part, part by part; json (lossless, for TopoTopo itself) last. Nothing for an empty output,
134
+ * or one of analytic SDFs alone (sdf_to_mesh makes them a mesh).
135
+ */
136
+ export function fittingFormats(o) {
137
+ // what there is to write: the parts, and textures beside them (the textures format writes those)
138
+ const present = new Set(o.parts);
139
+ if (o.images)
140
+ present.add('image');
141
+ const writes = (f) => [...present].filter((p) => PART_FORMATS[p].includes(f) && !(p === 'volume' && !o.grids));
142
+ const ordered = [];
143
+ const add = (f) => { if (!ordered.includes(f) && f !== 'json' && hasWhatItNeeds(f, o) && writes(f).length)
144
+ ordered.push(f); };
145
+ const parts = o.parts.length ? o.parts : [...present];
146
+ for (const f of PART_FORMATS[parts[0]] ?? [])
147
+ if (parts.every((p) => writes(f).includes(p)))
148
+ add(f);
149
+ for (const p of [...parts, ...present])
150
+ for (const f of PART_FORMATS[p])
151
+ add(f);
152
+ if (writes('json').length)
153
+ ordered.push('json');
154
+ const instances = o.parts.includes('instances');
155
+ return ordered.map((format) => {
156
+ const w = writes(format);
157
+ return {
158
+ format, label: FORMAT_LABELS[format], extension: targetExtension(format),
159
+ writes: formatWrites(format, { instances, images: o.images > 0 }), leaves: o.parts.filter((p) => !w.includes(p)),
160
+ oneFile: SOURCE_INSIDE.includes(format),
161
+ };
162
+ });
163
+ }
@@ -29,7 +29,8 @@ export declare function instancePoints(g: Geometry, space?: ExportOptions): Inst
29
29
  /**
30
30
  * Sidecar for an instance stream (<name>.meshes.json): the sources, in source order, with the GLB file each one is
31
31
  * written to (meshDir/<Mesh>.glb, one mesh at the origin in metres, Y-up), instance counts, local bounds, triangles
32
- * and materials, so a consumer (the Unreal PCG plugin, a script) can map the Mesh column to a mesh asset.
32
+ * and materials, so a consumer (the Unreal PCG plugin, a script) can map the Mesh column to a mesh asset; with
33
+ * o.source, also how the export was made (io/source.ts).
33
34
  */
34
35
  export declare function instanceMeshesJSON(g: Geometry, o?: ExportOptions & {
35
36
  meshDir?: string;
package/dist/io/points.js CHANGED
@@ -254,7 +254,8 @@ function rowGeometry(g, o, format, space) {
254
254
  /**
255
255
  * Sidecar for an instance stream (<name>.meshes.json): the sources, in source order, with the GLB file each one is
256
256
  * written to (meshDir/<Mesh>.glb, one mesh at the origin in metres, Y-up), instance counts, local bounds, triangles
257
- * and materials, so a consumer (the Unreal PCG plugin, a script) can map the Mesh column to a mesh asset.
257
+ * and materials, so a consumer (the Unreal PCG plugin, a script) can map the Mesh column to a mesh asset; with
258
+ * o.source, also how the export was made (io/source.ts).
258
259
  */
259
260
  export function instanceMeshesJSON(g, o = {}) {
260
261
  const names = packedSourceNames(g);
@@ -282,6 +283,7 @@ export function instanceMeshesJSON(g, o = {}) {
282
283
  stream: o.stream ?? null, scene: o.scene ?? null, mesh_column: 'Mesh', instances: counts.reduce((a, b) => a + b, 0),
283
284
  units: 'mesh files: metres, Y-up, mesh at its own origin (the instance transform places it); PCG CSV rows: centimetres, Unreal axes X = x, Y = z, Z = y',
284
285
  meshes,
286
+ ...(o.source ? { source: o.source } : {}),
285
287
  }, null, 2) + '\n';
286
288
  }
287
289
  // ------------------------------------------------------------------ CSV
@@ -0,0 +1,24 @@
1
+ export type SidecarRole = 'source' | 'heightmap' | 'meshes' | 'landscape';
2
+ /** The "format" each kind of sidecar declares. */
3
+ export declare const SIDECAR_FORMATS: Record<string, SidecarRole>;
4
+ /** What each kind of sidecar is called. */
5
+ export declare const SIDECAR_NAMES: Record<SidecarRole, string>;
6
+ /** What each kind of sidecar holds, in a few words. */
7
+ export declare const SIDECAR_TEXT: Record<SidecarRole, string>;
8
+ /** Bytes of a JSON file worth reading to find its format: the key comes first in every sidecar. */
9
+ export declare const SIDECAR_HEAD_BYTES = 512;
10
+ /** The "format" a JSON document declares at its start ({"format": "png16", …}), or null. */
11
+ export declare function jsonFormat(head: string | Uint8Array): string | null;
12
+ /** Could this file be a sidecar (a .json)? Only those are worth reading. */
13
+ export declare const maybeSidecar: (file: string) => boolean;
14
+ export interface Sidecar {
15
+ role: SidecarRole;
16
+ /** the file (or, for a folder's source.json and landscape.json, the folder) it describes; null when it is not there */
17
+ of: string | null;
18
+ }
19
+ /**
20
+ * Is `file` (a "/"-separated path) a sidecar, and of what? `format` is the format its first bytes declare (jsonFormat),
21
+ * `exists(p)` whether a file or folder `p` is there. A JSON that declares another format (a TopoTopo geometry, a points
22
+ * stream) or none is not a sidecar: null.
23
+ */
24
+ export declare function sidecarOf(file: string, format: string | null, exists: (p: string) => boolean): Sidecar | null;
@@ -0,0 +1,57 @@
1
+ // Export sidecars: the JSON files an export writes beside its main file (io/files.ts). They are metadata of that
2
+ // export, not geometry to read:
3
+ // source <file>.source.json, and source.json inside a textures folder: how the export was made (io/source.ts)
4
+ // heightmap <name>.json beside a png16 / r16 heightmap: the height range, the Unreal import numbers, the source
5
+ // meshes <base>.meshes.json beside csv / points.json instance rows: Mesh → GLB, the source
6
+ // landscape landscape.json in an unreal_landscape folder: the import settings, the files, the source
7
+ // Each declares its "format" as its first key, so the first bytes of a file tell a sidecar from a geometry JSON. The
8
+ // viewer's Outputs and Inputs lists (and Session.listInputs, ArtifactStore.list) show a sidecar with the file it
9
+ // describes. Pure: callers pass names and the first bytes of the files.
10
+ /** The "format" each kind of sidecar declares. */
11
+ export const SIDECAR_FORMATS = {
12
+ 'topotopo-export-source': 'source', png16: 'heightmap', r16: 'heightmap', 'topotopo-instance-meshes': 'meshes', 'topotopo-unreal-landscape': 'landscape',
13
+ };
14
+ /** What each kind of sidecar is called. */
15
+ export const SIDECAR_NAMES = {
16
+ source: 'export source', heightmap: 'heightmap sidecar', meshes: 'instance meshes sidecar', landscape: 'Unreal Landscape manifest',
17
+ };
18
+ /** What each kind of sidecar holds, in a few words. */
19
+ export const SIDECAR_TEXT = {
20
+ source: 'how it was made',
21
+ heightmap: 'height range, Unreal import settings, how it was made',
22
+ meshes: 'the instance meshes, how it was made',
23
+ landscape: 'Landscape import settings, the files, how it was made',
24
+ };
25
+ /** Bytes of a JSON file worth reading to find its format: the key comes first in every sidecar. */
26
+ export const SIDECAR_HEAD_BYTES = 512;
27
+ /** The "format" a JSON document declares at its start ({"format": "png16", …}), or null. */
28
+ export function jsonFormat(head) {
29
+ const s = typeof head === 'string' ? head : new TextDecoder().decode(head.subarray(0, SIDECAR_HEAD_BYTES));
30
+ const m = /^\s*\{\s*"format"\s*:\s*"([^"\\]{1,64})"/.exec(s);
31
+ return m ? m[1] : null;
32
+ }
33
+ /** Could this file be a sidecar (a .json)? Only those are worth reading. */
34
+ export const maybeSidecar = (file) => /\.json$/i.test(file);
35
+ const dirOf = (p) => { const i = p.lastIndexOf('/'); return i < 0 ? '' : p.slice(0, i); };
36
+ /**
37
+ * Is `file` (a "/"-separated path) a sidecar, and of what? `format` is the format its first bytes declare (jsonFormat),
38
+ * `exists(p)` whether a file or folder `p` is there. A JSON that declares another format (a TopoTopo geometry, a points
39
+ * stream) or none is not a sidecar: null.
40
+ */
41
+ export function sidecarOf(file, format, exists) {
42
+ const role = format ? SIDECAR_FORMATS[format] : undefined;
43
+ if (!role || !maybeSidecar(file))
44
+ return null;
45
+ const pick = (...c) => c.find((p) => p && p !== file && exists(p)) ?? null;
46
+ const lower = file.toLowerCase(), folder = dirOf(file);
47
+ if (role === 'source')
48
+ return { role, of: lower.endsWith('.source.json') ? pick(file.slice(0, -'.source.json'.length)) : pick(folder) };
49
+ if (role === 'meshes') {
50
+ const base = lower.endsWith('.meshes.json') ? file.slice(0, -'.meshes.json'.length) : file.slice(0, -'.json'.length);
51
+ return { role, of: pick(base + '.csv', base + '.points.json') };
52
+ }
53
+ // the heightmap's own file: <name>.png for png16, <name>.r16 for r16 (io/heightmap.ts heightmapPaths)
54
+ if (role === 'heightmap')
55
+ return { role, of: pick(file.slice(0, -'.json'.length) + (format === 'r16' ? '.r16' : '.png')) };
56
+ return { role, of: pick(folder) };
57
+ }
@@ -0,0 +1,65 @@
1
+ import type { GraphSpec } from '../graph/types.ts';
2
+ export interface ExportSource {
3
+ graph: string;
4
+ graph_sha256: string;
5
+ output: string | null;
6
+ node: string;
7
+ frame: number;
8
+ fps: number;
9
+ vars: Record<string, unknown>;
10
+ seeds: Record<string, unknown>;
11
+ /** the package versions the graph uses (absent when it uses none) */
12
+ packages?: Record<string, string>;
13
+ export: {
14
+ format: string;
15
+ options: Record<string, unknown>;
16
+ };
17
+ /** the package an engine cook made it for: its publish name, else its id (absent elsewhere) */
18
+ package?: string;
19
+ topotopo: string;
20
+ }
21
+ export interface SourceInput {
22
+ /** the graph's name */
23
+ graph: string;
24
+ /** the graph as cooked (vars after overrides) */
25
+ spec: GraphSpec;
26
+ /** the node that was cooked */
27
+ node: string;
28
+ /** the named output exported, if one was */
29
+ output?: string | null;
30
+ /** cook time (the engine's defaults: frame 1, 24 fps) */
31
+ frame?: number;
32
+ fps?: number;
33
+ format: string;
34
+ /** the export options given, by the export tool's names (up_axis, scale, …) */
35
+ options?: Record<string, unknown>;
36
+ /** the package versions the cooked graph uses (packagesUsed) */
37
+ packages?: Record<string, string>;
38
+ /** an engine cook: the package it cooks for (ExportSource.package) */
39
+ package?: string;
40
+ /** the TopoTopo version */
41
+ version: string;
42
+ }
43
+ /** The name of a standalone source manifest: next to the export file it describes. */
44
+ export declare const SOURCE_SUFFIX = ".source.json";
45
+ /** JSON with every object's keys in sorted order and no whitespace: equal content gives equal text. */
46
+ export declare function canonicalJSON(v: unknown): string;
47
+ /** SHA-256 of a graph document (canonicalJSON). */
48
+ export declare function graphSha256(spec: GraphSpec): string;
49
+ /** The seed params a graph sets (param names compared as the engine does), by node path, keys sorted. */
50
+ export declare function graphSeeds(spec: GraphSpec): Record<string, unknown>;
51
+ /** The source block of an export. */
52
+ export declare function exportSource(i: SourceInput): ExportSource;
53
+ /** The source block with these export options (an export records the options it used, defaults included). */
54
+ export declare function withExportOptions(s: ExportSource, options: Record<string, unknown>): ExportSource;
55
+ /**
56
+ * The command line that makes an export again from its source block: the output (or node), frame, fps, every var as
57
+ * JSON, the format and every export option as its flag (io/targets.ts exportOptionFlags), then --export <path>.
58
+ * Run it on the graph file the block names (its graph_sha256 says whether the file still is the one exported).
59
+ */
60
+ export declare function replayArgs(s: ExportSource, exportPath: string, flags: (o: Record<string, unknown>) => string[]): string[];
61
+ /**
62
+ * A standalone source manifest: the files of the export (relative to the manifest's folder, "/" separated) and the
63
+ * source block.
64
+ */
65
+ export declare function sourceManifestBytes(source: ExportSource, manifestPath: string, files: string[]): Uint8Array;
@@ -0,0 +1,112 @@
1
+ // Export sources: how an export was made, so it can be made again. Every export written through the CLI (--export,
2
+ // --export-all), the MCP export tool and graph export targets (the viewer's Export buttons) records a "source" block:
3
+ // graph the graph's name (for the CLI, the graph file's name without .json)
4
+ // graph_sha256 SHA-256 of the graph JSON as cooked: vars after overrides, format version stamped, keys sorted,
5
+ // no whitespace (canonicalJSON), so a reformatted file hashes the same
6
+ // output the named output exported (graph.outputs), or null (a node, or the default output)
7
+ // node the node that was cooked
8
+ // frame, fps the cook time
9
+ // vars every var of the graph after overrides (CLI --var), keys sorted
10
+ // seeds the seed params the graph sets, by node ("loop/pts" inside a nested graph), as written
11
+ // packages only when the graph uses packages (src/graph/packages.ts packagesUsed): "owner/name@version" → the
12
+ // version's hash for every package version it uses, directly or through other packages (an export
13
+ // made while following a working folder cooks with the published copies, so it names those)
14
+ // export {format, options}: the export options given (the export tool's names)
15
+ // package only on a package's outputs cooked for an engine (topotopo cook --for godot, src/host/cook.ts): the
16
+ // package's publish name, else its id; the cook replaces a file at an output path only when it names
17
+ // this package (or the cook record lists the file)
18
+ // topotopo the version that wrote it
19
+ // Formats that write a sidecar or manifest carry the block there (png16 / r16: <name>.json; csv / points.json instance
20
+ // rows: <name>.meshes.json; unreal_landscape: its landscape.json); every other export gets <file>.source.json next to
21
+ // it (textures, a folder: source.json inside it), and glb / gltf also carry it in asset.extras.source. Nothing in the
22
+ // block depends on the time or the machine: the same graph and values give the same bytes. Pure: no file system.
23
+ import { isGraph } from '../graph/types.js';
24
+ import { norm } from '../graph/params.js';
25
+ import { sha256Hex } from '../core/sha256.js';
26
+ import { dirOf } from './common.js';
27
+ /** The name of a standalone source manifest: next to the export file it describes. */
28
+ export const SOURCE_SUFFIX = '.source.json';
29
+ /** JSON with every object's keys in sorted order and no whitespace: equal content gives equal text. */
30
+ export function canonicalJSON(v) {
31
+ return JSON.stringify(v, (_k, x) => {
32
+ if (!x || typeof x !== 'object' || Array.isArray(x) || ArrayBuffer.isView(x))
33
+ return x;
34
+ const o = {};
35
+ for (const k of Object.keys(x).sort())
36
+ o[k] = x[k];
37
+ return o;
38
+ }) ?? 'null';
39
+ }
40
+ /** A deep copy with sorted keys (undefined dropped), as plain JSON data. */
41
+ const sorted = (v) => JSON.parse(canonicalJSON(v));
42
+ /** SHA-256 of a graph document (canonicalJSON). */
43
+ export function graphSha256(spec) {
44
+ return sha256Hex(canonicalJSON(spec));
45
+ }
46
+ /** The seed params a graph sets (param names compared as the engine does), by node path, keys sorted. */
47
+ export function graphSeeds(spec) {
48
+ const out = {};
49
+ const walk = (g, prefix, depth) => {
50
+ if (depth > 64)
51
+ return;
52
+ for (const [name, node] of Object.entries(g.nodes ?? {})) {
53
+ if (!node || typeof node !== 'object' || !node.params || typeof node.params !== 'object')
54
+ continue;
55
+ for (const [k, v] of Object.entries(node.params)) {
56
+ if (norm(k) === 'seed')
57
+ out[prefix + name] = v;
58
+ else if (isGraph(v))
59
+ walk(v, `${prefix}${name}/`, depth + 1);
60
+ }
61
+ }
62
+ };
63
+ walk(spec, '', 0);
64
+ return sorted(out);
65
+ }
66
+ /** The source block of an export. */
67
+ export function exportSource(i) {
68
+ const spec = i.spec;
69
+ return {
70
+ graph: i.graph,
71
+ graph_sha256: sha256Hex(canonicalJSON(spec)),
72
+ output: i.output ?? null,
73
+ node: i.node,
74
+ frame: i.frame ?? 1,
75
+ fps: i.fps ?? 24,
76
+ vars: sorted(spec.vars ?? {}),
77
+ seeds: graphSeeds(spec),
78
+ ...(i.packages && Object.keys(i.packages).length ? { packages: sorted(i.packages) } : {}),
79
+ export: { format: i.format, options: sorted(i.options ?? {}) },
80
+ ...(i.package ? { package: i.package } : {}),
81
+ topotopo: i.version,
82
+ };
83
+ }
84
+ /** The source block with these export options (an export records the options it used, defaults included). */
85
+ export function withExportOptions(s, options) {
86
+ return { ...s, export: { format: s.export.format, options: sorted(options) } };
87
+ }
88
+ /**
89
+ * The command line that makes an export again from its source block: the output (or node), frame, fps, every var as
90
+ * JSON, the format and every export option as its flag (io/targets.ts exportOptionFlags), then --export <path>.
91
+ * Run it on the graph file the block names (its graph_sha256 says whether the file still is the one exported).
92
+ */
93
+ export function replayArgs(s, exportPath, flags) {
94
+ return [
95
+ ...(s.output ? ['--output', s.output] : ['--node', s.node]),
96
+ '--frame', String(s.frame), '--fps', String(s.fps),
97
+ ...Object.entries(s.vars).flatMap(([k, v]) => ['--var', `${k}=${JSON.stringify(v)}`]),
98
+ '--format', s.export.format, ...flags(s.export.options), '--export', exportPath,
99
+ ];
100
+ }
101
+ /**
102
+ * A standalone source manifest: the files of the export (relative to the manifest's folder, "/" separated) and the
103
+ * source block.
104
+ */
105
+ export function sourceManifestBytes(source, manifestPath, files) {
106
+ const dir = dirOf(manifestPath).replace(/\\/g, '/');
107
+ const rel = (p) => {
108
+ const q = p.replace(/\\/g, '/');
109
+ return dir && q.startsWith(dir + '/') ? q.slice(dir.length + 1) : dir ? q.slice(q.lastIndexOf('/') + 1) : q;
110
+ };
111
+ return new TextEncoder().encode(JSON.stringify({ format: 'topotopo-export-source', version: 1, files: files.map(rel), source }, null, 2) + '\n');
112
+ }
@@ -7,12 +7,45 @@ export declare const TARGET_FORMATS: ExportFormat[];
7
7
  export declare const targetExtension: (format: ExportFormat) => string;
8
8
  /** A format name in canonical form ("USD" → usda), or null. */
9
9
  export declare function targetFormat(f: unknown): ExportFormat | null;
10
- /** Why a target is invalid, or null when it is valid. */
10
+ /** The export tool's options among `a` (the tool's arguments), those that are set. */
11
+ export declare function exportToolOptions(a: Record<string, unknown>): Record<string, unknown>;
12
+ /**
13
+ * The options a format reads, with the value each takes when it is not given. Every export passes them explicitly
14
+ * (host/export-targets.ts serializeExport) and records them in its source block, so a record replays to the same bytes
15
+ * even when a later version changes a default. Options whose default depends on the data (height_min / height_max:
16
+ * the layer's range; attributes: all; layers) are recorded only when given.
17
+ */
18
+ export declare function exportDefaults(format: ExportFormat, a?: Record<string, unknown>): Record<string, unknown>;
19
+ /** The options an export of `format` uses: the given ones over the format's defaults (keys sorted). */
20
+ export declare function resolvedExportOptions(format: ExportFormat, a: Record<string, unknown>): Record<string, unknown>;
21
+ /** Export options as CLI flags: booleans as --name / --no-name, lists comma-joined, the rest --name value. */
22
+ export declare function exportOptionFlags(o: Record<string, unknown>): string[];
23
+ /**
24
+ * The export options among CLI arguments (the reverse of exportOptionFlags): every option of the export tool as a flag.
25
+ * Throws on a value the option does not take (targetError's checks).
26
+ */
27
+ export declare function exportOptionsFromFlags(argv: string[]): Record<string, unknown>;
28
+ /** What a target still written with the prefix that is gone is told, its path as written given. */
29
+ export declare const prefixGone: (written: string) => string;
30
+ /**
31
+ * What a valid target is warned of when a graph is validated or cooked: a path still written with the prefix that is
32
+ * gone, which cooks, views and freezes in versions as it is but is refused where a file would be written. null for
33
+ * none.
34
+ */
35
+ export declare function targetWarning(t: unknown): string | null;
36
+ /**
37
+ * Why a target is refused where it is set (the edit op "export", the viewer's Export) or a file would be written: its
38
+ * path still has the prefix that is gone. null for any other target (targetError checks the rest).
39
+ */
40
+ export declare function targetRefusal(t: unknown): string | null;
41
+ /** Why a target is invalid, or null when it is valid (a path written with the prefix that is gone only warns: targetWarning). */
11
42
  export declare function targetError(t: unknown): string | null;
12
43
  export interface ResolvedTarget {
13
44
  format: ExportFormat;
14
45
  /** posix path inside exports/: a file, or a folder for unreal_landscape and textures */
15
46
  path: string;
47
+ /** the path as the graph writes it, when it still has the prefix that is gone: writing it is refused (prefixGone) */
48
+ refused?: string;
16
49
  /** the export tool's options (up_axis, scale, …) */
17
50
  options: Record<string, unknown>;
18
51
  }
@@ -20,12 +53,23 @@ export interface ResolvedTarget {
20
53
  export declare const fileStem: (s: string) => string;
21
54
  /** A valid target with its path filled in: <stem><extension> unless it names one. */
22
55
  export declare function resolveTarget(t: ExportTarget, stem: string): ResolvedTarget;
56
+ /** A target's path as written in a graph (one still written with the prefix that is gone, as it is). */
57
+ export declare const targetPathText: (t: ResolvedTarget) => string;
23
58
  export interface PublishedOutput {
24
- /** null for the graph's default output (graph.export), else the id in graph.outputs */
59
+ /** the id in graph.outputs, or null for a default output that is no named output (its target is graph.export) */
25
60
  output: string | null;
26
61
  node: string;
27
62
  label: string;
63
+ /** the graph's default output (its output node): one entry, a named output when one is that node */
64
+ default: boolean;
28
65
  target: ResolvedTarget | null;
66
+ /** the graph it is published from: a target export records it in its source block (io/source.ts) */
67
+ spec: GraphSpec;
29
68
  }
30
- /** A graph's default output (its files named after the graph) and its named outputs, each with its target if valid. */
69
+ /**
70
+ * A graph's results, the default output first, each once and with its target if valid. The default output (the graph's
71
+ * output node) is the first named output of that node, when there is one, and keeps its own target (or graph.export,
72
+ * named after the graph, when it has none); otherwise it is an entry of its own, named after the graph, whose target
73
+ * is graph.export.
74
+ */
31
75
  export declare function publishedOutputs(graph: string, spec: GraphSpec, defaultNode: string): PublishedOutput[];