@adatechnology/game-interactables-three 0.3.7 → 0.4.1

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.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/effects.ts
2
- import { warnOnce } from "@adatechnology/game-contracts";
2
+ import { markKitOrigin, warnOnce } from "@adatechnology/game-contracts";
3
3
 
4
4
  // src/routed-particles.ts
5
5
  var channel = (value) => Math.round(Math.min(1, Math.max(0, value)) * 255);
@@ -179,7 +179,7 @@ function createEffects(THREE, a, b = {}) {
179
179
  depthWrite: false,
180
180
  blending: additive ? THREE.AdditiveBlending : THREE.NormalBlending
181
181
  });
182
- const points = new THREE.Points(geo, mat);
182
+ const points = markKitOrigin(new THREE.Points(geo, mat), { owner: "game-interactables-three", kind: "effect", id: kind });
183
183
  points.frustumCulled = false;
184
184
  points.name = `effects:${kind}`;
185
185
  scene.add(points);
@@ -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 wide = size >= 0.1;
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 sp = (wide ? 0.5 : 0.25) + rand() * 0.7;
335
- spawn(pools.water, ex + Math.cos(a2) * r, arc.stopY + 5e-3, ez + Math.sin(a2) * r, Math.cos(a2) * sp, 0.9 + rand() * 1.3, Math.sin(a2) * sp, 0.3 + rand() * 0.25, 0.014 + rand() * 0.018, 0.01, rand(), 3, arc.stopY);
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
- spawn(pools.water, ex + Math.cos(a2) * r, arc.stopY + 0.02, ez + Math.sin(a2) * r, Math.cos(a2) * 0.15, 0.18 + rand() * 0.15, Math.sin(a2) * 0.15, 0.7 + rand() * 0.5, 0.06 + size * 0.2, 0.2 + size * 0.5, rand(), 4, arc.stopY);
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
  };
@@ -708,7 +724,7 @@ function createEffects(THREE, a, b = {}) {
708
724
  import { createCord, catenary } from "@adatechnology/game-shapes-three";
709
725
 
710
726
  // src/mesh.ts
711
- import { markKitOrigin } from "@adatechnology/game-contracts";
727
+ import { markKitOrigin as markKitOrigin2 } from "@adatechnology/game-contracts";
712
728
  import { LIGHT_PRIORITY } from "@adatechnology/game-render-three";
713
729
  import { createShapeRecorder } from "@adatechnology/game-props3d";
714
730
  import { colorChannels, generate } from "@adatechnology/game-shapes";
@@ -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, geometry, template, set, group) => {
919
- const mesh = new THREE.Mesh(geometry, set.material);
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, concat(THREE, e.pieces, { swayId: 1, swayAnchor: 1 }), e.mesh, set, merged);
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, concat(THREE, e.pieces, { batchPivot: 3 }), e.mesh, set, merged);
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,11 +1440,12 @@ 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) });
1402
- const group = markKitOrigin(new THREE.Group(), { owner: "game-interactables-three", kind: "furniture", ...spec ? { id: spec.type } : {} });
1448
+ const group = markKitOrigin2(new THREE.Group(), { owner: "game-interactables-three", kind: "furniture", ...spec ? { id: spec.type } : {} });
1403
1449
  group.name = "interactable";
1404
1450
  const parts = {};
1405
1451
  const body = of(null);