@khr3/core 0.2.12 → 0.2.13

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/dist/inertia.d.ts CHANGED
@@ -1,15 +1,13 @@
1
1
  import * as THREE from "three";
2
2
  import type { RapierRigidBody } from "@react-three/rapier";
3
- import { type KhrBodySpec, type KhrColliderShape } from "./types.js";
3
+ import { type KhrBodySpec, type KhrColliderShape, type KhrColliderSpec } from "./types.js";
4
4
  export type Vec3Tuple = [number, number, number];
5
5
  export type QuatTuple = [number, number, number, number];
6
- export interface RapierBodyMassTarget {
6
+ export interface LumpedMassProps {
7
7
  readonly mass: number;
8
8
  readonly com: Vec3Tuple;
9
- readonly hasExplicitCom: boolean;
10
- readonly inertiaDiagonal: Vec3Tuple;
9
+ readonly inertia: Vec3Tuple;
11
10
  readonly inertiaFrame: QuatTuple;
12
- readonly hasExplicitInertia: boolean;
13
11
  }
14
12
  export declare function assertUnitScale(scale: unknown, owner: string): void;
15
13
  export declare function readFiniteVec3(val: unknown, fieldLabel: string): Vec3Tuple;
@@ -21,21 +19,35 @@ export declare function computeRelativePose(ownerObj: THREE.Object3D, childObj:
21
19
  localQuaternion: QuatTuple;
22
20
  };
23
21
  export declare function extractMeshColliderShape(targetObj: THREE.Object3D, meshNodeName: string, convexHull: boolean): KhrColliderShape;
24
- export declare function bodyPoseMatrix(body: KhrBodySpec, target?: THREE.Matrix4): THREE.Matrix4;
22
+ /**
23
+ * Exact 3x3 symmetric Jacobi eigendecomposition returning positive principal inertia diagonal
24
+ * and right-handed `SO(3)` principal frame quaternion `[x, y, z, w]`.
25
+ */
26
+ export declare function jacobiPrincipalInertia(ixx: number, iyy: number, izz: number, ixy: number, ixz: number, iyz: number): {
27
+ inertia: Vec3Tuple;
28
+ inertiaFrame: QuatTuple;
29
+ };
30
+ /**
31
+ * Computes exact principal inertia diagonal `[I1, I2, I3]` for a single `KhrColliderShape` of `mass` kg
32
+ * about its centroid.
33
+ */
34
+ export declare function computeShapeInertia(shape: KhrColliderShape, mass: number): Vec3Tuple;
35
+ /**
36
+ * Resolves exact center of mass, full 3x3 Steiner parallel-axis inertia tensor, and Jacobi principal frame
37
+ * for a dynamic `KhrBodySpec` from its colliders when `motion.inertiaDiagonal` is omitted in the `.glb`.
38
+ */
39
+ export declare function resolveBodyMassFromColliders(colliders: readonly KhrColliderSpec[], mass: number, explicitCom: Vec3Tuple | null, explicitInertiaOrientation: QuatTuple | null, nodeName: string): {
40
+ centerOfMass: Vec3Tuple;
41
+ inertiaDiagonal: Vec3Tuple;
42
+ inertiaOrientation: QuatTuple;
43
+ };
25
44
  export declare function computeAssemblyMassAndCom(bodies: readonly KhrBodySpec[]): {
26
45
  totalDynamicMass: number;
27
46
  centerOfMass: Vec3Tuple;
28
47
  };
48
+ export declare function bodyPoseMatrix(body: KhrBodySpec, target?: THREE.Matrix4): THREE.Matrix4;
49
+ export declare function computeLumpedMassProps(bodies: readonly KhrBodySpec[], invFrame?: THREE.Matrix4): LumpedMassProps | null;
29
50
  /**
30
- * Builds a `RigidBody`-local mass specification from a `KhrBodySpec`.
31
- * When `hasExplicitInertia` is false, Rapier WASM (`parry3d`) computes exact volume, CoM,
32
- * parallel-axis tensor, and principal inertia directly from the attached colliders.
33
- */
34
- export declare function buildBodyMassTarget(body: KhrBodySpec, bodyRotInRigidBody?: readonly [number, number, number, number], bodyOffsetInRigidBody?: readonly [number, number, number]): RapierBodyMassTarget | null;
35
- /**
36
- * Applies `KHR_physics_rigid_bodies` mass properties to a live Rapier WASM `RigidBody`:
37
- * - Explicit `motion.inertiaDiagonal`: passes authored `{ mass, com, inertiaDiagonal, inertiaFrame }` directly to Rapier.
38
- * - Omitted `motion.inertiaDiagonal`: delegates volume, CoM, parallel-axis lumping, and Jacobi principal-axis inertia
39
- * to Rapier's Rust `parry3d` engine across all attached colliders, preserving explicit `motion.centerOfMass` if authored.
51
+ * Applies exact `LumpedMassProps` directly in `RigidBody` local space (`density = 0` on colliders).
40
52
  */
41
- export declare function applyRapierBodyMass(rb: RapierRigidBody, target: RapierBodyMassTarget | null): void;
53
+ export declare function applyRapierBodyMass(rb: RapierRigidBody, lumped: LumpedMassProps | null): void;