@playcanvas/supersplat-viewer 1.32.0 → 1.33.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 +2 -2
- package/dist/viewer.js +368 -99
- package/dist/viewer.js.map +1 -1
- package/package.json +1 -1
- package/public/index.html +8 -1
- package/public/index.js +368 -99
- package/public/index.js.map +1 -1
package/public/index.js
CHANGED
|
@@ -83898,7 +83898,7 @@ const importSettings = (settings) => {
|
|
|
83898
83898
|
return result;
|
|
83899
83899
|
};
|
|
83900
83900
|
|
|
83901
|
-
var version = "1.
|
|
83901
|
+
var version = "1.33.0";
|
|
83902
83902
|
|
|
83903
83903
|
class Tooltip {
|
|
83904
83904
|
register;
|
|
@@ -86192,9 +86192,30 @@ class SphereMover {
|
|
|
86192
86192
|
}
|
|
86193
86193
|
}
|
|
86194
86194
|
|
|
86195
|
-
/**
|
|
86195
|
+
/**
|
|
86196
|
+
* Maximum Euclidean distance (metres) from the spawn origin to search for a valid placement.
|
|
86197
|
+
* Used by the cylinder search, which has to reach far enough to find a standable floor. The
|
|
86198
|
+
* sphere search sizes itself from its own radius instead — see `SPHERE_SEARCH_REACH_RADII`.
|
|
86199
|
+
*/
|
|
86196
86200
|
const SEARCH_RADIUS = 5;
|
|
86197
86201
|
const SEARCH_RADIUS_SQ = SEARCH_RADIUS * SEARCH_RADIUS;
|
|
86202
|
+
/**
|
|
86203
|
+
* Reach of the sphere search, in multiples of the sphere's radius.
|
|
86204
|
+
*
|
|
86205
|
+
* Its job is to un-clip a sphere that is intersecting a surface, not to relocate one that is deep
|
|
86206
|
+
* inside geometry — `FlyController` holds collision until the camera is clear rather than relying
|
|
86207
|
+
* on a rescue — so reaching a few radii is enough. Bounding the reach is what makes the search
|
|
86208
|
+
* cheap: at radius 0.2 on a 0.05 m grid the worst case, finding nothing, is 7,153 probes, where
|
|
86209
|
+
* reaching `SEARCH_RADIUS` cost 8,120,601. A sphere deep inside geometry never finds a free cell
|
|
86210
|
+
* to tighten `bestDistSq`, so nothing breaks the search early and it pays for every shell.
|
|
86211
|
+
*
|
|
86212
|
+
* The lattice still steps by `collision.voxelResolution`, deliberately. A coarser step is not
|
|
86213
|
+
* safe: the valid positions for a collider's centre are free space eroded by its radius, which
|
|
86214
|
+
* can be far narrower than the free space itself. A 0.45 m passage admits a 0.2 m sphere across
|
|
86215
|
+
* only a 0.05 m band of centres, so a 0.1 m lattice steps straight over it and reports no
|
|
86216
|
+
* placement at all.
|
|
86217
|
+
*/
|
|
86218
|
+
const SPHERE_SEARCH_REACH_RADII = 3;
|
|
86198
86219
|
/** Ray budget when probing for ground/ceiling under or above a candidate column. */
|
|
86199
86220
|
const RAY_MAX_DIST = 1000;
|
|
86200
86221
|
// Scratch values reused across calls — these helpers run only at spawn time
|
|
@@ -86207,7 +86228,8 @@ const scratchPush = { x: 0, y: 0, z: 0 };
|
|
|
86207
86228
|
*
|
|
86208
86229
|
* Lattice search across voxel-spaced offsets from the origin (step =
|
|
86209
86230
|
* `collision.voxelResolution`), ordered by Chebyshev shell with Euclidean
|
|
86210
|
-
* tie-break within a shell.
|
|
86231
|
+
* tie-break within a shell. Reach is derived from `radius` — see
|
|
86232
|
+
* `SPHERE_SEARCH_REACH_RADII`.
|
|
86211
86233
|
*
|
|
86212
86234
|
* @param collision - Active collision implementation.
|
|
86213
86235
|
* @param ox - Origin X (world space).
|
|
@@ -86219,7 +86241,9 @@ const scratchPush = { x: 0, y: 0, z: 0 };
|
|
|
86219
86241
|
*/
|
|
86220
86242
|
const findSphereSpawn = (collision, ox, oy, oz, radius, out) => {
|
|
86221
86243
|
const step = collision.voxelResolution;
|
|
86222
|
-
const
|
|
86244
|
+
const reach = radius * SPHERE_SEARCH_REACH_RADII;
|
|
86245
|
+
const reachSq = reach * reach;
|
|
86246
|
+
const maxCells = Math.ceil(reach / step);
|
|
86223
86247
|
let bestDistSq = Infinity;
|
|
86224
86248
|
let found = false;
|
|
86225
86249
|
for (let r = 0; r <= maxCells; r++) {
|
|
@@ -86230,13 +86254,16 @@ const findSphereSpawn = (collision, ox, oy, oz, radius, out) => {
|
|
|
86230
86254
|
const absDy = dy < 0 ? -dy : dy;
|
|
86231
86255
|
for (let dz = -r; dz <= r; dz++) {
|
|
86232
86256
|
const absDz = dz < 0 ? -dz : dz;
|
|
86233
|
-
|
|
86234
|
-
|
|
86235
|
-
|
|
86236
|
-
|
|
86237
|
-
|
|
86257
|
+
// Enumerate the Chebyshev shell of radius r directly instead of scanning the
|
|
86258
|
+
// whole cube and skipping its interior. A row is fully on the shell when dy or dz
|
|
86259
|
+
// is already at the extreme; otherwise only its two end cells are, so dx jumps
|
|
86260
|
+
// straight across the interior. `full` is always true at r = 0, so the stride is
|
|
86261
|
+
// never zero.
|
|
86262
|
+
const full = absDy === r || absDz === r;
|
|
86263
|
+
const dxStep = full ? 1 : 2 * r;
|
|
86264
|
+
for (let dx = -r; dx <= r; dx += dxStep) {
|
|
86238
86265
|
const distSq = (dx * dx + dy * dy + dz * dz) * step * step;
|
|
86239
|
-
if (distSq >= bestDistSq || distSq >
|
|
86266
|
+
if (distSq >= bestDistSq || distSq > reachSq)
|
|
86240
86267
|
continue;
|
|
86241
86268
|
const cx = ox + dx * step;
|
|
86242
86269
|
const cy = oy + dy * step;
|
|
@@ -86304,10 +86331,11 @@ const findCylinderSpawn = (collision, ox, oy, oz, halfHeight, radius, out) => {
|
|
|
86304
86331
|
const absDy = dy < 0 ? -dy : dy;
|
|
86305
86332
|
for (let dz = -r; dz <= r; dz++) {
|
|
86306
86333
|
const absDz = dz < 0 ? -dz : dz;
|
|
86307
|
-
|
|
86308
|
-
|
|
86309
|
-
|
|
86310
|
-
|
|
86334
|
+
// Enumerate the Chebyshev shell of radius r directly rather than scanning the
|
|
86335
|
+
// whole cube and skipping its interior — see `findSphereSpawn`.
|
|
86336
|
+
const full = absDy === r || absDz === r;
|
|
86337
|
+
const dxStep = full ? 1 : 2 * r;
|
|
86338
|
+
for (let dx = -r; dx <= r; dx += dxStep) {
|
|
86311
86339
|
const distSq = (dx * dx + dy * dy + dz * dz) * step * step;
|
|
86312
86340
|
if (distSq >= bestDistSq || distSq > SEARCH_RADIUS_SQ)
|
|
86313
86341
|
continue;
|
|
@@ -86370,6 +86398,9 @@ const right$2 = new Vec3();
|
|
|
86370
86398
|
const up$1 = new Vec3();
|
|
86371
86399
|
const offset$1 = new Vec3();
|
|
86372
86400
|
const spawnProbe$1 = new Vec3();
|
|
86401
|
+
const clearProbe = { x: 0, y: 0, z: 0 };
|
|
86402
|
+
// Whether the camera sphere fits at `position` without intersecting collision geometry.
|
|
86403
|
+
const isClear = (collision, position) => !collision.querySphere(position.x, position.y, position.z, CAMERA_RADIUS, clearProbe);
|
|
86373
86404
|
class FlyController {
|
|
86374
86405
|
fov = 90;
|
|
86375
86406
|
rotateDamping = DEFAULT_CONTROLLER_DAMPING;
|
|
@@ -86379,24 +86410,73 @@ class FlyController {
|
|
|
86379
86410
|
_distance = 1;
|
|
86380
86411
|
_spawn = new SpawnState();
|
|
86381
86412
|
_mover = new SphereMover(CAMERA_RADIUS);
|
|
86413
|
+
// Collision that arrived while the camera was inside geometry, held until it is somewhere
|
|
86414
|
+
// valid. See the `collision` setter.
|
|
86415
|
+
_pendingCollision = null;
|
|
86416
|
+
// False until `goto` seeds `_position` from a real camera. Collision is normally attached
|
|
86417
|
+
// before this controller has ever been entered, and testing clearance against an unseeded
|
|
86418
|
+
// position would hold the attachment for no reason and skip the spawn search in `onEnter`.
|
|
86419
|
+
_hasPosition = false;
|
|
86382
86420
|
/** Optional collision for sphere collision with sliding */
|
|
86383
86421
|
set collision(value) {
|
|
86422
|
+
// The viewer reveals the scene before the collision data has downloaded, so fly mode has
|
|
86423
|
+
// no collision response until it lands and the camera may already be inside geometry by
|
|
86424
|
+
// then. The mover cannot escape a solid region: push-out has nothing to push against and
|
|
86425
|
+
// `_clipMove` cancels the movement every frame, so the camera sticks. Hold the
|
|
86426
|
+
// attachment until the camera is somewhere valid and let `update` engage it, which keeps
|
|
86427
|
+
// the flight the user is already making instead of teleporting them out. `onEnter` falls
|
|
86428
|
+
// back to the same hold when its spawn search cannot place the camera.
|
|
86429
|
+
if (value && this._hasPosition && !isClear(value, this._position)) {
|
|
86430
|
+
this._pendingCollision = value;
|
|
86431
|
+
// Detaching the mover is part of holding, not an optimisation. Left engaged it keeps
|
|
86432
|
+
// running push-out against geometry it cannot escape; and without the reset,
|
|
86433
|
+
// `SphereMover`'s last-clear position still points wherever the camera was before,
|
|
86434
|
+
// so `resolve` teleports it back there on the next idle step.
|
|
86435
|
+
this._mover.collision = null;
|
|
86436
|
+
this._mover.reset(this._position);
|
|
86437
|
+
return;
|
|
86438
|
+
}
|
|
86439
|
+
this._pendingCollision = null;
|
|
86384
86440
|
this._mover.collision = value;
|
|
86385
86441
|
this._mover.reset(this._position);
|
|
86386
86442
|
}
|
|
86387
86443
|
get collision() {
|
|
86388
86444
|
return this._mover.collision;
|
|
86389
86445
|
}
|
|
86446
|
+
/**
|
|
86447
|
+
* Re-run the engage-or-hold decision at the camera's current position, whether collision is
|
|
86448
|
+
* currently engaged or held. The invariant behind the setter: collision is never active while
|
|
86449
|
+
* the camera is inside a collider, because the mover cannot escape one.
|
|
86450
|
+
*/
|
|
86451
|
+
_reengage() {
|
|
86452
|
+
this.collision = this._mover.collision ?? this._pendingCollision;
|
|
86453
|
+
}
|
|
86390
86454
|
onEnter(camera) {
|
|
86391
86455
|
this.goto(camera);
|
|
86392
|
-
|
|
86393
|
-
|
|
86394
|
-
|
|
86395
|
-
|
|
86456
|
+
// Entry may follow a previous one that ended with collision held, so start from the
|
|
86457
|
+
// collision we have either way and drop that hold. Otherwise the block below would be
|
|
86458
|
+
// skipped on re-entry, leaving the spawn search unrun. Whether to hold again is decided
|
|
86459
|
+
// fresh, from this entry's position. Mirrors `WalkController.onEnter`.
|
|
86460
|
+
const collision = this._mover.collision ?? this._pendingCollision;
|
|
86461
|
+
this._pendingCollision = null;
|
|
86462
|
+
if (collision) {
|
|
86463
|
+
if (findSphereSpawn(collision, this._position.x, this._position.y, this._position.z, CAMERA_RADIUS, spawnProbe$1)) {
|
|
86464
|
+
this._position.copy(spawnProbe$1);
|
|
86465
|
+
}
|
|
86466
|
+
// Engage at the placed position. The search starts at the camera's own cell, so
|
|
86467
|
+
// failing it means the camera is inside geometry with no free space within reach to
|
|
86468
|
+
// nudge it to; the setter holds collision in that case and `update` engages it once
|
|
86469
|
+
// the camera is clear, as it does for a late attachment. Assigning rather than
|
|
86470
|
+
// resetting the mover inline keeps the engage-or-hold decision in one place.
|
|
86471
|
+
this.collision = collision;
|
|
86396
86472
|
}
|
|
86397
86473
|
this._storeSpawn();
|
|
86398
86474
|
}
|
|
86399
86475
|
update(deltaTime, inputFrame, camera) {
|
|
86476
|
+
// engage a held attachment as soon as the camera flies back into valid space
|
|
86477
|
+
if (this._pendingCollision && isClear(this._pendingCollision, this._position)) {
|
|
86478
|
+
this._reengage();
|
|
86479
|
+
}
|
|
86400
86480
|
const { move, rotate } = inputFrame.read();
|
|
86401
86481
|
applyFrameRotation(this._targetAngles, rotate);
|
|
86402
86482
|
dampAngles(this._angles, this._targetAngles, this.rotateDamping, deltaTime);
|
|
@@ -86410,6 +86490,7 @@ class FlyController {
|
|
|
86410
86490
|
// no cleanup needed
|
|
86411
86491
|
}
|
|
86412
86492
|
goto(camera) {
|
|
86493
|
+
this._hasPosition = true;
|
|
86413
86494
|
this._position.copy(camera.position);
|
|
86414
86495
|
this._angles.set(camera.angles.x, camera.angles.y, 0);
|
|
86415
86496
|
this._targetAngles.copy(this._angles);
|
|
@@ -86422,7 +86503,13 @@ class FlyController {
|
|
|
86422
86503
|
}
|
|
86423
86504
|
this._distance = this._spawn.restore(this._position, this._angles);
|
|
86424
86505
|
this._targetAngles.copy(this._angles);
|
|
86425
|
-
|
|
86506
|
+
// A spawn captured while collision was held is itself inside geometry — `onEnter` stores
|
|
86507
|
+
// the entry pose whether or not its search could place the camera. Restoring it with
|
|
86508
|
+
// collision engaged would put the camera straight back into the stuck state, so re-run
|
|
86509
|
+
// the decision instead of assuming the stored pose is valid. This also covers a spawn
|
|
86510
|
+
// that was valid when stored and is not now, after a collision swap. `_reengage` resets
|
|
86511
|
+
// the mover, which is why the explicit reset is gone.
|
|
86512
|
+
this._reengage();
|
|
86426
86513
|
camera.position.copy(this._position);
|
|
86427
86514
|
camera.angles.copy(this._angles);
|
|
86428
86515
|
camera.distance = this._distance;
|
|
@@ -86717,10 +86804,6 @@ const spawnProbe = new Vec3();
|
|
|
86717
86804
|
* collision handles walls and obstacles. When airborne, normal gravity applies.
|
|
86718
86805
|
*/
|
|
86719
86806
|
class WalkController {
|
|
86720
|
-
/**
|
|
86721
|
-
* Optional collision for capsule collision with sliding
|
|
86722
|
-
*/
|
|
86723
|
-
collision = null;
|
|
86724
86807
|
/**
|
|
86725
86808
|
* Field of view in degrees for walk mode.
|
|
86726
86809
|
*/
|
|
@@ -86796,12 +86879,63 @@ class WalkController {
|
|
|
86796
86879
|
_grounded = false;
|
|
86797
86880
|
_jumping = false;
|
|
86798
86881
|
_jumpHeld = false;
|
|
86882
|
+
_collision = null;
|
|
86883
|
+
/**
|
|
86884
|
+
* Collision held because the capsule is inside geometry, mirroring `FlyController`. While
|
|
86885
|
+
* held, `_heldFloorY` stands in for the ground probe so the camera walks on the level it
|
|
86886
|
+
* entered at instead of falling, and the capsule check is skipped. `_step` engages it for
|
|
86887
|
+
* real as soon as the capsule fits.
|
|
86888
|
+
*/
|
|
86889
|
+
_pendingCollision = null;
|
|
86890
|
+
/**
|
|
86891
|
+
* Synthetic ground height. Set while `_pendingCollision` is held, and while walk mode is
|
|
86892
|
+
* active with no collision at all: the viewer attaches collision after the scene is
|
|
86893
|
+
* interactive, so a host can enter walk before the data has arrived.
|
|
86894
|
+
*/
|
|
86895
|
+
_heldFloorY = null;
|
|
86896
|
+
// False until `goto` seeds `_position` from a real camera, so an attach before this
|
|
86897
|
+
// controller has ever been entered engages directly instead of testing clearance against an
|
|
86898
|
+
// unseeded position.
|
|
86899
|
+
_hasPosition = false;
|
|
86900
|
+
/**
|
|
86901
|
+
* Optional collision for capsule collision with sliding. Assigning while the capsule is
|
|
86902
|
+
* inside geometry holds the attachment instead: engaged collision cannot escape a solid
|
|
86903
|
+
* region, so the capsule keeps the synthetic floor and `_step` engages it once it fits.
|
|
86904
|
+
* Collision normally lands this way, after walk mode may already be active.
|
|
86905
|
+
*/
|
|
86906
|
+
set collision(value) {
|
|
86907
|
+
if (value && this._hasPosition && !this._capsuleClear(value, this._position)) {
|
|
86908
|
+
this._pendingCollision = value;
|
|
86909
|
+
this._collision = null;
|
|
86910
|
+
this._heldFloorY = this._position.y - this.eyeHeight - this.hoverHeight;
|
|
86911
|
+
return;
|
|
86912
|
+
}
|
|
86913
|
+
this._pendingCollision = null;
|
|
86914
|
+
this._heldFloorY = null;
|
|
86915
|
+
this._collision = value;
|
|
86916
|
+
}
|
|
86917
|
+
get collision() {
|
|
86918
|
+
return this._collision;
|
|
86919
|
+
}
|
|
86799
86920
|
onEnter(camera) {
|
|
86800
86921
|
this.goto(camera);
|
|
86801
|
-
|
|
86802
|
-
|
|
86803
|
-
|
|
86804
|
-
|
|
86922
|
+
// Spawn is scoped to this walk-mode entry; reset so a stale spawn from a previous entry
|
|
86923
|
+
// can't be restored if this entry fails or has no collision to place against.
|
|
86924
|
+
this._spawn.clear();
|
|
86925
|
+
// Entry may follow a previous one that ended with collision held, so start from the
|
|
86926
|
+
// collision we have either way. Whether to hold again is decided fresh, from this
|
|
86927
|
+
// entry's position.
|
|
86928
|
+
const collision = this._collision ?? this._pendingCollision;
|
|
86929
|
+
// Stand on the entry level until collision can place the capsule. This covers collision
|
|
86930
|
+
// that has not arrived yet as well as a spawn search that finds nowhere to go: engaged
|
|
86931
|
+
// collision would strand the camera either way, with no floor under the ground probe and
|
|
86932
|
+
// nothing for push-out to push against. Held, the user can walk out the way they came,
|
|
86933
|
+
// and the setter or `_step` engages collision once the capsule fits.
|
|
86934
|
+
this._pendingCollision = null;
|
|
86935
|
+
this._collision = null;
|
|
86936
|
+
this._heldFloorY = this._position.y - this.eyeHeight - this.hoverHeight;
|
|
86937
|
+
this._grounded = true;
|
|
86938
|
+
if (collision) {
|
|
86805
86939
|
// Treat the walk capsule as a tight-superset cylinder for spawn.
|
|
86806
86940
|
// The carve was produced with a separable XYZ dilation (flat ends,
|
|
86807
86941
|
// no hemispheres), so cylinder math matches the data exactly.
|
|
@@ -86809,16 +86943,24 @@ class WalkController {
|
|
|
86809
86943
|
// check accounts for the placed capsule's full vertical envelope:
|
|
86810
86944
|
// foot sits at `floor + hoverHeight`, head at `floor + hoverHeight
|
|
86811
86945
|
// + capsuleHeight`.
|
|
86812
|
-
if (findCylinderSpawn(
|
|
86946
|
+
if (findCylinderSpawn(collision, camera.position.x, camera.position.y, camera.position.z, (this.capsuleHeight + this.hoverHeight) * 0.5, this.capsuleRadius, spawnProbe)) {
|
|
86813
86947
|
// spawnProbe is the floor world position the cylinder rests
|
|
86814
86948
|
// on. Eye sits hoverHeight + eyeHeight above the floor.
|
|
86815
86949
|
this._position.set(spawnProbe.x, spawnProbe.y + this.hoverHeight + this.eyeHeight, spawnProbe.z);
|
|
86816
|
-
this._grounded = true;
|
|
86817
|
-
this._velocity.y = 0;
|
|
86818
86950
|
this._storeSpawn();
|
|
86951
|
+
// The placement is known to fit, so engage directly rather than re-testing it
|
|
86952
|
+
// through the setter's capsule query, which is a different test from the
|
|
86953
|
+
// cylinder search and could hold on a hairline disagreement.
|
|
86954
|
+
this._heldFloorY = null;
|
|
86955
|
+
this._collision = collision;
|
|
86956
|
+
}
|
|
86957
|
+
else {
|
|
86958
|
+
// No placement within reach. The setter holds if the capsule is inside geometry
|
|
86959
|
+
// and engages otherwise, which is what `_step` would do on its first step anyway.
|
|
86960
|
+
this.collision = collision;
|
|
86819
86961
|
}
|
|
86820
|
-
this._prevPosition.copy(this._position);
|
|
86821
86962
|
}
|
|
86963
|
+
this._prevPosition.copy(this._position);
|
|
86822
86964
|
}
|
|
86823
86965
|
update(deltaTime, inputFrame, camera) {
|
|
86824
86966
|
const { move, rotate } = inputFrame.read();
|
|
@@ -86852,6 +86994,12 @@ class WalkController {
|
|
|
86852
86994
|
camera.fov = this.fov;
|
|
86853
86995
|
}
|
|
86854
86996
|
_step(dt, move) {
|
|
86997
|
+
// engage a held attachment as soon as the capsule reaches space it fits in
|
|
86998
|
+
if (this._pendingCollision && this._capsuleClear(this._pendingCollision, this._position)) {
|
|
86999
|
+
this._collision = this._pendingCollision;
|
|
87000
|
+
this._pendingCollision = null;
|
|
87001
|
+
this._heldFloorY = null;
|
|
87002
|
+
}
|
|
86855
87003
|
// ground probe: cast a ray downward to find the terrain surface
|
|
86856
87004
|
const groundY = this._probeGround(this._position);
|
|
86857
87005
|
const hasGround = groundY !== null;
|
|
@@ -86912,6 +87060,7 @@ class WalkController {
|
|
|
86912
87060
|
*/
|
|
86913
87061
|
goto(camera) {
|
|
86914
87062
|
// position
|
|
87063
|
+
this._hasPosition = true;
|
|
86915
87064
|
this._position.copy(camera.position);
|
|
86916
87065
|
this._prevPosition.copy(this._position);
|
|
86917
87066
|
// angles (clamp pitch to avoid gimbal lock)
|
|
@@ -86956,6 +87105,18 @@ class WalkController {
|
|
|
86956
87105
|
this._pendingMove[2] = 0;
|
|
86957
87106
|
this._accumulator = 0;
|
|
86958
87107
|
}
|
|
87108
|
+
/**
|
|
87109
|
+
* Whether the walk capsule fits at `pos` without intersecting collision geometry.
|
|
87110
|
+
*
|
|
87111
|
+
* @param collision - Collision to test against.
|
|
87112
|
+
* @param pos - Eye position in PlayCanvas world space.
|
|
87113
|
+
* @returns True if the capsule is clear.
|
|
87114
|
+
*/
|
|
87115
|
+
_capsuleClear(collision, pos) {
|
|
87116
|
+
const center = pos.y - this.eyeHeight + this.capsuleHeight * 0.5;
|
|
87117
|
+
const half = this.capsuleHeight * 0.5 - this.capsuleRadius;
|
|
87118
|
+
return !collision.queryCapsule(pos.x, center, pos.z, half, this.capsuleRadius, out);
|
|
87119
|
+
}
|
|
86959
87120
|
/**
|
|
86960
87121
|
* Cast multiple rays downward to find the average ground surface height.
|
|
86961
87122
|
* Uses 5 rays (center + 4 cardinal at capsule radius) to spatially filter
|
|
@@ -86965,6 +87126,10 @@ class WalkController {
|
|
|
86965
87126
|
* @returns Average ground surface Y in PlayCanvas space, or null if no ground found.
|
|
86966
87127
|
*/
|
|
86967
87128
|
_probeGround(pos) {
|
|
87129
|
+
// While collision is held the real surface is unreachable, so stand on the level the
|
|
87130
|
+
// camera entered at. Without this the camera reads as airborne and falls.
|
|
87131
|
+
if (this._heldFloorY !== null)
|
|
87132
|
+
return this._heldFloorY;
|
|
86968
87133
|
if (!this.collision)
|
|
86969
87134
|
return null;
|
|
86970
87135
|
const oy = pos.y - this.eyeHeight;
|
|
@@ -86999,6 +87164,8 @@ class WalkController {
|
|
|
86999
87164
|
* @param disp - Pre-allocated vector to receive the collision push-out displacement.
|
|
87000
87165
|
*/
|
|
87001
87166
|
_checkCollision(pos, disp) {
|
|
87167
|
+
if (!this.collision)
|
|
87168
|
+
return;
|
|
87002
87169
|
const center = pos.y - this.eyeHeight + this.capsuleHeight * 0.5;
|
|
87003
87170
|
const half = this.capsuleHeight * 0.5 - this.capsuleRadius;
|
|
87004
87171
|
if (this.collision.queryCapsule(pos.x, center, pos.z, half, this.capsuleRadius, out)) {
|
|
@@ -87156,11 +87323,16 @@ class CameraManager {
|
|
|
87156
87323
|
// mutating `camera` and/or `state.cameraMode` to make the change
|
|
87157
87324
|
// visible instantly.
|
|
87158
87325
|
snap;
|
|
87326
|
+
// Attach (or clear) collision after construction. The viewer reveals the scene without
|
|
87327
|
+
// waiting for collision data, which can be larger than the splats themselves, so this
|
|
87328
|
+
// arrives late. It re-tests whether walk mode is allowed, which gates the walk toggle
|
|
87329
|
+
// and the mode the camera falls back to when an animation is interrupted.
|
|
87330
|
+
setCollision;
|
|
87159
87331
|
// holds the camera state
|
|
87160
87332
|
camera = new Camera();
|
|
87161
87333
|
constructor(global, bbox, collision = null) {
|
|
87162
87334
|
const { events, settings, state } = global;
|
|
87163
|
-
|
|
87335
|
+
let walkAllowed = isWalkAllowed(bbox, collision);
|
|
87164
87336
|
const camera0 = settings.cameras[0]?.initial;
|
|
87165
87337
|
const defaultFov = camera0?.fov ?? DEFAULT_CAMERA_FOV;
|
|
87166
87338
|
const frameCamera = createFrameCamera(bbox, defaultFov);
|
|
@@ -87216,8 +87388,10 @@ class CameraManager {
|
|
|
87216
87388
|
this.camera.copy(resetCamera);
|
|
87217
87389
|
const target = new Camera(this.camera); // the active controller updates this
|
|
87218
87390
|
const from = new Camera(this.camera); // stores the previous camera state during transition
|
|
87219
|
-
const defaultMode = isObjectExperience ? 'orbit' : walkAllowed ? 'walk' : 'fly';
|
|
87220
|
-
|
|
87391
|
+
const defaultMode = () => (isObjectExperience ? 'orbit' : walkAllowed ? 'walk' : 'fly');
|
|
87392
|
+
// null until the first mode change, so the fallback tracks `walkAllowed` if collision
|
|
87393
|
+
// attaches before the user has moved
|
|
87394
|
+
let fromMode = null;
|
|
87221
87395
|
// tracks the mode to restore when exiting walk
|
|
87222
87396
|
let preWalkMode = isObjectExperience ? 'orbit' : 'fly';
|
|
87223
87397
|
// enter the initial controller
|
|
@@ -87231,6 +87405,11 @@ class CameraManager {
|
|
|
87231
87405
|
from.copy(this.camera);
|
|
87232
87406
|
transitionTimer = 0;
|
|
87233
87407
|
};
|
|
87408
|
+
this.setCollision = (value) => {
|
|
87409
|
+
controllers.fly.collision = value;
|
|
87410
|
+
controllers.walk.collision = value;
|
|
87411
|
+
walkAllowed = isWalkAllowed(bbox, value);
|
|
87412
|
+
};
|
|
87234
87413
|
this.snap = () => {
|
|
87235
87414
|
getController(state.cameraMode).onEnter(this.camera);
|
|
87236
87415
|
target.copy(this.camera);
|
|
@@ -87307,7 +87486,9 @@ class CameraManager {
|
|
|
87307
87486
|
}
|
|
87308
87487
|
break;
|
|
87309
87488
|
case 'requestFirstPerson':
|
|
87310
|
-
|
|
87489
|
+
// movement input from a non-first-person mode: walk where the scene allows
|
|
87490
|
+
// it, fly otherwise, the same preference as the animation fallback
|
|
87491
|
+
state.cameraMode = walkAllowed ? 'walk' : 'fly';
|
|
87311
87492
|
break;
|
|
87312
87493
|
case 'toggleWalk':
|
|
87313
87494
|
if (walkAllowed) {
|
|
@@ -87326,12 +87507,12 @@ class CameraManager {
|
|
|
87326
87507
|
break;
|
|
87327
87508
|
case 'cancel':
|
|
87328
87509
|
if (state.cameraMode === 'anim') {
|
|
87329
|
-
state.cameraMode = fromMode;
|
|
87510
|
+
state.cameraMode = fromMode ?? defaultMode();
|
|
87330
87511
|
}
|
|
87331
87512
|
break;
|
|
87332
87513
|
case 'interrupt':
|
|
87333
87514
|
if (state.cameraMode === 'anim') {
|
|
87334
|
-
state.cameraMode = fromMode;
|
|
87515
|
+
state.cameraMode = fromMode ?? defaultMode();
|
|
87335
87516
|
}
|
|
87336
87517
|
break;
|
|
87337
87518
|
}
|
|
@@ -88152,7 +88333,7 @@ class ModeShortcuts {
|
|
|
88152
88333
|
default:
|
|
88153
88334
|
if (isWasdKey(event) && state.inputMode === 'desktop') {
|
|
88154
88335
|
if (!isCaptureMode$1(state.cameraMode)) {
|
|
88155
|
-
|
|
88336
|
+
events.fire('inputEvent', 'requestFirstPerson');
|
|
88156
88337
|
}
|
|
88157
88338
|
if (!state.gamingControls) {
|
|
88158
88339
|
state.gamingControls = true;
|
|
@@ -89734,6 +89915,9 @@ class NavCursor {
|
|
|
89734
89915
|
hoverRing;
|
|
89735
89916
|
targetRing;
|
|
89736
89917
|
camera;
|
|
89918
|
+
// Settable after construction: the viewer reveals the scene before the collision data has
|
|
89919
|
+
// downloaded, so this arrives late. Ring sizing reads `state.walkAllowed` live, so only the
|
|
89920
|
+
// pick path needs updating here.
|
|
89737
89921
|
collision;
|
|
89738
89922
|
canvas;
|
|
89739
89923
|
state;
|
|
@@ -90590,12 +90774,10 @@ const MAX_STEPS: u32 = 512u;
|
|
|
90590
90774
|
// Target wireframe edge width in pixels
|
|
90591
90775
|
const EDGE_PIXELS: f32 = 1.5;
|
|
90592
90776
|
|
|
90593
|
-
//
|
|
90594
|
-
// overlay's wireframe pass).
|
|
90777
|
+
// Keep edges tinted so dense grids retain the solid/free-space distinction.
|
|
90595
90778
|
const EDGE_ALPHA: f32 = 0.8;
|
|
90596
90779
|
|
|
90597
|
-
|
|
90598
|
-
const FILL_ALPHA: f32 = 0.30;
|
|
90780
|
+
const FILL_ALPHA: f32 = 0.4;
|
|
90599
90781
|
|
|
90600
90782
|
struct Uniforms {
|
|
90601
90783
|
invVP: mat4x4<f32>,
|
|
@@ -90704,10 +90886,9 @@ fn edgeFactor(hitPos: vec3f, voxMin: vec3f, voxSize: f32, edgeWidth: f32) -> f32
|
|
|
90704
90886
|
return 1.0 - smoothstep(0.0, edgeWidth, edgeDist);
|
|
90705
90887
|
}
|
|
90706
90888
|
|
|
90707
|
-
// Shade
|
|
90708
|
-
//
|
|
90709
|
-
//
|
|
90710
|
-
// wireframe pass.
|
|
90889
|
+
// Shade by the camera's occupancy: gray in free space, orange inside solid
|
|
90890
|
+
// voxels (where the ray-march is inverted to find the exit into free space).
|
|
90891
|
+
// Face-axis brightness and darker edges keep the grid shape readable.
|
|
90711
90892
|
fn shadeVoxelHit(hitPos: vec3f, voxMin: vec3f, voxelRes: f32, ro: vec3f) -> vec4f {
|
|
90712
90893
|
let dist = length(hitPos - ro);
|
|
90713
90894
|
let pixelWorld = 2.0 * dist / (f32(uniforms.screenHeight) * uniforms.projScaleY);
|
|
@@ -90727,15 +90908,12 @@ fn shadeVoxelHit(hitPos: vec3f, voxMin: vec3f, voxelRes: f32, ro: vec3f) -> vec4
|
|
|
90727
90908
|
faceAxis = 2u;
|
|
90728
90909
|
}
|
|
90729
90910
|
|
|
90730
|
-
var
|
|
90731
|
-
if (faceAxis ==
|
|
90732
|
-
else if (faceAxis ==
|
|
90733
|
-
else { baseColor = vec3f(0.30); }
|
|
90911
|
+
var brightness = 0.85;
|
|
90912
|
+
if (faceAxis == 1u) { brightness = 0.65; }
|
|
90913
|
+
else if (faceAxis == 2u) { brightness = 0.45; }
|
|
90734
90914
|
|
|
90735
|
-
|
|
90736
|
-
|
|
90737
|
-
// opaque black lines while the interior stays at the surface tint.
|
|
90738
|
-
let color = mix(baseColor, vec3f(0.0), ef);
|
|
90915
|
+
let tint = select(vec3f(1.0), vec3f(1.0, 0.35, 0.08), uniforms.inverted != 0u);
|
|
90916
|
+
let color = tint * mix(brightness, 0.2, ef);
|
|
90739
90917
|
let alpha = mix(FILL_ALPHA, EDGE_ALPHA, ef);
|
|
90740
90918
|
|
|
90741
90919
|
return vec4f(color * alpha, alpha);
|
|
@@ -90789,7 +90967,7 @@ fn main(@builtin(global_invocation_id) gid: vec3u) {
|
|
|
90789
90967
|
let invDir = 1.0 / rd;
|
|
90790
90968
|
let gridHit = intersectAABB(ro, invDir, gridMin, gridMax);
|
|
90791
90969
|
|
|
90792
|
-
if (gridHit.x > gridHit.y) {
|
|
90970
|
+
if (max(gridHit.x, 0.0) > gridHit.y) {
|
|
90793
90971
|
textureStore(outputTexture, vec2i(px, py), vec4f(0.0));
|
|
90794
90972
|
return;
|
|
90795
90973
|
}
|
|
@@ -91126,7 +91304,7 @@ class VoxelDebugOverlay {
|
|
|
91126
91304
|
});
|
|
91127
91305
|
}
|
|
91128
91306
|
update() {
|
|
91129
|
-
if (!this.enabled)
|
|
91307
|
+
if (!this.enabled || this.collision.nodes.length === 0)
|
|
91130
91308
|
return;
|
|
91131
91309
|
const { app, camera, compute, collision } = this;
|
|
91132
91310
|
const device = app.graphicsDevice;
|
|
@@ -91200,6 +91378,9 @@ class VoxelDebugOverlay {
|
|
|
91200
91378
|
app.drawTexture(0, 0, 2, 2, null, this.overlayMaterial);
|
|
91201
91379
|
}
|
|
91202
91380
|
destroy() {
|
|
91381
|
+
this.compute.destroy();
|
|
91382
|
+
this.compute.shader.destroy();
|
|
91383
|
+
this.overlayMaterial.destroy();
|
|
91203
91384
|
this.nodesBuffer?.destroy();
|
|
91204
91385
|
this.leafDataBuffer?.destroy();
|
|
91205
91386
|
this.storageTexture?.destroy();
|
|
@@ -93098,13 +93279,64 @@ class Viewer {
|
|
|
93098
93279
|
}
|
|
93099
93280
|
}, ignoreLoadFailure);
|
|
93100
93281
|
}
|
|
93282
|
+
// Loading progress has to start reporting as soon as the splat data starts streaming,
|
|
93283
|
+
// which is well before the reveal. The reveal is wired up in the `Promise.all` below, so
|
|
93284
|
+
// it also waits on the skybox and the collision data — and a collision download can take
|
|
93285
|
+
// far longer than the splats themselves (ten seconds against under six, on a 4G trace of
|
|
93286
|
+
// a real scene), leaving the bar frozen at 0% for the whole wait. Chaining off
|
|
93287
|
+
// `gsplatLoad` alone lets the bar track the one load it can measure, from the moment
|
|
93288
|
+
// that load begins. The reveal below stops it and puts the bar at 100.
|
|
93289
|
+
let stopProgress;
|
|
93290
|
+
gsplatLoad.then(() => {
|
|
93291
|
+
if (this.destroyed)
|
|
93292
|
+
return;
|
|
93293
|
+
const eventHandler = app.systems.gsplat;
|
|
93294
|
+
// `loading` counts the node files the streamer has requested and not yet made
|
|
93295
|
+
// resident. Before the reveal the LOD range is clamped to the coarsest level, so this
|
|
93296
|
+
// is a single wave and completed / (completed + in-flight) tracks it directly. A drop
|
|
93297
|
+
// in the count is work that finished, or was cancelled, which this cannot tell apart
|
|
93298
|
+
// and counts as done. Clamped monotone and capped below 100 so only the reveal fills
|
|
93299
|
+
// the bar. See docs/streaming-progress.md for the engine signal that would replace it.
|
|
93300
|
+
let prevLoading = 0;
|
|
93301
|
+
let completed = 0;
|
|
93302
|
+
const progressHandler = (camera, layer, ready, loading) => {
|
|
93303
|
+
completed += Math.max(0, prevLoading - loading);
|
|
93304
|
+
prevLoading = loading;
|
|
93305
|
+
const total = completed + loading;
|
|
93306
|
+
if (total > 0) {
|
|
93307
|
+
state.progress = Math.max(state.progress, Math.min(99, Math.trunc((completed / total) * 100)));
|
|
93308
|
+
}
|
|
93309
|
+
};
|
|
93310
|
+
eventHandler.on('frame:ready', progressHandler);
|
|
93311
|
+
stopProgress = () => eventHandler.off('frame:ready', progressHandler);
|
|
93312
|
+
this.onDestroy(stopProgress);
|
|
93313
|
+
}, ignoreLoadFailure);
|
|
93314
|
+
// Collision data is not needed to draw the scene, and it can be larger than the splats
|
|
93315
|
+
// themselves: 5.65 MB against 4.28 MB for the coarsest LOD level on a traced scene. So
|
|
93316
|
+
// it is kept out of the reveal path below, which would otherwise sit on a blank poster
|
|
93317
|
+
// with everything needed to render already in memory. `attachCollision` wires it up
|
|
93318
|
+
// whenever it lands; the two chains can resolve in either order, so whichever is second
|
|
93319
|
+
// performs the attach.
|
|
93320
|
+
//
|
|
93321
|
+
// Nothing in the opening view depends on it. The scene always starts in `anim` mode, so
|
|
93322
|
+
// no collision-dependent controller is entered until the user takes over. Until it
|
|
93323
|
+
// attaches, `walkAllowed` stays false so walk mode cannot be entered without the data it
|
|
93324
|
+
// needs to place the camera, fly mode has no collision response, and nav targeting falls
|
|
93325
|
+
// back to splat depth instead of collision ray hits.
|
|
93326
|
+
let collisionReady = null;
|
|
93327
|
+
let attachCollision;
|
|
93328
|
+
collisionLoad?.then((collision) => {
|
|
93329
|
+
if (this.destroyed || !collision)
|
|
93330
|
+
return;
|
|
93331
|
+
collisionReady = collision;
|
|
93332
|
+
attachCollision?.(collision);
|
|
93333
|
+
}, ignoreLoadFailure);
|
|
93101
93334
|
// wait for the model to load
|
|
93102
|
-
Promise.all([gsplatLoad, skyboxLoad
|
|
93335
|
+
Promise.all([gsplatLoad, skyboxLoad]).then((results) => {
|
|
93103
93336
|
// destroyed while loading: the app is gone, so there is nothing to wire up
|
|
93104
93337
|
if (this.destroyed)
|
|
93105
93338
|
return;
|
|
93106
93339
|
const gsplatComponent = results[0].gsplat;
|
|
93107
|
-
const collision = results[2];
|
|
93108
93340
|
// get scene bounding box
|
|
93109
93341
|
const gsplatBbox = gsplatComponent.customAabb;
|
|
93110
93342
|
if (gsplatBbox) {
|
|
@@ -93112,37 +93344,54 @@ class Viewer {
|
|
|
93112
93344
|
}
|
|
93113
93345
|
this.picker = new Picker(app, camera);
|
|
93114
93346
|
this.inputController = new InputController(global, this.picker);
|
|
93115
|
-
this.
|
|
93347
|
+
this.cameraManager = new CameraManager(global, sceneBound);
|
|
93348
|
+
applyCamera(this.cameraManager.camera);
|
|
93349
|
+
if (config.ui) {
|
|
93350
|
+
this.navCursor = new NavCursor(app, camera, null, events, state, config.reticle);
|
|
93351
|
+
}
|
|
93116
93352
|
// hasCollision = collision data exists (drives fly-mode collision
|
|
93117
93353
|
// detection and the voxel/mesh debug overlay availability).
|
|
93118
93354
|
// walkAllowed = walk mode is offered to the user; requires both
|
|
93119
93355
|
// collision data and a scene large enough to walk around in.
|
|
93120
|
-
|
|
93121
|
-
|
|
93122
|
-
|
|
93123
|
-
|
|
93124
|
-
|
|
93125
|
-
|
|
93126
|
-
|
|
93127
|
-
state.
|
|
93128
|
-
|
|
93129
|
-
|
|
93130
|
-
|
|
93131
|
-
|
|
93132
|
-
|
|
93133
|
-
|
|
93134
|
-
|
|
93135
|
-
|
|
93136
|
-
|
|
93137
|
-
|
|
93138
|
-
|
|
93139
|
-
|
|
93140
|
-
|
|
93141
|
-
|
|
93142
|
-
|
|
93143
|
-
|
|
93144
|
-
|
|
93145
|
-
|
|
93356
|
+
attachCollision = (collision) => {
|
|
93357
|
+
this.inputController.collision = collision;
|
|
93358
|
+
this.cameraManager.setCollision(collision);
|
|
93359
|
+
if (this.navCursor) {
|
|
93360
|
+
this.navCursor.collision = collision;
|
|
93361
|
+
}
|
|
93362
|
+
state.hasCollision = true;
|
|
93363
|
+
state.walkAllowed = isWalkAllowed(sceneBound, collision);
|
|
93364
|
+
// Create collision debug overlay (voxel uses a compute shader, mesh
|
|
93365
|
+
// uses standard line rendering). The voxel path requires WebGPU.
|
|
93366
|
+
if (collision instanceof VoxelCollision && renderer !== 'webgl') {
|
|
93367
|
+
const setOverlayEnabled = (value) => {
|
|
93368
|
+
// Upload the voxel data and allocate the screen-sized texture only
|
|
93369
|
+
// when the debug overlay is first used.
|
|
93370
|
+
if (value && !this.voxelOverlay) {
|
|
93371
|
+
this.voxelOverlay = new VoxelDebugOverlay(app, collision, camera);
|
|
93372
|
+
this.voxelOverlay.mode = config.heatmap ? 'heatmap' : 'overlay';
|
|
93373
|
+
}
|
|
93374
|
+
if (this.voxelOverlay)
|
|
93375
|
+
this.voxelOverlay.enabled = value;
|
|
93376
|
+
app.renderNextFrame = true;
|
|
93377
|
+
};
|
|
93378
|
+
events.on('collisionOverlayEnabled:changed', setOverlayEnabled);
|
|
93379
|
+
state.hasCollisionOverlay = true;
|
|
93380
|
+
setOverlayEnabled(state.collisionOverlayEnabled);
|
|
93381
|
+
}
|
|
93382
|
+
else if (collision instanceof MeshCollision) {
|
|
93383
|
+
this.meshOverlay = new MeshDebugOverlay(app, collision, camera, !!this.cameraFrame);
|
|
93384
|
+
state.hasCollisionOverlay = true;
|
|
93385
|
+
events.on('collisionOverlayEnabled:changed', (value) => {
|
|
93386
|
+
this.meshOverlay.enabled = value;
|
|
93387
|
+
app.renderNextFrame = true;
|
|
93388
|
+
});
|
|
93389
|
+
}
|
|
93390
|
+
app.renderNextFrame = true;
|
|
93391
|
+
};
|
|
93392
|
+
// collision may already have landed while the splats were still streaming
|
|
93393
|
+
if (collisionReady)
|
|
93394
|
+
attachCollision(collisionReady);
|
|
93146
93395
|
this.debugPanel = new DebugPanel(global, this.cameraManager);
|
|
93147
93396
|
// quality budget
|
|
93148
93397
|
const budgets = {
|
|
@@ -93182,12 +93431,28 @@ class Viewer {
|
|
|
93182
93431
|
eventHandler.on('frame:request', () => {
|
|
93183
93432
|
app.renderNextFrame = true;
|
|
93184
93433
|
});
|
|
93185
|
-
|
|
93186
|
-
|
|
93434
|
+
// `ready && loading === 0` describes the state before streaming starts just as well
|
|
93435
|
+
// as the state after it finishes: on the first frame the octree instance has not run
|
|
93436
|
+
// its LOD pass yet, so nothing is in flight and the world trivially reports ready.
|
|
93437
|
+
// Taken at face value that revealed the scene on the first event, before a single
|
|
93438
|
+
// frame had rendered, which both skipped the whole loading bar and undid the coarse
|
|
93439
|
+
// LOD clamp above by running applyPerfSettings immediately. So require evidence that
|
|
93440
|
+
// the streamer has left that initial state: work in flight, or splats on screen.
|
|
93441
|
+
// Only octree content has a streaming phase to wait for; single-file content is fully
|
|
93442
|
+
// loaded before this handler is registered, so it must not be gated.
|
|
93443
|
+
const octree = gsplatComponent.resource?.octree ?? null;
|
|
93444
|
+
let streamingStarted = !octree;
|
|
93187
93445
|
const readyHandler = (camera, layer, ready, loading) => {
|
|
93188
|
-
|
|
93446
|
+
// `frame.gsplats` is the rendered splat count, the same stat the ministats panel
|
|
93447
|
+
// above reads. It covers an octree that renders before it reports work in flight.
|
|
93448
|
+
if (loading > 0 || app.stats.frame.gsplats > 0) {
|
|
93449
|
+
streamingStarted = true;
|
|
93450
|
+
}
|
|
93451
|
+
if (ready && loading === 0 && streamingStarted) {
|
|
93189
93452
|
// scene is done with initial/reveal loading
|
|
93190
93453
|
eventHandler.off('frame:ready', readyHandler);
|
|
93454
|
+
stopProgress?.();
|
|
93455
|
+
state.progress = 100;
|
|
93191
93456
|
// switch to on-demand rendering (frame:request + camera-change detection)
|
|
93192
93457
|
app.autoRender = false;
|
|
93193
93458
|
// handle quality mode changes
|
|
@@ -93201,12 +93466,6 @@ class Viewer {
|
|
|
93201
93466
|
window.firstFrame?.();
|
|
93202
93467
|
});
|
|
93203
93468
|
}
|
|
93204
|
-
// update loading status
|
|
93205
|
-
if (loading !== current) {
|
|
93206
|
-
watermark = Math.max(watermark, loading);
|
|
93207
|
-
current = watermark - loading;
|
|
93208
|
-
state.progress = Math.trunc((current / watermark) * 100);
|
|
93209
|
-
}
|
|
93210
93469
|
};
|
|
93211
93470
|
eventHandler.on('frame:ready', readyHandler);
|
|
93212
93471
|
}, ignoreLoadFailure);
|
|
@@ -93473,13 +93732,22 @@ class Viewer {
|
|
|
93473
93732
|
}
|
|
93474
93733
|
}
|
|
93475
93734
|
|
|
93735
|
+
// The filename's extension selects the gsplat parser, so a url with no usable name (a data:
|
|
93736
|
+
// uri) needs the config to name its content instead; falsy (an empty name) falls back to the
|
|
93737
|
+
// url-derived name.
|
|
93738
|
+
const contentName = (contentUrl, contentFilename) => contentFilename || new URL(contentUrl, location.href).pathname.split('/').pop();
|
|
93739
|
+
// Whether a prefetched response for this content is worth starting. The engine's octree parser
|
|
93740
|
+
// fetches lod-meta.json itself and ignores `asset.file.contents`, so prefetching it downloads
|
|
93741
|
+
// the metadata twice — a quarter of a megabyte on a real scene, served with no cache-control
|
|
93742
|
+
// header, so the second request is not a cache hit. Every other splat parser consumes the
|
|
93743
|
+
// prefetched response, so they keep the head start. `src/index.html` applies the same rule when
|
|
93744
|
+
// it starts its own prefetch, and docs/streaming-progress.md covers the engine fix that would
|
|
93745
|
+
// let the octree path reuse the response instead of opting out of it.
|
|
93746
|
+
const isPrefetchable = (contentUrl, contentFilename) => contentName(contentUrl, contentFilename)?.toLowerCase() !== 'lod-meta.json';
|
|
93476
93747
|
const loadGsplat = async (app, config, progressCallback, cancelled) => {
|
|
93477
93748
|
const { contents, contentUrl, contentFilename } = config;
|
|
93478
93749
|
const c = contents;
|
|
93479
|
-
|
|
93480
|
-
// data: uri) needs the config to name its content instead; falsy (an empty name) falls
|
|
93481
|
-
// back to the url-derived name
|
|
93482
|
-
const filename = contentFilename || new URL(contentUrl, location.href).pathname.split('/').pop();
|
|
93750
|
+
const filename = contentName(contentUrl, contentFilename);
|
|
93483
93751
|
const data = filename.toLowerCase() === 'meta.json' ? await (await contents).json() : undefined;
|
|
93484
93752
|
// Reading that metadata spans a network round trip, so a destroy can land in the middle of
|
|
93485
93753
|
// it. `app.destroy()` nulls the asset registry, so registering the asset now would throw
|
|
@@ -93656,7 +93924,8 @@ const resolveConfig = (options) => ({
|
|
|
93656
93924
|
skyboxUrl: options.skyboxUrl,
|
|
93657
93925
|
collisionUrl: options.collisionUrl,
|
|
93658
93926
|
poster: options.poster ?? (options.posterUrl ? createImage(options.posterUrl) : undefined),
|
|
93659
|
-
contents: options.contents ??
|
|
93927
|
+
contents: options.contents ??
|
|
93928
|
+
(isPrefetchable(options.contentUrl, options.contentFilename) ? fetch(options.contentUrl) : undefined),
|
|
93660
93929
|
renderer: options.renderer ?? 'webgpu',
|
|
93661
93930
|
ui: options.ui ?? true,
|
|
93662
93931
|
reticle: options.reticle ?? false,
|