@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,366 @@
|
|
|
1
|
+
#include "surface_velocity.hpp"
|
|
2
|
+
|
|
3
|
+
#include <algorithm>
|
|
4
|
+
#include <cmath>
|
|
5
|
+
#include <cstring>
|
|
6
|
+
|
|
7
|
+
namespace rundot::kinetix::physics {
|
|
8
|
+
|
|
9
|
+
double combineMaterialProperty(double a, double b, MaterialCombineMode mode) {
|
|
10
|
+
switch (mode) {
|
|
11
|
+
case MaterialCombineMode::Average:
|
|
12
|
+
return (a + b) * 0.5;
|
|
13
|
+
case MaterialCombineMode::Minimum:
|
|
14
|
+
return std::min(a, b);
|
|
15
|
+
case MaterialCombineMode::Multiply:
|
|
16
|
+
return solverSqrt(std::max(0.0, a * b));
|
|
17
|
+
case MaterialCombineMode::Maximum:
|
|
18
|
+
return std::max(a, b);
|
|
19
|
+
default:
|
|
20
|
+
return (a + b) * 0.5;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
SurfaceVec3 computeSurfacePointVelocity(
|
|
25
|
+
const SurfaceVelocityConfig& config,
|
|
26
|
+
const SurfaceQuat& orientation,
|
|
27
|
+
const SurfaceVec3& point,
|
|
28
|
+
const SurfaceVec3& center) {
|
|
29
|
+
if (!config.enabled) {
|
|
30
|
+
return {0.0, 0.0, 0.0};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
SurfaceVec3 linearWorld = config.linear;
|
|
34
|
+
SurfaceVec3 angularWorld = config.angular;
|
|
35
|
+
|
|
36
|
+
if (config.space == SurfaceVelocitySpace::Local) {
|
|
37
|
+
linearWorld = rotateByQuat(orientation, config.linear);
|
|
38
|
+
angularWorld = rotateByQuat(orientation, config.angular);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Linear motion + rotational tangential motion (w x r)
|
|
42
|
+
const SurfaceVec3 r = subVec3(point, center);
|
|
43
|
+
const SurfaceVec3 rotational = crossVec3(angularWorld, r);
|
|
44
|
+
return addVec3(linearWorld, rotational);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
bool evaluateContactMaterialRules(
|
|
48
|
+
std::span<const ContactMaterialRule> rules,
|
|
49
|
+
std::uint64_t bodyKeyA,
|
|
50
|
+
std::uint64_t bodyKeyB,
|
|
51
|
+
std::uint32_t materialA,
|
|
52
|
+
std::uint32_t materialB,
|
|
53
|
+
std::int32_t shapeA,
|
|
54
|
+
std::int32_t shapeB,
|
|
55
|
+
const SurfaceVelocityConfig& surfA,
|
|
56
|
+
const SurfaceVelocityConfig& surfB,
|
|
57
|
+
const SurfaceQuat& orientationA,
|
|
58
|
+
const SurfaceQuat& orientationB,
|
|
59
|
+
const SurfaceVec3& contactPoint,
|
|
60
|
+
const SurfaceVec3& centerA,
|
|
61
|
+
const SurfaceVec3& centerB,
|
|
62
|
+
double defaultFrictionA,
|
|
63
|
+
double defaultFrictionB,
|
|
64
|
+
double defaultRestitutionA,
|
|
65
|
+
double defaultRestitutionB,
|
|
66
|
+
double defaultRollingA,
|
|
67
|
+
double defaultRollingB,
|
|
68
|
+
ContactSurfaceProperties& outProps) {
|
|
69
|
+
|
|
70
|
+
// Default combined properties
|
|
71
|
+
outProps.friction = combineMaterialProperty(defaultFrictionA, defaultFrictionB, MaterialCombineMode::Multiply);
|
|
72
|
+
outProps.restitution = combineMaterialProperty(defaultRestitutionA, defaultRestitutionB, MaterialCombineMode::Maximum);
|
|
73
|
+
outProps.rollingResistance = combineMaterialProperty(defaultRollingA, defaultRollingB, MaterialCombineMode::Maximum);
|
|
74
|
+
outProps.enabled = true;
|
|
75
|
+
outProps.ruleMatched = false;
|
|
76
|
+
outProps.matchedRuleIndex = 0;
|
|
77
|
+
|
|
78
|
+
// Base surface velocities at the contact point (in world space)
|
|
79
|
+
const SurfaceVec3 vA = computeSurfacePointVelocity(surfA, orientationA, contactPoint, centerA);
|
|
80
|
+
const SurfaceVec3 vB = computeSurfacePointVelocity(surfB, orientationB, contactPoint, centerB);
|
|
81
|
+
outProps.relativeSurfaceVelocity = subVec3(vA, vB);
|
|
82
|
+
|
|
83
|
+
if (rules.empty()) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const ContactMaterialRule* bestRule = nullptr;
|
|
88
|
+
bool bestMatchedForward = true;
|
|
89
|
+
std::int32_t bestPriority = std::numeric_limits<std::int32_t>::min();
|
|
90
|
+
std::uint32_t bestIndex = 0;
|
|
91
|
+
|
|
92
|
+
// Stable deterministic iteration in index order
|
|
93
|
+
for (std::size_t i = 0; i < rules.size(); ++i) {
|
|
94
|
+
const auto& rule = rules[i];
|
|
95
|
+
|
|
96
|
+
// Check forward match (A matches rule.A, B matches rule.B)
|
|
97
|
+
const bool bodyMatchFwd =
|
|
98
|
+
(rule.bodyKeyA == 0 || rule.bodyKeyA == bodyKeyA) &&
|
|
99
|
+
(rule.bodyKeyB == 0 || rule.bodyKeyB == bodyKeyB);
|
|
100
|
+
|
|
101
|
+
const bool matMatchFwd =
|
|
102
|
+
(rule.materialA == 0 || rule.materialA == materialA) &&
|
|
103
|
+
(rule.materialB == 0 || rule.materialB == materialB);
|
|
104
|
+
|
|
105
|
+
const bool shapeMatchFwd =
|
|
106
|
+
(rule.shapeIndexA < 0 || rule.shapeIndexA == shapeA) &&
|
|
107
|
+
(rule.shapeIndexB < 0 || rule.shapeIndexB == shapeB);
|
|
108
|
+
|
|
109
|
+
const bool forwardMatch = bodyMatchFwd && matMatchFwd && shapeMatchFwd;
|
|
110
|
+
|
|
111
|
+
// Check reverse match (A matches rule.B, B matches rule.A)
|
|
112
|
+
const bool bodyMatchRev =
|
|
113
|
+
(rule.bodyKeyA == 0 || rule.bodyKeyA == bodyKeyB) &&
|
|
114
|
+
(rule.bodyKeyB == 0 || rule.bodyKeyB == bodyKeyA);
|
|
115
|
+
|
|
116
|
+
const bool matMatchRev =
|
|
117
|
+
(rule.materialA == 0 || rule.materialA == materialB) &&
|
|
118
|
+
(rule.materialB == 0 || rule.materialB == materialA);
|
|
119
|
+
|
|
120
|
+
const bool shapeMatchRev =
|
|
121
|
+
(rule.shapeIndexA < 0 || rule.shapeIndexA == shapeB) &&
|
|
122
|
+
(rule.shapeIndexB < 0 || rule.shapeIndexB == shapeA);
|
|
123
|
+
|
|
124
|
+
const bool reverseMatch = bodyMatchRev && matMatchRev && shapeMatchRev;
|
|
125
|
+
|
|
126
|
+
if (forwardMatch || reverseMatch) {
|
|
127
|
+
if (rule.priority > bestPriority) {
|
|
128
|
+
bestPriority = rule.priority;
|
|
129
|
+
bestRule = &rule;
|
|
130
|
+
bestIndex = static_cast<std::uint32_t>(i);
|
|
131
|
+
bestMatchedForward = forwardMatch;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (bestRule != nullptr) {
|
|
137
|
+
outProps.ruleMatched = true;
|
|
138
|
+
outProps.matchedRuleIndex = bestIndex;
|
|
139
|
+
|
|
140
|
+
if (!bestRule->enabled) {
|
|
141
|
+
outProps.enabled = false;
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Apply friction rule
|
|
146
|
+
if (bestRule->friction >= 0.0) {
|
|
147
|
+
outProps.friction = bestRule->friction;
|
|
148
|
+
} else {
|
|
149
|
+
outProps.friction = combineMaterialProperty(
|
|
150
|
+
defaultFrictionA, defaultFrictionB, bestRule->frictionCombine);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Apply restitution rule
|
|
154
|
+
if (bestRule->restitution >= 0.0) {
|
|
155
|
+
outProps.restitution = bestRule->restitution;
|
|
156
|
+
} else {
|
|
157
|
+
outProps.restitution = combineMaterialProperty(
|
|
158
|
+
defaultRestitutionA, defaultRestitutionB, bestRule->restitutionCombine);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Apply rolling resistance rule
|
|
162
|
+
if (bestRule->rollingResistance >= 0.0) {
|
|
163
|
+
outProps.rollingResistance = bestRule->rollingResistance;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Apply surface velocity rule override
|
|
167
|
+
if (bestRule->hasSurfaceVelocity) {
|
|
168
|
+
SurfaceVec3 ruleVel = bestRule->surfaceVelocity.linear;
|
|
169
|
+
if (bestRule->surfaceVelocity.space == SurfaceVelocitySpace::Local) {
|
|
170
|
+
const SurfaceQuat& refOri = bestMatchedForward ? orientationA : orientationB;
|
|
171
|
+
ruleVel = rotateByQuat(refOri, ruleVel);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (bestMatchedForward) {
|
|
175
|
+
outProps.relativeSurfaceVelocity = ruleVel;
|
|
176
|
+
} else {
|
|
177
|
+
// Reverse direction if rule defined pair in opposite order
|
|
178
|
+
outProps.relativeSurfaceVelocity = scaleVec3(ruleVel, -1.0);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
void computeTangentialFrictionBias(
|
|
187
|
+
const SurfaceVec3& relativeSurfaceVelocity,
|
|
188
|
+
const SurfaceVec3& normal,
|
|
189
|
+
const SurfaceVec3& tangent1,
|
|
190
|
+
const SurfaceVec3& tangent2,
|
|
191
|
+
double& biasTangent1,
|
|
192
|
+
double& biasTangent2) {
|
|
193
|
+
|
|
194
|
+
// Project relative surface velocity onto tangent plane: v_tan = v - n * (v . n)
|
|
195
|
+
const double normalComp = dotVec3(relativeSurfaceVelocity, normal);
|
|
196
|
+
const SurfaceVec3 tangentSurfaceVel = subVec3(relativeSurfaceVelocity, scaleVec3(normal, normalComp));
|
|
197
|
+
|
|
198
|
+
biasTangent1 = dotVec3(tangentSurfaceVel, tangent1);
|
|
199
|
+
biasTangent2 = dotVec3(tangentSurfaceVel, tangent2);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
void solveTangentialFrictionRow(
|
|
203
|
+
const SurfaceVec3& postRelativeVelocity,
|
|
204
|
+
const SurfaceVec3& normal,
|
|
205
|
+
const SurfaceVec3& tangent1,
|
|
206
|
+
const SurfaceVec3& tangent2,
|
|
207
|
+
double tangentMass1,
|
|
208
|
+
double tangentMass2,
|
|
209
|
+
double friction,
|
|
210
|
+
double normalTotal,
|
|
211
|
+
double biasTangent1,
|
|
212
|
+
double biasTangent2,
|
|
213
|
+
double& accumulatedTangent1,
|
|
214
|
+
double& accumulatedTangent2,
|
|
215
|
+
double& impulseDelta1,
|
|
216
|
+
double& impulseDelta2) {
|
|
217
|
+
|
|
218
|
+
const double old1 = accumulatedTangent1;
|
|
219
|
+
const double old2 = accumulatedTangent2;
|
|
220
|
+
|
|
221
|
+
// Tangential relative velocity
|
|
222
|
+
const double postNormalVelocity = dotVec3(postRelativeVelocity, normal);
|
|
223
|
+
const SurfaceVec3 tangent = subVec3(postRelativeVelocity, scaleVec3(normal, postNormalVelocity));
|
|
224
|
+
|
|
225
|
+
// Tangential slip velocity relative to conveyor bias
|
|
226
|
+
const double relTan1 = dotVec3(tangent, tangent1) - biasTangent1;
|
|
227
|
+
const double relTan2 = dotVec3(tangent, tangent2) - biasTangent2;
|
|
228
|
+
|
|
229
|
+
double total1 = old1 + (tangentMass1 > 0.0 ? -relTan1 / tangentMass1 : 0.0);
|
|
230
|
+
double total2 = old2 + (tangentMass2 > 0.0 ? -relTan2 / tangentMass2 : 0.0);
|
|
231
|
+
|
|
232
|
+
const double tangentLimit = friction * normalTotal;
|
|
233
|
+
const double tangentLength = solverSqrt(total1 * total1 + total2 * total2);
|
|
234
|
+
|
|
235
|
+
if (tangentLength > tangentLimit && tangentLength > 1e-18) {
|
|
236
|
+
const double scale = tangentLimit / tangentLength;
|
|
237
|
+
total1 *= scale;
|
|
238
|
+
total2 *= scale;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
accumulatedTangent1 = total1;
|
|
242
|
+
accumulatedTangent2 = total2;
|
|
243
|
+
impulseDelta1 = total1 - old1;
|
|
244
|
+
impulseDelta2 = total2 - old2;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
} // namespace rundot::kinetix::physics
|
|
248
|
+
|
|
249
|
+
extern "C" {
|
|
250
|
+
|
|
251
|
+
std::uint32_t rundot_kinetix_physics_surface_velocity_abi_version() {
|
|
252
|
+
return rundot::kinetix::physics::kSurfaceVelocityAbiVersion;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
std::int32_t rundot_kinetix_physics_evaluate_material_rule(
|
|
256
|
+
const double* ruleBuffer,
|
|
257
|
+
std::uint32_t ruleCount,
|
|
258
|
+
std::uint64_t bodyKeyA,
|
|
259
|
+
std::uint64_t bodyKeyB,
|
|
260
|
+
double defaultFrictionA,
|
|
261
|
+
double defaultFrictionB,
|
|
262
|
+
double defaultRestitutionA,
|
|
263
|
+
double defaultRestitutionB,
|
|
264
|
+
double* outputProps) {
|
|
265
|
+
|
|
266
|
+
using namespace rundot::kinetix::physics;
|
|
267
|
+
if (outputProps == nullptr) return -1;
|
|
268
|
+
|
|
269
|
+
std::vector<ContactMaterialRule> rules;
|
|
270
|
+
rules.reserve(ruleCount);
|
|
271
|
+
|
|
272
|
+
for (std::uint32_t i = 0; i < ruleCount; ++i) {
|
|
273
|
+
const double* r = ruleBuffer + (i * kContactMaterialRuleStride);
|
|
274
|
+
ContactMaterialRule rule;
|
|
275
|
+
rule.bodyKeyA = static_cast<std::uint64_t>(r[0]);
|
|
276
|
+
rule.bodyKeyB = static_cast<std::uint64_t>(r[1]);
|
|
277
|
+
rule.materialA = static_cast<std::uint32_t>(r[2]);
|
|
278
|
+
rule.materialB = static_cast<std::uint32_t>(r[3]);
|
|
279
|
+
rule.shapeIndexA = static_cast<std::int32_t>(r[4]);
|
|
280
|
+
rule.shapeIndexB = static_cast<std::int32_t>(r[5]);
|
|
281
|
+
rule.friction = r[6];
|
|
282
|
+
rule.restitution = r[7];
|
|
283
|
+
rule.rollingResistance = r[8];
|
|
284
|
+
rule.frictionCombine = static_cast<MaterialCombineMode>(static_cast<std::uint32_t>(r[9]));
|
|
285
|
+
rule.restitutionCombine = static_cast<MaterialCombineMode>(static_cast<std::uint32_t>(r[10]));
|
|
286
|
+
rule.hasSurfaceVelocity = r[11] != 0.0;
|
|
287
|
+
rule.surfaceVelocity.linear = {r[12], r[13], r[14]};
|
|
288
|
+
rule.surfaceVelocity.angular = {r[15], r[16], r[17]};
|
|
289
|
+
rule.surfaceVelocity.space = static_cast<SurfaceVelocitySpace>(static_cast<std::uint32_t>(r[18]));
|
|
290
|
+
rule.surfaceVelocity.enabled = true;
|
|
291
|
+
rule.enabled = r[19] >= 0.0;
|
|
292
|
+
rule.priority = static_cast<std::int32_t>(r[19]);
|
|
293
|
+
rules.push_back(rule);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
ContactSurfaceProperties props;
|
|
297
|
+
SurfaceVelocityConfig surfA{};
|
|
298
|
+
SurfaceVelocityConfig surfB{};
|
|
299
|
+
SurfaceQuat oriA{};
|
|
300
|
+
SurfaceQuat oriB{};
|
|
301
|
+
SurfaceVec3 pt{};
|
|
302
|
+
SurfaceVec3 cA{};
|
|
303
|
+
SurfaceVec3 cB{};
|
|
304
|
+
|
|
305
|
+
evaluateContactMaterialRules(
|
|
306
|
+
rules, bodyKeyA, bodyKeyB, 0, 0, -1, -1,
|
|
307
|
+
surfA, surfB, oriA, oriB, pt, cA, cB,
|
|
308
|
+
defaultFrictionA, defaultFrictionB,
|
|
309
|
+
defaultRestitutionA, defaultRestitutionB,
|
|
310
|
+
0.0, 0.0, props);
|
|
311
|
+
|
|
312
|
+
outputProps[0] = props.friction;
|
|
313
|
+
outputProps[1] = props.restitution;
|
|
314
|
+
outputProps[2] = props.rollingResistance;
|
|
315
|
+
outputProps[3] = props.relativeSurfaceVelocity.x;
|
|
316
|
+
outputProps[4] = props.relativeSurfaceVelocity.y;
|
|
317
|
+
outputProps[5] = props.relativeSurfaceVelocity.z;
|
|
318
|
+
outputProps[6] = props.enabled ? 1.0 : 0.0;
|
|
319
|
+
outputProps[7] = props.ruleMatched ? 1.0 : 0.0;
|
|
320
|
+
outputProps[8] = static_cast<double>(props.matchedRuleIndex);
|
|
321
|
+
outputProps[9] = 0.0;
|
|
322
|
+
|
|
323
|
+
return 0;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
std::int32_t rundot_kinetix_physics_solve_conveyor_friction(
|
|
327
|
+
double relVelX, double relVelY, double relVelZ,
|
|
328
|
+
double normalX, double normalY, double normalZ,
|
|
329
|
+
double tangentMass1, double tangentMass2,
|
|
330
|
+
double friction, double normalTotal,
|
|
331
|
+
double bias1, double bias2,
|
|
332
|
+
double inAccum1, double inAccum2,
|
|
333
|
+
double* outAccum1, double* outAccum2,
|
|
334
|
+
double* outDelta1, double* outDelta2) {
|
|
335
|
+
|
|
336
|
+
using namespace rundot::kinetix::physics;
|
|
337
|
+
if (outAccum1 == nullptr || outAccum2 == nullptr || outDelta1 == nullptr || outDelta2 == nullptr) {
|
|
338
|
+
return -1;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
const SurfaceVec3 relVel{relVelX, relVelY, relVelZ};
|
|
342
|
+
const SurfaceVec3 normal{normalX, normalY, normalZ};
|
|
343
|
+
SurfaceVec3 t1;
|
|
344
|
+
SurfaceVec3 t2;
|
|
345
|
+
contactTangentBasis(normal, t1, t2);
|
|
346
|
+
|
|
347
|
+
double acc1 = inAccum1;
|
|
348
|
+
double acc2 = inAccum2;
|
|
349
|
+
double d1 = 0.0;
|
|
350
|
+
double d2 = 0.0;
|
|
351
|
+
|
|
352
|
+
solveTangentialFrictionRow(
|
|
353
|
+
relVel, normal, t1, t2,
|
|
354
|
+
tangentMass1, tangentMass2,
|
|
355
|
+
friction, normalTotal,
|
|
356
|
+
bias1, bias2,
|
|
357
|
+
acc1, acc2, d1, d2);
|
|
358
|
+
|
|
359
|
+
*outAccum1 = acc1;
|
|
360
|
+
*outAccum2 = acc2;
|
|
361
|
+
*outDelta1 = d1;
|
|
362
|
+
*outDelta2 = d2;
|
|
363
|
+
return 0;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <algorithm>
|
|
4
|
+
#include <array>
|
|
5
|
+
#include <cmath>
|
|
6
|
+
#include <cstdint>
|
|
7
|
+
#include <limits>
|
|
8
|
+
#include <span>
|
|
9
|
+
#include <string_view>
|
|
10
|
+
|
|
11
|
+
#include "physics.hpp"
|
|
12
|
+
|
|
13
|
+
namespace rundot::kinetix::physics {
|
|
14
|
+
|
|
15
|
+
constexpr std::uint32_t kSurfaceVelocityAbiVersion = 1;
|
|
16
|
+
constexpr std::uint32_t kSurfaceVelocityRecordStride = 8;
|
|
17
|
+
constexpr std::uint32_t kContactMaterialRuleStride = 20;
|
|
18
|
+
constexpr std::uint32_t kContactSurfacePropertiesStride = 10;
|
|
19
|
+
|
|
20
|
+
// Deterministic vector for surface calculations (double only)
|
|
21
|
+
struct SurfaceVec3 {
|
|
22
|
+
double x = 0.0;
|
|
23
|
+
double y = 0.0;
|
|
24
|
+
double z = 0.0;
|
|
25
|
+
|
|
26
|
+
constexpr bool operator==(const SurfaceVec3& other) const = default;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// Deterministic quaternion
|
|
30
|
+
struct SurfaceQuat {
|
|
31
|
+
double x = 0.0;
|
|
32
|
+
double y = 0.0;
|
|
33
|
+
double z = 0.0;
|
|
34
|
+
double w = 1.0;
|
|
35
|
+
|
|
36
|
+
constexpr bool operator==(const SurfaceQuat& other) const = default;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// Pure deterministic math functions
|
|
40
|
+
inline double solverSqrt(double value) {
|
|
41
|
+
if (value <= 0.0) return 0.0;
|
|
42
|
+
return std::sqrt(value);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
inline SurfaceVec3 addVec3(const SurfaceVec3& a, const SurfaceVec3& b) {
|
|
46
|
+
return {a.x + b.x, a.y + b.y, a.z + b.z};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
inline SurfaceVec3 subVec3(const SurfaceVec3& a, const SurfaceVec3& b) {
|
|
50
|
+
return {a.x - b.x, a.y - b.y, a.z - b.z};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
inline SurfaceVec3 scaleVec3(const SurfaceVec3& v, double s) {
|
|
54
|
+
return {v.x * s, v.y * s, v.z * s};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
inline double dotVec3(const SurfaceVec3& a, const SurfaceVec3& b) {
|
|
58
|
+
return a.x * b.x + a.y * b.y + a.z * b.z;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
inline SurfaceVec3 crossVec3(const SurfaceVec3& a, const SurfaceVec3& b) {
|
|
62
|
+
return {
|
|
63
|
+
a.y * b.z - a.z * b.y,
|
|
64
|
+
a.z * b.x - a.x * b.z,
|
|
65
|
+
a.x * b.y - a.y * b.x,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
inline double lengthSquaredVec3(const SurfaceVec3& v) {
|
|
70
|
+
return dotVec3(v, v);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
inline double lengthVec3(const SurfaceVec3& v) {
|
|
74
|
+
return solverSqrt(lengthSquaredVec3(v));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
inline SurfaceVec3 normalizeVec3(const SurfaceVec3& v) {
|
|
78
|
+
const double len = lengthVec3(v);
|
|
79
|
+
if (len <= 1e-15) return {0.0, 0.0, 0.0};
|
|
80
|
+
return scaleVec3(v, 1.0 / len);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
inline SurfaceVec3 rotateByQuat(const SurfaceQuat& q, const SurfaceVec3& v) {
|
|
84
|
+
const SurfaceVec3 u{q.x, q.y, q.z};
|
|
85
|
+
const SurfaceVec3 uv = crossVec3(u, v);
|
|
86
|
+
const SurfaceVec3 uuv = crossVec3(u, uv);
|
|
87
|
+
return addVec3(v, addVec3(scaleVec3(uv, 2.0 * q.w), scaleVec3(uuv, 2.0)));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
inline SurfaceVec3 invRotateByQuat(const SurfaceQuat& q, const SurfaceVec3& v) {
|
|
91
|
+
const SurfaceQuat conj{-q.x, -q.y, -q.z, q.w};
|
|
92
|
+
return rotateByQuat(conj, v);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Orthonormal tangent basis matching physics.cpp
|
|
96
|
+
inline void contactTangentBasis(const SurfaceVec3& normal, SurfaceVec3& first, SurfaceVec3& second) {
|
|
97
|
+
const SurfaceVec3 reference = std::abs(normal.x) < 0.5773502691896258
|
|
98
|
+
? SurfaceVec3{1.0, 0.0, 0.0}
|
|
99
|
+
: SurfaceVec3{0.0, 1.0, 0.0};
|
|
100
|
+
first = crossVec3(normal, reference);
|
|
101
|
+
const double firstLength = solverSqrt(dotVec3(first, first));
|
|
102
|
+
first = firstLength <= 1e-18 ? SurfaceVec3{0.0, 0.0, 1.0} : scaleVec3(first, 1.0 / firstLength);
|
|
103
|
+
second = crossVec3(normal, first);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
enum class SurfaceVelocitySpace : std::uint32_t {
|
|
107
|
+
World = 0,
|
|
108
|
+
Local = 1,
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
enum class MaterialCombineMode : std::uint32_t {
|
|
112
|
+
Average = 0, // (a + b) * 0.5
|
|
113
|
+
Minimum = 1, // min(a, b)
|
|
114
|
+
Multiply = 2, // sqrt(max(0, a * b))
|
|
115
|
+
Maximum = 3, // max(a, b)
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
struct SurfaceVelocityConfig {
|
|
119
|
+
SurfaceVec3 linear{};
|
|
120
|
+
SurfaceVec3 angular{};
|
|
121
|
+
SurfaceVelocitySpace space = SurfaceVelocitySpace::World;
|
|
122
|
+
bool enabled = true;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
struct ContactMaterialRule {
|
|
126
|
+
std::uint64_t bodyKeyA = 0; // 0 = wildcard / any
|
|
127
|
+
std::uint64_t bodyKeyB = 0; // 0 = wildcard / any
|
|
128
|
+
std::uint32_t materialA = 0; // 0 = wildcard / any
|
|
129
|
+
std::uint32_t materialB = 0; // 0 = wildcard / any
|
|
130
|
+
std::int32_t shapeIndexA = -1; // -1 = any shape
|
|
131
|
+
std::int32_t shapeIndexB = -1; // -1 = any shape
|
|
132
|
+
|
|
133
|
+
double friction = -1.0; // < 0 means no override
|
|
134
|
+
double restitution = -1.0; // < 0 means no override
|
|
135
|
+
double rollingResistance = -1.0; // < 0 means no override
|
|
136
|
+
|
|
137
|
+
MaterialCombineMode frictionCombine = MaterialCombineMode::Multiply;
|
|
138
|
+
MaterialCombineMode restitutionCombine = MaterialCombineMode::Maximum;
|
|
139
|
+
|
|
140
|
+
SurfaceVelocityConfig surfaceVelocity{};
|
|
141
|
+
bool hasSurfaceVelocity = false;
|
|
142
|
+
|
|
143
|
+
bool enabled = true; // if false, filters contact
|
|
144
|
+
std::int32_t priority = 0; // higher priority rules take precedence
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
struct ContactSurfaceProperties {
|
|
148
|
+
double friction = 0.6;
|
|
149
|
+
double restitution = 0.0;
|
|
150
|
+
double rollingResistance = 0.0;
|
|
151
|
+
SurfaceVec3 relativeSurfaceVelocity{}; // in world space at contact point
|
|
152
|
+
bool enabled = true;
|
|
153
|
+
bool ruleMatched = false;
|
|
154
|
+
std::uint32_t matchedRuleIndex = 0;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// Computes combined property value based on combine mode
|
|
158
|
+
double combineMaterialProperty(double a, double b, MaterialCombineMode mode);
|
|
159
|
+
|
|
160
|
+
// Computes point velocity on a surface given its linear and angular velocity
|
|
161
|
+
SurfaceVec3 computeSurfacePointVelocity(
|
|
162
|
+
const SurfaceVelocityConfig& config,
|
|
163
|
+
const SurfaceQuat& orientation,
|
|
164
|
+
const SurfaceVec3& point,
|
|
165
|
+
const SurfaceVec3& center);
|
|
166
|
+
|
|
167
|
+
// Evaluates declarative contact material rules for a contact pair
|
|
168
|
+
bool evaluateContactMaterialRules(
|
|
169
|
+
std::span<const ContactMaterialRule> rules,
|
|
170
|
+
std::uint64_t bodyKeyA,
|
|
171
|
+
std::uint64_t bodyKeyB,
|
|
172
|
+
std::uint32_t materialA,
|
|
173
|
+
std::uint32_t materialB,
|
|
174
|
+
std::int32_t shapeA,
|
|
175
|
+
std::int32_t shapeB,
|
|
176
|
+
const SurfaceVelocityConfig& surfA,
|
|
177
|
+
const SurfaceVelocityConfig& surfB,
|
|
178
|
+
const SurfaceQuat& orientationA,
|
|
179
|
+
const SurfaceQuat& orientationB,
|
|
180
|
+
const SurfaceVec3& contactPoint,
|
|
181
|
+
const SurfaceVec3& centerA,
|
|
182
|
+
const SurfaceVec3& centerB,
|
|
183
|
+
double defaultFrictionA,
|
|
184
|
+
double defaultFrictionB,
|
|
185
|
+
double defaultRestitutionA,
|
|
186
|
+
double defaultRestitutionB,
|
|
187
|
+
double defaultRollingA,
|
|
188
|
+
double defaultRollingB,
|
|
189
|
+
ContactSurfaceProperties& outProps);
|
|
190
|
+
|
|
191
|
+
// Computes tangential friction bias along tangent basis vectors
|
|
192
|
+
void computeTangentialFrictionBias(
|
|
193
|
+
const SurfaceVec3& relativeSurfaceVelocity,
|
|
194
|
+
const SurfaceVec3& normal,
|
|
195
|
+
const SurfaceVec3& tangent1,
|
|
196
|
+
const SurfaceVec3& tangent2,
|
|
197
|
+
double& biasTangent1,
|
|
198
|
+
double& biasTangent2);
|
|
199
|
+
|
|
200
|
+
// Solves one iteration of tangential friction constraint with surface velocity bias
|
|
201
|
+
void solveTangentialFrictionRow(
|
|
202
|
+
const SurfaceVec3& postRelativeVelocity,
|
|
203
|
+
const SurfaceVec3& normal,
|
|
204
|
+
const SurfaceVec3& tangent1,
|
|
205
|
+
const SurfaceVec3& tangent2,
|
|
206
|
+
double tangentMass1,
|
|
207
|
+
double tangentMass2,
|
|
208
|
+
double friction,
|
|
209
|
+
double normalTotal,
|
|
210
|
+
double biasTangent1,
|
|
211
|
+
double biasTangent2,
|
|
212
|
+
double& accumulatedTangent1,
|
|
213
|
+
double& accumulatedTangent2,
|
|
214
|
+
double& impulseDelta1,
|
|
215
|
+
double& impulseDelta2);
|
|
216
|
+
|
|
217
|
+
} // namespace rundot::kinetix::physics
|
|
218
|
+
|
|
219
|
+
// C ABI exports for WASM interop
|
|
220
|
+
extern "C" {
|
|
221
|
+
std::uint32_t rundot_kinetix_physics_surface_velocity_abi_version();
|
|
222
|
+
|
|
223
|
+
std::int32_t rundot_kinetix_physics_evaluate_material_rule(
|
|
224
|
+
const double* ruleBuffer,
|
|
225
|
+
std::uint32_t ruleCount,
|
|
226
|
+
std::uint64_t bodyKeyA,
|
|
227
|
+
std::uint64_t bodyKeyB,
|
|
228
|
+
double defaultFrictionA,
|
|
229
|
+
double defaultFrictionB,
|
|
230
|
+
double defaultRestitutionA,
|
|
231
|
+
double defaultRestitutionB,
|
|
232
|
+
double* outputProps);
|
|
233
|
+
|
|
234
|
+
std::int32_t rundot_kinetix_physics_solve_conveyor_friction(
|
|
235
|
+
double relVelX, double relVelY, double relVelZ,
|
|
236
|
+
double normalX, double normalY, double normalZ,
|
|
237
|
+
double tangentMass1, double tangentMass2,
|
|
238
|
+
double friction, double normalTotal,
|
|
239
|
+
double bias1, double bias2,
|
|
240
|
+
double inAccum1, double inAccum2,
|
|
241
|
+
double* outAccum1, double* outAccum2,
|
|
242
|
+
double* outDelta1, double* outDelta2);
|
|
243
|
+
}
|