@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
package/dist/canonical.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export type CanonicalValue = null | boolean | string | number | readonly Canonic
|
|
|
3
3
|
};
|
|
4
4
|
export declare function canonicalize(value: unknown): CanonicalValue;
|
|
5
5
|
export declare function canonicalStringify(value: unknown): string;
|
|
6
|
+
export declare function canonicalParse<T = unknown>(text: string): T;
|
|
6
7
|
export declare function cloneCanonical<T>(value: T): T;
|
|
7
8
|
export declare function decodeCanonicalValue<T>(value: CanonicalValue): T;
|
|
8
9
|
export declare function defaultChecksum(value: unknown): string;
|
package/dist/canonical.js
CHANGED
|
@@ -6,6 +6,9 @@ export function canonicalize(value) {
|
|
|
6
6
|
export function canonicalStringify(value) {
|
|
7
7
|
return JSON.stringify(canonicalize(value));
|
|
8
8
|
}
|
|
9
|
+
export function canonicalParse(text) {
|
|
10
|
+
return decodeCanonical(JSON.parse(text));
|
|
11
|
+
}
|
|
9
12
|
export function cloneCanonical(value) {
|
|
10
13
|
return decodeCanonical(JSON.parse(canonicalStringify(value)));
|
|
11
14
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type SyncplayChecksumMode = 'per-tick' | 'interval' | 'sparse' | 'events-only';
|
|
2
|
+
export interface SyncplayChecksumOptions {
|
|
3
|
+
readonly checksumMode?: SyncplayChecksumMode;
|
|
4
|
+
readonly checksumIntervalFrames?: number;
|
|
5
|
+
}
|
|
6
|
+
export interface SyncplayChecksumPolicy {
|
|
7
|
+
readonly checksumMode: SyncplayChecksumMode;
|
|
8
|
+
readonly checksumIntervalFrames: number;
|
|
9
|
+
}
|
|
10
|
+
export declare function parseSyncplayChecksumPolicy(options: SyncplayChecksumOptions, defaultMode?: SyncplayChecksumMode): SyncplayChecksumPolicy;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SyncplayError } from './errors.js';
|
|
2
|
+
export function parseSyncplayChecksumPolicy(options, defaultMode = 'per-tick') {
|
|
3
|
+
const checksumMode = options.checksumMode ?? defaultMode;
|
|
4
|
+
const checksumIntervalFrames = options.checksumIntervalFrames ?? 1;
|
|
5
|
+
if ((checksumMode !== 'per-tick' && checksumMode !== 'interval'
|
|
6
|
+
&& checksumMode !== 'sparse' && checksumMode !== 'events-only')
|
|
7
|
+
|| !Number.isSafeInteger(checksumIntervalFrames) || checksumIntervalFrames < 1) {
|
|
8
|
+
throw new SyncplayError('Checksum policy requires a supported mode and a positive frame interval.', {
|
|
9
|
+
code: 'session.checksum-policy-invalid',
|
|
10
|
+
operation: 'configure-checksums',
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
return Object.freeze({ checksumMode, checksumIntervalFrames });
|
|
14
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Point3D } from './physics3d-shared.js';
|
|
2
|
+
export interface HullFace {
|
|
3
|
+
/** Outward unit normal in hull-local space. */
|
|
4
|
+
readonly normal: Point3D;
|
|
5
|
+
/** Plane offset: dot(normal, vertex) === offset for on-plane vertices. */
|
|
6
|
+
readonly offset: number;
|
|
7
|
+
/** Vertex indices, CCW around `normal`. */
|
|
8
|
+
readonly verts: readonly number[];
|
|
9
|
+
}
|
|
10
|
+
export interface SolverHullData {
|
|
11
|
+
/** Local space, deduplicated, lexicographically sorted. */
|
|
12
|
+
readonly vertices: readonly Point3D[];
|
|
13
|
+
/** Outward face planes, verts CCW. */
|
|
14
|
+
readonly faces: readonly HullFace[];
|
|
15
|
+
/** Unique undirected edge directions (normalized, canonical sign). */
|
|
16
|
+
readonly edgeDirs: readonly Point3D[];
|
|
17
|
+
}
|
|
18
|
+
export declare function buildSolverHull(vertices: readonly Point3D[]): SolverHullData;
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { crossVec3, dotVec3, scaleVec3, solverSqrt, subVec3, } from './physics3d-shared.js';
|
|
2
|
+
const PLANE_TOL = 1e-9;
|
|
3
|
+
const COPLANAR_TOL = 1e-6;
|
|
4
|
+
const DEDUP_TOL2 = 1e-12;
|
|
5
|
+
const EDGE_TOL = 1e-6;
|
|
6
|
+
function lexCompare(a, b) {
|
|
7
|
+
if (a.x !== b.x) {
|
|
8
|
+
return a.x < b.x ? -1 : 1;
|
|
9
|
+
}
|
|
10
|
+
if (a.y !== b.y) {
|
|
11
|
+
return a.y < b.y ? -1 : 1;
|
|
12
|
+
}
|
|
13
|
+
if (a.z !== b.z) {
|
|
14
|
+
return a.z < b.z ? -1 : 1;
|
|
15
|
+
}
|
|
16
|
+
return 0;
|
|
17
|
+
}
|
|
18
|
+
function dedupSorted(input) {
|
|
19
|
+
const sorted = [...input].sort(lexCompare);
|
|
20
|
+
const out = [];
|
|
21
|
+
for (const v of sorted) {
|
|
22
|
+
const last = out[out.length - 1];
|
|
23
|
+
if (last !== undefined) {
|
|
24
|
+
const dx = v.x - last.x;
|
|
25
|
+
const dy = v.y - last.y;
|
|
26
|
+
const dz = v.z - last.z;
|
|
27
|
+
if (dx * dx + dy * dy + dz * dz <= DEDUP_TOL2) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
out.push({ x: v.x, y: v.y, z: v.z });
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
function isFinitePoint(v) {
|
|
36
|
+
return Number.isFinite(v.x) && Number.isFinite(v.y) && Number.isFinite(v.z);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Order the on-plane vertex indices CCW around `normal` (right-hand rule) using
|
|
40
|
+
* a signed-angle comparator built from cross/dot sign tests only — no atan2.
|
|
41
|
+
* The polygon is convex, so all points share a consistent winding relative to
|
|
42
|
+
* the centroid; we sort by half-plane then by cross-product sign.
|
|
43
|
+
*/
|
|
44
|
+
function orderFaceVerts(indices, verts, normal) {
|
|
45
|
+
/* istanbul ignore next -- a supporting-plane face always carries at least three vertices. */
|
|
46
|
+
if (indices.length <= 2) {
|
|
47
|
+
return [...indices];
|
|
48
|
+
}
|
|
49
|
+
let cx = 0;
|
|
50
|
+
let cy = 0;
|
|
51
|
+
let cz = 0;
|
|
52
|
+
for (const i of indices) {
|
|
53
|
+
cx += verts[i].x;
|
|
54
|
+
cy += verts[i].y;
|
|
55
|
+
cz += verts[i].z;
|
|
56
|
+
}
|
|
57
|
+
const inv = 1 / indices.length;
|
|
58
|
+
const center = { x: cx * inv, y: cy * inv, z: cz * inv };
|
|
59
|
+
// Build an orthonormal basis (u, w) spanning the face plane.
|
|
60
|
+
const ref = subVec3(verts[indices[0]], center);
|
|
61
|
+
const refLen = solverSqrt(dotVec3(ref, ref));
|
|
62
|
+
/* istanbul ignore next -- a face vertex never coincides with its own face centroid, so refLen is always positive. */
|
|
63
|
+
const u = refLen > EDGE_TOL ? scaleVec3(ref, 1 / refLen) : orthonormalAny(normal);
|
|
64
|
+
const w = crossVec3(normal, u);
|
|
65
|
+
const key = (i) => {
|
|
66
|
+
const d = subVec3(verts[i], center);
|
|
67
|
+
const s = dotVec3(d, w);
|
|
68
|
+
const c = dotVec3(d, u);
|
|
69
|
+
// half 0 for upper (s>=0), 1 for lower — upper sweeps first for CCW order.
|
|
70
|
+
return { half: s >= 0 ? 0 : 1, s, c };
|
|
71
|
+
};
|
|
72
|
+
return [...indices].sort((ia, ib) => {
|
|
73
|
+
const a = key(ia);
|
|
74
|
+
const b = key(ib);
|
|
75
|
+
if (a.half !== b.half) {
|
|
76
|
+
return a.half - b.half;
|
|
77
|
+
}
|
|
78
|
+
// Within a half-plane, angle increases as (c descending) via cross sign:
|
|
79
|
+
// cross of the two direction vectors' sign gives relative order.
|
|
80
|
+
const da = subVec3(verts[ia], center);
|
|
81
|
+
const db = subVec3(verts[ib], center);
|
|
82
|
+
const cr = dotVec3(crossVec3(da, db), normal);
|
|
83
|
+
if (cr > EDGE_TOL) {
|
|
84
|
+
return -1;
|
|
85
|
+
}
|
|
86
|
+
/* istanbul ignore else -- an exact cross-product tie needs two same-half face vertices antipodal through the centroid; no convex face produces one (searched over cube + 4/6/8-gon prisms at four phases). The index tie-break stays as the determinism guarantee. */
|
|
87
|
+
if (cr < -EDGE_TOL) {
|
|
88
|
+
return 1;
|
|
89
|
+
}
|
|
90
|
+
/* istanbul ignore next -- see above: the exact tie is unreachable, the tie-break stays for determinism. */
|
|
91
|
+
return ia - ib;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/* istanbul ignore next -- only reachable from the unreachable refLen guard in orderFaceVerts. */
|
|
95
|
+
function orthonormalAny(n) {
|
|
96
|
+
const ax = Math.abs(n.x);
|
|
97
|
+
const ay = Math.abs(n.y);
|
|
98
|
+
const az = Math.abs(n.z);
|
|
99
|
+
const pick = ax <= ay && ax <= az ? { x: 1, y: 0, z: 0 } : ay <= az ? { x: 0, y: 1, z: 0 } : { x: 0, y: 0, z: 1 };
|
|
100
|
+
const proj = dotVec3(pick, n);
|
|
101
|
+
const t = subVec3(pick, scaleVec3(n, proj));
|
|
102
|
+
const len = solverSqrt(dotVec3(t, t));
|
|
103
|
+
return len > EDGE_TOL ? scaleVec3(t, 1 / len) : { x: 1, y: 0, z: 0 };
|
|
104
|
+
}
|
|
105
|
+
function buildHullUncached(vertices) {
|
|
106
|
+
if (vertices.length < 4 || vertices.length > 16) {
|
|
107
|
+
throw new Error(`hull requires 4-16 finite vertices with non-zero volume, received ${vertices.length}`);
|
|
108
|
+
}
|
|
109
|
+
for (const v of vertices) {
|
|
110
|
+
if (!isFinitePoint(v)) {
|
|
111
|
+
throw new Error('hull requires 4-16 finite vertices with non-zero volume, received non-finite vertex');
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const verts = dedupSorted(vertices);
|
|
115
|
+
if (verts.length < 4) {
|
|
116
|
+
throw new Error('hull requires 4-16 finite vertices with non-zero volume, received degenerate vertex set');
|
|
117
|
+
}
|
|
118
|
+
const n = verts.length;
|
|
119
|
+
let cx = 0;
|
|
120
|
+
let cy = 0;
|
|
121
|
+
let cz = 0;
|
|
122
|
+
for (const v of verts) {
|
|
123
|
+
cx += v.x;
|
|
124
|
+
cy += v.y;
|
|
125
|
+
cz += v.z;
|
|
126
|
+
}
|
|
127
|
+
const centroid = { x: cx / n, y: cy / n, z: cz / n };
|
|
128
|
+
// Enumerate every triple as a candidate supporting plane.
|
|
129
|
+
const candidates = [];
|
|
130
|
+
for (let i = 0; i < n; i += 1) {
|
|
131
|
+
for (let j = i + 1; j < n; j += 1) {
|
|
132
|
+
for (let k = j + 1; k < n; k += 1) {
|
|
133
|
+
const e1 = subVec3(verts[j], verts[i]);
|
|
134
|
+
const e2 = subVec3(verts[k], verts[i]);
|
|
135
|
+
const cr = crossVec3(e1, e2);
|
|
136
|
+
const len2 = dotVec3(cr, cr);
|
|
137
|
+
if (len2 < PLANE_TOL * PLANE_TOL) {
|
|
138
|
+
continue; // collinear triple
|
|
139
|
+
}
|
|
140
|
+
const invLen = 1 / solverSqrt(len2);
|
|
141
|
+
let nx = cr.x * invLen;
|
|
142
|
+
let ny = cr.y * invLen;
|
|
143
|
+
let nz = cr.z * invLen;
|
|
144
|
+
let offset = nx * verts[i].x + ny * verts[i].y + nz * verts[i].z;
|
|
145
|
+
// Orient outward: centroid must lie behind the plane (dot < offset).
|
|
146
|
+
const centroidDot = nx * centroid.x + ny * centroid.y + nz * centroid.z;
|
|
147
|
+
if (centroidDot > offset) {
|
|
148
|
+
nx = -nx;
|
|
149
|
+
ny = -ny;
|
|
150
|
+
nz = -nz;
|
|
151
|
+
offset = -offset;
|
|
152
|
+
}
|
|
153
|
+
// Keep iff all vertices lie on or behind the plane.
|
|
154
|
+
let supporting = true;
|
|
155
|
+
const onPlane = [];
|
|
156
|
+
for (let m = 0; m < n; m += 1) {
|
|
157
|
+
const d = nx * verts[m].x + ny * verts[m].y + nz * verts[m].z - offset;
|
|
158
|
+
if (d > PLANE_TOL) {
|
|
159
|
+
supporting = false;
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
if (d >= -PLANE_TOL) {
|
|
163
|
+
onPlane.push(m);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (supporting && onPlane.length >= 3) {
|
|
167
|
+
candidates.push({ nx, ny, nz, offset, onPlane });
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
// Merge coplanar candidates (same oriented plane within tolerance).
|
|
173
|
+
const faces = [];
|
|
174
|
+
const usedVerts = new Array(n).fill(false);
|
|
175
|
+
for (const cand of candidates) {
|
|
176
|
+
const existing = faces.find((f) => Math.abs(f.normal.x - cand.nx) <= COPLANAR_TOL
|
|
177
|
+
&& Math.abs(f.normal.y - cand.ny) <= COPLANAR_TOL
|
|
178
|
+
&& Math.abs(f.normal.z - cand.nz) <= COPLANAR_TOL
|
|
179
|
+
&& Math.abs(f.offset - cand.offset) <= COPLANAR_TOL);
|
|
180
|
+
if (existing !== undefined) {
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
const merged = new Set(cand.onPlane);
|
|
184
|
+
for (let m = 0; m < n; m += 1) {
|
|
185
|
+
const d = cand.nx * verts[m].x + cand.ny * verts[m].y + cand.nz * verts[m].z - cand.offset;
|
|
186
|
+
if (d >= -PLANE_TOL && d <= PLANE_TOL) {
|
|
187
|
+
merged.add(m);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
const normal = { x: cand.nx, y: cand.ny, z: cand.nz };
|
|
191
|
+
const ordered = orderFaceVerts([...merged], verts, normal);
|
|
192
|
+
for (const idx of ordered) {
|
|
193
|
+
usedVerts[idx] = true;
|
|
194
|
+
}
|
|
195
|
+
faces.push({ normal, offset: cand.offset, verts: ordered });
|
|
196
|
+
}
|
|
197
|
+
if (faces.length < 4) {
|
|
198
|
+
throw new Error('hull requires 4-16 finite vertices with non-zero volume, received coplanar vertex set');
|
|
199
|
+
}
|
|
200
|
+
for (let m = 0; m < n; m += 1) {
|
|
201
|
+
if (!usedVerts[m]) {
|
|
202
|
+
throw new Error('hull requires all vertices on the convex boundary, received interior vertex');
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
// Sort faces deterministically by outward normal then offset.
|
|
206
|
+
/* istanbul ignore next -- two faces of a convex hull never share a normal, so the offset tie-break never runs; it stays as the determinism guarantee. */
|
|
207
|
+
faces.sort((a, b) => lexCompare(a.normal, b.normal) || (a.offset < b.offset ? -1 : a.offset > b.offset ? 1 : 0));
|
|
208
|
+
// Unique undirected edge directions from face polygon edges.
|
|
209
|
+
const edgeDirs = [];
|
|
210
|
+
for (const face of faces) {
|
|
211
|
+
const fv = face.verts;
|
|
212
|
+
for (let e = 0; e < fv.length; e += 1) {
|
|
213
|
+
const a = verts[fv[e]];
|
|
214
|
+
const b = verts[fv[(e + 1) % fv.length]];
|
|
215
|
+
let dir = subVec3(b, a);
|
|
216
|
+
const len = solverSqrt(dotVec3(dir, dir));
|
|
217
|
+
/* istanbul ignore next -- dedupSorted removes coincident vertices, so no face edge is degenerate. */
|
|
218
|
+
if (len <= EDGE_TOL) {
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
dir = scaleVec3(dir, 1 / len);
|
|
222
|
+
// Canonical sign: first non-zero component positive.
|
|
223
|
+
if (dir.x < -EDGE_TOL || (Math.abs(dir.x) <= EDGE_TOL && (dir.y < -EDGE_TOL || (Math.abs(dir.y) <= EDGE_TOL && dir.z < 0)))) {
|
|
224
|
+
dir = scaleVec3(dir, -1);
|
|
225
|
+
}
|
|
226
|
+
const dup = edgeDirs.some((d) => Math.abs(d.x - dir.x) <= EDGE_TOL && Math.abs(d.y - dir.y) <= EDGE_TOL && Math.abs(d.z - dir.z) <= EDGE_TOL);
|
|
227
|
+
if (!dup) {
|
|
228
|
+
edgeDirs.push(dir);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
edgeDirs.sort(lexCompare);
|
|
233
|
+
return { vertices: verts, faces, edgeDirs };
|
|
234
|
+
}
|
|
235
|
+
// Memoize by vertex-array identity: hull topology is a pure derived function of
|
|
236
|
+
// the immutable input vertex list (same rationale as quatMat3Cache) — never
|
|
237
|
+
// canonical rollback state, so it is safe to keep outside the frame.
|
|
238
|
+
// rdm-ignore-next-line determinism/no-module-mutable-state: pure derived hull data keyed by immutable input identity
|
|
239
|
+
const hullCache = new WeakMap();
|
|
240
|
+
export function buildSolverHull(vertices) {
|
|
241
|
+
const cached = hullCache.get(vertices);
|
|
242
|
+
if (cached !== undefined) {
|
|
243
|
+
return cached;
|
|
244
|
+
}
|
|
245
|
+
const built = buildHullUncached(vertices);
|
|
246
|
+
hullCache.set(vertices, built);
|
|
247
|
+
return built;
|
|
248
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import type { Point3D } from './physics3d-shared.js';
|
|
2
|
+
type ColliderHullShape = Readonly<{
|
|
3
|
+
type: 'hull';
|
|
4
|
+
vertices: readonly Point3D[];
|
|
5
|
+
}>;
|
|
6
|
+
type ColliderCompoundChild = Readonly<{
|
|
7
|
+
shape: ColliderHullShape;
|
|
8
|
+
offset: Point3D;
|
|
9
|
+
}>;
|
|
10
|
+
type ColliderCompoundShape = Readonly<{
|
|
11
|
+
type: 'compound';
|
|
12
|
+
children: readonly ColliderCompoundChild[];
|
|
13
|
+
}>;
|
|
14
|
+
export interface ColliderSourceMesh {
|
|
15
|
+
/** Triangle-list vertices; `length` must be a positive multiple of 3. */
|
|
16
|
+
readonly vertices: readonly Point3D[];
|
|
17
|
+
}
|
|
18
|
+
export interface ColliderCookOptions {
|
|
19
|
+
/** Voxel grid resolution along the mesh's longest axis (4..96). */
|
|
20
|
+
readonly resolution?: number;
|
|
21
|
+
/** Upper bound on emitted hull children (1..64). */
|
|
22
|
+
readonly maxHulls?: number;
|
|
23
|
+
/** Vertex cap per emitted hull (8..16); 8 is the voxel-AABB fallback's size. */
|
|
24
|
+
readonly maxHullVertices?: number;
|
|
25
|
+
/** Stop splitting a part once `1 - partVolume/hullVolume` falls under this. */
|
|
26
|
+
readonly concavityTolerance?: number;
|
|
27
|
+
/** Output vertex quantum; must match the runtime's distance quantum or be coarser. */
|
|
28
|
+
readonly quantum?: number;
|
|
29
|
+
/** Candidate split planes evaluated per axis. */
|
|
30
|
+
readonly splitCandidates?: number;
|
|
31
|
+
}
|
|
32
|
+
export interface CookedColliderHull {
|
|
33
|
+
readonly vertexCount: number;
|
|
34
|
+
/** `1 - partVoxelVolume / hullVolume` for the part this hull covers. */
|
|
35
|
+
readonly concavity: number;
|
|
36
|
+
}
|
|
37
|
+
export interface CookedCollider {
|
|
38
|
+
readonly schemaVersion: 1;
|
|
39
|
+
readonly kind: 'deterministic-convex-decomposition';
|
|
40
|
+
readonly shape: ColliderCompoundShape;
|
|
41
|
+
readonly hulls: readonly CookedColliderHull[];
|
|
42
|
+
readonly sourceTriangles: number;
|
|
43
|
+
readonly resolution: number;
|
|
44
|
+
/** Volume-weighted mean concavity across the emitted hulls. */
|
|
45
|
+
readonly concavity: number;
|
|
46
|
+
readonly hash: string;
|
|
47
|
+
}
|
|
48
|
+
interface Lattice {
|
|
49
|
+
/** Grid dimensions in voxels. */
|
|
50
|
+
readonly nx: number;
|
|
51
|
+
readonly ny: number;
|
|
52
|
+
readonly nz: number;
|
|
53
|
+
readonly voxelSize: number;
|
|
54
|
+
readonly originX: number;
|
|
55
|
+
readonly originY: number;
|
|
56
|
+
readonly originZ: number;
|
|
57
|
+
/** Occupied voxel indices, ascending. */
|
|
58
|
+
readonly occupied: readonly number[];
|
|
59
|
+
}
|
|
60
|
+
/** A voxel-index subset of the lattice. */
|
|
61
|
+
interface Part {
|
|
62
|
+
readonly voxels: readonly number[];
|
|
63
|
+
readonly hull: LatticeHull;
|
|
64
|
+
readonly concavity: number;
|
|
65
|
+
}
|
|
66
|
+
/** Convex hull in corner-lattice integer coordinates. */
|
|
67
|
+
interface LatticeHull {
|
|
68
|
+
readonly vertices: readonly (readonly [number, number, number])[];
|
|
69
|
+
readonly faces: readonly (readonly [number, number, number])[];
|
|
70
|
+
/** Exact hull volume in corner-lattice units (voxel = 1 unit³). */
|
|
71
|
+
readonly volume: number;
|
|
72
|
+
}
|
|
73
|
+
export declare function cookConvexDecomposition(source: ColliderSourceMesh, options?: ColliderCookOptions): CookedCollider;
|
|
74
|
+
export declare function assertCookedColliderIsRuntimeValid(cooked: CookedCollider): void;
|
|
75
|
+
declare function voxelize(triangles: readonly (readonly [Point3D, Point3D, Point3D])[], resolution: number): Lattice;
|
|
76
|
+
/**
|
|
77
|
+
* Akenine-Möller triangle/AABB overlap, box centred at `center` with half-width
|
|
78
|
+
* `half`, biased outward by `tol`.
|
|
79
|
+
*
|
|
80
|
+
* The bias is load-bearing, not a fudge. Axis-aligned source faces land exactly
|
|
81
|
+
* on voxel boundaries whenever the voxel size is not a binary fraction (`1/24`
|
|
82
|
+
* is not), so the overlap test is decided at exact tangency and rounding rejects
|
|
83
|
+
* roughly half the cells. That punches holes in the surface shell, the exterior
|
|
84
|
+
* flood fill leaks through them, and the mesh cooks hollow. A conservative
|
|
85
|
+
* rasteriser must resolve tangency as "overlapping".
|
|
86
|
+
*/
|
|
87
|
+
declare function triangleIntersectsBox(triangle: readonly [Point3D, Point3D, Point3D], center: Point3D, half: number): boolean;
|
|
88
|
+
declare function makePart(voxels: readonly number[], lattice: Lattice): Part;
|
|
89
|
+
declare function bestSplit(part: Part, lattice: Lattice, splitCandidates: number): readonly [Part, Part] | undefined;
|
|
90
|
+
type IVec = readonly [number, number, number];
|
|
91
|
+
/**
|
|
92
|
+
* Incremental convex hull over integer points. Degenerate inputs (collinear or
|
|
93
|
+
* coplanar) return an empty face set with zero volume; callers treat that as a
|
|
94
|
+
* flat part and fall back to its voxel AABB.
|
|
95
|
+
*/
|
|
96
|
+
declare function convexHullLattice(points: readonly IVec[]): LatticeHull;
|
|
97
|
+
declare function collinear(a: IVec, b: IVec, c: IVec): boolean;
|
|
98
|
+
declare function finalizeHull(part: Part, lattice: Lattice, maxHullVertices: number, quantum: number): readonly Point3D[];
|
|
99
|
+
/**
|
|
100
|
+
* Drop the least load-bearing vertex until the cap is met.
|
|
101
|
+
*
|
|
102
|
+
* A vertex's cost is the volume of the cone its incident faces subtend from the
|
|
103
|
+
* hull's centroid — the part of the hull only that vertex carries. Scoring from
|
|
104
|
+
* the current hull's faces costs one hull rebuild per removal rather than one
|
|
105
|
+
* per candidate, which is the difference between a cook that takes a second and
|
|
106
|
+
* one that takes a minute. It is a greedy proxy, and it is allowed to be: the
|
|
107
|
+
* caller re-inflates the survivor until it contains the original hull, so a
|
|
108
|
+
* suboptimal choice costs tightness, never correctness.
|
|
109
|
+
*/
|
|
110
|
+
declare function reduceLatticeHull(hull: LatticeHull, maxHullVertices: number): readonly IVec[];
|
|
111
|
+
/**
|
|
112
|
+
* Inflate `hullPoints` about their centroid by the smallest factor that puts
|
|
113
|
+
* every point of `mustContain` back inside. A cooked collider is never smaller
|
|
114
|
+
* than the geometry it stands for.
|
|
115
|
+
*/
|
|
116
|
+
declare function inflateToContain(hullPoints: readonly Point3D[], mustContain: readonly Point3D[]): readonly Point3D[];
|
|
117
|
+
interface SupportPlane {
|
|
118
|
+
readonly normal: Point3D;
|
|
119
|
+
/** Signed distance from the centroid to the plane; always > 0. */
|
|
120
|
+
readonly offset: number;
|
|
121
|
+
}
|
|
122
|
+
declare function supportingPlanes(points: readonly Point3D[], centroid: Point3D): readonly SupportPlane[];
|
|
123
|
+
/** Vertices of `points` that survive on the convex boundary, in canonical order. */
|
|
124
|
+
declare function boundaryVertices(points: readonly Point3D[]): readonly Point3D[];
|
|
125
|
+
declare function dedupePoints(points: readonly Point3D[]): readonly Point3D[];
|
|
126
|
+
export declare const __colliderCookingInternals: {
|
|
127
|
+
bestSplit: typeof bestSplit;
|
|
128
|
+
boundaryVertices: typeof boundaryVertices;
|
|
129
|
+
collinear: typeof collinear;
|
|
130
|
+
convexHullLattice: typeof convexHullLattice;
|
|
131
|
+
dedupePoints: typeof dedupePoints;
|
|
132
|
+
finalizeHull: typeof finalizeHull;
|
|
133
|
+
inflateToContain: typeof inflateToContain;
|
|
134
|
+
makePart: typeof makePart;
|
|
135
|
+
reduceLatticeHull: typeof reduceLatticeHull;
|
|
136
|
+
supportingPlanes: typeof supportingPlanes;
|
|
137
|
+
triangleIntersectsBox: typeof triangleIntersectsBox;
|
|
138
|
+
voxelize: typeof voxelize;
|
|
139
|
+
};
|
|
140
|
+
export {};
|