@adatechnology/game-vehicles 0.4.7 → 0.5.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 +6 -0
- package/dist/index.d.ts +42 -2
- package/dist/index.global.js +88 -0
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +88 -0
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -12905,13 +12905,100 @@ function buildVehicleItem(kit, key, options = {}) {
|
|
|
12905
12905
|
root.userData.vehicle = vehicle;
|
|
12906
12906
|
return { root, vehicle };
|
|
12907
12907
|
}
|
|
12908
|
+
|
|
12909
|
+
// src/destructible/enclosure.ts
|
|
12910
|
+
var CABIN_LEAK = 0.02;
|
|
12911
|
+
var HOLE_RATE_PER_AREA = 3e3;
|
|
12912
|
+
var CRACK_GAP_PER_METRE = 0.5;
|
|
12913
|
+
var THROUGH = 0.18;
|
|
12914
|
+
var HOLE_PATCH = 0.12;
|
|
12915
|
+
var FULL_SWING = 1.15;
|
|
12916
|
+
var SHELL_ROLES = /* @__PURE__ */ new Set(["door", "glass", "roof", "lid", "panel", "pillar"]);
|
|
12917
|
+
var GONE = /* @__PURE__ */ new Set(["broken", "melted", "ashes"]);
|
|
12918
|
+
function cabinBoxOf(vehicle) {
|
|
12919
|
+
const cabin = vehicle.meta.cabin;
|
|
12920
|
+
if (!cabin || !(cabin.x1 > cabin.x0) || !(cabin.y1 > cabin.y0) || !(cabin.z > 0)) return null;
|
|
12921
|
+
return cabin;
|
|
12922
|
+
}
|
|
12923
|
+
function swingOf(vehicle, partId) {
|
|
12924
|
+
const pivot = vehicle.vehicle?.getObjectByName?.(partId);
|
|
12925
|
+
const q = pivot?.quaternion;
|
|
12926
|
+
if (!q) return 0;
|
|
12927
|
+
const angle = 2 * Math.acos(Math.min(1, Math.abs(q.w)));
|
|
12928
|
+
return Math.min(1, angle / FULL_SWING);
|
|
12929
|
+
}
|
|
12930
|
+
var overlaps = (b, c, margin) => Math.abs(b.center[0] - (c.x0 + c.x1) / 2) <= b.size[0] / 2 + (c.x1 - c.x0) / 2 + margin && Math.abs(b.center[1] - (c.y0 + c.y1) / 2) <= b.size[1] / 2 + (c.y1 - c.y0) / 2 + margin && Math.abs(b.center[2]) <= b.size[2] / 2 + c.z + margin;
|
|
12931
|
+
function cabinEnclosure(source, options = {}) {
|
|
12932
|
+
const c = source.vehicle;
|
|
12933
|
+
const cabin = cabinBoxOf(c);
|
|
12934
|
+
const node = c.vehicle;
|
|
12935
|
+
if (!cabin || !node?.localToWorld) return null;
|
|
12936
|
+
const state = source.state();
|
|
12937
|
+
if (state.destroyed) return null;
|
|
12938
|
+
const V3 = node.position.constructor;
|
|
12939
|
+
const Quat = node.quaternion.constructor;
|
|
12940
|
+
const mid = [(cabin.x0 + cabin.x1) / 2, (cabin.y0 + cabin.y1) / 2, 0];
|
|
12941
|
+
const half = [(cabin.x1 - cabin.x0) / 2, (cabin.y1 - cabin.y0) / 2, cabin.z];
|
|
12942
|
+
const ajar = options.ajar ?? 0.06;
|
|
12943
|
+
const byId = new Map(state.parts.map((p) => [p.id, p]));
|
|
12944
|
+
const mainGroup = state.groups[0] ? new Set(state.groups[0]) : null;
|
|
12945
|
+
const openings = [];
|
|
12946
|
+
let crackLength = 0;
|
|
12947
|
+
const toCabin = (b) => ({
|
|
12948
|
+
center: [b.center[0] - mid[0], b.center[1] - mid[1], b.center[2] - mid[2]],
|
|
12949
|
+
halfSize: [b.size[0] / 2 + THROUGH, b.size[1] / 2 + THROUGH, b.size[2] / 2 + THROUGH]
|
|
12950
|
+
});
|
|
12951
|
+
node.updateWorldMatrix?.(true, false);
|
|
12952
|
+
const frame = options.frame ?? c.root;
|
|
12953
|
+
frame?.updateWorldMatrix?.(true, false);
|
|
12954
|
+
const inverse = node.matrixWorld.clone().invert();
|
|
12955
|
+
for (const def of source.model.parts) {
|
|
12956
|
+
if (!SHELL_ROLES.has(def.role) || !overlaps(def.box, cabin, 0.12)) continue;
|
|
12957
|
+
const part = byId.get(def.id);
|
|
12958
|
+
if (!part) continue;
|
|
12959
|
+
const gone = GONE.has(part.status) || mainGroup !== null && !mainGroup.has(def.id);
|
|
12960
|
+
const swung = (def.role === "door" || def.role === "lid") && swingOf(c, def.id) > ajar;
|
|
12961
|
+
if (gone || swung) {
|
|
12962
|
+
openings.push(toCabin(def.box));
|
|
12963
|
+
continue;
|
|
12964
|
+
}
|
|
12965
|
+
for (const hole of part.holes) {
|
|
12966
|
+
if (!hole.through && def.material !== "glass") continue;
|
|
12967
|
+
const area = Math.PI * (hole.diameter / 2) ** 2;
|
|
12968
|
+
const p = new V3(hole.point[0], hole.point[1], hole.point[2]);
|
|
12969
|
+
if (frame?.localToWorld) frame.localToWorld(p);
|
|
12970
|
+
p.applyMatrix4(inverse);
|
|
12971
|
+
openings.push({
|
|
12972
|
+
center: [p.x - mid[0], p.y - mid[1], p.z - mid[2]],
|
|
12973
|
+
halfSize: [HOLE_PATCH, HOLE_PATCH, HOLE_PATCH],
|
|
12974
|
+
// the patch is far bigger than the hole: only a share of what crosses it passes, more for a bigger hole
|
|
12975
|
+
rate: Math.min(4, area * HOLE_RATE_PER_AREA)
|
|
12976
|
+
});
|
|
12977
|
+
}
|
|
12978
|
+
for (const crack of part.cracks) crackLength += crack.length;
|
|
12979
|
+
}
|
|
12980
|
+
const center = node.localToWorld(new V3(mid[0], mid[1], mid[2]));
|
|
12981
|
+
const q = node.getWorldQuaternion(new Quat());
|
|
12982
|
+
const scale = node.getWorldScale(new V3());
|
|
12983
|
+
const leak = (options.leak ?? CABIN_LEAK) * (1 + crackLength * CRACK_GAP_PER_METRE);
|
|
12984
|
+
return {
|
|
12985
|
+
center: [center.x, center.y, center.z],
|
|
12986
|
+
halfSize: [half[0] * Math.abs(scale.x), half[1] * Math.abs(scale.y), half[2] * Math.abs(scale.z)],
|
|
12987
|
+
orientation: [q.x, q.y, q.z, q.w],
|
|
12988
|
+
openings: openings.map((o) => ({ ...o, center: [o.center[0] * scale.x, o.center[1] * scale.y, o.center[2] * scale.z], halfSize: [o.halfSize[0] * Math.abs(scale.x), o.halfSize[1] * Math.abs(scale.y), o.halfSize[2] * Math.abs(scale.z)] })),
|
|
12989
|
+
leak
|
|
12990
|
+
};
|
|
12991
|
+
}
|
|
12908
12992
|
export {
|
|
12993
|
+
CABIN_LEAK,
|
|
12909
12994
|
JOINT_RULES,
|
|
12910
12995
|
LEGACY_STATES,
|
|
12911
12996
|
LEGACY_ZONE_IDS,
|
|
12912
12997
|
SEED_SALTS,
|
|
12913
12998
|
buildVehicleItem,
|
|
12914
12999
|
buildVehicleModel,
|
|
13000
|
+
cabinBoxOf,
|
|
13001
|
+
cabinEnclosure,
|
|
12915
13002
|
clamp,
|
|
12916
13003
|
createLod,
|
|
12917
13004
|
createTranslate,
|
|
@@ -12931,6 +13018,7 @@ export {
|
|
|
12931
13018
|
rng,
|
|
12932
13019
|
smooth,
|
|
12933
13020
|
strHash,
|
|
13021
|
+
swingOf,
|
|
12934
13022
|
wrapThreeForLod
|
|
12935
13023
|
};
|
|
12936
13024
|
//# sourceMappingURL=index.js.map
|