@adatechnology/game-vehicles 0.4.7 → 0.6.0

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/README.md CHANGED
@@ -258,6 +258,12 @@ come in `Hit.ignition` (the weapons build them from the core and jacket of the a
258
258
  easiest, a full one mostly leaks); diesel takes a spark far worse than petrol. `createVehicleDestructible(kit, vehicle, { fuel: 0.1, ignition: { fillCurve, fireNear, sparkTarget } })`;
259
259
  the defaults and every number are `IgnitionRules` of `@adatechnology/game-contracts`.
260
260
 
261
+ Cabin and smoke: `cabinEnclosure(car, { frame })` is the cabin (`meta.cabin`, from `kit.interior`) as an `Enclosure` in world space, for the host's
262
+ `EffectSink.enclose`: a shut car keeps the smoke out and seeps only at `CABIN_LEAK` (2 % per second), more with cracked glass. It is open where a door
263
+ or lid stands open (past 6 % of its swing), where a window shattered and where a door, glass, roof or panel was torn off or burnt away; a bullet hole
264
+ lets smoke in at the hole at a rate that grows with its area (a 9 mm hole about 0.2 a second). `null` for a vehicle with no cabin (a bike) or one
265
+ destroyed. `createCabinSmoke()` of `game-vehicles-three` keeps a host told every frame.
266
+
261
267
  ## Português
262
268
 
263
269
  Motor genérico de veículos procedurais para three.js: carrocerias, vidros, faróis, rodas, interiores, capô e compartimento do motor, **zonas de dano
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ToolKind, JointKind, Vec3, MaterialId, DestructibleImpl, AnimationClipSpec, IgnitionRules } from '@adatechnology/game-contracts';
1
+ import { MaterialId, Vec3, JointKind, ToolKind, DeferredQueue, DestructibleImpl, AnimationClipSpec, IgnitionRules, ObjectState, Enclosure } from '@adatechnology/game-contracts';
2
2
 
3
3
  /**
4
4
  * Light mode ("lite"): the same vehicles with fewer triangles, for a whole street of them. Port of the `[LOD]` hooks of the team's Frota Leve
@@ -39,6 +39,18 @@ declare function createLod(options?: Partial<LodSettings>): LodSettings;
39
39
  */
40
40
  declare function wrapThreeForLod(TH: any, lod: LodSettings): any;
41
41
 
42
+ /** Smoke, fire and dust puffs handed to the host's effects world instead of the kit's own sprites. */
43
+ /** What `EffectSink.play` of `game-contracts` takes, as a structural type: this package does not depend on the contracts layer. */
44
+ interface ParticleEffectRequest {
45
+ readonly effect: string;
46
+ readonly point: [number, number, number];
47
+ readonly values: Readonly<Record<string, number>>;
48
+ }
49
+ /** The host's effects world as far as the puffs need it (`EffectSink` of `game-contracts` fits). */
50
+ interface ParticleEffects {
51
+ play(request: ParticleEffectRequest): unknown;
52
+ }
53
+
42
54
  /**
43
55
  * Damageable parts: what a bullet, a bat or a crash can hurt on a built vehicle, as boxes. Port of `coletarDanificaveis` and `tipoDaZona`
44
56
  * (frota-leve.js 14391-14405), driven by the zones the kit already derives, so it works for any vehicle of any pack.
@@ -571,8 +583,25 @@ interface VehicleKitOptions extends KitConfiguration {
571
583
  locale?: string | PartialLocaleStrings;
572
584
  /** Document used for canvas textures and the UI. Defaults to the global `document`. */
573
585
  document?: Document;
586
+ /**
587
+ * Where the material of every smoke, fire and dust puff comes from and goes back to: puffs change their own material every frame (opacity, rotation, dissolve), so each keeps one, but
588
+ * handing them to the host's pool keeps the shader program linked when the last puff dies. Without it each puff makes and disposes its own (deprecated, removed in the next major).
589
+ */
590
+ particleMaterials?: ParticleMaterials;
591
+ /**
592
+ * The host's effects world, read at each puff (the host attaches after the first build). With one, smoke, fire and dust go through it and its one budget; without one the kit draws its own
593
+ * sprites with their own cap (deprecated, removed in the next major).
594
+ */
595
+ effects?: () => ParticleEffects | undefined;
574
596
  plugins?: Plugin[];
575
597
  }
598
+ /** What the host's material pool (`MaterialPool` of `@adatechnology/game-render-three`) lends the particles: a structural type, because this package does not depend on the render layer. */
599
+ interface ParticleMaterials {
600
+ /** Makes (with `build`) a material the caller owns and changes per frame. */
601
+ own<TMaterial>(build: () => TMaterial): TMaterial;
602
+ /** Gives it back: the first of its program family is kept alive, the others are disposed. */
603
+ release(material: unknown): void;
604
+ }
576
605
  interface ImpactOptions {
577
606
  /** Do not leave a stain. */
578
607
  noStain?: boolean;
@@ -782,6 +811,8 @@ interface PartDef {
782
811
  hp: number;
783
812
  /** The damage zone this part is, when it is one. */
784
813
  zoneId?: string;
814
+ /** The panes of a glass part no damage zone claims. */
815
+ panes?: any[];
785
816
  /** Fluid held, in litres. */
786
817
  contains?: {
787
818
  fluid: string;
@@ -827,9 +858,31 @@ declare const JOINT_RULES: Record<'hinge' | 'bolt' | 'weld' | 'glue' | 'clip', {
827
858
  tools: ToolKind[];
828
859
  seconds: number;
829
860
  }>;
830
- /** Builds the part and joint model of a built vehicle. */
831
861
  declare function buildVehicleModel(kit: VehicleKit, c: VehicleContext, options?: ModelOptions): VehicleModel;
832
862
 
863
+ /** What one vehicle's visuals give the shared crease queue: the normal smoothing and the triangle indexes still to finish. */
864
+ interface CreaseWork {
865
+ /** Units waiting; 0 in the frame a panel was torn (that frame already paid for the cut). `frame` is the budget's frame counter. */
866
+ pendingUnits(frame?: number): number;
867
+ /** Runs one slice of the work (a smoothing step or a piece of the index warm-up) until `deadline` on `performance.now()`; false when there was nothing to run. */
868
+ runStep(deadline: number): boolean;
869
+ /** Finishes everything now. */
870
+ finishAll(): void;
871
+ /** While true the vehicle's own update leaves the work to the queue. */
872
+ setQueued(isQueued: boolean): void;
873
+ }
874
+ interface CreaseQueue {
875
+ /** The queue for a frame budget (id `vehicles.crease`, `DEFERRED_PRIORITY['vehicles.crease']`); asking for it changes nothing. */
876
+ deferredQueue(): DeferredQueue;
877
+ /** A vehicle's visuals join the queue; returns the function that takes them out (a rebuilt vehicle, a vehicle that goes away). */
878
+ track(work: CreaseWork): () => void;
879
+ }
880
+ /**
881
+ * One queue for every vehicle of a scene, run round robin over the vehicles with work, so that the first vehicle does not take the whole budget.
882
+ * Until a budget attaches it, each vehicle keeps smoothing in its own `update`.
883
+ */
884
+ declare function createCreaseQueue(): CreaseQueue;
885
+
833
886
  /**
834
887
  * `createVehicleDestructible`: a vehicle that follows the destruction contract of `@adatechnology/game-contracts` and brings its own rules.
835
888
  * Every damage zone and mechanical part is a part with a material, hits become events (dent, hole, crack, fracture, detach, leak, ignite,
@@ -860,6 +913,11 @@ interface VehicleDestructibleOptions {
860
913
  * Defaults and meaning of every number: `IgnitionRules` of `@adatechnology/game-contracts`.
861
914
  */
862
915
  ignition?: Partial<IgnitionRules>;
916
+ /**
917
+ * One queue that smooths the normals of cut panels for every vehicle that shares it (`createCreaseQueue()`), run by a frame budget. Without it, or while
918
+ * nobody registered the queue with a budget, each vehicle smooths in its own `update` (2.5 ms a frame), as always.
919
+ */
920
+ creaseQueue?: CreaseQueue;
863
921
  }
864
922
  /** What the vehicle can do now, from the state of its hidden mechanics. */
865
923
  interface VehicleStatus {
@@ -917,4 +975,49 @@ interface VehicleItem {
917
975
  */
918
976
  declare function buildVehicleItem(kit: VehicleKit, key: string, options?: VehicleItemOptions): VehicleItem;
919
977
 
920
- export { type Band, type BandId, type BandIndex, type BandOverride, type BuildFunction, type BuildOptions, type BuildState, type BuildZoneState, type DamageMapOptions, type DamageZone, type Damageable, type DamageableKind, type DamageableMaterial, type DamageableSide, type ExplodeOptions, type FlagEffect, type FluidDefinition, type ImpactOptions, JOINT_RULES, type JointDef, type KitConfiguration, type KitInternals, type KitTexts, LEGACY_STATES, LEGACY_ZONE_IDS, type LocalBox, type LocaleStrings, type LodSettings, type OverallHealth, type PartDef, type PartLabel, type PartRole, type PartialLocaleStrings, type Plugin, type ResolvedConfiguration, SEED_SALTS, type ScenarioContext, type ScenarioDefinition, type ScenarioResult, type SplatOptions, type ThreeObject, type ThreeVector, type Translate, type UiHelpers, type VehicleContext, type VehicleDestructible, type VehicleDestructibleOptions, type VehicleItem, type VehicleItemOptions, type VehicleKit, type VehicleKitOptions, type VehicleMeta, type VehicleModel, type VehiclePart, type VehicleSpec, type VehicleStatus, type ZoneDamageEntry, type ZoneEffect, type ZoneState, buildVehicleItem, buildVehicleModel, clamp, createLod, createTranslate, createVehicleDestructible, createVehicleKit, defaultDamageableKinds, defaultLodSettings, format, hash, legacyGlassId, legacyLightId, legacyZoneId, listLocales, registerLegacySeeds, registerLocale, resolveStrings, rng, smooth, strHash, wrapThreeForLod };
978
+ /**
979
+ * The cabin of a vehicle as a closed space for the smoke, dust and steam of the host's effects (`EffectSink.enclose` of the contracts): a shut car
980
+ * keeps the smoke out. It is open where it is in the real world: a door standing open, a window shattered, a door, glass or roof torn off or burnt
981
+ * away; a bullet hole lets a little in at a rate that grows with its size, and the gaps of a shut door let a trace in.
982
+ */
983
+
984
+ /** The cabin box a vehicle with an interior records (`kit.interior`), in the vehicle's own space: x along it, `z` the inner half width. */
985
+ interface CabinBox {
986
+ readonly x0: number;
987
+ readonly x1: number;
988
+ readonly y0: number;
989
+ readonly y1: number;
990
+ readonly z: number;
991
+ }
992
+ /** What the cabin enclosure reads of a vehicle: its parts and their state (any `DestructibleImpl` of a vehicle has these). */
993
+ interface CabinSource {
994
+ readonly vehicle: VehicleContext;
995
+ readonly model: VehicleModel;
996
+ state(): ObjectState;
997
+ }
998
+ interface CabinEnclosureOptions {
999
+ /** The object the destructible answers in (its `frame` option, where the host placed the vehicle): the holes of `state()` are in its space. Default `vehicle.root`. */
1000
+ readonly frame?: any;
1001
+ /** Gaps of the shut doors and vents, share per second of the smoke pressing on the closed shell (default {@link CABIN_LEAK}). */
1002
+ readonly leak?: number;
1003
+ /** How open a door or lid has to be (share of its full swing) to count as open (default 0.06: ajar). */
1004
+ readonly ajar?: number;
1005
+ }
1006
+ /** The gaps of a shut car (door seals, the vents, the dash): about 2 % per second of what presses on it seeps in. */
1007
+ declare const CABIN_LEAK = 0.02;
1008
+ /** The cabin box of a vehicle, or `null` when it has none (a bike, a vehicle with no interior). */
1009
+ declare function cabinBoxOf(vehicle: VehicleContext): CabinBox | null;
1010
+ /** How far a door or lid stands open, 0 shut to 1 at the end of its clip: the turn of its drawn hinge from rest (the room poses it by the part id). */
1011
+ declare function swingOf(vehicle: VehicleContext, partId: string): number;
1012
+ /**
1013
+ * The cabin of `source` as an `Enclosure` in world space, or `null` when there is no closed cabin (no interior, the vehicle exploded, every shell
1014
+ * part gone). Call it each frame, or when the vehicle moves or changes, and hand it to `EffectSink.enclose`.
1015
+ */
1016
+ declare function cabinEnclosure(source: CabinSource, options?: CabinEnclosureOptions): Enclosure | null;
1017
+
1018
+ /** Glass cracks, shattering and tempered or laminated breakage textures. */
1019
+
1020
+ /** The material of a pane with cracks drawn on it. A host warms its program at load with any texture: the first crack is in the middle of a blast. */
1021
+ declare function crackedGlassMaterial(THREE: any, texture: unknown): any;
1022
+
1023
+ export { type Band, type BandId, type BandIndex, type BandOverride, type BuildFunction, type BuildOptions, type BuildState, type BuildZoneState, CABIN_LEAK, type CabinBox, type CabinEnclosureOptions, type CabinSource, type CreaseQueue, type CreaseWork, type DamageMapOptions, type DamageZone, type Damageable, type DamageableKind, type DamageableMaterial, type DamageableSide, type ExplodeOptions, type FlagEffect, type FluidDefinition, type ImpactOptions, JOINT_RULES, type JointDef, type KitConfiguration, type KitInternals, type KitTexts, LEGACY_STATES, LEGACY_ZONE_IDS, type LocalBox, type LocaleStrings, type LodSettings, type OverallHealth, type PartDef, type PartLabel, type PartRole, type PartialLocaleStrings, type ParticleEffectRequest, type ParticleEffects, type ParticleMaterials, type Plugin, type ResolvedConfiguration, SEED_SALTS, type ScenarioContext, type ScenarioDefinition, type ScenarioResult, type SplatOptions, type ThreeObject, type ThreeVector, type Translate, type UiHelpers, type VehicleContext, type VehicleDestructible, type VehicleDestructibleOptions, type VehicleItem, type VehicleItemOptions, type VehicleKit, type VehicleKitOptions, type VehicleMeta, type VehicleModel, type VehiclePart, type VehicleSpec, type VehicleStatus, type ZoneDamageEntry, type ZoneEffect, type ZoneState, buildVehicleItem, buildVehicleModel, cabinBoxOf, cabinEnclosure, clamp, crackedGlassMaterial, createCreaseQueue, createLod, createTranslate, createVehicleDestructible, createVehicleKit, defaultDamageableKinds, defaultLodSettings, format, hash, legacyGlassId, legacyLightId, legacyZoneId, listLocales, registerLegacySeeds, registerLocale, resolveStrings, rng, smooth, strHash, swingOf, wrapThreeForLod };