@adatechnology/game-vehicles-three 0.9.7 → 0.9.9

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.
@@ -30797,10 +30797,15 @@ var GameVehiclesThree = (() => {
30797
30797
  if (geo.boundingSphere === null) geo.computeBoundingSphere();
30798
30798
  s.sphere.copy(geo.boundingSphere).applyMatrix4(mesh2.matrixWorld);
30799
30799
  if (!raycaster.ray.intersectsSphere(s.sphere)) return;
30800
- const ti = rayIndexOf(geo);
30801
- if (!ti) return;
30802
30800
  s.inverse.copy(mesh2.matrixWorld).invert();
30803
30801
  s.local.copy(raycaster.ray).applyMatrix4(s.inverse);
30802
+ intersectTriangles(THREE, raycaster, mesh2, out);
30803
+ }
30804
+ function intersectTriangles(THREE, raycaster, mesh2, out) {
30805
+ const geo = mesh2.geometry;
30806
+ const s = scratchOf(THREE);
30807
+ const ti = rayIndexOf(geo);
30808
+ if (!ti) return;
30804
30809
  const material = mesh2.material;
30805
30810
  const back = material.side === THREE.BackSide;
30806
30811
  const cull = material.side === THREE.FrontSide;
@@ -30848,6 +30853,37 @@ var GameVehiclesThree = (() => {
30848
30853
  }
30849
30854
  if (recursive) for (const child of object2.children) collect2(THREE, raycaster, child, true, out);
30850
30855
  }
30856
+ function passesThreePrologue(THREE, raycaster, mesh2) {
30857
+ const geo = mesh2.geometry;
30858
+ const s = scratchOf(THREE);
30859
+ if (geo.boundingSphere === null) geo.computeBoundingSphere();
30860
+ s.sphere.copy(geo.boundingSphere).applyMatrix4(mesh2.matrixWorld);
30861
+ s.local.copy(raycaster.ray).recast(raycaster.near);
30862
+ if (!s.sphere.containsPoint(s.local.origin)) {
30863
+ if (s.local.intersectSphere(s.sphere, s.point) === null) return false;
30864
+ if (s.local.origin.distanceToSquared(s.point) > (raycaster.far - raycaster.near) ** 2) return false;
30865
+ }
30866
+ s.inverse.copy(mesh2.matrixWorld).invert();
30867
+ s.local.copy(raycaster.ray).applyMatrix4(s.inverse);
30868
+ return geo.boundingBox === null || s.local.intersectsBox(geo.boundingBox);
30869
+ }
30870
+ function alignedRange(mesh2) {
30871
+ const geo = mesh2.geometry;
30872
+ const count2 = geo.index ? geo.index.count : geo.attributes.position.count;
30873
+ const first = Math.max(0, geo.drawRange.start);
30874
+ const last = Math.min(count2, geo.drawRange.start + geo.drawRange.count);
30875
+ return first % 3 === 0 && (last <= first || (last - first) % 3 === 0);
30876
+ }
30877
+ function raycastMeshesLikeThree(THREE, raycaster, objects) {
30878
+ const out = [];
30879
+ for (const object2 of objects) {
30880
+ if (!object2.layers.test(raycaster.layers)) continue;
30881
+ if (!indexable(THREE, object2) || !alignedRange(object2)) object2.raycast(raycaster, out);
30882
+ else if (passesThreePrologue(THREE, raycaster, object2)) intersectTriangles(THREE, raycaster, object2, out);
30883
+ }
30884
+ out.sort((x, y) => x.distance - y.distance);
30885
+ return out;
30886
+ }
30851
30887
  function raycastIndexed(THREE, raycaster, objects, recursive = false) {
30852
30888
  const out = [];
30853
30889
  for (const object2 of objects) collect2(THREE, raycaster, object2, recursive, out);
@@ -44128,12 +44164,13 @@ var GameVehiclesThree = (() => {
44128
44164
  for (const child of o.children) collectSurfaces(child);
44129
44165
  };
44130
44166
  const surfaceRay = (ray) => {
44131
- sync();
44167
+ c.vehicle.updateWorldMatrix(true, true);
44132
44168
  surfaceRays.set(new V3(ray.origin[0], ray.origin[1], ray.origin[2]), new V3(ray.direction[0], ray.direction[1], ray.direction[2]));
44133
44169
  surfaceRays.far = ray.maxDistance;
44134
44170
  surfaceMeshes.length = 0;
44135
44171
  for (const child of c.vehicle.children) collectSurfaces(child);
44136
- for (const h of surfaceRays.intersectObjects(surfaceMeshes, false)) {
44172
+ const hits = options.bruteForceRays ? surfaceRays.intersectObjects(surfaceMeshes, false) : raycastMeshesLikeThree(THREE, surfaceRays, surfaceMeshes);
44173
+ for (const h of hits) {
44137
44174
  if (!h.face || !isDrawnSurface(h.object)) continue;
44138
44175
  const p = partOfSurface(h.object, c.vehicle.worldToLocal(h.point.clone()));
44139
44176
  if (!p || p.lost || ray.ignored?.(p.def.id)) continue;
@@ -44591,7 +44628,7 @@ var GameVehiclesThree = (() => {
44591
44628
  };
44592
44629
  }
44593
44630
 
44594
- // ../game-audio/dist/chunk-KGYMFUK7.js
44631
+ // ../game-audio/dist/chunk-ZFNHDQRV.js
44595
44632
  var DISTANCE_CURVES = {
44596
44633
  /** The game's `sfx`: `vol / (1 + d² × 0.004)`, cutoff `/ (1 + d × 0.01)`, silent below 0.01 (jogo L62091–62092, L62101). */
44597
44634
  game_sfx: { model: "inverse_square", k: 4e-3, cutoffK: 0.01, minGain: 0.01 },
@@ -46733,11 +46770,12 @@ var GameVehiclesThree = (() => {
46733
46770
  const geometry = mesh2.geometry;
46734
46771
  return geometry.attributes.position !== void 0 && Object.keys(geometry.morphAttributes).length === 0;
46735
46772
  };
46736
- var signatureOf = (mesh2) => {
46773
+ var signatureOf = (mesh2, materialKey2) => {
46737
46774
  const { attributes } = mesh2.geometry;
46738
46775
  const present = ATTRIBUTES.filter((name) => attributes[name] !== void 0).map((name) => `${name}${attributes[name].itemSize}`);
46739
- return `${mesh2.material.uuid}|${present.join(",")}|${mesh2.castShadow ? 1 : 0}${mesh2.receiveShadow ? 1 : 0}`;
46776
+ return `${materialKey2(mesh2.material)}|${present.join(",")}|${mesh2.castShadow ? 1 : 0}${mesh2.receiveShadow ? 1 : 0}`;
46740
46777
  };
46778
+ var uuidOf = (material) => material.uuid;
46741
46779
  var sameMatrix = (a, b) => a.elements.every((value, index) => Math.abs(value - b.elements[index]) < MATRIX_EPSILON);
46742
46780
  function createStaticBatcher(THREE, root, options = {}) {
46743
46781
  const include = options.include ?? (() => true);
@@ -46748,7 +46786,7 @@ var GameVehiclesThree = (() => {
46748
46786
  root.traverse((object2) => {
46749
46787
  const mesh2 = object2;
46750
46788
  if (!mesh2.isMesh || !isShown(mesh2, root) || !isBatchable(mesh2) || !include(mesh2)) return;
46751
- const key = signatureOf(mesh2);
46789
+ const key = signatureOf(mesh2, options.materialKey ?? uuidOf);
46752
46790
  groups.set(key, [...groups.get(key) ?? [], mesh2]);
46753
46791
  });
46754
46792
  const group = new THREE.Group();
@@ -46758,7 +46796,7 @@ var GameVehiclesThree = (() => {
46758
46796
  const mergeSome = (deadline) => {
46759
46797
  while (pending.length > 0) {
46760
46798
  const meshes = pending.shift();
46761
- if (meshes.every((mesh2) => isShown(mesh2, root))) sources.push(...mergeGroup(THREE, { meshes, inverse: new THREE.Matrix4().copy(root.matrixWorld).invert(), group, follow }));
46799
+ if (meshes.every((mesh2) => isShown(mesh2, root))) sources.push(...mergeGroup(THREE, { meshes, inverse: new THREE.Matrix4().copy(root.matrixWorld).invert(), group, follow, onBatch: options.onBatch }));
46762
46800
  if (performance.now() >= deadline) return;
46763
46801
  }
46764
46802
  };
@@ -46856,7 +46894,7 @@ var GameVehiclesThree = (() => {
46856
46894
  mesh2.frustumCulled = false;
46857
46895
  return mesh2;
46858
46896
  }
46859
- function mergeGroup(THREE, { meshes, inverse: rootInverse, group, follow }) {
46897
+ function mergeGroup(THREE, { meshes, inverse: rootInverse, group, follow, onBatch }) {
46860
46898
  const identity = new THREE.Matrix4();
46861
46899
  const inverse = follow ? identity : rootInverse;
46862
46900
  const first = meshes[0];
@@ -46893,6 +46931,7 @@ var GameVehiclesThree = (() => {
46893
46931
  merged.computeBoundingBox();
46894
46932
  merged.computeBoundingSphere();
46895
46933
  group.add(mesh2);
46934
+ onBatch?.(mesh2, meshes);
46896
46935
  const batch = { mesh: mesh2, live: pieces.length, index: indexAttribute };
46897
46936
  const sources = [];
46898
46937
  let vertexOffset = 0;