@series-inc/rundot-syncplay 6.0.0-rc.2 → 6.0.0-rc.21
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/README.md +133 -0
- package/core/deterministic-math.d.ts +75 -1
- package/core/native/instance_ledger.hpp +1095 -0
- package/core/native/legacy_checkpoint_ids.hpp +107 -0
- package/core/native/physics/abi.cpp +39 -211
- package/core/native/physics/abi.hpp +2 -6
- package/core/native/physics/articulation.cpp +1434 -0
- package/core/native/physics/articulation.hpp +279 -0
- package/core/native/physics/buoyancy.cpp +1588 -0
- package/core/native/physics/buoyancy.hpp +254 -0
- package/core/native/physics/capsule_triangle.cpp +168 -0
- package/core/native/physics/capsule_triangle.hpp +40 -0
- package/core/native/physics/capsule_triangle_native.inc +291 -0
- package/core/native/physics/certified_sum.hpp +218 -0
- package/core/native/physics/character.cpp +638 -0
- package/core/native/physics/character.hpp +169 -0
- package/core/native/physics/checkpoint_schema.hpp +379 -0
- package/core/native/physics/cloth.cpp +1401 -0
- package/core/native/physics/cloth.hpp +357 -0
- package/core/native/physics/constraint_rows.cpp +363 -2
- package/core/native/physics/constraint_rows.hpp +72 -1
- package/core/native/physics/deformable_query.cpp +1630 -0
- package/core/native/physics/deformable_query.hpp +578 -0
- package/core/native/physics/distance.cpp +1166 -0
- package/core/native/physics/distance.hpp +151 -0
- package/core/native/physics/exact/exact-applied.cpp +101 -0
- package/core/native/physics/exact/exact-applied.hpp +112 -0
- package/core/native/physics/exact/exact-dyadic.cpp +691 -0
- package/core/native/physics/exact/exact-dyadic.hpp +58 -0
- package/core/native/physics/exact/exact-operation.hpp +51 -0
- package/core/native/physics/exact/word-core.hpp +262 -0
- package/core/native/physics/extended_abi.cpp +1242 -0
- package/core/native/physics/extended_abi.hpp +355 -0
- package/core/native/physics/extended_abi_characters.cpp +261 -0
- package/core/native/physics/extended_abi_characters.hpp +434 -0
- package/core/native/physics/extended_abi_core_features.cpp +713 -0
- package/core/native/physics/extended_abi_core_features.hpp +226 -0
- package/core/native/physics/extended_abi_deformables.cpp +448 -0
- package/core/native/physics/extended_abi_deformables.hpp +867 -0
- package/core/native/physics/extended_abi_vehicles.cpp +411 -0
- package/core/native/physics/extended_abi_vehicles.hpp +222 -0
- package/core/native/physics/fracture.cpp +1981 -0
- package/core/native/physics/fracture.hpp +460 -0
- package/core/native/physics/gear.cpp +563 -0
- package/core/native/physics/gear.hpp +158 -0
- package/core/native/physics/geometry_memory.hpp +476 -0
- package/core/native/physics/geometry_store.cpp +547 -0
- package/core/native/physics/geometry_store.hpp +134 -0
- package/core/native/physics/lag_compensation.cpp +1626 -0
- package/core/native/physics/lag_compensation.hpp +405 -0
- package/core/native/physics/mass_properties.cpp +449 -0
- package/core/native/physics/mass_properties.hpp +23 -0
- package/core/native/physics/material_pose.hpp +988 -0
- package/core/native/physics/particles.cpp +1065 -0
- package/core/native/physics/particles.hpp +261 -0
- package/core/native/physics/path_joint.cpp +781 -0
- package/core/native/physics/path_joint.hpp +154 -0
- package/core/native/physics/physics.cpp +13043 -1065
- package/core/native/physics/physics.hpp +184 -8
- package/core/native/physics/planar_deformable.cpp +2433 -0
- package/core/native/physics/planar_deformable.hpp +889 -0
- package/core/native/physics/platformer_2d.cpp +1353 -0
- package/core/native/physics/platformer_2d.hpp +340 -0
- package/core/native/physics/powered_ragdoll.cpp +1100 -0
- package/core/native/physics/powered_ragdoll.hpp +279 -0
- package/core/native/physics/powertrain.cpp +586 -0
- package/core/native/physics/powertrain.hpp +180 -0
- package/core/native/physics/pulley.cpp +311 -0
- package/core/native/physics/pulley.hpp +121 -0
- package/core/native/physics/ragdoll.cpp +586 -0
- package/core/native/physics/ragdoll.hpp +221 -0
- package/core/native/physics/rope.cpp +692 -0
- package/core/native/physics/rope.hpp +215 -0
- package/core/native/physics/rounded_convex.cpp +1229 -0
- package/core/native/physics/rounded_convex.hpp +287 -0
- package/core/native/physics/sdf_geometry.cpp +1821 -0
- package/core/native/physics/sdf_geometry.hpp +474 -0
- package/core/native/physics/soft_body.cpp +1449 -0
- package/core/native/physics/soft_body.hpp +328 -0
- package/core/native/physics/soft_collision.cpp +1862 -0
- package/core/native/physics/soft_collision.hpp +561 -0
- package/core/native/physics/surface_velocity.cpp +366 -0
- package/core/native/physics/surface_velocity.hpp +243 -0
- package/core/native/physics/topology.cpp +357 -39
- package/core/native/physics/topology.hpp +97 -6
- package/core/native/physics/tracks.cpp +1179 -0
- package/core/native/physics/tracks.hpp +404 -0
- package/core/native/physics/vehicle.cpp +629 -0
- package/core/native/physics/vehicle.hpp +191 -0
- package/core/native/physics/voxel_cooking.cpp +1929 -0
- package/core/native/physics/voxel_cooking.hpp +395 -0
- package/core/native/physics/world.cpp +5290 -854
- package/core/native/physics/world.hpp +796 -24
- package/core/native/physics/world_abi.cpp +3840 -306
- package/core/native/physics/world_abi.hpp +530 -10
- package/core/native/physics/world_digest_visitor.hpp +277 -0
- package/core/native/physics/world_strong_digest.hpp +557 -0
- package/core/native/physics2d/ccd.cpp +1302 -0
- package/core/native/physics2d/ccd.hpp +141 -0
- package/core/native/physics2d/checkpoint_memory.hpp +349 -0
- package/core/native/physics2d/clock_primitives.hpp +138 -0
- package/core/native/physics2d/commands.cpp +174 -28
- package/core/native/physics2d/commands.hpp +3 -1
- package/core/native/physics2d/compound.cpp +581 -0
- package/core/native/physics2d/compound.hpp +248 -0
- package/core/native/physics2d/contour.cpp +325 -0
- package/core/native/physics2d/contour.hpp +143 -0
- package/core/native/physics2d/frame_scope.hpp +124 -0
- package/core/native/physics2d/joint_phases.hpp +93 -0
- package/core/native/physics2d/joints.cpp +587 -150
- package/core/native/physics2d/joints.hpp +5 -0
- package/core/native/physics2d/memory_private.hpp +125 -0
- package/core/native/physics2d/owned_abi.cpp +1354 -879
- package/core/native/physics2d/owned_abi.hpp +190 -52
- package/core/native/physics2d/phase_test_hooks.hpp +17 -0
- package/core/native/physics2d/physics2d.cpp +2073 -120
- package/core/native/physics2d/physics2d.hpp +154 -2
- package/core/native/physics2d/queries.cpp +1055 -79
- package/core/native/physics2d/queries.hpp +71 -5
- package/core/native/physics2d/world.cpp +1313 -353
- package/core/native/physics2d/world.hpp +124 -13
- package/core/native/sha256/sha256_compress_unsigned.hpp +68 -0
- package/core/native/sha256/sha256_fips_constants.hpp +24 -0
- package/core/native/sha256/sha256_length.hpp +56 -0
- package/core/native/sha256/sha256_memo.hpp +48 -0
- package/core/native/sha256/sha256_sink.hpp +234 -0
- package/core/physics2d-owned.d.ts +466 -126
- package/core/runtime.d.ts +192 -19
- package/core/scripts/build-native.mjs +34 -0
- package/core/scripts/build-wasm-physics.mjs +272 -23
- package/core/scripts/extended-physics-profile.mjs +634 -0
- package/core/scripts/generate-physics2d-vectors.mjs +59 -0
- package/core/src/kinetix-deterministic-math.d.ts +2 -0
- package/core/src/kinetix-deterministic-math.mjs +513 -27
- package/core/src/kinetix-owned-runtime-adapter.mjs +788 -0
- package/core/src/kinetix-runtime-adapter-utils.mjs +54 -6
- package/core/src/kinetix-runtime-contract.mjs +55 -9
- package/core/src/kinetix-runtime-identity.mjs +12 -1
- package/core/src/kinetix-session-config.mjs +7 -2
- package/core/src/kinetix-state-report.mjs +36 -0
- package/core/src/physics/abi-constants.mjs +5 -4
- package/core/src/physics/articulation.d.mts +194 -0
- package/core/src/physics/articulation.mjs +1141 -0
- package/core/src/physics/buoyancy.d.mts +143 -0
- package/core/src/physics/buoyancy.mjs +268 -0
- package/core/src/physics/cloth.d.mts +314 -0
- package/core/src/physics/cloth.mjs +1156 -0
- package/core/src/physics/deformable-query.d.mts +217 -0
- package/core/src/physics/deformable-query.mjs +1412 -0
- package/core/src/physics/distance.d.mts +160 -0
- package/core/src/physics/distance.mjs +175 -0
- package/core/src/physics/extended-wasm-instance.d.mts +5 -0
- package/core/src/physics/extended-wasm-instance.mjs +48 -0
- package/core/src/physics/feature-api.d.mts +74 -0
- package/core/src/physics/feature-api.mjs +98 -0
- package/core/src/physics/fracture.d.mts +133 -0
- package/core/src/physics/fracture.mjs +1324 -0
- package/core/src/physics/gear.d.mts +585 -0
- package/core/src/physics/gear.mjs +955 -0
- package/core/src/physics/lag-compensation.d.mts +101 -0
- package/core/src/physics/lag-compensation.mjs +1100 -0
- package/core/src/physics/mass-properties.d.mts +114 -0
- package/core/src/physics/mass-properties.mjs +137 -468
- package/core/src/physics/particles.d.mts +177 -0
- package/core/src/physics/particles.mjs +758 -0
- package/core/src/physics/path-joint.d.mts +171 -0
- package/core/src/physics/path-joint.mjs +1231 -0
- package/core/src/physics/physics-extended-wasm-module.generated.mjs +13 -0
- package/core/src/physics/physics-profile-wasm-module.generated.mjs +48 -0
- package/core/src/physics/physics-wasm-module.generated.mjs +34 -5
- package/core/src/physics/powered-ragdoll.d.mts +188 -0
- package/core/src/physics/powered-ragdoll.mjs +1043 -0
- package/core/src/physics/powertrain.d.mts +260 -0
- package/core/src/physics/powertrain.mjs +621 -0
- package/core/src/physics/pulley.d.mts +98 -0
- package/core/src/physics/pulley.mjs +686 -0
- package/core/src/physics/ragdoll.d.mts +289 -0
- package/core/src/physics/ragdoll.mjs +1323 -0
- package/core/src/physics/rope.d.mts +241 -0
- package/core/src/physics/rope.mjs +319 -0
- package/core/src/physics/rounded-convex.d.mts +328 -0
- package/core/src/physics/rounded-convex.mjs +1404 -0
- package/core/src/physics/sdf-geometry.d.mts +117 -0
- package/core/src/physics/sdf-geometry.mjs +1204 -0
- package/core/src/physics/soft-body.d.mts +144 -0
- package/core/src/physics/soft-body.mjs +1285 -0
- package/core/src/physics/soft-collision.d.mts +651 -0
- package/core/src/physics/soft-collision.mjs +1883 -0
- package/core/src/physics/surface-velocity.d.mts +156 -0
- package/core/src/physics/surface-velocity.mjs +722 -0
- package/core/src/physics/tracks.d.mts +411 -0
- package/core/src/physics/tracks.mjs +1074 -0
- package/core/src/physics/vehicle.d.mts +3 -0
- package/core/src/physics/vehicle.mjs +172 -0
- package/core/src/physics/voxel-cooking.d.mts +219 -0
- package/core/src/physics/voxel-cooking.mjs +1499 -0
- package/core/src/physics/voxel-swept-quad.mjs +110 -0
- package/core/src/physics/wasm-instance.mjs +160 -23
- package/core/src/physics/world.d.mts +62 -0
- package/core/src/physics/world.mjs +1947 -152
- package/core/src/physics2d/body-state.mjs +218 -15
- package/core/src/physics2d/collision.d.mts +52 -0
- package/core/src/physics2d/collision.mjs +234 -0
- package/core/src/physics2d/compound.mjs +454 -0
- package/core/src/physics2d/contour-state.mjs +771 -0
- package/core/src/physics2d/feature-api.d.mts +211 -0
- package/core/src/physics2d/feature-api.mjs +3 -0
- package/core/src/physics2d/fluid-state.mjs +145 -0
- package/core/src/physics2d/joint-state.mjs +1 -1
- package/core/src/physics2d/owned-queries.mjs +3 -1
- package/core/src/physics2d/owned-transport.mjs +268 -122
- package/core/src/physics2d/owned-world.mjs +353 -230
- package/core/src/physics2d/particle-fluid.d.mts +152 -0
- package/core/src/physics2d/particle-fluid.mjs +233 -0
- package/core/src/physics2d/physics2d-wasm-module.generated.mjs +27 -10
- package/core/src/physics2d/query-codec.mjs +61 -13
- package/core/src/physics2d/submerged-geometry.d.mts +51 -0
- package/core/src/physics2d/submerged-geometry.mjs +186 -0
- package/core/src/runtime.mjs +23 -0
- package/core/src/shared/bytes.d.mts +2 -0
- package/core/src/shared/bytes.mjs +33 -0
- package/core/src/shared/sha256.d.mts +3 -0
- package/core/src/shared/sha256.mjs +72 -22
- package/core/units.d.ts +50 -0
- package/core/world.d.ts +253 -5
- package/dist/authority-room.d.ts +9 -0
- package/dist/authority-room.js +45 -16
- package/dist/browser.d.ts +6 -5
- package/dist/browser.js +4 -3
- package/dist/cadence.d.ts +7 -0
- package/dist/cadence.js +19 -0
- package/dist/canonical.d.ts +1 -0
- package/dist/canonical.js +3 -0
- package/dist/checksum-policy.d.ts +10 -0
- package/dist/checksum-policy.js +14 -0
- package/dist/collider-cooking-hull.d.ts +18 -0
- package/dist/collider-cooking-hull.js +248 -0
- package/dist/collider-cooking.d.ts +140 -0
- package/dist/collider-cooking.js +794 -0
- package/dist/compat/v5.d.ts +121 -0
- package/dist/compat/v5.js +479 -0
- package/dist/creator.d.ts +7 -6
- package/dist/creator.js +4 -3
- package/dist/game-byte-section.d.ts +36 -0
- package/dist/game-byte-section.js +350 -0
- package/dist/index.d.ts +13 -6
- package/dist/index.js +9 -4
- package/dist/instant-replay.d.ts +27 -2
- package/dist/instant-replay.js +91 -16
- package/dist/lag-compensation3d.js +11 -10
- package/dist/match-log.d.ts +21 -4
- package/dist/match-log.js +92 -9
- package/dist/math.d.ts +2 -0
- package/dist/math.js +1 -0
- package/dist/modules/character-3d.d.ts +16 -1
- package/dist/modules/character-3d.js +42 -5
- package/dist/modules/combat.js +6 -5
- package/dist/movement3d-revision1.d.ts +2 -0
- package/dist/movement3d-revision1.js +973 -0
- package/dist/movement3d.d.ts +53 -3
- package/dist/movement3d.js +917 -247
- package/dist/networked-client.d.ts +15 -0
- package/dist/networked-client.js +378 -105
- package/dist/node.d.ts +3 -2
- package/dist/node.js +2 -1
- package/dist/physics/2d.d.ts +38 -4
- package/dist/physics/2d.js +57 -36
- package/dist/physics/3d.d.ts +755 -111
- package/dist/physics/3d.js +2355 -158
- package/dist/physics/edit-result-graph.d.ts +36 -0
- package/dist/physics/edit-result-graph.js +141 -0
- package/dist/physics/game-codec3d.d.ts +41 -0
- package/dist/physics/game-codec3d.js +544 -0
- package/dist/physics/installed-checkpoint3d.d.ts +13 -0
- package/dist/physics/installed-checkpoint3d.js +120 -0
- package/dist/physics/installed-runtime3d.d.ts +51 -0
- package/dist/physics/installed-runtime3d.js +372 -0
- package/dist/physics/installed-state-commitment3d.d.ts +2 -0
- package/dist/physics/installed-state-commitment3d.js +24 -0
- package/dist/physics/units.d.ts +38 -0
- package/dist/physics/units.js +56 -0
- package/dist/physics/vehicle-state3d.d.ts +93 -0
- package/dist/physics/vehicle-state3d.js +1191 -0
- package/dist/physics/voxel-body-state.d.ts +61 -0
- package/dist/physics/voxel-body-state.js +410 -0
- package/dist/r3f-render-adapter.d.ts +59 -1
- package/dist/r3f-render-adapter.js +137 -2
- package/dist/replay.d.ts +13 -0
- package/dist/replay.js +95 -70
- package/dist/run-room-transport.js +5 -1
- package/dist/runner.d.ts +17 -2
- package/dist/runner.js +472 -84
- package/dist/runtime-cleanup.d.ts +54 -0
- package/dist/runtime-cleanup.js +266 -0
- package/dist/runtime-lease.d.ts +11 -1
- package/dist/runtime-lease.js +23 -10
- package/dist/runtime-room-metadata.d.ts +2 -8
- package/dist/runtime-room-metadata.js +11 -14
- package/dist/runtime-session.d.ts +8 -0
- package/dist/runtime-session.js +222 -58
- package/dist/schema-codegen.js +3 -0
- package/dist/schema-dsl-binary.d.ts +10 -4
- package/dist/schema-dsl-binary.js +375 -76
- package/dist/scratch-pool.d.ts +32 -0
- package/dist/scratch-pool.js +60 -0
- package/dist/sdk-session.d.ts +1 -0
- package/dist/sdk-session.js +4 -0
- package/dist/secret-config.js +2 -60
- package/dist/secret-crypto.js +70 -36
- package/dist/session-snapshot.d.ts +15 -4
- package/dist/session-snapshot.js +35 -33
- package/dist/session-wire.js +14 -22
- package/dist/sparse-set.d.ts +1 -0
- package/dist/sparse-set.js +22 -0
- package/dist/spatial/spatial-grid-3d.d.ts +41 -0
- package/dist/spatial/spatial-grid-3d.js +115 -0
- package/dist/synctest.d.ts +9 -0
- package/dist/synctest.js +106 -17
- package/dist/testing-network.d.ts +2 -0
- package/dist/testing-network.js +122 -18
- package/dist/testing.d.ts +27 -6
- package/dist/testing.js +297 -56
- package/dist/tools/index.d.ts +3 -2
- package/dist/tools/index.js +3 -2
- package/dist/tools/module-certification.d.ts +6 -0
- package/dist/tools/module-certification.js +26 -2
- package/package.json +18 -5
- package/core/scripts/run-box3d-benchmark.mjs +0 -350
- package/core/src/physics/index.mjs +0 -3169
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CubicMeters,
|
|
3
|
+
Dimensionless,
|
|
4
|
+
KilogramMetersSquared,
|
|
5
|
+
Kilograms,
|
|
6
|
+
KilogramsPerCubicMeter,
|
|
7
|
+
Meters,
|
|
8
|
+
MetersPerSecond,
|
|
9
|
+
MetersPerSecondSquared,
|
|
10
|
+
NewtonMeterSecondsPerRadian,
|
|
11
|
+
NewtonMeters,
|
|
12
|
+
Newtons,
|
|
13
|
+
PerSecond,
|
|
14
|
+
RadiansPerSecond,
|
|
15
|
+
UnitVector3,
|
|
16
|
+
} from '../../units.js';
|
|
17
|
+
|
|
18
|
+
export interface BuoyancyQuaternion {
|
|
19
|
+
readonly x: Dimensionless;
|
|
20
|
+
readonly y: Dimensionless;
|
|
21
|
+
readonly z: Dimensionless;
|
|
22
|
+
readonly w: Dimensionless;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type BuoyancyShape =
|
|
26
|
+
| { readonly type: 'sphere'; readonly radius: Meters }
|
|
27
|
+
| { readonly type: 'box'; readonly halfX: Meters; readonly halfY: Meters; readonly halfZ: Meters }
|
|
28
|
+
| {
|
|
29
|
+
readonly type: 'voxel_compound';
|
|
30
|
+
readonly children: readonly {
|
|
31
|
+
readonly shape: { readonly type: 'box'; readonly halfX: Meters; readonly halfY: Meters; readonly halfZ: Meters };
|
|
32
|
+
readonly offset: UnitVector3<Meters>;
|
|
33
|
+
}[];
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export interface BuoyancyBody {
|
|
37
|
+
readonly shape: BuoyancyShape;
|
|
38
|
+
readonly position: UnitVector3<Meters>;
|
|
39
|
+
readonly orientation: BuoyancyQuaternion;
|
|
40
|
+
/**
|
|
41
|
+
* Local offset from position, in meters.
|
|
42
|
+
* The solver rotates this offset and adds it to position before it builds the torque arm.
|
|
43
|
+
*/
|
|
44
|
+
readonly centerOfMass: UnitVector3<Meters>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface BuoyancyOptions {
|
|
48
|
+
readonly waterY: Meters;
|
|
49
|
+
readonly density: KilogramsPerCubicMeter;
|
|
50
|
+
readonly gravity: UnitVector3<MetersPerSecondSquared>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface BuoyancyResult {
|
|
54
|
+
readonly submergedVolume: CubicMeters;
|
|
55
|
+
readonly centerOfBuoyancy: UnitVector3<Meters>;
|
|
56
|
+
readonly force: UnitVector3<Newtons>;
|
|
57
|
+
readonly torque: UnitVector3<NewtonMeters>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface FluidInertiaDiagonal {
|
|
61
|
+
readonly xx: KilogramMetersSquared;
|
|
62
|
+
readonly yy: KilogramMetersSquared;
|
|
63
|
+
readonly zz: KilogramMetersSquared;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface FluidBody extends BuoyancyBody {
|
|
67
|
+
readonly linearVelocity: UnitVector3<MetersPerSecond>;
|
|
68
|
+
readonly angularVelocity: UnitVector3<RadiansPerSecond>;
|
|
69
|
+
readonly mass: Kilograms;
|
|
70
|
+
readonly inertia: FluidInertiaDiagonal;
|
|
71
|
+
readonly gravityScale: Dimensionless;
|
|
72
|
+
readonly sleeping: boolean;
|
|
73
|
+
readonly layer: Dimensionless;
|
|
74
|
+
readonly mask: Dimensionless;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface FluidBounds {
|
|
78
|
+
readonly minX: Meters;
|
|
79
|
+
readonly maxX: Meters;
|
|
80
|
+
readonly minY: Meters;
|
|
81
|
+
readonly maxY: Meters;
|
|
82
|
+
readonly minZ: Meters;
|
|
83
|
+
readonly maxZ: Meters;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface FluidSurfacePlane {
|
|
87
|
+
readonly normal: UnitVector3<Dimensionless>;
|
|
88
|
+
readonly offset: Meters;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface FluidVolume {
|
|
92
|
+
readonly bounds: FluidBounds;
|
|
93
|
+
readonly surfacePlane?: FluidSurfacePlane;
|
|
94
|
+
readonly density: KilogramsPerCubicMeter;
|
|
95
|
+
/**
|
|
96
|
+
* dragForce = -relativeVelocity * density * submergedVolume * linearDrag.
|
|
97
|
+
* The unit is 1/s.
|
|
98
|
+
*/
|
|
99
|
+
readonly linearDrag: PerSecond;
|
|
100
|
+
/**
|
|
101
|
+
* Angular drag for this helper.
|
|
102
|
+
* The drag torque adds -submergedFraction * angularDrag * angularVelocity.
|
|
103
|
+
* The unit is N*m*s/rad.
|
|
104
|
+
* The owned world field angularDragPerSecond uses 1/s.
|
|
105
|
+
* That formula multiplies the coefficient by time before it changes angular velocity.
|
|
106
|
+
*/
|
|
107
|
+
readonly angularDrag: NewtonMeterSecondsPerRadian;
|
|
108
|
+
readonly flowVelocity: UnitVector3<MetersPerSecond>;
|
|
109
|
+
readonly layer: Dimensionless;
|
|
110
|
+
readonly mask: Dimensionless;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export type FluidOverlapPolicy = 'accumulate' | 'reject' | 'priority';
|
|
114
|
+
|
|
115
|
+
export interface FluidForceOptions {
|
|
116
|
+
readonly volumes: readonly FluidVolume[];
|
|
117
|
+
readonly overlapPolicy: FluidOverlapPolicy;
|
|
118
|
+
readonly gravity: UnitVector3<MetersPerSecondSquared>;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export interface FluidForceResult {
|
|
122
|
+
readonly submergedVolume: CubicMeters;
|
|
123
|
+
readonly centerOfBuoyancy: UnitVector3<Meters>;
|
|
124
|
+
readonly buoyantForce: UnitVector3<Newtons>;
|
|
125
|
+
readonly buoyantTorque: UnitVector3<NewtonMeters>;
|
|
126
|
+
readonly dragForce: UnitVector3<Newtons>;
|
|
127
|
+
readonly dragTorque: UnitVector3<NewtonMeters>;
|
|
128
|
+
readonly totalForce: UnitVector3<Newtons>;
|
|
129
|
+
readonly totalTorque: UnitVector3<NewtonMeters>;
|
|
130
|
+
readonly relativeVelocity: UnitVector3<MetersPerSecond>;
|
|
131
|
+
readonly shouldWake: boolean;
|
|
132
|
+
readonly isInEquilibrium: boolean;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function calculateNativePhysicsBuoyancy(
|
|
136
|
+
body: BuoyancyBody,
|
|
137
|
+
options: BuoyancyOptions,
|
|
138
|
+
): BuoyancyResult;
|
|
139
|
+
|
|
140
|
+
export function calculateNativePhysicsFluidForces(
|
|
141
|
+
body: FluidBody,
|
|
142
|
+
options: FluidForceOptions,
|
|
143
|
+
): FluidForceResult;
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { requirePhysicsExports } from './wasm-instance.mjs';
|
|
2
|
+
|
|
3
|
+
function voxelChildren(shape) {
|
|
4
|
+
if (shape.type !== 'voxel_compound' || !Array.isArray(shape.children)
|
|
5
|
+
|| shape.children.length === 0) {
|
|
6
|
+
throw new Error('KINETIX_PHYSICS_VOXEL_SHAPE_INVALID');
|
|
7
|
+
}
|
|
8
|
+
const values = new Float64Array(shape.children.length * 6);
|
|
9
|
+
shape.children.forEach((child, index) => {
|
|
10
|
+
if (child?.shape?.type !== 'box') {
|
|
11
|
+
throw new Error('KINETIX_PHYSICS_VOXEL_SHAPE_INVALID');
|
|
12
|
+
}
|
|
13
|
+
const record = [child.shape.halfX, child.shape.halfY, child.shape.halfZ,
|
|
14
|
+
child.offset?.x, child.offset?.y, child.offset?.z];
|
|
15
|
+
if (!record.every(Number.isFinite)) {
|
|
16
|
+
throw new Error('KINETIX_PHYSICS_VOXEL_SHAPE_INVALID');
|
|
17
|
+
}
|
|
18
|
+
values.set(record, index * 6);
|
|
19
|
+
});
|
|
20
|
+
return values;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function fluidResult(output) {
|
|
24
|
+
return Object.freeze({
|
|
25
|
+
submergedVolume: output[0],
|
|
26
|
+
centerOfBuoyancy: Object.freeze({ x: output[1], y: output[2], z: output[3] }),
|
|
27
|
+
buoyantForce: Object.freeze({ x: output[4], y: output[5], z: output[6] }),
|
|
28
|
+
buoyantTorque: Object.freeze({ x: output[7], y: output[8], z: output[9] }),
|
|
29
|
+
dragForce: Object.freeze({ x: output[10], y: output[11], z: output[12] }),
|
|
30
|
+
dragTorque: Object.freeze({ x: output[13], y: output[14], z: output[15] }),
|
|
31
|
+
totalForce: Object.freeze({ x: output[16], y: output[17], z: output[18] }),
|
|
32
|
+
totalTorque: Object.freeze({ x: output[19], y: output[20], z: output[21] }),
|
|
33
|
+
relativeVelocity: Object.freeze({ x: output[22], y: output[23], z: output[24] }),
|
|
34
|
+
shouldWake: output[25] !== 0,
|
|
35
|
+
isInEquilibrium: output[26] !== 0,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function calculateVoxelFluidForces(exports, body, options, children) {
|
|
40
|
+
const volumes = options.volumes;
|
|
41
|
+
if (!Array.isArray(volumes) || volumes.length > 16) {
|
|
42
|
+
throw new Error('KINETIX_PHYSICS_FLUID_INPUT_INVALID');
|
|
43
|
+
}
|
|
44
|
+
if (options.overlapPolicy === 'reject') {
|
|
45
|
+
for (let first = 0; first < volumes.length; first += 1) {
|
|
46
|
+
const a = volumes[first].bounds;
|
|
47
|
+
for (let second = first + 1; second < volumes.length; second += 1) {
|
|
48
|
+
const b = volumes[second].bounds;
|
|
49
|
+
if (a.minX < b.maxX && b.minX < a.maxX
|
|
50
|
+
&& a.minY < b.maxY && b.minY < a.maxY
|
|
51
|
+
&& a.minZ < b.maxZ && b.minZ < a.maxZ) {
|
|
52
|
+
throw new Error('KINETIX_PHYSICS_FLUID_NATIVE_FAILURE status=-7');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const total = {
|
|
58
|
+
submergedVolume: 0,
|
|
59
|
+
centerOfBuoyancy: { x: 0, y: 0, z: 0 },
|
|
60
|
+
buoyantForce: { x: 0, y: 0, z: 0 },
|
|
61
|
+
buoyantTorque: { x: 0, y: 0, z: 0 },
|
|
62
|
+
dragForce: { x: 0, y: 0, z: 0 },
|
|
63
|
+
dragTorque: { x: 0, y: 0, z: 0 },
|
|
64
|
+
totalForce: { x: 0, y: 0, z: 0 },
|
|
65
|
+
totalTorque: { x: 0, y: 0, z: 0 },
|
|
66
|
+
relativeVelocity: { x: 0, y: 0, z: 0 },
|
|
67
|
+
shouldWake: false,
|
|
68
|
+
isInEquilibrium: true,
|
|
69
|
+
};
|
|
70
|
+
const fullVolume = body.shape.children.reduce((sum, child) => sum
|
|
71
|
+
+ 8 * child.shape.halfX * child.shape.halfY * child.shape.halfZ, 0);
|
|
72
|
+
const vectorFields = ['buoyantForce', 'buoyantTorque', 'dragForce',
|
|
73
|
+
'dragTorque', 'totalForce', 'totalTorque'];
|
|
74
|
+
for (let index = 0; index < volumes.length; index += 1) {
|
|
75
|
+
if (options.overlapPolicy === 'priority'
|
|
76
|
+
&& total.submergedVolume >= fullVolume) break;
|
|
77
|
+
const volume = volumes[index];
|
|
78
|
+
const bounds = volume.bounds;
|
|
79
|
+
const plane = volume.surfacePlane;
|
|
80
|
+
const flow = volume.flowVelocity;
|
|
81
|
+
const input = new Float64Array(51);
|
|
82
|
+
input.set([
|
|
83
|
+
5, body.position.x, body.position.y, body.position.z,
|
|
84
|
+
body.orientation.x, body.orientation.y, body.orientation.z,
|
|
85
|
+
body.orientation.w, 0, 0, 0,
|
|
86
|
+
body.centerOfMass.x, body.centerOfMass.y, body.centerOfMass.z,
|
|
87
|
+
body.linearVelocity.x, body.linearVelocity.y, body.linearVelocity.z,
|
|
88
|
+
body.angularVelocity.x, body.angularVelocity.y, body.angularVelocity.z,
|
|
89
|
+
body.mass, body.inertia.xx, body.inertia.yy, body.inertia.zz,
|
|
90
|
+
body.gravityScale, body.sleeping ? 1 : 0, body.layer, body.mask,
|
|
91
|
+
index + 1,
|
|
92
|
+
bounds.minX, bounds.maxX, bounds.minY, bounds.maxY,
|
|
93
|
+
bounds.minZ, bounds.maxZ,
|
|
94
|
+
plane === undefined ? 0 : 1,
|
|
95
|
+
plane?.normal.x ?? 0, plane?.normal.y ?? 1, plane?.normal.z ?? 0,
|
|
96
|
+
plane?.offset ?? 0, volume.density, volume.linearDrag,
|
|
97
|
+
volume.angularDrag, flow.x, flow.y, flow.z, volume.layer, volume.mask,
|
|
98
|
+
options.gravity.x, options.gravity.y, options.gravity.z,
|
|
99
|
+
]);
|
|
100
|
+
const inputBytes = input.byteLength;
|
|
101
|
+
const childBytes = children.byteLength;
|
|
102
|
+
const pointer = exports.rundot_kinetix_world_buffer_allocate(
|
|
103
|
+
inputBytes + childBytes + 27 * 8);
|
|
104
|
+
if (!Number.isInteger(pointer) || pointer <= 0) {
|
|
105
|
+
throw new Error('KINETIX_PHYSICS_FLUID_OUT_OF_MEMORY');
|
|
106
|
+
}
|
|
107
|
+
let result;
|
|
108
|
+
try {
|
|
109
|
+
new Float64Array(exports.memory.buffer, pointer, input.length).set(input);
|
|
110
|
+
new Float64Array(exports.memory.buffer, pointer + inputBytes,
|
|
111
|
+
children.length).set(children);
|
|
112
|
+
const status = exports.rundot_kinetix_physics_voxel_fluid_forces(
|
|
113
|
+
pointer, input.length, pointer + inputBytes, children.length,
|
|
114
|
+
pointer + inputBytes + childBytes, 27);
|
|
115
|
+
if (status !== 0) {
|
|
116
|
+
throw new Error(`KINETIX_PHYSICS_FLUID_NATIVE_FAILURE status=${status}`);
|
|
117
|
+
}
|
|
118
|
+
result = fluidResult(new Float64Array(exports.memory.buffer,
|
|
119
|
+
pointer + inputBytes + childBytes, 27));
|
|
120
|
+
} finally {
|
|
121
|
+
exports.rundot_kinetix_world_buffer_free(pointer);
|
|
122
|
+
}
|
|
123
|
+
let factor = 1;
|
|
124
|
+
if (options.overlapPolicy === 'priority'
|
|
125
|
+
&& result.submergedVolume > fullVolume - total.submergedVolume) {
|
|
126
|
+
factor = (fullVolume - total.submergedVolume) / result.submergedVolume;
|
|
127
|
+
}
|
|
128
|
+
const volumeAmount = result.submergedVolume * factor;
|
|
129
|
+
total.centerOfBuoyancy.x += result.centerOfBuoyancy.x * volumeAmount;
|
|
130
|
+
total.centerOfBuoyancy.y += result.centerOfBuoyancy.y * volumeAmount;
|
|
131
|
+
total.centerOfBuoyancy.z += result.centerOfBuoyancy.z * volumeAmount;
|
|
132
|
+
total.relativeVelocity.x += result.relativeVelocity.x * volumeAmount;
|
|
133
|
+
total.relativeVelocity.y += result.relativeVelocity.y * volumeAmount;
|
|
134
|
+
total.relativeVelocity.z += result.relativeVelocity.z * volumeAmount;
|
|
135
|
+
for (const field of vectorFields) {
|
|
136
|
+
total[field].x += result[field].x * factor;
|
|
137
|
+
total[field].y += result[field].y * factor;
|
|
138
|
+
total[field].z += result[field].z * factor;
|
|
139
|
+
}
|
|
140
|
+
total.submergedVolume += volumeAmount;
|
|
141
|
+
total.shouldWake ||= result.shouldWake;
|
|
142
|
+
if (volumeAmount > 0 && !result.isInEquilibrium) {
|
|
143
|
+
total.isInEquilibrium = false;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (total.submergedVolume > 0) {
|
|
147
|
+
for (const field of ['centerOfBuoyancy', 'relativeVelocity']) {
|
|
148
|
+
total[field].x /= total.submergedVolume;
|
|
149
|
+
total[field].y /= total.submergedVolume;
|
|
150
|
+
total[field].z /= total.submergedVolume;
|
|
151
|
+
}
|
|
152
|
+
} else {
|
|
153
|
+
total.centerOfBuoyancy = { ...body.position };
|
|
154
|
+
total.isInEquilibrium = false;
|
|
155
|
+
}
|
|
156
|
+
return Object.freeze(Object.fromEntries(Object.entries(total).map(([key, value]) =>
|
|
157
|
+
[key, typeof value === 'object' ? Object.freeze(value) : value])));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function calculateNativePhysicsBuoyancy(body, options) {
|
|
161
|
+
const exports = requirePhysicsExports();
|
|
162
|
+
if (exports.rundot_kinetix_physics_buoyancy_abi_version?.() !== 1
|
|
163
|
+
|| exports.rundot_kinetix_physics_buoyancy_input_stride?.() !== 19
|
|
164
|
+
|| exports.rundot_kinetix_physics_buoyancy_output_stride?.() !== 10) {
|
|
165
|
+
throw new Error('KINETIX_PHYSICS_BUOYANCY_ABI_MISMATCH');
|
|
166
|
+
}
|
|
167
|
+
const shape = body.shape;
|
|
168
|
+
const children = shape.type === 'voxel_compound' ? voxelChildren(shape) : undefined;
|
|
169
|
+
const orientation = body.orientation;
|
|
170
|
+
const center = body.centerOfMass;
|
|
171
|
+
const values = [
|
|
172
|
+
shape.type === 'box' ? 0 : shape.type === 'sphere' ? 1 : 5,
|
|
173
|
+
body.position.x, body.position.y, body.position.z,
|
|
174
|
+
orientation.x, orientation.y, orientation.z, orientation.w,
|
|
175
|
+
shape.type === 'box' ? shape.halfX : shape.type === 'sphere' ? shape.radius : 0,
|
|
176
|
+
shape.type === 'box' ? shape.halfY : 0,
|
|
177
|
+
shape.type === 'box' ? shape.halfZ : 0,
|
|
178
|
+
options.waterY, options.density, options.gravity.x, options.gravity.y, options.gravity.z,
|
|
179
|
+
center.x, center.y, center.z,
|
|
180
|
+
];
|
|
181
|
+
if (!values.every(Number.isFinite)) throw new Error('KINETIX_PHYSICS_BUOYANCY_INPUT_INVALID');
|
|
182
|
+
const childBytes = children?.byteLength ?? 0;
|
|
183
|
+
const pointer = exports.rundot_kinetix_world_buffer_allocate(29 * 8 + childBytes);
|
|
184
|
+
if (!Number.isInteger(pointer) || pointer <= 0) throw new Error('KINETIX_PHYSICS_BUOYANCY_OUT_OF_MEMORY');
|
|
185
|
+
try {
|
|
186
|
+
new Float64Array(exports.memory.buffer, pointer, 19).set(values);
|
|
187
|
+
if (children !== undefined) {
|
|
188
|
+
new Float64Array(exports.memory.buffer, pointer + 29 * 8,
|
|
189
|
+
children.length).set(children);
|
|
190
|
+
}
|
|
191
|
+
const status = children === undefined
|
|
192
|
+
? exports.rundot_kinetix_physics_buoyancy(
|
|
193
|
+
pointer, 19, pointer + 19 * 8, 10)
|
|
194
|
+
: exports.rundot_kinetix_physics_voxel_buoyancy(
|
|
195
|
+
pointer, 19, pointer + 29 * 8, children.length,
|
|
196
|
+
pointer + 19 * 8, 10);
|
|
197
|
+
if (status !== 0) throw new Error(`KINETIX_PHYSICS_BUOYANCY_NATIVE_FAILURE status=${status}`);
|
|
198
|
+
const output = new Float64Array(exports.memory.buffer, pointer + 19 * 8, 10);
|
|
199
|
+
return Object.freeze({
|
|
200
|
+
submergedVolume: output[0],
|
|
201
|
+
centerOfBuoyancy: Object.freeze({ x: output[1], y: output[2], z: output[3] }),
|
|
202
|
+
force: Object.freeze({ x: output[4], y: output[5], z: output[6] }),
|
|
203
|
+
torque: Object.freeze({ x: output[7], y: output[8], z: output[9] }),
|
|
204
|
+
});
|
|
205
|
+
} finally {
|
|
206
|
+
exports.rundot_kinetix_world_buffer_free(pointer);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export function calculateNativePhysicsFluidForces(body, options) {
|
|
211
|
+
const exports = requirePhysicsExports();
|
|
212
|
+
if (exports.rundot_kinetix_physics_fluid_abi_version?.() !== 1
|
|
213
|
+
|| exports.rundot_kinetix_physics_fluid_forces_output_stride?.() !== 27
|
|
214
|
+
|| exports.rundot_kinetix_physics_fluid_volume_input_stride?.() !== 20
|
|
215
|
+
|| exports.rundot_kinetix_physics_fluid_state_forces_input_stride?.() !== 353) {
|
|
216
|
+
throw new Error('KINETIX_PHYSICS_FLUID_ABI_MISMATCH');
|
|
217
|
+
}
|
|
218
|
+
const values = new Float64Array(353);
|
|
219
|
+
const shape = body.shape;
|
|
220
|
+
if (shape.type === 'voxel_compound') {
|
|
221
|
+
return calculateVoxelFluidForces(exports, body, options, voxelChildren(shape));
|
|
222
|
+
}
|
|
223
|
+
const orientation = body.orientation;
|
|
224
|
+
const center = body.centerOfMass;
|
|
225
|
+
const velocity = body.linearVelocity;
|
|
226
|
+
const angularVelocity = body.angularVelocity;
|
|
227
|
+
const inertia = body.inertia;
|
|
228
|
+
values.set([
|
|
229
|
+
shape.type === 'box' ? 0 : 1, body.position.x, body.position.y, body.position.z,
|
|
230
|
+
orientation.x, orientation.y, orientation.z, orientation.w,
|
|
231
|
+
shape.type === 'box' ? shape.halfX : shape.radius,
|
|
232
|
+
shape.type === 'box' ? shape.halfY : 0,
|
|
233
|
+
shape.type === 'box' ? shape.halfZ : 0,
|
|
234
|
+
center.x, center.y, center.z,
|
|
235
|
+
velocity.x, velocity.y, velocity.z,
|
|
236
|
+
angularVelocity.x, angularVelocity.y, angularVelocity.z,
|
|
237
|
+
body.mass, inertia.xx, inertia.yy, inertia.zz, body.gravityScale,
|
|
238
|
+
body.sleeping ? 1 : 0, body.layer, body.mask,
|
|
239
|
+
options.overlapPolicy === 'reject' ? 0 : options.overlapPolicy === 'priority' ? 1 : 2,
|
|
240
|
+
options.volumes.length,
|
|
241
|
+
]);
|
|
242
|
+
options.volumes.forEach((volume, index) => {
|
|
243
|
+
const base = 30 + index * 20;
|
|
244
|
+
const bounds = volume.bounds;
|
|
245
|
+
const plane = volume.surfacePlane;
|
|
246
|
+
const flow = volume.flowVelocity;
|
|
247
|
+
values.set([
|
|
248
|
+
index + 1,
|
|
249
|
+
bounds.minX, bounds.maxX, bounds.minY, bounds.maxY, bounds.minZ, bounds.maxZ,
|
|
250
|
+
plane === undefined ? 0 : 1,
|
|
251
|
+
plane?.normal.x ?? 0, plane?.normal.y ?? 1, plane?.normal.z ?? 0,
|
|
252
|
+
plane?.offset ?? 0,
|
|
253
|
+
volume.density, volume.linearDrag, volume.angularDrag,
|
|
254
|
+
flow.x, flow.y, flow.z, volume.layer, volume.mask,
|
|
255
|
+
], base);
|
|
256
|
+
});
|
|
257
|
+
values.set([options.gravity.x, options.gravity.y, options.gravity.z], 350);
|
|
258
|
+
const pointer = exports.rundot_kinetix_world_buffer_allocate((353 + 27) * 8);
|
|
259
|
+
if (!Number.isInteger(pointer) || pointer <= 0) throw new Error('KINETIX_PHYSICS_FLUID_OUT_OF_MEMORY');
|
|
260
|
+
try {
|
|
261
|
+
new Float64Array(exports.memory.buffer, pointer, 353).set(values);
|
|
262
|
+
const status = exports.rundot_kinetix_physics_fluid_state_forces(pointer, 353, pointer + 353 * 8, 27);
|
|
263
|
+
if (status !== 0) throw new Error(`KINETIX_PHYSICS_FLUID_NATIVE_FAILURE status=${status}`);
|
|
264
|
+
return fluidResult(new Float64Array(exports.memory.buffer, pointer + 353 * 8, 27));
|
|
265
|
+
} finally {
|
|
266
|
+
exports.rundot_kinetix_world_buffer_free(pointer);
|
|
267
|
+
}
|
|
268
|
+
}
|