@playcanvas/supersplat-viewer 1.16.12 → 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 +104 -81
- package/public/index.js.map +1 -1
package/package.json
CHANGED
package/public/index.js
CHANGED
|
@@ -75980,8 +75980,23 @@ class Viewer {
|
|
|
75980
75980
|
// same performance, but rotating on slow devices does not give us unsorted splats on sides
|
|
75981
75981
|
gsplat.radialSorting = true;
|
|
75982
75982
|
const eventHandler = app.systems.gsplat;
|
|
75983
|
-
//
|
|
75983
|
+
// idle timer: force continuous rendering until 4s of inactivity
|
|
75984
|
+
let idleTime = 0;
|
|
75984
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
|
+
});
|
|
75985
76000
|
let current = 0;
|
|
75986
76001
|
let watermark = 1;
|
|
75987
76002
|
const readyHandler = (camera, layer, ready, loading) => {
|
|
@@ -76077,6 +76092,69 @@ const SOLID_LEAF_MARKER = 0xFF000000 >>> 0;
|
|
|
76077
76092
|
const PENETRATION_EPSILON = 1e-4;
|
|
76078
76093
|
/** Half-extent of the flatness sampling patch (5x5 when R=2). */
|
|
76079
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
|
+
}
|
|
76152
|
+
}
|
|
76153
|
+
if (s > best)
|
|
76154
|
+
best = s;
|
|
76155
|
+
}
|
|
76156
|
+
return best;
|
|
76157
|
+
}
|
|
76080
76158
|
/**
|
|
76081
76159
|
* Count the number of set bits in a 32-bit integer.
|
|
76082
76160
|
*
|
|
@@ -76267,12 +76345,12 @@ class VoxelCollider {
|
|
|
76267
76345
|
return this.isVoxelSolid(ix, iy, iz);
|
|
76268
76346
|
}
|
|
76269
76347
|
/**
|
|
76270
|
-
* Compute a stable
|
|
76271
|
-
*
|
|
76272
|
-
*
|
|
76273
|
-
*
|
|
76274
|
-
*
|
|
76275
|
-
*
|
|
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.
|
|
76276
76354
|
*
|
|
76277
76355
|
* @param x - World X coordinate of the surface point.
|
|
76278
76356
|
* @param y - World Y coordinate of the surface point.
|
|
@@ -76280,7 +76358,7 @@ class VoxelCollider {
|
|
|
76280
76358
|
* @param rdx - Ray direction X (toward the surface, in voxel space).
|
|
76281
76359
|
* @param rdy - Ray direction Y.
|
|
76282
76360
|
* @param rdz - Ray direction Z.
|
|
76283
|
-
* @returns Object with nx, ny, nz components of the
|
|
76361
|
+
* @returns Object with nx, ny, nz components of the surface normal.
|
|
76284
76362
|
*/
|
|
76285
76363
|
querySurfaceNormal(x, y, z, rdx, rdy, rdz) {
|
|
76286
76364
|
// Nudge the query point slightly along the ray direction so that a hit point
|
|
@@ -76292,84 +76370,29 @@ class VoxelCollider {
|
|
|
76292
76370
|
const iy = Math.floor((y + Math.sign(rdy) * nudge - this._gridMinY) / this._voxelResolution);
|
|
76293
76371
|
const iz = Math.floor((z + Math.sign(rdz) * nudge - this._gridMinZ) / this._voxelResolution);
|
|
76294
76372
|
const result = this._normalResult;
|
|
76295
|
-
// For each axis, the camera-facing step is opposite to the ray direction component.
|
|
76296
|
-
const stepX = rdx < 0 ? 1 : -1;
|
|
76297
|
-
const stepY = rdy < 0 ? 1 : -1;
|
|
76298
|
-
const stepZ = rdz < 0 ? 1 : -1;
|
|
76299
76373
|
let bestScore = -1;
|
|
76300
76374
|
let bestNx = 0;
|
|
76301
76375
|
let bestNy = 1;
|
|
76302
76376
|
let bestNz = 0;
|
|
76303
|
-
|
|
76304
|
-
|
|
76305
|
-
|
|
76306
|
-
|
|
76307
|
-
|
|
76308
|
-
|
|
76309
|
-
|
|
76310
|
-
|
|
76311
|
-
|
|
76312
|
-
|
|
76313
|
-
|
|
76314
|
-
|
|
76315
|
-
|
|
76316
|
-
}
|
|
76317
|
-
if (s > score)
|
|
76318
|
-
score = s;
|
|
76319
|
-
}
|
|
76320
|
-
if (score > bestScore) {
|
|
76321
|
-
bestScore = score;
|
|
76322
|
-
bestNx = stepX;
|
|
76323
|
-
bestNy = 0;
|
|
76324
|
-
bestNz = 0;
|
|
76325
|
-
}
|
|
76326
|
-
}
|
|
76327
|
-
// Axis Y: sample 5x5 in XZ plane at y = iy ± 1
|
|
76328
|
-
if (Math.abs(rdy) > 1e-6) {
|
|
76329
|
-
let score = 0;
|
|
76330
|
-
for (let depth = 1; depth >= -1; depth--) {
|
|
76331
|
-
let s = 0;
|
|
76332
|
-
const py = iy - stepY * depth;
|
|
76333
|
-
for (let da = -FLAT_R; da <= FLAT_R; da++) {
|
|
76334
|
-
for (let db = -FLAT_R; db <= FLAT_R; db++) {
|
|
76335
|
-
if (this.isVoxelSolid(ix + da, py, iz + db) &&
|
|
76336
|
-
!this.isVoxelSolid(ix + da, py + stepY, iz + db)) {
|
|
76337
|
-
s++;
|
|
76338
|
-
}
|
|
76339
|
-
}
|
|
76340
|
-
}
|
|
76341
|
-
if (s > score)
|
|
76342
|
-
score = s;
|
|
76343
|
-
}
|
|
76344
|
-
if (score > bestScore) {
|
|
76345
|
-
bestScore = score;
|
|
76346
|
-
bestNx = 0;
|
|
76347
|
-
bestNy = stepY;
|
|
76348
|
-
bestNz = 0;
|
|
76349
|
-
}
|
|
76350
|
-
}
|
|
76351
|
-
// Axis Z: sample 5x5 in XY plane at z = iz ± 1
|
|
76352
|
-
if (Math.abs(rdz) > 1e-6) {
|
|
76353
|
-
let score = 0;
|
|
76354
|
-
for (let depth = 1; depth >= -1; depth--) {
|
|
76355
|
-
let s = 0;
|
|
76356
|
-
const pz = iz - stepZ * depth;
|
|
76357
|
-
for (let da = -FLAT_R; da <= FLAT_R; da++) {
|
|
76358
|
-
for (let db = -FLAT_R; db <= FLAT_R; db++) {
|
|
76359
|
-
if (this.isVoxelSolid(ix + da, iy + db, pz) &&
|
|
76360
|
-
!this.isVoxelSolid(ix + da, iy + db, pz + stepZ)) {
|
|
76361
|
-
s++;
|
|
76362
|
-
}
|
|
76363
|
-
}
|
|
76364
|
-
}
|
|
76365
|
-
if (s > score)
|
|
76366
|
-
score = s;
|
|
76367
|
-
}
|
|
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]);
|
|
76368
76390
|
if (score > bestScore) {
|
|
76369
76391
|
bestScore = score;
|
|
76370
|
-
|
|
76371
|
-
|
|
76372
|
-
|
|
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;
|
|
76373
76396
|
}
|
|
76374
76397
|
}
|
|
76375
76398
|
result.nx = bestNx;
|
|
@@ -77922,7 +77945,7 @@ const initXr = (global) => {
|
|
|
77922
77945
|
});
|
|
77923
77946
|
};
|
|
77924
77947
|
|
|
77925
|
-
var version = "1.16.
|
|
77948
|
+
var version = "1.16.13";
|
|
77926
77949
|
|
|
77927
77950
|
const loadGsplat = async (app, config, progressCallback) => {
|
|
77928
77951
|
const { contents, contentUrl, unified, aa } = config;
|