@adatechnology/game-vehicles-three 0.10.1 → 0.11.1

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/index.d.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  import { E as EngineProfile, V as VehicleSoundKeys, B as BuiltVehicle } from './testing-CRVetKNa.js';
2
2
  export { a as BIKE_ENGINE, b as BuildVehicleOptions, C as CAR_ENGINE, c as CRASH_SPEEDS, D as DEFAULT_TEST_VEHICLES, d as DEFAULT_TEST_WRECKS, e as DEFAULT_VEHICLE_SOUND_KEYS, f as DocumentLike, g as ENGINE_PROFILES, h as EffectsLike, i as EngineLayer, j as EngineLoadLayer, F as FleetDims, M as ModuleRoomLike, P as PAGE_ITEM_ALIASES, k as PAGE_SCENARIO_ALIASES, l as PROVING_AREA_ID, m as PROVING_TEXT, n as ProvingModuleOptions, o as ProvingRoomLike, p as ProvingText, T as TRUCK_ENGINE, q as VEHICLES_AREA_ID, r as VEHICLE_SCENARIO_IDS, s as VehicleEffectIds, t as VehicleFleetContent, u as VehicleQuality, v as VehicleSoundIds, w as VehicleWreck, x as VehiclesContext, y as VehiclesRoom, z as VehiclesTestFleet, A as VehiclesTestOptions, G as VehiclesThree, H as VehiclesThreeOptions, I as createProvingModule, J as createVehiclesTestModule, K as createVehiclesThree, L as defaultEffectIds, N as defaultSoundIds, O as engineProfileOfGroup, Q as hornOfGroup, R as loadProvingModule, S as loadVehiclesTestModule } from './testing-CRVetKNa.js';
3
- import { EffectSink, RainCover, Vec3, AudioSink, AnimationClipSpec, DrawnCollider } from '@adatechnology/game-contracts';
4
- import { CabinSource, VehicleContext, VehicleDestructible } from '@adatechnology/game-vehicles';
3
+ import { EffectSink, RainCover, Vec3, AudioSink, AnimationClipSpec, DrawnCollider, WorkerCoordinator } from '@adatechnology/game-contracts';
4
+ import { CabinSource, VehicleContext, HullPlan, HullPlanResult, VehicleDestructible, PartDef } from '@adatechnology/game-vehicles';
5
+ export { FLAT_PAD, HullFace, HullPlanJob, HullPlanResult, MAX_HULL_POINTS, convexFaces, hullVolume, reducePoints } from '@adatechnology/game-vehicles';
5
6
  import { LoopRecipe, Falloff, SampleAlias, SoundRecipe, SoundBank } from '@adatechnology/game-audio';
6
7
  import * as THREE_NS from 'three';
7
8
  import { Texture, Material, Color, Object3D, Matrix4, MeshStandardMaterial, MeshBasicMaterial, Mesh, Vector3, Box3, CanvasTexture, CircleGeometry, BufferGeometry, Side } from 'three';
8
9
  import { StaticBatchQueue } from '@adatechnology/game-render-three';
10
+ import { Vec3 as Vec3$1, ShapeDesc, BodyId, PhysicsWorld } from '@adatechnology/game-physics';
9
11
  import '@adatechnology/game-vehicles-driving';
10
12
  import '@adatechnology/game-vehicles-proving';
11
13
 
@@ -214,7 +216,7 @@ declare function createVehicleSound(audio: AudioSink | undefined, options?: Vehi
214
216
  * 0.25 and 0.45 emissive) and the colours are the team's.
215
217
  */
216
218
 
217
- type Three$1 = typeof THREE_NS;
219
+ type Three$2 = typeof THREE_NS;
218
220
  /** The six classes of a fused vehicle, in the order they are added to the group. */
219
221
  declare const LITE_CLASSES: readonly ["paint", "trim", "metal", "glass", "light", "plate"];
220
222
  type LiteClass = (typeof LITE_CLASSES)[number];
@@ -257,14 +259,14 @@ declare function classify(mat: LiteSourceMaterial, mesh: Object3D, c: LiteSource
257
259
  /** The vertex colour of a piece of a class. `paintColor` replaces the primary paint. */
258
260
  declare function classColor(mat: LiteSourceMaterial, cls: LiteClass, primary: Material | null | undefined, paintColor: Color | null | undefined, out: Color): Color;
259
261
  /** The material of each class (vertex colours; glass blends; light is unlit; the plate keeps its canvas texture). */
260
- declare function liteMaterials(THREE: Three$1, environment: Texture | null): Record<LiteClass, LiteMaterial>;
262
+ declare function liteMaterials(THREE: Three$2, environment: Texture | null): Record<LiteClass, LiteMaterial>;
261
263
  /**
262
264
  * Walks the built vehicle and collects every visible mesh, in the frame of `pivot`, into one set of arrays per class.
263
265
  * `hidden` is the set of materials nobody sees from outside (`kit.lodHiddenMaterials()`).
264
266
  */
265
- declare function fuse(THREE: Three$1, c: LiteSource, pivot: Matrix4, paintColor: Color | null, primary: Material | null | undefined, hidden: ReadonlySet<Material>): LiteFusion;
267
+ declare function fuse(THREE: Three$2, c: LiteSource, pivot: Matrix4, paintColor: Color | null, primary: Material | null | undefined, hidden: ReadonlySet<Material>): LiteFusion;
266
268
  /** One mesh per class that has triangles. */
267
- declare function liteMeshes(THREE: Three$1, fusion: LiteFusion, materials: Record<LiteClass, LiteMaterial>): Mesh[];
269
+ declare function liteMeshes(THREE: Three$2, fusion: LiteFusion, materials: Record<LiteClass, LiteMaterial>): Mesh[];
268
270
 
269
271
  /** Past this distance (m) an untouched vehicle draws fused: nobody sees a door seam from here, and the full model costs hundreds of draw calls. */
270
272
  declare const VEHICLE_LOD_DISTANCE = 14;
@@ -619,16 +621,84 @@ interface WindshieldMist {
619
621
  }
620
622
  declare function createWindshieldMist(THREE: MistThree, built: BuiltVehicle): WindshieldMist;
621
623
 
622
- type Three = typeof THREE_NS;
624
+ /** A hull and the drawn vertices (x y z triples) it was made from. */
625
+ interface SharedHull {
626
+ readonly hull: VehicleHull;
627
+ readonly drawn: ArrayLike<number>;
628
+ }
629
+ /** The hulls of an intact model, made once: what every car of it is given instead of making them. */
630
+ interface SharedHulls {
631
+ /** The pieces (names and vertex counts) and the hull ceiling it was made for: a car whose pieces differ makes its own. */
632
+ readonly signature: string;
633
+ readonly plan: HullPlan;
634
+ readonly pieces: ReadonlyMap<string, readonly SharedHull[]>;
635
+ /** The solid parts' hulls (one each, whole), filled in by the first car that made them. */
636
+ readonly solids: Map<string, {
637
+ readonly signature: string;
638
+ readonly hulls: VehicleHull[];
639
+ }>;
640
+ }
641
+ /** A division on its way (in a worker): the cars of the same model wait for it instead of sending another. */
642
+ interface HullPlanFlight {
643
+ readonly signature: string;
644
+ readonly promise: Promise<HullPlanResult>;
645
+ }
646
+ interface HullPlanCacheStats {
647
+ readonly models: number;
648
+ /** Divisions made (here or in a worker). */
649
+ readonly planned: number;
650
+ /** Cars given the hulls of a model that was already made. */
651
+ readonly reused: number;
652
+ }
653
+ /**
654
+ * The hulls of the intact models, by model (the vehicle key, its seed key and its build state, and the ceiling): the division of a car is the same for every car of the model, so it is
655
+ * made once. `dispose` lets everything go (design 10.4: the memory is the engine's shapes and these, nothing is kept after).
656
+ */
657
+ interface HullPlanCache {
658
+ get(key: string): SharedHulls | undefined;
659
+ set(key: string, shared: SharedHulls): void;
660
+ flight(key: string): HullPlanFlight | undefined;
661
+ setFlight(key: string, flight: HullPlanFlight): void;
662
+ clearFlight(key: string): void;
663
+ noteReused(): void;
664
+ noteDivided(): void;
665
+ stats(): HullPlanCacheStats;
666
+ dispose(): void;
667
+ }
668
+ declare const createHullPlanCache: () => HullPlanCache;
669
+
670
+ type Three$1 = typeof THREE_NS;
623
671
  interface VehicleCollidersOptions {
624
672
  /** Triangles of work per `pieces()` call: a vehicle that spawns fills in over several calls. Default all at once. */
625
673
  readonly budget?: number;
674
+ /** Keeps what `hulls()` needs (the triangles of each piece); off by default, the pieces alone need none of it. */
675
+ readonly hulls?: boolean;
676
+ /** Hulls the model may have at most: the adaptive division (design 10.3) stops there. Default no limit. */
677
+ readonly maxHulls?: number;
678
+ /** Where the division of the first car of a model is made (CLAUDE.md §14): in a worker, while `hulls()` answers nothing and the car keeps the boxes of `pieces()`. Without it the division is made in the call. */
679
+ readonly workers?: WorkerCoordinator;
680
+ /** The hulls of the models already made, shared by the cars of a model: the second car of a model is given them whole. */
681
+ readonly planCache?: HullPlanCache;
682
+ /** The model this car is of, for `planCache`; default the vehicle's key, seed key and build state. Cars with the same key must be drawn the same when intact. */
683
+ readonly planKey?: string;
684
+ }
685
+ /** A convex hull of drawn vertices (at most 64), in the frame `pieces()` answers in: `id` is the part it belongs to, `key` names it across calls. */
686
+ interface VehicleHull {
687
+ readonly id: string;
688
+ readonly key: string;
689
+ readonly points: Float32Array;
626
690
  }
627
691
  interface VehicleColliders {
628
692
  /** The pieces now: only what changed since the last call is made again. */
629
693
  pieces(): DrawnCollider[];
630
694
  /** Pieces are still to be made (the budget ran out): call `pieces()` again. */
631
695
  isPending(): boolean;
696
+ /** The convex hulls of what is drawn (design 10.1): one hull of the drawn vertices of each piece (part x cell of 0.8 m), a solid part one hull whole, the wheels none; only the pieces a dent touched are made again. Needs `options.hulls`. */
697
+ hulls(): VehicleHull[];
698
+ /** The division is being made in a worker (`options.workers`): `hulls()` answers nothing until it is back, and the one call after that installs it. */
699
+ isHullPending(): boolean;
700
+ /** The drawn vertices (x y z triples, the frame of `pieces()`) a hull of the last `hulls()` call was made from; empty for a hull that is not one of them. */
701
+ drawnPointsOf(hull: VehicleHull): number[];
632
702
  }
633
703
  /**
634
704
  * What a vehicle collides with in an engine, as it is drawn: one piece per part that has a mesh of its own (a door, the hood, the lid, a bumper, a wheel, a tyre, a lamp, a
@@ -639,8 +709,76 @@ interface VehicleColliders {
639
709
  * Kept between calls: where each triangle went is worked out once per mesh, and a call finds what moved (a mesh that was posed, vertices a dent pushed) and makes again only
640
710
  * the pieces it touched.
641
711
  */
642
- declare const createVehicleColliders: (THREE: Three, vehicle: VehicleDestructible, frame: THREE_NS.Object3D, options?: VehicleCollidersOptions) => VehicleColliders;
712
+ declare const createVehicleColliders: (THREE: Three$1, vehicle: VehicleDestructible, frame: THREE_NS.Object3D, options?: VehicleCollidersOptions) => VehicleColliders;
643
713
  /** The pieces of a vehicle once, all at once (`createVehicleColliders` keeps them between calls). */
644
- declare const vehicleColliders: (THREE: Three, vehicle: VehicleDestructible, frame: THREE_NS.Object3D) => DrawnCollider[];
714
+ declare const vehicleColliders: (THREE: Three$1, vehicle: VehicleDestructible, frame: THREE_NS.Object3D) => DrawnCollider[];
715
+ /** The convex hulls of a vehicle once, all at once (`createVehicleColliders` with `hulls` keeps them between calls). */
716
+ declare const vehicleHulls: (THREE: Three$1, vehicle: VehicleDestructible, frame: THREE_NS.Object3D) => VehicleHull[];
717
+
718
+ /** What a body weighs and how it turns: its mass, centre of mass and moments about the principal axes, all in the body's frame. */
719
+ interface BodyMass {
720
+ readonly mass: number;
721
+ readonly centre: Vec3$1;
722
+ readonly inertia: Vec3$1;
723
+ }
724
+ /** Moments of a solid box of `mass` and full `size` about its own centre. */
725
+ declare const boxInertia: (mass: number, size: Vec3$1) => Vec3$1;
726
+ /**
727
+ * What is left of `total` when `part` (its own mass, centre and moments, in the same frame) leaves: the mass, the centre of mass the rest has, and its moments about that
728
+ * centre (the whole's moments about its centre, less the part's about that centre, moved to the rest's centre by the parallel axis theorem).
729
+ */
730
+ declare const withoutPart: (total: BodyMass, part: BodyMass) => BodyMass;
731
+
732
+ type Three = typeof THREE_NS;
733
+ interface CrashPartsOptions {
734
+ readonly THREE: Three;
735
+ readonly world: PhysicsWorld;
736
+ readonly vehicle: VehicleDestructible;
737
+ /** The frame the hulls and the drawn meshes are in (`createVehicleColliders`' frame); its pose is the body's. */
738
+ readonly frame: THREE_NS.Object3D;
739
+ /** Made with `hulls: true`, and its plan back (`isHullPending()` false). */
740
+ readonly colliders: VehicleColliders;
741
+ /** The kit's numbers for the whole car, in the frame: its mass, centre of mass and moments. */
742
+ readonly mass: BodyMass;
743
+ /** A part left the car (the host remakes what depends on it: a wheel, the vehicle's constraint). */
744
+ readonly onPartLost?: (part: PartDef) => void;
745
+ }
746
+ interface CrashParts {
747
+ /** The chassis compound: make the body from it (dynamic, `mass.mass`, `mass.inertia`, `centreAtOrigin` off) and `bind` it. */
748
+ shape(): ShapeDesc;
749
+ bind(chassis: BodyId): void;
750
+ /** Once after each step: the contact rows become damage, the parts' drawings follow their bodies, and a car at rest has its hulls made again. */
751
+ step(): void;
752
+ /** What the car weighs now. */
753
+ mass(): BodyMass;
754
+ partBodies(): ReadonlyMap<string, BodyId>;
755
+ /** The kit's numbers each part that came off took with it (its mass, its centre in the frame, its moments). */
756
+ partNumbers(): ReadonlyMap<string, BodyMass>;
757
+ stats(): {
758
+ readonly released: number;
759
+ readonly pushedOut: number;
760
+ /** Times the hulls were looked at again, how many were given to the engine again, held back by the touching rule, and left without a child to go in. */
761
+ readonly settles: number;
762
+ readonly remade: number;
763
+ readonly held: number;
764
+ readonly unplaced: number;
765
+ /** Blows the contact rows made (`crashVehicle` calls), the damage events they gave, and the parts whose hull was in those rows. */
766
+ readonly blows: number;
767
+ readonly events: number;
768
+ readonly hitParts: ReadonlySet<string>;
769
+ /** Children left in the chassis compound. */
770
+ readonly children: number;
771
+ };
772
+ /** Takes the part bodies out of the world and gives the fling back to the vehicle. The chassis body is the host's. */
773
+ dispose(): void;
774
+ }
775
+ declare const createCrashParts: (options: CrashPartsOptions) => CrashParts;
776
+
777
+ /**
778
+ * The points of a rebuilt hull held to the old one while the part is touching something (design 10.5): a point may move in as far as it likes and out at most `slop` past
779
+ * a face of the old hull, so the rebuilt hull does not push what rests on it (energy made). The points past that are brought back along the face they are past; what
780
+ * is left of the move waits for the contact to end. Returns `next` itself when nothing was past the old hull, and the old points when the old hull is not a solid.
781
+ */
782
+ declare const holdWithin: (old: ArrayLike<number>, next: Float32Array, slop: number) => Float32Array;
645
783
 
646
- export { type BodyEvent, type BodyThree, BuiltVehicle, CAR_RECORDED_RPM, CAR_START_RUN_STOP, type CabinSmoke, DASHBOARD_LOOK, type DashboardOptions, type DashboardReading, type EngineBudget, type EngineBudgetOptions, type EngineLayerSetting, type EngineMixInput, EngineProfile, LAMP_RULES, LITE_CLASSES, type LampSwitch, type LiteClass, type LiteFusion, MIST_RULES, type MistThree, PRUNE_BELOW, RAIN_SHELL_INTERVAL, VEHICLE_LOD_DISTANCE, VEHICLE_LOOPS, VEHICLE_LOOP_FALLOFF, VEHICLE_PRELOAD_SOUNDS, VEHICLE_SAMPLE_ALIASES, VEHICLE_SOUNDS, VEHICLE_SOUND_BANK, type VehicleBody, type VehicleBodyOptions, type VehicleColliders, type VehicleCollidersOptions, type VehicleDashboard, type VehicleLamps, type VehicleLod, type VehicleLodKit, type VehicleRainCovers, type VehicleSound, type VehicleSoundFrame, VehicleSoundKeys, type VehicleSoundOptions, type VehicleSoundReading, type WheelRoll, type WheelRollThree, type WindowId, type WindshieldMist, classColor, classify, createCabinSmoke, createEngineBudget, createGearGuess, createVehicleBody, createVehicleColliders, createVehicleDashboard, createVehicleLamps, createVehicleLod, createVehicleLodQueue, createVehicleRainCovers, createVehicleSound, createWheelRoll, createWindshieldMist, engineMix, firingHz, fuse, layerWeight, liteMaterials, liteMeshes, rpmShare, slideOfGrip, vehicleColliders };
784
+ export { type BodyEvent, type BodyMass, type BodyThree, BuiltVehicle, CAR_RECORDED_RPM, CAR_START_RUN_STOP, type CabinSmoke, type CrashParts, type CrashPartsOptions, DASHBOARD_LOOK, type DashboardOptions, type DashboardReading, type EngineBudget, type EngineBudgetOptions, type EngineLayerSetting, type EngineMixInput, EngineProfile, type HullPlanCache, type HullPlanCacheStats, LAMP_RULES, LITE_CLASSES, type LampSwitch, type LiteClass, type LiteFusion, MIST_RULES, type MistThree, PRUNE_BELOW, RAIN_SHELL_INTERVAL, VEHICLE_LOD_DISTANCE, VEHICLE_LOOPS, VEHICLE_LOOP_FALLOFF, VEHICLE_PRELOAD_SOUNDS, VEHICLE_SAMPLE_ALIASES, VEHICLE_SOUNDS, VEHICLE_SOUND_BANK, type VehicleBody, type VehicleBodyOptions, type VehicleColliders, type VehicleCollidersOptions, type VehicleDashboard, type VehicleHull, type VehicleLamps, type VehicleLod, type VehicleLodKit, type VehicleRainCovers, type VehicleSound, type VehicleSoundFrame, VehicleSoundKeys, type VehicleSoundOptions, type VehicleSoundReading, type WheelRoll, type WheelRollThree, type WindowId, type WindshieldMist, boxInertia, classColor, classify, createCabinSmoke, createCrashParts, createEngineBudget, createGearGuess, createHullPlanCache, createVehicleBody, createVehicleColliders, createVehicleDashboard, createVehicleLamps, createVehicleLod, createVehicleLodQueue, createVehicleRainCovers, createVehicleSound, createWheelRoll, createWindshieldMist, engineMix, firingHz, fuse, holdWithin, layerWeight, liteMaterials, liteMeshes, rpmShare, slideOfGrip, vehicleColliders, vehicleHulls, withoutPart };