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
@@ -4,12 +4,15 @@
4
4
  import { GeoBuilder, Geometry } from '../core/geometry.js';
5
5
  import { defineNode } from '../graph/registry.js';
6
6
  import { NodeError } from '../graph/types.js';
7
- import { add, cross, dot, length, normalize, scale, sub } from '../core/math.js';
8
- import { orientOutward, topologyReport } from '../core/topology.js';
9
- import { crossSection, crossSectionFaces, detectPlane, fromManifold, planeMatrix, polygonsToGeo, propLayout, toPolygons } from '../core/manifold.js';
7
+ import { add, cross, dot, length, m4applyDir, m4euler, normalize, scale, sub } from '../core/math.js';
8
+ import { orientOutward, primNormals, topologyReport } from '../core/topology.js';
9
+ import { mergeTriangles } from '../core/polymerge.js';
10
+ import earcut from 'earcut';
11
+ import { crossSection, crossSectionFaces, detectPlane, fromManifold, orientNested, planeMatrix, polygonsToGeo, propLayout, toPolygons } from '../core/manifold.js';
10
12
  import { FRAMES, P, mask } from './util.js';
11
13
  import { evalRamp } from '../graph/params.js';
12
14
  import { arcTable, evalBasis, evaluateSplines, samplesByLength, splineFromPrim, tangentAt, tidySplineAttribs } from '../core/splines.js';
15
+ import { filletCurves } from './splines.js';
13
16
  // ---------------------------------------------------------------- helpers
14
17
  /** Catmull–Rom (centripetal) through points; returns dense samples. */
15
18
  export function catmullRom(pts, closed, sub) {
@@ -189,23 +192,49 @@ defineNode({
189
192
  defineNode({
190
193
  type: 'curve',
191
194
  category: 'curve',
192
- summary: 'Curve through explicit points; optional Catmull-Rom smoothing; open or closed.',
195
+ summary: 'Curve through explicit points; optional Catmull-Rom smoothing or rounded corners; open or closed.',
196
+ description: 'corner_radius rounds the corners with arcs tangent to both edges: one number for every corner, or a list with one radius per point (0 keeps that corner sharp; the ends of an open curve are never rounded). Radii that do not fit between neighbouring corners shrink. A point that is not three numbers (NaN, null, a missing coordinate) is an error that names it.',
193
197
  aliases: ['polyline', 'path', 'spline'],
194
198
  inputs: [],
195
199
  params: {
196
200
  points: { type: 'json', default: [[0, 0, 0], [1, 0.5, 0], [2, 0, 0]], desc: 'list of [x,y,z] (2-number entries → [x, 0, z] on the ground)', aliases: ['positions', 'pts'] },
197
201
  closed: { type: 'bool', default: false, desc: 'close the curve (makes a polygon)' },
198
- smooth: { type: 'bool', default: false, desc: 'Catmull-Rom interpolate through the points' },
202
+ smooth: { type: 'bool', default: false, desc: 'Catmull-Rom interpolate through the points (not with corner_radius)' },
199
203
  subdivisions: { type: 'int', default: 8, min: 1, max: 10000, desc: 'smooth: samples per segment' },
204
+ corner_radius: { type: 'json', default: 0, desc: 'round the corners: a radius for every corner, or a list with one per point (0 = sharp)', aliases: ['fillet', 'radius', 'radii', 'corner_radii'] },
205
+ corner_segments: { type: 'int', default: 6, min: 1, max: 10000, desc: 'segments per rounded corner' },
200
206
  },
207
+ outputs: 'point group fillet (the points of rounded corners)',
201
208
  example: { type: 'curve', params: { points: [[0, 0, 0], [2, 0, 1], [4, 0, -1], [6, 0, 0]], smooth: true, subdivisions: 12 } },
202
- cook: ({ p }) => {
209
+ cook: ({ p, warn }) => {
203
210
  if (!Array.isArray(p.points) || p.points.length < 2)
204
211
  throw new NodeError('points must be a list of at least 2 [x,y,z]');
205
- let pts = p.points.map((q) => (q.length === 2 ? [+q[0], 0, +q[1]] : [+q[0], +q[1], +q[2]]));
206
- if (p.smooth && pts.length > 2)
207
- pts = catmullRom(pts, p.closed, p.subdivisions).pos;
208
- return new Geometry({ positions: pts.flat(), prims: [pts.map((_, i) => i)], closed: p.closed });
212
+ const pts = p.points.map((q, i) => {
213
+ const ok = Array.isArray(q) && (q.length === 2 || q.length === 3) && q.every((x) => typeof x === 'number' && Number.isFinite(x));
214
+ const v = ok ? (q.length === 2 ? [q[0], 0, q[1]] : [q[0], q[1], q[2]]) : [];
215
+ if (!ok)
216
+ throw new NodeError(`point ${i} is not three numbers: ${JSON.stringify(q)}`, 'every entry of points is [x, y, z] (or [x, z] on the ground); an expression that divides by zero gives NaN');
217
+ return v;
218
+ });
219
+ const radii = p.corner_radius;
220
+ const perPoint = Array.isArray(radii);
221
+ if (perPoint && radii.length !== pts.length)
222
+ throw new NodeError(`corner_radius has ${radii.length} entries for ${pts.length} points`, 'give one radius per point (0 keeps a corner sharp), or one number for every corner');
223
+ if (!perPoint && !(typeof radii === 'number' && Number.isFinite(radii)))
224
+ throw new NodeError(`corner_radius must be a number or a list of numbers, got ${JSON.stringify(radii)}`);
225
+ if (perPoint && !radii.every((r) => typeof r === 'number' && Number.isFinite(r)))
226
+ throw new NodeError('corner_radius: every entry must be a number');
227
+ const rounded = perPoint ? radii.some((r) => r > 0) : radii > 0;
228
+ if (rounded && p.smooth)
229
+ warn('smooth is ignored: corner_radius rounds the corners instead');
230
+ const final = p.smooth && pts.length > 2 && !rounded ? catmullRom(pts, p.closed, p.subdivisions).pos : pts;
231
+ const g = new Geometry({ positions: final.flat(), prims: [final.map((_, i) => i)], closed: p.closed });
232
+ if (!rounded)
233
+ return g;
234
+ return filletCurves(g, {
235
+ radius: 1, type: 'round', segments: p.corner_segments, angleMin: 0.01, sel: null, clamp: true,
236
+ radiusOf: (pt) => (perPoint ? radii[pt] : radii),
237
+ });
209
238
  },
210
239
  });
211
240
  defineNode({
@@ -238,17 +267,17 @@ defineNode({
238
267
  defineNode({
239
268
  type: 'shape2d',
240
269
  category: 'curve',
241
- summary: 'Flat 2D shapes as closed polygons: rect, rounded_rect, ngon, star, gear, cross, L, U.',
270
+ summary: 'Flat 2D shapes as closed polygons: rect, rounded_rect, capsule (slot), ngon, star, gear, cross, L, U.',
242
271
  aliases: ['rect', 'rectangle', 'ngon', 'star', 'polygon2d'],
243
272
  inputs: [],
244
273
  params: {
245
- shape: { type: 'enum', options: ['rect', 'rounded_rect', 'ngon', 'star', 'gear', 'cross', 'L', 'U'], default: 'rect', desc: 'shape type' },
246
- size: { type: 'vec2', default: [1, 1], desc: 'rect/rounded_rect/cross/L/U: width and depth' },
274
+ shape: { type: 'enum', options: ['rect', 'rounded_rect', 'capsule', 'slot', 'ngon', 'star', 'gear', 'cross', 'L', 'U'], default: 'rect', desc: 'shape type; capsule and slot are the same stadium: a rect whose short ends are half circles' },
275
+ size: { type: 'vec2', default: [1, 1], desc: 'rect/rounded_rect/capsule/slot/cross/L/U: width and depth (overall, ends included)' },
247
276
  radius: { type: 'float', default: 0.5, desc: 'ngon/star/gear: outer radius' },
248
277
  inner_radius: { type: 'float', default: 0.25, desc: 'star/gear: inner radius' },
249
278
  sides: { type: 'int', default: 6, min: 3, max: 100000, desc: 'ngon sides / star points / gear teeth', aliases: ['points', 'teeth'] },
250
279
  corner_radius: { type: 'float', default: 0.1, min: 0, desc: 'rounded_rect corner radius' },
251
- corner_segments: { type: 'int', default: 6, min: 1, max: 10000, desc: 'rounded_rect segments per corner' },
280
+ corner_segments: { type: 'int', default: 6, min: 1, max: 10000, desc: 'rounded_rect/capsule/slot: segments per quarter circle' },
252
281
  thickness: { type: 'float', default: 0.25, desc: 'cross/L/U arm thickness' },
253
282
  rotate: { type: 'float', default: 0, desc: 'rotation in degrees within the plane' },
254
283
  plane: P.plane('xz'),
@@ -263,8 +292,10 @@ defineNode({
263
292
  case 'rect':
264
293
  pts2 = [[-hw, -hd], [hw, -hd], [hw, hd], [-hw, hd]];
265
294
  break;
266
- case 'rounded_rect': {
267
- const r = Math.min(p.corner_radius, hw, hd), s = p.corner_segments;
295
+ case 'rounded_rect':
296
+ case 'capsule':
297
+ case 'slot': {
298
+ const r = p.shape === 'rounded_rect' ? Math.min(p.corner_radius, hw, hd) : Math.min(hw, hd), s = p.corner_segments;
268
299
  const cs = [[hw - r, -hd + r, -90], [hw - r, hd - r, 0], [-hw + r, hd - r, 90], [-hw + r, -hd + r, 180]];
269
300
  for (const [cx, cy, a0] of cs)
270
301
  for (let k = 0; k <= s; k++) {
@@ -548,7 +579,7 @@ function sweepCurves(g, profiles, o) {
548
579
  const L = arcLengths(pts, closed), total = L[L.length - 1] || 1;
549
580
  const prof = profiles[Math.min(pr, profiles.length - 1)];
550
581
  const m = prof.pts.length;
551
- const rings = [];
582
+ const rings = [], scales = [];
552
583
  for (let k = 0; k < pts.length; k++) {
553
584
  const u = L[k] / total;
554
585
  let s = psA ? psA.get(idx[k]) : 1;
@@ -556,6 +587,7 @@ function sweepCurves(g, profiles, o) {
556
587
  s *= o.radiusOf(idx[k]);
557
588
  if (o.scaleRamp)
558
589
  s *= evalRamp(o.scaleRamp, u);
590
+ scales.push(s);
559
591
  const tw = ((o.twist * u) * Math.PI) / 180, c = Math.cos(tw), sn = Math.sin(tw);
560
592
  const X = F.X[k], Y = F.Y[k], T = F.T[k];
561
593
  const ring = [];
@@ -579,8 +611,26 @@ function sweepCurves(g, profiles, o) {
579
611
  }
580
612
  }
581
613
  if (o.caps && !closed && prof.closed && m >= 3) {
582
- capG.add(b.addPrim(rings[0].slice().reverse(), true, pr));
583
- capG.add(b.addPrim(rings[rings.length - 1].slice(), true, pr));
614
+ // caps take the profile's own flat layout: its x, y spread over 0..1 (uv_length: in metres at that end's scale)
615
+ let x0 = Infinity, x1 = -Infinity, y0 = Infinity, y1 = -Infinity;
616
+ for (const q of prof.pts) {
617
+ x0 = Math.min(x0, q[0]);
618
+ x1 = Math.max(x1, q[0]);
619
+ y0 = Math.min(y0, q[1]);
620
+ y1 = Math.max(y1, q[1]);
621
+ }
622
+ const span = Math.max(x1 - x0, y1 - y0) || 1;
623
+ for (const end of [0, rings.length - 1]) {
624
+ const ids = end === 0 ? rings[0].slice().reverse() : rings[end].slice();
625
+ const order = end === 0 ? prof.pts.map((_, j) => m - 1 - j) : prof.pts.map((_, j) => j);
626
+ const sc = o.uvLength ? scales[end] : 1 / span;
627
+ const vb = b.numVertices;
628
+ capG.add(b.addPrim(ids, true, pr));
629
+ order.forEach((j, q) => {
630
+ const u = (prof.pts[j][0] - x0) * sc, v = (prof.pts[j][1] - y0) * sc;
631
+ uv.set(vb + q, [end === 0 ? 1 - u : u, v, 0]);
632
+ });
633
+ }
584
634
  }
585
635
  }
586
636
  return b.build();
@@ -592,14 +642,16 @@ defineNode({
592
642
  type: 'sweep',
593
643
  category: 'curve',
594
644
  summary: 'Sweep a cross-section along curves using rotation-minimising frames (tubes, ribbons, rails, mouldings).',
645
+ description: 'The profile is drawn in the XY plane around the origin, looking along the curve: at every curve point it is placed with its +Z along the curve (the direction of travel), its +Y on the up direction (the "up" param, or the point attribute up) kept perpendicular to the curve, and its +X = Y × Z, to the left of the direction of travel when up points up. The frame then turns as little as possible from point to point (rotation-minimising), so a flat ribbon does not twist on its own; twist adds a turn. The sides are wound so a closed profile drawn counter-clockwise (seen from +Z) faces outward; caps on open curves face away from the curve. uv: u runs around the profile, v along the curve; caps take the profile\'s flat layout.',
595
646
  inputs: [
596
647
  { name: 'backbone', desc: 'curves to sweep along (Bezier/NURBS curves are sampled adaptively)' },
597
648
  { name: 'profile', desc: 'cross-section curve drawn in the XY plane (optional; one per backbone or a single shared one)', optional: true },
598
649
  ],
599
650
  splines: 'keep',
600
651
  params: {
601
- shape: { type: 'enum', options: ['circle', 'square', 'ribbon', 'half_circle'], default: 'circle', desc: 'built-in profile when no profile input' },
652
+ shape: { type: 'enum', options: ['circle', 'square', 'rect', 'ribbon', 'half_circle'], default: 'circle', desc: 'built-in profile when no profile input; rect is size wide (X) and high (Y), for straps and bars' },
602
653
  radius: { type: 'float', default: 0.1, desc: 'built-in profile radius / half width', aliases: ['width', 'rad'] },
654
+ size: { type: 'vec2', default: [0.2, 0.05], desc: 'rect profile: width along the profile X (sideways) and height along Y (up)' },
603
655
  divisions: { type: 'int', default: 12, min: 2, max: 1024, desc: 'built-in profile segments', aliases: ['sides', 'cols'] },
604
656
  caps: { type: 'bool', default: true, desc: 'cap open ends (closed profiles only)' },
605
657
  twist: { type: 'float', default: 0, desc: 'total twist in degrees along each curve' },
@@ -628,6 +680,10 @@ defineNode({
628
680
  }
629
681
  else if (p.shape === 'square')
630
682
  profiles = [{ pts: [[-p.radius, -p.radius, 0], [p.radius, -p.radius, 0], [p.radius, p.radius, 0], [-p.radius, p.radius, 0]], closed: true }];
683
+ else if (p.shape === 'rect') {
684
+ const w = p.size[0] / 2, h = p.size[1] / 2;
685
+ profiles = [{ pts: [[-w, -h, 0], [w, -h, 0], [w, h, 0], [-w, h, 0]], closed: true }];
686
+ }
631
687
  else if (p.shape === 'ribbon')
632
688
  profiles = [{ pts: [[-p.radius, 0, 0], [p.radius, 0, 0]], closed: false }];
633
689
  else if (p.shape === 'half_circle')
@@ -672,10 +728,13 @@ defineNode({
672
728
  defineNode({
673
729
  type: 'revolve',
674
730
  category: 'curve',
675
- summary: 'Lathe: revolve profile curves (drawn in XY, x = radius) around the Y axis. Profiles touching the axis close up.',
731
+ summary: 'Lathe: revolve profile curves around an axis (Y through the origin by default). Profiles touching the axis close up.',
732
+ description: 'Each profile point turns around the axis line (through origin, along axis) at its own distance from it, so the profile can be drawn in any plane that holds the axis: the XY plane (x = radius) for the default Y axis, the XY plane (y = radius) for axis [1, 0, 0]. angle is measured from where the profile is drawn, turning counter-clockwise when the axis points at the viewer. Closed results face outward.',
676
733
  aliases: ['lathe'],
677
- inputs: [{ name: 'profile', desc: 'curves in the XY plane (x = distance from the axis)' }],
734
+ inputs: [{ name: 'profile', desc: 'curves in a plane holding the axis (default: the XY plane, x = distance from the Y axis)' }],
678
735
  params: {
736
+ axis: { type: 'vec3', default: [0, 1, 0], desc: 'direction of the axis to turn around', aliases: ['direction', 'dir'] },
737
+ origin: { type: 'vec3', default: [0, 0, 0], desc: 'a point on the axis', aliases: ['center', 'pivot'] },
679
738
  segments: { type: 'int', default: 32, min: 3, max: 4096, desc: 'segments around', aliases: ['divisions', 'cols'] },
680
739
  angle: { type: 'vec2', default: [0, 360], desc: 'start/end angle in degrees' },
681
740
  caps: { type: 'bool', default: false, desc: 'cap partial revolves (closed profiles)' },
@@ -693,13 +752,23 @@ defineNode({
693
752
  const g = input(0);
694
753
  const span = p.angle[1] - p.angle[0], full = Math.abs(span) >= 360 - 1e-9;
695
754
  const n = p.segments, cols = full ? n : n + 1;
755
+ const al = Math.hypot(p.axis[0], p.axis[1], p.axis[2]);
756
+ if (!(al > 0))
757
+ throw new NodeError('axis must not be zero', 'e.g. [0, 1, 0] for the Y axis');
758
+ // a frame with the axis as its Y: points go into it, turn around Y, and come back
759
+ const R = toYAxis([p.axis[0] / al, p.axis[1] / al, p.axis[2] / al]), o = p.origin;
760
+ const local = (i) => {
761
+ const x = g.P[i * 3] - o[0], y = g.P[i * 3 + 1] - o[1], z = g.P[i * 3 + 2] - o[2];
762
+ return [R[0] * x + R[1] * y + R[2] * z, R[3] * x + R[4] * y + R[5] * z, R[6] * x + R[7] * y + R[8] * z];
763
+ };
764
+ const world = (x, y, z) => [o[0] + R[0] * x + R[3] * y + R[6] * z, o[1] + R[1] * x + R[4] * y + R[7] * z, o[2] + R[2] * x + R[5] * y + R[8] * z];
696
765
  const b = new GeoBuilder(g);
697
766
  const uv = b.attrib('vertex', 'uv', 3);
698
767
  for (let pr = 0; pr < g.numPrims; pr++) {
699
768
  const idx = g.primPoints(pr), closed = !!g.primClosed[pr];
700
769
  const grid = [];
701
770
  for (const i of idx) {
702
- const x = g.P[i * 3], y = g.P[i * 3 + 1], z = g.P[i * 3 + 2];
771
+ const [x, y, z] = local(i);
703
772
  const r = Math.hypot(x, z);
704
773
  if (r < 1e-9) {
705
774
  const c = b.copyPoint(i);
@@ -710,7 +779,8 @@ defineNode({
710
779
  const row = [];
711
780
  for (let j = 0; j < cols; j++) {
712
781
  const a = a0 + ((p.angle[0] + (span * j) / n) * Math.PI) / 180;
713
- row.push(b.addPoint(r * Math.cos(a), y, -r * Math.sin(a), i));
782
+ const w = world(r * Math.cos(a), y, -r * Math.sin(a));
783
+ row.push(b.addPoint(w[0], w[1], w[2], i));
714
784
  }
715
785
  grid.push(row);
716
786
  }
@@ -745,6 +815,19 @@ defineNode({
745
815
  return out;
746
816
  },
747
817
  });
818
+ /** Row-major rotation taking unit vector a onto +Y (Rodrigues; a half turn about X when a points down). */
819
+ function toYAxis(a) {
820
+ const c = a[1];
821
+ if (c < -1 + 1e-12)
822
+ return [1, 0, 0, 0, -1, 0, 0, 0, -1];
823
+ // v = a × Y, R = I + [v]x + [v]x² / (1 + c)
824
+ const vx = -a[2], vy = 0, vz = a[0], k = 1 / (1 + c);
825
+ return [
826
+ 1 - (vy * vy + vz * vz) * k, -vz + vx * vy * k, vy + vx * vz * k,
827
+ vz + vx * vy * k, 1 - (vx * vx + vz * vz) * k, -vx + vy * vz * k,
828
+ -vy + vx * vz * k, vx + vy * vz * k, 1 - (vx * vx + vy * vy) * k,
829
+ ];
830
+ }
748
831
  function pointInPoly(pt, poly) {
749
832
  let inside = false;
750
833
  for (let i = 0, j = poly.length - 1; i < poly.length; j = i++) {
@@ -790,18 +873,12 @@ defineNode({
790
873
  if (!g.numPrims)
791
874
  throw new NodeError('extrude needs closed shapes (polygons) as input');
792
875
  const plane = p.plane === 'auto' ? detectPlane(g) : p.plane;
793
- const { polys, offset } = toPolygons(g, plane);
794
- // holes or tapering to a point → use manifold's robust extrude
795
- let nested = false;
796
- for (let i = 0; i < polys.length && !nested; i++)
797
- for (let j = 0; j < polys.length; j++)
798
- if (i !== j && pointInPoly(polys[i][0], polys[j])) {
799
- nested = true;
800
- break;
801
- }
876
+ const { polys: raw, offset } = toPolygons(g, plane);
877
+ const F = FRAMES[plane];
802
878
  const pyramid = p.scale_top[0] === 0 && p.scale_top[1] === 0;
803
- if (nested || pyramid) {
804
- const cs = crossSection(polys, 'EvenOdd');
879
+ if (pyramid) {
880
+ // tapering to a point: manifold's extrude makes the apex; groups by face direction
881
+ const cs = crossSection(raw, 'EvenOdd');
805
882
  let m = cs.extrude(Math.abs(p.height), p.divisions - 1, p.twist, p.scale_top, p.center);
806
883
  cs.delete();
807
884
  if (p.height < 0) {
@@ -811,35 +888,107 @@ defineNode({
811
888
  }
812
889
  const mt = m.transform(planeMatrix(plane, offset));
813
890
  m.delete();
814
- const out = fromManifold(mt, propLayout([])).geo;
891
+ const tri = fromManifold(mt, propLayout([])).geo;
815
892
  mt.delete();
893
+ const nrm = primNormals(tri), down = Math.sign(p.height || 1);
894
+ const bottom = Uint8Array.from({ length: tri.numPrims }, (_, t) => ((nrm[t * 3] * F.N[0] + nrm[t * 3 + 1] * F.N[1] + nrm[t * 3 + 2] * F.N[2]) * down < -0.9999 ? 1 : 0));
895
+ const out = mergeTriangles(tri, Float64Array.from(bottom));
896
+ const bm = new Uint8Array(out.numPrims), on = primNormals(out);
897
+ for (let t = 0; t < out.numPrims; t++)
898
+ bm[t] = (on[t * 3] * F.N[0] + on[t * 3 + 1] * F.N[1] + on[t * 3 + 2] * F.N[2]) * down < -0.9999 ? 1 : 0;
899
+ out.addGroup('prim', 'bottom', bm);
900
+ out.addGroup('prim', 'top', new Uint8Array(out.numPrims));
901
+ out.addGroup('prim', 'side', bm.map((x) => 1 - x));
816
902
  return out;
817
903
  }
818
- const F = FRAMES[plane];
904
+ // shapes inside shapes are holes (and shapes inside holes islands): outlines counter-clockwise, holes clockwise
905
+ const { polys, depth, parent } = orientNested(raw);
906
+ const root = polys.map((_, i) => { let r = i; while (parent[r] >= 0)
907
+ r = parent[r]; return r; });
908
+ const centre = polys.map((poly) => [poly.reduce((s, q) => s + q[0], 0) / poly.length, poly.reduce((s, q) => s + q[1], 0) / poly.length]);
819
909
  const b = new GeoBuilder();
820
910
  const top = b.group('prim', 'top'), bottom = b.group('prim', 'bottom'), side = b.group('prim', 'side');
821
911
  const h0 = p.center ? -p.height / 2 : 0;
822
- for (const poly0 of polys) {
823
- const poly = area2(poly0) < 0 ? poly0.slice().reverse() : poly0;
824
- const cx = poly.reduce((s, q) => s + q[0], 0) / poly.length, cy = poly.reduce((s, q) => s + q[1], 0) / poly.length;
825
- const rings = [];
912
+ const rings = polys.map((poly, i) => {
913
+ // twist and taper about the outermost outline's centre, so holes stay where they are in their shape
914
+ const [cx, cy] = centre[root[i]];
915
+ const out = [];
826
916
  for (let k = 0; k <= p.divisions; k++) {
827
917
  const t = k / p.divisions, w = offset + h0 + p.height * t;
828
- const a = ((p.twist * t) * Math.PI) / 180, c = Math.cos(a), s = Math.sin(a);
918
+ const a = ((p.twist * t) * Math.PI) / 180, c = Math.cos(a), sn = Math.sin(a);
829
919
  const sx = 1 + (p.scale_top[0] - 1) * t, sy = 1 + (p.scale_top[1] - 1) * t;
830
- rings.push(poly.map(([u, v]) => {
920
+ out.push(poly.map(([u, v]) => {
831
921
  const du = (u - cx) * sx, dv = (v - cy) * sy;
832
- const uu = cx + du * c - dv * s, vv = cy + du * s + dv * c;
922
+ const uu = cx + du * c - dv * sn, vv = cy + du * sn + dv * c;
833
923
  return b.addPoint(F.U[0] * uu + F.V[0] * vv + F.N[0] * w, F.U[1] * uu + F.V[1] * vv + F.N[1] * w, F.U[2] * uu + F.V[2] * vv + F.N[2] * w);
834
924
  }));
835
925
  }
836
- const m = poly.length;
926
+ return out;
927
+ });
928
+ polys.forEach((poly, i) => {
929
+ const m = poly.length, r = rings[i];
837
930
  for (let k = 0; k < p.divisions; k++)
838
931
  for (let j = 0; j < m; j++)
839
- side.add(b.addPrim([rings[k][j], rings[k][(j + 1) % m], rings[k + 1][(j + 1) % m], rings[k + 1][j]]));
840
- if (p.caps) {
841
- bottom.add(b.addPrim(rings[0].slice().reverse()));
842
- top.add(b.addPrim(rings[p.divisions].slice()));
932
+ side.add(b.addPrim([r[k][j], r[k][(j + 1) % m], r[k + 1][(j + 1) % m], r[k + 1][j]]));
933
+ });
934
+ if (p.caps) {
935
+ // each outline with its own holes is one cap, triangulated on the ring points (so it stays watertight) and
936
+ // merged back into as few polygons as a cap with holes needs
937
+ const capTris = [], capOf = [];
938
+ polys.forEach((poly, i) => {
939
+ if (depth[i] % 2)
940
+ return;
941
+ const holes = polys.map((_, j) => j).filter((j) => parent[j] === i);
942
+ if (!holes.length) {
943
+ bottom.add(b.addPrim(rings[i][0].slice().reverse()));
944
+ top.add(b.addPrim(rings[i][p.divisions].slice()));
945
+ return;
946
+ }
947
+ const flat = [], holeAt = [], ids = [];
948
+ for (const j of [i, ...holes]) {
949
+ if (j !== i)
950
+ holeAt.push(flat.length / 2);
951
+ polys[j].forEach((q, k) => { flat.push(q[0], q[1]); ids.push(k); });
952
+ }
953
+ const owner = [i, ...holes].flatMap((j) => polys[j].map(() => j));
954
+ const tri = earcut(flat, holeAt.length ? holeAt : undefined);
955
+ for (let t = 0; t < tri.length; t += 3) {
956
+ capTris.push([tri[t], tri[t + 1], tri[t + 2]].map((x) => owner[x] * 1e9 + ids[x]));
957
+ capOf.push(i);
958
+ }
959
+ });
960
+ const capGeo = (level, flip) => {
961
+ const cb = new GeoBuilder();
962
+ const map = new Map();
963
+ const pt = (code) => {
964
+ let id = map.get(code);
965
+ if (id === undefined) {
966
+ const j = Math.floor(code / 1e9), k = code - j * 1e9, src = rings[j][level][k];
967
+ id = cb.addPoint(b.pos[src * 3], b.pos[src * 3 + 1], b.pos[src * 3 + 2]);
968
+ map.set(code, id);
969
+ }
970
+ return id;
971
+ };
972
+ // earcut's triangles run one way round in plane coordinates: counter-clockwise faces +N
973
+ for (const t of capTris) {
974
+ const [x, y, z] = t.map(pt);
975
+ const ccw = signed2(t.map((c) => { const j = Math.floor(c / 1e9); return polys[j][c - j * 1e9]; })) > 0;
976
+ cb.addPrim(ccw !== flip ? [x, y, z] : [x, z, y]);
977
+ }
978
+ const tg = cb.build();
979
+ const merged = mergeTriangles(tg, Float64Array.from(capOf));
980
+ // back to the ring points
981
+ const back = new Map();
982
+ for (const [code, id] of map) {
983
+ const j = Math.floor(code / 1e9);
984
+ back.set(id, rings[j][level][code - j * 1e9]);
985
+ }
986
+ return { merged, back };
987
+ };
988
+ for (const [level, grp, flip] of [[0, bottom, true], [p.divisions, top, false]]) {
989
+ const { merged, back } = capGeo(level, flip);
990
+ for (let pr = 0; pr < merged.numPrims; pr++)
991
+ grp.add(b.addPrim(merged.primPoints(pr).map((i) => back.get(i))));
843
992
  }
844
993
  }
845
994
  let out = b.build();
@@ -848,17 +997,23 @@ defineNode({
848
997
  return out;
849
998
  },
850
999
  });
1000
+ /** Twice the signed area of a 2D triangle (> 0 counter-clockwise). */
1001
+ function signed2(t) {
1002
+ return (t[1][0] - t[0][0]) * (t[2][1] - t[0][1]) - (t[2][0] - t[0][0]) * (t[1][1] - t[0][1]);
1003
+ }
851
1004
  const NO_SHAPES = 'no closed shapes in the input (polygons, or polylines whose ends meet, with 3+ points): output is empty';
852
1005
  defineNode({
853
1006
  type: 'offset_curve',
854
1007
  category: 'curve',
855
- summary: '2D offset (grow/shrink) of closed shapes, like PolyExpand2D. Negative distance = inset.',
856
- aliases: ['polyexpand2d', 'offset2d', 'inset2d'],
857
- inputs: [{ name: 'shapes', desc: 'closed polygons in a plane' }],
1008
+ summary: '2D offset (grow/shrink) of closed shapes, like PolyExpand2D. Negative distance = inset. Open paths become straps.',
1009
+ description: 'Closed shapes grow by distance (shrink when negative). An open path (a polyline whose ends do not meet) becomes a strap: a closed outline at |distance| on both sides, with its ends cut square at the end points (cap butt), rounded, or extended by the distance; extrude it for a 3D strap or band. Shapes and straps in one input are joined.',
1010
+ aliases: ['polyexpand2d', 'offset2d', 'inset2d', 'strap', 'stroke'],
1011
+ inputs: [{ name: 'shapes', desc: 'closed polygons in a plane, or open paths for straps' }],
858
1012
  params: {
859
- distance: { type: 'float', default: 0.1, desc: 'offset distance (negative shrinks)', aliases: ['offset', 'dist'] },
1013
+ distance: { type: 'float', default: 0.1, desc: 'offset distance (negative shrinks); straps: half their width', aliases: ['offset', 'dist'] },
860
1014
  join: { type: 'enum', options: ['round', 'miter', 'square'], default: 'round', desc: 'corner style' },
861
- segments: { type: 'int', default: 16, min: 3, max: 10000, desc: 'segments per full circle for round joins' },
1015
+ cap: { type: 'enum', options: ['butt', 'round', 'square'], default: 'butt', desc: 'strap ends: butt = cut square at the end point, round = half circle, square = extended by the distance' },
1016
+ segments: { type: 'int', default: 16, min: 3, max: 10000, desc: 'segments per full circle for round joins and caps' },
862
1017
  output: { type: 'enum', options: ['outlines', 'faces'], default: 'outlines', desc: 'outlines = closed polygons per contour; faces = filled with holes cut' },
863
1018
  plane: { type: 'enum', options: ['auto', 'xz', 'xy', 'yz'], default: 'auto', desc: 'shape plane' },
864
1019
  },
@@ -872,27 +1027,126 @@ defineNode({
872
1027
  cook: ({ input, p, warn }) => {
873
1028
  const g = input(0);
874
1029
  const plane = p.plane === 'auto' ? detectPlane(g) : p.plane;
875
- const { polys, offset } = toPolygons(g, plane);
876
- if (!polys.length && g.numPoints)
877
- warn(NO_SHAPES);
878
- const cs = crossSection(polys, 'EvenOdd');
1030
+ // open paths (ends apart) are straps; the rest are shapes
1031
+ const isOpen = (pr) => {
1032
+ if (g.primClosed[pr])
1033
+ return false;
1034
+ const ids = g.primPoints(pr);
1035
+ if (ids.length < 2)
1036
+ return false;
1037
+ const a = ids[0] * 3, b = ids[ids.length - 1] * 3;
1038
+ return Math.hypot(g.P[a] - g.P[b], g.P[a + 1] - g.P[b + 1], g.P[a + 2] - g.P[b + 2]) > 1e-9;
1039
+ };
1040
+ const open = Uint8Array.from({ length: g.numPrims }, (_, pr) => (isOpen(pr) ? 1 : 0));
1041
+ const anyOpen = open.some((x) => x);
1042
+ const shapes = anyOpen ? g.subsetPrims(open.map((x) => 1 - x), false) : g;
1043
+ const { polys, offset } = toPolygons(shapes, plane);
879
1044
  const jt = p.join === 'round' ? 'Round' : p.join === 'miter' ? 'Miter' : 'Square';
880
- const o = cs.offset(p.distance, jt, 2, p.segments);
1045
+ const cs = crossSection(polys, 'EvenOdd');
1046
+ let o = cs.offset(p.distance, jt, 2, p.segments);
881
1047
  cs.delete();
882
- const out = p.output === 'faces' ? crossSectionFaces(o, plane, offset) : polygonsToGeo(o.toPolygons(), plane, offset);
1048
+ let nStraps = 0, planeOffset = offset;
1049
+ if (anyOpen) {
1050
+ const lines = g.subsetPrims(open, false);
1051
+ const w = Math.abs(p.distance);
1052
+ if (!polys.length)
1053
+ planeOffset = toPolygons(lines, plane).offset;
1054
+ if (w > 0)
1055
+ for (const path of toPaths(lines, plane)) {
1056
+ const st = strap(path, w, p.join, p.cap, p.segments);
1057
+ const u = o.add(st);
1058
+ o.delete();
1059
+ st.delete();
1060
+ o = u;
1061
+ nStraps++;
1062
+ }
1063
+ else
1064
+ warn('distance is 0: open paths give no strap');
1065
+ }
1066
+ if (!polys.length && !nStraps && g.numPoints)
1067
+ warn(NO_SHAPES);
1068
+ const out = p.output === 'faces' ? crossSectionFaces(o, plane, planeOffset) : polygonsToGeo(o.toPolygons(), plane, planeOffset);
883
1069
  o.delete();
884
1070
  return out;
885
1071
  },
886
1072
  });
1073
+ /** Open polylines as 2D point lists in the plane frame. */
1074
+ function toPaths(g, plane) {
1075
+ const F = FRAMES[plane], P = g.P, out = [];
1076
+ for (let pr = 0; pr < g.numPrims; pr++) {
1077
+ const path = [];
1078
+ for (const i of g.primPoints(pr)) {
1079
+ const x = P[i * 3], y = P[i * 3 + 1], z = P[i * 3 + 2];
1080
+ const q = [x * F.U[0] + y * F.U[1] + z * F.U[2], x * F.V[0] + y * F.V[1] + z * F.V[2]];
1081
+ const last = path[path.length - 1];
1082
+ if (!last || Math.hypot(q[0] - last[0], q[1] - last[1]) > 1e-12)
1083
+ path.push(q);
1084
+ }
1085
+ if (path.length >= 2)
1086
+ out.push(path);
1087
+ }
1088
+ return out;
1089
+ }
1090
+ /**
1091
+ * The outline of a strap of half-width w along an open 2D path, as a CrossSection: a rectangle per segment joined at
1092
+ * the corners (round: a disc; miter: the wedge to the mitre point, cut back to a bevel when it would reach past 2·w;
1093
+ * square: the wedge cut flat) and capped at the ends.
1094
+ */
1095
+ function strap(path, w, join, cap, segments) {
1096
+ const n = path.length;
1097
+ const dir = (i) => { const a = path[i], b = path[i + 1], l = Math.hypot(b[0] - a[0], b[1] - a[1]); return [(b[0] - a[0]) / l, (b[1] - a[1]) / l]; };
1098
+ const parts = [];
1099
+ const disc = (c) => Array.from({ length: segments }, (_, k) => { const a = (2 * Math.PI * k) / segments; return [c[0] + w * Math.cos(a), c[1] + w * Math.sin(a)]; });
1100
+ for (let i = 0; i < n - 1; i++) {
1101
+ const [dx, dy] = dir(i), nx = -dy * w, ny = dx * w;
1102
+ let a = path[i], b = path[i + 1];
1103
+ if (cap === 'square' && i === 0)
1104
+ a = [a[0] - dx * w, a[1] - dy * w];
1105
+ if (cap === 'square' && i === n - 2)
1106
+ b = [b[0] + dx * w, b[1] + dy * w];
1107
+ parts.push([[a[0] + nx, a[1] + ny], [a[0] - nx, a[1] - ny], [b[0] - nx, b[1] - ny], [b[0] + nx, b[1] + ny]]);
1108
+ }
1109
+ for (let i = 1; i < n - 1; i++) {
1110
+ const c = path[i], d0 = dir(i - 1), d1 = dir(i);
1111
+ const turn = d0[0] * d1[1] - d0[1] * d1[0];
1112
+ if (Math.abs(turn) < 1e-12 && d0[0] * d1[0] + d0[1] * d1[1] > 0)
1113
+ continue;
1114
+ if (join === 'round') {
1115
+ parts.push(disc(c));
1116
+ continue;
1117
+ }
1118
+ // the outer side of the corner: the gap between the two rectangles
1119
+ const s = turn > 0 ? -1 : 1;
1120
+ const o0 = [c[0] - d0[1] * w * s, c[1] + d0[0] * w * s], o1 = [c[0] - d1[1] * w * s, c[1] + d1[0] * w * s];
1121
+ const bis = [o0[0] + o1[0] - 2 * c[0], o0[1] + o1[1] - 2 * c[1]], bl = Math.hypot(bis[0], bis[1]);
1122
+ const cosHalf = bl / (2 * w);
1123
+ const miter = cosHalf > 1e-9 ? w / cosHalf : Infinity;
1124
+ if (join === 'miter' && miter <= 2 * w)
1125
+ parts.push([c, o0, [c[0] + (bis[0] / bl) * miter, c[1] + (bis[1] / bl) * miter], o1]);
1126
+ else
1127
+ parts.push([c, o0, o1]);
1128
+ }
1129
+ if (cap === 'round') {
1130
+ parts.push(disc(path[0]));
1131
+ parts.push(disc(path[n - 1]));
1132
+ }
1133
+ // every part counter-clockwise, then one union
1134
+ const ccw = parts.map((q) => { let a = 0; for (let i = 0; i < q.length; i++) {
1135
+ const u = q[i], v = q[(i + 1) % q.length];
1136
+ a += u[0] * v[1] - v[0] * u[1];
1137
+ } return a < 0 ? q.slice().reverse() : q; });
1138
+ return crossSection(ccw, 'Positive');
1139
+ }
887
1140
  defineNode({
888
1141
  type: 'boolean2d',
889
1142
  category: 'curve',
890
1143
  summary: '2D boolean of closed shapes in a plane (union / subtract / intersect / xor).',
1144
+ description: 'Within each input, a shape lying wholly inside another is a hole in it (a merged plate and circle make a plate with a hole), a shape inside that hole an island, and shapes that only overlap are joined. Faces with holes come out as a few polygons that share edges.',
891
1145
  aliases: ['curve_boolean', 'shape_boolean'],
892
1146
  inputs: [{ name: 'a', desc: 'shapes A' }, { name: 'b', desc: 'shapes B (optional: union of A with itself)', optional: true }],
893
1147
  params: {
894
1148
  operation: { type: 'enum', options: ['union', 'subtract', 'intersect', 'xor'], default: 'union', desc: 'boolean op', aliases: ['op', 'mode'] },
895
- output: { type: 'enum', options: ['outlines', 'faces'], default: 'faces', desc: 'faces = filled (holes cut, triangulated where needed); outlines = closed contour polygons' },
1149
+ output: { type: 'enum', options: ['outlines', 'faces'], default: 'faces', desc: 'faces = filled, holes cut (a face with holes as a few polygons sharing edges); outlines = closed contour polygons' },
896
1150
  plane: { type: 'enum', options: ['auto', 'xz', 'xy', 'yz'], default: 'auto', desc: 'shape plane' },
897
1151
  },
898
1152
  example: {
@@ -910,12 +1164,13 @@ defineNode({
910
1164
  if (!ta.polys.length && !tb?.polys.length && (A.numPoints || B?.numPoints))
911
1165
  warn(NO_SHAPES);
912
1166
  const offset = ta.polys.length || !tb ? ta.offset : tb.offset;
913
- const csA = crossSection(ta.polys, 'NonZero');
1167
+ // within each input a shape inside another is a hole, shapes that overlap union (orientNested)
1168
+ const csA = crossSection(orientNested(ta.polys).polys, 'NonZero');
914
1169
  let r;
915
1170
  if (!tb)
916
1171
  r = csA;
917
1172
  else {
918
- const csB = crossSection(tb.polys, 'NonZero');
1173
+ const csB = crossSection(orientNested(tb.polys).polys, 'NonZero');
919
1174
  r = p.operation === 'union' ? csA.add(csB) : p.operation === 'subtract' ? csA.subtract(csB) : p.operation === 'intersect' ? csA.intersect(csB) : csA.add(csB).subtract(csA.intersect(csB));
920
1175
  csB.delete();
921
1176
  }
@@ -952,14 +1207,17 @@ defineNode({
952
1207
  defineNode({
953
1208
  type: 'loft',
954
1209
  category: 'curve',
955
- summary: 'Skin a surface through a sequence of curves (in prim order). Curves are resampled to equal counts.',
1210
+ summary: 'Skin a surface through a sequence of curves (in prim order), or through copies of one profile placed by "sections".',
1211
+ description: 'Sections: with several input curves, each is a section in prim order. With one curve and the sections list, each entry places a copy of it: {"offset": [x, y, z], "scale": [sx, sy], "rotate": [rx, ry, rz]} (any key may be left out; a number for offset moves it along the curve\'s normal, a number for scale scales it evenly), applied as scale and rotate about the curve\'s centre, then the offset. Correspondence: when every section has the same number of points, point k of one section joins point k of the next (insets and rounded corners stay where they are); otherwise each section is resampled evenly by length (resample "length"). Closed sections are turned to run the same way round as the first one, and each starts at the point nearest the previous section\'s start, so the skin does not twist. Winding: the side faces follow the first section\'s direction; a closed result (closed sections with caps, or closed: true) is turned to face outward, caps included. uv: u along the section, v across the sections.',
956
1212
  aliases: ['skin'],
957
- inputs: [{ name: 'curves', desc: 'two or more curves, in order' }],
1213
+ inputs: [{ name: 'curves', desc: 'two or more curves, in order; or one profile with sections' }],
958
1214
  params: {
1215
+ sections: { type: 'json', default: [], desc: 'one input curve: a list of placements, each {offset, scale, rotate} (see the description)', aliases: ['stations', 'placements'] },
1216
+ resample: { type: 'enum', options: ['auto', 'length', 'none'], default: 'auto', desc: 'auto = keep the points when every section has the same count, else even by length; length = always resample evenly; none = points by index (counts must match)' },
959
1217
  closed: { type: 'bool', default: false, desc: 'connect the last curve back to the first' },
960
1218
  caps: { type: 'bool', default: false, desc: 'cap the first and last curves (when they are closed)' },
961
1219
  },
962
- outputs: 'vertex uv',
1220
+ outputs: 'vertex uv; prim groups caps, sides',
963
1221
  example: {
964
1222
  nodes: {
965
1223
  a: { type: 'circle', params: { radius: 1, segments: 32 } },
@@ -971,41 +1229,63 @@ defineNode({
971
1229
  output: 'skin',
972
1230
  },
973
1231
  cook: ({ input, p }) => {
974
- const g = input(0);
975
- if (g.numPrims < 2)
976
- throw new NodeError('loft needs at least 2 curves');
977
- const curves = Array.from({ length: g.numPrims }, (_, pr) => ({ pts: curvePoints(g, pr), closed: !!g.primClosed[pr] }));
978
- const n = Math.max(...curves.map((c) => c.pts.length));
1232
+ const g = evaluateSplines(input(0));
1233
+ let curves = Array.from({ length: g.numPrims }, (_, pr) => ({ pts: curvePoints(g, pr), closed: !!g.primClosed[pr] }))
1234
+ .filter((c) => c.pts.length >= 2);
1235
+ if (Array.isArray(p.sections) && p.sections.length) {
1236
+ if (curves.length !== 1)
1237
+ throw new NodeError(`sections places copies of one profile, but the input has ${curves.length} curves`, 'merge nothing into the profile, or leave sections empty to loft through the input curves');
1238
+ curves = p.sections.map((sec, i) => placeSection(curves[0], sec, i));
1239
+ }
1240
+ if (curves.length < 2)
1241
+ throw new NodeError('loft needs at least 2 curves', 'merge two or more curves in order, or give one profile and a sections list');
1242
+ // every open polyline whose ends meet is a loop
1243
+ for (const c of curves)
1244
+ if (!c.closed && c.pts.length > 3 && dist3(c.pts[0], c.pts[c.pts.length - 1]) < 1e-9) {
1245
+ c.pts.pop();
1246
+ c.closed = true;
1247
+ }
979
1248
  const closedU = curves[0].closed;
980
- const sampled = curves.map((c) => {
981
- const pts = c.closed ? [...c.pts, c.pts[0]] : c.pts;
982
- const L = arcLengths(pts, false), T = L[L.length - 1] || 1;
983
- const cnt = closedU ? n : n;
984
- const out = [];
985
- for (let i = 0; i < cnt; i++) {
986
- const s = (T * i) / (closedU ? cnt : cnt - 1);
987
- let k = 0;
988
- while (k < L.length - 2 && L[k + 1] < s)
989
- k++;
990
- const f = L[k + 1] > L[k] ? (s - L[k]) / (L[k + 1] - L[k]) : 0;
991
- out.push(pts[k].map((v, ci) => v + (pts[k + 1][ci] - v) * f));
1249
+ if (curves.some((c) => c.closed !== closedU))
1250
+ throw new NodeError('loft sections must be all closed or all open', 'close them with ends {mode: close}, or open them');
1251
+ const same = curves.every((c) => c.pts.length === curves[0].pts.length);
1252
+ if (p.resample === 'none' && !same)
1253
+ throw new NodeError(`resample "none" needs every section with the same number of points (${curves.map((c) => c.pts.length).join(', ')})`, 'use resample "auto" or "length"');
1254
+ const n = Math.max(...curves.map((c) => c.pts.length));
1255
+ let rows = p.resample === 'length' || !same
1256
+ ? curves.map((c) => evenByLength(c.pts, c.closed, n))
1257
+ : curves.map((c) => c.pts.map((q) => q.slice()));
1258
+ if (closedU) {
1259
+ // same way round as the first section, each starting where the previous one starts
1260
+ const n0 = loopNormal(rows[0]);
1261
+ for (let r = 1; r < rows.length; r++) {
1262
+ if (dot(loopNormal(rows[r]), n0) < 0)
1263
+ rows[r] = [rows[r][0], ...rows[r].slice(1).reverse()];
1264
+ const prev = rows[r - 1][0];
1265
+ let best = 0, bd = Infinity;
1266
+ rows[r].forEach((q, k) => { const d = dist3(q, prev); if (d < bd) {
1267
+ bd = d;
1268
+ best = k;
1269
+ } });
1270
+ if (best)
1271
+ rows[r] = [...rows[r].slice(best), ...rows[r].slice(0, best)];
992
1272
  }
993
- return out;
994
- });
1273
+ }
995
1274
  const b = new GeoBuilder();
996
1275
  const uv = b.attrib('vertex', 'uv', 3);
997
- const ids = sampled.map((row) => row.map((q) => b.addPoint(q[0], q[1], q[2])));
998
- const nr = ids.length, rows = p.closed ? nr : nr - 1, cols = closedU ? n : n - 1;
999
- for (let r = 0; r < rows; r++)
1276
+ const sides = b.group('prim', 'sides'), capsG = b.group('prim', 'caps');
1277
+ const ids = rows.map((row) => row.map((q) => b.addPoint(q[0], q[1], q[2])));
1278
+ const nr = ids.length, m = rows[0].length, nRows = p.closed ? nr : nr - 1, cols = closedU ? m : m - 1;
1279
+ for (let r = 0; r < nRows; r++)
1000
1280
  for (let c = 0; c < cols; c++) {
1001
- const r1 = (r + 1) % nr, c1 = (c + 1) % n;
1281
+ const r1 = (r + 1) % nr, c1 = (c + 1) % m;
1002
1282
  const vb = b.numVertices;
1003
- b.addPrim([ids[r][c], ids[r][c1], ids[r1][c1], ids[r1][c]]);
1004
- [[c / cols, r / rows], [(c + 1) / cols, r / rows], [(c + 1) / cols, (r + 1) / rows], [c / cols, (r + 1) / rows]].forEach(([a, d], k) => uv.set(vb + k, [a, d, 0]));
1283
+ sides.add(b.addPrim([ids[r][c], ids[r][c1], ids[r1][c1], ids[r1][c]]));
1284
+ [[c / cols, r / nRows], [(c + 1) / cols, r / nRows], [(c + 1) / cols, (r + 1) / nRows], [c / cols, (r + 1) / nRows]].forEach(([a, d], k) => uv.set(vb + k, [a, d, 0]));
1005
1285
  }
1006
1286
  if (p.caps && closedU && !p.closed) {
1007
- b.addPrim(ids[0].slice().reverse());
1008
- b.addPrim(ids[nr - 1].slice());
1287
+ capsG.add(b.addPrim(ids[0].slice().reverse()));
1288
+ capsG.add(b.addPrim(ids[nr - 1].slice()));
1009
1289
  }
1010
1290
  let out = b.build();
1011
1291
  if (topologyReport(out).closed)
@@ -1013,3 +1293,63 @@ defineNode({
1013
1293
  return out;
1014
1294
  },
1015
1295
  });
1296
+ function dist3(a, b) { return Math.hypot(a[0] - b[0], a[1] - b[1], a[2] - b[2]); }
1297
+ /** Newell normal of a closed loop of points. */
1298
+ function loopNormal(pts) {
1299
+ const n = [0, 0, 0];
1300
+ for (let i = 0; i < pts.length; i++) {
1301
+ const a = pts[i], c = pts[(i + 1) % pts.length];
1302
+ n[0] += (a[1] - c[1]) * (a[2] + c[2]);
1303
+ n[1] += (a[2] - c[2]) * (a[0] + c[0]);
1304
+ n[2] += (a[0] - c[0]) * (a[1] + c[1]);
1305
+ }
1306
+ return n;
1307
+ }
1308
+ /** n points spread evenly by length along a curve (a closed one starts and ends at its first point). */
1309
+ function evenByLength(pts0, closed, n) {
1310
+ const pts = closed ? [...pts0, pts0[0]] : pts0;
1311
+ const L = arcLengths(pts, false), T = L[L.length - 1] || 1;
1312
+ const out = [];
1313
+ for (let i = 0; i < n; i++) {
1314
+ const s = (T * i) / (closed ? n : n - 1);
1315
+ let k = 0;
1316
+ while (k < L.length - 2 && L[k + 1] < s)
1317
+ k++;
1318
+ const f = L[k + 1] > L[k] ? (s - L[k]) / (L[k + 1] - L[k]) : 0;
1319
+ out.push(pts[k].map((v, ci) => v + (pts[k + 1][ci] - v) * f));
1320
+ }
1321
+ return out;
1322
+ }
1323
+ /** A copy of the profile placed by one sections entry: scale and rotate about its centre, then offset. */
1324
+ function placeSection(prof, sec, i) {
1325
+ if (!sec || typeof sec !== 'object' || Array.isArray(sec))
1326
+ throw new NodeError(`sections[${i}] must be an object like {"offset": [0, 0.1, 0], "scale": [0.8, 0.8]}`);
1327
+ const vec = (v, k, def) => {
1328
+ if (v === undefined)
1329
+ return def;
1330
+ const a = typeof v === 'number' ? null : v;
1331
+ if (a && !(Array.isArray(a) && a.every((x) => typeof x === 'number' && Number.isFinite(x))))
1332
+ throw new NodeError(`sections[${i}].${k} must be a number or a list of numbers`);
1333
+ return a ?? v;
1334
+ };
1335
+ const c = prof.pts.reduce((s, q) => [s[0] + q[0], s[1] + q[1], s[2] + q[2]], [0, 0, 0]).map((x) => x / prof.pts.length);
1336
+ const N = normalize(loopNormal(prof.pts));
1337
+ const nrm = length(N) > 0 ? N : [0, 1, 0];
1338
+ const off = vec(sec.offset, 'offset', [0, 0, 0]);
1339
+ const offset = typeof off === 'number' ? [nrm[0] * off, nrm[1] * off, nrm[2] * off] : [off[0] ?? 0, off[1] ?? 0, off[2] ?? 0];
1340
+ const sc = vec(sec.scale, 'scale', [1, 1]);
1341
+ // scale in the profile's own plane: along two axes perpendicular to its normal
1342
+ const ax = Math.abs(nrm[1]) < 0.9 ? [0, 1, 0] : [1, 0, 0];
1343
+ const U = normalize(cross(ax, nrm)), V = cross(nrm, U);
1344
+ const sx = typeof sc === 'number' ? sc : sc[0] ?? 1, sy = typeof sc === 'number' ? sc : sc[1] ?? sx;
1345
+ const rot = vec(sec.rotate, 'rotate', [0, 0, 0]);
1346
+ const R = m4euler(typeof rot === 'number' ? [0, rot, 0] : [rot[0] ?? 0, rot[1] ?? 0, rot[2] ?? 0]);
1347
+ const pts = prof.pts.map((q) => {
1348
+ const d = [q[0] - c[0], q[1] - c[1], q[2] - c[2]];
1349
+ const u = dot(d, U) * sx, v = dot(d, V) * sy, w = dot(d, nrm);
1350
+ const e = [U[0] * u + V[0] * v + nrm[0] * w, U[1] * u + V[1] * v + nrm[1] * w, U[2] * u + V[2] * v + nrm[2] * w];
1351
+ const r = m4applyDir(R, e[0], e[1], e[2]);
1352
+ return [c[0] + r[0] + offset[0], c[1] + r[1] + offset[1], c[2] + r[2] + offset[2]];
1353
+ });
1354
+ return { pts, closed: prof.closed };
1355
+ }