@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.
|
@@ -1097,8 +1097,48 @@ function rainLayer(THREE, rain) {
|
|
|
1097
1097
|
}
|
|
1098
1098
|
};
|
|
1099
1099
|
}
|
|
1100
|
-
var
|
|
1101
|
-
var
|
|
1100
|
+
var REST_STEP = 15e-4;
|
|
1101
|
+
var REST_TRIES = 8;
|
|
1102
|
+
var SAME_NORMAL = 0.9995;
|
|
1103
|
+
var restBox = () => ({ c: new Float64Array(3), axes: new Float64Array(9), half: new Float64Array(3), ext: new Float64Array(3) });
|
|
1104
|
+
function boxOf(piece, out) {
|
|
1105
|
+
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);
|
|
1106
|
+
const a = out.axes;
|
|
1107
|
+
a[0] = cy * cz;
|
|
1108
|
+
a[1] = sx * sy * cz + cx * sz;
|
|
1109
|
+
a[2] = sx * sz - cx * sy * cz;
|
|
1110
|
+
a[3] = -cy * sz;
|
|
1111
|
+
a[4] = cx * cz - sx * sy * sz;
|
|
1112
|
+
a[5] = cx * sy * sz + sx * cz;
|
|
1113
|
+
a[6] = sy;
|
|
1114
|
+
a[7] = -sx * cy;
|
|
1115
|
+
a[8] = cx * cy;
|
|
1116
|
+
out.half[0] = piece.sx / 2;
|
|
1117
|
+
out.half[1] = piece.sy / 2;
|
|
1118
|
+
out.half[2] = piece.sz / 2;
|
|
1119
|
+
out.c[0] = piece.x;
|
|
1120
|
+
out.c[1] = piece.y;
|
|
1121
|
+
out.c[2] = piece.z;
|
|
1122
|
+
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];
|
|
1123
|
+
}
|
|
1124
|
+
function sharedPlane(a, b, push) {
|
|
1125
|
+
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;
|
|
1126
|
+
for (let i = 0; i < 3; i++) for (let j = 0; j < 3; j++) {
|
|
1127
|
+
const ax = a.axes[3 * i], ay = a.axes[3 * i + 1], az = a.axes[3 * i + 2];
|
|
1128
|
+
const dot = ax * b.axes[3 * j] + ay * b.axes[3 * j + 1] + az * b.axes[3 * j + 2];
|
|
1129
|
+
if (Math.abs(dot) < SAME_NORMAL) continue;
|
|
1130
|
+
const ca = ax * a.c[0] + ay * a.c[1] + az * a.c[2];
|
|
1131
|
+
const cb = ax * b.c[0] + ay * b.c[1] + az * b.c[2];
|
|
1132
|
+
for (let side = -1; side <= 1; side += 2) {
|
|
1133
|
+
if (Math.abs(ca + side * a.half[i] - (cb + side * b.half[j])) >= REST_STEP * 0.75) continue;
|
|
1134
|
+
push[0] = ax * side;
|
|
1135
|
+
push[1] = ay * side;
|
|
1136
|
+
push[2] = az * side;
|
|
1137
|
+
return true;
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
return false;
|
|
1141
|
+
}
|
|
1102
1142
|
function debrisLayer(THREE, pool) {
|
|
1103
1143
|
const geometry = new THREE.BoxGeometry(1, 1, 1);
|
|
1104
1144
|
const material = new THREE.MeshStandardMaterial({ color: 16777215, roughness: 0.45, metalness: 0.25, flatShading: true });
|
|
@@ -1113,6 +1153,36 @@ function debrisLayer(THREE, pool) {
|
|
|
1113
1153
|
const matrix = new THREE.Matrix4();
|
|
1114
1154
|
const colour = new THREE.Color();
|
|
1115
1155
|
const hidden = new THREE.Matrix4().makeScale(0, 0, 0);
|
|
1156
|
+
const offset = new Float64Array(DEBRIS_CAPACITY * 3);
|
|
1157
|
+
const settled = new Uint8Array(DEBRIS_CAPACITY);
|
|
1158
|
+
const boxes = Array.from({ length: DEBRIS_CAPACITY }, restBox);
|
|
1159
|
+
const push = new Float64Array(3);
|
|
1160
|
+
const settle = (index) => {
|
|
1161
|
+
const box = boxes[index];
|
|
1162
|
+
boxOf(pool.pieces[index], box);
|
|
1163
|
+
let dx = 0, dy = 0, dz = 0;
|
|
1164
|
+
for (let tries = 0; tries < REST_TRIES; tries++) {
|
|
1165
|
+
let clash = false;
|
|
1166
|
+
for (let other = 0; other < DEBRIS_CAPACITY && !clash; other++) {
|
|
1167
|
+
if (other === index || !settled[other]) continue;
|
|
1168
|
+
if (!sharedPlane(box, boxes[other], push)) continue;
|
|
1169
|
+
clash = true;
|
|
1170
|
+
const up = Math.abs(push[1]) > 0.7;
|
|
1171
|
+
const ux = up ? 0 : push[0], uy = up ? 1 : push[1], uz = up ? 0 : push[2];
|
|
1172
|
+
dx += ux * REST_STEP;
|
|
1173
|
+
dy += uy * REST_STEP;
|
|
1174
|
+
dz += uz * REST_STEP;
|
|
1175
|
+
box.c[0] = box.c[0] + ux * REST_STEP;
|
|
1176
|
+
box.c[1] = box.c[1] + uy * REST_STEP;
|
|
1177
|
+
box.c[2] = box.c[2] + uz * REST_STEP;
|
|
1178
|
+
}
|
|
1179
|
+
if (!clash) break;
|
|
1180
|
+
}
|
|
1181
|
+
offset[3 * index] = dx;
|
|
1182
|
+
offset[3 * index + 1] = dy;
|
|
1183
|
+
offset[3 * index + 2] = dz;
|
|
1184
|
+
settled[index] = 1;
|
|
1185
|
+
};
|
|
1116
1186
|
for (let index = 0; index < DEBRIS_CAPACITY; index++) mesh.setMatrixAt(index, hidden);
|
|
1117
1187
|
mesh.setColorAt(0, colour.setHex(16777215));
|
|
1118
1188
|
return {
|
|
@@ -1121,16 +1191,18 @@ function debrisLayer(THREE, pool) {
|
|
|
1121
1191
|
let drawn = false;
|
|
1122
1192
|
for (let index = 0; index < DEBRIS_CAPACITY; index++) {
|
|
1123
1193
|
const piece = pool.pieces[index];
|
|
1194
|
+
if (!piece.on || !piece.rest) settled[index] = 0;
|
|
1124
1195
|
if (!piece.on) {
|
|
1125
1196
|
mesh.setMatrixAt(index, hidden);
|
|
1126
1197
|
continue;
|
|
1127
1198
|
}
|
|
1199
|
+
if (piece.rest && !settled[index]) settle(index);
|
|
1128
1200
|
drawn = true;
|
|
1129
1201
|
const shrink = Math.min(1, piece.life / FADE_SECONDS);
|
|
1130
1202
|
euler.set(piece.rx, piece.ry, piece.rz);
|
|
1131
1203
|
quaternion.setFromEuler(euler);
|
|
1132
|
-
const
|
|
1133
|
-
matrix.compose(position.set(piece.x, piece.y +
|
|
1204
|
+
const off = piece.rest ? 3 * index : -1;
|
|
1205
|
+
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));
|
|
1134
1206
|
mesh.setMatrixAt(index, matrix);
|
|
1135
1207
|
mesh.setColorAt(index, colour.setHex(piece.color));
|
|
1136
1208
|
}
|
|
@@ -1960,4 +2032,4 @@ export {
|
|
|
1960
2032
|
benchText,
|
|
1961
2033
|
createVfxTestModule
|
|
1962
2034
|
};
|
|
1963
|
-
//# sourceMappingURL=chunk-
|
|
2035
|
+
//# sourceMappingURL=chunk-ACY6ZQC5.js.map
|