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
@@ -6,14 +6,17 @@
6
6
  // i[]@nbrs = nearpoints(0, @P, 0.5); // array attributes: f[] i[] s[] (read = copy, written back)
7
7
  // if (@P.y < 0) removepoint(0, @ptnum);
8
8
  // @group_top = @N.y > 0.9; // group membership
9
+ // @P.y += height * 0.5; // graph vars by their bare name, read-only
9
10
  //
10
11
  // The snippet is compiled into a kernel that loops over elements, binding each
11
- // referenced attribute to a local variable and writing it back afterwards.
12
+ // referenced attribute to a local variable and writing it back afterwards. The graph vars
13
+ // the snippet names are constants of a scope around the kernel, so its own names come first.
12
14
  import { Attribute, Geometry, defaultValueFor, isArrayType } from './geometry.js';
13
15
  import { primCentroid, primNormals, pointNeighbors, pointPrims } from './topology.js';
16
+ import { primIntrinsic } from './intrinsics.js';
14
17
  import { KDTree, TriBVH } from './spatial.js';
15
- import { GEOMETRY_FUNCTIONS, REALM_CONTROL } from './snippet-lib.js';
16
- import { runUserCode } from './usercode.js';
18
+ import { GEOMETRY_FUNCTIONS, REALM_CONTROL, scriptVarsGuard } from './snippet-lib.js';
19
+ import { codeVarDecl, codeVarNames, codeVarValues, runUserCode } from './usercode.js';
17
20
  const CLASS_OF = { points: 'point', prims: 'prim', vertices: 'vertex', detail: 'detail' };
18
21
  const PREFIX_TYPE = {
19
22
  f: { type: 'float', size: 1 }, i: { type: 'int', size: 1 }, v: { type: 'float', size: 3 },
@@ -34,6 +37,8 @@ const KNOWN = {
34
37
  };
35
38
  const SPECIAL = new Set(['ptnum', 'primnum', 'vtxnum', 'elemnum', 'numpt', 'numprim', 'numvtx', 'numelem', 'Frame', 'Time', 'TimeInc']);
36
39
  const TIME_REFS = ['Frame', 'Time', 'TimeInc'];
40
+ /** The names every wrangle defines (@ptnum … @TimeInc, also readable without the @): a graph var cannot take one. */
41
+ export const WRANGLE_NAMES = SPECIAL;
37
42
  const REF = /(?<![\w$.@])([fivpus](?:\[\])?)?@([A-Za-z_][A-Za-z0-9_]*)/g;
38
43
  /** compiled kernels per host: a kernel belongs to its host's realm (its library globals and geometry API live there) */
39
44
  const kernelCaches = new WeakMap();
@@ -62,7 +67,6 @@ export function runWrangle(geo, opts) {
62
67
  return finishWrangle(w);
63
68
  }
64
69
  const CROSS_ELEMENT = new RegExp(String.raw `\b(${GEOMETRY_FUNCTIONS.join('|')}|globalThis|this|eval|Function)\b`);
65
- const WRITES_VARS = /\bvars\b[^;\n]*?((?<![=!<>])=(?!=)|\+\+|--)/;
66
70
  /**
67
71
  * Run a wrangle, letting `par` execute a point wrangle in chunks: par(job, serial) runs the job on worker threads
68
72
  * (or calls serial() to run it here) and may return a promise. Same result as runWrangle, bit for bit: chunks run the
@@ -81,7 +85,7 @@ export function runWrangleParallel(geo, opts, par) {
81
85
  function wrangleJob(w, opts) {
82
86
  if (w.runOver !== 'points' || w.n < 2)
83
87
  return null;
84
- if (CROSS_ELEMENT.test(w.body) || WRITES_VARS.test(w.body))
88
+ if (CROSS_ELEMENT.test(w.body))
85
89
  return null;
86
90
  const inputs = {}, outputs = {};
87
91
  for (let i = 0; i < w.bindings.length; i++) {
@@ -95,13 +99,6 @@ function wrangleJob(w, opts) {
95
99
  else
96
100
  outputs['b' + i] = b.data;
97
101
  }
98
- let vars;
99
- try {
100
- vars = structuredClone(opts.vars);
101
- }
102
- catch {
103
- return null;
104
- }
105
102
  if (opts.mask)
106
103
  inputs.mask = opts.mask;
107
104
  const e = w.env;
@@ -109,7 +106,8 @@ function wrangleJob(w, opts) {
109
106
  count: w.n, inputs, outputs,
110
107
  args: {
111
108
  source: w.source, bindings: w.bindings.length, n: w.n, numpt: e.numpt, numprim: e.numprim, numvtx: e.numvtx,
112
- frame: e.frame, time: e.time, timeInc: e.timeInc, vars, timeoutMs: opts.timeoutMs, bodyLine: w.bodyLine, code: opts.code,
109
+ // the vars the snippet reads (plain data; the worker freezes its copy)
110
+ frame: e.frame, time: e.time, timeInc: e.timeInc, vars: e.vars, timeoutMs: opts.timeoutMs, bodyLine: w.bodyLine, code: opts.code,
113
111
  },
114
112
  };
115
113
  }
@@ -219,12 +217,16 @@ function prepareWrangle(geo, opts) {
219
217
  }
220
218
  }
221
219
  // ---- generate kernel source
220
+ // the graph vars the snippet names (iteration, numiterations in a loop body …): constants of the outer function,
221
+ // so the kernel's own names and the snippet's locals come first
222
+ const varNames = codeVarNames(opts.code, opts.vars);
222
223
  const src = [];
223
224
  src.push('(function(__env){', '"use strict";');
225
+ src.push(codeVarDecl(varNames, '__env.vars', '__env.varsGuard'));
226
+ src.push('return (function(){');
224
227
  // __s/__e: the element range of a chunk (the whole range when absent); numelem stays the total
225
228
  src.push('const __n=__env.n, __s=__env.s|0, __e=__env.e===undefined?__env.n:__env.e, __mask=__env.mask, __vp=__env.vp, __vprim=__env.vprim, __B=__env.B;');
226
229
  src.push('const numpt=__env.numpt, numprim=__env.numprim, numvtx=__env.numvtx, numelem=__n, Frame=__env.frame, Time=__env.time, TimeInc=__env.timeInc;');
227
- src.push('const vars=__env.vars, iteration=vars.iteration, numiterations=vars.numiterations;');
228
230
  src.push('let ptnum=0, primnum=0, vtxnum=0, elemnum=0;');
229
231
  bindings.forEach((b, i) => src.push(`const __d${i}=__B[${i}].data; let ${b.local};`));
230
232
  // user code inside a closure so `return` exits just this element
@@ -283,7 +285,7 @@ function prepareWrangle(geo, opts) {
283
285
  else
284
286
  src.push(`__wf(__d${i},${ix},${b.size},${b.local});`);
285
287
  });
286
- src.push('}', '})');
288
+ src.push('}', '})();', '})');
287
289
  const source = src.join('\n');
288
290
  let kernelCache = kernelCaches.get(opts.host);
289
291
  if (!kernelCache)
@@ -312,7 +314,8 @@ function prepareWrangle(geo, opts) {
312
314
  n, mask: runOver === 'detail' ? null : opts.mask, vp: g.vertexPoint, vprim,
313
315
  B: bindings, numpt: g.numPoints, numprim: g.numPrims, numvtx: g.numVertices,
314
316
  frame: opts.time?.frame ?? opts.vars.frame ?? 1, time: opts.time?.time ?? opts.vars.time ?? 0,
315
- timeInc: opts.time?.timeInc ?? opts.vars.timeInc ?? 1 / 24, vars: opts.vars,
317
+ timeInc: opts.time?.timeInc ?? opts.vars.timeInc ?? 1 / 24,
318
+ vars: codeVarValues(opts.vars, varNames), varsGuard: scriptVarsGuard(opts.host),
316
319
  centroid: (p) => primCentroid(g, p),
317
320
  };
318
321
  return { g, n, runOver, bindings, log, kernel, source, body, bodyLine, env, api };
@@ -539,6 +542,14 @@ export class WrangleAPI {
539
542
  return a.get(idx);
540
543
  }
541
544
  primpoints(i, p) { return this.geo(i).primPoints(p); }
545
+ primintrinsic(i, name, p) {
546
+ try {
547
+ return primIntrinsic(this.geo(i), Number(p), String(name));
548
+ }
549
+ catch (e) {
550
+ throw new Error(`primintrinsic(${i}, ${JSON.stringify(String(name))}, ${p}): ${e.message}`);
551
+ }
552
+ }
542
553
  pointprims(i, pt) {
543
554
  let m = this.pp.get(i);
544
555
  if (!m) {
@@ -40,6 +40,22 @@ export interface XatlasResult {
40
40
  chartCount: number;
41
41
  utilization: number[];
42
42
  }
43
+ /**
44
+ * xatlas charts of a set of triangles (vertex triples into g). A corner's input vertex is keyOf(v) (its point, or a
45
+ * seam-split key); triangles of different group(t) never share a chart. The triangles are scaled on their own to a
46
+ * bounding-box diagonal of XATLAS_SIZE, so a small part of a large model is charted as finely as it would be alone.
47
+ * Returns the chart per triangle (-1: xatlas dropped it, e.g. no area) and the uv per triangle corner in xatlas texel
48
+ * space: each chart's shape (where xatlas placed it is not used).
49
+ */
50
+ export declare function xatlasCharts(X: any, g: Geometry, tris: ArrayLike<number>, o: {
51
+ keyOf: (v: number) => number;
52
+ group?: ((t: number) => number) | null;
53
+ chart: XatlasChartOptions;
54
+ }): {
55
+ triChart: Int32Array;
56
+ cornerUV: Float64Array;
57
+ chartCount: number;
58
+ };
43
59
  /**
44
60
  * Run xatlas on the closed polygons of g (prims outside primMask are skipped). Input vertices are the
45
61
  * geometry points, or per-vertex keys (`vertexKey[v]`, e.g. split along seams); `faceGroup[prim]`
@@ -49,5 +65,4 @@ export declare function runXatlas(X: any, g: Geometry, chart: XatlasChartOptions
49
65
  vertexKey?: Int32Array | null;
50
66
  faceGroup?: Int32Array | null;
51
67
  primMask?: ArrayLike<number> | null;
52
- unmirror?: boolean;
53
68
  }): XatlasResult;
@@ -26,6 +26,71 @@ function xatlasScale(pos) {
26
26
  const d = Math.hypot(hi[0] - lo[0], hi[1] - lo[1], hi[2] - lo[2]);
27
27
  return d > 0 && d < XATLAS_SIZE ? XATLAS_SIZE / d : 1;
28
28
  }
29
+ /**
30
+ * xatlas charts of a set of triangles (vertex triples into g). A corner's input vertex is keyOf(v) (its point, or a
31
+ * seam-split key); triangles of different group(t) never share a chart. The triangles are scaled on their own to a
32
+ * bounding-box diagonal of XATLAS_SIZE, so a small part of a large model is charted as finely as it would be alone.
33
+ * Returns the chart per triangle (-1: xatlas dropped it, e.g. no area) and the uv per triangle corner in xatlas texel
34
+ * space: each chart's shape (where xatlas placed it is not used).
35
+ */
36
+ export function xatlasCharts(X, g, tris, o) {
37
+ const nt = Math.floor(tris.length / 3), P = g.P;
38
+ const remap = new Map(), pos = [], idx = new Uint32Array(nt * 3);
39
+ for (let i = 0; i < nt * 3; i++) {
40
+ const v = tris[i], key = o.keyOf(v);
41
+ let x = remap.get(key);
42
+ if (x === undefined) {
43
+ x = pos.length / 3;
44
+ remap.set(key, x);
45
+ const pt = g.vertexPoint[v];
46
+ pos.push(P[pt * 3], P[pt * 3 + 1], P[pt * 3 + 2]);
47
+ }
48
+ idx[i] = x;
49
+ }
50
+ const res = { triChart: new Int32Array(nt).fill(-1), cornerUV: new Float64Array(nt * 6), chartCount: 0 };
51
+ if (!nt)
52
+ return res;
53
+ let chart = o.chart;
54
+ const k = xatlasScale(pos);
55
+ if (k !== 1) {
56
+ for (let i = 0; i < pos.length; i++)
57
+ pos[i] *= k;
58
+ chart = { ...chart };
59
+ if (chart.maxChartArea)
60
+ chart.maxChartArea *= k * k;
61
+ if (chart.maxBoundaryLength)
62
+ chart.maxBoundaryLength *= k;
63
+ }
64
+ const atlas = X.createAtlas();
65
+ try {
66
+ const decl = { positions: Float32Array.from(pos), indices: idx };
67
+ if (o.group)
68
+ decl.faceMaterialData = Uint32Array.from({ length: nt }, (_, t) => Math.max(0, o.group(t)));
69
+ const err = atlas.addMesh(decl);
70
+ if (err !== 0)
71
+ throw new Error(`xatlas addMesh failed: ${X.addMeshErrorString ? X.addMeshErrorString(err) : err}`);
72
+ atlas.computeCharts(chart);
73
+ // xatlas writes uv only when it packs; the placement is thrown away, so the atlas is as small as keeps the shapes
74
+ // precise (its cost grows with its area)
75
+ atlas.packCharts({ resolution: Math.max(64, Math.min(1024, Math.round(Math.sqrt(nt) * 8))), padding: 0, rotateCharts: false, rotateChartsToAxis: false, blockAlign: true });
76
+ const m = atlas.getMesh(0);
77
+ res.chartCount = m.chartCount;
78
+ const out = m.indices;
79
+ const verts = m.vertices;
80
+ for (let i = 0; i < out.length && i < nt * 3; i++) {
81
+ const ov = verts[out[i]];
82
+ res.cornerUV[i * 2] = ov.uv[0];
83
+ res.cornerUV[i * 2 + 1] = ov.uv[1];
84
+ const t = (i / 3) | 0;
85
+ if (ov.chartIndex >= 0 && res.triChart[t] < 0)
86
+ res.triChart[t] = ov.chartIndex;
87
+ }
88
+ }
89
+ finally {
90
+ atlas.destroy();
91
+ }
92
+ return res;
93
+ }
29
94
  /**
30
95
  * Run xatlas on the closed polygons of g (prims outside primMask are skipped). Input vertices are the
31
96
  * geometry points, or per-vertex keys (`vertexKey[v]`, e.g. split along seams); `faceGroup[prim]`
@@ -60,7 +125,7 @@ export function runXatlas(X, g, chart, pack, opts = {}) {
60
125
  // xatlas compares positions and areas against absolute epsilons (about 1e-4 and 1.2e-7), so on a model a few
61
126
  // centimetres across it welds bevel corners and drops small faces as degenerate. Scale small inputs up to a
62
127
  // bounding-box diagonal of XATLAS_SIZE; the world-unit options scale with them, so the result is unchanged.
63
- const k = xatlasScale(pos), repack = pack;
128
+ const k = xatlasScale(pos);
64
129
  if (k !== 1) {
65
130
  for (let i = 0; i < pos.length; i++)
66
131
  pos[i] *= k;
@@ -101,70 +166,9 @@ export function runXatlas(X, g, chart, pack, opts = {}) {
101
166
  result.triAtlas[t] = ov.atlasIndex;
102
167
  }
103
168
  }
104
- if (opts.unmirror && repack)
105
- unmirrorAndRepack(X, result, out, verts.length, repack);
106
169
  }
107
170
  finally {
108
171
  atlas.destroy();
109
172
  }
110
173
  return result;
111
174
  }
112
- /**
113
- * xatlas charts come out in either orientation (its texel space is y-down and LSCM/planar charts are not
114
- * winding-aware). Mirror the charts whose uv winding disagrees with the polygon winding, then repack all
115
- * charts with xatlas's UV-mesh packer so the packing stays tight and overlap-free.
116
- */
117
- function unmirrorAndRepack(X, r, out, nOut, pack) {
118
- const nt = r.triChart.length;
119
- const signed = new Map();
120
- for (let t = 0; t < nt; t++) {
121
- const c = r.triChart[t];
122
- if (c < 0)
123
- continue;
124
- const u = r.cornerUV, i = t * 6;
125
- const a = (u[i + 2] - u[i]) * (u[i + 5] - u[i + 1]) - (u[i + 3] - u[i + 1]) * (u[i + 4] - u[i]);
126
- signed.set(c, (signed.get(c) ?? 0) + a);
127
- }
128
- let mirrored = 0;
129
- for (const [, a] of signed)
130
- if (a < 0)
131
- mirrored++;
132
- if (!mirrored)
133
- return;
134
- const uvs = new Float32Array(nOut * 2);
135
- for (let i = 0; i < out.length; i++) {
136
- const c = r.triChart[(i / 3) | 0];
137
- const flip = c >= 0 && signed.get(c) < 0;
138
- uvs[out[i] * 2] = flip ? -r.cornerUV[i * 2] : r.cornerUV[i * 2];
139
- uvs[out[i] * 2 + 1] = r.cornerUV[i * 2 + 1];
140
- }
141
- const b = X.createAtlas();
142
- try {
143
- const err = b.addUvMesh({ uvs, indices: out, faceMaterialData: Uint32Array.from(r.triChart, (c) => c + 1) });
144
- if (err !== 0)
145
- return;
146
- b.computeCharts();
147
- b.packCharts(pack);
148
- const m = b.getMesh(0);
149
- const o2 = m.indices;
150
- const v2 = m.vertices;
151
- if (o2.length !== out.length)
152
- return;
153
- for (let i = 0; i < o2.length; i++) {
154
- const ov = v2[o2[i]];
155
- r.cornerUV[i * 2] = ov.uv[0];
156
- r.cornerUV[i * 2 + 1] = ov.uv[1];
157
- if (i % 3 === 0)
158
- r.triAtlas[i / 3] = ov.atlasIndex;
159
- }
160
- r.width = b.width;
161
- r.height = b.height;
162
- r.atlasCount = b.atlasCount;
163
- r.utilization = [];
164
- for (let a = 0; a < b.atlasCount; a++)
165
- r.utilization.push(b.getUtilization(a));
166
- }
167
- finally {
168
- b.destroy();
169
- }
170
- }
@@ -0,0 +1,63 @@
1
+ export type EngineType = 'godot' | 'unreal';
2
+ /** The game engine a workspace builds with: its project file, written from the workspace ("game/project.godot", "../Game.uproject"). */
3
+ export interface EngineLink {
4
+ type: EngineType;
5
+ project: string;
6
+ }
7
+ /** The engine type a project file's name says, or null. */
8
+ export declare const engineTypeOf: (file: string) => EngineType | null;
9
+ /**
10
+ * Files an engine writes beside the files it imports, which never count as TopoTopo's: Godot's *.import, *.uid and
11
+ * *.translation, Unreal's *.uasset, and TopoTopo's own .gdignore. Versions, their hashes, input listings, bake keys and
12
+ * the viewer's saved outputs leave them out, so a package inside an engine project publishes what it would elsewhere.
13
+ */
14
+ export declare const isEngineFile: (name: string) => boolean;
15
+ /**
16
+ * The nearest engine project at or above a folder: project.godot in the folder or above it, a *.uproject the same;
17
+ * null when there is none. A folder holding both answers Godot's (the one a workspace there sees first).
18
+ */
19
+ export declare function engineAbove(dir: string): {
20
+ file: string;
21
+ type: EngineType;
22
+ } | null;
23
+ /** The engine projects below a folder (project.godot, *.uproject), nearest first, at most 4 levels down; paths from `dir`. */
24
+ export declare function findEngines(dir: string): EngineLink[];
25
+ /**
26
+ * The engine project a workspace at `dir` builds with when none is named: the nearest at or above it (the workspace
27
+ * inside the engine's content folder), else the nearest below it; `found` says how many there were below, when that
28
+ * is where it came from.
29
+ */
30
+ export declare function detectEngine(dir: string): {
31
+ link: EngineLink;
32
+ below: EngineLink[];
33
+ } | null;
34
+ /**
35
+ * Whether Unreal sees a folder of its project: Unreal imports only what lies under the project's Content/ folder or a
36
+ * plugin's (Plugins/…/Content/). `uproject`: the project file.
37
+ */
38
+ export declare function unrealSees(folder: string, uproject: string): boolean;
39
+ /** The Godot project a folder lies in: the folder holding the nearest project.godot at or above it; null for none. */
40
+ export declare function godotProjectOf(dir: string): string | null;
41
+ /** TopoTopo's working folders of a package, which are not game content: Godot imports none of them (a .gdignore in each). */
42
+ export declare const GODOT_IGNORED: string[];
43
+ /** With the import addon, cooked outputs replace these working folders as Godot's source assets. */
44
+ export declare const GODOT_PLUGIN_IGNORED: string[];
45
+ /**
46
+ * Inside a Godot project (project.godot at or above the package), keep Godot's importer out of a package's working
47
+ * folders: an empty .gdignore in each of versions/, packages/ and inputs/ that is there, and in the folders of `make`
48
+ * (made when they are not there yet), so the file is in place before the first version or copy lands. Nothing outside a
49
+ * Godot project. With the TopoTopo addon installed, also hide the package's graphs/, assets/ and exports/ as they
50
+ * appear (for example when the viewer opens after setup). Returns the files it added (none when they were all there).
51
+ */
52
+ export declare function godotIgnore(pkgDir: string, make?: string[]): string[];
53
+ /** The .gdignore files a package inside a Godot project lacks in the working folders it has (godotIgnore adds them); none outside one. */
54
+ export declare function godotIgnoreMissing(pkgDir: string): string[];
55
+ /** What a Godot export preset should exclude so that it ships none of TopoTopo's files. */
56
+ export declare const GODOT_EXCLUDES: string[];
57
+ /**
58
+ * The export presets of a Godot project (export_presets.cfg in `projectDir`) that would ship TopoTopo's files: one that
59
+ * exports every resource (export_filter="all_resources", or "exclude": all but the files checked) or includes *.json or
60
+ * *.txt files, with the exclude_filter entries it lacks. Nothing is edited. One line each; none when the file is missing
61
+ * or every preset excludes them.
62
+ */
63
+ export declare function godotPresetReport(projectDir: string): string[];
@@ -0,0 +1,180 @@
1
+ // Game engine projects (Godot, Unreal) as TopoTopo meets them: finding the project a workspace builds with (the nearest
2
+ // one at or above the workspace, else one below it), whether Unreal sees a workspace (under the project's Content/ or a
3
+ // plugin's), the files engines write beside TopoTopo's (never TopoTopo's: left out of versions, hashes, listings and
4
+ // bake keys), the .gdignore files that keep TopoTopo's working folders out of Godot's importer, and the Godot export
5
+ // presets that would ship TopoTopo's files.
6
+ import fs from 'node:fs';
7
+ import path from 'node:path';
8
+ const ENGINE_FILES = [[/^project\.godot$/, 'godot'], [/\.uproject$/i, 'unreal']];
9
+ /** The engine type a project file's name says, or null. */
10
+ export const engineTypeOf = (file) => ENGINE_FILES.find(([re]) => re.test(path.basename(file)))?.[1] ?? null;
11
+ /** Folders an engine search below a folder never enters (besides dot folders). */
12
+ const SKIP_BELOW = new Set(['node_modules', 'binaries', 'intermediate', 'saved', 'deriveddatacache', 'versions', 'packages', 'topotopo-packages']);
13
+ /**
14
+ * Files an engine writes beside the files it imports, which never count as TopoTopo's: Godot's *.import, *.uid and
15
+ * *.translation, Unreal's *.uasset, and TopoTopo's own .gdignore. Versions, their hashes, input listings, bake keys and
16
+ * the viewer's saved outputs leave them out, so a package inside an engine project publishes what it would elsewhere.
17
+ */
18
+ export const isEngineFile = (name) => name === '.gdignore' || /\.(import|uid|translation|uasset)$/i.test(name);
19
+ const rel = (from, to) => path.relative(path.resolve(from), path.resolve(to)).split(path.sep).join('/') || '.';
20
+ /** The engine project files directly in a folder. */
21
+ function projectsIn(dir) {
22
+ try {
23
+ return fs.readdirSync(dir, { withFileTypes: true }).filter((e) => e.isFile() && engineTypeOf(e.name)).map((e) => e.name).sort();
24
+ }
25
+ catch {
26
+ return [];
27
+ }
28
+ }
29
+ /**
30
+ * The nearest engine project at or above a folder: project.godot in the folder or above it, a *.uproject the same;
31
+ * null when there is none. A folder holding both answers Godot's (the one a workspace there sees first).
32
+ */
33
+ export function engineAbove(dir) {
34
+ for (let d = path.resolve(dir);;) {
35
+ const found = projectsIn(d).sort((a, b) => (engineTypeOf(a) === 'godot' ? -1 : engineTypeOf(b) === 'godot' ? 1 : 0));
36
+ if (found.length)
37
+ return { file: path.join(d, found[0]), type: engineTypeOf(found[0]) };
38
+ const up = path.dirname(d);
39
+ if (up === d)
40
+ return null;
41
+ d = up;
42
+ }
43
+ }
44
+ /** The engine projects below a folder (project.godot, *.uproject), nearest first, at most 4 levels down; paths from `dir`. */
45
+ export function findEngines(dir) {
46
+ const out = [];
47
+ const walk = (d, depth) => {
48
+ let entries;
49
+ try {
50
+ entries = fs.readdirSync(d, { withFileTypes: true });
51
+ }
52
+ catch {
53
+ return;
54
+ }
55
+ for (const e of entries) {
56
+ const type = e.isFile() ? engineTypeOf(e.name) : null;
57
+ if (type)
58
+ out.push({ link: { type, project: rel(dir, path.join(d, e.name)) }, depth });
59
+ }
60
+ if (depth >= 4)
61
+ return;
62
+ for (const e of entries)
63
+ if (e.isDirectory() && !e.name.startsWith('.') && !SKIP_BELOW.has(e.name.toLowerCase()))
64
+ walk(path.join(d, e.name), depth + 1);
65
+ };
66
+ walk(path.resolve(dir), 0);
67
+ return out.sort((a, b) => a.depth - b.depth || (a.link.project < b.link.project ? -1 : 1)).map((x) => x.link);
68
+ }
69
+ /**
70
+ * The engine project a workspace at `dir` builds with when none is named: the nearest at or above it (the workspace
71
+ * inside the engine's content folder), else the nearest below it; `found` says how many there were below, when that
72
+ * is where it came from.
73
+ */
74
+ export function detectEngine(dir) {
75
+ const above = engineAbove(dir);
76
+ if (above)
77
+ return { link: { type: above.type, project: rel(dir, above.file) }, below: [] };
78
+ const below = findEngines(dir);
79
+ return below.length ? { link: below[0], below } : null;
80
+ }
81
+ /**
82
+ * Whether Unreal sees a folder of its project: Unreal imports only what lies under the project's Content/ folder or a
83
+ * plugin's (Plugins/…/Content/). `uproject`: the project file.
84
+ */
85
+ export function unrealSees(folder, uproject) {
86
+ const r = path.relative(path.dirname(path.resolve(uproject)), path.resolve(folder));
87
+ if (!r || r.startsWith('..') || path.isAbsolute(r))
88
+ return false;
89
+ const parts = r.split(path.sep).map((s) => s.toLowerCase());
90
+ if (parts[0] === 'content')
91
+ return true;
92
+ return parts[0] === 'plugins' && parts.indexOf('content') > 1;
93
+ }
94
+ /** The Godot project a folder lies in: the folder holding the nearest project.godot at or above it; null for none. */
95
+ export function godotProjectOf(dir) {
96
+ for (let d = path.resolve(dir);;) {
97
+ if (fs.statSync(path.join(d, 'project.godot'), { throwIfNoEntry: false })?.isFile())
98
+ return d;
99
+ const up = path.dirname(d);
100
+ if (up === d)
101
+ return null;
102
+ d = up;
103
+ }
104
+ }
105
+ /** TopoTopo's working folders of a package, which are not game content: Godot imports none of them (a .gdignore in each). */
106
+ export const GODOT_IGNORED = ['versions', 'packages', 'inputs'];
107
+ /** With the import addon, cooked outputs replace these working folders as Godot's source assets. */
108
+ export const GODOT_PLUGIN_IGNORED = ['graphs', 'assets', 'inputs', 'exports', 'versions', 'packages'];
109
+ function godotIgnoredFolders(pkgDir) {
110
+ const project = godotProjectOf(pkgDir);
111
+ if (!project)
112
+ return [];
113
+ // A package at the project root is unsupported by the addon: never hide the game's assets/ there.
114
+ return path.resolve(pkgDir) !== project && fs.statSync(path.join(project, 'addons', 'topotopo', 'plugin.cfg'), { throwIfNoEntry: false })?.isFile()
115
+ ? GODOT_PLUGIN_IGNORED : GODOT_IGNORED;
116
+ }
117
+ /**
118
+ * Inside a Godot project (project.godot at or above the package), keep Godot's importer out of a package's working
119
+ * folders: an empty .gdignore in each of versions/, packages/ and inputs/ that is there, and in the folders of `make`
120
+ * (made when they are not there yet), so the file is in place before the first version or copy lands. Nothing outside a
121
+ * Godot project. With the TopoTopo addon installed, also hide the package's graphs/, assets/ and exports/ as they
122
+ * appear (for example when the viewer opens after setup). Returns the files it added (none when they were all there).
123
+ */
124
+ export function godotIgnore(pkgDir, make = []) {
125
+ const added = [];
126
+ for (const d of godotIgnoredFolders(pkgDir)) {
127
+ const folder = path.join(pkgDir, d), f = path.join(folder, '.gdignore');
128
+ if (fs.existsSync(f) || (!make.includes(d) && !fs.statSync(folder, { throwIfNoEntry: false })?.isDirectory()))
129
+ continue;
130
+ try {
131
+ fs.mkdirSync(folder, { recursive: true });
132
+ fs.writeFileSync(f, '');
133
+ added.push(f);
134
+ }
135
+ catch { /* Godot imports them: harmless */ }
136
+ }
137
+ return added;
138
+ }
139
+ /** The .gdignore files a package inside a Godot project lacks in the working folders it has (godotIgnore adds them); none outside one. */
140
+ export function godotIgnoreMissing(pkgDir) {
141
+ return godotIgnoredFolders(pkgDir).filter((d) => fs.statSync(path.join(pkgDir, d), { throwIfNoEntry: false })?.isDirectory()).map((d) => path.join(pkgDir, d, '.gdignore')).filter((f) => !fs.existsSync(f));
142
+ }
143
+ /** What a Godot export preset should exclude so that it ships none of TopoTopo's files. */
144
+ export const GODOT_EXCLUDES = ['*/attachments/*', '*/graphs/*', '*/inputs/*', '*.topo', '*/exports/*.source.json', '*/exports/.outputs.json'];
145
+ /**
146
+ * The export presets of a Godot project (export_presets.cfg in `projectDir`) that would ship TopoTopo's files: one that
147
+ * exports every resource (export_filter="all_resources", or "exclude": all but the files checked) or includes *.json or
148
+ * *.txt files, with the exclude_filter entries it lacks. Nothing is edited. One line each; none when the file is missing
149
+ * or every preset excludes them.
150
+ */
151
+ export function godotPresetReport(projectDir) {
152
+ let text;
153
+ try {
154
+ text = fs.readFileSync(path.join(projectDir, 'export_presets.cfg'), 'utf8');
155
+ }
156
+ catch {
157
+ return [];
158
+ }
159
+ const out = [];
160
+ // [preset.N] sections; their keys are key="value" lines
161
+ for (const block of text.split(/^\[preset\.\d+\]\s*$/m).slice(1)) {
162
+ const body = block.split(/^\[/m)[0];
163
+ const key = (k) => new RegExp(`^${k}\\s*=\\s*"((?:[^"\\\\]|\\\\.)*)"`, 'm').exec(body)?.[1] ?? '';
164
+ const name = key('name') || '(unnamed)', filter = key('export_filter'), include = key('include_filter'), exclude = key('exclude_filter');
165
+ const includes = include.split(',').map((s) => s.trim()).filter(Boolean);
166
+ // "all_resources": every resource; "exclude": every resource but the files checked in the dialog
167
+ const every = filter === 'all_resources' || filter === 'exclude';
168
+ const ships = every || includes.some((p) => /\*\.(json|txt)$/i.test(p) || p === '*' || p === '*.*');
169
+ if (!ships)
170
+ continue;
171
+ const have = new Set(exclude.split(',').map((s) => s.trim()).filter(Boolean));
172
+ const missing = GODOT_EXCLUDES.filter((e) => !have.has(e));
173
+ if (!missing.length)
174
+ continue;
175
+ const why = filter === 'all_resources' ? 'exports every resource' : filter === 'exclude' ? 'exports every resource but the files it leaves out'
176
+ : `includes ${includes.filter((p) => /\*\.(json|txt)$/i.test(p) || p === '*' || p === '*.*').join(', ')}`;
177
+ out.push(`export preset "${name}" ${why}, so it would ship TopoTopo's files: add to its exclude_filter (Project > Export > Resources > Filters to exclude) ${missing.join(', ')}`);
178
+ }
179
+ return out;
180
+ }
package/dist/explain.d.ts CHANGED
@@ -10,7 +10,7 @@ export interface DiffResult {
10
10
  mean: number;
11
11
  identical: boolean;
12
12
  }
13
- /** What changed from a to b: counts, bbox, topology, attribute schema, groups, sampled Hausdorff and mean distance. */
13
+ /** What changed from a to b: counts, bbox, topology, attribute schema, groups, volumes, sampled Hausdorff and mean distance. */
14
14
  export declare function diffGeometry(a: Geometry, b: Geometry, labels?: [string, string], samples?: number): DiffResult;
15
15
  /** Colours of the diff overlay. */
16
16
  export declare const DIFF_COLORS: {
@@ -19,7 +19,8 @@ export declare const DIFF_COLORS: {
19
19
  a: number[];
20
20
  };
21
21
  /**
22
- * One geometry for the renderer: b first (grey where it lies on a, blue where it moved or is new), then a in
23
- * orange. Coincident surfaces resolve to b (drawn first), so grey = unchanged, blue = only b, orange = only a.
22
+ * One geometry for the renderer: b (grey where it lies on a, blue where it moved or is new), and in orange the polygons
23
+ * of a that do not lie on b. Those that do are left out, b's grey stands for both there: two coincident surfaces mix
24
+ * their colours in the renderer. So grey = unchanged, blue = only b, orange = only a.
24
25
  */
25
26
  export declare function diffOverlay(a: Geometry, b: Geometry): Geometry;