@adatechnology/game-vehicles 0.6.15 → 0.6.16
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.d.ts +5 -0
- package/dist/index.global.js +41 -4
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +41 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2184,6 +2184,11 @@ interface VehicleDestructibleOptions {
|
|
|
2184
2184
|
* nobody registered the queue with a budget, each vehicle smooths in its own `update` (2.5 ms a frame), as always.
|
|
2185
2185
|
*/
|
|
2186
2186
|
creaseQueue?: CreaseQueue;
|
|
2187
|
+
/**
|
|
2188
|
+
* `surfaceRay` tests every triangle through `Raycaster.intersectObjects` of three.js instead of the triangle index. The hits are the same
|
|
2189
|
+
* (tests/surface-ray-exact of the fleet compares the two); this is the reference path for those tests, slower by far on a heavy model.
|
|
2190
|
+
*/
|
|
2191
|
+
bruteForceRays?: boolean;
|
|
2187
2192
|
}
|
|
2188
2193
|
/** What the vehicle can do now, from the state of its hidden mechanics. */
|
|
2189
2194
|
interface VehicleStatus {
|
package/dist/index.global.js
CHANGED
|
@@ -2715,10 +2715,15 @@ var GameVehicles = (() => {
|
|
|
2715
2715
|
if (geo.boundingSphere === null) geo.computeBoundingSphere();
|
|
2716
2716
|
s.sphere.copy(geo.boundingSphere).applyMatrix4(mesh2.matrixWorld);
|
|
2717
2717
|
if (!raycaster.ray.intersectsSphere(s.sphere)) return;
|
|
2718
|
-
const ti = rayIndexOf(geo);
|
|
2719
|
-
if (!ti) return;
|
|
2720
2718
|
s.inverse.copy(mesh2.matrixWorld).invert();
|
|
2721
2719
|
s.local.copy(raycaster.ray).applyMatrix4(s.inverse);
|
|
2720
|
+
intersectTriangles(THREE, raycaster, mesh2, out);
|
|
2721
|
+
}
|
|
2722
|
+
function intersectTriangles(THREE, raycaster, mesh2, out) {
|
|
2723
|
+
const geo = mesh2.geometry;
|
|
2724
|
+
const s = scratchOf(THREE);
|
|
2725
|
+
const ti = rayIndexOf(geo);
|
|
2726
|
+
if (!ti) return;
|
|
2722
2727
|
const material = mesh2.material;
|
|
2723
2728
|
const back = material.side === THREE.BackSide;
|
|
2724
2729
|
const cull = material.side === THREE.FrontSide;
|
|
@@ -2766,6 +2771,37 @@ var GameVehicles = (() => {
|
|
|
2766
2771
|
}
|
|
2767
2772
|
if (recursive) for (const child of object2.children) collect(THREE, raycaster, child, true, out);
|
|
2768
2773
|
}
|
|
2774
|
+
function passesThreePrologue(THREE, raycaster, mesh2) {
|
|
2775
|
+
const geo = mesh2.geometry;
|
|
2776
|
+
const s = scratchOf(THREE);
|
|
2777
|
+
if (geo.boundingSphere === null) geo.computeBoundingSphere();
|
|
2778
|
+
s.sphere.copy(geo.boundingSphere).applyMatrix4(mesh2.matrixWorld);
|
|
2779
|
+
s.local.copy(raycaster.ray).recast(raycaster.near);
|
|
2780
|
+
if (!s.sphere.containsPoint(s.local.origin)) {
|
|
2781
|
+
if (s.local.intersectSphere(s.sphere, s.point) === null) return false;
|
|
2782
|
+
if (s.local.origin.distanceToSquared(s.point) > (raycaster.far - raycaster.near) ** 2) return false;
|
|
2783
|
+
}
|
|
2784
|
+
s.inverse.copy(mesh2.matrixWorld).invert();
|
|
2785
|
+
s.local.copy(raycaster.ray).applyMatrix4(s.inverse);
|
|
2786
|
+
return geo.boundingBox === null || s.local.intersectsBox(geo.boundingBox);
|
|
2787
|
+
}
|
|
2788
|
+
function alignedRange(mesh2) {
|
|
2789
|
+
const geo = mesh2.geometry;
|
|
2790
|
+
const count = geo.index ? geo.index.count : geo.attributes.position.count;
|
|
2791
|
+
const first = Math.max(0, geo.drawRange.start);
|
|
2792
|
+
const last = Math.min(count, geo.drawRange.start + geo.drawRange.count);
|
|
2793
|
+
return first % 3 === 0 && (last <= first || (last - first) % 3 === 0);
|
|
2794
|
+
}
|
|
2795
|
+
function raycastMeshesLikeThree(THREE, raycaster, objects) {
|
|
2796
|
+
const out = [];
|
|
2797
|
+
for (const object2 of objects) {
|
|
2798
|
+
if (!object2.layers.test(raycaster.layers)) continue;
|
|
2799
|
+
if (!indexable(THREE, object2) || !alignedRange(object2)) object2.raycast(raycaster, out);
|
|
2800
|
+
else if (passesThreePrologue(THREE, raycaster, object2)) intersectTriangles(THREE, raycaster, object2, out);
|
|
2801
|
+
}
|
|
2802
|
+
out.sort((x, y) => x.distance - y.distance);
|
|
2803
|
+
return out;
|
|
2804
|
+
}
|
|
2769
2805
|
function raycastIndexed(THREE, raycaster, objects, recursive = false) {
|
|
2770
2806
|
const out = [];
|
|
2771
2807
|
for (const object2 of objects) collect(THREE, raycaster, object2, recursive, out);
|
|
@@ -16140,12 +16176,13 @@ var GameVehicles = (() => {
|
|
|
16140
16176
|
for (const child of o.children) collectSurfaces(child);
|
|
16141
16177
|
};
|
|
16142
16178
|
const surfaceRay = (ray) => {
|
|
16143
|
-
|
|
16179
|
+
c.vehicle.updateWorldMatrix(true, true);
|
|
16144
16180
|
surfaceRays.set(new V3(ray.origin[0], ray.origin[1], ray.origin[2]), new V3(ray.direction[0], ray.direction[1], ray.direction[2]));
|
|
16145
16181
|
surfaceRays.far = ray.maxDistance;
|
|
16146
16182
|
surfaceMeshes.length = 0;
|
|
16147
16183
|
for (const child of c.vehicle.children) collectSurfaces(child);
|
|
16148
|
-
|
|
16184
|
+
const hits = options.bruteForceRays ? surfaceRays.intersectObjects(surfaceMeshes, false) : raycastMeshesLikeThree(THREE, surfaceRays, surfaceMeshes);
|
|
16185
|
+
for (const h of hits) {
|
|
16149
16186
|
if (!h.face || !isDrawnSurface(h.object)) continue;
|
|
16150
16187
|
const p = partOfSurface(h.object, c.vehicle.worldToLocal(h.point.clone()));
|
|
16151
16188
|
if (!p || p.lost || ray.ignored?.(p.def.id)) continue;
|