@adatechnology/game-terrain 0.7.1 → 0.7.2
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 +2 -1
- package/dist/index.global.js +14 -0
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1594,6 +1594,7 @@ var PART_ID = "ground";
|
|
|
1594
1594
|
var PART_DEPTH = 3;
|
|
1595
1595
|
var RAY_BACKOFF = 1;
|
|
1596
1596
|
var GROUND_HP = 1e12;
|
|
1597
|
+
var HEAP_REACH = 3;
|
|
1597
1598
|
function createTerrainImpl(terrain, options) {
|
|
1598
1599
|
const { id } = options;
|
|
1599
1600
|
const [x0, z0, x1, z1] = terrain.bounds;
|
|
@@ -1644,10 +1645,23 @@ function createTerrainImpl(terrain, options) {
|
|
|
1644
1645
|
const onGround = terrain.raycast(from, hit.direction, RAY_BACKOFF + PART_DEPTH);
|
|
1645
1646
|
return onGround ? { ...hit, point: onGround.point } : hit;
|
|
1646
1647
|
};
|
|
1648
|
+
const surfaceRay = (ray) => {
|
|
1649
|
+
if (ray.ignored?.(PART_ID)) return null;
|
|
1650
|
+
const [ox, oy, oz] = ray.origin;
|
|
1651
|
+
const [dx, dy, dz] = ray.direction;
|
|
1652
|
+
const enter = dy < 0 ? Math.max(0, (oy - HEAP_REACH) / -dy) : oy <= HEAP_REACH ? 0 : Infinity;
|
|
1653
|
+
const leave = dy < 0 ? (oy + PART_DEPTH) / -dy : Math.hypot(x1 - x0, z1 - z0) + Math.hypot(ox - (x0 + x1) / 2, oz - (z0 + z1) / 2);
|
|
1654
|
+
const far = Math.min(ray.maxDistance, leave);
|
|
1655
|
+
if (!(enter <= far)) return null;
|
|
1656
|
+
const hit = terrain.raycast([ox + dx * enter, oy + dy * enter, oz + dz * enter], ray.direction, far - enter);
|
|
1657
|
+
if (!hit) return null;
|
|
1658
|
+
return { part: PART_ID, point: hit.point, normal: hit.normal, distance: enter + hit.distance, pathLen: PART_DEPTH };
|
|
1659
|
+
};
|
|
1647
1660
|
return {
|
|
1648
1661
|
id,
|
|
1649
1662
|
...options.name ? { name: options.name } : {},
|
|
1650
1663
|
describe: spec,
|
|
1664
|
+
surfaceRay,
|
|
1651
1665
|
hit(hit) {
|
|
1652
1666
|
const landed = resolve(hit);
|
|
1653
1667
|
const result = terrain.applyHit(landed);
|