@woosh/meep-engine 2.164.0 → 2.165.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 (256) hide show
  1. package/build/bundle-worker-terrain.js +1 -1
  2. package/package.json +1 -1
  3. package/src/core/binary/BitImage2.d.ts +91 -0
  4. package/src/core/binary/BitImage2.d.ts.map +1 -0
  5. package/src/core/binary/BitImage2.js +242 -0
  6. package/src/core/geom/2d/oriented-box/min_area_rect_2d.d.ts +22 -0
  7. package/src/core/geom/2d/oriented-box/min_area_rect_2d.d.ts.map +1 -0
  8. package/src/core/geom/2d/oriented-box/min_area_rect_2d.js +69 -0
  9. package/src/core/geom/2d/packing/skyline.d.ts +116 -0
  10. package/src/core/geom/2d/packing/skyline.d.ts.map +1 -0
  11. package/src/core/geom/2d/packing/skyline.js +258 -0
  12. package/src/core/geom/2d/triangle/tri2_rasterize_conservative.d.ts +18 -0
  13. package/src/core/geom/2d/triangle/tri2_rasterize_conservative.d.ts.map +1 -0
  14. package/src/core/geom/2d/triangle/tri2_rasterize_conservative.js +86 -0
  15. package/src/core/geom/3d/atlas/ATLAS_PORT_PLAN.md +486 -0
  16. package/src/core/geom/3d/atlas/BFF_PLAN.md +174 -0
  17. package/src/core/geom/3d/atlas/Chart.d.ts +58 -0
  18. package/src/core/geom/3d/atlas/Chart.d.ts.map +1 -0
  19. package/src/core/geom/3d/atlas/Chart.js +77 -0
  20. package/src/core/geom/3d/atlas/REVIEW_02.md +392 -0
  21. package/src/core/geom/3d/atlas/atlas_bench_lib.d.ts +73 -0
  22. package/src/core/geom/3d/atlas/atlas_bench_lib.d.ts.map +1 -0
  23. package/src/core/geom/3d/atlas/atlas_bench_lib.js +315 -0
  24. package/src/core/geom/3d/atlas/atlas_chart_type.d.ts +17 -0
  25. package/src/core/geom/3d/atlas/atlas_chart_type.d.ts.map +1 -0
  26. package/src/core/geom/3d/atlas/atlas_chart_type.js +16 -0
  27. package/src/core/geom/3d/atlas/atlas_compute_charts.d.ts +25 -0
  28. package/src/core/geom/3d/atlas/atlas_compute_charts.d.ts.map +1 -0
  29. package/src/core/geom/3d/atlas/atlas_compute_charts.js +188 -0
  30. package/src/core/geom/3d/atlas/atlas_extract_chart.d.ts +17 -0
  31. package/src/core/geom/3d/atlas/atlas_extract_chart.d.ts.map +1 -0
  32. package/src/core/geom/3d/atlas/atlas_extract_chart.js +107 -0
  33. package/src/core/geom/3d/atlas/atlas_generate.d.ts +39 -0
  34. package/src/core/geom/3d/atlas/atlas_generate.d.ts.map +1 -0
  35. package/src/core/geom/3d/atlas/atlas_generate.js +43 -0
  36. package/src/core/geom/3d/atlas/atlas_test_fixtures.d.ts +84 -0
  37. package/src/core/geom/3d/atlas/atlas_test_fixtures.d.ts.map +1 -0
  38. package/src/core/geom/3d/atlas/atlas_test_fixtures.js +266 -0
  39. package/src/core/geom/3d/atlas/atlas_write_chart_uvs.d.ts +25 -0
  40. package/src/core/geom/3d/atlas/atlas_write_chart_uvs.d.ts.map +1 -0
  41. package/src/core/geom/3d/atlas/atlas_write_chart_uvs.js +36 -0
  42. package/src/core/geom/3d/atlas/data/atlas_build_edge_dihedrals.d.ts +22 -0
  43. package/src/core/geom/3d/atlas/data/atlas_build_edge_dihedrals.d.ts.map +1 -0
  44. package/src/core/geom/3d/atlas/data/atlas_build_edge_dihedrals.js +62 -0
  45. package/src/core/geom/3d/atlas/data/atlas_build_edge_lengths.d.ts +9 -0
  46. package/src/core/geom/3d/atlas/data/atlas_build_edge_lengths.d.ts.map +1 -0
  47. package/src/core/geom/3d/atlas/data/atlas_build_edge_lengths.js +33 -0
  48. package/src/core/geom/3d/atlas/data/atlas_build_face_areas.d.ts +9 -0
  49. package/src/core/geom/3d/atlas/data/atlas_build_face_areas.d.ts.map +1 -0
  50. package/src/core/geom/3d/atlas/data/atlas_build_face_areas.js +50 -0
  51. package/src/core/geom/3d/atlas/io/atlas_mesh_weld_colocals.d.ts +27 -0
  52. package/src/core/geom/3d/atlas/io/atlas_mesh_weld_colocals.d.ts.map +1 -0
  53. package/src/core/geom/3d/atlas/io/atlas_mesh_weld_colocals.js +39 -0
  54. package/src/core/geom/3d/atlas/io/bt_loop_uv.d.ts +22 -0
  55. package/src/core/geom/3d/atlas/io/bt_loop_uv.d.ts.map +1 -0
  56. package/src/core/geom/3d/atlas/io/bt_loop_uv.js +57 -0
  57. package/src/core/geom/3d/atlas/pack/ChartPlacement.d.ts +36 -0
  58. package/src/core/geom/3d/atlas/pack/ChartPlacement.d.ts.map +1 -0
  59. package/src/core/geom/3d/atlas/pack/ChartPlacement.js +46 -0
  60. package/src/core/geom/3d/atlas/pack/atlas_pack_charts.d.ts +62 -0
  61. package/src/core/geom/3d/atlas/pack/atlas_pack_charts.d.ts.map +1 -0
  62. package/src/core/geom/3d/atlas/pack/atlas_pack_charts.js +551 -0
  63. package/src/core/geom/3d/atlas/param/atlas_chart_param_validity.d.ts +22 -0
  64. package/src/core/geom/3d/atlas/param/atlas_chart_param_validity.d.ts.map +1 -0
  65. package/src/core/geom/3d/atlas/param/atlas_chart_param_validity.js +73 -0
  66. package/src/core/geom/3d/atlas/param/atlas_chart_parameterize_bff.d.ts +37 -0
  67. package/src/core/geom/3d/atlas/param/atlas_chart_parameterize_bff.d.ts.map +1 -0
  68. package/src/core/geom/3d/atlas/param/atlas_chart_parameterize_bff.js +270 -0
  69. package/src/core/geom/3d/atlas/param/atlas_chart_parameterize_lscm.d.ts +23 -0
  70. package/src/core/geom/3d/atlas/param/atlas_chart_parameterize_lscm.d.ts.map +1 -0
  71. package/src/core/geom/3d/atlas/param/atlas_chart_parameterize_lscm.js +224 -0
  72. package/src/core/geom/3d/atlas/param/atlas_chart_parameterize_ortho.d.ts +14 -0
  73. package/src/core/geom/3d/atlas/param/atlas_chart_parameterize_ortho.d.ts.map +1 -0
  74. package/src/core/geom/3d/atlas/param/atlas_chart_parameterize_ortho.js +38 -0
  75. package/src/core/geom/3d/atlas/param/atlas_chart_stretch_metric.d.ts +22 -0
  76. package/src/core/geom/3d/atlas/param/atlas_chart_stretch_metric.d.ts.map +1 -0
  77. package/src/core/geom/3d/atlas/param/atlas_chart_stretch_metric.js +86 -0
  78. package/src/core/geom/3d/atlas/param/atlas_piecewise_resegment.d.ts +20 -0
  79. package/src/core/geom/3d/atlas/param/atlas_piecewise_resegment.d.ts.map +1 -0
  80. package/src/core/geom/3d/atlas/param/atlas_piecewise_resegment.js +183 -0
  81. package/src/core/geom/3d/atlas/param/fit_plane_basis.d.ts +27 -0
  82. package/src/core/geom/3d/atlas/param/fit_plane_basis.d.ts.map +1 -0
  83. package/src/core/geom/3d/atlas/param/fit_plane_basis.js +66 -0
  84. package/src/core/geom/3d/atlas/segment/RegionGraph.d.ts +31 -0
  85. package/src/core/geom/3d/atlas/segment/RegionGraph.d.ts.map +1 -0
  86. package/src/core/geom/3d/atlas/segment/RegionGraph.js +40 -0
  87. package/src/core/geom/3d/atlas/segment/atlas_build_region_graph.d.ts +23 -0
  88. package/src/core/geom/3d/atlas/segment/atlas_build_region_graph.d.ts.map +1 -0
  89. package/src/core/geom/3d/atlas/segment/atlas_build_region_graph.js +136 -0
  90. package/src/core/geom/3d/atlas/segment/atlas_compute_planar_regions.d.ts +24 -0
  91. package/src/core/geom/3d/atlas/segment/atlas_compute_planar_regions.d.ts.map +1 -0
  92. package/src/core/geom/3d/atlas/segment/atlas_compute_planar_regions.js +77 -0
  93. package/src/core/geom/3d/atlas/segment/atlas_merge_charts.d.ts +27 -0
  94. package/src/core/geom/3d/atlas/segment/atlas_merge_charts.d.ts.map +1 -0
  95. package/src/core/geom/3d/atlas/segment/atlas_merge_charts.js +113 -0
  96. package/src/core/geom/3d/atlas/segment/atlas_segment_charts.d.ts +44 -0
  97. package/src/core/geom/3d/atlas/segment/atlas_segment_charts.d.ts.map +1 -0
  98. package/src/core/geom/3d/atlas/segment/atlas_segment_charts.js +275 -0
  99. package/src/core/geom/3d/atlas/segment/atlas_segment_charts_atomic.d.ts +22 -0
  100. package/src/core/geom/3d/atlas/segment/atlas_segment_charts_atomic.d.ts.map +1 -0
  101. package/src/core/geom/3d/atlas/segment/atlas_segment_charts_atomic.js +199 -0
  102. package/src/core/geom/3d/line/line3_compute_point_segment_point_distance_unfolded.d.ts +32 -0
  103. package/src/core/geom/3d/line/line3_compute_point_segment_point_distance_unfolded.d.ts.map +1 -0
  104. package/src/core/geom/3d/line/line3_compute_point_segment_point_distance_unfolded.js +64 -0
  105. package/src/core/geom/3d/mat4/m4_from_rotation_translation_scale.d.ts +20 -0
  106. package/src/core/geom/3d/mat4/m4_from_rotation_translation_scale.d.ts.map +1 -0
  107. package/src/core/geom/3d/mat4/m4_from_rotation_translation_scale.js +66 -0
  108. package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.d.ts.map +1 -1
  109. package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.js +13 -11
  110. package/src/core/geom/3d/sphere/sphere_compute_bounding_of_2_spheres.d.ts.map +1 -1
  111. package/src/core/geom/3d/sphere/sphere_compute_bounding_of_2_spheres.js +4 -3
  112. package/src/core/geom/3d/topology/simplify/decimate_edge_collapse_snap.d.ts.map +1 -1
  113. package/src/core/geom/3d/topology/simplify/decimate_edge_collapse_snap.js +4 -3
  114. package/src/core/geom/3d/topology/simplify/quadratic/Quadric3.d.ts.map +1 -1
  115. package/src/core/geom/3d/topology/simplify/quadratic/Quadric3.js +4 -3
  116. package/src/core/geom/3d/topology/simplify/quadratic/apply_border_penalty_to_vertex_quadrics.d.ts.map +1 -1
  117. package/src/core/geom/3d/topology/simplify/quadratic/apply_border_penalty_to_vertex_quadrics.js +10 -6
  118. package/src/core/geom/3d/topology/struct/TopoMesh.js +2 -2
  119. package/src/core/geom/3d/topology/struct/TopoTriangle.d.ts +0 -2
  120. package/src/core/geom/3d/topology/struct/TopoTriangle.d.ts.map +1 -1
  121. package/src/core/geom/3d/topology/struct/TopoTriangle.js +2 -2
  122. package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_face_find_path_polyanya.d.ts.map +1 -1
  123. package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_face_find_path_polyanya.js +8 -27
  124. package/src/core/geom/vec3/v3_cotangent.d.ts +20 -0
  125. package/src/core/geom/vec3/v3_cotangent.d.ts.map +1 -0
  126. package/src/core/geom/vec3/v3_cotangent.js +29 -0
  127. package/src/core/geom/vec3/v3_matrix3_multiply.d.ts +19 -0
  128. package/src/core/geom/vec3/v3_matrix3_multiply.d.ts.map +1 -0
  129. package/src/core/geom/vec3/v3_matrix3_multiply.js +30 -0
  130. package/src/core/geom/vec3/v3_multiply.d.ts +16 -0
  131. package/src/core/geom/vec3/v3_multiply.d.ts.map +1 -0
  132. package/src/core/geom/vec3/v3_multiply.js +19 -0
  133. package/src/core/math/linalg/cg/cg_solve.d.ts +24 -0
  134. package/src/core/math/linalg/cg/cg_solve.d.ts.map +1 -0
  135. package/src/core/math/linalg/cg/cg_solve.js +106 -0
  136. package/src/core/math/linalg/cg/cg_solve_normal_equations.d.ts +21 -0
  137. package/src/core/math/linalg/cg/cg_solve_normal_equations.d.ts.map +1 -0
  138. package/src/core/math/linalg/cg/cg_solve_normal_equations.js +59 -0
  139. package/src/core/math/linalg/eigen/matrix_symmetric_3x3_eigen.d.ts +19 -0
  140. package/src/core/math/linalg/eigen/matrix_symmetric_3x3_eigen.d.ts.map +1 -0
  141. package/src/core/math/linalg/eigen/matrix_symmetric_3x3_eigen.js +117 -0
  142. package/src/core/math/linalg/sparse/SparseMatrixCSR.d.ts +50 -0
  143. package/src/core/math/linalg/sparse/SparseMatrixCSR.d.ts.map +1 -0
  144. package/src/core/math/linalg/sparse/SparseMatrixCSR.js +88 -0
  145. package/src/core/math/linalg/sparse/spm_matvec.d.ts +9 -0
  146. package/src/core/math/linalg/sparse/spm_matvec.d.ts.map +1 -0
  147. package/src/core/math/linalg/sparse/spm_matvec.js +22 -0
  148. package/src/core/math/linalg/sparse/spm_matvec_transpose.d.ts +12 -0
  149. package/src/core/math/linalg/sparse/spm_matvec_transpose.d.ts.map +1 -0
  150. package/src/core/math/linalg/sparse/spm_matvec_transpose.js +29 -0
  151. package/src/core/math/physics/mie/MIE_PARTICLES_STANDARD_PRECOMPUTED.d.ts +39 -0
  152. package/src/core/math/physics/mie/MIE_PARTICLES_STANDARD_PRECOMPUTED.js +22 -1
  153. package/src/core/math/physics/mie/compute_mie_particle_properties_rgb.d.ts.map +1 -1
  154. package/src/core/math/physics/mie/compute_mie_particle_properties_rgb.js +32 -9
  155. package/src/core/math/physics/mie/compute_mie_phase.d.ts +2 -3
  156. package/src/core/math/physics/mie/compute_mie_phase.d.ts.map +1 -1
  157. package/src/core/math/physics/mie/compute_mie_phase.js +1 -3
  158. package/src/core/math/physics/mie/lorenz_mie_coefs.d.ts +0 -1
  159. package/src/core/math/physics/mie/lorenz_mie_coefs.d.ts.map +1 -1
  160. package/src/core/math/physics/mie/lorenz_mie_coefs.js +0 -7
  161. package/src/engine/ecs/attachment/TransformAttachmentBinding.js +3 -3
  162. package/src/engine/ecs/gui/hud/HeadsUpDisplaySystem.js +2 -2
  163. package/src/engine/ecs/terrain/ecs/Terrain.d.ts.map +1 -1
  164. package/src/engine/ecs/terrain/ecs/Terrain.js +4 -3
  165. package/src/engine/ecs/terrain/tiles/TerrainTile.js +2 -2
  166. package/src/engine/ecs/terrain/tiles/TerrainTileManager.d.ts.map +1 -1
  167. package/src/engine/ecs/terrain/tiles/TerrainTileManager.js +9 -8
  168. package/src/engine/graphics/GraphicsEngine.d.ts.map +1 -1
  169. package/src/engine/graphics/GraphicsEngine.js +2 -1
  170. package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.js +2 -2
  171. package/src/engine/graphics/ecs/decal/v2/prototypeDecalSystem.js +2 -2
  172. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +2 -2
  173. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.d.ts.map +1 -1
  174. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +0 -1
  175. package/src/engine/graphics/ecs/path/tube/build/computeFrenetFrames.d.ts.map +1 -1
  176. package/src/engine/graphics/ecs/path/tube/build/computeFrenetFrames.js +8 -7
  177. package/src/engine/graphics/geometry/MikkT/AvgTSpace.d.ts.map +1 -1
  178. package/src/engine/graphics/geometry/MikkT/AvgTSpace.js +11 -6
  179. package/src/engine/graphics/geometry/MikkT/BuildNeighborsFast.d.ts.map +1 -1
  180. package/src/engine/graphics/geometry/MikkT/BuildNeighborsFast.js +2 -3
  181. package/src/engine/graphics/geometry/MikkT/CalcTexArea.d.ts.map +1 -1
  182. package/src/engine/graphics/geometry/MikkT/CalcTexArea.js +3 -4
  183. package/src/engine/graphics/geometry/MikkT/DegenEpilogue.js +4 -4
  184. package/src/engine/graphics/geometry/MikkT/EvalTspace.d.ts.map +1 -1
  185. package/src/engine/graphics/geometry/MikkT/EvalTspace.js +11 -8
  186. package/src/engine/graphics/geometry/MikkT/GenerateSharedVerticesIndexList.d.ts.map +1 -1
  187. package/src/engine/graphics/geometry/MikkT/GenerateSharedVerticesIndexList.js +7 -8
  188. package/src/engine/graphics/geometry/MikkT/GenerateTSpaces.js +8 -8
  189. package/src/engine/graphics/geometry/MikkT/InitTriInfo.d.ts.map +1 -1
  190. package/src/engine/graphics/geometry/MikkT/InitTriInfo.js +30 -25
  191. package/src/engine/graphics/geometry/MikkT/MikkTSpace.js +7 -7
  192. package/src/engine/graphics/geometry/MikkT/NormalizeSafe.d.ts +0 -1
  193. package/src/engine/graphics/geometry/MikkT/NormalizeSafe.d.ts.map +1 -1
  194. package/src/engine/graphics/geometry/MikkT/NormalizeSafe.js +6 -4
  195. package/src/engine/graphics/geometry/MikkT/STSpace.d.ts +0 -2
  196. package/src/engine/graphics/geometry/MikkT/STSpace.d.ts.map +1 -1
  197. package/src/engine/graphics/geometry/MikkT/STSpace.js +3 -3
  198. package/src/engine/graphics/geometry/MikkT/v3_scale_dot_sub_normalize.d.ts +0 -2
  199. package/src/engine/graphics/geometry/MikkT/v3_scale_dot_sub_normalize.d.ts.map +1 -1
  200. package/src/engine/graphics/geometry/MikkT/v3_scale_dot_sub_normalize.js +0 -1
  201. package/src/engine/graphics/impostors/octahedral/ImpostorBaker.d.ts +0 -2
  202. package/src/engine/graphics/impostors/octahedral/ImpostorBaker.d.ts.map +1 -1
  203. package/src/engine/graphics/impostors/octahedral/ImpostorBaker.js +4 -3
  204. package/src/engine/graphics/impostors/octahedral/grid/HemiOctahedralUvEncoder.js +2 -2
  205. package/src/engine/graphics/impostors/octahedral/grid/UvEncoder.d.ts +17 -7
  206. package/src/engine/graphics/impostors/voxel/VoxelImpostorBaker.js +2 -2
  207. package/src/engine/graphics/particles/particular/engine/utils/volume/ParticleVolume.js +3 -3
  208. package/src/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +4 -3
  209. package/src/engine/graphics/render/forward_plus/LightManager.js +2 -2
  210. package/src/engine/graphics/render/forward_plus/model/Decal.d.ts +0 -2
  211. package/src/engine/graphics/render/forward_plus/model/Decal.d.ts.map +1 -1
  212. package/src/engine/graphics/render/forward_plus/model/Decal.js +3 -3
  213. package/src/engine/graphics/render/forward_plus/prototype/prototypeLightManager.js +4 -3
  214. package/src/engine/graphics/render/visibility/hiz/prototypeHiZ.js +6 -4
  215. package/src/engine/graphics/sh3/lightmap/ARTIFACTS_PLAN.md +146 -0
  216. package/src/engine/graphics/sh3/lightmap/CODE_REVIEW.md +121 -0
  217. package/src/engine/graphics/sh3/lightmap/LIGHTMAPPER_REVIEW.md +183 -0
  218. package/src/engine/graphics/sh3/lightmap/bake_lightmap_for_scene.d.ts +90 -0
  219. package/src/engine/graphics/sh3/lightmap/bake_lightmap_for_scene.d.ts.map +1 -0
  220. package/src/engine/graphics/sh3/lightmap/bake_lightmap_for_scene.js +678 -0
  221. package/src/engine/graphics/sh3/lightmap/lightmap_build_geometry.d.ts +32 -0
  222. package/src/engine/graphics/sh3/lightmap/lightmap_build_geometry.d.ts.map +1 -0
  223. package/src/engine/graphics/sh3/lightmap/lightmap_build_geometry.js +155 -0
  224. package/src/engine/graphics/sh3/lightmap/lightmap_denoise.d.ts +49 -0
  225. package/src/engine/graphics/sh3/lightmap/lightmap_denoise.d.ts.map +1 -0
  226. package/src/engine/graphics/sh3/lightmap/lightmap_denoise.js +136 -0
  227. package/src/engine/graphics/sh3/lightmap/lightmap_dilate.d.ts +19 -0
  228. package/src/engine/graphics/sh3/lightmap/lightmap_dilate.d.ts.map +1 -0
  229. package/src/engine/graphics/sh3/lightmap/lightmap_dilate.js +89 -0
  230. package/src/engine/graphics/sh3/lightmap/lightmap_gather.d.ts +54 -0
  231. package/src/engine/graphics/sh3/lightmap/lightmap_gather.d.ts.map +1 -0
  232. package/src/engine/graphics/sh3/lightmap/lightmap_gather.js +168 -0
  233. package/src/engine/graphics/sh3/lightmap/lightmap_rasterize_triangle.d.ts +30 -0
  234. package/src/engine/graphics/sh3/lightmap/lightmap_rasterize_triangle.d.ts.map +1 -0
  235. package/src/engine/graphics/sh3/lightmap/lightmap_rasterize_triangle.js +145 -0
  236. package/src/engine/graphics/sh3/lightmap/lightmap_seam_fix.d.ts +38 -0
  237. package/src/engine/graphics/sh3/lightmap/lightmap_seam_fix.d.ts.map +1 -0
  238. package/src/engine/graphics/sh3/lightmap/lightmap_seam_fix.js +152 -0
  239. package/src/engine/graphics/sh3/lightmap/prototypeLightmapBaker.d.ts +2 -0
  240. package/src/engine/graphics/sh3/lightmap/prototypeLightmapBaker.d.ts.map +1 -0
  241. package/src/engine/graphics/sh3/lightmap/prototypeLightmapBaker.js +186 -0
  242. package/src/engine/graphics/sh3/path_tracer/PathTracedMesh.d.ts.map +1 -1
  243. package/src/engine/graphics/sh3/path_tracer/PathTracedMesh.js +2 -2
  244. package/src/engine/graphics/sh3/path_tracer/PathTracer.js +2 -2
  245. package/src/engine/graphics/sh3/path_tracer/prepare_scene_gltf.d.ts.map +1 -1
  246. package/src/engine/graphics/sh3/path_tracer/prepare_scene_gltf.js +6 -4
  247. package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +3 -3
  248. package/src/engine/graphics/sh3/path_tracer/texture/sample_material.d.ts.map +1 -1
  249. package/src/engine/graphics/sh3/path_tracer/texture/sample_material.js +5 -4
  250. package/src/engine/graphics/sh3/sky/hosek/prototype_hosek.js +2 -2
  251. package/src/engine/input/devices/KeyboardDevice.d.ts +61 -14
  252. package/src/engine/input/devices/KeyboardDevice.d.ts.map +1 -1
  253. package/src/engine/input/devices/KeyboardDevice.js +41 -15
  254. package/src/engine/input/devices/isHTMLElementFocusable.d.ts.map +1 -1
  255. package/src/engine/input/devices/isHTMLElementFocusable.js +2 -9
  256. package/src/engine/sound/simulation/prototypeAcousticSolver.js +261 -143
@@ -0,0 +1,486 @@
1
+ # UV Atlas — xatlas `ComputeCharts` + `PackCharts` port into meep
2
+
3
+ Status: **M0–M14 IMPLEMENTED** (2026-06-25) · Target: `app/src/mir-engine/meep/src/...`
4
+
5
+ > **M12–M14 (phase 2 cont.):** M12 region-atomic segmentation (default;
6
+ > `segment/atlas_{build_region_graph,segment_charts_atomic}`). M13 multi-page +
7
+ > **elastic density** packing (`maxResolution`/`maxPages`; `maxPages:1` = single
8
+ > elastic page). M14 benchmark suite (`atlas_generate.bench.spec`, `.skip`,
9
+ > `BENCH_SECONDS`) — it surfaced that the bitmap canBlit scan is O(atlas²) (13–22s
10
+ > at 2048), fixed by a fast **skyline rectangle packer** (`core/geom/2d/packing/
11
+ > skyline`) auto-selected for large atlases; exact bitmap kept for small / behind
12
+ > `bruteForce`. Pack at 2048: 3–43ms, 46–95% utilization. A second `.skip` bench
13
+ > builds a deterministic `~4M-tri` procedural scene (`soup_scene`, env
14
+ > `BENCH_LARGE_TRIS`) for scaling measurement.
15
+ >
16
+ > **Benchmark findings (updated 2026-06-25):**
17
+ > - *Sphere "over-fragmentation" was a fixture bug, not a tool bug.* The bench's
18
+ > `soup_uv_sphere` fanned the poles with degenerate coincident-vertex triangles
19
+ > that welded into slivers (125 charts, 120 "degenerate"). Fixed to skip them →
20
+ > **4 charts, 0 degenerate**, matching the clean indexed fixture. A clean closed
21
+ > sphere segments fine; the earlier "closed surfaces over-fragment" finding is
22
+ > retracted.
23
+ > - *Chart extraction was O(charts × faces)* (re-scanned every face per chart +
24
+ > allocated a full per-vertex array per chart). Now O(faces): one face-bucket
25
+ > pass + a reused version-stamped vertex map. **Compute 92.8s → 35.9s (2.6×)** on
26
+ > a 150k-tri scene, behaviour-preserving.
27
+ > - *New `~4M-tri` procedural-scene bench* (`soup_scene`, env `BENCH_LARGE_TRIS`):
28
+ > a representative field (terrain + large objects + thousands of small shapes).
29
+ > It quantifies the remaining scaling walls — **mesh conditioning (colocal weld +
30
+ > t-junction resolution + edge-data) ~75%** of compute, **LSCM ~20%**;
31
+ > segmentation+extraction is now negligible. Both walls are the next perf targets
32
+ > (conditioning lives in the shared topology layer → wider blast radius); the
33
+ > bench is the standing quantifier. A max-stretch outlier (133–359) on
34
+ > decimated/curved meshes remains the quality target.
35
+ > - *Degenerate-triangle robustness* (collinear / needle / sliver) is now an
36
+ > end-to-end test: the pipeline stays finite (no NaN, no crash); degenerate faces
37
+ > become isolated zero-area charts, good charts stay bijective.
38
+
39
+ > **Implementation status.** All milestones M0–M11 landed and green (20 spec suites, 82 tests).
40
+ > Public entry: [`atlas_generate(mesh, options)`](atlas_generate.js) = ComputeCharts + PackCharts in one
41
+ > call (per-corner UVs written to the loop_data channel). Pieces: M0 sparse CG/eigen
42
+ > (`core/math/linalg/{cg,sparse}`, `eigen/matrix_symmetric_3x3_eigen`, `vec3/v3_cotangent`); M1 weld +
43
+ > AtlasData + `io/bt_loop_uv`; M2 `fit_plane_basis` + `segment/atlas_compute_planar_regions`; M3
44
+ > `segment/atlas_segment_charts`; M4 `atlas_extract_chart` + `param/{ortho,validity,stretch}`; M5
45
+ > `param/atlas_chart_parameterize_lscm`; M6 `atlas_compute_charts`; M7 `core/binary/BitImage2` +
46
+ > `2d/triangle/tri2_rasterize_conservative`; M8 `pack/atlas_pack_charts`; M9 `atlas_generate`;
47
+ > **M10** chart rotation (`2d/oriented-box/min_area_rect_2d` + `BitImage2.transposed`); **M11**
48
+ > `param/atlas_piecewise_resegment` (region-grow piecewise).
49
+ >
50
+ > **Deferred refinements** (documented in code, not yet built; §12 backlog): region-atomic segmentation
51
+ > (currently face-granular), multi-atlas pages + blockAlign, Jacobi/IC preconditioner for the CG if
52
+ > large charts need it, a placement-scan acceleration structure, optional `createImage`, and benchmarks.
53
+
54
+ Port the two load-bearing capabilities of [xatlas](https://github.com/jpcy/xatlas) — segmentation
55
+ into UV charts (`ComputeCharts`) and packing those charts into an atlas (`PackCharts`) — onto meep's
56
+ existing geometry, topology, linear-algebra and packing toolkits. xatlas is a ~10k-line single C++
57
+ file; large parts of it (half-edge mesh, union-find, heaps, eigen, BVH, sort) are **replaced wholesale**
58
+ by primitives meep already ships. This document is the implementation contract.
59
+
60
+ ---
61
+
62
+ ## 1. Locked scope decisions
63
+
64
+ | Decision | Choice | Consequence |
65
+ |---|---|---|
66
+ | **Fidelity** | **xatlas-grade** | Build the bitmap shifted-OR packer **and** true conformal LSCM up front (not MaxRects/harmonic stopgaps). |
67
+ | **Output** | **In-place on `BinaryTopology`** | Per-corner UVs written to a `loop_data` pool. No indexed-geometry exporter required. |
68
+ | **Input** | **Clean + robust colocal/non-manifold welding; NO authored UVs** | New spatial colocal merge (xatlas `createColocals`). **Drops** the `OriginalUvCharts`/`useInputMeshUvs` path **and** the `textureSeamWeight` cost term (both derive from authored input UVs we will never have). |
69
+
70
+ These three choices remove three whole xatlas subsystems (authored-UV ingest, original-UV charts,
71
+ texture-seam metric) and pin two hard build targets (bitmap packer, LSCM). Everything below is sized
72
+ to exactly this scope.
73
+
74
+ ---
75
+
76
+ ## 2. Pipeline at a glance
77
+
78
+ ```
79
+ ComputeCharts (3D, topology-coupled) PackCharts (2D, bitmap)
80
+ ───────────────────────────────────── ─────────────────────────────
81
+ ingest indexed tris ─► BinaryTopology per-chart scale + rotate-to-OBB
82
+ + colocal weld (NEW) + AABB / block-align
83
+ precompute AtlasData (NEW) rasterize chart ─► BitImage2 (NEW)
84
+ face area/normal, edge len/dihedral + bilinear expand + dilate(padding)
85
+ planar-region merge (union_find) sort charts by perimeter (radix)
86
+ seed + grow charts (IndexedFloatMinHeap) placement scan: canBlit shifted-OR (NEW)
87
+ cost = N + roundness + straightness + normalSeam atlas pow2-grow / multi-page spill
88
+ validity gate per add (ortho + self-intersect) OR-blit mask, chart.uv -> atlas space
89
+ (loop_data write is the separate
90
+ atlas_write_chart_uvs step)
91
+ Lloyd relocate / fillHoles / mergeCharts
92
+ per-chart parameterize:
93
+ ortho (no solve) ──fail──► LSCM (sparse CG, NEW) ──fail──► piecewise re-segment
94
+ write per-corner UVs to loop_data
95
+ ```
96
+
97
+ The two halves meet at one in-memory artifact: a **`ChartSet`** — a list of charts, each holding its
98
+ face list, its unified-vertex↔loop mapping, its proxy basis, its per-unified-vertex UVs, and its
99
+ `surfaceArea`/`parametricArea`. `ComputeCharts` produces it; `PackCharts` consumes it and finalizes
100
+ the loop_data UVs into atlas space.
101
+
102
+ ---
103
+
104
+ ## 3. Data model
105
+
106
+ ### 3.1 Mesh substrate — reuse `BinaryTopology` verbatim
107
+ [`BinaryTopology`](struct/binary/BinaryTopology.js) is a Blender-BMesh model: **vertex / edge / loop /
108
+ face** pools. A **loop is a per-corner slot** carrying `radial_next/prev` (edge-radial adjacency →
109
+ opposite-face / boundary / manifold tests) and `next/prev` (face-cycle traversal). This is the direct
110
+ analogue of xatlas's `Mesh` + `m_oppositeEdges`. **No structural changes needed.**
111
+
112
+ Verified accessors we build on: `vertex_read/write_coordinate`, `vertex_read/write_normal`,
113
+ `edge_read_vertex1/2`, `edge_read_loop`, disk-cycle `v1/v2_disk_next/prev`, `loop_read_vertex/edge/
114
+ face/radial_next/prev/next/prev`, `face_read_loop`, `face_read/write_normal`.
115
+
116
+ ### 3.2 Per-corner UVs — reuse the optional `loop_data` pool
117
+ `BinaryTopology.create_loop_data(item_size_bytes)` (verified, line 256) allocates an opaque per-loop
118
+ data pool, ids 1:1 with loops. **UVs live here**: `item_size = 2 * Float32 = 8 bytes` (`u`, `v`).
119
+ Two thin helpers (NEW): `bt_loop_write_uv(mesh, loop_id, u, v)` / `bt_loop_read_uv(out, off, mesh,
120
+ loop_id)`. Seams are implicit: corners of one geometric vertex that belong to different charts are
121
+ different loops, hence carry different UVs — exactly xatlas per-wedge output, for free.
122
+
123
+ ### 3.3 Derived attribute arrays — `AtlasData` (NEW, plain parallel typed arrays)
124
+ xatlas precomputes per-element scalars once; we mirror with parallel `Float32Array`s keyed by element
125
+ id (no new container, follows the meep "scatter into a flat typed array" idiom):
126
+
127
+ | Array | Source | xatlas name |
128
+ |---|---|---|
129
+ | `face_area: Float32Array` | NEW pass (`tri3_area`) | `faceAreas` |
130
+ | `face_normal` | reuse `bt_mesh_compute_face_normals` (writes into face pool) | `faceNormals` |
131
+ | `edge_length: Float32Array` | NEW pass (`v3_distance_sqr`→sqrt) | `edgeLengths` |
132
+ | `edge_dihedral: Float32Array` | NEW pass (`v3_dot` of adjacent face normals; `FLT_MAX` = boundary) | `edgeDihedralAngles` |
133
+
134
+ `face_normal` exists; the other three are trivial one-pass kernels.
135
+
136
+ ### 3.4 Chart state — typed, not stringly (honours *typed-over-magic*, *no-null-defaults*)
137
+ ```
138
+ class Chart { // core/geom/3d/atlas/segment/Chart.js
139
+ faces = new GrowableUint32Array() // face ids
140
+ type = CHART_TYPE.LSCM // enum const, NOT a string
141
+ basis = new Float32Array(9) // normal(3) tangent(3) bitangent(3)
142
+ area = 0; boundaryLength = 0
143
+ // unified vertex layer, filled at parameterization:
144
+ unified_of_loop = new GrowableUint32Array() // loop_id -> chart-local unified vertex
145
+ uv = new GrowableFloat32Array() // per unified vertex (u,v)
146
+ surfaceArea = 0; parametricArea = 0
147
+ }
148
+ const CHART_TYPE = { PLANAR: 0, ORTHO: 1, LSCM: 2, PIECEWISE: 3 }; // frozen
149
+ ```
150
+
151
+ ---
152
+
153
+ ## 4. Module layout
154
+
155
+ Generic primitives stay in their natural homes (so they're reusable beyond the atlas); only the
156
+ orchestration is atlas-specific. New trees: `core/geom/3d/atlas/`, `core/math/linalg/cg/`,
157
+ `core/math/linalg/sparse/`.
158
+
159
+ ```
160
+ core/geom/3d/atlas/
161
+ atlas_compute_charts.js # driver: mesh -> charts (local UVs on chart.uv; no mesh write)
162
+ atlas_write_chart_uvs.js # actualize chart UVs onto a mesh's loop_data (per source mesh)
163
+ atlas_generate.js # one-call single mesh: compute -> pack -> write_chart_uvs
164
+ ChartSet.js Chart.js # state structs + CHART_TYPE enum
165
+ data/
166
+ atlas_build_face_areas.js
167
+ atlas_build_edge_lengths.js
168
+ atlas_build_edge_dihedrals.js
169
+ io/
170
+ atlas_mesh_create_colocals.js # spatial colocal weld (uf_* + SpatialHashGrid)
171
+ bt_loop_uv.js # bt_loop_read_uv / bt_loop_write_uv
172
+ segment/
173
+ atlas_compute_planar_regions.js # union_find coplanar merge (stage 2)
174
+ atlas_place_seeds.js # stage 3
175
+ atlas_segment_cost.js # stage 4 cost (N + roundness + straightness + normalSeam)
176
+ atlas_grow_charts.js # stage 6 global min-of-mins
177
+ atlas_relocate_seeds.js # stage 8 Lloyd
178
+ atlas_fill_holes.js
179
+ atlas_merge_charts.js # stage 9
180
+ param/
181
+ fit_plane_basis.js # stage 5 covariance + smallest-eigvec
182
+ atlas_chart_parameterize_ortho.js # stage 7/11
183
+ atlas_chart_parameterize_lscm.js # stage 12 (uses the sparse CG)
184
+ atlas_chart_param_validity.js # flips + boundary self-intersection + stretch gate
185
+ atlas_chart_stretch_metric.js # Sander/Hoppe L2 + Linf
186
+ atlas_piecewise_resegment.js # stage 13
187
+ pack/
188
+ atlas_pack_charts.js # driver: charts -> atlas (mutates chart.uv to atlas space; no mesh)
189
+ atlas_chart_oriented_box.js # rotate-to-axis via hull + min-area rect
190
+ atlas_estimate_resolution.js # P0 texelsPerUnit / resolution
191
+
192
+ core/math/linalg/eigen/
193
+ matrix_symmetric_3x3_eigen.js # NEW closed-form symmetric 3x3 eigen (vals+vecs)
194
+ core/math/linalg/cg/
195
+ cg_solve_csr.js # NEW generic SPD conjugate gradient over a sparse operator
196
+ cg_solve_csr_jacobi.js # NEW (optional) diagonal-preconditioned variant
197
+ core/math/linalg/sparse/
198
+ SparseMatrixCSR.js # NEW rectangular CSR (rows x cols) for LSCM A
199
+ spm_matvec.js spm_matvec_transpose.js
200
+ cg_solve_normal_equations.js # NEW matrix-free A^T A solve, reuses cg core
201
+
202
+ core/binary/
203
+ BitImage2.js # NEW 2D bit raster: canBlit/or_blit/dilate/grow/cardinality
204
+ core/geom/2d/triangle/
205
+ tri2_rasterize_conservative.js # NEW conservative tri -> BitImage2 coverage
206
+ core/geom/2d/segment/
207
+ seg2_intersect.js # NEW exact segment-segment test (if absent)
208
+ core/geom/2d/oriented-box/
209
+ min_area_rect_2d.js # NEW rotating-calipers OBB over a hull
210
+ core/geom/vec3/
211
+ v3_cotangent.js # NEW cotangent weight helper
212
+ core/math/
213
+ nextPowerOfTwo.js # NEW trivial
214
+ ```
215
+
216
+ ---
217
+
218
+ ## 5. Reuse map (the "maximize reuse" deliverable)
219
+
220
+ `reuse` = use as-is · `adapt` = thin wrapper · `new` = build · `drop` = out of scope per §1.
221
+
222
+ ### ComputeCharts
223
+ | xatlas stage | meep mapping | verdict |
224
+ |---|---|---|
225
+ | 0 build atlas mesh | `bt_mesh_from_indexed_geometry`, `bt_mesh_compute_face_normals`, radial/disk accessors | **reuse** |
226
+ | 0 colocal weld | `uf_init/uf_find/uf_union` + `SpatialHashGrid` (or `BVH`) → `atlas_mesh_create_colocals` | reuse + **new** driver |
227
+ | 0 AtlasData | `tri3_area`, `v3_distance_sqr`, `v3_dot` → 3 one-pass kernels | **new** (trivial) |
228
+ | 1 OriginalUvCharts | — | **drop** |
229
+ | 2 planar regions | `uf_union` over coplanar (`v3_dot(n,n')≈1`) faces; areas scatter-add | reuse + **new** driver |
230
+ | 3 placeSeeds | `IndexedFloatMinHeap` as per-chart CostQueue; `BitSet` ownership | reuse + **new** driver |
231
+ | 4 cost metric | `v3_dot`/`v3_cross` + AtlasData; `textureSeam` term **dropped** | **new** formulas |
232
+ | 5 chart basis fit | `matrix_symmetric_3x3_eigen` (smallest eigvec) + `v3_orthonormal_matrix_from_normal` → `fit_plane_basis` | **new** eigen + **new** wrapper |
233
+ | 6 growCharts | per-chart `IndexedFloatMinHeap`, global min-of-mins; lazy-delete claimed faces | reuse + **new** driver |
234
+ | 7 ortho validity | `tri2_signed_area` (flip), `SpatialHashGrid`+`shg_query_elements_line`+`seg2_intersect` (self-x) | reuse + **new** gate |
235
+ | 8 relocate/iterate | small fixed-cap `IndexedFloatMinHeap`; reuse 3/5/6 | reuse + **new** loop |
236
+ | 9 fillHoles/merge | chart adjacency over edges + stage-7 gate + `fit_plane_basis` | reuse + **new** driver |
237
+ | 10 unified submesh | `uf_*` colocal weld per chart → unified vertices; loop↔unified map | reuse + **new** |
238
+ | 11 ortho param + gate | `v3_dot` projection + `atlas_chart_stretch_metric` + validity gate | **new** |
239
+ | 12 **LSCM** | `SparseMatrixCSR` + `cg_solve_normal_equations` + `v3_cotangent`; pins via `solve_linear_system_GEPP_2x2`; diameter pins via `bt_mesh_walk_boundary_loops` | **new** (the big one) |
240
+ | 13 piecewise | region-grow + per-add gate (reuse 6/7) | **new** driver |
241
+ | 14 output | write per-corner UVs to `loop_data` (`bt_loop_write_uv`) | **new** (thin) |
242
+
243
+ ### PackCharts (xatlas-grade bitmap path)
244
+ | xatlas stage | meep mapping | verdict |
245
+ |---|---|---|
246
+ | P0 estimate res/texels | scalar + `nextPowerOfTwo` | **new** (trivial) |
247
+ | P1 scale + rotate-to-axis + block | `convex_hull_monotone_2d` + `min_area_rect_2d`; `AABB2` | reuse + **new** OBB |
248
+ | P2 sort by perimeter | float radix or `array_quick_sort_by_lookup_uint` | reuse / **new** radix |
249
+ | P3 rasterize coverage | `tri2_rasterize_conservative` → `BitImage2` (+ transposed for rotation) | **new** |
250
+ | P4 bilinear + dilate | `BitImage2.dilate(padding)`; bilinear via boundary hash-grid | **new** |
251
+ | P5 placement scan | `BitImage2.canBlit` shifted-OR; brute-force/random | **new** |
252
+ | P6 atlas grow / multi-page | `BitImage2.grow_preserving` + page list; `nextPowerOfTwo` | **new** |
253
+ | P7 blit + write UVs + utilization | `BitImage2.or_blit` + `bt_loop_write_uv` | **new** |
254
+
255
+ > `MaxRectanglesPacker` (real API `add/addMany/canAdd/resize/repack/clear` over `AABB2`) is **not** on
256
+ > the xatlas-grade path — it's a *different* algorithm (max-rects free-list, no shifted-OR). It is kept
257
+ > as a **test oracle**: pack the chart AABBs with it and assert the bitmap packer never does worse on
258
+ > utilization, and `aabb2_validate_packing` for overlap sanity.
259
+
260
+ ---
261
+
262
+ ## 6. New primitives — signatures + per-file test plan
263
+
264
+ All follow house style: one export per file, snake_case, result-first args, typed arrays, module-static
265
+ scratch pools, `assert.*` guards (free in prod), `#private`, class fields, no `X|null` defaults.
266
+
267
+ ### 6.1 Numerics
268
+ - **`matrix_symmetric_3x3_eigen(out_values, out_vectors, m)`** — closed-form symmetric 3×3
269
+ eigendecomposition (analytic, deterministic; xatlas `eigenSolveSymmetric3`). Returns 3 eigenvalues +
270
+ 3 column eigenvectors. *Replaces* the wrong-axis `matrix_top_eigenvector_power_iteration` for the
271
+ plane fit (we need the **smallest**-eigenvalue eigenvector).
272
+ *Tests:* diagonal matrix → identity vectors; known covariance of a planar point set → smallest
273
+ eigvec ‖ plane normal (±sign); rotation-invariance; degenerate (rank-1) covariance handled.
274
+ - **`cg_solve_csr(x, csr, diag, b, max_iterations, tolerance)`** — generic unpreconditioned CG for an
275
+ SPD operator `A = diag − offdiag(csr)` (cotangent Laplacian shape). Module-static `r/p/Ap` scratch
276
+ like the fluid PCG. Diagonal is a **separate `Float32Array`** (CSRGraph `vertex_weights` is Uint32 —
277
+ verified — so the float diagonal cannot live there).
278
+ *Tests:* 3×3 and 5×5 Laplacians with closed-form solution; symmetric RHS; iteration-count regression;
279
+ converges to tolerance; determinism (fixed reduction order).
280
+ - **`cg_solve_csr_jacobi(...)`** — diagonal-preconditioned variant. **Deferred until measured** (build
281
+ only if plain CG iteration counts are bad on thin charts).
282
+ - **`SparseMatrixCSR`** (`rows`, `cols`, `row_ptr`, `col_idx`, `values`) + **`spm_matvec(out, A, x)`** /
283
+ **`spm_matvec_transpose(out, A, x)`** — rectangular `A` for the LSCM least-squares system.
284
+ *Tests:* matvec vs dense reference on random small matrices; `(A^T x)·y == x·(A y)` adjoint identity.
285
+ - **`cg_solve_normal_equations(x, A, b, max_iterations, tolerance)`** — matrix-free `AᵀA x = Aᵀb`
286
+ using `spm_matvec`/`spm_matvec_transpose` and the `cg_solve_csr` reduction core. The OpenNL
287
+ equivalent. *Tests:* overdetermined system with known least-squares solution; pinned-DOF handling.
288
+ - **`v3_cotangent(ax,ay,az, bx,by,bz)`** → `cos/sin` of the angle between two edge vectors. The one
289
+ missing scalar (grep-confirmed absent). *Tests:* 90°→0, 45°→1, obtuse→negative.
290
+ - **`nextPowerOfTwo(x)`** — trivial. *Tests:* boundaries, exact powers.
291
+
292
+ ### 6.2 Packing
293
+ - **`BitImage2`** — `width`, `height`, word-aligned `Uint32Array` rows. Methods: `set/get`,
294
+ `canBlit(other, x, y)` (per-row shifted-OR AND collision, **trailing-word masked**), `or_blit(other,
295
+ x, y)`, `dilate(passes)` (3×3 OR), `cardinality()`, `grow_preserving(w, h)` (**re-strides every
296
+ row** — the one subtle trap), `reset()`.
297
+ *Tests:* explicit **truth tables** for `canBlit` (touching vs overlapping vs adjacent, across word
298
+ boundaries), `dilate` 1-pass result, `grow_preserving` content preservation when row stride changes,
299
+ blit-then-canBlit round-trip.
300
+ - **`tri2_rasterize_conservative(image, x0,y0, x1,y1, x2,y2)`** — conservative (super-coverage) tri
301
+ rasterization into a `BitImage2`. *Tests:* axis triangle exact mask; conservative ⊇ center-sampled;
302
+ degenerate/zero-area no-crash.
303
+ - **`min_area_rect_2d(out, hull_points, count)`** — rotating-calipers minimum-area OBB → angle + extents.
304
+ *Tests:* axis-aligned rect → 0°; rotated rect → recovers angle; vs brute-force on random hulls.
305
+ - **`seg2_intersect(ax,ay,bx,by, cx,cy,dx,dy)`** — exact segment-segment intersection (orientation
306
+ predicates). *Tests:* crossing, collinear-overlap, shared-endpoint, disjoint.
307
+
308
+ ### 6.3 Atlas drivers
309
+ Each `atlas_*` driver is a pure function over the mesh + AtlasData + ChartSet (no hidden state),
310
+ individually unit-testable on small inline meshes. See §8.
311
+
312
+ ---
313
+
314
+ ## 7. Phased milestones
315
+
316
+ Each milestone is independently shippable, ends with a **standing spec gate**, and only depends on
317
+ earlier ones. Ordering puts reusable numerics first, then the two pipelines bottom-up, so every phase
318
+ is testable in isolation before integration.
319
+
320
+ Legend: ✅ done · ⏳ Phase 2 (§12). Actual file names note where the build superseded a tentative plan
321
+ name. Per-milestone test counts in parentheses; total **18 suites / 72 tests**.
322
+
323
+ - **M0 — Numerics foundation. ✅ (23).** `matrix_symmetric_3x3_eigen` (Jacobi), `cg_solve` (generic
324
+ matrix-free SPD CG via an `apply_A` callback — supersedes `cg_solve_csr`; serves LSCM *and* any
325
+ Laplacian), `SparseMatrixCSR` + `spm_matvec`/`spm_matvec_transpose`, `cg_solve_normal_equations`,
326
+ `v3_cotangent`. `nextPowerOfTwo` dropped — reused existing `ceilPowerOfTwo`. *Gate met:* closed-form
327
+ solves (1D Laplacian, least-squares, analytic eigen). The LSCM-solver unknown is fully retired.
328
+ - **M1 — Mesh prep. ✅ (9).** `atlas_mesh_weld_colocals` (reuses the navmesh
329
+ `bt_merge_vertices_by_distance` → `bt_mesh_fuse_duplicate_edges` → T-junction sequence — supersedes a
330
+ from-scratch `create_colocals`), `atlas_build_{face_areas,edge_lengths,edge_dihedrals}`, `bt_loop_uv`.
331
+ Dihedral stores adjacent-normal **dot** (1=flat, 0=90°, sentinel `2` for boundary). *Gate met.*
332
+ - **M2 — Planar segmentation. ✅ (6).** `fit_plane_basis`, `atlas_compute_planar_regions`. *Gate met:*
333
+ cube → 6 regions, fitted normals ‖ face normals.
334
+ - **M3 — General segmentation. ✅ (5).** One driver `atlas_segment_charts` (greedy seed+grow,
335
+ lazy-re-eval min-heap, cost = `wN·N + wNS·NS + wR·roundness`, 73° hard reject). Face-granular;
336
+ region-atomic growth + Lloyd relocation + `mergeCharts` are ⏳ backlog. *Gate met:* coverage,
337
+ deterministic count, maxCost-monotone.
338
+ - **M4 — Ortho + validity. ✅ (5).** `atlas_extract_chart`, `atlas_chart_parameterize_ortho`,
339
+ `atlas_chart_param_validity`, `atlas_chart_stretch_metric`. *Gate met.*
340
+ - **M5 — LSCM. ✅ (4).** `atlas_chart_parameterize_lscm` — true Cauchy-Riemann least-squares
341
+ (two diameter pins, **1/√area weights, not cotangent weights** → obtuse-cotangent non-SPD risk does
342
+ not arise), solved via M0. *Gate met:* rescues a developable ribbon ortho can't flatten.
343
+ - **M6 — Integration + piecewise. ✅ (3).** `atlas_compute_charts` + `CHART_TYPE`. Fallback is
344
+ region-grow piecewise (✅ M11). *Gate met.*
345
+ - **M7 — Bitmap packer core. ✅ (9).** `BitImage2` (in `core/binary/`), `tri2_rasterize_conservative`
346
+ (SAT). `seg2_intersect` dropped — reused `segment2_intersects_segment2_2d`. `min_area_rect_2d` →
347
+ ⏳ M10. *Gate met:* truth tables.
348
+ - **M8 — Pack driver. ✅ (5).** `atlas_pack_charts` (P0 auto-resolution, P1 scale, P3–P4 raster+dilate,
349
+ P5 bottom-left `canBlit` first-fit, P6 pow2 grow, P7 write-back). Chart rotation ✅ M10; multi-page +
350
+ blockAlign ⏳ backlog. *Gate met:* `occupied == Σ masks` (provable no-overlap), UVs ∈ [0,1],
351
+ deterministic.
352
+ - **M9 — One-call API + e2e. ✅ (5).** `atlas_generate`; integration across cube, closed octahedron,
353
+ LSCM ribbon, welded split mesh. Benches ⏳ backlog. *Gate met.*
354
+
355
+ **Critical path / parallelism:** M0 was the de-risking spike — done first and alone. M1→M6 (ComputeCharts)
356
+ and M7→M8 (PackCharts) were largely independent after M0; they join at M9.
357
+
358
+ ---
359
+
360
+ ## 8. Testing strategy (the "very testable" deliverable)
361
+
362
+ Honours the standing feedback: **black-box only** (assert observable output, never call-counts/private
363
+ paths), **no mocks** (real `BinaryTopology`, real heaps/union-find), **run from `H:/git/moh`** with the
364
+ root `jest.conf.json`, **no `.d.ts`**, asserts are compiled out of prod so they're free.
365
+
366
+ - **Inline mesh fixtures** (small builders returning indexed geometry, colocated in spec files): unit
367
+ quad, cube, cube-with-duplicated-verts (colocal test), open disk (one cube face), cylinder (seam),
368
+ saddle/hemisphere (LSCM), torus (multi-chart), one degenerate-triangle mesh (robustness).
369
+ - **Property-based invariants** rather than golden numbers where possible:
370
+ - Segmentation: partition is a **cover** (∪ charts = all faces, pairwise disjoint); chart count is a
371
+ deterministic function of mesh+options.
372
+ - Parameterization: **bijectivity** (zero flipped faces via `tri2_signed_area` sign agreement), **no
373
+ boundary self-intersection** (the validity gate), **bounded stretch** (`stretch ≤ 1.1`, `maxStretch
374
+ ≤ 1.25` to accept ortho; LSCM below a looser bound).
375
+ - Packing: **no two charts' texels overlap** (re-rasterize the final atlas, assert each texel covered
376
+ ≤ once), all UVs ∈ [0,1]² after normalization, utilization ≥ oracle.
377
+ - **Determinism gate** (meep has a standing determinism contract): fixed CSR-row / lex reduction order
378
+ in CG; fixed seed-face order (union-by-min-index already deterministic); fixed sort; no wall-clock
379
+ early-exit. A spec runs the full pipeline twice and asserts bit-identical UVs.
380
+ - **Numerics specs** assert against closed-form solutions (Laplace on a line/grid, least-squares of an
381
+ overdetermined system, analytic 3×3 eigen) — not against the implementation.
382
+ - **Benches** as `.bench.spec.js` (matches `bakeVisibility.bench.spec.js` precedent): segmentation
383
+ ms/face, CG iters/solve, pack ms + utilization%.
384
+
385
+ ---
386
+
387
+ ## 9. Risks & mitigations
388
+
389
+ | Risk | Mitigation |
390
+ |---|---|
391
+ | **Cotangent weights go negative** on obtuse triangles → Laplacian non-SPD → CG breaks. *(top correctness risk)* | Clamp negative cotangents to 0, or fall to **mean-value weights** (unconditionally positive, valid Tutte embedding); detect non-convergence → ortho/piecewise fallback. Decide the default in M5 with a spec on an obtuse-heavy chart. |
392
+ | **CG perf in V8** (fluid PCG header documents loop-overhead-bound, PCG slower per-iter than SOR). | Charts are far smaller than a 64³ grid; keep the CG kernel tight (typed arrays, inlined SpMV option, no per-iter closures). Hold `cg_solve_csr_jacobi` in reserve, gated on measured iteration counts (M5/M9). |
393
+ | **`BitImage2.grow_preserving` re-stride bug** — naive linear copy corrupts when row word-width changes. | Explicit re-stride; truth-table spec that grows across a word boundary and checks every bit (M7). |
394
+ | **`canBlit` trailing-word mask** off-by-one silently overlaps charts. | Mask partial trailing word; truth-table specs across word boundaries; final-atlas disjoint-coverage assertion in M8. |
395
+ | **Data-model bridging** (xatlas face-varying ↔ meep topology). | Resolved by §3: per-corner UVs on `loop_data`, per-chart unified-vertex layer via `uf_*`, loop↔unified map. Validated end-to-end at M6. |
396
+ | **Non-manifold / colocal input** (in scope). | `atlas_mesh_create_colocals` (uf + spatial hash) up front; radial cycle already handles n-radial loops; boundary = single-radial-loop test. Spec with a duplicated-vertex and a >2-faces-per-edge mesh (M1). |
397
+ | **No-boundary charts** (closed genus-0) — LSCM has no pins. | Match xatlas: abandon LSCM, route to piecewise re-segment (which introduces boundaries). Spec a closed sphere chart (M5/M6). |
398
+ | **Determinism drift** from float reductions. | Fixed iteration order everywhere; determinism spec is the standing gate (M9). |
399
+
400
+ ---
401
+
402
+ ## 10. Out of scope (deferred, with reasons)
403
+
404
+ - **Authored-UV ingest / `OriginalUvCharts` / `useInputMeshUvs`** — user excluded; we always re-segment.
405
+ - **`textureSeamWeight` cost term** — derives from authored UVs we never have; the cost metric is
406
+ `normalDeviationWeight·N + roundnessWeight·R + straightnessWeight·S + normalSeamWeight·NS`.
407
+ - **`createImage` (RGBA atlas rasterization)** — not requested; loop_data UVs are the output. (Trivial
408
+ to add later on `tri2_rasterize_conservative`.)
409
+ - **Indexed-geometry exporter** — user chose in-place loop_data output. (A `bt_mesh_to_indexed_geometry`
410
+ with a UV channel is a clean follow-up if a second consumer appears.)
411
+ - **GPU/WASM packer or solver** — JS first; the fluid PCG header notes the perf calculus flips under
412
+ SIMD/WebGPU, revisit then.
413
+
414
+ ---
415
+
416
+ ## 11. Open items to confirm during M0–M1
417
+
418
+ 1. **Cotangent fallback default** — clamp-to-zero vs mean-value (pick in M5; mean-value is the safer default).
419
+ 2. **SpMV inline vs separate file** — house style favors separate `spm_matvec`; fluid PCG inlines for V8
420
+ speed. Measure in M0; inline only if the bench demands it.
421
+ 3. **`BitImage2` home** — `core/binary/` (next to `BitSet`, generic) vs `core/geom/2d/`. Plan picks
422
+ `core/binary/` since it's a generic 2D bit raster; revisit if only the atlas ever uses it.
423
+ 4. **Colocal spatial index** — `SpatialHashGrid` (simpler) vs `BVH` (xatlas `createColocalsBVH`). Start
424
+ with the hash grid; swap to BVH only if welding shows up in profiles.
425
+
426
+ **Resolutions (after M0–M9):** (1) cotangent fallback is **moot** — the implemented LSCM uses
427
+ Cauchy-Riemann 1/√area weights, not cotangent weights, so the obtuse-triangle non-SPD risk never arises;
428
+ `v3_cotangent` stays as a utility for a future harmonic-map variant. (2) SpMV is a **separate file**
429
+ (`spm_matvec`) per house style; perf is ample at chart sizes. (3) `BitImage2` lives in **`core/binary/`**.
430
+ (4) Colocal welding reuses **`bt_merge_vertices_by_distance`** (its own internal hash grid), not a new
431
+ spatial index.
432
+
433
+ ---
434
+
435
+ ## 12. Phase 2 — refinements
436
+
437
+ Layered on the green M0–M9 core. Each is opt-in (behind an option) or a drop-in replacement, and must
438
+ preserve the standing invariants: disjoint packing (`occupied == Σ masks`), bijective charts,
439
+ determinism, all-UVs ∈ [0,1].
440
+
441
+ ### M10 — Chart rotation in the packer ✅ (done)
442
+ Two xatlas `PackOptions`, both raising atlas density:
443
+ - **`rotateChartsToAxis`** (default true): before scaling, rotate each chart's UVs so its
444
+ minimum-area oriented box is axis-aligned, shrinking its footprint. New
445
+ `core/geom/2d/oriented-box/min_area_rect_2d.js` — rotating calipers over `convex_hull_monotone_2d`
446
+ of the chart UVs, returning the box angle; apply the inverse rotation to `chart.uv` (rigid → validity
447
+ and stretch unchanged). *Tests:* axis-aligned rect → 0°; rotated rect → recovers angle + area; vs a
448
+ brute-force angle sweep on random hulls; a diagonal chart's AABB area shrinks after alignment.
449
+ - **`rotateCharts`** (default true): allow a 90° orientation at placement. New `BitImage2.transposed()`
450
+ builds the swapped-axis mask; the placement scan tries both orientations and keeps the better fit,
451
+ recording the choice; UV write-back swaps `(tu,tv)` for rotated charts (a transpose — self-consistent
452
+ since we author the UVs, no external texture to mirror). *Tests:* a tall-thin chart set packs no
453
+ larger with rotation on; `occupied == Σ masks` still holds; determinism preserved.
454
+
455
+ *Gate:* on a mixed-aspect chart fixture, `utilization(on) ≥ utilization(off)`, atlas no larger, all
456
+ standing pack invariants hold.
457
+
458
+ ### M11 — Region-grow piecewise re-segmentation ✅ (done)
459
+ Replace the single-triangle explode fallback with xatlas `PiecewiseParam`. New
460
+ `param/atlas_piecewise_resegment.js`: build triangle adjacency within the invalid chart, then greedily
461
+ grow connected sub-charts from a seed triangle, ortho-projecting and validating (flip + boundary
462
+ self-intersection) after each tentative add; reject a triangle that breaks validity, finalize a
463
+ sub-chart when no neighbour can be added, repeat until every triangle is covered. Each sub-chart is
464
+ connected and ortho-valid by construction (a lone seed triangle is always valid → termination). Wired
465
+ into `atlas_compute_charts` in place of the explode. *Tests:* a chart LSCM leaves invalid splits into
466
+ ≥2 connected, bijective sub-charts covering every triangle exactly once; an already-valid chart returns
467
+ as one piece; fewer/larger pieces than the explode.
468
+
469
+ ### Backlog (not yet scheduled)
470
+ - ✅ **Region-atomic segmentation** — M12. (Lloyd seed relocation + `mergeCharts` still open for more
471
+ balanced charts / fewer seams.)
472
+ - ✅ **Placement-scan acceleration** — M14 skyline packer.
473
+ - ✅ **Multi-atlas pages** — M13. (`blockAlign` 4×4 for BC/DXT still open.)
474
+ - ✅ **Benchmarks** — M14.
475
+ - ✅ **Chart extraction O(charts × faces)** — fixed: one face-bucket pass + reused version-stamped
476
+ vertex map → O(faces). 92.8s → 35.9s (2.6×) on a 150k-tri scene.
477
+ - **Compute performance** *(bench finding, large-scene bench)* — at scale, **mesh conditioning**
478
+ dominates (~75%): profile the weld sequence (`atlas_mesh_weld_colocals` → colocal merge +
479
+ `bt_mesh_resolve_t_junctions`) and the edge-data builds. **LSCM is ~20%** (many curved charts; see
480
+ CG preconditioner / warm-start below). The boundary self-intersection check is O(boundary²).
481
+ *(User-deferred 2026-06-25: bench is the standing quantifier; revisit as its own task.)*
482
+ - ~~**Closed-surface robustness**~~ — was a bench fixture bug (degenerate sphere poles), not a tool
483
+ bug; a clean closed sphere segments into 4 charts. Retracted. Degenerate-triangle robustness is now
484
+ covered by an end-to-end test (`atlas_generate.spec`).
485
+ - **CG preconditioner** — Jacobi/IC `cg_solve` variant if large/thin charts show high iteration counts.
486
+ - **`createImage`** — optional RGBA atlas rasterization via `tri2_rasterize_conservative`.