topotopo 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (354) hide show
  1. package/NOTICE +40 -10
  2. package/README.md +475 -111
  3. package/dist/cli.js +328 -133
  4. package/dist/config.d.ts +48 -0
  5. package/dist/config.js +170 -0
  6. package/dist/core/analysis.d.ts +5 -1
  7. package/dist/core/analysis.js +8 -3
  8. package/dist/core/bake.d.ts +16 -8
  9. package/dist/core/bake.js +165 -29
  10. package/dist/core/bevel.d.ts +3 -1
  11. package/dist/core/bevel.js +238 -97
  12. package/dist/core/decimate.d.ts +65 -0
  13. package/dist/core/decimate.js +409 -3
  14. package/dist/core/erosion.d.ts +37 -0
  15. package/dist/core/erosion.js +41 -1
  16. package/dist/core/geometry.d.ts +5 -1
  17. package/dist/core/geometry.js +204 -4
  18. package/dist/core/heightfield.d.ts +27 -4
  19. package/dist/core/heightfield.js +54 -16
  20. package/dist/core/imageops.d.ts +6 -0
  21. package/dist/core/imageops.js +51 -0
  22. package/dist/core/intrinsics.d.ts +7 -0
  23. package/dist/core/intrinsics.js +94 -0
  24. package/dist/core/manifold.d.ts +12 -1
  25. package/dist/core/manifold.js +78 -6
  26. package/dist/core/materials.d.ts +11 -0
  27. package/dist/core/materials.js +56 -0
  28. package/dist/core/noise.d.ts +9 -0
  29. package/dist/core/noise.js +10 -1
  30. package/dist/core/packed.js +11 -0
  31. package/dist/core/particles.d.ts +1 -1
  32. package/dist/core/particles.js +1 -1
  33. package/dist/core/polymerge.d.ts +21 -0
  34. package/dist/core/polymerge.js +327 -0
  35. package/dist/core/rbd.js +13 -1
  36. package/dist/core/repair.d.ts +2 -0
  37. package/dist/core/repair.js +2 -0
  38. package/dist/core/report.d.ts +70 -0
  39. package/dist/core/report.js +275 -0
  40. package/dist/core/scatter.d.ts +1 -1
  41. package/dist/core/scatter.js +1 -1
  42. package/dist/core/scene.d.ts +20 -0
  43. package/dist/core/scene.js +72 -0
  44. package/dist/core/sha256.d.ts +4 -0
  45. package/dist/core/sha256.js +69 -0
  46. package/dist/core/shapes.d.ts +3 -0
  47. package/dist/core/shapes.js +34 -0
  48. package/dist/core/snippet-lib.d.ts +15 -2
  49. package/dist/core/snippet-lib.js +40 -14
  50. package/dist/core/solidify.d.ts +38 -0
  51. package/dist/core/solidify.js +356 -0
  52. package/dist/core/tangents.d.ts +54 -0
  53. package/dist/core/tangents.js +218 -0
  54. package/dist/core/texcoord.d.ts +4 -0
  55. package/dist/core/texcoord.js +14 -0
  56. package/dist/core/texnoise.d.ts +6 -1
  57. package/dist/core/texnoise.js +6 -2
  58. package/dist/core/texsdf.d.ts +131 -0
  59. package/dist/core/texsdf.js +637 -0
  60. package/dist/core/texture.d.ts +163 -9
  61. package/dist/core/texture.js +844 -20
  62. package/dist/core/topology.d.ts +32 -0
  63. package/dist/core/topology.js +238 -7
  64. package/dist/core/traceimage.d.ts +7 -0
  65. package/dist/core/traceimage.js +221 -0
  66. package/dist/core/tritri.d.ts +5 -0
  67. package/dist/core/tritri.js +120 -0
  68. package/dist/core/unwrap.d.ts +72 -0
  69. package/dist/core/unwrap.js +800 -0
  70. package/dist/core/usercode.d.ts +27 -0
  71. package/dist/core/usercode.js +87 -0
  72. package/dist/core/uv.d.ts +15 -16
  73. package/dist/core/uv.js +36 -189
  74. package/dist/core/uvislands.d.ts +62 -0
  75. package/dist/core/uvislands.js +574 -0
  76. package/dist/core/uvoverlap.d.ts +58 -0
  77. package/dist/core/uvoverlap.js +220 -0
  78. package/dist/core/uvpack.d.ts +64 -0
  79. package/dist/core/uvpack.js +628 -0
  80. package/dist/core/uvreport.d.ts +127 -0
  81. package/dist/core/uvreport.js +372 -0
  82. package/dist/core/wrangle.d.ts +6 -1
  83. package/dist/core/wrangle.js +27 -16
  84. package/dist/core/xatlas.d.ts +16 -1
  85. package/dist/core/xatlas.js +95 -61
  86. package/dist/engines.d.ts +63 -0
  87. package/dist/engines.js +180 -0
  88. package/dist/explain.d.ts +4 -3
  89. package/dist/explain.js +129 -12
  90. package/dist/graph/engine.d.ts +92 -29
  91. package/dist/graph/engine.js +298 -148
  92. package/dist/graph/expr.d.ts +6 -3
  93. package/dist/graph/expr.js +18 -8
  94. package/dist/graph/outputs.d.ts +23 -0
  95. package/dist/graph/outputs.js +41 -0
  96. package/dist/graph/packages.d.ts +72 -0
  97. package/dist/graph/packages.js +261 -0
  98. package/dist/graph/parallel.d.ts +3 -1
  99. package/dist/graph/parallel.js +4 -1
  100. package/dist/graph/params.d.ts +6 -0
  101. package/dist/graph/params.js +34 -7
  102. package/dist/graph/scope.d.ts +55 -0
  103. package/dist/graph/scope.js +14 -0
  104. package/dist/graph/types.d.ts +75 -12
  105. package/dist/graph/types.js +4 -2
  106. package/dist/graph/vars.d.ts +16 -0
  107. package/dist/graph/vars.js +80 -0
  108. package/dist/host/artifacts.d.ts +10 -1
  109. package/dist/host/artifacts.js +37 -6
  110. package/dist/host/cook.d.ts +241 -0
  111. package/dist/host/cook.js +844 -0
  112. package/dist/host/export-targets.d.ts +42 -5
  113. package/dist/host/export-targets.js +72 -13
  114. package/dist/host/godot-commands.d.ts +4 -0
  115. package/dist/host/godot-commands.js +21 -0
  116. package/dist/host/godot.d.ts +183 -0
  117. package/dist/host/godot.js +916 -0
  118. package/dist/host/node.d.ts +12 -7
  119. package/dist/host/node.js +27 -9
  120. package/dist/host/pool.js +51 -2
  121. package/dist/host/sidecars.d.ts +8 -0
  122. package/dist/host/sidecars.js +50 -0
  123. package/dist/host/types.d.ts +19 -6
  124. package/dist/host/version.d.ts +1 -0
  125. package/dist/host/version.js +3 -0
  126. package/dist/host/worker.js +5 -2
  127. package/dist/index.d.ts +5 -3
  128. package/dist/index.js +3 -2
  129. package/dist/inspect.d.ts +84 -1
  130. package/dist/inspect.js +271 -24
  131. package/dist/io/common.d.ts +33 -5
  132. package/dist/io/export.js +2 -1
  133. package/dist/io/files.d.ts +23 -4
  134. package/dist/io/files.js +60 -8
  135. package/dist/io/gltf.js +355 -51
  136. package/dist/io/heightmap.d.ts +3 -0
  137. package/dist/io/heightmap.js +1 -0
  138. package/dist/io/import.js +10 -0
  139. package/dist/io/inspect-scene.d.ts +55 -0
  140. package/dist/io/inspect-scene.js +155 -0
  141. package/dist/io/kinds.d.ts +81 -0
  142. package/dist/io/kinds.js +163 -0
  143. package/dist/io/points.d.ts +2 -1
  144. package/dist/io/points.js +3 -1
  145. package/dist/io/sidecars.d.ts +24 -0
  146. package/dist/io/sidecars.js +57 -0
  147. package/dist/io/source.d.ts +65 -0
  148. package/dist/io/source.js +112 -0
  149. package/dist/io/targets.d.ts +47 -3
  150. package/dist/io/targets.js +149 -14
  151. package/dist/io/textures.js +21 -1
  152. package/dist/io/unreal.js +5 -1
  153. package/dist/mcp/docs.d.ts +10 -1
  154. package/dist/mcp/docs.js +816 -119
  155. package/dist/mcp/inputs.d.ts +12 -5
  156. package/dist/mcp/inputs.js +50 -13
  157. package/dist/mcp/server.js +70 -24
  158. package/dist/mcp/tools.d.ts +14 -7
  159. package/dist/mcp/tools.js +207 -108
  160. package/dist/mcp/verify.d.ts +2 -2
  161. package/dist/mcp/verify.js +1 -1
  162. package/dist/mcp/workspace.d.ts +15 -0
  163. package/dist/mcp/workspace.js +349 -0
  164. package/dist/nodes/attributes.js +198 -1
  165. package/dist/nodes/bake.js +207 -83
  166. package/dist/nodes/beam.d.ts +1 -0
  167. package/dist/nodes/beam.js +201 -0
  168. package/dist/nodes/bevel.js +54 -5
  169. package/dist/nodes/cloth.js +2 -0
  170. package/dist/nodes/code.js +22 -10
  171. package/dist/nodes/curves.js +440 -93
  172. package/dist/nodes/flow.js +53 -33
  173. package/dist/nodes/generate.js +13 -39
  174. package/dist/nodes/heightfield.js +248 -77
  175. package/dist/nodes/imageops.d.ts +1 -0
  176. package/dist/nodes/imageops.js +203 -0
  177. package/dist/nodes/index.d.ts +4 -0
  178. package/dist/nodes/index.js +4 -0
  179. package/dist/nodes/material.js +91 -23
  180. package/dist/nodes/measure.js +45 -18
  181. package/dist/nodes/particles.js +2 -0
  182. package/dist/nodes/pcg.js +6 -5
  183. package/dist/nodes/procedural.js +4 -3
  184. package/dist/nodes/rbd.js +1 -1
  185. package/dist/nodes/remesh.js +71 -15
  186. package/dist/nodes/scene.d.ts +1 -0
  187. package/dist/nodes/scene.js +55 -0
  188. package/dist/nodes/sdf.js +10 -5
  189. package/dist/nodes/solid.js +20 -5
  190. package/dist/nodes/solidify.d.ts +1 -0
  191. package/dist/nodes/solidify.js +52 -0
  192. package/dist/nodes/splines.d.ts +15 -1
  193. package/dist/nodes/splines.js +112 -105
  194. package/dist/nodes/texture.d.ts +21 -6
  195. package/dist/nodes/texture.js +1318 -185
  196. package/dist/nodes/topology.d.ts +7 -0
  197. package/dist/nodes/topology.js +133 -6
  198. package/dist/nodes/transform.js +11 -3
  199. package/dist/nodes/util.d.ts +1 -1
  200. package/dist/nodes/uv.js +192 -174
  201. package/dist/nodes/wasmcall.js +6 -2
  202. package/dist/open.d.ts +19 -0
  203. package/dist/open.js +12 -0
  204. package/dist/package.d.ts +288 -0
  205. package/dist/package.js +772 -0
  206. package/dist/packages/check.d.ts +32 -0
  207. package/dist/packages/check.js +169 -0
  208. package/dist/packages/commands.d.ts +57 -0
  209. package/dist/packages/commands.js +537 -0
  210. package/dist/packages/registry.d.ts +796 -0
  211. package/dist/packages/registry.js +2998 -0
  212. package/dist/packages/update.d.ts +124 -0
  213. package/dist/packages/update.js +476 -0
  214. package/dist/render/options.d.ts +2 -0
  215. package/dist/render/options.js +44 -5
  216. package/dist/render/pbr.d.ts +28 -0
  217. package/dist/render/pbr.js +378 -0
  218. package/dist/render/preview.d.ts +69 -0
  219. package/dist/render/preview.js +26 -0
  220. package/dist/render/raster.d.ts +78 -7
  221. package/dist/render/raster.js +600 -145
  222. package/dist/render/texview.d.ts +7 -1
  223. package/dist/render/texview.js +34 -2
  224. package/dist/scan.d.ts +61 -0
  225. package/dist/scan.js +228 -0
  226. package/dist/session.d.ts +311 -0
  227. package/dist/session.js +849 -0
  228. package/dist/viewer/app/api.js +48 -6
  229. package/dist/viewer/app/camera.js +1 -1
  230. package/dist/viewer/app/cooking.js +78 -0
  231. package/dist/viewer/app/embed.js +100 -0
  232. package/dist/viewer/app/export-popover.js +118 -16
  233. package/dist/viewer/app/grid.js +6 -2
  234. package/dist/viewer/app/guides.js +123 -1
  235. package/dist/viewer/app/keymap.js +7 -4
  236. package/dist/viewer/app/layers.js +5 -5
  237. package/dist/viewer/app/main.js +186 -53
  238. package/dist/viewer/app/markers.js +61 -1
  239. package/dist/viewer/app/outliner.js +72 -27
  240. package/dist/viewer/app/output-info.js +45 -0
  241. package/dist/viewer/app/outputs.css +147 -8
  242. package/dist/viewer/app/outputs.js +168 -54
  243. package/dist/viewer/app/packages.js +614 -0
  244. package/dist/viewer/app/props.js +177 -53
  245. package/dist/viewer/app/scene.js +35 -6
  246. package/dist/viewer/app/select.js +5 -4
  247. package/dist/viewer/app/selection.js +1 -1
  248. package/dist/viewer/app/status.js +12 -15
  249. package/dist/viewer/app/style.css +66 -8
  250. package/dist/viewer/app/units.js +1 -1
  251. package/dist/viewer/app/vars.js +48 -1
  252. package/dist/viewer/app/welcome.js +72 -0
  253. package/dist/viewer/graph-file.d.ts +62 -0
  254. package/dist/viewer/graph-file.js +175 -0
  255. package/dist/viewer/index.html +24 -11
  256. package/dist/viewer/json-edit.d.ts +13 -0
  257. package/dist/viewer/json-edit.js +274 -0
  258. package/dist/viewer/outputs.d.ts +49 -5
  259. package/dist/viewer/outputs.js +264 -56
  260. package/dist/viewer/packages.d.ts +121 -0
  261. package/dist/viewer/packages.js +584 -0
  262. package/dist/viewer/server.d.ts +24 -7
  263. package/dist/viewer/server.js +289 -31
  264. package/dist/web/app/web.css +419 -0
  265. package/dist/web/app/web.js +188 -0
  266. package/dist/web/bake.d.ts +34 -0
  267. package/dist/web/bake.js +153 -0
  268. package/dist/web/folder-page.d.ts +101 -0
  269. package/dist/web/folder-page.js +146 -0
  270. package/dist/web/folders.d.ts +280 -0
  271. package/dist/web/folders.js +970 -0
  272. package/dist/web/library.d.ts +91 -0
  273. package/dist/web/library.js +228 -0
  274. package/dist/web/markdown.d.ts +45 -0
  275. package/dist/web/markdown.js +677 -0
  276. package/dist/web/pages.d.ts +258 -0
  277. package/dist/web/pages.js +301 -0
  278. package/dist/web/server.d.ts +24 -0
  279. package/dist/web/server.js +1068 -0
  280. package/dist/workspace.d.ts +88 -105
  281. package/dist/workspace.js +359 -375
  282. package/integrations/godot/addons/topotopo/LICENSE +202 -0
  283. package/integrations/godot/addons/topotopo/README.md +57 -0
  284. package/integrations/godot/addons/topotopo/context_menu.gd +43 -0
  285. package/integrations/godot/addons/topotopo/dock.gd +266 -0
  286. package/integrations/godot/addons/topotopo/dock.tscn +72 -0
  287. package/integrations/godot/addons/topotopo/export_filter.gd +72 -0
  288. package/integrations/godot/addons/topotopo/gltf_instancing.gd +131 -0
  289. package/integrations/godot/addons/topotopo/icons/topotopo.svg +1 -0
  290. package/integrations/godot/addons/topotopo/inspector.gd +38 -0
  291. package/integrations/godot/addons/topotopo/instances_post_import.gd +111 -0
  292. package/integrations/godot/addons/topotopo/package.gd +23 -0
  293. package/integrations/godot/addons/topotopo/package_importer.gd +187 -0
  294. package/integrations/godot/addons/topotopo/plugin.cfg +7 -0
  295. package/integrations/godot/addons/topotopo/plugin.gd +970 -0
  296. package/integrations/godot/addons/topotopo/record.gd +435 -0
  297. package/integrations/godot/addons/topotopo/runner.gd +458 -0
  298. package/integrations/godot/addons/topotopo/tools/check.gd +42 -0
  299. package/integrations/godot/addons/topotopo/watcher.gd +199 -0
  300. package/kernels/pkg/README.md +23 -29
  301. package/kernels/pkg-simd/README.md +23 -29
  302. package/library/architecture/versions/1.0/architecture.topo +12 -0
  303. package/{shelf → library/architecture/versions/1.0/graphs}/arch.json +3 -3
  304. package/{shelf → library/architecture/versions/1.0/graphs}/beam_truss.json +6 -6
  305. package/{shelf → library/architecture/versions/1.0/graphs}/brick_wall.json +8 -8
  306. package/{shelf → library/architecture/versions/1.0/graphs}/door_frame.json +3 -3
  307. package/{shelf → library/architecture/versions/1.0/graphs}/hex_grid_floor.json +3 -2
  308. package/{shelf → library/architecture/versions/1.0/graphs}/house.json +8 -8
  309. package/library/architecture/versions/1.0/graphs/lineup.json +42 -0
  310. package/{shelf → library/architecture/versions/1.0/graphs}/pillar.json +3 -2
  311. package/{shelf → library/architecture/versions/1.0/graphs}/railing.json +5 -5
  312. package/{shelf → library/architecture/versions/1.0/graphs}/roof_gable.json +2 -2
  313. package/{shelf → library/architecture/versions/1.0/graphs}/roof_hip.json +2 -2
  314. package/{shelf → library/architecture/versions/1.0/graphs}/roof_skeleton.json +2 -1
  315. package/{shelf → library/architecture/versions/1.0/graphs}/scaffold.json +4 -4
  316. package/{shelf → library/architecture/versions/1.0/graphs}/spiral_stairs.json +3 -2
  317. package/{shelf → library/architecture/versions/1.0/graphs}/stairs.json +6 -6
  318. package/{shelf → library/architecture/versions/1.0/graphs}/tile_floor.json +3 -2
  319. package/{shelf → library/architecture/versions/1.0/graphs}/wall_segment.json +10 -10
  320. package/{shelf → library/architecture/versions/1.0/graphs}/window_frame.json +2 -2
  321. package/library/architecture/versions/1.0/version.json +1119 -0
  322. package/{shelf → library/nature/versions/1.0/graphs}/bush.json +2 -2
  323. package/{shelf → library/nature/versions/1.0/graphs}/cliff_block.json +4 -3
  324. package/{shelf → library/nature/versions/1.0/graphs}/forest_patch.json +5 -5
  325. package/{shelf → library/nature/versions/1.0/graphs}/grass_clumps.json +2 -2
  326. package/library/nature/versions/1.0/graphs/lineup.json +24 -0
  327. package/{shelf → library/nature/versions/1.0/graphs}/log.json +6 -6
  328. package/{shelf → library/nature/versions/1.0/graphs}/rock.json +5 -4
  329. package/{shelf → library/nature/versions/1.0/graphs}/scatter_rocks.json +5 -5
  330. package/{shelf → library/nature/versions/1.0/graphs}/tree_lowpoly.json +3 -2
  331. package/library/nature/versions/1.0/nature.topo +12 -0
  332. package/library/nature/versions/1.0/version.json +534 -0
  333. package/{shelf → library/props/versions/1.0/graphs}/barrel.json +5 -4
  334. package/{shelf → library/props/versions/1.0/graphs}/crate.json +3 -3
  335. package/library/props/versions/1.0/graphs/lineup.json +18 -0
  336. package/{shelf → library/props/versions/1.0/graphs}/pallet.json +4 -3
  337. package/{shelf → library/props/versions/1.0/graphs}/pipe_run.json +3 -3
  338. package/{shelf → library/props/versions/1.0/graphs}/sandbag_wall.json +5 -5
  339. package/library/props/versions/1.0/props.topo +12 -0
  340. package/library/props/versions/1.0/version.json +336 -0
  341. package/{shelf → library/street/versions/1.0/graphs}/bench.json +5 -5
  342. package/{shelf → library/street/versions/1.0/graphs}/bollard.json +2 -1
  343. package/{shelf → library/street/versions/1.0/graphs}/cable.json +4 -4
  344. package/{shelf → library/street/versions/1.0/graphs}/fence.json +7 -7
  345. package/{shelf → library/street/versions/1.0/graphs}/lamp_post.json +2 -2
  346. package/library/street/versions/1.0/graphs/lineup.json +22 -0
  347. package/{shelf → library/street/versions/1.0/graphs}/road_strip.json +2 -2
  348. package/{shelf → library/street/versions/1.0/graphs}/sign_post.json +1 -1
  349. package/library/street/versions/1.0/street.topo +12 -0
  350. package/library/street/versions/1.0/version.json +421 -0
  351. package/package.json +23 -8
  352. package/dist/graph/migrate.d.ts +0 -23
  353. package/dist/graph/migrate.js +0 -58
  354. package/shelf/index.json +0 -190
@@ -1,5 +1,6 @@
1
1
  import type { Geometry } from '../core/geometry.ts';
2
2
  import type { Heightfield } from '../core/heightfield.ts';
3
+ import type { ExportSource } from './source.ts';
3
4
  export type HeightmapFormat = 'png16' | 'r16' | 'mask_png';
4
5
  export declare const HEIGHTMAP_FORMATS: HeightmapFormat[];
5
6
  export interface HeightmapOptions {
@@ -14,6 +15,8 @@ export interface HeightmapOptions {
14
15
  heightfield?: number;
15
16
  /** zlib compressor for PNG data (default: stored, uncompressed blocks) */
16
17
  deflate?: (data: Uint8Array) => Uint8Array;
18
+ /** png16 / r16: how the export was made (io/source.ts), written into the sidecar as "source" */
19
+ source?: ExportSource;
17
20
  }
18
21
  export interface HeightmapFile {
19
22
  kind: 'main' | 'sidecar' | 'layer';
@@ -184,6 +184,7 @@ export function heightmapExport(g, format, o = {}) {
184
184
  : 'RAW little-endian uint16, row-major, no header; h = height_min + value / 65535 * (height_max - height_min)',
185
185
  clipped: min > st.min || max < st.max,
186
186
  unreal,
187
+ ...(o.source ? { source: o.source } : {}),
187
188
  };
188
189
  const sidecar = new TextEncoder().encode(JSON.stringify(info, null, 2) + '\n');
189
190
  return {
package/dist/io/import.js CHANGED
@@ -9,6 +9,7 @@ import { importGLTFAsync } from './gltf.js';
9
9
  import { importHoudiniBgeo, importHoudiniGeo, isBinaryJSON } from './hgeo.js';
10
10
  import { importCSV, importPointsJSON, isPointsJSON } from './points.js';
11
11
  import { imageFromPNGFile } from './textures.js';
12
+ import { SIDECAR_FORMATS, SIDECAR_NAMES, SIDECAR_TEXT } from './sidecars.js';
12
13
  export { importGLTFAsync } from './gltf.js';
13
14
  export { importHoudiniBgeo, importHoudiniGeo } from './hgeo.js';
14
15
  export { importCSV, importPointsJSON } from './points.js';
@@ -29,6 +30,15 @@ function importAnyJSON(j, warn) {
29
30
  return importHoudiniGeo(j, warn);
30
31
  if (isPointsJSON(j))
31
32
  return importPointsJSON(j);
33
+ // an export's sidecar (io/sidecars.ts) is metadata of the file beside it: say so instead of "not a topotopo-geo file"
34
+ const role = typeof j?.format === 'string' ? SIDECAR_FORMATS[j.format] : undefined;
35
+ if (role)
36
+ throw new Error(`this JSON is an export's ${SIDECAR_NAMES[role]} (${SIDECAR_TEXT[role]}), not geometry: ${{
37
+ source: 'read the exported file it sits beside',
38
+ heightmap: j.format === 'png16' ? 'read the heightmap PNG beside it with heightfield_from_image (height_min / height_max from this sidecar)' : 'the RAW heightmap beside it is for Unreal; export png16 to read it back',
39
+ meshes: 'read the instance stream (.csv / .points.json) beside it',
40
+ landscape: 'read the files of its folder (heightmap.png, objects.glb)',
41
+ }[role]}`);
32
42
  return geoFromJSON(j);
33
43
  }
34
44
  /** Synchronous import for every format except glb/gltf (see importGeometryAsync). */
@@ -0,0 +1,55 @@
1
+ /** A node of the exported scene. */
2
+ export interface SceneNode {
3
+ name: string;
4
+ /** the parent node's name, or null at the scene root */
5
+ parent: string | null;
6
+ /** "mesh" (with its mesh), "instances" (EXT_mesh_gpu_instancing), "empty" (a socket / scene empty) */
7
+ kind: 'mesh' | 'instances' | 'empty';
8
+ mesh: string | null;
9
+ /** local translation, and the world position of the node's origin (metres, Y up) */
10
+ translation: [number, number, number];
11
+ world: [number, number, number];
12
+ instances: number;
13
+ extras: string[];
14
+ }
15
+ export interface SceneMesh {
16
+ name: string;
17
+ primitives: {
18
+ material: string | null;
19
+ mode: string;
20
+ triangles: number;
21
+ vertices: number;
22
+ attributes: string[];
23
+ }[];
24
+ triangles: number;
25
+ }
26
+ export interface SceneMaterial {
27
+ name: string;
28
+ baseColor: number[];
29
+ metallic: number;
30
+ roughness: number;
31
+ maps: Record<string, string>;
32
+ alphaMode: string;
33
+ doubleSided: boolean;
34
+ unlit: boolean;
35
+ }
36
+ export interface SceneImage {
37
+ name: string;
38
+ mimeType: string;
39
+ bytes: number;
40
+ width: number;
41
+ height: number;
42
+ }
43
+ export interface SceneReport {
44
+ nodes: SceneNode[];
45
+ meshes: SceneMesh[];
46
+ materials: SceneMaterial[];
47
+ images: SceneImage[];
48
+ extensions: string[];
49
+ bytes: number;
50
+ triangles: number;
51
+ }
52
+ /** The scene a GLB holds (see the file comment). */
53
+ export declare function glbSceneReport(bytes: Uint8Array): SceneReport;
54
+ /** The scene report as text. */
55
+ export declare function sceneReportText(r: SceneReport): string[];
@@ -0,0 +1,155 @@
1
+ // inspect detail "scene": what a glb export of the geometry holds, read back from the exported bytes themselves (the
2
+ // GLB's JSON chunk), so it is the export and not a guess at it: the node tree (meshes, scene empties and their
3
+ // parents, local and world positions, extras), each mesh's primitives (triangles, vertex attributes, material), the
4
+ // materials with their factors and maps, and the images (size, format, bytes). Pure: no file system.
5
+ const MODES = ['POINTS', 'LINES', 'LINE_LOOP', 'LINE_STRIP', 'TRIANGLES', 'TRIANGLE_STRIP', 'TRIANGLE_FAN'];
6
+ /** The JSON chunk and binary chunk of a GLB. */
7
+ function glbChunks(bytes) {
8
+ const dv = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
9
+ if (bytes.length < 20 || dv.getUint32(0, true) !== 0x46546c67)
10
+ throw new Error('not a GLB file');
11
+ let o = 12, json = null, bin = null;
12
+ while (o + 8 <= bytes.length) {
13
+ const len = dv.getUint32(o, true), type = dv.getUint32(o + 4, true);
14
+ const data = bytes.subarray(o + 8, o + 8 + len);
15
+ if (type === 0x4e4f534a)
16
+ json = JSON.parse(new TextDecoder().decode(data));
17
+ else if (type === 0x004e4942)
18
+ bin = data;
19
+ o += 8 + len;
20
+ }
21
+ if (!json)
22
+ throw new Error('GLB without a JSON chunk');
23
+ return { json, bin };
24
+ }
25
+ /** Width and height of a PNG or JPEG from its header (0 × 0 when unknown). */
26
+ function imageSize(b) {
27
+ if (!b || b.length < 24)
28
+ return [0, 0];
29
+ const dv = new DataView(b.buffer, b.byteOffset, b.byteLength);
30
+ if (b[0] === 0x89 && b[1] === 0x50)
31
+ return [dv.getUint32(16), dv.getUint32(20)];
32
+ if (b[0] === 0xff && b[1] === 0xd8) {
33
+ let o = 2;
34
+ while (o + 9 < b.length) {
35
+ if (b[o] !== 0xff)
36
+ break;
37
+ const m = b[o + 1], len = dv.getUint16(o + 2);
38
+ if (m >= 0xc0 && m <= 0xcf && m !== 0xc4 && m !== 0xc8 && m !== 0xcc)
39
+ return [dv.getUint16(o + 7), dv.getUint16(o + 5)];
40
+ o += 2 + len;
41
+ }
42
+ }
43
+ return [0, 0];
44
+ }
45
+ /** Quaternion (x, y, z, w) applied to v. */
46
+ function qrot(q, v) {
47
+ const [x, y, z, w] = q, ix = w * v[0] + y * v[2] - z * v[1], iy = w * v[1] + z * v[0] - x * v[2], iz = w * v[2] + x * v[1] - y * v[0], iw = -x * v[0] - y * v[1] - z * v[2];
48
+ return [ix * w + iw * -x + iy * -z - iz * -y, iy * w + iw * -y + iz * -x - ix * -z, iz * w + iw * -z + ix * -y - iy * -x];
49
+ }
50
+ /** The scene a GLB holds (see the file comment). */
51
+ export function glbSceneReport(bytes) {
52
+ const { json, bin } = glbChunks(bytes);
53
+ const acc = (i) => (i === undefined ? null : json.accessors?.[i] ?? null);
54
+ const images = (json.images ?? []).map((im, i) => {
55
+ const bv = im.bufferView !== undefined ? json.bufferViews?.[im.bufferView] : null;
56
+ const data = bv && bin ? bin.subarray(bv.byteOffset ?? 0, (bv.byteOffset ?? 0) + bv.byteLength) : null;
57
+ const [w, h] = imageSize(data);
58
+ return { name: im.name ?? `image_${i}`, mimeType: im.mimeType ?? (im.uri ? 'uri' : '?'), bytes: bv?.byteLength ?? 0, width: w, height: h };
59
+ });
60
+ const texName = (t) => {
61
+ if (!t || t.index === undefined)
62
+ return null;
63
+ const tex = json.textures?.[t.index];
64
+ const src = tex?.source ?? tex?.extensions?.EXT_texture_webp?.source;
65
+ const im = src !== undefined ? images[src] : undefined;
66
+ return im ? `${im.name}${im.width ? ` ${im.width}×${im.height}` : ''}` : `texture ${t.index}`;
67
+ };
68
+ const materials = (json.materials ?? []).map((m, i) => {
69
+ const pbr = m.pbrMetallicRoughness ?? {}, maps = {};
70
+ const put = (k, t) => { const nm = texName(t); if (nm)
71
+ maps[k] = nm; };
72
+ put('baseColor', pbr.baseColorTexture);
73
+ put('metallicRoughness', pbr.metallicRoughnessTexture);
74
+ put('normal', m.normalTexture);
75
+ put('occlusion', m.occlusionTexture);
76
+ put('emissive', m.emissiveTexture);
77
+ return {
78
+ name: m.name ?? `material_${i}`, baseColor: pbr.baseColorFactor ?? [1, 1, 1, 1], metallic: pbr.metallicFactor ?? 1, roughness: pbr.roughnessFactor ?? 1,
79
+ maps, alphaMode: m.alphaMode ?? 'OPAQUE', doubleSided: !!m.doubleSided, unlit: !!m.extensions?.KHR_materials_unlit,
80
+ };
81
+ });
82
+ const meshes = (json.meshes ?? []).map((m, i) => {
83
+ const prims = (m.primitives ?? []).map((p) => {
84
+ const mode = MODES[p.mode ?? 4] ?? String(p.mode);
85
+ const pos = acc(p.attributes?.POSITION), idx = acc(p.indices);
86
+ const count = idx ? idx.count : pos ? pos.count : 0;
87
+ const triangles = mode === 'TRIANGLES' ? Math.floor(count / 3) : mode === 'TRIANGLE_STRIP' || mode === 'TRIANGLE_FAN' ? Math.max(0, count - 2) : 0;
88
+ return { material: p.material !== undefined ? materials[p.material]?.name ?? `material ${p.material}` : null, mode, triangles, vertices: pos?.count ?? 0, attributes: Object.keys(p.attributes ?? {}) };
89
+ });
90
+ return { name: m.name ?? `mesh_${i}`, primitives: prims, triangles: prims.reduce((s, p) => s + p.triangles, 0) };
91
+ });
92
+ // the node tree, depth first from the scene roots
93
+ const nodes = [];
94
+ let triangles = 0;
95
+ const scene = json.scenes?.[json.scene ?? 0];
96
+ const walk = (i, parent, world, depth) => {
97
+ const nd = json.nodes?.[i];
98
+ if (!nd || depth > 64)
99
+ return;
100
+ const t = nd.translation ?? [0, 0, 0], r = nd.rotation ?? [0, 0, 0, 1], sc = nd.scale ?? [1, 1, 1];
101
+ // the world origin: parent's transform applied to the local translation (matrices: none are written by the exporter)
102
+ const rt = qrot(world.r, [t[0] * world.s[0], t[1] * world.s[1], t[2] * world.s[2]]);
103
+ const wt = [world.t[0] + rt[0], world.t[1] + rt[1], world.t[2] + rt[2]];
104
+ const qr = world.r, wr = [
105
+ qr[3] * r[0] + qr[0] * r[3] + qr[1] * r[2] - qr[2] * r[1], qr[3] * r[1] - qr[0] * r[2] + qr[1] * r[3] + qr[2] * r[0],
106
+ qr[3] * r[2] + qr[0] * r[1] - qr[1] * r[0] + qr[2] * r[3], qr[3] * r[3] - qr[0] * r[0] - qr[1] * r[1] - qr[2] * r[2]
107
+ ];
108
+ const inst = nd.extensions?.EXT_mesh_gpu_instancing;
109
+ const ic = inst ? acc(inst.attributes?.TRANSLATION ?? inst.attributes?.ROTATION ?? inst.attributes?.SCALE)?.count ?? 0 : 0;
110
+ const mesh = nd.mesh !== undefined ? meshes[nd.mesh] : null;
111
+ if (mesh)
112
+ triangles += mesh.triangles * (inst ? ic : 1);
113
+ const name = nd.name ?? `node_${i}`;
114
+ nodes.push({
115
+ name, parent, kind: mesh ? (inst ? 'instances' : 'mesh') : 'empty', mesh: mesh?.name ?? null,
116
+ translation: [t[0], t[1], t[2]], world: [wt[0], wt[1], wt[2]], instances: ic,
117
+ extras: nd.extras && typeof nd.extras === 'object' ? Object.keys(nd.extras).filter((k) => k !== 'topotopo') : [],
118
+ });
119
+ for (const c of nd.children ?? [])
120
+ walk(c, name, { t: wt, r: wr, s: [world.s[0] * sc[0], world.s[1] * sc[1], world.s[2] * sc[2]] }, depth + 1);
121
+ };
122
+ for (const i of scene?.nodes ?? [])
123
+ walk(i, null, { t: [0, 0, 0], r: [0, 0, 0, 1], s: [1, 1, 1] }, 0);
124
+ return { nodes, meshes, materials, images, extensions: json.extensionsUsed ?? [], bytes: bytes.length, triangles };
125
+ }
126
+ /** The scene report as text. */
127
+ export function sceneReportText(r) {
128
+ const n = (x) => x.toLocaleString('en-US');
129
+ const f = (x) => (Math.abs(x) < 5e-4 ? 0 : x).toFixed(3);
130
+ const p3 = (v) => `(${v.map(f).join(', ')})`;
131
+ const kb = (b) => (b >= 1 << 20 ? `${(b / (1 << 20)).toFixed(2)} MB` : `${(b / 1024).toFixed(1)} KB`);
132
+ const out = [`scene (the glb export, read back): ${r.nodes.length} nodes, ${r.meshes.length} meshes, ${n(r.triangles)} triangles, ${r.materials.length} materials, ${r.images.length} images; ${kb(r.bytes)}${r.extensions.length ? `; extensions ${r.extensions.join(', ')}` : ''}`];
133
+ out.push('nodes (parent → child; positions in metres, Y up):');
134
+ const depth = new Map();
135
+ for (const nd of r.nodes) {
136
+ const d = nd.parent === null ? 0 : (depth.get(nd.parent) ?? 0) + 1;
137
+ depth.set(nd.name, d);
138
+ const mesh = nd.mesh ? r.meshes.find((m) => m.name === nd.mesh) : null;
139
+ const what = nd.kind === 'empty' ? 'empty (socket)' : `${nd.kind === 'instances' ? `${n(nd.instances)} instances of ` : ''}mesh "${nd.mesh}": ${n(mesh?.triangles ?? 0)} tris, ${mesh?.primitives.length ?? 0} primitive(s)${mesh && mesh.primitives.some((p) => p.material) ? ` [${[...new Set(mesh.primitives.map((p) => p.material ?? 'no material'))].join(', ')}]` : ''}`;
140
+ out.push(` ${' '.repeat(d)}${nd.name}: ${what}; at ${p3(nd.world)}${nd.parent !== null ? `, local ${p3(nd.translation)}` : ''}${nd.extras.length ? `; extras ${nd.extras.join(', ')}` : ''}`);
141
+ }
142
+ const attrs = [...new Set(r.meshes.flatMap((m) => m.primitives.flatMap((p) => p.attributes)))].sort();
143
+ if (attrs.length)
144
+ out.push(`vertex attributes: ${attrs.join(', ')}`);
145
+ if (r.materials.length) {
146
+ out.push('materials:');
147
+ for (const m of r.materials) {
148
+ const maps = Object.entries(m.maps).map(([k, v]) => `${k} ${v}`);
149
+ out.push(` ${m.name}: base colour factor (linear) (${m.baseColor.slice(0, 3).map((x) => x.toFixed(2)).join(', ')}${m.baseColor[3] !== undefined && m.baseColor[3] !== 1 ? `, alpha ${m.baseColor[3].toFixed(2)}` : ''}), metallic ${m.metallic.toFixed(2)}, roughness ${m.roughness.toFixed(2)}${m.alphaMode !== 'OPAQUE' ? `, ${m.alphaMode}` : ''}${m.doubleSided ? ', double-sided' : ''}${m.unlit ? ', unlit' : ''}${maps.length ? `; maps: ${maps.join(', ')}` : '; no maps'}`);
150
+ }
151
+ }
152
+ if (r.images.length)
153
+ out.push(`images: ${r.images.map((im) => `${im.name} ${im.width ? `${im.width}×${im.height} ` : ''}${im.mimeType.replace('image/', '')} ${kb(im.bytes)}`).join(', ')}`);
154
+ return out;
155
+ }
@@ -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
+ }