export interface LibraryAsset {
  id: string; name: string; class: string; summary: string; file: string; release: string;
  /** true metres after scale (width x, length z, height y); front is +Z, origin on the ground */
  size: { w: number; l: number; h: number }; scale: number;
  footprint: { minX: number; maxX: number; minZ: number; maxZ: number };
  collider: Array<Record<string, number | string | boolean>>; sockets: Array<{ name: string; role: string; pos: number[] | null }>;
  role: string | null; notes: string | null; tris: number;
  /** vehicles only: the Paint material recolours the model; paints are linear RGB, the first is the default */
  paint?: { material: string; default: number[]; paints: number[][]; names?: string[] };
  /** vehicles only: node names of the moving parts */
  nodes?: { wheels?: string[]; steer?: string[]; crank?: string[]; doors?: string[]; body?: string[]; turret?: string[]; guns?: string[];
    rotors?: string[]; gear?: string[]; surfaces?: string[]; tracks?: string[];
    /** spacecraft (vehicle.space.*): turrets with their guns, spinning parts, and EMPTY nodes where things come out */
    turrets?: string[]; rings?: string[]; fans?: string[]; arms?: string[]; pods?: string[]; thrusters?: string[]; lifts?: string[];
    muzzles?: string[]; hardpoints?: string[]; hangars?: string[]; docks?: string[];
    moving?: Record<string, { kind: string; axis: number[] }>;
    axes?: Record<string, number[] | { yaw: number[]; pitch: number[] }>; limits?: Record<string, number[] | { yaw: number[]; pitch: number[] }>;
    /** destructible tanks (tank-damage/v1): the damage file's nodes */
    damage?: { states: string[]; parts: Array<{ node: string; twin: string | null; zone: string }>; scars: Record<string, string>;
      broken: Record<string, string>; wreck: { hull: string; turret?: string }; attach: Record<string, string | null> } };
  /** destructible tanks only: path of the damage file (hidden pieces, use lib.damage(object)) */
  damage?: string;
}
export type Paint = number | 'random' | [number, number, number];
export type TankSide = 'front' | 'left' | 'right' | 'rear' | 'turret' | 'turret-front' | 'turret-left' | 'turret-right' | 'turret-rear';
export interface TankDamage {
  state: 'healthy' | 'hit' | 'wreck';
  /** marks + dents on that side; later hits knock panels off (lost = the hidden panel node, clone it for debris) */
  hit(where?: TankSide | { point: any } | any): { side: TankSide | null; dented: any | null; lost: any | null };
  /** thrown track (stop the tank) */ track(which?: 'left' | 'right', broken?: boolean): void;
  /** burst gun (no shots) */ gun(broken?: boolean): void;
  /** every panel off */ strip(): void;
  /** burnt wreck; turretOff: the burnt turret lies beside the hull (returned) */ wreck(opts?: { turretOff?: boolean }): any | null;
  /** back to new */ repair(): void;
}
export interface ColliderBox { type: 'box'; x: number; y: number; z: number; hx: number; hy: number; hz: number; yaw: number; blocksMovement: boolean }
export interface Library {
  manifest: { assets: LibraryAsset[]; lock: string; ktx2?: boolean; draco?: boolean };
  list(): LibraryAsset[]; get(id: string): LibraryAsset;
  load(id: string): Promise<any>;
  place(id: string, at?: { x?: number; y?: number; z?: number; yaw?: number; scene?: any; paint?: Paint }): Promise<{ object: any; colliders: ColliderBox[]; asset: LibraryAsset }>;
  /** vehicles: give this copy its own paint (index, 'random' with a seed, or linear RGB) */
  paint(object: any, which?: Paint, seed?: number): any;
  /** vehicles: moving parts (wheels roll about local X, steer about local Y with rotation.order 'YXZ', crank = pedals) */
  parts(object: any): { wheels: any[]; steer: any[]; crank: any | null; doors: any[]; turret: any | null; guns: any[]; rotors: any[];
    gear: any[]; surfaces: any[]; tracks: any[]; belts: Array<{ move(m: number): any; set(m: number): any; length: number }>;
    /** spacecraft: turret(s) traverse with turn(turret, yaw), their gun with turn(gun, pitch); rings, fans, arms, pods turn too */
    turrets: any[]; rings: any[]; fans: any[]; arms: any[]; pods: any[];
    /** spacecraft: EMPTY nodes (world position + -Z exhaust direction): engine flames, hover glow, shots, missiles, small craft */
    thrusters: any[]; lifts: any[]; muzzles: any[]; hardpoints: any[]; hangars: any[]; docks: any[];
    /** spin/hinge a part about its own card axis (clamped to the card limits) */ turn(node: any, angle: number): any;
    /** guns: yaw + pitch (positive = up), clamped */ aim(gun: any, yaw: number, pitch: number): any;
    /** roll every wheel by metres / radius and move the tank tracks; call each frame with the distance moved */ drive(metres: number): void;
    /** front wheels / bicycle fork */ steerTo(angle: number): void };
  /** destructible tanks: damage states of ONE placed copy (null for models without a damage file) */
  damage(object: any): Promise<TankDamage | null>;
  colliders(id: string, at?: { x?: number; y?: number; z?: number; yaw?: number }): ColliderBox[];
  /** a DRIVEN car: the same rig as the Garage's createVehicle (group, dims, wheels, exhausts, ready, setSteer, spin, setPaint,
   *  player). Synchronous; the model fills `group` when `ready` resolves (preload first). True metres: never rescale. */
  vehicle(id: string, opts?: { paint?: Paint | { body?: number | string; accent?: number | string }; seed?: number }): LibraryVehicleRig;
  preload(ids?: string[]): Promise<void>;
}
export interface LibraryVehicleRig {
  id: string; family: 'library'; group: any; body: any; axles: Array<{ z: number; radius: number; steer: boolean; wheels: any[] }>;
  wheels: any[]; pivots: any[]; exhausts: any[]; lights: { head: any[]; brake: any[] };
  seat: { x: number; y: number; z: number }; grip: { x: number; y: number; z: number; tilt: number; r: number };
  dims: { length: number; width: number; height: number; wheelbase: number; track: number };
  loaded: boolean; failed: boolean; player: boolean; ready: Promise<void>;
  setSteer(radians: number): void; spin(metres: number): void; setPaint(p: Paint | { body?: number | string }): void;
  setTheme(t: any, opts?: { keepPaint?: boolean }): void; setHeadlights(on: boolean): void; setBrake(on: boolean): void; dispose(): void;
}
export function createLibrary(THREE: any, opts?: { base?: string; renderer?: any }): Promise<Library>;
