@playcanvas/supersplat-viewer 1.20.3 → 1.21.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/package.json +1 -1
- package/public/index.html +1 -1
- package/public/index.js +332 -37
- package/public/index.js.map +1 -1
package/package.json
CHANGED
package/public/index.html
CHANGED
|
@@ -148,7 +148,7 @@
|
|
|
148
148
|
</svg>
|
|
149
149
|
</button>
|
|
150
150
|
|
|
151
|
-
<button id="
|
|
151
|
+
<button id="showCollision" class="controlButton hidden">
|
|
152
152
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24">
|
|
153
153
|
<g class='stroke'><use href="#voxelIcon"/></g>
|
|
154
154
|
<g class='fill'><use href="#voxelIcon"/></g>
|
package/public/index.js
CHANGED
|
@@ -3684,6 +3684,7 @@ const FILTER_NEAREST_MIPMAP_LINEAR = 3;
|
|
|
3684
3684
|
const FILTER_LINEAR_MIPMAP_NEAREST = 4;
|
|
3685
3685
|
const FILTER_LINEAR_MIPMAP_LINEAR = 5;
|
|
3686
3686
|
const FUNC_LESS = 1;
|
|
3687
|
+
const FUNC_EQUAL = 2;
|
|
3687
3688
|
const FUNC_LESSEQUAL = 3;
|
|
3688
3689
|
const FUNC_ALWAYS = 7;
|
|
3689
3690
|
const INDEXFORMAT_UINT8 = 0;
|
|
@@ -75351,6 +75352,16 @@ class MeshCollision {
|
|
|
75351
75352
|
this._tris = tris;
|
|
75352
75353
|
this._root = buildBVH(tris, 0, numTris);
|
|
75353
75354
|
}
|
|
75355
|
+
// ---- Public accessors ----
|
|
75356
|
+
/**
|
|
75357
|
+
* Read-only view of the de-indexed triangle data, used by debug overlays.
|
|
75358
|
+
* The underlying typed arrays are reused and must not be mutated.
|
|
75359
|
+
*
|
|
75360
|
+
* @returns the triangle SoA backing this collision.
|
|
75361
|
+
*/
|
|
75362
|
+
get triangles() {
|
|
75363
|
+
return this._tris;
|
|
75364
|
+
}
|
|
75354
75365
|
// ---- Collision interface ----
|
|
75355
75366
|
queryRay(ox, oy, oz, dx, dy, dz, maxDist) {
|
|
75356
75367
|
const len = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
@@ -76909,7 +76920,7 @@ const initUI = (global) => {
|
|
|
76909
76920
|
'reset', 'frame',
|
|
76910
76921
|
'loadingText', 'loadingBar',
|
|
76911
76922
|
'joystickBase', 'joystick',
|
|
76912
|
-
'
|
|
76923
|
+
'showCollision',
|
|
76913
76924
|
'tooltip',
|
|
76914
76925
|
'annotationNav', 'annotationPrev', 'annotationNext', 'annotationInfo', 'annotationNavTitle',
|
|
76915
76926
|
'supersplatBranding'
|
|
@@ -77231,15 +77242,15 @@ const initUI = (global) => {
|
|
|
77231
77242
|
dom.flyCamera.classList.toggle('middle', value);
|
|
77232
77243
|
dom.flyCamera.classList.toggle('right', !value);
|
|
77233
77244
|
});
|
|
77234
|
-
//
|
|
77235
|
-
events.on('
|
|
77236
|
-
dom.
|
|
77245
|
+
// Collision overlay toggle (only visible when overlay is available)
|
|
77246
|
+
events.on('hasCollisionOverlay:changed', (value) => {
|
|
77247
|
+
dom.showCollision.classList.toggle('hidden', !value);
|
|
77237
77248
|
});
|
|
77238
|
-
dom.
|
|
77239
|
-
state.
|
|
77249
|
+
dom.showCollision.addEventListener('click', () => {
|
|
77250
|
+
state.collisionOverlayEnabled = !state.collisionOverlayEnabled;
|
|
77240
77251
|
});
|
|
77241
|
-
events.on('
|
|
77242
|
-
dom.
|
|
77252
|
+
events.on('collisionOverlayEnabled:changed', (value) => {
|
|
77253
|
+
dom.showCollision.classList.toggle('active', value);
|
|
77243
77254
|
});
|
|
77244
77255
|
dom.settings.addEventListener('click', () => {
|
|
77245
77256
|
dom.settingsPanel.classList.toggle('hidden');
|
|
@@ -77276,7 +77287,7 @@ const initUI = (global) => {
|
|
|
77276
77287
|
tooltip.register(dom.fpsCamera, 'Walk Mode', 'top');
|
|
77277
77288
|
tooltip.register(dom.reset, 'Reset Camera', 'bottom');
|
|
77278
77289
|
tooltip.register(dom.frame, 'Frame Scene', 'bottom');
|
|
77279
|
-
tooltip.register(dom.
|
|
77290
|
+
tooltip.register(dom.showCollision, 'Show Collision', 'top');
|
|
77280
77291
|
tooltip.register(dom.settings, 'Settings', 'top');
|
|
77281
77292
|
tooltip.register(dom.info, 'Help', 'top');
|
|
77282
77293
|
tooltip.register(dom.arMode, 'Enter AR', 'top');
|
|
@@ -79095,8 +79106,8 @@ class ModeShortcuts {
|
|
|
79095
79106
|
events.fire('inputEvent', 'toggleWalk');
|
|
79096
79107
|
break;
|
|
79097
79108
|
case 'v':
|
|
79098
|
-
if (state.
|
|
79099
|
-
state.
|
|
79109
|
+
if (state.hasCollisionOverlay) {
|
|
79110
|
+
state.collisionOverlayEnabled = !state.collisionOverlayEnabled;
|
|
79100
79111
|
}
|
|
79101
79112
|
break;
|
|
79102
79113
|
case 'g':
|
|
@@ -80363,6 +80374,276 @@ class InputController {
|
|
|
80363
80374
|
}
|
|
80364
80375
|
}
|
|
80365
80376
|
|
|
80377
|
+
// Single-layer overlay rendered after the gaussians, three passes on a fresh
|
|
80378
|
+
// depth buffer:
|
|
80379
|
+
//
|
|
80380
|
+
// 1. Surface depth pre-pass: color writes masked off, depth test/write on.
|
|
80381
|
+
// Stamps the front-most surface depth into the depth buffer.
|
|
80382
|
+
// 2. Surface color pass: depthFunc EQUAL, depth write off, vertex-color
|
|
80383
|
+
// tinted via StandardMaterial. Only the front-most fragment from pass 1
|
|
80384
|
+
// survives so a single layer of semi-transparent surface color blends
|
|
80385
|
+
// onto the camera target.
|
|
80386
|
+
// 3. Wireframe pass: opaque-looking black lines (RENDERSTYLE_WIREFRAME),
|
|
80387
|
+
// depth-tested against the surface depth so back-facing edges are
|
|
80388
|
+
// hidden.
|
|
80389
|
+
//
|
|
80390
|
+
// All three passes use BLEND_NORMAL so they share the layer's *transparent*
|
|
80391
|
+
// render action. PlayCanvas creates separate opaque and transparent render
|
|
80392
|
+
// actions per layer and `clearDepthBuffer` clears the depth buffer for each
|
|
80393
|
+
// of them — if the depth pre-pass were opaque, the transparent action would
|
|
80394
|
+
// wipe the depth before pass 2 and FUNC_EQUAL would always fail.
|
|
80395
|
+
// Linear gray levels picked by dominant face axis, plus the surface alpha.
|
|
80396
|
+
// These values are what we want the framebuffer to actually contain — pre-
|
|
80397
|
+
// encoding below makes that true regardless of the gamma path taken.
|
|
80398
|
+
const SURFACE_GRAY_X = 0.85;
|
|
80399
|
+
const SURFACE_GRAY_Y = 0.55;
|
|
80400
|
+
const SURFACE_GRAY_Z = 0.30;
|
|
80401
|
+
const SURFACE_ALPHA = 0.30;
|
|
80402
|
+
// Build an unindexed mesh where every triangle has three unique vertices that
|
|
80403
|
+
// share the triangle's flat face color (tint by dominant axis of the face
|
|
80404
|
+
// normal, alpha baked in). Per-triangle vertices give the surface a faceted
|
|
80405
|
+
// look matching the voxel overlay.
|
|
80406
|
+
//
|
|
80407
|
+
// `cameraFrameEnabled` controls how the per-vertex color is encoded so the
|
|
80408
|
+
// overlay looks identical between the WebGL (no CameraFrame) and
|
|
80409
|
+
// WebGPU/compute (CameraFrame) paths. With CameraFrame on, the engine's
|
|
80410
|
+
// `gammaCorrectOutput` is a no-op (GAMMA_NONE) and the StandardMaterial
|
|
80411
|
+
// output lands in the framebuffer as-is — so we feed the raw gray value.
|
|
80412
|
+
// Without CameraFrame, `gammaCorrectOutput` applies `pow(1/2.2)` to the
|
|
80413
|
+
// material output, so we feed `pow(gray, 2.2)` here and gamma-correct
|
|
80414
|
+
// undoes it; the framebuffer ends up storing the same raw gray value.
|
|
80415
|
+
// Encode the per-triangle gray + alpha into a flat Uint8 RGBA color stream
|
|
80416
|
+
// (one entry per unwelded vertex, three vertices per triangle). Reuses an
|
|
80417
|
+
// existing buffer if one is provided so colors can be re-baked when the
|
|
80418
|
+
// CameraFrame state toggles at runtime (e.g. XR start/end).
|
|
80419
|
+
const encodeFlatColors = (tris, cameraFrameEnabled, out) => {
|
|
80420
|
+
const encode = (v) => Math.round((cameraFrameEnabled ? v : Math.pow(v, 2.2)) * 255);
|
|
80421
|
+
const grayX = encode(SURFACE_GRAY_X);
|
|
80422
|
+
const grayY = encode(SURFACE_GRAY_Y);
|
|
80423
|
+
const grayZ = encode(SURFACE_GRAY_Z);
|
|
80424
|
+
const alpha = Math.round(SURFACE_ALPHA * 255);
|
|
80425
|
+
const numTris = tris.count;
|
|
80426
|
+
const colors = out ?? new Uint8Array(numTris * 12);
|
|
80427
|
+
for (let i = 0; i < numTris; i++) {
|
|
80428
|
+
const ax = Math.abs(tris.nx[i]);
|
|
80429
|
+
const ay = Math.abs(tris.ny[i]);
|
|
80430
|
+
const az = Math.abs(tris.nz[i]);
|
|
80431
|
+
let gray;
|
|
80432
|
+
if (ax > ay && ax > az) {
|
|
80433
|
+
gray = grayX;
|
|
80434
|
+
}
|
|
80435
|
+
else if (ay > az) {
|
|
80436
|
+
gray = grayY;
|
|
80437
|
+
}
|
|
80438
|
+
else {
|
|
80439
|
+
gray = grayZ;
|
|
80440
|
+
}
|
|
80441
|
+
const oc = i * 12;
|
|
80442
|
+
for (let j = 0; j < 3; j++) {
|
|
80443
|
+
const k = oc + j * 4;
|
|
80444
|
+
colors[k] = gray;
|
|
80445
|
+
colors[k + 1] = gray;
|
|
80446
|
+
colors[k + 2] = gray;
|
|
80447
|
+
colors[k + 3] = alpha;
|
|
80448
|
+
}
|
|
80449
|
+
}
|
|
80450
|
+
return colors;
|
|
80451
|
+
};
|
|
80452
|
+
const buildFlatMesh = (tris, cameraFrameEnabled) => {
|
|
80453
|
+
const numTris = tris.count;
|
|
80454
|
+
const flatPositions = new Float32Array(numTris * 9);
|
|
80455
|
+
const flatColors = encodeFlatColors(tris, cameraFrameEnabled);
|
|
80456
|
+
const flatIndices = new Uint32Array(numTris * 3);
|
|
80457
|
+
for (let i = 0; i < numTris; i++) {
|
|
80458
|
+
const op = i * 9;
|
|
80459
|
+
flatPositions[op] = tris.v0x[i];
|
|
80460
|
+
flatPositions[op + 1] = tris.v0y[i];
|
|
80461
|
+
flatPositions[op + 2] = tris.v0z[i];
|
|
80462
|
+
flatPositions[op + 3] = tris.v1x[i];
|
|
80463
|
+
flatPositions[op + 4] = tris.v1y[i];
|
|
80464
|
+
flatPositions[op + 5] = tris.v1z[i];
|
|
80465
|
+
flatPositions[op + 6] = tris.v2x[i];
|
|
80466
|
+
flatPositions[op + 7] = tris.v2y[i];
|
|
80467
|
+
flatPositions[op + 8] = tris.v2z[i];
|
|
80468
|
+
const oi = i * 3;
|
|
80469
|
+
flatIndices[oi] = oi;
|
|
80470
|
+
flatIndices[oi + 1] = oi + 1;
|
|
80471
|
+
flatIndices[oi + 2] = oi + 2;
|
|
80472
|
+
}
|
|
80473
|
+
return { flatPositions, flatColors, flatIndices };
|
|
80474
|
+
};
|
|
80475
|
+
// Configures a StandardMaterial that emits the per-vertex color directly. The
|
|
80476
|
+
// depth pre-pass and the color pass use the same configuration (so they
|
|
80477
|
+
// compile to identical shaders and produce bit-identical depth values for
|
|
80478
|
+
// FUNC_EQUAL); only their write masks and depth state differ.
|
|
80479
|
+
const makeSurfaceMaterial = () => {
|
|
80480
|
+
const m = new StandardMaterial();
|
|
80481
|
+
m.useLighting = false;
|
|
80482
|
+
m.useSkybox = false;
|
|
80483
|
+
m.useFog = false;
|
|
80484
|
+
m.useTonemap = false;
|
|
80485
|
+
m.ambient = new Color(0, 0, 0);
|
|
80486
|
+
m.diffuse = new Color(0, 0, 0);
|
|
80487
|
+
m.specular = new Color(0, 0, 0);
|
|
80488
|
+
m.emissive = new Color(1, 1, 1);
|
|
80489
|
+
m.emissiveVertexColor = true;
|
|
80490
|
+
m.emissiveVertexColorChannel = 'rgb';
|
|
80491
|
+
m.opacityVertexColor = true;
|
|
80492
|
+
m.opacityVertexColorChannel = 'a';
|
|
80493
|
+
m.opacity = 1;
|
|
80494
|
+
return m;
|
|
80495
|
+
};
|
|
80496
|
+
class MeshDebugOverlay {
|
|
80497
|
+
app;
|
|
80498
|
+
camera;
|
|
80499
|
+
layer;
|
|
80500
|
+
entity;
|
|
80501
|
+
mesh;
|
|
80502
|
+
triangles;
|
|
80503
|
+
flatColors;
|
|
80504
|
+
materials;
|
|
80505
|
+
_enabled = false;
|
|
80506
|
+
constructor(app, collision, camera, cameraFrameEnabled) {
|
|
80507
|
+
this.app = app;
|
|
80508
|
+
this.camera = camera;
|
|
80509
|
+
this.triangles = collision.triangles;
|
|
80510
|
+
const device = app.graphicsDevice;
|
|
80511
|
+
const { flatPositions, flatColors, flatIndices } = buildFlatMesh(this.triangles, cameraFrameEnabled);
|
|
80512
|
+
this.flatColors = flatColors;
|
|
80513
|
+
const mesh = new Mesh(device);
|
|
80514
|
+
mesh.setPositions(flatPositions);
|
|
80515
|
+
mesh.setColors32(flatColors);
|
|
80516
|
+
mesh.setIndices(flatIndices);
|
|
80517
|
+
mesh.update(PRIMITIVE_TRIANGLES);
|
|
80518
|
+
mesh.generateWireframe();
|
|
80519
|
+
this.mesh = mesh;
|
|
80520
|
+
this.layer = new Layer({
|
|
80521
|
+
name: 'CollisionOverlay',
|
|
80522
|
+
enabled: false,
|
|
80523
|
+
clearColorBuffer: false,
|
|
80524
|
+
clearDepthBuffer: true,
|
|
80525
|
+
opaqueSortMode: SORTMODE_MANUAL,
|
|
80526
|
+
transparentSortMode: SORTMODE_MANUAL
|
|
80527
|
+
});
|
|
80528
|
+
app.scene.layers.push(this.layer);
|
|
80529
|
+
camera.camera.layers = [...camera.camera.layers, this.layer.id];
|
|
80530
|
+
// Pass 1: depth pre-pass. Color writes masked off so only depth lands
|
|
80531
|
+
// in the buffer. Both this and pass 2 use the same depthBias /
|
|
80532
|
+
// slopeDepthBias so they write/test identical depth values
|
|
80533
|
+
// (FUNC_EQUAL relies on this) while still sitting slightly behind the
|
|
80534
|
+
// wireframe lines so pass 3's FUNC_LESSEQUAL passes reliably without
|
|
80535
|
+
// z-fighting.
|
|
80536
|
+
const depthMaterial = makeSurfaceMaterial();
|
|
80537
|
+
depthMaterial.cull = CULLFACE_BACK;
|
|
80538
|
+
depthMaterial.blendType = BLEND_NORMAL;
|
|
80539
|
+
depthMaterial.depthTest = true;
|
|
80540
|
+
depthMaterial.depthWrite = true;
|
|
80541
|
+
depthMaterial.depthBias = 1;
|
|
80542
|
+
depthMaterial.slopeDepthBias = 1;
|
|
80543
|
+
depthMaterial.redWrite = false;
|
|
80544
|
+
depthMaterial.greenWrite = false;
|
|
80545
|
+
depthMaterial.blueWrite = false;
|
|
80546
|
+
depthMaterial.alphaWrite = false;
|
|
80547
|
+
depthMaterial.update();
|
|
80548
|
+
const depthInstance = new MeshInstance(mesh, depthMaterial);
|
|
80549
|
+
depthInstance.drawOrder = 0;
|
|
80550
|
+
const depthEntity = new Entity('CollisionDepthPrepass');
|
|
80551
|
+
depthEntity.addComponent('render', {
|
|
80552
|
+
meshInstances: [depthInstance],
|
|
80553
|
+
layers: [this.layer.id]
|
|
80554
|
+
});
|
|
80555
|
+
// Pass 2: surface color, depth EQUAL. Only the front-most fragment
|
|
80556
|
+
// from pass 1 survives, so a single layer of vertex color blends onto
|
|
80557
|
+
// the camera target.
|
|
80558
|
+
const surfaceMaterial = makeSurfaceMaterial();
|
|
80559
|
+
surfaceMaterial.cull = CULLFACE_BACK;
|
|
80560
|
+
surfaceMaterial.blendType = BLEND_NORMAL;
|
|
80561
|
+
surfaceMaterial.depthTest = true;
|
|
80562
|
+
surfaceMaterial.depthFunc = FUNC_EQUAL;
|
|
80563
|
+
surfaceMaterial.depthWrite = false;
|
|
80564
|
+
surfaceMaterial.depthBias = 1;
|
|
80565
|
+
surfaceMaterial.slopeDepthBias = 1;
|
|
80566
|
+
surfaceMaterial.update();
|
|
80567
|
+
const surfaceInstance = new MeshInstance(mesh, surfaceMaterial);
|
|
80568
|
+
surfaceInstance.drawOrder = 1;
|
|
80569
|
+
const surfaceEntity = new Entity('CollisionSurface');
|
|
80570
|
+
surfaceEntity.addComponent('render', {
|
|
80571
|
+
meshInstances: [surfaceInstance],
|
|
80572
|
+
layers: [this.layer.id]
|
|
80573
|
+
});
|
|
80574
|
+
// Pass 3: wireframe — black lines depth-tested against the surface so
|
|
80575
|
+
// back-facing edges are hidden. BLEND_NORMAL with opacity = 1 looks
|
|
80576
|
+
// opaque but routes through the same transparent render action as the
|
|
80577
|
+
// other two passes, keeping all three under one depth clear.
|
|
80578
|
+
const wireframeMaterial = new StandardMaterial();
|
|
80579
|
+
wireframeMaterial.useLighting = false;
|
|
80580
|
+
wireframeMaterial.useSkybox = false;
|
|
80581
|
+
wireframeMaterial.useFog = false;
|
|
80582
|
+
wireframeMaterial.useTonemap = false;
|
|
80583
|
+
wireframeMaterial.ambient = new Color(0, 0, 0);
|
|
80584
|
+
wireframeMaterial.diffuse = new Color(0, 0, 0);
|
|
80585
|
+
wireframeMaterial.specular = new Color(0, 0, 0);
|
|
80586
|
+
wireframeMaterial.emissive = new Color(0, 0, 0);
|
|
80587
|
+
wireframeMaterial.opacity = 1;
|
|
80588
|
+
wireframeMaterial.blendType = BLEND_NORMAL;
|
|
80589
|
+
wireframeMaterial.depthTest = true;
|
|
80590
|
+
wireframeMaterial.depthFunc = FUNC_LESSEQUAL;
|
|
80591
|
+
wireframeMaterial.depthWrite = false;
|
|
80592
|
+
wireframeMaterial.cull = CULLFACE_NONE;
|
|
80593
|
+
wireframeMaterial.update();
|
|
80594
|
+
const wireframeInstance = new MeshInstance(mesh, wireframeMaterial);
|
|
80595
|
+
wireframeInstance.drawOrder = 2;
|
|
80596
|
+
const wireframeEntity = new Entity('CollisionWireframe');
|
|
80597
|
+
wireframeEntity.addComponent('render', {
|
|
80598
|
+
meshInstances: [wireframeInstance],
|
|
80599
|
+
layers: [this.layer.id]
|
|
80600
|
+
});
|
|
80601
|
+
wireframeEntity.render.renderStyle = RENDERSTYLE_WIREFRAME;
|
|
80602
|
+
this.materials = [depthMaterial, surfaceMaterial, wireframeMaterial];
|
|
80603
|
+
this.entity = new Entity('MeshCollisionDebug');
|
|
80604
|
+
this.entity.addChild(depthEntity);
|
|
80605
|
+
this.entity.addChild(surfaceEntity);
|
|
80606
|
+
this.entity.addChild(wireframeEntity);
|
|
80607
|
+
this.entity.enabled = false;
|
|
80608
|
+
app.root.addChild(this.entity);
|
|
80609
|
+
}
|
|
80610
|
+
set enabled(value) {
|
|
80611
|
+
this._enabled = value;
|
|
80612
|
+
this.entity.enabled = value;
|
|
80613
|
+
// Disable the layer too — otherwise its render actions still execute
|
|
80614
|
+
// each frame and the per-layer `clearDepthBuffer` would wipe depth
|
|
80615
|
+
// even when no overlay meshes are submitted.
|
|
80616
|
+
this.layer.enabled = value;
|
|
80617
|
+
}
|
|
80618
|
+
get enabled() {
|
|
80619
|
+
return this._enabled;
|
|
80620
|
+
}
|
|
80621
|
+
/**
|
|
80622
|
+
* Re-bake and re-upload the per-vertex colors so the overlay stays
|
|
80623
|
+
* correct if CameraFrame is destroyed or recreated at runtime (the
|
|
80624
|
+
* gamma path differs between the two states).
|
|
80625
|
+
*
|
|
80626
|
+
* @param cameraFrameEnabled - whether CameraFrame is currently active.
|
|
80627
|
+
*/
|
|
80628
|
+
setCameraFrameEnabled(cameraFrameEnabled) {
|
|
80629
|
+
encodeFlatColors(this.triangles, cameraFrameEnabled, this.flatColors);
|
|
80630
|
+
this.mesh.setColors32(this.flatColors);
|
|
80631
|
+
this.mesh.update(PRIMITIVE_TRIANGLES);
|
|
80632
|
+
}
|
|
80633
|
+
destroy() {
|
|
80634
|
+
// Entity.destroy() removes child entities and tears down their render
|
|
80635
|
+
// components, which destroy the MeshInstances and decref the shared
|
|
80636
|
+
// Mesh (the last decref destroys its GPU buffers). Materials are not
|
|
80637
|
+
// owned by MeshInstance so destroy them explicitly here.
|
|
80638
|
+
this.entity?.destroy();
|
|
80639
|
+
for (const m of this.materials)
|
|
80640
|
+
m.destroy();
|
|
80641
|
+
this.materials.length = 0;
|
|
80642
|
+
this.app.scene.layers.remove(this.layer);
|
|
80643
|
+
this.camera.camera.layers = this.camera.camera.layers.filter(id => id !== this.layer.id);
|
|
80644
|
+
}
|
|
80645
|
+
}
|
|
80646
|
+
|
|
80366
80647
|
// ---------------------------------------------------------------------------
|
|
80367
80648
|
// WGSL compute shader: ray-march through the sparse voxel octree per pixel
|
|
80368
80649
|
// ---------------------------------------------------------------------------
|
|
@@ -80377,11 +80658,12 @@ const MAX_STEPS: u32 = 512u;
|
|
|
80377
80658
|
// Target wireframe edge width in pixels
|
|
80378
80659
|
const EDGE_PIXELS: f32 = 1.5;
|
|
80379
80660
|
|
|
80380
|
-
// Wireframe edge alpha
|
|
80381
|
-
|
|
80661
|
+
// Wireframe edge alpha (1.0 = pure black opaque edges, matching the mesh
|
|
80662
|
+
// overlay's wireframe pass).
|
|
80663
|
+
const EDGE_ALPHA: f32 = 0.8;
|
|
80382
80664
|
|
|
80383
|
-
// Interior fill alpha (
|
|
80384
|
-
const FILL_ALPHA: f32 = 0.
|
|
80665
|
+
// Interior fill alpha (matching the mesh overlay's surface alpha).
|
|
80666
|
+
const FILL_ALPHA: f32 = 0.30;
|
|
80385
80667
|
|
|
80386
80668
|
struct Uniforms {
|
|
80387
80669
|
invVP: mat4x4<f32>,
|
|
@@ -80490,14 +80772,16 @@ fn edgeFactor(hitPos: vec3f, voxMin: vec3f, voxSize: f32, edgeWidth: f32) -> f32
|
|
|
80490
80772
|
return 1.0 - smoothstep(0.0, edgeWidth, edgeDist);
|
|
80491
80773
|
}
|
|
80492
80774
|
|
|
80493
|
-
// Shade a voxel hit, returning premultiplied RGBA
|
|
80494
|
-
|
|
80775
|
+
// Shade a voxel hit, returning premultiplied RGBA. Uses the same face-axis
|
|
80776
|
+
// grayscale palette as the mesh collision overlay (0.85 / 0.55 / 0.30 by
|
|
80777
|
+
// dominant axis), with pure black at face edges to mimic that overlay's
|
|
80778
|
+
// wireframe pass.
|
|
80779
|
+
fn shadeVoxelHit(hitPos: vec3f, voxMin: vec3f, voxelRes: f32, ro: vec3f) -> vec4f {
|
|
80495
80780
|
let dist = length(hitPos - ro);
|
|
80496
80781
|
let pixelWorld = 2.0 * dist / (f32(uniforms.screenHeight) * uniforms.projScaleY);
|
|
80497
80782
|
let ew = clamp(EDGE_PIXELS * pixelWorld / voxelRes, 0.01, 0.5);
|
|
80498
80783
|
|
|
80499
80784
|
let ef = edgeFactor(hitPos, voxMin, voxelRes, ew);
|
|
80500
|
-
let distFade = clamp(1.0 - dist * 0.01, 0.2, 1.0);
|
|
80501
80785
|
|
|
80502
80786
|
let local = (hitPos - voxMin) / voxelRes;
|
|
80503
80787
|
let fx = min(local.x, 1.0 - local.x);
|
|
@@ -80512,19 +80796,17 @@ fn shadeVoxelHit(hitPos: vec3f, voxMin: vec3f, voxelRes: f32, ro: vec3f, isFullB
|
|
|
80512
80796
|
}
|
|
80513
80797
|
|
|
80514
80798
|
var baseColor: vec3f;
|
|
80515
|
-
if (
|
|
80516
|
-
|
|
80517
|
-
|
|
80518
|
-
else { baseColor = vec3f(0.55, 0.08, 0.05); }
|
|
80519
|
-
} else {
|
|
80520
|
-
if (faceAxis == 0u) { baseColor = vec3f(0.7, 0.7, 0.72); }
|
|
80521
|
-
else if (faceAxis == 1u) { baseColor = vec3f(0.5, 0.5, 0.52); }
|
|
80522
|
-
else { baseColor = vec3f(0.33, 0.33, 0.35); }
|
|
80523
|
-
}
|
|
80799
|
+
if (faceAxis == 0u) { baseColor = vec3f(0.85); }
|
|
80800
|
+
else if (faceAxis == 1u) { baseColor = vec3f(0.55); }
|
|
80801
|
+
else { baseColor = vec3f(0.30); }
|
|
80524
80802
|
|
|
80525
|
-
|
|
80803
|
+
// Mix the surface base color toward black as the edge factor approaches 1
|
|
80804
|
+
// and ramp alpha from FILL_ALPHA up to EDGE_ALPHA so face edges read as
|
|
80805
|
+
// opaque black lines while the interior stays at the surface tint.
|
|
80806
|
+
let color = mix(baseColor, vec3f(0.0), ef);
|
|
80807
|
+
let alpha = mix(FILL_ALPHA, EDGE_ALPHA, ef);
|
|
80526
80808
|
|
|
80527
|
-
return vec4f(
|
|
80809
|
+
return vec4f(color * alpha, alpha);
|
|
80528
80810
|
}
|
|
80529
80811
|
|
|
80530
80812
|
// Blue (0) -> Cyan (0.25) -> Green (0.5) -> Yellow (0.75) -> Red (1.0)
|
|
@@ -80721,8 +81003,7 @@ fn main(@builtin(global_invocation_id) gid: vec3u) {
|
|
|
80721
81003
|
let voxMin = blockOrigin + vec3f(f32(vx), f32(vy), f32(vz)) * voxelRes;
|
|
80722
81004
|
let vHit = intersectAABB(ro, invDir, voxMin, voxMin + vec3f(voxelRes));
|
|
80723
81005
|
let hitPos = ro + rd * max(vHit.x, 0.0);
|
|
80724
|
-
let
|
|
80725
|
-
let result = shadeVoxelHit(hitPos, voxMin, voxelRes, ro, isFullBlock);
|
|
81006
|
+
let result = shadeVoxelHit(hitPos, voxMin, voxelRes, ro);
|
|
80726
81007
|
textureStore(outputTexture, vec2i(px, py), result);
|
|
80727
81008
|
} else {
|
|
80728
81009
|
let effort = f32(totalWork) / 256.0;
|
|
@@ -81324,6 +81605,7 @@ class Viewer {
|
|
|
81324
81605
|
annotations;
|
|
81325
81606
|
forceRenderNextFrame = false;
|
|
81326
81607
|
voxelOverlay = null;
|
|
81608
|
+
meshOverlay = null;
|
|
81327
81609
|
walkCursor = null;
|
|
81328
81610
|
origChunks;
|
|
81329
81611
|
constructor(global, gsplatLoad, skyboxLoad, collisionLoad) {
|
|
@@ -81471,16 +81753,25 @@ class Viewer {
|
|
|
81471
81753
|
this.inputController = new InputController(global);
|
|
81472
81754
|
this.inputController.collision = collision ?? null;
|
|
81473
81755
|
state.hasCollision = !!collision;
|
|
81474
|
-
// Create
|
|
81756
|
+
// Create collision debug overlay (voxel uses a compute shader, mesh
|
|
81757
|
+
// uses standard line rendering). The voxel path requires WebGPU.
|
|
81475
81758
|
if (collision instanceof VoxelCollision && config.renderer !== 'webgl') {
|
|
81476
81759
|
this.voxelOverlay = new VoxelDebugOverlay(app, collision, camera);
|
|
81477
81760
|
this.voxelOverlay.mode = config.heatmap ? 'heatmap' : 'overlay';
|
|
81478
|
-
state.
|
|
81479
|
-
events.on('
|
|
81761
|
+
state.hasCollisionOverlay = true;
|
|
81762
|
+
events.on('collisionOverlayEnabled:changed', (value) => {
|
|
81480
81763
|
this.voxelOverlay.enabled = value;
|
|
81481
81764
|
app.renderNextFrame = true;
|
|
81482
81765
|
});
|
|
81483
81766
|
}
|
|
81767
|
+
else if (collision instanceof MeshCollision) {
|
|
81768
|
+
this.meshOverlay = new MeshDebugOverlay(app, collision, camera, !!this.cameraFrame);
|
|
81769
|
+
state.hasCollisionOverlay = true;
|
|
81770
|
+
events.on('collisionOverlayEnabled:changed', (value) => {
|
|
81771
|
+
this.meshOverlay.enabled = value;
|
|
81772
|
+
app.renderNextFrame = true;
|
|
81773
|
+
});
|
|
81774
|
+
}
|
|
81484
81775
|
this.cameraManager = new CameraManager(global, sceneBound, collision);
|
|
81485
81776
|
applyCamera(this.cameraManager.camera);
|
|
81486
81777
|
if (collision) {
|
|
@@ -81659,6 +81950,10 @@ class Viewer {
|
|
|
81659
81950
|
camera.camera.clearColor = new Color(background.color);
|
|
81660
81951
|
}
|
|
81661
81952
|
}
|
|
81953
|
+
// Mesh overlay bakes its vertex colors based on the current gamma
|
|
81954
|
+
// path; reapply when CameraFrame is created/destroyed (e.g. on XR
|
|
81955
|
+
// start/end) so the overlay tracks the new path.
|
|
81956
|
+
this.meshOverlay?.setCameraFrameEnabled(!!this.cameraFrame);
|
|
81662
81957
|
}
|
|
81663
81958
|
}
|
|
81664
81959
|
|
|
@@ -82568,7 +82863,7 @@ const initXr = (global) => {
|
|
|
82568
82863
|
});
|
|
82569
82864
|
};
|
|
82570
82865
|
|
|
82571
|
-
var version = "1.
|
|
82866
|
+
var version = "1.21.0";
|
|
82572
82867
|
|
|
82573
82868
|
const loadGsplat = async (app, config, progressCallback) => {
|
|
82574
82869
|
const { contents, contentUrl, aa } = config;
|
|
@@ -82736,8 +83031,8 @@ const main = async (canvas, settingsJson, config) => {
|
|
|
82736
83031
|
hasAR: false,
|
|
82737
83032
|
hasVR: false,
|
|
82738
83033
|
hasCollision: false,
|
|
82739
|
-
|
|
82740
|
-
|
|
83034
|
+
hasCollisionOverlay: false,
|
|
83035
|
+
collisionOverlayEnabled: false,
|
|
82741
83036
|
isFullscreen: false,
|
|
82742
83037
|
controlsHidden: false,
|
|
82743
83038
|
gamingControls: localStorage.getItem('gamingControls') === 'true'
|