topotopo 0.4.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (336) hide show
  1. package/NOTICE +10 -10
  2. package/README.md +460 -117
  3. package/dist/cli.js +327 -147
  4. package/dist/config.d.ts +48 -0
  5. package/dist/config.js +170 -0
  6. package/dist/core/bake.d.ts +14 -3
  7. package/dist/core/bake.js +153 -4
  8. package/dist/core/bevel.d.ts +3 -1
  9. package/dist/core/bevel.js +76 -3
  10. package/dist/core/decimate.d.ts +65 -0
  11. package/dist/core/decimate.js +409 -3
  12. package/dist/core/erosion.d.ts +37 -0
  13. package/dist/core/erosion.js +41 -1
  14. package/dist/core/geometry.d.ts +5 -1
  15. package/dist/core/geometry.js +203 -3
  16. package/dist/core/heightfield.d.ts +27 -4
  17. package/dist/core/heightfield.js +54 -16
  18. package/dist/core/intrinsics.d.ts +7 -0
  19. package/dist/core/intrinsics.js +94 -0
  20. package/dist/core/manifold.d.ts +12 -1
  21. package/dist/core/manifold.js +78 -6
  22. package/dist/core/materials.d.ts +7 -0
  23. package/dist/core/materials.js +45 -0
  24. package/dist/core/noise.d.ts +9 -0
  25. package/dist/core/noise.js +10 -1
  26. package/dist/core/polymerge.d.ts +21 -0
  27. package/dist/core/polymerge.js +327 -0
  28. package/dist/core/repair.d.ts +2 -0
  29. package/dist/core/repair.js +2 -0
  30. package/dist/core/report.d.ts +70 -0
  31. package/dist/core/report.js +275 -0
  32. package/dist/core/scene.js +2 -1
  33. package/dist/core/sha256.d.ts +4 -0
  34. package/dist/core/sha256.js +69 -0
  35. package/dist/core/shapes.d.ts +3 -0
  36. package/dist/core/shapes.js +34 -0
  37. package/dist/core/snippet-lib.d.ts +14 -1
  38. package/dist/core/snippet-lib.js +39 -13
  39. package/dist/core/tangents.d.ts +2 -0
  40. package/dist/core/tangents.js +5 -1
  41. package/dist/core/texnoise.d.ts +6 -1
  42. package/dist/core/texnoise.js +6 -2
  43. package/dist/core/texsdf.d.ts +131 -0
  44. package/dist/core/texsdf.js +637 -0
  45. package/dist/core/texture.d.ts +163 -9
  46. package/dist/core/texture.js +844 -20
  47. package/dist/core/topology.d.ts +10 -0
  48. package/dist/core/topology.js +168 -0
  49. package/dist/core/unwrap.d.ts +72 -0
  50. package/dist/core/unwrap.js +800 -0
  51. package/dist/core/usercode.d.ts +27 -0
  52. package/dist/core/usercode.js +87 -0
  53. package/dist/core/uv.d.ts +4 -18
  54. package/dist/core/uv.js +35 -188
  55. package/dist/core/uvislands.d.ts +62 -0
  56. package/dist/core/uvislands.js +574 -0
  57. package/dist/core/uvoverlap.d.ts +58 -0
  58. package/dist/core/uvoverlap.js +220 -0
  59. package/dist/core/uvpack.d.ts +64 -0
  60. package/dist/core/uvpack.js +628 -0
  61. package/dist/core/uvreport.d.ts +61 -0
  62. package/dist/core/uvreport.js +207 -143
  63. package/dist/core/wrangle.d.ts +6 -1
  64. package/dist/core/wrangle.js +27 -16
  65. package/dist/core/xatlas.d.ts +16 -1
  66. package/dist/core/xatlas.js +66 -62
  67. package/dist/engines.d.ts +63 -0
  68. package/dist/engines.js +180 -0
  69. package/dist/explain.d.ts +4 -3
  70. package/dist/explain.js +129 -12
  71. package/dist/graph/engine.d.ts +92 -29
  72. package/dist/graph/engine.js +298 -148
  73. package/dist/graph/expr.d.ts +6 -3
  74. package/dist/graph/expr.js +18 -8
  75. package/dist/graph/outputs.d.ts +23 -0
  76. package/dist/graph/outputs.js +41 -0
  77. package/dist/graph/packages.d.ts +72 -0
  78. package/dist/graph/packages.js +261 -0
  79. package/dist/graph/parallel.d.ts +3 -1
  80. package/dist/graph/parallel.js +4 -1
  81. package/dist/graph/params.d.ts +6 -0
  82. package/dist/graph/params.js +34 -7
  83. package/dist/graph/scope.d.ts +55 -0
  84. package/dist/graph/scope.js +14 -0
  85. package/dist/graph/types.d.ts +75 -12
  86. package/dist/graph/types.js +4 -2
  87. package/dist/graph/vars.d.ts +16 -0
  88. package/dist/graph/vars.js +80 -0
  89. package/dist/host/artifacts.d.ts +10 -1
  90. package/dist/host/artifacts.js +37 -6
  91. package/dist/host/cook.d.ts +241 -0
  92. package/dist/host/cook.js +844 -0
  93. package/dist/host/export-targets.d.ts +42 -5
  94. package/dist/host/export-targets.js +72 -13
  95. package/dist/host/godot-commands.d.ts +4 -0
  96. package/dist/host/godot-commands.js +21 -0
  97. package/dist/host/godot.d.ts +183 -0
  98. package/dist/host/godot.js +916 -0
  99. package/dist/host/node.d.ts +12 -7
  100. package/dist/host/node.js +27 -9
  101. package/dist/host/pool.js +51 -2
  102. package/dist/host/sidecars.d.ts +8 -0
  103. package/dist/host/sidecars.js +50 -0
  104. package/dist/host/types.d.ts +19 -6
  105. package/dist/host/version.d.ts +1 -0
  106. package/dist/host/version.js +3 -0
  107. package/dist/host/worker.js +5 -2
  108. package/dist/index.d.ts +2 -2
  109. package/dist/index.js +1 -1
  110. package/dist/inspect.d.ts +80 -2
  111. package/dist/inspect.js +265 -30
  112. package/dist/io/common.d.ts +25 -5
  113. package/dist/io/export.js +2 -1
  114. package/dist/io/files.d.ts +23 -4
  115. package/dist/io/files.js +60 -8
  116. package/dist/io/gltf.js +134 -47
  117. package/dist/io/heightmap.d.ts +3 -0
  118. package/dist/io/heightmap.js +1 -0
  119. package/dist/io/import.js +10 -0
  120. package/dist/io/inspect-scene.d.ts +55 -0
  121. package/dist/io/inspect-scene.js +155 -0
  122. package/dist/io/kinds.d.ts +81 -0
  123. package/dist/io/kinds.js +163 -0
  124. package/dist/io/points.d.ts +2 -1
  125. package/dist/io/points.js +3 -1
  126. package/dist/io/sidecars.d.ts +24 -0
  127. package/dist/io/sidecars.js +57 -0
  128. package/dist/io/source.d.ts +65 -0
  129. package/dist/io/source.js +112 -0
  130. package/dist/io/targets.d.ts +47 -3
  131. package/dist/io/targets.js +148 -13
  132. package/dist/io/textures.js +21 -1
  133. package/dist/io/unreal.js +5 -1
  134. package/dist/mcp/docs.d.ts +10 -1
  135. package/dist/mcp/docs.js +786 -143
  136. package/dist/mcp/inputs.d.ts +12 -5
  137. package/dist/mcp/inputs.js +50 -13
  138. package/dist/mcp/server.js +56 -27
  139. package/dist/mcp/tools.d.ts +14 -7
  140. package/dist/mcp/tools.js +198 -103
  141. package/dist/mcp/verify.d.ts +2 -2
  142. package/dist/mcp/verify.js +1 -1
  143. package/dist/mcp/workspace.d.ts +15 -0
  144. package/dist/mcp/workspace.js +349 -0
  145. package/dist/nodes/attributes.js +198 -1
  146. package/dist/nodes/bake.js +151 -47
  147. package/dist/nodes/beam.d.ts +1 -0
  148. package/dist/nodes/beam.js +201 -0
  149. package/dist/nodes/bevel.js +51 -3
  150. package/dist/nodes/cloth.js +2 -0
  151. package/dist/nodes/code.js +21 -9
  152. package/dist/nodes/curves.js +433 -93
  153. package/dist/nodes/flow.js +53 -33
  154. package/dist/nodes/generate.js +12 -38
  155. package/dist/nodes/heightfield.js +248 -77
  156. package/dist/nodes/imageops.js +16 -19
  157. package/dist/nodes/index.d.ts +1 -0
  158. package/dist/nodes/index.js +1 -0
  159. package/dist/nodes/material.js +89 -24
  160. package/dist/nodes/measure.js +43 -17
  161. package/dist/nodes/particles.js +2 -0
  162. package/dist/nodes/pcg.js +6 -5
  163. package/dist/nodes/procedural.js +4 -3
  164. package/dist/nodes/remesh.js +71 -15
  165. package/dist/nodes/scene.js +4 -2
  166. package/dist/nodes/sdf.js +10 -5
  167. package/dist/nodes/solid.js +20 -5
  168. package/dist/nodes/splines.d.ts +15 -1
  169. package/dist/nodes/splines.js +112 -105
  170. package/dist/nodes/texture.d.ts +21 -6
  171. package/dist/nodes/texture.js +1318 -185
  172. package/dist/nodes/topology.d.ts +7 -0
  173. package/dist/nodes/topology.js +133 -6
  174. package/dist/nodes/transform.js +6 -2
  175. package/dist/nodes/uv.js +192 -174
  176. package/dist/nodes/wasmcall.js +5 -1
  177. package/dist/open.d.ts +19 -0
  178. package/dist/open.js +12 -0
  179. package/dist/package.d.ts +288 -0
  180. package/dist/package.js +772 -0
  181. package/dist/packages/check.d.ts +32 -0
  182. package/dist/packages/check.js +169 -0
  183. package/dist/packages/commands.d.ts +57 -0
  184. package/dist/packages/commands.js +537 -0
  185. package/dist/packages/registry.d.ts +796 -0
  186. package/dist/packages/registry.js +2998 -0
  187. package/dist/packages/update.d.ts +124 -0
  188. package/dist/packages/update.js +476 -0
  189. package/dist/render/options.d.ts +2 -0
  190. package/dist/render/options.js +57 -5
  191. package/dist/render/preview.d.ts +17 -4
  192. package/dist/render/preview.js +6 -4
  193. package/dist/render/raster.d.ts +74 -5
  194. package/dist/render/raster.js +527 -143
  195. package/dist/render/texview.d.ts +6 -0
  196. package/dist/render/texview.js +27 -0
  197. package/dist/scan.d.ts +61 -0
  198. package/dist/scan.js +228 -0
  199. package/dist/session.d.ts +311 -0
  200. package/dist/session.js +849 -0
  201. package/dist/viewer/app/api.js +48 -6
  202. package/dist/viewer/app/cooking.js +78 -0
  203. package/dist/viewer/app/embed.js +27 -7
  204. package/dist/viewer/app/export-popover.js +118 -16
  205. package/dist/viewer/app/grid.js +5 -1
  206. package/dist/viewer/app/guides.js +122 -0
  207. package/dist/viewer/app/keymap.js +6 -3
  208. package/dist/viewer/app/layers.js +4 -4
  209. package/dist/viewer/app/main.js +185 -52
  210. package/dist/viewer/app/markers.js +60 -0
  211. package/dist/viewer/app/outliner.js +72 -27
  212. package/dist/viewer/app/output-info.js +45 -0
  213. package/dist/viewer/app/outputs.css +147 -8
  214. package/dist/viewer/app/outputs.js +168 -54
  215. package/dist/viewer/app/packages.js +614 -0
  216. package/dist/viewer/app/props.js +176 -52
  217. package/dist/viewer/app/scene.js +30 -5
  218. package/dist/viewer/app/select.js +4 -3
  219. package/dist/viewer/app/status.js +12 -15
  220. package/dist/viewer/app/style.css +65 -7
  221. package/dist/viewer/app/vars.js +47 -0
  222. package/dist/viewer/app/welcome.js +72 -0
  223. package/dist/viewer/graph-file.d.ts +62 -0
  224. package/dist/viewer/graph-file.js +175 -0
  225. package/dist/viewer/index.html +23 -10
  226. package/dist/viewer/json-edit.d.ts +13 -0
  227. package/dist/viewer/json-edit.js +274 -0
  228. package/dist/viewer/outputs.d.ts +49 -5
  229. package/dist/viewer/outputs.js +264 -56
  230. package/dist/viewer/packages.d.ts +121 -0
  231. package/dist/viewer/packages.js +584 -0
  232. package/dist/viewer/server.d.ts +14 -9
  233. package/dist/viewer/server.js +266 -28
  234. package/dist/web/app/web.css +419 -0
  235. package/dist/web/app/web.js +188 -0
  236. package/dist/{gallery → web}/bake.d.ts +4 -4
  237. package/dist/{gallery → web}/bake.js +24 -15
  238. package/dist/web/folder-page.d.ts +101 -0
  239. package/dist/web/folder-page.js +146 -0
  240. package/dist/web/folders.d.ts +280 -0
  241. package/dist/web/folders.js +970 -0
  242. package/dist/web/library.d.ts +91 -0
  243. package/dist/web/library.js +228 -0
  244. package/dist/web/markdown.d.ts +45 -0
  245. package/dist/web/markdown.js +677 -0
  246. package/dist/web/pages.d.ts +258 -0
  247. package/dist/web/pages.js +301 -0
  248. package/dist/web/server.d.ts +24 -0
  249. package/dist/web/server.js +1068 -0
  250. package/dist/workspace.d.ts +88 -118
  251. package/dist/workspace.js +358 -460
  252. package/integrations/godot/addons/topotopo/LICENSE +202 -0
  253. package/integrations/godot/addons/topotopo/README.md +57 -0
  254. package/integrations/godot/addons/topotopo/context_menu.gd +43 -0
  255. package/integrations/godot/addons/topotopo/dock.gd +266 -0
  256. package/integrations/godot/addons/topotopo/dock.tscn +72 -0
  257. package/integrations/godot/addons/topotopo/export_filter.gd +72 -0
  258. package/integrations/godot/addons/topotopo/gltf_instancing.gd +131 -0
  259. package/integrations/godot/addons/topotopo/icons/topotopo.svg +1 -0
  260. package/integrations/godot/addons/topotopo/inspector.gd +38 -0
  261. package/integrations/godot/addons/topotopo/instances_post_import.gd +111 -0
  262. package/integrations/godot/addons/topotopo/package.gd +23 -0
  263. package/integrations/godot/addons/topotopo/package_importer.gd +187 -0
  264. package/integrations/godot/addons/topotopo/plugin.cfg +7 -0
  265. package/integrations/godot/addons/topotopo/plugin.gd +970 -0
  266. package/integrations/godot/addons/topotopo/record.gd +435 -0
  267. package/integrations/godot/addons/topotopo/runner.gd +458 -0
  268. package/integrations/godot/addons/topotopo/tools/check.gd +42 -0
  269. package/integrations/godot/addons/topotopo/watcher.gd +199 -0
  270. package/kernels/pkg/README.md +2 -1
  271. package/kernels/pkg-simd/README.md +2 -1
  272. package/library/architecture/versions/1.0/architecture.topo +12 -0
  273. package/{shelf → library/architecture/versions/1.0/graphs}/arch.json +3 -3
  274. package/{shelf → library/architecture/versions/1.0/graphs}/beam_truss.json +6 -6
  275. package/{shelf → library/architecture/versions/1.0/graphs}/brick_wall.json +8 -8
  276. package/{shelf → library/architecture/versions/1.0/graphs}/door_frame.json +3 -3
  277. package/{shelf → library/architecture/versions/1.0/graphs}/hex_grid_floor.json +3 -2
  278. package/{shelf → library/architecture/versions/1.0/graphs}/house.json +8 -8
  279. package/library/architecture/versions/1.0/graphs/lineup.json +42 -0
  280. package/{shelf → library/architecture/versions/1.0/graphs}/pillar.json +3 -2
  281. package/{shelf → library/architecture/versions/1.0/graphs}/railing.json +5 -5
  282. package/{shelf → library/architecture/versions/1.0/graphs}/roof_gable.json +2 -2
  283. package/{shelf → library/architecture/versions/1.0/graphs}/roof_hip.json +2 -2
  284. package/{shelf → library/architecture/versions/1.0/graphs}/roof_skeleton.json +2 -1
  285. package/{shelf → library/architecture/versions/1.0/graphs}/scaffold.json +4 -4
  286. package/{shelf → library/architecture/versions/1.0/graphs}/spiral_stairs.json +3 -2
  287. package/{shelf → library/architecture/versions/1.0/graphs}/stairs.json +6 -6
  288. package/{shelf → library/architecture/versions/1.0/graphs}/tile_floor.json +3 -2
  289. package/{shelf → library/architecture/versions/1.0/graphs}/wall_segment.json +10 -10
  290. package/{shelf → library/architecture/versions/1.0/graphs}/window_frame.json +2 -2
  291. package/library/architecture/versions/1.0/version.json +1119 -0
  292. package/{shelf → library/nature/versions/1.0/graphs}/bush.json +2 -2
  293. package/{shelf → library/nature/versions/1.0/graphs}/cliff_block.json +4 -3
  294. package/{shelf → library/nature/versions/1.0/graphs}/forest_patch.json +5 -5
  295. package/{shelf → library/nature/versions/1.0/graphs}/grass_clumps.json +2 -2
  296. package/library/nature/versions/1.0/graphs/lineup.json +24 -0
  297. package/{shelf → library/nature/versions/1.0/graphs}/log.json +6 -6
  298. package/{shelf → library/nature/versions/1.0/graphs}/rock.json +5 -4
  299. package/{shelf → library/nature/versions/1.0/graphs}/scatter_rocks.json +5 -5
  300. package/{shelf → library/nature/versions/1.0/graphs}/tree_lowpoly.json +3 -2
  301. package/library/nature/versions/1.0/nature.topo +12 -0
  302. package/library/nature/versions/1.0/version.json +534 -0
  303. package/{shelf → library/props/versions/1.0/graphs}/barrel.json +5 -4
  304. package/{shelf → library/props/versions/1.0/graphs}/crate.json +3 -3
  305. package/library/props/versions/1.0/graphs/lineup.json +18 -0
  306. package/{shelf → library/props/versions/1.0/graphs}/pallet.json +4 -3
  307. package/{shelf → library/props/versions/1.0/graphs}/pipe_run.json +3 -3
  308. package/{shelf → library/props/versions/1.0/graphs}/sandbag_wall.json +5 -5
  309. package/library/props/versions/1.0/props.topo +12 -0
  310. package/library/props/versions/1.0/version.json +336 -0
  311. package/{shelf → library/street/versions/1.0/graphs}/bench.json +5 -5
  312. package/{shelf → library/street/versions/1.0/graphs}/bollard.json +2 -1
  313. package/{shelf → library/street/versions/1.0/graphs}/cable.json +4 -4
  314. package/{shelf → library/street/versions/1.0/graphs}/fence.json +7 -7
  315. package/{shelf → library/street/versions/1.0/graphs}/lamp_post.json +2 -2
  316. package/library/street/versions/1.0/graphs/lineup.json +22 -0
  317. package/{shelf → library/street/versions/1.0/graphs}/road_strip.json +2 -2
  318. package/{shelf → library/street/versions/1.0/graphs}/sign_post.json +1 -1
  319. package/library/street/versions/1.0/street.topo +12 -0
  320. package/library/street/versions/1.0/version.json +421 -0
  321. package/package.json +13 -8
  322. package/dist/gallery/app/gallery.css +0 -100
  323. package/dist/gallery/app/gallery.js +0 -80
  324. package/dist/gallery/cli.d.ts +0 -4
  325. package/dist/gallery/cli.js +0 -157
  326. package/dist/gallery/library.d.ts +0 -124
  327. package/dist/gallery/library.js +0 -366
  328. package/dist/gallery/pages.d.ts +0 -94
  329. package/dist/gallery/pages.js +0 -148
  330. package/dist/gallery/server.d.ts +0 -21
  331. package/dist/gallery/server.js +0 -391
  332. package/dist/graph/migrate.d.ts +0 -23
  333. package/dist/graph/migrate.js +0 -58
  334. package/dist/mcp/library.d.ts +0 -12
  335. package/dist/mcp/library.js +0 -159
  336. package/shelf/index.json +0 -190
package/dist/inspect.js CHANGED
@@ -1,18 +1,33 @@
1
1
  // Text-first geometry introspection for LLMs: compact summaries, attribute statistics,
2
2
  // topology health, and element listings.
3
+ // summarize(g) the short block every cook report carries (counts, bbox in metres to the millimetre, one images
4
+ // line, attributes, groups)
5
+ // detail "summary" one screen: counts and triangles, bbox, parts, materials and their maps, images, uv state,
6
+ // closed or open (after welding seam splits)
7
+ // detail "budget" triangles per part (prim "name", what each exported mesh holds) split per LOD (_lodN names),
8
+ // and per node (what each node adds), sorted, with totals
9
+ // detail "attributes" adds the attribute statistics and each image's layer ranges
3
10
  import { Geometry } from './core/geometry.js';
4
- import { primArea, signedVolume, topologyReport, triangleReport } from './core/topology.js';
11
+ import { primArea, signedVolume, topologyReport, triangleReport, triangulate } from './core/topology.js';
12
+ import { selfIntersections } from './core/analysis.js';
5
13
  import { evalGroup } from './core/groups.js';
6
14
  import { edgeList } from './core/edges.js';
7
15
  import { halfEdges } from './core/halfedge.js';
8
16
  import { fmtNum } from './render/raster.js';
9
- import { packedSummaryLine } from './core/packed.js';
17
+ import { expandedTriangles, packedSummaryLine } from './core/packed.js';
18
+ import { packedSourceNames } from './io/common.js';
19
+ import { primMaterials, readMaterials } from './core/materials.js';
20
+ import { lodOf } from './core/uvreport.js';
10
21
  import { heightfieldSummary, volumeCounts } from './core/heightfield.js';
11
- import { imageSummary } from './core/image.js';
22
+ import { imageSummary, imagesOf } from './core/image.js';
12
23
  import { sdfGridSummary } from './core/sdfgrid.js';
13
24
  import { uvReport, uvReportText } from './core/uvreport.js';
25
+ import { openEdgesText, partsOf, primWhere, solidCauses, solidReport } from './core/report.js';
14
26
  const n = (x) => x.toLocaleString('en-US');
15
27
  const v3 = (a) => `(${a.map(fmtNum).join(', ')})`;
28
+ /** metres to the millimetre */
29
+ const mm = (x) => (Number.isFinite(x) ? (Math.abs(x) < 5e-4 ? 0 : x).toFixed(3) : String(x));
30
+ const v3mm = (a) => `(${a.map(mm).join(', ')})`;
16
31
  const typeCode = (a) => (a.isArray ? a.type : (a.type === 'float' ? 'f' : a.type === 'int' ? 'i' : 's') + a.size);
17
32
  function fmtVal(v) {
18
33
  if (typeof v === 'string')
@@ -119,12 +134,12 @@ export function summarize(g) {
119
134
  lines.push(pk);
120
135
  lines.push(...heightfieldSummary(g));
121
136
  lines.push(...sdfGridSummary(g));
122
- lines.push(...imageSummary(g));
123
- if (g.numPoints || g.volumes.some((v) => v.kind !== 'image')) {
124
- const b = g.bbox(true);
125
- const size = [0, 1, 2].map((a) => b.max[a] - b.min[a]);
126
- lines.push(`bbox: min ${v3(b.min)} max ${v3(b.max)} size ${size.map(fmtNum).join(' × ')} center ${v3([0, 1, 2].map((a) => (b.min[a] + b.max[a]) / 2))}`);
127
- }
137
+ const im = imagesLine(g);
138
+ if (im)
139
+ lines.push(im);
140
+ const bb = bboxLine(g);
141
+ if (bb)
142
+ lines.push(bb);
128
143
  const attrLines = [];
129
144
  for (const cls of ['point', 'vertex', 'prim', 'detail']) {
130
145
  const t = g.table(cls);
@@ -161,6 +176,22 @@ export function summarize(g) {
161
176
  lines.push(`groups: ${grp.join(' ')}`);
162
177
  return lines.join('\n');
163
178
  }
179
+ /** One line for the images: name, size and layers of each (inspect detail "attributes" gives each layer's range). */
180
+ export function imagesLine(g, max = 8) {
181
+ const imgs = imagesOf(g);
182
+ if (!imgs.length)
183
+ return null;
184
+ const one = (img) => `"${img.name}" ${img.width}×${img.height}${img.layers.size > 1 ? ` ${[...img.layers.keys()].join('+')}` : ''}`;
185
+ return `images (${imgs.length}): ${imgs.slice(0, max).map(one).join(', ')}${imgs.length > max ? `, … ${imgs.length - max} more` : ''}`;
186
+ }
187
+ /** The bbox in metres to the millimetre: min, max, size, centre. */
188
+ export function bboxLine(g) {
189
+ if (!(g.numPoints || g.volumes.some((v) => v.kind !== 'image')))
190
+ return null;
191
+ const b = g.bbox(true);
192
+ const size = [0, 1, 2].map((a) => b.max[a] - b.min[a]);
193
+ return `bbox: min ${v3mm(b.min)} max ${v3mm(b.max)} size ${size.map(mm).join(' × ')} m, center ${v3mm([0, 1, 2].map((a) => (b.min[a] + b.max[a]) / 2))}`;
194
+ }
164
195
  function attribStats(a, count, sel) {
165
196
  if (a.isArray)
166
197
  return arrayStats(a, count, sel);
@@ -206,10 +237,20 @@ function attribStats(a, count, sel) {
206
237
  return `min ${f(mn)} max ${f(mx)} mean ${f(sum.map((x) => x / k))}${extra}${nan ? `, ${nan} NaN/inf` : ''}`;
207
238
  }
208
239
  export function inspect(g, o = {}) {
209
- const out = [summarize(g)];
210
240
  const detail = o.detail ?? 'summary';
241
+ if (detail === 'summary')
242
+ return summaryLines(g).join('\n');
243
+ const out = [summarize(g)];
244
+ if (detail === 'budget') {
245
+ const b = budgetReport(g, o.nodes);
246
+ out.push(...budgetText(b));
247
+ if (o.json)
248
+ out.push('budget (JSON):', JSON.stringify(b));
249
+ return out.join('\n');
250
+ }
211
251
  const sel = o.group && (o.cls === 'point' || o.cls === 'prim' || o.cls === 'vertex') ? evalGroup(g, o.cls, o.group) : null;
212
252
  if (detail === 'attributes' || detail === 'all') {
253
+ out.push(...imageSummary(g));
213
254
  out.push('attribute stats:');
214
255
  for (const cls of ['point', 'vertex', 'prim', 'detail']) {
215
256
  if (o.cls && o.cls !== cls)
@@ -222,26 +263,8 @@ export function inspect(g, o = {}) {
222
263
  }
223
264
  }
224
265
  }
225
- if (detail === 'topology' || detail === 'all') {
226
- const r = topologyReport(g);
227
- out.push('topology:');
228
- out.push(` ${r.closed ? 'CLOSED manifold surface (watertight)' : `open/non-manifold: ${r.boundaryEdges} boundary edges, ${r.nonManifoldEdges} non-manifold edges`}`);
229
- out.push(` ${r.pieces} connected piece(s); ${r.edges} edges; ${r.degenerate} degenerate prims; ${r.unusedPoints} unused points`);
230
- const t = triangleReport(g);
231
- if (t.triangles) {
232
- const ids = (a) => (a.length ? ` (prims ${a.slice(0, 12).join(' ')}${a.length > 12 ? ' …' : ''})` : '');
233
- out.push(` ${t.triangles} render/export triangles; min area ${fmtNum(t.minArea)}, min quality ${fmtNum(t.minQuality)}; ${t.degenerate} degenerate${ids(t.degeneratePrims)}, ${t.nearDegenerate} near-degenerate${ids(t.nearDegeneratePrims)}`);
234
- }
235
- const flipped = halfEdges(g).flippedEdges.size;
236
- if (flipped)
237
- out.push(` ${flipped} edge(s) with inconsistent winding between neighbouring polygons (use reverse on part of the mesh or clean fix_winding)`);
238
- let area = 0;
239
- for (let p = 0; p < g.numPrims; p++)
240
- area += primArea(g, p);
241
- out.push(` surface area ${fmtNum(area)}${r.closed ? `; volume ${fmtNum(signedVolume(g))}${signedVolume(g) < 0 ? ' (NEGATIVE: faces point inward — use reverse)' : ''}` : ''}`);
242
- if (r.closed && r.pieces === 1)
243
- out.push(` euler ${r.euler} → genus ${(2 - r.euler) / 2}`);
244
- }
266
+ if (detail === 'topology' || detail === 'all')
267
+ out.push('topology:', ...topologyLines(g));
245
268
  if (detail === 'uv') {
246
269
  const r = uvReport(g, { attribute: o.uvAttrib, resolution: o.uvResolution });
247
270
  out.push(...uvReportText(r));
@@ -280,6 +303,218 @@ export function inspect(g, o = {}) {
280
303
  }
281
304
  return out.join('\n');
282
305
  }
306
+ /**
307
+ * One screen: counts with the triangles export and render draw, bbox in metres to the millimetre, parts (prim "name"),
308
+ * materials with their maps, images, the uv state (charts, in-tile overlap, outside 0..1, tiling, utilization) and
309
+ * whether it is a closed solid (open edges after welding seam splits), then attributes and groups.
310
+ */
311
+ export function summaryLines(g) {
312
+ const short = summarize(g).split('\n');
313
+ const out = [];
314
+ const tris = expandedTriangles(g);
315
+ out.push(short[0] + (tris ? `; ${n(tris)} triangles` : ''));
316
+ out.push(...short.slice(1).filter((l) => !l.startsWith('attributes:') && !l.startsWith(' ') && !l.startsWith('groups:')));
317
+ const na = g.prims.get('name');
318
+ if (na && na.type === 'string' && g.numPrims) {
319
+ const by = new Map();
320
+ for (let p = 0; p < g.numPrims; p++) {
321
+ const k = String(na.get(p) ?? '');
322
+ by.set(k, (by.get(k) ?? 0) + 1);
323
+ }
324
+ const list = [...by].sort((x, y) => y[1] - x[1]);
325
+ out.push(`parts (prim "name", ${list.length}): ${list.slice(0, 10).map(([k, c]) => `"${k}" ${n(c)}`).join(', ')}${list.length > 10 ? `, … ${list.length - 10} more` : ''}`);
326
+ }
327
+ const table = readMaterials(g), pm = primMaterials(g);
328
+ if (pm || Object.keys(table).length) {
329
+ const count = new Map();
330
+ if (pm)
331
+ for (let p = 0; p < g.numPrims; p++)
332
+ count.set(pm[p], (count.get(pm[p]) ?? 0) + 1);
333
+ const names = [...new Set([...Object.keys(table), ...count.keys()])].filter((k) => k !== '').sort();
334
+ const one = (k) => {
335
+ const m = table[k];
336
+ const maps = m?.textures ? Object.entries(m.textures).filter(([, v]) => !!v).map(([t]) => t) : [];
337
+ return `${k} (${n(count.get(k) ?? 0)} prims${m ? '' : ', not in the table'}${maps.length ? `; maps ${maps.join(', ')}` : ''})`;
338
+ };
339
+ out.push(`materials (${names.length}): ${names.slice(0, 8).map(one).join(', ')}${names.length > 8 ? `, … ${names.length - 8} more` : ''}`);
340
+ }
341
+ // uv state, bounded so a summary stays quick
342
+ const uvA = g.findAttrib('uv', ['vertex', 'point']);
343
+ if (uvA && g.numPrims) {
344
+ const r = uvReport(g, { maxPairTests: 500_000, maxExamples: 1 });
345
+ const ov = r.overlap;
346
+ out.push(`uv: ${n(r.charts)} charts${r.tiling ? `, TILING (${n(r.tilingCharts)} charts run across tile borders)` : ''}; in-tile overlap ${n(ov.inTile.pairs)} pairs${ov.inTile.pairs && ov.examples[0] ? ` (first ${ov.examples[0].where[0]})` : ''}${ov.acrossLods.pairs ? `, across LODs ${n(ov.acrossLods.pairs)}` : ''}; ${n(r.outOfTile)} triangles outside 0..1; ${n(r.collapsed)} collapsed; utilization ${(r.utilization.value * 100).toFixed(1)}%${r.utilization.method === 'raster-estimate' ? ' (estimate)' : ''}${r.complete ? '' : ' (INCOMPLETE: inspect detail "uv")'}`);
347
+ }
348
+ else if (g.numPrims)
349
+ out.push('uv: none');
350
+ if (g.numPrims && g.primClosed.some((c) => c === 1)) {
351
+ const sr = solidReport(g, { flips: false });
352
+ out.push(`topology: ${sr.closedAfterWeld ? (sr.closed ? 'closed solid' : 'closed solid after welding seam splits') : 'NOT a closed solid'}; ${openEdgesText(sr)}${sr.openEdges ? `, first ${sr.firstOpen}` : ''}${sr.nonManifoldEdges ? `; ${n(sr.nonManifoldEdges)} non-manifold edges` : ''}; ${n(sr.pieces)} piece(s)`);
353
+ }
354
+ out.push(...short.filter((l) => l.startsWith('attributes:') || l.startsWith(' ') || l.startsWith('groups:')));
355
+ return out;
356
+ }
357
+ /** Triangle budget: per part, per LOD and per node (see BudgetReport). */
358
+ export function budgetReport(g, nodes = []) {
359
+ const na = g.prims.get('name');
360
+ const nameOf = (p) => (na && na.type === 'string' ? String(na.get(p) ?? '') : '');
361
+ const by = new Map();
362
+ const part = (name) => { let x = by.get(name); if (!x)
363
+ by.set(name, (x = { name, lod: lodOf(name), triangles: 0, prims: 0, instances: 0 })); return x; };
364
+ let polyT = 0, instT = 0, instances = 0;
365
+ const srcNames = g.hasPacked() ? packedSourceNames(g) : [];
366
+ const srcTris = g.hasPacked() ? g.packedSources.map(expandedTriangles) : [];
367
+ for (let p = 0; p < g.numPrims; p++) {
368
+ const k = g.primKind ? g.primKind[p] : 0;
369
+ if (k === 1) {
370
+ const t = srcTris[g.packedSource[p]] ?? 0, x = part(nameOf(p) || `instances of ${srcNames[g.packedSource[p]] ?? 'a source'}`);
371
+ x.triangles += t;
372
+ x.instances++;
373
+ instT += t;
374
+ instances++;
375
+ continue;
376
+ }
377
+ if (k || !g.primClosed[p])
378
+ continue;
379
+ const sz = g.primSize(p);
380
+ if (sz < 3)
381
+ continue;
382
+ const x = part(nameOf(p));
383
+ x.triangles += sz - 2;
384
+ x.prims++;
385
+ polyT += sz - 2;
386
+ }
387
+ const parts = [...by.values()].filter((x) => x.triangles > 0 || x.prims > 0).sort((x, y) => y.triangles - x.triangles || (x.name < y.name ? -1 : 1));
388
+ const lodSet = [...new Set(parts.map((x) => x.lod))].sort((a, b) => (a < 0 ? 1 : b < 0 ? -1 : a - b));
389
+ const lods = parts.some((x) => x.lod >= 0) ? lodSet.map((lod) => { const ps = parts.filter((x) => x.lod === lod); return { lod, triangles: ps.reduce((s, x) => s + x.triangles, 0), parts: ps }; }) : [];
390
+ // per node: its triangles, minus those of the inputs it reads
391
+ const tris = new Map();
392
+ for (const x of nodes)
393
+ if (x.geo)
394
+ tris.set(x.node, expandedTriangles(x.geo));
395
+ // nodes whose output draws no triangles (bakes, images, points) are not part of the mesh budget
396
+ const rows = nodes.filter((x) => x.geo && (tris.get(x.node) ?? 0) > 0).map((x) => {
397
+ const t = tris.get(x.node) ?? 0, inT = x.inputs.reduce((s, i) => s + (tris.get(i) ?? 0), 0);
398
+ return { node: x.node, type: x.type, triangles: t, added: t - inT };
399
+ }).sort((a, b) => b.added - a.added || (a.node < b.node ? -1 : 1));
400
+ return { triangles: polyT + instT, polygonTriangles: polyT, instanceTriangles: instT, instances, parts, lods, nodes: rows };
401
+ }
402
+ /** The budget as text: totals, parts (per LOD when names carry one), nodes. */
403
+ export function budgetText(b) {
404
+ const out = [`budget: ${n(b.triangles)} triangles${b.instances ? ` (${n(b.polygonTriangles)} in polygons + ${n(b.instanceTriangles)} in ${n(b.instances)} packed instances, expanded)` : ''}`];
405
+ const pct = (x, of) => (of ? `${((x / of) * 100).toFixed(1)}%` : '-');
406
+ const w = Math.min(40, Math.max(8, ...b.parts.map((x) => (x.name || '(no name)').length)));
407
+ const row = (x, of) => ` ${(x.name || '(no name)').padEnd(w)} ${n(x.triangles).padStart(10)} ${pct(x.triangles, of).padStart(6)}${x.instances ? ` (${n(x.instances)} instances)` : ''}`;
408
+ if (!b.parts.length)
409
+ out.push(' no polygons');
410
+ else if (b.lods.length) {
411
+ out.push(`by part (prim "name": each exports as its own mesh), per LOD:`);
412
+ const lod0 = b.lods.find((l) => l.lod === 0);
413
+ for (const l of b.lods) {
414
+ out.push(` ${l.lod >= 0 ? `LOD ${l.lod}` : 'no LOD suffix'}: ${n(l.triangles)} triangles${l.lod > 0 && lod0 ? ` (${pct(l.triangles, lod0.triangles)} of LOD 0)` : ''}, ${l.parts.length} part(s)`);
415
+ for (const x of l.parts.slice(0, 30))
416
+ out.push(row(x, l.triangles));
417
+ if (l.parts.length > 30)
418
+ out.push(` … ${l.parts.length - 30} more`);
419
+ }
420
+ }
421
+ else {
422
+ out.push(`by part (prim "name": each exports as its own mesh), ${b.parts.length} part(s):`);
423
+ for (const x of b.parts.slice(0, 40))
424
+ out.push(row(x, b.triangles));
425
+ if (b.parts.length > 40)
426
+ out.push(` … ${b.parts.length - 40} more`);
427
+ }
428
+ if (b.nodes.length) {
429
+ const shown = b.nodes.filter((x) => x.added !== 0).slice(0, 20);
430
+ out.push(`by node (the triangles each node adds to what its inputs had, negative = removes; nodes upstream of the result):`);
431
+ const wn = Math.min(48, Math.max(8, ...shown.map((x) => `${x.node} (${x.type})`.length)));
432
+ for (const x of shown)
433
+ out.push(` ${`${x.node} (${x.type})`.padEnd(wn)} ${(x.added > 0 ? '+' : '') + n(x.added)}`.padEnd(wn + 16) + ` → ${n(x.triangles)}`);
434
+ const changing = b.nodes.filter((x) => x.added !== 0).length, same = b.nodes.length - changing;
435
+ if (changing > shown.length)
436
+ out.push(` … ${changing - shown.length} more that add or remove triangles`);
437
+ if (same)
438
+ out.push(` ${same} more pass their input's triangles on`);
439
+ }
440
+ return out;
441
+ }
442
+ /** The cooked nodes of a graph for the per-node budget (graph spec, the cook's results). */
443
+ export function nodeBudgetInput(spec, results) {
444
+ const out = [];
445
+ for (const [name, r] of results) {
446
+ const node = spec.nodes?.[name];
447
+ if (!node)
448
+ continue;
449
+ const raw = node.in, ins = [];
450
+ if (typeof raw === 'string')
451
+ ins.push(raw);
452
+ else if (Array.isArray(raw))
453
+ for (const x of raw) {
454
+ if (typeof x === 'string')
455
+ ins.push(x);
456
+ }
457
+ else if (raw && typeof raw === 'object')
458
+ for (const x of Object.values(raw)) {
459
+ if (typeof x === 'string')
460
+ ins.push(x);
461
+ }
462
+ out.push({ node: name, type: node.type, geo: r.geo, inputs: ins.map((x) => x.split(':')[0]) });
463
+ }
464
+ return out;
465
+ }
466
+ /**
467
+ * The topology section: closed solid or not and why (open edges after welding uv/normal seam splits, non-manifold
468
+ * edges, winding flips, inward pieces, degenerate faces: each with the first one's part and position and the fix),
469
+ * pieces, render/export triangle health, area, volume, genus.
470
+ */
471
+ export function topologyLines(g) {
472
+ const out = [];
473
+ const r = topologyReport(g), s = solidReport(g);
474
+ const causes = solidCauses(s);
475
+ if (!s.polys)
476
+ out.push(` no polygons (${r.lines} polylines, ${g.numPoints} points): not a surface`);
477
+ else if (s.closedAfterWeld) {
478
+ out.push(s.closed ? ' CLOSED solid (watertight: every polygon edge shared by exactly two polygons)'
479
+ : ` CLOSED solid after welding seam splits: ${openEdgesText(s)}; fuse the points to make it closed as it is`);
480
+ // a closed mesh can still have flipped faces, face inward, hold degenerate faces or cross itself
481
+ out.push(...causes.map((c) => ` ${c}`));
482
+ const x = crossingText(g);
483
+ if (x)
484
+ out.push(` ${x}`);
485
+ }
486
+ else
487
+ out.push(' NOT a closed solid:', ...causes.map((c) => ` ${c}`));
488
+ out.push(` ${s.pieces} connected piece(s) after welding seam splits${r.pieces !== s.pieces ? ` (${r.pieces} as the points are)` : ''}; ${r.edges} edges; ${r.degenerate} degenerate prims; ${r.unusedPoints} unused points`);
489
+ const t = triangleReport(g);
490
+ if (t.triangles) {
491
+ const first = (a) => (a.length ? ` (first ${primWhere(g, a[0])}${a.length > 1 ? `; parts: ${partsOf(g, a) || `${a.length} prims`}` : ''})` : '');
492
+ out.push(` ${t.triangles} render/export triangles; min area ${fmtNum(t.minArea)}, min quality ${fmtNum(t.minQuality)}; ${t.degenerate} degenerate${first(t.degeneratePrims)}, ${t.nearDegenerate} near-degenerate${first(t.nearDegeneratePrims)}`);
493
+ }
494
+ let area = 0;
495
+ for (let p = 0; p < g.numPrims; p++)
496
+ area += primArea(g, p);
497
+ const vol = s.closedAfterWeld ? signedVolume(g) : NaN;
498
+ out.push(` surface area ${fmtNum(area)}${s.closedAfterWeld ? `; volume ${fmtNum(vol)}${vol < 0 ? ' (NEGATIVE: faces point inward, use reverse)' : ''}` : ''}`);
499
+ if (r.closed && r.pieces === 1)
500
+ out.push(` euler ${r.euler} → genus ${(2 - r.euler) / 2}`);
501
+ return out;
502
+ }
503
+ /**
504
+ * Faces of a closed mesh that cross each other ("" when none): booleans reject such a mesh even though every edge is
505
+ * shared by two faces. Meshes above CROSSING_CHECK_MAX triangles are not searched.
506
+ */
507
+ export function crossingText(g) {
508
+ const nt = triangulate(g).tris.length / 3;
509
+ if (nt > CROSSING_CHECK_MAX)
510
+ return `(faces crossing each other not searched above ${CROSSING_CHECK_MAX.toLocaleString('en-US')} triangles)`;
511
+ const x = selfIntersections(g);
512
+ if (!x.pairs)
513
+ return '';
514
+ const first = x.prims.indexOf(1);
515
+ return `${x.pairs}${x.capped ? '+' : ''} pair(s) of faces CROSS each other, first ${primWhere(g, first)}: booleans reject it; a bevel or offset too big for a thin part does this (a smaller offset, or remesh)`;
516
+ }
517
+ const CROSSING_CHECK_MAX = 400_000;
283
518
  /** Edge listing: index, point pair, length, polygon count, dihedral angle, edge groups. */
284
519
  function edgeElements(g, o) {
285
520
  const L = edgeList(g);
@@ -1,5 +1,6 @@
1
1
  import type { Attribute, Geometry } from '../core/geometry.ts';
2
2
  import type { Quat } from '../core/math.ts';
3
+ import type { ExportSource } from './source.ts';
3
4
  export interface ExportOptions {
4
5
  /** multiply positions (e.g. 100 for metres → centimetres) */
5
6
  scale?: number;
@@ -10,8 +11,9 @@ export interface ExportOptions {
10
11
  /** cusp angle for computed normals */
11
12
  cuspAngle?: number;
12
13
  /**
13
- * include extra numeric attributes (glTF `_NAME` accessors, PLY properties, USD primvars).
14
- * glTF default: true; PLY default: true; USD default: false.
14
+ * include extra numeric attributes: glTF `_NAME` vertex and per-instance accessors, PLY properties, USD primvars
15
+ * (the export tool's custom_attribs, the CLI's --custom-attribs). Default false for glTF and USD (only the standard
16
+ * channels), true for PLY (io/targets.ts records the defaults per format).
15
17
  */
16
18
  custom?: boolean;
17
19
  /** glTF: write NORMAL (N if present, else computed with cuspAngle). false = only when N exists. Default true. */
@@ -31,9 +33,16 @@ export interface ExportOptions {
31
33
  /** glTF: write materials from the prim "material" attribute and the detail table (default true) */
32
34
  materials?: boolean;
33
35
  /**
34
- * glTF: a named material's base colour is the factor even where Cd varies (COLOR_0 is still written). For engines
35
- * whose default materials ignore vertex colours (Unreal Interchange), where glTF's white factor × COLOR_0 imports
36
- * white; spec viewers then show factor × COLOR_0. The unreal_landscape bundle sets it. Default false.
36
+ * glTF: also write Cd / Alpha (COLOR_0) on primitives whose prim "material" names a material of the table (the
37
+ * export tool's vertex_colors). Default false: a named material decides their colour as it is and their Cd is not
38
+ * written (no COLOR_0, no white-factor or tinted copy of the material); primitives without one keep their Cd.
39
+ */
40
+ vertexColors?: boolean;
41
+ /**
42
+ * glTF with vertexColors: a named material's base colour is the factor even where Cd varies (COLOR_0 is still
43
+ * written). For engines whose default materials ignore vertex colours (Unreal Interchange), where glTF's white
44
+ * factor × COLOR_0 imports white; spec viewers then show factor × COLOR_0. The unreal_landscape bundle sets it.
45
+ * Default false.
37
46
  */
38
47
  materialColorWins?: boolean;
39
48
  /** glTF: polylines as one LINE_STRIP per curve ('strip', default) or one LINES primitive ('lines') */
@@ -52,6 +61,12 @@ export interface ExportOptions {
52
61
  * 'expand' always writes real geometry.
53
62
  */
54
63
  instancing?: 'packed' | 'expand';
64
+ /**
65
+ * glTF with packed instances: write the instances' Cd (with Alpha, VEC4) as the `_COLOR` instance accessor even
66
+ * without `custom`, and no other per-instance attribute, for engines that read instance colours alone (Godot's
67
+ * MultiMesh: src/host/godot.ts sets it). Default false.
68
+ */
69
+ instanceColors?: boolean;
55
70
  /**
56
71
  * csv / points.json with packed prims: 'rows' (default) = the instance stream, one row per instance with its full
57
72
  * transform (P, orient, scale; PCG Position/Rotation/Scale), a Mesh column naming the source and the anchor
@@ -68,6 +83,11 @@ export interface ExportOptions {
68
83
  deflate?: (data: Uint8Array) => Uint8Array;
69
84
  /** receives non-fatal notes (instances expanded for a format without instancing, shear dropped, …) */
70
85
  warn?: (msg: string) => void;
86
+ /**
87
+ * How the export was made (io/source.ts). glb / gltf write it to asset.extras.source; exportFilesAsync (io/files.ts)
88
+ * also puts it in the format's sidecar or manifest, or in <file>.source.json next to the export.
89
+ */
90
+ source?: ExportSource;
71
91
  }
72
92
  /**
73
93
  * Attributes that define an instance's transform. copy_to_points and pack fold them into the packed transform, so
package/dist/io/export.js CHANGED
@@ -104,6 +104,7 @@ export function exportPLY(g, o = {}) {
104
104
  g = expandForExport(g, o, 'ply');
105
105
  const np = g.numPoints;
106
106
  const N = g.points.get('N'), Cd = g.points.get('Cd');
107
+ // PLY carries its extra properties by default (custom_attribs false drops them)
107
108
  const custom = o.custom !== false ? [...g.points.map].filter(([n, a]) => !SKIP_CUSTOM.has(n) && (a.type === 'float' || a.type === 'int') && a.size <= 4) : [];
108
109
  const props = ['property float x', 'property float y', 'property float z'];
109
110
  if (N && N.size === 3)
@@ -353,7 +354,7 @@ function usdaInstancer(g, o, uniq, out, mats = null) {
353
354
  out.push(` float[] primvars:displayOpacity = [${num.map((v) => fmt(v[0])).join(', ')}] (`, ...vertex);
354
355
  continue;
355
356
  }
356
- if (o.custom === false)
357
+ if (o.custom !== true)
357
358
  continue;
358
359
  const ut = usdArrayType(t, sz);
359
360
  if (!ut)
@@ -12,10 +12,29 @@ export type FileExportOptions = ExportOptions & HeightmapOptions & {
12
12
  /** unreal_landscape: quads per tile; 0 (default) keeps the single-landscape bundle. */
13
13
  tile_size?: number;
14
14
  };
15
+ export interface ExportFiles {
16
+ files: ExportFile[];
17
+ summary: string;
18
+ /** with options.source: the file that records it (a sidecar, the bundle manifest, or a standalone manifest) */
19
+ sourceFile?: string;
20
+ /** with options.source: the standalone <path>.source.json written for it (also sourceFile), when there is one */
21
+ sourceManifest?: string;
22
+ }
15
23
  /** Path without its extension (".points.json" counts as one). */
16
24
  export declare function stripExtension(p: string): string;
25
+ /** Where the standalone source manifest of an export to `path` goes: <path>.source.json, or source.json inside a textures folder. */
26
+ export declare function sourceManifestPath(format: string, path: string): string;
27
+ /** Formats whose one file carries the source block itself (asset.extras.source): the file alone tells how it was made. */
28
+ export declare const SOURCE_INSIDE: readonly ExportFormat[];
29
+ /**
30
+ * What an export of each format writes (the files of formatFiles below, and the record exportFilesAsync adds), in a
31
+ * line for a person choosing a format: the viewer's export and download menus. `instances`: the geometry holds packed
32
+ * instances, which csv and points.json write as instance rows and obj, ply and stl expand into geometry; `images`: it
33
+ * carries images (textures), which usda writes as PNGs beside the stage.
34
+ */
35
+ export declare function formatWrites(format: ExportFormat, o?: {
36
+ instances?: boolean;
37
+ images?: boolean;
38
+ }): string;
17
39
  /** Every file an export of `format` to `path` writes, plus a one-line summary. */
18
- export declare function exportFilesAsync(g: Geometry, format: ExportFormat | 'unreal_landscape', path: string, o?: FileExportOptions): Promise<{
19
- files: ExportFile[];
20
- summary: string;
21
- }>;
40
+ export declare function exportFilesAsync(g: Geometry, format: ExportFormat | 'unreal_landscape', path: string, o?: FileExportOptions): Promise<ExportFiles>;
package/dist/io/files.js CHANGED
@@ -6,6 +6,7 @@ import { flattenSource } from '../core/packed.js';
6
6
  import { baseOf, dirOf, joinPath, packedSourceNames } from './common.js';
7
7
  import { unrealLandscapeBundle } from './unreal.js';
8
8
  import { texturesExport, usdTextureFiles } from './textures.js';
9
+ import { SOURCE_SUFFIX, sourceManifestBytes } from './source.js';
9
10
  /** Path without its extension (".points.json" counts as one). */
10
11
  export function stripExtension(p) {
11
12
  if (/\.points\.json$/i.test(p))
@@ -14,12 +15,58 @@ export function stripExtension(p) {
14
15
  const dot = p.lastIndexOf('.');
15
16
  return dot > cut ? p.slice(0, dot) : p;
16
17
  }
18
+ /** The folder a textures export writes into: the path, or the directory of a .png path. */
19
+ const texturesDir = (path) => (/\.png$/i.test(path) ? dirOf(path) : path.replace(/[\\/]+$/, ''));
20
+ /** Where the standalone source manifest of an export to `path` goes: <path>.source.json, or source.json inside a textures folder. */
21
+ export function sourceManifestPath(format, path) {
22
+ return format === 'textures' ? joinPath(texturesDir(path), 'source.json') : path.replace(/[\\/]+$/, '') + SOURCE_SUFFIX;
23
+ }
24
+ /** Formats whose one file carries the source block itself (asset.extras.source): the file alone tells how it was made. */
25
+ export const SOURCE_INSIDE = ['glb', 'gltf'];
26
+ /**
27
+ * What an export of each format writes (the files of formatFiles below, and the record exportFilesAsync adds), in a
28
+ * line for a person choosing a format: the viewer's export and download menus. `instances`: the geometry holds packed
29
+ * instances, which csv and points.json write as instance rows and obj, ply and stl expand into geometry; `images`: it
30
+ * carries images (textures), which usda writes as PNGs beside the stage.
31
+ */
32
+ export function formatWrites(format, o = {}) {
33
+ const rows = o.instances ? ', one row per instance + .meshes.json with how it was made + one GLB per source mesh' : '';
34
+ const expanded = o.instances ? ' (instances expanded)' : '';
35
+ const record = ' + .source.json with how it was made';
36
+ const lines = {
37
+ glb: 'binary glTF with its textures and how it was made inside (+ .source.json in exports/)',
38
+ gltf: 'glTF JSON with its buffers, textures and how it was made inside (+ .source.json in exports/)',
39
+ usda: `USD stage${o.instances ? ' (instances as a PointInstancer)' : ''}${o.images ? ' + its textures as PNGs' : ''}${record}`,
40
+ obj: `OBJ with vertex colours, no materials${expanded}${record}`,
41
+ geo: `Houdini .geo with every attribute and group${record}`,
42
+ ply: `binary PLY with the point attributes${expanded}${record}`,
43
+ stl: `binary STL triangles, no colours${expanded}${record}`,
44
+ json: `TopoTopo JSON, everything lossless${record}`,
45
+ csv: rows ? `CSV for Unreal PCG${rows}` : `CSV, one row per point${record}`,
46
+ pointsjson: rows ? `points JSON${rows}` : `points JSON with every point attribute${record}`,
47
+ png16: '16-bit PNG + JSON sidecar with the height range and how it was made',
48
+ r16: 'RAW 16-bit heightmap + JSON sidecar with the height range and how it was made',
49
+ mask_png: `8-bit PNG of the mask layer (an Unreal weight layer)${record}`,
50
+ unreal_landscape: 'a folder: heightmap, weight layers, meshes and instances + landscape.json with the import settings and how it was made',
51
+ textures: 'a folder of PNGs, one per image + source.json with how it was made',
52
+ };
53
+ return lines[format];
54
+ }
17
55
  /** Every file an export of `format` to `path` writes, plus a one-line summary. */
18
56
  export async function exportFilesAsync(g, format, path, o = {}) {
57
+ const res = await formatFiles(g, format, path, o);
58
+ if (!o.source)
59
+ return { files: res.files, summary: res.summary };
60
+ if (res.sourceFile)
61
+ return res;
62
+ const at = sourceManifestPath(format, path);
63
+ return { files: [...res.files, { path: at, bytes: sourceManifestBytes(o.source, at, res.files.map((f) => f.path)) }], summary: res.summary, sourceFile: at, sourceManifest: at };
64
+ }
65
+ /** The files of the format; sourceFile names the sidecar that took options.source, if one did. */
66
+ async function formatFiles(g, format, path, o) {
19
67
  if (format === 'textures') {
20
68
  // a directory (or the directory of a .png path) with one PNG per image
21
- const dir = /\.png$/i.test(path) ? dirOf(path) : path.replace(/[\\/]+$/, '');
22
- return texturesExport(g, dir, { deflate: o.deflate, layers: o.layers });
69
+ return texturesExport(g, texturesDir(path), { deflate: o.deflate, layers: o.layers });
23
70
  }
24
71
  const nImages = g.volumes.filter((v) => v.kind === 'image').length;
25
72
  if (nImages && !['glb', 'gltf', 'usda', 'json'].includes(format))
@@ -34,27 +81,32 @@ export async function exportFilesAsync(g, format, path, o = {}) {
34
81
  if (HEIGHTMAP_FORMATS.includes(format)) {
35
82
  const res = heightmapExport(g, format, o);
36
83
  const paths = heightmapPaths(path, res.files);
37
- return { files: res.files.map((f, i) => ({ path: paths[i], bytes: f.bytes })), summary: res.summary };
84
+ const sidecar = res.files.findIndex((f) => f.kind === 'sidecar');
85
+ return { files: res.files.map((f, i) => ({ path: paths[i], bytes: f.bytes })), summary: res.summary, sourceFile: o.source && sidecar >= 0 ? paths[sidecar] : undefined };
38
86
  }
39
87
  if (format === 'unreal_landscape') {
40
88
  const isManifest = /\.json$/i.test(path);
41
89
  const dir = isManifest ? dirOf(path) : path.replace(/[\\/]+$/, '');
42
- const res = await unrealLandscapeBundle(g, { ...o, manifestName: isManifest ? baseOf(path) : undefined });
43
- return { files: res.files.map((f) => ({ path: joinPath(dir, f.path), bytes: f.bytes })), summary: res.summary };
90
+ const manifestName = isManifest ? baseOf(path) : undefined;
91
+ const res = await unrealLandscapeBundle(g, { ...o, manifestName });
92
+ return { files: res.files.map((f) => ({ path: joinPath(dir, f.path), bytes: f.bytes })), summary: res.summary, sourceFile: o.source ? joinPath(dir, manifestName || 'landscape.json') : undefined };
44
93
  }
45
94
  const bytes = await exportGeometryAsync(g, format, o);
46
95
  const files = [{ path, bytes }];
47
96
  if ((format === 'csv' || format === 'pointsjson') && instanceRows(g, o)) {
48
97
  const base = stripExtension(path);
49
98
  const meshDir = baseOf(base) + '_meshes';
50
- files.push({ path: base + '.meshes.json', bytes: new TextEncoder().encode(instanceMeshesJSON(g, { meshDir, stream: baseOf(path) })) });
99
+ files.push({ path: base + '.meshes.json', bytes: new TextEncoder().encode(instanceMeshesJSON(g, { meshDir, stream: baseOf(path), source: o.source })) });
51
100
  if (o.meshes !== false) {
52
101
  const names = packedSourceNames(g);
53
102
  for (let s = 0; s < g.packedSources.length; s++) {
54
- files.push({ path: joinPath(dirOf(base), meshDir, names[s] + '.glb'), bytes: await exportGLB(flattenSource(g.packedSources[s]), { materials: o.materials, readFile: o.readFile, warn: o.warn, custom: o.custom }) });
103
+ files.push({ path: joinPath(dirOf(base), meshDir, names[s] + '.glb'), bytes: await exportGLB(flattenSource(g.packedSources[s]), { materials: o.materials, readFile: o.readFile, warn: o.warn, custom: o.custom, vertexColors: o.vertexColors }) });
55
104
  }
56
105
  }
57
- return { files, summary: `${g.numPacked} instance rows (Mesh column) of ${g.packedSources.length} source mesh(es); sidecar ${baseOf(base)}.meshes.json${o.meshes !== false ? ` + ${meshDir}/*.glb` : ''}` };
106
+ return {
107
+ files, summary: `${g.numPacked} instance rows (Mesh column) of ${g.packedSources.length} source mesh(es); sidecar ${baseOf(base)}.meshes.json${o.meshes !== false ? ` + ${meshDir}/*.glb` : ''}`,
108
+ sourceFile: o.source ? base + '.meshes.json' : undefined,
109
+ };
58
110
  }
59
111
  return { files, summary: `${format}, ${(bytes.byteLength / 1024).toFixed(1)} KB` };
60
112
  }