@playcanvas/supersplat-viewer 1.16.11 → 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 +140 -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)}`);
|
|
@@ -76042,19 +76075,8 @@ class Viewer {
|
|
|
76042
76075
|
const SOLID_LEAF_MARKER = 0xFF000000 >>> 0;
|
|
76043
76076
|
/** Minimum penetration depth to report a collision (avoids floating-point noise at corners) */
|
|
76044
76077
|
const PENETRATION_EPSILON = 1e-4;
|
|
76045
|
-
/**
|
|
76046
|
-
const
|
|
76047
|
-
const normalOffsets = [];
|
|
76048
|
-
for (let dz = -NORMAL_R; dz <= NORMAL_R; dz++) {
|
|
76049
|
-
for (let dy = -NORMAL_R; dy <= NORMAL_R; dy++) {
|
|
76050
|
-
for (let dx = -NORMAL_R; dx <= NORMAL_R; dx++) {
|
|
76051
|
-
if (dx === 0 && dy === 0 && dz === 0)
|
|
76052
|
-
continue;
|
|
76053
|
-
const invLen = 1.0 / Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
76054
|
-
normalOffsets.push({ dx, dy, dz, wx: dx * invLen, wy: dy * invLen, wz: dz * invLen });
|
|
76055
|
-
}
|
|
76056
|
-
}
|
|
76057
|
-
}
|
|
76078
|
+
/** Half-extent of the flatness sampling patch (5x5 when R=2). */
|
|
76079
|
+
const FLAT_R = 2;
|
|
76058
76080
|
/**
|
|
76059
76081
|
* Count the number of set bits in a 32-bit integer.
|
|
76060
76082
|
*
|
|
@@ -76245,48 +76267,114 @@ class VoxelCollider {
|
|
|
76245
76267
|
return this.isVoxelSolid(ix, iy, iz);
|
|
76246
76268
|
}
|
|
76247
76269
|
/**
|
|
76248
|
-
* Compute a
|
|
76249
|
-
*
|
|
76250
|
-
*
|
|
76251
|
-
* the
|
|
76252
|
-
*
|
|
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.
|
|
76253
76276
|
*
|
|
76254
76277
|
* @param x - World X coordinate of the surface point.
|
|
76255
76278
|
* @param y - World Y coordinate of the surface point.
|
|
76256
76279
|
* @param z - World Z coordinate of the surface point.
|
|
76257
|
-
* @
|
|
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.
|
|
76258
76284
|
*/
|
|
76259
|
-
querySurfaceNormal(x, y, z) {
|
|
76260
|
-
|
|
76261
|
-
|
|
76262
|
-
|
|
76263
|
-
|
|
76264
|
-
|
|
76265
|
-
|
|
76266
|
-
|
|
76267
|
-
|
|
76268
|
-
|
|
76269
|
-
|
|
76270
|
-
|
|
76271
|
-
|
|
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;
|
|
76272
76325
|
}
|
|
76273
76326
|
}
|
|
76274
|
-
|
|
76275
|
-
if (
|
|
76276
|
-
|
|
76277
|
-
|
|
76278
|
-
|
|
76279
|
-
|
|
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
|
+
}
|
|
76280
76350
|
}
|
|
76281
|
-
|
|
76282
|
-
|
|
76283
|
-
|
|
76284
|
-
|
|
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
|
+
}
|
|
76285
76374
|
}
|
|
76286
|
-
|
|
76287
|
-
result.
|
|
76288
|
-
result.
|
|
76289
|
-
result.nz = nz;
|
|
76375
|
+
result.nx = bestNx;
|
|
76376
|
+
result.ny = bestNy;
|
|
76377
|
+
result.nz = bestNz;
|
|
76290
76378
|
return result;
|
|
76291
76379
|
}
|
|
76292
76380
|
/**
|
|
@@ -77834,7 +77922,7 @@ const initXr = (global) => {
|
|
|
77834
77922
|
});
|
|
77835
77923
|
};
|
|
77836
77924
|
|
|
77837
|
-
var version = "1.16.
|
|
77925
|
+
var version = "1.16.12";
|
|
77838
77926
|
|
|
77839
77927
|
const loadGsplat = async (app, config, progressCallback) => {
|
|
77840
77928
|
const { contents, contentUrl, unified, aa } = config;
|