@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,186 @@
1
+ import { BoxBufferGeometry, MeshStandardMaterial, SphereBufferGeometry } from "three";
2
+ import Quaternion from "../../../../core/geom/Quaternion.js";
3
+ import Vector3 from "../../../../core/geom/Vector3.js";
4
+ import Tag from "../../../ecs/components/Tag.js";
5
+ import Entity from "../../../ecs/Entity.js";
6
+ import { Transform } from "../../../ecs/transform/Transform.js";
7
+ import { EngineHarness } from "../../../EngineHarness.js";
8
+ import { Light } from "../../ecs/light/Light.js";
9
+ import LightSystem from "../../ecs/light/LightSystem.js";
10
+ import { ShadedGeometry } from "../../ecs/mesh-v2/ShadedGeometry.js";
11
+ import { ShadedGeometryFlags } from "../../ecs/mesh-v2/ShadedGeometryFlags.js";
12
+ import { ShadedGeometrySystem } from "../../ecs/mesh-v2/ShadedGeometrySystem.js";
13
+ import { bake_lightmap_for_scene } from "./bake_lightmap_for_scene.js";
14
+
15
+ const harness = new EngineHarness();
16
+
17
+ /**
18
+ * Add one coloured {@link ShadedGeometry} entity to the scene.
19
+ *
20
+ * @param {EntityComponentDataset} ecd
21
+ * @param {THREE.BufferGeometry} geometry
22
+ * @param {number} color hex colour
23
+ * @param {Vector3} position
24
+ * @param {Quaternion} [rotation]
25
+ */
26
+ function spawn(ecd, geometry, color, position, rotation) {
27
+ const material = new MeshStandardMaterial({ color, roughness: 1, metalness: 0 });
28
+
29
+ const sg = ShadedGeometry.from(geometry, material);
30
+ sg.setFlag(ShadedGeometryFlags.CastShadow);
31
+ sg.setFlag(ShadedGeometryFlags.ReceiveShadow);
32
+ sg.setFlag(ShadedGeometryFlags.Visible);
33
+
34
+ const transform = new Transform();
35
+ transform.position.copy(position);
36
+ if (rotation !== undefined) {
37
+ transform.rotation.copy(rotation);
38
+ }
39
+
40
+ new Entity()
41
+ .add(sg)
42
+ .add(transform)
43
+ .add(Tag.fromJSON(["LightmapTarget"]))
44
+ .build(ecd);
45
+ }
46
+
47
+ /**
48
+ * Add a coloured light. DIRECTION lights bake crisp shadows; POINT lights add
49
+ * coloured bounce. Both are read by the path-traced bake.
50
+ *
51
+ * @param {EntityComponentDataset} ecd
52
+ * @param {number} type one of {@link Light.Type}
53
+ * @param {number[]} color linear [r, g, b] in 0..1
54
+ * @param {number} intensity
55
+ * @param {Object} placement
56
+ * @param {Vector3} [placement.position]
57
+ * @param {Vector3} [placement.direction]
58
+ * @param {number} [placement.distance] point-light influence radius
59
+ */
60
+ function spawn_light(ecd, type, color, intensity, { position, direction, distance = 30 }) {
61
+ const light = new Light();
62
+ light.type.set(type);
63
+ light.color.setRGB(color[0], color[1], color[2]);
64
+ light.intensity.set(intensity);
65
+ light.distance.set(distance);
66
+ light.castShadow.set(true);
67
+
68
+ const transform = new Transform();
69
+ if (position !== undefined) {
70
+ transform.position.copy(position);
71
+ }
72
+ if (direction !== undefined) {
73
+ transform.rotation.lookRotation(direction.clone().normalize());
74
+ }
75
+
76
+ new Entity()
77
+ .add(light)
78
+ .add(transform)
79
+ .add(Tag.fromJSON(["Light"]))
80
+ .build(ecd);
81
+ }
82
+
83
+ /**
84
+ * @param {Engine} engine
85
+ */
86
+ async function main(engine) {
87
+ const em = engine.entityManager;
88
+
89
+ await em.addSystem(new ShadedGeometrySystem(engine));
90
+ await em.addSystem(new LightSystem(engine, { shadowResolution: 2048 }));
91
+
92
+ // camera + orbital/keyboard controls; no terrain (we build our own platform),
93
+ // no engine lights (we place our own so we can dim them after the bake)
94
+ await EngineHarness.buildBasics({
95
+ engine,
96
+ focus: new Vector3(0, 1.5, 0),
97
+ pitch: 0.95,
98
+ yaw: 0.6,
99
+ distance: 18,
100
+ enableTerrain: false,
101
+ enableWater: false,
102
+ enableLights: false,
103
+ cameraController: true,
104
+ showFps: true,
105
+ });
106
+
107
+ const ecd = em.dataset;
108
+
109
+ // --- platform ---
110
+ spawn(ecd, new BoxBufferGeometry(16, 1, 16), 0xA1A1A1, new Vector3(0, -0.5, 0));
111
+
112
+ // --- a few shapes ---
113
+ spawn(ecd, new BoxBufferGeometry(2, 2, 2), 0xe23b3b, new Vector3(-4, 1, -2));
114
+ spawn(ecd, new BoxBufferGeometry(2, 4, 2), 0x3bd16f, new Vector3(3.5, 2, 2));
115
+ spawn(ecd, new SphereBufferGeometry(1.5, 32, 24), 0x4f86ff, new Vector3(0, 1.5, 3.5));
116
+ spawn(
117
+ ecd,
118
+ new BoxBufferGeometry(2.5, 2.5, 2.5),
119
+ 0xf0c020,
120
+ new Vector3(2.5, 1.25, -3.5),
121
+ Quaternion.fromEulerAngles(0, Math.PI / 5, 0)
122
+ );
123
+
124
+ // --- lights (baked) ---
125
+ spawn_light(ecd, Light.Type.DIRECTION, [1.0, 0.95, 0.88], 1.6, { direction: new Vector3(-0.6, -1, -0.35) });
126
+ spawn_light(ecd, Light.Type.POINT, [1.0, 0.3, 0.18], 1, { position: new Vector3(-4, 2.5, 4), distance: 16 });
127
+ spawn_light(ecd, Light.Type.POINT, [0.18, 0.42, 1.0], 1, { position: new Vector3(5, 3, -5), distance: 16 });
128
+
129
+ const status = make_status_overlay();
130
+
131
+ // give the ECS one frame to settle transforms before baking
132
+ requestAnimationFrame(() => {
133
+ const group = bake_lightmap_for_scene({
134
+ ecd,
135
+ lightmap_resolution: 1024,
136
+ samples_per_texel: 1024,
137
+ min_bounce: 1,
138
+ max_bounce: 4,
139
+ padding: 2,
140
+ });
141
+
142
+ // expose for console poking
143
+ window.lightmap_bake = group;
144
+
145
+ // engine.executor.runGroup(group);
146
+
147
+ // progress readout
148
+ function poll() {
149
+ const p = group.computeProgress();
150
+ status.textContent = `Baking lightmap… ${(p * 100).toFixed(1)}%`;
151
+ if (p < 1) {
152
+ requestAnimationFrame(poll);
153
+ }
154
+ }
155
+
156
+ poll();
157
+ });
158
+ }
159
+
160
+ /**
161
+ * @returns {HTMLDivElement}
162
+ */
163
+ function make_status_overlay() {
164
+ const el = document.createElement("div");
165
+ el.style.position = "fixed";
166
+ el.style.left = "8px";
167
+ el.style.top = "8px";
168
+ el.style.zIndex = "1000";
169
+ el.style.padding = "6px 10px";
170
+ el.style.font = "13px monospace";
171
+ el.style.color = "#fff";
172
+ el.style.background = "rgba(0,0,0,0.55)";
173
+ el.style.borderRadius = "4px";
174
+ el.style.pointerEvents = "none";
175
+ el.textContent = "Preparing bake…";
176
+ document.body.appendChild(el);
177
+ return el;
178
+ }
179
+
180
+ harness.initialize({
181
+ configuration(config) {
182
+
183
+ // config.addPlugin(AmbientOcclusionPostProcessEffect)
184
+
185
+ },
186
+ }).then(main);
@@ -1 +1 @@
1
- {"version":3,"file":"PathTracedMesh.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/PathTracedMesh.js"],"names":[],"mappings":"AAgBA;IACI;;;OAGG;IACH,IAFU,MAAM,CAEO;IAEvB;;;OAGG;IACH,MAFU,KAAK,CAEI;IAEnB;;;OAGG;IACH,KAFU,sBAAoB,IAAI,CAEvB;IAGX;;;OAGG;IACH,UAFU,MAAM,cAAc,GAAC,IAAI,CAEnB;IAEhB;;;OAGG;IACH,UAFU,mBAAiB,IAAI,CAEf;IAYhB,sCAEC;IAED,kCAEC;IAED,2BAqBC;IAED,sBAGC;IAED,iCAUC;IAED,8BAEC;IAED;;;;OAIG;IACH,cAHW,IAAI,GACF,OAAO,CAWnB;IAED;;;;;;OAMG;IACH,SALW,MAAM,EAAE,OACR,MAAM,EAAE,GAAC,IAAI,aACb,MAAM,GACJ,MAAM,CA4BlB;;CACJ;sBA9JqB,wCAAwC;qBAKzC,sCAAsC"}
1
+ {"version":3,"file":"PathTracedMesh.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/PathTracedMesh.js"],"names":[],"mappings":"AAgBA;IACI;;;OAGG;IACH,IAFU,MAAM,CAEO;IAEvB;;;OAGG;IACH,MAFU,KAAK,CAEI;IAEnB;;;OAGG;IACH,KAFU,sBAAoB,IAAI,CAEvB;IAGX;;;OAGG;IACH,UAFU,MAAM,cAAc,GAAC,IAAI,CAEnB;IAEhB;;;OAGG;IACH,UAFU,mBAAiB,IAAI,CAEf;IAYhB,sCAEC;IAED,kCAEC;IAED,2BAqBC;IAED,sBAGC;IAED,iCAUC;IAED,8BAEC;IAED;;;;OAIG;IACH,cAHW,IAAI,GACF,OAAO,CAWnB;IAED;;;;;;OAMG;IACH,SALW,MAAM,EAAE,OACR,MAAM,EAAE,GAAC,IAAI,aACb,MAAM,GACJ,MAAM,CA4BlB;;CACJ;sBA/JqB,wCAAwC;qBAMzC,sCAAsC"}
@@ -1,10 +1,10 @@
1
- import { mat4 } from "gl-matrix";
2
1
  import { array_copy } from "../../../../core/collection/array/array_copy.js";
3
2
  import { AABB3 } from "../../../../core/geom/3d/aabb/AABB3.js";
4
3
  import { aabb3_from_v3_array_transformed } from "../../../../core/geom/3d/aabb/aabb3_from_v3_array_transformed.js";
5
4
  import { m4_allocate } from "../../../../core/geom/3d/mat4/m4_allocate.js";
6
5
  import { m4_decompose } from "../../../../core/geom/3d/mat4/m4_decompose.js";
7
6
  import { m4_normal_matrix3 } from "../../../../core/geom/3d/mat4/m4_normal_matrix3.js";
7
+ import { m4_invert } from "../../../../core/geom/3d/mat4/m4_invert.js";
8
8
  import { Ray3 } from "../../../../core/geom/3d/ray/Ray3.js";
9
9
  import Quaternion from "../../../../core/geom/Quaternion.js";
10
10
  import { v3_distance } from "../../../../core/geom/vec3/v3_distance.js";
@@ -95,7 +95,7 @@ export class PathTracedMesh {
95
95
  set transform(m) {
96
96
  array_copy(m, 0, this.#transform, 0, 16);
97
97
 
98
- mat4.invert(this.#transform_inverse, m);
98
+ m4_invert(this.#transform_inverse, m);
99
99
 
100
100
  m4_normal_matrix3(this.#normal_matrix, this.#transform);
101
101
 
@@ -1,5 +1,5 @@
1
- import { vec3 } from "gl-matrix";
2
1
  import { array_copy } from "../../../../core/collection/array/array_copy.js";
2
+ import { v3_multiply } from "../../../../core/geom/vec3/v3_multiply.js";
3
3
  import { Ray3 } from "../../../../core/geom/3d/ray/Ray3.js";
4
4
  import { getBiasedNormalSample } from "./sampling/getBiasedNormalSample.js";
5
5
 
@@ -112,7 +112,7 @@ export class PathTracer {
112
112
  irradiance[2] += color_mask[2] * tmp_0[8];
113
113
 
114
114
  // fold the surface albedo into the path throughput
115
- vec3.multiply(color_mask, color_mask, tmp_0);
115
+ v3_multiply(color_mask, 0, color_mask[0], color_mask[1], color_mask[2], tmp_0[0], tmp_0[1], tmp_0[2]);
116
116
 
117
117
  // construct new ray, aligned on the normal of the contact
118
118
  array_copy(tmp_0, 3, _ray_0, 3, 3); // copy surface normal into the direction slot (read by sample_lights)
@@ -1 +1 @@
1
- {"version":3,"file":"prepare_scene_gltf.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/prepare_scene_gltf.js"],"names":[],"mappings":"AAaA;;;;;qBAyBC;AAaD;;;;;;;;;;GAUG;AACH,mHAFY,QAAQ,IAAI,CAAC,CA8CxB;oBAnGmB,kCAAkC;iCAErB,qDAAqD"}
1
+ {"version":3,"file":"prepare_scene_gltf.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/prepare_scene_gltf.js"],"names":[],"mappings":"AAeA;;;;;qBAyBC;AAaD;;;;;;;;;;GAUG;AACH,mHAFY,QAAQ,IAAI,CAAC,CA8CxB;oBAnGmB,kCAAkC;iCAErB,qDAAqD"}
@@ -1,9 +1,11 @@
1
- import { vec3 } from "gl-matrix";
2
1
  import { Box3, MeshStandardMaterial, PlaneBufferGeometry, Sphere } from "three";
2
+ import { v3_length } from "../../../../core/geom/vec3/v3_length.js";
3
+ import { v3_scale } from "../../../../core/geom/vec3/v3_scale.js";
3
4
  import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
4
5
  import { Color } from "../../../../core/color/Color.js";
5
6
  import { kelvin_to_rgb } from "../../../../core/color/kelvin/kelvin_to_rgb.js";
6
7
  import { noop } from "../../../../core/function/noop.js";
8
+ import { v3_multiply } from "../../../../core/geom/vec3/v3_multiply.js";
7
9
  import Quaternion from "../../../../core/geom/Quaternion.js";
8
10
  import Vector3 from "../../../../core/geom/Vector3.js";
9
11
  import { Transform } from "../../../ecs/transform/Transform.js";
@@ -25,10 +27,10 @@ export function make_sun({
25
27
  const light = new DirectionalLight();
26
28
 
27
29
  light.color.parse(color);
28
- vec3.multiply(light.color, light.color, temp_c);
30
+ v3_multiply(light.color, 0, light.color[0], light.color[1], light.color[2], temp_c[0], temp_c[1], temp_c[2]);
29
31
 
30
- const n = vec3.length(light.color);
31
- vec3.scale(light.color, light.color, 1 / n); // normalize color vector
32
+ const n = v3_length(light.color[0], light.color[1], light.color[2]);
33
+ v3_scale(light.color, 0, light.color[0], light.color[1], light.color[2], 1 / n); // normalize color vector
32
34
 
33
35
  light.intensity.set(intensity * n);
34
36
  light.direction.copy(direction);
@@ -1,4 +1,4 @@
1
- import { mat4 } from "gl-matrix";
1
+ import { m4_from_rotation_translation_scale } from "../../../../core/geom/3d/mat4/m4_from_rotation_translation_scale.js";
2
2
  import { MeshStandardMaterial, OctahedronBufferGeometry, PerspectiveCamera, PlaneBufferGeometry } from "three";
3
3
  import { PLYLoader } from "three/examples/jsm/loaders/PLYLoader.js";
4
4
 
@@ -313,7 +313,7 @@ async function prepare_scene_rtiow(pt, camera) {
313
313
  function add_sphere(center, radius, material) {
314
314
 
315
315
  const mat = new Float32Array(16);
316
- mat4.fromRotationTranslationScale(mat, [0, 0, 0, 1], center, [radius, radius, radius])
316
+ m4_from_rotation_translation_scale(mat, [0, 0, 0, 1], center, [radius, radius, radius])
317
317
 
318
318
  scene.createMesh(sphere_geo, material, mat);
319
319
 
@@ -357,7 +357,7 @@ async function prepare_scene_rtiow(pt, camera) {
357
357
 
358
358
 
359
359
  const mat = new Float32Array(16);
360
- mat4.fromRotationTranslationScale(mat, [0, 0, 0, 1], center, [radius, radius, radius])
360
+ m4_from_rotation_translation_scale(mat, [0, 0, 0, 1], center, [radius, radius, radius])
361
361
 
362
362
  const material = new MeshStandardMaterial({
363
363
  color: Color.fromHSV(random(), 0.9, 0.9).toHex()
@@ -1 +1 @@
1
- {"version":3,"file":"sample_material.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/path_tracer/texture/sample_material.js"],"names":[],"mappings":"AA6CA;;;;;;;GAOG;AACH,qCANW,MAAM,EAAE,sCAER,MAAM,KACN,MAAM,KACN,MAAM,QA4FhB"}
1
+ {"version":3,"file":"sample_material.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/path_tracer/texture/sample_material.js"],"names":[],"mappings":"AA8CA;;;;;;;GAOG;AACH,qCANW,MAAM,EAAE,sCAER,MAAM,KACN,MAAM,KACN,MAAM,QA4FhB"}
@@ -1,6 +1,7 @@
1
- import { vec3 } from "gl-matrix";
2
1
  import { compute_binary_data_type_from_typed_array } from "../../../../../core/collection/array/typed/compute_binary_data_type_from_typed_array.js";
3
2
  import { v3_distance_sqr } from "../../../../../core/geom/vec3/v3_distance_sqr.js";
3
+ import { v3_multiply } from "../../../../../core/geom/vec3/v3_multiply.js";
4
+ import { v3_normalize_array } from "../../../../../core/geom/vec3/v3_normalize_array.js";
4
5
  import { v3_matrix3_rotate } from "../../../../../core/geom/vec3/v3_matrix3_rotate.js";
5
6
  import { decode_attribute_value } from "../../../geometry/decode_attribute_value.js";
6
7
  import { geometry_construct_triangle_normal } from "../../../geometry/geometry_construct_triangle_normal.js";
@@ -111,7 +112,7 @@ export function sample_material(
111
112
  normal[1] = normal[1] * 2 - 1;
112
113
  normal[2] = normal[2] * 2 - 1;
113
114
 
114
- vec3.normalize(normal, normal);
115
+ v3_normalize_array(normal, 0, normal, 0);
115
116
 
116
117
  // needs transform
117
118
  v3_orthonormal_matrix_from_normal(scratch_m3, 0, out[3], out[4], out[5]);
@@ -126,13 +127,13 @@ export function sample_material(
126
127
  if (color_attribute !== undefined) {
127
128
  sample_color_attribute(color, color_attribute, index_0, index_1, index_2, u, v);
128
129
 
129
- vec3.multiply(out, out, color);
130
+ v3_multiply(out, 0, out[0], out[1], out[2], color[0], color[1], color[2]);
130
131
  }
131
132
 
132
133
 
133
134
  material.diffuse.sample(color, texture_uv[0], texture_uv[1]);
134
135
 
135
- vec3.multiply(out, out, color);
136
+ v3_multiply(out, 0, out[0], out[1], out[2], color[0], color[1], color[2]);
136
137
 
137
138
  // emissive radiance emitted by this surface
138
139
  material.emissive.sample(emissive, texture_uv[0], texture_uv[1]);
@@ -1,4 +1,4 @@
1
- import { vec3 } from "gl-matrix";
1
+ import { v3_normalize_array } from "../../../../../core/geom/vec3/v3_normalize_array.js";
2
2
  import { CanvasView } from "../../../../../view/elements/CanvasView.js";
3
3
  import { Sampler2D } from "../../../texture/sampler/Sampler2D.js";
4
4
  import sampler2D2Canvas from "../../../texture/sampler/sampler2d_to_html_canvas.js";
@@ -52,7 +52,7 @@ for (let i = 0; i < sampler.width; i++) {
52
52
 
53
53
  const direction = [v_x, v_z, v_y];
54
54
 
55
- vec3.normalize(direction, direction);
55
+ v3_normalize_array(direction, 0, direction, 0);
56
56
 
57
57
  sky(color, 0, direction, 0);
58
58
 
@@ -1,14 +1,61 @@
1
- import {InputDeviceSwitch} from "./InputDeviceSwitch";
2
- import Signal from "../../../core/events/signal/Signal";
3
-
4
- export default class KeyboardDevice {
5
- constructor(domElement:EventTarget|Element)
6
-
7
- readonly on: {up:Signal,down:Signal}
8
-
9
- readonly keys:{[key:string]:InputDeviceSwitch}
10
-
11
- start():void
12
-
13
- stop():void
14
- }
1
+ export default KeyboardDevice;
2
+ /**
3
+ * Provides keyboard input.
4
+ * Listens for key events on a DOM element and provides signals and state for key presses.
5
+ * NOTE: if the bound element loses focus within the page (e.g. you hold "A" and click on some other element),
6
+ * the key remains pressed and the eventual physical release is picked up at the window level.
7
+ * NOTE: when the window itself loses focus (e.g. switching to another application), key releases can no longer
8
+ * be observed at all, so any "pressed" keys are forcibly released with the appropriate signal.
9
+ *
10
+ * @author Alex Goldring
11
+ * @copyright Company Named Limited (c) 2026
12
+ */
13
+ declare class KeyboardDevice {
14
+ /**
15
+ * @param {EventTarget|Element} domElement The DOM element to listen for keyboard events on. This element *must* be focusable (e.g., have a `tabindex` attribute).
16
+ * @throws {TypeError} If the provided `domElement` is not focusable and doesn't have a `tabindex` attribute.
17
+ */
18
+ constructor(domElement: EventTarget | Element);
19
+ /**
20
+ * @readonly
21
+ */
22
+ readonly on: {
23
+ /**
24
+ * Fires when any key is pressed
25
+ * @type {Signal<KeyboardEvent>}
26
+ */
27
+ down: Signal<KeyboardEvent>;
28
+ /**
29
+ * Fires when any key is released
30
+ * @type {Signal<KeyboardEvent>}
31
+ */
32
+ up: Signal<KeyboardEvent>;
33
+ };
34
+ /**
35
+ * See {@link KeyCodes} for valid IDs
36
+ * @readonly
37
+ * @type {Object<InputDeviceSwitch>}
38
+ *
39
+ * @example
40
+ * const is_enter_pressed = keyboard.keys.enter.is_down;
41
+ */
42
+ readonly keys: any;
43
+ /**
44
+ * The DOM element being listened to.
45
+ * @type {EventTarget}
46
+ */
47
+ domElement: EventTarget;
48
+ /**
49
+ * Starts listening for keyboard events on the associated DOM element.
50
+ * @returns {void}
51
+ */
52
+ start(): void;
53
+ /**
54
+ * Stops listening for keyboard events.
55
+ * @returns {void}
56
+ */
57
+ stop(): void;
58
+ #private;
59
+ }
60
+ import Signal from "../../../core/events/signal/Signal.js";
61
+ //# sourceMappingURL=KeyboardDevice.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"KeyboardDevice.d.ts","sourceRoot":"","sources":["../../../../../src/engine/input/devices/KeyboardDevice.js"],"names":[],"mappings":";AAYA;;;;;;;;GAQG;AACH;IA4BI;;;OAGG;IACH,wBAHW,WAAW,GAAC,OAAO,EAgC7B;IA3DD;;OAEG;IACH;QACI;;;WAGG;cADO,OAAO,aAAa,CAAC;QAG/B;;;WAGG;YADO,OAAO,aAAa,CAAC;MAGjC;IAEF;;;;;;;OAOG;IACH,mBAAU;IAkBN;;;OAGG;IACH,YAFU,WAAW,CAEO;IA8FhC;;;OAGG;IACH,SAFa,IAAI,CAahB;IAED;;;OAGG;IACH,QAFa,IAAI,CAahB;;CAEJ;mBArMkB,uCAAuC"}
1
+ {"version":3,"file":"KeyboardDevice.d.ts","sourceRoot":"","sources":["../../../../../src/engine/input/devices/KeyboardDevice.js"],"names":[],"mappings":";AAYA;;;;;;;;;;GAUG;AACH;IA4BI;;;OAGG;IACH,wBAHW,WAAW,GAAC,OAAO,EAgC7B;IA3DD;;OAEG;IACH;QACI;;;WAGG;cADO,OAAO,aAAa,CAAC;QAG/B;;;WAGG;YADO,OAAO,aAAa,CAAC;MAGjC;IAEF;;;;;;;OAOG;IACH,mBAAU;IAkBN;;;OAGG;IACH,YAFU,WAAW,CAEO;IA2HhC;;;OAGG;IACH,SAFa,IAAI,CAWhB;IAED;;;OAGG;IACH,QAFa,IAAI,CAUhB;;CAEJ;mBA/NkB,uCAAuC"}
@@ -13,8 +13,10 @@ const codeToKeyNameMap = [];
13
13
  /**
14
14
  * Provides keyboard input.
15
15
  * Listens for key events on a DOM element and provides signals and state for key presses.
16
- * NOTE: when losing focus of the application, any "pressed" keys will be automatically released.
17
- * For example, if you hold "A" and click over into another application window - A will be forcibly released with appropriate signal.
16
+ * NOTE: if the bound element loses focus within the page (e.g. you hold "A" and click on some other element),
17
+ * the key remains pressed and the eventual physical release is picked up at the window level.
18
+ * NOTE: when the window itself loses focus (e.g. switching to another application), key releases can no longer
19
+ * be observed at all, so any "pressed" keys are forcibly released with the appropriate signal.
18
20
  *
19
21
  * @author Alex Goldring
20
22
  * @copyright Company Named Limited (c) 2026
@@ -60,7 +62,7 @@ class KeyboardDevice {
60
62
  !isHTMLElementFocusable(domElement)
61
63
  && domElement.getAttribute('tabindex') === null
62
64
  ) {
63
- new TypeError('Supplied element is not inherently focusable and does not have tabindex attribute, so it must have a tabindex attribute in order to be able receive keyboard events. Something like tabindex=0 would suffice.');
65
+ throw new TypeError('Supplied element is not inherently focusable and does not have tabindex attribute, so it must have a tabindex attribute in order to be able receive keyboard events. Something like tabindex=0 would suffice.');
64
66
  }
65
67
 
66
68
  /**
@@ -149,12 +151,41 @@ class KeyboardDevice {
149
151
 
150
152
  }
151
153
 
154
+ /**
155
+ * Recovery handler for key releases that happen while the bound element does not have focus.
156
+ * Covers the scenario where a key is pressed on the element, focus is then lost to another
157
+ * element in the page (e.g. via a mouse click), and only then is the physical key released.
158
+ * Registered on window in the bubble phase, so for keys released while the element still has
159
+ * focus the element-scoped handler runs first and this one sees the key as already released.
160
+ *
161
+ * @param {KeyboardEvent} event
162
+ */
163
+ #handlerWindowKeyUp = (event) => {
164
+ const keyName = codeToKeyNameMap[event.keyCode];
165
+
166
+ if (keyName === undefined) {
167
+ return;
168
+ }
169
+
170
+ const button = this.keys[keyName];
171
+
172
+ if (button.is_up) {
173
+ // key is not tracked as pressed; either it was never pressed via this device,
174
+ // or the element-scoped handler has already processed this release
175
+ return;
176
+ }
177
+
178
+ this.on.up.send1(event);
179
+
180
+ button.release();
181
+ }
182
+
152
183
  /**
153
184
  *
154
185
  * @param {FocusEvent} event
155
186
  */
156
- #handleGlobalBlurEvent = (event) => {
157
- // Element lost focus, we won't be able to capture key-up events
187
+ #handleWindowBlurEvent = (event) => {
188
+ // Window lost focus, we won't be able to capture key-up events
158
189
  // release all keys
159
190
  for (let keyName in KeyCodes) {
160
191
  this.keys[keyName].release();
@@ -170,12 +201,10 @@ class KeyboardDevice {
170
201
  el.addEventListener(KeyboardEvents.KeyDown, this.#handlerKeyDown);
171
202
  el.addEventListener(KeyboardEvents.KeyUp, this.#handlerKeyUp);
172
203
 
173
- el.addEventListener('blur', this.#handleGlobalBlurEvent);
204
+ // catch releases of tracked keys that happen after the element lost focus within the page
205
+ window.addEventListener(KeyboardEvents.KeyUp, this.#handlerWindowKeyUp);
174
206
 
175
- //https://w3c.github.io/uievents/#event-type-focusout
176
- el.addEventListener('focusout', this.#handleGlobalBlurEvent);
177
-
178
- window.addEventListener('blur', this.#handleGlobalBlurEvent);
207
+ window.addEventListener('blur', this.#handleWindowBlurEvent);
179
208
  }
180
209
 
181
210
  /**
@@ -187,12 +216,9 @@ class KeyboardDevice {
187
216
  el.removeEventListener(KeyboardEvents.KeyDown, this.#handlerKeyDown);
188
217
  el.removeEventListener(KeyboardEvents.KeyUp, this.#handlerKeyUp);
189
218
 
190
- el.removeEventListener('blur', this.#handleGlobalBlurEvent);
191
-
192
- //https://w3c.github.io/uievents/#event-type-focusout
193
- el.removeEventListener('focusout', this.#handleGlobalBlurEvent);
219
+ window.removeEventListener(KeyboardEvents.KeyUp, this.#handlerWindowKeyUp);
194
220
 
195
- window.removeEventListener('blur', this.#handleGlobalBlurEvent);
221
+ window.removeEventListener('blur', this.#handleWindowBlurEvent);
196
222
  }
197
223
 
198
224
  }
@@ -1 +1 @@
1
- {"version":3,"file":"isHTMLElementFocusable.d.ts","sourceRoot":"","sources":["../../../../../src/engine/input/devices/isHTMLElementFocusable.js"],"names":[],"mappings":"AAsBA;;;GAGG;AACH,2CAFW,OAAO,WASjB"}
1
+ {"version":3,"file":"isHTMLElementFocusable.d.ts","sourceRoot":"","sources":["../../../../../src/engine/input/devices/isHTMLElementFocusable.js"],"names":[],"mappings":"AAeA;;;GAGG;AACH,2CAFW,OAAO,WASjB"}
@@ -5,17 +5,10 @@
5
5
  * @returns {boolean}
6
6
  */
7
7
  function isInstanceOf(thing, klass) {
8
- if (klass === undefined) {
8
+ // constructors are functions; the check also guards against the class being absent in the environment
9
+ if (typeof klass !== "function") {
9
10
  return false;
10
11
  }
11
- if (klass === null) {
12
- return false;
13
- }
14
-
15
- if (typeof klass !== "object") {
16
- return false;
17
- }
18
-
19
12
 
20
13
  return thing instanceof klass;
21
14
  }