@khr3/core 0.1.1 → 0.1.2

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.
@@ -1,15 +1,17 @@
1
1
  import type { JointRuntime } from "./physicsEcs.js";
2
2
  import { type KhrBodySpec, type KhrJointSpec } from "./khrTypes.js";
3
3
  /**
4
- * Effective inertia of a jointed body about its joint axis (axis through the node origin, in node-local frame).
5
- * Revolute: I = aᵀ·R·diag(I)·Rᵀ·a + m·(|c|² − (a·c)²) (parallel-axis theorem). Prismatic: m.
4
+ * Effective inertia of a jointed subtree `[body, ...descendants]` about `body`'s joint axis
5
+ * (axis through `body`'s node origin, in `body`'s rest frame).
6
+ * Revolute: Sum_k [ a^T * R_k * diag(I_k) * R_k^T * a + m_k * (|c_k|^2 - (a . c_k)^2) ]. Prismatic: Sum_k m_k.
6
7
  */
7
- export declare function effectiveJointInertia(body: KhrBodySpec, joint: KhrJointSpec): number;
8
+ export declare function effectiveJointInertia(body: KhrBodySpec, joint: KhrJointSpec, descendants?: readonly KhrBodySpec[]): number;
8
9
  /**
9
- * Advances one joint by `dt` seconds with the authored KHR drive (implicit spring–damper, unconditionally stable):
10
- * force mode: I·a = k·(q* − q) + c·(v* − v)
11
- * acceleration mode: a = k·(q* − q) + c·(v* − v)
12
- * Soft limits add their authored limit spring/damper outside [min, max]; hard limits clamp and zero the rate.
10
+ * Advances one joint by `dt` seconds with the authored KHR drive (implicit spring-damper, unconditionally stable):
11
+ * force mode: I * a = k * (q* - q) + c * (v* - v)
12
+ * acceleration mode: a = k * (q* - q) + c * (v* - v)
13
+ * Soft limits add physical restoring stiffness/damping scaled by `1 / I` outside [min, max];
14
+ * hard limits (`limitStiffness === null`) clamp position and inward-Zero velocity.
13
15
  */
14
16
  export declare function stepJoint(j: JointRuntime, dt: number): void;
15
17
  /** Writes `q` onto the live glTF node and re-poses its compound colliders inside the root body when moved. */
@@ -0,0 +1,16 @@
1
+ import * as THREE from "three";
2
+ import type { KhrBodySpec } from "./khrTypes.js";
3
+ export type Vec3Tuple = [number, number, number];
4
+ export type QuatTuple = [number, number, number, number];
5
+ export interface LumpedMassProps {
6
+ mass: number;
7
+ com: Vec3Tuple;
8
+ inertia: Vec3Tuple;
9
+ inertiaFrame: QuatTuple;
10
+ }
11
+ export declare function bodyPoseMatrix(body: KhrBodySpec, target?: THREE.Matrix4): THREE.Matrix4;
12
+ export declare function jacobiPrincipalInertia(ixx: number, iyy: number, izz: number, ixy: number, ixz: number, iyz: number): {
13
+ inertia: Vec3Tuple;
14
+ inertiaFrame: QuatTuple;
15
+ };
16
+ export declare function computeLumpedMassProps(bodies: readonly KhrBodySpec[], invFrame?: THREE.Matrix4): LumpedMassProps | null;
@@ -1,18 +1,17 @@
1
1
  import * as THREE from "three";
2
2
  import type { EcctrlVehicleProps } from "@pinkaphant/ecctrl/vehicle";
3
+ import { type QuatTuple, type Vec3Tuple } from "./khrMassProps.js";
3
4
  import { type KhrBodySpec, type KhrColliderSpec } from "./khrTypes.js";
4
- type Vec3 = [number, number, number];
5
- type Quat = [number, number, number, number];
6
5
  export declare function assertVehicleProps(scale: unknown, colliders: unknown): void;
7
- export declare function readPosTuple(pos: EcctrlVehicleProps["position"]): Vec3;
8
- export declare function readSpawnQuat(rotation: EcctrlVehicleProps["rotation"], quaternion: EcctrlVehicleProps["quaternion"]): Quat;
6
+ export declare function readPosTuple(pos: EcctrlVehicleProps["position"]): Vec3Tuple;
7
+ export declare function readSpawnQuat(rotation: EcctrlVehicleProps["rotation"], quaternion: EcctrlVehicleProps["quaternion"]): QuatTuple;
9
8
  export declare function computeChassisMassProps(bodies: readonly KhrBodySpec[]): {
10
9
  mass: number;
11
- com: Vec3;
12
- inertia: Vec3;
13
- inertiaFrame: Quat;
14
- linearVelocity?: Vec3;
15
- angularVelocity?: Vec3;
10
+ com: Vec3Tuple;
11
+ inertia: Vec3Tuple;
12
+ inertiaFrame: QuatTuple;
13
+ linearVelocity?: Vec3Tuple;
14
+ angularVelocity?: Vec3Tuple;
16
15
  gravityFactor?: number;
17
16
  };
18
17
  export declare function buildChassisColliders(bodies: readonly KhrBodySpec[], com: readonly [number, number, number]): Array<{
@@ -20,4 +19,3 @@ export declare function buildChassisColliders(bodies: readonly KhrBodySpec[], co
20
19
  spec: KhrColliderSpec;
21
20
  }>;
22
21
  export declare function computeRotorLocalMatrix(node: THREE.Object3D, scene: THREE.Object3D, center: readonly [number, number, number], quaternion?: readonly [number, number, number, number]): THREE.Matrix4;
23
- export {};
@@ -2,7 +2,6 @@ import React from "react";
2
2
  import * as THREE from "three";
3
3
  import type { EcctrlVehicleHandle, WheelInfoType } from "@pinkaphant/ecctrl/vehicle";
4
4
  import { captureSubtreeOrigins, type SubtreeOrigin } from "./BundleSceneHost.js";
5
- import { type VehicleSettleState } from "./khrVehicleSettle.js";
6
5
  export type RotorOrigin = SubtreeOrigin;
7
6
  export declare const captureRotorOrigins: typeof captureSubtreeOrigins;
8
7
  export declare function RotorVisualSlot({ object, center, quaternion, scene, origin, }: {
@@ -12,37 +11,18 @@ export declare function RotorVisualSlot({ object, center, quaternion, scene, ori
12
11
  scene: THREE.Object3D;
13
12
  origin?: RotorOrigin;
14
13
  }): React.JSX.Element;
15
- export declare function clearWheelImpulses(w: WheelInfoType): void;
16
- export interface CustomGravityStepDelta {
17
- active: boolean;
18
- preX: number;
19
- preY: number;
20
- preZ: number;
21
- dx: number;
22
- dy: number;
23
- dz: number;
24
- }
25
- export declare function GravityReadyGate(p: {
14
+ export declare function syncWheelEnableState(w: WheelInfoType, active: boolean): void;
15
+ /**
16
+ * Lightweight state sync around `<EcctrlVehicle>` and `<ShapeCastWheel>`:
17
+ * - zeroes residual wheel impulses before `<EcctrlVehicle>` when `<PhysicsWorld>` `dt === 0` (imperative `timeScale` hitstop)
18
+ * - evaluates spatial 0G from the live gravity field after each physics step so `<ShapeCastWheel>` disables before `0 / 0` `NaN`
19
+ * - wakes Rapier rigid bodies on driver/drone input edges without mutating active wheel impulses
20
+ */
21
+ export declare function VehicleStateSync({ vehicleRef, active, enableCustomGravity, disabledWheels, spatialZeroGRef, setSpatialZeroG, }: {
26
22
  vehicleRef: React.RefObject<EcctrlVehicleHandle | null>;
27
- enable: boolean;
23
+ active: boolean;
28
24
  enableCustomGravity: boolean;
29
- gravDeltaRef: React.RefObject<CustomGravityStepDelta>;
25
+ disabledWheels: ReadonlySet<string>;
30
26
  spatialZeroGRef: React.RefObject<boolean>;
31
27
  setSpatialZeroG: React.Dispatch<React.SetStateAction<boolean>>;
32
- disabledWheels: ReadonlySet<string>;
33
- settleRef: React.RefObject<VehicleSettleState>;
34
- }): null;
35
- export declare function PreWheelVelocityUnbias(p: {
36
- vehicleRef: React.RefObject<EcctrlVehicleHandle | null>;
37
- gravDeltaRef: React.RefObject<CustomGravityStepDelta>;
38
- }): null;
39
- export declare function WheelImpulseSync(p: {
40
- vehicleRef: React.RefObject<EcctrlVehicleHandle | null>;
41
- enable: boolean;
42
- enableCustomGravity: boolean;
43
- gravDeltaRef: React.RefObject<CustomGravityStepDelta>;
44
- disabledWheels: ReadonlySet<string>;
45
- settleRef: React.RefObject<VehicleSettleState>;
46
- rollCenterHeight?: number;
47
- antiRollStiffness?: number;
48
28
  }): null;
@@ -1,3 +1,4 @@
1
+ import { type RefObject } from "react";
1
2
  import type * as THREE from "three";
2
3
  import type { RapierCollider } from "@react-three/rapier";
3
4
  import type { KhrJointDriveSpec, KhrJointSpec } from "./khrTypes.js";
@@ -10,7 +11,7 @@ export interface JointCollider {
10
11
  }
11
12
  /**
12
13
  * Runtime state of one articulated glTF node. The node stays in the live scene graph and the
13
- * root `RigidBody` carries its authored mass as compound colliders; `PhysicsWorld` integrates `q`.
14
+ * root `RigidBody` carries composite authored mass; `PhysicsWorld` integrates `q`.
14
15
  */
15
16
  export interface JointRuntime {
16
17
  assemblyId: number;
@@ -31,7 +32,7 @@ export interface JointRuntime {
31
32
  limits: [number, number] | null;
32
33
  limitStiffness: number | null;
33
34
  limitDamping: number;
34
- /** Effective inertia about the joint axis (kg·m² revolute, kg prismatic). */
35
+ /** Effective inertia about the joint axis (kg*m^2 revolute, kg prismatic). */
35
36
  inertia: number;
36
37
  parent: JointRuntime | null;
37
38
  /** Rest pose relative to the parent joint's frame (or the root body frame when `parent` is null). */
@@ -51,3 +52,7 @@ export type JointRegistry = Set<JointRuntime>;
51
52
  export declare const JointRegistryContext: import("react").Context<JointRegistry | null>;
52
53
  /** Reactive gravity tuple provided by `<PhysicsWorld>` so `<KhrVehicle>` updates before `world.gravity` effects lag. */
53
54
  export declare const WorldGravityContext: import("react").Context<readonly [number, number, number] | null>;
55
+ /** Reactive active flag provided by `<PhysicsWorld>` (`false` when paused or non-positive step/scale). */
56
+ export declare const WorldActiveContext: import("react").Context<boolean>;
57
+ /** Mutable current-frame physics `dt` ref (`0` when paused or `timeScale <= 0`), set at `priority = -0.5` before child `useFrame`s. */
58
+ export declare const WorldStepDtContext: import("react").Context<RefObject<number> | null>;
package/dist/vehicle.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export { KhrVehicle, WHEEL_ASSEMBLY_DENSITY_KG_M3, type KhrVehicleProps, type KhrWheelConfig } from "./KhrVehicle.js";
2
- export { BENCH_GRAVITY, solveWheelLoads, type SolvedWheel } from "./wheelLoads.js";
2
+ export { BENCH_GRAVITY, boundWheelModalDamping, solveWheelLoads, type SolvedWheel } from "./wheelLoads.js";