@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,61 @@
|
|
|
1
|
+
import { type VoxelBoxChild, type VoxelCarveRegion, type VoxelChunk, type VoxelCookStats } from '../../core/src/physics/voxel-cooking.mjs';
|
|
2
|
+
import { type Kilograms, type Meters } from './units.js';
|
|
3
|
+
import type { PhysicsBodyId3D, PhysicsBodyInput3D, PhysicsVector3D, PhysicsWorld3D } from './3d.js';
|
|
4
|
+
interface VoxelBodyRoot3D {
|
|
5
|
+
readonly format: 'syncplay-voxel-body-1';
|
|
6
|
+
readonly bodyId: PhysicsBodyId3D;
|
|
7
|
+
readonly revision: bigint;
|
|
8
|
+
}
|
|
9
|
+
export interface LiveVoxelBodyState3D extends VoxelBodyRoot3D {
|
|
10
|
+
readonly status: 'live';
|
|
11
|
+
readonly dimX: number;
|
|
12
|
+
readonly dimY: number;
|
|
13
|
+
readonly dimZ: number;
|
|
14
|
+
readonly cellSize: Meters;
|
|
15
|
+
readonly occupancy: readonly number[];
|
|
16
|
+
readonly materials: readonly number[];
|
|
17
|
+
readonly children: readonly VoxelBoxChild[];
|
|
18
|
+
readonly nextChildId: number;
|
|
19
|
+
readonly massPerCell: Kilograms;
|
|
20
|
+
readonly originOffset: PhysicsVector3D<Meters>;
|
|
21
|
+
readonly maxChildren: number;
|
|
22
|
+
}
|
|
23
|
+
export interface RemovedVoxelBodyState3D extends VoxelBodyRoot3D {
|
|
24
|
+
readonly status: 'removed';
|
|
25
|
+
}
|
|
26
|
+
export type VoxelBodyState3D = LiveVoxelBodyState3D | RemovedVoxelBodyState3D;
|
|
27
|
+
export declare function voxelBodyDigest3D(state: VoxelBodyState3D): string;
|
|
28
|
+
export type VoxelBodyRegion3D = Readonly<{
|
|
29
|
+
op: VoxelCarveRegion['op'];
|
|
30
|
+
}> & (Extract<VoxelCarveRegion, {
|
|
31
|
+
shapeType: 'box' | 0;
|
|
32
|
+
}> | Readonly<{
|
|
33
|
+
shapeType: 'sphere' | 1;
|
|
34
|
+
sphereCenter: PhysicsVector3D<Meters>;
|
|
35
|
+
sphereRadius: Meters;
|
|
36
|
+
}> | Readonly<{
|
|
37
|
+
shapeType: 'capsule' | 2;
|
|
38
|
+
capsuleP0: PhysicsVector3D<Meters>;
|
|
39
|
+
capsuleP1: PhysicsVector3D<Meters>;
|
|
40
|
+
capsuleRadius: Meters;
|
|
41
|
+
}> | Extract<VoxelCarveRegion, {
|
|
42
|
+
shapeType: 'swept_quad' | 3;
|
|
43
|
+
}>);
|
|
44
|
+
export interface VoxelBodyOptions3D {
|
|
45
|
+
readonly maxChildren?: number;
|
|
46
|
+
readonly materials?: readonly number[];
|
|
47
|
+
readonly originOffset?: PhysicsVector3D<Meters>;
|
|
48
|
+
}
|
|
49
|
+
export interface VoxelBodyEditResult3D {
|
|
50
|
+
readonly state: VoxelBodyState3D;
|
|
51
|
+
readonly changed: boolean;
|
|
52
|
+
readonly stats: VoxelCookStats | null;
|
|
53
|
+
}
|
|
54
|
+
export declare function createVoxelBody3D(world: PhysicsWorld3D, body: Omit<PhysicsBodyInput3D, 'shape' | 'mass' | 'centerOfMass' | 'inertia'>, chunk: VoxelChunk, mass: Kilograms, options?: VoxelBodyOptions3D): LiveVoxelBodyState3D;
|
|
55
|
+
export declare function carveVoxelBody3D(world: PhysicsWorld3D, state: VoxelBodyState3D, region: VoxelBodyRegion3D): VoxelBodyEditResult3D;
|
|
56
|
+
export declare function paintVoxelBody3D(state: VoxelBodyState3D, region: VoxelBodyRegion3D, materialId: number, options?: {
|
|
57
|
+
readonly paintEmpty?: boolean;
|
|
58
|
+
}): VoxelBodyEditResult3D;
|
|
59
|
+
export declare function removeVoxelBody3D(world: PhysicsWorld3D, state: VoxelBodyState3D): RemovedVoxelBodyState3D;
|
|
60
|
+
export declare function hydrateVoxelBodyState3D(world: PhysicsWorld3D, value: unknown): VoxelBodyState3D;
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
import { prepareSha256Hex, sha256Hex } from '@series-inc/rundot-syncplay/core/runtime';
|
|
2
|
+
import { carveAndIncrementalCook, computeVoxelMassProperties, cookVoxelChunk, createVoxelChunk, paintVoxelChunk, } from '../../core/src/physics/voxel-cooking.mjs';
|
|
3
|
+
import { kilograms, meters, metersPerSecond } from './units.js';
|
|
4
|
+
const rootDigests = new WeakMap();
|
|
5
|
+
function assertRegisteredRoot(state) {
|
|
6
|
+
if (!rootDigests.has(state))
|
|
7
|
+
invalid('unregistered root');
|
|
8
|
+
}
|
|
9
|
+
export function voxelBodyDigest3D(state) {
|
|
10
|
+
const digest = rootDigests.get(state);
|
|
11
|
+
if (digest === undefined)
|
|
12
|
+
invalid('digest requires a created or hydrated root');
|
|
13
|
+
return digest;
|
|
14
|
+
}
|
|
15
|
+
function encodeRoot(state, bodyId) {
|
|
16
|
+
const byteLength = state.status === 'removed' ? 25
|
|
17
|
+
: 93 + state.occupancy.length * 5 + state.children.length * 80;
|
|
18
|
+
if (!Number.isSafeInteger(byteLength) || byteLength > 0x7ffffff0)
|
|
19
|
+
invalid('digest size');
|
|
20
|
+
const bytes = new Uint8Array(byteLength);
|
|
21
|
+
bytes.set(new TextEncoder().encode('SYNVXL01'));
|
|
22
|
+
const view = new DataView(bytes.buffer);
|
|
23
|
+
let offset = 8;
|
|
24
|
+
const u32 = (value) => { view.setUint32(offset, value, true); offset += 4; };
|
|
25
|
+
const f64 = (value) => { view.setFloat64(offset, value, true); offset += 8; };
|
|
26
|
+
view.setUint8(offset++, state.status === 'live' ? 1 : 0);
|
|
27
|
+
view.setBigUint64(offset, bodyId, true);
|
|
28
|
+
offset += 8;
|
|
29
|
+
view.setBigUint64(offset, state.revision, true);
|
|
30
|
+
offset += 8;
|
|
31
|
+
if (state.status === 'live') {
|
|
32
|
+
u32(state.dimX);
|
|
33
|
+
u32(state.dimY);
|
|
34
|
+
u32(state.dimZ);
|
|
35
|
+
f64(state.cellSize);
|
|
36
|
+
f64(state.massPerCell);
|
|
37
|
+
f64(state.originOffset.x);
|
|
38
|
+
f64(state.originOffset.y);
|
|
39
|
+
f64(state.originOffset.z);
|
|
40
|
+
u32(state.nextChildId);
|
|
41
|
+
u32(state.maxChildren);
|
|
42
|
+
u32(state.occupancy.length);
|
|
43
|
+
u32(state.children.length);
|
|
44
|
+
bytes.set(state.occupancy, offset);
|
|
45
|
+
offset += state.occupancy.length;
|
|
46
|
+
for (const value of state.materials)
|
|
47
|
+
u32(value);
|
|
48
|
+
for (const child of state.children) {
|
|
49
|
+
u32(child.childId);
|
|
50
|
+
u32(child.flags);
|
|
51
|
+
u32(child.cellBounds.minX);
|
|
52
|
+
u32(child.cellBounds.minY);
|
|
53
|
+
u32(child.cellBounds.minZ);
|
|
54
|
+
u32(child.cellBounds.maxX);
|
|
55
|
+
u32(child.cellBounds.maxY);
|
|
56
|
+
u32(child.cellBounds.maxZ);
|
|
57
|
+
f64(child.halfExtents.x);
|
|
58
|
+
f64(child.halfExtents.y);
|
|
59
|
+
f64(child.halfExtents.z);
|
|
60
|
+
f64(child.offset.x);
|
|
61
|
+
f64(child.offset.y);
|
|
62
|
+
f64(child.offset.z);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return bytes;
|
|
66
|
+
}
|
|
67
|
+
function freezeRoot(state, bytes = encodeRoot(state, state.bodyId), hash = sha256Hex) {
|
|
68
|
+
const digest = hash(bytes);
|
|
69
|
+
Object.freeze(state);
|
|
70
|
+
rootDigests.set(state, digest);
|
|
71
|
+
return state;
|
|
72
|
+
}
|
|
73
|
+
function invalid(field) {
|
|
74
|
+
throw new Error(`KINETIX_VOXEL_BODY_INVALID: ${field}`);
|
|
75
|
+
}
|
|
76
|
+
function integer(value, minimum, maximum, field) {
|
|
77
|
+
if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < minimum || value > maximum)
|
|
78
|
+
invalid(field);
|
|
79
|
+
return value;
|
|
80
|
+
}
|
|
81
|
+
function record(value, field) {
|
|
82
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
83
|
+
invalid(field);
|
|
84
|
+
const result = {};
|
|
85
|
+
for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(value))) {
|
|
86
|
+
if (!Object.hasOwn(descriptor, 'value'))
|
|
87
|
+
invalid(`${field}.${key}`);
|
|
88
|
+
result[key] = descriptor.value;
|
|
89
|
+
}
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
function length(value, field) {
|
|
93
|
+
if (typeof value !== 'number' || !Number.isFinite(value))
|
|
94
|
+
invalid(field);
|
|
95
|
+
return meters(value);
|
|
96
|
+
}
|
|
97
|
+
function point(value, field) {
|
|
98
|
+
const input = record(value, field);
|
|
99
|
+
return Object.freeze({ x: length(input.x, field), y: length(input.y, field), z: length(input.z, field) });
|
|
100
|
+
}
|
|
101
|
+
function cells(value, count, maximum, field) {
|
|
102
|
+
if (!Array.isArray(value) || value.length !== count)
|
|
103
|
+
invalid(field);
|
|
104
|
+
return Object.freeze(Array.from({ length: count }, (_, index) => {
|
|
105
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, String(index));
|
|
106
|
+
if (descriptor === undefined || !Object.hasOwn(descriptor, 'value'))
|
|
107
|
+
invalid(field);
|
|
108
|
+
return integer(descriptor.value, 0, maximum, field);
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
function chunkOf(state) {
|
|
112
|
+
return createVoxelChunk(state.dimX, state.dimY, state.dimZ, state.cellSize, Uint8Array.from(state.occupancy));
|
|
113
|
+
}
|
|
114
|
+
function freezeChildren(children) {
|
|
115
|
+
return Object.freeze(children.map((child) => Object.freeze({
|
|
116
|
+
...child,
|
|
117
|
+
halfExtents: Object.freeze({ ...child.halfExtents }),
|
|
118
|
+
offset: Object.freeze({ ...child.offset }),
|
|
119
|
+
cellBounds: Object.freeze({ ...child.cellBounds }),
|
|
120
|
+
})));
|
|
121
|
+
}
|
|
122
|
+
function occupiedCount(occupancy) {
|
|
123
|
+
return occupancy.reduce((count, cell) => count + cell, 0);
|
|
124
|
+
}
|
|
125
|
+
function properties(state) {
|
|
126
|
+
const result = computeVoxelMassProperties(chunkOf(state), kilograms(state.massPerCell * occupiedCount(state.occupancy)), state.originOffset);
|
|
127
|
+
if (result.status !== 0)
|
|
128
|
+
invalid('empty live body');
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
function shapeOf(state) {
|
|
132
|
+
return {
|
|
133
|
+
type: 'voxel_compound',
|
|
134
|
+
children: state.children.map((child) => ({
|
|
135
|
+
shape: { type: 'box', halfX: child.halfExtents.x, halfY: child.halfExtents.y, halfZ: child.halfExtents.z },
|
|
136
|
+
offset: {
|
|
137
|
+
x: meters(child.offset.x + state.originOffset.x),
|
|
138
|
+
y: meters(child.offset.y + state.originOffset.y),
|
|
139
|
+
z: meters(child.offset.z + state.originOffset.z),
|
|
140
|
+
},
|
|
141
|
+
})),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
function nextRevision(state) {
|
|
145
|
+
if (state.revision === 0xffffffffffffffffn)
|
|
146
|
+
invalid('revision exhausted');
|
|
147
|
+
return state.revision + 1n;
|
|
148
|
+
}
|
|
149
|
+
function gridRegion(state, region) {
|
|
150
|
+
const input = record(region, 'region');
|
|
151
|
+
const op = input.op;
|
|
152
|
+
if (op !== 'carve' && op !== 'fill' && op !== 0 && op !== 1)
|
|
153
|
+
invalid('region op');
|
|
154
|
+
const local = (value) => {
|
|
155
|
+
const vector = point(value, 'region point');
|
|
156
|
+
return { x: meters(vector.x - state.originOffset.x), y: meters(vector.y - state.originOffset.y),
|
|
157
|
+
z: meters(vector.z - state.originOffset.z) };
|
|
158
|
+
};
|
|
159
|
+
const cell = (value) => {
|
|
160
|
+
const vector = local(value);
|
|
161
|
+
return { x: vector.x / state.cellSize, y: vector.y / state.cellSize, z: vector.z / state.cellSize };
|
|
162
|
+
};
|
|
163
|
+
switch (input.shapeType) {
|
|
164
|
+
case 'box':
|
|
165
|
+
case 0: {
|
|
166
|
+
const box = record(input.box, 'region box');
|
|
167
|
+
const coordinate = (key) => integer(box[key], -2147482623, 2147482623, `region box.${key}`);
|
|
168
|
+
return { op, shapeType: 'box', box: { minX: coordinate('minX'), minY: coordinate('minY'), minZ: coordinate('minZ'),
|
|
169
|
+
maxX: coordinate('maxX'), maxY: coordinate('maxY'), maxZ: coordinate('maxZ') } };
|
|
170
|
+
}
|
|
171
|
+
case 'sphere':
|
|
172
|
+
case 1: return { op, shapeType: 'sphere', sphereCenter: cell(input.sphereCenter),
|
|
173
|
+
sphereRadius: length(input.sphereRadius, 'sphereRadius') / state.cellSize };
|
|
174
|
+
case 'capsule':
|
|
175
|
+
case 2: return { op, shapeType: 'capsule', capsuleP0: cell(input.capsuleP0), capsuleP1: cell(input.capsuleP1),
|
|
176
|
+
capsuleRadius: length(input.capsuleRadius, 'capsuleRadius') / state.cellSize };
|
|
177
|
+
case 'swept_quad':
|
|
178
|
+
case 3: {
|
|
179
|
+
if (!Array.isArray(input.corners) || input.corners.length !== 4)
|
|
180
|
+
invalid('corners');
|
|
181
|
+
const corners = input.corners;
|
|
182
|
+
const corner = (index) => {
|
|
183
|
+
const descriptor = Object.getOwnPropertyDescriptor(corners, String(index));
|
|
184
|
+
if (descriptor === undefined || !Object.hasOwn(descriptor, 'value'))
|
|
185
|
+
invalid('corner');
|
|
186
|
+
return local(descriptor.value);
|
|
187
|
+
};
|
|
188
|
+
return { op, shapeType: 'swept_quad', corners: [corner(0), corner(1), corner(2), corner(3)],
|
|
189
|
+
thickness: length(input.thickness, 'thickness') };
|
|
190
|
+
}
|
|
191
|
+
default: return invalid('region shape');
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function retainedMaterialVelocity(body, center) {
|
|
195
|
+
const x = center.x - body.centerOfMass.x;
|
|
196
|
+
const y = center.y - body.centerOfMass.y;
|
|
197
|
+
const z = center.z - body.centerOfMass.z;
|
|
198
|
+
const q = body.orientation;
|
|
199
|
+
const tx = 2 * (q.y * z - q.z * y);
|
|
200
|
+
const ty = 2 * (q.z * x - q.x * z);
|
|
201
|
+
const tz = 2 * (q.x * y - q.y * x);
|
|
202
|
+
const dx = x + q.w * tx + q.y * tz - q.z * ty;
|
|
203
|
+
const dy = y + q.w * ty + q.z * tx - q.x * tz;
|
|
204
|
+
const dz = z + q.w * tz + q.x * ty - q.y * tx;
|
|
205
|
+
const omega = body.angularVelocity;
|
|
206
|
+
return {
|
|
207
|
+
x: metersPerSecond((body.motionLocks & 1) === 0 ? body.linearVelocity.x + omega.y * dz - omega.z * dy : 0),
|
|
208
|
+
y: metersPerSecond((body.motionLocks & 2) === 0 ? body.linearVelocity.y + omega.z * dx - omega.x * dz : 0),
|
|
209
|
+
z: metersPerSecond((body.motionLocks & 4) === 0 ? body.linearVelocity.z + omega.x * dy - omega.y * dx : 0),
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
export function createVoxelBody3D(world, body, chunk, mass, options = {}) {
|
|
213
|
+
const source = createVoxelChunk(chunk.dimX, chunk.dimY, chunk.dimZ, chunk.cellSize, chunk.occupancy.slice());
|
|
214
|
+
if (source.occupancy.some((cell) => cell !== 0 && cell !== 1))
|
|
215
|
+
invalid('occupancy');
|
|
216
|
+
const occupancy = Object.freeze(Array.from(source.occupancy));
|
|
217
|
+
const count = occupiedCount(occupancy);
|
|
218
|
+
if (count === 0 || !Number.isFinite(mass) || mass <= 0)
|
|
219
|
+
invalid('mass or occupancy');
|
|
220
|
+
const maxChildren = integer(options.maxChildren ?? Math.min(32768, occupancy.length), 1, 32768, 'maxChildren');
|
|
221
|
+
const materials = cells(options.materials ?? occupancy.map(() => 0), occupancy.length, 0xffffffff, 'materials');
|
|
222
|
+
const originOffset = point(options.originOffset ?? { x: 0, y: 0, z: 0 }, 'originOffset');
|
|
223
|
+
const cooked = cookVoxelChunk(source, { maxChildren });
|
|
224
|
+
const initial = {
|
|
225
|
+
format: 'syncplay-voxel-body-1',
|
|
226
|
+
status: 'live',
|
|
227
|
+
revision: 0n,
|
|
228
|
+
dimX: source.dimX, dimY: source.dimY, dimZ: source.dimZ, cellSize: source.cellSize,
|
|
229
|
+
occupancy, materials, children: freezeChildren(cooked.children), nextChildId: cooked.nextChildId,
|
|
230
|
+
massPerCell: kilograms(mass / count), originOffset, maxChildren,
|
|
231
|
+
};
|
|
232
|
+
const physical = properties(initial);
|
|
233
|
+
const encoded = encodeRoot(initial, 0n);
|
|
234
|
+
const header = new DataView(encoded.buffer);
|
|
235
|
+
const hash = prepareSha256Hex(encoded.byteLength);
|
|
236
|
+
const created = world.edit((edit) => edit.createBody({ ...body, ...physical, shape: shapeOf(initial) })).created;
|
|
237
|
+
header.setBigUint64(9, created.id, true);
|
|
238
|
+
return freezeRoot({ ...initial, bodyId: created.id }, encoded, hash);
|
|
239
|
+
}
|
|
240
|
+
export function carveVoxelBody3D(world, state, region) {
|
|
241
|
+
assertRegisteredRoot(state);
|
|
242
|
+
if (state.status === 'removed')
|
|
243
|
+
return { state, changed: false, stats: null };
|
|
244
|
+
const handle = world.resolveBody(state.bodyId);
|
|
245
|
+
const current = validateNativeBody(world, state);
|
|
246
|
+
const cooked = carveAndIncrementalCook(chunkOf(state), state.children, gridRegion(state, region), { maxChildren: state.maxChildren, nextChildId: state.nextChildId, mutateInPlace: false });
|
|
247
|
+
if (!cooked.changed)
|
|
248
|
+
return { state, changed: false, stats: null };
|
|
249
|
+
const revision = nextRevision(state);
|
|
250
|
+
const occupancy = Object.freeze(Array.from(cooked.carveResult.occupancy));
|
|
251
|
+
if (occupiedCount(occupancy) === 0) {
|
|
252
|
+
const removed = freezeRoot({
|
|
253
|
+
format: state.format, status: 'removed', bodyId: state.bodyId, revision,
|
|
254
|
+
});
|
|
255
|
+
world.edit((edit) => edit.removeBody(handle));
|
|
256
|
+
return { state: removed, changed: true, stats: cooked.stats };
|
|
257
|
+
}
|
|
258
|
+
const staged = freezeRoot({ ...state, revision, occupancy,
|
|
259
|
+
children: freezeChildren(cooked.children), nextChildId: cooked.nextChildId });
|
|
260
|
+
const physical = properties(staged);
|
|
261
|
+
const linearVelocity = retainedMaterialVelocity(current, physical.centerOfMass);
|
|
262
|
+
world.edit((edit) => edit.replaceBody(handle, { ...current, ...physical, linearVelocity, shape: shapeOf(staged), sleeping: false }));
|
|
263
|
+
return { state: staged, changed: true, stats: cooked.stats };
|
|
264
|
+
}
|
|
265
|
+
export function paintVoxelBody3D(state, region, materialId, options = {}) {
|
|
266
|
+
assertRegisteredRoot(state);
|
|
267
|
+
if (state.status === 'removed')
|
|
268
|
+
return { state, changed: false, stats: null };
|
|
269
|
+
const painted = paintVoxelChunk(chunkOf(state), state.materials, gridRegion(state, region), materialId, options);
|
|
270
|
+
if (!painted.changed)
|
|
271
|
+
return { state, changed: false, stats: null };
|
|
272
|
+
return { state: freezeRoot({ ...state, revision: nextRevision(state), materials: painted.materials }),
|
|
273
|
+
changed: true, stats: null };
|
|
274
|
+
}
|
|
275
|
+
export function removeVoxelBody3D(world, state) {
|
|
276
|
+
assertRegisteredRoot(state);
|
|
277
|
+
if (state.status === 'removed')
|
|
278
|
+
return state;
|
|
279
|
+
validateNativeBody(world, state);
|
|
280
|
+
const removed = freezeRoot({
|
|
281
|
+
format: state.format, status: 'removed', bodyId: state.bodyId, revision: nextRevision(state),
|
|
282
|
+
});
|
|
283
|
+
world.edit((edit) => edit.removeBody(world.resolveBody(state.bodyId)));
|
|
284
|
+
return removed;
|
|
285
|
+
}
|
|
286
|
+
export function hydrateVoxelBodyState3D(world, value) {
|
|
287
|
+
const input = record(value, 'state');
|
|
288
|
+
if (input.format !== 'syncplay-voxel-body-1')
|
|
289
|
+
invalid('format');
|
|
290
|
+
if (typeof input.bodyId !== 'bigint' || input.bodyId <= 0n || input.bodyId > 0xffffffffffffffffn)
|
|
291
|
+
invalid('bodyId');
|
|
292
|
+
if (typeof input.revision !== 'bigint' || input.revision < 0n || input.revision > 0xffffffffffffffffn)
|
|
293
|
+
invalid('revision');
|
|
294
|
+
const bodyId = input.bodyId;
|
|
295
|
+
if (input.status === 'removed') {
|
|
296
|
+
if (input.revision < 1n)
|
|
297
|
+
invalid('removed revision');
|
|
298
|
+
let exists = false;
|
|
299
|
+
try {
|
|
300
|
+
world.resolveBody(bodyId);
|
|
301
|
+
exists = true;
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
if (!(error instanceof Error) || !('code' in error) || error.code !== 'physics.handle-missing')
|
|
305
|
+
throw error;
|
|
306
|
+
}
|
|
307
|
+
if (exists)
|
|
308
|
+
invalid('removed body exists');
|
|
309
|
+
return freezeRoot({ format: input.format, status: 'removed', bodyId, revision: input.revision });
|
|
310
|
+
}
|
|
311
|
+
if (input.status !== 'live')
|
|
312
|
+
invalid('status');
|
|
313
|
+
const dimX = integer(input.dimX, 1, 1024, 'dimX');
|
|
314
|
+
const dimY = integer(input.dimY, 1, 1024, 'dimY');
|
|
315
|
+
const dimZ = integer(input.dimZ, 1, 1024, 'dimZ');
|
|
316
|
+
const cellSize = length(input.cellSize, 'cellSize');
|
|
317
|
+
const count = dimX * dimY * dimZ;
|
|
318
|
+
if (cellSize <= 0 || !Number.isFinite(cellSize * Math.max(dimX, dimY, dimZ))
|
|
319
|
+
|| count * 6 > 0x7ffffff0)
|
|
320
|
+
invalid('grid size');
|
|
321
|
+
const occupancy = cells(input.occupancy, count, 1, 'occupancy');
|
|
322
|
+
const materials = cells(input.materials, count, 0xffffffff, 'materials');
|
|
323
|
+
const maxChildren = integer(input.maxChildren, 1, 32768, 'maxChildren');
|
|
324
|
+
const nextChildId = integer(input.nextChildId, 1, 0xffffffff, 'nextChildId');
|
|
325
|
+
if (!Array.isArray(input.children))
|
|
326
|
+
invalid('children');
|
|
327
|
+
const childCount = integer(input.children.length, 1, maxChildren, 'children');
|
|
328
|
+
const covered = new Uint8Array(count);
|
|
329
|
+
const ids = new Set();
|
|
330
|
+
const rawChildren = input.children;
|
|
331
|
+
const children = Array.from({ length: childCount }, (_, index) => {
|
|
332
|
+
const descriptor = Object.getOwnPropertyDescriptor(rawChildren, String(index));
|
|
333
|
+
if (descriptor === undefined || !Object.hasOwn(descriptor, 'value'))
|
|
334
|
+
invalid('child');
|
|
335
|
+
const value = descriptor.value;
|
|
336
|
+
const child = record(value, 'child');
|
|
337
|
+
const childId = integer(child.childId, 0, nextChildId - 1, 'childId');
|
|
338
|
+
if (ids.has(childId))
|
|
339
|
+
invalid('duplicate childId');
|
|
340
|
+
ids.add(childId);
|
|
341
|
+
const bounds = record(child.cellBounds, 'cellBounds');
|
|
342
|
+
const minX = integer(bounds.minX, 0, dimX - 1, 'minX');
|
|
343
|
+
const minY = integer(bounds.minY, 0, dimY - 1, 'minY');
|
|
344
|
+
const minZ = integer(bounds.minZ, 0, dimZ - 1, 'minZ');
|
|
345
|
+
const maxX = integer(bounds.maxX, minX, dimX - 1, 'maxX');
|
|
346
|
+
const maxY = integer(bounds.maxY, minY, dimY - 1, 'maxY');
|
|
347
|
+
const maxZ = integer(bounds.maxZ, minZ, dimZ - 1, 'maxZ');
|
|
348
|
+
const halfExtents = point(child.halfExtents, 'halfExtents');
|
|
349
|
+
const offset = point(child.offset, 'offset');
|
|
350
|
+
for (const [axis, min, max] of [['x', minX, maxX], ['y', minY, maxY], ['z', minZ, maxZ]]) {
|
|
351
|
+
if (!Object.is(halfExtents[axis], (max - min + 1) * cellSize * 0.5)
|
|
352
|
+
|| !Object.is(offset[axis], ((min + max) * 0.5) * cellSize))
|
|
353
|
+
invalid('child geometry');
|
|
354
|
+
}
|
|
355
|
+
for (let z = minZ; z <= maxZ; z += 1)
|
|
356
|
+
for (let y = minY; y <= maxY; y += 1)
|
|
357
|
+
for (let x = minX; x <= maxX; x += 1) {
|
|
358
|
+
const index = x + dimX * (y + dimY * z);
|
|
359
|
+
if (covered[index] !== 0 || occupancy[index] !== 1)
|
|
360
|
+
invalid('child coverage');
|
|
361
|
+
covered[index] = 1;
|
|
362
|
+
}
|
|
363
|
+
return { childId, halfExtents, offset, cellBounds: { minX, minY, minZ, maxX, maxY, maxZ },
|
|
364
|
+
flags: integer(child.flags, 0, 7, 'flags') };
|
|
365
|
+
});
|
|
366
|
+
if (covered.some((cell, index) => cell !== occupancy[index]))
|
|
367
|
+
invalid('missing child coverage');
|
|
368
|
+
if (typeof input.massPerCell !== 'number' || !Number.isFinite(input.massPerCell) || input.massPerCell <= 0)
|
|
369
|
+
invalid('massPerCell');
|
|
370
|
+
const state = freezeRoot({
|
|
371
|
+
format: input.format, status: 'live', bodyId, revision: input.revision,
|
|
372
|
+
dimX, dimY, dimZ, cellSize, occupancy, materials, children: freezeChildren(children), nextChildId,
|
|
373
|
+
massPerCell: kilograms(input.massPerCell), originOffset: point(input.originOffset, 'originOffset'), maxChildren,
|
|
374
|
+
});
|
|
375
|
+
validateNativeBody(world, state);
|
|
376
|
+
return state;
|
|
377
|
+
}
|
|
378
|
+
function validateNativeBody(world, state) {
|
|
379
|
+
const body = world.readBody(world.resolveBody(state.bodyId));
|
|
380
|
+
const expected = shapeOf(state);
|
|
381
|
+
if (expected.type !== 'voxel_compound' || body.shape.type !== 'voxel_compound'
|
|
382
|
+
|| body.shape.children.length !== expected.children.length)
|
|
383
|
+
invalid('native shape');
|
|
384
|
+
for (let index = 0; index < expected.children.length; index += 1) {
|
|
385
|
+
const actual = body.shape.children[index];
|
|
386
|
+
const wanted = expected.children[index];
|
|
387
|
+
if (actual.shape.type !== 'box' || wanted.shape.type !== 'box')
|
|
388
|
+
invalid('native child');
|
|
389
|
+
for (const axis of ['x', 'y', 'z']) {
|
|
390
|
+
if (!Object.is(actual.offset?.[axis] ?? 0, wanted.offset?.[axis] ?? 0))
|
|
391
|
+
invalid('native child offset');
|
|
392
|
+
}
|
|
393
|
+
if (!Object.is(actual.shape.halfX, wanted.shape.halfX) || !Object.is(actual.shape.halfY, wanted.shape.halfY)
|
|
394
|
+
|| !Object.is(actual.shape.halfZ, wanted.shape.halfZ))
|
|
395
|
+
invalid('native child size');
|
|
396
|
+
if ('orientation' in actual && actual.orientation !== undefined
|
|
397
|
+
&& (actual.orientation.x !== 0 || actual.orientation.y !== 0 || actual.orientation.z !== 0 || actual.orientation.w !== 1))
|
|
398
|
+
invalid('native child orientation');
|
|
399
|
+
}
|
|
400
|
+
const physical = properties(state);
|
|
401
|
+
if (!Object.is(body.mass, physical.mass))
|
|
402
|
+
invalid('native mass');
|
|
403
|
+
for (const axis of ['x', 'y', 'z'])
|
|
404
|
+
if (!Object.is(body.centerOfMass[axis], physical.centerOfMass[axis]))
|
|
405
|
+
invalid('native centerOfMass');
|
|
406
|
+
for (const axis of ['xx', 'yy', 'zz', 'xy', 'xz', 'yz'])
|
|
407
|
+
if (!Object.is(body.inertia[axis] ?? 0, physical.inertia[axis]))
|
|
408
|
+
invalid('native inertia');
|
|
409
|
+
return body;
|
|
410
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RuntimeSession } from './runtime-session.js';
|
|
2
|
-
export type DeterministicRenderReadonly<T> = T extends (...args: readonly never[]) => unknown ? never : T extends readonly (infer Item)[] ? readonly DeterministicRenderReadonly<Item>[] : T extends object ? {
|
|
2
|
+
export type DeterministicRenderReadonly<T> = T extends (...args: readonly never[]) => unknown ? never : T extends number | string | boolean | bigint | symbol | null | undefined ? T : T extends readonly (infer Item)[] ? readonly DeterministicRenderReadonly<Item>[] : T extends object ? {
|
|
3
3
|
readonly [Key in keyof T]: DeterministicRenderReadonly<T[Key]>;
|
|
4
4
|
} : T;
|
|
5
5
|
export interface DeterministicR3fRenderFrame<RenderState> {
|
|
@@ -47,6 +47,23 @@ export interface DeterministicR3fRenderAdapterConfig<State, Input, RenderState =
|
|
|
47
47
|
readonly errorCorrection?: DeterministicR3fErrorCorrectionConfig<RenderState>;
|
|
48
48
|
}
|
|
49
49
|
export declare function createDeterministicR3fRenderAdapter<State, Input, RenderState = State>(config: DeterministicR3fRenderAdapterConfig<State, Input, RenderState>): DeterministicR3fRenderAdapter<State, Input, RenderState>;
|
|
50
|
+
/**
|
|
51
|
+
* Duck-typed representation of an instanced mesh (e.g. THREE.InstancedMesh),
|
|
52
|
+
* avoiding hard dependencies on Three.js in the syncplay core or adapter.
|
|
53
|
+
*/
|
|
54
|
+
export interface InstancedMeshLike {
|
|
55
|
+
count?: number;
|
|
56
|
+
instanceMatrix: {
|
|
57
|
+
array: Float32Array;
|
|
58
|
+
needsUpdate: boolean;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Updates an instanced mesh's instanceMatrix array from contiguous [px, py, pz, qx, qy, qz, qw] transforms.
|
|
63
|
+
* Each transform occupies 7 floats. Writes 16-float column-major 4x4 affine matrices into instanceMatrix.array.
|
|
64
|
+
* Respects statusMask bit 0 (awake/moved): skips stationary bodies unless forceFullUpload is true.
|
|
65
|
+
*/
|
|
66
|
+
export declare function updateInstancedMeshFromTransforms(mesh: InstancedMeshLike, transforms: Float32Array, count: number, statusMask?: Uint8Array, forceFullUpload?: boolean): void;
|
|
50
67
|
export declare function createDeterministicR3fDebugOverlay<RenderState>(frame: DeterministicR3fRenderFrame<RenderState>): DeterministicR3fRenderDebug;
|
|
51
68
|
export declare function interpolateDeterministicRenderNumber(previous: number, next: number, alpha: number): number;
|
|
52
69
|
export declare function interpolateDeterministicRenderVec2(previous: {
|
|
@@ -59,3 +76,44 @@ export declare function interpolateDeterministicRenderVec2(previous: {
|
|
|
59
76
|
readonly x: number;
|
|
60
77
|
readonly y: number;
|
|
61
78
|
};
|
|
79
|
+
export interface DeterministicPhysicsWireframeShape3D {
|
|
80
|
+
readonly bodyId: number;
|
|
81
|
+
readonly kind: "box" | "sphere" | "capsule" | "compound" | "mesh" | "other";
|
|
82
|
+
readonly position: {
|
|
83
|
+
readonly x: number;
|
|
84
|
+
readonly y: number;
|
|
85
|
+
readonly z: number;
|
|
86
|
+
};
|
|
87
|
+
readonly orientation: {
|
|
88
|
+
readonly x: number;
|
|
89
|
+
readonly y: number;
|
|
90
|
+
readonly z: number;
|
|
91
|
+
readonly w: number;
|
|
92
|
+
};
|
|
93
|
+
readonly lines: Float32Array;
|
|
94
|
+
}
|
|
95
|
+
export interface DeterministicPhysicsDebugOverlay3D {
|
|
96
|
+
readonly shapes: readonly DeterministicPhysicsWireframeShape3D[];
|
|
97
|
+
readonly totalVertices: number;
|
|
98
|
+
}
|
|
99
|
+
export declare function createDeterministicPhysicsDebugOverlay3D(world: {
|
|
100
|
+
readonly info: () => {
|
|
101
|
+
readonly bodyCount: number;
|
|
102
|
+
};
|
|
103
|
+
readonly resolveBody?: (id: any) => any;
|
|
104
|
+
readonly readBody: (handle: any) => {
|
|
105
|
+
readonly bodyId: any;
|
|
106
|
+
readonly shape: unknown;
|
|
107
|
+
readonly position: {
|
|
108
|
+
readonly x: number;
|
|
109
|
+
readonly y: number;
|
|
110
|
+
readonly z: number;
|
|
111
|
+
};
|
|
112
|
+
readonly orientation: {
|
|
113
|
+
readonly x: number;
|
|
114
|
+
readonly y: number;
|
|
115
|
+
readonly z: number;
|
|
116
|
+
readonly w: number;
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
}, bodyHandles?: readonly any[]): DeterministicPhysicsDebugOverlay3D;
|