@adatechnology/game-vehicles 0.6.13 → 0.6.15
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 +38 -2
- package/dist/index.global.js +151 -17
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +151 -17
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -212,7 +212,13 @@ var en_default = {
|
|
|
212
212
|
pillar_c: "{Side} C pillar",
|
|
213
213
|
engine: "Engine",
|
|
214
214
|
radiator: "Radiator",
|
|
215
|
-
fuel_tank: "Fuel tank"
|
|
215
|
+
fuel_tank: "Fuel tank",
|
|
216
|
+
fog_light: "{Side} fog light",
|
|
217
|
+
fog_light_center: "Fog light",
|
|
218
|
+
lamp_front: "{Side} front lamp",
|
|
219
|
+
lamp_front_center: "Front lamp",
|
|
220
|
+
lamp_rear: "{Side} rear lamp",
|
|
221
|
+
lamp_rear_center: "Rear lamp"
|
|
216
222
|
}
|
|
217
223
|
};
|
|
218
224
|
|
|
@@ -423,7 +429,13 @@ var pt_BR_default = {
|
|
|
423
429
|
pillar_c: "Coluna C {sideM}",
|
|
424
430
|
engine: "Motor",
|
|
425
431
|
radiator: "Radiador",
|
|
426
|
-
fuel_tank: "Tanque de combust\xEDvel"
|
|
432
|
+
fuel_tank: "Tanque de combust\xEDvel",
|
|
433
|
+
fog_light: "Farol de neblina {sideM}",
|
|
434
|
+
fog_light_center: "Farol de neblina",
|
|
435
|
+
lamp_front: "Luz dianteira {side}",
|
|
436
|
+
lamp_front_center: "Luz dianteira",
|
|
437
|
+
lamp_rear: "Luz traseira {side}",
|
|
438
|
+
lamp_rear_center: "Luz traseira"
|
|
427
439
|
}
|
|
428
440
|
};
|
|
429
441
|
|
|
@@ -5535,12 +5547,16 @@ function installGlassDamage(kit) {
|
|
|
5535
5547
|
}
|
|
5536
5548
|
kit.breakLight = breakLight;
|
|
5537
5549
|
const crazedCache = /* @__PURE__ */ new Map();
|
|
5538
|
-
const CRAZED_OPACITY = 0.
|
|
5550
|
+
const CRAZED_OPACITY = 0.5;
|
|
5551
|
+
const CRAZED_TINT = 0.6;
|
|
5552
|
+
const CRAZED_ROUGHNESS = 0.6;
|
|
5539
5553
|
function crazed(material) {
|
|
5540
5554
|
const known = crazedCache.get(material);
|
|
5541
5555
|
if (known) return known;
|
|
5542
5556
|
const m = I.crackLens(material).clone();
|
|
5543
5557
|
m.opacity = Math.max(m.opacity ?? 1, CRAZED_OPACITY);
|
|
5558
|
+
m.color?.multiplyScalar(CRAZED_TINT);
|
|
5559
|
+
m.roughness = Math.max(m.roughness ?? 0, CRAZED_ROUGHNESS);
|
|
5544
5560
|
m.transparent = true;
|
|
5545
5561
|
m.userData.shared = true;
|
|
5546
5562
|
crazedCache.set(material, m);
|
|
@@ -5558,6 +5574,7 @@ function installGlassDamage(kit) {
|
|
|
5558
5574
|
L.dark = true;
|
|
5559
5575
|
for (const m of L.inner) m.material = MATERIALS.bulbBroken;
|
|
5560
5576
|
for (const h of L.halo ?? []) h.visible = false;
|
|
5577
|
+
for (const m of L.reflector ?? []) m.material = MATERIALS.broken;
|
|
5561
5578
|
}
|
|
5562
5579
|
kit.crackLight = crackLight;
|
|
5563
5580
|
const shared = { glassUV, drawWeb, crackGlass, glassRim, shatterGlass, hitGlass, breakLight, crackLight };
|
|
@@ -11124,6 +11141,88 @@ function createVehicleKit(options) {
|
|
|
11124
11141
|
return kit;
|
|
11125
11142
|
}
|
|
11126
11143
|
|
|
11144
|
+
// src/stray-lamps.ts
|
|
11145
|
+
var END_DEPTH = 0.45;
|
|
11146
|
+
var LAMP_EMISSIVE_MIN = 0.25;
|
|
11147
|
+
var LAMP_INTENSITY_MIN = 0.2;
|
|
11148
|
+
var UNIT_MARGIN = 0.03;
|
|
11149
|
+
var CLUSTER_GAP = 0.04;
|
|
11150
|
+
var CENTRE_Z = 0.08;
|
|
11151
|
+
function glowsLikeLamp(material) {
|
|
11152
|
+
if (!material || Array.isArray(material)) return false;
|
|
11153
|
+
const { emissive, emissiveIntensity } = material;
|
|
11154
|
+
if (!emissive || !((emissiveIntensity ?? 0) >= LAMP_INTENSITY_MIN)) return false;
|
|
11155
|
+
return Math.max(emissive.r, emissive.g, emissive.b) >= LAMP_EMISSIVE_MIN;
|
|
11156
|
+
}
|
|
11157
|
+
function membersOf(lights) {
|
|
11158
|
+
const members = /* @__PURE__ */ new Set();
|
|
11159
|
+
for (const L of lights) {
|
|
11160
|
+
L.group?.traverse((o) => members.add(o));
|
|
11161
|
+
for (const m of [...L.lens, ...L.inner, ...L.halo ?? []]) members.add(m);
|
|
11162
|
+
}
|
|
11163
|
+
return members;
|
|
11164
|
+
}
|
|
11165
|
+
function sideOf(box) {
|
|
11166
|
+
const z = (box.min.z + box.max.z) / 2;
|
|
11167
|
+
return Math.abs(z) < CENTRE_Z ? "center" : z < 0 ? "left" : "right";
|
|
11168
|
+
}
|
|
11169
|
+
function lampOf(inner, box, front, flags) {
|
|
11170
|
+
return { group: null, lens: [], inner, kind: front ? "headlight" : "taillight", tint: front ? "clear" : "red", broken: false, side: sideOf(box), ...flags };
|
|
11171
|
+
}
|
|
11172
|
+
function strayLampsOf(c, THREE) {
|
|
11173
|
+
c.strayLamps ?? (c.strayLamps = findStrayLamps(c, THREE));
|
|
11174
|
+
return c.strayLamps;
|
|
11175
|
+
}
|
|
11176
|
+
function findStrayLamps(c, THREE) {
|
|
11177
|
+
const Box = THREE.Box3;
|
|
11178
|
+
const vehicle = c.vehicle;
|
|
11179
|
+
vehicle.updateMatrixWorld(true);
|
|
11180
|
+
const inverse = vehicle.matrixWorld.clone().invert();
|
|
11181
|
+
const localBox = (o) => new Box().setFromObject(o).applyMatrix4(inverse);
|
|
11182
|
+
const lights = c.lights ?? [];
|
|
11183
|
+
const members = membersOf(lights);
|
|
11184
|
+
const units = lights.map((L) => {
|
|
11185
|
+
const bb = new Box();
|
|
11186
|
+
for (const o of L.group ? [L.group] : [...L.lens, ...L.inner]) bb.union(localBox(o));
|
|
11187
|
+
return bb.expandByScalar(UNIT_MARGIN);
|
|
11188
|
+
});
|
|
11189
|
+
const front = c.meta?.front ?? new Box().setFromObject(vehicle).applyMatrix4(inverse).max.x;
|
|
11190
|
+
const rear = c.meta?.rear ?? new Box().setFromObject(vehicle).applyMatrix4(inverse).min.x;
|
|
11191
|
+
const found = [];
|
|
11192
|
+
const bulbs = [...c.fogBulbs ?? []];
|
|
11193
|
+
vehicle.traverse((o) => {
|
|
11194
|
+
if (o.userData.lamp === "fog" && o.isMesh && !bulbs.includes(o)) bulbs.push(o);
|
|
11195
|
+
});
|
|
11196
|
+
for (const bulb of bulbs) {
|
|
11197
|
+
if (members.has(bulb)) continue;
|
|
11198
|
+
members.add(bulb);
|
|
11199
|
+
const bb = localBox(bulb);
|
|
11200
|
+
found.push(lampOf([bulb], bb, bb.max.x > (front + rear) / 2, { fog: true }));
|
|
11201
|
+
}
|
|
11202
|
+
const loose = [];
|
|
11203
|
+
vehicle.traverse((o) => {
|
|
11204
|
+
const mesh = o;
|
|
11205
|
+
if (!mesh.isMesh || members.has(mesh) || mesh.userData.glass || mesh.userData.decal || mesh.userData.lamp === "beacon") return;
|
|
11206
|
+
if (!glowsLikeLamp(mesh.material)) return;
|
|
11207
|
+
const bb = localBox(mesh);
|
|
11208
|
+
const mid = bb.getCenter(new THREE.Vector3());
|
|
11209
|
+
const atFront = mid.x > front - END_DEPTH;
|
|
11210
|
+
if (!atFront && mid.x > rear + END_DEPTH) return;
|
|
11211
|
+
if (units.some((u) => u.containsPoint(mid))) return;
|
|
11212
|
+
loose.push({ mesh, box: bb, front: atFront });
|
|
11213
|
+
});
|
|
11214
|
+
const groups = [];
|
|
11215
|
+
for (const piece of loose) {
|
|
11216
|
+
const near = groups.find((g) => g.front === piece.front && g.box.clone().expandByScalar(CLUSTER_GAP).intersectsBox(piece.box));
|
|
11217
|
+
if (near) {
|
|
11218
|
+
near.meshes.push(piece.mesh);
|
|
11219
|
+
near.box.union(piece.box);
|
|
11220
|
+
} else groups.push({ meshes: [piece.mesh], box: piece.box.clone(), front: piece.front });
|
|
11221
|
+
}
|
|
11222
|
+
for (const g of groups) found.push(lampOf(g.meshes, g.box, g.front, { aux: true }));
|
|
11223
|
+
return found;
|
|
11224
|
+
}
|
|
11225
|
+
|
|
11127
11226
|
// src/destructible/armour.ts
|
|
11128
11227
|
var ARMOUR_LEVELS = {
|
|
11129
11228
|
IIIA: { glassStops: 1700, glassHp: 6e3, glassTakes: 0.25, steel: 8 },
|
|
@@ -11161,6 +11260,7 @@ var MECHANICS = {
|
|
|
11161
11260
|
var HITCH_CHANCE = { car: 30, truck: 60, bus: 0, tractor: 100, quad: 40, bike: 0, tank: 0, boat: 0, plane: 0, heli: 0 };
|
|
11162
11261
|
var GLASS_LENS_HP = 320;
|
|
11163
11262
|
var PLASTIC_LENS_HP = 900;
|
|
11263
|
+
var STRAY_LAMP_MARGIN = 0.03;
|
|
11164
11264
|
var STEEL_KG_M2 = 7;
|
|
11165
11265
|
var ALU_KG_M2 = 3.2;
|
|
11166
11266
|
var kindOf = (c) => {
|
|
@@ -11232,6 +11332,18 @@ var floorPan = (b) => ({
|
|
|
11232
11332
|
center: [b.center[0], b.center[1] - b.size[1] / 2 + Math.min(0.14, b.size[1]) / 2 + 0.04, b.center[2]],
|
|
11233
11333
|
size: [b.size[0] * 0.5, Math.min(0.14, b.size[1]), b.size[2] * 0.95]
|
|
11234
11334
|
});
|
|
11335
|
+
function strayLampBox(c, lamp, inverse) {
|
|
11336
|
+
const lo = [Infinity, Infinity, Infinity];
|
|
11337
|
+
const hi = [-Infinity, -Infinity, -Infinity];
|
|
11338
|
+
for (const mesh of [...lamp.lens, ...lamp.inner]) {
|
|
11339
|
+
const b = paneBox(c, mesh, inverse);
|
|
11340
|
+
for (let i = 0; i < 3; i++) {
|
|
11341
|
+
lo[i] = Math.min(lo[i], b.center[i] - b.size[i] / 2);
|
|
11342
|
+
hi[i] = Math.max(hi[i], b.center[i] + b.size[i] / 2);
|
|
11343
|
+
}
|
|
11344
|
+
}
|
|
11345
|
+
return { center: [0, 1, 2].map((i) => (lo[i] + hi[i]) / 2), size: [0, 1, 2].map((i) => hi[i] - lo[i] + 2 * STRAY_LAMP_MARGIN) };
|
|
11346
|
+
}
|
|
11235
11347
|
function paneBox(c, pane, inverse) {
|
|
11236
11348
|
pane.geometry.computeBoundingBox();
|
|
11237
11349
|
const box = pane.geometry.boundingBox.clone().applyMatrix4(pane.matrixWorld);
|
|
@@ -11393,6 +11505,15 @@ function buildVehicleModel(kit, c, options = {}) {
|
|
|
11393
11505
|
const laminated = G?.type === "laminated" || !!armoured;
|
|
11394
11506
|
add({ id: `pane_${G?.key ?? "glass"}`, role: "glass", name: String(G?.label ?? G?.key ?? "glass"), material: "glass", box: bb, mass: 10 * areaOf(bb.size), hp: armoured ? armoured.glassHp : laminated ? 4e3 : 450, panes: [pane], visual: false, tags: ["glass"] });
|
|
11395
11507
|
}
|
|
11508
|
+
for (const lamp of strayLampsOf(c, kit.THREE)) {
|
|
11509
|
+
const front = lamp.kind !== "taillight";
|
|
11510
|
+
const lens = front ? spec.headlightLens ?? "polycarbonate" : "acrylic";
|
|
11511
|
+
const glassLens = lens === "glass";
|
|
11512
|
+
const box = strayLampBox(c, lamp, inverse);
|
|
11513
|
+
const what = lamp.fog ? "fog_light" : front ? "lamp_front" : "lamp_rear";
|
|
11514
|
+
const name = lamp.side === "center" ? t(`mechanics.${what}_center`) : t(`mechanics.${what}`, { side: t(`sides.${lamp.side}`), sideM: t(`sides.${lamp.side}M`) });
|
|
11515
|
+
add({ id: lamp.side === "center" ? what : `${what}_${lamp.side}`, role: "light", name, material: glassLens ? "glass" : "plastic", box, mass: 0.4 + 4 * areaOf(box.size), hp: glassLens ? GLASS_LENS_HP : PLASTIC_LENS_HP, lamps: [lamp], visual: true, tags: ["light", `lens_${lens}`, ...lamp.fog ? ["fog"] : []] });
|
|
11516
|
+
}
|
|
11396
11517
|
if (!hubZone) {
|
|
11397
11518
|
const h = Math.max(0.15, belt - clearance);
|
|
11398
11519
|
add({
|
|
@@ -11963,6 +12084,9 @@ var DOOR_TOP_OVER_PANE = 0.03;
|
|
|
11963
12084
|
var HOLE_TEXTURE_SIZE = 64;
|
|
11964
12085
|
var LAMP_BOX_MARGIN = 0.03;
|
|
11965
12086
|
var GLOW_MIN_EMISSIVE = 0.05;
|
|
12087
|
+
var MIRROR_MIN_METALNESS = 0.8;
|
|
12088
|
+
var MIRROR_MAX_ROUGHNESS = 0.35;
|
|
12089
|
+
var MIRROR_MIN_LIGHTNESS = 0.4;
|
|
11966
12090
|
var LAMINATED_HP = 1e3;
|
|
11967
12091
|
var HOOD_SINK = 2e-3;
|
|
11968
12092
|
var HOOD_GAP_CLOSED = 0.016;
|
|
@@ -12050,6 +12174,14 @@ function holeMaterial(kit, material) {
|
|
|
12050
12174
|
cache2.set(material, made);
|
|
12051
12175
|
return made;
|
|
12052
12176
|
}
|
|
12177
|
+
function isGlowing(material) {
|
|
12178
|
+
const { emissive, emissiveIntensity } = material;
|
|
12179
|
+
return !!emissive && (emissiveIntensity ?? 0) > 0 && emissive.r + emissive.g + emissive.b >= GLOW_MIN_EMISSIVE;
|
|
12180
|
+
}
|
|
12181
|
+
function isMirrorChrome(material) {
|
|
12182
|
+
const { metalness, roughness, color } = material;
|
|
12183
|
+
return (metalness ?? 0) >= MIRROR_MIN_METALNESS && (roughness ?? 1) <= MIRROR_MAX_ROUGHNESS && !!color && (color.r + color.g + color.b) / 3 >= MIRROR_MIN_LIGHTNESS;
|
|
12184
|
+
}
|
|
12053
12185
|
var VehicleVisuals = class {
|
|
12054
12186
|
constructor(kit, c, model) {
|
|
12055
12187
|
__publicField(this, "kit");
|
|
@@ -12144,7 +12276,7 @@ var VehicleVisuals = class {
|
|
|
12144
12276
|
case "bumper":
|
|
12145
12277
|
return z ? z.owned.filter((o) => o.parent) : [];
|
|
12146
12278
|
case "light":
|
|
12147
|
-
return
|
|
12279
|
+
return this.lampsOf(p).map((L) => L.group).filter((g) => g && g.parent);
|
|
12148
12280
|
case "rim":
|
|
12149
12281
|
return z ? z.wheels.filter((o) => o.parent) : [];
|
|
12150
12282
|
case "tyre": {
|
|
@@ -13047,7 +13179,7 @@ var VehicleVisuals = class {
|
|
|
13047
13179
|
if (on === this.lightsOn) return;
|
|
13048
13180
|
this.lightsOn = on;
|
|
13049
13181
|
const dark = this.I.MATERIALS.bulbBroken;
|
|
13050
|
-
for (const L of this.c.lights) {
|
|
13182
|
+
for (const L of [...this.c.lights, ...this.c.strayLamps ?? []]) {
|
|
13051
13183
|
if (L.broken || L.dark) continue;
|
|
13052
13184
|
for (const h of L.halo ?? []) h.visible = on;
|
|
13053
13185
|
for (const m of L.inner ?? []) {
|
|
@@ -13063,33 +13195,34 @@ var VehicleVisuals = class {
|
|
|
13063
13195
|
/** The lens of a light is holed or cracked and stays; `pierced`: a round went through it to the bulb, and the lamp goes dark. */
|
|
13064
13196
|
crackLight(p, pierced) {
|
|
13065
13197
|
if (pierced) this.darkenGlowIn(p);
|
|
13066
|
-
const
|
|
13067
|
-
|
|
13068
|
-
|
|
13198
|
+
for (const L of this.lampsOf(p)) this.kit.crackLight(this.c, L, new this.THREE.Vector3(p.box.center[0] > 0 ? -1 : 1, 0, 0), pierced);
|
|
13199
|
+
}
|
|
13200
|
+
/** The lamps of a light part: the ones its zone holds, or its own when no zone claims it (a fog lamp, a lit strip in the bumper). */
|
|
13201
|
+
lampsOf(p) {
|
|
13202
|
+
return p.lamps ?? this.zone(p)?.lights ?? [];
|
|
13069
13203
|
}
|
|
13070
13204
|
/** Everything of the lamp that glows goes dark: the fleet draws extra bulbs, reversing and amber strips in a lamp's place that the lamp's own list does not hold. */
|
|
13071
13205
|
darkenGlowIn(p) {
|
|
13072
13206
|
const dark = this.I.MATERIALS.bulbBroken;
|
|
13207
|
+
const dull = this.I.MATERIALS.broken;
|
|
13073
13208
|
const [cx, cy, cz] = p.box.center;
|
|
13074
13209
|
const [sx, sy, sz] = p.box.size;
|
|
13075
13210
|
this.c.vehicle.updateMatrixWorld(true);
|
|
13076
13211
|
this.c.vehicle.traverse((o) => {
|
|
13077
13212
|
const mesh = o;
|
|
13078
|
-
if (!mesh.isMesh || mesh.userData.glass || mesh.material === dark || Array.isArray(mesh.material)) return;
|
|
13079
|
-
const
|
|
13080
|
-
if (!
|
|
13213
|
+
if (!mesh.isMesh || mesh.userData.glass || mesh.userData.decal || mesh.material === dark || mesh.material === dull || Array.isArray(mesh.material)) return;
|
|
13214
|
+
const glows = isGlowing(mesh.material);
|
|
13215
|
+
if (!glows && !isMirrorChrome(mesh.material)) return;
|
|
13081
13216
|
mesh.geometry.computeBoundingBox();
|
|
13082
13217
|
const mid = this.c.vehicle.worldToLocal(mesh.localToWorld(mesh.geometry.boundingBox.getCenter(new this.THREE.Vector3())));
|
|
13083
13218
|
if (Math.abs(mid.x - cx) > sx / 2 + LAMP_BOX_MARGIN || Math.abs(mid.y - cy) > sy / 2 + LAMP_BOX_MARGIN || Math.abs(mid.z - cz) > sz / 2 + LAMP_BOX_MARGIN) return;
|
|
13084
|
-
mesh.material = dark;
|
|
13219
|
+
mesh.material = glows ? dark : dull;
|
|
13085
13220
|
});
|
|
13086
13221
|
}
|
|
13087
13222
|
/** The lens of a light breaks and its unit stays (damaged) or goes (destroyed). */
|
|
13088
13223
|
breakLight(p, gone) {
|
|
13089
13224
|
this.darkenGlowIn(p);
|
|
13090
|
-
const
|
|
13091
|
-
if (!z) return;
|
|
13092
|
-
for (const L of z.lights) {
|
|
13225
|
+
for (const L of this.lampsOf(p)) {
|
|
13093
13226
|
L.lensMaterial = p.material;
|
|
13094
13227
|
this.kit.breakLight(this.c, L, new this.THREE.Vector3(p.box.center[0] > 0 ? -1 : 1, 0, 0));
|
|
13095
13228
|
if (gone) {
|
|
@@ -13281,8 +13414,7 @@ var VehicleVisuals = class {
|
|
|
13281
13414
|
moved = true;
|
|
13282
13415
|
}
|
|
13283
13416
|
if (p.role === "light") {
|
|
13284
|
-
const
|
|
13285
|
-
for (const L of z?.lights ?? []) {
|
|
13417
|
+
for (const L of this.lampsOf(p)) {
|
|
13286
13418
|
L.broken = L.broken || true;
|
|
13287
13419
|
for (const h of L.halo ?? []) h.visible = false;
|
|
13288
13420
|
}
|
|
@@ -14288,6 +14420,7 @@ function createVehicleDestructible(kit, vehicleCtx, options = {}) {
|
|
|
14288
14420
|
if (meshParts) return meshParts;
|
|
14289
14421
|
meshParts = /* @__PURE__ */ new Map();
|
|
14290
14422
|
for (const d of model.parts) {
|
|
14423
|
+
for (const L of d.lamps ?? []) for (const m of [...L.lens, ...L.inner]) meshParts.set(m, d.id);
|
|
14291
14424
|
if (d.role !== "glass") continue;
|
|
14292
14425
|
const z = kit.zonesOf(c).find((q) => q.id === d.zoneId);
|
|
14293
14426
|
for (const g of z?.glass ?? d.panes ?? []) meshParts.set(g, d.id);
|
|
@@ -14787,6 +14920,7 @@ export {
|
|
|
14787
14920
|
rng,
|
|
14788
14921
|
smooth,
|
|
14789
14922
|
strHash,
|
|
14923
|
+
strayLampsOf,
|
|
14790
14924
|
swingOf,
|
|
14791
14925
|
wrapThreeForLod
|
|
14792
14926
|
};
|