@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,889 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <array>
|
|
4
|
+
#include <cmath>
|
|
5
|
+
#include <cstddef>
|
|
6
|
+
#include <cstdint>
|
|
7
|
+
#include <cstring>
|
|
8
|
+
#include <limits>
|
|
9
|
+
#include <span>
|
|
10
|
+
|
|
11
|
+
#include "physics.hpp"
|
|
12
|
+
|
|
13
|
+
namespace rundot::kinetix::physics {
|
|
14
|
+
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
// Capability D18: 2D Ropes, Cloth, and Particles (Planar Deformables)
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
|
|
19
|
+
constexpr std::uint32_t kPlanarDeformableAbiVersion = 1;
|
|
20
|
+
constexpr std::uint32_t kPlanarDeformableSnapshotVersion = 1;
|
|
21
|
+
|
|
22
|
+
// Strides in double precision units (for C ABI / Flat Buffer serialization)
|
|
23
|
+
constexpr std::uint32_t kPlanarNodeStride = 12;
|
|
24
|
+
// Node layout (12 doubles):
|
|
25
|
+
// [0..1] position (x, y)
|
|
26
|
+
// [2..3] previousPosition (px, py)
|
|
27
|
+
// [4..5] velocity (vx, vy)
|
|
28
|
+
// [6..7] force (fx, fy)
|
|
29
|
+
// [8] mass
|
|
30
|
+
// [9] inverseMass
|
|
31
|
+
// [10] radius
|
|
32
|
+
// [11] flags
|
|
33
|
+
|
|
34
|
+
constexpr std::uint32_t kPlanarSegmentStride = 6;
|
|
35
|
+
// Segment layout (6 doubles):
|
|
36
|
+
// [0..1] nodeA, nodeB
|
|
37
|
+
// [2] restLength
|
|
38
|
+
// [3] radius
|
|
39
|
+
// [4] tension
|
|
40
|
+
// [5] broken
|
|
41
|
+
|
|
42
|
+
constexpr std::uint32_t kPlanarFaceStride = 6;
|
|
43
|
+
// Face layout (6 doubles):
|
|
44
|
+
// [0..2] nodeA, nodeB, nodeC
|
|
45
|
+
// [3] restArea
|
|
46
|
+
// [4] currentArea
|
|
47
|
+
// [5] broken
|
|
48
|
+
|
|
49
|
+
constexpr std::uint32_t kPlanarDistanceConstraintStride = 8;
|
|
50
|
+
// Distance constraint layout (8 doubles):
|
|
51
|
+
// [0..1] nodeA, nodeB
|
|
52
|
+
// [2] restLength
|
|
53
|
+
// [3] stiffness
|
|
54
|
+
// [4] damping
|
|
55
|
+
// [5] tension
|
|
56
|
+
// [6] breakThreshold
|
|
57
|
+
// [7] broken
|
|
58
|
+
|
|
59
|
+
constexpr std::uint32_t kPlanarBendConstraintStride = 8;
|
|
60
|
+
// Bend constraint layout (8 doubles):
|
|
61
|
+
// [0..2] nodeA, nodeB (center), nodeC
|
|
62
|
+
// [3] restAngle
|
|
63
|
+
// [4] stiffness
|
|
64
|
+
// [5] bendingMoment
|
|
65
|
+
// [6] breakThreshold
|
|
66
|
+
// [7] broken
|
|
67
|
+
|
|
68
|
+
constexpr std::uint32_t kPlanarShearConstraintStride = 8;
|
|
69
|
+
// Shear constraint layout (8 doubles):
|
|
70
|
+
// [0..1] nodeA, nodeB
|
|
71
|
+
// [2] restLength
|
|
72
|
+
// [3] stiffness
|
|
73
|
+
// [4] damping
|
|
74
|
+
// [5] shearForce
|
|
75
|
+
// [6] breakThreshold
|
|
76
|
+
// [7] broken
|
|
77
|
+
|
|
78
|
+
constexpr std::uint32_t kPlanarAreaConstraintStride = 8;
|
|
79
|
+
// Area constraint layout (8 doubles):
|
|
80
|
+
// [0..2] nodeA, nodeB, nodeC
|
|
81
|
+
// [3] restArea
|
|
82
|
+
// [4] currentArea
|
|
83
|
+
// [5] stiffness
|
|
84
|
+
// [6] pressure
|
|
85
|
+
// [7] broken
|
|
86
|
+
|
|
87
|
+
constexpr std::uint32_t kPlanarAnchorStride = 10;
|
|
88
|
+
// Anchor layout (10 doubles):
|
|
89
|
+
// [0] nodeIndex
|
|
90
|
+
// [1] bodyIndex (-1 for fixed world point, >= 0 for rigid body)
|
|
91
|
+
// [2..3] localAnchor (x, y)
|
|
92
|
+
// [4..5] worldAnchor (x, y)
|
|
93
|
+
// [6] stiffness
|
|
94
|
+
// [7] reactionForce
|
|
95
|
+
// [8] active
|
|
96
|
+
// [9] reserved
|
|
97
|
+
|
|
98
|
+
constexpr std::uint32_t kPlanarParticleStride = 10;
|
|
99
|
+
// Particle layout (10 doubles):
|
|
100
|
+
// [0..1] position (x, y)
|
|
101
|
+
// [2..3] velocity (vx, vy)
|
|
102
|
+
// [4] radius
|
|
103
|
+
// [5] mass
|
|
104
|
+
// [6] inverseMass
|
|
105
|
+
// [7] age
|
|
106
|
+
// [8] lifetime
|
|
107
|
+
// [9] active
|
|
108
|
+
|
|
109
|
+
constexpr std::uint32_t kPlanarEmitterStride = 14;
|
|
110
|
+
// Emitter layout (14 doubles):
|
|
111
|
+
// [0] shape (0=Point, 1=Line, 2=Box, 3=Circle)
|
|
112
|
+
// [1..2] position (x, y)
|
|
113
|
+
// [3..4] size (sx, sy)
|
|
114
|
+
// [5..6] speedRange (minSpeed, maxSpeed)
|
|
115
|
+
// [7..8] angleRange (minAngle, maxAngle)
|
|
116
|
+
// [9..10] lifetimeRange (minLife, maxLife)
|
|
117
|
+
// [11] rate (particles / sec)
|
|
118
|
+
// [12] accumulator
|
|
119
|
+
// [13] enabled
|
|
120
|
+
|
|
121
|
+
constexpr std::uint32_t kPlanarParamsStride = 18;
|
|
122
|
+
// Params layout (18 doubles):
|
|
123
|
+
// [0..1] gravity (gx, gy)
|
|
124
|
+
// [2] damping
|
|
125
|
+
// [3] airDensity
|
|
126
|
+
// [4..5] wind (wx, wy)
|
|
127
|
+
// [6] dragCoefficient
|
|
128
|
+
// [7] liftCoefficient
|
|
129
|
+
// [8] groundEnabled
|
|
130
|
+
// [9] groundY
|
|
131
|
+
// [10] groundFriction
|
|
132
|
+
// [11] groundRestitution
|
|
133
|
+
// [12] solverIterations
|
|
134
|
+
// [13] substeps
|
|
135
|
+
// [14] particleCollisionEnabled
|
|
136
|
+
// [15] particleRestitution
|
|
137
|
+
// [16] particleFriction
|
|
138
|
+
// [17] breakThresholdDefault
|
|
139
|
+
|
|
140
|
+
constexpr std::uint32_t kPlanarRigidBodyStride = 18;
|
|
141
|
+
// Rigid body layout (18 doubles):
|
|
142
|
+
// [0] id
|
|
143
|
+
// [1] shape (1=Circle, 2=Box, 3=Capsule, 4=Polygon, 5=Ground)
|
|
144
|
+
// [2] isDynamic (1.0 or 0.0)
|
|
145
|
+
// [3..4] position (x, y)
|
|
146
|
+
// [5] angle
|
|
147
|
+
// [6..7] velocity (vx, vy)
|
|
148
|
+
// [8] angularVelocity
|
|
149
|
+
// [9] mass
|
|
150
|
+
// [10] inertia
|
|
151
|
+
// [11..12] halfExtents (hx, hy)
|
|
152
|
+
// [13] radius
|
|
153
|
+
// [14] friction
|
|
154
|
+
// [15] restitution
|
|
155
|
+
// [16..17] reserved
|
|
156
|
+
|
|
157
|
+
constexpr std::uint32_t kPlanarRaycastQueryStride = 6;
|
|
158
|
+
constexpr std::uint32_t kPlanarRaycastHitStride = 10;
|
|
159
|
+
constexpr std::uint32_t kPlanarClosestPointQueryStride = 4;
|
|
160
|
+
constexpr std::uint32_t kPlanarClosestPointHitStride = 8;
|
|
161
|
+
constexpr std::uint32_t kPlanarOverlapQueryStride = 6;
|
|
162
|
+
constexpr std::uint32_t kPlanarOverlapHitStride = 4;
|
|
163
|
+
|
|
164
|
+
// Capacities (Pre-allocated, fixed deterministic storage, zero heap allocation in step path)
|
|
165
|
+
constexpr std::uint32_t kPlanarMaxNodes = 1024;
|
|
166
|
+
constexpr std::uint32_t kPlanarMaxSegments = 2048;
|
|
167
|
+
constexpr std::uint32_t kPlanarMaxFaces = 2048;
|
|
168
|
+
constexpr std::uint32_t kPlanarMaxDistanceConstraints = 4096;
|
|
169
|
+
constexpr std::uint32_t kPlanarMaxBendConstraints = 2048;
|
|
170
|
+
constexpr std::uint32_t kPlanarMaxShearConstraints = 2048;
|
|
171
|
+
constexpr std::uint32_t kPlanarMaxAreaConstraints = 1024;
|
|
172
|
+
constexpr std::uint32_t kPlanarMaxAnchors = 128;
|
|
173
|
+
constexpr std::uint32_t kPlanarMaxParticles = 2048;
|
|
174
|
+
constexpr std::uint32_t kPlanarMaxEmitters = 32;
|
|
175
|
+
constexpr std::uint32_t kPlanarMaxBreakEvents = 128;
|
|
176
|
+
|
|
177
|
+
// ---------------------------------------------------------------------------
|
|
178
|
+
// Enums
|
|
179
|
+
// ---------------------------------------------------------------------------
|
|
180
|
+
|
|
181
|
+
enum class PlanarStatus : std::int32_t {
|
|
182
|
+
Success = 0,
|
|
183
|
+
NoHit = 1,
|
|
184
|
+
InvalidInput = -1,
|
|
185
|
+
InvalidCapacity = -2,
|
|
186
|
+
InvalidParams = -3,
|
|
187
|
+
BufferOverflow = -4,
|
|
188
|
+
SnapshotCorrupted = -5,
|
|
189
|
+
SnapshotVersionMismatch = -6,
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
enum class PlanarBreakReason : std::uint32_t {
|
|
193
|
+
None = 0,
|
|
194
|
+
TensionExceeded = 1,
|
|
195
|
+
BendTorqueExceeded = 2,
|
|
196
|
+
ShearExceeded = 3,
|
|
197
|
+
AreaExceeded = 4,
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
enum class PlanarElementKind : std::uint32_t {
|
|
201
|
+
Node = 0,
|
|
202
|
+
Segment = 1,
|
|
203
|
+
Face = 2,
|
|
204
|
+
Particle = 3,
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
enum class PlanarEmitterShape : std::uint32_t {
|
|
208
|
+
Point = 0,
|
|
209
|
+
Line = 1,
|
|
210
|
+
Box = 2,
|
|
211
|
+
Circle = 3,
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
enum class PlanarRigidShapeKind : std::uint32_t {
|
|
215
|
+
Circle = 1,
|
|
216
|
+
Box = 2,
|
|
217
|
+
Capsule = 3,
|
|
218
|
+
Polygon = 4,
|
|
219
|
+
Ground = 5,
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
enum class PlanarNodeFlags : std::uint32_t {
|
|
223
|
+
None = 0,
|
|
224
|
+
Pinned = 1 << 0,
|
|
225
|
+
Rope = 1 << 1,
|
|
226
|
+
Cloth = 1 << 2,
|
|
227
|
+
Particle = 1 << 3,
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
// ---------------------------------------------------------------------------
|
|
231
|
+
// Deterministic Geometric Types (Double Precision Only)
|
|
232
|
+
// ---------------------------------------------------------------------------
|
|
233
|
+
|
|
234
|
+
struct PlanarVec2 {
|
|
235
|
+
double x = 0.0;
|
|
236
|
+
double y = 0.0;
|
|
237
|
+
|
|
238
|
+
constexpr bool operator==(const PlanarVec2& other) const = default;
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
struct PlanarMat2 {
|
|
242
|
+
double m[2][2]{{1.0, 0.0}, {0.0, 1.0}};
|
|
243
|
+
|
|
244
|
+
static constexpr PlanarMat2 identity() {
|
|
245
|
+
return PlanarMat2{{{1.0, 0.0}, {0.0, 1.0}}};
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
static constexpr PlanarMat2 zero() {
|
|
249
|
+
return PlanarMat2{{{0.0, 0.0}, {0.0, 0.0}}};
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
struct PlanarAABB {
|
|
254
|
+
PlanarVec2 min{0.0, 0.0};
|
|
255
|
+
PlanarVec2 max{0.0, 0.0};
|
|
256
|
+
|
|
257
|
+
constexpr bool contains(const PlanarVec2& p) const {
|
|
258
|
+
return p.x >= min.x && p.x <= max.x && p.y >= min.y && p.y <= max.y;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
constexpr bool intersects(const PlanarAABB& o) const {
|
|
262
|
+
return min.x <= o.max.x && max.x >= o.min.x &&
|
|
263
|
+
min.y <= o.max.y && max.y >= o.min.y;
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
struct PlanarMassProperties {
|
|
268
|
+
double totalMass = 0.0;
|
|
269
|
+
PlanarVec2 centerOfMass{0.0, 0.0};
|
|
270
|
+
double momentOfInertia = 0.0; // Polar moment of inertia about center of mass
|
|
271
|
+
PlanarAABB boundingBox{};
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
// ---------------------------------------------------------------------------
|
|
275
|
+
// Simulation Element Structures
|
|
276
|
+
// ---------------------------------------------------------------------------
|
|
277
|
+
|
|
278
|
+
struct PlanarDeformableNode {
|
|
279
|
+
PlanarVec2 position{};
|
|
280
|
+
PlanarVec2 previousPosition{};
|
|
281
|
+
PlanarVec2 velocity{};
|
|
282
|
+
PlanarVec2 force{};
|
|
283
|
+
double mass = 1.0;
|
|
284
|
+
double inverseMass = 1.0; // 0.0 = fixed / pinned
|
|
285
|
+
double radius = 0.05;
|
|
286
|
+
double damping = 0.005;
|
|
287
|
+
std::uint32_t flags = static_cast<std::uint32_t>(PlanarNodeFlags::None);
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
struct PlanarSegment {
|
|
291
|
+
std::uint32_t nodeA = 0;
|
|
292
|
+
std::uint32_t nodeB = 1;
|
|
293
|
+
double restLength = 1.0;
|
|
294
|
+
double radius = 0.05;
|
|
295
|
+
double tension = 0.0;
|
|
296
|
+
bool broken = false;
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
struct PlanarFace {
|
|
300
|
+
std::uint32_t nodeA = 0;
|
|
301
|
+
std::uint32_t nodeB = 1;
|
|
302
|
+
std::uint32_t nodeC = 2;
|
|
303
|
+
double restArea = 0.5;
|
|
304
|
+
double currentArea = 0.5;
|
|
305
|
+
PlanarVec2 normal{0.0, 1.0};
|
|
306
|
+
PlanarVec2 aerodynamicForce{0.0, 0.0};
|
|
307
|
+
bool broken = false;
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
struct PlanarDistanceConstraint {
|
|
311
|
+
std::uint32_t nodeA = 0;
|
|
312
|
+
std::uint32_t nodeB = 1;
|
|
313
|
+
double restLength = 1.0;
|
|
314
|
+
double stiffness = 1.0; // 0.0 .. 1.0
|
|
315
|
+
double damping = 0.01;
|
|
316
|
+
double tension = 0.0;
|
|
317
|
+
double breakThreshold = 0.0; // 0.0 = unbreakable
|
|
318
|
+
bool broken = false;
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
struct PlanarBendConstraint {
|
|
322
|
+
std::uint32_t nodeA = 0;
|
|
323
|
+
std::uint32_t nodeB = 1; // Pivot / center vertex
|
|
324
|
+
std::uint32_t nodeC = 2;
|
|
325
|
+
double restAngle = 3.14159265358979323846; // Rest angle in radians (pi for straight)
|
|
326
|
+
double stiffness = 0.5;
|
|
327
|
+
double currentAngle = 3.14159265358979323846;
|
|
328
|
+
double bendingMoment = 0.0;
|
|
329
|
+
double breakThreshold = 0.0;
|
|
330
|
+
bool broken = false;
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
struct PlanarShearConstraint {
|
|
334
|
+
std::uint32_t nodeA = 0;
|
|
335
|
+
std::uint32_t nodeB = 1;
|
|
336
|
+
double restLength = 1.4142135623730951;
|
|
337
|
+
double stiffness = 0.8;
|
|
338
|
+
double damping = 0.01;
|
|
339
|
+
double currentLength = 1.4142135623730951;
|
|
340
|
+
double shearForce = 0.0;
|
|
341
|
+
double breakThreshold = 0.0;
|
|
342
|
+
bool broken = false;
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
struct PlanarAreaConstraint {
|
|
346
|
+
std::uint32_t nodeA = 0;
|
|
347
|
+
std::uint32_t nodeB = 1;
|
|
348
|
+
std::uint32_t nodeC = 2;
|
|
349
|
+
double restArea = 0.5;
|
|
350
|
+
double currentArea = 0.5;
|
|
351
|
+
double stiffness = 0.8;
|
|
352
|
+
double pressure = 0.0;
|
|
353
|
+
double breakThreshold = 0.0;
|
|
354
|
+
bool broken = false;
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
struct PlanarAnchor {
|
|
358
|
+
std::uint32_t nodeIndex = 0;
|
|
359
|
+
std::int32_t bodyIndex = -1; // -1 for fixed world target, >= 0 for rigid body
|
|
360
|
+
PlanarVec2 localAnchor{0.0, 0.0};
|
|
361
|
+
PlanarVec2 worldAnchor{0.0, 0.0};
|
|
362
|
+
double stiffness = 1.0;
|
|
363
|
+
double reactionForce = 0.0;
|
|
364
|
+
bool active = true;
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
struct PlanarParticle {
|
|
368
|
+
PlanarVec2 position{};
|
|
369
|
+
PlanarVec2 previousPosition{};
|
|
370
|
+
PlanarVec2 velocity{};
|
|
371
|
+
PlanarVec2 force{};
|
|
372
|
+
double radius = 0.05;
|
|
373
|
+
double mass = 0.1;
|
|
374
|
+
double inverseMass = 10.0;
|
|
375
|
+
double age = 0.0;
|
|
376
|
+
double lifetime = 5.0;
|
|
377
|
+
bool active = false;
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
struct PlanarEmitter {
|
|
381
|
+
PlanarEmitterShape shape = PlanarEmitterShape::Point;
|
|
382
|
+
PlanarVec2 position{0.0, 0.0};
|
|
383
|
+
PlanarVec2 size{1.0, 1.0};
|
|
384
|
+
double minSpeed = 1.0;
|
|
385
|
+
double maxSpeed = 3.0;
|
|
386
|
+
double minAngle = 0.0;
|
|
387
|
+
double maxAngle = 6.283185307179586;
|
|
388
|
+
double minLifetime = 2.0;
|
|
389
|
+
double maxLifetime = 5.0;
|
|
390
|
+
double particleRadius = 0.05;
|
|
391
|
+
double particleMass = 0.1;
|
|
392
|
+
double rate = 10.0; // Particles per second
|
|
393
|
+
double accumulator = 0.0;
|
|
394
|
+
bool enabled = true;
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
struct PlanarBreakEvent {
|
|
398
|
+
std::uint32_t systemId = 0;
|
|
399
|
+
std::uint32_t elementIndex = 0;
|
|
400
|
+
PlanarBreakReason reason = PlanarBreakReason::None;
|
|
401
|
+
double measuredValue = 0.0;
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
struct PlanarDeformableParams {
|
|
405
|
+
PlanarVec2 gravity{0.0, -9.81};
|
|
406
|
+
double damping = 0.005;
|
|
407
|
+
double airDensity = 1.225;
|
|
408
|
+
PlanarVec2 wind{0.0, 0.0};
|
|
409
|
+
double dragCoefficient = 1.0;
|
|
410
|
+
double liftCoefficient = 0.5;
|
|
411
|
+
bool groundEnabled = true;
|
|
412
|
+
double groundY = 0.0;
|
|
413
|
+
double groundFriction = 0.3;
|
|
414
|
+
double groundRestitution = 0.0;
|
|
415
|
+
std::uint32_t solverIterations = 10;
|
|
416
|
+
std::uint32_t substeps = 1;
|
|
417
|
+
bool particleCollisionEnabled = true;
|
|
418
|
+
double particleRestitution = 0.2;
|
|
419
|
+
double particleFriction = 0.1;
|
|
420
|
+
double breakThresholdDefault = 1e9;
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
struct PlanarRigidBody2D {
|
|
424
|
+
std::uint32_t id = 0;
|
|
425
|
+
PlanarRigidShapeKind shape = PlanarRigidShapeKind::Box;
|
|
426
|
+
bool isDynamic = true;
|
|
427
|
+
double x = 0.0;
|
|
428
|
+
double y = 0.0;
|
|
429
|
+
double angle = 0.0;
|
|
430
|
+
double vx = 0.0;
|
|
431
|
+
double vy = 0.0;
|
|
432
|
+
double angularVelocity = 0.0;
|
|
433
|
+
double mass = 1.0;
|
|
434
|
+
double inverseMass = 1.0;
|
|
435
|
+
double inertia = 1.0;
|
|
436
|
+
double inverseInertia = 1.0;
|
|
437
|
+
double halfX = 0.5;
|
|
438
|
+
double halfY = 0.5;
|
|
439
|
+
double radius = 0.5;
|
|
440
|
+
double friction = 0.5;
|
|
441
|
+
double restitution = 0.0;
|
|
442
|
+
std::uint32_t vertexCount = 0;
|
|
443
|
+
std::array<PlanarVec2, 8> vertices{};
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
// ---------------------------------------------------------------------------
|
|
447
|
+
// Query Types
|
|
448
|
+
// ---------------------------------------------------------------------------
|
|
449
|
+
|
|
450
|
+
struct PlanarRaycastQuery {
|
|
451
|
+
PlanarVec2 origin{0.0, 0.0};
|
|
452
|
+
PlanarVec2 direction{1.0, 0.0};
|
|
453
|
+
double maxDistance = 1000.0;
|
|
454
|
+
std::uint32_t flags = 0x0f; // Bit 0: nodes, 1: segments, 2: faces, 3: particles
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
struct PlanarRaycastHit {
|
|
458
|
+
bool hit = false;
|
|
459
|
+
double distance = 0.0;
|
|
460
|
+
PlanarVec2 point{0.0, 0.0};
|
|
461
|
+
PlanarVec2 normal{0.0, 0.0};
|
|
462
|
+
PlanarElementKind elementKind = PlanarElementKind::Node;
|
|
463
|
+
std::uint32_t elementIndex = 0;
|
|
464
|
+
std::uint32_t nodeIndex = 0;
|
|
465
|
+
double parameter = 0.0; // Barycentric t or segment fraction
|
|
466
|
+
};
|
|
467
|
+
|
|
468
|
+
struct PlanarClosestPointQuery {
|
|
469
|
+
PlanarVec2 point{0.0, 0.0};
|
|
470
|
+
double maxDistance = 1000.0;
|
|
471
|
+
std::uint32_t flags = 0x0f;
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
struct PlanarClosestPointHit {
|
|
475
|
+
bool hit = false;
|
|
476
|
+
double distance = 0.0;
|
|
477
|
+
PlanarVec2 point{0.0, 0.0};
|
|
478
|
+
PlanarVec2 normal{0.0, 0.0};
|
|
479
|
+
PlanarElementKind elementKind = PlanarElementKind::Node;
|
|
480
|
+
std::uint32_t elementIndex = 0;
|
|
481
|
+
};
|
|
482
|
+
|
|
483
|
+
struct PlanarOverlapQuery {
|
|
484
|
+
std::uint32_t shapeType = 0; // 0=Circle, 1=Box, 2=AABB
|
|
485
|
+
PlanarVec2 center{0.0, 0.0};
|
|
486
|
+
PlanarVec2 halfExtents{0.5, 0.5}; // radius in halfExtents.x for Circle
|
|
487
|
+
double angle = 0.0;
|
|
488
|
+
};
|
|
489
|
+
|
|
490
|
+
struct PlanarOverlapResult {
|
|
491
|
+
std::uint32_t count = 0;
|
|
492
|
+
double maxPenetration = 0.0;
|
|
493
|
+
std::array<std::uint32_t, 128> hitIndices{};
|
|
494
|
+
std::array<PlanarElementKind, 128> hitKinds{};
|
|
495
|
+
};
|
|
496
|
+
|
|
497
|
+
// ---------------------------------------------------------------------------
|
|
498
|
+
// Deterministic 64-bit PRNG
|
|
499
|
+
// ---------------------------------------------------------------------------
|
|
500
|
+
|
|
501
|
+
struct PlanarRng {
|
|
502
|
+
std::uint64_t state = 123456789ULL;
|
|
503
|
+
|
|
504
|
+
constexpr explicit PlanarRng(std::uint64_t seed = 123456789ULL)
|
|
505
|
+
: state(seed == 0 ? 123456789ULL : seed) {}
|
|
506
|
+
|
|
507
|
+
std::uint64_t nextU64() {
|
|
508
|
+
std::uint64_t z = (state += 0x9e3779b97f4a7c15ULL);
|
|
509
|
+
z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9ULL;
|
|
510
|
+
z = (z ^ (z >> 27)) * 0x94d049bb133111ebULL;
|
|
511
|
+
return z ^ (z >> 31);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
double nextDouble() {
|
|
515
|
+
return static_cast<double>(nextU64() >> 11) * (1.0 / 9007199254740992.0);
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
double nextRange(double minVal, double maxVal) {
|
|
519
|
+
return minVal + nextDouble() * (maxVal - minVal);
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
// ---------------------------------------------------------------------------
|
|
524
|
+
// Deterministic Snapshot Format
|
|
525
|
+
// ---------------------------------------------------------------------------
|
|
526
|
+
|
|
527
|
+
#pragma pack(push, 1)
|
|
528
|
+
struct PlanarSnapshotHeader {
|
|
529
|
+
std::uint8_t magic[4]; // 'P', 'D', 'E', 'F'
|
|
530
|
+
std::uint32_t version; // 1
|
|
531
|
+
std::uint64_t tick; // Simulation frame / tick
|
|
532
|
+
std::uint32_t nodeCount;
|
|
533
|
+
std::uint32_t segmentCount;
|
|
534
|
+
std::uint32_t faceCount;
|
|
535
|
+
std::uint32_t distanceConstraintCount;
|
|
536
|
+
std::uint32_t bendConstraintCount;
|
|
537
|
+
std::uint32_t shearConstraintCount;
|
|
538
|
+
std::uint32_t areaConstraintCount;
|
|
539
|
+
std::uint32_t anchorCount;
|
|
540
|
+
std::uint32_t particleCount;
|
|
541
|
+
std::uint32_t activeParticleCount;
|
|
542
|
+
std::uint32_t emitterCount;
|
|
543
|
+
std::uint64_t payloadBytes;
|
|
544
|
+
std::uint32_t checksum; // FNV-1a checksum of payload
|
|
545
|
+
};
|
|
546
|
+
#pragma pack(pop)
|
|
547
|
+
|
|
548
|
+
static_assert(sizeof(PlanarSnapshotHeader) == 72, "Header must be exactly 72 bytes");
|
|
549
|
+
|
|
550
|
+
// ---------------------------------------------------------------------------
|
|
551
|
+
// Complete Planar Deformable World Structure
|
|
552
|
+
// ---------------------------------------------------------------------------
|
|
553
|
+
|
|
554
|
+
struct PlanarDeformableWorld {
|
|
555
|
+
std::uint32_t id = 0;
|
|
556
|
+
std::uint64_t tick = 0;
|
|
557
|
+
PlanarDeformableParams params{};
|
|
558
|
+
|
|
559
|
+
// Node pool
|
|
560
|
+
std::uint32_t nodeCount = 0;
|
|
561
|
+
std::array<PlanarDeformableNode, kPlanarMaxNodes> nodes{};
|
|
562
|
+
|
|
563
|
+
// Constraints
|
|
564
|
+
std::uint32_t distanceConstraintCount = 0;
|
|
565
|
+
std::array<PlanarDistanceConstraint, kPlanarMaxDistanceConstraints> distanceConstraints{};
|
|
566
|
+
|
|
567
|
+
std::uint32_t bendConstraintCount = 0;
|
|
568
|
+
std::array<PlanarBendConstraint, kPlanarMaxBendConstraints> bendConstraints{};
|
|
569
|
+
|
|
570
|
+
std::uint32_t shearConstraintCount = 0;
|
|
571
|
+
std::array<PlanarShearConstraint, kPlanarMaxShearConstraints> shearConstraints{};
|
|
572
|
+
|
|
573
|
+
std::uint32_t areaConstraintCount = 0;
|
|
574
|
+
std::array<PlanarAreaConstraint, kPlanarMaxAreaConstraints> areaConstraints{};
|
|
575
|
+
|
|
576
|
+
std::uint32_t anchorCount = 0;
|
|
577
|
+
std::array<PlanarAnchor, kPlanarMaxAnchors> anchors{};
|
|
578
|
+
|
|
579
|
+
// Topology elements
|
|
580
|
+
std::uint32_t segmentCount = 0;
|
|
581
|
+
std::array<PlanarSegment, kPlanarMaxSegments> segments{};
|
|
582
|
+
|
|
583
|
+
std::uint32_t faceCount = 0;
|
|
584
|
+
std::array<PlanarFace, kPlanarMaxFaces> faces{};
|
|
585
|
+
|
|
586
|
+
// Particles & Emitters
|
|
587
|
+
std::uint32_t particleCount = 0;
|
|
588
|
+
std::uint32_t activeParticleCount = 0;
|
|
589
|
+
std::array<PlanarParticle, kPlanarMaxParticles> particles{};
|
|
590
|
+
|
|
591
|
+
std::uint32_t emitterCount = 0;
|
|
592
|
+
std::array<PlanarEmitter, kPlanarMaxEmitters> emitters{};
|
|
593
|
+
|
|
594
|
+
PlanarRng rng{123456789ULL};
|
|
595
|
+
|
|
596
|
+
// Break events
|
|
597
|
+
std::uint32_t breakEventCount = 0;
|
|
598
|
+
std::array<PlanarBreakEvent, kPlanarMaxBreakEvents> breakEvents{};
|
|
599
|
+
|
|
600
|
+
// Telemetry
|
|
601
|
+
double maxTension = 0.0;
|
|
602
|
+
double maxBendMoment = 0.0;
|
|
603
|
+
double maxShearForce = 0.0;
|
|
604
|
+
double totalKineticEnergy = 0.0;
|
|
605
|
+
double totalPotentialEnergy = 0.0;
|
|
606
|
+
double totalDeformedArea = 0.0;
|
|
607
|
+
};
|
|
608
|
+
|
|
609
|
+
// ---------------------------------------------------------------------------
|
|
610
|
+
// Pure Deterministic Math Functions (Double Only)
|
|
611
|
+
// ---------------------------------------------------------------------------
|
|
612
|
+
|
|
613
|
+
PlanarVec2 addPlanarVec2(const PlanarVec2& a, const PlanarVec2& b);
|
|
614
|
+
PlanarVec2 subPlanarVec2(const PlanarVec2& a, const PlanarVec2& b);
|
|
615
|
+
PlanarVec2 scalePlanarVec2(const PlanarVec2& v, double s);
|
|
616
|
+
double dotPlanarVec2(const PlanarVec2& a, const PlanarVec2& b);
|
|
617
|
+
double crossPlanarVec2(const PlanarVec2& a, const PlanarVec2& b);
|
|
618
|
+
PlanarVec2 crossScalarPlanarVec2(double s, const PlanarVec2& v);
|
|
619
|
+
PlanarVec2 crossPlanarVec2Scalar(const PlanarVec2& v, double s);
|
|
620
|
+
double lengthSquaredPlanarVec2(const PlanarVec2& v);
|
|
621
|
+
double lengthPlanarVec2(const PlanarVec2& v);
|
|
622
|
+
PlanarVec2 normalizePlanarVec2(const PlanarVec2& v);
|
|
623
|
+
double distancePlanarVec2(const PlanarVec2& a, const PlanarVec2& b);
|
|
624
|
+
double distanceSquaredPlanarVec2(const PlanarVec2& a, const PlanarVec2& b);
|
|
625
|
+
PlanarVec2 perpendicularPlanarVec2(const PlanarVec2& v);
|
|
626
|
+
PlanarVec2 rotatePlanarVec2(const PlanarVec2& v, double angle);
|
|
627
|
+
PlanarVec2 unrotatePlanarVec2(const PlanarVec2& v, double angle);
|
|
628
|
+
|
|
629
|
+
PlanarMat2 multiplyPlanarMat2(const PlanarMat2& a, const PlanarMat2& b);
|
|
630
|
+
PlanarVec2 multiplyPlanarMat2Vec2(const PlanarMat2& m, const PlanarVec2& v);
|
|
631
|
+
bool invertPlanarMat2(const PlanarMat2& m, PlanarMat2& outInverse);
|
|
632
|
+
|
|
633
|
+
// ---------------------------------------------------------------------------
|
|
634
|
+
// Mass Model & Properties
|
|
635
|
+
// ---------------------------------------------------------------------------
|
|
636
|
+
|
|
637
|
+
PlanarMassProperties computePlanarMassProperties(
|
|
638
|
+
std::span<const PlanarDeformableNode> nodes);
|
|
639
|
+
|
|
640
|
+
PlanarStatus distributeRopeSegmentMass(
|
|
641
|
+
std::span<PlanarDeformableNode> nodes,
|
|
642
|
+
std::span<const PlanarSegment> segments,
|
|
643
|
+
double linearDensity);
|
|
644
|
+
|
|
645
|
+
PlanarStatus distributeClothTriangleMass(
|
|
646
|
+
std::span<PlanarDeformableNode> nodes,
|
|
647
|
+
std::span<const PlanarFace> faces,
|
|
648
|
+
double surfaceDensity);
|
|
649
|
+
|
|
650
|
+
// ---------------------------------------------------------------------------
|
|
651
|
+
// Construction & Element Addition Helpers
|
|
652
|
+
// ---------------------------------------------------------------------------
|
|
653
|
+
|
|
654
|
+
PlanarStatus addRope2D(
|
|
655
|
+
PlanarDeformableWorld& world,
|
|
656
|
+
PlanarVec2 start,
|
|
657
|
+
PlanarVec2 end,
|
|
658
|
+
std::uint32_t segmentCount,
|
|
659
|
+
double totalMass,
|
|
660
|
+
double stretchStiffness,
|
|
661
|
+
double bendStiffness,
|
|
662
|
+
double radius,
|
|
663
|
+
std::uint32_t* outStartNodeIndex = nullptr,
|
|
664
|
+
std::uint32_t* outEndNodeIndex = nullptr);
|
|
665
|
+
|
|
666
|
+
PlanarStatus addClothGrid2D(
|
|
667
|
+
PlanarDeformableWorld& world,
|
|
668
|
+
PlanarVec2 origin,
|
|
669
|
+
double width,
|
|
670
|
+
double height,
|
|
671
|
+
std::uint32_t cols,
|
|
672
|
+
std::uint32_t rows,
|
|
673
|
+
double totalMass,
|
|
674
|
+
double stretchStiffness,
|
|
675
|
+
double shearStiffness,
|
|
676
|
+
double bendStiffness,
|
|
677
|
+
double areaStiffness,
|
|
678
|
+
double radius);
|
|
679
|
+
|
|
680
|
+
PlanarStatus addParticleEmitter2D(
|
|
681
|
+
PlanarDeformableWorld& world,
|
|
682
|
+
const PlanarEmitter& emitter,
|
|
683
|
+
std::uint32_t* outEmitterIndex = nullptr);
|
|
684
|
+
|
|
685
|
+
PlanarStatus addParticle2D(
|
|
686
|
+
PlanarDeformableWorld& world,
|
|
687
|
+
PlanarVec2 pos,
|
|
688
|
+
PlanarVec2 vel,
|
|
689
|
+
double radius,
|
|
690
|
+
double mass,
|
|
691
|
+
double lifetime,
|
|
692
|
+
std::uint32_t* outParticleIndex = nullptr);
|
|
693
|
+
|
|
694
|
+
PlanarStatus addPinAnchor2D(
|
|
695
|
+
PlanarDeformableWorld& world,
|
|
696
|
+
std::uint32_t nodeIndex,
|
|
697
|
+
std::int32_t bodyIndex,
|
|
698
|
+
PlanarVec2 localAnchor,
|
|
699
|
+
double stiffness,
|
|
700
|
+
std::uint32_t* outAnchorIndex = nullptr);
|
|
701
|
+
|
|
702
|
+
// ---------------------------------------------------------------------------
|
|
703
|
+
// Core Simulation Step Functions
|
|
704
|
+
// ---------------------------------------------------------------------------
|
|
705
|
+
|
|
706
|
+
PlanarStatus stepPlanarDeformableWorld(
|
|
707
|
+
PlanarDeformableWorld& world,
|
|
708
|
+
std::span<PlanarRigidBody2D> bodies,
|
|
709
|
+
double dt);
|
|
710
|
+
|
|
711
|
+
PlanarStatus stepPlanarDeformableRaw(
|
|
712
|
+
double* nodeData,
|
|
713
|
+
std::uint32_t nodeCount,
|
|
714
|
+
double* distanceConstraintData,
|
|
715
|
+
std::uint32_t distanceConstraintCount,
|
|
716
|
+
double* bendConstraintData,
|
|
717
|
+
std::uint32_t bendConstraintCount,
|
|
718
|
+
double* shearConstraintData,
|
|
719
|
+
std::uint32_t shearConstraintCount,
|
|
720
|
+
double* areaConstraintData,
|
|
721
|
+
std::uint32_t areaConstraintCount,
|
|
722
|
+
double* anchorData,
|
|
723
|
+
std::uint32_t anchorCount,
|
|
724
|
+
double* particleData,
|
|
725
|
+
std::uint32_t particleCount,
|
|
726
|
+
double* emitterData,
|
|
727
|
+
std::uint32_t emitterCount,
|
|
728
|
+
double* rigidBodyData,
|
|
729
|
+
std::uint32_t rigidBodyCount,
|
|
730
|
+
const double* paramsData,
|
|
731
|
+
double* breakEventsData,
|
|
732
|
+
std::uint32_t* breakEventCount,
|
|
733
|
+
double dt);
|
|
734
|
+
|
|
735
|
+
// ---------------------------------------------------------------------------
|
|
736
|
+
// Queries
|
|
737
|
+
// ---------------------------------------------------------------------------
|
|
738
|
+
|
|
739
|
+
PlanarStatus raycastPlanarDeformable(
|
|
740
|
+
const PlanarDeformableWorld& world,
|
|
741
|
+
const PlanarRaycastQuery& query,
|
|
742
|
+
PlanarRaycastHit& outHit);
|
|
743
|
+
|
|
744
|
+
PlanarStatus closestPointPlanarDeformable(
|
|
745
|
+
const PlanarDeformableWorld& world,
|
|
746
|
+
const PlanarClosestPointQuery& query,
|
|
747
|
+
PlanarClosestPointHit& outHit);
|
|
748
|
+
|
|
749
|
+
PlanarStatus overlapPlanarDeformable(
|
|
750
|
+
const PlanarDeformableWorld& world,
|
|
751
|
+
const PlanarOverlapQuery& query,
|
|
752
|
+
PlanarOverlapResult& outResult);
|
|
753
|
+
|
|
754
|
+
PlanarAABB computeAABBPlanarDeformable(
|
|
755
|
+
const PlanarDeformableWorld& world);
|
|
756
|
+
|
|
757
|
+
// ---------------------------------------------------------------------------
|
|
758
|
+
// Rollback & State Snapshots
|
|
759
|
+
// ---------------------------------------------------------------------------
|
|
760
|
+
|
|
761
|
+
PlanarStatus captureSnapshot(
|
|
762
|
+
const PlanarDeformableWorld& world,
|
|
763
|
+
std::span<std::uint8_t> outBuffer,
|
|
764
|
+
std::uint32_t& outBytes);
|
|
765
|
+
|
|
766
|
+
PlanarStatus restoreSnapshot(
|
|
767
|
+
PlanarDeformableWorld& world,
|
|
768
|
+
std::span<const std::uint8_t> inBuffer);
|
|
769
|
+
|
|
770
|
+
} // namespace rundot::kinetix::physics
|
|
771
|
+
|
|
772
|
+
// ---------------------------------------------------------------------------
|
|
773
|
+
// C ABI Export Surface
|
|
774
|
+
// ---------------------------------------------------------------------------
|
|
775
|
+
|
|
776
|
+
extern "C" {
|
|
777
|
+
|
|
778
|
+
std::uint32_t rundot_kinetix_ext_d18_abi_version();
|
|
779
|
+
std::uint32_t rundot_kinetix_ext_d18_node_stride();
|
|
780
|
+
std::uint32_t rundot_kinetix_ext_d18_segment_stride();
|
|
781
|
+
std::uint32_t rundot_kinetix_ext_d18_face_stride();
|
|
782
|
+
std::uint32_t rundot_kinetix_ext_d18_distance_constraint_stride();
|
|
783
|
+
std::uint32_t rundot_kinetix_ext_d18_bend_constraint_stride();
|
|
784
|
+
std::uint32_t rundot_kinetix_ext_d18_shear_constraint_stride();
|
|
785
|
+
std::uint32_t rundot_kinetix_ext_d18_area_constraint_stride();
|
|
786
|
+
std::uint32_t rundot_kinetix_ext_d18_anchor_stride();
|
|
787
|
+
std::uint32_t rundot_kinetix_ext_d18_particle_stride();
|
|
788
|
+
std::uint32_t rundot_kinetix_ext_d18_emitter_stride();
|
|
789
|
+
std::uint32_t rundot_kinetix_ext_d18_params_stride();
|
|
790
|
+
std::uint32_t rundot_kinetix_ext_d18_rigid_body_stride();
|
|
791
|
+
std::uint32_t rundot_kinetix_ext_d18_raycast_query_stride();
|
|
792
|
+
std::uint32_t rundot_kinetix_ext_d18_raycast_hit_stride();
|
|
793
|
+
std::uint32_t rundot_kinetix_ext_d18_closest_point_query_stride();
|
|
794
|
+
std::uint32_t rundot_kinetix_ext_d18_closest_point_hit_stride();
|
|
795
|
+
std::uint32_t rundot_kinetix_ext_d18_overlap_query_stride();
|
|
796
|
+
std::uint32_t rundot_kinetix_ext_d18_overlap_hit_stride();
|
|
797
|
+
std::uint32_t rundot_kinetix_ext_d18_world_size();
|
|
798
|
+
|
|
799
|
+
std::int32_t rundot_kinetix_ext_d18_step(
|
|
800
|
+
rundot::kinetix::physics::PlanarDeformableWorld* world,
|
|
801
|
+
double* rigidBodiesData,
|
|
802
|
+
std::uint32_t bodyCount,
|
|
803
|
+
double dt);
|
|
804
|
+
|
|
805
|
+
std::int32_t rundot_kinetix_ext_d18_step_raw(
|
|
806
|
+
double* nodeData,
|
|
807
|
+
std::uint32_t nodeCount,
|
|
808
|
+
double* distanceConstraintData,
|
|
809
|
+
std::uint32_t distanceConstraintCount,
|
|
810
|
+
double* bendConstraintData,
|
|
811
|
+
std::uint32_t bendConstraintCount,
|
|
812
|
+
double* shearConstraintData,
|
|
813
|
+
std::uint32_t shearConstraintCount,
|
|
814
|
+
double* areaConstraintData,
|
|
815
|
+
std::uint32_t areaConstraintCount,
|
|
816
|
+
double* anchorData,
|
|
817
|
+
std::uint32_t anchorCount,
|
|
818
|
+
double* particleData,
|
|
819
|
+
std::uint32_t particleCount,
|
|
820
|
+
double* emitterData,
|
|
821
|
+
std::uint32_t emitterCount,
|
|
822
|
+
double* rigidBodyData,
|
|
823
|
+
std::uint32_t rigidBodyCount,
|
|
824
|
+
const double* paramsData,
|
|
825
|
+
double* breakEventsData,
|
|
826
|
+
std::uint32_t* breakEventCount,
|
|
827
|
+
double dt);
|
|
828
|
+
|
|
829
|
+
std::int32_t rundot_kinetix_ext_d18_add_rope(
|
|
830
|
+
rundot::kinetix::physics::PlanarDeformableWorld* world,
|
|
831
|
+
double startX, double startY,
|
|
832
|
+
double endX, double endY,
|
|
833
|
+
std::uint32_t segmentCount,
|
|
834
|
+
double totalMass,
|
|
835
|
+
double stretchStiffness,
|
|
836
|
+
double bendStiffness,
|
|
837
|
+
double radius);
|
|
838
|
+
|
|
839
|
+
std::int32_t rundot_kinetix_ext_d18_add_cloth_grid(
|
|
840
|
+
rundot::kinetix::physics::PlanarDeformableWorld* world,
|
|
841
|
+
double originX, double originY,
|
|
842
|
+
double width, double height,
|
|
843
|
+
std::uint32_t cols, std::uint32_t rows,
|
|
844
|
+
double totalMass,
|
|
845
|
+
double stretchStiffness,
|
|
846
|
+
double shearStiffness,
|
|
847
|
+
double bendStiffness,
|
|
848
|
+
double areaStiffness,
|
|
849
|
+
double radius);
|
|
850
|
+
|
|
851
|
+
std::int32_t rundot_kinetix_ext_d18_add_particle(
|
|
852
|
+
rundot::kinetix::physics::PlanarDeformableWorld* world,
|
|
853
|
+
double posX, double posY,
|
|
854
|
+
double velX, double velY,
|
|
855
|
+
double radius, double mass, double lifetime);
|
|
856
|
+
|
|
857
|
+
std::int32_t rundot_kinetix_ext_d18_raycast(
|
|
858
|
+
const rundot::kinetix::physics::PlanarDeformableWorld* world,
|
|
859
|
+
const double* queryData,
|
|
860
|
+
double* hitData);
|
|
861
|
+
|
|
862
|
+
std::int32_t rundot_kinetix_ext_d18_closest_point(
|
|
863
|
+
const rundot::kinetix::physics::PlanarDeformableWorld* world,
|
|
864
|
+
const double* queryData,
|
|
865
|
+
double* hitData);
|
|
866
|
+
|
|
867
|
+
std::int32_t rundot_kinetix_ext_d18_overlap(
|
|
868
|
+
const rundot::kinetix::physics::PlanarDeformableWorld* world,
|
|
869
|
+
const double* queryData,
|
|
870
|
+
double* resultData,
|
|
871
|
+
std::uint32_t* outIndices,
|
|
872
|
+
std::uint32_t maxIndices);
|
|
873
|
+
|
|
874
|
+
std::int32_t rundot_kinetix_ext_d18_capture_snapshot(
|
|
875
|
+
const rundot::kinetix::physics::PlanarDeformableWorld* world,
|
|
876
|
+
std::uint8_t* outBuffer,
|
|
877
|
+
std::uint32_t maxBytes,
|
|
878
|
+
std::uint32_t* outBytes);
|
|
879
|
+
|
|
880
|
+
std::int32_t rundot_kinetix_ext_d18_restore_snapshot(
|
|
881
|
+
rundot::kinetix::physics::PlanarDeformableWorld* world,
|
|
882
|
+
const std::uint8_t* inBuffer,
|
|
883
|
+
std::uint32_t byteCount);
|
|
884
|
+
|
|
885
|
+
std::int32_t rundot_kinetix_ext_d18_compute_mass_properties(
|
|
886
|
+
const rundot::kinetix::physics::PlanarDeformableWorld* world,
|
|
887
|
+
double* outProperties);
|
|
888
|
+
|
|
889
|
+
}
|