@playcanvas/supersplat-viewer 1.24.0 → 1.25.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/dist/index.js +1 -1
- package/package.json +9 -9
- package/public/index.js +517 -299
- package/public/index.js.map +1 -1
package/public/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const TRACEID_GPU_TIMINGS = 'GpuTimings';
|
|
2
2
|
|
|
3
|
-
const version$1 = '2.19.0-preview.
|
|
4
|
-
const revision = '
|
|
3
|
+
const version$1 = '2.19.0-preview.1';
|
|
4
|
+
const revision = '4ceb7e8';
|
|
5
5
|
function extend(target, ex) {
|
|
6
6
|
for(const prop in ex){
|
|
7
7
|
const copy = ex[prop];
|
|
@@ -26433,27 +26433,27 @@ float getOpacity() {
|
|
|
26433
26433
|
return float(cachedTransformA.a >> 24u) / 255.0;
|
|
26434
26434
|
}
|
|
26435
26435
|
vec3 getColor() {
|
|
26436
|
-
uint
|
|
26437
|
-
float r = float(
|
|
26438
|
-
float g = float((
|
|
26439
|
-
float b = float((
|
|
26436
|
+
uint data = loadDataColor().x;
|
|
26437
|
+
float r = float(data & 0x7FFu) * (4.0 / 2047.0);
|
|
26438
|
+
float g = float((data >> 11u) & 0x7FFu) * (4.0 / 2047.0);
|
|
26439
|
+
float b = float((data >> 22u) & 0x3FFu) * (4.0 / 1023.0);
|
|
26440
26440
|
return vec3(r, g, b);
|
|
26441
26441
|
}
|
|
26442
26442
|
vec4 getRotation() {
|
|
26443
|
-
uint
|
|
26443
|
+
uint data = loadDataTransformB().x;
|
|
26444
26444
|
vec3 p = vec3(
|
|
26445
|
-
float(
|
|
26446
|
-
float((
|
|
26447
|
-
float((
|
|
26445
|
+
float(data & 0x7FFu) / 2047.0 * 2.0 - 1.0,
|
|
26446
|
+
float((data >> 11u) & 0x7FFu) / 2047.0 * 2.0 - 1.0,
|
|
26447
|
+
float((data >> 22u) & 0x3FFu) / 1023.0 * 2.0 - 1.0
|
|
26448
26448
|
);
|
|
26449
26449
|
float d = dot(p, p);
|
|
26450
26450
|
return vec4(1.0 - d, sqrt(max(0.0, 2.0 - d)) * p);
|
|
26451
26451
|
}
|
|
26452
26452
|
vec3 getScale() {
|
|
26453
|
-
uint
|
|
26454
|
-
float sx = float(
|
|
26455
|
-
float sy = float((
|
|
26456
|
-
float sz = float((
|
|
26453
|
+
uint data = cachedTransformA.a;
|
|
26454
|
+
float sx = float(data & 0xFFu);
|
|
26455
|
+
float sy = float((data >> 8u) & 0xFFu);
|
|
26456
|
+
float sz = float((data >> 16u) & 0xFFu);
|
|
26457
26457
|
const float logRange = 21.0 / 255.0;
|
|
26458
26458
|
const float logMin = -12.0;
|
|
26459
26459
|
return vec3(
|
|
@@ -26559,27 +26559,27 @@ fn getOpacity() -> f32 {
|
|
|
26559
26559
|
return f32(cachedTransformA.a >> 24u) / 255.0;
|
|
26560
26560
|
}
|
|
26561
26561
|
fn getColor() -> vec3f {
|
|
26562
|
-
let
|
|
26563
|
-
let r = f32(
|
|
26564
|
-
let g = f32((
|
|
26565
|
-
let b = f32((
|
|
26562
|
+
let data = loadDataColor().x;
|
|
26563
|
+
let r = f32(data & 0x7FFu) * (4.0 / 2047.0);
|
|
26564
|
+
let g = f32((data >> 11u) & 0x7FFu) * (4.0 / 2047.0);
|
|
26565
|
+
let b = f32((data >> 22u) & 0x3FFu) * (4.0 / 1023.0);
|
|
26566
26566
|
return vec3f(r, g, b);
|
|
26567
26567
|
}
|
|
26568
26568
|
fn getRotation() -> vec4f {
|
|
26569
|
-
let
|
|
26569
|
+
let data = loadDataTransformB().x;
|
|
26570
26570
|
let p = vec3f(
|
|
26571
|
-
f32(
|
|
26572
|
-
f32((
|
|
26573
|
-
f32((
|
|
26571
|
+
f32(data & 0x7FFu) / 2047.0 * 2.0 - 1.0,
|
|
26572
|
+
f32((data >> 11u) & 0x7FFu) / 2047.0 * 2.0 - 1.0,
|
|
26573
|
+
f32((data >> 22u) & 0x3FFu) / 1023.0 * 2.0 - 1.0
|
|
26574
26574
|
);
|
|
26575
26575
|
let d = dot(p, p);
|
|
26576
26576
|
return vec4f(1.0 - d, sqrt(max(0.0, 2.0 - d)) * p);
|
|
26577
26577
|
}
|
|
26578
26578
|
fn getScale() -> vec3f {
|
|
26579
|
-
let
|
|
26580
|
-
let sx = f32(
|
|
26581
|
-
let sy = f32((
|
|
26582
|
-
let sz = f32((
|
|
26579
|
+
let data = cachedTransformA.a;
|
|
26580
|
+
let sx = f32(data & 0xFFu);
|
|
26581
|
+
let sy = f32((data >> 8u) & 0xFFu);
|
|
26582
|
+
let sz = f32((data >> 16u) & 0xFFu);
|
|
26583
26583
|
let logRange = 21.0 / 255.0;
|
|
26584
26584
|
let logMin = -12.0;
|
|
26585
26585
|
return vec3f(
|
|
@@ -61572,8 +61572,8 @@ uniform uint splatTextureSize;
|
|
|
61572
61572
|
var gsplatUncompressedVS$1 = `
|
|
61573
61573
|
uint tAw;
|
|
61574
61574
|
vec4 tBcached;
|
|
61575
|
-
vec4 unpackRotation(vec3
|
|
61576
|
-
return vec4(
|
|
61575
|
+
vec4 unpackRotation(vec3 data) {
|
|
61576
|
+
return vec4(data.xyz, sqrt(max(0.0, 1.0 - dot(data, data))));
|
|
61577
61577
|
}
|
|
61578
61578
|
vec3 getCenter() {
|
|
61579
61579
|
uvec4 tA = loadTransformA();
|
|
@@ -62594,8 +62594,8 @@ uniform splatTextureSize: u32;
|
|
|
62594
62594
|
var gsplatUncompressedVS = `
|
|
62595
62595
|
var<private> tAw: u32;
|
|
62596
62596
|
var<private> tBcached: vec4f;
|
|
62597
|
-
fn unpackRotation(
|
|
62598
|
-
return vec4f(
|
|
62597
|
+
fn unpackRotation(data: vec3f) -> vec4f {
|
|
62598
|
+
return vec4f(data.xyz, sqrt(max(0.0, 1.0 - dot(data, data))));
|
|
62599
62599
|
}
|
|
62600
62600
|
fn getCenter() -> vec3f {
|
|
62601
62601
|
let tA: vec4<u32> = loadTransformA();
|
|
@@ -76052,6 +76052,12 @@ class App extends AppBase {
|
|
|
76052
76052
|
}
|
|
76053
76053
|
}
|
|
76054
76054
|
|
|
76055
|
+
/**
|
|
76056
|
+
* Fallback voxel cell size for mesh collision, which doesn't carry the carve
|
|
76057
|
+
* metadata itself. Assumes the mesh was generated from a voxel grid at this
|
|
76058
|
+
* resolution (matches the default `splat-transform --voxel-carve` output).
|
|
76059
|
+
*/
|
|
76060
|
+
const DEFAULT_VOXEL_RESOLUTION = 0.05;
|
|
76055
76061
|
/** Minimum penetration depth to report (avoids floating-point noise) */
|
|
76056
76062
|
const PENETRATION_EPSILON = 1e-4;
|
|
76057
76063
|
/** Maximum iterations for iterative sphere/capsule resolution */
|
|
@@ -76376,6 +76382,12 @@ const _closest = { x: 0, y: 0, z: 0 };
|
|
|
76376
76382
|
const _segClosest = { x: 0, y: 0, z: 0 };
|
|
76377
76383
|
const _triClosest = { x: 0, y: 0, z: 0 };
|
|
76378
76384
|
class MeshCollision {
|
|
76385
|
+
/**
|
|
76386
|
+
* Assumed voxel resolution of the source carve that produced this mesh.
|
|
76387
|
+
* The mesh itself doesn't carry this metadata, so we fall back to the
|
|
76388
|
+
* default; can be overridden post-construction if a loader knows better.
|
|
76389
|
+
*/
|
|
76390
|
+
voxelResolution = DEFAULT_VOXEL_RESOLUTION;
|
|
76379
76391
|
_tris;
|
|
76380
76392
|
_root;
|
|
76381
76393
|
_normalResult = { nx: 0, ny: 0, nz: 0 };
|
|
@@ -76480,6 +76492,12 @@ class MeshCollision {
|
|
|
76480
76492
|
queryCapsule(cx, cy, cz, halfHeight, radius, out) {
|
|
76481
76493
|
return resolveIterative(cx, cy, cz, (rx, ry, rz, push) => this._deepestCapsulePenetration(rx, ry, rz, halfHeight, radius, push), this._constraintNormals, this._push, out);
|
|
76482
76494
|
}
|
|
76495
|
+
isFreeAt(x, y, z) {
|
|
76496
|
+
// Approximation: a point is in free space iff no triangle is within
|
|
76497
|
+
// half a voxel of it. Matches the voxel-grid notion for data derived
|
|
76498
|
+
// from the same carve.
|
|
76499
|
+
return !this._deepestSpherePenetration(x, y, z, this.voxelResolution * 0.5, this._push);
|
|
76500
|
+
}
|
|
76483
76501
|
querySurfaceNormal(x, y, z, rdx, rdy, rdz) {
|
|
76484
76502
|
const len = Math.sqrt(rdx * rdx + rdy * rdy + rdz * rdz);
|
|
76485
76503
|
if (len < 1e-10) {
|
|
@@ -77013,6 +77031,25 @@ class VoxelCollision {
|
|
|
77013
77031
|
get flipXY() {
|
|
77014
77032
|
return false;
|
|
77015
77033
|
}
|
|
77034
|
+
isFreeAt(x, y, z) {
|
|
77035
|
+
// Without voxel data, there's no carve to consult — report not-free
|
|
77036
|
+
// rather than have the lattice search treat the world as wide open.
|
|
77037
|
+
if (this._nodes.length === 0) {
|
|
77038
|
+
return false;
|
|
77039
|
+
}
|
|
77040
|
+
const res = this._voxelResolution;
|
|
77041
|
+
const ix = Math.floor((x - this._gridMinX) / res);
|
|
77042
|
+
const iy = Math.floor((y - this._gridMinY) / res);
|
|
77043
|
+
const iz = Math.floor((z - this._gridMinZ) / res);
|
|
77044
|
+
// Outside the carved grid is "no data" — also not-free. Without this
|
|
77045
|
+
// check the lattice search would spend candidates on out-of-bounds
|
|
77046
|
+
// cells (and `isVoxelSolid` would mislead callers by returning false).
|
|
77047
|
+
if (ix < 0 || iy < 0 || iz < 0 ||
|
|
77048
|
+
ix >= this._numVoxelsX || iy >= this._numVoxelsY || iz >= this._numVoxelsZ) {
|
|
77049
|
+
return false;
|
|
77050
|
+
}
|
|
77051
|
+
return !this.isVoxelSolid(ix, iy, iz);
|
|
77052
|
+
}
|
|
77016
77053
|
querySurfaceNormal(x, y, z, rdx, rdy, rdz) {
|
|
77017
77054
|
const nudge = this._voxelResolution * 0.25;
|
|
77018
77055
|
const ix = Math.floor((x + Math.sign(rdx) * nudge - this._gridMinX) / this._voxelResolution);
|
|
@@ -77555,6 +77592,9 @@ class FlippedVoxelCollision extends VoxelCollision {
|
|
|
77555
77592
|
}
|
|
77556
77593
|
return result;
|
|
77557
77594
|
}
|
|
77595
|
+
isFreeAt(x, y, z) {
|
|
77596
|
+
return super.isFreeAt(-x, -y, z);
|
|
77597
|
+
}
|
|
77558
77598
|
}
|
|
77559
77599
|
/**
|
|
77560
77600
|
* Load a VoxelCollision from a .voxel.json URL.
|
|
@@ -77723,7 +77763,7 @@ const importSettings = (settings) => {
|
|
|
77723
77763
|
return result;
|
|
77724
77764
|
};
|
|
77725
77765
|
|
|
77726
|
-
var version = "1.
|
|
77766
|
+
var version = "1.25.0";
|
|
77727
77767
|
|
|
77728
77768
|
class Tooltip {
|
|
77729
77769
|
register;
|
|
@@ -79150,6 +79190,161 @@ const createRotateTrack = (position, target, fov, keys = 12, duration = 20) => {
|
|
|
79150
79190
|
};
|
|
79151
79191
|
};
|
|
79152
79192
|
|
|
79193
|
+
/**
|
|
79194
|
+
* Damping function to smooth out transitions.
|
|
79195
|
+
*
|
|
79196
|
+
* @param damping - Damping factor (0 < damping < 1).
|
|
79197
|
+
* @param dt - Delta time in seconds.
|
|
79198
|
+
* @returns - Damping factor adjusted for the delta time.
|
|
79199
|
+
*/
|
|
79200
|
+
const damp = (damping, dt) => 1 - Math.pow(damping, dt * 1000);
|
|
79201
|
+
/**
|
|
79202
|
+
* Easing function for smooth transitions.
|
|
79203
|
+
*
|
|
79204
|
+
* @param x - Input value in the range [0, 1].
|
|
79205
|
+
* @returns - Output value in the range [0, 1].
|
|
79206
|
+
*/
|
|
79207
|
+
const easeOut = (x) => (1 - (2 ** (-10 * x))) / (1 - (2 ** -10));
|
|
79208
|
+
/**
|
|
79209
|
+
* Modulus function that handles negative values correctly.
|
|
79210
|
+
*
|
|
79211
|
+
* @param n - The number to be modulated.
|
|
79212
|
+
* @param m - The modulus value.
|
|
79213
|
+
* @returns - The result of n mod m, adjusted to be non-negative.
|
|
79214
|
+
*/
|
|
79215
|
+
const mod = (n, m) => ((n % m) + m) % m;
|
|
79216
|
+
const nearlyEquals = (a, b, epsilon = 1e-4) => {
|
|
79217
|
+
return !a.some((v, i) => Math.abs(v - b[i]) >= epsilon);
|
|
79218
|
+
};
|
|
79219
|
+
const vecToAngles = (result, vec) => {
|
|
79220
|
+
const radToDeg = 180 / Math.PI;
|
|
79221
|
+
const horizLenSq = vec.x * vec.x + vec.z * vec.z;
|
|
79222
|
+
result.x = Math.asin(Math.max(-1, Math.min(1, vec.y))) * radToDeg;
|
|
79223
|
+
result.y = horizLenSq > 1e-8 ? Math.atan2(-vec.x, -vec.z) * radToDeg : 0;
|
|
79224
|
+
result.z = 0;
|
|
79225
|
+
return result;
|
|
79226
|
+
};
|
|
79227
|
+
|
|
79228
|
+
/**
|
|
79229
|
+
* Shared damping factor for controller smoothing (rotate / move / zoom) so
|
|
79230
|
+
* orbit, fly, and walk feel the same. Used as `damp(damping, dt)` →
|
|
79231
|
+
* `1 - damping^(dt*1000)`. Higher means smoother / more lag. Not used for
|
|
79232
|
+
* physics-style velocity decay (e.g. walk's grounded/air velocity damping),
|
|
79233
|
+
* which has different tuning needs.
|
|
79234
|
+
*/
|
|
79235
|
+
const DEFAULT_CONTROLLER_DAMPING = 0.95;
|
|
79236
|
+
const rotation$1 = new Quat();
|
|
79237
|
+
/**
|
|
79238
|
+
* Apply a CameraFrame rotate delta to camera Euler angles.
|
|
79239
|
+
*
|
|
79240
|
+
* CameraFrame rotate uses [yaw, pitch, roll]-style input deltas, while camera
|
|
79241
|
+
* angles are stored as [pitch, yaw, roll].
|
|
79242
|
+
*
|
|
79243
|
+
* @param angles - Camera Euler angles to mutate.
|
|
79244
|
+
* @param rotate - Frame rotate delta.
|
|
79245
|
+
* @param minPitch - Minimum pitch angle in degrees.
|
|
79246
|
+
* @param maxPitch - Maximum pitch angle in degrees.
|
|
79247
|
+
* @returns The mutated angles.
|
|
79248
|
+
*/
|
|
79249
|
+
const applyFrameRotation = (angles, rotate, minPitch = -90, maxPitch = 90) => {
|
|
79250
|
+
angles.x -= rotate[1];
|
|
79251
|
+
angles.y -= rotate[0];
|
|
79252
|
+
angles.z = 0;
|
|
79253
|
+
angles.x = math.clamp(angles.x, minPitch, maxPitch);
|
|
79254
|
+
return angles;
|
|
79255
|
+
};
|
|
79256
|
+
/**
|
|
79257
|
+
* Calculate camera-relative basis vectors from Euler angles.
|
|
79258
|
+
*
|
|
79259
|
+
* @param angles - Camera Euler angles in degrees.
|
|
79260
|
+
* @param forward - Receives the forward vector.
|
|
79261
|
+
* @param right - Receives the right vector.
|
|
79262
|
+
* @param up - Receives the up vector.
|
|
79263
|
+
*/
|
|
79264
|
+
const setCameraBasis = (angles, forward, right, up) => {
|
|
79265
|
+
rotation$1.setFromEulerAngles(angles);
|
|
79266
|
+
rotation$1.transformVector(Vec3.FORWARD, forward);
|
|
79267
|
+
rotation$1.transformVector(Vec3.RIGHT, right);
|
|
79268
|
+
rotation$1.transformVector(Vec3.UP, up);
|
|
79269
|
+
};
|
|
79270
|
+
/**
|
|
79271
|
+
* Calculate a camera forward vector from Euler angles.
|
|
79272
|
+
*
|
|
79273
|
+
* @param angles - Camera Euler angles in degrees.
|
|
79274
|
+
* @param forward - Receives the forward vector.
|
|
79275
|
+
*/
|
|
79276
|
+
const setCameraForward = (angles, forward) => {
|
|
79277
|
+
rotation$1.setFromEulerAngles(angles);
|
|
79278
|
+
rotation$1.transformVector(Vec3.FORWARD, forward);
|
|
79279
|
+
};
|
|
79280
|
+
/**
|
|
79281
|
+
* Calculate yaw-only movement basis vectors.
|
|
79282
|
+
*
|
|
79283
|
+
* @param yaw - Camera yaw angle in degrees.
|
|
79284
|
+
* @param forward - Receives the horizontal forward vector.
|
|
79285
|
+
* @param right - Receives the horizontal right vector.
|
|
79286
|
+
*/
|
|
79287
|
+
const setYawBasis = (yaw, forward, right) => {
|
|
79288
|
+
rotation$1.setFromEulerAngles(0, yaw, 0);
|
|
79289
|
+
rotation$1.transformVector(Vec3.FORWARD, forward);
|
|
79290
|
+
rotation$1.transformVector(Vec3.RIGHT, right);
|
|
79291
|
+
};
|
|
79292
|
+
/**
|
|
79293
|
+
* Build a world-space offset from local movement along camera basis vectors.
|
|
79294
|
+
*
|
|
79295
|
+
* @param out - Receives the world-space offset.
|
|
79296
|
+
* @param x - Local right movement.
|
|
79297
|
+
* @param y - Local up movement.
|
|
79298
|
+
* @param z - Local forward movement.
|
|
79299
|
+
* @param forward - Forward basis vector.
|
|
79300
|
+
* @param right - Right basis vector.
|
|
79301
|
+
* @param up - Up basis vector.
|
|
79302
|
+
* @returns The mutated output vector.
|
|
79303
|
+
*/
|
|
79304
|
+
const setBasisOffset = (out, x, y, z, forward, right, up) => {
|
|
79305
|
+
out.set(right.x * x + up.x * y + forward.x * z, right.y * x + up.y * y + forward.y * z, right.z * x + up.z * y + forward.z * z);
|
|
79306
|
+
return out;
|
|
79307
|
+
};
|
|
79308
|
+
/**
|
|
79309
|
+
* Lerp Euler angles toward a target using frame-rate-independent shortest-path
|
|
79310
|
+
* interpolation. Yaw/roll on both `angles` and `target` are wrapped into
|
|
79311
|
+
* `[0, 360)` so `lerpAngle`'s single-shift shortest-path stays valid after
|
|
79312
|
+
* many full rotations (otherwise the camera takes the long way around). Pitch
|
|
79313
|
+
* is left untouched since callers clamp it.
|
|
79314
|
+
*
|
|
79315
|
+
* @param angles - Current angles, mutated toward target.
|
|
79316
|
+
* @param target - Target angles. Yaw/roll are wrapped in place to keep
|
|
79317
|
+
* accumulated drift bounded across frames.
|
|
79318
|
+
* @param damping - Damping factor in [0, 1]. Higher = smoother (1 = never moves).
|
|
79319
|
+
* @param dt - Delta time in seconds.
|
|
79320
|
+
* @returns The mutated angles.
|
|
79321
|
+
*/
|
|
79322
|
+
const dampAngles = (angles, target, damping, dt) => {
|
|
79323
|
+
if (dt <= 0) {
|
|
79324
|
+
return angles;
|
|
79325
|
+
}
|
|
79326
|
+
const t = damp(damping, dt);
|
|
79327
|
+
angles.y = mod(angles.y, 360);
|
|
79328
|
+
angles.z = mod(angles.z, 360);
|
|
79329
|
+
target.y = mod(target.y, 360);
|
|
79330
|
+
target.z = mod(target.z, 360);
|
|
79331
|
+
angles.x = math.lerpAngle(angles.x, target.x, t);
|
|
79332
|
+
angles.y = math.lerpAngle(angles.y, target.y, t);
|
|
79333
|
+
angles.z = math.lerpAngle(angles.z, target.z, t);
|
|
79334
|
+
return angles;
|
|
79335
|
+
};
|
|
79336
|
+
/**
|
|
79337
|
+
* Discard any pending input deltas in the frame. `InputFrame.read()` zeros
|
|
79338
|
+
* deltas as a side-effect of reading, so calling this prevents accumulated
|
|
79339
|
+
* input from leaking into the next controller when a non-input-driven mode
|
|
79340
|
+
* (e.g. animation) is active.
|
|
79341
|
+
*
|
|
79342
|
+
* @param frame - The camera frame whose deltas should be drained.
|
|
79343
|
+
*/
|
|
79344
|
+
const drainInputFrame = (frame) => {
|
|
79345
|
+
frame.read();
|
|
79346
|
+
};
|
|
79347
|
+
|
|
79153
79348
|
class CubicSpline {
|
|
79154
79349
|
// control times
|
|
79155
79350
|
times;
|
|
@@ -79261,41 +79456,6 @@ class CubicSpline {
|
|
|
79261
79456
|
}
|
|
79262
79457
|
}
|
|
79263
79458
|
|
|
79264
|
-
/**
|
|
79265
|
-
* Damping function to smooth out transitions.
|
|
79266
|
-
*
|
|
79267
|
-
* @param damping - Damping factor (0 < damping < 1).
|
|
79268
|
-
* @param dt - Delta time in seconds.
|
|
79269
|
-
* @returns - Damping factor adjusted for the delta time.
|
|
79270
|
-
*/
|
|
79271
|
-
const damp = (damping, dt) => 1 - Math.pow(damping, dt * 1000);
|
|
79272
|
-
/**
|
|
79273
|
-
* Easing function for smooth transitions.
|
|
79274
|
-
*
|
|
79275
|
-
* @param x - Input value in the range [0, 1].
|
|
79276
|
-
* @returns - Output value in the range [0, 1].
|
|
79277
|
-
*/
|
|
79278
|
-
const easeOut = (x) => (1 - (2 ** (-10 * x))) / (1 - (2 ** -10));
|
|
79279
|
-
/**
|
|
79280
|
-
* Modulus function that handles negative values correctly.
|
|
79281
|
-
*
|
|
79282
|
-
* @param n - The number to be modulated.
|
|
79283
|
-
* @param m - The modulus value.
|
|
79284
|
-
* @returns - The result of n mod m, adjusted to be non-negative.
|
|
79285
|
-
*/
|
|
79286
|
-
const mod = (n, m) => ((n % m) + m) % m;
|
|
79287
|
-
const nearlyEquals = (a, b, epsilon = 1e-4) => {
|
|
79288
|
-
return !a.some((v, i) => Math.abs(v - b[i]) >= epsilon);
|
|
79289
|
-
};
|
|
79290
|
-
const vecToAngles = (result, vec) => {
|
|
79291
|
-
const radToDeg = 180 / Math.PI;
|
|
79292
|
-
const horizLenSq = vec.x * vec.x + vec.z * vec.z;
|
|
79293
|
-
result.x = Math.asin(Math.max(-1, Math.min(1, vec.y))) * radToDeg;
|
|
79294
|
-
result.y = horizLenSq > 1e-8 ? Math.atan2(-vec.x, -vec.z) * radToDeg : 0;
|
|
79295
|
-
result.z = 0;
|
|
79296
|
-
return result;
|
|
79297
|
-
};
|
|
79298
|
-
|
|
79299
79459
|
// track an animation cursor with support for repeat and ping-pong loop modes
|
|
79300
79460
|
class AnimCursor {
|
|
79301
79461
|
duration = 0;
|
|
@@ -79397,13 +79557,13 @@ class AnimController {
|
|
|
79397
79557
|
this.animState.update(deltaTime);
|
|
79398
79558
|
camera.look(this.animState.position, this.animState.target);
|
|
79399
79559
|
camera.fov = this.animState.fov;
|
|
79400
|
-
inputFrame
|
|
79560
|
+
drainInputFrame(inputFrame);
|
|
79401
79561
|
}
|
|
79402
79562
|
onExit(camera) {
|
|
79403
79563
|
}
|
|
79404
79564
|
}
|
|
79405
79565
|
|
|
79406
|
-
const rotation
|
|
79566
|
+
const rotation = new Quat();
|
|
79407
79567
|
const avec = new Vec3();
|
|
79408
79568
|
const bvec = new Vec3();
|
|
79409
79569
|
class Camera {
|
|
@@ -79438,88 +79598,72 @@ class Camera {
|
|
|
79438
79598
|
vecToAngles(this.angles, dir);
|
|
79439
79599
|
}
|
|
79440
79600
|
calcFocusPoint(result) {
|
|
79441
|
-
rotation
|
|
79601
|
+
rotation.setFromEulerAngles(this.angles)
|
|
79442
79602
|
.transformVector(Vec3.FORWARD, result)
|
|
79443
79603
|
.mulScalar(this.distance)
|
|
79444
79604
|
.add(this.position);
|
|
79445
79605
|
}
|
|
79446
79606
|
}
|
|
79447
79607
|
|
|
79448
|
-
const rotation = new Quat();
|
|
79449
|
-
/**
|
|
79450
|
-
* Apply a CameraFrame rotate delta to camera Euler angles.
|
|
79451
|
-
*
|
|
79452
|
-
* CameraFrame rotate uses [yaw, pitch, roll]-style input deltas, while camera
|
|
79453
|
-
* angles are stored as [pitch, yaw, roll].
|
|
79454
|
-
*
|
|
79455
|
-
* @param angles - Camera Euler angles to mutate.
|
|
79456
|
-
* @param rotate - Frame rotate delta.
|
|
79457
|
-
* @param minPitch - Minimum pitch angle in degrees.
|
|
79458
|
-
* @param maxPitch - Maximum pitch angle in degrees.
|
|
79459
|
-
* @returns The mutated angles.
|
|
79460
|
-
*/
|
|
79461
|
-
const applyFrameRotation = (angles, rotate, minPitch = -90, maxPitch = 90) => {
|
|
79462
|
-
angles.x -= rotate[1];
|
|
79463
|
-
angles.y -= rotate[0];
|
|
79464
|
-
angles.z = 0;
|
|
79465
|
-
angles.x = math.clamp(angles.x, minPitch, maxPitch);
|
|
79466
|
-
return angles;
|
|
79467
|
-
};
|
|
79468
|
-
/**
|
|
79469
|
-
* Calculate camera-relative basis vectors from Euler angles.
|
|
79470
|
-
*
|
|
79471
|
-
* @param angles - Camera Euler angles in degrees.
|
|
79472
|
-
* @param forward - Receives the forward vector.
|
|
79473
|
-
* @param right - Receives the right vector.
|
|
79474
|
-
* @param up - Receives the up vector.
|
|
79475
|
-
*/
|
|
79476
|
-
const setCameraBasis = (angles, forward, right, up) => {
|
|
79477
|
-
rotation.setFromEulerAngles(angles);
|
|
79478
|
-
rotation.transformVector(Vec3.FORWARD, forward);
|
|
79479
|
-
rotation.transformVector(Vec3.RIGHT, right);
|
|
79480
|
-
rotation.transformVector(Vec3.UP, up);
|
|
79481
|
-
};
|
|
79482
|
-
/**
|
|
79483
|
-
* Calculate a camera forward vector from Euler angles.
|
|
79484
|
-
*
|
|
79485
|
-
* @param angles - Camera Euler angles in degrees.
|
|
79486
|
-
* @param forward - Receives the forward vector.
|
|
79487
|
-
*/
|
|
79488
|
-
const setCameraForward = (angles, forward) => {
|
|
79489
|
-
rotation.setFromEulerAngles(angles);
|
|
79490
|
-
rotation.transformVector(Vec3.FORWARD, forward);
|
|
79491
|
-
};
|
|
79492
|
-
/**
|
|
79493
|
-
* Calculate yaw-only movement basis vectors.
|
|
79494
|
-
*
|
|
79495
|
-
* @param yaw - Camera yaw angle in degrees.
|
|
79496
|
-
* @param forward - Receives the horizontal forward vector.
|
|
79497
|
-
* @param right - Receives the horizontal right vector.
|
|
79498
|
-
*/
|
|
79499
|
-
const setYawBasis = (yaw, forward, right) => {
|
|
79500
|
-
rotation.setFromEulerAngles(0, yaw, 0);
|
|
79501
|
-
rotation.transformVector(Vec3.FORWARD, forward);
|
|
79502
|
-
rotation.transformVector(Vec3.RIGHT, right);
|
|
79503
|
-
};
|
|
79504
79608
|
/**
|
|
79505
|
-
*
|
|
79609
|
+
* Captures a controller's pose at its initial spawn so it can be restored
|
|
79610
|
+
* later (e.g. via the "reset" UI gesture). Shared by fly and walk controllers
|
|
79611
|
+
* which both implement `resetToSpawn`.
|
|
79506
79612
|
*
|
|
79507
|
-
*
|
|
79508
|
-
*
|
|
79509
|
-
*
|
|
79510
|
-
* @param z - Local forward movement.
|
|
79511
|
-
* @param forward - Forward basis vector.
|
|
79512
|
-
* @param right - Right basis vector.
|
|
79513
|
-
* @param up - Up basis vector.
|
|
79514
|
-
* @returns The mutated output vector.
|
|
79613
|
+
* Position / angles / distance are the basic camera-pose components. Callers
|
|
79614
|
+
* with extra controller-specific state (e.g. walk's grounded flag) keep that
|
|
79615
|
+
* alongside as a separate field.
|
|
79515
79616
|
*/
|
|
79516
|
-
|
|
79517
|
-
|
|
79518
|
-
|
|
79519
|
-
|
|
79617
|
+
class SpawnState {
|
|
79618
|
+
_position = new Vec3();
|
|
79619
|
+
_angles = new Vec3();
|
|
79620
|
+
_distance = 1;
|
|
79621
|
+
_has = false;
|
|
79622
|
+
/**
|
|
79623
|
+
* True once `store` has been called at least once.
|
|
79624
|
+
*
|
|
79625
|
+
* @returns Whether a spawn pose has been captured.
|
|
79626
|
+
*/
|
|
79627
|
+
get has() {
|
|
79628
|
+
return this._has;
|
|
79629
|
+
}
|
|
79630
|
+
/**
|
|
79631
|
+
* Capture the given pose as the spawn state.
|
|
79632
|
+
*
|
|
79633
|
+
* @param position - World-space position to remember.
|
|
79634
|
+
* @param angles - Euler angles to remember.
|
|
79635
|
+
* @param distance - Camera distance (orbit-style) to remember.
|
|
79636
|
+
*/
|
|
79637
|
+
store(position, angles, distance) {
|
|
79638
|
+
this._position.copy(position);
|
|
79639
|
+
this._angles.copy(angles);
|
|
79640
|
+
this._distance = distance;
|
|
79641
|
+
this._has = true;
|
|
79642
|
+
}
|
|
79643
|
+
/**
|
|
79644
|
+
* Forget any previously-stored spawn pose so a subsequent `has` check
|
|
79645
|
+
* reports false. Used by controllers that scope spawn to a single mode
|
|
79646
|
+
* entry (e.g. walk).
|
|
79647
|
+
*/
|
|
79648
|
+
clear() {
|
|
79649
|
+
this._has = false;
|
|
79650
|
+
}
|
|
79651
|
+
/**
|
|
79652
|
+
* Copy the captured pose into the supplied targets. Caller must check
|
|
79653
|
+
* `has` first; calling `restore` before `store` returns the field
|
|
79654
|
+
* defaults (position and angles zeroed, distance `1`).
|
|
79655
|
+
*
|
|
79656
|
+
* @param position - Mutated with the stored world position.
|
|
79657
|
+
* @param angles - Mutated with the stored Euler angles.
|
|
79658
|
+
* @returns The stored camera distance.
|
|
79659
|
+
*/
|
|
79660
|
+
restore(position, angles) {
|
|
79661
|
+
position.copy(this._position);
|
|
79662
|
+
angles.copy(this._angles);
|
|
79663
|
+
return this._distance;
|
|
79664
|
+
}
|
|
79665
|
+
}
|
|
79520
79666
|
|
|
79521
|
-
/** Extra resolve passes above the collider's internal iteration for tight corners */
|
|
79522
|
-
const MAX_COLLISION_PASSES = 4;
|
|
79523
79667
|
/** Small clearance that keeps the sphere from resting exactly on a collision surface */
|
|
79524
79668
|
const COLLISION_SKIN = 1e-3;
|
|
79525
79669
|
/** Maximum surface planes to slide along in a single frame */
|
|
@@ -79537,7 +79681,7 @@ const SWEEP_RAY_OFFSETS = [
|
|
|
79537
79681
|
[-INV_SQRT2, -INV_SQRT2, false],
|
|
79538
79682
|
[INV_SQRT2, -INV_SQRT2, false]
|
|
79539
79683
|
];
|
|
79540
|
-
const v$
|
|
79684
|
+
const v$1 = new Vec3();
|
|
79541
79685
|
const remainingMove = new Vec3();
|
|
79542
79686
|
const collisionPush = new Vec3();
|
|
79543
79687
|
const sweepDir = new Vec3();
|
|
@@ -79611,10 +79755,10 @@ class SphereMover {
|
|
|
79611
79755
|
this.resolve(position);
|
|
79612
79756
|
return false;
|
|
79613
79757
|
}
|
|
79614
|
-
position.add(v$
|
|
79758
|
+
position.add(v$1.copy(sweepDir).mulScalar(sweepHit.travel));
|
|
79615
79759
|
this.resolve(position);
|
|
79616
79760
|
sweepNormal.set(sweepHit.nx, sweepHit.ny, sweepHit.nz);
|
|
79617
|
-
move.add(v$
|
|
79761
|
+
move.add(v$1.copy(sweepDir).mulScalar(-sweepHit.travel));
|
|
79618
79762
|
this._clipMove(move, sweepNormal);
|
|
79619
79763
|
return true;
|
|
79620
79764
|
}
|
|
@@ -79634,8 +79778,8 @@ class SphereMover {
|
|
|
79634
79778
|
const rayExtension = centerRay ? this.radius : 0;
|
|
79635
79779
|
sweepOrigin.copy(position);
|
|
79636
79780
|
if (!centerRay) {
|
|
79637
|
-
sweepOrigin.add(v$
|
|
79638
|
-
sweepOrigin.add(v$
|
|
79781
|
+
sweepOrigin.add(v$1.copy(sweepTangent).mulScalar(tx * radiusOffset));
|
|
79782
|
+
sweepOrigin.add(v$1.copy(sweepBitangent).mulScalar(ty * radiusOffset));
|
|
79639
79783
|
}
|
|
79640
79784
|
const hit = this.collision.queryRay(sweepOrigin.x, sweepOrigin.y, sweepOrigin.z, dir.x, dir.y, dir.z, distance + rayExtension + COLLISION_SKIN);
|
|
79641
79785
|
if (!hit) {
|
|
@@ -79664,21 +79808,20 @@ class SphereMover {
|
|
|
79664
79808
|
return found;
|
|
79665
79809
|
}
|
|
79666
79810
|
_resolveSphere(position, push) {
|
|
79667
|
-
|
|
79668
|
-
|
|
79669
|
-
|
|
79670
|
-
|
|
79671
|
-
|
|
79672
|
-
|
|
79673
|
-
position.x += pushOut.x;
|
|
79674
|
-
position.y += pushOut.y;
|
|
79675
|
-
position.z += pushOut.z;
|
|
79676
|
-
push.x += pushOut.x;
|
|
79677
|
-
push.y += pushOut.y;
|
|
79678
|
-
push.z += pushOut.z;
|
|
79679
|
-
collided = true;
|
|
79811
|
+
// `querySphere` is already corner-aware (resolveIterative inside the
|
|
79812
|
+
// collider iterates up to 4 passes with constraint-normal projection),
|
|
79813
|
+
// so a single call here is enough.
|
|
79814
|
+
if (!this.collision.querySphere(position.x, position.y, position.z, this.radius, pushOut)) {
|
|
79815
|
+
push.set(0, 0, 0);
|
|
79816
|
+
return false;
|
|
79680
79817
|
}
|
|
79681
|
-
|
|
79818
|
+
position.x += pushOut.x;
|
|
79819
|
+
position.y += pushOut.y;
|
|
79820
|
+
position.z += pushOut.z;
|
|
79821
|
+
push.x = pushOut.x;
|
|
79822
|
+
push.y = pushOut.y;
|
|
79823
|
+
push.z = pushOut.z;
|
|
79824
|
+
return true;
|
|
79682
79825
|
}
|
|
79683
79826
|
_clipMove(move, push) {
|
|
79684
79827
|
const normalSq = push.x * push.x + push.y * push.y + push.z * push.z;
|
|
@@ -79708,20 +79851,192 @@ class SphereMover {
|
|
|
79708
79851
|
}
|
|
79709
79852
|
}
|
|
79710
79853
|
|
|
79854
|
+
/** Maximum Euclidean distance (metres) from the spawn origin to search for a valid placement. */
|
|
79855
|
+
const SEARCH_RADIUS = 5;
|
|
79856
|
+
const SEARCH_RADIUS_SQ = SEARCH_RADIUS * SEARCH_RADIUS;
|
|
79857
|
+
/** Ray budget when probing for ground/ceiling under or above a candidate column. */
|
|
79858
|
+
const RAY_MAX_DIST = 1000;
|
|
79859
|
+
// Scratch values reused across calls — these helpers run only at spawn time
|
|
79860
|
+
// so the lack of re-entrancy is fine.
|
|
79861
|
+
const scratchPush = { x: 0, y: 0, z: 0 };
|
|
79862
|
+
/**
|
|
79863
|
+
* Find the closest sphere placement to (ox, oy, oz) where a sphere of `radius`
|
|
79864
|
+
* fits clear of geometry. Output is the sphere centre. Used for fly-camera
|
|
79865
|
+
* spawn — fly cameras have no ground constraint.
|
|
79866
|
+
*
|
|
79867
|
+
* Lattice search across voxel-spaced offsets from the origin (step =
|
|
79868
|
+
* `collision.voxelResolution`), ordered by Chebyshev shell with Euclidean
|
|
79869
|
+
* tie-break within a shell. Search bounded by `SEARCH_RADIUS`.
|
|
79870
|
+
*
|
|
79871
|
+
* @param collision - Active collision implementation.
|
|
79872
|
+
* @param ox - Origin X (world space).
|
|
79873
|
+
* @param oy - Origin Y (world space).
|
|
79874
|
+
* @param oz - Origin Z (world space).
|
|
79875
|
+
* @param radius - Sphere radius.
|
|
79876
|
+
* @param out - Receives the sphere centre on success.
|
|
79877
|
+
* @returns True if a valid placement was found.
|
|
79878
|
+
*/
|
|
79879
|
+
const findSphereSpawn = (collision, ox, oy, oz, radius, out) => {
|
|
79880
|
+
const step = collision.voxelResolution;
|
|
79881
|
+
const maxCells = Math.ceil(SEARCH_RADIUS / step);
|
|
79882
|
+
let bestDistSq = Infinity;
|
|
79883
|
+
let found = false;
|
|
79884
|
+
for (let r = 0; r <= maxCells; r++) {
|
|
79885
|
+
const shellMinDistSq = (r * step) * (r * step);
|
|
79886
|
+
if (shellMinDistSq >= bestDistSq)
|
|
79887
|
+
break;
|
|
79888
|
+
for (let dy = -r; dy <= r; dy++) {
|
|
79889
|
+
const absDy = dy < 0 ? -dy : dy;
|
|
79890
|
+
for (let dz = -r; dz <= r; dz++) {
|
|
79891
|
+
const absDz = dz < 0 ? -dz : dz;
|
|
79892
|
+
for (let dx = -r; dx <= r; dx++) {
|
|
79893
|
+
const absDx = dx < 0 ? -dx : dx;
|
|
79894
|
+
// Only cells on the Chebyshev shell of radius r.
|
|
79895
|
+
if (absDx < r && absDy < r && absDz < r)
|
|
79896
|
+
continue;
|
|
79897
|
+
const distSq = (dx * dx + dy * dy + dz * dz) * step * step;
|
|
79898
|
+
if (distSq >= bestDistSq || distSq > SEARCH_RADIUS_SQ)
|
|
79899
|
+
continue;
|
|
79900
|
+
const cx = ox + dx * step;
|
|
79901
|
+
const cy = oy + dy * step;
|
|
79902
|
+
const cz = oz + dz * step;
|
|
79903
|
+
if (collision.querySphere(cx, cy, cz, radius, scratchPush))
|
|
79904
|
+
continue;
|
|
79905
|
+
bestDistSq = distSq;
|
|
79906
|
+
out.x = cx;
|
|
79907
|
+
out.y = cy;
|
|
79908
|
+
out.z = cz;
|
|
79909
|
+
found = true;
|
|
79910
|
+
}
|
|
79911
|
+
}
|
|
79912
|
+
}
|
|
79913
|
+
}
|
|
79914
|
+
return found;
|
|
79915
|
+
};
|
|
79916
|
+
/**
|
|
79917
|
+
* Find the closest standable cylinder placement to (ox, oy, oz). Output is the
|
|
79918
|
+
* floor world position the cylinder rests on (highest geometry hit across the
|
|
79919
|
+
* footprint). Used for walk-camera spawn.
|
|
79920
|
+
*
|
|
79921
|
+
* The algorithm:
|
|
79922
|
+
*
|
|
79923
|
+
* 1. Lattice search for the closest free voxel `C` (per `isFreeAt`) that has
|
|
79924
|
+
* geometry somewhere below — i.e. a downward ray from `C` hits.
|
|
79925
|
+
* 2. At `(C.x, C.z)`, fan rays up and down from `C.y` through every cell
|
|
79926
|
+
* (step = `collision.voxelResolution`) within the xz footprint disc.
|
|
79927
|
+
* Compute, across columns:
|
|
79928
|
+
* - `floor = max(yDown_i)` (highest ground in the footprint)
|
|
79929
|
+
* - `ceiling = min(yUp_i)` (lowest obstruction overhead, or ∞)
|
|
79930
|
+
* Every column must have a `yDown` hit; otherwise the cylinder is partly
|
|
79931
|
+
* unsupported and the candidate is discarded.
|
|
79932
|
+
* 3. The cylinder fits iff `floor + halfHeight ≤ ceiling - halfHeight`,
|
|
79933
|
+
* i.e. enough vertical clearance for the full cylinder above the floor.
|
|
79934
|
+
* The "resting on ground" placement has centre at `floor + halfHeight`.
|
|
79935
|
+
*
|
|
79936
|
+
* Cylinder math (flat ends, no hemispheres) intentionally matches the carve,
|
|
79937
|
+
* which used a separable XYZ dilation.
|
|
79938
|
+
*
|
|
79939
|
+
* @param collision - Active collision implementation.
|
|
79940
|
+
* @param ox - Origin X (world space).
|
|
79941
|
+
* @param oy - Origin Y (world space).
|
|
79942
|
+
* @param oz - Origin Z (world space).
|
|
79943
|
+
* @param halfHeight - Cylinder half-height (full height = 2 × halfHeight).
|
|
79944
|
+
* @param radius - Cylinder radius.
|
|
79945
|
+
* @param out - Receives the floor position the cylinder rests on.
|
|
79946
|
+
* @returns True if a valid placement was found.
|
|
79947
|
+
*/
|
|
79948
|
+
const findCylinderSpawn = (collision, ox, oy, oz, halfHeight, radius, out) => {
|
|
79949
|
+
const step = collision.voxelResolution;
|
|
79950
|
+
const maxCells = Math.ceil(SEARCH_RADIUS / step);
|
|
79951
|
+
// Round up so float division (e.g. 0.2 / 0.05) can't accidentally drop
|
|
79952
|
+
// the outer ring of footprint cells; the Euclidean check below trims any
|
|
79953
|
+
// overshoot back to the true radius.
|
|
79954
|
+
const footCells = Math.ceil(radius / step);
|
|
79955
|
+
const radiusSq = radius * radius;
|
|
79956
|
+
let bestDistSq = Infinity;
|
|
79957
|
+
let found = false;
|
|
79958
|
+
for (let r = 0; r <= maxCells; r++) {
|
|
79959
|
+
const shellMinDistSq = (r * step) * (r * step);
|
|
79960
|
+
if (shellMinDistSq >= bestDistSq)
|
|
79961
|
+
break;
|
|
79962
|
+
for (let dy = -r; dy <= r; dy++) {
|
|
79963
|
+
const absDy = dy < 0 ? -dy : dy;
|
|
79964
|
+
for (let dz = -r; dz <= r; dz++) {
|
|
79965
|
+
const absDz = dz < 0 ? -dz : dz;
|
|
79966
|
+
for (let dx = -r; dx <= r; dx++) {
|
|
79967
|
+
const absDx = dx < 0 ? -dx : dx;
|
|
79968
|
+
if (absDx < r && absDy < r && absDz < r)
|
|
79969
|
+
continue;
|
|
79970
|
+
const distSq = (dx * dx + dy * dy + dz * dz) * step * step;
|
|
79971
|
+
if (distSq >= bestDistSq || distSq > SEARCH_RADIUS_SQ)
|
|
79972
|
+
continue;
|
|
79973
|
+
const cx = ox + dx * step;
|
|
79974
|
+
const cy = oy + dy * step;
|
|
79975
|
+
const cz = oz + dz * step;
|
|
79976
|
+
// Stage 1: cheap filter — only consider free voxels.
|
|
79977
|
+
// The footprint loop below will reject candidates whose
|
|
79978
|
+
// center column has no ground support, so no separate
|
|
79979
|
+
// down-ray probe is needed here.
|
|
79980
|
+
if (!collision.isFreeAt(cx, cy, cz))
|
|
79981
|
+
continue;
|
|
79982
|
+
// Stage 2/3: fan rays through the xz footprint.
|
|
79983
|
+
let floor = -Infinity;
|
|
79984
|
+
let ceiling = Infinity;
|
|
79985
|
+
let supported = true;
|
|
79986
|
+
for (let i = -footCells; i <= footCells && supported; i++) {
|
|
79987
|
+
const fxOff = i * step;
|
|
79988
|
+
const fxOffSq = fxOff * fxOff;
|
|
79989
|
+
for (let j = -footCells; j <= footCells; j++) {
|
|
79990
|
+
const fzOff = j * step;
|
|
79991
|
+
if (fxOffSq + fzOff * fzOff > radiusSq)
|
|
79992
|
+
continue;
|
|
79993
|
+
const fx = cx + fxOff;
|
|
79994
|
+
const fz = cz + fzOff;
|
|
79995
|
+
const down = collision.queryRay(fx, cy, fz, 0, -1, 0, RAY_MAX_DIST);
|
|
79996
|
+
if (!down) {
|
|
79997
|
+
supported = false;
|
|
79998
|
+
break;
|
|
79999
|
+
}
|
|
80000
|
+
if (down.y > floor)
|
|
80001
|
+
floor = down.y;
|
|
80002
|
+
const up = collision.queryRay(fx, cy, fz, 0, 1, 0, RAY_MAX_DIST);
|
|
80003
|
+
if (up && up.y < ceiling)
|
|
80004
|
+
ceiling = up.y;
|
|
80005
|
+
}
|
|
80006
|
+
}
|
|
80007
|
+
if (!supported)
|
|
80008
|
+
continue;
|
|
80009
|
+
// Cylinder vertical extent = 2 × halfHeight. Need that
|
|
80010
|
+
// much room between floor and ceiling.
|
|
80011
|
+
if (floor + 2 * halfHeight > ceiling)
|
|
80012
|
+
continue;
|
|
80013
|
+
bestDistSq = distSq;
|
|
80014
|
+
out.x = cx;
|
|
80015
|
+
out.y = floor;
|
|
80016
|
+
out.z = cz;
|
|
80017
|
+
found = true;
|
|
80018
|
+
}
|
|
80019
|
+
}
|
|
80020
|
+
}
|
|
80021
|
+
}
|
|
80022
|
+
return found;
|
|
80023
|
+
};
|
|
80024
|
+
|
|
79711
80025
|
/** Radius of the camera collision sphere (meters) */
|
|
79712
80026
|
const CAMERA_RADIUS = 0.2;
|
|
79713
80027
|
const forward$2 = new Vec3();
|
|
79714
80028
|
const right$2 = new Vec3();
|
|
79715
80029
|
const up$1 = new Vec3();
|
|
79716
80030
|
const offset$1 = new Vec3();
|
|
80031
|
+
const spawnProbe$1 = new Vec3();
|
|
79717
80032
|
class FlyController {
|
|
79718
80033
|
fov = 90;
|
|
80034
|
+
rotateDamping = DEFAULT_CONTROLLER_DAMPING;
|
|
79719
80035
|
_position = new Vec3();
|
|
79720
80036
|
_angles = new Vec3();
|
|
80037
|
+
_targetAngles = new Vec3();
|
|
79721
80038
|
_distance = 1;
|
|
79722
|
-
|
|
79723
|
-
_spawnAngles = new Vec3();
|
|
79724
|
-
_spawnDistance = 1;
|
|
80039
|
+
_spawn = new SpawnState();
|
|
79725
80040
|
_mover = new SphereMover(CAMERA_RADIUS);
|
|
79726
80041
|
/** Optional collision for sphere collision with sliding */
|
|
79727
80042
|
set collision(value) {
|
|
@@ -79731,15 +80046,19 @@ class FlyController {
|
|
|
79731
80046
|
get collision() {
|
|
79732
80047
|
return this._mover.collision;
|
|
79733
80048
|
}
|
|
79734
|
-
_hasSpawn = false;
|
|
79735
80049
|
onEnter(camera) {
|
|
79736
80050
|
this.goto(camera);
|
|
79737
|
-
|
|
80051
|
+
if (this.collision &&
|
|
80052
|
+
findSphereSpawn(this.collision, this._position.x, this._position.y, this._position.z, CAMERA_RADIUS, spawnProbe$1)) {
|
|
80053
|
+
this._position.copy(spawnProbe$1);
|
|
80054
|
+
this._mover.reset(this._position);
|
|
80055
|
+
}
|
|
79738
80056
|
this._storeSpawn();
|
|
79739
80057
|
}
|
|
79740
80058
|
update(deltaTime, inputFrame, camera) {
|
|
79741
80059
|
const { move, rotate } = inputFrame.read();
|
|
79742
|
-
applyFrameRotation(this.
|
|
80060
|
+
applyFrameRotation(this._targetAngles, rotate);
|
|
80061
|
+
dampAngles(this._angles, this._targetAngles, this.rotateDamping, deltaTime);
|
|
79743
80062
|
this._step(move);
|
|
79744
80063
|
camera.position.copy(this._position);
|
|
79745
80064
|
camera.angles.set(this._angles.x, this._angles.y, 0);
|
|
@@ -79751,16 +80070,16 @@ class FlyController {
|
|
|
79751
80070
|
goto(camera) {
|
|
79752
80071
|
this._position.copy(camera.position);
|
|
79753
80072
|
this._angles.set(camera.angles.x, camera.angles.y, 0);
|
|
80073
|
+
this._targetAngles.copy(this._angles);
|
|
79754
80074
|
this._distance = camera.distance;
|
|
79755
80075
|
this._mover.reset(this._position);
|
|
79756
80076
|
}
|
|
79757
80077
|
resetToSpawn(camera) {
|
|
79758
|
-
if (!this.
|
|
80078
|
+
if (!this._spawn.has) {
|
|
79759
80079
|
return false;
|
|
79760
80080
|
}
|
|
79761
|
-
this.
|
|
79762
|
-
this.
|
|
79763
|
-
this._distance = this._spawnDistance;
|
|
80081
|
+
this._distance = this._spawn.restore(this._position, this._angles);
|
|
80082
|
+
this._targetAngles.copy(this._angles);
|
|
79764
80083
|
this._mover.reset(this._position);
|
|
79765
80084
|
camera.position.copy(this._position);
|
|
79766
80085
|
camera.angles.copy(this._angles);
|
|
@@ -79769,10 +80088,7 @@ class FlyController {
|
|
|
79769
80088
|
return true;
|
|
79770
80089
|
}
|
|
79771
80090
|
_storeSpawn() {
|
|
79772
|
-
this.
|
|
79773
|
-
this._spawnAngles.copy(this._angles);
|
|
79774
|
-
this._spawnDistance = this._distance;
|
|
79775
|
-
this._hasSpawn = true;
|
|
80091
|
+
this._spawn.store(this._position, this._angles, this._distance);
|
|
79776
80092
|
}
|
|
79777
80093
|
_step(move) {
|
|
79778
80094
|
setCameraBasis(this._angles, forward$2, right$2, up$1);
|
|
@@ -80012,9 +80328,9 @@ class OrbitController {
|
|
|
80012
80328
|
this.controller = new OrbitController$1();
|
|
80013
80329
|
this.controller.zoomRange = new Vec2(0.01, Infinity);
|
|
80014
80330
|
this.controller.pitchRange = new Vec2(-90, 90);
|
|
80015
|
-
this.controller.rotateDamping =
|
|
80016
|
-
this.controller.moveDamping =
|
|
80017
|
-
this.controller.zoomDamping =
|
|
80331
|
+
this.controller.rotateDamping = DEFAULT_CONTROLLER_DAMPING;
|
|
80332
|
+
this.controller.moveDamping = DEFAULT_CONTROLLER_DAMPING;
|
|
80333
|
+
this.controller.zoomDamping = DEFAULT_CONTROLLER_DAMPING;
|
|
80018
80334
|
}
|
|
80019
80335
|
onEnter(camera) {
|
|
80020
80336
|
this._attach(camera);
|
|
@@ -80040,103 +80356,6 @@ class OrbitController {
|
|
|
80040
80356
|
}
|
|
80041
80357
|
}
|
|
80042
80358
|
|
|
80043
|
-
const SPAWN_HIT_EPSILON = 1e-3;
|
|
80044
|
-
const SPAWN_SEARCH_MIN_STEP = 0.05;
|
|
80045
|
-
const SPAWN_SEARCH_MAX_STEPS = 128;
|
|
80046
|
-
const out$1 = { x: 0, y: 0, z: 0 };
|
|
80047
|
-
const v$1 = new Vec3();
|
|
80048
|
-
const probe = new Vec3();
|
|
80049
|
-
const queryCapsule = (collision, pos, p) => {
|
|
80050
|
-
const half = p.capsuleHeight * 0.5 - p.capsuleRadius;
|
|
80051
|
-
const center = pos.y - p.eyeHeight + p.capsuleHeight * 0.5;
|
|
80052
|
-
return collision.queryCapsule(pos.x, center, pos.z, half, p.capsuleRadius, out$1);
|
|
80053
|
-
};
|
|
80054
|
-
const eyeYFromGround = (groundY, p) => groundY + p.hoverHeight + p.eyeHeight;
|
|
80055
|
-
const isInsideSolid = (collision, pos) => {
|
|
80056
|
-
return collision.querySphere(pos.x, pos.y, pos.z, SPAWN_HIT_EPSILON, out$1);
|
|
80057
|
-
};
|
|
80058
|
-
const probeGroundY = (collision, pos, p) => {
|
|
80059
|
-
const hit = collision.queryRay(pos.x, pos.y, pos.z, 0, -1, 0, p.spawnSearchRange);
|
|
80060
|
-
return hit ? hit.y : null;
|
|
80061
|
-
};
|
|
80062
|
-
const hasSpawnGroundSupport = (collision, pos, p) => {
|
|
80063
|
-
const groundY = probeGroundY(collision, pos, p);
|
|
80064
|
-
if (groundY === null) {
|
|
80065
|
-
return false;
|
|
80066
|
-
}
|
|
80067
|
-
const clearance = pos.y - p.eyeHeight - groundY;
|
|
80068
|
-
return clearance >= -SPAWN_HIT_EPSILON &&
|
|
80069
|
-
clearance <= p.hoverHeight + p.capsuleRadius + SPAWN_HIT_EPSILON;
|
|
80070
|
-
};
|
|
80071
|
-
// Push a candidate eye position out of solid geometry. Returns true if the
|
|
80072
|
-
// candidate becomes clear within the allowed budget and remains supported by
|
|
80073
|
-
// ground beneath it.
|
|
80074
|
-
const resolveSpawnCandidate = (collision, pos, p) => {
|
|
80075
|
-
const startX = pos.x;
|
|
80076
|
-
const startY = pos.y;
|
|
80077
|
-
const startZ = pos.z;
|
|
80078
|
-
const maxResolveDistance = p.capsuleRadius + p.hoverHeight;
|
|
80079
|
-
const maxResolveDistanceSq = maxResolveDistance * maxResolveDistance;
|
|
80080
|
-
for (let i = 0; i < 100; i++) {
|
|
80081
|
-
if (!queryCapsule(collision, pos, p)) {
|
|
80082
|
-
return hasSpawnGroundSupport(collision, pos, p);
|
|
80083
|
-
}
|
|
80084
|
-
pos.add(v$1.set(out$1.x, out$1.y, out$1.z));
|
|
80085
|
-
const dx = pos.x - startX;
|
|
80086
|
-
const dy = pos.y - startY;
|
|
80087
|
-
const dz = pos.z - startZ;
|
|
80088
|
-
if (dx * dx + dy * dy + dz * dz > maxResolveDistanceSq) {
|
|
80089
|
-
return false;
|
|
80090
|
-
}
|
|
80091
|
-
}
|
|
80092
|
-
return false;
|
|
80093
|
-
};
|
|
80094
|
-
// Find the first collision surface below a point that can hold a clear walk
|
|
80095
|
-
// capsule. Writes the resolved eye position to outPos on success.
|
|
80096
|
-
const findClearSpawnGroundBelow = (collision, pos, range, allowInitialHit, p, outPos) => {
|
|
80097
|
-
const hit = collision.queryRay(pos.x, pos.y, pos.z, 0, -1, 0, range);
|
|
80098
|
-
if (!hit) {
|
|
80099
|
-
return false;
|
|
80100
|
-
}
|
|
80101
|
-
if (!allowInitialHit && Math.abs(pos.y - hit.y) <= SPAWN_HIT_EPSILON) {
|
|
80102
|
-
return false;
|
|
80103
|
-
}
|
|
80104
|
-
outPos.set(pos.x, eyeYFromGround(hit.y, p), pos.z);
|
|
80105
|
-
const clear = !queryCapsule(collision, outPos, p);
|
|
80106
|
-
return clear || resolveSpawnCandidate(collision, outPos, p);
|
|
80107
|
-
};
|
|
80108
|
-
const searchSpawnGround = (collision, pos, direction, p, outPos) => {
|
|
80109
|
-
const step = Math.max(p.capsuleRadius, p.hoverHeight, SPAWN_SEARCH_MIN_STEP, p.spawnSearchRange / SPAWN_SEARCH_MAX_STEPS);
|
|
80110
|
-
const endY = pos.y + direction * p.spawnSearchRange;
|
|
80111
|
-
for (let y = pos.y + direction * step; direction < 0 ? y >= endY : y <= endY; y += direction * step) {
|
|
80112
|
-
probe.set(pos.x, y, pos.z);
|
|
80113
|
-
if (findClearSpawnGroundBelow(collision, probe, p.spawnSearchRange, false, p, outPos)) {
|
|
80114
|
-
return true;
|
|
80115
|
-
}
|
|
80116
|
-
}
|
|
80117
|
-
return false;
|
|
80118
|
-
};
|
|
80119
|
-
/**
|
|
80120
|
-
* Find an eye position for spawning into walk mode. Prefer ground directly
|
|
80121
|
-
* below the camera; if that is not usable, search down and then up for the
|
|
80122
|
-
* first clear walk placement with ground below it. On success, the resolved
|
|
80123
|
-
* eye position is written to outPos.
|
|
80124
|
-
*
|
|
80125
|
-
* @param collision - The active collision implementation.
|
|
80126
|
-
* @param pos - Incoming camera position.
|
|
80127
|
-
* @param p - Walk capsule and spawn-search parameters.
|
|
80128
|
-
* @param outPos - Receives the resolved eye position.
|
|
80129
|
-
* @returns True if a spawn position was found.
|
|
80130
|
-
*/
|
|
80131
|
-
const findWalkSpawn = (collision, pos, p, outPos) => {
|
|
80132
|
-
const insideSolid = isInsideSolid(collision, pos);
|
|
80133
|
-
if (findClearSpawnGroundBelow(collision, pos, p.spawnSearchRange, !insideSolid, p, outPos)) {
|
|
80134
|
-
return true;
|
|
80135
|
-
}
|
|
80136
|
-
return searchSpawnGround(collision, pos, -1, p, outPos) ||
|
|
80137
|
-
searchSpawnGround(collision, pos, 1, p, outPos);
|
|
80138
|
-
};
|
|
80139
|
-
|
|
80140
80359
|
const FIXED_DT = 1 / 60;
|
|
80141
80360
|
const MAX_SUBSTEPS = 10;
|
|
80142
80361
|
/** Pre-allocated push-out vector for capsule collision */
|
|
@@ -80193,14 +80412,10 @@ class WalkController {
|
|
|
80193
80412
|
* Movement speed in m/s when in the air (for air control)
|
|
80194
80413
|
*/
|
|
80195
80414
|
moveAirSpeed = 1;
|
|
80196
|
-
/**
|
|
80197
|
-
* Movement damping factor (0 = no damping, 1 = full damping)
|
|
80198
|
-
*/
|
|
80199
|
-
moveDamping = 0.97;
|
|
80200
80415
|
/**
|
|
80201
80416
|
* Rotation damping factor (0 = no damping, 1 = full damping)
|
|
80202
80417
|
*/
|
|
80203
|
-
rotateDamping =
|
|
80418
|
+
rotateDamping = DEFAULT_CONTROLLER_DAMPING;
|
|
80204
80419
|
/**
|
|
80205
80420
|
* Velocity damping factor when grounded (0 = no damping, 1 = full damping)
|
|
80206
80421
|
*/
|
|
@@ -80227,31 +80442,36 @@ class WalkController {
|
|
|
80227
80442
|
* Maximum downward raycast distance to search for ground below the capsule.
|
|
80228
80443
|
*/
|
|
80229
80444
|
groundProbeRange = 1.0;
|
|
80230
|
-
/**
|
|
80231
|
-
* Maximum vertical raycast distance to search for walk spawn ground.
|
|
80232
|
-
*/
|
|
80233
|
-
spawnSearchRange = 1000;
|
|
80234
80445
|
_position = new Vec3();
|
|
80235
80446
|
_prevPosition = new Vec3();
|
|
80236
80447
|
_angles = new Vec3();
|
|
80448
|
+
_targetAngles = new Vec3();
|
|
80237
80449
|
_distance = 1;
|
|
80238
|
-
|
|
80239
|
-
|
|
80240
|
-
_spawnDistance = 1;
|
|
80450
|
+
_spawn = new SpawnState();
|
|
80451
|
+
_spawnGrounded = false;
|
|
80241
80452
|
_velocity = new Vec3();
|
|
80242
80453
|
_pendingMove = [0, 0, 0];
|
|
80243
80454
|
_accumulator = 0;
|
|
80244
80455
|
_grounded = false;
|
|
80245
80456
|
_jumping = false;
|
|
80246
80457
|
_jumpHeld = false;
|
|
80247
|
-
_spawnGrounded = false;
|
|
80248
|
-
_hasSpawn = false;
|
|
80249
80458
|
onEnter(camera) {
|
|
80250
80459
|
this.goto(camera);
|
|
80251
80460
|
if (this.collision) {
|
|
80252
|
-
this
|
|
80253
|
-
|
|
80254
|
-
|
|
80461
|
+
// Spawn is scoped to this walk-mode entry; reset so a stale spawn
|
|
80462
|
+
// from a previous entry can't be restored if this entry fails.
|
|
80463
|
+
this._spawn.clear();
|
|
80464
|
+
// Treat the walk capsule as a tight-superset cylinder for spawn.
|
|
80465
|
+
// The carve was produced with a separable XYZ dilation (flat ends,
|
|
80466
|
+
// no hemispheres), so cylinder math matches the data exactly.
|
|
80467
|
+
// Include `hoverHeight` in the height so the ceiling-clearance
|
|
80468
|
+
// check accounts for the placed capsule's full vertical envelope:
|
|
80469
|
+
// foot sits at `floor + hoverHeight`, head at `floor + hoverHeight
|
|
80470
|
+
// + capsuleHeight`.
|
|
80471
|
+
if (findCylinderSpawn(this.collision, camera.position.x, camera.position.y, camera.position.z, (this.capsuleHeight + this.hoverHeight) * 0.5, this.capsuleRadius, spawnProbe)) {
|
|
80472
|
+
// spawnProbe is the floor world position the cylinder rests
|
|
80473
|
+
// on. Eye sits hoverHeight + eyeHeight above the floor.
|
|
80474
|
+
this._position.set(spawnProbe.x, spawnProbe.y + this.hoverHeight + this.eyeHeight, spawnProbe.z);
|
|
80255
80475
|
this._grounded = true;
|
|
80256
80476
|
this._velocity.y = 0;
|
|
80257
80477
|
this._storeSpawn();
|
|
@@ -80262,7 +80482,8 @@ class WalkController {
|
|
|
80262
80482
|
update(deltaTime, inputFrame, camera) {
|
|
80263
80483
|
const { move, rotate } = inputFrame.read();
|
|
80264
80484
|
// apply rotation at display rate for responsive mouse look
|
|
80265
|
-
applyFrameRotation(this.
|
|
80485
|
+
applyFrameRotation(this._targetAngles, rotate);
|
|
80486
|
+
dampAngles(this._angles, this._targetAngles, this.rotateDamping, deltaTime);
|
|
80266
80487
|
// accumulate movement input so frames without a physics step don't lose input
|
|
80267
80488
|
this._pendingMove[0] += move[0];
|
|
80268
80489
|
this._pendingMove[1] = this._pendingMove[1] || move[1];
|
|
@@ -80354,6 +80575,7 @@ class WalkController {
|
|
|
80354
80575
|
this._prevPosition.copy(this._position);
|
|
80355
80576
|
// angles (clamp pitch to avoid gimbal lock)
|
|
80356
80577
|
this._angles.set(camera.angles.x, camera.angles.y, 0);
|
|
80578
|
+
this._targetAngles.copy(this._angles);
|
|
80357
80579
|
this._distance = camera.distance;
|
|
80358
80580
|
// reset velocity and state
|
|
80359
80581
|
this._resetMotion();
|
|
@@ -80365,13 +80587,12 @@ class WalkController {
|
|
|
80365
80587
|
* @returns True if a spawn pose was available.
|
|
80366
80588
|
*/
|
|
80367
80589
|
resetToSpawn(camera) {
|
|
80368
|
-
if (!this.
|
|
80590
|
+
if (!this._spawn.has) {
|
|
80369
80591
|
return false;
|
|
80370
80592
|
}
|
|
80371
|
-
this.
|
|
80593
|
+
this._distance = this._spawn.restore(this._position, this._angles);
|
|
80372
80594
|
this._prevPosition.copy(this._position);
|
|
80373
|
-
this.
|
|
80374
|
-
this._distance = this._spawnDistance;
|
|
80595
|
+
this._targetAngles.copy(this._angles);
|
|
80375
80596
|
this._resetMotion();
|
|
80376
80597
|
this._grounded = this._spawnGrounded;
|
|
80377
80598
|
camera.position.copy(this._position);
|
|
@@ -80381,11 +80602,8 @@ class WalkController {
|
|
|
80381
80602
|
return true;
|
|
80382
80603
|
}
|
|
80383
80604
|
_storeSpawn() {
|
|
80384
|
-
this.
|
|
80385
|
-
this._spawnAngles.copy(this._angles);
|
|
80386
|
-
this._spawnDistance = this._distance;
|
|
80605
|
+
this._spawn.store(this._position, this._angles, this._distance);
|
|
80387
80606
|
this._spawnGrounded = this._grounded;
|
|
80388
|
-
this._hasSpawn = true;
|
|
80389
80607
|
}
|
|
80390
80608
|
_resetMotion() {
|
|
80391
80609
|
this._velocity.set(0, 0, 0);
|