@woosh/meep-engine 2.138.20 → 2.139.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.
- package/package.json +1 -1
- package/src/core/collection/PairUint32Map.d.ts +100 -0
- package/src/core/collection/PairUint32Map.d.ts.map +1 -0
- package/src/core/collection/PairUint32Map.js +321 -0
- package/src/core/collection/Uint32Map.d.ts +119 -0
- package/src/core/collection/Uint32Map.d.ts.map +1 -0
- package/src/core/collection/Uint32Map.js +345 -0
- package/src/core/collection/array/array_shuffle.d.ts +10 -3
- package/src/core/collection/array/array_shuffle.d.ts.map +1 -1
- package/src/core/collection/array/array_shuffle.js +27 -22
- package/src/core/collection/heap/FibonacciHeap.d.ts +195 -0
- package/src/core/collection/heap/FibonacciHeap.d.ts.map +1 -0
- package/src/core/collection/heap/FibonacciHeap.js +586 -0
- package/src/core/collection/heap/Uint32Heap.js +1 -1
- package/src/core/collection/heap/Uint32Heap4.d.ts +169 -0
- package/src/core/collection/heap/Uint32Heap4.d.ts.map +1 -0
- package/src/core/collection/heap/Uint32Heap4.js +490 -0
- package/src/core/geom/3d/line/line3_closest_points_segment_segment.d.ts +27 -0
- package/src/core/geom/3d/line/line3_closest_points_segment_segment.d.ts.map +1 -0
- package/src/core/geom/3d/line/line3_closest_points_segment_segment.js +88 -0
- package/src/core/geom/3d/shape/BoxShape3D.d.ts +61 -0
- package/src/core/geom/3d/shape/BoxShape3D.d.ts.map +1 -0
- package/src/core/geom/3d/shape/BoxShape3D.js +158 -0
- package/src/core/geom/3d/shape/CapsuleShape3D.d.ts +11 -0
- package/src/core/geom/3d/shape/CapsuleShape3D.d.ts.map +1 -1
- package/src/core/geom/3d/shape/CapsuleShape3D.js +12 -0
- package/src/core/geom/3d/shape/UnitCubeShape3D.d.ts +37 -9
- package/src/core/geom/3d/shape/UnitCubeShape3D.d.ts.map +1 -1
- package/src/core/geom/3d/shape/UnitCubeShape3D.js +45 -98
- package/src/core/geom/3d/shape/UnitSphereShape3D.d.ts +10 -0
- package/src/core/geom/3d/shape/UnitSphereShape3D.d.ts.map +1 -1
- package/src/core/geom/3d/shape/UnitSphereShape3D.js +11 -0
- package/src/core/geom/3d/shape/util/shape3d_voxelize_to_grid.d.ts +61 -0
- package/src/core/geom/3d/shape/util/shape3d_voxelize_to_grid.d.ts.map +1 -0
- package/src/core/geom/3d/shape/util/shape3d_voxelize_to_grid.js +148 -0
- package/src/core/geom/3d/tetrahedra/compute_tetrahedral_mesh_from_surface.d.ts +39 -0
- package/src/core/geom/3d/tetrahedra/compute_tetrahedral_mesh_from_surface.d.ts.map +1 -0
- package/src/core/geom/3d/tetrahedra/compute_tetrahedral_mesh_from_surface.js +147 -0
- package/src/core/geom/3d/tetrahedra/compute_tetrahedron_quality.d.ts +15 -0
- package/src/core/geom/3d/tetrahedra/compute_tetrahedron_quality.d.ts.map +1 -0
- package/src/core/geom/3d/tetrahedra/compute_tetrahedron_quality.js +22 -0
- package/src/core/geom/3d/tetrahedra/prototype_tetrahedrize_mesh.d.ts +2 -0
- package/src/core/geom/3d/tetrahedra/prototype_tetrahedrize_mesh.d.ts.map +1 -0
- package/src/core/geom/3d/tetrahedra/prototype_tetrahedrize_mesh.js +673 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_carve_outside_surface.d.ts +26 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_carve_outside_surface.d.ts.map +1 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_carve_outside_surface.js +222 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_find_tets_around_edge.d.ts +34 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_find_tets_around_edge.d.ts.map +1 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_find_tets_around_edge.js +146 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_flip_23.d.ts +36 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_flip_23.d.ts.map +1 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_flip_23.js +232 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_flip_32.d.ts +33 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_flip_32.d.ts.map +1 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_flip_32.js +255 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_improve_quality.d.ts +68 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_improve_quality.d.ts.map +1 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_improve_quality.js +365 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_smooth_vertex.d.ts +31 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_smooth_vertex.d.ts.map +1 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_smooth_vertex.js +112 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_vertex_is_boundary.d.ts +22 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_vertex_is_boundary.d.ts.map +1 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_vertex_is_boundary.js +55 -0
- package/src/core/geom/3d/tetrahedra/tetrahedron_compute_quality.d.ts +32 -0
- package/src/core/geom/3d/tetrahedra/tetrahedron_compute_quality.d.ts.map +1 -0
- package/src/core/geom/3d/tetrahedra/tetrahedron_compute_quality.js +66 -0
- package/src/core/geom/3d/topology/struct/binary/BinaryElementPool.d.ts +22 -0
- package/src/core/geom/3d/topology/struct/binary/BinaryElementPool.d.ts.map +1 -1
- package/src/core/geom/3d/topology/struct/binary/BinaryElementPool.js +49 -0
- package/src/core/geom/3d/topology/struct/binary/BinaryTopology.d.ts +134 -0
- package/src/core/geom/3d/topology/struct/binary/BinaryTopology.d.ts.map +1 -1
- package/src/core/geom/3d/topology/struct/binary/BinaryTopology.js +276 -3
- package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_close_boundary_holes.d.ts +17 -0
- package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_close_boundary_holes.d.ts.map +1 -0
- package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_close_boundary_holes.js +135 -0
- package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_compact.d.ts +14 -0
- package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_compact.d.ts.map +1 -0
- package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_compact.js +177 -0
- package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_face_decouple.d.ts.map +1 -1
- package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_face_decouple.js +20 -4
- package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_simplify.d.ts.map +1 -1
- package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_simplify.js +5 -3
- package/src/core/geom/3d/topology/struct/binary/io/edge/bt_edge_create.d.ts.map +1 -1
- package/src/core/geom/3d/topology/struct/binary/io/edge/bt_edge_create.js +9 -0
- package/src/core/geom/3d/topology/struct/binary/io/edge/bt_edge_get_or_create.d.ts.map +1 -1
- package/src/core/geom/3d/topology/struct/binary/io/edge/bt_edge_get_or_create.js +21 -45
- package/src/core/geom/3d/topology/struct/binary/io/edge/bt_edge_kill.d.ts.map +1 -1
- package/src/core/geom/3d/topology/struct/binary/io/edge/bt_edge_kill.js +7 -1
- package/src/core/geom/3d/topology/struct/binary/io/edge/bt_edge_kill_parallels.d.ts +8 -6
- package/src/core/geom/3d/topology/struct/binary/io/edge/bt_edge_kill_parallels.d.ts.map +1 -1
- package/src/core/geom/3d/topology/struct/binary/io/edge/bt_edge_kill_parallels.js +8 -6
- package/src/core/geom/3d/topology/struct/binary/io/edge/bt_mesh_kill_short_edges.d.ts +22 -0
- package/src/core/geom/3d/topology/struct/binary/io/edge/bt_mesh_kill_short_edges.d.ts.map +1 -0
- package/src/core/geom/3d/topology/struct/binary/io/edge/bt_mesh_kill_short_edges.js +73 -0
- package/src/core/geom/3d/topology/struct/binary/io/vertex/bt_vertex_replace.d.ts.map +1 -1
- package/src/core/geom/3d/topology/struct/binary/io/vertex/bt_vertex_replace.js +51 -1
- package/src/core/geom/3d/topology/struct/binary/query/bt_edge_get.d.ts +10 -0
- package/src/core/geom/3d/topology/struct/binary/query/bt_edge_get.d.ts.map +1 -0
- package/src/core/geom/3d/topology/struct/binary/query/bt_edge_get.js +42 -0
- package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_sample_interior_grid_points.d.ts +28 -0
- package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_sample_interior_grid_points.d.ts.map +1 -0
- package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_sample_interior_grid_points.js +227 -0
- package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_walk_boundary_loops.d.ts +13 -0
- package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_walk_boundary_loops.d.ts.map +1 -0
- package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_walk_boundary_loops.js +108 -0
- package/src/core/geom/3d/topology/struct/binary/query/bt_query_edge_is_boundary.d.ts +11 -0
- package/src/core/geom/3d/topology/struct/binary/query/bt_query_edge_is_boundary.d.ts.map +1 -0
- package/src/core/geom/3d/topology/struct/binary/query/bt_query_edge_is_boundary.js +20 -0
- package/src/core/geom/3d/triangle/triangle_mesh_compute_signed_volume.d.ts +20 -0
- package/src/core/geom/3d/triangle/triangle_mesh_compute_signed_volume.d.ts.map +1 -0
- package/src/core/geom/3d/triangle/triangle_mesh_compute_signed_volume.js +38 -0
- package/src/core/graph/csr/CSRGraph.d.ts +168 -0
- package/src/core/graph/csr/CSRGraph.d.ts.map +1 -0
- package/src/core/graph/csr/CSRGraph.js +319 -0
- package/src/core/graph/metis/cluster_mesh_metis.d.ts +12 -0
- package/src/core/graph/metis/cluster_mesh_metis.d.ts.map +1 -1
- package/src/core/graph/metis/cluster_mesh_metis.js +12 -0
- package/src/core/graph/metis/metis.d.ts +19 -0
- package/src/core/graph/metis/metis.d.ts.map +1 -1
- package/src/core/graph/metis/metis.js +20 -0
- package/src/core/graph/metis/metis_cluster_bs.d.ts +11 -0
- package/src/core/graph/metis/metis_cluster_bs.d.ts.map +1 -1
- package/src/core/graph/metis/metis_cluster_bs.js +11 -0
- package/src/core/graph/metis/metis_options.d.ts +17 -2
- package/src/core/graph/metis/metis_options.d.ts.map +1 -1
- package/src/core/graph/metis/metis_options.js +17 -2
- package/src/core/graph/metis/native/MetisGraph.d.ts +144 -0
- package/src/core/graph/metis/native/MetisGraph.d.ts.map +1 -0
- package/src/core/graph/metis/native/MetisGraph.js +212 -0
- package/src/core/graph/metis/native/bisection/BisectionScratch.d.ts +72 -0
- package/src/core/graph/metis/native/bisection/BisectionScratch.d.ts.map +1 -0
- package/src/core/graph/metis/native/bisection/BisectionScratch.js +101 -0
- package/src/core/graph/metis/native/bisection/bisect_graph.d.ts +37 -0
- package/src/core/graph/metis/native/bisection/bisect_graph.d.ts.map +1 -0
- package/src/core/graph/metis/native/bisection/bisect_graph.js +100 -0
- package/src/core/graph/metis/native/bisection/compute_2way_params.d.ts +15 -0
- package/src/core/graph/metis/native/bisection/compute_2way_params.d.ts.map +1 -0
- package/src/core/graph/metis/native/bisection/compute_2way_params.js +84 -0
- package/src/core/graph/metis/native/bisection/fm_2way.d.ts +30 -0
- package/src/core/graph/metis/native/bisection/fm_2way.d.ts.map +1 -0
- package/src/core/graph/metis/native/bisection/fm_2way.js +290 -0
- package/src/core/graph/metis/native/bisection/grow_bisection.d.ts +23 -0
- package/src/core/graph/metis/native/bisection/grow_bisection.d.ts.map +1 -0
- package/src/core/graph/metis/native/bisection/grow_bisection.js +137 -0
- package/src/core/graph/metis/native/bisection/split_graph_two_way.d.ts +28 -0
- package/src/core/graph/metis/native/bisection/split_graph_two_way.d.ts.map +1 -0
- package/src/core/graph/metis/native/bisection/split_graph_two_way.js +119 -0
- package/src/core/graph/metis/native/coarsen/coarsen_graph.d.ts +20 -0
- package/src/core/graph/metis/native/coarsen/coarsen_graph.d.ts.map +1 -0
- package/src/core/graph/metis/native/coarsen/coarsen_graph.js +94 -0
- package/src/core/graph/metis/native/coarsen/create_coarse_graph.d.ts +24 -0
- package/src/core/graph/metis/native/coarsen/create_coarse_graph.d.ts.map +1 -0
- package/src/core/graph/metis/native/coarsen/create_coarse_graph.js +158 -0
- package/src/core/graph/metis/native/coarsen/match_shem.d.ts +41 -0
- package/src/core/graph/metis/native/coarsen/match_shem.d.ts.map +1 -0
- package/src/core/graph/metis/native/coarsen/match_shem.js +175 -0
- package/src/core/graph/metis/native/initial/initial_kway_bfs.d.ts +24 -0
- package/src/core/graph/metis/native/initial/initial_kway_bfs.d.ts.map +1 -0
- package/src/core/graph/metis/native/initial/initial_kway_bfs.js +122 -0
- package/src/core/graph/metis/native/initial/initial_kway_recursive_bisection.d.ts +29 -0
- package/src/core/graph/metis/native/initial/initial_kway_recursive_bisection.d.ts.map +1 -0
- package/src/core/graph/metis/native/initial/initial_kway_recursive_bisection.js +170 -0
- package/src/core/graph/metis/native/metis_partition_kway.d.ts +41 -0
- package/src/core/graph/metis/native/metis_partition_kway.d.ts.map +1 -0
- package/src/core/graph/metis/native/metis_partition_kway.js +126 -0
- package/src/core/graph/metis/native/refine/IndexedFloatMaxHeap.d.ts +62 -0
- package/src/core/graph/metis/native/refine/IndexedFloatMaxHeap.d.ts.map +1 -0
- package/src/core/graph/metis/native/refine/IndexedFloatMaxHeap.js +261 -0
- package/src/core/graph/metis/native/refine/RefinementScratch.d.ts +45 -0
- package/src/core/graph/metis/native/refine/RefinementScratch.d.ts.map +1 -0
- package/src/core/graph/metis/native/refine/RefinementScratch.js +53 -0
- package/src/core/graph/metis/native/refine/compute_kway_params.d.ts +18 -0
- package/src/core/graph/metis/native/refine/compute_kway_params.d.ts.map +1 -0
- package/src/core/graph/metis/native/refine/compute_kway_params.js +138 -0
- package/src/core/graph/metis/native/refine/fm_kway.d.ts +63 -0
- package/src/core/graph/metis/native/refine/fm_kway.d.ts.map +1 -0
- package/src/core/graph/metis/native/refine/fm_kway.js +462 -0
- package/src/core/graph/metis/native/refine/project_kway.d.ts +22 -0
- package/src/core/graph/metis/native/refine/project_kway.d.ts.map +1 -0
- package/src/core/graph/metis/native/refine/project_kway.js +43 -0
- package/src/core/graph/metis/native/refine/refine_kway.d.ts +34 -0
- package/src/core/graph/metis/native/refine/refine_kway.d.ts.map +1 -0
- package/src/core/graph/metis/native/refine/refine_kway.js +43 -0
- package/src/core/math/linalg/eigen/matrix_householder_in_place.d.ts +2 -2
- package/src/core/math/linalg/eigen/matrix_householder_in_place.js +2 -2
- package/src/core/math/linalg/eigen/matrix_qr_in_place.d.ts +6 -4
- package/src/core/math/linalg/eigen/matrix_qr_in_place.d.ts.map +1 -1
- package/src/core/math/linalg/eigen/matrix_qr_in_place.js +69 -23
- package/src/engine/EngineHarness.d.ts +3 -1
- package/src/engine/EngineHarness.d.ts.map +1 -1
- package/src/engine/EngineHarness.js +3 -0
- package/src/engine/control/first-person/DESIGN.md +30 -6
- package/src/engine/control/first-person/DESIGN_EXTENSIONS.md +563 -0
- package/src/engine/control/first-person/FirstPersonPlayerController.d.ts +102 -9
- package/src/engine/control/first-person/FirstPersonPlayerController.d.ts.map +1 -1
- package/src/engine/control/first-person/FirstPersonPlayerController.js +38 -3
- package/src/engine/control/first-person/FirstPersonPlayerControllerConfig.d.ts +533 -4
- package/src/engine/control/first-person/FirstPersonPlayerControllerConfig.d.ts.map +1 -1
- package/src/engine/control/first-person/FirstPersonPlayerControllerConfig.js +315 -6
- package/src/engine/control/first-person/FirstPersonPlayerControllerSystem.d.ts +220 -22
- package/src/engine/control/first-person/FirstPersonPlayerControllerSystem.d.ts.map +1 -1
- package/src/engine/control/first-person/FirstPersonPlayerControllerSystem.js +858 -241
- package/src/engine/control/first-person/TODO.md +127 -0
- package/src/engine/control/first-person/abilities/Ability.d.ts +101 -0
- package/src/engine/control/first-person/abilities/Ability.d.ts.map +1 -0
- package/src/engine/control/first-person/abilities/Ability.js +119 -0
- package/src/engine/control/first-person/abilities/AbilitySet.d.ts +86 -0
- package/src/engine/control/first-person/abilities/AbilitySet.d.ts.map +1 -0
- package/src/engine/control/first-person/abilities/AbilitySet.js +185 -0
- package/src/engine/control/first-person/abilities/LedgeGrab.d.ts +62 -0
- package/src/engine/control/first-person/abilities/LedgeGrab.d.ts.map +1 -0
- package/src/engine/control/first-person/abilities/LedgeGrab.js +199 -0
- package/src/engine/control/first-person/abilities/Mantle.d.ts +45 -0
- package/src/engine/control/first-person/abilities/Mantle.d.ts.map +1 -0
- package/src/engine/control/first-person/abilities/Mantle.js +188 -0
- package/src/engine/control/first-person/abilities/Slide.d.ts +33 -0
- package/src/engine/control/first-person/abilities/Slide.d.ts.map +1 -0
- package/src/engine/control/first-person/abilities/Slide.js +158 -0
- package/src/engine/control/first-person/abilities/WallJump.d.ts +45 -0
- package/src/engine/control/first-person/abilities/WallJump.d.ts.map +1 -0
- package/src/engine/control/first-person/abilities/WallJump.js +131 -0
- package/src/engine/control/first-person/abilities/WallRun.d.ts +44 -0
- package/src/engine/control/first-person/abilities/WallRun.d.ts.map +1 -0
- package/src/engine/control/first-person/abilities/WallRun.js +180 -0
- package/src/engine/control/first-person/composer/EyeOffsetStack.d.ts +49 -0
- package/src/engine/control/first-person/composer/EyeOffsetStack.d.ts.map +1 -0
- package/src/engine/control/first-person/composer/EyeOffsetStack.js +60 -0
- package/src/engine/control/first-person/mastery/BreathRhythmEvaluator.d.ts +100 -0
- package/src/engine/control/first-person/mastery/BreathRhythmEvaluator.d.ts.map +1 -0
- package/src/engine/control/first-person/mastery/BreathRhythmEvaluator.js +133 -0
- package/src/engine/control/first-person/mastery/DecisionPoint.d.ts +10 -0
- package/src/engine/control/first-person/mastery/DecisionPoint.d.ts.map +1 -0
- package/src/engine/control/first-person/mastery/DecisionPoint.js +30 -0
- package/src/engine/control/first-person/mastery/FootAsymmetryTurnEvaluator.d.ts +61 -0
- package/src/engine/control/first-person/mastery/FootAsymmetryTurnEvaluator.d.ts.map +1 -0
- package/src/engine/control/first-person/mastery/FootAsymmetryTurnEvaluator.js +109 -0
- package/src/engine/control/first-person/mastery/MasteryEvaluator.d.ts +40 -0
- package/src/engine/control/first-person/mastery/MasteryEvaluator.d.ts.map +1 -0
- package/src/engine/control/first-person/mastery/MasteryEvaluator.js +45 -0
- package/src/engine/control/first-person/mastery/MasteryScore.d.ts +68 -0
- package/src/engine/control/first-person/mastery/MasteryScore.d.ts.map +1 -0
- package/src/engine/control/first-person/mastery/MasteryScore.js +100 -0
- package/src/engine/control/first-person/mastery/MasterySet.d.ts +60 -0
- package/src/engine/control/first-person/mastery/MasterySet.d.ts.map +1 -0
- package/src/engine/control/first-person/mastery/MasterySet.js +86 -0
- package/src/engine/control/first-person/mastery/SlideInitiationTimingEvaluator.d.ts +58 -0
- package/src/engine/control/first-person/mastery/SlideInitiationTimingEvaluator.d.ts.map +1 -0
- package/src/engine/control/first-person/mastery/SlideInitiationTimingEvaluator.js +83 -0
- package/src/engine/control/first-person/mastery/StrideTimingJumpEvaluator.d.ts +69 -0
- package/src/engine/control/first-person/mastery/StrideTimingJumpEvaluator.d.ts.map +1 -0
- package/src/engine/control/first-person/mastery/StrideTimingJumpEvaluator.js +109 -0
- package/src/engine/control/first-person/math/Spring.d.ts +56 -0
- package/src/engine/control/first-person/math/Spring.d.ts.map +1 -0
- package/src/engine/control/first-person/math/Spring.js +71 -0
- package/src/engine/control/first-person/math/computeLRCBreathRate.d.ts +26 -0
- package/src/engine/control/first-person/math/computeLRCBreathRate.d.ts.map +1 -0
- package/src/engine/control/first-person/math/computeLRCBreathRate.js +41 -0
- package/src/engine/control/first-person/math/computeMassRatios.d.ts +35 -0
- package/src/engine/control/first-person/math/computeMassRatios.d.ts.map +1 -0
- package/src/engine/control/first-person/math/computeMassRatios.js +44 -0
- package/src/engine/control/first-person/pose/FirstPersonPose.d.ts +31 -1
- package/src/engine/control/first-person/pose/FirstPersonPose.d.ts.map +1 -1
- package/src/engine/control/first-person/pose/FirstPersonPose.js +49 -3
- package/src/engine/control/first-person/pose/FirstPersonPosture.d.ts +7 -0
- package/src/engine/control/first-person/pose/FirstPersonPosture.d.ts.map +1 -0
- package/src/engine/control/first-person/pose/FirstPersonPosture.js +27 -0
- package/src/engine/control/first-person/prototype_first_person_controller.js +550 -119
- package/src/engine/control/first-person/sensors/FirstPersonSensors.d.ts +58 -0
- package/src/engine/control/first-person/sensors/FirstPersonSensors.d.ts.map +1 -0
- package/src/engine/control/first-person/sensors/FirstPersonSensors.js +77 -0
- package/src/engine/control/first-person/sensors/FirstPersonSensorsSystem.d.ts +80 -0
- package/src/engine/control/first-person/sensors/FirstPersonSensorsSystem.d.ts.map +1 -0
- package/src/engine/control/first-person/sensors/FirstPersonSensorsSystem.js +196 -0
- package/src/engine/control/first-person/test/buildTestPlayer.d.ts +20 -0
- package/src/engine/control/first-person/test/buildTestPlayer.d.ts.map +1 -0
- package/src/engine/control/first-person/test/buildTestPlayer.js +28 -0
- package/src/engine/graphics/camera/testClippingPlaneComputation.js +0 -2
- package/src/engine/graphics/ecs/light/Light.d.ts.map +1 -1
- package/src/engine/graphics/ecs/light/Light.js +27 -0
- package/src/engine/graphics/ecs/light/LightSystem.js +1 -1
- package/src/engine/graphics/ecs/path/PathDisplaySystem.d.ts.map +1 -1
- package/src/engine/graphics/ecs/path/testPathDisplaySystem.js +0 -2
- package/src/engine/graphics/ecs/path/tube/prototypeAnimatedPathMask.js +0 -2
- package/src/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +0 -2
- package/src/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +0 -2
- package/src/engine/graphics/render/visibility/hiz/prototypeHiZ.js +0 -2
- package/src/engine/navigation/grid/find_path_on_grid_astar.d.ts.map +1 -1
- package/src/engine/navigation/grid/find_path_on_grid_astar.js +11 -2
- package/src/engine/navigation/mesh/bt_mesh_face_find_path.d.ts.map +1 -1
- package/src/engine/navigation/mesh/bt_mesh_face_find_path.js +11 -1
- package/src/engine/physics/PLAN.md +236 -0
- package/src/engine/physics/body/BodyStorage.d.ts +187 -0
- package/src/engine/physics/body/BodyStorage.d.ts.map +1 -0
- package/src/engine/physics/body/BodyStorage.js +427 -0
- package/src/engine/physics/broadphase/PairList.d.ts +62 -0
- package/src/engine/physics/broadphase/PairList.d.ts.map +1 -0
- package/src/engine/physics/broadphase/PairList.js +97 -0
- package/src/engine/physics/broadphase/aabb_transform_oriented.d.ts +30 -0
- package/src/engine/physics/broadphase/aabb_transform_oriented.d.ts.map +1 -0
- package/src/engine/physics/broadphase/aabb_transform_oriented.js +93 -0
- package/src/engine/physics/broadphase/compute_fat_world_aabb.d.ts +16 -0
- package/src/engine/physics/broadphase/compute_fat_world_aabb.d.ts.map +1 -0
- package/src/engine/physics/broadphase/compute_fat_world_aabb.js +61 -0
- package/src/engine/physics/broadphase/generate_pairs.d.ts +38 -0
- package/src/engine/physics/broadphase/generate_pairs.d.ts.map +1 -0
- package/src/engine/physics/broadphase/generate_pairs.js +101 -0
- package/src/engine/physics/contact/ManifoldStore.d.ts +226 -0
- package/src/engine/physics/contact/ManifoldStore.d.ts.map +1 -0
- package/src/engine/physics/contact/ManifoldStore.js +499 -0
- package/src/engine/physics/ecs/BodyKind.d.ts +23 -0
- package/src/engine/physics/ecs/BodyKind.d.ts.map +1 -0
- package/src/engine/physics/ecs/BodyKind.js +24 -0
- package/src/engine/physics/ecs/Collider.d.ts +98 -0
- package/src/engine/physics/ecs/Collider.d.ts.map +1 -0
- package/src/engine/physics/ecs/Collider.js +136 -0
- package/src/engine/physics/ecs/ColliderFlags.d.ts +14 -0
- package/src/engine/physics/ecs/ColliderFlags.d.ts.map +1 -0
- package/src/engine/physics/ecs/ColliderFlags.js +15 -0
- package/src/engine/physics/ecs/ColliderObserverSystem.d.ts +58 -0
- package/src/engine/physics/ecs/ColliderObserverSystem.d.ts.map +1 -0
- package/src/engine/physics/ecs/ColliderObserverSystem.js +103 -0
- package/src/engine/physics/ecs/ColliderSerializationAdapter.d.ts +25 -0
- package/src/engine/physics/ecs/ColliderSerializationAdapter.d.ts.map +1 -0
- package/src/engine/physics/ecs/ColliderSerializationAdapter.js +37 -0
- package/src/engine/physics/ecs/PhysicsEvents.d.ts +15 -0
- package/src/engine/physics/ecs/PhysicsEvents.d.ts.map +1 -0
- package/src/engine/physics/ecs/PhysicsEvents.js +16 -0
- package/src/engine/physics/ecs/PhysicsSystem.d.ts +520 -0
- package/src/engine/physics/ecs/PhysicsSystem.d.ts.map +1 -0
- package/src/engine/physics/ecs/PhysicsSystem.js +1159 -0
- package/src/engine/physics/ecs/RigidBody.d.ts +197 -0
- package/src/engine/physics/ecs/RigidBody.d.ts.map +1 -0
- package/src/engine/physics/ecs/RigidBody.js +240 -0
- package/src/engine/physics/ecs/RigidBodyFlags.d.ts +21 -0
- package/src/engine/physics/ecs/RigidBodyFlags.d.ts.map +1 -0
- package/src/engine/physics/ecs/RigidBodyFlags.js +22 -0
- package/src/engine/physics/ecs/RigidBodySerializationAdapter.d.ts +28 -0
- package/src/engine/physics/ecs/RigidBodySerializationAdapter.d.ts.map +1 -0
- package/src/engine/physics/ecs/RigidBodySerializationAdapter.js +81 -0
- package/src/engine/physics/ecs/SleepState.d.ts +11 -0
- package/src/engine/physics/ecs/SleepState.d.ts.map +1 -0
- package/src/engine/physics/ecs/SleepState.js +12 -0
- package/src/engine/physics/events/ContactEventBuffer.d.ts +46 -0
- package/src/engine/physics/events/ContactEventBuffer.d.ts.map +1 -0
- package/src/engine/physics/events/ContactEventBuffer.js +83 -0
- package/src/engine/physics/events/diff_manifolds.d.ts +25 -0
- package/src/engine/physics/events/diff_manifolds.d.ts.map +1 -0
- package/src/engine/physics/events/diff_manifolds.js +50 -0
- package/src/engine/physics/fluid/FluidField.d.ts +294 -16
- package/src/engine/physics/fluid/FluidField.d.ts.map +1 -1
- package/src/engine/physics/fluid/FluidField.js +510 -66
- package/src/engine/physics/fluid/FluidSimulator.d.ts +188 -5
- package/src/engine/physics/fluid/FluidSimulator.d.ts.map +1 -1
- package/src/engine/physics/fluid/FluidSimulator.js +455 -95
- package/src/engine/physics/fluid/SliceVisualiser.d.ts +29 -6
- package/src/engine/physics/fluid/SliceVisualiser.d.ts.map +1 -1
- package/src/engine/physics/fluid/SliceVisualiser.js +190 -165
- package/src/engine/physics/fluid/ecs/FluidComponent.d.ts +154 -0
- package/src/engine/physics/fluid/ecs/FluidComponent.d.ts.map +1 -0
- package/src/engine/physics/fluid/ecs/FluidComponent.js +238 -0
- package/src/engine/physics/fluid/ecs/FluidEffectorsComponent.d.ts +45 -0
- package/src/engine/physics/fluid/ecs/FluidEffectorsComponent.d.ts.map +1 -0
- package/src/engine/physics/fluid/ecs/FluidEffectorsComponent.js +89 -0
- package/src/engine/physics/fluid/ecs/FluidSystem.d.ts +107 -0
- package/src/engine/physics/fluid/ecs/FluidSystem.d.ts.map +1 -0
- package/src/engine/physics/fluid/ecs/FluidSystem.js +278 -0
- package/src/engine/physics/fluid/effector/AbstractFluidEffector.d.ts +62 -1
- package/src/engine/physics/fluid/effector/AbstractFluidEffector.d.ts.map +1 -1
- package/src/engine/physics/fluid/effector/AbstractFluidEffector.js +81 -6
- package/src/engine/physics/fluid/effector/GlobalFluidEffector.d.ts +17 -4
- package/src/engine/physics/fluid/effector/GlobalFluidEffector.d.ts.map +1 -1
- package/src/engine/physics/fluid/effector/GlobalFluidEffector.js +105 -12
- package/src/engine/physics/fluid/effector/ImpulseFluidEffector.d.ts +43 -0
- package/src/engine/physics/fluid/effector/ImpulseFluidEffector.d.ts.map +1 -0
- package/src/engine/physics/fluid/effector/ImpulseFluidEffector.js +210 -0
- package/src/engine/physics/fluid/effector/WakeFluidEffector.d.ts +62 -1
- package/src/engine/physics/fluid/effector/WakeFluidEffector.d.ts.map +1 -1
- package/src/engine/physics/fluid/effector/WakeFluidEffector.js +302 -8
- package/src/engine/physics/fluid/prototype.js +102 -91
- package/src/engine/physics/fluid/solver/optimal_sor_omega.d.ts +33 -0
- package/src/engine/physics/fluid/solver/optimal_sor_omega.d.ts.map +1 -0
- package/src/engine/physics/fluid/solver/optimal_sor_omega.js +41 -0
- package/src/engine/physics/fluid/solver/v3_grid_apply_advection_forward.d.ts +20 -5
- package/src/engine/physics/fluid/solver/v3_grid_apply_advection_forward.d.ts.map +1 -1
- package/src/engine/physics/fluid/solver/v3_grid_apply_advection_forward.js +60 -38
- package/src/engine/physics/fluid/solver/v3_grid_apply_diffusion.d.ts +25 -4
- package/src/engine/physics/fluid/solver/v3_grid_apply_diffusion.d.ts.map +1 -1
- package/src/engine/physics/fluid/solver/v3_grid_apply_diffusion.js +93 -73
- package/src/engine/physics/fluid/solver/v3_grid_apply_scalar_advection.d.ts +23 -0
- package/src/engine/physics/fluid/solver/v3_grid_apply_scalar_advection.d.ts.map +1 -0
- package/src/engine/physics/fluid/solver/v3_grid_apply_scalar_advection.js +60 -0
- package/src/engine/physics/fluid/solver/v3_grid_compute_divergence.d.ts +23 -0
- package/src/engine/physics/fluid/solver/v3_grid_compute_divergence.d.ts.map +1 -0
- package/src/engine/physics/fluid/solver/v3_grid_compute_divergence.js +68 -0
- package/src/engine/physics/fluid/solver/v3_grid_compute_solid_neighbour_mask.d.ts +30 -0
- package/src/engine/physics/fluid/solver/v3_grid_compute_solid_neighbour_mask.d.ts.map +1 -0
- package/src/engine/physics/fluid/solver/v3_grid_compute_solid_neighbour_mask.js +66 -0
- package/src/engine/physics/fluid/solver/v3_grid_patch_edges_uniform.d.ts +26 -0
- package/src/engine/physics/fluid/solver/v3_grid_patch_edges_uniform.d.ts.map +1 -0
- package/src/engine/physics/fluid/solver/v3_grid_patch_edges_uniform.js +113 -0
- package/src/engine/physics/fluid/solver/v3_grid_shift_in_place.d.ts +30 -0
- package/src/engine/physics/fluid/solver/v3_grid_shift_in_place.d.ts.map +1 -0
- package/src/engine/physics/fluid/solver/v3_grid_shift_in_place.js +107 -0
- package/src/engine/physics/fluid/solver/v3_grid_solve_pressure.d.ts +49 -0
- package/src/engine/physics/fluid/solver/v3_grid_solve_pressure.d.ts.map +1 -0
- package/src/engine/physics/fluid/solver/v3_grid_solve_pressure.js +126 -0
- package/src/engine/physics/fluid/solver/v3_grid_solve_pressure_pcg.d.ts +93 -0
- package/src/engine/physics/fluid/solver/v3_grid_solve_pressure_pcg.d.ts.map +1 -0
- package/src/engine/physics/fluid/solver/v3_grid_solve_pressure_pcg.js +424 -0
- package/src/engine/physics/fluid/solver/v3_grid_solve_pressure_unmasked_legacy.d.ts +20 -0
- package/src/engine/physics/fluid/solver/v3_grid_solve_pressure_unmasked_legacy.d.ts.map +1 -0
- package/src/engine/physics/fluid/solver/v3_grid_solve_pressure_unmasked_legacy.js +83 -0
- package/src/engine/physics/fluid/solver/v3_grid_subtract_pressure_gradient.d.ts +26 -0
- package/src/engine/physics/fluid/solver/v3_grid_subtract_pressure_gradient.d.ts.map +1 -0
- package/src/engine/physics/fluid/solver/v3_grid_subtract_pressure_gradient.js +70 -0
- package/src/engine/physics/gjk/expanding_polytope_algorithm.d.ts.map +1 -1
- package/src/engine/physics/gjk/expanding_polytope_algorithm.js +8 -10
- package/src/engine/physics/inertia/world_inverse_inertia.d.ts +29 -0
- package/src/engine/physics/inertia/world_inverse_inertia.d.ts.map +1 -0
- package/src/engine/physics/inertia/world_inverse_inertia.js +79 -0
- package/src/engine/physics/integration/integrate_position.d.ts +16 -0
- package/src/engine/physics/integration/integrate_position.d.ts.map +1 -0
- package/src/engine/physics/integration/integrate_position.js +48 -0
- package/src/engine/physics/integration/integrate_velocity.d.ts +25 -0
- package/src/engine/physics/integration/integrate_velocity.d.ts.map +1 -0
- package/src/engine/physics/integration/integrate_velocity.js +79 -0
- package/src/engine/physics/integration/quat_integrate.d.ts +27 -0
- package/src/engine/physics/integration/quat_integrate.d.ts.map +1 -0
- package/src/engine/physics/integration/quat_integrate.js +62 -0
- package/src/engine/physics/island/IslandBuilder.d.ts +167 -0
- package/src/engine/physics/island/IslandBuilder.d.ts.map +1 -0
- package/src/engine/physics/island/IslandBuilder.js +411 -0
- package/src/engine/physics/island/union_find.d.ts +51 -0
- package/src/engine/physics/island/union_find.d.ts.map +1 -0
- package/src/engine/physics/island/union_find.js +76 -0
- package/src/engine/physics/narrowphase/PosedShape.d.ts +59 -0
- package/src/engine/physics/narrowphase/PosedShape.d.ts.map +1 -0
- package/src/engine/physics/narrowphase/PosedShape.js +110 -0
- package/src/engine/physics/narrowphase/box_box_manifold.d.ts +32 -0
- package/src/engine/physics/narrowphase/box_box_manifold.d.ts.map +1 -0
- package/src/engine/physics/narrowphase/box_box_manifold.js +543 -0
- package/src/engine/physics/narrowphase/capsule_contacts.d.ts +122 -0
- package/src/engine/physics/narrowphase/capsule_contacts.d.ts.map +1 -0
- package/src/engine/physics/narrowphase/capsule_contacts.js +508 -0
- package/src/engine/physics/narrowphase/narrowphase_step.d.ts +11 -0
- package/src/engine/physics/narrowphase/narrowphase_step.d.ts.map +1 -0
- package/src/engine/physics/narrowphase/narrowphase_step.js +382 -0
- package/src/engine/physics/narrowphase/sphere_box_contact.d.ts +38 -0
- package/src/engine/physics/narrowphase/sphere_box_contact.d.ts.map +1 -0
- package/src/engine/physics/narrowphase/sphere_box_contact.js +130 -0
- package/src/engine/physics/narrowphase/sphere_sphere_contact.d.ts +26 -0
- package/src/engine/physics/narrowphase/sphere_sphere_contact.d.ts.map +1 -0
- package/src/engine/physics/narrowphase/sphere_sphere_contact.js +51 -0
- package/src/engine/physics/queries/PhysicsSurfacePoint.d.ts +83 -0
- package/src/engine/physics/queries/PhysicsSurfacePoint.d.ts.map +1 -0
- package/src/engine/physics/queries/PhysicsSurfacePoint.js +100 -0
- package/src/engine/physics/queries/raycast.d.ts +20 -0
- package/src/engine/physics/queries/raycast.d.ts.map +1 -0
- package/src/engine/physics/queries/raycast.js +249 -0
- package/src/engine/physics/solver/friction_cone.d.ts +16 -0
- package/src/engine/physics/solver/friction_cone.d.ts.map +1 -0
- package/src/engine/physics/solver/friction_cone.js +37 -0
- package/src/engine/physics/solver/solve_contacts.d.ts +36 -0
- package/src/engine/physics/solver/solve_contacts.d.ts.map +1 -0
- package/src/engine/physics/solver/solve_contacts.js +598 -0
- package/src/core/geom/3d/topology/struct/binary/io/edge/OrderedEdge.d.ts +0 -34
- package/src/core/geom/3d/topology/struct/binary/io/edge/OrderedEdge.d.ts.map +0 -1
- package/src/core/geom/3d/topology/struct/binary/io/edge/OrderedEdge.js +0 -66
- package/src/core/geom/3d/topology/struct/binary/io/edge/bt_mesh_calc_edges.d.ts +0 -2
- package/src/core/geom/3d/topology/struct/binary/io/edge/bt_mesh_calc_edges.d.ts.map +0 -1
- package/src/core/geom/3d/topology/struct/binary/io/edge/bt_mesh_calc_edges.js +0 -54
- package/src/core/geom/3d/topology/struct/binary/io/edge/get_or_create_edge_map.d.ts +0 -2
- package/src/core/geom/3d/topology/struct/binary/io/edge/get_or_create_edge_map.d.ts.map +0 -1
- package/src/core/geom/3d/topology/struct/binary/io/edge/get_or_create_edge_map.js +0 -26
- package/src/engine/ecs/components/Motion.d.ts +0 -21
- package/src/engine/ecs/components/Motion.d.ts.map +0 -1
- package/src/engine/ecs/components/Motion.js +0 -27
- package/src/engine/ecs/components/MotionSerializationAdapter.d.ts +0 -20
- package/src/engine/ecs/components/MotionSerializationAdapter.d.ts.map +0 -1
- package/src/engine/ecs/components/MotionSerializationAdapter.js +0 -26
- package/src/engine/ecs/systems/MotionSystem.d.ts +0 -9
- package/src/engine/ecs/systems/MotionSystem.d.ts.map +0 -1
- package/src/engine/ecs/systems/MotionSystem.js +0 -29
- package/src/engine/physics/fluid/Fluid.d.ts +0 -26
- package/src/engine/physics/fluid/Fluid.d.ts.map +0 -1
- package/src/engine/physics/fluid/Fluid.js +0 -221
- package/src/engine/physics/fluid/solver/v3_grid_apply_advection_reverse.d.ts +0 -7
- package/src/engine/physics/fluid/solver/v3_grid_apply_advection_reverse.d.ts.map +0 -1
- package/src/engine/physics/fluid/solver/v3_grid_apply_advection_reverse.js +0 -8
|
@@ -0,0 +1,543 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-point manifold construction for two oriented bounding boxes.
|
|
3
|
+
*
|
|
4
|
+
* Algorithm:
|
|
5
|
+
* 1. SAT over the canonical 15 axes (3 face normals of A, 3 of B, 9 edge-pair
|
|
6
|
+
* crosses) to find the smallest-overlap axis and remember whether it came
|
|
7
|
+
* from a face normal of A, a face normal of B, or an edge-pair cross.
|
|
8
|
+
* 2. Face axis ⇒ identify a reference face (on the box that owned the axis)
|
|
9
|
+
* and an incident face (on the opposite box, the face whose outward
|
|
10
|
+
* normal is most antiparallel to the contact normal). Project the four
|
|
11
|
+
* incident corners into the reference face's 2-D coordinate frame and
|
|
12
|
+
* clip the resulting quad against the reference face rectangle via
|
|
13
|
+
* Sutherland-Hodgman. Each surviving vertex with positive penetration
|
|
14
|
+
* becomes a contact point.
|
|
15
|
+
* 3. Edge-cross axis ⇒ a single contact at the body-centre midpoint
|
|
16
|
+
* (v1 fallback; closest-edge-points refinement is a follow-up).
|
|
17
|
+
* 4. If more than {@link MAX_CONTACTS} survive, reduce by picking the
|
|
18
|
+
* deepest first, then three more that maximise the perimeter of the
|
|
19
|
+
* resulting quad.
|
|
20
|
+
*
|
|
21
|
+
* Contact convention (matches the manifold cache): the normal points from
|
|
22
|
+
* box B toward box A; positive depth means penetration.
|
|
23
|
+
*
|
|
24
|
+
* Output layout:
|
|
25
|
+
* out[0..2] : world normal
|
|
26
|
+
* out[3] : contact count (0 .. {@link MAX_CONTACTS})
|
|
27
|
+
* out[4 + k*7 + 0..2] : world contact on A's surface
|
|
28
|
+
* out[4 + k*7 + 3..5] : world contact on B's surface
|
|
29
|
+
* out[4 + k*7 + 6] : penetration depth (positive)
|
|
30
|
+
*
|
|
31
|
+
* @author Alex Goldring
|
|
32
|
+
* @copyright Company Named Limited (c) 2026
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
const MAX_CONTACTS = 4;
|
|
36
|
+
const CONTACT_STRIDE = 7;
|
|
37
|
+
const PARALLEL_EPS_SQR = 1e-8;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Length of `out` required by {@link box_box_manifold}.
|
|
41
|
+
* @type {number}
|
|
42
|
+
*/
|
|
43
|
+
export const BOX_BOX_OUT_LENGTH = 4 + MAX_CONTACTS * CONTACT_STRIDE;
|
|
44
|
+
|
|
45
|
+
// --- shared scratch storage -------------------------------------------------
|
|
46
|
+
|
|
47
|
+
const scratch_axes_a = new Float64Array(9);
|
|
48
|
+
const scratch_axes_b = new Float64Array(9);
|
|
49
|
+
|
|
50
|
+
// 4 incident face corners in world space.
|
|
51
|
+
const incident_world = new Float64Array(12);
|
|
52
|
+
// Clipped polygon — worst case 8 vertices (quad clipped by 4 planes).
|
|
53
|
+
const clip_in = new Float64Array(8 * 3);
|
|
54
|
+
const clip_out = new Float64Array(8 * 3);
|
|
55
|
+
// 2-D projection of incident corners onto reference-face uv plane.
|
|
56
|
+
const incident_uv = new Float64Array(8 * 2);
|
|
57
|
+
const clipped_uv_in = new Float64Array(8 * 2);
|
|
58
|
+
const clipped_uv_out = new Float64Array(8 * 2);
|
|
59
|
+
|
|
60
|
+
// Surviving 3-D contact points along with their (signed) depth.
|
|
61
|
+
// Stride 4 per candidate: x, y, z, depth.
|
|
62
|
+
const candidates = new Float64Array(8 * 4);
|
|
63
|
+
|
|
64
|
+
// --- helpers ---------------------------------------------------------------
|
|
65
|
+
|
|
66
|
+
function quat_to_axes(out, off, qx, qy, qz, qw) {
|
|
67
|
+
const xx = qx * qx, yy = qy * qy, zz = qz * qz;
|
|
68
|
+
const xy = qx * qy, xz = qx * qz, yz = qy * qz;
|
|
69
|
+
const wx = qw * qx, wy = qw * qy, wz = qw * qz;
|
|
70
|
+
out[off] = 1 - 2 * (yy + zz); out[off + 1] = 2 * (xy + wz); out[off + 2] = 2 * (xz - wy);
|
|
71
|
+
out[off + 3] = 2 * (xy - wz); out[off + 4] = 1 - 2 * (xx + zz); out[off + 5] = 2 * (yz + wx);
|
|
72
|
+
out[off + 6] = 2 * (xz + wy); out[off + 7] = 2 * (yz - wx); out[off + 8] = 1 - 2 * (xx + yy);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function projected_half_extent(axes, off, hx, hy, hz, lx, ly, lz) {
|
|
76
|
+
const px = lx * axes[off] + ly * axes[off + 1] + lz * axes[off + 2];
|
|
77
|
+
const py = lx * axes[off + 3] + ly * axes[off + 4] + lz * axes[off + 5];
|
|
78
|
+
const pz = lx * axes[off + 6] + ly * axes[off + 7] + lz * axes[off + 8];
|
|
79
|
+
return (px < 0 ? -px : px) * hx
|
|
80
|
+
+ (py < 0 ? -py : py) * hy
|
|
81
|
+
+ (pz < 0 ? -pz : pz) * hz;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Sutherland-Hodgman clip of `points_in_uv` (point_count vertices, stride 2)
|
|
86
|
+
* against the half-plane `coord_idx ≤ bound` (or `coord_idx ≥ bound` when
|
|
87
|
+
* `keep_below` is false). Result is written to `points_out_uv`, returns the
|
|
88
|
+
* vertex count.
|
|
89
|
+
*
|
|
90
|
+
* @param {Float64Array} points_in
|
|
91
|
+
* @param {number} point_count
|
|
92
|
+
* @param {Float64Array} points_out
|
|
93
|
+
* @param {number} coord_idx 0 = u, 1 = v
|
|
94
|
+
* @param {number} bound
|
|
95
|
+
* @param {boolean} keep_below true to keep points with coord ≤ bound
|
|
96
|
+
* @returns {number} surviving vertex count
|
|
97
|
+
*/
|
|
98
|
+
function clip_against_axis(points_in, point_count, points_out, coord_idx, bound, keep_below) {
|
|
99
|
+
let out_count = 0;
|
|
100
|
+
for (let i = 0; i < point_count; i++) {
|
|
101
|
+
const j = (i + 1) % point_count;
|
|
102
|
+
const ax = points_in[i * 2], ay = points_in[i * 2 + 1];
|
|
103
|
+
const bx = points_in[j * 2], by = points_in[j * 2 + 1];
|
|
104
|
+
const av = coord_idx === 0 ? ax : ay;
|
|
105
|
+
const bv = coord_idx === 0 ? bx : by;
|
|
106
|
+
const a_inside = keep_below ? (av <= bound) : (av >= bound);
|
|
107
|
+
const b_inside = keep_below ? (bv <= bound) : (bv >= bound);
|
|
108
|
+
|
|
109
|
+
if (a_inside) {
|
|
110
|
+
// emit a
|
|
111
|
+
points_out[out_count * 2] = ax;
|
|
112
|
+
points_out[out_count * 2 + 1] = ay;
|
|
113
|
+
out_count++;
|
|
114
|
+
}
|
|
115
|
+
if (a_inside !== b_inside) {
|
|
116
|
+
// emit intersection on the bounding line
|
|
117
|
+
// Parameterise: p(t) = a + t * (b - a); solve coord(p(t)) = bound.
|
|
118
|
+
const denom = bv - av;
|
|
119
|
+
const t = denom !== 0 ? (bound - av) / denom : 0;
|
|
120
|
+
points_out[out_count * 2] = ax + (bx - ax) * t;
|
|
121
|
+
points_out[out_count * 2 + 1] = ay + (by - ay) * t;
|
|
122
|
+
out_count++;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return out_count;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// --- main -------------------------------------------------------------------
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
*
|
|
132
|
+
* @param {number[]|Float64Array} out length >= BOX_BOX_OUT_LENGTH
|
|
133
|
+
* @param {number} ax centre x of A
|
|
134
|
+
* @param {number} ay
|
|
135
|
+
* @param {number} az
|
|
136
|
+
* @param {number} aqx A rotation quaternion x
|
|
137
|
+
* @param {number} aqy
|
|
138
|
+
* @param {number} aqz
|
|
139
|
+
* @param {number} aqw
|
|
140
|
+
* @param {number} ahx A half-extent x in body frame
|
|
141
|
+
* @param {number} ahy
|
|
142
|
+
* @param {number} ahz
|
|
143
|
+
* @param {number} bx centre x of B
|
|
144
|
+
* @param {number} by
|
|
145
|
+
* @param {number} bz
|
|
146
|
+
* @param {number} bqx
|
|
147
|
+
* @param {number} bqy
|
|
148
|
+
* @param {number} bqz
|
|
149
|
+
* @param {number} bqw
|
|
150
|
+
* @param {number} bhx
|
|
151
|
+
* @param {number} bhy
|
|
152
|
+
* @param {number} bhz
|
|
153
|
+
* @returns {boolean} true if overlap
|
|
154
|
+
*/
|
|
155
|
+
export function box_box_manifold(
|
|
156
|
+
out,
|
|
157
|
+
ax, ay, az, aqx, aqy, aqz, aqw, ahx, ahy, ahz,
|
|
158
|
+
bx, by, bz, bqx, bqy, bqz, bqw, bhx, bhy, bhz
|
|
159
|
+
) {
|
|
160
|
+
quat_to_axes(scratch_axes_a, 0, aqx, aqy, aqz, aqw);
|
|
161
|
+
quat_to_axes(scratch_axes_b, 0, bqx, bqy, bqz, bqw);
|
|
162
|
+
|
|
163
|
+
const ta = scratch_axes_a;
|
|
164
|
+
const tb = scratch_axes_b;
|
|
165
|
+
|
|
166
|
+
const dx = bx - ax;
|
|
167
|
+
const dy = by - ay;
|
|
168
|
+
const dz = bz - az;
|
|
169
|
+
|
|
170
|
+
// SAT — track winning axis + source.
|
|
171
|
+
// source: 0..2 = A face normal, 3..5 = B face normal, 6..14 = edge cross.
|
|
172
|
+
let best_overlap = Infinity;
|
|
173
|
+
let best_nx = 0, best_ny = 0, best_nz = 0;
|
|
174
|
+
let best_source = -1;
|
|
175
|
+
|
|
176
|
+
function test_axis(lx, ly, lz, source) {
|
|
177
|
+
const len_sqr = lx * lx + ly * ly + lz * lz;
|
|
178
|
+
if (len_sqr < PARALLEL_EPS_SQR) return false;
|
|
179
|
+
const inv_len = 1 / Math.sqrt(len_sqr);
|
|
180
|
+
const ux = lx * inv_len, uy = ly * inv_len, uz = lz * inv_len;
|
|
181
|
+
const rA = projected_half_extent(ta, 0, ahx, ahy, ahz, ux, uy, uz);
|
|
182
|
+
const rB = projected_half_extent(tb, 0, bhx, bhy, bhz, ux, uy, uz);
|
|
183
|
+
const proj = dx * ux + dy * uy + dz * uz;
|
|
184
|
+
const dist = proj < 0 ? -proj : proj;
|
|
185
|
+
const overlap = (rA + rB) - dist;
|
|
186
|
+
if (overlap < 0) return true;
|
|
187
|
+
if (overlap < best_overlap) {
|
|
188
|
+
best_overlap = overlap;
|
|
189
|
+
const sign = proj > 0 ? -1 : 1; // normal points B→A
|
|
190
|
+
best_nx = ux * sign;
|
|
191
|
+
best_ny = uy * sign;
|
|
192
|
+
best_nz = uz * sign;
|
|
193
|
+
best_source = source;
|
|
194
|
+
}
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (test_axis(ta[0], ta[1], ta[2], 0)) return false;
|
|
199
|
+
if (test_axis(ta[3], ta[4], ta[5], 1)) return false;
|
|
200
|
+
if (test_axis(ta[6], ta[7], ta[8], 2)) return false;
|
|
201
|
+
if (test_axis(tb[0], tb[1], tb[2], 3)) return false;
|
|
202
|
+
if (test_axis(tb[3], tb[4], tb[5], 4)) return false;
|
|
203
|
+
if (test_axis(tb[6], tb[7], tb[8], 5)) return false;
|
|
204
|
+
|
|
205
|
+
for (let i = 0; i < 3; i++) {
|
|
206
|
+
const aix = ta[i * 3], aiy = ta[i * 3 + 1], aiz = ta[i * 3 + 2];
|
|
207
|
+
for (let j = 0; j < 3; j++) {
|
|
208
|
+
const bjx = tb[j * 3], bjy = tb[j * 3 + 1], bjz = tb[j * 3 + 2];
|
|
209
|
+
const cx = aiy * bjz - aiz * bjy;
|
|
210
|
+
const cy = aiz * bjx - aix * bjz;
|
|
211
|
+
const cz = aix * bjy - aiy * bjx;
|
|
212
|
+
if (test_axis(cx, cy, cz, 6 + i * 3 + j)) return false;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// We have a contact. Output the normal.
|
|
217
|
+
const nx = best_nx, ny = best_ny, nz = best_nz;
|
|
218
|
+
out[0] = nx; out[1] = ny; out[2] = nz;
|
|
219
|
+
|
|
220
|
+
// ---- Edge-cross axis: single-point fallback ----
|
|
221
|
+
if (best_source >= 6) {
|
|
222
|
+
const mx = (ax + bx) * 0.5;
|
|
223
|
+
const my = (ay + by) * 0.5;
|
|
224
|
+
const mz = (az + bz) * 0.5;
|
|
225
|
+
out[3] = 1;
|
|
226
|
+
out[4] = mx; out[5] = my; out[6] = mz;
|
|
227
|
+
out[7] = mx; out[8] = my; out[9] = mz;
|
|
228
|
+
out[10] = best_overlap;
|
|
229
|
+
return true;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// ---- Face axis: face clipping ----
|
|
233
|
+
// Determine reference and incident.
|
|
234
|
+
const ref_is_A = best_source < 3;
|
|
235
|
+
// Reference axis index in the owning box (0..2).
|
|
236
|
+
const ref_axis_idx = ref_is_A ? best_source : best_source - 3;
|
|
237
|
+
|
|
238
|
+
// Reference box pose.
|
|
239
|
+
const ref_axes = ref_is_A ? ta : tb;
|
|
240
|
+
const inc_axes = ref_is_A ? tb : ta;
|
|
241
|
+
const ref_h_x = ref_is_A ? ahx : bhx;
|
|
242
|
+
const ref_h_y = ref_is_A ? ahy : bhy;
|
|
243
|
+
const ref_h_z = ref_is_A ? ahz : bhz;
|
|
244
|
+
const inc_h_x = ref_is_A ? bhx : ahx;
|
|
245
|
+
const inc_h_y = ref_is_A ? bhy : ahy;
|
|
246
|
+
const inc_h_z = ref_is_A ? bhz : ahz;
|
|
247
|
+
const ref_cx = ref_is_A ? ax : bx;
|
|
248
|
+
const ref_cy = ref_is_A ? ay : by;
|
|
249
|
+
const ref_cz = ref_is_A ? az : bz;
|
|
250
|
+
const inc_cx = ref_is_A ? bx : ax;
|
|
251
|
+
const inc_cy = ref_is_A ? by : ay;
|
|
252
|
+
const inc_cz = ref_is_A ? bz : az;
|
|
253
|
+
|
|
254
|
+
// Reference face outward normal in world: the face of the ref box facing
|
|
255
|
+
// the incident box. The contact normal points B→A; the ref face's
|
|
256
|
+
// outward normal must point toward the incident box (= -n if ref is A,
|
|
257
|
+
// = +n if ref is B).
|
|
258
|
+
const ref_out_nx = ref_is_A ? -nx : nx;
|
|
259
|
+
const ref_out_ny = ref_is_A ? -ny : ny;
|
|
260
|
+
const ref_out_nz = ref_is_A ? -nz : nz;
|
|
261
|
+
|
|
262
|
+
// Ref face's three axis-in-world directions: the axis-direction matching
|
|
263
|
+
// ref_axis_idx is the OUTWARD normal; the other two are the face tangents.
|
|
264
|
+
// Sign of the reference-face axis aligned with ref_out:
|
|
265
|
+
const ref_axis_world_x = ref_axes[ref_axis_idx * 3];
|
|
266
|
+
const ref_axis_world_y = ref_axes[ref_axis_idx * 3 + 1];
|
|
267
|
+
const ref_axis_world_z = ref_axes[ref_axis_idx * 3 + 2];
|
|
268
|
+
const ref_axis_dot = ref_axis_world_x * ref_out_nx
|
|
269
|
+
+ ref_axis_world_y * ref_out_ny
|
|
270
|
+
+ ref_axis_world_z * ref_out_nz;
|
|
271
|
+
const ref_axis_sign = ref_axis_dot >= 0 ? 1 : -1;
|
|
272
|
+
|
|
273
|
+
// Face plane: passes through `ref_cx + ref_axis * ref_axis_sign * ref_h_<axis>`,
|
|
274
|
+
// with outward normal = `ref_axis_world * ref_axis_sign`.
|
|
275
|
+
const ref_h_along_axis = ref_axis_idx === 0 ? ref_h_x : (ref_axis_idx === 1 ? ref_h_y : ref_h_z);
|
|
276
|
+
const ref_face_origin_x = ref_cx + ref_axis_world_x * ref_axis_sign * ref_h_along_axis;
|
|
277
|
+
const ref_face_origin_y = ref_cy + ref_axis_world_y * ref_axis_sign * ref_h_along_axis;
|
|
278
|
+
const ref_face_origin_z = ref_cz + ref_axis_world_z * ref_axis_sign * ref_h_along_axis;
|
|
279
|
+
|
|
280
|
+
// Reference face's two tangent axes (u, v) in world, with the corresponding half-extents.
|
|
281
|
+
let u_axis_idx, v_axis_idx;
|
|
282
|
+
if (ref_axis_idx === 0) { u_axis_idx = 1; v_axis_idx = 2; }
|
|
283
|
+
else if (ref_axis_idx === 1) { u_axis_idx = 2; v_axis_idx = 0; }
|
|
284
|
+
else { u_axis_idx = 0; v_axis_idx = 1; }
|
|
285
|
+
|
|
286
|
+
const ux = ref_axes[u_axis_idx * 3], uy = ref_axes[u_axis_idx * 3 + 1], uz = ref_axes[u_axis_idx * 3 + 2];
|
|
287
|
+
const vx = ref_axes[v_axis_idx * 3], vy = ref_axes[v_axis_idx * 3 + 1], vz = ref_axes[v_axis_idx * 3 + 2];
|
|
288
|
+
const half_u = u_axis_idx === 0 ? ref_h_x : (u_axis_idx === 1 ? ref_h_y : ref_h_z);
|
|
289
|
+
const half_v = v_axis_idx === 0 ? ref_h_x : (v_axis_idx === 1 ? ref_h_y : ref_h_z);
|
|
290
|
+
|
|
291
|
+
// ---- Pick incident face on the OTHER box ----
|
|
292
|
+
// Its outward normal should be MOST antiparallel to the ref face outward normal
|
|
293
|
+
// (i.e., the face of the incident box that is "looking back" at the ref face).
|
|
294
|
+
let inc_axis_idx = 0, inc_axis_sign = 1;
|
|
295
|
+
let max_anti = -Infinity;
|
|
296
|
+
for (let i = 0; i < 3; i++) {
|
|
297
|
+
const iax = inc_axes[i * 3], iay = inc_axes[i * 3 + 1], iaz = inc_axes[i * 3 + 2];
|
|
298
|
+
const d_pos = iax * ref_out_nx + iay * ref_out_ny + iaz * ref_out_nz;
|
|
299
|
+
// We want dot ≈ -1, so most negative dot is the most anti-parallel
|
|
300
|
+
if (-d_pos > max_anti) { max_anti = -d_pos; inc_axis_idx = i; inc_axis_sign = -1; }
|
|
301
|
+
if ( d_pos > max_anti) { max_anti = d_pos; inc_axis_idx = i; inc_axis_sign = 1; }
|
|
302
|
+
}
|
|
303
|
+
// Now the incident face outward normal must be antiparallel to ref_out_n.
|
|
304
|
+
// We chose inc_axis_sign as the sign of dot(inc_axis_dir, ref_out_n). The
|
|
305
|
+
// incident face's outward direction is the OPPOSITE sign (facing back at ref).
|
|
306
|
+
const inc_outward_sign = -inc_axis_sign;
|
|
307
|
+
|
|
308
|
+
const inc_h_along_axis = inc_axis_idx === 0 ? inc_h_x : (inc_axis_idx === 1 ? inc_h_y : inc_h_z);
|
|
309
|
+
// Incident face centre in world.
|
|
310
|
+
const inc_face_cx = inc_cx + inc_axes[inc_axis_idx * 3] * inc_outward_sign * inc_h_along_axis;
|
|
311
|
+
const inc_face_cy = inc_cy + inc_axes[inc_axis_idx * 3 + 1] * inc_outward_sign * inc_h_along_axis;
|
|
312
|
+
const inc_face_cz = inc_cz + inc_axes[inc_axis_idx * 3 + 2] * inc_outward_sign * inc_h_along_axis;
|
|
313
|
+
|
|
314
|
+
// Incident face's two tangent axes in world, with their half-extents.
|
|
315
|
+
let i_u_idx, i_v_idx;
|
|
316
|
+
if (inc_axis_idx === 0) { i_u_idx = 1; i_v_idx = 2; }
|
|
317
|
+
else if (inc_axis_idx === 1) { i_u_idx = 2; i_v_idx = 0; }
|
|
318
|
+
else { i_u_idx = 0; i_v_idx = 1; }
|
|
319
|
+
const iux = inc_axes[i_u_idx * 3], iuy = inc_axes[i_u_idx * 3 + 1], iuz = inc_axes[i_u_idx * 3 + 2];
|
|
320
|
+
const ivx = inc_axes[i_v_idx * 3], ivy = inc_axes[i_v_idx * 3 + 1], ivz = inc_axes[i_v_idx * 3 + 2];
|
|
321
|
+
const i_half_u = i_u_idx === 0 ? inc_h_x : (i_u_idx === 1 ? inc_h_y : inc_h_z);
|
|
322
|
+
const i_half_v = i_v_idx === 0 ? inc_h_x : (i_v_idx === 1 ? inc_h_y : inc_h_z);
|
|
323
|
+
|
|
324
|
+
// Build incident face's 4 world corners (ordered CCW around the face).
|
|
325
|
+
const signs_u = [ 1, 1, -1, -1];
|
|
326
|
+
const signs_v = [-1, 1, 1, -1];
|
|
327
|
+
for (let i = 0; i < 4; i++) {
|
|
328
|
+
const su = signs_u[i] * i_half_u;
|
|
329
|
+
const sv = signs_v[i] * i_half_v;
|
|
330
|
+
incident_world[i * 3] = inc_face_cx + iux * su + ivx * sv;
|
|
331
|
+
incident_world[i * 3 + 1] = inc_face_cy + iuy * su + ivy * sv;
|
|
332
|
+
incident_world[i * 3 + 2] = inc_face_cz + iuz * su + ivz * sv;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// Project incident corners into ref-face uv coordinates.
|
|
336
|
+
// For each corner C: uv = ((C - ref_face_origin) · u_axis, ... · v_axis).
|
|
337
|
+
for (let i = 0; i < 4; i++) {
|
|
338
|
+
const ex = incident_world[i * 3] - ref_face_origin_x;
|
|
339
|
+
const ey = incident_world[i * 3 + 1] - ref_face_origin_y;
|
|
340
|
+
const ez = incident_world[i * 3 + 2] - ref_face_origin_z;
|
|
341
|
+
incident_uv[i * 2] = ex * ux + ey * uy + ez * uz;
|
|
342
|
+
incident_uv[i * 2 + 1] = ex * vx + ey * vy + ez * vz;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// Sutherland-Hodgman clip against the rectangle |u|<=half_u, |v|<=half_v.
|
|
346
|
+
// Apply 4 successive single-axis clips.
|
|
347
|
+
let n = 4;
|
|
348
|
+
// Copy into clipped_uv_in first.
|
|
349
|
+
for (let i = 0; i < n * 2; i++) clipped_uv_in[i] = incident_uv[i];
|
|
350
|
+
|
|
351
|
+
n = clip_against_axis(clipped_uv_in, n, clipped_uv_out, 0, half_u, true);
|
|
352
|
+
if (n === 0) return out_empty(out);
|
|
353
|
+
n = clip_against_axis(clipped_uv_out, n, clipped_uv_in, 0, -half_u, false);
|
|
354
|
+
if (n === 0) return out_empty(out);
|
|
355
|
+
n = clip_against_axis(clipped_uv_in, n, clipped_uv_out, 1, half_v, true);
|
|
356
|
+
if (n === 0) return out_empty(out);
|
|
357
|
+
n = clip_against_axis(clipped_uv_out, n, clipped_uv_in, 1, -half_v, false);
|
|
358
|
+
if (n === 0) return out_empty(out);
|
|
359
|
+
|
|
360
|
+
// Each surviving uv-point is on the ref face rectangle. We need to:
|
|
361
|
+
// 1. Map uv back to world → that's the contact point on the *incident* face
|
|
362
|
+
// (still on the inc face plane at that uv).
|
|
363
|
+
// 2. Compute depth = penetration along contact normal n (B→A).
|
|
364
|
+
// 3. The contact on the *reference* face is the projection of the inc-face
|
|
365
|
+
// point onto the reference plane along the contact normal.
|
|
366
|
+
|
|
367
|
+
// To re-derive the world position from a uv coord: we need to keep both the
|
|
368
|
+
// uv coord and the corresponding world point. But we just clipped uv-only,
|
|
369
|
+
// so the world position is the projection back. The depth resolves it:
|
|
370
|
+
//
|
|
371
|
+
// ref plane: normal = ref_outward, origin at ref_face_origin
|
|
372
|
+
// incident point world = ref_face_origin + u*u_axis + v*v_axis + (signed projection along ref_out)
|
|
373
|
+
//
|
|
374
|
+
// The component along ref_out for the original incident corner is what we lost
|
|
375
|
+
// by going to uv. We recompute it from the original incident face plane (which
|
|
376
|
+
// is at a fixed offset from ref): the inc corner's signed distance from the ref
|
|
377
|
+
// plane is `(corner - ref_face_origin) · ref_out_n`.
|
|
378
|
+
//
|
|
379
|
+
// After clipping in uv, we can't directly recover that distance without
|
|
380
|
+
// re-projecting onto the inc face plane. We do that here.
|
|
381
|
+
|
|
382
|
+
const ref_out_x = ref_axis_world_x * ref_axis_sign;
|
|
383
|
+
const ref_out_y = ref_axis_world_y * ref_axis_sign;
|
|
384
|
+
const ref_out_z = ref_axis_world_z * ref_axis_sign;
|
|
385
|
+
|
|
386
|
+
// Inc face plane (in world): point inc_face_c, normal inc_outward
|
|
387
|
+
// = inc_axes[inc_axis_idx*3..+2] * inc_outward_sign.
|
|
388
|
+
const inc_out_x = inc_axes[inc_axis_idx * 3] * inc_outward_sign;
|
|
389
|
+
const inc_out_y = inc_axes[inc_axis_idx * 3 + 1] * inc_outward_sign;
|
|
390
|
+
const inc_out_z = inc_axes[inc_axis_idx * 3 + 2] * inc_outward_sign;
|
|
391
|
+
|
|
392
|
+
// For a clipped uv point P_uv, the corresponding world point P_world on the
|
|
393
|
+
// incident face plane satisfies:
|
|
394
|
+
// P_world = ref_face_origin + u*u_axis + v*v_axis + t * ref_out for some t
|
|
395
|
+
// (P_world - inc_face_c) · inc_out = 0
|
|
396
|
+
// Substitute and solve for t. Let:
|
|
397
|
+
// X = ref_face_origin + u*u_axis + v*v_axis (a point on the line)
|
|
398
|
+
// t such that (X + t*ref_out - inc_face_c) · inc_out = 0
|
|
399
|
+
// t * (ref_out · inc_out) = (inc_face_c - X) · inc_out
|
|
400
|
+
const ref_dot_inc = ref_out_x * inc_out_x + ref_out_y * inc_out_y + ref_out_z * inc_out_z;
|
|
401
|
+
// Faces are nearly parallel → ref_dot_inc ≈ -1 (anti-parallel). Robust.
|
|
402
|
+
|
|
403
|
+
// Build candidates: for each clipped uv point.
|
|
404
|
+
let cand_count = 0;
|
|
405
|
+
const clipped_uv = clipped_uv_in;
|
|
406
|
+
for (let i = 0; i < n; i++) {
|
|
407
|
+
const u = clipped_uv[i * 2];
|
|
408
|
+
const v = clipped_uv[i * 2 + 1];
|
|
409
|
+
|
|
410
|
+
const x_x = ref_face_origin_x + u * ux + v * vx;
|
|
411
|
+
const x_y = ref_face_origin_y + u * uy + v * vy;
|
|
412
|
+
const x_z = ref_face_origin_z + u * uz + v * vz;
|
|
413
|
+
|
|
414
|
+
let world_inc_x, world_inc_y, world_inc_z;
|
|
415
|
+
if (ref_dot_inc !== 0) {
|
|
416
|
+
const num_x = inc_face_cx - x_x;
|
|
417
|
+
const num_y = inc_face_cy - x_y;
|
|
418
|
+
const num_z = inc_face_cz - x_z;
|
|
419
|
+
const t = (num_x * inc_out_x + num_y * inc_out_y + num_z * inc_out_z) / ref_dot_inc;
|
|
420
|
+
world_inc_x = x_x + ref_out_x * t;
|
|
421
|
+
world_inc_y = x_y + ref_out_y * t;
|
|
422
|
+
world_inc_z = x_z + ref_out_z * t;
|
|
423
|
+
} else {
|
|
424
|
+
// Faces orthogonal — degenerate, fall back to uv point on ref plane.
|
|
425
|
+
world_inc_x = x_x; world_inc_y = x_y; world_inc_z = x_z;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// Penetration: signed distance of inc-face contact from the ref plane,
|
|
429
|
+
// measured into the ref box (= along -ref_out). Positive means penetrating.
|
|
430
|
+
const sep_x = world_inc_x - ref_face_origin_x;
|
|
431
|
+
const sep_y = world_inc_y - ref_face_origin_y;
|
|
432
|
+
const sep_z = world_inc_z - ref_face_origin_z;
|
|
433
|
+
const sep_along_ref_out = sep_x * ref_out_x + sep_y * ref_out_y + sep_z * ref_out_z;
|
|
434
|
+
const depth = -sep_along_ref_out;
|
|
435
|
+
if (depth < 0) continue;
|
|
436
|
+
|
|
437
|
+
candidates[cand_count * 4] = world_inc_x;
|
|
438
|
+
candidates[cand_count * 4 + 1] = world_inc_y;
|
|
439
|
+
candidates[cand_count * 4 + 2] = world_inc_z;
|
|
440
|
+
candidates[cand_count * 4 + 3] = depth;
|
|
441
|
+
cand_count++;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
if (cand_count === 0) return out_empty(out);
|
|
445
|
+
|
|
446
|
+
// ---- Reduce to ≤ MAX_CONTACTS by best-deepest + perimeter ----
|
|
447
|
+
const kept = reduce_contacts(cand_count);
|
|
448
|
+
|
|
449
|
+
// ---- Emit: contact-on-incident is the candidate's world point;
|
|
450
|
+
// contact-on-reference is the same point projected onto the ref plane.
|
|
451
|
+
out[3] = kept;
|
|
452
|
+
for (let k = 0; k < kept; k++) {
|
|
453
|
+
const px = candidates[k * 4];
|
|
454
|
+
const py = candidates[k * 4 + 1];
|
|
455
|
+
const pz = candidates[k * 4 + 2];
|
|
456
|
+
const depth = candidates[k * 4 + 3];
|
|
457
|
+
|
|
458
|
+
// ref-side contact = project onto ref plane along ref_out.
|
|
459
|
+
const dist_to_plane = (px - ref_face_origin_x) * ref_out_x
|
|
460
|
+
+ (py - ref_face_origin_y) * ref_out_y
|
|
461
|
+
+ (pz - ref_face_origin_z) * ref_out_z;
|
|
462
|
+
const rpx = px - ref_out_x * dist_to_plane;
|
|
463
|
+
const rpy = py - ref_out_y * dist_to_plane;
|
|
464
|
+
const rpz = pz - ref_out_z * dist_to_plane;
|
|
465
|
+
|
|
466
|
+
let wax, way, waz, wbx_, wby_, wbz_;
|
|
467
|
+
if (ref_is_A) {
|
|
468
|
+
wax = rpx; way = rpy; waz = rpz;
|
|
469
|
+
wbx_ = px; wby_ = py; wbz_ = pz;
|
|
470
|
+
} else {
|
|
471
|
+
wax = px; way = py; waz = pz;
|
|
472
|
+
wbx_ = rpx; wby_ = rpy; wbz_ = rpz;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
const base = 4 + k * CONTACT_STRIDE;
|
|
476
|
+
out[base] = wax; out[base + 1] = way; out[base + 2] = waz;
|
|
477
|
+
out[base + 3] = wbx_; out[base + 4] = wby_; out[base + 5] = wbz_;
|
|
478
|
+
out[base + 6] = depth;
|
|
479
|
+
}
|
|
480
|
+
return true;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
function out_empty(out) {
|
|
484
|
+
out[3] = 0;
|
|
485
|
+
return true; // overlap exists per SAT, just no clipped manifold
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* In-place reduction of `candidates` to at most {@link MAX_CONTACTS}:
|
|
490
|
+
* 1. Sort by depth descending; deepest stays at index 0.
|
|
491
|
+
* 2. From the remaining, greedily pick the points that maximise the spread
|
|
492
|
+
* (sum of squared distances to already-kept points). This approximates
|
|
493
|
+
* the maximum-area heuristic without needing the actual area.
|
|
494
|
+
*
|
|
495
|
+
* @param {number} n input count
|
|
496
|
+
* @returns {number} kept count (min(n, MAX_CONTACTS))
|
|
497
|
+
*/
|
|
498
|
+
function reduce_contacts(n) {
|
|
499
|
+
if (n <= MAX_CONTACTS) return n;
|
|
500
|
+
|
|
501
|
+
// Find deepest, swap into slot 0.
|
|
502
|
+
let deepest_idx = 0;
|
|
503
|
+
let deepest_val = candidates[3];
|
|
504
|
+
for (let i = 1; i < n; i++) {
|
|
505
|
+
if (candidates[i * 4 + 3] > deepest_val) {
|
|
506
|
+
deepest_val = candidates[i * 4 + 3];
|
|
507
|
+
deepest_idx = i;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
if (deepest_idx !== 0) swap_candidate(0, deepest_idx);
|
|
511
|
+
|
|
512
|
+
// Greedy: for slot k in 1..MAX_CONTACTS-1, pick the remaining candidate
|
|
513
|
+
// whose min-distance-sq-to-already-kept-set is largest.
|
|
514
|
+
for (let k = 1; k < MAX_CONTACTS; k++) {
|
|
515
|
+
let best_score = -1;
|
|
516
|
+
let best_i = -1;
|
|
517
|
+
for (let i = k; i < n; i++) {
|
|
518
|
+
let min_d2 = Infinity;
|
|
519
|
+
for (let j = 0; j < k; j++) {
|
|
520
|
+
const dx = candidates[i * 4] - candidates[j * 4];
|
|
521
|
+
const dy = candidates[i * 4 + 1] - candidates[j * 4 + 1];
|
|
522
|
+
const dz = candidates[i * 4 + 2] - candidates[j * 4 + 2];
|
|
523
|
+
const d2 = dx * dx + dy * dy + dz * dz;
|
|
524
|
+
if (d2 < min_d2) min_d2 = d2;
|
|
525
|
+
}
|
|
526
|
+
if (min_d2 > best_score) { best_score = min_d2; best_i = i; }
|
|
527
|
+
}
|
|
528
|
+
if (best_i !== k) swap_candidate(k, best_i);
|
|
529
|
+
}
|
|
530
|
+
return MAX_CONTACTS;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
function swap_candidate(a, b) {
|
|
534
|
+
const ax = candidates[a * 4], ay = candidates[a * 4 + 1], az = candidates[a * 4 + 2], ad = candidates[a * 4 + 3];
|
|
535
|
+
candidates[a * 4] = candidates[b * 4];
|
|
536
|
+
candidates[a * 4 + 1] = candidates[b * 4 + 1];
|
|
537
|
+
candidates[a * 4 + 2] = candidates[b * 4 + 2];
|
|
538
|
+
candidates[a * 4 + 3] = candidates[b * 4 + 3];
|
|
539
|
+
candidates[b * 4] = ax;
|
|
540
|
+
candidates[b * 4 + 1] = ay;
|
|
541
|
+
candidates[b * 4 + 2] = az;
|
|
542
|
+
candidates[b * 4 + 3] = ad;
|
|
543
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compute the two world endpoints of a capsule's central segment given its
|
|
3
|
+
* pose. The capsule is Y-aligned in body frame; the segment runs from
|
|
4
|
+
* `(0, -h/2, 0)` to `(0, +h/2, 0)`. Writes endpoints into `out` as
|
|
5
|
+
* `[ax, ay, az, bx, by, bz]`.
|
|
6
|
+
*
|
|
7
|
+
* @param {number[]|Float64Array} out length >= 6
|
|
8
|
+
* @param {number} cx capsule centre x
|
|
9
|
+
* @param {number} cy
|
|
10
|
+
* @param {number} cz
|
|
11
|
+
* @param {number} qx quaternion x
|
|
12
|
+
* @param {number} qy
|
|
13
|
+
* @param {number} qz
|
|
14
|
+
* @param {number} qw
|
|
15
|
+
* @param {number} half_height
|
|
16
|
+
*/
|
|
17
|
+
export function capsule_world_segment(out: number[] | Float64Array, cx: number, cy: number, cz: number, qx: number, qy: number, qz: number, qw: number, half_height: number): void;
|
|
18
|
+
/**
|
|
19
|
+
* Capsule (A) vs sphere (B) contact, closed-form via point-segment distance.
|
|
20
|
+
*
|
|
21
|
+
* @param {number[]|Float64Array} out length >= 10
|
|
22
|
+
* @param {number} a_cx capsule centre x
|
|
23
|
+
* @param {number} a_cy
|
|
24
|
+
* @param {number} a_cz
|
|
25
|
+
* @param {number} a_qx capsule rotation
|
|
26
|
+
* @param {number} a_qy
|
|
27
|
+
* @param {number} a_qz
|
|
28
|
+
* @param {number} a_qw
|
|
29
|
+
* @param {number} a_radius
|
|
30
|
+
* @param {number} a_half_h capsule half-height (not including caps)
|
|
31
|
+
* @param {number} b_cx sphere centre x
|
|
32
|
+
* @param {number} b_cy
|
|
33
|
+
* @param {number} b_cz
|
|
34
|
+
* @param {number} b_radius
|
|
35
|
+
* @returns {boolean} true on overlap
|
|
36
|
+
*/
|
|
37
|
+
export function capsule_sphere_contact(out: number[] | Float64Array, a_cx: number, a_cy: number, a_cz: number, a_qx: number, a_qy: number, a_qz: number, a_qw: number, a_radius: number, a_half_h: number, b_cx: number, b_cy: number, b_cz: number, b_radius: number): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Two capsules (A and B). Reduces to segment-segment closest pair + radius.
|
|
40
|
+
*
|
|
41
|
+
* @param {number[]|Float64Array} out length >= 10
|
|
42
|
+
* @returns {boolean} true on overlap
|
|
43
|
+
*/
|
|
44
|
+
export function capsule_capsule_contact(out: number[] | Float64Array, a_cx: any, a_cy: any, a_cz: any, a_qx: any, a_qy: any, a_qz: any, a_qw: any, a_radius: any, a_half_h: any, b_cx: any, b_cy: any, b_cz: any, b_qx: any, b_qy: any, b_qz: any, b_qw: any, b_radius: any, b_half_h: any): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Capsule (A) vs oriented box (B). Brings the capsule segment into box-local
|
|
47
|
+
* space, then refines via 2 fixed-point iterations between:
|
|
48
|
+
* - closest point on the segment to the current box-side candidate
|
|
49
|
+
* - clamped point on the box closest to the current segment-side candidate
|
|
50
|
+
*
|
|
51
|
+
* Two iterations suffice for the cases this engine targets (sphere-like cap
|
|
52
|
+
* geometry against axis-aligned-in-local box). When the segment passes
|
|
53
|
+
* through the box, the "inside" branch picks the smallest-overlap face
|
|
54
|
+
* deterministically, mirroring {@link sphere_box_contact}.
|
|
55
|
+
*
|
|
56
|
+
* @param {number[]|Float64Array} out length >= 10
|
|
57
|
+
* @returns {boolean}
|
|
58
|
+
*/
|
|
59
|
+
export function capsule_box_contact(out: number[] | Float64Array, a_cx: any, a_cy: any, a_cz: any, a_qx: any, a_qy: any, a_qz: any, a_qw: any, a_radius: any, a_half_h: any, b_cx: any, b_cy: any, b_cz: any, b_qx: any, b_qy: any, b_qz: any, b_qw: any, b_hx: any, b_hy: any, b_hz: any): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Multi-point capsule-vs-OBB contact generation. Emits up to
|
|
62
|
+
* {@link CAPSULE_BOX_MAX_CONTACTS} contacts into `out` in the
|
|
63
|
+
* `(wax, way, waz, wbx, wby, wbz, nx, ny, nz, depth)` stride layout.
|
|
64
|
+
*
|
|
65
|
+
* The motivation: a capsule lying flat on a face needs more than one
|
|
66
|
+
* contact to rest stably — a single contact at the segment's closest point
|
|
67
|
+
* is positionally ambiguous (every interior segment point is equidistant
|
|
68
|
+
* from the face), and the body wobbles around whichever point the
|
|
69
|
+
* iterative closest-point solver happened to converge on. Two contacts at
|
|
70
|
+
* the cap centres pin the capsule's rotation about its long axis.
|
|
71
|
+
*
|
|
72
|
+
* Algorithm:
|
|
73
|
+
* 1. Closest-point-on-segment vs OBB → primary contact (same as
|
|
74
|
+
* {@link capsule_box_contact}).
|
|
75
|
+
* 2. Treat each cap centre as a sphere of cap-radius and run
|
|
76
|
+
* {@link sphere_box_contact} → up to two additional contacts.
|
|
77
|
+
* 3. Dedupe spatially against the primary so a capsule touching with one
|
|
78
|
+
* cap doesn't emit two contacts at the same point.
|
|
79
|
+
*
|
|
80
|
+
* @param {Float64Array} out length >= CAPSULE_BOX_MAX_CONTACTS * CAPSULE_BOX_CONTACT_STRIDE
|
|
81
|
+
* @param {number} a_cx capsule centre x
|
|
82
|
+
* @param {number} a_cy
|
|
83
|
+
* @param {number} a_cz
|
|
84
|
+
* @param {number} a_qx capsule rotation
|
|
85
|
+
* @param {number} a_qy
|
|
86
|
+
* @param {number} a_qz
|
|
87
|
+
* @param {number} a_qw
|
|
88
|
+
* @param {number} a_radius
|
|
89
|
+
* @param {number} a_half_h
|
|
90
|
+
* @param {number} b_cx box centre x
|
|
91
|
+
* @param {number} b_cy
|
|
92
|
+
* @param {number} b_cz
|
|
93
|
+
* @param {number} b_qx
|
|
94
|
+
* @param {number} b_qy
|
|
95
|
+
* @param {number} b_qz
|
|
96
|
+
* @param {number} b_qw
|
|
97
|
+
* @param {number} b_hx
|
|
98
|
+
* @param {number} b_hy
|
|
99
|
+
* @param {number} b_hz
|
|
100
|
+
* @returns {number} number of contacts emitted, in `[0, CAPSULE_BOX_MAX_CONTACTS]`
|
|
101
|
+
*/
|
|
102
|
+
export function capsule_box_multi_contacts(out: Float64Array, a_cx: number, a_cy: number, a_cz: number, a_qx: number, a_qy: number, a_qz: number, a_qw: number, a_radius: number, a_half_h: number, b_cx: number, b_cy: number, b_cz: number, b_qx: number, b_qy: number, b_qz: number, b_qw: number, b_hx: number, b_hy: number, b_hz: number): number;
|
|
103
|
+
/**
|
|
104
|
+
* Output stride per contact in {@link capsule_box_multi_contacts}.
|
|
105
|
+
* Matches the candidate-buffer layout used by `narrowphase_step`.
|
|
106
|
+
*
|
|
107
|
+
* 0..2 : world contact on capsule side
|
|
108
|
+
* 3..5 : world contact on box side
|
|
109
|
+
* 6..8 : normal from box (B) toward capsule (A)
|
|
110
|
+
* 9 : depth (positive = penetration)
|
|
111
|
+
*
|
|
112
|
+
* @type {number}
|
|
113
|
+
*/
|
|
114
|
+
export const CAPSULE_BOX_CONTACT_STRIDE: number;
|
|
115
|
+
/**
|
|
116
|
+
* Maximum contact points {@link capsule_box_multi_contacts} can emit.
|
|
117
|
+
* - 1 from the closest-point-on-segment vs OBB query (primary)
|
|
118
|
+
* - up to 2 from the cap-centre sphere-vs-OBB queries (one per endpoint)
|
|
119
|
+
* @type {number}
|
|
120
|
+
*/
|
|
121
|
+
export const CAPSULE_BOX_MAX_CONTACTS: number;
|
|
122
|
+
//# sourceMappingURL=capsule_contacts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capsule_contacts.d.ts","sourceRoot":"","sources":["../../../../../src/engine/physics/narrowphase/capsule_contacts.js"],"names":[],"mappings":"AA0EA;;;;;;;;;;;;;;;GAeG;AACH,2CAVW,MAAM,EAAE,GAAC,YAAY,MACrB,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,eACN,MAAM,QAOhB;AAID;;;;;;;;;;;;;;;;;;GAkBG;AACH,4CAhBW,MAAM,EAAE,GAAC,YAAY,QACrB,MAAM,QACN,MAAM,QACN,MAAM,QACN,MAAM,QACN,MAAM,QACN,MAAM,QACN,MAAM,YACN,MAAM,YACN,MAAM,QACN,MAAM,QACN,MAAM,QACN,MAAM,YACN,MAAM,GACJ,OAAO,CA6CnB;AAMD;;;;;GAKG;AACH,6CAHW,MAAM,EAAE,GAAC,YAAY,yNACnB,OAAO,CAuEnB;AAOD;;;;;;;;;;;;;GAaG;AACH,yCAHW,MAAM,EAAE,GAAC,YAAY,4NACnB,OAAO,CA8FnB;AAyCD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,gDAtBW,YAAY,QACZ,MAAM,QACN,MAAM,QACN,MAAM,QACN,MAAM,QACN,MAAM,QACN,MAAM,QACN,MAAM,YACN,MAAM,YACN,MAAM,QACN,MAAM,QACN,MAAM,QACN,MAAM,QACN,MAAM,QACN,MAAM,QACN,MAAM,QACN,MAAM,QACN,MAAM,QACN,MAAM,QACN,MAAM,GACJ,MAAM,CAuElB;AApJD;;;;;;;;;;GAUG;AACH,yCAFU,MAAM,CAE6B;AAE7C;;;;;GAKG;AACH,uCAFU,MAAM,CAE0B"}
|