@khr3/core 0.2.10 → 0.2.12

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.
Files changed (55) hide show
  1. package/README.md +8 -0
  2. package/dist/KhrAssembly.d.ts +44 -8
  3. package/dist/KhrCollider.d.ts +25 -7
  4. package/dist/clone.d.ts +45 -0
  5. package/dist/decoders.d.ts +30 -0
  6. package/dist/{khrExporter.d.ts → exporter.d.ts} +2 -2
  7. package/dist/{khrGlb.d.ts → glb.d.ts} +4 -3
  8. package/dist/index.d.ts +10 -9
  9. package/dist/index.js +1087 -926
  10. package/dist/index.js.map +1 -1
  11. package/dist/inertia.d.ts +41 -0
  12. package/dist/joints-5IgWDD2w.js +865 -0
  13. package/dist/joints-5IgWDD2w.js.map +1 -0
  14. package/dist/{jointDynamics.d.ts → joints.d.ts} +10 -7
  15. package/dist/loader.d.ts +9 -0
  16. package/dist/types.d.ts +284 -0
  17. package/dist/useKhrGlb.d.ts +6 -1
  18. package/dist/vehicle.d.ts +22 -2
  19. package/dist/vehicle.js +617 -665
  20. package/dist/vehicle.js.map +1 -1
  21. package/dist/vehicleJoints.d.ts +50 -0
  22. package/dist/wheelLoads.d.ts +5 -4
  23. package/package.json +4 -16
  24. package/dist/AssemblyRootBody.d.ts +0 -16
  25. package/dist/BundleSceneHost.d.ts +0 -23
  26. package/dist/KhrVehicle.d.ts +0 -20
  27. package/dist/assemblyPlan.d.ts +0 -61
  28. package/dist/curves.d.ts +0 -378
  29. package/dist/curves.js +0 -542
  30. package/dist/curves.js.map +0 -1
  31. package/dist/khrBundleFinalize.d.ts +0 -15
  32. package/dist/khrClone.d.ts +0 -14
  33. package/dist/khrConfigTypes.d.ts +0 -62
  34. package/dist/khrExportEncoders.d.ts +0 -8
  35. package/dist/khrExtras.d.ts +0 -22
  36. package/dist/khrInertia.d.ts +0 -18
  37. package/dist/khrJointParser.d.ts +0 -3
  38. package/dist/khrLoader.d.ts +0 -7
  39. package/dist/khrMassProps.d.ts +0 -16
  40. package/dist/khrParsers.d.ts +0 -10
  41. package/dist/khrPlugin.d.ts +0 -8
  42. package/dist/khrPluginHelpers.d.ts +0 -26
  43. package/dist/khrRotorDecoders.d.ts +0 -4
  44. package/dist/khrShapeParser.d.ts +0 -8
  45. package/dist/khrTypes.d.ts +0 -141
  46. package/dist/khrVehicleChassis.d.ts +0 -20
  47. package/dist/khrVehicleJointHelpers.d.ts +0 -37
  48. package/dist/khrVehicleJoints.d.ts +0 -30
  49. package/dist/khrVehicleRotors.d.ts +0 -22
  50. package/dist/khrVehicleSlots.d.ts +0 -41
  51. package/dist/khrVehicleTypes.d.ts +0 -52
  52. package/dist/pacejka.d.ts +0 -22
  53. package/dist/physicsEcs-Bi0ikONC.js +0 -1156
  54. package/dist/physicsEcs-Bi0ikONC.js.map +0 -1
  55. package/dist/physicsEcs.d.ts +0 -25
package/README.md ADDED
@@ -0,0 +1,8 @@
1
+ # `@khr3/core`
2
+
3
+ Khronos `KHR_physics_rigid_bodies` + `KHR_implicit_shapes` + `OMI_vehicle_wheel` loader, exporter, Rapier WASM assembly, and `@pinkaphant/ecctrl` vehicle rig for React Three Fiber.
4
+
5
+ ## Entrypoints
6
+
7
+ - `@khr3/core` — `loadKhrGlb`, `useKhrGlb`, `exportKhrGlb`, `cloneKhrBundle`, `disposeKhrBundle`, `PhysicsWorld`, `KhrAssembly`, `KhrCollider`, `JointRegistryContext`
8
+ - `@khr3/core/vehicle` — `KhrVehicle`, `solveWheelLoads`
@@ -1,15 +1,50 @@
1
1
  import React from "react";
2
- import type { ThreeElements } from "@react-three/fiber";
3
- import type { RapierRigidBody } from "@react-three/rapier";
4
- import { type AssemblyRigidBodyProps } from "./AssemblyRootBody.js";
5
- import { type KhrAssetBundle } from "./khrTypes.js";
2
+ import * as THREE from "three";
3
+ import { type ThreeElements } from "@react-three/fiber";
4
+ import { type RapierRigidBody, type RigidBodyProps } from "@react-three/rapier";
5
+ import { type RapierBodyMassTarget } from "./inertia.js";
6
+ import { type JointRuntime, type KhrAssetBundle, type KhrBodySpec, type KhrColliderSpec, type KhrJointSpec } from "./types.js";
7
+ type Vec3 = [number, number, number];
8
+ type Quat = [number, number, number, number];
9
+ export interface PlannedCollider {
10
+ spec: KhrColliderSpec;
11
+ position: Vec3;
12
+ quaternion: Quat;
13
+ density?: number;
14
+ }
15
+ export interface PartPlan {
16
+ spec: KhrBodySpec;
17
+ joint: KhrJointSpec;
18
+ parent: PartPlan | null;
19
+ restRelParentPos: Vec3;
20
+ restRelParentQuat: Quat;
21
+ restRelRootPos: Vec3;
22
+ restRelRootQuat: Quat;
23
+ axisParent: Vec3;
24
+ axisChild: Vec3;
25
+ massTarget: RapierBodyMassTarget | null;
26
+ colliders: PlannedCollider[];
27
+ }
28
+ export interface RootPlan {
29
+ spec: KhrBodySpec;
30
+ sceneInRootPos: Vec3;
31
+ sceneInRootQuat: Quat;
32
+ mountNode: THREE.Object3D;
33
+ mountPosition: Vec3;
34
+ mountQuaternion: Quat;
35
+ massTarget: RapierBodyMassTarget | null;
36
+ colliders: PlannedCollider[];
37
+ parts: PartPlan[];
38
+ }
39
+ export declare function planAssembly(bundle: KhrAssetBundle): RootPlan[];
40
+ export type AssemblyRigidBodyProps = Omit<RigidBodyProps, "type" | "position" | "rotation" | "quaternion" | "colliders" | "children" | "ref">;
6
41
  export interface KhrAssemblyHandle {
7
- /** RigidBody owning `nodeName`, or null if absent from the KHR bundle. */
42
+ readonly jointNames: readonly string[];
8
43
  getBody: (nodeName: string) => RapierRigidBody | null;
9
- /** Sets the authored Rapier motor position target on one articulated node. */
44
+ getJointRuntime: (nodeName: string) => JointRuntime | null;
10
45
  setJointTarget: (nodeName: string, target: number) => void;
11
- /** Sets the motor position target on every articulated node whose `extras.role` matches. */
12
46
  setRoleTarget: (role: string, target: number) => void;
47
+ toggleHitObject: (hit: THREE.Object3D | null) => boolean;
13
48
  }
14
49
  type GroupProps = Omit<ThreeElements["group"], "ref" | "position" | "rotation" | "quaternion" | "scale" | "children">;
15
50
  export interface KhrAssemblyProps extends GroupProps {
@@ -20,8 +55,9 @@ export interface KhrAssemblyProps extends GroupProps {
20
55
  quaternion?: [number, number, number, number];
21
56
  scale?: ThreeElements["group"]["scale"];
22
57
  fixedRoot?: boolean;
58
+ enableCustomGravity?: boolean;
23
59
  rigidBodyProps?: AssemblyRigidBodyProps;
24
60
  children?: React.ReactNode;
25
61
  }
26
- export declare function KhrAssembly({ ref, bundle, position, rotation, quaternion, scale, fixedRoot, rigidBodyProps, children, ...groupProps }: KhrAssemblyProps): React.JSX.Element;
62
+ export declare function KhrAssembly({ ref, bundle, position, rotation, quaternion, scale, fixedRoot, enableCustomGravity, rigidBodyProps, children, ...groupProps }: KhrAssemblyProps): React.JSX.Element;
27
63
  export {};
@@ -1,18 +1,36 @@
1
1
  import React from "react";
2
2
  import { type RapierCollider } from "@react-three/rapier";
3
- import type { ColliderMass } from "./assemblyPlan.js";
4
- import type { KhrColliderSpec } from "./khrTypes.js";
3
+ import { type KhrColliderSpec } from "./types.js";
4
+ export interface ColliderMass {
5
+ mass: number;
6
+ centerOfMass: {
7
+ x: number;
8
+ y: number;
9
+ z: number;
10
+ };
11
+ principalAngularInertia: {
12
+ x: number;
13
+ y: number;
14
+ z: number;
15
+ };
16
+ angularInertiaLocalFrame: {
17
+ x: number;
18
+ y: number;
19
+ z: number;
20
+ w: number;
21
+ };
22
+ }
23
+ /** `RAPIER.TriMeshFlags.FIX_INTERNAL_EDGES` (144) — merges duplicate vertices and suppresses internal seam ghost normals. */
24
+ export declare const KHR_TRIMESH_FLAGS = 144;
5
25
  export interface KhrColliderProps {
6
26
  c: KhrColliderSpec;
7
- /** Pose override in the parent RigidBody frame; defaults to the authored KHR collider offset. */
8
27
  position?: [number, number, number];
9
28
  quaternion?: [number, number, number, number];
10
- /** Authored body mass carried declaratively by this collider (`density: 0` when omitted). */
29
+ density?: number;
30
+ mass?: number;
11
31
  massProperties?: ColliderMass;
12
- /** Fallback Rapier collision groups when `c.collisionGroups` is omitted. */
13
32
  collisionGroups?: number;
14
- /** Fallback Rapier solver groups when `c.collisionGroups` is omitted. */
15
33
  solverGroups?: number;
16
34
  ref?: React.Ref<RapierCollider>;
17
35
  }
18
- export declare function KhrCollider({ c, position, quaternion, massProperties, collisionGroups, solverGroups, ref }: KhrColliderProps): React.JSX.Element;
36
+ export declare function KhrCollider({ c, position, quaternion, density, mass, massProperties, collisionGroups, solverGroups, ref, }: KhrColliderProps): React.JSX.Element;
@@ -0,0 +1,45 @@
1
+ import React from "react";
2
+ import * as THREE from "three";
3
+ import { type KhrAssetBundle } from "./types.js";
4
+ export declare function registerMountedSubtree(ownerScene: THREE.Object3D, restoreForClone: () => () => void): () => void;
5
+ export declare function claimBundleMount(bundle: KhrAssetBundle, ownerComponent: string): void;
6
+ export declare function releaseBundleMount(bundle: KhrAssetBundle): void;
7
+ /**
8
+ * Returns a structural `Object3D` clone with any mounted `RotorVisualSlot` / `MountSubtreeSlot`
9
+ * subtrees restored synchronously when `root` is currently mounted, or `root` itself otherwise.
10
+ */
11
+ export declare function snapshotSceneWithMountedSubtrees(root: THREE.Object3D): THREE.Object3D;
12
+ /**
13
+ * Clones a parsed `KhrAssetBundle` in O(nodes) while sharing GPU `BufferGeometry` / `Material` buffers
14
+ * and Rapier `Float32Array` collider vertices. Only restores subtrees belonging to `bundle.scene`.
15
+ */
16
+ export declare function cloneKhrBundle(bundle: KhrAssetBundle): KhrAssetBundle;
17
+ export declare function disposeSceneGpuResources(roots: readonly THREE.Object3D[]): void;
18
+ /**
19
+ * Releases mount ownership. On root templates (or when `{ disposeTemplate: true }` is passed on a clone),
20
+ * disposes unique GPU geometries, materials, and textures once.
21
+ */
22
+ export declare function disposeKhrBundle(bundle: KhrAssetBundle, options?: {
23
+ disposeTemplate?: boolean;
24
+ }): void;
25
+ export interface SubtreeOrigin {
26
+ ownerScene: THREE.Object3D;
27
+ origParent: THREE.Object3D | null;
28
+ origIndex: number;
29
+ origOrder: ReadonlyMap<THREE.Object3D, number> | null;
30
+ origPos: THREE.Vector3;
31
+ origQuat: THREE.Quaternion;
32
+ origScale: THREE.Vector3;
33
+ }
34
+ export declare function captureSubtreeOrigins(objects: readonly THREE.Object3D[], explicitScene?: THREE.Object3D): Map<THREE.Object3D, SubtreeOrigin>;
35
+ export declare function restoreSubtreeOrigin(object: THREE.Object3D, snap: SubtreeOrigin): void;
36
+ export declare function BundleSceneHost({ bundle, owner }: {
37
+ bundle: KhrAssetBundle;
38
+ owner: string;
39
+ }): React.JSX.Element;
40
+ export declare function MountSubtreeSlot({ object, position, quaternion, origin, }: {
41
+ object: THREE.Object3D;
42
+ position: [number, number, number];
43
+ quaternion: [number, number, number, number];
44
+ origin?: SubtreeOrigin;
45
+ }): React.JSX.Element;
@@ -0,0 +1,30 @@
1
+ import * as THREE from "three";
2
+ import { type EcctrlPropellerTag, type EcctrlWheelTag, type KhrBodySpec, type KhrBreakawaySpec, type KhrCombineMode, type KhrImplicitShape, type KhrJointSpec, type KhrPluginOptions } from "./types.js";
3
+ export interface KhrNodeMeta {
4
+ nodeName: string;
5
+ extras: Record<string, unknown>;
6
+ worldPosition: [number, number, number];
7
+ contactDots?: Array<[string, [number, number, number]]>;
8
+ }
9
+ export interface KhrTemplateMeta {
10
+ nodes: KhrNodeMeta[];
11
+ bodies: Array<{
12
+ nodeName: string;
13
+ extras: Record<string, unknown>;
14
+ }>;
15
+ ikSockets: Array<[string, [number, number, number]]>;
16
+ }
17
+ export declare function decodeShape(raw: Record<string, unknown>, idx: number): KhrImplicitShape;
18
+ export declare function decodePhysicsMaterial(rawMaterials: Array<Record<string, unknown>>, idx: unknown, ownerName: string): {
19
+ friction?: number;
20
+ restitution?: number;
21
+ frictionCombine?: KhrCombineMode;
22
+ restitutionCombine?: KhrCombineMode;
23
+ };
24
+ export declare function decodeCollisionGroups(rawFilters: Array<Record<string, unknown>>): number[];
25
+ export declare function decodeMotion(motion: Record<string, unknown>, hasMotion: boolean, name: string): Omit<KhrBodySpec, "nodeName" | "localPosition" | "localQuaternion" | "colliders" | "joint" | "object" | "role">;
26
+ export declare function decodeJoint(rawJoints: Array<Record<string, unknown>>, jointIdx: number, nodeName: string, connectedNode: THREE.Object3D, childNode: THREE.Object3D, enableCollision: boolean, role: string | null, connectedNodeName?: string): KhrJointSpec;
27
+ export declare function decodeWheelTag(obj: THREE.Object3D, name: string, rawWheel: unknown, scene?: THREE.Object3D, rawOmiWheel?: unknown): EcctrlWheelTag;
28
+ export declare function decodePropellerTag(obj: THREE.Object3D, name: string, rawPropeller: unknown, scene?: THREE.Object3D): EcctrlPropellerTag;
29
+ export declare function decodeBreakawaySpec(raw: unknown): KhrBreakawaySpec | undefined;
30
+ export declare function collectNodeSockets(obj: THREE.Object3D, name: string, extras: Record<string, unknown>, sockets: Record<string, [number, number, number]>, isSocketNode?: KhrPluginOptions["isSocketNode"]): KhrNodeMeta;
@@ -1,5 +1,5 @@
1
1
  import type * as THREE from "three";
2
- import { patchGlbJsonChunk } from "./khrGlb.js";
3
- import { type KhrExportNodeSpec } from "./khrTypes.js";
2
+ import { patchGlbJsonChunk } from "./glb.js";
3
+ import { type KhrExportNodeSpec } from "./types.js";
4
4
  export { patchGlbJsonChunk };
5
5
  export declare function exportKhrGlb(root: THREE.Object3D, specs: readonly KhrExportNodeSpec[], sceneExtras?: Record<string, unknown>): Promise<ArrayBuffer>;
@@ -1,5 +1,8 @@
1
+ /** ASCII "glTF" little-endian fourCC. */
1
2
  export declare const GLB_MAGIC = 1179937895;
3
+ /** ASCII "JSON" little-endian fourCC. */
2
4
  export declare const GLB_JSON_CHUNK = 1313821514;
5
+ /** ASCII "BIN\0" little-endian fourCC. */
3
6
  export declare const GLB_BIN_CHUNK = 5130562;
4
7
  export interface RawGltfJson {
5
8
  scene?: number;
@@ -23,7 +26,6 @@ export interface RawGltfJson {
23
26
  wheels?: Array<Record<string, unknown>>;
24
27
  [k: string]: unknown;
25
28
  };
26
- KOLMO_emitter?: Record<string, unknown>;
27
29
  KHR_lights_punctual?: {
28
30
  lights?: Array<Record<string, unknown>>;
29
31
  [k: string]: unknown;
@@ -39,7 +41,6 @@ export interface RawGltfJson {
39
41
  OMI_vehicle_wheel?: {
40
42
  wheel?: number;
41
43
  } | Record<string, unknown>;
42
- KOLMO_emitter?: Record<string, unknown>;
43
44
  KHR_lights_punctual?: Record<string, unknown>;
44
45
  [ext: string]: unknown;
45
46
  };
@@ -61,7 +62,7 @@ export interface MutableGltfJson {
61
62
  extensions?: Record<string, unknown>;
62
63
  }>;
63
64
  }
64
- export declare function validateGlbHeader(buffer: ArrayBuffer): number;
65
+ export declare function validateGlbHeader(buffer: ArrayBuffer, byteOffset?: number, byteLength?: number): number;
65
66
  export declare function parseGlbJson(buffer: ArrayBuffer): RawGltfJson;
66
67
  export declare function ensureHeadlessFileReader(): void;
67
68
  export declare function packJsonToGlb(gltf: Record<string, unknown>): ArrayBuffer;
package/dist/index.d.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  export { PhysicsWorld, type PhysicsWorldProps, type TimeControlValue } from "./PhysicsWorld.js";
2
- export { KhrValidationError, createKhrGltfPlugin, loadKhrGlb, type EcctrlPropellerTag, type EcctrlWheelTag, type KhrAssetBundle, type KhrBodySpec, type KhrBreakawaySpec, type KhrCarConfig, type KhrColliderShape, type KhrColliderSpec, type KhrCombineMode, type KhrCurveData, type KhrCurvePoint, type KhrDroneConfig, type KhrExportNodeSpec, type KhrImplicitShape, type KhrJointDriveSpec, type KhrJointSpec, type KhrPluginOptions, type LoadKhrGlbOptions, type OmiVehicleWheelSpec, type UseKhrGlbOptions, } from "./khrLoader.js";
3
- export { exportKhrGlb, patchGlbJsonChunk } from "./khrExporter.js";
4
- export type { MutableGltfJson, RawGltfJson } from "./khrGlb.js";
5
- export { claimBundleMount, cloneKhrBundle, disposeKhrBundle, releaseBundleMount } from "./khrClone.js";
6
- export { assertIdentityWorldScale, assertSceneIdentityWorldScale, assertUnitScale } from "./khrInertia.js";
7
- export { KhrCollider, type KhrColliderProps } from "./KhrCollider.js";
8
- export { KhrAssembly, type KhrAssemblyHandle, type KhrAssemblyProps } from "./KhrAssembly.js";
9
- export { useKhrGlb } from "./useKhrGlb.js";
10
- export { JointRegistryContext, type JointRegistry, type JointRuntime } from "./physicsEcs.js";
2
+ export { JointRegistryContext, KhrValidationError, assignRef, type CurveData, type CurvePoint, type EcctrlPropellerTag, type EcctrlWheelTag, type JointRegistry, type JointRuntime, type KhrAssetBundle, type KhrBodySpec, type KhrBreakawaySpec, type KhrCarConfig, type KhrColliderShape, type KhrColliderSpec, type KhrCombineMode, type KhrCurveData, type KhrCurvePoint, type KhrDroneConfig, type KhrExportNodeSpec, type KhrImplicitShape, type KhrJointDriveSpec, type KhrJointSpec, type KhrPluginOptions, type LoadKhrGlbOptions, type OmiVehicleWheelSpec, type UseKhrGlbOptions, } from "./types.js";
3
+ export { createKhrGltfPlugin, loadKhrGlb } from "./loader.js";
4
+ export { exportKhrGlb, patchGlbJsonChunk } from "./exporter.js";
5
+ export type { MutableGltfJson, RawGltfJson } from "./glb.js";
6
+ export { claimBundleMount, cloneKhrBundle, disposeKhrBundle, releaseBundleMount, snapshotSceneWithMountedSubtrees } from "./clone.js";
7
+ export { applyRapierBodyMass, assertIdentityWorldScale, assertSceneIdentityWorldScale, assertUnitScale, buildBodyMassTarget, type RapierBodyMassTarget, } from "./inertia.js";
8
+ export { KHR_TRIMESH_FLAGS, KhrCollider, type ColliderMass, type KhrColliderProps } from "./KhrCollider.js";
9
+ export { KhrAssembly, planAssembly, type KhrAssemblyHandle, type KhrAssemblyProps } from "./KhrAssembly.js";
10
+ export { KhrGLTFLoader, createScopedGltfLoaderClass, useKhrGlb } from "./useKhrGlb.js";
11
+ export { ATTACHED_PANEL_INTERACTION_GROUPS, DETACHED_PANEL_INTERACTION_GROUPS, buildJointRuntime, closedTargetForLimits, configureJointDrive, createRapierImpulseJoint, isJointOpen, measureJointCoordinate, openTargetForLimits, toggleDrivenJoint, } from "./joints.js";