@playcanvas/supersplat-viewer 1.16.10 → 1.16.12
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 +141 -55
- 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,29 +75559,30 @@ 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);
|
|
75563
75573
|
const updateActive = () => {
|
|
75564
75574
|
this.active = state.cameraMode === 'walk' &&
|
|
75565
|
-
!state.gamingControls
|
|
75566
|
-
state.inputMode === 'desktop';
|
|
75575
|
+
!state.gamingControls;
|
|
75567
75576
|
if (!this.active) {
|
|
75568
75577
|
this.svg.style.display = 'none';
|
|
75569
75578
|
}
|
|
75570
75579
|
};
|
|
75571
75580
|
events.on('cameraMode:changed', updateActive);
|
|
75572
75581
|
events.on('gamingControls:changed', updateActive);
|
|
75573
|
-
events.on('inputMode:changed', updateActive);
|
|
75574
75582
|
events.on('walkTo', () => {
|
|
75575
75583
|
this.walking = true;
|
|
75576
75584
|
this.cursorPath.style.display = 'none';
|
|
75585
|
+
this.hasSmoothedNormal = false;
|
|
75577
75586
|
});
|
|
75578
75587
|
events.on('walkCancel', () => {
|
|
75579
75588
|
this.walking = false;
|
|
@@ -75630,6 +75639,7 @@ class WalkCursor {
|
|
|
75630
75639
|
updateCursor(offsetX, offsetY) {
|
|
75631
75640
|
if (!this.active || this.walking) {
|
|
75632
75641
|
this.cursorPath.style.display = 'none';
|
|
75642
|
+
this.hasSmoothedNormal = false;
|
|
75633
75643
|
return;
|
|
75634
75644
|
}
|
|
75635
75645
|
const { camera, collider } = this;
|
|
@@ -75639,15 +75649,36 @@ class WalkCursor {
|
|
|
75639
75649
|
const hit = collider.queryRay(-cameraPos.x, -cameraPos.y, cameraPos.z, -tmpV.x, -tmpV.y, tmpV.z, camera.camera.farClip);
|
|
75640
75650
|
if (!hit) {
|
|
75641
75651
|
this.cursorPath.style.display = 'none';
|
|
75652
|
+
this.hasSmoothedNormal = false;
|
|
75642
75653
|
return;
|
|
75643
75654
|
}
|
|
75644
75655
|
const px = -hit.x;
|
|
75645
75656
|
const py = -hit.y;
|
|
75646
75657
|
const pz = hit.z;
|
|
75647
|
-
const
|
|
75648
|
-
const
|
|
75649
|
-
const
|
|
75650
|
-
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;
|
|
75651
75682
|
this.projectCircle(px, py, pz, nx, ny, nz, CIRCLE_OUTER_RADIUS, this.outerX, this.outerY);
|
|
75652
75683
|
this.projectCircle(px, py, pz, nx, ny, nz, CIRCLE_INNER_RADIUS, this.innerX, this.innerY);
|
|
75653
75684
|
this.cursorPath.setAttribute('d', `${buildBezierRing(this.outerX, this.outerY)} ${buildBezierRing(this.innerX, this.innerY)}`);
|
|
@@ -76044,19 +76075,8 @@ class Viewer {
|
|
|
76044
76075
|
const SOLID_LEAF_MARKER = 0xFF000000 >>> 0;
|
|
76045
76076
|
/** Minimum penetration depth to report a collision (avoids floating-point noise at corners) */
|
|
76046
76077
|
const PENETRATION_EPSILON = 1e-4;
|
|
76047
|
-
/**
|
|
76048
|
-
const
|
|
76049
|
-
const normalOffsets = [];
|
|
76050
|
-
for (let dz = -NORMAL_R; dz <= NORMAL_R; dz++) {
|
|
76051
|
-
for (let dy = -NORMAL_R; dy <= NORMAL_R; dy++) {
|
|
76052
|
-
for (let dx = -NORMAL_R; dx <= NORMAL_R; dx++) {
|
|
76053
|
-
if (dx === 0 && dy === 0 && dz === 0)
|
|
76054
|
-
continue;
|
|
76055
|
-
const invLen = 1.0 / Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
76056
|
-
normalOffsets.push({ dx, dy, dz, wx: dx * invLen, wy: dy * invLen, wz: dz * invLen });
|
|
76057
|
-
}
|
|
76058
|
-
}
|
|
76059
|
-
}
|
|
76078
|
+
/** Half-extent of the flatness sampling patch (5x5 when R=2). */
|
|
76079
|
+
const FLAT_R = 2;
|
|
76060
76080
|
/**
|
|
76061
76081
|
* Count the number of set bits in a 32-bit integer.
|
|
76062
76082
|
*
|
|
@@ -76247,48 +76267,114 @@ class VoxelCollider {
|
|
|
76247
76267
|
return this.isVoxelSolid(ix, iy, iz);
|
|
76248
76268
|
}
|
|
76249
76269
|
/**
|
|
76250
|
-
* Compute a
|
|
76251
|
-
*
|
|
76252
|
-
*
|
|
76253
|
-
* the
|
|
76254
|
-
*
|
|
76270
|
+
* Compute a stable, axis-aligned surface normal at a world-space position using
|
|
76271
|
+
* flatness-probability sampling. The camera can see at most 3 axis-aligned faces of any
|
|
76272
|
+
* voxel (one per axis, determined by ray direction sign). For each candidate axis a 5x5
|
|
76273
|
+
* patch of voxels in the perpendicular plane is sampled: a voxel counts as a "surface hit"
|
|
76274
|
+
* if it is solid and the adjacent voxel toward the camera is empty. The axis with the
|
|
76275
|
+
* highest hit count is the surface orientation.
|
|
76255
76276
|
*
|
|
76256
76277
|
* @param x - World X coordinate of the surface point.
|
|
76257
76278
|
* @param y - World Y coordinate of the surface point.
|
|
76258
76279
|
* @param z - World Z coordinate of the surface point.
|
|
76259
|
-
* @
|
|
76280
|
+
* @param rdx - Ray direction X (toward the surface, in voxel space).
|
|
76281
|
+
* @param rdy - Ray direction Y.
|
|
76282
|
+
* @param rdz - Ray direction Z.
|
|
76283
|
+
* @returns Object with nx, ny, nz components of the axis-aligned surface normal.
|
|
76260
76284
|
*/
|
|
76261
|
-
querySurfaceNormal(x, y, z) {
|
|
76262
|
-
|
|
76263
|
-
|
|
76264
|
-
|
|
76265
|
-
|
|
76266
|
-
|
|
76267
|
-
|
|
76268
|
-
|
|
76269
|
-
|
|
76270
|
-
|
|
76271
|
-
|
|
76272
|
-
|
|
76273
|
-
|
|
76285
|
+
querySurfaceNormal(x, y, z, rdx, rdy, rdz) {
|
|
76286
|
+
// Nudge the query point slightly along the ray direction so that a hit point
|
|
76287
|
+
// sitting exactly on a voxel face boundary resolves to the solid voxel rather
|
|
76288
|
+
// than the adjacent empty one. Uses Math.sign so the nudge is independent of
|
|
76289
|
+
// ray vector magnitude.
|
|
76290
|
+
const nudge = this._voxelResolution * 0.25;
|
|
76291
|
+
const ix = Math.floor((x + Math.sign(rdx) * nudge - this._gridMinX) / this._voxelResolution);
|
|
76292
|
+
const iy = Math.floor((y + Math.sign(rdy) * nudge - this._gridMinY) / this._voxelResolution);
|
|
76293
|
+
const iz = Math.floor((z + Math.sign(rdz) * nudge - this._gridMinZ) / this._voxelResolution);
|
|
76294
|
+
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
|
+
let bestScore = -1;
|
|
76300
|
+
let bestNx = 0;
|
|
76301
|
+
let bestNy = 1;
|
|
76302
|
+
let bestNz = 0;
|
|
76303
|
+
// Axis X: sample 5x5 in YZ plane at x = ix ± 1
|
|
76304
|
+
if (Math.abs(rdx) > 1e-6) {
|
|
76305
|
+
let score = 0;
|
|
76306
|
+
for (let depth = 1; depth >= -1; depth--) {
|
|
76307
|
+
let s = 0;
|
|
76308
|
+
const px = ix - stepX * depth;
|
|
76309
|
+
for (let da = -FLAT_R; da <= FLAT_R; da++) {
|
|
76310
|
+
for (let db = -FLAT_R; db <= FLAT_R; db++) {
|
|
76311
|
+
if (this.isVoxelSolid(px, iy + da, iz + db) &&
|
|
76312
|
+
!this.isVoxelSolid(px + stepX, iy + da, iz + db)) {
|
|
76313
|
+
s++;
|
|
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;
|
|
76274
76325
|
}
|
|
76275
76326
|
}
|
|
76276
|
-
|
|
76277
|
-
if (
|
|
76278
|
-
|
|
76279
|
-
|
|
76280
|
-
|
|
76281
|
-
|
|
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
|
+
}
|
|
76282
76350
|
}
|
|
76283
|
-
|
|
76284
|
-
|
|
76285
|
-
|
|
76286
|
-
|
|
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
|
+
}
|
|
76368
|
+
if (score > bestScore) {
|
|
76369
|
+
bestScore = score;
|
|
76370
|
+
bestNx = 0;
|
|
76371
|
+
bestNy = 0;
|
|
76372
|
+
bestNz = stepZ;
|
|
76373
|
+
}
|
|
76287
76374
|
}
|
|
76288
|
-
|
|
76289
|
-
result.
|
|
76290
|
-
result.
|
|
76291
|
-
result.nz = nz;
|
|
76375
|
+
result.nx = bestNx;
|
|
76376
|
+
result.ny = bestNy;
|
|
76377
|
+
result.nz = bestNz;
|
|
76292
76378
|
return result;
|
|
76293
76379
|
}
|
|
76294
76380
|
/**
|
|
@@ -77836,7 +77922,7 @@ const initXr = (global) => {
|
|
|
77836
77922
|
});
|
|
77837
77923
|
};
|
|
77838
77924
|
|
|
77839
|
-
var version = "1.16.
|
|
77925
|
+
var version = "1.16.12";
|
|
77840
77926
|
|
|
77841
77927
|
const loadGsplat = async (app, config, progressCallback) => {
|
|
77842
77928
|
const { contents, contentUrl, unified, aa } = config;
|