topotopo 0.4.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (336) hide show
  1. package/NOTICE +10 -10
  2. package/README.md +460 -117
  3. package/dist/cli.js +327 -147
  4. package/dist/config.d.ts +48 -0
  5. package/dist/config.js +170 -0
  6. package/dist/core/bake.d.ts +14 -3
  7. package/dist/core/bake.js +153 -4
  8. package/dist/core/bevel.d.ts +3 -1
  9. package/dist/core/bevel.js +76 -3
  10. package/dist/core/decimate.d.ts +65 -0
  11. package/dist/core/decimate.js +409 -3
  12. package/dist/core/erosion.d.ts +37 -0
  13. package/dist/core/erosion.js +41 -1
  14. package/dist/core/geometry.d.ts +5 -1
  15. package/dist/core/geometry.js +203 -3
  16. package/dist/core/heightfield.d.ts +27 -4
  17. package/dist/core/heightfield.js +54 -16
  18. package/dist/core/intrinsics.d.ts +7 -0
  19. package/dist/core/intrinsics.js +94 -0
  20. package/dist/core/manifold.d.ts +12 -1
  21. package/dist/core/manifold.js +78 -6
  22. package/dist/core/materials.d.ts +7 -0
  23. package/dist/core/materials.js +45 -0
  24. package/dist/core/noise.d.ts +9 -0
  25. package/dist/core/noise.js +10 -1
  26. package/dist/core/polymerge.d.ts +21 -0
  27. package/dist/core/polymerge.js +327 -0
  28. package/dist/core/repair.d.ts +2 -0
  29. package/dist/core/repair.js +2 -0
  30. package/dist/core/report.d.ts +70 -0
  31. package/dist/core/report.js +275 -0
  32. package/dist/core/scene.js +2 -1
  33. package/dist/core/sha256.d.ts +4 -0
  34. package/dist/core/sha256.js +69 -0
  35. package/dist/core/shapes.d.ts +3 -0
  36. package/dist/core/shapes.js +34 -0
  37. package/dist/core/snippet-lib.d.ts +14 -1
  38. package/dist/core/snippet-lib.js +39 -13
  39. package/dist/core/tangents.d.ts +2 -0
  40. package/dist/core/tangents.js +5 -1
  41. package/dist/core/texnoise.d.ts +6 -1
  42. package/dist/core/texnoise.js +6 -2
  43. package/dist/core/texsdf.d.ts +131 -0
  44. package/dist/core/texsdf.js +637 -0
  45. package/dist/core/texture.d.ts +163 -9
  46. package/dist/core/texture.js +844 -20
  47. package/dist/core/topology.d.ts +10 -0
  48. package/dist/core/topology.js +168 -0
  49. package/dist/core/unwrap.d.ts +72 -0
  50. package/dist/core/unwrap.js +800 -0
  51. package/dist/core/usercode.d.ts +27 -0
  52. package/dist/core/usercode.js +87 -0
  53. package/dist/core/uv.d.ts +4 -18
  54. package/dist/core/uv.js +35 -188
  55. package/dist/core/uvislands.d.ts +62 -0
  56. package/dist/core/uvislands.js +574 -0
  57. package/dist/core/uvoverlap.d.ts +58 -0
  58. package/dist/core/uvoverlap.js +220 -0
  59. package/dist/core/uvpack.d.ts +64 -0
  60. package/dist/core/uvpack.js +628 -0
  61. package/dist/core/uvreport.d.ts +61 -0
  62. package/dist/core/uvreport.js +207 -143
  63. package/dist/core/wrangle.d.ts +6 -1
  64. package/dist/core/wrangle.js +27 -16
  65. package/dist/core/xatlas.d.ts +16 -1
  66. package/dist/core/xatlas.js +66 -62
  67. package/dist/engines.d.ts +63 -0
  68. package/dist/engines.js +180 -0
  69. package/dist/explain.d.ts +4 -3
  70. package/dist/explain.js +129 -12
  71. package/dist/graph/engine.d.ts +92 -29
  72. package/dist/graph/engine.js +298 -148
  73. package/dist/graph/expr.d.ts +6 -3
  74. package/dist/graph/expr.js +18 -8
  75. package/dist/graph/outputs.d.ts +23 -0
  76. package/dist/graph/outputs.js +41 -0
  77. package/dist/graph/packages.d.ts +72 -0
  78. package/dist/graph/packages.js +261 -0
  79. package/dist/graph/parallel.d.ts +3 -1
  80. package/dist/graph/parallel.js +4 -1
  81. package/dist/graph/params.d.ts +6 -0
  82. package/dist/graph/params.js +34 -7
  83. package/dist/graph/scope.d.ts +55 -0
  84. package/dist/graph/scope.js +14 -0
  85. package/dist/graph/types.d.ts +75 -12
  86. package/dist/graph/types.js +4 -2
  87. package/dist/graph/vars.d.ts +16 -0
  88. package/dist/graph/vars.js +80 -0
  89. package/dist/host/artifacts.d.ts +10 -1
  90. package/dist/host/artifacts.js +37 -6
  91. package/dist/host/cook.d.ts +241 -0
  92. package/dist/host/cook.js +844 -0
  93. package/dist/host/export-targets.d.ts +42 -5
  94. package/dist/host/export-targets.js +72 -13
  95. package/dist/host/godot-commands.d.ts +4 -0
  96. package/dist/host/godot-commands.js +21 -0
  97. package/dist/host/godot.d.ts +183 -0
  98. package/dist/host/godot.js +916 -0
  99. package/dist/host/node.d.ts +12 -7
  100. package/dist/host/node.js +27 -9
  101. package/dist/host/pool.js +51 -2
  102. package/dist/host/sidecars.d.ts +8 -0
  103. package/dist/host/sidecars.js +50 -0
  104. package/dist/host/types.d.ts +19 -6
  105. package/dist/host/version.d.ts +1 -0
  106. package/dist/host/version.js +3 -0
  107. package/dist/host/worker.js +5 -2
  108. package/dist/index.d.ts +2 -2
  109. package/dist/index.js +1 -1
  110. package/dist/inspect.d.ts +80 -2
  111. package/dist/inspect.js +265 -30
  112. package/dist/io/common.d.ts +25 -5
  113. package/dist/io/export.js +2 -1
  114. package/dist/io/files.d.ts +23 -4
  115. package/dist/io/files.js +60 -8
  116. package/dist/io/gltf.js +134 -47
  117. package/dist/io/heightmap.d.ts +3 -0
  118. package/dist/io/heightmap.js +1 -0
  119. package/dist/io/import.js +10 -0
  120. package/dist/io/inspect-scene.d.ts +55 -0
  121. package/dist/io/inspect-scene.js +155 -0
  122. package/dist/io/kinds.d.ts +81 -0
  123. package/dist/io/kinds.js +163 -0
  124. package/dist/io/points.d.ts +2 -1
  125. package/dist/io/points.js +3 -1
  126. package/dist/io/sidecars.d.ts +24 -0
  127. package/dist/io/sidecars.js +57 -0
  128. package/dist/io/source.d.ts +65 -0
  129. package/dist/io/source.js +112 -0
  130. package/dist/io/targets.d.ts +47 -3
  131. package/dist/io/targets.js +148 -13
  132. package/dist/io/textures.js +21 -1
  133. package/dist/io/unreal.js +5 -1
  134. package/dist/mcp/docs.d.ts +10 -1
  135. package/dist/mcp/docs.js +786 -143
  136. package/dist/mcp/inputs.d.ts +12 -5
  137. package/dist/mcp/inputs.js +50 -13
  138. package/dist/mcp/server.js +56 -27
  139. package/dist/mcp/tools.d.ts +14 -7
  140. package/dist/mcp/tools.js +198 -103
  141. package/dist/mcp/verify.d.ts +2 -2
  142. package/dist/mcp/verify.js +1 -1
  143. package/dist/mcp/workspace.d.ts +15 -0
  144. package/dist/mcp/workspace.js +349 -0
  145. package/dist/nodes/attributes.js +198 -1
  146. package/dist/nodes/bake.js +151 -47
  147. package/dist/nodes/beam.d.ts +1 -0
  148. package/dist/nodes/beam.js +201 -0
  149. package/dist/nodes/bevel.js +51 -3
  150. package/dist/nodes/cloth.js +2 -0
  151. package/dist/nodes/code.js +21 -9
  152. package/dist/nodes/curves.js +433 -93
  153. package/dist/nodes/flow.js +53 -33
  154. package/dist/nodes/generate.js +12 -38
  155. package/dist/nodes/heightfield.js +248 -77
  156. package/dist/nodes/imageops.js +16 -19
  157. package/dist/nodes/index.d.ts +1 -0
  158. package/dist/nodes/index.js +1 -0
  159. package/dist/nodes/material.js +89 -24
  160. package/dist/nodes/measure.js +43 -17
  161. package/dist/nodes/particles.js +2 -0
  162. package/dist/nodes/pcg.js +6 -5
  163. package/dist/nodes/procedural.js +4 -3
  164. package/dist/nodes/remesh.js +71 -15
  165. package/dist/nodes/scene.js +4 -2
  166. package/dist/nodes/sdf.js +10 -5
  167. package/dist/nodes/solid.js +20 -5
  168. package/dist/nodes/splines.d.ts +15 -1
  169. package/dist/nodes/splines.js +112 -105
  170. package/dist/nodes/texture.d.ts +21 -6
  171. package/dist/nodes/texture.js +1318 -185
  172. package/dist/nodes/topology.d.ts +7 -0
  173. package/dist/nodes/topology.js +133 -6
  174. package/dist/nodes/transform.js +6 -2
  175. package/dist/nodes/uv.js +192 -174
  176. package/dist/nodes/wasmcall.js +5 -1
  177. package/dist/open.d.ts +19 -0
  178. package/dist/open.js +12 -0
  179. package/dist/package.d.ts +288 -0
  180. package/dist/package.js +772 -0
  181. package/dist/packages/check.d.ts +32 -0
  182. package/dist/packages/check.js +169 -0
  183. package/dist/packages/commands.d.ts +57 -0
  184. package/dist/packages/commands.js +537 -0
  185. package/dist/packages/registry.d.ts +796 -0
  186. package/dist/packages/registry.js +2998 -0
  187. package/dist/packages/update.d.ts +124 -0
  188. package/dist/packages/update.js +476 -0
  189. package/dist/render/options.d.ts +2 -0
  190. package/dist/render/options.js +57 -5
  191. package/dist/render/preview.d.ts +17 -4
  192. package/dist/render/preview.js +6 -4
  193. package/dist/render/raster.d.ts +74 -5
  194. package/dist/render/raster.js +527 -143
  195. package/dist/render/texview.d.ts +6 -0
  196. package/dist/render/texview.js +27 -0
  197. package/dist/scan.d.ts +61 -0
  198. package/dist/scan.js +228 -0
  199. package/dist/session.d.ts +311 -0
  200. package/dist/session.js +849 -0
  201. package/dist/viewer/app/api.js +48 -6
  202. package/dist/viewer/app/cooking.js +78 -0
  203. package/dist/viewer/app/embed.js +27 -7
  204. package/dist/viewer/app/export-popover.js +118 -16
  205. package/dist/viewer/app/grid.js +5 -1
  206. package/dist/viewer/app/guides.js +122 -0
  207. package/dist/viewer/app/keymap.js +6 -3
  208. package/dist/viewer/app/layers.js +4 -4
  209. package/dist/viewer/app/main.js +185 -52
  210. package/dist/viewer/app/markers.js +60 -0
  211. package/dist/viewer/app/outliner.js +72 -27
  212. package/dist/viewer/app/output-info.js +45 -0
  213. package/dist/viewer/app/outputs.css +147 -8
  214. package/dist/viewer/app/outputs.js +168 -54
  215. package/dist/viewer/app/packages.js +614 -0
  216. package/dist/viewer/app/props.js +176 -52
  217. package/dist/viewer/app/scene.js +30 -5
  218. package/dist/viewer/app/select.js +4 -3
  219. package/dist/viewer/app/status.js +12 -15
  220. package/dist/viewer/app/style.css +65 -7
  221. package/dist/viewer/app/vars.js +47 -0
  222. package/dist/viewer/app/welcome.js +72 -0
  223. package/dist/viewer/graph-file.d.ts +62 -0
  224. package/dist/viewer/graph-file.js +175 -0
  225. package/dist/viewer/index.html +23 -10
  226. package/dist/viewer/json-edit.d.ts +13 -0
  227. package/dist/viewer/json-edit.js +274 -0
  228. package/dist/viewer/outputs.d.ts +49 -5
  229. package/dist/viewer/outputs.js +264 -56
  230. package/dist/viewer/packages.d.ts +121 -0
  231. package/dist/viewer/packages.js +584 -0
  232. package/dist/viewer/server.d.ts +14 -9
  233. package/dist/viewer/server.js +266 -28
  234. package/dist/web/app/web.css +419 -0
  235. package/dist/web/app/web.js +188 -0
  236. package/dist/{gallery → web}/bake.d.ts +4 -4
  237. package/dist/{gallery → web}/bake.js +24 -15
  238. package/dist/web/folder-page.d.ts +101 -0
  239. package/dist/web/folder-page.js +146 -0
  240. package/dist/web/folders.d.ts +280 -0
  241. package/dist/web/folders.js +970 -0
  242. package/dist/web/library.d.ts +91 -0
  243. package/dist/web/library.js +228 -0
  244. package/dist/web/markdown.d.ts +45 -0
  245. package/dist/web/markdown.js +677 -0
  246. package/dist/web/pages.d.ts +258 -0
  247. package/dist/web/pages.js +301 -0
  248. package/dist/web/server.d.ts +24 -0
  249. package/dist/web/server.js +1068 -0
  250. package/dist/workspace.d.ts +88 -118
  251. package/dist/workspace.js +358 -460
  252. package/integrations/godot/addons/topotopo/LICENSE +202 -0
  253. package/integrations/godot/addons/topotopo/README.md +57 -0
  254. package/integrations/godot/addons/topotopo/context_menu.gd +43 -0
  255. package/integrations/godot/addons/topotopo/dock.gd +266 -0
  256. package/integrations/godot/addons/topotopo/dock.tscn +72 -0
  257. package/integrations/godot/addons/topotopo/export_filter.gd +72 -0
  258. package/integrations/godot/addons/topotopo/gltf_instancing.gd +131 -0
  259. package/integrations/godot/addons/topotopo/icons/topotopo.svg +1 -0
  260. package/integrations/godot/addons/topotopo/inspector.gd +38 -0
  261. package/integrations/godot/addons/topotopo/instances_post_import.gd +111 -0
  262. package/integrations/godot/addons/topotopo/package.gd +23 -0
  263. package/integrations/godot/addons/topotopo/package_importer.gd +187 -0
  264. package/integrations/godot/addons/topotopo/plugin.cfg +7 -0
  265. package/integrations/godot/addons/topotopo/plugin.gd +970 -0
  266. package/integrations/godot/addons/topotopo/record.gd +435 -0
  267. package/integrations/godot/addons/topotopo/runner.gd +458 -0
  268. package/integrations/godot/addons/topotopo/tools/check.gd +42 -0
  269. package/integrations/godot/addons/topotopo/watcher.gd +199 -0
  270. package/kernels/pkg/README.md +2 -1
  271. package/kernels/pkg-simd/README.md +2 -1
  272. package/library/architecture/versions/1.0/architecture.topo +12 -0
  273. package/{shelf → library/architecture/versions/1.0/graphs}/arch.json +3 -3
  274. package/{shelf → library/architecture/versions/1.0/graphs}/beam_truss.json +6 -6
  275. package/{shelf → library/architecture/versions/1.0/graphs}/brick_wall.json +8 -8
  276. package/{shelf → library/architecture/versions/1.0/graphs}/door_frame.json +3 -3
  277. package/{shelf → library/architecture/versions/1.0/graphs}/hex_grid_floor.json +3 -2
  278. package/{shelf → library/architecture/versions/1.0/graphs}/house.json +8 -8
  279. package/library/architecture/versions/1.0/graphs/lineup.json +42 -0
  280. package/{shelf → library/architecture/versions/1.0/graphs}/pillar.json +3 -2
  281. package/{shelf → library/architecture/versions/1.0/graphs}/railing.json +5 -5
  282. package/{shelf → library/architecture/versions/1.0/graphs}/roof_gable.json +2 -2
  283. package/{shelf → library/architecture/versions/1.0/graphs}/roof_hip.json +2 -2
  284. package/{shelf → library/architecture/versions/1.0/graphs}/roof_skeleton.json +2 -1
  285. package/{shelf → library/architecture/versions/1.0/graphs}/scaffold.json +4 -4
  286. package/{shelf → library/architecture/versions/1.0/graphs}/spiral_stairs.json +3 -2
  287. package/{shelf → library/architecture/versions/1.0/graphs}/stairs.json +6 -6
  288. package/{shelf → library/architecture/versions/1.0/graphs}/tile_floor.json +3 -2
  289. package/{shelf → library/architecture/versions/1.0/graphs}/wall_segment.json +10 -10
  290. package/{shelf → library/architecture/versions/1.0/graphs}/window_frame.json +2 -2
  291. package/library/architecture/versions/1.0/version.json +1119 -0
  292. package/{shelf → library/nature/versions/1.0/graphs}/bush.json +2 -2
  293. package/{shelf → library/nature/versions/1.0/graphs}/cliff_block.json +4 -3
  294. package/{shelf → library/nature/versions/1.0/graphs}/forest_patch.json +5 -5
  295. package/{shelf → library/nature/versions/1.0/graphs}/grass_clumps.json +2 -2
  296. package/library/nature/versions/1.0/graphs/lineup.json +24 -0
  297. package/{shelf → library/nature/versions/1.0/graphs}/log.json +6 -6
  298. package/{shelf → library/nature/versions/1.0/graphs}/rock.json +5 -4
  299. package/{shelf → library/nature/versions/1.0/graphs}/scatter_rocks.json +5 -5
  300. package/{shelf → library/nature/versions/1.0/graphs}/tree_lowpoly.json +3 -2
  301. package/library/nature/versions/1.0/nature.topo +12 -0
  302. package/library/nature/versions/1.0/version.json +534 -0
  303. package/{shelf → library/props/versions/1.0/graphs}/barrel.json +5 -4
  304. package/{shelf → library/props/versions/1.0/graphs}/crate.json +3 -3
  305. package/library/props/versions/1.0/graphs/lineup.json +18 -0
  306. package/{shelf → library/props/versions/1.0/graphs}/pallet.json +4 -3
  307. package/{shelf → library/props/versions/1.0/graphs}/pipe_run.json +3 -3
  308. package/{shelf → library/props/versions/1.0/graphs}/sandbag_wall.json +5 -5
  309. package/library/props/versions/1.0/props.topo +12 -0
  310. package/library/props/versions/1.0/version.json +336 -0
  311. package/{shelf → library/street/versions/1.0/graphs}/bench.json +5 -5
  312. package/{shelf → library/street/versions/1.0/graphs}/bollard.json +2 -1
  313. package/{shelf → library/street/versions/1.0/graphs}/cable.json +4 -4
  314. package/{shelf → library/street/versions/1.0/graphs}/fence.json +7 -7
  315. package/{shelf → library/street/versions/1.0/graphs}/lamp_post.json +2 -2
  316. package/library/street/versions/1.0/graphs/lineup.json +22 -0
  317. package/{shelf → library/street/versions/1.0/graphs}/road_strip.json +2 -2
  318. package/{shelf → library/street/versions/1.0/graphs}/sign_post.json +1 -1
  319. package/library/street/versions/1.0/street.topo +12 -0
  320. package/library/street/versions/1.0/version.json +421 -0
  321. package/package.json +13 -8
  322. package/dist/gallery/app/gallery.css +0 -100
  323. package/dist/gallery/app/gallery.js +0 -80
  324. package/dist/gallery/cli.d.ts +0 -4
  325. package/dist/gallery/cli.js +0 -157
  326. package/dist/gallery/library.d.ts +0 -124
  327. package/dist/gallery/library.js +0 -366
  328. package/dist/gallery/pages.d.ts +0 -94
  329. package/dist/gallery/pages.js +0 -148
  330. package/dist/gallery/server.d.ts +0 -21
  331. package/dist/gallery/server.js +0 -391
  332. package/dist/graph/migrate.d.ts +0 -23
  333. package/dist/graph/migrate.js +0 -58
  334. package/dist/mcp/library.d.ts +0 -12
  335. package/dist/mcp/library.js +0 -159
  336. package/shelf/index.json +0 -190
@@ -4,7 +4,7 @@ import { Attribute, Geometry } from '../core/geometry.js';
4
4
  import { defineNode } from '../graph/registry.js';
5
5
  import { NodeError } from '../graph/types.js';
6
6
  import { RemeshError, isotropicRemesh } from '../core/remesh.js';
7
- import { DecimateError, decimateMesh, decimatePoints, parseSteerAttribs } from '../core/decimate.js';
7
+ import { DecimateError, decimateKeepUV, decimatePoints, parseSteerAttribs, reductionLocks, uvKeptText } from '../core/decimate.js';
8
8
  import { repairMesh, repairSummary } from '../core/repair.js';
9
9
  import { P, edgeMask, mask } from './util.js';
10
10
  /** Run a kernel and turn its own errors into node errors. */
@@ -95,7 +95,12 @@ defineNode({
95
95
  'max_error stops early (relative to the mesh extent, or in scene units with error_absolute); the achieved error ' +
96
96
  'is written to detail "error" (and "error_abs" in scene units). prune lets whole small pieces vanish; ' +
97
97
  'aggressive (sloppy) ignores topology and seams to reach any target. group decimates only those prims (points ' +
98
- 'shared with other prims stay; sparse speeds up small groups of big meshes). mode points (or auto on a point ' +
98
+ 'shared with other prims stay; sparse speeds up small groups of big meshes). keep_uv: a collapse keeps its ' +
99
+ 'corners\' uv, so it can fold the uv where the map bends (bevels, curved chart borders) even with uv steering; when ' +
100
+ 'the input uv has no overlaps, the reduction is checked and, where it folds, goes in steps that lock the points ' +
101
+ 'around each fold, so the output has none (it may stop above the target there; the warning names the parts; ' +
102
+ 'not with group or aggressive). ' +
103
+ 'Reducing before uv_unwrap gives the full reduction. mode points (or auto on a point ' +
99
104
  'cloud) thins points with simplifyPoints, keeping an even spread and the point_attributes (Cd, pscale).',
100
105
  aliases: ['polyreduce', 'simplify', 'reduce', 'decimate_points'],
101
106
  inputs: [{ name: 'geo', desc: 'polygon mesh or point cloud' }],
@@ -110,6 +115,7 @@ defineNode({
110
115
  sparse: { type: 'bool', default: false, desc: 'faster when the group is a small part of a big mesh (use error_absolute for consistent errors)', advanced: true },
111
116
  regularize: { type: 'bool', default: false, desc: 'favour evenly sized triangles over exact shape', advanced: true },
112
117
  aggressive: { type: 'bool', default: false, desc: 'sloppy mode: ignores topology and seams, reaches any target', aliases: ['sloppy'] },
118
+ keep_uv: { type: 'bool', default: true, desc: 'when the input uv has no overlaps, keep the output free of uv folds: where a collapse would fold the uv, reduce in steps around it (can stop above the target); off = one plain reduction (not checked with group or aggressive)' },
113
119
  group: P.group('prim', 'prims to decimate ("" = all); points shared with other prims stay'),
114
120
  lock: { type: 'group', default: '', groupClass: 'point', desc: 'point group that must not move or disappear ("" = none)', aliases: ['lock_points'] },
115
121
  mode: { type: 'enum', options: ['auto', 'mesh', 'points'], default: 'auto', desc: 'auto = points when the input has no polygons; points thins a point cloud' },
@@ -134,9 +140,12 @@ defineNode({
134
140
  lockBorder: p.lock_border, prune: p.prune, sparse: p.sparse, regularize: p.regularize, sloppy: p.aggressive,
135
141
  attributes: guard(() => parseSteerAttribs(p.attributes)), group: mask(g, 'prim', p.group), lockPoints: pointMaskOrNone(g, p.lock),
136
142
  };
137
- const r = guard(() => decimateMesh(g, opts));
143
+ const r = guard(() => decimateKeepUV(g, opts, !!p.keep_uv));
138
144
  if (r.skipped.length)
139
145
  warn(`decimate: attributes ${r.skipped.join(', ')} cannot steer (only float point/vertex attributes, 32 floats in total)`);
146
+ const held = uvKeptText(r);
147
+ if (held)
148
+ warn(`decimate: ${held}. Reduce before uv_unwrap for the full reduction, or set keep_uv off to allow the folds`);
140
149
  const out = r.geo;
141
150
  out.detail.add('error', 'float', 1).data[0] = r.error;
142
151
  out.detail.add('error_abs', 'float', 1).data[0] = r.errorAbs;
@@ -210,16 +219,22 @@ const DEFAULT_RATIOS = [1, 0.5, 0.25, 0.125];
210
219
  defineNode({
211
220
  type: 'lod',
212
221
  category: 'topology',
213
- summary: 'Levels of detail in one go: decimated copies tagged with prim lod and name suffix _LOD0, _LOD1 … (merged), or one level (switch).',
222
+ summary: 'Levels of detail in one go: decimated copies tagged with prim lod and named {name}_lod0, {name}_lod1 … (merged), or one level (switch); optionally of one group only.',
214
223
  description: 'Houdini: PolyReduce per level + a name per level (LOD Create). Each level is decimated from the input with the ' +
215
224
  'decimate kernel (attribute steering, uv seams kept, optional lock_border, prune small pieces); level 0 with ' +
216
225
  'ratio 1 is the triangulated input. Levels come from ratios (fractions of the triangle count; missing entries keep ' +
217
226
  'halving) or, when screen_sizes is given, from screen sizes (fraction of the screen height the object covers, ' +
218
227
  'like Unreal LOD screen size): each such level reduces as far as an error of pixel_error pixels at screen_height ' +
219
- 'allows. merge outputs all levels together with prim int "lod" and prim "name" = input name (or base_name) + ' +
220
- '"_LOD<k>", so exporters that split by name (export split_by_name, glTF/USD) write one mesh per level; spacing ' +
221
- 'offsets level k by k·spacing for side-by-side previews. switch outputs only level "level". Detail "lod" is a ' +
222
- 'JSON list of {level, ratio | screen_size, triangles, error}; detail int[] "lod_tris" the triangle counts.',
228
+ 'allows. Every level\'s prims get prim int "lod" and prim "name" = name_format with {name} = the prim\'s input name ' +
229
+ '(or base_name) and {level} = the level, by default "{name}_lod{level}" (gun_lod0, gun_lod1), so exporters that ' +
230
+ 'split by name (export split_by_name, glTF/USD) write one mesh per level. merge outputs all levels together; ' +
231
+ 'spacing offsets level k by k·spacing for side-by-side previews. switch outputs only level "level", named the same ' +
232
+ 'way (gun_lod2; name_format "{name}" keeps the input names). group reduces only those prims (e.g. "@name=magazine"): ' +
233
+ 'the others pass through once, unchanged and unnamed by the levels. A ratio level that stops well short of its ' +
234
+ 'target warns with what held it: uv seams, hard normals (vertex N), prim attribute or group borders and open ' +
235
+ 'borders, with point counts (or the max_error limit), or the parts where a plain reduction folds the uv (keep_uv, ' +
236
+ 'as in decimate: a level never folds a clean uv atlas). Detail "lod" is a JSON list of {level, ratio | screen_size, ' +
237
+ 'triangles, error}; detail int[] "lod_tris" the triangle counts.',
223
238
  aliases: ['lod_tree', 'polyreduce_lod', 'lod_create', 'lods'],
224
239
  inputs: [{ name: 'geo', desc: 'polygon mesh' }],
225
240
  params: {
@@ -232,15 +247,18 @@ defineNode({
232
247
  attributes: { type: 'string', default: 'uv N Cd', desc: 'float point/vertex attributes that steer the reduction, with optional weights ("uv:2 N:0.5")' },
233
248
  lock_border: { type: 'bool', default: false, desc: 'keep open borders fixed in every level' },
234
249
  prune: { type: 'bool', default: true, desc: 'let small disconnected pieces (leaves, bolts) vanish in coarse levels' },
250
+ keep_uv: { type: 'bool', default: true, desc: 'when the input uv has no overlaps, keep every level free of uv folds (as decimate keep_uv: reduce in steps around a fold; a level can stop above its target); off = plain reductions' },
235
251
  mode: { type: 'enum', options: ['merge', 'switch'], default: 'merge', desc: 'merge = all levels in one geometry; switch = only "level"' },
236
252
  level: { type: 'int', default: 0, min: 0, desc: 'switch mode: the level to output' },
237
- base_name: { type: 'string', default: 'mesh', desc: 'name for prims without a "name" attribute (becomes mesh_LOD0 …)', aliases: ['name'] },
253
+ name_format: { type: 'string', default: '{name}_lod{level}', desc: 'prim name of each level: {name} = the input prim name (or base_name), {level} = the level number (merge needs {level})', aliases: ['name_pattern', 'suffix_format'] },
254
+ base_name: { type: 'string', default: 'mesh', desc: 'the {name} of prims without a "name" attribute (mesh_lod0 …)', aliases: ['name'] },
255
+ group: P.group('prim', 'prims to make levels of ("" = all); the others pass through once, unchanged'),
238
256
  spacing: { type: 'vec3', default: [0, 0, 0], desc: 'offset of level k = k * spacing (side-by-side previews; keep 0 for export)', aliases: ['offset'] },
239
257
  },
240
- outputs: 'prim int lod, prim string name (…_LOD<k>); detail string lod (JSON per level), detail int[] lod_tris',
258
+ outputs: 'prim int lod, prim string name (name_format, default {name}_lod{level}); detail string lod (JSON per level), detail int[] lod_tris',
241
259
  example: { type: 'lod', params: { levels: 4, ratios: [1, 0.5, 0.25, 0.1], spacing: [2.5, 0, 0] } },
242
- cook: ({ input, p, stat }) => {
243
- const g = input(0);
260
+ cook: ({ input, p, stat, warn }) => {
261
+ const all = input(0);
244
262
  const steer = guard(() => parseSteerAttribs(p.attributes));
245
263
  const sizes = Array.isArray(p.screen_sizes) ? p.screen_sizes.map(Number).filter((x) => x > 0) : [];
246
264
  const n = sizes.length ? sizes.length : Math.max(1, Math.floor(p.levels));
@@ -252,9 +270,24 @@ defineNode({
252
270
  ratios.push(Number.isFinite(r) && r >= 0 ? Math.min(1, r) : k ? ratios[k - 1] / 2 : 1);
253
271
  }
254
272
  const levels = p.mode === 'switch' ? [Math.min(n - 1, Math.max(0, Math.floor(p.level)))] : Array.from({ length: n }, (_, k) => k);
273
+ const fmt = String(p.name_format ?? '').trim();
274
+ if (!fmt)
275
+ throw new NodeError('lod: name_format is empty', 'e.g. "{name}_lod{level}" (gun_lod0) or "{name}" in switch mode to keep the names');
276
+ if (levels.length > 1 && !fmt.includes('{level}'))
277
+ throw new NodeError(`lod: name_format "${fmt}" has no {level}, so every level would get the same name`, 'e.g. "{name}_lod{level}"; switch mode can keep the names with "{name}"');
278
+ // group: only those prims get levels; the rest passes through once
279
+ const sel = mask(all, 'prim', p.group);
280
+ let g = all, rest = null;
281
+ if (sel) {
282
+ if (!sel.some((x) => x))
283
+ throw new NodeError(`lod: group "${p.group}" matches no prim`);
284
+ g = all.subsetPrims(sel);
285
+ rest = all.subsetPrims(Uint8Array.from(sel, (x) => (x ? 0 : 1)));
286
+ }
255
287
  const info = [], tris = [], geos = [];
256
288
  const nameAttr = g.prims.get('name');
257
289
  const baseNames = nameAttr && nameAttr.type === 'string' ? nameAttr.data : null;
290
+ let locks = null;
258
291
  for (const k of levels) {
259
292
  const bySize = sizes.length > 0;
260
293
  const opts = {
@@ -263,16 +296,37 @@ defineNode({
263
296
  lockBorder: p.lock_border, prune: p.prune && !(bySize ? false : ratios[k] >= 1), sparse: false, regularize: false, sloppy: false,
264
297
  attributes: steer, group: null, lockPoints: null,
265
298
  };
266
- const r = guard(() => decimateMesh(g, opts));
299
+ const r = guard(() => decimateKeepUV(g, opts, !!p.keep_uv));
267
300
  const lg = r.geo;
268
- // tag the level: prim lod + name suffix
301
+ const uvHeld = uvKeptText(r);
302
+ // a ratio level well short of its target: say what held it
303
+ const want = Math.round(ratios[k] * r.trisIn), short = (x) => x > want * 1.1 + 2;
304
+ if (!bySize && ratios[k] < 1 && short(r.trisOut)) {
305
+ const pct = (x) => `${Math.round((100 * x) / Math.max(1, r.trisIn))} %`;
306
+ let why;
307
+ if (uvHeld && !short(r.uv.plainTris))
308
+ why = uvHeld;
309
+ else if (p.max_error < 1 && r.error >= p.max_error * 0.999)
310
+ why = `the error limit max_error ${p.max_error} was reached`;
311
+ else {
312
+ locks ??= reductionLocks(g);
313
+ const held = locks.slice(0, 5).map((l) => `${l.cause} (${l.points.toLocaleString('en-US')} points)`).join(', ');
314
+ why = held ? `the reduction cannot collapse across ${held}${p.lock_border && locks.some((l) => l.cause === 'open borders') ? '; lock_border keeps the open borders whole' : ''}` : 'the mesh has nothing left to collapse at this error';
315
+ if (uvHeld)
316
+ why += `; and ${uvHeld}`;
317
+ }
318
+ warn(`lod: level ${k} stopped at ${r.trisOut.toLocaleString('en-US')} triangles (${pct(r.trisOut)} of ${r.trisIn.toLocaleString('en-US')}), short of its ${pct(want)} target: ${why}. Fewer seams reduce further: compute normals after lod (normal node) rather than before, reduce before uv_unwrap or with fewer charts, drop groups and prim strings the levels do not need (group_delete, attrib_delete)${uvHeld ? '; keep_uv off allows the uv folds' : ''}`);
319
+ }
320
+ else if (uvHeld)
321
+ warn(`lod: level ${k}: ${uvHeld}. Reduce before uv_unwrap for the full reduction, or set keep_uv off to allow the folds`);
322
+ // tag the level: prim lod + name from name_format
269
323
  const lod = lg.prims.add('lod', 'int', 1);
270
324
  lod.data.fill(k);
271
325
  const names = new Array(lg.numPrims);
272
326
  const srcName = lg.prims.get('name');
273
327
  for (let pr = 0; pr < lg.numPrims; pr++) {
274
328
  const base = baseNames && srcName && srcName.type === 'string' ? srcName.data[pr] || p.base_name : p.base_name;
275
- names[pr] = `${base}_LOD${k}`;
329
+ names[pr] = fmt.replaceAll('{name}', base).replaceAll('{level}', String(k));
276
330
  }
277
331
  lg.prims.set('name', new Attribute('string', 1, names, ''));
278
332
  const off = p.spacing;
@@ -288,6 +342,8 @@ defineNode({
288
342
  tris.push(r.trisOut);
289
343
  geos.push(lg);
290
344
  }
345
+ if (rest && (rest.numPrims || rest.numPoints))
346
+ geos.unshift(rest);
291
347
  const out = geos.length === 1 ? geos[0] : Geometry.merge(geos);
292
348
  for (const a of ['error', 'error_abs'])
293
349
  out.detail.delete(a);
@@ -15,8 +15,10 @@ defineNode({
15
15
  '(model) space, so later transform nodes move the empty with the mesh; glTF export writes it as a node without a ' +
16
16
  'mesh under its parent with the local transform that keeps this geometry-space placement. parent names another ' +
17
17
  'empty or a mesh (the prim "name" of the pieces export splits by); missing, ambiguous and cyclic parents are export ' +
18
- 'errors. Other point attributes set on the empty (e.g. a "forward" vector) export as node extras. Ordinary loose ' +
19
- 'points still export as POINTS.',
18
+ 'errors. Other point attributes set on the empty (e.g. a "forward" vector) export as node extras. The empty\'s ' +
19
+ 'attributes (scene_empty, parent, orient, scale and such extras) only hold their defaults on the mesh points after ' +
20
+ 'a merge, and export never writes them as mesh channels, even with custom_attribs. Ordinary loose points still ' +
21
+ 'export as POINTS.',
20
22
  aliases: ['null_object', 'empty', 'socket', 'locator', 'scene_empty', 'attachment_point'],
21
23
  inputs: [{ name: 'geo', desc: 'geometry to add the empty to (optional)', optional: true }],
22
24
  params: {
package/dist/nodes/sdf.js CHANGED
@@ -4,7 +4,8 @@
4
4
  import { Geometry } from '../core/geometry.js';
5
5
  import { defineNode } from '../graph/registry.js';
6
6
  import { NodeError } from '../graph/types.js';
7
- import { runUserCode } from '../core/usercode.js';
7
+ import { codeVarDecl, codeVarNames, codeVarValues, runUserCode } from '../core/usercode.js';
8
+ import { scriptVarsGuard } from '../core/snippet-lib.js';
8
9
  import { M, fromManifold, propLayout } from '../core/manifold.js';
9
10
  import { TriBVH } from '../core/spatial.js';
10
11
  import { triangulate } from '../core/topology.js';
@@ -166,7 +167,8 @@ defineNode({
166
167
  type: 'sdf_expr',
167
168
  category: 'sdf',
168
169
  summary: 'SDF from JS code: return a signed distance for point p ([x,y,z]). IQ helpers built in (sdSphere, sdBox, smin, opTwist…). sdf(i, p) samples input i.',
169
- description: 'The code runs sandboxed like a wrangle, under the script timeout (TOPOTOPO_SCRIPT_TIMEOUT_MS, default 30 s). ' +
170
+ description: 'The code runs sandboxed like a wrangle, under the script timeout (TOPOTOPO_SCRIPT_TIMEOUT_MS, default 30 s), and ' +
171
+ 'reads graph vars by their bare name (sdSphere(p, radius)). ' +
170
172
  'This node only probes the field at the origin; the nodes that sample it later (sdf_to_mesh, sdf_grid, also after ' +
171
173
  'transform, sdf_modify or sdf_combine) run all of their sampling under that limit, so the whole mesh or grid must ' +
172
174
  'be computed within it: a field that loops anywhere, or is too slow for the resolution, fails the sampling node ' +
@@ -183,7 +185,7 @@ defineNode({
183
185
  auto_bounds: { type: 'bool', default: false, desc: 'use the union of input volume bounds (padded) instead' },
184
186
  name: { type: 'string', default: 'sdf', desc: 'volume name' },
185
187
  },
186
- usesVars: true,
188
+ usesVars: (p) => String(p.code ?? ''),
187
189
  example: { type: 'sdf_expr', params: { code: 'const q = opTwist(p, 2.0);\nreturn sdTorus(q, 0.8, 0.2);' } },
188
190
  cook: ({ inputs, p, engine, vars }) => {
189
191
  const ins = inputs.map((g) => (g && sdfsOf(g).length ? unionVolumes(g, 'sdf_expr').sample : null));
@@ -194,14 +196,17 @@ defineNode({
194
196
  const syntax = engine.host.checkSyntax?.(`"use strict";${body}`);
195
197
  if (syntax)
196
198
  throw new NodeError(`sdf_expr syntax error: ${syntax.message}${p.code.includes('\n') ? ` (line ${syntax.line})` : ''}`);
199
+ // the graph vars the code names: constants of the outermost function, so sdf, p, x y z and the code's own names
200
+ // come first
201
+ const varNames = codeVarNames(p.code, vars);
197
202
  let make;
198
203
  try {
199
- make = engine.host.compile(`(function(__in, vars){ "use strict"; const sdf = (i, q) => { const f = __in[i]; if (!f) throw new Error('sdf input ' + i + ' has no volume'); return f(q[0], q[1], q[2]); };\nreturn function(x, y, z){ const p = [x, y, z];\n${body}\n}; })`);
204
+ make = engine.host.compile(`(function(__in, __vars, __varsGuard){ "use strict"; ${codeVarDecl(varNames)}\nreturn (function(){ const sdf = (i, q) => { const f = __in[i]; if (!f) throw new Error('sdf input ' + i + ' has no volume'); return f(q[0], q[1], q[2]); };\nreturn function(x, y, z){ const p = [x, y, z];\n${body}\n}; })(); })`);
200
205
  }
201
206
  catch (e) {
202
207
  throw new NodeError(`sdf_expr syntax error: ${e.message}`);
203
208
  }
204
- const f = make(ins, vars);
209
+ const f = make(ins, codeVarValues(vars, varNames), scriptVarsGuard(engine.host));
205
210
  let t, failed;
206
211
  try {
207
212
  engine.host.runGuarded(() => {
@@ -4,7 +4,9 @@ import { GeoBuilder, Geometry } from '../core/geometry.js';
4
4
  import { defineNode } from '../graph/registry.js';
5
5
  import { NodeError } from '../graph/types.js';
6
6
  import { M, fromManifold, manifoldId, planeMatrix, polygonsToGeo, propLayout, toManifold } from '../core/manifold.js';
7
- import { boundaryLoops, triangulate, topologyReport } from '../core/topology.js';
7
+ import { boundaryLoops, outwardPieces, triangulate, topologyReport } from '../core/topology.js';
8
+ import { mergeTriangles } from '../core/polymerge.js';
9
+ import { primWhere } from '../core/report.js';
8
10
  import { KDTree, TriBVH } from '../core/spatial.js';
9
11
  import { rng } from '../core/random.js';
10
12
  import { normalize, m4invert } from '../core/math.js';
@@ -27,10 +29,13 @@ defineNode({
27
29
  type: 'boolean',
28
30
  category: 'solid',
29
31
  summary: 'Robust mesh boolean (union / subtract / intersect) of closed solids. Without B, unions A’s overlapping pieces.',
32
+ description: 'The result is a closed solid made of polygons: each input face that survives the cut comes out as one polygon (a face the cut leaves with a hole as a few polygons sharing flat edges), so a bevel or inset after the boolean sees the real edges, and edges shorter than "tolerance" are collapsed so no slivers are left. Inside-out input pieces (a mirror without a winding flip) are turned outward first, with a warning.',
30
33
  aliases: ['csg', 'bool', 'difference', 'union', 'intersect'],
31
34
  inputs: [{ name: 'a', desc: 'solid A' }, { name: 'b', desc: 'solid B (optional)', optional: true }],
32
35
  params: {
33
36
  operation: { type: 'enum', options: ['union', 'subtract', 'intersect'], default: 'subtract', desc: 'A ∪ B, A − B, or A ∩ B', aliases: ['op', 'mode'] },
37
+ output: { type: 'enum', options: ['polygons', 'triangles'], default: 'polygons', desc: 'polygons = each surviving input face as one polygon (or a few around a hole); triangles = the kernel triangles as they come' },
38
+ tolerance: { type: 'float', default: 0.00001, min: 0, desc: 'after the cut, collapse edges shorter than this and flatten slivers thinner than it, keeping the solid closed (0 = rounding only)', aliases: ['simplify', 'sliver'] },
34
39
  },
35
40
  outputs: 'prim groups from_a, from_b (cut faces come from B when subtracting); float point/vertex attributes interpolated',
36
41
  example: {
@@ -41,8 +46,14 @@ defineNode({
41
46
  },
42
47
  output: 'cut',
43
48
  },
44
- cook: ({ input, hasInput, p }) => withManifolds((track) => {
45
- const A = input(0), B = hasInput(1) ? input(1) : null;
49
+ cook: ({ input, hasInput, p, warn }) => withManifolds((track) => {
50
+ const outward = (g, label) => {
51
+ const r = outwardPieces(g);
52
+ if (r.flipped.length)
53
+ warn(`${label}: ${r.flipped.length} piece(s) were inside out (faces pointing inward, e.g. mirrored without a winding flip) and were turned outward first; first ${primWhere(g, r.flipped[0])}`);
54
+ return r.geo;
55
+ };
56
+ const A = outward(input(0), 'A'), B = hasInput(1) ? outward(input(1), 'B') : null;
46
57
  const L = propLayout(B ? [A, B] : [A]);
47
58
  const mA = track(toManifold(A, L));
48
59
  let r;
@@ -54,10 +65,14 @@ defineNode({
54
65
  sources.push({ geo: B, id: manifoldId(mB) });
55
66
  r = track(p.operation === 'union' ? mA.add(mB) : p.operation === 'intersect' ? mA.intersect(mB) : mA.subtract(mB));
56
67
  }
57
- const { geo, primSource } = fromManifold(r, L, sources);
68
+ if (p.tolerance > 0)
69
+ r = track(r.simplify(p.tolerance));
70
+ const { geo, primSource, primFace } = fromManifold(r, L, sources);
58
71
  geo.addGroup('prim', 'from_a', Uint8Array.from(primSource, (s) => (s === 0 ? 1 : 0)));
59
72
  geo.addGroup('prim', 'from_b', Uint8Array.from(primSource, (s) => (s === 1 ? 1 : 0)));
60
- return geo;
73
+ if (p.output === 'triangles')
74
+ return geo;
75
+ return mergeTriangles(geo, Float64Array.from(primSource, (s, t) => (s >= 0 && primFace[t] >= 0 ? s * 2 ** 32 + primFace[t] : -1)));
61
76
  }),
62
77
  });
63
78
  defineNode({
@@ -1 +1,15 @@
1
- export {};
1
+ import { Geometry } from '../core/geometry.ts';
2
+ export interface FilletOptions {
3
+ radius: number;
4
+ type: 'round' | 'chamfer' | 'bezier';
5
+ segments: number;
6
+ /** degrees: corners turning less stay */
7
+ angleMin: number;
8
+ /** corner points to fillet (null = all) */
9
+ sel: ArrayLike<number> | null;
10
+ clamp: boolean;
11
+ /** per corner point, multiplies the radius */
12
+ radiusOf: ((pt: number) => number) | null;
13
+ }
14
+ /** Fillet the corners of polylines and polygons (the fillet_curve node; also curve's corner_radius). */
15
+ export declare function filletCurves(g: Geometry, p: FilletOptions): Geometry;
@@ -503,123 +503,130 @@ defineNode({
503
503
  example: { type: 'fillet_curve', params: { radius: 0.5, segments: 8 } },
504
504
  cook: ({ input, p }) => {
505
505
  const g = input(0);
506
- const ptSel = mask(g, 'point', p.group);
507
506
  const ra = p.radius_attrib ? g.points.get(p.radius_attrib) : null;
508
507
  if (p.radius_attrib && (!ra || ra.type === 'string' || ra.isArray))
509
508
  throw new NodeError(`no numeric point attribute "${p.radius_attrib}" for radius_attrib`);
510
- const minTurn = p.angle_min * DEG;
511
- const rb = new Rebuild(g);
512
- const fg = rb.b.group('point', 'fillet');
513
- for (let pr = 0; pr < g.numPrims; pr++) {
514
- if (!isCurvePrim(g, pr) || g.primSize(pr) < 3) {
515
- rb.keep(pr);
509
+ return filletCurves(g, {
510
+ radius: p.radius, type: p.type, segments: p.segments, angleMin: p.angle_min, sel: mask(g, 'point', p.group), clamp: p.clamp,
511
+ radiusOf: ra ? (pt) => Number(ra.get(pt)) : null,
512
+ });
513
+ },
514
+ });
515
+ /** Fillet the corners of polylines and polygons (the fillet_curve node; also curve's corner_radius). */
516
+ export function filletCurves(g, p) {
517
+ const ptSel = p.sel;
518
+ const minTurn = p.angleMin * DEG;
519
+ const rb = new Rebuild(g);
520
+ const fg = rb.b.group('point', 'fillet');
521
+ for (let pr = 0; pr < g.numPrims; pr++) {
522
+ if (!isCurvePrim(g, pr) || g.primSize(pr) < 3) {
523
+ rb.keep(pr);
524
+ continue;
525
+ }
526
+ let pts = g.primPoints(pr);
527
+ let closed = !!g.primClosed[pr];
528
+ // an open polyline whose ends meet is a loop: fillet its seam too, keep it open (seam point repeated)
529
+ const loop = !closed && pts.length > 3 && pts[0] === pts[pts.length - 1];
530
+ if (loop)
531
+ pts = pts.slice(0, -1);
532
+ const cyc = closed || loop;
533
+ const m = pts.length, X = positionsOf(g, pts);
534
+ const t = new Float64Array(m), ang = new Float64Array(m);
535
+ const d1s = new Array(m), d2s = new Array(m), lenA = new Float64Array(m), lenB = new Float64Array(m);
536
+ for (let k = 0; k < m; k++) {
537
+ if (!cyc && (k === 0 || k === m - 1))
516
538
  continue;
517
- }
518
- let pts = g.primPoints(pr);
519
- let closed = !!g.primClosed[pr];
520
- // an open polyline whose ends meet is a loop: fillet its seam too, keep it open (seam point repeated)
521
- const loop = !closed && pts.length > 3 && pts[0] === pts[pts.length - 1];
522
- if (loop)
523
- pts = pts.slice(0, -1);
524
- const cyc = closed || loop;
525
- const m = pts.length, X = positionsOf(g, pts);
526
- const t = new Float64Array(m), ang = new Float64Array(m);
527
- const d1s = new Array(m), d2s = new Array(m), lenA = new Float64Array(m), lenB = new Float64Array(m);
539
+ if (ptSel && !ptSel[pts[k]])
540
+ continue;
541
+ const a = (k - 1 + m) % m, c = (k + 1) % m;
542
+ const P0 = v3(X, k), A = v3(X, a), B = v3(X, c);
543
+ const da = [A[0] - P0[0], A[1] - P0[1], A[2] - P0[2]], db = [B[0] - P0[0], B[1] - P0[1], B[2] - P0[2]];
544
+ const la = Math.hypot(...da), lb = Math.hypot(...db);
545
+ if (!(la > 1e-12 && lb > 1e-12))
546
+ continue;
547
+ const d1 = normalize(da), d2 = normalize(db);
548
+ const th = Math.acos(Math.max(-1, Math.min(1, dot(d1, d2)))); // interior angle
549
+ if (Math.PI - th < minTurn || th < 1e-6)
550
+ continue;
551
+ const r = p.radius * (p.radiusOf ? p.radiusOf(pts[k]) : 1);
552
+ if (!(r > 0))
553
+ continue;
554
+ t[k] = r / Math.tan(th / 2);
555
+ ang[k] = th;
556
+ d1s[k] = d1;
557
+ d2s[k] = d2;
558
+ lenA[k] = la;
559
+ lenB[k] = lb;
560
+ }
561
+ if (p.clamp) {
562
+ // tangent lengths of the two corners of an edge may not add up to more than the edge
563
+ const f = new Float64Array(m).fill(1);
528
564
  for (let k = 0; k < m; k++) {
529
- if (!cyc && (k === 0 || k === m - 1))
530
- continue;
531
- if (ptSel && !ptSel[pts[k]])
532
- continue;
533
- const a = (k - 1 + m) % m, c = (k + 1) % m;
534
- const P0 = v3(X, k), A = v3(X, a), B = v3(X, c);
535
- const da = [A[0] - P0[0], A[1] - P0[1], A[2] - P0[2]], db = [B[0] - P0[0], B[1] - P0[1], B[2] - P0[2]];
536
- const la = Math.hypot(...da), lb = Math.hypot(...db);
537
- if (!(la > 1e-12 && lb > 1e-12))
538
- continue;
539
- const d1 = normalize(da), d2 = normalize(db);
540
- const th = Math.acos(Math.max(-1, Math.min(1, dot(d1, d2)))); // interior angle
541
- if (Math.PI - th < minTurn || th < 1e-6)
542
- continue;
543
- const r = p.radius * (ra ? Number(ra.get(pts[k])) : 1);
544
- if (!(r > 0))
565
+ const c = (k + 1) % m;
566
+ if (!cyc && k === m - 1)
545
567
  continue;
546
- t[k] = r / Math.tan(th / 2);
547
- ang[k] = th;
548
- d1s[k] = d1;
549
- d2s[k] = d2;
550
- lenA[k] = la;
551
- lenB[k] = lb;
552
- }
553
- if (p.clamp) {
554
- // tangent lengths of the two corners of an edge may not add up to more than the edge
555
- const f = new Float64Array(m).fill(1);
556
- for (let k = 0; k < m; k++) {
557
- const c = (k + 1) % m;
558
- if (!cyc && k === m - 1)
559
- continue;
560
- const L = Math.hypot(X[c * 3] - X[k * 3], X[c * 3 + 1] - X[k * 3 + 1], X[c * 3 + 2] - X[k * 3 + 2]);
561
- const need = t[k] + t[c];
562
- if (need > L && need > 0) {
563
- const s = L / need;
564
- f[k] = Math.min(f[k], s);
565
- f[c] = Math.min(f[c], s);
566
- }
568
+ const L = Math.hypot(X[c * 3] - X[k * 3], X[c * 3 + 1] - X[k * 3 + 1], X[c * 3 + 2] - X[k * 3 + 2]);
569
+ const need = t[k] + t[c];
570
+ if (need > L && need > 0) {
571
+ const s = L / need;
572
+ f[k] = Math.min(f[k], s);
573
+ f[c] = Math.min(f[c], s);
567
574
  }
568
- for (let k = 0; k < m; k++)
569
- t[k] *= f[k];
570
575
  }
571
- const verts = [];
572
- for (let k = 0; k < m; k++) {
573
- if (!(t[k] > 1e-12)) {
574
- verts.push({ k });
575
- continue;
576
- }
577
- const a = (k - 1 + m) % m, c = (k + 1) % m, th = ang[k], d1 = d1s[k], d2 = d2s[k], tk = t[k];
578
- const P0 = v3(X, k);
579
- const T1 = addS(P0, d1, tk), T2 = addS(P0, d2, tk);
580
- const fa = tk / lenA[k], fb = tk / lenB[k];
581
- const prov = (s) => ({ idx: [k, a, k, c], w: [(1 - s) * (1 - fa), (1 - s) * fa, s * (1 - fb), s * fb] });
582
- const push = (P, s) => { verts.push({ P, ...prov(s) }); };
583
- if (p.type === 'chamfer') {
584
- push(T1, 0);
585
- push(T2, 1);
586
- continue;
587
- }
588
- const n = Math.max(1, p.segments);
589
- if (p.type === 'bezier') {
590
- for (let j = 0; j <= n; j++) {
591
- const s = j / n, w0 = (1 - s) * (1 - s), w1 = 2 * s * (1 - s), w2 = s * s;
592
- push([w0 * T1[0] + w1 * P0[0] + w2 * T2[0], w0 * T1[1] + w1 * P0[1] + w2 * T2[1], w0 * T1[2] + w1 * P0[2] + w2 * T2[2]], s);
593
- }
594
- continue;
595
- }
596
- // round: arc around the centre on the bisector, from T1 to T2
597
- const bis = normalize([d1[0] + d2[0], d1[1] + d2[1], d1[2] + d2[2]]);
598
- const C = addS(P0, bis, tk / Math.cos(th / 2));
599
- const va = [T1[0] - C[0], T1[1] - C[1], T1[2] - C[2]], vb = [T2[0] - C[0], T2[1] - C[1], T2[2] - C[2]];
600
- const phi = Math.PI - th, sp = Math.sin(phi);
576
+ for (let k = 0; k < m; k++)
577
+ t[k] *= f[k];
578
+ }
579
+ const verts = [];
580
+ for (let k = 0; k < m; k++) {
581
+ if (!(t[k] > 1e-12)) {
582
+ verts.push({ k });
583
+ continue;
584
+ }
585
+ const a = (k - 1 + m) % m, c = (k + 1) % m, th = ang[k], d1 = d1s[k], d2 = d2s[k], tk = t[k];
586
+ const P0 = v3(X, k);
587
+ const T1 = addS(P0, d1, tk), T2 = addS(P0, d2, tk);
588
+ const fa = tk / lenA[k], fb = tk / lenB[k];
589
+ const prov = (s) => ({ idx: [k, a, k, c], w: [(1 - s) * (1 - fa), (1 - s) * fa, s * (1 - fb), s * fb] });
590
+ const push = (P, s) => { verts.push({ P, ...prov(s) }); };
591
+ if (p.type === 'chamfer') {
592
+ push(T1, 0);
593
+ push(T2, 1);
594
+ continue;
595
+ }
596
+ const n = Math.max(1, p.segments);
597
+ if (p.type === 'bezier') {
601
598
  for (let j = 0; j <= n; j++) {
602
- const s = j / n;
603
- const wa = sp > 1e-12 ? Math.sin((1 - s) * phi) / sp : 1 - s, wb = sp > 1e-12 ? Math.sin(s * phi) / sp : s;
604
- push([C[0] + va[0] * wa + vb[0] * wb, C[1] + va[1] * wa + vb[1] * wb, C[2] + va[2] * wa + vb[2] * wb], s);
599
+ const s = j / n, w0 = (1 - s) * (1 - s), w1 = 2 * s * (1 - s), w2 = s * s;
600
+ push([w0 * T1[0] + w1 * P0[0] + w2 * T2[0], w0 * T1[1] + w1 * P0[1] + w2 * T2[1], w0 * T1[2] + w1 * P0[2] + w2 * T2[2]], s);
605
601
  }
602
+ continue;
603
+ }
604
+ // round: arc around the centre on the bisector, from T1 to T2
605
+ const bis = normalize([d1[0] + d2[0], d1[1] + d2[1], d1[2] + d2[2]]);
606
+ const C = addS(P0, bis, tk / Math.cos(th / 2));
607
+ const va = [T1[0] - C[0], T1[1] - C[1], T1[2] - C[2]], vb = [T2[0] - C[0], T2[1] - C[1], T2[2] - C[2]];
608
+ const phi = Math.PI - th, sp = Math.sin(phi);
609
+ for (let j = 0; j <= n; j++) {
610
+ const s = j / n;
611
+ const wa = sp > 1e-12 ? Math.sin((1 - s) * phi) / sp : 1 - s, wb = sp > 1e-12 ? Math.sin(s * phi) / sp : s;
612
+ push([C[0] + va[0] * wa + vb[0] * wb, C[1] + va[1] * wa + vb[1] * wb, C[2] + va[2] * wa + vb[2] * wb], s);
606
613
  }
607
- // tangent points of neighbouring corners that meet exactly (clamped radii): keep one
608
- const posOf = (c) => ('k' in c ? v3(X, c.k) : c.P);
609
- const same = (a, b) => { const x = posOf(a), y = posOf(b); return Math.hypot(x[0] - y[0], x[1] - y[1], x[2] - y[2]) < 1e-12; };
610
- const vv = [];
611
- for (const c of verts)
612
- if (!(vv.length && !('k' in c) && same(vv[vv.length - 1], c)))
613
- vv.push(c);
614
- if (cyc && vv.length > 1 && !('k' in vv[vv.length - 1]) && same(vv[0], vv[vv.length - 1]))
615
- vv.pop();
616
- const { created } = rb.addCurve(pr, vv, closed, undefined, loop);
617
- for (const id of created)
618
- fg.add(id);
619
614
  }
620
- return rb.finish();
621
- },
622
- });
615
+ // tangent points of neighbouring corners that meet exactly (clamped radii): keep one
616
+ const posOf = (c) => ('k' in c ? v3(X, c.k) : c.P);
617
+ const same = (a, b) => { const x = posOf(a), y = posOf(b); return Math.hypot(x[0] - y[0], x[1] - y[1], x[2] - y[2]) < 1e-12; };
618
+ const vv = [];
619
+ for (const c of verts)
620
+ if (!(vv.length && !('k' in c) && same(vv[vv.length - 1], c)))
621
+ vv.push(c);
622
+ if (cyc && vv.length > 1 && !('k' in vv[vv.length - 1]) && same(vv[0], vv[vv.length - 1]))
623
+ vv.pop();
624
+ const { created } = rb.addCurve(pr, vv, closed, undefined, loop);
625
+ for (const id of created)
626
+ fg.add(id);
627
+ }
628
+ return rb.finish();
629
+ }
623
630
  // ---------------------------------------------------------------- offset_curve_3d
624
631
  /**
625
632
  * Offset of one polyline by d along each edge's side vector (direction × up: the right of the direction of travel),
@@ -3,7 +3,16 @@ import { Image } from '../core/image.ts';
3
3
  import type { CookContext, ParamDef } from '../graph/types.ts';
4
4
  export declare const NO_IMAGE = "make one with a generator (tex_noise, tex_pattern, tex_shape, tex_cells \u2026), a bake (bake_ao, bake_curvature \u2026) or heightfield_to_tex, or load a PNG with image_file";
5
5
  export declare const resolutionParam: (def?: number) => ParamDef;
6
- export declare const nameParam: (def: string, desc?: string) => ParamDef;
6
+ /** The name of the image a node makes: "" = the node's own name (unique in its graph). */
7
+ export declare const nameParam: (desc?: string) => ParamDef;
8
+ /** Which image of an input to read: "" = its only image (an input holding several is an error that lists them). */
9
+ export declare const imageParam: (of?: string, aliases?: string[]) => ParamDef;
10
+ /** A filter's result name: "" = the filter node's name (the processed image is renamed; one already so called is replaced). */
11
+ export declare const renameParam: () => ParamDef;
12
+ /** usesNodeName for nodes whose image takes the node's name when the name param is empty. */
13
+ export declare const NAMED_BY_NODE: (p: Record<string, any>) => boolean;
14
+ /** The name of the image a node outputs: its name param, else the node's own name. */
15
+ export declare const outName: (ctx: CookContext) => string;
7
16
  export declare function checkSize(w: number, h: number, node: string): void;
8
17
  /** A geometry holding only this image. */
9
18
  export declare function imageGeo(img: Image): Geometry;
@@ -16,9 +25,15 @@ export interface Source {
16
25
  data: Float32Array;
17
26
  ch: 1 | 4;
18
27
  }
19
- /** The image (by name, "" = first) and layer ("" = main) a node reads from input i. */
20
- export declare function source(ctx: CookContext, i: number, imageName?: string, layerName?: string): Source;
21
- /** The input geometry with the source image's layer replaced (and the image renamed when `rename` is set). */
22
- export declare function withLayer(s: Source, data: Float32Array, rename?: string, extra?: Record<string, Float32Array>): Geometry;
28
+ /**
29
+ * The image (by name; "" = the input's only image) and layer ("" = main) a node reads from input i. `param` names the
30
+ * param that picks the image of this input, for the error when the input holds several and none is named ("" = the
31
+ * node has none: keep one image in that input).
32
+ */
33
+ export declare function source(ctx: CookContext, i: number, imageName?: string, layerName?: string, param?: string): Source;
34
+ /**
35
+ * The input geometry with the source image's layer replaced and the image named `name` (outName: the filter node's
36
+ * name by default); another image already called `name` is replaced by it.
37
+ */
38
+ export declare function withLayer(s: Source, data: Float32Array, name: string, extra?: Record<string, Float32Array>): Geometry;
23
39
  export declare const size2: (p: any, node: string) => [number, number];
24
- export declare const imgName: (p: any, def: string) => string;