@adatechnology/game-interactables-three 0.3.7 → 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 +7 -0
- package/dist/index.global.js +131 -20
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +58 -12
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
package/dist/index.js
CHANGED
|
@@ -298,11 +298,20 @@ function createEffects(THREE, a, b = {}) {
|
|
|
298
298
|
arc.r0 = size * 0.45;
|
|
299
299
|
arc.r1 = arc.r0 * 1.2;
|
|
300
300
|
}
|
|
301
|
+
if (e.bowl) {
|
|
302
|
+
const most = Math.max(4e-3, e.bowl.radius * 0.7);
|
|
303
|
+
arc.r0 = Math.min(arc.r0, most);
|
|
304
|
+
arc.r1 = Math.min(arc.r1, most);
|
|
305
|
+
}
|
|
301
306
|
return true;
|
|
302
307
|
};
|
|
303
308
|
const emitWater = (e, k, nSpray, nSplash, nMist) => {
|
|
304
309
|
const size = e.size > 0 ? e.size : 0.05;
|
|
305
|
-
const
|
|
310
|
+
const bowl = e.bowl;
|
|
311
|
+
const wide = size >= 0.1 && !bowl;
|
|
312
|
+
const riseMax = bowl ? Math.sqrt(2 * 9.8 * Math.max(0.01, bowl.depth)) * 0.85 : Infinity;
|
|
313
|
+
const outMax = (vy) => bowl ? bowl.radius * 0.6 * 9.8 / (2 * Math.max(vy, 0.3)) : Infinity;
|
|
314
|
+
const within = bowl ? bowl.radius * 0.3 : Infinity;
|
|
306
315
|
for (let j = 0; j < nSpray; j++) {
|
|
307
316
|
const s = rand();
|
|
308
317
|
const t = s * arc.t;
|
|
@@ -330,14 +339,21 @@ function createEffects(THREE, a, b = {}) {
|
|
|
330
339
|
const ez = arc.z + arc.vz * arc.t;
|
|
331
340
|
for (let j = 0; j < nSplash; j++) {
|
|
332
341
|
const a2 = rand() * Math.PI * 2;
|
|
333
|
-
const r = arc.r1 * Math.sqrt(rand());
|
|
334
|
-
const
|
|
335
|
-
|
|
342
|
+
const r = Math.min(arc.r1, within) * Math.sqrt(rand());
|
|
343
|
+
const sp0 = (wide ? 0.5 : 0.25) + rand() * 0.7;
|
|
344
|
+
const vy0 = 0.9 + rand() * 1.3;
|
|
345
|
+
const vy = bowl ? riseMax * (0.5 + 0.5 * (vy0 - 0.9) / 1.3) : vy0;
|
|
346
|
+
const sp = Math.min(sp0, outMax(vy));
|
|
347
|
+
spawn(pools.water, ex + Math.cos(a2) * r, arc.stopY + 5e-3, ez + Math.sin(a2) * r, Math.cos(a2) * sp, vy, Math.sin(a2) * sp, 0.3 + rand() * 0.25, 0.014 + rand() * 0.018, 0.01, rand(), 3, arc.stopY);
|
|
336
348
|
}
|
|
337
349
|
for (let j = 0; j < nMist; j++) {
|
|
338
350
|
const a2 = rand() * Math.PI * 2;
|
|
339
|
-
const r = arc.r1 * 1.4 * Math.sqrt(rand());
|
|
340
|
-
|
|
351
|
+
const r = Math.min(arc.r1 * 1.4, within) * Math.sqrt(rand());
|
|
352
|
+
const up0 = 0.18 + rand() * 0.15;
|
|
353
|
+
const life = 0.7 + rand() * 0.5;
|
|
354
|
+
const up = bowl ? Math.min(up0, Math.max(5e-3, bowl.depth - 0.03) / life) : up0;
|
|
355
|
+
const drift = bowl ? Math.min(0.15, bowl.radius * 0.5 / life) : 0.15;
|
|
356
|
+
spawn(pools.water, ex + Math.cos(a2) * r, arc.stopY + 0.02, ez + Math.sin(a2) * r, Math.cos(a2) * drift, up, Math.sin(a2) * drift, life, 0.06 + size * 0.2, 0.2 + size * 0.5, rand(), 4, arc.stopY);
|
|
341
357
|
}
|
|
342
358
|
void k;
|
|
343
359
|
};
|
|
@@ -881,6 +897,32 @@ function concat(THREE, pieces, extraSizes) {
|
|
|
881
897
|
out.computeBoundingBox();
|
|
882
898
|
return out;
|
|
883
899
|
}
|
|
900
|
+
function mergedSolids(THREE, pieces) {
|
|
901
|
+
if (pieces.some((p) => !p.solids)) return void 0;
|
|
902
|
+
const out = [];
|
|
903
|
+
const position = new THREE.Vector3();
|
|
904
|
+
const turn = new THREE.Quaternion();
|
|
905
|
+
const scale = new THREE.Vector3();
|
|
906
|
+
const centre = new THREE.Vector3();
|
|
907
|
+
const own = new THREE.Quaternion();
|
|
908
|
+
let first = 0;
|
|
909
|
+
for (const p of pieces) {
|
|
910
|
+
p.matrix.decompose(position, turn, scale);
|
|
911
|
+
for (const solid of p.solids ?? []) {
|
|
912
|
+
centre.set(solid.center[0], solid.center[1], solid.center[2]).applyMatrix4(p.matrix);
|
|
913
|
+
own.set(solid.rotation[0], solid.rotation[1], solid.rotation[2], solid.rotation[3]).premultiply(turn).normalize();
|
|
914
|
+
out.push({
|
|
915
|
+
...solid,
|
|
916
|
+
center: [centre.x, centre.y, centre.z],
|
|
917
|
+
half: [solid.half[0] * Math.abs(scale.x), solid.half[1] * Math.abs(scale.y), solid.half[2] * Math.abs(scale.z)],
|
|
918
|
+
rotation: [own.x, own.y, own.z, own.w],
|
|
919
|
+
vertexStart: solid.vertexStart + first
|
|
920
|
+
});
|
|
921
|
+
}
|
|
922
|
+
first += p.geometry.getAttribute("position").count;
|
|
923
|
+
}
|
|
924
|
+
return out;
|
|
925
|
+
}
|
|
884
926
|
function meshesOf(group) {
|
|
885
927
|
return group.children.filter((c) => c.isMesh);
|
|
886
928
|
}
|
|
@@ -910,15 +952,17 @@ function mergeParts(THREE, root, parts, spec, options = {}) {
|
|
|
910
952
|
e = { base: mesh.material, pieces: [], mesh };
|
|
911
953
|
map.set(key, e);
|
|
912
954
|
}
|
|
913
|
-
e.pieces.push({ geometry: mesh.geometry, matrix: g.matrix, extra: extra(g, mesh.geometry.getAttribute("position").count) });
|
|
955
|
+
e.pieces.push({ geometry: mesh.geometry, matrix: g.matrix, extra: extra(g, mesh.geometry.getAttribute("position").count), solids: mesh.userData.solids });
|
|
914
956
|
}
|
|
915
957
|
}
|
|
916
958
|
return map;
|
|
917
959
|
};
|
|
918
|
-
const finishMesh = (name, key,
|
|
919
|
-
const mesh = new THREE.Mesh(
|
|
960
|
+
const finishMesh = (name, key, pieces, extraSizes, template, set, group) => {
|
|
961
|
+
const mesh = new THREE.Mesh(concat(THREE, pieces, extraSizes), set.material);
|
|
920
962
|
mesh.name = `${name}:${key}`;
|
|
921
963
|
mesh.userData.material = key;
|
|
964
|
+
const solids = mergedSolids(THREE, pieces);
|
|
965
|
+
if (solids) mesh.userData.solids = solids;
|
|
922
966
|
mesh.castShadow = template.castShadow;
|
|
923
967
|
mesh.receiveShadow = template.receiveShadow;
|
|
924
968
|
mesh.customDepthMaterial = set.depth;
|
|
@@ -972,7 +1016,7 @@ uniform vec2 swayAxz[${n}];
|
|
|
972
1016
|
for (const e of plan.values()) {
|
|
973
1017
|
const key = String(e.mesh.userData.material);
|
|
974
1018
|
const set = patchedSet(THREE, e.base, `swayBatch:${n}:${amplitude}`, patch2);
|
|
975
|
-
finishMesh("merge:cloth", key,
|
|
1019
|
+
finishMesh("merge:cloth", key, e.pieces, { swayId: 1, swayAnchor: 1 }, e.mesh, set, merged);
|
|
976
1020
|
}
|
|
977
1021
|
const batch = {
|
|
978
1022
|
kind: "sway",
|
|
@@ -1028,7 +1072,7 @@ ${QROT}${shader.vertexShader}`;
|
|
|
1028
1072
|
for (const e of plan.values()) {
|
|
1029
1073
|
const key = String(e.mesh.userData.material);
|
|
1030
1074
|
const set = patchedSet(THREE, e.base, "poseBatch", patch2);
|
|
1031
|
-
finishMesh(merged.name, key,
|
|
1075
|
+
finishMesh(merged.name, key, e.pieces, { batchPivot: 3 }, e.mesh, set, merged);
|
|
1032
1076
|
}
|
|
1033
1077
|
const batch = {
|
|
1034
1078
|
kind: "pose",
|
|
@@ -1362,6 +1406,7 @@ function createMeshApi(THREE, options = {}) {
|
|
|
1362
1406
|
mesh.name = id === null ? `static:${key}` : `part:${id}`;
|
|
1363
1407
|
if (id !== null) mesh.userData.part = id;
|
|
1364
1408
|
mesh.userData.material = key;
|
|
1409
|
+
if (batch.solids) mesh.userData.solids = batch.solids;
|
|
1365
1410
|
mesh.castShadow = shadows;
|
|
1366
1411
|
mesh.receiveShadow = shadows;
|
|
1367
1412
|
into.add(mesh);
|
|
@@ -1395,7 +1440,8 @@ function createMeshApi(THREE, options = {}) {
|
|
|
1395
1440
|
fallbackMaterial: "plain",
|
|
1396
1441
|
materialAlias,
|
|
1397
1442
|
validate: false,
|
|
1398
|
-
key: false
|
|
1443
|
+
key: false,
|
|
1444
|
+
solids: true
|
|
1399
1445
|
});
|
|
1400
1446
|
const batches = buffers.levels[0]?.batches ?? [];
|
|
1401
1447
|
const of = (id) => ({ batches: batches.filter((b) => b.part === id), points: buffers.points.filter((p) => p.part === id) });
|