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
@@ -1,5 +1,12 @@
1
1
  import { Geometry } from '../core/geometry.ts';
2
2
  import { primCentroid, primNewell, topologyReport } from '../core/topology.ts';
3
+ /**
4
+ * Faces below minArea go without opening the surface: a tiny face (all its points within 2·√minArea) is collapsed
5
+ * into one point, so its neighbours meet (an edge collapse); a long thin sliver triangle hands its middle point to the
6
+ * face across its long side (mesh_repair's degenerate step). Only a sliver polygon of 4+ points with no such
7
+ * neighbour is simply removed.
8
+ */
9
+ export declare function removeSmallFaces(g: Geometry, minArea: number): Geometry;
3
10
  /** One level of Catmull–Clark (or linear) subdivision with full attribute interpolation. */
4
11
  export declare function subdivideOnce(g: Geometry, smooth: boolean, boundaryMode: 'smooth' | 'sharp'): Geometry;
5
12
  /**
@@ -2,12 +2,14 @@
2
2
  import { AttribTable, Attribute, GeoBuilder, Geometry, cloneVolumes } from '../core/geometry.js';
3
3
  import { defineNode } from '../graph/registry.js';
4
4
  import { NodeError } from '../graph/types.js';
5
- import { boundaryLoops, buildEdges, connectivity, orientOutward, refreshNormals, primArea, primCentroid, primNewell, primNormals, reversePrims, topologyReport, triangulate, } from '../core/topology.js';
5
+ import { boundaryLoops, buildEdges, connectivity, orientOutward, refreshNormals, primArea, primCentroid, primNewell, primNormals, reversePrims, signedVolume, topologyReport, triangulate, } from '../core/topology.js';
6
+ import { TriBVH } from '../core/spatial.js';
6
7
  import { M, fromManifold, propLayout } from '../core/manifold.js';
7
8
  import { EdgeSet, edgeFromKey, edgeKey, forEachPrimEdge } from '../core/edges.js';
8
9
  import { P, edgeMask, mask } from './util.js';
9
10
  import { fusePoints, removeDegenerate } from './transform.js';
10
11
  import { makeBox } from './generate.js';
12
+ import { repairMesh } from '../core/repair.js';
11
13
  defineNode({
12
14
  type: 'fuse',
13
15
  category: 'topology',
@@ -36,7 +38,7 @@ defineNode({
36
38
  params: {
37
39
  fuse_distance: { type: 'float', default: 0, min: 0, desc: 'weld points within this distance first (0 = off)' },
38
40
  remove_degenerate: { type: 'bool', default: true, desc: 'remove prims with repeated/too few points' },
39
- min_area: { type: 'float', default: 1e-12, min: 0, desc: 'remove polygons with smaller area (0 = keep)' },
41
+ min_area: { type: 'float', default: 1e-12, min: 0, desc: 'remove polygons with smaller area (0 = keep); a closed mesh stays closed: a tiny face collapses into a point, a thin sliver hands its middle point to the face across its long side' },
40
42
  remove_unused_points: { type: 'bool', default: true, desc: 'remove points not used by prims (only when the geometry has prims)' },
41
43
  fix_winding: { type: 'bool', default: false, desc: 'make closed meshes face outward' },
42
44
  },
@@ -47,10 +49,8 @@ defineNode({
47
49
  g = fusePoints(g, p.fuse_distance);
48
50
  if (p.remove_degenerate)
49
51
  g = removeDegenerate(g);
50
- if (p.min_area > 0) {
51
- const keep = Uint8Array.from({ length: g.numPrims }, (_, pr) => (!g.primClosed[pr] || primArea(g, pr) >= p.min_area ? 1 : 0));
52
- g = g.subsetPrims(keep, false);
53
- }
52
+ if (p.min_area > 0)
53
+ g = removeSmallFaces(g, p.min_area);
54
54
  if (p.remove_unused_points && g.numPrims > 0)
55
55
  g = g.removeUnusedPoints();
56
56
  if (p.fix_winding)
@@ -58,6 +58,133 @@ defineNode({
58
58
  return g === input(0) ? g.clone() : g;
59
59
  },
60
60
  });
61
+ /**
62
+ * Faces below minArea go without opening the surface: a tiny face (all its points within 2·√minArea) is collapsed
63
+ * into one point, so its neighbours meet (an edge collapse); a long thin sliver triangle hands its middle point to the
64
+ * face across its long side (mesh_repair's degenerate step). Only a sliver polygon of 4+ points with no such
65
+ * neighbour is simply removed.
66
+ */
67
+ export function removeSmallFaces(g, minArea) {
68
+ const reach = 2 * Math.sqrt(minArea), P = g.P;
69
+ const cand = new Uint8Array(g.numPoints);
70
+ let compact = 0, small = 0;
71
+ for (let pr = 0; pr < g.numPrims; pr++) {
72
+ if (!g.primClosed[pr] || primArea(g, pr) >= minArea)
73
+ continue;
74
+ small++;
75
+ const ids = g.primPoints(pr);
76
+ let far = false;
77
+ for (let a = 0; a < ids.length && !far; a++)
78
+ for (let b = a + 1; b < ids.length; b++) {
79
+ const i = ids[a] * 3, j = ids[b] * 3;
80
+ if (Math.hypot(P[i] - P[j], P[i + 1] - P[j + 1], P[i + 2] - P[j + 2]) > reach) {
81
+ far = true;
82
+ break;
83
+ }
84
+ }
85
+ if (far)
86
+ continue;
87
+ compact++;
88
+ for (const i of ids)
89
+ cand[i] = 1;
90
+ }
91
+ if (!small)
92
+ return g;
93
+ if (compact)
94
+ g = fusePoints(g, reach, (i) => !!cand[i]);
95
+ if (compact === small)
96
+ return g;
97
+ const out = repairMesh(g, {
98
+ fuse: 'off', tolerance: 0, degenerate: true, duplicates: false, nonManifold: 'keep', winding: false, outward: false,
99
+ fillHoles: false, maxHoleEdges: 0, isolated: false, selfIntersections: 'off', minArea,
100
+ }).geo;
101
+ out.primGroups.delete('filled');
102
+ return out;
103
+ }
104
+ defineNode({
105
+ type: 'remove_interior',
106
+ category: 'topology',
107
+ summary: 'Delete faces buried inside other closed parts (kitbashed pieces that overlap): they can never be seen.',
108
+ description: 'Parts are told apart by connectivity (or by the prim attribute name). A face goes when its centre and every corner, pulled a hair toward the centre, lie inside one other part that is a closed solid; a face only partly inside stays (cut it with boolean union instead). Faces touching another part face to face stay too. The parts are left open where their buried faces were: that is the point, nothing inside is rendered or baked.',
109
+ aliases: ['remove_hidden', 'remove_inside', 'hidden_faces', 'interior_faces'],
110
+ inputs: [{ name: 'geo', desc: 'overlapping parts (each closed part hides what is inside it)' }],
111
+ params: {
112
+ group: P.group('prim', 'faces that may be removed ("" = all)'),
113
+ parts: { type: 'enum', options: ['connected', 'name'], default: 'connected', desc: 'what makes a part: connected polygons, or the prim attribute name' },
114
+ output: { type: 'enum', options: ['delete', 'group'], default: 'delete', desc: 'delete the hidden faces, or keep them in prim group "interior"' },
115
+ },
116
+ outputs: 'prim group interior (output group)',
117
+ example: {
118
+ nodes: {
119
+ body: { type: 'box', params: { size: [1, 0.4, 0.4] } },
120
+ boss: { type: 'tube', params: { radius: 0.1, height: 0.3, caps: true } },
121
+ place: { type: 'transform', in: ['boss'], params: { rotate: [0, 0, 90], translate: [0.5, 0, 0] } },
122
+ parts: { type: 'merge', in: ['body', 'place'] },
123
+ tidy: { type: 'remove_interior', in: ['parts'] },
124
+ },
125
+ output: 'tidy',
126
+ },
127
+ cook: ({ input, p, warn }) => {
128
+ const g = input(0);
129
+ const sel = mask(g, 'prim', p.group);
130
+ let part, nParts;
131
+ if (p.parts === 'name') {
132
+ const na = g.prims.get('name');
133
+ if (!na || na.type !== 'string')
134
+ throw new NodeError('parts "name" needs a prim string attribute name', 'name the parts first (name node), or use parts "connected"');
135
+ const ids = new Map();
136
+ part = Int32Array.from({ length: g.numPrims }, (_, pr) => { const k = String(na.get(pr) ?? ''); let i = ids.get(k); if (i === undefined)
137
+ ids.set(k, i = ids.size); return i; });
138
+ nParts = ids.size;
139
+ }
140
+ else
141
+ ({ primClass: part, count: nParts } = connectivity(g));
142
+ // closed parts hide what is inside them
143
+ const solids = [];
144
+ for (let k = 0; k < nParts; k++) {
145
+ const sub = g.subsetPrims(Uint8Array.from(part, (c) => (c === k ? 1 : 0)), true);
146
+ if (!sub.numPrims || !topologyReport(sub).closed || !(signedVolume(sub) > 0))
147
+ continue;
148
+ const bb = sub.bbox();
149
+ solids.push({ k, bvh: new TriBVH(sub), lo: bb.min, hi: bb.max });
150
+ }
151
+ const hidden = new Uint8Array(g.numPrims);
152
+ let n = 0;
153
+ if (solids.length) {
154
+ const P = g.P;
155
+ for (let pr = 0; pr < g.numPrims; pr++) {
156
+ if (!g.primClosed[pr] || (sel && !sel[pr]))
157
+ continue;
158
+ const ids = g.primPoints(pr);
159
+ if (ids.length < 3)
160
+ continue;
161
+ const c = primCentroid(g, pr);
162
+ const pts = [c, ...ids.map((i) => [P[i * 3] + (c[0] - P[i * 3]) * 0.01, P[i * 3 + 1] + (c[1] - P[i * 3 + 1]) * 0.01, P[i * 3 + 2] + (c[2] - P[i * 3 + 2]) * 0.01])];
163
+ for (const s of solids) {
164
+ if (s.k === part[pr])
165
+ continue;
166
+ if (!pts.every((q) => q[0] >= s.lo[0] && q[0] <= s.hi[0] && q[1] >= s.lo[1] && q[1] <= s.hi[1] && q[2] >= s.lo[2] && q[2] <= s.hi[2]))
167
+ continue;
168
+ if (pts.every((q) => s.bvh.inside(q[0], q[1], q[2]))) {
169
+ hidden[pr] = 1;
170
+ n++;
171
+ break;
172
+ }
173
+ }
174
+ }
175
+ }
176
+ else if (g.numPrims)
177
+ warn('no closed part to hide anything: every part has open edges (or no volume), so nothing is inside one');
178
+ if (p.output === 'group') {
179
+ const out = g.clone();
180
+ out.addGroup('prim', 'interior', hidden);
181
+ return out;
182
+ }
183
+ if (!n)
184
+ return g.clone();
185
+ return g.subsetPrims(hidden.map((x) => 1 - x), true);
186
+ },
187
+ });
61
188
  defineNode({
62
189
  type: 'reverse',
63
190
  category: 'topology',
@@ -527,7 +527,7 @@ defineNode({
527
527
  inputs: [{ name: 'geo', desc: 'geometry to copy' }],
528
528
  params: {
529
529
  count: { type: 'int', default: 4, min: 0, max: 100000, desc: 'total copies (including the original)', aliases: ['ncy', 'copies', 'n'] },
530
- translate: { type: 'vec3', default: [1, 0, 0], desc: 'offset applied per copy', aliases: ['t', 'offset'] },
530
+ translate: { type: 'vec3', default: [0, 0, 0], desc: 'offset applied per copy, in metres (0 by default, as in Houdini: set it, or rotate, or the copies stack in place)', aliases: ['t', 'offset'] },
531
531
  rotate: { type: 'vec3', default: [0, 0, 0], desc: 'rotation per copy (degrees)', aliases: ['r'] },
532
532
  scale: { type: 'vec3', default: [1, 1, 1], desc: 'scale per copy (compounding)', aliases: ['s'] },
533
533
  pivot: { type: 'vec3', default: [0, 0, 0], desc: 'pivot for rotate/scale' },
@@ -535,8 +535,12 @@ defineNode({
535
535
  },
536
536
  outputs: 'prim copynum',
537
537
  example: { type: 'copy_xform', params: { count: 12, translate: [0, 0.2, 0], rotate: [0, 30, 0] } },
538
- cook: ({ input, p }) => {
538
+ cook: ({ input, p, warn }) => {
539
539
  const g = input(0);
540
+ const still = (v, k) => v.every((x) => x === k);
541
+ // points stacked on purpose (to jitter or scatter them next) are fine; stacked meshes are a slip
542
+ if (p.count > 1 && g.numPrims && still(p.translate, 0) && still(p.rotate, 0) && still(p.scale, 1))
543
+ warn(`the ${p.count} copies stack in place: translate, rotate and scale are all at rest (translate is 0 by default); set the step between copies`);
540
544
  const step = m4trs(p.translate, p.rotate, p.scale, p.pivot);
541
545
  let m = m4trs([0, 0, 0], [0, 0, 0], [1, 1, 1]);
542
546
  const parts = [];