@adatechnology/game-vehicles 0.3.0 → 0.4.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 -2
- package/dist/index.d.ts +11 -2
- package/dist/index.global.js +284 -60
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +284 -60
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -938,46 +938,79 @@ function installGeometry(kit) {
|
|
|
938
938
|
}
|
|
939
939
|
const p = geo.attributes.position;
|
|
940
940
|
const n = p.count;
|
|
941
|
-
const
|
|
942
|
-
const
|
|
943
|
-
const
|
|
944
|
-
const
|
|
945
|
-
const C = new V3();
|
|
946
|
-
const e1 = new V3();
|
|
947
|
-
const e2 = new V3();
|
|
941
|
+
const faces = n / 3;
|
|
942
|
+
const FN = new Float64Array(faces * 3);
|
|
943
|
+
const map = /* @__PURE__ */ new Map();
|
|
944
|
+
const RANGE = 65536;
|
|
948
945
|
function key(i) {
|
|
949
|
-
|
|
946
|
+
const x = Math.round(p.getX(i) * 2e3);
|
|
947
|
+
const y = Math.round(p.getY(i) * 2e3);
|
|
948
|
+
const z = Math.round(p.getZ(i) * 2e3);
|
|
949
|
+
if (Math.abs(x) < RANGE && Math.abs(y) < RANGE && Math.abs(z) < RANGE) return ((x + RANGE) * 131072 + (y + RANGE)) * 131072 + (z + RANGE);
|
|
950
|
+
return x + "," + y + "," + z;
|
|
950
951
|
}
|
|
951
952
|
const keys = new Array(n);
|
|
952
|
-
for (let f = 0; f <
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
const
|
|
957
|
-
|
|
958
|
-
|
|
953
|
+
for (let f = 0; f < faces; f++) {
|
|
954
|
+
const ax = p.getX(3 * f);
|
|
955
|
+
const ay = p.getY(3 * f);
|
|
956
|
+
const az = p.getZ(3 * f);
|
|
957
|
+
const bx = p.getX(3 * f + 1);
|
|
958
|
+
const by = p.getY(3 * f + 1);
|
|
959
|
+
const bz = p.getZ(3 * f + 1);
|
|
960
|
+
const cx = p.getX(3 * f + 2);
|
|
961
|
+
const cy = p.getY(3 * f + 2);
|
|
962
|
+
const cz = p.getZ(3 * f + 2);
|
|
963
|
+
const e1x = cx - bx;
|
|
964
|
+
const e1y = cy - by;
|
|
965
|
+
const e1z = cz - bz;
|
|
966
|
+
const e2x = ax - bx;
|
|
967
|
+
const e2y = ay - by;
|
|
968
|
+
const e2z = az - bz;
|
|
969
|
+
let nx = e1y * e2z - e1z * e2y;
|
|
970
|
+
let ny = e1z * e2x - e1x * e2z;
|
|
971
|
+
let nz = e1x * e2y - e1y * e2x;
|
|
972
|
+
if (nx * nx + ny * ny + nz * nz > 1e-20) {
|
|
973
|
+
const inv = 1 / (Math.sqrt(nx * nx + ny * ny + nz * nz) || 1);
|
|
974
|
+
nx *= inv;
|
|
975
|
+
ny *= inv;
|
|
976
|
+
nz *= inv;
|
|
977
|
+
}
|
|
978
|
+
FN[3 * f] = nx;
|
|
979
|
+
FN[3 * f + 1] = ny;
|
|
980
|
+
FN[3 * f + 2] = nz;
|
|
959
981
|
for (let k = 0; k < 3; k++) {
|
|
960
982
|
const kk = key(3 * f + k);
|
|
961
983
|
keys[3 * f + k] = kk;
|
|
962
|
-
|
|
984
|
+
const list = map.get(kk);
|
|
985
|
+
if (list) list.push(f);
|
|
986
|
+
else map.set(kk, [f]);
|
|
963
987
|
}
|
|
964
988
|
}
|
|
965
989
|
const cs = Math.cos(deg * PI / 180);
|
|
966
990
|
const out = new Float32Array(n * 3);
|
|
967
|
-
const s = new V3();
|
|
968
991
|
for (let i = 0; i < n; i++) {
|
|
969
|
-
const fi = i / 3 | 0;
|
|
970
|
-
const list = map
|
|
971
|
-
|
|
992
|
+
const fi = (i / 3 | 0) * 3;
|
|
993
|
+
const list = map.get(keys[i]);
|
|
994
|
+
let sx = 0;
|
|
995
|
+
let sy = 0;
|
|
996
|
+
let sz = 0;
|
|
972
997
|
for (let j = 0; j < list.length; j++) {
|
|
973
|
-
const g =
|
|
974
|
-
if (g
|
|
998
|
+
const g = list[j] * 3;
|
|
999
|
+
if (FN[g] * FN[fi] + FN[g + 1] * FN[fi + 1] + FN[g + 2] * FN[fi + 2] >= cs) {
|
|
1000
|
+
sx += FN[g];
|
|
1001
|
+
sy += FN[g + 1];
|
|
1002
|
+
sz += FN[g + 2];
|
|
1003
|
+
}
|
|
975
1004
|
}
|
|
976
|
-
if (
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
1005
|
+
if (sx * sx + sy * sy + sz * sz < 1e-20) {
|
|
1006
|
+
sx = FN[fi];
|
|
1007
|
+
sy = FN[fi + 1];
|
|
1008
|
+
sz = FN[fi + 2];
|
|
1009
|
+
}
|
|
1010
|
+
const inv = 1 / (Math.sqrt(sx * sx + sy * sy + sz * sz) || 1);
|
|
1011
|
+
out[3 * i] = sx * inv;
|
|
1012
|
+
out[3 * i + 1] = sy * inv;
|
|
1013
|
+
out[3 * i + 2] = sz * inv;
|
|
981
1014
|
}
|
|
982
1015
|
geo.setAttribute("normal", new THREE.BufferAttribute(out, 3));
|
|
983
1016
|
geo.userData.crease = true;
|
|
@@ -6635,6 +6668,153 @@ function installZoneDecals(kit) {
|
|
|
6635
6668
|
return hole;
|
|
6636
6669
|
}
|
|
6637
6670
|
const _zr = new THREE.Raycaster();
|
|
6671
|
+
const PROXY_MIN_TRIANGLES = 500;
|
|
6672
|
+
const STROKE_REACH = 0.6;
|
|
6673
|
+
const _pv = new V3();
|
|
6674
|
+
const _pm = new THREE.Matrix4();
|
|
6675
|
+
function decalRegion(c, z) {
|
|
6676
|
+
const B = z.box;
|
|
6677
|
+
const lo = [0, 1, 2].map(function(k) {
|
|
6678
|
+
return I.boxLo(B, k) - STROKE_REACH;
|
|
6679
|
+
});
|
|
6680
|
+
const hi = [0, 1, 2].map(function(k) {
|
|
6681
|
+
return I.boxHi(B, k) + STROKE_REACH;
|
|
6682
|
+
});
|
|
6683
|
+
const a = axisOf(z.dir);
|
|
6684
|
+
const dn = z.dir.clone().normalize();
|
|
6685
|
+
const sg = z.dir.getComponent(a) > 0 ? 1 : -1;
|
|
6686
|
+
const outer = sg > 0 ? I.boxLo(B, a) - 0.6 : I.boxHi(B, a) + 0.6;
|
|
6687
|
+
const far = 0.6 + (I.boxHi(B, a) - I.boxLo(B, a)) + 0.05;
|
|
6688
|
+
for (let i = 0; i < 8; i++) {
|
|
6689
|
+
const p = new V3();
|
|
6690
|
+
p.setComponent(a, outer);
|
|
6691
|
+
[0, 1, 2].filter(function(k) {
|
|
6692
|
+
return k !== a;
|
|
6693
|
+
}).forEach(function(k, j) {
|
|
6694
|
+
p.setComponent(k, i >> j & 1 ? I.boxHi(B, k) : I.boxLo(B, k));
|
|
6695
|
+
});
|
|
6696
|
+
for (let e = 0; e < 2; e++) {
|
|
6697
|
+
const q = e ? p.clone().addScaledVector(dn, far) : p;
|
|
6698
|
+
for (let k = 0; k < 3; k++) {
|
|
6699
|
+
lo[k] = Math.min(lo[k], q.getComponent(k) - 0.05);
|
|
6700
|
+
hi[k] = Math.max(hi[k], q.getComponent(k) + 0.05);
|
|
6701
|
+
}
|
|
6702
|
+
}
|
|
6703
|
+
}
|
|
6704
|
+
return { lo, hi };
|
|
6705
|
+
}
|
|
6706
|
+
function regionCands(c, z, cands) {
|
|
6707
|
+
if (!cands.some(heavy)) return cands;
|
|
6708
|
+
const R = decalRegion(c, z);
|
|
6709
|
+
const Mw = c.vehicle.matrixWorld;
|
|
6710
|
+
return cands.map(function(o) {
|
|
6711
|
+
if (!heavy(o)) return o;
|
|
6712
|
+
if (!o.geometry.boundingSphere) o.geometry.computeBoundingSphere();
|
|
6713
|
+
if (!o.geometry.boundingBox) o.geometry.computeBoundingBox();
|
|
6714
|
+
return proxyIn(o, Mw, R);
|
|
6715
|
+
});
|
|
6716
|
+
}
|
|
6717
|
+
function heavy(o) {
|
|
6718
|
+
const g = o.geometry;
|
|
6719
|
+
const pos = g && g.attributes && g.attributes.position;
|
|
6720
|
+
return o.raycast === THREE.Mesh.prototype.raycast && !o.isSkinnedMesh && !Array.isArray(o.material) && pos && !pos.isInterleavedBufferAttribute && pos.itemSize === 3 && !g.groups.length && !(g.morphAttributes && g.morphAttributes.position) && (g.index ? g.index.count : pos.count) / 3 >= PROXY_MIN_TRIANGLES;
|
|
6721
|
+
}
|
|
6722
|
+
function proxyIn(o, Mw, R) {
|
|
6723
|
+
_pm.copy(o.matrixWorld).invert().multiply(Mw);
|
|
6724
|
+
const lo = [Infinity, Infinity, Infinity];
|
|
6725
|
+
const hi = [-Infinity, -Infinity, -Infinity];
|
|
6726
|
+
for (let i = 0; i < 8; i++) {
|
|
6727
|
+
_pv.set(i & 1 ? R.hi[0] : R.lo[0], i & 2 ? R.hi[1] : R.lo[1], i & 4 ? R.hi[2] : R.lo[2]).applyMatrix4(_pm);
|
|
6728
|
+
for (let k = 0; k < 3; k++) {
|
|
6729
|
+
lo[k] = Math.min(lo[k], _pv.getComponent(k));
|
|
6730
|
+
hi[k] = Math.max(hi[k], _pv.getComponent(k));
|
|
6731
|
+
}
|
|
6732
|
+
}
|
|
6733
|
+
const g = o.geometry;
|
|
6734
|
+
const P = g.attributes.position.array;
|
|
6735
|
+
const ix = g.index ? g.index.array : null;
|
|
6736
|
+
const n = ix ? ix.length : P.length / 3;
|
|
6737
|
+
const keep = new Uint32Array(n - n % 3);
|
|
6738
|
+
let nk = 0;
|
|
6739
|
+
for (let t = 0; t + 2 < n; t += 3) {
|
|
6740
|
+
const a = (ix ? ix[t] : t) * 3;
|
|
6741
|
+
const b = (ix ? ix[t + 1] : t + 1) * 3;
|
|
6742
|
+
const d = (ix ? ix[t + 2] : t + 2) * 3;
|
|
6743
|
+
let out = false;
|
|
6744
|
+
for (let k = 0; k < 3 && !out; k++) {
|
|
6745
|
+
const u = P[a + k];
|
|
6746
|
+
const v = P[b + k];
|
|
6747
|
+
const w = P[d + k];
|
|
6748
|
+
out = Math.max(u, v, w) < lo[k] || Math.min(u, v, w) > hi[k];
|
|
6749
|
+
}
|
|
6750
|
+
if (!out) {
|
|
6751
|
+
keep[nk++] = ix ? ix[t] : t;
|
|
6752
|
+
keep[nk++] = ix ? ix[t + 1] : t + 1;
|
|
6753
|
+
keep[nk++] = ix ? ix[t + 2] : t + 2;
|
|
6754
|
+
}
|
|
6755
|
+
}
|
|
6756
|
+
if (!nk) return null;
|
|
6757
|
+
const kept = keep.slice(0, nk);
|
|
6758
|
+
const box = new Float32Array(kept.length / 3 * 6);
|
|
6759
|
+
for (let t = 0, j = 0; t < kept.length; t += 3, j += 6) {
|
|
6760
|
+
const a = kept[t] * 3;
|
|
6761
|
+
const b = kept[t + 1] * 3;
|
|
6762
|
+
const d = kept[t + 2] * 3;
|
|
6763
|
+
for (let k = 0; k < 3; k++) {
|
|
6764
|
+
box[j + k] = Math.min(P[a + k], P[b + k], P[d + k]);
|
|
6765
|
+
box[j + 3 + k] = Math.max(P[a + k], P[b + k], P[d + k]);
|
|
6766
|
+
}
|
|
6767
|
+
}
|
|
6768
|
+
const pg = new THREE.BufferGeometry();
|
|
6769
|
+
pg.setAttribute("position", g.attributes.position);
|
|
6770
|
+
pg.setIndex(new THREE.BufferAttribute(new Uint32Array(kept.length), 1));
|
|
6771
|
+
pg.boundingSphere = g.boundingSphere;
|
|
6772
|
+
pg.boundingBox = g.boundingBox;
|
|
6773
|
+
const proxy = new THREE.Mesh(pg, o.material);
|
|
6774
|
+
proxy.layers.mask = o.layers.mask;
|
|
6775
|
+
proxy.proxyOf = o;
|
|
6776
|
+
proxy.kept = kept;
|
|
6777
|
+
proxy.keptBox = box;
|
|
6778
|
+
return proxy;
|
|
6779
|
+
}
|
|
6780
|
+
function narrowTo(rc, proxy) {
|
|
6781
|
+
const o = proxy.proxyOf;
|
|
6782
|
+
const ray = rc.ray;
|
|
6783
|
+
_pm.copy(o.matrixWorld).invert();
|
|
6784
|
+
_pv.copy(ray.origin).applyMatrix4(_pm);
|
|
6785
|
+
const x0 = _pv.x;
|
|
6786
|
+
const y0 = _pv.y;
|
|
6787
|
+
const z0 = _pv.z;
|
|
6788
|
+
_pv.copy(ray.direction).multiplyScalar(rc.far).add(ray.origin).applyMatrix4(_pm);
|
|
6789
|
+
const lo0 = Math.min(x0, _pv.x) - 1e-4;
|
|
6790
|
+
const lo1 = Math.min(y0, _pv.y) - 1e-4;
|
|
6791
|
+
const lo2 = Math.min(z0, _pv.z) - 1e-4;
|
|
6792
|
+
const hi0 = Math.max(x0, _pv.x) + 1e-4;
|
|
6793
|
+
const hi1 = Math.max(y0, _pv.y) + 1e-4;
|
|
6794
|
+
const hi2 = Math.max(z0, _pv.z) + 1e-4;
|
|
6795
|
+
const K = proxy.kept;
|
|
6796
|
+
const X = proxy.keptBox;
|
|
6797
|
+
const dst = proxy.geometry.index.array;
|
|
6798
|
+
let m = 0;
|
|
6799
|
+
for (let t = 0, j = 0; t < K.length; t += 3, j += 6) {
|
|
6800
|
+
if (X[j + 3] < lo0 || X[j] > hi0 || X[j + 4] < lo1 || X[j + 1] > hi1 || X[j + 5] < lo2 || X[j + 2] > hi2) continue;
|
|
6801
|
+
dst[m++] = K[t];
|
|
6802
|
+
dst[m++] = K[t + 1];
|
|
6803
|
+
dst[m++] = K[t + 2];
|
|
6804
|
+
}
|
|
6805
|
+
proxy.geometry.setDrawRange(0, m);
|
|
6806
|
+
}
|
|
6807
|
+
function castAt(rc, cands) {
|
|
6808
|
+
for (let i = 0; i < cands.length; i++) {
|
|
6809
|
+
const q = cands[i];
|
|
6810
|
+
if (!q.proxyOf) continue;
|
|
6811
|
+
q.matrixWorld.copy(q.proxyOf.matrixWorld);
|
|
6812
|
+
narrowTo(rc, q);
|
|
6813
|
+
}
|
|
6814
|
+
const hits = rc.intersectObjects(cands, false);
|
|
6815
|
+
for (let i = 0; i < hits.length; i++) if (hits[i].object.proxyOf) hits[i].object = hits[i].object.proxyOf;
|
|
6816
|
+
return hits;
|
|
6817
|
+
}
|
|
6638
6818
|
function zoneCands(c, z, inv, glassToo) {
|
|
6639
6819
|
const out = [];
|
|
6640
6820
|
c.vehicle.traverse(function(o) {
|
|
@@ -6687,7 +6867,7 @@ function installZoneDecals(kit) {
|
|
|
6687
6867
|
});
|
|
6688
6868
|
_zr.set(org.clone().applyMatrix4(Mw), d.clone().transformDirection(Mw));
|
|
6689
6869
|
_zr.far = 0.6 + (I.boxHi(B, a) - I.boxLo(B, a)) + 0.05;
|
|
6690
|
-
const hits = _zr
|
|
6870
|
+
const hits = castAt(_zr, cands);
|
|
6691
6871
|
for (let i = 0; i < hits.length; i++) {
|
|
6692
6872
|
const h = hits[i];
|
|
6693
6873
|
if (!h.face) continue;
|
|
@@ -6715,7 +6895,7 @@ function installZoneDecals(kit) {
|
|
|
6715
6895
|
const q = s.p.clone().addScaledVector(t, len * 0.5 * k / M);
|
|
6716
6896
|
_rt.set(q.clone().addScaledVector(n, 0.08).applyMatrix4(Mw), n.clone().negate().transformDirection(Mw));
|
|
6717
6897
|
_rt.far = 0.2;
|
|
6718
|
-
const h = _rt
|
|
6898
|
+
const h = castAt(_rt, cands).find(function(x) {
|
|
6719
6899
|
return x.face;
|
|
6720
6900
|
});
|
|
6721
6901
|
if (!h) return null;
|
|
@@ -6786,6 +6966,7 @@ function installZoneDecals(kit) {
|
|
|
6786
6966
|
const R = c.rand;
|
|
6787
6967
|
const need = (spec.fine || 0) + (spec.deep || 0) + (spec.chip || 0) + (spec.rust || 0) + (spec.tear || 0) + (spec.ding || 0) + (spec.soot || 0) + (spec.crater || 0);
|
|
6788
6968
|
if (!need) return [];
|
|
6969
|
+
cands = regionCands(c, z, cands).filter(Boolean);
|
|
6789
6970
|
const S = zoneSurf(c, z, need + 2, R, cands);
|
|
6790
6971
|
let k = 0;
|
|
6791
6972
|
const ang0 = R() * PI;
|
|
@@ -6866,8 +7047,25 @@ function installZoneDent(kit) {
|
|
|
6866
7047
|
}
|
|
6867
7048
|
function subdivIn(geo, rel, B, maxLen) {
|
|
6868
7049
|
const a = geo.attributes.position.array;
|
|
6869
|
-
|
|
6870
|
-
|
|
7050
|
+
let out = new Float32Array(a.length + 4096);
|
|
7051
|
+
let used = 0;
|
|
7052
|
+
const push = function(a0, a1, a2, b0, b1, b2, c0, c1, c2) {
|
|
7053
|
+
if (used + 9 > out.length) {
|
|
7054
|
+
const bigger = new Float32Array(out.length * 2);
|
|
7055
|
+
bigger.set(out);
|
|
7056
|
+
out = bigger;
|
|
7057
|
+
}
|
|
7058
|
+
out[used] = a0;
|
|
7059
|
+
out[used + 1] = a1;
|
|
7060
|
+
out[used + 2] = a2;
|
|
7061
|
+
out[used + 3] = b0;
|
|
7062
|
+
out[used + 4] = b1;
|
|
7063
|
+
out[used + 5] = b2;
|
|
7064
|
+
out[used + 6] = c0;
|
|
7065
|
+
out[used + 7] = c1;
|
|
7066
|
+
out[used + 8] = c2;
|
|
7067
|
+
used += 9;
|
|
7068
|
+
};
|
|
6871
7069
|
const e = 0.15;
|
|
6872
7070
|
function d(p, q) {
|
|
6873
7071
|
return Math.hypot(p[0] - q[0], p[1] - q[1], p[2] - q[2]);
|
|
@@ -6881,7 +7079,7 @@ function installZoneDent(kit) {
|
|
|
6881
7079
|
const ca = d(C, A);
|
|
6882
7080
|
const mx = Math.max(ab, bc, ca);
|
|
6883
7081
|
if (mx <= maxLen || depth > 9) {
|
|
6884
|
-
|
|
7082
|
+
push(A[0], A[1], A[2], Bv[0], Bv[1], Bv[2], C[0], C[1], C[2]);
|
|
6885
7083
|
return;
|
|
6886
7084
|
}
|
|
6887
7085
|
if (mx === ab) {
|
|
@@ -6898,31 +7096,26 @@ function installZoneDent(kit) {
|
|
|
6898
7096
|
tri(F2, Bv, C, depth + 1);
|
|
6899
7097
|
}
|
|
6900
7098
|
}
|
|
7099
|
+
const M = rel.elements;
|
|
7100
|
+
const at = function(x, y, z, k) {
|
|
7101
|
+
const w = 1 / (M[3] * x + M[7] * y + M[11] * z + M[15]);
|
|
7102
|
+
return k === 0 ? (M[0] * x + M[4] * y + M[8] * z + M[12]) * w : k === 1 ? (M[1] * x + M[5] * y + M[9] * z + M[13]) * w : (M[2] * x + M[6] * y + M[10] * z + M[14]) * w;
|
|
7103
|
+
};
|
|
7104
|
+
const lo = [B.x0 - e, B.y0 - e, B.z0 - e];
|
|
7105
|
+
const hi = [B.x1 + e, B.y1 + e, B.z1 + e];
|
|
6901
7106
|
for (let i = 0; i < a.length; i += 9) {
|
|
6902
|
-
|
|
6903
|
-
|
|
6904
|
-
|
|
6905
|
-
|
|
6906
|
-
|
|
6907
|
-
|
|
6908
|
-
|
|
6909
|
-
|
|
6910
|
-
|
|
6911
|
-
[A, Bv, C].forEach(function(p) {
|
|
6912
|
-
v.set(p[0], p[1], p[2]).applyMatrix4(rel);
|
|
6913
|
-
x0 = Math.min(x0, v.x);
|
|
6914
|
-
x1 = Math.max(x1, v.x);
|
|
6915
|
-
y0 = Math.min(y0, v.y);
|
|
6916
|
-
y1 = Math.max(y1, v.y);
|
|
6917
|
-
z0 = Math.min(z0, v.z);
|
|
6918
|
-
z1 = Math.max(z1, v.z);
|
|
6919
|
-
});
|
|
6920
|
-
if (x1 < B.x0 - e || x0 > B.x1 + e || y1 < B.y0 - e || y0 > B.y1 + e || z1 < B.z0 - e || z0 > B.z1 + e)
|
|
6921
|
-
out.push(A[0], A[1], A[2], Bv[0], Bv[1], Bv[2], C[0], C[1], C[2]);
|
|
6922
|
-
else tri(A, Bv, C, 0);
|
|
7107
|
+
let outside = false;
|
|
7108
|
+
for (let k = 0; k < 3 && !outside; k++) {
|
|
7109
|
+
const p = at(a[i], a[i + 1], a[i + 2], k);
|
|
7110
|
+
const q = at(a[i + 3], a[i + 4], a[i + 5], k);
|
|
7111
|
+
const r = at(a[i + 6], a[i + 7], a[i + 8], k);
|
|
7112
|
+
outside = Math.max(p, q, r) < lo[k] || Math.min(p, q, r) > hi[k];
|
|
7113
|
+
}
|
|
7114
|
+
if (outside) push(a[i], a[i + 1], a[i + 2], a[i + 3], a[i + 4], a[i + 5], a[i + 6], a[i + 7], a[i + 8]);
|
|
7115
|
+
else tri([a[i], a[i + 1], a[i + 2]], [a[i + 3], a[i + 4], a[i + 5]], [a[i + 6], a[i + 7], a[i + 8]], 0);
|
|
6923
7116
|
}
|
|
6924
7117
|
const g = new THREE.BufferGeometry();
|
|
6925
|
-
g.setAttribute("position", new THREE.
|
|
7118
|
+
g.setAttribute("position", new THREE.BufferAttribute(out.slice(0, used), 3));
|
|
6926
7119
|
g.userData.crease = true;
|
|
6927
7120
|
g.userData.p0 = null;
|
|
6928
7121
|
return g;
|
|
@@ -6945,6 +7138,17 @@ function installZoneDent(kit) {
|
|
|
6945
7138
|
});
|
|
6946
7139
|
return out;
|
|
6947
7140
|
}
|
|
7141
|
+
function boxInFrame(B, m, tmp) {
|
|
7142
|
+
const r = [Infinity, Infinity, Infinity, -Infinity, -Infinity, -Infinity];
|
|
7143
|
+
for (let i = 0; i < 8; i++) {
|
|
7144
|
+
tmp.set(i & 1 ? B.x1 : B.x0, i & 2 ? B.y1 : B.y0, i & 4 ? B.z1 : B.z0).applyMatrix4(m);
|
|
7145
|
+
for (let k = 0; k < 3; k++) {
|
|
7146
|
+
r[k] = Math.min(r[k], tmp.getComponent(k) - 1e-4);
|
|
7147
|
+
r[k + 3] = Math.max(r[k + 3], tmp.getComponent(k) + 1e-4);
|
|
7148
|
+
}
|
|
7149
|
+
}
|
|
7150
|
+
return r;
|
|
7151
|
+
}
|
|
6948
7152
|
function zoneDent(c, z, dents, dirty, opt) {
|
|
6949
7153
|
opt = opt || {};
|
|
6950
7154
|
const B = z.box;
|
|
@@ -6999,6 +7203,7 @@ function installZoneDent(kit) {
|
|
|
6999
7203
|
g = msh.geometry = g.clone();
|
|
7000
7204
|
msh.userData.zCloned = true;
|
|
7001
7205
|
}
|
|
7206
|
+
let boundsDue = false;
|
|
7002
7207
|
const nonIdx = !g.index;
|
|
7003
7208
|
const onlyPos = Object.keys(g.attributes).every(function(k) {
|
|
7004
7209
|
return k === "position" || k === "normal";
|
|
@@ -7007,15 +7212,17 @@ function installZoneDent(kit) {
|
|
|
7007
7212
|
const ng = subdivIn(g, rel, B, opt.sub || 0.075);
|
|
7008
7213
|
g.dispose();
|
|
7009
7214
|
g = msh.geometry = ng;
|
|
7010
|
-
|
|
7011
|
-
ng.computeBoundingBox();
|
|
7215
|
+
boundsDue = true;
|
|
7012
7216
|
dirty.add(msh);
|
|
7013
7217
|
}
|
|
7014
7218
|
irel.copy(rel).invert();
|
|
7015
7219
|
const pos = g.attributes.position;
|
|
7016
7220
|
let changed = false;
|
|
7221
|
+
const near = boxInFrame(B, irel, v);
|
|
7017
7222
|
for (let i = 0; i < pos.count; i++) {
|
|
7018
|
-
v.fromBufferAttribute(pos, i)
|
|
7223
|
+
v.fromBufferAttribute(pos, i);
|
|
7224
|
+
if (v.x < near[0] || v.x > near[3] || v.y < near[1] || v.y > near[4] || v.z < near[2] || v.z > near[5]) continue;
|
|
7225
|
+
v.applyMatrix4(rel);
|
|
7019
7226
|
const f = field(v);
|
|
7020
7227
|
if (f <= 1e-5) continue;
|
|
7021
7228
|
v.addScaledVector(d, f);
|
|
@@ -7036,9 +7243,11 @@ function installZoneDent(kit) {
|
|
|
7036
7243
|
}
|
|
7037
7244
|
if (changed) {
|
|
7038
7245
|
pos.needsUpdate = true;
|
|
7246
|
+
dirty.add(msh);
|
|
7247
|
+
}
|
|
7248
|
+
if (changed || boundsDue) {
|
|
7039
7249
|
g.computeBoundingSphere();
|
|
7040
7250
|
g.computeBoundingBox();
|
|
7041
|
-
dirty.add(msh);
|
|
7042
7251
|
}
|
|
7043
7252
|
});
|
|
7044
7253
|
const dset = new Set(c.deform);
|
|
@@ -10141,6 +10350,20 @@ function createVehicleKit(options) {
|
|
|
10141
10350
|
else kit.applyArmor(c);
|
|
10142
10351
|
}
|
|
10143
10352
|
if (zoneState == null && st === "damaged" && kit.config.damagedScenario) zoneState = kit.zoneScenario(c, kit.config.damagedScenario);
|
|
10353
|
+
else if (zoneState && zoneState.scenario != null) {
|
|
10354
|
+
c.scenario = zoneState.scenario;
|
|
10355
|
+
let fromScenario = { health: {}, flags: {} };
|
|
10356
|
+
try {
|
|
10357
|
+
fromScenario = kit.zoneScenario(c, zoneState.scenario);
|
|
10358
|
+
} catch (e) {
|
|
10359
|
+
;
|
|
10360
|
+
(c.zoneErrors = c.zoneErrors || []).push("scenario: " + (e && e.message));
|
|
10361
|
+
}
|
|
10362
|
+
zoneState = {
|
|
10363
|
+
health: Object.assign({}, fromScenario.health, zoneState.health),
|
|
10364
|
+
flags: Object.assign({}, fromScenario.flags, zoneState.flags)
|
|
10365
|
+
};
|
|
10366
|
+
}
|
|
10144
10367
|
if (zoneState) kit.applyZones(c, zoneState);
|
|
10145
10368
|
else {
|
|
10146
10369
|
c.zoneState = { health: {}, flags: {} };
|
|
@@ -12097,7 +12320,7 @@ function createVehicleDestructible(kit, vehicleCtx, options = {}) {
|
|
|
12097
12320
|
const reset = () => {
|
|
12098
12321
|
const old = c;
|
|
12099
12322
|
const parent = old.root.parent;
|
|
12100
|
-
const next = kit.build(old.key, old.state);
|
|
12323
|
+
const next = kit.build(old.key, old.state, old.scenario != null ? { scenario: old.scenario } : void 0);
|
|
12101
12324
|
if (parent) {
|
|
12102
12325
|
next.root.position.copy(old.root.position);
|
|
12103
12326
|
next.root.quaternion.copy(old.root.quaternion);
|
|
@@ -12154,7 +12377,8 @@ function createVehicleDestructible(kit, vehicleCtx, options = {}) {
|
|
|
12154
12377
|
// src/destructible/item.ts
|
|
12155
12378
|
function buildVehicleItem(kit, key, options = {}) {
|
|
12156
12379
|
const THREE = kit.THREE;
|
|
12157
|
-
const
|
|
12380
|
+
const zoneState = options.scenario != null ? { scenario: options.scenario } : void 0;
|
|
12381
|
+
const vehicle = options.lod ? kit.build(key, options.state ?? "intact", zoneState, { lod: true }) : kit.build(key, options.state ?? "intact", zoneState);
|
|
12158
12382
|
const m = vehicle.meta;
|
|
12159
12383
|
const root = new THREE.Group();
|
|
12160
12384
|
root.name = key;
|