@adatechnology/game-vehicles 0.1.12 → 0.3.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 +18 -1
- package/dist/index.d.ts +90 -3
- package/dist/index.global.js +1900 -139
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +216 -11
- package/dist/index.js.map +1 -1
- package/package.json +9 -6
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ pnpm add @adatechnology/game-vehicles three
|
|
|
18
18
|
Browser without a bundler (the global is `GameVehicles`):
|
|
19
19
|
|
|
20
20
|
```html
|
|
21
|
-
<script src="https://unpkg.com/three@0.
|
|
21
|
+
<script src="https://unpkg.com/three@0.160.1/build/three.min.js"></script>
|
|
22
22
|
<script src="https://unpkg.com/@adatechnology/game-vehicles/dist/index.global.js"></script>
|
|
23
23
|
<script>
|
|
24
24
|
const kit = GameVehicles.createVehicleKit({ THREE })
|
|
@@ -201,6 +201,13 @@ Plain DOM and SVG, no framework: `ui.damageMap(host, c, { selected, onSelect })`
|
|
|
201
201
|
ones in a strip below); `ui.bandButtons`, `ui.legend`, `ui.healthBar({ text, bar }, c)`, `ui.scenarioButtons`. `ui.injectStyles()` adds minimal CSS
|
|
202
202
|
(`--panel-2`, `--line` and `--muted` customise it).
|
|
203
203
|
|
|
204
|
+
## Geometry
|
|
205
|
+
|
|
206
|
+
The kit's three is `shapeGeometries(THREE)` of `@adatechnology/game-shapes-three`, thinned by the light mode: boxes, cylinders, cones, spheres,
|
|
207
|
+
planes, circles, rings, tori, the tyre lathes and the straight-edged extrusions are made by game-shapes, bit-identical to three's
|
|
208
|
+
(`tests/exact-golden.test.ts`, and the fleet's and `game-vehicles-three`'s) and cached by parameters across vehicles. Tubes, curved
|
|
209
|
+
extrusions, the lofted bodies and the warps stay three's own or the kit's custom buffers. The IIFE build bundles game-shapes.
|
|
210
|
+
|
|
204
211
|
## Determinism and old seeds
|
|
205
212
|
|
|
206
213
|
The random stream of a zone is seeded from the vehicle key, the zone id and the band. The first version of this engine used Portuguese ids, so ids
|
|
@@ -241,6 +248,12 @@ car.animations() // open/close clips for the doors, hood and trunk
|
|
|
241
248
|
|
|
242
249
|
Fluids: the tank, the oil pan and the radiator hold fuel, oil and coolant; a hole below the level makes a `leak` event, a puddle and a falling level.
|
|
243
250
|
|
|
251
|
+
Fuel tank: a bullet that goes through it **leaks and does not set it alight by itself**. The leak lights (event `ignite`, then the usual fire and, for a petrol tank, the explosion) with
|
|
252
|
+
a spark of a hard round on the steel wall, an incendiary or tracer round, a burning part or burning fuel stain within `ignition.fireNear.radius`, or a blast. The chances of the round
|
|
253
|
+
come in `Hit.ignition` (the weapons build them from the core and jacket of the ammunition) and are weighed by how full the tank is (`fuel`, 0 to 1, the starting level; a nearly empty tank lights
|
|
254
|
+
easiest, a full one mostly leaks); diesel takes a spark far worse than petrol. `createVehicleDestructible(kit, vehicle, { fuel: 0.1, ignition: { fillCurve, fireNear, sparkTarget } })`;
|
|
255
|
+
the defaults and every number are `IgnitionRules` of `@adatechnology/game-contracts`.
|
|
256
|
+
|
|
244
257
|
## Português
|
|
245
258
|
|
|
246
259
|
Motor genérico de veículos procedurais para three.js: carrocerias, vidros, faróis, rodas, interiores, capô e compartimento do motor, **zonas de dano
|
|
@@ -266,3 +279,7 @@ scene.add(c.root)
|
|
|
266
279
|
### Contrato de destruição
|
|
267
280
|
|
|
268
281
|
`createVehicleDestructible(kit, c, opções)` faz um veículo construído seguir o `DestructibleImpl` de `@adatechnology/game-contracts`: cada zona de dano vira uma peça com material, as peças mecânicas (bateria, alternador, câmbio, freios, direção, amortecedores, pneus, retrovisores, engate) são acrescentadas, as juntas (dobradiça, parafuso, solda) se desfazem por desgaste ou com a chave inglesa, e as peças saem do veículo e caem. `status()` diz o que a mecânica faz (freios, direção, bateria, câmbio). Os nomes em português estão em `locales/pt-BR.json` (`mechanics.*`).
|
|
282
|
+
|
|
283
|
+
## Light mode and damageable parts
|
|
284
|
+
|
|
285
|
+
`createVehicleKit({ lod })` takes the settings of the light mode (`defaultLodSettings`: every number can be overridden). `kit.build(key, state, zones, { lod: true })` builds the same vehicle with fewer triangles (rounded boxes with one ring, coarser lofts, grilles and generators, interiors tagged `userData.skipLite`) and puts the switch back; with it off nothing changes. `kit.damageables(c, matrix?)` lists the metal, glass, rubber and fuel parts of a built vehicle as `Box3` boxes (`kit.damageableKinds` maps zone types to parts and can be extended).
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,58 @@
|
|
|
1
|
-
import { ToolKind, JointKind, Vec3, MaterialId, DestructibleImpl, AnimationClipSpec } from '@adatechnology/game-contracts';
|
|
1
|
+
import { ToolKind, JointKind, Vec3, MaterialId, DestructibleImpl, AnimationClipSpec, IgnitionRules } from '@adatechnology/game-contracts';
|
|
2
|
+
|
|
3
|
+
/**
|
|
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
|
|
5
|
+
* (frota-leve.js lines 21-65, 232-257, 1205-1221, 14155-14170). Every number is a setting; with `on` false nothing changes, so every golden
|
|
6
|
+
* of the full-detail build stays byte for byte the same.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
interface LodSettings {
|
|
10
|
+
/** Light mode is active for the builds that run now. Set by `kit.build(key, state, zones, { lod: true })`. */
|
|
11
|
+
on: boolean;
|
|
12
|
+
/** Fraction of the segments three's own generators keep (cylinders, spheres, tori, lathes, tubes, extrusions, circles, rings). */
|
|
13
|
+
segmentFraction: number;
|
|
14
|
+
/** Rounding rings of a rounded box (the full build uses 3). */
|
|
15
|
+
roundingRings: number;
|
|
16
|
+
/** Multiplier of the maximum edge length when subdividing a mesh (bigger triangles). */
|
|
17
|
+
subdivisionFactor: number;
|
|
18
|
+
/** A box with an edge under this, or a rounding radius under 1.2 cm, is drawn as a plain 12-triangle box. */
|
|
19
|
+
flatBoxEdge: number;
|
|
20
|
+
/** Fewest segments of a superellipse loft. */
|
|
21
|
+
minLoftSegments: number;
|
|
22
|
+
/** Fraction of a loft's segments. */
|
|
23
|
+
loftSegmentFraction: number;
|
|
24
|
+
/** Fewest stations of a resampled loft. */
|
|
25
|
+
minStations: number;
|
|
26
|
+
/** Fraction of the stations of a resampled loft. */
|
|
27
|
+
stationFraction: number;
|
|
28
|
+
/** Multiplier of the grid cell size of grilles and side grilles. */
|
|
29
|
+
gridFactor: number;
|
|
30
|
+
/** Materials (by name in `kit.materials`) whose meshes are never seen from outside and are left out in light mode. */
|
|
31
|
+
hiddenMaterials: readonly string[];
|
|
32
|
+
}
|
|
33
|
+
declare const defaultLodSettings: LodSettings;
|
|
34
|
+
/** The settings the kit starts with: the defaults, overridden by the options. */
|
|
35
|
+
declare function createLod(options?: Partial<LodSettings>): LodSettings;
|
|
36
|
+
/**
|
|
37
|
+
* A copy of the three.js namespace whose geometry generators take fewer segments while `lod.on` is true (and whose canvas textures come out in
|
|
38
|
+
* sRGB when three has colour management). With `lod.on` false every generator passes its arguments through untouched.
|
|
39
|
+
*/
|
|
40
|
+
declare function wrapThreeForLod(TH: any, lod: LodSettings): any;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Damageable parts: what a bullet, a bat or a crash can hurt on a built vehicle, as boxes. Port of `coletarDanificaveis` and `tipoDaZona`
|
|
44
|
+
* (frota-leve.js 14391-14405), driven by the zones the kit already derives, so it works for any vehicle of any pack.
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
type DamageableMaterial = 'metal' | 'glass' | 'rubber' | 'fuel';
|
|
48
|
+
type DamageableSide = 'center' | 'left' | 'right';
|
|
49
|
+
/** What a zone is, by type: the material it is made of and the part name a game shows. */
|
|
50
|
+
interface DamageableKind {
|
|
51
|
+
material: DamageableMaterial;
|
|
52
|
+
part: string;
|
|
53
|
+
}
|
|
54
|
+
/** Zone type (and, for some, `fxKey` or `sub`) to material and part. A game replaces or adds entries with `kit.damageableKinds`. */
|
|
55
|
+
declare const defaultDamageableKinds: Record<string, DamageableKind>;
|
|
2
56
|
|
|
3
57
|
var plate = {
|
|
4
58
|
band: "BRAZIL"
|
|
@@ -487,9 +541,25 @@ interface Plugin {
|
|
|
487
541
|
configure?: KitConfiguration;
|
|
488
542
|
install?(kit: VehicleKit): void;
|
|
489
543
|
}
|
|
544
|
+
interface BuildOptions {
|
|
545
|
+
/** Build this vehicle in light mode (fewer triangles; interiors tagged `skipLite`). */
|
|
546
|
+
lod?: boolean;
|
|
547
|
+
}
|
|
548
|
+
interface Damageable {
|
|
549
|
+
material: DamageableMaterial;
|
|
550
|
+
/** Id of the zone. */
|
|
551
|
+
zone: string;
|
|
552
|
+
/** `door`, `hood`, `lid`, `bumper`, `window`, `windshield`, `headlight`, `taillight`, `wheel`, `fuel_tank`. */
|
|
553
|
+
part: string;
|
|
554
|
+
side: DamageableSide;
|
|
555
|
+
/** A `THREE.Box3`. */
|
|
556
|
+
box: ThreeObject;
|
|
557
|
+
}
|
|
490
558
|
interface VehicleKitOptions extends KitConfiguration {
|
|
491
559
|
/** The three.js namespace (`import * as THREE from 'three'` or `window.THREE`). */
|
|
492
560
|
THREE: any;
|
|
561
|
+
/** Light mode settings (every number of `defaultLodSettings` can be overridden). */
|
|
562
|
+
lod?: Partial<LodSettings>;
|
|
493
563
|
/** A registered locale code (`'en'`, `'pt-BR'`), or a partial string table overriding English. Default `'en'`. */
|
|
494
564
|
locale?: string | PartialLocaleStrings;
|
|
495
565
|
/** Document used for canvas textures and the UI. Defaults to the global `document`. */
|
|
@@ -552,6 +622,10 @@ interface KitInternals {
|
|
|
552
622
|
type Builder = (...args: any[]) => any;
|
|
553
623
|
interface VehicleKit {
|
|
554
624
|
readonly THREE: any;
|
|
625
|
+
/** The light mode settings (live: change a number and the next build uses it). */
|
|
626
|
+
readonly lod: LodSettings;
|
|
627
|
+
/** Zone type to material and part of `damageables`; add or replace entries. */
|
|
628
|
+
readonly damageableKinds: Record<string, DamageableKind>;
|
|
555
629
|
/** Translated strings in use. */
|
|
556
630
|
readonly strings: LocaleStrings;
|
|
557
631
|
/** Looks up a locale key (`'zones.hood'`) and fills variables. */
|
|
@@ -588,7 +662,9 @@ interface VehicleKit {
|
|
|
588
662
|
defineFluid(key: string, def: FluidDefinition): FluidDefinition;
|
|
589
663
|
on(event: string, fn: (...args: any[]) => void): VehicleKit;
|
|
590
664
|
hook(event: string, ...args: any[]): void;
|
|
591
|
-
build(key: string, state?: BuildState, zoneState?: Partial<ZoneState
|
|
665
|
+
build(key: string, state?: BuildState, zoneState?: Partial<ZoneState>, options?: BuildOptions): VehicleContext;
|
|
666
|
+
/** The damageable parts of a built vehicle as boxes (optionally in the frame of `matrix`). */
|
|
667
|
+
damageables(c: VehicleContext, matrix?: ThreeObject): Damageable[];
|
|
592
668
|
dispose(c: VehicleContext): void;
|
|
593
669
|
/** Advances particles, fluids, hood, blast and rollover animations by `dt` seconds. */
|
|
594
670
|
tick(c: VehicleContext, dt: number): void;
|
|
@@ -768,6 +844,15 @@ interface VehicleDestructibleOptions {
|
|
|
768
844
|
headless?: boolean;
|
|
769
845
|
/** Extra seed for the choices that are random in the real world (which way a broken steering pulls). */
|
|
770
846
|
seed?: number;
|
|
847
|
+
/** How full the fuel tank starts, 0 to 1 (default 1). A nearly empty tank leaks little and lights easily (see `ignition`). */
|
|
848
|
+
fuel?: number;
|
|
849
|
+
/**
|
|
850
|
+
* What lights the fuel that leaks from a pierced tank: a plain bullet only leaks; a spark of a hard round on steel, an incendiary or tracer
|
|
851
|
+
* round, a fire within `fireNear.radius` (a burning part or a burning fuel stain) or a blast lights it, and then the usual fire and explosion
|
|
852
|
+
* follow. The chance of the round is in `Hit.ignition`; this is the target side (how full the tank is, what the wall is, the fire near).
|
|
853
|
+
* Defaults and meaning of every number: `IgnitionRules` of `@adatechnology/game-contracts`.
|
|
854
|
+
*/
|
|
855
|
+
ignition?: Partial<IgnitionRules>;
|
|
771
856
|
}
|
|
772
857
|
/** What the vehicle can do now, from the state of its hidden mechanics. */
|
|
773
858
|
interface VehicleStatus {
|
|
@@ -807,6 +892,8 @@ declare function createVehicleDestructible(kit: VehicleKit, vehicleCtx: VehicleC
|
|
|
807
892
|
|
|
808
893
|
interface VehicleItemOptions {
|
|
809
894
|
state?: BuildState;
|
|
895
|
+
/** Build in the light mode of the kit (`kit.lod`): fewer segments and no interior, for crowds and for budgets. Default off. */
|
|
896
|
+
lod?: boolean;
|
|
810
897
|
}
|
|
811
898
|
interface VehicleItem {
|
|
812
899
|
/** Add this to the scene: origin at the centre of the footprint on the floor, front facing +z. */
|
|
@@ -821,4 +908,4 @@ interface VehicleItem {
|
|
|
821
908
|
*/
|
|
822
909
|
declare function buildVehicleItem(kit: VehicleKit, key: string, options?: VehicleItemOptions): VehicleItem;
|
|
823
910
|
|
|
824
|
-
export { type Band, type BandId, type BandIndex, type BandOverride, type BuildFunction, type BuildState, type DamageMapOptions, type DamageZone, 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 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, createTranslate, createVehicleDestructible, createVehicleKit, format, hash, legacyGlassId, legacyLightId, legacyZoneId, listLocales, registerLegacySeeds, registerLocale, resolveStrings, rng, smooth, strHash };
|
|
911
|
+
export { type Band, type BandId, type BandIndex, type BandOverride, type BuildFunction, type BuildOptions, type BuildState, 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 };
|