@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,1074 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tracked vehicles and motorcycle balance (V05 capability).
|
|
3
|
+
*
|
|
4
|
+
* Implements continuous track contact, friction evaluation, differential skid steering,
|
|
5
|
+
* and two-wheel motorcycle balance / lean stability / countersteering controllers.
|
|
6
|
+
* Computation is routed through compiled C++ WASM (physics-extended.wasm).
|
|
7
|
+
*
|
|
8
|
+
* Determinism is strictly maintained: 64-bit IEEE 754 doubles only, zero host divergence.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { ensureExtendedInstance, extendedPhysicsReady } from './extended-wasm-instance.mjs';
|
|
12
|
+
import { physicsExtendedWasmModuleBase64 } from './physics-extended-wasm-module.generated.mjs';
|
|
13
|
+
|
|
14
|
+
export { ensureExtendedInstance, extendedPhysicsReady };
|
|
15
|
+
|
|
16
|
+
export const TRACKS_WASM_ENTRY_POINTS = Object.freeze([
|
|
17
|
+
'rundot_kinetix_ext_tracks_abi_version',
|
|
18
|
+
'rundot_kinetix_ext_tracks_wheel_stride',
|
|
19
|
+
'rundot_kinetix_ext_tracks_track_config_stride',
|
|
20
|
+
'rundot_kinetix_ext_tracks_vehicle_config_stride',
|
|
21
|
+
'rundot_kinetix_ext_tracks_input_stride',
|
|
22
|
+
'rundot_kinetix_ext_tracks_state_stride',
|
|
23
|
+
'rundot_kinetix_ext_tracks_output_stride',
|
|
24
|
+
'rundot_kinetix_ext_tracks_max_wheels_per_track',
|
|
25
|
+
'rundot_kinetix_ext_tracks_max_tracks',
|
|
26
|
+
'rundot_kinetix_ext_tracks_stride',
|
|
27
|
+
'rundot_kinetix_ext_tracks_size',
|
|
28
|
+
'rundot_kinetix_ext_tracks_step_vehicle',
|
|
29
|
+
'rundot_kinetix_ext_tracks_step',
|
|
30
|
+
'rundot_kinetix_ext_tracks_evaluate_friction',
|
|
31
|
+
'rundot_kinetix_ext_tracks_differential_steering',
|
|
32
|
+
'rundot_kinetix_ext_motorcycle_abi_version',
|
|
33
|
+
'rundot_kinetix_ext_motorcycle_config_stride',
|
|
34
|
+
'rundot_kinetix_ext_motorcycle_input_stride',
|
|
35
|
+
'rundot_kinetix_ext_motorcycle_state_stride',
|
|
36
|
+
'rundot_kinetix_ext_motorcycle_output_stride',
|
|
37
|
+
'rundot_kinetix_ext_motorcycle_stride',
|
|
38
|
+
'rundot_kinetix_ext_motorcycle_size',
|
|
39
|
+
'rundot_kinetix_ext_motorcycle_step',
|
|
40
|
+
'rundot_kinetix_ext_motorcycle_lean_stability',
|
|
41
|
+
'rundot_kinetix_ext_motorcycle_countersteer',
|
|
42
|
+
'rundot_kinetix_ext_vehicles_abi_version',
|
|
43
|
+
]);
|
|
44
|
+
|
|
45
|
+
let defaultWasmInstance = null;
|
|
46
|
+
|
|
47
|
+
export async function initTracks() {
|
|
48
|
+
if (defaultWasmInstance !== null) return defaultWasmInstance;
|
|
49
|
+
await extendedPhysicsReady();
|
|
50
|
+
defaultWasmInstance = await ensureExtendedInstance();
|
|
51
|
+
return defaultWasmInstance;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function setTracksWasmInstance(instance) {
|
|
55
|
+
defaultWasmInstance = instance;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function getTracksWasmInstance() {
|
|
59
|
+
return defaultWasmInstance;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function decodeBase64(value) {
|
|
63
|
+
if (typeof atob === 'function') {
|
|
64
|
+
const decoded = atob(value);
|
|
65
|
+
const bytes = new Uint8Array(decoded.length);
|
|
66
|
+
for (let i = 0; i < decoded.length; i += 1) bytes[i] = decoded.charCodeAt(i);
|
|
67
|
+
return bytes;
|
|
68
|
+
}
|
|
69
|
+
if (typeof Buffer !== 'undefined') return Uint8Array.from(Buffer.from(value, 'base64'));
|
|
70
|
+
throw new Error('KINETIX_EXTENDED_PHYSICS_BASE64_UNAVAILABLE: Base64 decoding is unavailable in this environment');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function getWasmExports(customInstance) {
|
|
74
|
+
if (customInstance?.exports) {
|
|
75
|
+
return customInstance.exports;
|
|
76
|
+
}
|
|
77
|
+
if (defaultWasmInstance?.exports) {
|
|
78
|
+
return defaultWasmInstance.exports;
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
const bytes = decodeBase64(physicsExtendedWasmModuleBase64);
|
|
82
|
+
const module = new WebAssembly.Module(bytes);
|
|
83
|
+
const instance = new WebAssembly.Instance(module, {});
|
|
84
|
+
instance.exports._initialize?.();
|
|
85
|
+
defaultWasmInstance = instance;
|
|
86
|
+
return defaultWasmInstance.exports;
|
|
87
|
+
} catch (error) {
|
|
88
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
89
|
+
throw new Error(
|
|
90
|
+
`KINETIX_EXTENDED_PHYSICS_NOT_INITIALIZED: failed to load extended physics WASM module (${detail}). Await extendedPhysicsReady() or initTracks().`,
|
|
91
|
+
{ cause: error }
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function allocateScratch(exports, byteLength) {
|
|
97
|
+
if (typeof exports.malloc === 'function') {
|
|
98
|
+
const ptr = exports.malloc(byteLength);
|
|
99
|
+
if (ptr !== 0) return ptr;
|
|
100
|
+
}
|
|
101
|
+
const stack = typeof exports.emscripten_stack_get_current === 'function'
|
|
102
|
+
? exports.emscripten_stack_get_current()
|
|
103
|
+
: 1048576;
|
|
104
|
+
const base = Math.ceil((stack + 65536) / 16) * 16;
|
|
105
|
+
const required = base + byteLength;
|
|
106
|
+
if (required > exports.memory.buffer.byteLength) {
|
|
107
|
+
const pages = Math.ceil((required - exports.memory.buffer.byteLength) / 65536);
|
|
108
|
+
exports.memory.grow(pages);
|
|
109
|
+
}
|
|
110
|
+
return base;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function freeScratch(exports, ptr) {
|
|
114
|
+
if (typeof exports.free === 'function') {
|
|
115
|
+
exports.free(ptr);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// ---------------------------------------------------------------------------
|
|
120
|
+
// ABI, Stride & Metadata Getters
|
|
121
|
+
// ---------------------------------------------------------------------------
|
|
122
|
+
|
|
123
|
+
export function getTracksAbiVersion(instance) {
|
|
124
|
+
const exp = getWasmExports(instance);
|
|
125
|
+
return exp.rundot_kinetix_ext_tracks_abi_version();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function getTracksWheelStride(instance) {
|
|
129
|
+
const exp = getWasmExports(instance);
|
|
130
|
+
return exp.rundot_kinetix_ext_tracks_wheel_stride();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function getTracksTrackConfigStride(instance) {
|
|
134
|
+
const exp = getWasmExports(instance);
|
|
135
|
+
return exp.rundot_kinetix_ext_tracks_track_config_stride();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function getTracksVehicleConfigStride(instance) {
|
|
139
|
+
const exp = getWasmExports(instance);
|
|
140
|
+
return exp.rundot_kinetix_ext_tracks_vehicle_config_stride();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function getTracksInputStride(instance) {
|
|
144
|
+
const exp = getWasmExports(instance);
|
|
145
|
+
return exp.rundot_kinetix_ext_tracks_input_stride();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function getTracksStateStride(instance) {
|
|
149
|
+
const exp = getWasmExports(instance);
|
|
150
|
+
return exp.rundot_kinetix_ext_tracks_state_stride();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export function getTracksOutputStride(instance) {
|
|
154
|
+
const exp = getWasmExports(instance);
|
|
155
|
+
return exp.rundot_kinetix_ext_tracks_output_stride();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function getTracksMaxWheelsPerTrack(instance) {
|
|
159
|
+
const exp = getWasmExports(instance);
|
|
160
|
+
return exp.rundot_kinetix_ext_tracks_max_wheels_per_track();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export function getTracksMaxTracks(instance) {
|
|
164
|
+
const exp = getWasmExports(instance);
|
|
165
|
+
return exp.rundot_kinetix_ext_tracks_max_tracks();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function getTracksStride(instance) {
|
|
169
|
+
const exp = getWasmExports(instance);
|
|
170
|
+
return exp.rundot_kinetix_ext_tracks_stride();
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export function getTracksSize(instance) {
|
|
174
|
+
const exp = getWasmExports(instance);
|
|
175
|
+
return exp.rundot_kinetix_ext_tracks_size();
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export function getMotorcycleAbiVersion(instance) {
|
|
179
|
+
const exp = getWasmExports(instance);
|
|
180
|
+
return exp.rundot_kinetix_ext_motorcycle_abi_version();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export function getMotorcycleConfigStride(instance) {
|
|
184
|
+
const exp = getWasmExports(instance);
|
|
185
|
+
return exp.rundot_kinetix_ext_motorcycle_config_stride();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export function getMotorcycleInputStride(instance) {
|
|
189
|
+
const exp = getWasmExports(instance);
|
|
190
|
+
return exp.rundot_kinetix_ext_motorcycle_input_stride();
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export function getMotorcycleStateStride(instance) {
|
|
194
|
+
const exp = getWasmExports(instance);
|
|
195
|
+
return exp.rundot_kinetix_ext_motorcycle_state_stride();
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export function getMotorcycleOutputStride(instance) {
|
|
199
|
+
const exp = getWasmExports(instance);
|
|
200
|
+
return exp.rundot_kinetix_ext_motorcycle_output_stride();
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export function getMotorcycleStride(instance) {
|
|
204
|
+
const exp = getWasmExports(instance);
|
|
205
|
+
return exp.rundot_kinetix_ext_motorcycle_stride();
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export function getMotorcycleSize(instance) {
|
|
209
|
+
const exp = getWasmExports(instance);
|
|
210
|
+
return exp.rundot_kinetix_ext_motorcycle_size();
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export function getVehiclesAbiVersion(instance) {
|
|
214
|
+
const exp = getWasmExports(instance);
|
|
215
|
+
return exp.rundot_kinetix_ext_vehicles_abi_version();
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// ---------------------------------------------------------------------------
|
|
219
|
+
// Configuration / State Builders
|
|
220
|
+
// ---------------------------------------------------------------------------
|
|
221
|
+
|
|
222
|
+
export function createTrackConfig(options = {}) {
|
|
223
|
+
return {
|
|
224
|
+
side: options.side ?? 0,
|
|
225
|
+
offset: {
|
|
226
|
+
x: options.offset?.x ?? 0.0,
|
|
227
|
+
y: options.offset?.y ?? 0.0,
|
|
228
|
+
z: options.offset?.z ?? (options.side === 1 ? 1.0 : -1.0),
|
|
229
|
+
},
|
|
230
|
+
trackLength: options.trackLength ?? 3.0,
|
|
231
|
+
trackWidth: options.trackWidth ?? 0.4,
|
|
232
|
+
wheelCount: options.wheelCount ?? 5,
|
|
233
|
+
muLongitudinal: options.muLongitudinal ?? 0.85,
|
|
234
|
+
muLateral: options.muLateral ?? 0.95,
|
|
235
|
+
trackTension: options.trackTension ?? 15000.0,
|
|
236
|
+
sprocketRadius: options.sprocketRadius ?? 0.3,
|
|
237
|
+
sprocketInertia: options.sprocketInertia ?? 2.5,
|
|
238
|
+
maxDriveTorque: options.maxDriveTorque ?? 5000.0,
|
|
239
|
+
maxBrakeTorque: options.maxBrakeTorque ?? 6000.0,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export function createTrackedVehicleConfig(options = {}) {
|
|
244
|
+
const trackGauge = options.trackGauge ?? 2.0;
|
|
245
|
+
const tracks = options.tracks ?? [
|
|
246
|
+
createTrackConfig({ side: 0, offset: { x: 0.0, y: 0.0, z: -trackGauge * 0.5 } }),
|
|
247
|
+
createTrackConfig({ side: 1, offset: { x: 0.0, y: 0.0, z: trackGauge * 0.5 } }),
|
|
248
|
+
];
|
|
249
|
+
|
|
250
|
+
return {
|
|
251
|
+
mass: options.mass ?? 12000.0,
|
|
252
|
+
length: options.length ?? 4.5,
|
|
253
|
+
width: options.width ?? 2.4,
|
|
254
|
+
height: options.height ?? 1.8,
|
|
255
|
+
inertia: {
|
|
256
|
+
x: options.inertia?.x ?? 15000.0,
|
|
257
|
+
y: options.inertia?.y ?? 25000.0,
|
|
258
|
+
z: options.inertia?.z ?? 18000.0,
|
|
259
|
+
},
|
|
260
|
+
trackGauge,
|
|
261
|
+
sprocketRadius: options.sprocketRadius ?? 0.3,
|
|
262
|
+
maxSpeed: options.maxSpeed ?? 18.0,
|
|
263
|
+
roadWheelCount: options.roadWheelCount ?? 5,
|
|
264
|
+
tracks,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export function createTrackedVehicleState(options = {}) {
|
|
269
|
+
return {
|
|
270
|
+
position: {
|
|
271
|
+
x: options.position?.x ?? 0.0,
|
|
272
|
+
y: options.position?.y ?? 0.0,
|
|
273
|
+
z: options.position?.z ?? 0.0,
|
|
274
|
+
},
|
|
275
|
+
orientation: {
|
|
276
|
+
x: options.orientation?.x ?? 0.0,
|
|
277
|
+
y: options.orientation?.y ?? 0.0,
|
|
278
|
+
z: options.orientation?.z ?? 0.0,
|
|
279
|
+
w: options.orientation?.w ?? 1.0,
|
|
280
|
+
},
|
|
281
|
+
linearVel: {
|
|
282
|
+
x: options.linearVel?.x ?? 0.0,
|
|
283
|
+
y: options.linearVel?.y ?? 0.0,
|
|
284
|
+
z: options.linearVel?.z ?? 0.0,
|
|
285
|
+
},
|
|
286
|
+
angularVel: {
|
|
287
|
+
x: options.angularVel?.x ?? 0.0,
|
|
288
|
+
y: options.angularVel?.y ?? 0.0,
|
|
289
|
+
z: options.angularVel?.z ?? 0.0,
|
|
290
|
+
},
|
|
291
|
+
leftTrackLinearSpeed: options.leftTrackLinearSpeed ?? 0.0,
|
|
292
|
+
rightTrackLinearSpeed: options.rightTrackLinearSpeed ?? 0.0,
|
|
293
|
+
leftSprocketAngularVel: options.leftSprocketAngularVel ?? 0.0,
|
|
294
|
+
rightSprocketAngularVel: options.rightSprocketAngularVel ?? 0.0,
|
|
295
|
+
leftTrackSlip: options.leftTrackSlip ?? 0.0,
|
|
296
|
+
rightTrackSlip: options.rightTrackSlip ?? 0.0,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export function createTrackedVehicleInput(options = {}) {
|
|
301
|
+
return {
|
|
302
|
+
forward: options.forward ?? 0.0,
|
|
303
|
+
steer: options.steer ?? 0.0,
|
|
304
|
+
leftRatio: options.leftRatio ?? 1.0,
|
|
305
|
+
rightRatio: options.rightRatio ?? 1.0,
|
|
306
|
+
brake: options.brake ?? 0.0,
|
|
307
|
+
leftBrake: options.leftBrake ?? 0.0,
|
|
308
|
+
rightBrake: options.rightBrake ?? 0.0,
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export function createMotorcycleConfig(options = {}) {
|
|
313
|
+
return {
|
|
314
|
+
mass: options.mass ?? 220.0,
|
|
315
|
+
inertia: {
|
|
316
|
+
x: options.inertia?.x ?? 35.0,
|
|
317
|
+
y: options.inertia?.y ?? 45.0,
|
|
318
|
+
z: options.inertia?.z ?? 15.0,
|
|
319
|
+
},
|
|
320
|
+
wheelbase: options.wheelbase ?? 1.45,
|
|
321
|
+
rakeAngle: options.rakeAngle ?? 0.436332,
|
|
322
|
+
trail: options.trail ?? 0.095,
|
|
323
|
+
comHeight: options.comHeight ?? 0.55,
|
|
324
|
+
frontRadius: options.frontRadius ?? 0.30,
|
|
325
|
+
rearRadius: options.rearRadius ?? 0.32,
|
|
326
|
+
frontInertia: options.frontInertia ?? 0.85,
|
|
327
|
+
rearInertia: options.rearInertia ?? 1.10,
|
|
328
|
+
frontCorneringStiffness: options.frontCorneringStiffness ?? 15000.0,
|
|
329
|
+
rearCorneringStiffness: options.rearCorneringStiffness ?? 20000.0,
|
|
330
|
+
frontCamberStiffness: options.frontCamberStiffness ?? 2200.0,
|
|
331
|
+
rearCamberStiffness: options.rearCamberStiffness ?? 3000.0,
|
|
332
|
+
enableLeanController: options.enableLeanController ?? true,
|
|
333
|
+
enableLeanSteeringLimit: options.enableLeanSteeringLimit ?? true,
|
|
334
|
+
leanSpringConstant: options.leanSpringConstant ?? 3200.0,
|
|
335
|
+
leanSpringDamping: options.leanSpringDamping ?? 450.0,
|
|
336
|
+
leanSpringIntegrationCoefficient: options.leanSpringIntegrationCoefficient ?? 120.0,
|
|
337
|
+
leanSpringIntegrationCoefficientDecay: options.leanSpringIntegrationCoefficientDecay ?? 0.95,
|
|
338
|
+
leanSmoothingFactor: options.leanSmoothingFactor ?? 0.15,
|
|
339
|
+
maxLeanAngle: options.maxLeanAngle ?? 0.82,
|
|
340
|
+
maxBalanceTorque: options.maxBalanceTorque ?? 1200.0,
|
|
341
|
+
maxSteerTorque: options.maxSteerTorque ?? 250.0,
|
|
342
|
+
maxSteerAngle: options.maxSteerAngle ?? 0.65,
|
|
343
|
+
counterSteerFactor: options.counterSteerFactor ?? 1.25,
|
|
344
|
+
gyroscopicFactor: options.gyroscopicFactor ?? 1.0,
|
|
345
|
+
maxDriveTorque: options.maxDriveTorque ?? 450.0,
|
|
346
|
+
maxBrakeTorque: options.maxBrakeTorque ?? 900.0,
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export function createMotorcycleState(options = {}) {
|
|
351
|
+
return {
|
|
352
|
+
position: {
|
|
353
|
+
x: options.position?.x ?? 0.0,
|
|
354
|
+
y: options.position?.y ?? 0.0,
|
|
355
|
+
z: options.position?.z ?? 0.0,
|
|
356
|
+
},
|
|
357
|
+
orientation: {
|
|
358
|
+
x: options.orientation?.x ?? 0.0,
|
|
359
|
+
y: options.orientation?.y ?? 0.0,
|
|
360
|
+
z: options.orientation?.z ?? 0.0,
|
|
361
|
+
w: options.orientation?.w ?? 1.0,
|
|
362
|
+
},
|
|
363
|
+
linearVel: {
|
|
364
|
+
x: options.linearVel?.x ?? 0.0,
|
|
365
|
+
y: options.linearVel?.y ?? 0.0,
|
|
366
|
+
z: options.linearVel?.z ?? 0.0,
|
|
367
|
+
},
|
|
368
|
+
angularVel: {
|
|
369
|
+
x: options.angularVel?.x ?? 0.0,
|
|
370
|
+
y: options.angularVel?.y ?? 0.0,
|
|
371
|
+
z: options.angularVel?.z ?? 0.0,
|
|
372
|
+
},
|
|
373
|
+
steerAngle: options.steerAngle ?? 0.0,
|
|
374
|
+
steerAngularVel: options.steerAngularVel ?? 0.0,
|
|
375
|
+
frontWheelOmega: options.frontWheelOmega ?? 0.0,
|
|
376
|
+
rearWheelOmega: options.rearWheelOmega ?? 0.0,
|
|
377
|
+
currentLean: options.currentLean ?? 0.0,
|
|
378
|
+
currentLeanRate: options.currentLeanRate ?? 0.0,
|
|
379
|
+
targetLean: options.targetLean ?? 0.0,
|
|
380
|
+
leanErrorIntegral: options.leanErrorIntegral ?? 0.0,
|
|
381
|
+
smoothedLean: options.smoothedLean ?? 0.0,
|
|
382
|
+
frontNormalForce: options.frontNormalForce ?? 1100.0,
|
|
383
|
+
rearNormalForce: options.rearNormalForce ?? 1100.0,
|
|
384
|
+
frontGrounded: options.frontGrounded ?? true,
|
|
385
|
+
rearGrounded: options.rearGrounded ?? true,
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
export function createMotorcycleInput(options = {}) {
|
|
390
|
+
return {
|
|
391
|
+
throttle: options.throttle ?? 0.0,
|
|
392
|
+
steer: options.steer ?? 0.0,
|
|
393
|
+
frontBrake: options.frontBrake ?? 0.0,
|
|
394
|
+
rearBrake: options.rearBrake ?? 0.0,
|
|
395
|
+
targetLeanOverride: options.targetLeanOverride ?? 0.0,
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// ---------------------------------------------------------------------------
|
|
400
|
+
// Continuous Tracks Physics Solvers
|
|
401
|
+
// ---------------------------------------------------------------------------
|
|
402
|
+
|
|
403
|
+
function packTrackedVehicleConfig(exp, config, cfgView) {
|
|
404
|
+
const trackGauge = config.trackGauge ?? 2.0;
|
|
405
|
+
cfgView[0] = config.mass ?? 12000.0;
|
|
406
|
+
cfgView[1] = config.length ?? 4.5;
|
|
407
|
+
cfgView[2] = config.width ?? 2.4;
|
|
408
|
+
cfgView[3] = config.height ?? 1.8;
|
|
409
|
+
cfgView[4] = config.inertia?.x ?? 15000.0;
|
|
410
|
+
cfgView[5] = config.inertia?.y ?? 25000.0;
|
|
411
|
+
cfgView[6] = config.inertia?.z ?? 18000.0;
|
|
412
|
+
cfgView[7] = trackGauge;
|
|
413
|
+
cfgView[8] = config.sprocketRadius ?? 0.3;
|
|
414
|
+
cfgView[9] = config.maxSpeed ?? 18.0;
|
|
415
|
+
cfgView[10] = config.roadWheelCount ?? 5;
|
|
416
|
+
|
|
417
|
+
const vehicleStride = exp.rundot_kinetix_ext_tracks_vehicle_config_stride();
|
|
418
|
+
const trackStride = exp.rundot_kinetix_ext_tracks_track_config_stride();
|
|
419
|
+
|
|
420
|
+
const tracks = Array.isArray(config.tracks)
|
|
421
|
+
? config.tracks
|
|
422
|
+
: [config.tracks?.left, config.tracks?.right];
|
|
423
|
+
|
|
424
|
+
for (let t = 0; t < 2; t += 1) {
|
|
425
|
+
const track = tracks?.[t] ?? {};
|
|
426
|
+
const offset = vehicleStride + t * trackStride;
|
|
427
|
+
cfgView[offset + 0] = track.offset?.x ?? 0.0;
|
|
428
|
+
cfgView[offset + 1] = track.offset?.y ?? 0.0;
|
|
429
|
+
cfgView[offset + 2] = track.offset?.z ?? (t === 1 ? trackGauge * 0.5 : -trackGauge * 0.5);
|
|
430
|
+
cfgView[offset + 3] = track.trackLength ?? 3.0;
|
|
431
|
+
cfgView[offset + 4] = track.trackWidth ?? 0.4;
|
|
432
|
+
cfgView[offset + 5] = track.wheelCount ?? (config.roadWheelCount ?? 5);
|
|
433
|
+
cfgView[offset + 6] = track.muLongitudinal ?? 0.85;
|
|
434
|
+
cfgView[offset + 7] = track.muLateral ?? 0.95;
|
|
435
|
+
cfgView[offset + 8] = track.trackTension ?? 15000.0;
|
|
436
|
+
cfgView[offset + 9] = track.sprocketRadius ?? (config.sprocketRadius ?? 0.3);
|
|
437
|
+
cfgView[offset + 10] = track.sprocketInertia ?? 2.5;
|
|
438
|
+
cfgView[offset + 11] = track.maxDriveTorque ?? 5000.0;
|
|
439
|
+
cfgView[offset + 12] = track.maxBrakeTorque ?? 6000.0;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
function packTrackedVehicleState(state, stView) {
|
|
444
|
+
stView[0] = state.position?.x ?? 0.0;
|
|
445
|
+
stView[1] = state.position?.y ?? 0.0;
|
|
446
|
+
stView[2] = state.position?.z ?? 0.0;
|
|
447
|
+
stView[3] = state.orientation?.x ?? 0.0;
|
|
448
|
+
stView[4] = state.orientation?.y ?? 0.0;
|
|
449
|
+
stView[5] = state.orientation?.z ?? 0.0;
|
|
450
|
+
stView[6] = state.orientation?.w ?? 1.0;
|
|
451
|
+
stView[7] = state.linearVel?.x ?? 0.0;
|
|
452
|
+
stView[8] = state.linearVel?.y ?? 0.0;
|
|
453
|
+
stView[9] = state.linearVel?.z ?? 0.0;
|
|
454
|
+
stView[10] = state.angularVel?.x ?? 0.0;
|
|
455
|
+
stView[11] = state.angularVel?.y ?? 0.0;
|
|
456
|
+
stView[12] = state.angularVel?.z ?? 0.0;
|
|
457
|
+
stView[13] = state.leftTrackLinearSpeed ?? 0.0;
|
|
458
|
+
stView[14] = state.rightTrackLinearSpeed ?? 0.0;
|
|
459
|
+
stView[15] = state.leftSprocketAngularVel ?? 0.0;
|
|
460
|
+
stView[16] = state.rightSprocketAngularVel ?? 0.0;
|
|
461
|
+
stView[17] = state.leftTrackSlip ?? 0.0;
|
|
462
|
+
stView[18] = state.rightTrackSlip ?? 0.0;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
function packTrackedVehicleInput(input, inView) {
|
|
466
|
+
inView[0] = input.forward ?? 0.0;
|
|
467
|
+
inView[1] = input.steer ?? 0.0;
|
|
468
|
+
inView[2] = input.leftRatio ?? 1.0;
|
|
469
|
+
inView[3] = input.rightRatio ?? 1.0;
|
|
470
|
+
inView[4] = input.brake ?? 0.0;
|
|
471
|
+
inView[5] = input.leftBrake ?? 0.0;
|
|
472
|
+
inView[6] = input.rightBrake ?? 0.0;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
function unpackTrackedVehicleOutput(outView) {
|
|
476
|
+
return {
|
|
477
|
+
netForce: { x: outView[0], y: outView[1], z: outView[2] },
|
|
478
|
+
netTorque: { x: outView[3], y: outView[4], z: outView[5] },
|
|
479
|
+
leftTrack: {
|
|
480
|
+
tractionForce: outView[6],
|
|
481
|
+
lateralScrubForce: outView[8],
|
|
482
|
+
linearSpeed: outView[13],
|
|
483
|
+
},
|
|
484
|
+
rightTrack: {
|
|
485
|
+
tractionForce: outView[7],
|
|
486
|
+
lateralScrubForce: outView[9],
|
|
487
|
+
linearSpeed: outView[14],
|
|
488
|
+
},
|
|
489
|
+
scrubResistanceTorque: outView[10],
|
|
490
|
+
turnRadius: outView[11],
|
|
491
|
+
yawRate: outView[12],
|
|
492
|
+
totalGroundedWheels: Math.round(outView[15]),
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
function unpackTrackedVehicleState(nextStView, targetState) {
|
|
497
|
+
const next = {
|
|
498
|
+
position: { x: nextStView[0], y: nextStView[1], z: nextStView[2] },
|
|
499
|
+
orientation: { x: nextStView[3], y: nextStView[4], z: nextStView[5], w: nextStView[6] },
|
|
500
|
+
linearVel: { x: nextStView[7], y: nextStView[8], z: nextStView[9] },
|
|
501
|
+
angularVel: { x: nextStView[10], y: nextStView[11], z: nextStView[12] },
|
|
502
|
+
leftTrackLinearSpeed: nextStView[13],
|
|
503
|
+
rightTrackLinearSpeed: nextStView[14],
|
|
504
|
+
leftSprocketAngularVel: nextStView[15],
|
|
505
|
+
rightSprocketAngularVel: nextStView[16],
|
|
506
|
+
leftTrackSlip: nextStView[17],
|
|
507
|
+
rightTrackSlip: nextStView[18],
|
|
508
|
+
};
|
|
509
|
+
|
|
510
|
+
if (targetState && typeof targetState === 'object') {
|
|
511
|
+
targetState.position = next.position;
|
|
512
|
+
targetState.orientation = next.orientation;
|
|
513
|
+
targetState.linearVel = next.linearVel;
|
|
514
|
+
targetState.angularVel = next.angularVel;
|
|
515
|
+
targetState.leftTrackLinearSpeed = next.leftTrackLinearSpeed;
|
|
516
|
+
targetState.rightTrackLinearSpeed = next.rightTrackLinearSpeed;
|
|
517
|
+
targetState.leftSprocketAngularVel = next.leftSprocketAngularVel;
|
|
518
|
+
targetState.rightSprocketAngularVel = next.rightSprocketAngularVel;
|
|
519
|
+
targetState.leftTrackSlip = next.leftTrackSlip;
|
|
520
|
+
targetState.rightTrackSlip = next.rightTrackSlip;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
return next;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
export function stepTrackedVehicle(config, state, input, groundElevation = 0.0, dt = 1.0 / 60.0, customInstance = null) {
|
|
527
|
+
const exp = getWasmExports(customInstance);
|
|
528
|
+
const cfgStride = exp.rundot_kinetix_ext_tracks_vehicle_config_stride();
|
|
529
|
+
const trackStride = exp.rundot_kinetix_ext_tracks_track_config_stride();
|
|
530
|
+
const maxTracks = exp.rundot_kinetix_ext_tracks_max_tracks();
|
|
531
|
+
const stateStride = exp.rundot_kinetix_ext_tracks_state_stride();
|
|
532
|
+
const inStride = exp.rundot_kinetix_ext_tracks_input_stride();
|
|
533
|
+
const outStride = exp.rundot_kinetix_ext_tracks_output_stride();
|
|
534
|
+
|
|
535
|
+
const totalCfgDoubles = cfgStride + maxTracks * trackStride;
|
|
536
|
+
const totalDoubles = totalCfgDoubles + stateStride + inStride + outStride + stateStride;
|
|
537
|
+
const totalBytes = totalDoubles * 8;
|
|
538
|
+
const basePtr = allocateScratch(exp, totalBytes);
|
|
539
|
+
|
|
540
|
+
try {
|
|
541
|
+
let ptr = basePtr;
|
|
542
|
+
const cfgPtr = ptr; ptr += totalCfgDoubles * 8;
|
|
543
|
+
const stPtr = ptr; ptr += stateStride * 8;
|
|
544
|
+
const inPtr = ptr; ptr += inStride * 8;
|
|
545
|
+
const outPtr = ptr; ptr += outStride * 8;
|
|
546
|
+
const nextStPtr = ptr; ptr += stateStride * 8;
|
|
547
|
+
|
|
548
|
+
const cfgView = new Float64Array(exp.memory.buffer, cfgPtr, totalCfgDoubles);
|
|
549
|
+
cfgView.fill(0.0);
|
|
550
|
+
packTrackedVehicleConfig(exp, config, cfgView);
|
|
551
|
+
|
|
552
|
+
const stView = new Float64Array(exp.memory.buffer, stPtr, stateStride);
|
|
553
|
+
stView.fill(0.0);
|
|
554
|
+
packTrackedVehicleState(state, stView);
|
|
555
|
+
|
|
556
|
+
const inView = new Float64Array(exp.memory.buffer, inPtr, inStride);
|
|
557
|
+
inView.fill(0.0);
|
|
558
|
+
packTrackedVehicleInput(input, inView);
|
|
559
|
+
|
|
560
|
+
const outView = new Float64Array(exp.memory.buffer, outPtr, outStride);
|
|
561
|
+
outView.fill(0.0);
|
|
562
|
+
|
|
563
|
+
const nextStView = new Float64Array(exp.memory.buffer, nextStPtr, stateStride);
|
|
564
|
+
nextStView.fill(0.0);
|
|
565
|
+
|
|
566
|
+
const status = exp.rundot_kinetix_ext_tracks_step_vehicle(
|
|
567
|
+
cfgPtr,
|
|
568
|
+
stPtr,
|
|
569
|
+
inPtr,
|
|
570
|
+
groundElevation,
|
|
571
|
+
dt,
|
|
572
|
+
outPtr,
|
|
573
|
+
nextStPtr
|
|
574
|
+
);
|
|
575
|
+
|
|
576
|
+
if (status !== 0) {
|
|
577
|
+
throw new Error(`KINETIX_TRACKS_STEP_VEHICLE_FAILED status=${status}`);
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
const output = unpackTrackedVehicleOutput(outView);
|
|
581
|
+
const nextState = unpackTrackedVehicleState(nextStView, state);
|
|
582
|
+
|
|
583
|
+
return { output, nextState };
|
|
584
|
+
} finally {
|
|
585
|
+
freeScratch(exp, basePtr);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
export function stepTrack(config, state, input, groundElevation = 0.0, dt = 1.0 / 60.0, customInstance = null) {
|
|
590
|
+
const exp = getWasmExports(customInstance);
|
|
591
|
+
const cfgStride = exp.rundot_kinetix_ext_tracks_vehicle_config_stride();
|
|
592
|
+
const trackStride = exp.rundot_kinetix_ext_tracks_track_config_stride();
|
|
593
|
+
const maxTracks = exp.rundot_kinetix_ext_tracks_max_tracks();
|
|
594
|
+
const stateStride = exp.rundot_kinetix_ext_tracks_state_stride();
|
|
595
|
+
const inStride = exp.rundot_kinetix_ext_tracks_input_stride();
|
|
596
|
+
const outStride = exp.rundot_kinetix_ext_tracks_output_stride();
|
|
597
|
+
|
|
598
|
+
const totalCfgDoubles = cfgStride + maxTracks * trackStride;
|
|
599
|
+
const totalDoubles = totalCfgDoubles + stateStride + inStride + outStride + stateStride;
|
|
600
|
+
const totalBytes = totalDoubles * 8;
|
|
601
|
+
const basePtr = allocateScratch(exp, totalBytes);
|
|
602
|
+
|
|
603
|
+
try {
|
|
604
|
+
let ptr = basePtr;
|
|
605
|
+
const cfgPtr = ptr; ptr += totalCfgDoubles * 8;
|
|
606
|
+
const stPtr = ptr; ptr += stateStride * 8;
|
|
607
|
+
const inPtr = ptr; ptr += inStride * 8;
|
|
608
|
+
const outPtr = ptr; ptr += outStride * 8;
|
|
609
|
+
const nextStPtr = ptr; ptr += stateStride * 8;
|
|
610
|
+
|
|
611
|
+
const cfgView = new Float64Array(exp.memory.buffer, cfgPtr, totalCfgDoubles);
|
|
612
|
+
cfgView.fill(0.0);
|
|
613
|
+
packTrackedVehicleConfig(exp, config, cfgView);
|
|
614
|
+
|
|
615
|
+
const stView = new Float64Array(exp.memory.buffer, stPtr, stateStride);
|
|
616
|
+
stView.fill(0.0);
|
|
617
|
+
packTrackedVehicleState(state, stView);
|
|
618
|
+
|
|
619
|
+
const inView = new Float64Array(exp.memory.buffer, inPtr, inStride);
|
|
620
|
+
inView.fill(0.0);
|
|
621
|
+
packTrackedVehicleInput(input, inView);
|
|
622
|
+
|
|
623
|
+
const outView = new Float64Array(exp.memory.buffer, outPtr, outStride);
|
|
624
|
+
outView.fill(0.0);
|
|
625
|
+
|
|
626
|
+
const nextStView = new Float64Array(exp.memory.buffer, nextStPtr, stateStride);
|
|
627
|
+
nextStView.fill(0.0);
|
|
628
|
+
|
|
629
|
+
const status = exp.rundot_kinetix_ext_tracks_step(
|
|
630
|
+
cfgPtr,
|
|
631
|
+
stPtr,
|
|
632
|
+
inPtr,
|
|
633
|
+
groundElevation,
|
|
634
|
+
dt,
|
|
635
|
+
outPtr,
|
|
636
|
+
nextStPtr
|
|
637
|
+
);
|
|
638
|
+
|
|
639
|
+
if (status !== 0) {
|
|
640
|
+
throw new Error(`KINETIX_TRACKS_STEP_FAILED status=${status}`);
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
const output = unpackTrackedVehicleOutput(outView);
|
|
644
|
+
const nextState = unpackTrackedVehicleState(nextStView, state);
|
|
645
|
+
|
|
646
|
+
return { output, nextState };
|
|
647
|
+
} finally {
|
|
648
|
+
freeScratch(exp, basePtr);
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
export function evaluateTrackFriction(
|
|
653
|
+
trackSpeed,
|
|
654
|
+
contactVx,
|
|
655
|
+
contactVz,
|
|
656
|
+
normalForce,
|
|
657
|
+
muLon,
|
|
658
|
+
muLat,
|
|
659
|
+
contactXOffset = 0.0,
|
|
660
|
+
customInstance = null
|
|
661
|
+
) {
|
|
662
|
+
const exp = getWasmExports(customInstance);
|
|
663
|
+
const totalBytes = 3 * 8;
|
|
664
|
+
const outPtr = allocateScratch(exp, totalBytes);
|
|
665
|
+
|
|
666
|
+
try {
|
|
667
|
+
const outView = new Float64Array(exp.memory.buffer, outPtr, 3);
|
|
668
|
+
outView.fill(0.0);
|
|
669
|
+
|
|
670
|
+
const status = exp.rundot_kinetix_ext_tracks_evaluate_friction(
|
|
671
|
+
trackSpeed,
|
|
672
|
+
contactVx,
|
|
673
|
+
contactVz,
|
|
674
|
+
normalForce,
|
|
675
|
+
muLon,
|
|
676
|
+
muLat,
|
|
677
|
+
contactXOffset,
|
|
678
|
+
outPtr
|
|
679
|
+
);
|
|
680
|
+
|
|
681
|
+
if (status !== 0) {
|
|
682
|
+
throw new Error(`KINETIX_TRACKS_EVALUATE_FRICTION_FAILED status=${status}`);
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
return {
|
|
686
|
+
longitudinalForce: outView[0],
|
|
687
|
+
lateralForce: outView[1],
|
|
688
|
+
scrubTorque: outView[2],
|
|
689
|
+
};
|
|
690
|
+
} finally {
|
|
691
|
+
freeScratch(exp, outPtr);
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
export function evaluateDifferentialSteering(
|
|
696
|
+
forwardInput,
|
|
697
|
+
leftRatio,
|
|
698
|
+
rightRatio,
|
|
699
|
+
trackGauge,
|
|
700
|
+
maxSpeed,
|
|
701
|
+
currentForwardSpeed,
|
|
702
|
+
customInstance = null
|
|
703
|
+
) {
|
|
704
|
+
const exp = getWasmExports(customInstance);
|
|
705
|
+
const totalBytes = 3 * 8;
|
|
706
|
+
const outPtr = allocateScratch(exp, totalBytes);
|
|
707
|
+
|
|
708
|
+
try {
|
|
709
|
+
const outView = new Float64Array(exp.memory.buffer, outPtr, 3);
|
|
710
|
+
outView.fill(0.0);
|
|
711
|
+
|
|
712
|
+
const status = exp.rundot_kinetix_ext_tracks_differential_steering(
|
|
713
|
+
forwardInput,
|
|
714
|
+
leftRatio,
|
|
715
|
+
rightRatio,
|
|
716
|
+
trackGauge,
|
|
717
|
+
maxSpeed,
|
|
718
|
+
currentForwardSpeed,
|
|
719
|
+
outPtr
|
|
720
|
+
);
|
|
721
|
+
|
|
722
|
+
if (status !== 0) {
|
|
723
|
+
throw new Error(`KINETIX_TRACKS_DIFFERENTIAL_STEERING_FAILED status=${status}`);
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
return {
|
|
727
|
+
targetLeftSpeed: outView[0],
|
|
728
|
+
targetRightSpeed: outView[1],
|
|
729
|
+
differentialTorque: outView[2],
|
|
730
|
+
};
|
|
731
|
+
} finally {
|
|
732
|
+
freeScratch(exp, outPtr);
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
// ---------------------------------------------------------------------------
|
|
737
|
+
// Motorcycle Balance, Lean Stability & Countersteering Solvers
|
|
738
|
+
// ---------------------------------------------------------------------------
|
|
739
|
+
|
|
740
|
+
function packMotorcycleConfig(config, cfgView) {
|
|
741
|
+
cfgView[0] = config.mass ?? 220.0;
|
|
742
|
+
cfgView[1] = config.inertia?.x ?? 35.0;
|
|
743
|
+
cfgView[2] = config.inertia?.y ?? 45.0;
|
|
744
|
+
cfgView[3] = config.inertia?.z ?? 15.0;
|
|
745
|
+
cfgView[4] = config.wheelbase ?? 1.45;
|
|
746
|
+
cfgView[5] = config.rakeAngle ?? 0.436332;
|
|
747
|
+
cfgView[6] = config.trail ?? 0.095;
|
|
748
|
+
cfgView[7] = config.comHeight ?? 0.55;
|
|
749
|
+
cfgView[8] = config.frontRadius ?? 0.30;
|
|
750
|
+
cfgView[9] = config.rearRadius ?? 0.32;
|
|
751
|
+
cfgView[10] = config.frontInertia ?? 0.85;
|
|
752
|
+
cfgView[11] = config.rearInertia ?? 1.10;
|
|
753
|
+
cfgView[12] = config.frontCorneringStiffness ?? 15000.0;
|
|
754
|
+
cfgView[13] = config.rearCorneringStiffness ?? 20000.0;
|
|
755
|
+
cfgView[14] = config.frontCamberStiffness ?? 2200.0;
|
|
756
|
+
cfgView[15] = config.rearCamberStiffness ?? 3000.0;
|
|
757
|
+
cfgView[16] = (config.enableLeanController !== false) ? 1.0 : 0.0;
|
|
758
|
+
cfgView[17] = (config.enableLeanSteeringLimit !== false) ? 1.0 : 0.0;
|
|
759
|
+
cfgView[18] = config.leanSpringConstant ?? 3200.0;
|
|
760
|
+
cfgView[19] = config.leanSpringDamping ?? 450.0;
|
|
761
|
+
cfgView[20] = config.leanSpringIntegrationCoefficient ?? 120.0;
|
|
762
|
+
cfgView[21] = config.leanSpringIntegrationCoefficientDecay ?? 0.95;
|
|
763
|
+
cfgView[22] = config.leanSmoothingFactor ?? 0.15;
|
|
764
|
+
cfgView[23] = config.maxLeanAngle ?? 0.82;
|
|
765
|
+
cfgView[24] = config.maxBalanceTorque ?? 1200.0;
|
|
766
|
+
cfgView[25] = config.maxSteerTorque ?? 250.0;
|
|
767
|
+
cfgView[26] = config.maxSteerAngle ?? 0.65;
|
|
768
|
+
cfgView[27] = config.counterSteerFactor ?? 1.25;
|
|
769
|
+
cfgView[28] = config.gyroscopicFactor ?? 1.0;
|
|
770
|
+
cfgView[29] = config.maxDriveTorque ?? 450.0;
|
|
771
|
+
cfgView[30] = config.maxBrakeTorque ?? 900.0;
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
function packMotorcycleState(state, stView) {
|
|
775
|
+
stView[0] = state.position?.x ?? 0.0;
|
|
776
|
+
stView[1] = state.position?.y ?? 0.0;
|
|
777
|
+
stView[2] = state.position?.z ?? 0.0;
|
|
778
|
+
stView[3] = state.orientation?.x ?? 0.0;
|
|
779
|
+
stView[4] = state.orientation?.y ?? 0.0;
|
|
780
|
+
stView[5] = state.orientation?.z ?? 0.0;
|
|
781
|
+
stView[6] = state.orientation?.w ?? 1.0;
|
|
782
|
+
stView[7] = state.linearVel?.x ?? 0.0;
|
|
783
|
+
stView[8] = state.linearVel?.y ?? 0.0;
|
|
784
|
+
stView[9] = state.linearVel?.z ?? 0.0;
|
|
785
|
+
stView[10] = state.angularVel?.x ?? 0.0;
|
|
786
|
+
stView[11] = state.angularVel?.y ?? 0.0;
|
|
787
|
+
stView[12] = state.angularVel?.z ?? 0.0;
|
|
788
|
+
stView[13] = state.steerAngle ?? 0.0;
|
|
789
|
+
stView[14] = state.steerAngularVel ?? 0.0;
|
|
790
|
+
stView[15] = state.frontWheelOmega ?? 0.0;
|
|
791
|
+
stView[16] = state.rearWheelOmega ?? 0.0;
|
|
792
|
+
stView[17] = state.currentLean ?? 0.0;
|
|
793
|
+
stView[18] = state.currentLeanRate ?? 0.0;
|
|
794
|
+
stView[19] = state.targetLean ?? 0.0;
|
|
795
|
+
stView[20] = state.leanErrorIntegral ?? 0.0;
|
|
796
|
+
stView[21] = state.smoothedLean ?? 0.0;
|
|
797
|
+
stView[22] = state.frontNormalForce ?? 1100.0;
|
|
798
|
+
stView[23] = state.rearNormalForce ?? 1100.0;
|
|
799
|
+
stView[24] = (state.frontGrounded !== false) ? 1.0 : 0.0;
|
|
800
|
+
stView[25] = (state.rearGrounded !== false) ? 1.0 : 0.0;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
function packMotorcycleInput(input, inView) {
|
|
804
|
+
inView[0] = input.throttle ?? 0.0;
|
|
805
|
+
inView[1] = input.steer ?? 0.0;
|
|
806
|
+
inView[2] = input.frontBrake ?? 0.0;
|
|
807
|
+
inView[3] = input.rearBrake ?? 0.0;
|
|
808
|
+
inView[4] = input.targetLeanOverride ?? 0.0;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
function unpackMotorcycleOutput(outView) {
|
|
812
|
+
return {
|
|
813
|
+
balanceTorque: outView[0],
|
|
814
|
+
steerTorque: outView[1],
|
|
815
|
+
updatedSteerAngle: outView[2],
|
|
816
|
+
gyroscopicTorque: outView[3],
|
|
817
|
+
counterSteerTorque: outView[4],
|
|
818
|
+
frontLongitudinalForce: outView[5],
|
|
819
|
+
frontLateralForce: outView[6],
|
|
820
|
+
frontCamberForce: outView[7],
|
|
821
|
+
rearLongitudinalForce: outView[8],
|
|
822
|
+
rearLateralForce: outView[9],
|
|
823
|
+
rearCamberForce: outView[10],
|
|
824
|
+
netForce: { x: outView[11], y: outView[12], z: outView[13] },
|
|
825
|
+
netTorque: { x: outView[14], y: outView[15], z: outView[16] },
|
|
826
|
+
targetLean: outView[17],
|
|
827
|
+
leanStable: outView[18] > 0.5,
|
|
828
|
+
};
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
function unpackMotorcycleState(nextStView, targetState) {
|
|
832
|
+
const next = {
|
|
833
|
+
position: { x: nextStView[0], y: nextStView[1], z: nextStView[2] },
|
|
834
|
+
orientation: { x: nextStView[3], y: nextStView[4], z: nextStView[5], w: nextStView[6] },
|
|
835
|
+
linearVel: { x: nextStView[7], y: nextStView[8], z: nextStView[9] },
|
|
836
|
+
angularVel: { x: nextStView[10], y: nextStView[11], z: nextStView[12] },
|
|
837
|
+
steerAngle: nextStView[13],
|
|
838
|
+
steerAngularVel: nextStView[14],
|
|
839
|
+
frontWheelOmega: nextStView[15],
|
|
840
|
+
rearWheelOmega: nextStView[16],
|
|
841
|
+
currentLean: nextStView[17],
|
|
842
|
+
currentLeanRate: nextStView[18],
|
|
843
|
+
targetLean: nextStView[19],
|
|
844
|
+
leanErrorIntegral: nextStView[20],
|
|
845
|
+
smoothedLean: nextStView[21],
|
|
846
|
+
frontNormalForce: nextStView[22],
|
|
847
|
+
rearNormalForce: nextStView[23],
|
|
848
|
+
frontGrounded: nextStView[24] > 0.5,
|
|
849
|
+
rearGrounded: nextStView[25] > 0.5,
|
|
850
|
+
};
|
|
851
|
+
|
|
852
|
+
if (targetState && typeof targetState === 'object') {
|
|
853
|
+
targetState.position = next.position;
|
|
854
|
+
targetState.orientation = next.orientation;
|
|
855
|
+
targetState.linearVel = next.linearVel;
|
|
856
|
+
targetState.angularVel = next.angularVel;
|
|
857
|
+
targetState.steerAngle = next.steerAngle;
|
|
858
|
+
targetState.steerAngularVel = next.steerAngularVel;
|
|
859
|
+
targetState.frontWheelOmega = next.frontWheelOmega;
|
|
860
|
+
targetState.rearWheelOmega = next.rearWheelOmega;
|
|
861
|
+
targetState.currentLean = next.currentLean;
|
|
862
|
+
targetState.currentLeanRate = next.currentLeanRate;
|
|
863
|
+
targetState.targetLean = next.targetLean;
|
|
864
|
+
targetState.leanErrorIntegral = next.leanErrorIntegral;
|
|
865
|
+
targetState.smoothedLean = next.smoothedLean;
|
|
866
|
+
targetState.frontNormalForce = next.frontNormalForce;
|
|
867
|
+
targetState.rearNormalForce = next.rearNormalForce;
|
|
868
|
+
targetState.frontGrounded = next.frontGrounded;
|
|
869
|
+
targetState.rearGrounded = next.rearGrounded;
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
return next;
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
export function stepMotorcycle(config, state, input, groundElevation = 0.0, dt = 1.0 / 60.0, customInstance = null) {
|
|
876
|
+
const exp = getWasmExports(customInstance);
|
|
877
|
+
const cfgStride = exp.rundot_kinetix_ext_motorcycle_config_stride();
|
|
878
|
+
const stStride = exp.rundot_kinetix_ext_motorcycle_state_stride();
|
|
879
|
+
const inStride = exp.rundot_kinetix_ext_motorcycle_input_stride();
|
|
880
|
+
const outStride = exp.rundot_kinetix_ext_motorcycle_output_stride();
|
|
881
|
+
|
|
882
|
+
const totalDoubles = cfgStride + stStride + inStride + outStride + stStride;
|
|
883
|
+
const totalBytes = totalDoubles * 8;
|
|
884
|
+
const basePtr = allocateScratch(exp, totalBytes);
|
|
885
|
+
|
|
886
|
+
try {
|
|
887
|
+
let ptr = basePtr;
|
|
888
|
+
const cfgPtr = ptr; ptr += cfgStride * 8;
|
|
889
|
+
const stPtr = ptr; ptr += stStride * 8;
|
|
890
|
+
const inPtr = ptr; ptr += inStride * 8;
|
|
891
|
+
const outPtr = ptr; ptr += outStride * 8;
|
|
892
|
+
const nextStPtr = ptr; ptr += stStride * 8;
|
|
893
|
+
|
|
894
|
+
const cfgView = new Float64Array(exp.memory.buffer, cfgPtr, cfgStride);
|
|
895
|
+
cfgView.fill(0.0);
|
|
896
|
+
packMotorcycleConfig(config, cfgView);
|
|
897
|
+
|
|
898
|
+
const stView = new Float64Array(exp.memory.buffer, stPtr, stStride);
|
|
899
|
+
stView.fill(0.0);
|
|
900
|
+
packMotorcycleState(state, stView);
|
|
901
|
+
|
|
902
|
+
const inView = new Float64Array(exp.memory.buffer, inPtr, inStride);
|
|
903
|
+
inView.fill(0.0);
|
|
904
|
+
packMotorcycleInput(input, inView);
|
|
905
|
+
|
|
906
|
+
const outView = new Float64Array(exp.memory.buffer, outPtr, outStride);
|
|
907
|
+
outView.fill(0.0);
|
|
908
|
+
|
|
909
|
+
const nextStView = new Float64Array(exp.memory.buffer, nextStPtr, stStride);
|
|
910
|
+
nextStView.fill(0.0);
|
|
911
|
+
|
|
912
|
+
const status = exp.rundot_kinetix_ext_motorcycle_step(
|
|
913
|
+
cfgPtr,
|
|
914
|
+
stPtr,
|
|
915
|
+
inPtr,
|
|
916
|
+
groundElevation,
|
|
917
|
+
dt,
|
|
918
|
+
outPtr,
|
|
919
|
+
nextStPtr
|
|
920
|
+
);
|
|
921
|
+
|
|
922
|
+
if (status !== 0) {
|
|
923
|
+
throw new Error(`KINETIX_MOTORCYCLE_STEP_FAILED status=${status}`);
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
const output = unpackMotorcycleOutput(outView);
|
|
927
|
+
const nextState = unpackMotorcycleState(nextStView, state);
|
|
928
|
+
|
|
929
|
+
return { output, nextState };
|
|
930
|
+
} finally {
|
|
931
|
+
freeScratch(exp, basePtr);
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
export function computeMotorcycleLeanStability(
|
|
936
|
+
config,
|
|
937
|
+
currentLean,
|
|
938
|
+
currentLeanRate,
|
|
939
|
+
targetLean,
|
|
940
|
+
leanIntegral = 0.0,
|
|
941
|
+
dt = 1.0 / 60.0,
|
|
942
|
+
customInstance = null
|
|
943
|
+
) {
|
|
944
|
+
const exp = getWasmExports(customInstance);
|
|
945
|
+
const cfgStride = exp.rundot_kinetix_ext_motorcycle_config_stride();
|
|
946
|
+
const totalDoubles = cfgStride + 2;
|
|
947
|
+
const totalBytes = totalDoubles * 8;
|
|
948
|
+
const basePtr = allocateScratch(exp, totalBytes);
|
|
949
|
+
|
|
950
|
+
try {
|
|
951
|
+
const cfgPtr = basePtr;
|
|
952
|
+
const outTorquePtr = cfgPtr + cfgStride * 8;
|
|
953
|
+
const outNewIntegralPtr = outTorquePtr + 8;
|
|
954
|
+
|
|
955
|
+
const cfgView = new Float64Array(exp.memory.buffer, cfgPtr, cfgStride);
|
|
956
|
+
cfgView.fill(0.0);
|
|
957
|
+
packMotorcycleConfig(config, cfgView);
|
|
958
|
+
|
|
959
|
+
const status = exp.rundot_kinetix_ext_motorcycle_lean_stability(
|
|
960
|
+
cfgPtr,
|
|
961
|
+
currentLean,
|
|
962
|
+
currentLeanRate,
|
|
963
|
+
targetLean,
|
|
964
|
+
leanIntegral,
|
|
965
|
+
dt,
|
|
966
|
+
outTorquePtr,
|
|
967
|
+
outNewIntegralPtr
|
|
968
|
+
);
|
|
969
|
+
|
|
970
|
+
if (status !== 0) {
|
|
971
|
+
throw new Error(`KINETIX_MOTORCYCLE_LEAN_STABILITY_FAILED status=${status}`);
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
const torqueView = new Float64Array(exp.memory.buffer, outTorquePtr, 1);
|
|
975
|
+
const integralView = new Float64Array(exp.memory.buffer, outNewIntegralPtr, 1);
|
|
976
|
+
|
|
977
|
+
return {
|
|
978
|
+
balanceTorque: torqueView[0],
|
|
979
|
+
newIntegral: integralView[0],
|
|
980
|
+
};
|
|
981
|
+
} finally {
|
|
982
|
+
freeScratch(exp, basePtr);
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
export function computeMotorcycleCountersteer(
|
|
987
|
+
forwardSpeed,
|
|
988
|
+
steerCommand,
|
|
989
|
+
currentSteerAngle,
|
|
990
|
+
currentLean,
|
|
991
|
+
targetLean,
|
|
992
|
+
wheelbase = 1.45,
|
|
993
|
+
rakeAngle = 0.436332,
|
|
994
|
+
counterSteerFactor = 1.25,
|
|
995
|
+
maxSteerTorque = 250.0,
|
|
996
|
+
customInstance = null
|
|
997
|
+
) {
|
|
998
|
+
const exp = getWasmExports(customInstance);
|
|
999
|
+
const totalBytes = 2 * 8;
|
|
1000
|
+
const basePtr = allocateScratch(exp, totalBytes);
|
|
1001
|
+
|
|
1002
|
+
try {
|
|
1003
|
+
const outTorquePtr = basePtr;
|
|
1004
|
+
const outTargetSteerPtr = basePtr + 8;
|
|
1005
|
+
|
|
1006
|
+
const status = exp.rundot_kinetix_ext_motorcycle_countersteer(
|
|
1007
|
+
forwardSpeed,
|
|
1008
|
+
steerCommand,
|
|
1009
|
+
currentSteerAngle,
|
|
1010
|
+
currentLean,
|
|
1011
|
+
targetLean,
|
|
1012
|
+
wheelbase,
|
|
1013
|
+
rakeAngle,
|
|
1014
|
+
counterSteerFactor,
|
|
1015
|
+
maxSteerTorque,
|
|
1016
|
+
outTorquePtr,
|
|
1017
|
+
outTargetSteerPtr
|
|
1018
|
+
);
|
|
1019
|
+
|
|
1020
|
+
if (status !== 0) {
|
|
1021
|
+
throw new Error(`KINETIX_MOTORCYCLE_COUNTERSTEER_FAILED status=${status}`);
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
const torqueView = new Float64Array(exp.memory.buffer, outTorquePtr, 1);
|
|
1025
|
+
const steerView = new Float64Array(exp.memory.buffer, outTargetSteerPtr, 1);
|
|
1026
|
+
|
|
1027
|
+
return {
|
|
1028
|
+
counterSteerTorque: torqueView[0],
|
|
1029
|
+
targetSteerAngle: steerView[0],
|
|
1030
|
+
};
|
|
1031
|
+
} finally {
|
|
1032
|
+
freeScratch(exp, basePtr);
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
export default {
|
|
1037
|
+
TRACKS_WASM_ENTRY_POINTS,
|
|
1038
|
+
initTracks,
|
|
1039
|
+
setTracksWasmInstance,
|
|
1040
|
+
getTracksWasmInstance,
|
|
1041
|
+
getTracksAbiVersion,
|
|
1042
|
+
getTracksWheelStride,
|
|
1043
|
+
getTracksTrackConfigStride,
|
|
1044
|
+
getTracksVehicleConfigStride,
|
|
1045
|
+
getTracksInputStride,
|
|
1046
|
+
getTracksStateStride,
|
|
1047
|
+
getTracksOutputStride,
|
|
1048
|
+
getTracksMaxWheelsPerTrack,
|
|
1049
|
+
getTracksMaxTracks,
|
|
1050
|
+
getTracksStride,
|
|
1051
|
+
getTracksSize,
|
|
1052
|
+
getMotorcycleAbiVersion,
|
|
1053
|
+
getMotorcycleConfigStride,
|
|
1054
|
+
getMotorcycleInputStride,
|
|
1055
|
+
getMotorcycleStateStride,
|
|
1056
|
+
getMotorcycleOutputStride,
|
|
1057
|
+
getMotorcycleStride,
|
|
1058
|
+
getMotorcycleSize,
|
|
1059
|
+
getVehiclesAbiVersion,
|
|
1060
|
+
createTrackConfig,
|
|
1061
|
+
createTrackedVehicleConfig,
|
|
1062
|
+
createTrackedVehicleState,
|
|
1063
|
+
createTrackedVehicleInput,
|
|
1064
|
+
createMotorcycleConfig,
|
|
1065
|
+
createMotorcycleState,
|
|
1066
|
+
createMotorcycleInput,
|
|
1067
|
+
stepTrackedVehicle,
|
|
1068
|
+
stepTrack,
|
|
1069
|
+
evaluateTrackFriction,
|
|
1070
|
+
evaluateDifferentialSteering,
|
|
1071
|
+
stepMotorcycle,
|
|
1072
|
+
computeMotorcycleLeanStability,
|
|
1073
|
+
computeMotorcycleCountersteer,
|
|
1074
|
+
};
|