@khr3/core 0.2.0 → 0.2.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,18 +1,24 @@
1
- import { type KhrBodySpec, type KhrJointSpec } from "./khrTypes.js";
1
+ import * as THREE from "three";
2
+ import type RAPIER from "@dimforge/rapier3d-compat";
3
+ import { type KhrBreakawaySpec, type KhrJointDriveSpec, type KhrJointSpec } from "./khrTypes.js";
2
4
  import type { JointRuntime } from "./physicsEcs.js";
3
- /**
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.
7
- */
8
- export declare function effectiveJointInertia(body: KhrBodySpec, joint: KhrJointSpec, descendants?: readonly KhrBodySpec[]): number;
9
- /**
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.
15
- */
16
- export declare function stepJoint(j: JointRuntime, dt: number): void;
17
- /** Writes `q` onto the live glTF node and re-poses its compound colliders inside the root body when moved. */
18
- export declare function writeJointPose(j: JointRuntime, frame: number): void;
5
+ export declare function createRapierImpulseJoint(rapier: typeof RAPIER, world: RAPIER.World, parentBody: RAPIER.RigidBody, childBody: RAPIER.RigidBody, joint: KhrJointSpec, anchorParent: readonly [number, number, number], anchorChild: readonly [number, number, number], axisParent: readonly [number, number, number], axisChild: readonly [number, number, number], restFrameRelQuat: readonly [number, number, number, number]): RAPIER.ImpulseJoint;
6
+ export declare function configureJointDrive(rapier: typeof RAPIER, imp: RAPIER.ImpulseJoint, kind: KhrJointSpec["kind"], drive: KhrJointDriveSpec | null, targetPos: number | null): void;
7
+ export declare function measureJointCoordinate(parentBody: RAPIER.RigidBody | null, childBody: RAPIER.RigidBody | null, kind: KhrJointSpec["kind"], axisParent: readonly [number, number, number], anchorParent: readonly [number, number, number], restRelQuat: readonly [number, number, number, number]): number;
8
+ export declare function buildJointRuntime(params: {
9
+ rapier: typeof RAPIER;
10
+ world?: RAPIER.World;
11
+ nodeName: string;
12
+ role: string | null;
13
+ kind: KhrJointSpec["kind"];
14
+ object: THREE.Object3D;
15
+ axisParent: readonly [number, number, number];
16
+ anchorParent: readonly [number, number, number];
17
+ restRelQuat: readonly [number, number, number, number];
18
+ limits: [number, number] | null;
19
+ drive: KhrJointDriveSpec | null;
20
+ breakaway?: KhrBreakawaySpec;
21
+ rapierJoint: RAPIER.ImpulseJoint;
22
+ parentBody: RAPIER.RigidBody;
23
+ childBody: RAPIER.RigidBody;
24
+ }): JointRuntime;
@@ -1,6 +1,7 @@
1
1
  import * as THREE from "three";
2
- import { type KhrAssetBundle, type KhrPluginOptions } from "./khrTypes.js";
2
+ import { type KhrAssetBundle, type KhrBreakawaySpec, type KhrPluginOptions } from "./khrTypes.js";
3
3
  export { decodePropellerTag, decodeWheelTag } from "./khrRotorDecoders.js";
4
+ export declare function decodeBreakawaySpec(raw: unknown): KhrBreakawaySpec | undefined;
4
5
  export interface KhrNodeMeta {
5
6
  nodeName: string;
6
7
  extras: Record<string, unknown>;
package/dist/khrGlb.d.ts CHANGED
@@ -23,10 +23,6 @@ export interface RawGltfJson {
23
23
  wheels?: Array<Record<string, unknown>>;
24
24
  [k: string]: unknown;
25
25
  };
26
- KHR3_vfx_emitter?: {
27
- emitters?: Array<Record<string, unknown>>;
28
- [k: string]: unknown;
29
- };
30
26
  KOLMO_emitter?: Record<string, unknown>;
31
27
  KHR_lights_punctual?: {
32
28
  lights?: Array<Record<string, unknown>>;
@@ -43,7 +39,6 @@ export interface RawGltfJson {
43
39
  OMI_vehicle_wheel?: {
44
40
  wheel?: number;
45
41
  } | Record<string, unknown>;
46
- KHR3_vfx_emitter?: Record<string, unknown>;
47
42
  KOLMO_emitter?: Record<string, unknown>;
48
43
  KHR_lights_punctual?: Record<string, unknown>;
49
44
  [ext: string]: unknown;
@@ -67,6 +67,10 @@ export interface KhrJointSpec {
67
67
  anchor2: [number, number, number];
68
68
  role: string | null;
69
69
  }
70
+ export interface KhrBreakawaySpec {
71
+ latchImpulseNs?: number;
72
+ breakImpulseNs: number;
73
+ }
70
74
  export interface KhrBodySpec {
71
75
  nodeName: string;
72
76
  isKinematic: boolean;
@@ -81,6 +85,7 @@ export interface KhrBodySpec {
81
85
  localQuaternion: [number, number, number, number];
82
86
  colliders: KhrColliderSpec[];
83
87
  joint: KhrJointSpec | null;
88
+ breakaway?: KhrBreakawaySpec;
84
89
  object: THREE.Object3D;
85
90
  role: string | null;
86
91
  }
@@ -1,24 +1,22 @@
1
- import * as THREE from "three";
2
- import type { RapierCollider } from "@react-three/rapier";
3
- import { type KhrBodySpec, type KhrColliderSpec, type KhrJointSpec } from "./khrTypes.js";
1
+ import { type ColliderMass, type PlannedCollider } from "./assemblyPlan.js";
2
+ import { type KhrBodySpec, type KhrJointSpec } from "./khrTypes.js";
4
3
  import type { JointRuntime } from "./physicsEcs.js";
5
- export interface PlannedVehicleJointCollider {
6
- spec: KhrColliderSpec;
7
- local: THREE.Matrix4;
8
- position: [number, number, number];
9
- quaternion: [number, number, number, number];
10
- }
4
+ type Vec3 = [number, number, number];
5
+ type Quat = [number, number, number, number];
11
6
  export interface PlannedVehiclePart {
12
7
  spec: KhrBodySpec;
13
8
  joint: KhrJointSpec;
14
9
  parent: PlannedVehiclePart | null;
15
- restRelParent: THREE.Matrix4;
16
- inertia: number;
17
- colliders: PlannedVehicleJointCollider[];
10
+ restRelParentPos: Vec3;
11
+ restRelParentQuat: Quat;
12
+ restRelChassisPos: Vec3;
13
+ restRelChassisQuat: Quat;
14
+ axisParent: Vec3;
15
+ axisChild: Vec3;
16
+ partMass?: ColliderMass;
17
+ colliders: PlannedCollider[];
18
18
  }
19
19
  export declare function planVehicleJointParts(bodies: readonly KhrBodySpec[]): PlannedVehiclePart[];
20
20
  export declare function openTargetForLimits(limits: readonly [number, number]): number;
21
21
  export declare function isVehicleJointOpen(rt: JointRuntime): boolean;
22
- export declare function createVehicleJointRuntime(part: PlannedVehiclePart, assemblyId: number, parent: JointRuntime | null, colliderRefs: ReadonlyArray<{
23
- current: RapierCollider | null;
24
- }>): JointRuntime;
22
+ export {};
@@ -1,18 +1,24 @@
1
1
  import React from "react";
2
2
  import * as THREE from "three";
3
+ import { type RapierRigidBody } from "@react-three/rapier";
3
4
  import type { EcctrlVehicleHandle } from "@pinkaphant/ecctrl/vehicle";
4
5
  import { type KhrBodySpec } from "./khrTypes.js";
6
+ import { type JointRuntime } from "./physicsEcs.js";
5
7
  export interface KhrVehicleJointsHandle {
6
8
  readonly hasJoints: boolean;
7
9
  readonly jointNames: readonly string[];
10
+ getBody: (nodeName: string) => RapierRigidBody | null;
11
+ getJointRuntime: (nodeName: string) => JointRuntime | null;
8
12
  getJointAngle: (nodeName: string) => number | null;
9
13
  setJointTarget: (nodeName: string, target: number) => void;
10
14
  setRoleTarget: (role: string, target: number) => void;
11
15
  toggleHitObject: (hit: THREE.Object3D | null) => boolean;
12
16
  toggleRolePrefix: (prefix: string) => void;
13
17
  }
14
- export declare function KhrVehicleJoints({ bodies, vehicleRef, jointsRef, }: {
18
+ export declare function KhrVehicleJoints({ bodies, vehicleRef, spawnPos, spawnQuat, jointsRef, }: {
15
19
  bodies: readonly KhrBodySpec[];
16
20
  vehicleRef: React.RefObject<EcctrlVehicleHandle | null>;
21
+ spawnPos: readonly [number, number, number];
22
+ spawnQuat: readonly [number, number, number, number];
17
23
  jointsRef?: React.Ref<KhrVehicleJointsHandle>;
18
24
  }): React.JSX.Element | null;
@@ -4,22 +4,20 @@ import type { EcctrlVehicleHandle } from "@pinkaphant/ecctrl/vehicle";
4
4
  import { captureSubtreeOrigins, type SubtreeOrigin } from "./BundleSceneHost.js";
5
5
  export type RotorOrigin = SubtreeOrigin;
6
6
  export declare const captureRotorOrigins: typeof captureSubtreeOrigins;
7
- export declare function isZeroGravityVec(x: number, y: number, z: number): boolean;
8
7
  export declare function resetAllWheelHits(handle: EcctrlVehicleHandle | null): void;
9
- export declare function ZeroGWheelPreGuard({ vehicleRef, enable, enableCustomGravity, spawnPos, wheelActiveRef, zeroGRef, customPrimedRef, needsEpochBumpRef, onZeroGChange, onCustomPrimed, onBumpWheelEpoch, }: {
8
+ /**
9
+ * Gates `<ShapeCastWheel>` only when gravity is non-zero (`gravityMag > 1e-6`), preventing
10
+ * `ShapeCastWheel`'s internal `smoothedLngImpulse += Infinity` closure poisoning in 0G.
11
+ */
12
+ export declare function ZeroGWheelGate({ vehicleRef, enable, enableCustomGravity, spawnPos, zeroGRef, onZeroGChange, }: {
10
13
  vehicleRef: React.RefObject<EcctrlVehicleHandle | null>;
11
14
  enable: boolean;
12
15
  enableCustomGravity: boolean;
13
16
  spawnPos: readonly [number, number, number];
14
- wheelActiveRef: React.RefObject<boolean>;
15
17
  zeroGRef: React.RefObject<boolean>;
16
- customPrimedRef: React.RefObject<boolean>;
17
- needsEpochBumpRef: React.RefObject<boolean>;
18
- onZeroGChange: (zeroG: boolean) => void;
19
- onCustomPrimed: () => void;
20
- onBumpWheelEpoch: () => void;
18
+ onZeroGChange: (isZeroG: boolean) => void;
21
19
  }): null;
22
- export declare function ZeroGWheelPostGuard({ vehicleRef, zeroGRef, }: {
20
+ export declare function ZeroGWheelPostClear({ vehicleRef, zeroGRef, }: {
23
21
  vehicleRef: React.RefObject<EcctrlVehicleHandle | null>;
24
22
  zeroGRef: React.RefObject<boolean>;
25
23
  }): null;