@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,722 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Surface velocity, conveyor contact, and declarative contact material rules (G21 capability).
|
|
3
|
+
*
|
|
4
|
+
* Implements per-shape/body surface velocities that enter the friction solve as tangential biases,
|
|
5
|
+
* along with deterministic, declarative contact material modification rules, rollback of rules,
|
|
6
|
+
* and pure native solve without host callbacks.
|
|
7
|
+
*
|
|
8
|
+
* Computation is routed through compiled C++ WASM (physics-extended.wasm).
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
ensureExtendedInstance,
|
|
13
|
+
extendedPhysicsReady,
|
|
14
|
+
} from './extended-wasm-instance.mjs';
|
|
15
|
+
import {
|
|
16
|
+
physicsExtendedWasmModuleBase64,
|
|
17
|
+
} from './physics-extended-wasm-module.generated.mjs';
|
|
18
|
+
|
|
19
|
+
export const SURFACE_VELOCITY_ABI_VERSION = 1;
|
|
20
|
+
export const SURFACE_VELOCITY_RECORD_STRIDE = 8;
|
|
21
|
+
export const CONTACT_MATERIAL_RULE_STRIDE = 20;
|
|
22
|
+
export const CONTACT_SURFACE_PROPERTIES_STRIDE = 10;
|
|
23
|
+
|
|
24
|
+
export const SurfaceVelocitySpace = Object.freeze({
|
|
25
|
+
World: 0,
|
|
26
|
+
Local: 1,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export const MaterialCombineMode = Object.freeze({
|
|
30
|
+
Average: 0,
|
|
31
|
+
Minimum: 1,
|
|
32
|
+
Multiply: 2,
|
|
33
|
+
Maximum: 3,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const COMBINE_MODE_MAP = {
|
|
37
|
+
average: MaterialCombineMode.Average,
|
|
38
|
+
minimum: MaterialCombineMode.Minimum,
|
|
39
|
+
min: MaterialCombineMode.Minimum,
|
|
40
|
+
multiply: MaterialCombineMode.Multiply,
|
|
41
|
+
mult: MaterialCombineMode.Multiply,
|
|
42
|
+
maximum: MaterialCombineMode.Maximum,
|
|
43
|
+
max: MaterialCombineMode.Maximum,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
let extendedInstance = null;
|
|
47
|
+
let scratchOffset = 0;
|
|
48
|
+
let scratchCapacity = 0;
|
|
49
|
+
|
|
50
|
+
function decodeBase64(value) {
|
|
51
|
+
if (typeof atob === 'function') {
|
|
52
|
+
const decoded = atob(value);
|
|
53
|
+
const bytes = new Uint8Array(decoded.length);
|
|
54
|
+
for (let index = 0; index < decoded.length; index += 1) bytes[index] = decoded.charCodeAt(index);
|
|
55
|
+
return bytes;
|
|
56
|
+
}
|
|
57
|
+
if (typeof Buffer !== 'undefined') return Uint8Array.from(Buffer.from(value, 'base64'));
|
|
58
|
+
throw new Error('KINETIX_EXTENDED_PHYSICS_BASE64_UNAVAILABLE: Base64 decoding is unavailable in this environment');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export async function initSurfaceVelocity() {
|
|
62
|
+
if (extendedInstance !== null) return extendedInstance;
|
|
63
|
+
extendedInstance = await ensureExtendedInstance();
|
|
64
|
+
return extendedInstance;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export { ensureExtendedInstance, extendedPhysicsReady };
|
|
68
|
+
|
|
69
|
+
function getExtendedInstanceSync() {
|
|
70
|
+
if (extendedInstance !== null) return extendedInstance;
|
|
71
|
+
try {
|
|
72
|
+
const bytes = decodeBase64(physicsExtendedWasmModuleBase64);
|
|
73
|
+
const mod = new WebAssembly.Module(bytes);
|
|
74
|
+
const instance = new WebAssembly.Instance(mod, {});
|
|
75
|
+
instance.exports._initialize?.();
|
|
76
|
+
extendedInstance = instance;
|
|
77
|
+
return extendedInstance;
|
|
78
|
+
} catch (err) {
|
|
79
|
+
throw new Error(
|
|
80
|
+
`KINETIX_EXTENDED_PHYSICS_NOT_INITIALIZED: failed to load extended physics WASM module (${err?.message ?? err})`,
|
|
81
|
+
{ cause: err }
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function acquireScratch(instance, byteCount) {
|
|
87
|
+
const exports = instance.exports;
|
|
88
|
+
if (typeof exports.malloc === 'function' && typeof exports.free === 'function') {
|
|
89
|
+
const ptr = exports.malloc(byteCount);
|
|
90
|
+
if (ptr !== 0) {
|
|
91
|
+
return {
|
|
92
|
+
ptr,
|
|
93
|
+
free: () => {
|
|
94
|
+
exports.free(ptr);
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Fallback scratch pool in grown linear memory when malloc is not in exports
|
|
101
|
+
const required = Math.max(byteCount, 64);
|
|
102
|
+
if (scratchCapacity < required) {
|
|
103
|
+
const pages = Math.ceil(required / 65536);
|
|
104
|
+
const prevPages = exports.memory.grow(pages);
|
|
105
|
+
scratchOffset = prevPages * 65536;
|
|
106
|
+
scratchCapacity = pages * 65536;
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
ptr: scratchOffset,
|
|
110
|
+
free: () => {},
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function resolveBodyKey(id, bodyKey = 0) {
|
|
115
|
+
if (bodyKey !== undefined && bodyKey !== 0 && bodyKey !== null) {
|
|
116
|
+
if (typeof bodyKey === 'number' && Number.isFinite(bodyKey)) return bodyKey;
|
|
117
|
+
if (typeof bodyKey === 'bigint') return Number(bodyKey);
|
|
118
|
+
}
|
|
119
|
+
if (typeof id === 'number' && Number.isFinite(id)) return id;
|
|
120
|
+
if (typeof id === 'bigint') return Number(id);
|
|
121
|
+
if (typeof id === 'string' && id !== '' && id !== '*') {
|
|
122
|
+
const num = Number(id);
|
|
123
|
+
if (!Number.isNaN(num) && Number.isFinite(num)) return num;
|
|
124
|
+
let h = 2166136261 >>> 0;
|
|
125
|
+
for (let i = 0; i < id.length; i += 1) {
|
|
126
|
+
h ^= id.charCodeAt(i);
|
|
127
|
+
h = Math.imul(h, 16777619) >>> 0;
|
|
128
|
+
}
|
|
129
|
+
return h;
|
|
130
|
+
}
|
|
131
|
+
return Number(bodyKey) || 0;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function toKey64(val) {
|
|
135
|
+
if (typeof val === 'bigint') return val;
|
|
136
|
+
if (typeof val === 'number' && Number.isFinite(val)) return BigInt(Math.trunc(val));
|
|
137
|
+
return 0n;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function parseCombineMode(mode, defaultMode) {
|
|
141
|
+
if (typeof mode === 'number' && mode >= 0 && mode <= 3) {
|
|
142
|
+
return mode;
|
|
143
|
+
}
|
|
144
|
+
if (typeof mode === 'string') {
|
|
145
|
+
const lower = mode.toLowerCase();
|
|
146
|
+
if (COMBINE_MODE_MAP[lower] !== undefined) {
|
|
147
|
+
return COMBINE_MODE_MAP[lower];
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return defaultMode;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function cleanZero(val) {
|
|
154
|
+
return val === 0 ? 0 : (Math.abs(val) <= 1e-15 ? 0 : val);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function solverSqrt(value) {
|
|
158
|
+
if (value <= 0.0) return 0.0;
|
|
159
|
+
return Math.sqrt(value);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export function addVec3(a, b) {
|
|
163
|
+
return { x: cleanZero(a.x + b.x), y: cleanZero(a.y + b.y), z: cleanZero(a.z + b.z) };
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function subVec3(a, b) {
|
|
167
|
+
return { x: cleanZero(a.x - b.x), y: cleanZero(a.y - b.y), z: cleanZero(a.z - b.z) };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function scaleVec3(v, s) {
|
|
171
|
+
return { x: cleanZero(v.x * s), y: cleanZero(v.y * s), z: cleanZero(v.z * s) };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function dotVec3(a, b) {
|
|
175
|
+
return a.x * b.x + a.y * b.y + a.z * b.z;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export function crossVec3(a, b) {
|
|
179
|
+
return {
|
|
180
|
+
x: cleanZero(a.y * b.z - a.z * b.y),
|
|
181
|
+
y: cleanZero(a.z * b.x - a.x * b.z),
|
|
182
|
+
z: cleanZero(a.x * b.y - a.y * b.x),
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export function lengthSquaredVec3(v) {
|
|
187
|
+
return dotVec3(v, v);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function lengthVec3(v) {
|
|
191
|
+
return solverSqrt(lengthSquaredVec3(v));
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export function normalizeVec3(v) {
|
|
195
|
+
const len = lengthVec3(v);
|
|
196
|
+
if (len <= 1e-15) return { x: 0.0, y: 0.0, z: 0.0 };
|
|
197
|
+
return scaleVec3(v, 1.0 / len);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export function rotateByQuat(q, v) {
|
|
201
|
+
const u = { x: q.x, y: q.y, z: q.z };
|
|
202
|
+
const uv = crossVec3(u, v);
|
|
203
|
+
const uuv = crossVec3(u, uv);
|
|
204
|
+
return addVec3(v, addVec3(scaleVec3(uv, 2.0 * q.w), scaleVec3(uuv, 2.0)));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export function invRotateByQuat(q, v) {
|
|
208
|
+
const conj = { x: -q.x, y: -q.y, z: -q.z, w: q.w };
|
|
209
|
+
return rotateByQuat(conj, v);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export function contactTangentBasis(normal) {
|
|
213
|
+
const reference = Math.abs(normal.x) < 0.5773502691896258
|
|
214
|
+
? { x: 1.0, y: 0.0, z: 0.0 }
|
|
215
|
+
: { x: 0.0, y: 1.0, z: 0.0 };
|
|
216
|
+
let first = crossVec3(normal, reference);
|
|
217
|
+
const firstLen = lengthVec3(first);
|
|
218
|
+
first = firstLen <= 1e-18 ? { x: 0.0, y: 0.0, z: 1.0 } : scaleVec3(first, 1.0 / firstLen);
|
|
219
|
+
const second = crossVec3(normal, first);
|
|
220
|
+
return { tangent1: first, tangent2: second };
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export function combineMaterialProperty(a, b, mode) {
|
|
224
|
+
switch (mode) {
|
|
225
|
+
case MaterialCombineMode.Average:
|
|
226
|
+
return (a + b) * 0.5;
|
|
227
|
+
case MaterialCombineMode.Minimum:
|
|
228
|
+
return Math.min(a, b);
|
|
229
|
+
case MaterialCombineMode.Multiply:
|
|
230
|
+
return solverSqrt(Math.max(0.0, a * b));
|
|
231
|
+
case MaterialCombineMode.Maximum:
|
|
232
|
+
return Math.max(a, b);
|
|
233
|
+
default:
|
|
234
|
+
return (a + b) * 0.5;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export function createSurfaceVelocity(options = {}) {
|
|
239
|
+
const linear = options.linear ?? options.surfaceVelocity ?? (typeof options.x === 'number' || typeof options.y === 'number' || typeof options.z === 'number'
|
|
240
|
+
? { x: options.x ?? 0, y: options.y ?? 0, z: options.z ?? 0 }
|
|
241
|
+
: null);
|
|
242
|
+
|
|
243
|
+
const speed = options.conveyorSpeed ?? options.speed;
|
|
244
|
+
let finalLinear = { x: 0, y: 0, z: 0 };
|
|
245
|
+
if (linear) {
|
|
246
|
+
finalLinear = { x: Number(linear.x ?? 0), y: Number(linear.y ?? 0), z: Number(linear.z ?? 0) };
|
|
247
|
+
} else if (typeof speed === 'number') {
|
|
248
|
+
finalLinear = { x: speed, y: 0, z: 0 };
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const angular = options.angular ?? { x: 0, y: 0, z: 0 };
|
|
252
|
+
const space = options.space === 'local' || options.space === SurfaceVelocitySpace.Local
|
|
253
|
+
? SurfaceVelocitySpace.Local
|
|
254
|
+
: SurfaceVelocitySpace.World;
|
|
255
|
+
|
|
256
|
+
return Object.freeze({
|
|
257
|
+
linear: Object.freeze(finalLinear),
|
|
258
|
+
angular: Object.freeze({ x: Number(angular.x ?? 0), y: Number(angular.y ?? 0), z: Number(angular.z ?? 0) }),
|
|
259
|
+
space,
|
|
260
|
+
enabled: options.enabled ?? true,
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export function createContactMaterialRule(options = {}) {
|
|
265
|
+
let bodyKeyA = 0;
|
|
266
|
+
let bodyKeyB = 0;
|
|
267
|
+
let pair = null;
|
|
268
|
+
|
|
269
|
+
if (Array.isArray(options.pair) && options.pair.length === 2) {
|
|
270
|
+
pair = [options.pair[0], options.pair[1]];
|
|
271
|
+
bodyKeyA = typeof options.pair[0] === 'number' ? options.pair[0] : 0;
|
|
272
|
+
bodyKeyB = typeof options.pair[1] === 'number' ? options.pair[1] : 0;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
let materialA = 0;
|
|
276
|
+
let materialB = 0;
|
|
277
|
+
if (Array.isArray(options.materialPair) && options.materialPair.length === 2) {
|
|
278
|
+
materialA = Number(options.materialPair[0]) || 0;
|
|
279
|
+
materialB = Number(options.materialPair[1]) || 0;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
let shapeIndexA = -1;
|
|
283
|
+
let shapeIndexB = -1;
|
|
284
|
+
if (Array.isArray(options.shapePair) && options.shapePair.length === 2) {
|
|
285
|
+
shapeIndexA = Number(options.shapePair[0]);
|
|
286
|
+
shapeIndexB = Number(options.shapePair[1]);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const friction = typeof options.friction === 'number' ? Math.max(0.0, options.friction) : -1.0;
|
|
290
|
+
const restitution = typeof options.restitution === 'number' ? Math.max(0.0, options.restitution) : -1.0;
|
|
291
|
+
const rollingResistance = typeof options.rollingResistance === 'number' ? Math.max(0.0, options.rollingResistance) : -1.0;
|
|
292
|
+
|
|
293
|
+
const frictionCombine = parseCombineMode(options.frictionCombine, MaterialCombineMode.Multiply);
|
|
294
|
+
const restitutionCombine = parseCombineMode(options.restitutionCombine, MaterialCombineMode.Maximum);
|
|
295
|
+
|
|
296
|
+
let surfaceVelocity = null;
|
|
297
|
+
const rawSurf = options.tangentialVelocity ?? options.surfaceVelocity;
|
|
298
|
+
if (rawSurf) {
|
|
299
|
+
surfaceVelocity = createSurfaceVelocity(rawSurf);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return Object.freeze({
|
|
303
|
+
pair: pair ? Object.freeze([pair[0], pair[1]]) : null,
|
|
304
|
+
bodyKeyA,
|
|
305
|
+
bodyKeyB,
|
|
306
|
+
materialA,
|
|
307
|
+
materialB,
|
|
308
|
+
shapeIndexA,
|
|
309
|
+
shapeIndexB,
|
|
310
|
+
friction,
|
|
311
|
+
restitution,
|
|
312
|
+
rollingResistance,
|
|
313
|
+
frictionCombine,
|
|
314
|
+
restitutionCombine,
|
|
315
|
+
surfaceVelocity,
|
|
316
|
+
hasSurfaceVelocity: surfaceVelocity !== null,
|
|
317
|
+
enabled: options.enabled ?? true,
|
|
318
|
+
priority: typeof options.priority === 'number' ? options.priority : 0,
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export function normalizeContactMaterialRules(rules) {
|
|
323
|
+
if (!Array.isArray(rules)) {
|
|
324
|
+
return Object.freeze([]);
|
|
325
|
+
}
|
|
326
|
+
return Object.freeze(rules.map((rule) => createContactMaterialRule(rule)));
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
export function computeSurfacePointVelocity(config, orientation, point, center) {
|
|
330
|
+
if (!config || !config.enabled) {
|
|
331
|
+
return { x: 0.0, y: 0.0, z: 0.0 };
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
let linear = config.linear;
|
|
335
|
+
let angular = config.angular;
|
|
336
|
+
|
|
337
|
+
if (config.space === SurfaceVelocitySpace.Local && orientation) {
|
|
338
|
+
linear = rotateByQuat(orientation, linear);
|
|
339
|
+
angular = rotateByQuat(orientation, angular);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const r = subVec3(point, center);
|
|
343
|
+
const rot = crossVec3(angular, r);
|
|
344
|
+
return addVec3(linear, rot);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Evaluates contact material rules for a pair using compiled C++ WASM.
|
|
349
|
+
*/
|
|
350
|
+
export function evaluateContactMaterialRules(options = {}) {
|
|
351
|
+
const {
|
|
352
|
+
rules = [],
|
|
353
|
+
idA = '',
|
|
354
|
+
idB = '',
|
|
355
|
+
bodyKeyA = 0,
|
|
356
|
+
bodyKeyB = 0,
|
|
357
|
+
materialA = 0,
|
|
358
|
+
materialB = 0,
|
|
359
|
+
shapeA = -1,
|
|
360
|
+
shapeB = -1,
|
|
361
|
+
surfA = null,
|
|
362
|
+
surfB = null,
|
|
363
|
+
orientationA = { x: 0, y: 0, z: 0, w: 1 },
|
|
364
|
+
orientationB = { x: 0, y: 0, z: 0, w: 1 },
|
|
365
|
+
contactPoint = { x: 0, y: 0, z: 0 },
|
|
366
|
+
centerA = { x: 0, y: 0, z: 0 },
|
|
367
|
+
centerB = { x: 0, y: 0, z: 0 },
|
|
368
|
+
defaultFrictionA = 0.6,
|
|
369
|
+
defaultFrictionB = 0.6,
|
|
370
|
+
defaultRestitutionA = 0.0,
|
|
371
|
+
defaultRestitutionB = 0.0,
|
|
372
|
+
defaultRollingA = 0.0,
|
|
373
|
+
defaultRollingB = 0.0,
|
|
374
|
+
} = options;
|
|
375
|
+
|
|
376
|
+
const instance = getExtendedInstanceSync();
|
|
377
|
+
const exports = instance.exports;
|
|
378
|
+
|
|
379
|
+
if (typeof exports.rundot_kinetix_ext_surface_velocity_evaluate_rules !== 'function') {
|
|
380
|
+
throw new Error('KINETIX_EXTENDED_PHYSICS_EXPORT_MISSING: rundot_kinetix_ext_surface_velocity_evaluate_rules');
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
const ruleStride = exports.rundot_kinetix_ext_surface_velocity_rule_stride();
|
|
384
|
+
const propStride = exports.rundot_kinetix_ext_surface_velocity_properties_stride();
|
|
385
|
+
|
|
386
|
+
const normRules = Array.isArray(rules) ? normalizeContactMaterialRules(rules) : [];
|
|
387
|
+
const ruleCount = normRules.length;
|
|
388
|
+
const ruleBytes = ruleCount * ruleStride * Float64Array.BYTES_PER_ELEMENT;
|
|
389
|
+
const propBytes = propStride * Float64Array.BYTES_PER_ELEMENT;
|
|
390
|
+
const totalBytes = ruleBytes + propBytes;
|
|
391
|
+
|
|
392
|
+
const scratch = acquireScratch(instance, totalBytes);
|
|
393
|
+
try {
|
|
394
|
+
const memBuffer = exports.memory.buffer;
|
|
395
|
+
const rulePtr = scratch.ptr;
|
|
396
|
+
const propPtr = scratch.ptr + ruleBytes;
|
|
397
|
+
|
|
398
|
+
if (ruleCount > 0) {
|
|
399
|
+
const ruleF64 = new Float64Array(memBuffer, rulePtr, ruleCount * ruleStride);
|
|
400
|
+
for (let i = 0; i < ruleCount; i += 1) {
|
|
401
|
+
const r = normRules[i];
|
|
402
|
+
const offset = i * ruleStride;
|
|
403
|
+
ruleF64[offset + 0] = resolveBodyKey(r.pair?.[0], r.bodyKeyA);
|
|
404
|
+
ruleF64[offset + 1] = resolveBodyKey(r.pair?.[1], r.bodyKeyB);
|
|
405
|
+
ruleF64[offset + 2] = r.materialA;
|
|
406
|
+
ruleF64[offset + 3] = r.materialB;
|
|
407
|
+
ruleF64[offset + 4] = r.shapeIndexA;
|
|
408
|
+
ruleF64[offset + 5] = r.shapeIndexB;
|
|
409
|
+
ruleF64[offset + 6] = r.friction;
|
|
410
|
+
ruleF64[offset + 7] = r.restitution;
|
|
411
|
+
ruleF64[offset + 8] = r.rollingResistance;
|
|
412
|
+
ruleF64[offset + 9] = r.frictionCombine;
|
|
413
|
+
ruleF64[offset + 10] = r.restitutionCombine;
|
|
414
|
+
ruleF64[offset + 11] = r.hasSurfaceVelocity ? 1.0 : 0.0;
|
|
415
|
+
ruleF64[offset + 12] = r.surfaceVelocity ? r.surfaceVelocity.linear.x : 0.0;
|
|
416
|
+
ruleF64[offset + 13] = r.surfaceVelocity ? r.surfaceVelocity.linear.y : 0.0;
|
|
417
|
+
ruleF64[offset + 14] = r.surfaceVelocity ? r.surfaceVelocity.linear.z : 0.0;
|
|
418
|
+
ruleF64[offset + 15] = r.surfaceVelocity ? r.surfaceVelocity.angular.x : 0.0;
|
|
419
|
+
ruleF64[offset + 16] = r.surfaceVelocity ? r.surfaceVelocity.angular.y : 0.0;
|
|
420
|
+
ruleF64[offset + 17] = r.surfaceVelocity ? r.surfaceVelocity.angular.z : 0.0;
|
|
421
|
+
ruleF64[offset + 18] = r.surfaceVelocity ? r.surfaceVelocity.space : 0.0;
|
|
422
|
+
ruleF64[offset + 19] = r.enabled ? r.priority : -1.0;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
const keyA = toKey64(resolveBodyKey(idA, bodyKeyA));
|
|
427
|
+
const keyB = toKey64(resolveBodyKey(idB, bodyKeyB));
|
|
428
|
+
|
|
429
|
+
const status = exports.rundot_kinetix_ext_surface_velocity_evaluate_rules(
|
|
430
|
+
rulePtr,
|
|
431
|
+
ruleCount,
|
|
432
|
+
keyA,
|
|
433
|
+
keyB,
|
|
434
|
+
Number(defaultFrictionA ?? 0.6),
|
|
435
|
+
Number(defaultFrictionB ?? 0.6),
|
|
436
|
+
Number(defaultRestitutionA ?? 0.0),
|
|
437
|
+
Number(defaultRestitutionB ?? 0.0),
|
|
438
|
+
propPtr
|
|
439
|
+
);
|
|
440
|
+
|
|
441
|
+
if (status !== 0) {
|
|
442
|
+
throw new Error(`KINETIX_EXTENDED_PHYSICS_EVALUATE_RULES_FAILED: status ${status}`);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
const outProps = new Float64Array(exports.memory.buffer, propPtr, propStride);
|
|
446
|
+
const friction = outProps[0];
|
|
447
|
+
const restitution = outProps[1];
|
|
448
|
+
const rollingResistance = outProps[2];
|
|
449
|
+
let relVel = {
|
|
450
|
+
x: cleanZero(outProps[3]),
|
|
451
|
+
y: cleanZero(outProps[4]),
|
|
452
|
+
z: cleanZero(outProps[5]),
|
|
453
|
+
};
|
|
454
|
+
const enabled = outProps[6] !== 0.0;
|
|
455
|
+
const ruleMatched = outProps[7] !== 0.0;
|
|
456
|
+
const matchedRuleIndex = ruleMatched ? Math.round(outProps[8]) : -1;
|
|
457
|
+
const matchedRule = ruleMatched && matchedRuleIndex >= 0 && matchedRuleIndex < normRules.length
|
|
458
|
+
? normRules[matchedRuleIndex]
|
|
459
|
+
: null;
|
|
460
|
+
|
|
461
|
+
if ((!matchedRule || !matchedRule.hasSurfaceVelocity) && (surfA || surfB)) {
|
|
462
|
+
const vA = computeSurfacePointVelocity(surfA, orientationA, contactPoint, centerA);
|
|
463
|
+
const vB = computeSurfacePointVelocity(surfB, orientationB, contactPoint, centerB);
|
|
464
|
+
relVel = subVec3(vA, vB);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
return Object.freeze({
|
|
468
|
+
friction,
|
|
469
|
+
restitution,
|
|
470
|
+
rollingResistance,
|
|
471
|
+
relativeSurfaceVelocity: Object.freeze(relVel),
|
|
472
|
+
enabled,
|
|
473
|
+
ruleMatched,
|
|
474
|
+
matchedRuleIndex,
|
|
475
|
+
});
|
|
476
|
+
} finally {
|
|
477
|
+
scratch.free();
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
export function computeTangentialFrictionBias(relativeSurfaceVelocity, normal, tangent1, tangent2) {
|
|
482
|
+
const normComp = dotVec3(relativeSurfaceVelocity, normal);
|
|
483
|
+
const tanVel = subVec3(relativeSurfaceVelocity, scaleVec3(normal, normComp));
|
|
484
|
+
return {
|
|
485
|
+
bias1: cleanZero(dotVec3(tanVel, tangent1)),
|
|
486
|
+
bias2: cleanZero(dotVec3(tanVel, tangent2)),
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Solves one row of tangential friction constraint using compiled C++ WASM.
|
|
492
|
+
*/
|
|
493
|
+
export function solveTangentialFrictionRow(options = {}) {
|
|
494
|
+
const {
|
|
495
|
+
postRelativeVelocity = { x: 0, y: 0, z: 0 },
|
|
496
|
+
normal = { x: 0, y: 1, z: 0 },
|
|
497
|
+
tangentMass1 = 1.0,
|
|
498
|
+
tangentMass2 = 1.0,
|
|
499
|
+
friction = 0.6,
|
|
500
|
+
normalTotal = 0.0,
|
|
501
|
+
bias1 = 0.0,
|
|
502
|
+
bias2 = 0.0,
|
|
503
|
+
accumulatedTangent1 = 0.0,
|
|
504
|
+
accumulatedTangent2 = 0.0,
|
|
505
|
+
} = options;
|
|
506
|
+
|
|
507
|
+
const instance = getExtendedInstanceSync();
|
|
508
|
+
const exports = instance.exports;
|
|
509
|
+
|
|
510
|
+
if (typeof exports.rundot_kinetix_ext_surface_velocity_solve_conveyor_friction !== 'function') {
|
|
511
|
+
throw new Error('KINETIX_EXTENDED_PHYSICS_EXPORT_MISSING: rundot_kinetix_ext_surface_velocity_solve_conveyor_friction');
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
const scratch = acquireScratch(instance, 32);
|
|
515
|
+
try {
|
|
516
|
+
const ptr = scratch.ptr;
|
|
517
|
+
const status = exports.rundot_kinetix_ext_surface_velocity_solve_conveyor_friction(
|
|
518
|
+
Number(postRelativeVelocity.x ?? 0),
|
|
519
|
+
Number(postRelativeVelocity.y ?? 0),
|
|
520
|
+
Number(postRelativeVelocity.z ?? 0),
|
|
521
|
+
Number(normal.x ?? 0),
|
|
522
|
+
Number(normal.y ?? 0),
|
|
523
|
+
Number(normal.z ?? 0),
|
|
524
|
+
Number(tangentMass1 ?? 1.0),
|
|
525
|
+
Number(tangentMass2 ?? 1.0),
|
|
526
|
+
Number(friction ?? 0.6),
|
|
527
|
+
Number(normalTotal ?? 0.0),
|
|
528
|
+
Number(bias1 ?? 0.0),
|
|
529
|
+
Number(bias2 ?? 0.0),
|
|
530
|
+
Number(accumulatedTangent1 ?? 0.0),
|
|
531
|
+
Number(accumulatedTangent2 ?? 0.0),
|
|
532
|
+
ptr + 0,
|
|
533
|
+
ptr + 8,
|
|
534
|
+
ptr + 16,
|
|
535
|
+
ptr + 24
|
|
536
|
+
);
|
|
537
|
+
|
|
538
|
+
if (status !== 0) {
|
|
539
|
+
throw new Error(`KINETIX_EXTENDED_PHYSICS_SOLVE_CONVEYOR_FRICTION_FAILED: status ${status}`);
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
const out = new Float64Array(exports.memory.buffer, ptr, 4);
|
|
543
|
+
return {
|
|
544
|
+
accumulatedTangent1: cleanZero(out[0]),
|
|
545
|
+
accumulatedTangent2: cleanZero(out[1]),
|
|
546
|
+
impulseDelta1: cleanZero(out[2]),
|
|
547
|
+
impulseDelta2: cleanZero(out[3]),
|
|
548
|
+
};
|
|
549
|
+
} finally {
|
|
550
|
+
scratch.free();
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* Solves surface friction via C++ rundot_kinetix_ext_surface_velocity_solve_friction.
|
|
556
|
+
*/
|
|
557
|
+
export function solveSurfaceFriction(options = {}) {
|
|
558
|
+
const {
|
|
559
|
+
postRelativeVelocity = { x: 0, y: 0, z: 0 },
|
|
560
|
+
normal = { x: 0, y: 1, z: 0 },
|
|
561
|
+
tangentMass1 = 1.0,
|
|
562
|
+
tangentMass2 = 1.0,
|
|
563
|
+
friction = 0.6,
|
|
564
|
+
normalTotal = 0.0,
|
|
565
|
+
bias1 = 0.0,
|
|
566
|
+
bias2 = 0.0,
|
|
567
|
+
accumulatedTangent1 = 0.0,
|
|
568
|
+
accumulatedTangent2 = 0.0,
|
|
569
|
+
} = options;
|
|
570
|
+
|
|
571
|
+
const instance = getExtendedInstanceSync();
|
|
572
|
+
const exports = instance.exports;
|
|
573
|
+
|
|
574
|
+
if (typeof exports.rundot_kinetix_ext_surface_velocity_solve_friction !== 'function') {
|
|
575
|
+
throw new Error('KINETIX_EXTENDED_PHYSICS_EXPORT_MISSING: rundot_kinetix_ext_surface_velocity_solve_friction');
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
const scratch = acquireScratch(instance, 32);
|
|
579
|
+
try {
|
|
580
|
+
const ptr = scratch.ptr;
|
|
581
|
+
const status = exports.rundot_kinetix_ext_surface_velocity_solve_friction(
|
|
582
|
+
Number(postRelativeVelocity.x ?? 0),
|
|
583
|
+
Number(postRelativeVelocity.y ?? 0),
|
|
584
|
+
Number(postRelativeVelocity.z ?? 0),
|
|
585
|
+
Number(normal.x ?? 0),
|
|
586
|
+
Number(normal.y ?? 0),
|
|
587
|
+
Number(normal.z ?? 0),
|
|
588
|
+
Number(tangentMass1 ?? 1.0),
|
|
589
|
+
Number(tangentMass2 ?? 1.0),
|
|
590
|
+
Number(friction ?? 0.6),
|
|
591
|
+
Number(normalTotal ?? 0.0),
|
|
592
|
+
Number(bias1 ?? 0.0),
|
|
593
|
+
Number(bias2 ?? 0.0),
|
|
594
|
+
Number(accumulatedTangent1 ?? 0.0),
|
|
595
|
+
Number(accumulatedTangent2 ?? 0.0),
|
|
596
|
+
ptr + 0,
|
|
597
|
+
ptr + 8,
|
|
598
|
+
ptr + 16,
|
|
599
|
+
ptr + 24
|
|
600
|
+
);
|
|
601
|
+
|
|
602
|
+
if (status !== 0) {
|
|
603
|
+
throw new Error(`KINETIX_EXTENDED_PHYSICS_SOLVE_FRICTION_FAILED: status ${status}`);
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
const out = new Float64Array(exports.memory.buffer, ptr, 4);
|
|
607
|
+
return {
|
|
608
|
+
accumulatedTangent1: cleanZero(out[0]),
|
|
609
|
+
accumulatedTangent2: cleanZero(out[1]),
|
|
610
|
+
impulseDelta1: cleanZero(out[2]),
|
|
611
|
+
impulseDelta2: cleanZero(out[3]),
|
|
612
|
+
};
|
|
613
|
+
} finally {
|
|
614
|
+
scratch.free();
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* Queries C ABI strides and sizes from the WASM extended instance.
|
|
620
|
+
*/
|
|
621
|
+
export function getSurfaceVelocityRecordStride() {
|
|
622
|
+
const instance = getExtendedInstanceSync();
|
|
623
|
+
return instance.exports.rundot_kinetix_ext_surface_velocity_record_stride();
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
export function getContactMaterialRuleStride() {
|
|
627
|
+
const instance = getExtendedInstanceSync();
|
|
628
|
+
return instance.exports.rundot_kinetix_ext_surface_velocity_rule_stride();
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
export function getContactSurfacePropertiesStride() {
|
|
632
|
+
const instance = getExtendedInstanceSync();
|
|
633
|
+
return instance.exports.rundot_kinetix_ext_surface_velocity_properties_stride();
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
export function getSurfaceVelocityStride() {
|
|
637
|
+
const instance = getExtendedInstanceSync();
|
|
638
|
+
return instance.exports.rundot_kinetix_ext_surface_velocity_stride();
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
export function getSurfaceVelocitySize() {
|
|
642
|
+
const instance = getExtendedInstanceSync();
|
|
643
|
+
return instance.exports.rundot_kinetix_ext_surface_velocity_size();
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
export function cloneContactMaterialRules(rules) {
|
|
647
|
+
if (!Array.isArray(rules)) return [];
|
|
648
|
+
return rules.map((r) => ({
|
|
649
|
+
...r,
|
|
650
|
+
pair: r.pair ? [...r.pair] : null,
|
|
651
|
+
materialPair: r.materialPair ? [...r.materialPair] : null,
|
|
652
|
+
shapePair: r.shapePair ? [...r.shapePair] : null,
|
|
653
|
+
surfaceVelocity: r.surfaceVelocity ? { ...r.surfaceVelocity, linear: { ...r.surfaceVelocity.linear } } : null,
|
|
654
|
+
}));
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
export function serializeContactMaterialRules(rules) {
|
|
658
|
+
const norm = normalizeContactMaterialRules(rules);
|
|
659
|
+
const buffer = new Float64Array(norm.length * CONTACT_MATERIAL_RULE_STRIDE);
|
|
660
|
+
|
|
661
|
+
for (let i = 0; i < norm.length; i += 1) {
|
|
662
|
+
const r = norm[i];
|
|
663
|
+
const offset = i * CONTACT_MATERIAL_RULE_STRIDE;
|
|
664
|
+
buffer[offset + 0] = resolveBodyKey(r.pair?.[0], r.bodyKeyA);
|
|
665
|
+
buffer[offset + 1] = resolveBodyKey(r.pair?.[1], r.bodyKeyB);
|
|
666
|
+
buffer[offset + 2] = r.materialA;
|
|
667
|
+
buffer[offset + 3] = r.materialB;
|
|
668
|
+
buffer[offset + 4] = r.shapeIndexA;
|
|
669
|
+
buffer[offset + 5] = r.shapeIndexB;
|
|
670
|
+
buffer[offset + 6] = r.friction;
|
|
671
|
+
buffer[offset + 7] = r.restitution;
|
|
672
|
+
buffer[offset + 8] = r.rollingResistance;
|
|
673
|
+
buffer[offset + 9] = r.frictionCombine;
|
|
674
|
+
buffer[offset + 10] = r.restitutionCombine;
|
|
675
|
+
buffer[offset + 11] = r.hasSurfaceVelocity ? 1.0 : 0.0;
|
|
676
|
+
buffer[offset + 12] = r.surfaceVelocity ? r.surfaceVelocity.linear.x : 0.0;
|
|
677
|
+
buffer[offset + 13] = r.surfaceVelocity ? r.surfaceVelocity.linear.y : 0.0;
|
|
678
|
+
buffer[offset + 14] = r.surfaceVelocity ? r.surfaceVelocity.linear.z : 0.0;
|
|
679
|
+
buffer[offset + 15] = r.surfaceVelocity ? r.surfaceVelocity.angular.x : 0.0;
|
|
680
|
+
buffer[offset + 16] = r.surfaceVelocity ? r.surfaceVelocity.angular.y : 0.0;
|
|
681
|
+
buffer[offset + 17] = r.surfaceVelocity ? r.surfaceVelocity.angular.z : 0.0;
|
|
682
|
+
buffer[offset + 18] = r.surfaceVelocity ? r.surfaceVelocity.space : 0.0;
|
|
683
|
+
buffer[offset + 19] = r.enabled ? r.priority : -1.0;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
return buffer;
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
export function deserializeContactMaterialRules(buffer) {
|
|
690
|
+
if (!(buffer instanceof Float64Array)) {
|
|
691
|
+
return [];
|
|
692
|
+
}
|
|
693
|
+
const count = Math.floor(buffer.length / CONTACT_MATERIAL_RULE_STRIDE);
|
|
694
|
+
const rules = [];
|
|
695
|
+
|
|
696
|
+
for (let i = 0; i < count; i += 1) {
|
|
697
|
+
const offset = i * CONTACT_MATERIAL_RULE_STRIDE;
|
|
698
|
+
const bodyKeyA = buffer[offset + 0];
|
|
699
|
+
const bodyKeyB = buffer[offset + 1];
|
|
700
|
+
const hasSurf = buffer[offset + 11] !== 0.0;
|
|
701
|
+
|
|
702
|
+
rules.push(createContactMaterialRule({
|
|
703
|
+
pair: bodyKeyA !== 0 || bodyKeyB !== 0 ? [bodyKeyA, bodyKeyB] : null,
|
|
704
|
+
materialPair: [buffer[offset + 2], buffer[offset + 3]],
|
|
705
|
+
shapePair: [buffer[offset + 4], buffer[offset + 5]],
|
|
706
|
+
friction: buffer[offset + 6],
|
|
707
|
+
restitution: buffer[offset + 7],
|
|
708
|
+
rollingResistance: buffer[offset + 8],
|
|
709
|
+
frictionCombine: buffer[offset + 9],
|
|
710
|
+
restitutionCombine: buffer[offset + 10],
|
|
711
|
+
surfaceVelocity: hasSurf ? {
|
|
712
|
+
linear: { x: buffer[offset + 12], y: buffer[offset + 13], z: buffer[offset + 14] },
|
|
713
|
+
angular: { x: buffer[offset + 15], y: buffer[offset + 16], z: buffer[offset + 17] },
|
|
714
|
+
space: buffer[offset + 18],
|
|
715
|
+
} : null,
|
|
716
|
+
enabled: buffer[offset + 19] >= 0.0,
|
|
717
|
+
priority: buffer[offset + 19],
|
|
718
|
+
}));
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
return rules;
|
|
722
|
+
}
|