@adatechnology/game-vehicles 0.1.12 → 0.2.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 +4 -0
- package/dist/index.d.ts +80 -2
- package/dist/index.global.js +181 -8
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +181 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -837,9 +837,11 @@ function installGeometry(kit) {
|
|
|
837
837
|
const V3 = THREE.Vector3;
|
|
838
838
|
const PI = Math.PI;
|
|
839
839
|
const I = kit._;
|
|
840
|
+
const lod = kit.lod;
|
|
840
841
|
function roundedBoxGeometry(w, h, d, r) {
|
|
841
842
|
r = Math.max(2e-3, Math.min(r, w * 0.45, h * 0.45, d * 0.45));
|
|
842
|
-
|
|
843
|
+
if (lod.on && (r < 0.012 || Math.max(w, h, d) < lod.flatBoxEdge || Math.min(w, h, d) < 0.08)) return new THREE.BoxGeometry(w, h, d);
|
|
844
|
+
const nb = lod.on ? lod.roundingRings : 3;
|
|
843
845
|
const n = 2 * nb + 1;
|
|
844
846
|
const g = new THREE.BoxGeometry(1, 1, 1, n, n, n);
|
|
845
847
|
const p = g.attributes.position;
|
|
@@ -884,6 +886,7 @@ function installGeometry(kit) {
|
|
|
884
886
|
geo.computeVertexNormals();
|
|
885
887
|
}
|
|
886
888
|
function subdivide(geo, maxLen) {
|
|
889
|
+
if (lod.on) maxLen = maxLen * lod.subdivisionFactor;
|
|
887
890
|
const src = geo.index ? geo.toNonIndexed() : geo;
|
|
888
891
|
const a = src.attributes.position.array;
|
|
889
892
|
const out = [];
|
|
@@ -1613,6 +1616,7 @@ function installWarp(kit) {
|
|
|
1613
1616
|
const V3 = THREE.Vector3;
|
|
1614
1617
|
const PI = Math.PI;
|
|
1615
1618
|
const I = kit._;
|
|
1619
|
+
const lod = kit.lod;
|
|
1616
1620
|
const { crease } = I;
|
|
1617
1621
|
function makeWarp(o) {
|
|
1618
1622
|
function sec(y) {
|
|
@@ -1710,6 +1714,7 @@ function installWarp(kit) {
|
|
|
1710
1714
|
});
|
|
1711
1715
|
}
|
|
1712
1716
|
function resample(st, n) {
|
|
1717
|
+
if (lod.on) n = Math.max(lod.minStations, Math.round(n * lod.stationFraction));
|
|
1713
1718
|
const out = [];
|
|
1714
1719
|
const L = st.length;
|
|
1715
1720
|
function P(i) {
|
|
@@ -1741,6 +1746,7 @@ function installWarp(kit) {
|
|
|
1741
1746
|
}
|
|
1742
1747
|
function smoothLoft(st, o) {
|
|
1743
1748
|
o = o || {};
|
|
1749
|
+
if (lod.on) o = Object.assign({}, o, { seg: Math.max(lod.minLoftSegments, Math.round((o.seg || 24) * lod.loftSegmentFraction)) });
|
|
1744
1750
|
if (o.smooth) st = resample(st, o.smooth);
|
|
1745
1751
|
const seg = o.seg || 24;
|
|
1746
1752
|
const pos = [];
|
|
@@ -9755,16 +9761,167 @@ function installUi(kit) {
|
|
|
9755
9761
|
kit.ui = { damageMap, bandButtons, legend, healthBar, scenarioButtons, zoneLabel, bandRange, css, injectStyles };
|
|
9756
9762
|
}
|
|
9757
9763
|
|
|
9764
|
+
// src/lod.ts
|
|
9765
|
+
var defaultLodSettings = {
|
|
9766
|
+
on: false,
|
|
9767
|
+
segmentFraction: 0.5,
|
|
9768
|
+
roundingRings: 1,
|
|
9769
|
+
subdivisionFactor: 2.2,
|
|
9770
|
+
flatBoxEdge: 0.22,
|
|
9771
|
+
minLoftSegments: 14,
|
|
9772
|
+
loftSegmentFraction: 0.45,
|
|
9773
|
+
minStations: 20,
|
|
9774
|
+
stationFraction: 0.55,
|
|
9775
|
+
gridFactor: 2.6,
|
|
9776
|
+
hiddenMaterials: ["seat", "carpet", "headliner", "gauge", "screen", "bay", "hoodLiner", "block", "cover", "radiator", "coolant", "coolantLiq", "washer", "hv", "hose", "leather"]
|
|
9777
|
+
};
|
|
9778
|
+
function createLod(options) {
|
|
9779
|
+
return { ...defaultLodSettings, ...options || {}, on: false };
|
|
9780
|
+
}
|
|
9781
|
+
var fewer = (lod, n, min) => Math.max(min, Math.round(n * lod.segmentFraction));
|
|
9782
|
+
function wrapThreeForLod(TH, lod) {
|
|
9783
|
+
const T = Object.assign({}, TH);
|
|
9784
|
+
if (TH.SRGBColorSpace) {
|
|
9785
|
+
T.CanvasTexture = class extends TH.CanvasTexture {
|
|
9786
|
+
constructor(a, b, c, d, e, f, g, h, i) {
|
|
9787
|
+
super(a, b, c, d, e, f, g, h, i);
|
|
9788
|
+
this.colorSpace = TH.SRGBColorSpace;
|
|
9789
|
+
}
|
|
9790
|
+
};
|
|
9791
|
+
}
|
|
9792
|
+
T.CylinderGeometry = class extends TH.CylinderGeometry {
|
|
9793
|
+
constructor(rt, rb, h, rs, hs, open, ts, tl) {
|
|
9794
|
+
super(rt, rb, h, lod.on && rs != null ? fewer(lod, rs, 6) : rs, lod.on ? 1 : hs, open, ts, tl);
|
|
9795
|
+
}
|
|
9796
|
+
};
|
|
9797
|
+
T.SphereGeometry = class extends TH.SphereGeometry {
|
|
9798
|
+
constructor(r, ws, hs, ps, pl, ts, tl) {
|
|
9799
|
+
super(r, lod.on && ws != null ? fewer(lod, ws, 8) : ws, lod.on && hs != null ? fewer(lod, hs, 5) : hs, ps, pl, ts, tl);
|
|
9800
|
+
}
|
|
9801
|
+
};
|
|
9802
|
+
T.TorusGeometry = class extends TH.TorusGeometry {
|
|
9803
|
+
constructor(r, tube, rs, ts, arc) {
|
|
9804
|
+
super(r, tube, lod.on && rs != null ? fewer(lod, rs, 4) : rs, lod.on && ts != null ? fewer(lod, ts, 8) : ts, arc);
|
|
9805
|
+
}
|
|
9806
|
+
};
|
|
9807
|
+
T.LatheGeometry = class extends TH.LatheGeometry {
|
|
9808
|
+
constructor(pts, seg, a, b) {
|
|
9809
|
+
super(pts, lod.on && seg != null ? fewer(lod, seg, 10) : seg, a, b);
|
|
9810
|
+
}
|
|
9811
|
+
};
|
|
9812
|
+
T.TubeGeometry = class extends TH.TubeGeometry {
|
|
9813
|
+
constructor(path, ts, r, rs, closed) {
|
|
9814
|
+
if (lod.on) {
|
|
9815
|
+
let len = 1;
|
|
9816
|
+
try {
|
|
9817
|
+
len = path.getLength();
|
|
9818
|
+
} catch (e) {
|
|
9819
|
+
}
|
|
9820
|
+
ts = Math.max(6, Math.min(ts == null ? 64 : ts, Math.ceil(len / 0.14)));
|
|
9821
|
+
rs = r < 0.025 ? 3 : Math.max(4, fewer(lod, rs == null ? 8 : rs, 4));
|
|
9822
|
+
}
|
|
9823
|
+
super(path, ts, r, rs, closed);
|
|
9824
|
+
}
|
|
9825
|
+
};
|
|
9826
|
+
T.ExtrudeGeometry = class extends TH.ExtrudeGeometry {
|
|
9827
|
+
constructor(shape, o) {
|
|
9828
|
+
if (lod.on && o) {
|
|
9829
|
+
o = Object.assign({}, o);
|
|
9830
|
+
if (o.curveSegments) o.curveSegments = fewer(lod, o.curveSegments, 5);
|
|
9831
|
+
if (o.bevelSegments) o.bevelSegments = Math.max(1, Math.round(o.bevelSegments * 0.5));
|
|
9832
|
+
}
|
|
9833
|
+
super(shape, o);
|
|
9834
|
+
}
|
|
9835
|
+
};
|
|
9836
|
+
T.CircleGeometry = class extends TH.CircleGeometry {
|
|
9837
|
+
constructor(r, seg, a, b) {
|
|
9838
|
+
super(r, lod.on && seg != null ? fewer(lod, seg, 8) : seg, a, b);
|
|
9839
|
+
}
|
|
9840
|
+
};
|
|
9841
|
+
T.RingGeometry = class extends TH.RingGeometry {
|
|
9842
|
+
constructor(a, b, ts, ps, c, d) {
|
|
9843
|
+
super(a, b, lod.on && ts != null ? fewer(lod, ts, 8) : ts, ps, c, d);
|
|
9844
|
+
}
|
|
9845
|
+
};
|
|
9846
|
+
return T;
|
|
9847
|
+
}
|
|
9848
|
+
var INTERIOR_FUNCTIONS = ["interior", "engineBay", "seat", "dashboard", "steeringWheel", "yoke", "busRows"];
|
|
9849
|
+
function installLod(kit) {
|
|
9850
|
+
const lod = kit.lod;
|
|
9851
|
+
const meshesOf = (c) => {
|
|
9852
|
+
const set = /* @__PURE__ */ new Set();
|
|
9853
|
+
c.vehicle.traverse((o) => {
|
|
9854
|
+
if (o.isMesh) set.add(o);
|
|
9855
|
+
});
|
|
9856
|
+
return set;
|
|
9857
|
+
};
|
|
9858
|
+
for (const name of INTERIOR_FUNCTIONS) {
|
|
9859
|
+
const original = kit[name];
|
|
9860
|
+
if (typeof original !== "function") continue;
|
|
9861
|
+
kit[name] = function(...args) {
|
|
9862
|
+
const c = args[0];
|
|
9863
|
+
if (!lod.on || !c || !c.vehicle) return original.apply(this, args);
|
|
9864
|
+
const before = meshesOf(c);
|
|
9865
|
+
const result = original.apply(this, args);
|
|
9866
|
+
c.vehicle.traverse((o) => {
|
|
9867
|
+
if (o.isMesh && !before.has(o)) o.userData.skipLite = true;
|
|
9868
|
+
});
|
|
9869
|
+
return result;
|
|
9870
|
+
};
|
|
9871
|
+
}
|
|
9872
|
+
kit.lodHiddenMaterials = function() {
|
|
9873
|
+
const materials = kit.materials;
|
|
9874
|
+
return new Set(lod.hiddenMaterials.map((name) => materials[name]).filter(Boolean));
|
|
9875
|
+
};
|
|
9876
|
+
}
|
|
9877
|
+
|
|
9878
|
+
// src/damageables.ts
|
|
9879
|
+
var defaultDamageableKinds = {
|
|
9880
|
+
door: { material: "metal", part: "door" },
|
|
9881
|
+
hood: { material: "metal", part: "hood" },
|
|
9882
|
+
lid: { material: "metal", part: "lid" },
|
|
9883
|
+
bumper: { material: "metal", part: "bumper" },
|
|
9884
|
+
glass: { material: "glass", part: "window" },
|
|
9885
|
+
"glass:windshield": { material: "glass", part: "windshield" },
|
|
9886
|
+
light: { material: "glass", part: "headlight" },
|
|
9887
|
+
"light:taillight": { material: "glass", part: "taillight" },
|
|
9888
|
+
wheel: { material: "rubber", part: "wheel" },
|
|
9889
|
+
"internal:fuel_tank": { material: "fuel", part: "fuel_tank" }
|
|
9890
|
+
};
|
|
9891
|
+
function installDamageables(kit) {
|
|
9892
|
+
const THREE = kit.THREE;
|
|
9893
|
+
kit.damageableKinds = { ...defaultDamageableKinds };
|
|
9894
|
+
const kindOf2 = (zone) => {
|
|
9895
|
+
const kinds = kit.damageableKinds;
|
|
9896
|
+
if (zone.type === "internal") return zone.sub ? kinds[`internal:${zone.sub}`] || null : null;
|
|
9897
|
+
return kinds[`${zone.type}:${zone.fxKey}`] || kinds[zone.type] || null;
|
|
9898
|
+
};
|
|
9899
|
+
kit.damageables = function(c, matrix) {
|
|
9900
|
+
const out = [];
|
|
9901
|
+
for (const zone of c.zones || []) {
|
|
9902
|
+
const kind = kindOf2(zone);
|
|
9903
|
+
if (!kind || !zone.box) continue;
|
|
9904
|
+
const b = zone.box;
|
|
9905
|
+
const box = new THREE.Box3(new THREE.Vector3(b.x0, b.y0, b.z0), new THREE.Vector3(b.x1, b.y1, b.z1));
|
|
9906
|
+
if (matrix) box.applyMatrix4(matrix);
|
|
9907
|
+
out.push({ material: kind.material, zone: zone.id, part: kind.part, side: zone.side === 0 ? "center" : zone.side < 0 ? "left" : "right", box });
|
|
9908
|
+
}
|
|
9909
|
+
return out;
|
|
9910
|
+
};
|
|
9911
|
+
}
|
|
9912
|
+
|
|
9758
9913
|
// src/kit.ts
|
|
9759
9914
|
function createVehicleKit(options) {
|
|
9760
9915
|
const opts = options || {};
|
|
9761
|
-
|
|
9762
|
-
|
|
9916
|
+
if (!opts.THREE || !opts.THREE.Vector3) throw new Error("createVehicleKit: options.THREE (the three.js namespace) is required");
|
|
9917
|
+
const lod = createLod(opts.lod);
|
|
9918
|
+
const THREE = wrapThreeForLod(opts.THREE, lod);
|
|
9763
9919
|
const strings = resolveStrings(opts.locale);
|
|
9764
9920
|
const t = createTranslate(strings);
|
|
9765
9921
|
const doc = opts.document || (typeof document !== "undefined" ? document : void 0);
|
|
9766
9922
|
const kit = {
|
|
9767
9923
|
THREE,
|
|
9924
|
+
lod,
|
|
9768
9925
|
V3: THREE.Vector3,
|
|
9769
9926
|
PI: Math.PI,
|
|
9770
9927
|
document: doc,
|
|
@@ -9836,6 +9993,8 @@ function createVehicleKit(options) {
|
|
|
9836
9993
|
installZoneApply(kit);
|
|
9837
9994
|
installScenarios(kit);
|
|
9838
9995
|
installUi(kit);
|
|
9996
|
+
installLod(kit);
|
|
9997
|
+
installDamageables(kit);
|
|
9839
9998
|
const I = kit._;
|
|
9840
9999
|
const HOOKS = {};
|
|
9841
10000
|
kit.on = function(ev, fn) {
|
|
@@ -9930,9 +10089,18 @@ function createVehicleKit(options) {
|
|
|
9930
10089
|
}
|
|
9931
10090
|
}
|
|
9932
10091
|
kit.defaultDamage = defaultDamage;
|
|
9933
|
-
kit.build = function(key, state, zoneState) {
|
|
10092
|
+
kit.build = function(key, state, zoneState, options2) {
|
|
9934
10093
|
const spec = kit.find(key);
|
|
9935
10094
|
if (!spec) throw new Error("Unknown vehicle: " + key);
|
|
10095
|
+
const lodBefore = lod.on;
|
|
10096
|
+
if (options2 && options2.lod != null) lod.on = !!options2.lod;
|
|
10097
|
+
try {
|
|
10098
|
+
return buildVehicle(spec, key, state, zoneState);
|
|
10099
|
+
} finally {
|
|
10100
|
+
lod.on = lodBefore;
|
|
10101
|
+
}
|
|
10102
|
+
};
|
|
10103
|
+
function buildVehicle(spec, key, state, zoneState) {
|
|
9936
10104
|
const st = state || "intact";
|
|
9937
10105
|
const seedKey = spec.seedKey || key;
|
|
9938
10106
|
const c = new kit.BuildContext(st, strHash(seedKey + (LEGACY_STATES[st] || st)));
|
|
@@ -9981,7 +10149,7 @@ function createVehicleKit(options) {
|
|
|
9981
10149
|
if (o.isMesh && !(o.material && o.material.transparent)) o.receiveShadow = true;
|
|
9982
10150
|
});
|
|
9983
10151
|
return c;
|
|
9984
|
-
}
|
|
10152
|
+
}
|
|
9985
10153
|
kit.dispose = function(c) {
|
|
9986
10154
|
const shared = Object.values(I.PARTICLE_GEOMETRIES);
|
|
9987
10155
|
c.root.traverse(function(o) {
|
|
@@ -9998,8 +10166,9 @@ function createVehicleKit(options) {
|
|
|
9998
10166
|
assignDeep(strings, resolveStrings(opts.locale));
|
|
9999
10167
|
return kit;
|
|
10000
10168
|
};
|
|
10001
|
-
const { THREE: _three, locale: _locale, document: _document, plugins, ...config } = opts;
|
|
10169
|
+
const { THREE: _three, lod: _lod, locale: _locale, document: _document, plugins, ...config } = opts;
|
|
10002
10170
|
void _three;
|
|
10171
|
+
void _lod;
|
|
10003
10172
|
void _locale;
|
|
10004
10173
|
void _document;
|
|
10005
10174
|
kit.configure(config);
|
|
@@ -11953,7 +12122,7 @@ function createVehicleDestructible(kit, vehicleCtx, options = {}) {
|
|
|
11953
12122
|
// src/destructible/item.ts
|
|
11954
12123
|
function buildVehicleItem(kit, key, options = {}) {
|
|
11955
12124
|
const THREE = kit.THREE;
|
|
11956
|
-
const vehicle = kit.build(key, options.state ?? "intact");
|
|
12125
|
+
const vehicle = options.lod ? kit.build(key, options.state ?? "intact", void 0, { lod: true }) : kit.build(key, options.state ?? "intact");
|
|
11957
12126
|
const m = vehicle.meta;
|
|
11958
12127
|
const root = new THREE.Group();
|
|
11959
12128
|
root.name = key;
|
|
@@ -11973,9 +12142,12 @@ export {
|
|
|
11973
12142
|
buildVehicleItem,
|
|
11974
12143
|
buildVehicleModel,
|
|
11975
12144
|
clamp,
|
|
12145
|
+
createLod,
|
|
11976
12146
|
createTranslate,
|
|
11977
12147
|
createVehicleDestructible,
|
|
11978
12148
|
createVehicleKit,
|
|
12149
|
+
defaultDamageableKinds,
|
|
12150
|
+
defaultLodSettings,
|
|
11979
12151
|
format,
|
|
11980
12152
|
hash,
|
|
11981
12153
|
legacyGlassId,
|
|
@@ -11987,6 +12159,7 @@ export {
|
|
|
11987
12159
|
resolveStrings,
|
|
11988
12160
|
rng,
|
|
11989
12161
|
smooth,
|
|
11990
|
-
strHash
|
|
12162
|
+
strHash,
|
|
12163
|
+
wrapThreeForLod
|
|
11991
12164
|
};
|
|
11992
12165
|
//# sourceMappingURL=index.js.map
|