@playcanvas/supersplat-viewer 1.16.11 → 1.16.13
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 +1 -1
- package/public/index.js +163 -52
- package/public/index.js.map +1 -1
package/package.json
CHANGED
package/public/index.js
CHANGED
|
@@ -74711,7 +74711,10 @@ class InputController {
|
|
|
74711
74711
|
const hit = this.collider.queryRay(-cameraPos.x, -cameraPos.y, cameraPos.z, -tmpV1.x, -tmpV1.y, tmpV1.z, camera.camera.farClip);
|
|
74712
74712
|
if (!hit)
|
|
74713
74713
|
return null;
|
|
74714
|
-
const
|
|
74714
|
+
const rdx = -tmpV1.x;
|
|
74715
|
+
const rdy = -tmpV1.y;
|
|
74716
|
+
const rdz = tmpV1.z;
|
|
74717
|
+
const sn = this.collider.querySurfaceNormal(hit.x, hit.y, hit.z, rdx, rdy, rdz);
|
|
74715
74718
|
return {
|
|
74716
74719
|
position: new Vec3(-hit.x, -hit.y, hit.z),
|
|
74717
74720
|
normal: new Vec3(-sn.nx, -sn.ny, sn.nz)
|
|
@@ -75480,6 +75483,7 @@ const NUM_SAMPLES = 12;
|
|
|
75480
75483
|
const CIRCLE_OUTER_RADIUS = 0.3;
|
|
75481
75484
|
const CIRCLE_INNER_RADIUS = 0.22;
|
|
75482
75485
|
const BEZIER_K = 1 / 6;
|
|
75486
|
+
const NORMAL_SMOOTH_FACTOR = 0.25;
|
|
75483
75487
|
const tmpV = new Vec3();
|
|
75484
75488
|
const tmpScreen = new Vec3();
|
|
75485
75489
|
const tangent = new Vec3();
|
|
@@ -75515,6 +75519,10 @@ class WalkCursor {
|
|
|
75515
75519
|
walking = false;
|
|
75516
75520
|
targetPos = null;
|
|
75517
75521
|
targetNormal = null;
|
|
75522
|
+
smoothNx = 0;
|
|
75523
|
+
smoothNy = 1;
|
|
75524
|
+
smoothNz = 0;
|
|
75525
|
+
hasSmoothedNormal = false;
|
|
75518
75526
|
onPointerMove;
|
|
75519
75527
|
onPointerLeave;
|
|
75520
75528
|
scratchX = new Float64Array(NUM_SAMPLES);
|
|
@@ -75551,12 +75559,14 @@ class WalkCursor {
|
|
|
75551
75559
|
return;
|
|
75552
75560
|
if (e.buttons) {
|
|
75553
75561
|
this.cursorPath.style.display = 'none';
|
|
75562
|
+
this.hasSmoothedNormal = false;
|
|
75554
75563
|
return;
|
|
75555
75564
|
}
|
|
75556
75565
|
this.updateCursor(e.offsetX, e.offsetY);
|
|
75557
75566
|
};
|
|
75558
75567
|
this.onPointerLeave = () => {
|
|
75559
75568
|
this.cursorPath.style.display = 'none';
|
|
75569
|
+
this.hasSmoothedNormal = false;
|
|
75560
75570
|
};
|
|
75561
75571
|
this.canvas.addEventListener('pointermove', this.onPointerMove);
|
|
75562
75572
|
this.canvas.addEventListener('pointerleave', this.onPointerLeave);
|
|
@@ -75572,6 +75582,7 @@ class WalkCursor {
|
|
|
75572
75582
|
events.on('walkTo', () => {
|
|
75573
75583
|
this.walking = true;
|
|
75574
75584
|
this.cursorPath.style.display = 'none';
|
|
75585
|
+
this.hasSmoothedNormal = false;
|
|
75575
75586
|
});
|
|
75576
75587
|
events.on('walkCancel', () => {
|
|
75577
75588
|
this.walking = false;
|
|
@@ -75628,6 +75639,7 @@ class WalkCursor {
|
|
|
75628
75639
|
updateCursor(offsetX, offsetY) {
|
|
75629
75640
|
if (!this.active || this.walking) {
|
|
75630
75641
|
this.cursorPath.style.display = 'none';
|
|
75642
|
+
this.hasSmoothedNormal = false;
|
|
75631
75643
|
return;
|
|
75632
75644
|
}
|
|
75633
75645
|
const { camera, collider } = this;
|
|
@@ -75637,15 +75649,36 @@ class WalkCursor {
|
|
|
75637
75649
|
const hit = collider.queryRay(-cameraPos.x, -cameraPos.y, cameraPos.z, -tmpV.x, -tmpV.y, tmpV.z, camera.camera.farClip);
|
|
75638
75650
|
if (!hit) {
|
|
75639
75651
|
this.cursorPath.style.display = 'none';
|
|
75652
|
+
this.hasSmoothedNormal = false;
|
|
75640
75653
|
return;
|
|
75641
75654
|
}
|
|
75642
75655
|
const px = -hit.x;
|
|
75643
75656
|
const py = -hit.y;
|
|
75644
75657
|
const pz = hit.z;
|
|
75645
|
-
const
|
|
75646
|
-
const
|
|
75647
|
-
const
|
|
75648
|
-
const
|
|
75658
|
+
const rdx = -tmpV.x;
|
|
75659
|
+
const rdy = -tmpV.y;
|
|
75660
|
+
const rdz = tmpV.z;
|
|
75661
|
+
const sn = collider.querySurfaceNormal(hit.x, hit.y, hit.z, rdx, rdy, rdz);
|
|
75662
|
+
let nx = -sn.nx;
|
|
75663
|
+
let ny = -sn.ny;
|
|
75664
|
+
let nz = sn.nz;
|
|
75665
|
+
if (this.hasSmoothedNormal) {
|
|
75666
|
+
const t = NORMAL_SMOOTH_FACTOR;
|
|
75667
|
+
nx = this.smoothNx + (nx - this.smoothNx) * t;
|
|
75668
|
+
ny = this.smoothNy + (ny - this.smoothNy) * t;
|
|
75669
|
+
nz = this.smoothNz + (nz - this.smoothNz) * t;
|
|
75670
|
+
const len = Math.sqrt(nx * nx + ny * ny + nz * nz);
|
|
75671
|
+
if (len > 1e-6) {
|
|
75672
|
+
const invLen = 1.0 / len;
|
|
75673
|
+
nx *= invLen;
|
|
75674
|
+
ny *= invLen;
|
|
75675
|
+
nz *= invLen;
|
|
75676
|
+
}
|
|
75677
|
+
}
|
|
75678
|
+
this.smoothNx = nx;
|
|
75679
|
+
this.smoothNy = ny;
|
|
75680
|
+
this.smoothNz = nz;
|
|
75681
|
+
this.hasSmoothedNormal = true;
|
|
75649
75682
|
this.projectCircle(px, py, pz, nx, ny, nz, CIRCLE_OUTER_RADIUS, this.outerX, this.outerY);
|
|
75650
75683
|
this.projectCircle(px, py, pz, nx, ny, nz, CIRCLE_INNER_RADIUS, this.innerX, this.innerY);
|
|
75651
75684
|
this.cursorPath.setAttribute('d', `${buildBezierRing(this.outerX, this.outerY)} ${buildBezierRing(this.innerX, this.innerY)}`);
|
|
@@ -75947,8 +75980,23 @@ class Viewer {
|
|
|
75947
75980
|
// same performance, but rotating on slow devices does not give us unsorted splats on sides
|
|
75948
75981
|
gsplat.radialSorting = true;
|
|
75949
75982
|
const eventHandler = app.systems.gsplat;
|
|
75950
|
-
//
|
|
75983
|
+
// idle timer: force continuous rendering until 4s of inactivity
|
|
75984
|
+
let idleTime = 0;
|
|
75951
75985
|
this.forceRenderNextFrame = true;
|
|
75986
|
+
app.on('update', (dt) => {
|
|
75987
|
+
idleTime += dt;
|
|
75988
|
+
this.forceRenderNextFrame = idleTime < 4;
|
|
75989
|
+
});
|
|
75990
|
+
events.on('inputEvent', (type) => {
|
|
75991
|
+
if (type !== 'interact') {
|
|
75992
|
+
idleTime = 0;
|
|
75993
|
+
}
|
|
75994
|
+
});
|
|
75995
|
+
eventHandler.on('frame:ready', (_camera, _layer, ready, loading) => {
|
|
75996
|
+
if (loading > 0 || !ready) {
|
|
75997
|
+
idleTime = 0;
|
|
75998
|
+
}
|
|
75999
|
+
});
|
|
75952
76000
|
let current = 0;
|
|
75953
76001
|
let watermark = 1;
|
|
75954
76002
|
const readyHandler = (camera, layer, ready, loading) => {
|
|
@@ -76042,18 +76090,70 @@ class Viewer {
|
|
|
76042
76090
|
const SOLID_LEAF_MARKER = 0xFF000000 >>> 0;
|
|
76043
76091
|
/** Minimum penetration depth to report a collision (avoids floating-point noise at corners) */
|
|
76044
76092
|
const PENETRATION_EPSILON = 1e-4;
|
|
76045
|
-
/**
|
|
76046
|
-
const
|
|
76047
|
-
|
|
76048
|
-
|
|
76049
|
-
|
|
76050
|
-
|
|
76051
|
-
|
|
76052
|
-
|
|
76053
|
-
|
|
76054
|
-
|
|
76093
|
+
/** Half-extent of the flatness sampling patch (5x5 when R=2). */
|
|
76094
|
+
const FLAT_R = 2;
|
|
76095
|
+
/** 1/sqrt(2), used to normalise 45-degree diagonal normals. */
|
|
76096
|
+
const INV_SQRT2 = 1 / Math.sqrt(2);
|
|
76097
|
+
/**
|
|
76098
|
+
* Surface normal candidate directions for querySurfaceNormal.
|
|
76099
|
+
* Each entry: [dx, dy, dz, t1x, t1y, t1z, t2x, t2y, t2z]
|
|
76100
|
+
* (dx,dy,dz) = canonical normal direction (components 0 or +/-1)
|
|
76101
|
+
* (t1,t2) = orthogonal tangent vectors spanning the perpendicular sampling plane
|
|
76102
|
+
*/
|
|
76103
|
+
const SURFACE_CANDIDATES = [
|
|
76104
|
+
// Axis-aligned
|
|
76105
|
+
[1, 0, 0, 0, 1, 0, 0, 0, 1],
|
|
76106
|
+
[0, 1, 0, 1, 0, 0, 0, 0, 1],
|
|
76107
|
+
[0, 0, 1, 1, 0, 0, 0, 1, 0],
|
|
76108
|
+
// XZ diagonals (vertical walls at 45 degrees)
|
|
76109
|
+
[1, 0, 1, 0, 1, 0, -1, 0, 1],
|
|
76110
|
+
[1, 0, -1, 0, 1, 0, 1, 0, 1],
|
|
76111
|
+
// XY diagonals (walls tilted from vertical)
|
|
76112
|
+
[1, 1, 0, 0, 0, 1, -1, 1, 0],
|
|
76113
|
+
[1, -1, 0, 0, 0, 1, 1, 1, 0],
|
|
76114
|
+
// YZ diagonals (sloped floors/ceilings)
|
|
76115
|
+
[0, 1, 1, 1, 0, 0, 0, -1, 1],
|
|
76116
|
+
[0, 1, -1, 1, 0, 0, 0, 1, 1]
|
|
76117
|
+
];
|
|
76118
|
+
/**
|
|
76119
|
+
* Score a surface candidate direction by sampling a 5x5 patch at three depth layers
|
|
76120
|
+
* shifted along the step direction. Returns the best (maximum) layer score. A "surface
|
|
76121
|
+
* hit" at each sample is a solid voxel whose neighbour in the step direction is empty.
|
|
76122
|
+
*
|
|
76123
|
+
* @param collider - The voxel collider instance.
|
|
76124
|
+
* @param ix - Voxel X index of the surface point.
|
|
76125
|
+
* @param iy - Voxel Y index of the surface point.
|
|
76126
|
+
* @param iz - Voxel Z index of the surface point.
|
|
76127
|
+
* @param sx - Step X component (camera-facing direction).
|
|
76128
|
+
* @param sy - Step Y component.
|
|
76129
|
+
* @param sz - Step Z component.
|
|
76130
|
+
* @param t1x - First tangent vector X.
|
|
76131
|
+
* @param t1y - First tangent vector Y.
|
|
76132
|
+
* @param t1z - First tangent vector Z.
|
|
76133
|
+
* @param t2x - Second tangent vector X.
|
|
76134
|
+
* @param t2y - Second tangent vector Y.
|
|
76135
|
+
* @param t2z - Second tangent vector Z.
|
|
76136
|
+
* @returns The best score across the three depth layers.
|
|
76137
|
+
*/
|
|
76138
|
+
function scoreSurfaceCandidate(collider, ix, iy, iz, sx, sy, sz, t1x, t1y, t1z, t2x, t2y, t2z) {
|
|
76139
|
+
let best = 0;
|
|
76140
|
+
for (let depth = 1; depth >= -1; depth--) {
|
|
76141
|
+
let s = 0;
|
|
76142
|
+
for (let da = -FLAT_R; da <= FLAT_R; da++) {
|
|
76143
|
+
for (let db = -FLAT_R; db <= FLAT_R; db++) {
|
|
76144
|
+
const px = ix + da * t1x + db * t2x - sx * depth;
|
|
76145
|
+
const py = iy + da * t1y + db * t2y - sy * depth;
|
|
76146
|
+
const pz = iz + da * t1z + db * t2z - sz * depth;
|
|
76147
|
+
if (collider.isVoxelSolid(px, py, pz) &&
|
|
76148
|
+
!collider.isVoxelSolid(px + sx, py + sy, pz + sz)) {
|
|
76149
|
+
s++;
|
|
76150
|
+
}
|
|
76151
|
+
}
|
|
76055
76152
|
}
|
|
76153
|
+
if (s > best)
|
|
76154
|
+
best = s;
|
|
76056
76155
|
}
|
|
76156
|
+
return best;
|
|
76057
76157
|
}
|
|
76058
76158
|
/**
|
|
76059
76159
|
* Count the number of set bits in a 32-bit integer.
|
|
@@ -76245,48 +76345,59 @@ class VoxelCollider {
|
|
|
76245
76345
|
return this.isVoxelSolid(ix, iy, iz);
|
|
76246
76346
|
}
|
|
76247
76347
|
/**
|
|
76248
|
-
* Compute a
|
|
76249
|
-
*
|
|
76250
|
-
*
|
|
76251
|
-
*
|
|
76252
|
-
*
|
|
76348
|
+
* Compute a stable surface normal at a world-space position using flatness-probability
|
|
76349
|
+
* sampling. Tests 9 candidate directions: 3 axis-aligned and 6 diagonal (45-degree in
|
|
76350
|
+
* each pair of axes). For each camera-facing candidate a 5x5 patch of voxels in the
|
|
76351
|
+
* perpendicular plane is sampled: a voxel counts as a "surface hit" if it is solid and
|
|
76352
|
+
* the adjacent voxel toward the camera is empty. The candidate with the highest hit
|
|
76353
|
+
* count is the surface orientation.
|
|
76253
76354
|
*
|
|
76254
76355
|
* @param x - World X coordinate of the surface point.
|
|
76255
76356
|
* @param y - World Y coordinate of the surface point.
|
|
76256
76357
|
* @param z - World Z coordinate of the surface point.
|
|
76257
|
-
* @
|
|
76358
|
+
* @param rdx - Ray direction X (toward the surface, in voxel space).
|
|
76359
|
+
* @param rdy - Ray direction Y.
|
|
76360
|
+
* @param rdz - Ray direction Z.
|
|
76361
|
+
* @returns Object with nx, ny, nz components of the surface normal.
|
|
76258
76362
|
*/
|
|
76259
|
-
querySurfaceNormal(x, y, z) {
|
|
76260
|
-
|
|
76261
|
-
|
|
76262
|
-
|
|
76263
|
-
|
|
76264
|
-
|
|
76265
|
-
|
|
76266
|
-
|
|
76267
|
-
|
|
76268
|
-
|
|
76269
|
-
|
|
76270
|
-
|
|
76271
|
-
|
|
76363
|
+
querySurfaceNormal(x, y, z, rdx, rdy, rdz) {
|
|
76364
|
+
// Nudge the query point slightly along the ray direction so that a hit point
|
|
76365
|
+
// sitting exactly on a voxel face boundary resolves to the solid voxel rather
|
|
76366
|
+
// than the adjacent empty one. Uses Math.sign so the nudge is independent of
|
|
76367
|
+
// ray vector magnitude.
|
|
76368
|
+
const nudge = this._voxelResolution * 0.25;
|
|
76369
|
+
const ix = Math.floor((x + Math.sign(rdx) * nudge - this._gridMinX) / this._voxelResolution);
|
|
76370
|
+
const iy = Math.floor((y + Math.sign(rdy) * nudge - this._gridMinY) / this._voxelResolution);
|
|
76371
|
+
const iz = Math.floor((z + Math.sign(rdz) * nudge - this._gridMinZ) / this._voxelResolution);
|
|
76372
|
+
const result = this._normalResult;
|
|
76373
|
+
let bestScore = -1;
|
|
76374
|
+
let bestNx = 0;
|
|
76375
|
+
let bestNy = 1;
|
|
76376
|
+
let bestNz = 0;
|
|
76377
|
+
for (let c = 0; c < SURFACE_CANDIDATES.length; c++) {
|
|
76378
|
+
const cand = SURFACE_CANDIDATES[c];
|
|
76379
|
+
const dx = cand[0];
|
|
76380
|
+
const dy = cand[1];
|
|
76381
|
+
const dz = cand[2];
|
|
76382
|
+
const dot = rdx * dx + rdy * dy + rdz * dz;
|
|
76383
|
+
if (Math.abs(dot) < 1e-6)
|
|
76384
|
+
continue;
|
|
76385
|
+
const sign = dot < 0 ? 1 : -1;
|
|
76386
|
+
const sx = dx * sign;
|
|
76387
|
+
const sy = dy * sign;
|
|
76388
|
+
const sz = dz * sign;
|
|
76389
|
+
const score = scoreSurfaceCandidate(this, ix, iy, iz, sx, sy, sz, cand[3], cand[4], cand[5], cand[6], cand[7], cand[8]);
|
|
76390
|
+
if (score > bestScore) {
|
|
76391
|
+
bestScore = score;
|
|
76392
|
+
const mag = (Math.abs(dx) + Math.abs(dy) + Math.abs(dz)) > 1 ? INV_SQRT2 : 1;
|
|
76393
|
+
bestNx = sx * mag;
|
|
76394
|
+
bestNy = sy * mag;
|
|
76395
|
+
bestNz = sz * mag;
|
|
76272
76396
|
}
|
|
76273
76397
|
}
|
|
76274
|
-
|
|
76275
|
-
|
|
76276
|
-
|
|
76277
|
-
nx *= invLen;
|
|
76278
|
-
ny *= invLen;
|
|
76279
|
-
nz *= invLen;
|
|
76280
|
-
}
|
|
76281
|
-
else {
|
|
76282
|
-
nx = 0;
|
|
76283
|
-
ny = 1;
|
|
76284
|
-
nz = 0;
|
|
76285
|
-
}
|
|
76286
|
-
const result = this._normalResult;
|
|
76287
|
-
result.nx = nx;
|
|
76288
|
-
result.ny = ny;
|
|
76289
|
-
result.nz = nz;
|
|
76398
|
+
result.nx = bestNx;
|
|
76399
|
+
result.ny = bestNy;
|
|
76400
|
+
result.nz = bestNz;
|
|
76290
76401
|
return result;
|
|
76291
76402
|
}
|
|
76292
76403
|
/**
|
|
@@ -77834,7 +77945,7 @@ const initXr = (global) => {
|
|
|
77834
77945
|
});
|
|
77835
77946
|
};
|
|
77836
77947
|
|
|
77837
|
-
var version = "1.16.
|
|
77948
|
+
var version = "1.16.13";
|
|
77838
77949
|
|
|
77839
77950
|
const loadGsplat = async (app, config, progressCallback) => {
|
|
77840
77951
|
const { contents, contentUrl, unified, aa } = config;
|