@woosh/meep-engine 2.138.19 → 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 +2 -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 +6 -4
- 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/ecs/EntityManager.d.ts +2 -2
- package/src/engine/ecs/EntityManager.d.ts.map +1 -1
- package/src/engine/ecs/EntityManager.js +13 -8
- package/src/engine/ecs/System.d.ts.map +1 -1
- package/src/engine/ecs/System.js +2 -2
- 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
|
@@ -1,122 +1,566 @@
|
|
|
1
|
+
import { assert } from "../../../core/assert.js";
|
|
2
|
+
import { combine_hash } from "../../../core/collection/array/combine_hash.js";
|
|
3
|
+
import { is_typed_array_equals } from "../../../core/collection/array/typed/is_typed_array_equals.js";
|
|
4
|
+
import { sparse_typed_array_hash } from "../../../core/collection/array/typed/sparse_typed_array_hash.js";
|
|
5
|
+
import { scs3d_sample_linear } from "../../graphics/texture/3d/scs3d_sample_linear.js";
|
|
6
|
+
import { v3_grid_compute_solid_neighbour_mask } from "./solver/v3_grid_compute_solid_neighbour_mask.js";
|
|
7
|
+
import { v3_grid_patch_edges_uniform } from "./solver/v3_grid_patch_edges_uniform.js";
|
|
8
|
+
import { v3_grid_shift_in_place } from "./solver/v3_grid_shift_in_place.js";
|
|
1
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Cell-centered 3D Eulerian grid for the fluid simulator.
|
|
12
|
+
*
|
|
13
|
+
* Holds three velocity components (x, y, z), an optional per-cell `solid` mask, and any
|
|
14
|
+
* number of user-defined passive scalar attributes that get transported by the flow.
|
|
15
|
+
*
|
|
16
|
+
* Holds only state whose value carries information across step boundaries. The
|
|
17
|
+
* simulator's transient working memory (per-step velocity snapshots, divergence,
|
|
18
|
+
* diffusion / scalar ping-pong scratch) lives on the simulator. `pressure` is the
|
|
19
|
+
* one exception: it's warm-started each step from the previous solve, so its value
|
|
20
|
+
* is genuine cross-step state and belongs here.
|
|
21
|
+
*
|
|
22
|
+
* All typed array references are STABLE for the lifetime of the field. External
|
|
23
|
+
* consumers can safely cache references returned from {@link getScalarData},
|
|
24
|
+
* {@link velocity_x}, etc.
|
|
25
|
+
*
|
|
26
|
+
* @see "Real-Time Fluid Dynamics for Games" (Stam, 2003)
|
|
27
|
+
* @see GDC 2019 talk "Wind Simulation in God of War" (Rupert Renard) for the wider
|
|
28
|
+
* effector-driven design pattern this package is moving toward.
|
|
29
|
+
*/
|
|
30
|
+
export class FluidField {
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Grid dimensions in cells, `[x, y, z]`.
|
|
34
|
+
* @type {[number, number, number]}
|
|
35
|
+
*/
|
|
36
|
+
#resolution = [0, 0, 0];
|
|
2
37
|
|
|
3
|
-
class FluidAttribute {
|
|
4
|
-
name = "unnamed"
|
|
5
38
|
/**
|
|
39
|
+
* Velocity X component, length = cell count. Cell-centered, indexed by
|
|
40
|
+
* `z * res_x * res_y + y * res_x + x`.
|
|
41
|
+
* @type {Float32Array|null}
|
|
42
|
+
*/
|
|
43
|
+
velocity_x = null;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @type {Float32Array|null}
|
|
47
|
+
*/
|
|
48
|
+
velocity_y = null;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @type {Float32Array|null}
|
|
52
|
+
*/
|
|
53
|
+
velocity_z = null;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Per-cell solid flag. `0` = fluid, non-zero = solid (wall). Always allocated by
|
|
57
|
+
* {@link build} (zero-filled — every cell defaults to fluid). The solver and every
|
|
58
|
+
* effector read this unconditionally, so the array is part of the field's
|
|
59
|
+
* uniform shape, not an optional add-on.
|
|
60
|
+
* @type {Uint8Array|null}
|
|
61
|
+
*/
|
|
62
|
+
solid = null;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Per-cell pre-baked neighbourhood mask consumed by the pressure SOR loop.
|
|
66
|
+
* One byte per cell encoding which of the 6 cardinal neighbours are fluid:
|
|
67
|
+
*
|
|
68
|
+
* bit 0 (= 1) : -x neighbour is fluid (in-bounds AND non-solid)
|
|
69
|
+
* bit 1 (= 2) : +x neighbour is fluid
|
|
70
|
+
* bit 2 (= 4) : -y neighbour is fluid
|
|
71
|
+
* bit 3 (= 8) : +y neighbour is fluid
|
|
72
|
+
* bit 4 (= 16) : -z neighbour is fluid
|
|
73
|
+
* bit 5 (= 32) : +z neighbour is fluid
|
|
6
74
|
*
|
|
7
|
-
*
|
|
75
|
+
* Solid cells themselves are encoded as `mask = 0` so the SOR loop's
|
|
76
|
+
* `if (mask === 0) continue` skip handles both "this cell is solid" and
|
|
77
|
+
* "this fluid cell is isolated" with a single comparison instead of one
|
|
78
|
+
* solid-self-check plus six solid-neighbour-checks plus six boundary checks.
|
|
79
|
+
*
|
|
80
|
+
* Computed once by {@link recomputeSolidNeighbourMask} after every solid-mask
|
|
81
|
+
* mutation. The simulator runs that recompute at the top of every project()
|
|
82
|
+
* call so callers never have to remember to invalidate it; the per-step cost
|
|
83
|
+
* is one O(N) byte-pass against the bandwidth-bound SOR sweep that runs many
|
|
84
|
+
* iterations per call.
|
|
85
|
+
*
|
|
86
|
+
* @type {Uint8Array|null}
|
|
8
87
|
*/
|
|
9
|
-
|
|
10
|
-
}
|
|
88
|
+
solid_neighbour_mask = null;
|
|
11
89
|
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Pressure field from the most recent projection. Owned by the field rather than
|
|
92
|
+
* the simulator because the simulator warm-starts each solve from the previous
|
|
93
|
+
* result — step N+1 depends on the value step N wrote here. If this lived on the
|
|
94
|
+
* simulator, replacing the simulator instance between steps would silently degrade
|
|
95
|
+
* convergence at the same iteration count.
|
|
96
|
+
*
|
|
97
|
+
* Storage type is {@link Float32Array} by default, or {@link Float16Array} when
|
|
98
|
+
* {@link half_precision_pressure} is enabled before build — see that field for
|
|
99
|
+
* the bandwidth-vs-quality trade-off.
|
|
100
|
+
*
|
|
101
|
+
* Safe to read for debug visualisation. Don't mutate.
|
|
102
|
+
* @type {Float32Array|Float16Array|null}
|
|
103
|
+
*/
|
|
104
|
+
pressure = null;
|
|
19
105
|
|
|
20
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Allocate {@link pressure} as {@link Float16Array} instead of {@link Float32Array}.
|
|
108
|
+
*
|
|
109
|
+
* **Currently slower in V8 — keep `false`.** The intent of this option is to
|
|
110
|
+
* halve the memory bandwidth on the pressure SOR sweep (the simulator's
|
|
111
|
+
* hottest, bandwidth-bound loop). On hardware with F16C the per-cell f16↔f32
|
|
112
|
+
* conversion is ~1 cycle and the bandwidth saving wins. In V8 as of Node 24
|
|
113
|
+
* the conversion path is not yet specialized — each read of `pressure[i]`
|
|
114
|
+
* goes through a slow generic Float16 unboxing routine, and the result is
|
|
115
|
+
* the opposite of what you'd expect: bench at 64³ shows **49% slower** with
|
|
116
|
+
* f16, at 128³ **28% slower** (see `bench: half_precision_pressure on/off`
|
|
117
|
+
* in bench.spec.js). The bandwidth-savings story still holds in principle;
|
|
118
|
+
* it'll likely become a real win once V8 adds inline support for
|
|
119
|
+
* Float16Array access (the typed array landed in Node 24 / TC39 Stage 4 only
|
|
120
|
+
* recently).
|
|
121
|
+
*
|
|
122
|
+
* Cost when it does win: Float16 has ~3 decimal digits of precision. The SOR
|
|
123
|
+
* iterate rounds to f16 on every write, so iteration error can't fall below
|
|
124
|
+
* ~10⁻³ relative. Bench currently shows max|div| within 8% of the f32
|
|
125
|
+
* baseline at 64³ and 128³ — acceptable for visual sim but not for
|
|
126
|
+
* quantitative pressure use.
|
|
127
|
+
*
|
|
128
|
+
* Must be set before {@link build}.
|
|
129
|
+
*
|
|
130
|
+
* The simulator's internal divergence scratch follows this type automatically
|
|
131
|
+
* (re-allocated to match `pressure.constructor` on each project call).
|
|
132
|
+
*
|
|
133
|
+
* @type {boolean}
|
|
134
|
+
*/
|
|
135
|
+
half_precision_pressure = false;
|
|
21
136
|
|
|
137
|
+
/**
|
|
138
|
+
* @type {{ name: string, data: Float32Array }[]}
|
|
139
|
+
*/
|
|
140
|
+
#scalar_attributes = [];
|
|
22
141
|
|
|
23
|
-
#
|
|
24
|
-
#resolution = [0, 0, 0]
|
|
142
|
+
#built = false;
|
|
25
143
|
|
|
26
|
-
|
|
144
|
+
/**
|
|
145
|
+
* Set the grid dimensions in cells. Must be called before {@link build}; throws if
|
|
146
|
+
* the field is already built.
|
|
147
|
+
* @param {number} res_x positive integer
|
|
148
|
+
* @param {number} res_y positive integer
|
|
149
|
+
* @param {number} res_z positive integer
|
|
150
|
+
*/
|
|
151
|
+
setResolution(res_x, res_y, res_z) {
|
|
152
|
+
assert.notOk(this.#built, "resolution cannot be changed after build()");
|
|
153
|
+
assert.isPositiveInteger(res_x, "res_x");
|
|
154
|
+
assert.isPositiveInteger(res_y, "res_y");
|
|
155
|
+
assert.isPositiveInteger(res_z, "res_z");
|
|
156
|
+
|
|
157
|
+
this.#resolution[0] = res_x;
|
|
158
|
+
this.#resolution[1] = res_y;
|
|
159
|
+
this.#resolution[2] = res_z;
|
|
160
|
+
}
|
|
27
161
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
162
|
+
/**
|
|
163
|
+
* @return {[number, number, number]} A reference to the internal resolution array.
|
|
164
|
+
* Do not mutate.
|
|
165
|
+
*/
|
|
166
|
+
getResolution() {
|
|
167
|
+
return this.#resolution;
|
|
168
|
+
}
|
|
31
169
|
|
|
32
|
-
|
|
170
|
+
/**
|
|
171
|
+
* @return {number} `res_x * res_y * res_z`. Zero until {@link setResolution} is
|
|
172
|
+
* called.
|
|
173
|
+
*/
|
|
174
|
+
cellCount() {
|
|
175
|
+
return this.#resolution[0] * this.#resolution[1] * this.#resolution[2];
|
|
176
|
+
}
|
|
33
177
|
|
|
34
|
-
|
|
178
|
+
/**
|
|
179
|
+
* Register a passive scalar attribute (density, temperature, dye, etc.) that will be
|
|
180
|
+
* advected by the velocity field each step. Idempotent — re-adding an existing name
|
|
181
|
+
* returns the existing index.
|
|
182
|
+
*
|
|
183
|
+
* Must be called before {@link build}.
|
|
184
|
+
*
|
|
185
|
+
* @param {string} name
|
|
186
|
+
* @return {number} index of the attribute (use with {@link setScalarAtIndex})
|
|
187
|
+
*/
|
|
188
|
+
addScalar(name) {
|
|
189
|
+
assert.notOk(this.#built, "addScalar cannot be called after build()");
|
|
190
|
+
assert.isString(name, "name");
|
|
191
|
+
assert.greaterThan(name.length, 0, "name must be non-empty");
|
|
192
|
+
|
|
193
|
+
const existing = this.#scalar_attributes.findIndex(a => a.name === name);
|
|
194
|
+
if (existing !== -1) {
|
|
195
|
+
return existing;
|
|
196
|
+
}
|
|
35
197
|
|
|
198
|
+
const index = this.#scalar_attributes.length;
|
|
199
|
+
this.#scalar_attributes.push({ name, data: null });
|
|
36
200
|
return index;
|
|
37
201
|
}
|
|
38
202
|
|
|
39
|
-
|
|
40
|
-
|
|
203
|
+
/**
|
|
204
|
+
* @param {string} name
|
|
205
|
+
* @return {number} index the attribute was registered with, or -1 if not present.
|
|
206
|
+
*/
|
|
207
|
+
scalarIndex(name) {
|
|
208
|
+
return this.#scalar_attributes.findIndex(a => a.name === name);
|
|
41
209
|
}
|
|
42
210
|
|
|
43
211
|
/**
|
|
44
|
-
*
|
|
45
212
|
* @param {string} name
|
|
46
|
-
* @return {Float32Array}
|
|
213
|
+
* @return {Float32Array|null} live buffer for the named scalar, or null if not
|
|
214
|
+
* registered.
|
|
47
215
|
*/
|
|
48
|
-
|
|
49
|
-
|
|
216
|
+
getScalarData(name) {
|
|
217
|
+
const a = this.#scalar_attributes.find(a => a.name === name);
|
|
218
|
+
return a === undefined ? null : a.data;
|
|
50
219
|
}
|
|
51
220
|
|
|
52
|
-
|
|
53
|
-
|
|
221
|
+
/**
|
|
222
|
+
* @return {{ name: string, data: Float32Array }[]} Live reference; do not mutate.
|
|
223
|
+
*/
|
|
224
|
+
getScalarAttributes() {
|
|
225
|
+
return this.#scalar_attributes;
|
|
54
226
|
}
|
|
55
227
|
|
|
56
228
|
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* @param {number} offset
|
|
229
|
+
* Allocate all buffers. Must be called before any read/write. After this point,
|
|
230
|
+
* resolution and attribute set are frozen.
|
|
60
231
|
*/
|
|
61
|
-
|
|
232
|
+
build() {
|
|
233
|
+
assert.notOk(this.#built, "build() called twice");
|
|
234
|
+
assert.greaterThanOrEqual(this.#resolution[0], 1, "setResolution(...) must be called before build()");
|
|
62
235
|
|
|
63
|
-
const
|
|
236
|
+
const cell_count = this.cellCount();
|
|
64
237
|
|
|
65
|
-
|
|
238
|
+
this.velocity_x = new Float32Array(cell_count);
|
|
239
|
+
this.velocity_y = new Float32Array(cell_count);
|
|
240
|
+
this.velocity_z = new Float32Array(cell_count);
|
|
241
|
+
this.solid = new Uint8Array(cell_count);
|
|
242
|
+
this.solid_neighbour_mask = new Uint8Array(cell_count);
|
|
243
|
+
const PressureCtor = this.half_precision_pressure ? Float16Array : Float32Array;
|
|
244
|
+
this.pressure = new PressureCtor(cell_count);
|
|
66
245
|
|
|
67
|
-
for (
|
|
68
|
-
|
|
246
|
+
for (const attr of this.#scalar_attributes) {
|
|
247
|
+
attr.data = new Float32Array(cell_count);
|
|
248
|
+
}
|
|
69
249
|
|
|
70
|
-
|
|
250
|
+
this.#built = true;
|
|
251
|
+
}
|
|
71
252
|
|
|
253
|
+
/**
|
|
254
|
+
* Linear cell index for integer grid coordinates.
|
|
255
|
+
* @param {number} x integer in [0, res_x)
|
|
256
|
+
* @param {number} y integer in [0, res_y)
|
|
257
|
+
* @param {number} z integer in [0, res_z)
|
|
258
|
+
* @return {number} flat index `z * res_x * res_y + y * res_x + x`
|
|
259
|
+
*/
|
|
260
|
+
cellIndex(x, y, z) {
|
|
261
|
+
const res_x = this.#resolution[0];
|
|
262
|
+
const res_y = this.#resolution[1];
|
|
263
|
+
const res_z = this.#resolution[2];
|
|
264
|
+
assert.greaterThanOrEqual(x, 0, "x");
|
|
265
|
+
assert.lessThan(x, res_x, "x");
|
|
266
|
+
assert.greaterThanOrEqual(y, 0, "y");
|
|
267
|
+
assert.lessThan(y, res_y, "y");
|
|
268
|
+
assert.greaterThanOrEqual(z, 0, "z");
|
|
269
|
+
assert.lessThan(z, res_z, "z");
|
|
270
|
+
return z * res_x * res_y + y * res_x + x;
|
|
271
|
+
}
|
|
72
272
|
|
|
73
|
-
|
|
74
|
-
|
|
273
|
+
/**
|
|
274
|
+
* Set the velocity at an integer grid cell.
|
|
275
|
+
* @param {number} x
|
|
276
|
+
* @param {number} y
|
|
277
|
+
* @param {number} z
|
|
278
|
+
* @param {number} vx
|
|
279
|
+
* @param {number} vy
|
|
280
|
+
* @param {number} vz
|
|
281
|
+
*/
|
|
282
|
+
setVelocityAt(x, y, z, vx, vy, vz) {
|
|
283
|
+
const c = this.cellIndex(x, y, z);
|
|
284
|
+
this.velocity_x[c] = vx;
|
|
285
|
+
this.velocity_y[c] = vy;
|
|
286
|
+
this.velocity_z[c] = vz;
|
|
287
|
+
}
|
|
75
288
|
|
|
76
|
-
|
|
289
|
+
/**
|
|
290
|
+
* Add to the velocity at an integer grid cell (impulse).
|
|
291
|
+
* @param {number} x
|
|
292
|
+
* @param {number} y
|
|
293
|
+
* @param {number} z
|
|
294
|
+
* @param {number} dvx
|
|
295
|
+
* @param {number} dvy
|
|
296
|
+
* @param {number} dvz
|
|
297
|
+
*/
|
|
298
|
+
addVelocityAt(x, y, z, dvx, dvy, dvz) {
|
|
299
|
+
const c = this.cellIndex(x, y, z);
|
|
300
|
+
this.velocity_x[c] += dvx;
|
|
301
|
+
this.velocity_y[c] += dvy;
|
|
302
|
+
this.velocity_z[c] += dvz;
|
|
77
303
|
}
|
|
78
304
|
|
|
79
|
-
|
|
305
|
+
/**
|
|
306
|
+
* @param {number} attribute_index
|
|
307
|
+
* @param {number} x
|
|
308
|
+
* @param {number} y
|
|
309
|
+
* @param {number} z
|
|
310
|
+
* @param {number} value
|
|
311
|
+
*/
|
|
312
|
+
setScalarAtIndex(attribute_index, x, y, z, value) {
|
|
313
|
+
assert.greaterThanOrEqual(attribute_index, 0, "attribute_index");
|
|
314
|
+
assert.lessThan(attribute_index, this.#scalar_attributes.length, "attribute_index");
|
|
315
|
+
const c = this.cellIndex(x, y, z);
|
|
316
|
+
this.#scalar_attributes[attribute_index].data[c] = value;
|
|
317
|
+
}
|
|
80
318
|
|
|
81
|
-
|
|
319
|
+
/**
|
|
320
|
+
* Mark a cell as solid (wall) or fluid.
|
|
321
|
+
* @param {number} x
|
|
322
|
+
* @param {number} y
|
|
323
|
+
* @param {number} z
|
|
324
|
+
* @param {boolean} is_solid
|
|
325
|
+
*/
|
|
326
|
+
setSolidAt(x, y, z, is_solid) {
|
|
327
|
+
this.solid[this.cellIndex(x, y, z)] = is_solid ? 1 : 0;
|
|
328
|
+
}
|
|
82
329
|
|
|
83
|
-
|
|
330
|
+
/**
|
|
331
|
+
* @param {number} x
|
|
332
|
+
* @param {number} y
|
|
333
|
+
* @param {number} z
|
|
334
|
+
* @return {boolean} true if the cell is marked solid.
|
|
335
|
+
*/
|
|
336
|
+
isSolidAt(x, y, z) {
|
|
337
|
+
return this.solid[this.cellIndex(x, y, z)] !== 0;
|
|
338
|
+
}
|
|
84
339
|
|
|
85
|
-
|
|
340
|
+
/**
|
|
341
|
+
* Sample velocity at a fractional grid position (positions outside the grid are
|
|
342
|
+
* clamped). Writes into `out` and returns it.
|
|
343
|
+
* @param {Float32Array|number[]} out Length-3 destination.
|
|
344
|
+
* @param {number} x
|
|
345
|
+
* @param {number} y
|
|
346
|
+
* @param {number} z
|
|
347
|
+
* @return {Float32Array|number[]} `out`, for chaining.
|
|
348
|
+
*/
|
|
349
|
+
sampleVelocity(out, x, y, z) {
|
|
350
|
+
const res_x = this.#resolution[0];
|
|
351
|
+
const res_y = this.#resolution[1];
|
|
352
|
+
const res_z = this.#resolution[2];
|
|
353
|
+
out[0] = scs3d_sample_linear(this.velocity_x, res_x, res_y, res_z, x, y, z);
|
|
354
|
+
out[1] = scs3d_sample_linear(this.velocity_y, res_x, res_y, res_z, x, y, z);
|
|
355
|
+
out[2] = scs3d_sample_linear(this.velocity_z, res_x, res_y, res_z, x, y, z);
|
|
356
|
+
return out;
|
|
357
|
+
}
|
|
86
358
|
|
|
359
|
+
/**
|
|
360
|
+
* Sample a scalar attribute at a fractional grid position.
|
|
361
|
+
* @param {string} name
|
|
362
|
+
* @param {number} x
|
|
363
|
+
* @param {number} y
|
|
364
|
+
* @param {number} z
|
|
365
|
+
* @return {number} trilinearly-interpolated value at `(x, y, z)`.
|
|
366
|
+
*/
|
|
367
|
+
sampleScalar(name, x, y, z) {
|
|
368
|
+
const data = this.getScalarData(name);
|
|
369
|
+
assert.notNull(data, `scalar attribute '${name}'`);
|
|
370
|
+
return scs3d_sample_linear(data, this.#resolution[0], this.#resolution[1], this.#resolution[2], x, y, z);
|
|
87
371
|
}
|
|
88
372
|
|
|
89
|
-
|
|
90
|
-
|
|
373
|
+
/**
|
|
374
|
+
* Strict value equality. Two fields are equal iff they have the same resolution,
|
|
375
|
+
* the same set of scalar attributes (matched by name AND index), and the same
|
|
376
|
+
* buffer contents in `velocity_*`, `solid`, `pressure`, and each scalar. Pre-build
|
|
377
|
+
* fields compare by resolution + attribute names only (their buffers are null).
|
|
378
|
+
*
|
|
379
|
+
* O(N) — walks every cell. Use {@link hash} for change-detection on hot paths.
|
|
380
|
+
*
|
|
381
|
+
* @param {FluidField} other
|
|
382
|
+
* @return {boolean}
|
|
383
|
+
*/
|
|
384
|
+
equals(other) {
|
|
385
|
+
if (other === this) {
|
|
386
|
+
return true;
|
|
387
|
+
}
|
|
388
|
+
if (!(other instanceof FluidField)) {
|
|
389
|
+
return false;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
if (this.#resolution[0] !== other.#resolution[0]
|
|
393
|
+
|| this.#resolution[1] !== other.#resolution[1]
|
|
394
|
+
|| this.#resolution[2] !== other.#resolution[2]) {
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
if (this.#built !== other.#built) {
|
|
399
|
+
return false;
|
|
400
|
+
}
|
|
91
401
|
|
|
92
|
-
const
|
|
402
|
+
const my_attrs = this.#scalar_attributes;
|
|
403
|
+
const other_attrs = other.#scalar_attributes;
|
|
404
|
+
if (my_attrs.length !== other_attrs.length) {
|
|
405
|
+
return false;
|
|
406
|
+
}
|
|
407
|
+
for (let i = 0; i < my_attrs.length; i++) {
|
|
408
|
+
if (my_attrs[i].name !== other_attrs[i].name) {
|
|
409
|
+
return false;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
93
412
|
|
|
94
|
-
|
|
413
|
+
if (!this.#built) {
|
|
414
|
+
// Buffers are null on both sides; resolution + names already matched.
|
|
415
|
+
return true;
|
|
416
|
+
}
|
|
95
417
|
|
|
96
|
-
this.
|
|
418
|
+
if (!is_typed_array_equals(this.velocity_x, other.velocity_x)
|
|
419
|
+
|| !is_typed_array_equals(this.velocity_y, other.velocity_y)
|
|
420
|
+
|| !is_typed_array_equals(this.velocity_z, other.velocity_z)) {
|
|
421
|
+
return false;
|
|
422
|
+
}
|
|
423
|
+
if (!is_typed_array_equals(this.solid, other.solid)) {
|
|
424
|
+
return false;
|
|
425
|
+
}
|
|
426
|
+
if (!is_typed_array_equals(this.pressure, other.pressure)) {
|
|
427
|
+
return false;
|
|
428
|
+
}
|
|
429
|
+
for (let i = 0; i < my_attrs.length; i++) {
|
|
430
|
+
if (!is_typed_array_equals(my_attrs[i].data, other_attrs[i].data)) {
|
|
431
|
+
return false;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
return true;
|
|
97
435
|
}
|
|
98
436
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
437
|
+
/**
|
|
438
|
+
* Fast hash suitable for change-detection. Combines the resolution and a *sparse*
|
|
439
|
+
* sample of the velocity_x buffer — {@link sparse_typed_array_hash} only inspects
|
|
440
|
+
* the first ~1024 cells with stride enough to take ~31 samples, regardless of how
|
|
441
|
+
* large the field is. The hash will catch most local edits to the velocity field
|
|
442
|
+
* but is not a content-perfect fingerprint; for that, fall through to
|
|
443
|
+
* {@link equals}.
|
|
444
|
+
*
|
|
445
|
+
* Constant-time relative to grid size in the common case.
|
|
446
|
+
*
|
|
447
|
+
* @return {number}
|
|
448
|
+
*/
|
|
449
|
+
hash() {
|
|
450
|
+
const velocity_sample = this.#built
|
|
451
|
+
? sparse_typed_array_hash(this.velocity_x, 0, this.velocity_x.length)
|
|
452
|
+
: 0;
|
|
453
|
+
return combine_hash(
|
|
454
|
+
this.#resolution[0],
|
|
455
|
+
this.#resolution[1],
|
|
456
|
+
this.#resolution[2],
|
|
457
|
+
this.#scalar_attributes.length,
|
|
458
|
+
velocity_sample
|
|
459
|
+
);
|
|
460
|
+
}
|
|
103
461
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
462
|
+
/**
|
|
463
|
+
* Rebuild {@link solid_neighbour_mask} from the current {@link solid} buffer.
|
|
464
|
+
*
|
|
465
|
+
* O(N) — one byte-write per cell, six byte-reads per cell. Called by the
|
|
466
|
+
* simulator at the top of each project so callers never have to remember to
|
|
467
|
+
* invalidate the mask after mutating solids; the cost is amortized across the
|
|
468
|
+
* SOR sweep's many iterations.
|
|
469
|
+
*
|
|
470
|
+
* Encoding: see {@link solid_neighbour_mask}.
|
|
471
|
+
*/
|
|
472
|
+
recomputeSolidNeighbourMask() {
|
|
473
|
+
if (!this.#built) {
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
v3_grid_compute_solid_neighbour_mask(
|
|
477
|
+
this.solid_neighbour_mask,
|
|
478
|
+
this.solid,
|
|
479
|
+
this.#resolution[0], this.#resolution[1], this.#resolution[2]
|
|
480
|
+
);
|
|
107
481
|
}
|
|
108
482
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
483
|
+
/**
|
|
484
|
+
* Translate the field's contents by `(shift_x, shift_y, shift_z)` grid cells —
|
|
485
|
+
* called when the field's world-space origin moves, so the fluid data (anchored
|
|
486
|
+
* to world space) follows. Every owned buffer (velocity_x/y/z, solid, pressure,
|
|
487
|
+
* each scalar attribute) is shifted, then the newly-exposed edges are patched
|
|
488
|
+
* via {@link v3_grid_patch_edges_uniform} (zero-gradient Neumann extrapolation —
|
|
489
|
+
* "the field is locally uniform").
|
|
490
|
+
*
|
|
491
|
+
* Direction convention matches the primitive: positive shift means the grid's
|
|
492
|
+
* world origin moved in that direction, so each cell takes the value previously
|
|
493
|
+
* at its `+shift` neighbour.
|
|
494
|
+
*
|
|
495
|
+
* `(0, 0, 0)` is a no-op; |shift| ≥ res on any axis zero-fills (no valid source
|
|
496
|
+
* left to replicate from). Pre-build fields (buffers null) are no-op'd.
|
|
497
|
+
*
|
|
498
|
+
* The solid mask is NOT migrated — it's cleared. Solids are out of scope for the
|
|
499
|
+
* shift machinery: the contract is that the caller re-voxelizes scene geometry
|
|
500
|
+
* and splats updated solid cells back into the field before the next simulation
|
|
501
|
+
* tick. Migrating the existing mask would either lie about where the walls are
|
|
502
|
+
* (if scene geometry moved) or produce double-bookkeeping problems if the caller
|
|
503
|
+
* also re-voxelizes. Clearing keeps the contract obvious: "between a shift and
|
|
504
|
+
* the next step, the field has no solids until you write them."
|
|
505
|
+
*
|
|
506
|
+
* @param {number} shift_x integer
|
|
507
|
+
* @param {number} shift_y integer
|
|
508
|
+
* @param {number} shift_z integer
|
|
509
|
+
*/
|
|
510
|
+
shift(shift_x, shift_y, shift_z) {
|
|
511
|
+
if (!this.#built) {
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
if (shift_x === 0 && shift_y === 0 && shift_z === 0) {
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
const rx = this.#resolution[0];
|
|
519
|
+
const ry = this.#resolution[1];
|
|
520
|
+
const rz = this.#resolution[2];
|
|
521
|
+
|
|
522
|
+
// Velocity components.
|
|
523
|
+
v3_grid_shift_in_place(this.velocity_x, rx, ry, rz, shift_x, shift_y, shift_z);
|
|
524
|
+
v3_grid_patch_edges_uniform(this.velocity_x, rx, ry, rz, shift_x, shift_y, shift_z);
|
|
525
|
+
|
|
526
|
+
v3_grid_shift_in_place(this.velocity_y, rx, ry, rz, shift_x, shift_y, shift_z);
|
|
527
|
+
v3_grid_patch_edges_uniform(this.velocity_y, rx, ry, rz, shift_x, shift_y, shift_z);
|
|
113
528
|
|
|
114
|
-
this
|
|
115
|
-
this
|
|
116
|
-
|
|
529
|
+
v3_grid_shift_in_place(this.velocity_z, rx, ry, rz, shift_x, shift_y, shift_z);
|
|
530
|
+
v3_grid_patch_edges_uniform(this.velocity_z, rx, ry, rz, shift_x, shift_y, shift_z);
|
|
531
|
+
|
|
532
|
+
// Solid mask — cleared, not migrated. Caller is expected to re-voxelize and
|
|
533
|
+
// splat solids before the next simulation tick (see method docstring).
|
|
534
|
+
// The derived neighbour mask is cleared too; the simulator's next project()
|
|
535
|
+
// will repopulate it from the (potentially re-splatted) solid mask.
|
|
536
|
+
this.solid.fill(0);
|
|
537
|
+
this.solid_neighbour_mask.fill(0);
|
|
538
|
+
|
|
539
|
+
// Pressure (warm-start state, carried across steps).
|
|
540
|
+
v3_grid_shift_in_place(this.pressure, rx, ry, rz, shift_x, shift_y, shift_z);
|
|
541
|
+
v3_grid_patch_edges_uniform(this.pressure, rx, ry, rz, shift_x, shift_y, shift_z);
|
|
542
|
+
|
|
543
|
+
// Scalar attributes.
|
|
544
|
+
for (let i = 0; i < this.#scalar_attributes.length; i++) {
|
|
545
|
+
const data = this.#scalar_attributes[i].data;
|
|
546
|
+
v3_grid_shift_in_place(data, rx, ry, rz, shift_x, shift_y, shift_z);
|
|
547
|
+
v3_grid_patch_edges_uniform(data, rx, ry, rz, shift_x, shift_y, shift_z);
|
|
548
|
+
}
|
|
117
549
|
}
|
|
118
550
|
|
|
119
|
-
|
|
120
|
-
|
|
551
|
+
/**
|
|
552
|
+
* Zero velocity, pressure, and all scalar attributes. Solid mask is preserved.
|
|
553
|
+
* Pressure is cleared to drop the warm-start (otherwise the next step's solve
|
|
554
|
+
* begins from a stale solution that no longer matches the zero velocity).
|
|
555
|
+
*/
|
|
556
|
+
clear() {
|
|
557
|
+
assert.ok(this.#built, "build() must be called before clear()");
|
|
558
|
+
this.velocity_x.fill(0);
|
|
559
|
+
this.velocity_y.fill(0);
|
|
560
|
+
this.velocity_z.fill(0);
|
|
561
|
+
this.pressure.fill(0);
|
|
562
|
+
for (const attr of this.#scalar_attributes) {
|
|
563
|
+
attr.data.fill(0);
|
|
564
|
+
}
|
|
121
565
|
}
|
|
122
566
|
}
|