@adatechnology/game-vfx-three 0.10.11 → 0.10.12
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.global.js
CHANGED
|
@@ -9838,8 +9838,48 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
9838
9838
|
}
|
|
9839
9839
|
};
|
|
9840
9840
|
}
|
|
9841
|
-
var
|
|
9842
|
-
var
|
|
9841
|
+
var REST_STEP = 15e-4;
|
|
9842
|
+
var REST_TRIES = 8;
|
|
9843
|
+
var SAME_NORMAL = 0.9995;
|
|
9844
|
+
var restBox = () => ({ c: new Float64Array(3), axes: new Float64Array(9), half: new Float64Array(3), ext: new Float64Array(3) });
|
|
9845
|
+
function boxOf(piece, out) {
|
|
9846
|
+
const cx = Math.cos(piece.rx), sx = Math.sin(piece.rx), cy = Math.cos(piece.ry), sy = Math.sin(piece.ry), cz = Math.cos(piece.rz), sz = Math.sin(piece.rz);
|
|
9847
|
+
const a = out.axes;
|
|
9848
|
+
a[0] = cy * cz;
|
|
9849
|
+
a[1] = sx * sy * cz + cx * sz;
|
|
9850
|
+
a[2] = sx * sz - cx * sy * cz;
|
|
9851
|
+
a[3] = -cy * sz;
|
|
9852
|
+
a[4] = cx * cz - sx * sy * sz;
|
|
9853
|
+
a[5] = cx * sy * sz + sx * cz;
|
|
9854
|
+
a[6] = sy;
|
|
9855
|
+
a[7] = -sx * cy;
|
|
9856
|
+
a[8] = cx * cy;
|
|
9857
|
+
out.half[0] = piece.sx / 2;
|
|
9858
|
+
out.half[1] = piece.sy / 2;
|
|
9859
|
+
out.half[2] = piece.sz / 2;
|
|
9860
|
+
out.c[0] = piece.x;
|
|
9861
|
+
out.c[1] = piece.y;
|
|
9862
|
+
out.c[2] = piece.z;
|
|
9863
|
+
for (let w = 0; w < 3; w++) out.ext[w] = Math.abs(a[w]) * out.half[0] + Math.abs(a[3 + w]) * out.half[1] + Math.abs(a[6 + w]) * out.half[2];
|
|
9864
|
+
}
|
|
9865
|
+
function sharedPlane(a, b, push) {
|
|
9866
|
+
for (let w = 0; w < 3; w++) if (Math.abs(a.c[w] - b.c[w]) >= a.ext[w] + b.ext[w] + REST_STEP) return false;
|
|
9867
|
+
for (let i = 0; i < 3; i++) for (let j = 0; j < 3; j++) {
|
|
9868
|
+
const ax = a.axes[3 * i], ay = a.axes[3 * i + 1], az = a.axes[3 * i + 2];
|
|
9869
|
+
const dot = ax * b.axes[3 * j] + ay * b.axes[3 * j + 1] + az * b.axes[3 * j + 2];
|
|
9870
|
+
if (Math.abs(dot) < SAME_NORMAL) continue;
|
|
9871
|
+
const ca = ax * a.c[0] + ay * a.c[1] + az * a.c[2];
|
|
9872
|
+
const cb = ax * b.c[0] + ay * b.c[1] + az * b.c[2];
|
|
9873
|
+
for (let side = -1; side <= 1; side += 2) {
|
|
9874
|
+
if (Math.abs(ca + side * a.half[i] - (cb + side * b.half[j])) >= REST_STEP * 0.75) continue;
|
|
9875
|
+
push[0] = ax * side;
|
|
9876
|
+
push[1] = ay * side;
|
|
9877
|
+
push[2] = az * side;
|
|
9878
|
+
return true;
|
|
9879
|
+
}
|
|
9880
|
+
}
|
|
9881
|
+
return false;
|
|
9882
|
+
}
|
|
9843
9883
|
function debrisLayer(THREE, pool) {
|
|
9844
9884
|
const geometry = new THREE.BoxGeometry(1, 1, 1);
|
|
9845
9885
|
const material2 = new THREE.MeshStandardMaterial({ color: 16777215, roughness: 0.45, metalness: 0.25, flatShading: true });
|
|
@@ -9854,6 +9894,36 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
9854
9894
|
const matrix = new THREE.Matrix4();
|
|
9855
9895
|
const colour = new THREE.Color();
|
|
9856
9896
|
const hidden = new THREE.Matrix4().makeScale(0, 0, 0);
|
|
9897
|
+
const offset = new Float64Array(DEBRIS_CAPACITY * 3);
|
|
9898
|
+
const settled = new Uint8Array(DEBRIS_CAPACITY);
|
|
9899
|
+
const boxes = Array.from({ length: DEBRIS_CAPACITY }, restBox);
|
|
9900
|
+
const push = new Float64Array(3);
|
|
9901
|
+
const settle = (index) => {
|
|
9902
|
+
const box = boxes[index];
|
|
9903
|
+
boxOf(pool.pieces[index], box);
|
|
9904
|
+
let dx = 0, dy = 0, dz = 0;
|
|
9905
|
+
for (let tries = 0; tries < REST_TRIES; tries++) {
|
|
9906
|
+
let clash = false;
|
|
9907
|
+
for (let other = 0; other < DEBRIS_CAPACITY && !clash; other++) {
|
|
9908
|
+
if (other === index || !settled[other]) continue;
|
|
9909
|
+
if (!sharedPlane(box, boxes[other], push)) continue;
|
|
9910
|
+
clash = true;
|
|
9911
|
+
const up = Math.abs(push[1]) > 0.7;
|
|
9912
|
+
const ux = up ? 0 : push[0], uy = up ? 1 : push[1], uz = up ? 0 : push[2];
|
|
9913
|
+
dx += ux * REST_STEP;
|
|
9914
|
+
dy += uy * REST_STEP;
|
|
9915
|
+
dz += uz * REST_STEP;
|
|
9916
|
+
box.c[0] = box.c[0] + ux * REST_STEP;
|
|
9917
|
+
box.c[1] = box.c[1] + uy * REST_STEP;
|
|
9918
|
+
box.c[2] = box.c[2] + uz * REST_STEP;
|
|
9919
|
+
}
|
|
9920
|
+
if (!clash) break;
|
|
9921
|
+
}
|
|
9922
|
+
offset[3 * index] = dx;
|
|
9923
|
+
offset[3 * index + 1] = dy;
|
|
9924
|
+
offset[3 * index + 2] = dz;
|
|
9925
|
+
settled[index] = 1;
|
|
9926
|
+
};
|
|
9857
9927
|
for (let index = 0; index < DEBRIS_CAPACITY; index++) mesh2.setMatrixAt(index, hidden);
|
|
9858
9928
|
mesh2.setColorAt(0, colour.setHex(16777215));
|
|
9859
9929
|
return {
|
|
@@ -9862,16 +9932,18 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
9862
9932
|
let drawn = false;
|
|
9863
9933
|
for (let index = 0; index < DEBRIS_CAPACITY; index++) {
|
|
9864
9934
|
const piece = pool.pieces[index];
|
|
9935
|
+
if (!piece.on || !piece.rest) settled[index] = 0;
|
|
9865
9936
|
if (!piece.on) {
|
|
9866
9937
|
mesh2.setMatrixAt(index, hidden);
|
|
9867
9938
|
continue;
|
|
9868
9939
|
}
|
|
9940
|
+
if (piece.rest && !settled[index]) settle(index);
|
|
9869
9941
|
drawn = true;
|
|
9870
9942
|
const shrink = Math.min(1, piece.life / FADE_SECONDS2);
|
|
9871
9943
|
euler.set(piece.rx, piece.ry, piece.rz);
|
|
9872
9944
|
quaternion.setFromEuler(euler);
|
|
9873
|
-
const
|
|
9874
|
-
matrix.compose(position.set(piece.x, piece.y +
|
|
9945
|
+
const off = piece.rest ? 3 * index : -1;
|
|
9946
|
+
matrix.compose(position.set(piece.x + (off >= 0 ? offset[off] : 0), piece.y + (off >= 0 ? offset[off + 1] : 0), piece.z + (off >= 0 ? offset[off + 2] : 0)), quaternion, scale.set(piece.sx * shrink, piece.sy * shrink, piece.sz * shrink));
|
|
9875
9947
|
mesh2.setMatrixAt(index, matrix);
|
|
9876
9948
|
mesh2.setColorAt(index, colour.setHex(piece.color));
|
|
9877
9949
|
}
|