topotopo 0.4.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 (336) hide show
  1. package/NOTICE +10 -10
  2. package/README.md +460 -117
  3. package/dist/cli.js +323 -146
  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 +196 -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 +44 -5
  191. package/dist/render/preview.d.ts +15 -4
  192. package/dist/render/preview.js +6 -4
  193. package/dist/render/raster.d.ts +66 -5
  194. package/dist/render/raster.js +506 -138
  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 +17 -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
@@ -19,6 +19,10 @@ export interface UVOverlap {
19
19
  prims: [number, number];
20
20
  area: number;
21
21
  sameChart: boolean;
22
+ /** inTile (two atlas charts), tiling (a tiling chart) or acrossLods (different LODs) */
23
+ kind: 'inTile' | 'tiling' | 'acrossLods';
24
+ /** where the two prims are: "prim 12 of "barrel" (group …) at (x, y, z)" (core/report.ts) */
25
+ where: [string, string];
22
26
  }
23
27
  export interface UVPiece {
24
28
  name: string;
@@ -27,8 +31,33 @@ export interface UVPiece {
27
31
  uvArea: number;
28
32
  texelsPerMetre?: number;
29
33
  }
34
+ export interface UVOverlapClass {
35
+ pairs: number;
36
+ area: number;
37
+ }
38
+ /**
39
+ * Texel density of atlas charts (tiling charts are left out): sqrt(uv area / surface area), in texels per metre with a
40
+ * resolution (times sqrt(width · height)), else in uv units per metre. overall: all charts together; p05 / median / p95:
41
+ * per chart, weighted by surface area; min / max: over charts holding at least 0.1 % of the surface, with where they are.
42
+ */
43
+ export interface UVDensity {
44
+ unit: 'texels/m' | 'uv/m';
45
+ charts: number;
46
+ overall: number;
47
+ p05: number;
48
+ median: number;
49
+ p95: number;
50
+ min: number;
51
+ max: number;
52
+ lowest: string | null;
53
+ highest: string | null;
54
+ }
30
55
  export interface UVReport {
31
56
  attribute: string;
57
+ /** charts run across tile borders: uv for a repeating texture, not an atlas (their overlaps are overlap.tiling) */
58
+ tiling: boolean;
59
+ /** how many charts run across tile borders */
60
+ tilingCharts: number;
32
61
  /** false when uv is missing or a bound stopped the analysis early; reasons lists why */
33
62
  complete: boolean;
34
63
  reasons: string[];
@@ -37,6 +66,10 @@ export interface UVReport {
37
66
  nonFinite: number;
38
67
  collapsed: number;
39
68
  collapsedTriangles: number[];
69
+ /** where the first collapsed triangle is (its prim's part and the triangle's centre), or null */
70
+ firstCollapsed: string | null;
71
+ /** where the first triangle outside the unit tile is, or null */
72
+ firstOutOfTile: string | null;
40
73
  /** triangles with uv winding opposite to the majority (mirrored islands are legal; listed for review) */
41
74
  mirrored: number;
42
75
  outOfTile: number;
@@ -44,12 +77,19 @@ export interface UVReport {
44
77
  tiles: string[];
45
78
  charts: number;
46
79
  uvArea: number;
80
+ /**
81
+ * pairs / area: every overlapping triangle pair; inTile: between atlas charts (what a bake suffers); tiling: a tiling
82
+ * chart is involved (expected); acrossLods: prims of different LODs (expected); examples: inTile pairs first
83
+ */
47
84
  overlap: {
48
85
  pairs: number;
49
86
  sameChartPairs: number;
50
87
  area: number;
51
88
  candidatePairs: number;
52
89
  testedPairs: number;
90
+ inTile: UVOverlapClass;
91
+ tiling: UVOverlapClass;
92
+ acrossLods: UVOverlapClass;
53
93
  examples: UVOverlap[];
54
94
  };
55
95
  utilization: {
@@ -58,9 +98,30 @@ export interface UVReport {
58
98
  rasterSize?: number;
59
99
  note: string;
60
100
  };
101
+ /** with charts in several tiles and no overlaps: the exact covered share of each tile (UDIM number 1001 + u + 10 v) */
102
+ tileUtilization: {
103
+ tile: number;
104
+ value: number;
105
+ }[];
106
+ /** texel density of the atlas charts (null without any) */
107
+ density: UVDensity | null;
61
108
  pieces: UVPiece[];
62
109
  resolution?: [number, number];
63
110
  }
111
+ /**
112
+ * Per triangle: 0 = its chart lies in the unit tile, 1 = in one other integer tile (a UDIM tile), 2 = its chart runs
113
+ * across tile borders (a tiling chart). U: 6 uv numbers per triangle; root: the chart of a triangle.
114
+ */
115
+ export declare function chartKinds(U: Float64Array, nt: number, root: (t: number) => number): Uint8Array;
116
+ /**
117
+ * Charts: triangles joined across uv-continuous edges (both corners share the point and the uv). Returns the chart root
118
+ * of a triangle. U: 6 uv numbers per triangle (corner order of tris).
119
+ */
120
+ export declare function chartRoots(vertexPoint: ArrayLike<number>, tris: ArrayLike<number>, U: Float64Array, nt: number): (t: number) => number;
121
+ /** The LOD of a name: "barrel_lod1" → 1, "crate_LOD0" → 0, "rock.lod2" → 2; -1 without such a suffix. */
122
+ export declare function lodOf(name: string): number;
123
+ /** Per prim its LOD from the prim "name" (lodOf), or null when no name carries a LOD suffix. */
124
+ export declare function primLods(g: Geometry): Int32Array | null;
64
125
  export declare function uvReport(g: Geometry, o?: UVReportOptions, tri?: Triangulation): UVReport;
65
126
  /** Short text form of a report for inspect. */
66
127
  export declare function uvReportText(r: UVReport): string[];
@@ -1,34 +1,102 @@
1
1
  import { triangulate } from './topology.js';
2
- /** Relative tolerances: a uv triangle is collapsed below this (doubled area / squared edges); an overlap counts above this fraction of the smaller triangle's area. */
3
- const COLLAPSED_Q = 1e-9;
4
- const OVERLAP_REL = 1e-7;
5
- /** Area of the intersection of two counter-clockwise triangles (6 numbers each) by convex clipping. */
6
- function triIntersectionArea(a, b) {
7
- let poly = [a[0], a[1], a[2], a[3], a[4], a[5]];
8
- for (let e = 0; e < 3 && poly.length >= 6; e++) {
9
- const ax = b[e * 2], ay = b[e * 2 + 1], bx = b[((e + 1) % 3) * 2], by = b[((e + 1) % 3) * 2 + 1];
10
- const out = [];
11
- const n = poly.length / 2;
12
- for (let i = 0; i < n; i++) {
13
- const cx = poly[i * 2], cy = poly[i * 2 + 1], dx = poly[((i + 1) % n) * 2], dy = poly[((i + 1) % n) * 2 + 1];
14
- const sc = (bx - ax) * (cy - ay) - (by - ay) * (cx - ax), sd = (bx - ax) * (dy - ay) - (by - ay) * (dx - ax);
15
- if (sc >= 0)
16
- out.push(cx, cy);
17
- if ((sc >= 0) !== (sd >= 0)) {
18
- const t = sc / (sc - sd);
19
- out.push(cx + (dx - cx) * t, cy + (dy - cy) * t);
2
+ import { primWhere } from './report.js';
3
+ import { COLLAPSED_Q, uvOverlapPairs } from './uvoverlap.js';
4
+ /**
5
+ * Per triangle: 0 = its chart lies in the unit tile, 1 = in one other integer tile (a UDIM tile), 2 = its chart runs
6
+ * across tile borders (a tiling chart). U: 6 uv numbers per triangle; root: the chart of a triangle.
7
+ */
8
+ export function chartKinds(U, nt, root) {
9
+ const eps = 1e-9, tileOf = new Map(), out = new Uint8Array(nt);
10
+ const triTile = (t) => {
11
+ const o6 = t * 6;
12
+ for (let k = 0; k < 6; k++)
13
+ if (!Number.isFinite(U[o6 + k]))
14
+ return null;
15
+ const tu = Math.floor((U[o6] + U[o6 + 2] + U[o6 + 4]) / 3), tv = Math.floor((U[o6 + 1] + U[o6 + 3] + U[o6 + 5]) / 3);
16
+ for (let k = 0; k < 3; k++) {
17
+ const u = U[o6 + k * 2], v = U[o6 + k * 2 + 1];
18
+ if (u < tu - eps || u > tu + 1 + eps || v < tv - eps || v > tv + 1 + eps)
19
+ return 'x';
20
+ }
21
+ return `${tu},${tv}`;
22
+ };
23
+ const tt = new Array(nt);
24
+ for (let t = 0; t < nt; t++) {
25
+ const k = (tt[t] = triTile(t));
26
+ if (k === null)
27
+ continue;
28
+ const r = root(t), have = tileOf.get(r);
29
+ if (have === undefined)
30
+ tileOf.set(r, k);
31
+ else if (have !== k)
32
+ tileOf.set(r, 'x');
33
+ }
34
+ for (let t = 0; t < nt; t++) {
35
+ if (tt[t] === null)
36
+ continue;
37
+ const k = tileOf.get(root(t));
38
+ out[t] = k === 'x' ? 2 : k === '0,0' ? 0 : 1;
39
+ }
40
+ return out;
41
+ }
42
+ /**
43
+ * Charts: triangles joined across uv-continuous edges (both corners share the point and the uv). Returns the chart root
44
+ * of a triangle. U: 6 uv numbers per triangle (corner order of tris).
45
+ */
46
+ export function chartRoots(vertexPoint, tris, U, nt) {
47
+ const parent = Int32Array.from({ length: nt }, (_, i) => i);
48
+ const find = (x) => { while (parent[x] !== x) {
49
+ parent[x] = parent[parent[x]];
50
+ x = parent[x];
51
+ } return x; };
52
+ const cornerKey = (c) => `${vertexPoint[tris[c]]}:${U[c * 2]}:${U[c * 2 + 1]}`;
53
+ const corner = new Map(), cid = new Int32Array(nt * 3);
54
+ for (let c = 0; c < nt * 3; c++) {
55
+ const k = cornerKey(c);
56
+ let id = corner.get(k);
57
+ if (id === undefined) {
58
+ id = corner.size;
59
+ corner.set(k, id);
60
+ }
61
+ cid[c] = id;
62
+ }
63
+ const edgeOwner = new Map(), nc = corner.size;
64
+ for (let t = 0; t < nt; t++) {
65
+ if (!Number.isFinite(U[t * 6]) || !Number.isFinite(U[t * 6 + 2]) || !Number.isFinite(U[t * 6 + 4]))
66
+ continue;
67
+ for (let k = 0; k < 3; k++) {
68
+ const x = cid[t * 3 + k], y = cid[t * 3 + ((k + 1) % 3)];
69
+ const key = Math.min(x, y) * nc + Math.max(x, y);
70
+ const other = edgeOwner.get(key);
71
+ if (other === undefined)
72
+ edgeOwner.set(key, t);
73
+ else {
74
+ const ra = find(t), rb = find(other);
75
+ if (ra !== rb)
76
+ parent[rb] = ra;
20
77
  }
21
78
  }
22
- poly = out;
23
79
  }
24
- if (poly.length < 6)
25
- return 0;
26
- let s = 0;
27
- for (let i = 0, n = poly.length / 2; i < n; i++) {
28
- const j = (i + 1) % n;
29
- s += poly[i * 2] * poly[j * 2 + 1] - poly[j * 2] * poly[i * 2 + 1];
80
+ return find;
81
+ }
82
+ /** The LOD of a name: "barrel_lod1" → 1, "crate_LOD0" → 0, "rock.lod2" → 2; -1 without such a suffix. */
83
+ export function lodOf(name) {
84
+ const m = /[_.-]lod(\d+)$/i.exec(name);
85
+ return m ? Number(m[1]) : -1;
86
+ }
87
+ /** Per prim its LOD from the prim "name" (lodOf), or null when no name carries a LOD suffix. */
88
+ export function primLods(g) {
89
+ const na = g.prims.get('name');
90
+ if (!na || na.type !== 'string')
91
+ return null;
92
+ const out = new Int32Array(g.numPrims);
93
+ let any = false;
94
+ for (let p = 0; p < g.numPrims; p++) {
95
+ out[p] = lodOf(String(na.get(p) ?? ''));
96
+ if (out[p] >= 0)
97
+ any = true;
30
98
  }
31
- return Math.abs(s) / 2;
99
+ return any ? out : null;
32
100
  }
33
101
  export function uvReport(g, o = {}, tri = triangulate(g)) {
34
102
  const name = o.attribute || 'uv';
@@ -36,10 +104,10 @@ export function uvReport(g, o = {}, tri = triangulate(g)) {
36
104
  const res = o.resolution === undefined ? undefined : Array.isArray(o.resolution) ? [o.resolution[0], o.resolution[1]] : [o.resolution, o.resolution];
37
105
  const { tris, triPrim } = tri, nt = tris.length / 3;
38
106
  const rep = {
39
- attribute: name, complete: true, reasons: [], missing: false, triangles: nt, nonFinite: 0, collapsed: 0, collapsedTriangles: [], mirrored: 0,
107
+ attribute: name, tiling: false, tilingCharts: 0, complete: true, reasons: [], missing: false, triangles: nt, nonFinite: 0, collapsed: 0, collapsedTriangles: [], firstCollapsed: null, firstOutOfTile: null, mirrored: 0,
40
108
  outOfTile: 0, tiles: [], charts: 0, uvArea: 0,
41
- overlap: { pairs: 0, sameChartPairs: 0, area: 0, candidatePairs: 0, testedPairs: 0, examples: [] },
42
- utilization: { method: 'none', value: 0, note: '' }, pieces: [], ...(res ? { resolution: res } : {}),
109
+ overlap: { pairs: 0, sameChartPairs: 0, area: 0, candidatePairs: 0, testedPairs: 0, inTile: { pairs: 0, area: 0 }, tiling: { pairs: 0, area: 0 }, acrossLods: { pairs: 0, area: 0 }, examples: [] },
110
+ utilization: { method: 'none', value: 0, note: '' }, tileUtilization: [], density: null, pieces: [], ...(res ? { resolution: res } : {}),
43
111
  };
44
112
  const f = g.findAttrib(name, ['vertex', 'point']);
45
113
  if (!f || f.attr.type !== 'float' || f.attr.isArray) {
@@ -50,6 +118,12 @@ export function uvReport(g, o = {}, tri = triangulate(g)) {
50
118
  return rep;
51
119
  }
52
120
  const a = f.attr, d = a.data, sz = a.size;
121
+ /** a triangle in words: its prim's part, at the triangle's centre in world space */
122
+ const triWhere = (t) => {
123
+ const P = g.P, i0 = g.vertexPoint[tris[t * 3]] * 3, i1 = g.vertexPoint[tris[t * 3 + 1]] * 3, i2 = g.vertexPoint[tris[t * 3 + 2]] * 3;
124
+ const c = [0, 1, 2].map((k) => (P[i0 + k] + P[i1 + k] + P[i2 + k]) / 3);
125
+ return primWhere(g, triPrim[t], c);
126
+ };
53
127
  const U = new Float64Array(nt * 6);
54
128
  for (let c = 0; c < nt * 3; c++) {
55
129
  const v = tris[c], i = (f.cls === 'vertex' ? v : g.vertexPoint[v]) * sz;
@@ -79,12 +153,17 @@ export function uvReport(g, o = {}, tri = triangulate(g)) {
79
153
  }
80
154
  const cu = (U[o6] + U[o6 + 2] + U[o6 + 4]) / 3, cv = (U[o6 + 1] + U[o6 + 3] + U[o6 + 5]) / 3;
81
155
  tiles.add(`${Math.floor(cu)},${Math.floor(cv)}`);
82
- if (!inside)
156
+ if (!inside) {
83
157
  rep.outOfTile++;
158
+ if (rep.firstOutOfTile === null)
159
+ rep.firstOutOfTile = triWhere(t);
160
+ }
84
161
  if (!(Math.abs(cr) > COLLAPSED_Q * e2)) {
85
162
  rep.collapsed++;
86
163
  if (rep.collapsedTriangles.length < maxEx)
87
164
  rep.collapsedTriangles.push(t);
165
+ if (rep.firstCollapsed === null)
166
+ rep.firstCollapsed = triWhere(t);
88
167
  continue;
89
168
  }
90
169
  ok[t] = 1;
@@ -98,62 +177,27 @@ export function uvReport(g, o = {}, tri = triangulate(g)) {
98
177
  rep.mirrored = Math.min(pos, neg);
99
178
  rep.tiles = [...tiles].sort((x, y) => { const [a0, a1] = x.split(',').map(Number), [b0, b1] = y.split(',').map(Number); return a1 - b1 || a0 - b0; });
100
179
  // charts: union triangles across uv-continuous edges (same two points, same uv at both)
101
- const parent = Int32Array.from({ length: nt }, (_, i) => i);
102
- const find = (x) => { while (parent[x] !== x) {
103
- parent[x] = parent[parent[x]];
104
- x = parent[x];
105
- } return x; };
106
- const cornerKey = (c) => `${g.vertexPoint[tris[c]]}:${U[c * 2]}:${U[c * 2 + 1]}`;
107
- const corner = new Map(), cid = new Int32Array(nt * 3);
108
- for (let c = 0; c < nt * 3; c++) {
109
- const k = cornerKey(c);
110
- let id = corner.get(k);
111
- if (id === undefined) {
112
- id = corner.size;
113
- corner.set(k, id);
114
- }
115
- cid[c] = id;
116
- }
117
- const edgeOwner = new Map(), nc = corner.size;
118
- for (let t = 0; t < nt; t++) {
119
- if (!Number.isFinite(U[t * 6]) || !Number.isFinite(U[t * 6 + 2]) || !Number.isFinite(U[t * 6 + 4]))
120
- continue;
121
- for (let k = 0; k < 3; k++) {
122
- const x = cid[t * 3 + k], y = cid[t * 3 + ((k + 1) % 3)];
123
- const key = Math.min(x, y) * nc + Math.max(x, y);
124
- const other = edgeOwner.get(key);
125
- if (other === undefined)
126
- edgeOwner.set(key, t);
127
- else {
128
- const ra = find(t), rb = find(other);
129
- if (ra !== rb)
130
- parent[rb] = ra;
131
- }
132
- }
133
- }
180
+ const find = chartRoots(g.vertexPoint, tris, U, nt);
134
181
  const roots = new Set();
135
182
  for (let t = 0; t < nt; t++)
136
183
  if (Number.isFinite(U[t * 6]) && Number.isFinite(U[t * 6 + 2]) && Number.isFinite(U[t * 6 + 4]))
137
184
  roots.add(find(t));
138
185
  rep.charts = roots.size;
139
- // overlaps: grid candidates, exact clipping
186
+ // tiling charts (across tile borders) and the LOD of each prim, to classify the overlaps below
187
+ const kind = chartKinds(U, nt, find);
188
+ const tilingRoots = new Set();
189
+ for (let t = 0; t < nt; t++)
190
+ if (kind[t] === 2)
191
+ tilingRoots.add(find(t));
192
+ rep.tilingCharts = tilingRoots.size;
193
+ rep.tiling = tilingRoots.size > 0;
194
+ const lod = primLods(g);
195
+ const classOf = (ta, tb) => kind[ta] === 2 || kind[tb] === 2 ? 'tiling' : lod && lod[triPrim[ta]] >= 0 && lod[triPrim[tb]] >= 0 && lod[triPrim[ta]] !== lod[triPrim[tb]] ? 'acrossLods' : 'inTile';
196
+ // overlaps: grid candidates, exact clipping (core/uvoverlap.ts)
140
197
  const valid = [];
141
- let minU = Infinity, minV = Infinity, maxU = -Infinity, maxV = -Infinity;
142
198
  for (let t = 0; t < nt; t++)
143
- if (ok[t]) {
199
+ if (ok[t])
144
200
  valid.push(t);
145
- for (let k = 0; k < 3; k++) {
146
- const u = U[t * 6 + k * 2], v = U[t * 6 + k * 2 + 1];
147
- if (u < minU)
148
- minU = u;
149
- if (u > maxU)
150
- maxU = u;
151
- if (v < minV)
152
- minV = v;
153
- if (v > maxV)
154
- maxV = v;
155
- }
156
- }
157
201
  const ccw = new Float64Array(nt * 6);
158
202
  for (const t of valid) {
159
203
  const o6 = t * 6;
@@ -170,69 +214,34 @@ export function uvReport(g, o = {}, tri = triangulate(g)) {
170
214
  }
171
215
  }
172
216
  if (valid.length > 1) {
173
- const span = Math.max(maxU - minU, maxV - minV, 1e-12);
174
- const cells = Math.max(1, Math.min(1024, Math.ceil(Math.sqrt(valid.length / 2))));
175
- const cs = span / cells;
176
- const nx = Math.max(1, Math.min(1024, Math.ceil((maxU - minU) / cs) || 1)), ny = Math.max(1, Math.min(1024, Math.ceil((maxV - minV) / cs) || 1));
177
- const cellOf = (u, n, lo) => Math.max(0, Math.min(n - 1, Math.floor((u - lo) / cs)));
178
- const bb = new Float64Array(nt * 4);
179
- const counts = new Int32Array(nx * ny + 1);
180
- for (const t of valid) {
181
- const o6 = t * 6;
182
- const u0 = Math.min(U[o6], U[o6 + 2], U[o6 + 4]), u1 = Math.max(U[o6], U[o6 + 2], U[o6 + 4]), v0 = Math.min(U[o6 + 1], U[o6 + 3], U[o6 + 5]), v1 = Math.max(U[o6 + 1], U[o6 + 3], U[o6 + 5]);
183
- bb[t * 4] = u0;
184
- bb[t * 4 + 1] = v0;
185
- bb[t * 4 + 2] = u1;
186
- bb[t * 4 + 3] = v1;
187
- for (let y = cellOf(v0, ny, minV); y <= cellOf(v1, ny, minV); y++)
188
- for (let x = cellOf(u0, nx, minU); x <= cellOf(u1, nx, minU); x++)
189
- counts[y * nx + x + 1]++;
190
- }
191
- for (let i = 0; i < nx * ny; i++)
192
- counts[i + 1] += counts[i];
193
- const items = new Int32Array(counts[nx * ny]), fill = counts.slice(0, nx * ny);
194
- for (const t of valid) {
195
- const u0 = bb[t * 4], v0 = bb[t * 4 + 1], u1 = bb[t * 4 + 2], v1 = bb[t * 4 + 3];
196
- for (let y = cellOf(v0, ny, minV); y <= cellOf(v1, ny, minV); y++)
197
- for (let x = cellOf(u0, nx, minU); x <= cellOf(u1, nx, minU); x++)
198
- items[fill[y * nx + x]++] = t;
199
- }
200
- let tests = 0, stopped = false;
201
- for (let c = 0; c < nx * ny; c++) {
202
- const s = counts[c], e = counts[c + 1], cx = c % nx, cy = Math.floor(c / nx);
203
- for (let i = s; i < e; i++)
204
- for (let j = i + 1; j < e; j++) {
205
- const ta = items[i], tb = items[j];
206
- // bounding boxes overlap with positive extent, and this cell owns the pair
207
- const lu = Math.max(bb[ta * 4], bb[tb * 4]), lv = Math.max(bb[ta * 4 + 1], bb[tb * 4 + 1]);
208
- if (lu >= Math.min(bb[ta * 4 + 2], bb[tb * 4 + 2]) || lv >= Math.min(bb[ta * 4 + 3], bb[tb * 4 + 3]))
209
- continue;
210
- if (cellOf(lu, nx, minU) !== cx || cellOf(lv, ny, minV) !== cy)
211
- continue;
212
- rep.overlap.candidatePairs++;
213
- if (tests >= maxTests) {
214
- stopped = true;
215
- continue;
216
- }
217
- tests++;
218
- const A = triIntersectionArea(ccw.subarray(ta * 6, ta * 6 + 6), ccw.subarray(tb * 6, tb * 6 + 6));
219
- if (A > OVERLAP_REL * Math.min(Math.abs(signed[ta]), Math.abs(signed[tb]))) {
220
- const t0 = Math.min(ta, tb), t1 = Math.max(ta, tb), same = find(t0) === find(t1);
221
- rep.overlap.pairs++;
222
- rep.overlap.area += A;
223
- if (same)
224
- rep.overlap.sameChartPairs++;
225
- if (rep.overlap.examples.length < maxEx)
226
- rep.overlap.examples.push({ triangles: [t0, t1], prims: [triPrim[t0], triPrim[t1]], area: A, sameChart: same });
227
- }
228
- }
229
- }
230
- rep.overlap.testedPairs = tests;
231
- if (stopped) {
217
+ const scan = uvOverlapPairs(U, valid, signed, (t0, t1, A) => {
218
+ const same = find(t0) === find(t1), k = classOf(t0, t1);
219
+ rep.overlap.pairs++;
220
+ rep.overlap.area += A;
221
+ rep.overlap[k].pairs++;
222
+ rep.overlap[k].area += A;
223
+ if (same)
224
+ rep.overlap.sameChartPairs++;
225
+ // examples: the bake-relevant (inTile) pairs before the expected ones
226
+ const ex = { triangles: [t0, t1], prims: [triPrim[t0], triPrim[t1]], area: A, sameChart: same, kind: k, where: ['', ''] };
227
+ if (rep.overlap.examples.length < maxEx)
228
+ rep.overlap.examples.push(ex);
229
+ else if (k === 'inTile') {
230
+ const j = rep.overlap.examples.findIndex((e) => e.kind !== 'inTile');
231
+ if (j >= 0)
232
+ rep.overlap.examples[j] = ex;
233
+ }
234
+ }, { maxTests });
235
+ rep.overlap.candidatePairs = scan.candidatePairs;
236
+ rep.overlap.testedPairs = scan.testedPairs;
237
+ if (scan.stopped) {
232
238
  rep.complete = false;
233
- rep.reasons.push(`overlap test stopped after ${tests.toLocaleString('en-US')} exact pair tests (maxPairTests) of ${rep.overlap.candidatePairs.toLocaleString('en-US')} candidate pairs`);
239
+ rep.reasons.push(scan.reason ? `overlap test skipped: ${scan.reason}` : `overlap test stopped after ${scan.testedPairs.toLocaleString('en-US')} exact pair tests (maxPairTests) of ${scan.candidatePairs.toLocaleString('en-US')} candidate pairs`);
234
240
  }
235
- rep.overlap.examples.sort((x, y) => y.area - x.area || x.triangles[0] - y.triangles[0] || x.triangles[1] - y.triangles[1]);
241
+ const rank = (e) => (e.kind === 'inTile' ? 0 : 1);
242
+ rep.overlap.examples.sort((x, y) => rank(x) - rank(y) || y.area - x.area || x.triangles[0] - y.triangles[0] || x.triangles[1] - y.triangles[1]);
243
+ for (const e of rep.overlap.examples)
244
+ e.where = [triWhere(e.triangles[0]), triWhere(e.triangles[1])];
236
245
  }
237
246
  // utilization
238
247
  if (rep.overlap.pairs === 0 && rep.outOfTile === 0 && rep.complete) {
@@ -259,6 +268,44 @@ export function uvReport(g, o = {}, tri = triangulate(g)) {
259
268
  }
260
269
  else
261
270
  rep.utilization = { method: 'none', value: 0, note: 'no valid uv triangles' };
271
+ // texel density per atlas chart, and the covered share of each tile
272
+ {
273
+ const P = g.P, vp = g.vertexPoint, surf = new Map(), area = new Map(), first = new Map();
274
+ const tileArea = new Map();
275
+ let s3 = 0, sUV = 0;
276
+ for (let t = 0; t < nt; t++) {
277
+ if (!ok[t] || kind[t] === 2)
278
+ continue;
279
+ const i0 = vp[tris[t * 3]] * 3, i1 = vp[tris[t * 3 + 1]] * 3, i2 = vp[tris[t * 3 + 2]] * 3;
280
+ const ux = P[i1] - P[i0], uy = P[i1 + 1] - P[i0 + 1], uz = P[i1 + 2] - P[i0 + 2], wx = P[i2] - P[i0], wy = P[i2 + 1] - P[i0 + 1], wz = P[i2 + 2] - P[i0 + 2];
281
+ const a3 = 0.5 * Math.hypot(uy * wz - uz * wy, uz * wx - ux * wz, ux * wy - uy * wx), aUV = Math.abs(signed[t]), r = find(t);
282
+ surf.set(r, (surf.get(r) ?? 0) + a3);
283
+ area.set(r, (area.get(r) ?? 0) + aUV);
284
+ if (!first.has(r))
285
+ first.set(r, t);
286
+ s3 += a3;
287
+ sUV += aUV;
288
+ const tu = Math.floor((U[t * 6] + U[t * 6 + 2] + U[t * 6 + 4]) / 3), tv = Math.floor((U[t * 6 + 1] + U[t * 6 + 3] + U[t * 6 + 5]) / 3);
289
+ if (tu >= 0 && tu < 10 && tv >= 0)
290
+ tileArea.set(1001 + tu + 10 * tv, (tileArea.get(1001 + tu + 10 * tv) ?? 0) + aUV);
291
+ }
292
+ if (s3 > 0 && sUV > 0) {
293
+ const k = res ? Math.sqrt(res[0] * res[1]) : 1;
294
+ const list = [...surf].filter(([r, a]) => a > 0 && (area.get(r) ?? 0) > 0).map(([r, a]) => ({ r, a, d: Math.sqrt(area.get(r) / a) * k })).sort((x, y) => x.d - y.d || x.r - y.r);
295
+ const at = (q) => { let acc = 0; for (const c of list) {
296
+ acc += c.a;
297
+ if (acc >= q * s3)
298
+ return c.d;
299
+ } return list[list.length - 1].d; };
300
+ const big = list.filter((c) => c.a >= s3 * 1e-3), lo = big[0] ?? list[0], hi = big[big.length - 1] ?? list[list.length - 1];
301
+ rep.density = {
302
+ unit: res ? 'texels/m' : 'uv/m', charts: list.length, overall: Math.sqrt(sUV / s3) * k, p05: at(0.05), median: at(0.5), p95: at(0.95),
303
+ min: lo.d, max: hi.d, lowest: triWhere(first.get(lo.r)), highest: triWhere(first.get(hi.r)),
304
+ };
305
+ }
306
+ if (tileArea.size > 1 && rep.overlap.inTile.pairs === 0 && rep.complete)
307
+ rep.tileUtilization = [...tileArea].sort((x, y) => x[0] - y[0]).map(([tile, value]) => ({ tile, value }));
308
+ }
262
309
  // per-piece surface and uv area, texel density
263
310
  const pa = g.prims.get(o.pieceAttrib || 'name');
264
311
  if (pa && pa.type === 'string') {
@@ -290,12 +337,29 @@ export function uvReportText(r) {
290
337
  const out = [`uv "${r.attribute}": ${r.complete ? 'COMPLETE' : 'INCOMPLETE'} analysis of ${r.triangles} triangles${r.reasons.length ? ` (${r.reasons.join('; ')})` : ''}`];
291
338
  if (r.missing)
292
339
  return out;
293
- out.push(` ${r.charts} charts; tiles ${r.tiles.join(' ') || 'none'}; ${r.outOfTile} triangles outside 0..1; ${r.nonFinite} non-finite; ${r.collapsed} collapsed${r.collapsedTriangles.length ? ` (triangles ${r.collapsedTriangles.join(' ')}${r.collapsed > r.collapsedTriangles.length ? ' …' : ''})` : ''}; ${r.mirrored} mirrored`);
340
+ out.push(` ${r.charts} charts; tiles ${r.tiles.join(' ') || 'none'}; ${r.outOfTile} triangles outside 0..1; ${r.nonFinite} non-finite; ${r.collapsed} collapsed; ${r.mirrored} mirrored`);
341
+ if (r.collapsed && r.firstCollapsed)
342
+ out.push(` collapsed (no uv area: bakes and normal maps have no direction there), first ${r.firstCollapsed}`);
294
343
  const ov = r.overlap;
295
- out.push(` overlaps: ${ov.pairs} triangle pairs (${ov.sameChartPairs} within one chart), area ${f(ov.area)}; ${ov.testedPairs} of ${ov.candidatePairs} candidate pairs tested exactly`);
344
+ if (r.tiling)
345
+ out.push(` TILING: ${r.tilingCharts} chart${r.tilingCharts === 1 ? ' runs' : 's run'} across tile borders: uv for a repeating texture, not an atlas; overlap there is expected`);
346
+ out.push(` overlaps in tiles (atlas, what a bake suffers): ${ov.inTile.pairs} triangle pairs, area ${f(ov.inTile.area)}; ${ov.testedPairs} of ${ov.candidatePairs} candidate pairs tested exactly`);
347
+ if (ov.tiling.pairs)
348
+ out.push(` overlaps of tiling charts (expected): ${ov.tiling.pairs} pairs, area ${f(ov.tiling.area)}`);
349
+ if (ov.acrossLods.pairs)
350
+ out.push(` overlaps across LODs (expected: names with different _lodN suffixes share the uv space): ${ov.acrossLods.pairs} pairs, area ${f(ov.acrossLods.area)}`);
351
+ if (ov.sameChartPairs)
352
+ out.push(` ${ov.sameChartPairs} of the ${ov.pairs} overlapping pairs lie within one chart (folds)`);
296
353
  for (const e of ov.examples.slice(0, 8))
297
- out.push(` triangles ${e.triangles[0]} × ${e.triangles[1]} (prims ${e.prims[0]} × ${e.prims[1]}${e.sameChart ? ', same chart' : ''}): area ${f(e.area)}`);
298
- out.push(` utilization ${(r.utilization.value * 100).toFixed(2)}% (${r.utilization.method}${r.utilization.rasterSize ? ` ${r.utilization.rasterSize}²` : ''}): ${r.utilization.note}; uv area ${f(r.uvArea)}`);
354
+ out.push(` ${e.kind === 'inTile' ? '' : `[${e.kind === 'tiling' ? 'tiling' : 'across LODs'}] `}${e.where[0]} × ${e.where[1]}${e.sameChart ? ' (same chart: a fold)' : ''}: uv area ${f(e.area)}`);
355
+ out.push(` utilization ${(r.utilization.value * 100).toFixed(2)}% (${r.utilization.method}${r.utilization.rasterSize ? ` ${r.utilization.rasterSize}²` : ''}): ${r.utilization.note}; uv area ${f(r.uvArea)}${r.tiling ? ' (says little for tiling uv)' : ''}`);
356
+ if (r.outOfTile && r.firstOutOfTile && !r.tiling)
357
+ out.push(` outside 0..1, first ${r.firstOutOfTile}`);
358
+ if (r.tileUtilization.length)
359
+ out.push(` utilization per tile: ${r.tileUtilization.map((t) => `${t.tile} ${(t.value * 100).toFixed(1)}%`).join(', ')}`);
360
+ const d = r.density;
361
+ if (d)
362
+ out.push(` texel density (${d.unit}${d.unit === 'uv/m' ? '; --uv-resolution gives texels/m' : ` at ${r.resolution[0]}×${r.resolution[1]}`}): ${f(d.overall)} over ${d.charts} charts; per chart 5% ${f(d.p05)}, median ${f(d.median)}, 95% ${f(d.p95)} (by area); lowest ${f(d.min)} at ${d.lowest}, highest ${f(d.max)} at ${d.highest}`);
299
363
  if (r.pieces.length) {
300
364
  const shown = r.pieces.slice(0, 24);
301
365
  out.push(` pieces (${r.pieces.length})${r.resolution ? `, texel density at ${r.resolution[0]}×${r.resolution[1]}` : ''}:`);
@@ -4,6 +4,8 @@ import type { TypedArray } from './kernels.ts';
4
4
  import type { Host } from '../host/types.ts';
5
5
  import type { UserCodeError } from './usercode.ts';
6
6
  export type RunOver = 'points' | 'prims' | 'vertices' | 'detail';
7
+ /** The names every wrangle defines (@ptnum … @TimeInc, also readable without the @): a graph var cannot take one. */
8
+ export declare const WRANGLE_NAMES: ReadonlySet<string>;
7
9
  export interface WrangleResult {
8
10
  geo: Geometry;
9
11
  log: string[];
@@ -25,6 +27,7 @@ export interface WrangleOptions {
25
27
  runOver: RunOver;
26
28
  mask: Uint8Array | null;
27
29
  inputs: Geometry[];
30
+ /** the cook's graph vars: those the snippet names are bound by their bare name (frozen copies) */
28
31
  vars: Record<string, any>;
29
32
  host: Host;
30
33
  timeoutMs: number;
@@ -36,7 +39,8 @@ export declare function runWrangle(geo: Geometry, opts: WrangleOptions): Wrangle
36
39
  * The work of a point wrangle as a kernel job for the worker pool (CookContext.parallelMap('wrangle', …)), or null
37
40
  * when the snippet cannot run in chunks: it must run over points, bind only numeric attributes and groups, and call
38
41
  * nothing that reads other elements or edits the geometry (point(), neighbours(), nearpoints(), addpoint(),
39
- * setpointattrib(), print() … see GEOMETRY_FUNCTIONS), nor touch shared state (globalThis, writes to vars).
42
+ * setpointattrib(), print() … see GEOMETRY_FUNCTIONS), nor touch shared state (globalThis). Graph vars are frozen
43
+ * constants in every chunk: writing one fails the same way on any thread.
40
44
  */
41
45
  export interface WrangleJob {
42
46
  count: number;
@@ -98,6 +102,7 @@ export declare class WrangleAPI {
98
102
  attrtype(i: number, cls: AttribClass, name: string): string;
99
103
  attr(i: number, cls: AttribClass, name: string, idx: number): string | number | any[];
100
104
  primpoints(i: number, p: number): number[];
105
+ primintrinsic(i: number, name: string, p: number): string | number | number[];
101
106
  pointprims(i: number, pt: number): number[];
102
107
  neighbours(i: number, pt: number): number[];
103
108
  private kdOf;