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,10 +6,8 @@ import { traceMask } from '../core/traceimage.js';
6
6
  import { skylinePack } from '../core/uv.js';
7
7
  import { defineNode } from '../graph/registry.js';
8
8
  import { NodeError } from '../graph/types.js';
9
- import { source, withLayer, checkSize, resolutionParam } from './texture.js';
10
- const imageParam = () => ({ type: 'string', default: '', desc: 'image name (empty selects the first image)' });
9
+ import { NAMED_BY_NODE, imageParam, outName, renameParam, source, withLayer, checkSize, resolutionParam } from './texture.js';
11
10
  const layerParam = () => ({ type: 'string', default: '', desc: 'layer name (empty selects the main layer)' });
12
- const nameParam = () => ({ type: 'string', default: '', desc: 'output image name (empty keeps the source name)' });
13
11
  const channelParam = (def = 'alpha') => ({ type: 'enum', options: ['alpha', 'luminance', 'r', 'g', 'b'], default: def, desc: 'channel to read; alpha requires RGBA, luminance/R/G/B accept grey' });
14
12
  function channel(data, ch, which) {
15
13
  if (which === 'luminance')
@@ -23,12 +21,12 @@ function channel(data, ch, which) {
23
21
  return Float32Array.from({ length: data.length / 4 }, (_, i) => data[i * 4 + c]);
24
22
  }
25
23
  defineNode({
26
- type: 'tex_crop', category: 'texture', packed: 'keep',
24
+ type: 'tex_crop', category: 'texture', packed: 'keep', usesNodeName: NAMED_BY_NODE,
27
25
  summary: 'Extract an exact pixel rectangle, optionally resize it; all image layers stay aligned.',
28
- description: 'Origin is [x,y] from the top left. Size 0 on an axis means the remaining source extent; resolution 0 keeps the crop size. Outside pixels are zero, never wrapped. Filtered resize uses area averaging down and bilinear up; nearest preserves discrete masks. Values are not colour-converted. Other geometry/images pass through.',
26
+ description: 'Origin is [x,y] from the top left. Size 0 on an axis means the remaining source extent; resolution 0 keeps the crop size. Outside pixels are zero, never wrapped. Filtered resize uses area averaging down and bilinear up; nearest preserves discrete masks. Values are not colour-converted. The result takes this node\'s name unless name is set; other geometry/images pass through.',
29
27
  inputs: [{ name: 'image', desc: 'geometry carrying an image' }],
30
28
  params: {
31
- image: imageParam(), name: nameParam(),
29
+ image: imageParam(), name: renameParam(),
32
30
  origin: { type: 'ivec2', default: [0, 0], min: -1000000, max: 1000000, desc: 'crop origin in pixels, from the top left; negative origins add zero padding' },
33
31
  size: { type: 'ivec2', default: [0, 0], min: 0, max: 8192, desc: 'crop width/height in pixels; 0 = source extent minus origin' },
34
32
  resolution: { type: 'ivec2', default: [0, 0], min: 0, max: 8192, desc: 'output width/height; 0 = cropped size on that axis' },
@@ -42,7 +40,7 @@ defineNode({
42
40
  const ow = p.resolution[0] || w, oh = p.resolution[1] || h;
43
41
  checkSize(w, h, ctx.type);
44
42
  checkSize(ow, oh, ctx.type);
45
- const name = p.name.trim() || s.img.name, g = s.g.clone();
43
+ const name = outName(ctx), g = s.g.clone();
46
44
  const img = cropImage(s.img, x, y, w, h, ow, oh, p.filter === 'nearest', name);
47
45
  g.volumes[s.index] = img;
48
46
  g.volumes = g.volumes.filter((v) => v === img || v.kind !== 'image' || v.name !== name);
@@ -50,14 +48,14 @@ defineNode({
50
48
  },
51
49
  });
52
50
  defineNode({
53
- type: 'tex_dilate', category: 'texture', packed: 'keep',
51
+ type: 'tex_dilate', category: 'texture', packed: 'keep', usesNodeName: NAMED_BY_NODE,
54
52
  summary: 'Extend nearest valid image values into an invalid band, preserving opacity by default.',
55
- description: 'Validity comes from RGBA alpha or an explicit, same-sized mask. Grey images need a mask input. Valid pixels and pixels beyond radius are untouched. Nearest-site ties prefer the topmost, then leftmost source. No wrapping or colour conversion. Other layers pass through; preserve_alpha keeps every original RGBA alpha value. Uses the same exact distance transform as wide bake padding.',
53
+ description: 'Validity comes from RGBA alpha or an explicit, same-sized mask. Grey images need a mask input. Valid pixels and pixels beyond radius are untouched. Nearest-site ties prefer the topmost, then leftmost source. No wrapping or colour conversion. Other layers pass through; preserve_alpha keeps every original RGBA alpha value. Uses the same exact distance transform as wide bake padding. The result takes this node\'s name unless name is set.',
56
54
  inputs: [{ name: 'image', desc: 'image to pad' }, { name: 'mask', desc: 'optional explicit validity mask (same dimensions)', optional: true }],
57
55
  params: {
58
- image: imageParam(), layer: layerParam(), name: nameParam(),
56
+ image: imageParam(), layer: layerParam(), name: renameParam(),
59
57
  radius: { type: 'int', default: 8, min: 0, max: 8192, desc: 'maximum Euclidean distance in pixels from a valid source' },
60
- mask_image: imageParam(), mask_layer: layerParam(), mask_channel: channelParam('luminance'),
58
+ mask_image: imageParam('input 1 (the mask)', []), mask_layer: layerParam(), mask_channel: channelParam('luminance'),
61
59
  mask_threshold: { type: 'float', default: 0, desc: 'mask values strictly greater than this are valid' },
62
60
  preserve_alpha: { type: 'bool', default: true, desc: 'keep original alpha at every RGBA pixel while padding RGB' },
63
61
  },
@@ -67,7 +65,7 @@ defineNode({
67
65
  const { p } = ctx, s = source(ctx, 0, p.image, p.layer);
68
66
  let mask;
69
67
  if (ctx.hasInput(1)) {
70
- const m = source(ctx, 1, p.mask_image, p.mask_layer);
68
+ const m = source(ctx, 1, p.mask_image, p.mask_layer, 'mask_image');
71
69
  if (m.img.width !== s.img.width || m.img.height !== s.img.height)
72
70
  throw new NodeError('tex_dilate: mask dimensions must match the source image');
73
71
  mask = channel(m.data, m.ch, p.mask_channel);
@@ -77,7 +75,7 @@ defineNode({
77
75
  throw new NodeError('tex_dilate: a grey image requires an explicit mask input');
78
76
  mask = channel(s.data, s.ch, 'alpha');
79
77
  }
80
- return withLayer(s, dilateImage(s.data, s.ch, s.img.width, s.img.height, mask, p.mask_threshold, p.radius, p.preserve_alpha), p.name);
78
+ return withLayer(s, dilateImage(s.data, s.ch, s.img.width, s.img.height, mask, p.mask_threshold, p.radius, p.preserve_alpha), outName(ctx));
81
79
  },
82
80
  });
83
81
  defineNode({
@@ -114,7 +112,7 @@ defineNode({
114
112
  },
115
113
  });
116
114
  defineNode({
117
- type: 'tex_pack', category: 'texture',
115
+ type: 'tex_pack', category: 'texture', usesNodeName: NAMED_BY_NODE,
118
116
  summary: 'Pack named images into aligned atlases and output per-item UV placement attributes.',
119
117
  description: 'items is [{name:"leaf",maps:{color:"leaf_color",normal:"leaf_normal"}}]. Empty items packs each input image under the channel C. Every item must have the same map labels; images within an item must match dimensions and images within a channel must have matching channel counts. The selected images use their main layer. Native resolution, no rotation/downscaling, zero gutters. Outputs <name>_<channel> images and placement points in item order. rect is [x,y,width,height] in top-left pixels; atlasUV = localUV * uv_scale + uv_offset (V up). Connect the image output to texture_to_material and read placement attributes with a wrangle; do not merge placement points into your mesh. Padding is separate: tex_dilate. Limits: 4096 items, normal per-image pixel limit, at most 1 GiB of output image layers.',
120
118
  inputs: [{ name: 'images', desc: 'geometry carrying named source images (combine with merge)' }],
@@ -122,11 +120,12 @@ defineNode({
122
120
  items: { type: 'json', default: [], desc: 'array of {name, maps:{channel:imageName}}; empty = each image becomes one item in channel C' },
123
121
  resolution: resolutionParam(2048),
124
122
  padding: { type: 'int', default: 8, min: 0, max: 8192, desc: 'empty gutter on every side of each item, in pixels' },
125
- name: { type: 'string', default: 'atlas', desc: 'atlas image name prefix; images are named <name>_<channel>' },
123
+ name: { type: 'string', default: '', desc: 'atlas image name prefix ("" = this node\'s name); images are named <name>_<channel>' },
126
124
  },
127
125
  outputs: 'atlas images; points with name, rect, uv_offset and uv_scale; detail atlas_size',
128
126
  example: { nodes: { a: { type: 'tex_shape', params: { resolution: 32, name: 'disc' } }, b: { type: 'tex_pattern', params: { resolution: [32, 16], name: 'pattern' } }, images: { type: 'merge', in: ['a', 'b'] }, out: { type: 'tex_pack', in: ['images'], params: { resolution: 128, padding: 4 } } }, output: 'out' },
129
- cook: ({ input, p }) => {
127
+ cook: (ctx) => {
128
+ const { input, p } = ctx;
130
129
  const images = imagesOf(input(0)), pool = new Map();
131
130
  for (const im of images) {
132
131
  if (pool.has(im.name))
@@ -138,9 +137,7 @@ defineNode({
138
137
  const items = p.items.length ? p.items : images.map((im) => ({ name: im.name, maps: { C: im.name } }));
139
138
  if (!items.length || items.length > 4096)
140
139
  throw new NodeError('tex_pack: needs 1..4096 items');
141
- const prefix = p.name.trim();
142
- if (!prefix)
143
- throw new NodeError('tex_pack: name must not be empty');
140
+ const prefix = outName(ctx);
144
141
  const names = new Set();
145
142
  let labels = [];
146
143
  const sources = items.map((item, i) => {
@@ -32,3 +32,4 @@ import './rbd.ts';
32
32
  import './cloth.ts';
33
33
  import './scene.ts';
34
34
  import './solidify.ts';
35
+ import './beam.ts';
@@ -33,3 +33,4 @@ import './rbd.js';
33
33
  import './cloth.js';
34
34
  import './scene.js';
35
35
  import './solidify.js';
36
+ import './beam.js';
@@ -2,23 +2,33 @@
2
2
  // (see src/core/materials.ts). Exporters write them as glTF materials.
3
3
  import { defineNode } from '../graph/registry.js';
4
4
  import { NodeError } from '../graph/types.js';
5
+ import { Geometry, sameImage } from '../core/geometry.js';
6
+ import { referenceableImages } from '../core/image.js';
5
7
  import { MATERIAL_ATTRIB, normalizeMaterial, readMaterials, writeMaterials } from '../core/materials.js';
6
8
  import { P, mask } from './util.js';
7
9
  defineNode({
8
10
  type: 'material',
9
11
  category: 'attribute',
10
12
  packed: 'keep',
11
- summary: 'Assign a named material (PBR base colour, metallic, roughness, emissive, alpha) to prims; exporters write it as a glTF material.',
13
+ summary: 'Assign a named material (PBR base colour, metallic, roughness, emissive, alpha) to prims, or one from a material output; exporters write it as a glTF material.',
12
14
  description: 'Writes the prim string attribute "material" for the selected prims and adds (or replaces) the entry in the detail ' +
13
- 'material table "materials" (JSON). Vertex colours (Cd) still win in exports: a material then supplies the PBR scalars. ' +
14
- 'Assign several materials by chaining material nodes with different groups. Texture maps are file paths (PNG or ' +
15
- 'JPEG, relative to the graph/workspace): glb/gltf embed them, usda references them through UsdUVTexture shaders, ' +
16
- 'geo and json keep the paths in the table. A map replaces its scalar (base_color, roughness) in exports.',
15
+ 'material table "materials" (JSON). In glTF export the material decides the colour of its prims and their Cd is not ' +
16
+ 'written (export option vertex_colors keeps it). Assign several materials by chaining material nodes with different ' +
17
+ 'groups: by name pattern "@name=Glass*", prim ranges "0-11", or node groups (help topic "materials"). Texture maps are file paths (PNG or ' +
18
+ 'JPEG, relative to the package folder): glb/gltf embed them, usda references them through UsdUVTexture shaders, ' +
19
+ 'geo and json keep the paths in the table. A map replaces its scalar (base_color, roughness) in exports. ' +
20
+ 'Input 1 takes the material from elsewhere, typically a material output of a package ({"type": "owner/materials/steel"}): ' +
21
+ 'its entry and the maps it uses are copied in (from names it when the source holds several) and the colour and map ' +
22
+ 'params here are not used. With nothing in input 0 the result is the material alone: a material output.',
17
23
  aliases: ['material_assign', 'shop', 'assign_material', 'materialassign'],
18
- inputs: [{ name: 'geo', desc: 'geometry' }],
19
- outputs: 'prim "material" (string), detail "materials" (JSON table)',
24
+ inputs: [
25
+ { name: 'geo', desc: 'geometry (none: the material alone, for a material output)', optional: true },
26
+ { name: 'source', desc: 'a material output, or any geometry carrying materials, to take the material from', optional: true },
27
+ ],
28
+ outputs: 'prim "material" (string), detail "materials" (JSON table); with a source, the images its maps use',
20
29
  params: {
21
- name: { type: 'string', default: 'material', desc: 'material name (also the glTF material name)', aliases: ['shop_materialpath', 'material', 'path', 'materialpath'] },
30
+ name: { type: 'string', default: '', desc: 'material name, also the glTF material name ("" = "material", or the source material\'s own name with input 1)', aliases: ['shop_materialpath', 'material', 'path', 'materialpath'] },
31
+ from: { type: 'string', default: '', desc: 'input 1: which of its materials ("" = its only one)', aliases: ['source_material', 'use'] },
22
32
  group: P.group('prim', 'prims to assign ("" = all). e.g. "top", "@P.y>0", "0-9"'),
23
33
  base_color: { type: 'color', default: [0.8, 0.8, 0.8], desc: 'base colour [r,g,b] 0..1, "#rrggbb" or a name', aliases: ['basecolor', 'color', 'cd', 'albedo', 'diffuse'] },
24
34
  metallic: { type: 'float', default: 0, min: 0, max: 1, desc: 'metalness 0..1', aliases: ['metal', 'metalness'] },
@@ -34,23 +44,78 @@ defineNode({
34
44
  roughness_map: { type: 'path', default: '', desc: 'roughness texture (grey PNG/JPEG path or "image:<name>"; "" = none); glTF reads its green channel', aliases: ['roughness_texture', 'rough_map'] },
35
45
  },
36
46
  example: { type: 'material', params: { name: 'brick', base_color: '#a5462e', roughness: 0.9, group: '@P.y<0.5' } },
37
- cook: ({ input, p }) => {
38
- const name = String(p.name ?? '').trim();
39
- if (!name)
40
- throw new NodeError('material name is empty');
41
- const g = input(0).clone();
42
- const sel = mask(g, 'prim', p.group);
43
- const a = g.prims.add(MATERIAL_ATTRIB, 'string', 1);
44
- for (let i = 0; i < g.numPrims; i++)
45
- if (!sel || sel[i])
46
- a.set(i, name);
47
+ cook: ({ input, hasInput, p }) => {
48
+ const g = hasInput(0) ? input(0).clone() : new Geometry();
49
+ let name = String(p.name ?? '').trim();
50
+ let entry;
51
+ let images = [];
52
+ if (hasInput(1)) {
53
+ const src = input(1), table = readMaterials(src), names = Object.keys(table);
54
+ const want = String(p.from ?? '').trim();
55
+ if (!names.length)
56
+ throw new NodeError('input 1 carries no material', 'wire a material output (kind material) or any geometry that has materials into input 1');
57
+ if (want && !table[want])
58
+ throw new NodeError(`input 1 has no material "${want}"`, `its materials: ${names.join(', ')}`);
59
+ if (!want && names.length > 1)
60
+ throw new NodeError(`input 1 holds ${names.length} materials: say which with from`, `its materials: ${names.join(', ')}`);
61
+ const from = want || names[0];
62
+ entry = normalizeMaterial(table[from]);
63
+ if (!name)
64
+ name = from;
65
+ // the maps it uses travel with it
66
+ const pool = referenceableImages(src);
67
+ for (const ref of Object.values(entry.textures ?? {})) {
68
+ if (!ref?.startsWith('image:'))
69
+ continue;
70
+ const im = pool.get(ref.slice(6));
71
+ if (!im)
72
+ throw new NodeError(`input 1: material "${from}" uses image "${ref.slice(6)}", which it does not carry`);
73
+ images.push(im);
74
+ }
75
+ }
76
+ else {
77
+ if (!name)
78
+ name = 'material';
79
+ entry = normalizeMaterial({
80
+ baseColor: p.base_color, metallic: p.metallic, roughness: p.roughness, emissive: p.emissive,
81
+ alpha: p.alpha, doubleSided: !!p.double_sided, unlit: !!p.unlit,
82
+ alphaMode: p.alpha_mode, alphaCutoff: p.alpha_cutoff,
83
+ textures: { baseColor: p.base_color_map, normal: p.normal_map, roughness: p.roughness_map },
84
+ });
85
+ }
86
+ // copied maps join the target's images; one that differs from a target image of the same name is renamed
87
+ // "<material>_<map>" (as Geometry.merge does), and the entry follows
88
+ const have = referenceableImages(g);
89
+ const textures = { ...(entry.textures ?? {}) };
90
+ for (const im of images) {
91
+ const old = have.get(im.name);
92
+ if (old && sameImage(old, im))
93
+ continue;
94
+ let copy = im;
95
+ if (old) {
96
+ let n = `${name}_${im.name}`, k = 2;
97
+ while (have.has(n))
98
+ n = `${name}_${im.name}_${k++}`;
99
+ copy = im.clone();
100
+ copy.name = n;
101
+ for (const [slot, ref] of Object.entries(textures))
102
+ if (ref === `image:${im.name}`)
103
+ textures[slot] = `image:${n}`;
104
+ }
105
+ g.volumes.push(copy);
106
+ have.set(copy.name, copy);
107
+ }
108
+ if (images.length)
109
+ entry = { ...entry, textures: textures };
110
+ if (g.numPrims) {
111
+ const sel = mask(g, 'prim', p.group);
112
+ const a = g.prims.add(MATERIAL_ATTRIB, 'string', 1);
113
+ for (let i = 0; i < g.numPrims; i++)
114
+ if (!sel || sel[i])
115
+ a.set(i, name);
116
+ }
47
117
  const table = readMaterials(g);
48
- table[name] = normalizeMaterial({
49
- baseColor: p.base_color, metallic: p.metallic, roughness: p.roughness, emissive: p.emissive,
50
- alpha: p.alpha, doubleSided: !!p.double_sided, unlit: !!p.unlit,
51
- alphaMode: p.alpha_mode, alphaCutoff: p.alpha_cutoff,
52
- textures: { baseColor: p.base_color_map, normal: p.normal_map, roughness: p.roughness_map },
53
- });
118
+ table[name] = entry;
54
119
  writeMaterials(g, table);
55
120
  return g;
56
121
  },
@@ -5,8 +5,10 @@ import { Geometry } from '../core/geometry.js';
5
5
  import { defineNode } from '../graph/registry.js';
6
6
  import { NodeError } from '../graph/types.js';
7
7
  import { evalExpr, vecOut } from '../graph/params.js';
8
+ import { codeVarNames, pickVars } from '../core/usercode.js';
8
9
  import { pointNormals, primArea } from '../core/topology.js';
9
10
  import { halfEdges } from '../core/halfedge.js';
11
+ import { edgeWhere, pointWhere, primWhere } from '../core/report.js';
10
12
  import { CURVATURE_TYPES, RayScene, SurfaceQuery, bboxDiagonal, fmt, curvatureOfType, discreteCurvature, duplicatePoints, fillFromNearestValid, newNearest, nonManifoldPoints, percentileFit, pieceReport, rayMeasure, selfIntersections, shortEdges, smoothPointValues, } from '../core/analysis.js';
11
13
  import { P, getPointNormals, mask } from './util.js';
12
14
  import { andThen } from '../graph/parallel.js';
@@ -294,7 +296,7 @@ export function assertScope(g, pr) {
294
296
  closed: pr.pieces.length > 0 && pr.pieces.every((x) => x.closed), boundary_edges: sum((x) => x.boundaryEdges),
295
297
  };
296
298
  }
297
- const EXPR_NAMES = 'npoints nprims nvertices npolys nlines bbox (.min .max .size .center, each with .x .y .z) volume area pieces open_pieces genus closed boundary_edges';
299
+ const EXPR_NAMES = 'npoints nprims nvertices npolys nlines bbox (.min .max .size .center, each with .x .y .z) volume area pieces open_pieces genus closed boundary_edges and the graph vars (by their bare name; the names above come first)';
298
300
  defineNode({
299
301
  type: 'assert',
300
302
  category: 'measure',
@@ -334,6 +336,7 @@ defineNode({
334
336
  tolerance: { type: 'float', default: 1e-6, min: 0, desc: 'distance tolerance for bbox_min/max and duplicate points', advanced: true },
335
337
  },
336
338
  outputs: 'passes geometry through; mark: detail int assert_failed, detail string assert_report, point/prim group assert_fail',
339
+ usesVars: (p) => String(p.expr ?? ''),
337
340
  example: {
338
341
  nodes: {
339
342
  body: { type: 'box', params: { size: [1, 2, 1], center: [0, 1, 0] } },
@@ -341,7 +344,7 @@ defineNode({
341
344
  },
342
345
  output: 'check',
343
346
  },
344
- cook: ({ input, p, warn, stat, engine }) => {
347
+ cook: ({ input, p, warn, stat, engine, vars }) => {
345
348
  const src = input(0);
346
349
  const g = src;
347
350
  const fails = [];
@@ -350,6 +353,9 @@ defineNode({
350
353
  let prCache = null;
351
354
  const pieces = () => prCache ?? (prCache = pieceReport(g));
352
355
  const fail = (name, msg) => fails.push(`${name}: ${msg}`);
356
+ /** the first prim / point set in a mask, in words: its part and position (core/report.ts) */
357
+ const firstPrimOf = (m) => { const q = m.indexOf(1); return q >= 0 ? `; first ${primWhere(g, q)}` : ''; };
358
+ const firstPointOf = (m) => { const q = m.indexOf(1); return q >= 0 ? `; first ${pointWhere(g, q)}` : ''; };
353
359
  const tol = p.tolerance;
354
360
  if (p.watertight) {
355
361
  checks++;
@@ -368,32 +374,40 @@ defineNode({
368
374
  bits.push(`${nme} edges shared by 3+ polygons`);
369
375
  if (lines)
370
376
  bits.push(`${lines} polylines`);
371
- fail('watertight', `${bits.join(', ')}; ${open} of ${pr.pieces.length} piece(s) open`);
372
377
  const he = halfEdges(g);
378
+ let firstEdge = -1;
373
379
  for (let e = 0; e < he.numEdges; e++)
374
- if (he.edgeValence(e) !== 2)
380
+ if (he.edgeValence(e) !== 2) {
381
+ if (firstEdge < 0)
382
+ firstEdge = e;
375
383
  for (const f of he.edgeFaces(e))
376
384
  primFail[f] = 1;
385
+ }
377
386
  for (let q = 0; q < g.numPrims; q++)
378
387
  if (!g.primClosed[q])
379
388
  primFail[q] = 1;
389
+ const where = firstEdge >= 0 ? `; first ${edgeWhere(g, he.edgeA[firstEdge], he.edgeB[firstEdge], he.edgeFaces(firstEdge)[0] ?? -1)}` : firstPrimOf(primFail);
390
+ fail('watertight', `${bits.join(', ')}; ${open} of ${pr.pieces.length} piece(s) open${where}`);
380
391
  }
381
392
  }
382
393
  if (p.manifold) {
383
394
  checks++;
384
395
  const he = halfEdges(g);
385
- let multi = 0;
396
+ let multi = 0, firstMulti = -1;
386
397
  for (let e = 0; e < he.numEdges; e++)
387
398
  if (he.edgeValence(e) > 2) {
388
399
  multi++;
400
+ if (firstMulti < 0)
401
+ firstMulti = e;
389
402
  for (const f of he.edgeFaces(e))
390
403
  primFail[f] = 1;
391
404
  }
392
405
  const bow = nonManifoldPoints(g);
393
406
  for (const q of bow)
394
407
  ptFail[q] = 1;
408
+ const where = firstMulti >= 0 ? `; first ${edgeWhere(g, he.edgeA[firstMulti], he.edgeB[firstMulti], he.edgeFaces(firstMulti)[0] ?? -1)}` : bow.length ? `; first ${pointWhere(g, bow[0])}` : '';
395
409
  if (multi || bow.length)
396
- fail('manifold', `${multi} edges shared by 3+ polygons, ${bow.length} bowtie point(s)`);
410
+ fail('manifold', `${multi} edges shared by 3+ polygons, ${bow.length} bowtie point(s)${where}`);
397
411
  }
398
412
  if (p.no_flipped) {
399
413
  checks++;
@@ -405,12 +419,15 @@ defineNode({
405
419
  bits.push(`${pr.flippedEdges} edges between oppositely wound polygons`);
406
420
  if (inward.length)
407
421
  bits.push(`${inward.length} closed piece(s) facing inward (volume ${inward.slice(0, 3).map(({ x }) => fmt(x.volume)).join(', ')}${inward.length > 3 ? ', …' : ''}; use reverse)`);
408
- fail('no_flipped', bits.join('; '));
422
+ const mark = new Uint8Array(g.numPrims);
409
423
  for (let q = 0; q < g.numPrims; q++) {
410
424
  const pc = pr.primPiece[q] >= 0 ? pr.pieces[pr.primPiece[q]] : null;
411
- if (pr.flippedPrims[q] || (pc && pc.closed && pc.volume < 0 && !pc.cavity))
425
+ if (pr.flippedPrims[q] || (pc && pc.closed && pc.volume < 0 && !pc.cavity)) {
412
426
  primFail[q] = 1;
427
+ mark[q] = 1;
428
+ }
413
429
  }
430
+ fail('no_flipped', bits.join('; ') + firstPrimOf(mark));
414
431
  }
415
432
  }
416
433
  const count = (label, have, lim, atLeast) => {
@@ -428,7 +445,7 @@ defineNode({
428
445
  if (bmin || bmax) {
429
446
  checks++;
430
447
  const P = g.P;
431
- let outside = 0;
448
+ let outside = 0, firstOut = -1;
432
449
  for (let i = 0; i < g.numPoints; i++) {
433
450
  let out = false;
434
451
  for (let c = 0; c < 3; c++) {
@@ -439,18 +456,20 @@ defineNode({
439
456
  if (out) {
440
457
  outside++;
441
458
  ptFail[i] = 1;
459
+ if (firstOut < 0)
460
+ firstOut = i;
442
461
  }
443
462
  }
444
463
  if (outside) {
445
464
  const b = g.bbox();
446
- fail('bbox', `${outside} point(s) outside${bmin ? ` min ${v3(bmin)}` : ''}${bmax ? ` max ${v3(bmax)}` : ''}; geometry spans ${v3(b.min)} .. ${v3(b.max)}`);
465
+ fail('bbox', `${outside} point(s) outside${bmin ? ` min ${v3(bmin)}` : ''}${bmax ? ` max ${v3(bmax)}` : ''}; geometry spans ${v3(b.min)} .. ${v3(b.max)}; first ${pointWhere(g, firstOut)}`);
447
466
  }
448
467
  }
449
468
  if (p.min_edge_length > 0) {
450
469
  checks++;
451
470
  const r = shortEdges(g, p.min_edge_length);
452
471
  if (r.count) {
453
- fail('min_edge_length', `${r.count} edge(s) shorter than ${fmt(p.min_edge_length)} (shortest ${fmt(r.shortest)})`);
472
+ fail('min_edge_length', `${r.count} edge(s) shorter than ${fmt(p.min_edge_length)} (shortest ${fmt(r.shortest)})${firstPrimOf(r.prims)}`);
454
473
  for (let q = 0; q < g.numPrims; q++)
455
474
  if (r.prims[q])
456
475
  primFail[q] = 1;
@@ -458,7 +477,7 @@ defineNode({
458
477
  }
459
478
  if (p.no_degenerate) {
460
479
  checks++;
461
- let zero = 0;
480
+ let zero = 0, firstZero = -1;
462
481
  const amin = tol * tol;
463
482
  for (let q = 0; q < g.numPrims; q++) {
464
483
  if (!g.primClosed[q])
@@ -466,21 +485,24 @@ defineNode({
466
485
  if (g.primSize(q) < 3 || primArea(g, q) <= amin) {
467
486
  zero++;
468
487
  primFail[q] = 1;
488
+ if (firstZero < 0)
489
+ firstZero = q;
469
490
  }
470
491
  }
471
492
  const dup = duplicatePoints(g, tol);
472
493
  for (let i = 0; i < g.numPoints; i++)
473
494
  if (dup.mask[i])
474
495
  ptFail[i] = 1;
496
+ const where = firstZero >= 0 ? `; first ${primWhere(g, firstZero)}` : firstPointOf(dup.mask);
475
497
  if (zero || dup.count)
476
- fail('no_degenerate', `${zero} zero-area polygon(s), ${dup.count} point(s) within ${fmt(tol)} of another${dup.count ? ' (fuse them)' : ''}`);
498
+ fail('no_degenerate', `${zero} zero-area polygon(s), ${dup.count} point(s) within ${fmt(tol)} of another${dup.count ? ' (fuse them)' : ''}${where}`);
477
499
  }
478
500
  if (p.no_self_intersections) {
479
501
  checks++;
480
502
  const r = selfIntersections(g, p.max_tests, { strict: p.strict_intersections });
481
503
  const capped = r.capped ? ` (search stopped after ${r.tested.toLocaleString('en-US')} candidate pairs: there may be more)` : '';
482
504
  if (r.pairs) {
483
- fail('no_self_intersections', `${r.pairs} pair(s) of ${p.strict_intersections ? 'intersecting or touching' : 'crossing'} triangles${capped}`);
505
+ fail('no_self_intersections', `${r.pairs} pair(s) of ${p.strict_intersections ? 'intersecting or touching' : 'crossing'} triangles${capped}${firstPrimOf(r.prims)}`);
484
506
  for (let q = 0; q < g.numPrims; q++)
485
507
  if (r.prims[q])
486
508
  primFail[q] = 1;
@@ -500,7 +522,7 @@ defineNode({
500
522
  fail('attrib', `"${p.attrib}" is a string attribute: attrib_min/max need numbers`);
501
523
  else {
502
524
  const a = f.attr, d = a.data, s = a.size, n = a.count;
503
- let bad = 0, mn = Infinity, mx = -Infinity;
525
+ let bad = 0, mn = Infinity, mx = -Infinity, firstBad = -1;
504
526
  const vp = f.cls === 'vertex' ? g.vertexPrims() : null;
505
527
  for (let i = 0; i < n; i++) {
506
528
  const x = d[i * s];
@@ -510,6 +532,8 @@ defineNode({
510
532
  mx = x;
511
533
  if ((lo !== null && !(x >= lo)) || (hi !== null && !(x <= hi))) {
512
534
  bad++;
535
+ if (firstBad < 0)
536
+ firstBad = i;
513
537
  if (f.cls === 'point')
514
538
  ptFail[i] = 1;
515
539
  else if (f.cls === 'prim')
@@ -518,8 +542,9 @@ defineNode({
518
542
  primFail[vp[i]] = 1;
519
543
  }
520
544
  }
545
+ const where = firstBad < 0 || f.cls === 'detail' ? '' : `; first ${f.cls === 'point' ? pointWhere(g, firstBad) : primWhere(g, f.cls === 'prim' ? firstBad : vp[firstBad])}`;
521
546
  if (bad)
522
- fail('attrib', `${bad} ${f.cls} value(s) of "${p.attrib}"${s > 1 ? '[0]' : ''} outside ${lo !== null ? fmt(lo) : '-inf'} .. ${hi !== null ? fmt(hi) : 'inf'} (range ${fmt(mn)} .. ${fmt(mx)})`);
547
+ fail('attrib', `${bad} ${f.cls} value(s) of "${p.attrib}"${s > 1 ? '[0]' : ''} outside ${lo !== null ? fmt(lo) : '-inf'} .. ${hi !== null ? fmt(hi) : 'inf'} (range ${fmt(mn)} .. ${fmt(mx)})${where}`);
523
548
  }
524
549
  }
525
550
  }
@@ -547,7 +572,8 @@ defineNode({
547
572
  if (String(p.expr ?? '').trim()) {
548
573
  checks++;
549
574
  const src = String(p.expr).trim();
550
- const scope = assertScope(g, pieces());
575
+ // the measurements, over the graph vars the expression names
576
+ const scope = { ...pickVars(vars, codeVarNames(src, vars)), ...assertScope(g, pieces()) };
551
577
  let res;
552
578
  try {
553
579
  res = evalExpr(src, scope, { host: engine.host, timeoutMs: engine.scriptTimeoutMs });
@@ -243,6 +243,8 @@ defineNode({
243
243
  const perStep = Math.min(ep.maxBirths, Math.ceil(ep.rate) * prep.emitter.count);
244
244
  for (;;) {
245
245
  budget.check();
246
+ // a stopped cook stops between batches
247
+ await ctx.checkpoint();
246
248
  const { geo: st, end } = emitSteps(state, prep.emitter, s0, Math.min(s1, s0 + batchSteps(state ? state.numPoints : 0, perStep)), ep);
247
249
  batches++;
248
250
  state = await integrate(st, s0, end, prep);
package/dist/nodes/pcg.js CHANGED
@@ -340,7 +340,7 @@ defineNode({
340
340
  aliases: ['attribfrommap', 'attrib_from_image', 'texture_to_attrib', 'attrib_from_map', 'attribute_from_image', 'texture_sample'],
341
341
  inputs: [{ name: 'geo', desc: 'points or mesh' }],
342
342
  params: {
343
- path: { type: 'path', default: '', desc: 'PNG file (relative to the workspace) or URL', aliases: ['file', 'filename', 'map', 'texture', 'image'] },
343
+ path: { type: 'path', default: '', desc: 'PNG file or URL; a relative path reads from the package folder (nearest .topo file), else the graph\'s folder', aliases: ['file', 'filename', 'map', 'texture', 'image'] },
344
344
  name: { type: 'string', default: '', desc: 'output attribute ("" = Cd for channel rgb, else mask)', aliases: ['attrib', 'attribute', 'output'] },
345
345
  channel: { type: 'enum', options: ['luminance', 'r', 'g', 'b', 'a', 'rgb'], default: 'luminance', desc: 'which channel (rgb writes a vector)' },
346
346
  projection: { type: 'enum', options: ['uv', 'xz', 'xy', 'yz'], default: 'uv', desc: 'uv attribute or a planar projection (xz = top view)', aliases: ['mapping'] },
@@ -354,13 +354,14 @@ defineNode({
354
354
  class: { type: 'enum', options: ['point', 'vertex'], default: 'point', desc: 'write a point attribute or a vertex attribute' },
355
355
  group: P.group('point', 'points to write ("" = all)'),
356
356
  },
357
- signatureExtra: (p, engine) => engine.host.fileStamp(p.path),
357
+ // relative paths read the scope's folder
358
+ signatureExtra: (p, scope) => scope.files.fileStamp(p.path),
358
359
  outputs: 'point (or vertex) float <name> (vec3 for channel rgb)',
359
360
  example: { type: 'attribute_from_map', in: ['ground_pts'], params: { path: 'density.png', projection: 'xz', size: [100, 100], name: 'density' } },
360
- async cook({ input, p, engine, type, warn }) {
361
+ async cook({ input, p, scope, type, warn }) {
361
362
  if (!p.path)
362
- throw new NodeError(`${type}: path is empty`, 'a PNG file relative to the workspace, e.g. "maps/density.png"');
363
- const bytes = await engine.host.readFile(p.path).catch((e) => { throw new NodeError(`${type}: cannot read "${p.path}": ${e.message}`); });
363
+ throw new NodeError(`${type}: path is empty`, 'a PNG file relative to the package folder, e.g. "inputs/density.png"');
364
+ const bytes = await scope.files.readFile(p.path).catch((e) => { throw new NodeError(`${type}: cannot read "${p.path}": ${e.message}`); });
364
365
  let img;
365
366
  try {
366
367
  img = decodePNG(bytes);
@@ -317,10 +317,11 @@ defineNode({
317
317
  curve_segments: { type: 'int', default: 6, min: 1, max: 32, desc: 'segments per glyph curve' },
318
318
  center: P.center(),
319
319
  },
320
- signatureExtra: (p, engine) => engine.host.findFont(p.font || undefined) ?? 'nofont',
320
+ // a font path reads the scope's folder
321
+ signatureExtra: (p, scope) => scope.files.findFont(p.font || undefined) ?? 'nofont',
321
322
  example: { type: 'text', params: { text: 'OPEN', size: 0.5, depth: 0.1 } },
322
- async cook({ p, engine, warn }) {
323
- const host = engine.host;
323
+ async cook({ p, scope, warn }) {
324
+ const host = scope.files;
324
325
  const name = p.font || undefined;
325
326
  const candidates = host.fontCandidates?.(name) ?? [host.findFont(name)].filter((f) => !!f);
326
327
  if (!candidates.length)