@playcanvas/supersplat-viewer 1.9.1 → 1.10.1
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/README.md +12 -9
- package/dist/index.js +2 -2
- package/package.json +4 -4
- package/public/index.html +1 -0
- package/public/index.js +807 -257
- package/public/index.js.map +1 -1
package/public/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const TRACEID_GPU_TIMINGS = 'GpuTimings';
|
|
2
2
|
|
|
3
|
-
const version$1 = '2.
|
|
4
|
-
const revision = '
|
|
3
|
+
const version$1 = '2.14.2';
|
|
4
|
+
const revision = '8820645';
|
|
5
5
|
function extend(target, ex) {
|
|
6
6
|
for(const prop in ex){
|
|
7
7
|
const copy = ex[prop];
|
|
@@ -11955,6 +11955,9 @@ class WebgpuGraphicsDevice extends GraphicsDevice {
|
|
|
11955
11955
|
}
|
|
11956
11956
|
return true;
|
|
11957
11957
|
}
|
|
11958
|
+
get hasTranspilers() {
|
|
11959
|
+
return this.glslang && this.twgsl;
|
|
11960
|
+
}
|
|
11958
11961
|
}
|
|
11959
11962
|
|
|
11960
11963
|
class WebglBuffer {
|
|
@@ -14566,6 +14569,7 @@ class WebglGraphicsDevice extends GraphicsDevice {
|
|
|
14566
14569
|
const data = options.data ?? new (getPixelFormatArrayType(texture._format))(buffer);
|
|
14567
14570
|
this.setRenderTarget(renderTarget);
|
|
14568
14571
|
this.initRenderTarget(renderTarget);
|
|
14572
|
+
this.setFramebuffer(renderTarget.impl._glFrameBuffer);
|
|
14569
14573
|
return new Promise((resolve, reject)=>{
|
|
14570
14574
|
this.readPixelsAsync(x, y, width, height, data).then((data)=>{
|
|
14571
14575
|
if (this._destroyed) return;
|
|
@@ -17361,6 +17365,7 @@ const SHADER_FORWARD = 0;
|
|
|
17361
17365
|
const SHADER_PREPASS = 1;
|
|
17362
17366
|
const SHADER_SHADOW = 2;
|
|
17363
17367
|
const SHADER_PICK = 3;
|
|
17368
|
+
const SHADER_DEPTH_PICK = 4;
|
|
17364
17369
|
const SPRITE_RENDERMODE_SIMPLE = 0;
|
|
17365
17370
|
const SPRITE_RENDERMODE_SLICED = 1;
|
|
17366
17371
|
const SPRITE_RENDERMODE_TILED = 2;
|
|
@@ -17475,6 +17480,9 @@ class ShaderPassInfo {
|
|
|
17475
17480
|
keyword = 'FORWARD';
|
|
17476
17481
|
} else if (this.index === SHADER_PICK) {
|
|
17477
17482
|
keyword = 'PICK';
|
|
17483
|
+
} else if (this.index === SHADER_DEPTH_PICK) {
|
|
17484
|
+
keyword = 'PICK';
|
|
17485
|
+
this.defines.set('DEPTH_PICK_PASS', '');
|
|
17478
17486
|
}
|
|
17479
17487
|
this.defines.set(`${keyword}_PASS`, '');
|
|
17480
17488
|
this.defines.set(`${this.name.toUpperCase()}_PASS`, '');
|
|
@@ -17494,6 +17502,7 @@ class ShaderPass {
|
|
|
17494
17502
|
add('prepass');
|
|
17495
17503
|
add('shadow');
|
|
17496
17504
|
add('pick');
|
|
17505
|
+
add('depth_pick');
|
|
17497
17506
|
}
|
|
17498
17507
|
static get(device) {
|
|
17499
17508
|
return shaderPassDeviceCache.get(device, ()=>{
|
|
@@ -19936,7 +19945,8 @@ class CameraShaderParams {
|
|
|
19936
19945
|
if (this._definesDirty) {
|
|
19937
19946
|
this._definesDirty = false;
|
|
19938
19947
|
defines.clear();
|
|
19939
|
-
if (this._sceneDepthMapLinear) defines.set('SCENE_DEPTHMAP_LINEAR',
|
|
19948
|
+
if (this._sceneDepthMapLinear) defines.set('SCENE_DEPTHMAP_LINEAR', '');
|
|
19949
|
+
if (this.shaderOutputGamma === GAMMA_SRGB) defines.set('SCENE_COLORMAP_GAMMA', '');
|
|
19940
19950
|
defines.set('FOG', this._fog.toUpperCase());
|
|
19941
19951
|
defines.set('TONEMAP', tonemapNames[this._toneMapping]);
|
|
19942
19952
|
defines.set('GAMMA', gammaNames[this.shaderOutputGamma]);
|
|
@@ -28822,6 +28832,10 @@ class GSplatParams {
|
|
|
28822
28832
|
get lodUnderfillLimit() {
|
|
28823
28833
|
return this._lodUnderfillLimit;
|
|
28824
28834
|
}
|
|
28835
|
+
set splatBudget(value) {}
|
|
28836
|
+
get splatBudget() {
|
|
28837
|
+
return 0;
|
|
28838
|
+
}
|
|
28825
28839
|
set colorRamp(value) {
|
|
28826
28840
|
if (this._colorRamp !== value) {
|
|
28827
28841
|
this._colorRamp = value;
|
|
@@ -28850,6 +28864,7 @@ class GSplatParams {
|
|
|
28850
28864
|
this.colorUpdateAngle = 2;
|
|
28851
28865
|
this.colorUpdateDistanceLodScale = 2;
|
|
28852
28866
|
this.colorUpdateAngleLodScale = 2;
|
|
28867
|
+
this.cooldownTicks = 100;
|
|
28853
28868
|
}
|
|
28854
28869
|
}
|
|
28855
28870
|
|
|
@@ -31350,6 +31365,7 @@ class LitShaderOptions {
|
|
|
31350
31365
|
this.clusteredLightingShadowType = 0;
|
|
31351
31366
|
this.clusteredLightingAreaLightsEnabled = false;
|
|
31352
31367
|
this.vertexColors = false;
|
|
31368
|
+
this.useVertexColorGamma = false;
|
|
31353
31369
|
this.lightMapEnabled = false;
|
|
31354
31370
|
this.dirLightMapEnabled = false;
|
|
31355
31371
|
this.useHeights = false;
|
|
@@ -31554,7 +31570,10 @@ class LitShader {
|
|
|
31554
31570
|
this.device = device;
|
|
31555
31571
|
this.options = options;
|
|
31556
31572
|
const userChunks = options.shaderChunks;
|
|
31557
|
-
this.shaderLanguage = device.isWebGPU && allowWGSL && userChunks
|
|
31573
|
+
this.shaderLanguage = device.isWebGPU && allowWGSL && (!userChunks || userChunks.useWGSL) ? SHADERLANGUAGE_WGSL : SHADERLANGUAGE_GLSL;
|
|
31574
|
+
if (device.isWebGPU && this.shaderLanguage === SHADERLANGUAGE_GLSL) {
|
|
31575
|
+
if (!device.hasTranspilers) ;
|
|
31576
|
+
}
|
|
31558
31577
|
this.attributes = {
|
|
31559
31578
|
vertex_position: SEMANTIC_POSITION
|
|
31560
31579
|
};
|
|
@@ -31658,6 +31677,9 @@ class LitShader {
|
|
|
31658
31677
|
attributes.vertex_color = SEMANTIC_COLOR;
|
|
31659
31678
|
vDefines.set('VERTEX_COLOR', true);
|
|
31660
31679
|
varyings.set('vVertexColor', 'vec4');
|
|
31680
|
+
if (options.useVertexColorGamma) {
|
|
31681
|
+
vDefines.set('STD_VERTEX_COLOR_GAMMA', '');
|
|
31682
|
+
}
|
|
31661
31683
|
}
|
|
31662
31684
|
if (options.useMsdf && options.msdfTextAttribute) {
|
|
31663
31685
|
attributes.vertex_outlineParameters = SEMANTIC_ATTR8;
|
|
@@ -31876,6 +31898,7 @@ class StandardMaterialOptions {
|
|
|
31876
31898
|
this.glossTint = false;
|
|
31877
31899
|
this.emissiveEncoding = 'linear';
|
|
31878
31900
|
this.lightMapEncoding = 'linear';
|
|
31901
|
+
this.vertexColorGamma = false;
|
|
31879
31902
|
this.packedNormal = false;
|
|
31880
31903
|
this.normalDetailPackedNormal = false;
|
|
31881
31904
|
this.clearCoatPackedNormal = false;
|
|
@@ -31928,7 +31951,7 @@ class ShaderGeneratorStandard extends ShaderGenerator {
|
|
|
31928
31951
|
}
|
|
31929
31952
|
return expression;
|
|
31930
31953
|
}
|
|
31931
|
-
_validateMapChunk(propName, chunkName, chunks) {}
|
|
31954
|
+
_validateMapChunk(code, propName, chunkName, chunks) {}
|
|
31932
31955
|
_addMapDefines(fDefines, propName, chunkName, options, chunks, mapping, encoding = null) {
|
|
31933
31956
|
const mapPropName = `${propName}Map`;
|
|
31934
31957
|
const propNameCaps = propName.toUpperCase();
|
|
@@ -32363,6 +32386,7 @@ class StandardMaterialOptionsBuilder {
|
|
|
32363
32386
|
options.litOptions.useDynamicRefraction = stdMat.useDynamicRefraction;
|
|
32364
32387
|
options.litOptions.dispersion = stdMat.dispersion > 0;
|
|
32365
32388
|
options.litOptions.shadowCatcher = stdMat.shadowCatcher;
|
|
32389
|
+
options.litOptions.useVertexColorGamma = stdMat.vertexColorGamma;
|
|
32366
32390
|
}
|
|
32367
32391
|
_updateEnvOptions(options, stdMat, scene, cameraShaderParams) {
|
|
32368
32392
|
options.litOptions.fog = stdMat.useFog ? cameraShaderParams.fog : FOG_NONE;
|
|
@@ -32504,6 +32528,7 @@ const standardMaterialParameterTypes = {
|
|
|
32504
32528
|
..._textureParameter('diffuse'),
|
|
32505
32529
|
..._textureParameter('diffuseDetail', true, false),
|
|
32506
32530
|
diffuseDetailMode: 'string',
|
|
32531
|
+
vertexColorGamma: 'boolean',
|
|
32507
32532
|
specular: 'rgb',
|
|
32508
32533
|
specularTint: 'boolean',
|
|
32509
32534
|
..._textureParameter('specular'),
|
|
@@ -33109,6 +33134,7 @@ function _defineMaterialProps() {
|
|
|
33109
33134
|
_defineFlag('opacityDither', DITHER_NONE);
|
|
33110
33135
|
_defineFlag('opacityShadowDither', DITHER_NONE);
|
|
33111
33136
|
_defineFlag('shadowCatcher', false);
|
|
33137
|
+
_defineFlag('vertexColorGamma', false);
|
|
33112
33138
|
_defineTex2D('diffuse');
|
|
33113
33139
|
_defineTex2D('specular');
|
|
33114
33140
|
_defineTex2D('emissive');
|
|
@@ -34391,6 +34417,7 @@ class GSplatResourceBase {
|
|
|
34391
34417
|
constructor(device, gsplatData){
|
|
34392
34418
|
this.id = id++;
|
|
34393
34419
|
this.workBufferRenderInfos = new Map();
|
|
34420
|
+
this._refCount = 0;
|
|
34394
34421
|
this.device = device;
|
|
34395
34422
|
this.gsplatData = gsplatData;
|
|
34396
34423
|
this.centers = gsplatData.getCenters();
|
|
@@ -34407,6 +34434,15 @@ class GSplatResourceBase {
|
|
|
34407
34434
|
this.workBufferRenderInfos.forEach((info)=>info.destroy());
|
|
34408
34435
|
this.workBufferRenderInfos.clear();
|
|
34409
34436
|
}
|
|
34437
|
+
incRefCount() {
|
|
34438
|
+
this._refCount++;
|
|
34439
|
+
}
|
|
34440
|
+
decRefCount() {
|
|
34441
|
+
this._refCount--;
|
|
34442
|
+
}
|
|
34443
|
+
get refCount() {
|
|
34444
|
+
return this._refCount;
|
|
34445
|
+
}
|
|
34410
34446
|
getWorkBufferRenderInfo(useIntervals, colorTextureFormat, colorOnly = false) {
|
|
34411
34447
|
this.configureMaterialDefines(tempMap);
|
|
34412
34448
|
if (useIntervals) tempMap.set('GSPLAT_LOD', '');
|
|
@@ -35646,6 +35682,8 @@ class GSplatSogsData {
|
|
|
35646
35682
|
this.packedShN?.destroy();
|
|
35647
35683
|
}
|
|
35648
35684
|
destroy() {
|
|
35685
|
+
this.deviceRestoredEvent?.off();
|
|
35686
|
+
this.deviceRestoredEvent = null;
|
|
35649
35687
|
this.destroyed = true;
|
|
35650
35688
|
this._destroyGpuResources();
|
|
35651
35689
|
}
|
|
@@ -35672,12 +35710,7 @@ class GSplatSogsData {
|
|
|
35672
35710
|
return true;
|
|
35673
35711
|
}
|
|
35674
35712
|
get shBands() {
|
|
35675
|
-
|
|
35676
|
-
192: 1,
|
|
35677
|
-
512: 2,
|
|
35678
|
-
960: 3
|
|
35679
|
-
};
|
|
35680
|
-
return widths[this.sh_centroids?.width] ?? 0;
|
|
35713
|
+
return this._shBands;
|
|
35681
35714
|
}
|
|
35682
35715
|
async decompress() {
|
|
35683
35716
|
const members = [
|
|
@@ -35921,35 +35954,45 @@ class GSplatSogsData {
|
|
|
35921
35954
|
renderTarget.destroy();
|
|
35922
35955
|
}
|
|
35923
35956
|
async prepareGpuData() {
|
|
35924
|
-
|
|
35925
|
-
|
|
35957
|
+
let device = this.means_l.device;
|
|
35958
|
+
const { height, width } = this.means_l;
|
|
35959
|
+
if (this.destroyed || !device || device._destroyed) return;
|
|
35960
|
+
const shBandsWidths = {
|
|
35961
|
+
192: 1,
|
|
35962
|
+
512: 2,
|
|
35963
|
+
960: 3
|
|
35964
|
+
};
|
|
35965
|
+
this._shBands = shBandsWidths[this.sh_centroids?.width] ?? 0;
|
|
35966
|
+
const urlSuffix = this.url ? `_${this.url}` : '';
|
|
35926
35967
|
this.packedTexture = new Texture(device, {
|
|
35927
|
-
name:
|
|
35968
|
+
name: `sogsPackedTexture${urlSuffix}`,
|
|
35928
35969
|
width,
|
|
35929
35970
|
height,
|
|
35930
35971
|
format: PIXELFORMAT_RGBA32U,
|
|
35931
35972
|
mipmaps: false
|
|
35932
35973
|
});
|
|
35933
35974
|
this.packedSh0 = new Texture(device, {
|
|
35934
|
-
name:
|
|
35975
|
+
name: `sogsPackedSh0${urlSuffix}`,
|
|
35935
35976
|
width,
|
|
35936
35977
|
height,
|
|
35937
35978
|
format: PIXELFORMAT_RGBA8,
|
|
35938
35979
|
mipmaps: false
|
|
35939
35980
|
});
|
|
35940
35981
|
this.packedShN = this.sh_centroids && new Texture(device, {
|
|
35941
|
-
name:
|
|
35982
|
+
name: `sogsPackedShN${urlSuffix}`,
|
|
35942
35983
|
width: this.sh_centroids.width,
|
|
35943
35984
|
height: this.sh_centroids.height,
|
|
35944
35985
|
format: PIXELFORMAT_RGBA8,
|
|
35945
35986
|
mipmaps: false
|
|
35946
35987
|
});
|
|
35947
|
-
|
|
35948
|
-
this.
|
|
35949
|
-
|
|
35950
|
-
this.
|
|
35951
|
-
|
|
35952
|
-
|
|
35988
|
+
if (!this.minimalMemory) {
|
|
35989
|
+
this.deviceRestoredEvent = device.on('devicerestored', ()=>{
|
|
35990
|
+
this.packGpuMemory();
|
|
35991
|
+
if (this.packedShN) {
|
|
35992
|
+
this.packShMemory();
|
|
35993
|
+
}
|
|
35994
|
+
});
|
|
35995
|
+
}
|
|
35953
35996
|
[
|
|
35954
35997
|
'scales',
|
|
35955
35998
|
'sh0',
|
|
@@ -35960,21 +36003,44 @@ class GSplatSogsData {
|
|
|
35960
36003
|
codebook[0] = codebook[1] + (codebook[1] - codebook[255]) / 255;
|
|
35961
36004
|
}
|
|
35962
36005
|
});
|
|
35963
|
-
|
|
36006
|
+
device = this.means_l?.device;
|
|
36007
|
+
if (this.destroyed || !device || device._destroyed) return;
|
|
35964
36008
|
await this.generateCenters();
|
|
35965
|
-
|
|
36009
|
+
device = this.means_l?.device;
|
|
36010
|
+
if (this.destroyed || !device || device._destroyed) return;
|
|
35966
36011
|
this.packGpuMemory();
|
|
35967
36012
|
if (this.packedShN) {
|
|
35968
|
-
|
|
36013
|
+
device = this.means_l?.device;
|
|
36014
|
+
if (this.destroyed || !device || device._destroyed) return;
|
|
35969
36015
|
this.packShMemory();
|
|
35970
36016
|
}
|
|
36017
|
+
if (this.minimalMemory) {
|
|
36018
|
+
this.means_l?.destroy();
|
|
36019
|
+
this.means_u?.destroy();
|
|
36020
|
+
this.quats?.destroy();
|
|
36021
|
+
this.scales?.destroy();
|
|
36022
|
+
this.sh0?.destroy();
|
|
36023
|
+
this.sh_centroids?.destroy();
|
|
36024
|
+
this.sh_labels?.destroy();
|
|
36025
|
+
this.means_l = null;
|
|
36026
|
+
this.means_u = null;
|
|
36027
|
+
this.quats = null;
|
|
36028
|
+
this.scales = null;
|
|
36029
|
+
this.sh0 = null;
|
|
36030
|
+
this.sh_centroids = null;
|
|
36031
|
+
this.sh_labels = null;
|
|
36032
|
+
}
|
|
35971
36033
|
}
|
|
35972
36034
|
reorderData() {
|
|
35973
36035
|
return this.prepareGpuData();
|
|
35974
36036
|
}
|
|
35975
36037
|
constructor(){
|
|
36038
|
+
this.url = '';
|
|
36039
|
+
this.minimalMemory = false;
|
|
36040
|
+
this.deviceRestoredEvent = null;
|
|
35976
36041
|
this._centers = null;
|
|
35977
36042
|
this.destroyed = false;
|
|
36043
|
+
this._shBands = 0;
|
|
35978
36044
|
}
|
|
35979
36045
|
}
|
|
35980
36046
|
|
|
@@ -36923,6 +36989,9 @@ class AssetRegistry extends EventHandler {
|
|
|
36923
36989
|
super(), this._assets = new Set(), this._idToAsset = new Map(), this._urlToAsset = new Map(), this._nameToAsset = new Map(), this._tags = new TagsCache('id'), this.prefix = null, this.bundles = null;
|
|
36924
36990
|
this._loader = loader;
|
|
36925
36991
|
}
|
|
36992
|
+
get loader() {
|
|
36993
|
+
return this._loader;
|
|
36994
|
+
}
|
|
36926
36995
|
list(filters = {}) {
|
|
36927
36996
|
const assets = Array.from(this._assets);
|
|
36928
36997
|
if (filters.preload !== undefined) {
|
|
@@ -37045,7 +37114,9 @@ class AssetRegistry extends EventHandler {
|
|
|
37045
37114
|
if (handler._cache[asset.id] && handler._cache[asset.id].parentNode === document.head) {
|
|
37046
37115
|
document.head.removeChild(handler._cache[asset.id]);
|
|
37047
37116
|
}
|
|
37048
|
-
|
|
37117
|
+
if (extra) {
|
|
37118
|
+
handler._cache[asset.id] = extra;
|
|
37119
|
+
}
|
|
37049
37120
|
}
|
|
37050
37121
|
_opened(resource);
|
|
37051
37122
|
}
|
|
@@ -37235,6 +37306,7 @@ class AssetRegistry extends EventHandler {
|
|
|
37235
37306
|
if (!type) return results;
|
|
37236
37307
|
return results.filter((asset)=>asset.type === type);
|
|
37237
37308
|
}
|
|
37309
|
+
log() {}
|
|
37238
37310
|
}
|
|
37239
37311
|
|
|
37240
37312
|
class BundleRegistry {
|
|
@@ -39828,7 +39900,7 @@ void getAlbedo() {
|
|
|
39828
39900
|
dAlbedo *= albedoTexture;
|
|
39829
39901
|
#endif
|
|
39830
39902
|
#ifdef STD_DIFFUSE_VERTEX
|
|
39831
|
-
dAlbedo *=
|
|
39903
|
+
dAlbedo *= saturate(vVertexColor.{STD_DIFFUSE_VERTEX_CHANNEL});
|
|
39832
39904
|
#endif
|
|
39833
39905
|
}
|
|
39834
39906
|
`;
|
|
@@ -39842,7 +39914,7 @@ void getEmission() {
|
|
|
39842
39914
|
dEmission *= {STD_EMISSIVE_TEXTURE_DECODE}(texture2DBias({STD_EMISSIVE_TEXTURE_NAME}, {STD_EMISSIVE_TEXTURE_UV}, textureBias)).{STD_EMISSIVE_TEXTURE_CHANNEL};
|
|
39843
39915
|
#endif
|
|
39844
39916
|
#ifdef STD_EMISSIVE_VERTEX
|
|
39845
|
-
dEmission *=
|
|
39917
|
+
dEmission *= saturate(vVertexColor.{STD_EMISSIVE_VERTEX_CHANNEL});
|
|
39846
39918
|
#endif
|
|
39847
39919
|
}
|
|
39848
39920
|
`;
|
|
@@ -41310,6 +41382,14 @@ mat4 dModelMatrix;
|
|
|
41310
41382
|
#include "msdfVS"
|
|
41311
41383
|
#endif
|
|
41312
41384
|
#include "litUserCodeVS"
|
|
41385
|
+
#ifdef VERTEX_COLOR
|
|
41386
|
+
vec3 decodeGamma(vec3 raw) {
|
|
41387
|
+
return pow(raw, vec3(2.2));
|
|
41388
|
+
}
|
|
41389
|
+
vec4 gammaCorrectInput(vec4 color) {
|
|
41390
|
+
return vec4(decodeGamma(color.xyz), color.w);
|
|
41391
|
+
}
|
|
41392
|
+
#endif
|
|
41313
41393
|
void main(void) {
|
|
41314
41394
|
#include "litUserMainStartVS"
|
|
41315
41395
|
gl_PointSize = 1.0;
|
|
@@ -41338,7 +41418,11 @@ void main(void) {
|
|
|
41338
41418
|
#endif
|
|
41339
41419
|
#include "uvTransformVS, UV_TRANSFORMS_COUNT"
|
|
41340
41420
|
#ifdef VERTEX_COLOR
|
|
41341
|
-
|
|
41421
|
+
#ifdef STD_VERTEX_COLOR_GAMMA
|
|
41422
|
+
vVertexColor = gammaCorrectInput(vertex_color);
|
|
41423
|
+
#else
|
|
41424
|
+
vVertexColor = vertex_color;
|
|
41425
|
+
#endif
|
|
41342
41426
|
#endif
|
|
41343
41427
|
#ifdef LINEAR_DEPTH
|
|
41344
41428
|
vLinearDepth = -(matrix_view * vec4(vPositionW, 1.0)).z;
|
|
@@ -41361,7 +41445,10 @@ void main(void) {
|
|
|
41361
41445
|
#include "litUserMainStartPS"
|
|
41362
41446
|
evaluateFrontend();
|
|
41363
41447
|
#ifdef PICK_PASS
|
|
41364
|
-
|
|
41448
|
+
pcFragColor0 = getPickOutput();
|
|
41449
|
+
#ifdef DEPTH_PICK_PASS
|
|
41450
|
+
pcFragColor1 = getPickDepth();
|
|
41451
|
+
#endif
|
|
41365
41452
|
#endif
|
|
41366
41453
|
#ifdef PREPASS_PASS
|
|
41367
41454
|
gl_FragColor = float2vec4(vLinearDepth);
|
|
@@ -42140,6 +42227,12 @@ vec4 getPickOutput() {
|
|
|
42140
42227
|
uvec4 col = (uvec4(meshInstanceId) >> shifts) & uvec4(0xff);
|
|
42141
42228
|
return vec4(col) * inv;
|
|
42142
42229
|
}
|
|
42230
|
+
#ifdef DEPTH_PICK_PASS
|
|
42231
|
+
#include "floatAsUintPS"
|
|
42232
|
+
vec4 getPickDepth() {
|
|
42233
|
+
return float2uint(gl_FragCoord.z);
|
|
42234
|
+
}
|
|
42235
|
+
#endif
|
|
42143
42236
|
`;
|
|
42144
42237
|
|
|
42145
42238
|
var reflDirPS$1 = `
|
|
@@ -42322,6 +42415,9 @@ vec3 evalRefractionColor(vec3 refractionVector, float gloss, float refractionInd
|
|
|
42322
42415
|
float iorToRoughness = (1.0 - gloss) * clamp((1.0 / refractionIndex) * 2.0 - 2.0, 0.0, 1.0);
|
|
42323
42416
|
float refractionLod = log2(uScreenSize.x) * iorToRoughness;
|
|
42324
42417
|
vec3 refraction = texture2DLod(uSceneColorMap, uv, refractionLod).rgb;
|
|
42418
|
+
#ifdef SCENE_COLORMAP_GAMMA
|
|
42419
|
+
refraction = decodeGamma(refraction);
|
|
42420
|
+
#endif
|
|
42325
42421
|
return refraction;
|
|
42326
42422
|
}
|
|
42327
42423
|
void addRefraction(
|
|
@@ -42363,7 +42459,7 @@ void addRefraction(
|
|
|
42363
42459
|
}
|
|
42364
42460
|
else
|
|
42365
42461
|
{
|
|
42366
|
-
transmittance =
|
|
42462
|
+
transmittance = vec3(1.0);
|
|
42367
42463
|
}
|
|
42368
42464
|
vec3 fresnel = vec3(1.0) -
|
|
42369
42465
|
getFresnel(
|
|
@@ -45191,7 +45287,7 @@ fn getAlbedo() {
|
|
|
45191
45287
|
dAlbedo = dAlbedo * albedoTexture;
|
|
45192
45288
|
#endif
|
|
45193
45289
|
#ifdef STD_DIFFUSE_VERTEX
|
|
45194
|
-
dAlbedo = dAlbedo *
|
|
45290
|
+
dAlbedo = dAlbedo * saturate3(vVertexColor.{STD_DIFFUSE_VERTEX_CHANNEL});
|
|
45195
45291
|
#endif
|
|
45196
45292
|
}
|
|
45197
45293
|
`;
|
|
@@ -45205,7 +45301,7 @@ fn getEmission() {
|
|
|
45205
45301
|
dEmission *= {STD_EMISSIVE_TEXTURE_DECODE}(textureSampleBias({STD_EMISSIVE_TEXTURE_NAME}, {STD_EMISSIVE_TEXTURE_NAME}Sampler, {STD_EMISSIVE_TEXTURE_UV}, uniform.textureBias)).{STD_EMISSIVE_TEXTURE_CHANNEL};
|
|
45206
45302
|
#endif
|
|
45207
45303
|
#ifdef STD_EMISSIVE_VERTEX
|
|
45208
|
-
dEmission = dEmission *
|
|
45304
|
+
dEmission = dEmission * saturate3(vVertexColor.{STD_EMISSIVE_VERTEX_CHANNEL});
|
|
45209
45305
|
#endif
|
|
45210
45306
|
}
|
|
45211
45307
|
`;
|
|
@@ -46699,6 +46795,14 @@ var<private> dModelMatrix: mat4x4f;
|
|
|
46699
46795
|
#include "msdfVS"
|
|
46700
46796
|
#endif
|
|
46701
46797
|
#include "litUserCodeVS"
|
|
46798
|
+
#ifdef VERTEX_COLOR
|
|
46799
|
+
fn decodeGamma3(raw: vec3f) -> vec3f {
|
|
46800
|
+
return pow(raw, vec3f(2.2));
|
|
46801
|
+
}
|
|
46802
|
+
fn gammaCorrectInputVec4(color: vec4f) -> vec4f {
|
|
46803
|
+
return vec4f(decodeGamma3(color.xyz), color.w);
|
|
46804
|
+
}
|
|
46805
|
+
#endif
|
|
46702
46806
|
@vertex
|
|
46703
46807
|
fn vertexMain(input : VertexInput) -> VertexOutput {
|
|
46704
46808
|
#include "litUserMainStartVS"
|
|
@@ -46728,7 +46832,11 @@ fn vertexMain(input : VertexInput) -> VertexOutput {
|
|
|
46728
46832
|
#endif
|
|
46729
46833
|
#include "uvTransformVS, UV_TRANSFORMS_COUNT"
|
|
46730
46834
|
#ifdef VERTEX_COLOR
|
|
46731
|
-
|
|
46835
|
+
#ifdef STD_VERTEX_COLOR_GAMMA
|
|
46836
|
+
output.vVertexColor = gammaCorrectInputVec4(vertex_color);
|
|
46837
|
+
#else
|
|
46838
|
+
output.vVertexColor = vertex_color;
|
|
46839
|
+
#endif
|
|
46732
46840
|
#endif
|
|
46733
46841
|
#ifdef LINEAR_DEPTH
|
|
46734
46842
|
output.vLinearDepth = -(uniform.matrix_view * vec4f(output.vPositionW, 1.0)).z;
|
|
@@ -46764,6 +46872,9 @@ fn fragmentMain(input: FragmentInput) -> FragmentOutput {
|
|
|
46764
46872
|
evaluateFrontend();
|
|
46765
46873
|
#ifdef PICK_PASS
|
|
46766
46874
|
output.color = getPickOutput();
|
|
46875
|
+
#ifdef DEPTH_PICK_PASS
|
|
46876
|
+
output.color1 = getPickDepth();
|
|
46877
|
+
#endif
|
|
46767
46878
|
#endif
|
|
46768
46879
|
#ifdef PREPASS_PASS
|
|
46769
46880
|
output.color = float2vec4(vLinearDepth);
|
|
@@ -47544,7 +47655,14 @@ fn getPickOutput() -> vec4f {
|
|
|
47544
47655
|
let shifts: vec4u = vec4u(16u, 8u, 0u, 24u);
|
|
47545
47656
|
let col: vec4u = (vec4u(uniform.meshInstanceId) >> shifts) & vec4u(0xffu);
|
|
47546
47657
|
return vec4f(col) * inv;
|
|
47547
|
-
}
|
|
47658
|
+
}
|
|
47659
|
+
#ifdef DEPTH_PICK_PASS
|
|
47660
|
+
#include "floatAsUintPS"
|
|
47661
|
+
fn getPickDepth() -> vec4f {
|
|
47662
|
+
return float2uint(pcPosition.z);
|
|
47663
|
+
}
|
|
47664
|
+
#endif
|
|
47665
|
+
`;
|
|
47548
47666
|
|
|
47549
47667
|
var reflDirPS = `
|
|
47550
47668
|
fn getReflDir(worldNormal: vec3f, viewDir: vec3f, gloss: f32, tbn: mat3x3f) {
|
|
@@ -47744,7 +47862,10 @@ fn evalRefractionColor(refractionVector: vec3f, gloss: f32, refractionIndex: f32
|
|
|
47744
47862
|
let uv: vec2f = getGrabScreenPos(projectionPoint);
|
|
47745
47863
|
let iorToRoughness: f32 = (1.0 - gloss) * clamp((1.0 / refractionIndex) * 2.0 - 2.0, 0.0, 1.0);
|
|
47746
47864
|
let refractionLod: f32 = log2(uniform.uScreenSize.x) * iorToRoughness;
|
|
47747
|
-
|
|
47865
|
+
var refraction: vec3f = textureSampleLevel(uSceneColorMap, uSceneColorMapSampler, uv, refractionLod).rgb;
|
|
47866
|
+
#ifdef SCENE_COLORMAP_GAMMA
|
|
47867
|
+
refraction = decodeGamma3(refraction);
|
|
47868
|
+
#endif
|
|
47748
47869
|
return refraction;
|
|
47749
47870
|
}
|
|
47750
47871
|
fn addRefraction(
|
|
@@ -47786,7 +47907,7 @@ fn addRefraction(
|
|
|
47786
47907
|
}
|
|
47787
47908
|
else
|
|
47788
47909
|
{
|
|
47789
|
-
transmittance =
|
|
47910
|
+
transmittance = vec3f(1.0);
|
|
47790
47911
|
}
|
|
47791
47912
|
let fresnel: vec3f = vec3f(1.0) -
|
|
47792
47913
|
getFresnel(
|
|
@@ -49777,7 +49898,14 @@ class AppBase extends EventHandler {
|
|
|
49777
49898
|
this.systems.fire('postInitialize', this.root);
|
|
49778
49899
|
this.systems.fire('postPostInitialize', this.root);
|
|
49779
49900
|
this.fire('postinitialize');
|
|
49780
|
-
this.
|
|
49901
|
+
this.requestAnimationFrame();
|
|
49902
|
+
}
|
|
49903
|
+
requestAnimationFrame() {
|
|
49904
|
+
if (this.xr?.session) {
|
|
49905
|
+
this.frameRequestId = this.xr.session.requestAnimationFrame(this.tick);
|
|
49906
|
+
} else {
|
|
49907
|
+
this.frameRequestId = platform.browser || platform.worker ? requestAnimationFrame(this.tick) : null;
|
|
49908
|
+
}
|
|
49781
49909
|
}
|
|
49782
49910
|
inputUpdate(dt) {
|
|
49783
49911
|
if (this.controller) {
|
|
@@ -50118,12 +50246,6 @@ class AppBase extends EventHandler {
|
|
|
50118
50246
|
if (this.scene.layers) {
|
|
50119
50247
|
this.scene.layers.destroy();
|
|
50120
50248
|
}
|
|
50121
|
-
const assets = this.assets.list();
|
|
50122
|
-
for(let i = 0; i < assets.length; i++){
|
|
50123
|
-
assets[i].unload();
|
|
50124
|
-
assets[i].off();
|
|
50125
|
-
}
|
|
50126
|
-
this.assets.off();
|
|
50127
50249
|
this.bundles.destroy();
|
|
50128
50250
|
this.bundles = null;
|
|
50129
50251
|
this.i18n.destroy();
|
|
@@ -50132,8 +50254,6 @@ class AppBase extends EventHandler {
|
|
|
50132
50254
|
scriptHandler?.clearCache();
|
|
50133
50255
|
this.loader.destroy();
|
|
50134
50256
|
this.loader = null;
|
|
50135
|
-
this.scene.destroy();
|
|
50136
|
-
this.scene = null;
|
|
50137
50257
|
this.systems = null;
|
|
50138
50258
|
this.context = null;
|
|
50139
50259
|
this.scripts.destroy();
|
|
@@ -50155,6 +50275,14 @@ class AppBase extends EventHandler {
|
|
|
50155
50275
|
this.xr?.destroy();
|
|
50156
50276
|
this.renderer.destroy();
|
|
50157
50277
|
this.renderer = null;
|
|
50278
|
+
const assets = this.assets.list();
|
|
50279
|
+
for(let i = 0; i < assets.length; i++){
|
|
50280
|
+
assets[i].unload();
|
|
50281
|
+
assets[i].off();
|
|
50282
|
+
}
|
|
50283
|
+
this.assets.off();
|
|
50284
|
+
this.scene.destroy();
|
|
50285
|
+
this.scene = null;
|
|
50158
50286
|
this.graphicsDevice.destroy();
|
|
50159
50287
|
this.graphicsDevice = null;
|
|
50160
50288
|
this.tick = null;
|
|
@@ -50169,7 +50297,7 @@ class AppBase extends EventHandler {
|
|
|
50169
50297
|
}
|
|
50170
50298
|
static cancelTick(app) {
|
|
50171
50299
|
if (app.frameRequestId) {
|
|
50172
|
-
|
|
50300
|
+
cancelAnimationFrame(app.frameRequestId);
|
|
50173
50301
|
app.frameRequestId = undefined;
|
|
50174
50302
|
}
|
|
50175
50303
|
}
|
|
@@ -50199,11 +50327,7 @@ const makeTick = function(_app) {
|
|
|
50199
50327
|
dt = math.clamp(dt, 0, application.maxDeltaTime);
|
|
50200
50328
|
dt *= application.timeScale;
|
|
50201
50329
|
application._time = currentTime;
|
|
50202
|
-
|
|
50203
|
-
application.frameRequestId = application.xr.session.requestAnimationFrame(application.tick);
|
|
50204
|
-
} else {
|
|
50205
|
-
application.frameRequestId = platform.browser || platform.worker ? requestAnimationFrame(application.tick) : null;
|
|
50206
|
-
}
|
|
50330
|
+
application.requestAnimationFrame();
|
|
50207
50331
|
if (application.graphicsDevice.contextLost) {
|
|
50208
50332
|
return;
|
|
50209
50333
|
}
|
|
@@ -50699,8 +50823,11 @@ class RenderPassLightmapper extends RenderPass {
|
|
|
50699
50823
|
this.viewBindGroups.length = 0;
|
|
50700
50824
|
}
|
|
50701
50825
|
execute() {
|
|
50702
|
-
this.device;
|
|
50826
|
+
const device = this.device;
|
|
50703
50827
|
const { renderer, camera, receivers, renderTarget, worldClusters, lightArray } = this;
|
|
50828
|
+
if (device.supportsUniformBuffers && !renderer.viewUniformFormat) {
|
|
50829
|
+
renderer.initViewBindGroupFormat(renderer.scene.clusteredLightingEnabled);
|
|
50830
|
+
}
|
|
50704
50831
|
renderer.renderForwardLayer(camera, renderTarget, null, undefined, SHADER_FORWARD, this.viewBindGroups, {
|
|
50705
50832
|
meshInstances: receivers,
|
|
50706
50833
|
splitLights: lightArray,
|
|
@@ -69404,9 +69531,7 @@ class ScreenComponent extends Component {
|
|
|
69404
69531
|
return this._scaleBlend;
|
|
69405
69532
|
}
|
|
69406
69533
|
set priority(value) {
|
|
69407
|
-
|
|
69408
|
-
value = 0xFF;
|
|
69409
|
-
}
|
|
69534
|
+
value = math.clamp(value, 0, 0x7F);
|
|
69410
69535
|
if (this._priority === value) {
|
|
69411
69536
|
return;
|
|
69412
69537
|
}
|
|
@@ -74492,6 +74617,12 @@ class ScriptAttributes {
|
|
|
74492
74617
|
]);
|
|
74493
74618
|
}
|
|
74494
74619
|
add(name, args) {
|
|
74620
|
+
if (!args) {
|
|
74621
|
+
return;
|
|
74622
|
+
}
|
|
74623
|
+
if (!args.type) {
|
|
74624
|
+
return;
|
|
74625
|
+
}
|
|
74495
74626
|
if (this.index[name]) {
|
|
74496
74627
|
return;
|
|
74497
74628
|
} else if (ScriptAttributes.reservedNames.has(name)) {
|
|
@@ -76186,6 +76317,7 @@ class GSplatPlacement {
|
|
|
76186
76317
|
this.intervals = new Map();
|
|
76187
76318
|
this.lodIndex = 0;
|
|
76188
76319
|
this._lodDistances = null;
|
|
76320
|
+
this.splatBudget = 0;
|
|
76189
76321
|
this._aabb = new BoundingBox();
|
|
76190
76322
|
this.resource = resource;
|
|
76191
76323
|
this.node = node;
|
|
@@ -76226,6 +76358,18 @@ new BoundingBox();
|
|
|
76226
76358
|
new Color(1, 1, 0),
|
|
76227
76359
|
new Color(1, 0, 1)
|
|
76228
76360
|
];
|
|
76361
|
+
class NodeInfo {
|
|
76362
|
+
reset() {
|
|
76363
|
+
this.currentLod = -1;
|
|
76364
|
+
this.optimalLod = -1;
|
|
76365
|
+
this.importance = 0;
|
|
76366
|
+
}
|
|
76367
|
+
constructor(){
|
|
76368
|
+
this.currentLod = -1;
|
|
76369
|
+
this.optimalLod = -1;
|
|
76370
|
+
this.importance = 0;
|
|
76371
|
+
}
|
|
76372
|
+
}
|
|
76229
76373
|
class GSplatOctreeInstance {
|
|
76230
76374
|
get pendingLoadCount() {
|
|
76231
76375
|
let count = this.pending.size + this.prefetchPending.size;
|
|
@@ -76234,7 +76378,7 @@ class GSplatOctreeInstance {
|
|
|
76234
76378
|
}
|
|
76235
76379
|
return count;
|
|
76236
76380
|
}
|
|
76237
|
-
constructor(octree, placement
|
|
76381
|
+
constructor(device, octree, placement){
|
|
76238
76382
|
this.activePlacements = new Set();
|
|
76239
76383
|
this.dirtyModifiedPlacements = false;
|
|
76240
76384
|
this.pending = new Set();
|
|
@@ -76244,28 +76388,78 @@ class GSplatOctreeInstance {
|
|
|
76244
76388
|
this.needsLodUpdate = false;
|
|
76245
76389
|
this.prefetchPending = new Set();
|
|
76246
76390
|
this.pendingVisibleAdds = new Map();
|
|
76391
|
+
this.splatBudget = 0;
|
|
76392
|
+
this._nodeIndices = null;
|
|
76247
76393
|
this.environmentPlacement = null;
|
|
76394
|
+
this._deviceLostEvent = null;
|
|
76395
|
+
this.device = device;
|
|
76248
76396
|
this.octree = octree;
|
|
76249
76397
|
this.placement = placement;
|
|
76250
|
-
this.
|
|
76251
|
-
|
|
76252
|
-
|
|
76398
|
+
this.nodeInfos = new Array(octree.nodes.length);
|
|
76399
|
+
for(let i = 0; i < octree.nodes.length; i++){
|
|
76400
|
+
this.nodeInfos[i] = new NodeInfo();
|
|
76401
|
+
}
|
|
76253
76402
|
const numFiles = octree.files.length;
|
|
76254
76403
|
this.filePlacements = new Array(numFiles).fill(null);
|
|
76255
76404
|
if (octree.environmentUrl) {
|
|
76256
76405
|
octree.incEnvironmentRefCount();
|
|
76257
|
-
octree.ensureEnvironmentResource(
|
|
76406
|
+
octree.ensureEnvironmentResource();
|
|
76258
76407
|
}
|
|
76408
|
+
this._deviceLostEvent = device.on('devicelost', this._onDeviceLost, this);
|
|
76259
76409
|
}
|
|
76260
76410
|
destroy() {
|
|
76411
|
+
if (this.octree && !this.octree.destroyed) {
|
|
76412
|
+
const filesToDecRef = this.getFileDecrements();
|
|
76413
|
+
for (const fileIndex of filesToDecRef){
|
|
76414
|
+
this.octree.decRefCount(fileIndex, 0);
|
|
76415
|
+
}
|
|
76416
|
+
for (const fileIndex of this.pending){
|
|
76417
|
+
if (!this.filePlacements[fileIndex]) {
|
|
76418
|
+
this.octree.unloadResource(fileIndex);
|
|
76419
|
+
}
|
|
76420
|
+
}
|
|
76421
|
+
for (const fileIndex of this.prefetchPending){
|
|
76422
|
+
if (!this.filePlacements[fileIndex]) {
|
|
76423
|
+
this.octree.unloadResource(fileIndex);
|
|
76424
|
+
}
|
|
76425
|
+
}
|
|
76426
|
+
if (this.environmentPlacement) {
|
|
76427
|
+
this.octree.decEnvironmentRefCount();
|
|
76428
|
+
}
|
|
76429
|
+
}
|
|
76261
76430
|
this.pending.clear();
|
|
76262
76431
|
this.pendingDecrements.clear();
|
|
76263
76432
|
this.filePlacements.length = 0;
|
|
76264
76433
|
if (this.environmentPlacement) {
|
|
76265
76434
|
this.activePlacements.delete(this.environmentPlacement);
|
|
76266
|
-
this.octree.decEnvironmentRefCount(this.assetLoader);
|
|
76267
76435
|
this.environmentPlacement = null;
|
|
76268
76436
|
}
|
|
76437
|
+
this._deviceLostEvent?.off();
|
|
76438
|
+
this._deviceLostEvent = null;
|
|
76439
|
+
}
|
|
76440
|
+
_onDeviceLost() {
|
|
76441
|
+
for(let i = 0; i < this.filePlacements.length; i++){
|
|
76442
|
+
if (this.filePlacements[i]) {
|
|
76443
|
+
this.octree.decRefCount(i, 0);
|
|
76444
|
+
}
|
|
76445
|
+
}
|
|
76446
|
+
this.filePlacements.fill(null);
|
|
76447
|
+
this.activePlacements.clear();
|
|
76448
|
+
this.pending.clear();
|
|
76449
|
+
this.pendingDecrements.clear();
|
|
76450
|
+
this.removedCandidates.clear();
|
|
76451
|
+
this.prefetchPending.clear();
|
|
76452
|
+
this.pendingVisibleAdds.clear();
|
|
76453
|
+
for (const nodeInfo of this.nodeInfos){
|
|
76454
|
+
nodeInfo.reset();
|
|
76455
|
+
}
|
|
76456
|
+
if (this.environmentPlacement) {
|
|
76457
|
+
this.activePlacements.delete(this.environmentPlacement);
|
|
76458
|
+
this.environmentPlacement = null;
|
|
76459
|
+
this.octree.unloadEnvironmentResource();
|
|
76460
|
+
}
|
|
76461
|
+
this.dirtyModifiedPlacements = true;
|
|
76462
|
+
this.needsLodUpdate = true;
|
|
76269
76463
|
}
|
|
76270
76464
|
getFileDecrements() {
|
|
76271
76465
|
const toRelease = [];
|
|
@@ -76319,7 +76513,7 @@ class GSplatOctreeInstance {
|
|
|
76319
76513
|
if (desiredLodIndex === optimalLodIndex) {
|
|
76320
76514
|
const fi = node.lods[optimalLodIndex].fileIndex;
|
|
76321
76515
|
if (fi !== -1) {
|
|
76322
|
-
this.octree.ensureFileResource(fi
|
|
76516
|
+
this.octree.ensureFileResource(fi);
|
|
76323
76517
|
if (!this.octree.getFileResource(fi)) {
|
|
76324
76518
|
this.prefetchPending.add(fi);
|
|
76325
76519
|
}
|
|
@@ -76330,7 +76524,7 @@ class GSplatOctreeInstance {
|
|
|
76330
76524
|
for(let lod = targetLod; lod >= optimalLodIndex; lod--){
|
|
76331
76525
|
const fi = node.lods[lod].fileIndex;
|
|
76332
76526
|
if (fi !== -1) {
|
|
76333
|
-
this.octree.ensureFileResource(fi
|
|
76527
|
+
this.octree.ensureFileResource(fi);
|
|
76334
76528
|
if (!this.octree.getFileResource(fi)) {
|
|
76335
76529
|
this.prefetchPending.add(fi);
|
|
76336
76530
|
}
|
|
@@ -76339,12 +76533,6 @@ class GSplatOctreeInstance {
|
|
|
76339
76533
|
}
|
|
76340
76534
|
}
|
|
76341
76535
|
updateLod(cameraNode, params) {
|
|
76342
|
-
const worldCameraPosition = cameraNode.getPosition();
|
|
76343
|
-
const octreeWorldTransform = this.placement.node.getWorldTransform();
|
|
76344
|
-
_invWorldMat.copy(octreeWorldTransform).invert();
|
|
76345
|
-
const localCameraPosition = _invWorldMat.transformPoint(worldCameraPosition, _localCameraPos);
|
|
76346
|
-
const worldCameraForward = cameraNode.forward;
|
|
76347
|
-
const localCameraForward = _invWorldMat.transformVector(worldCameraForward, _localCameraFwd).normalize();
|
|
76348
76536
|
const maxLod = this.octree.lodLevels - 1;
|
|
76349
76537
|
const lodDistances = this.placement.lodDistances || [
|
|
76350
76538
|
5,
|
|
@@ -76360,16 +76548,134 @@ class GSplatOctreeInstance {
|
|
|
76360
76548
|
55,
|
|
76361
76549
|
60
|
|
76362
76550
|
];
|
|
76363
|
-
const {
|
|
76551
|
+
const { lodRangeMin, lodRangeMax } = params;
|
|
76364
76552
|
const rangeMin = Math.max(0, Math.min(lodRangeMin ?? 0, maxLod));
|
|
76365
76553
|
const rangeMax = Math.max(rangeMin, Math.min(lodRangeMax ?? maxLod, maxLod));
|
|
76554
|
+
const totalOptimalSplats = this.evaluateNodeLods(cameraNode, maxLod, lodDistances, rangeMin, rangeMax, params);
|
|
76555
|
+
if (this.splatBudget > 0) {
|
|
76556
|
+
this.enforceSplatBudget(totalOptimalSplats, this.splatBudget, rangeMin, rangeMax);
|
|
76557
|
+
}
|
|
76558
|
+
this.applyLodChanges(maxLod, params);
|
|
76559
|
+
}
|
|
76560
|
+
evaluateNodeLods(cameraNode, maxLod, lodDistances, rangeMin, rangeMax, params) {
|
|
76561
|
+
const { lodBehindPenalty } = params;
|
|
76562
|
+
const worldCameraPosition = cameraNode.getPosition();
|
|
76563
|
+
const octreeWorldTransform = this.placement.node.getWorldTransform();
|
|
76564
|
+
_invWorldMat.copy(octreeWorldTransform).invert();
|
|
76565
|
+
const localCameraPosition = _invWorldMat.transformPoint(worldCameraPosition, _localCameraPos);
|
|
76566
|
+
const worldCameraForward = cameraNode.forward;
|
|
76567
|
+
const localCameraForward = _invWorldMat.transformVector(worldCameraForward, _localCameraFwd).normalize();
|
|
76366
76568
|
const nodes = this.octree.nodes;
|
|
76569
|
+
const nodeInfos = this.nodeInfos;
|
|
76570
|
+
let totalSplats = 0;
|
|
76571
|
+
const maxDistance = lodDistances[rangeMax] || 100;
|
|
76367
76572
|
for(let nodeIndex = 0; nodeIndex < nodes.length; nodeIndex++){
|
|
76368
76573
|
const node = nodes[nodeIndex];
|
|
76369
|
-
|
|
76574
|
+
node.bounds.closestPoint(localCameraPosition, _dirToNode);
|
|
76575
|
+
_dirToNode.sub(localCameraPosition);
|
|
76576
|
+
const actualDistance = _dirToNode.length();
|
|
76577
|
+
let penalizedDistance = actualDistance;
|
|
76578
|
+
let importanceMultiplier = 1.0;
|
|
76579
|
+
if (lodBehindPenalty > 1 && actualDistance > 0.01) {
|
|
76580
|
+
const dotOverDistance = localCameraForward.dot(_dirToNode) / actualDistance;
|
|
76581
|
+
if (dotOverDistance < 0) {
|
|
76582
|
+
const t = -dotOverDistance;
|
|
76583
|
+
const factor = 1 + t * (lodBehindPenalty - 1);
|
|
76584
|
+
penalizedDistance = actualDistance * factor;
|
|
76585
|
+
importanceMultiplier = 1.0 / factor;
|
|
76586
|
+
}
|
|
76587
|
+
}
|
|
76588
|
+
let optimalLodIndex = maxLod;
|
|
76589
|
+
for(let lod = 0; lod < maxLod; lod++){
|
|
76590
|
+
if (penalizedDistance < lodDistances[lod]) {
|
|
76591
|
+
optimalLodIndex = lod;
|
|
76592
|
+
break;
|
|
76593
|
+
}
|
|
76594
|
+
}
|
|
76370
76595
|
if (optimalLodIndex < rangeMin) optimalLodIndex = rangeMin;
|
|
76371
76596
|
if (optimalLodIndex > rangeMax) optimalLodIndex = rangeMax;
|
|
76372
|
-
const
|
|
76597
|
+
const normalizedDistance = Math.min(actualDistance / maxDistance, 1.0);
|
|
76598
|
+
const importance = (1.0 - normalizedDistance) * importanceMultiplier;
|
|
76599
|
+
nodeInfos[nodeIndex].optimalLod = optimalLodIndex;
|
|
76600
|
+
nodeInfos[nodeIndex].importance = importance;
|
|
76601
|
+
const lod = nodes[nodeIndex].lods[optimalLodIndex];
|
|
76602
|
+
if (lod && lod.count) {
|
|
76603
|
+
totalSplats += lod.count;
|
|
76604
|
+
}
|
|
76605
|
+
}
|
|
76606
|
+
return totalSplats;
|
|
76607
|
+
}
|
|
76608
|
+
enforceSplatBudget(totalSplats, splatBudget, rangeMin, rangeMax) {
|
|
76609
|
+
const nodes = this.octree.nodes;
|
|
76610
|
+
const nodeInfos = this.nodeInfos;
|
|
76611
|
+
if (!this._nodeIndices) {
|
|
76612
|
+
this._nodeIndices = new Uint32Array(nodes.length);
|
|
76613
|
+
for(let i = 0; i < nodes.length; i++){
|
|
76614
|
+
this._nodeIndices[i] = i;
|
|
76615
|
+
}
|
|
76616
|
+
}
|
|
76617
|
+
const nodeIndices = this._nodeIndices;
|
|
76618
|
+
nodeIndices.sort((a, b)=>nodeInfos[a].importance - nodeInfos[b].importance);
|
|
76619
|
+
let currentSplats = totalSplats;
|
|
76620
|
+
if (currentSplats === splatBudget) {
|
|
76621
|
+
return;
|
|
76622
|
+
}
|
|
76623
|
+
const isOverBudget = currentSplats > splatBudget;
|
|
76624
|
+
const lodDelta = isOverBudget ? 1 : -1;
|
|
76625
|
+
while(isOverBudget ? currentSplats > splatBudget : currentSplats < splatBudget){
|
|
76626
|
+
let modified = false;
|
|
76627
|
+
if (isOverBudget) {
|
|
76628
|
+
for(let i = 0; i < nodeIndices.length; i++){
|
|
76629
|
+
const nodeIndex = nodeIndices[i];
|
|
76630
|
+
const nodeInfo = nodeInfos[nodeIndex];
|
|
76631
|
+
const node = nodes[nodeIndex];
|
|
76632
|
+
const currentOptimalLod = nodeInfo.optimalLod;
|
|
76633
|
+
if (currentOptimalLod < rangeMax) {
|
|
76634
|
+
const currentLod = node.lods[currentOptimalLod];
|
|
76635
|
+
const nextLod = node.lods[currentOptimalLod + 1];
|
|
76636
|
+
const splatsSaved = currentLod.count - nextLod.count;
|
|
76637
|
+
nodeInfo.optimalLod += lodDelta;
|
|
76638
|
+
currentSplats -= splatsSaved;
|
|
76639
|
+
modified = true;
|
|
76640
|
+
if (currentSplats <= splatBudget) {
|
|
76641
|
+
break;
|
|
76642
|
+
}
|
|
76643
|
+
}
|
|
76644
|
+
}
|
|
76645
|
+
} else {
|
|
76646
|
+
for(let i = nodeIndices.length - 1; i >= 0; i--){
|
|
76647
|
+
const nodeIndex = nodeIndices[i];
|
|
76648
|
+
const nodeInfo = nodeInfos[nodeIndex];
|
|
76649
|
+
const node = nodes[nodeIndex];
|
|
76650
|
+
const currentOptimalLod = nodeInfo.optimalLod;
|
|
76651
|
+
if (currentOptimalLod > rangeMin) {
|
|
76652
|
+
const currentLod = node.lods[currentOptimalLod];
|
|
76653
|
+
const nextLod = node.lods[currentOptimalLod - 1];
|
|
76654
|
+
const splatsAdded = nextLod.count - currentLod.count;
|
|
76655
|
+
if (currentSplats + splatsAdded <= splatBudget) {
|
|
76656
|
+
nodeInfo.optimalLod += lodDelta;
|
|
76657
|
+
currentSplats += splatsAdded;
|
|
76658
|
+
modified = true;
|
|
76659
|
+
if (currentSplats >= splatBudget) {
|
|
76660
|
+
break;
|
|
76661
|
+
}
|
|
76662
|
+
}
|
|
76663
|
+
}
|
|
76664
|
+
}
|
|
76665
|
+
}
|
|
76666
|
+
if (!modified) {
|
|
76667
|
+
break;
|
|
76668
|
+
}
|
|
76669
|
+
}
|
|
76670
|
+
}
|
|
76671
|
+
applyLodChanges(maxLod, params) {
|
|
76672
|
+
const nodes = this.octree.nodes;
|
|
76673
|
+
const { lodUnderfillLimit = 0 } = params;
|
|
76674
|
+
for(let nodeIndex = 0; nodeIndex < nodes.length; nodeIndex++){
|
|
76675
|
+
const node = nodes[nodeIndex];
|
|
76676
|
+
const nodeInfo = this.nodeInfos[nodeIndex];
|
|
76677
|
+
const optimalLodIndex = nodeInfo.optimalLod;
|
|
76678
|
+
const currentLodIndex = nodeInfo.currentLod;
|
|
76373
76679
|
const desiredLodIndex = this.selectDesiredLodIndex(node, optimalLodIndex, maxLod, lodUnderfillLimit);
|
|
76374
76680
|
if (desiredLodIndex !== currentLodIndex) {
|
|
76375
76681
|
const currentFileIndex = currentLodIndex >= 0 ? node.lods[currentLodIndex].fileIndex : -1;
|
|
@@ -76402,7 +76708,7 @@ class GSplatOctreeInstance {
|
|
|
76402
76708
|
this.incrementFileRef(desiredFileIndex, nodeIndex, desiredLodIndex);
|
|
76403
76709
|
const newPlacement = this.filePlacements[desiredFileIndex];
|
|
76404
76710
|
if (newPlacement?.resource) {
|
|
76405
|
-
|
|
76711
|
+
nodeInfo.currentLod = desiredLodIndex;
|
|
76406
76712
|
this.pendingVisibleAdds.delete(nodeIndex);
|
|
76407
76713
|
} else {
|
|
76408
76714
|
this.pendingVisibleAdds.set(nodeIndex, desiredFileIndex);
|
|
@@ -76414,7 +76720,7 @@ class GSplatOctreeInstance {
|
|
|
76414
76720
|
this.pendingDecrements.delete(nodeIndex);
|
|
76415
76721
|
}
|
|
76416
76722
|
this.decrementFileRef(currentFileIndex, nodeIndex);
|
|
76417
|
-
|
|
76723
|
+
nodeInfo.currentLod = -1;
|
|
76418
76724
|
this.pendingVisibleAdds.delete(nodeIndex);
|
|
76419
76725
|
} else if (wasVisible && willBeVisible) {
|
|
76420
76726
|
this.incrementFileRef(desiredFileIndex, nodeIndex, desiredLodIndex);
|
|
@@ -76422,7 +76728,7 @@ class GSplatOctreeInstance {
|
|
|
76422
76728
|
if (newPlacement?.resource) {
|
|
76423
76729
|
this.decrementFileRef(currentFileIndex, nodeIndex);
|
|
76424
76730
|
this.pendingDecrements.delete(nodeIndex);
|
|
76425
|
-
|
|
76731
|
+
nodeInfo.currentLod = desiredLodIndex;
|
|
76426
76732
|
this.pendingVisibleAdds.delete(nodeIndex);
|
|
76427
76733
|
} else {
|
|
76428
76734
|
this.pendingDecrements.set(nodeIndex, {
|
|
@@ -76447,7 +76753,7 @@ class GSplatOctreeInstance {
|
|
|
76447
76753
|
this.octree.incRefCount(fileIndex);
|
|
76448
76754
|
}
|
|
76449
76755
|
if (!this.addFilePlacement(fileIndex)) {
|
|
76450
|
-
this.octree.ensureFileResource(fileIndex
|
|
76756
|
+
this.octree.ensureFileResource(fileIndex);
|
|
76451
76757
|
this.pending.add(fileIndex);
|
|
76452
76758
|
}
|
|
76453
76759
|
}
|
|
@@ -76504,9 +76810,14 @@ class GSplatOctreeInstance {
|
|
|
76504
76810
|
this.previousPosition.copy(this.placement.node.getPosition());
|
|
76505
76811
|
}
|
|
76506
76812
|
update(scene) {
|
|
76813
|
+
const currentBudget = this.placement.splatBudget;
|
|
76814
|
+
if (currentBudget !== this.splatBudget) {
|
|
76815
|
+
this.splatBudget = currentBudget;
|
|
76816
|
+
this.needsLodUpdate = true;
|
|
76817
|
+
}
|
|
76507
76818
|
if (this.pending.size) {
|
|
76508
76819
|
for (const fileIndex of this.pending){
|
|
76509
|
-
this.octree.ensureFileResource(fileIndex
|
|
76820
|
+
this.octree.ensureFileResource(fileIndex);
|
|
76510
76821
|
if (this.addFilePlacement(fileIndex)) {
|
|
76511
76822
|
_tempCompletedUrls.push(fileIndex);
|
|
76512
76823
|
for (const [nodeIndex, { oldFileIndex, newFileIndex }] of this.pendingDecrements){
|
|
@@ -76521,7 +76832,7 @@ class GSplatOctreeInstance {
|
|
|
76521
76832
|
break;
|
|
76522
76833
|
}
|
|
76523
76834
|
}
|
|
76524
|
-
this.
|
|
76835
|
+
this.nodeInfos[nodeIndex].currentLod = newLodIndex;
|
|
76525
76836
|
}
|
|
76526
76837
|
}
|
|
76527
76838
|
}
|
|
@@ -76536,7 +76847,7 @@ class GSplatOctreeInstance {
|
|
|
76536
76847
|
}
|
|
76537
76848
|
this.pollPrefetchCompletions();
|
|
76538
76849
|
if (this.octree.environmentUrl && !this.environmentPlacement) {
|
|
76539
|
-
this.octree.ensureEnvironmentResource(
|
|
76850
|
+
this.octree.ensureEnvironmentResource();
|
|
76540
76851
|
const envResource = this.octree.environmentResource;
|
|
76541
76852
|
if (envResource) {
|
|
76542
76853
|
this.environmentPlacement = new GSplatPlacement(envResource, this.placement.node, 0);
|
|
@@ -76558,7 +76869,7 @@ class GSplatOctreeInstance {
|
|
|
76558
76869
|
pollPrefetchCompletions() {
|
|
76559
76870
|
if (this.prefetchPending.size) {
|
|
76560
76871
|
for (const fileIndex of this.prefetchPending){
|
|
76561
|
-
this.octree.ensureFileResource(fileIndex
|
|
76872
|
+
this.octree.ensureFileResource(fileIndex);
|
|
76562
76873
|
if (this.octree.getFileResource(fileIndex)) {
|
|
76563
76874
|
_tempCompletedUrls.push(fileIndex);
|
|
76564
76875
|
}
|
|
@@ -76594,6 +76905,9 @@ class GSplatOctree {
|
|
|
76594
76905
|
this.environmentUrl = null;
|
|
76595
76906
|
this.environmentResource = null;
|
|
76596
76907
|
this.environmentRefCount = 0;
|
|
76908
|
+
this.assetLoader = null;
|
|
76909
|
+
this.destroyed = false;
|
|
76910
|
+
this.cooldownTicks = 100;
|
|
76597
76911
|
this.lodLevels = data.lodLevels;
|
|
76598
76912
|
this.assetFileUrl = assetFileUrl;
|
|
76599
76913
|
const baseDir = path.getDirectory(assetFileUrl);
|
|
@@ -76631,6 +76945,14 @@ class GSplatOctree {
|
|
|
76631
76945
|
return new GSplatOctreeNode(lods, nodeData.bound);
|
|
76632
76946
|
});
|
|
76633
76947
|
}
|
|
76948
|
+
destroy() {
|
|
76949
|
+
this.destroyed = true;
|
|
76950
|
+
this.fileResources.clear();
|
|
76951
|
+
this.cooldowns.clear();
|
|
76952
|
+
this.assetLoader?.destroy();
|
|
76953
|
+
this.assetLoader = null;
|
|
76954
|
+
this.environmentResource = null;
|
|
76955
|
+
}
|
|
76634
76956
|
_traceLodCounts() {}
|
|
76635
76957
|
_extractLeafNodes(node, leafNodes) {
|
|
76636
76958
|
if (node.lods) {
|
|
@@ -76656,23 +76978,31 @@ class GSplatOctree {
|
|
|
76656
76978
|
const count = this.fileRefCounts[fileIndex] - 1;
|
|
76657
76979
|
this.fileRefCounts[fileIndex] = count;
|
|
76658
76980
|
if (count === 0) {
|
|
76659
|
-
|
|
76981
|
+
if (cooldownTicks === 0) {
|
|
76982
|
+
this.unloadResource(fileIndex);
|
|
76983
|
+
} else {
|
|
76984
|
+
this.cooldowns.set(fileIndex, cooldownTicks);
|
|
76985
|
+
}
|
|
76660
76986
|
}
|
|
76661
76987
|
}
|
|
76662
|
-
unloadResource(fileIndex
|
|
76988
|
+
unloadResource(fileIndex) {
|
|
76989
|
+
if (!this.assetLoader) {
|
|
76990
|
+
return;
|
|
76991
|
+
}
|
|
76992
|
+
const fullUrl = this.files[fileIndex].url;
|
|
76993
|
+
this.assetLoader.unload(fullUrl);
|
|
76663
76994
|
if (this.fileResources.has(fileIndex)) {
|
|
76664
|
-
const fullUrl = this.files[fileIndex].url;
|
|
76665
|
-
assetLoader.unload(fullUrl);
|
|
76666
76995
|
this.fileResources.delete(fileIndex);
|
|
76667
76996
|
this._traceLodCounts();
|
|
76668
76997
|
}
|
|
76669
76998
|
}
|
|
76670
|
-
updateCooldownTick(
|
|
76999
|
+
updateCooldownTick(cooldownTicks) {
|
|
77000
|
+
this.cooldownTicks = cooldownTicks;
|
|
76671
77001
|
if (this.cooldowns.size > 0) {
|
|
76672
77002
|
this.cooldowns.forEach((remaining, fileIndex)=>{
|
|
76673
77003
|
if (remaining <= 1) {
|
|
76674
77004
|
if (this.fileRefCounts[fileIndex] === 0) {
|
|
76675
|
-
this.unloadResource(fileIndex
|
|
77005
|
+
this.unloadResource(fileIndex);
|
|
76676
77006
|
}
|
|
76677
77007
|
_toDelete.push(fileIndex);
|
|
76678
77008
|
} else {
|
|
@@ -76683,62 +77013,73 @@ class GSplatOctree {
|
|
|
76683
77013
|
_toDelete.length = 0;
|
|
76684
77014
|
}
|
|
76685
77015
|
}
|
|
76686
|
-
ensureFileResource(fileIndex
|
|
77016
|
+
ensureFileResource(fileIndex) {
|
|
76687
77017
|
if (this.fileResources.has(fileIndex)) {
|
|
76688
77018
|
return;
|
|
76689
77019
|
}
|
|
76690
77020
|
const fullUrl = this.files[fileIndex].url;
|
|
76691
|
-
const res = assetLoader
|
|
77021
|
+
const res = this.assetLoader?.getResource(fullUrl);
|
|
76692
77022
|
if (res) {
|
|
76693
77023
|
this.fileResources.set(fileIndex, res);
|
|
76694
77024
|
if (this.fileRefCounts[fileIndex] === 0) {
|
|
76695
|
-
this.cooldowns.set(fileIndex,
|
|
77025
|
+
this.cooldowns.set(fileIndex, this.cooldownTicks);
|
|
76696
77026
|
}
|
|
76697
77027
|
this._traceLodCounts();
|
|
76698
77028
|
return;
|
|
76699
77029
|
}
|
|
76700
|
-
assetLoader
|
|
77030
|
+
this.assetLoader?.load(fullUrl);
|
|
76701
77031
|
}
|
|
76702
77032
|
incEnvironmentRefCount() {
|
|
76703
77033
|
this.environmentRefCount++;
|
|
76704
77034
|
}
|
|
76705
|
-
decEnvironmentRefCount(
|
|
77035
|
+
decEnvironmentRefCount() {
|
|
76706
77036
|
this.environmentRefCount--;
|
|
76707
77037
|
if (this.environmentRefCount === 0) {
|
|
76708
|
-
this.unloadEnvironmentResource(
|
|
77038
|
+
this.unloadEnvironmentResource();
|
|
76709
77039
|
}
|
|
76710
77040
|
}
|
|
76711
|
-
ensureEnvironmentResource(
|
|
77041
|
+
ensureEnvironmentResource() {
|
|
77042
|
+
if (!this.assetLoader) {
|
|
77043
|
+
return;
|
|
77044
|
+
}
|
|
76712
77045
|
if (!this.environmentUrl) {
|
|
76713
77046
|
return;
|
|
76714
77047
|
}
|
|
76715
77048
|
if (this.environmentResource) {
|
|
76716
77049
|
return;
|
|
76717
77050
|
}
|
|
76718
|
-
const res = assetLoader.getResource(this.environmentUrl);
|
|
77051
|
+
const res = this.assetLoader.getResource(this.environmentUrl);
|
|
76719
77052
|
if (res) {
|
|
76720
77053
|
this.environmentResource = res;
|
|
76721
77054
|
if (this.environmentRefCount === 0) {
|
|
76722
|
-
this.unloadEnvironmentResource(
|
|
77055
|
+
this.unloadEnvironmentResource();
|
|
76723
77056
|
}
|
|
76724
77057
|
return;
|
|
76725
77058
|
}
|
|
76726
|
-
assetLoader.load(this.environmentUrl);
|
|
77059
|
+
this.assetLoader.load(this.environmentUrl);
|
|
76727
77060
|
}
|
|
76728
|
-
unloadEnvironmentResource(
|
|
77061
|
+
unloadEnvironmentResource() {
|
|
77062
|
+
if (!this.assetLoader) {
|
|
77063
|
+
return;
|
|
77064
|
+
}
|
|
76729
77065
|
if (this.environmentResource && this.environmentUrl) {
|
|
76730
|
-
assetLoader.unload(this.environmentUrl);
|
|
77066
|
+
this.assetLoader.unload(this.environmentUrl);
|
|
76731
77067
|
this.environmentResource = null;
|
|
76732
77068
|
}
|
|
76733
77069
|
}
|
|
76734
77070
|
}
|
|
76735
77071
|
|
|
76736
77072
|
class GSplatOctreeResource {
|
|
76737
|
-
constructor(assetFileUrl, data){
|
|
77073
|
+
constructor(assetFileUrl, data, assetLoader){
|
|
76738
77074
|
this.aabb = new BoundingBox();
|
|
76739
77075
|
this.octree = new GSplatOctree(assetFileUrl, data);
|
|
77076
|
+
this.octree.assetLoader = assetLoader;
|
|
76740
77077
|
this.aabb.setMinMax(new Vec3(data.tree.bound.min), new Vec3(data.tree.bound.max));
|
|
76741
77078
|
}
|
|
77079
|
+
destroy() {
|
|
77080
|
+
this.octree?.destroy();
|
|
77081
|
+
this.octree = null;
|
|
77082
|
+
}
|
|
76742
77083
|
}
|
|
76743
77084
|
|
|
76744
77085
|
class GSplatWorldState {
|
|
@@ -76841,6 +77182,21 @@ const _lodColorsRaw = [
|
|
|
76841
77182
|
1,
|
|
76842
77183
|
0,
|
|
76843
77184
|
1
|
|
77185
|
+
],
|
|
77186
|
+
[
|
|
77187
|
+
0,
|
|
77188
|
+
1,
|
|
77189
|
+
1
|
|
77190
|
+
],
|
|
77191
|
+
[
|
|
77192
|
+
1,
|
|
77193
|
+
0.5,
|
|
77194
|
+
0
|
|
77195
|
+
],
|
|
77196
|
+
[
|
|
77197
|
+
0.5,
|
|
77198
|
+
0,
|
|
77199
|
+
1
|
|
76844
77200
|
]
|
|
76845
77201
|
];
|
|
76846
77202
|
[
|
|
@@ -76848,7 +77204,10 @@ const _lodColorsRaw = [
|
|
|
76848
77204
|
new Color(0, 1, 0),
|
|
76849
77205
|
new Color(0, 0, 1),
|
|
76850
77206
|
new Color(1, 1, 0),
|
|
76851
|
-
new Color(1, 0, 1)
|
|
77207
|
+
new Color(1, 0, 1),
|
|
77208
|
+
new Color(0, 1, 1),
|
|
77209
|
+
new Color(1, 0.5, 0),
|
|
77210
|
+
new Color(0.5, 0, 1)
|
|
76852
77211
|
];
|
|
76853
77212
|
let _randomColorRaw = null;
|
|
76854
77213
|
class GSplatManager {
|
|
@@ -76877,9 +77236,24 @@ class GSplatManager {
|
|
|
76877
77236
|
this.workBuffer = new GSplatWorkBuffer(device);
|
|
76878
77237
|
this.renderer = new GSplatRenderer(device, this.node, this.cameraNode, layer, this.workBuffer);
|
|
76879
77238
|
this.sorter = this.createSorter();
|
|
76880
|
-
this.cooldownTicks = this.director.assetLoader.cooldownTicks;
|
|
76881
77239
|
}
|
|
76882
77240
|
destroy() {
|
|
77241
|
+
this._destroyed = true;
|
|
77242
|
+
for (const [, worldState] of this.worldStates){
|
|
77243
|
+
for (const splat of worldState.splats){
|
|
77244
|
+
splat.resource.decRefCount();
|
|
77245
|
+
}
|
|
77246
|
+
worldState.destroy();
|
|
77247
|
+
}
|
|
77248
|
+
this.worldStates.clear();
|
|
77249
|
+
for (const [, instance] of this.octreeInstances){
|
|
77250
|
+
instance.destroy();
|
|
77251
|
+
}
|
|
77252
|
+
this.octreeInstances.clear();
|
|
77253
|
+
for (const instance of this.octreeInstancesToDestroy){
|
|
77254
|
+
instance.destroy();
|
|
77255
|
+
}
|
|
77256
|
+
this.octreeInstancesToDestroy.length = 0;
|
|
76883
77257
|
this.workBuffer.destroy();
|
|
76884
77258
|
this.renderer.destroy();
|
|
76885
77259
|
this.sorter.destroy();
|
|
@@ -76899,7 +77273,7 @@ class GSplatManager {
|
|
|
76899
77273
|
for (const p of placements){
|
|
76900
77274
|
if (p.resource instanceof GSplatOctreeResource) {
|
|
76901
77275
|
if (!this.octreeInstances.has(p)) {
|
|
76902
|
-
this.octreeInstances.set(p, new GSplatOctreeInstance(p.resource.octree, p
|
|
77276
|
+
this.octreeInstances.set(p, new GSplatOctreeInstance(this.device, p.resource.octree, p));
|
|
76903
77277
|
this.hasNewOctreeInstances = true;
|
|
76904
77278
|
}
|
|
76905
77279
|
tempOctreePlacements.add(p);
|
|
@@ -76953,6 +77327,9 @@ class GSplatManager {
|
|
|
76953
77327
|
}
|
|
76954
77328
|
this.sorter.updateCentersForSplats(splats);
|
|
76955
77329
|
const newState = new GSplatWorldState(this.device, this.lastWorldStateVersion, splats);
|
|
77330
|
+
for (const splat of newState.splats){
|
|
77331
|
+
splat.resource.incRefCount();
|
|
77332
|
+
}
|
|
76956
77333
|
for (const [, inst] of this.octreeInstances){
|
|
76957
77334
|
if (inst.removedCandidates && inst.removedCandidates.size) {
|
|
76958
77335
|
for (const fileIndex of inst.removedCandidates){
|
|
@@ -76986,6 +77363,9 @@ class GSplatManager {
|
|
|
76986
77363
|
for(let v = this.sortedVersion; v < version; v++){
|
|
76987
77364
|
const oldState = this.worldStates.get(v);
|
|
76988
77365
|
if (oldState) {
|
|
77366
|
+
for (const splat of oldState.splats){
|
|
77367
|
+
splat.resource.decRefCount();
|
|
77368
|
+
}
|
|
76989
77369
|
this.worldStates.delete(v);
|
|
76990
77370
|
oldState.destroy();
|
|
76991
77371
|
}
|
|
@@ -77008,8 +77388,9 @@ class GSplatManager {
|
|
|
77008
77388
|
});
|
|
77009
77389
|
this.updateColorCameraTracking();
|
|
77010
77390
|
if (worldState.pendingReleases && worldState.pendingReleases.length) {
|
|
77391
|
+
const cooldownTicks = this.scene.gsplat.cooldownTicks;
|
|
77011
77392
|
for (const [octree, fileIndex] of worldState.pendingReleases){
|
|
77012
|
-
octree.decRefCount(fileIndex,
|
|
77393
|
+
octree.decRefCount(fileIndex, cooldownTicks);
|
|
77013
77394
|
}
|
|
77014
77395
|
worldState.pendingReleases.length = 0;
|
|
77015
77396
|
}
|
|
@@ -77196,11 +77577,12 @@ class GSplatManager {
|
|
|
77196
77577
|
this.updateColorCameraTracking();
|
|
77197
77578
|
}
|
|
77198
77579
|
if (this.octreeInstances.size) {
|
|
77580
|
+
const cooldownTicks = this.scene.gsplat.cooldownTicks;
|
|
77199
77581
|
for (const [, inst] of this.octreeInstances){
|
|
77200
77582
|
const octree = inst.octree;
|
|
77201
77583
|
if (!tempOctreesTicked.has(octree)) {
|
|
77202
77584
|
tempOctreesTicked.add(octree);
|
|
77203
|
-
octree.updateCooldownTick(
|
|
77585
|
+
octree.updateCooldownTick(cooldownTicks);
|
|
77204
77586
|
}
|
|
77205
77587
|
}
|
|
77206
77588
|
tempOctreesTicked.clear();
|
|
@@ -77259,6 +77641,7 @@ class GSplatManager {
|
|
|
77259
77641
|
}
|
|
77260
77642
|
}
|
|
77261
77643
|
|
|
77644
|
+
const tempLayersToRemove = [];
|
|
77262
77645
|
class GSplatLayerData {
|
|
77263
77646
|
constructor(device, director, layer, cameraNode){
|
|
77264
77647
|
this.gsplatManager = new GSplatManager(device, director, layer, cameraNode);
|
|
@@ -77296,11 +77679,10 @@ class GSplatCameraData {
|
|
|
77296
77679
|
}
|
|
77297
77680
|
}
|
|
77298
77681
|
class GSplatDirector {
|
|
77299
|
-
constructor(device, renderer, scene,
|
|
77682
|
+
constructor(device, renderer, scene, eventHandler){
|
|
77300
77683
|
this.camerasMap = new Map();
|
|
77301
77684
|
this.device = device;
|
|
77302
77685
|
this.renderer = renderer;
|
|
77303
|
-
this.assetLoader = assetLoader;
|
|
77304
77686
|
this.scene = scene;
|
|
77305
77687
|
this.eventHandler = eventHandler;
|
|
77306
77688
|
}
|
|
@@ -77324,10 +77706,18 @@ class GSplatDirector {
|
|
|
77324
77706
|
} else {
|
|
77325
77707
|
cameraData.layersMap.forEach((layerData, layer)=>{
|
|
77326
77708
|
if (!camera.layersSet.has(layer.id) || !layer.enabled) {
|
|
77709
|
+
tempLayersToRemove.push(layer);
|
|
77710
|
+
}
|
|
77711
|
+
});
|
|
77712
|
+
for(let i = 0; i < tempLayersToRemove.length; i++){
|
|
77713
|
+
const layer = tempLayersToRemove[i];
|
|
77714
|
+
const layerData = cameraData.layersMap.get(layer);
|
|
77715
|
+
if (layerData) {
|
|
77327
77716
|
layerData.destroy();
|
|
77328
77717
|
cameraData.layersMap.delete(layer);
|
|
77329
77718
|
}
|
|
77330
|
-
}
|
|
77719
|
+
}
|
|
77720
|
+
tempLayersToRemove.length = 0;
|
|
77331
77721
|
}
|
|
77332
77722
|
});
|
|
77333
77723
|
let gsplatCount = 0;
|
|
@@ -77384,7 +77774,7 @@ class GSplatComponent extends Component {
|
|
|
77384
77774
|
50,
|
|
77385
77775
|
55,
|
|
77386
77776
|
60
|
|
77387
|
-
], this._customAabb = null, this._evtLayersChanged = null, this._evtLayerAdded = null, this._evtLayerRemoved = null, this._castShadows = false, this._unified = false;
|
|
77777
|
+
], this._splatBudget = 0, this._customAabb = null, this._evtLayersChanged = null, this._evtLayerAdded = null, this._evtLayerRemoved = null, this._castShadows = false, this._unified = false;
|
|
77388
77778
|
this._assetReference = new AssetReference('asset', this, system.app.assets, {
|
|
77389
77779
|
add: this._onGSplatAssetAdded,
|
|
77390
77780
|
load: this._onGSplatAssetLoad,
|
|
@@ -77492,6 +77882,15 @@ class GSplatComponent extends Component {
|
|
|
77492
77882
|
get lodDistances() {
|
|
77493
77883
|
return this._lodDistances ? this._lodDistances.slice() : null;
|
|
77494
77884
|
}
|
|
77885
|
+
set splatBudget(value) {
|
|
77886
|
+
this._splatBudget = value;
|
|
77887
|
+
if (this._placement) {
|
|
77888
|
+
this._placement.splatBudget = this._splatBudget;
|
|
77889
|
+
}
|
|
77890
|
+
}
|
|
77891
|
+
get splatBudget() {
|
|
77892
|
+
return this._splatBudget;
|
|
77893
|
+
}
|
|
77495
77894
|
set unified(value) {
|
|
77496
77895
|
if (this.enabled && this.entity.enabled) {
|
|
77497
77896
|
return;
|
|
@@ -77670,6 +78069,10 @@ class GSplatComponent extends Component {
|
|
|
77670
78069
|
if (asset) {
|
|
77671
78070
|
this._placement = new GSplatPlacement(asset.resource, this.entity);
|
|
77672
78071
|
this._placement.lodDistances = this._lodDistances;
|
|
78072
|
+
this._placement.splatBudget = this._splatBudget;
|
|
78073
|
+
if (this.enabled && this.entity.enabled) {
|
|
78074
|
+
this.addToLayers();
|
|
78075
|
+
}
|
|
77673
78076
|
}
|
|
77674
78077
|
} else {
|
|
77675
78078
|
if (asset) {
|
|
@@ -77698,102 +78101,6 @@ class GSplatComponentData {
|
|
|
77698
78101
|
}
|
|
77699
78102
|
}
|
|
77700
78103
|
|
|
77701
|
-
class GSplatAssetLoaderBase {
|
|
77702
|
-
load(url) {}
|
|
77703
|
-
unload(url) {}
|
|
77704
|
-
getResource(url) {}
|
|
77705
|
-
constructor(){
|
|
77706
|
-
this.cooldownTicks = 100;
|
|
77707
|
-
}
|
|
77708
|
-
}
|
|
77709
|
-
|
|
77710
|
-
class GSplatAssetLoader extends GSplatAssetLoaderBase {
|
|
77711
|
-
constructor(registry){
|
|
77712
|
-
super(), this._urlToAsset = new Map(), this.maxConcurrentLoads = 2, this.maxRetries = 2, this._currentlyLoading = new Set(), this._loadQueue = [], this._retryCount = new Map();
|
|
77713
|
-
this._registry = registry;
|
|
77714
|
-
}
|
|
77715
|
-
load(url) {
|
|
77716
|
-
const asset = this._urlToAsset.get(url);
|
|
77717
|
-
if (asset?.loaded || this._currentlyLoading.has(url)) {
|
|
77718
|
-
return;
|
|
77719
|
-
}
|
|
77720
|
-
if (this._loadQueue.includes(url)) {
|
|
77721
|
-
return;
|
|
77722
|
-
}
|
|
77723
|
-
if (this._currentlyLoading.size < this.maxConcurrentLoads) {
|
|
77724
|
-
this._startLoading(url);
|
|
77725
|
-
} else {
|
|
77726
|
-
this._loadQueue.push(url);
|
|
77727
|
-
}
|
|
77728
|
-
}
|
|
77729
|
-
_startLoading(url) {
|
|
77730
|
-
this._currentlyLoading.add(url);
|
|
77731
|
-
let asset = this._urlToAsset.get(url);
|
|
77732
|
-
if (!asset) {
|
|
77733
|
-
asset = this._registry.getByUrl(url);
|
|
77734
|
-
if (!asset) {
|
|
77735
|
-
asset = new Asset(url, 'gsplat', {
|
|
77736
|
-
url
|
|
77737
|
-
});
|
|
77738
|
-
this._registry.add(asset);
|
|
77739
|
-
}
|
|
77740
|
-
this._urlToAsset.set(url, asset);
|
|
77741
|
-
}
|
|
77742
|
-
asset.once('load', ()=>this._onAssetLoadSuccess(url, asset));
|
|
77743
|
-
asset.once('error', (err)=>this._onAssetLoadError(url, asset, err));
|
|
77744
|
-
if (!asset.loaded && !asset.loading) {
|
|
77745
|
-
this._registry.load(asset);
|
|
77746
|
-
}
|
|
77747
|
-
}
|
|
77748
|
-
_onAssetLoadSuccess(url, asset) {
|
|
77749
|
-
this._currentlyLoading.delete(url);
|
|
77750
|
-
this._retryCount.delete(url);
|
|
77751
|
-
this._processQueue();
|
|
77752
|
-
}
|
|
77753
|
-
_onAssetLoadError(url, asset, err) {
|
|
77754
|
-
const retryCount = this._retryCount.get(url) || 0;
|
|
77755
|
-
if (retryCount < this.maxRetries) {
|
|
77756
|
-
this._retryCount.set(url, retryCount + 1);
|
|
77757
|
-
asset.loaded = false;
|
|
77758
|
-
asset.loading = false;
|
|
77759
|
-
this._registry.load(asset);
|
|
77760
|
-
} else {
|
|
77761
|
-
this._currentlyLoading.delete(url);
|
|
77762
|
-
this._retryCount.delete(url);
|
|
77763
|
-
this._processQueue();
|
|
77764
|
-
}
|
|
77765
|
-
}
|
|
77766
|
-
_processQueue() {
|
|
77767
|
-
while(this._currentlyLoading.size < this.maxConcurrentLoads && this._loadQueue.length > 0){
|
|
77768
|
-
const url = this._loadQueue.shift();
|
|
77769
|
-
if (url) {
|
|
77770
|
-
this._startLoading(url);
|
|
77771
|
-
}
|
|
77772
|
-
}
|
|
77773
|
-
}
|
|
77774
|
-
unload(url) {
|
|
77775
|
-
this._currentlyLoading.delete(url);
|
|
77776
|
-
const queueIndex = this._loadQueue.indexOf(url);
|
|
77777
|
-
if (queueIndex !== -1) {
|
|
77778
|
-
this._loadQueue.splice(queueIndex, 1);
|
|
77779
|
-
}
|
|
77780
|
-
this._retryCount.delete(url);
|
|
77781
|
-
const asset = this._urlToAsset.get(url);
|
|
77782
|
-
if (asset) {
|
|
77783
|
-
asset.off('load');
|
|
77784
|
-
asset.off('error');
|
|
77785
|
-
this._registry.remove(asset);
|
|
77786
|
-
asset.unload();
|
|
77787
|
-
this._urlToAsset.delete(url);
|
|
77788
|
-
}
|
|
77789
|
-
this._processQueue();
|
|
77790
|
-
}
|
|
77791
|
-
getResource(url) {
|
|
77792
|
-
const asset = this._urlToAsset.get(url);
|
|
77793
|
-
return asset?.resource;
|
|
77794
|
-
}
|
|
77795
|
-
}
|
|
77796
|
-
|
|
77797
78104
|
var gsplatCenterVS$1 = `
|
|
77798
78105
|
uniform mat4 matrix_model;
|
|
77799
78106
|
uniform mat4 matrix_view;
|
|
@@ -78316,7 +78623,10 @@ void main(void) {
|
|
|
78316
78623
|
}
|
|
78317
78624
|
#endif
|
|
78318
78625
|
#ifdef PICK_PASS
|
|
78319
|
-
|
|
78626
|
+
pcFragColor0 = getPickOutput();
|
|
78627
|
+
#ifdef DEPTH_PICK_PASS
|
|
78628
|
+
pcFragColor1 = getPickDepth();
|
|
78629
|
+
#endif
|
|
78320
78630
|
#elif SHADOW_PASS
|
|
78321
78631
|
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
|
|
78322
78632
|
#elif PREPASS_PASS
|
|
@@ -79056,6 +79366,9 @@ fn fragmentMain(input: FragmentInput) -> FragmentOutput {
|
|
|
79056
79366
|
#endif
|
|
79057
79367
|
#ifdef PICK_PASS
|
|
79058
79368
|
output.color = getPickOutput();
|
|
79369
|
+
#ifdef DEPTH_PICK_PASS
|
|
79370
|
+
output.color1 = getPickDepth();
|
|
79371
|
+
#endif
|
|
79059
79372
|
#elif SHADOW_PASS
|
|
79060
79373
|
output.color = vec4f(0.0, 0.0, 0.0, 1.0);
|
|
79061
79374
|
#elif PREPASS_PASS
|
|
@@ -79345,8 +79658,7 @@ class GSplatComponentSystem extends ComponentSystem {
|
|
|
79345
79658
|
this.ComponentType = GSplatComponent;
|
|
79346
79659
|
this.DataType = GSplatComponentData;
|
|
79347
79660
|
this.schema = _schema;
|
|
79348
|
-
|
|
79349
|
-
app.renderer.gsplatDirector = new GSplatDirector(app.graphicsDevice, app.renderer, app.scene, gsplatAssetLoader, this);
|
|
79661
|
+
app.renderer.gsplatDirector = new GSplatDirector(app.graphicsDevice, app.renderer, app.scene, this);
|
|
79350
79662
|
ShaderChunks.get(app.graphicsDevice, SHADERLANGUAGE_GLSL).add(gsplatChunksGLSL);
|
|
79351
79663
|
ShaderChunks.get(app.graphicsDevice, SHADERLANGUAGE_WGSL).add(gsplatChunksWGSL);
|
|
79352
79664
|
this.on('beforeremove', this.onRemove, this);
|
|
@@ -83987,6 +84299,11 @@ class SogsParser {
|
|
|
83987
84299
|
this.app = app;
|
|
83988
84300
|
this.maxRetries = maxRetries;
|
|
83989
84301
|
}
|
|
84302
|
+
_shouldAbort(asset, unloaded) {
|
|
84303
|
+
if (unloaded || !this.app.assets.get(asset.id)) return true;
|
|
84304
|
+
if (!this.app?.graphicsDevice || this.app.graphicsDevice._destroyed) return true;
|
|
84305
|
+
return false;
|
|
84306
|
+
}
|
|
83990
84307
|
async loadTextures(url, callback, asset, meta) {
|
|
83991
84308
|
if (meta.version !== 2) {
|
|
83992
84309
|
meta = upgradeMeta(meta);
|
|
@@ -84009,6 +84326,8 @@ class SogsParser {
|
|
|
84009
84326
|
filename
|
|
84010
84327
|
}, {
|
|
84011
84328
|
mipmaps: false
|
|
84329
|
+
}, {
|
|
84330
|
+
crossOrigin: 'anonymous'
|
|
84012
84331
|
});
|
|
84013
84332
|
const promise = new Promise((resolve, reject)=>{
|
|
84014
84333
|
texture.on('load', ()=>resolve(null));
|
|
@@ -84020,7 +84339,9 @@ class SogsParser {
|
|
|
84020
84339
|
});
|
|
84021
84340
|
});
|
|
84022
84341
|
const textureAssets = subs.map((sub)=>textures[sub]).flat();
|
|
84342
|
+
let unloaded = false;
|
|
84023
84343
|
asset.once('unload', ()=>{
|
|
84344
|
+
unloaded = true;
|
|
84024
84345
|
textureAssets.forEach((t)=>{
|
|
84025
84346
|
assets.remove(t);
|
|
84026
84347
|
t.unload();
|
|
@@ -84029,7 +84350,16 @@ class SogsParser {
|
|
|
84029
84350
|
combineProgress(asset, textureAssets);
|
|
84030
84351
|
textureAssets.forEach((t)=>assets.load(t));
|
|
84031
84352
|
await Promise.allSettled(promises);
|
|
84353
|
+
if (this._shouldAbort(asset, unloaded)) {
|
|
84354
|
+
textureAssets.forEach((t)=>{
|
|
84355
|
+
assets.remove(t);
|
|
84356
|
+
t.unload();
|
|
84357
|
+
});
|
|
84358
|
+
callback(null, null);
|
|
84359
|
+
return;
|
|
84360
|
+
}
|
|
84032
84361
|
const data = new GSplatSogsData();
|
|
84362
|
+
data.url = url.original;
|
|
84033
84363
|
data.meta = meta;
|
|
84034
84364
|
data.numSplats = meta.count;
|
|
84035
84365
|
data.means_l = textures.means[0].resource;
|
|
@@ -84040,12 +84370,27 @@ class SogsParser {
|
|
|
84040
84370
|
data.sh_centroids = textures.shN?.[0]?.resource;
|
|
84041
84371
|
data.sh_labels = textures.shN?.[1]?.resource;
|
|
84042
84372
|
const decompress = asset.data?.decompress;
|
|
84373
|
+
const minimalMemory = asset.options?.minimalMemory ?? false;
|
|
84374
|
+
data.minimalMemory = minimalMemory;
|
|
84043
84375
|
if (!decompress) {
|
|
84044
|
-
if (
|
|
84376
|
+
if (this._shouldAbort(asset, unloaded)) {
|
|
84377
|
+
data.destroy();
|
|
84378
|
+
callback(null, null);
|
|
84379
|
+
return;
|
|
84380
|
+
}
|
|
84045
84381
|
await data.prepareGpuData();
|
|
84046
84382
|
}
|
|
84047
|
-
if (
|
|
84383
|
+
if (this._shouldAbort(asset, unloaded)) {
|
|
84384
|
+
data.destroy();
|
|
84385
|
+
callback(null, null);
|
|
84386
|
+
return;
|
|
84387
|
+
}
|
|
84048
84388
|
const resource = decompress ? new GSplatResource(this.app.graphicsDevice, await data.decompress()) : new GSplatSogsResource(this.app.graphicsDevice, data);
|
|
84389
|
+
if (this._shouldAbort(asset, unloaded)) {
|
|
84390
|
+
resource.destroy();
|
|
84391
|
+
callback(null, null);
|
|
84392
|
+
return;
|
|
84393
|
+
}
|
|
84049
84394
|
callback(null, resource);
|
|
84050
84395
|
}
|
|
84051
84396
|
load(url, callback, asset) {
|
|
@@ -84064,6 +84409,10 @@ class SogsParser {
|
|
|
84064
84409
|
responseType: Http.ResponseType.JSON
|
|
84065
84410
|
};
|
|
84066
84411
|
http.get(url.load, options, (err, meta)=>{
|
|
84412
|
+
if (this._shouldAbort(asset, false)) {
|
|
84413
|
+
callback(null, null);
|
|
84414
|
+
return;
|
|
84415
|
+
}
|
|
84067
84416
|
if (!err) {
|
|
84068
84417
|
this.loadTextures(url, callback, asset, meta);
|
|
84069
84418
|
} else {
|
|
@@ -84226,6 +84575,8 @@ class SogBundleParser {
|
|
|
84226
84575
|
contents: file.data
|
|
84227
84576
|
}, {
|
|
84228
84577
|
mipmaps: false
|
|
84578
|
+
}, {
|
|
84579
|
+
crossOrigin: 'anonymous'
|
|
84229
84580
|
});
|
|
84230
84581
|
} else {
|
|
84231
84582
|
const url = new URL(filename, new URL(filename, window.location.href).toString()).toString();
|
|
@@ -84234,6 +84585,8 @@ class SogBundleParser {
|
|
|
84234
84585
|
filename
|
|
84235
84586
|
}, {
|
|
84236
84587
|
mipmaps: false
|
|
84588
|
+
}, {
|
|
84589
|
+
crossOrigin: 'anonymous'
|
|
84237
84590
|
});
|
|
84238
84591
|
}
|
|
84239
84592
|
const promise = new Promise((resolve, reject)=>{
|
|
@@ -84253,7 +84606,11 @@ class SogBundleParser {
|
|
|
84253
84606
|
t.unload();
|
|
84254
84607
|
});
|
|
84255
84608
|
});
|
|
84609
|
+
const decompress = asset.data?.decompress;
|
|
84610
|
+
const minimalMemory = asset.options?.minimalMemory ?? false;
|
|
84256
84611
|
const data = new GSplatSogsData();
|
|
84612
|
+
data.url = url.original;
|
|
84613
|
+
data.minimalMemory = minimalMemory;
|
|
84257
84614
|
data.meta = meta;
|
|
84258
84615
|
data.numSplats = meta.count;
|
|
84259
84616
|
data.means_l = textures[meta.means.files[0]].resource;
|
|
@@ -84263,7 +84620,6 @@ class SogBundleParser {
|
|
|
84263
84620
|
data.sh0 = textures[meta.sh0.files[0]].resource;
|
|
84264
84621
|
data.sh_centroids = textures[meta.shN?.files[0]]?.resource;
|
|
84265
84622
|
data.sh_labels = textures[meta.shN?.files[1]]?.resource;
|
|
84266
|
-
const decompress = asset.data?.decompress;
|
|
84267
84623
|
if (!decompress) {
|
|
84268
84624
|
await data.prepareGpuData();
|
|
84269
84625
|
}
|
|
@@ -84275,6 +84631,126 @@ class SogBundleParser {
|
|
|
84275
84631
|
}
|
|
84276
84632
|
}
|
|
84277
84633
|
|
|
84634
|
+
class GSplatAssetLoaderBase {
|
|
84635
|
+
load(url) {}
|
|
84636
|
+
unload(url) {}
|
|
84637
|
+
getResource(url) {}
|
|
84638
|
+
destroy() {}
|
|
84639
|
+
}
|
|
84640
|
+
|
|
84641
|
+
class GSplatAssetLoader extends GSplatAssetLoaderBase {
|
|
84642
|
+
constructor(registry){
|
|
84643
|
+
super(), this._urlToAsset = new Map(), this.maxConcurrentLoads = 2, this.maxRetries = 2, this._currentlyLoading = new Set(), this._loadQueue = [], this._retryCount = new Map(), this._destroyed = false;
|
|
84644
|
+
this._registry = registry;
|
|
84645
|
+
}
|
|
84646
|
+
destroy() {
|
|
84647
|
+
this._destroyed = true;
|
|
84648
|
+
for (const asset of this._urlToAsset.values()){
|
|
84649
|
+
asset.fire('unload', asset);
|
|
84650
|
+
asset.off('load');
|
|
84651
|
+
asset.off('error');
|
|
84652
|
+
this._registry.remove(asset);
|
|
84653
|
+
asset.unload();
|
|
84654
|
+
}
|
|
84655
|
+
this._urlToAsset.clear();
|
|
84656
|
+
this._loadQueue.length = 0;
|
|
84657
|
+
this._currentlyLoading.clear();
|
|
84658
|
+
this._retryCount.clear();
|
|
84659
|
+
}
|
|
84660
|
+
_canLoad() {
|
|
84661
|
+
return !!this._registry.loader?.getHandler('gsplat');
|
|
84662
|
+
}
|
|
84663
|
+
load(url) {
|
|
84664
|
+
const asset = this._urlToAsset.get(url);
|
|
84665
|
+
if (asset?.loaded || this._currentlyLoading.has(url)) {
|
|
84666
|
+
return;
|
|
84667
|
+
}
|
|
84668
|
+
if (this._loadQueue.includes(url)) {
|
|
84669
|
+
return;
|
|
84670
|
+
}
|
|
84671
|
+
if (this._currentlyLoading.size < this.maxConcurrentLoads) {
|
|
84672
|
+
this._startLoading(url);
|
|
84673
|
+
} else {
|
|
84674
|
+
this._loadQueue.push(url);
|
|
84675
|
+
}
|
|
84676
|
+
}
|
|
84677
|
+
_startLoading(url) {
|
|
84678
|
+
this._currentlyLoading.add(url);
|
|
84679
|
+
let asset = this._urlToAsset.get(url);
|
|
84680
|
+
if (!asset) {
|
|
84681
|
+
asset = new Asset(url, 'gsplat', {
|
|
84682
|
+
url
|
|
84683
|
+
}, {}, {
|
|
84684
|
+
minimalMemory: true
|
|
84685
|
+
});
|
|
84686
|
+
this._registry.add(asset);
|
|
84687
|
+
this._urlToAsset.set(url, asset);
|
|
84688
|
+
}
|
|
84689
|
+
asset.once('load', ()=>this._onAssetLoadSuccess(url, asset));
|
|
84690
|
+
asset.once('error', (err)=>this._onAssetLoadError(url, asset, err));
|
|
84691
|
+
if (!asset.loaded && !asset.loading) {
|
|
84692
|
+
this._registry.load(asset);
|
|
84693
|
+
}
|
|
84694
|
+
}
|
|
84695
|
+
_onAssetLoadSuccess(url, asset) {
|
|
84696
|
+
if (this._destroyed || !this._urlToAsset.has(url)) {
|
|
84697
|
+
return;
|
|
84698
|
+
}
|
|
84699
|
+
this._currentlyLoading.delete(url);
|
|
84700
|
+
this._retryCount.delete(url);
|
|
84701
|
+
this._processQueue();
|
|
84702
|
+
}
|
|
84703
|
+
_onAssetLoadError(url, asset, err) {
|
|
84704
|
+
if (this._destroyed || !this._canLoad() || !this._urlToAsset.has(url)) {
|
|
84705
|
+
return;
|
|
84706
|
+
}
|
|
84707
|
+
const retryCount = this._retryCount.get(url) || 0;
|
|
84708
|
+
if (retryCount < this.maxRetries) {
|
|
84709
|
+
this._retryCount.set(url, retryCount + 1);
|
|
84710
|
+
asset.loaded = false;
|
|
84711
|
+
asset.loading = false;
|
|
84712
|
+
this._registry.load(asset);
|
|
84713
|
+
} else {
|
|
84714
|
+
this._currentlyLoading.delete(url);
|
|
84715
|
+
this._retryCount.delete(url);
|
|
84716
|
+
this._processQueue();
|
|
84717
|
+
}
|
|
84718
|
+
}
|
|
84719
|
+
_processQueue() {
|
|
84720
|
+
if (this._destroyed || !this._canLoad()) {
|
|
84721
|
+
return;
|
|
84722
|
+
}
|
|
84723
|
+
while(this._currentlyLoading.size < this.maxConcurrentLoads && this._loadQueue.length > 0){
|
|
84724
|
+
const url = this._loadQueue.shift();
|
|
84725
|
+
if (url) {
|
|
84726
|
+
this._startLoading(url);
|
|
84727
|
+
}
|
|
84728
|
+
}
|
|
84729
|
+
}
|
|
84730
|
+
unload(url) {
|
|
84731
|
+
this._currentlyLoading.delete(url);
|
|
84732
|
+
const queueIndex = this._loadQueue.indexOf(url);
|
|
84733
|
+
if (queueIndex !== -1) {
|
|
84734
|
+
this._loadQueue.splice(queueIndex, 1);
|
|
84735
|
+
}
|
|
84736
|
+
this._retryCount.delete(url);
|
|
84737
|
+
const asset = this._urlToAsset.get(url);
|
|
84738
|
+
if (asset) {
|
|
84739
|
+
asset.fire('unload', asset);
|
|
84740
|
+
asset.off('load');
|
|
84741
|
+
asset.off('error');
|
|
84742
|
+
this._registry.remove(asset);
|
|
84743
|
+
asset.unload();
|
|
84744
|
+
this._urlToAsset.delete(url);
|
|
84745
|
+
}
|
|
84746
|
+
this._processQueue();
|
|
84747
|
+
}
|
|
84748
|
+
getResource(url) {
|
|
84749
|
+
const asset = this._urlToAsset.get(url);
|
|
84750
|
+
return asset?.resource;
|
|
84751
|
+
}
|
|
84752
|
+
}
|
|
84753
|
+
|
|
84278
84754
|
class GSplatOctreeParser {
|
|
84279
84755
|
constructor(app, maxRetries){
|
|
84280
84756
|
this.app = app;
|
|
@@ -84294,7 +84770,8 @@ class GSplatOctreeParser {
|
|
|
84294
84770
|
};
|
|
84295
84771
|
http.get(url.load, options, (err, data)=>{
|
|
84296
84772
|
if (!err) {
|
|
84297
|
-
const
|
|
84773
|
+
const assetLoader = new GSplatAssetLoader(this.app.assets);
|
|
84774
|
+
const resource = new GSplatOctreeResource(asset.file.url, data, assetLoader);
|
|
84298
84775
|
callback(null, resource);
|
|
84299
84776
|
} else {
|
|
84300
84777
|
callback(`Error loading gsplat octree: ${url.original} [${err}]`);
|
|
@@ -89867,7 +90344,7 @@ class XrManager extends EventHandler {
|
|
|
89867
90344
|
this._type = null;
|
|
89868
90345
|
this._spaceType = null;
|
|
89869
90346
|
if (this.app.systems) {
|
|
89870
|
-
this.app.
|
|
90347
|
+
this.app.requestAnimationFrame();
|
|
89871
90348
|
}
|
|
89872
90349
|
};
|
|
89873
90350
|
session.addEventListener('end', onEnd);
|
|
@@ -89885,7 +90362,7 @@ class XrManager extends EventHandler {
|
|
|
89885
90362
|
});
|
|
89886
90363
|
session.requestReferenceSpace(spaceType).then((referenceSpace)=>{
|
|
89887
90364
|
this._referenceSpace = referenceSpace;
|
|
89888
|
-
this.app.
|
|
90365
|
+
this.app.requestAnimationFrame();
|
|
89889
90366
|
if (callback) callback(null);
|
|
89890
90367
|
this.fire('start');
|
|
89891
90368
|
}).catch((ex)=>{
|
|
@@ -90082,11 +90559,12 @@ class RenderPassPicker extends RenderPass {
|
|
|
90082
90559
|
});
|
|
90083
90560
|
this.viewBindGroups.length = 0;
|
|
90084
90561
|
}
|
|
90085
|
-
update(camera, scene, layers, mapping) {
|
|
90562
|
+
update(camera, scene, layers, mapping, depth) {
|
|
90086
90563
|
this.camera = camera;
|
|
90087
90564
|
this.scene = scene;
|
|
90088
90565
|
this.layers = layers;
|
|
90089
90566
|
this.mapping = mapping;
|
|
90567
|
+
this.depth = depth;
|
|
90090
90568
|
if (scene.clusteredLightingEnabled) {
|
|
90091
90569
|
this.emptyWorldClusters = this.renderer.worldClustersAllocator.empty;
|
|
90092
90570
|
}
|
|
@@ -90124,9 +90602,11 @@ class RenderPassPicker extends RenderPass {
|
|
|
90124
90602
|
}
|
|
90125
90603
|
renderer.setCameraUniforms(camera.camera, renderTarget);
|
|
90126
90604
|
if (device.supportsUniformBuffers) {
|
|
90605
|
+
renderer.initViewBindGroupFormat(clusteredLightingEnabled);
|
|
90127
90606
|
renderer.setupViewUniformBuffers(this.viewBindGroups, renderer.viewUniformFormat, renderer.viewBindGroupFormat, null);
|
|
90128
90607
|
}
|
|
90129
|
-
|
|
90608
|
+
const shaderPass = this.depth ? SHADER_DEPTH_PICK : SHADER_PICK;
|
|
90609
|
+
renderer.renderForward(camera.camera, renderTarget, tempMeshInstances$1, lights, shaderPass, (meshInstance)=>{
|
|
90130
90610
|
device.setBlendState(BlendState.NOBLEND);
|
|
90131
90611
|
});
|
|
90132
90612
|
tempMeshInstances$1.length = 0;
|
|
@@ -90139,21 +90619,31 @@ class RenderPassPicker extends RenderPass {
|
|
|
90139
90619
|
|
|
90140
90620
|
const tempSet = new Set();
|
|
90141
90621
|
const _rect = new Vec4();
|
|
90622
|
+
const _floatView = new Float32Array(1);
|
|
90623
|
+
const _int32View = new Int32Array(_floatView.buffer);
|
|
90142
90624
|
let Picker$1 = class Picker {
|
|
90143
|
-
constructor(app, width, height){
|
|
90625
|
+
constructor(app, width, height, depth = false){
|
|
90144
90626
|
this.renderTarget = null;
|
|
90627
|
+
this.colorBuffer = null;
|
|
90628
|
+
this.depthBuffer = null;
|
|
90629
|
+
this.renderTargetDepth = null;
|
|
90145
90630
|
this.mapping = new Map();
|
|
90146
90631
|
this.deviceValid = true;
|
|
90147
|
-
this.renderer = app.renderer;
|
|
90148
90632
|
this.device = app.graphicsDevice;
|
|
90149
90633
|
this.renderPass = new RenderPassPicker(this.device, app.renderer);
|
|
90634
|
+
this.depth = depth;
|
|
90150
90635
|
this.width = 0;
|
|
90151
90636
|
this.height = 0;
|
|
90152
90637
|
this.resize(width, height);
|
|
90638
|
+
this.allocateRenderTarget();
|
|
90153
90639
|
this.device.on('destroy', ()=>{
|
|
90154
90640
|
this.deviceValid = false;
|
|
90155
90641
|
});
|
|
90156
90642
|
}
|
|
90643
|
+
destroy() {
|
|
90644
|
+
this.releaseRenderTarget();
|
|
90645
|
+
this.renderPass?.destroy();
|
|
90646
|
+
}
|
|
90157
90647
|
getSelection(x, y, width = 1, height = 1) {
|
|
90158
90648
|
const device = this.device;
|
|
90159
90649
|
if (device.isWebGPU) {
|
|
@@ -90169,17 +90659,51 @@ let Picker$1 = class Picker {
|
|
|
90169
90659
|
return this.decodePixels(pixels, this.mapping);
|
|
90170
90660
|
}
|
|
90171
90661
|
getSelectionAsync(x, y, width = 1, height = 1) {
|
|
90662
|
+
if (!this.renderTarget || !this.renderTarget.colorBuffer) {
|
|
90663
|
+
return Promise.resolve([]);
|
|
90664
|
+
}
|
|
90665
|
+
return this._readTexture(this.renderTarget.colorBuffer, x, y, width, height, this.renderTarget).then((pixels)=>{
|
|
90666
|
+
return this.decodePixels(pixels, this.mapping);
|
|
90667
|
+
});
|
|
90668
|
+
}
|
|
90669
|
+
_readTexture(texture, x, y, width, height, renderTarget) {
|
|
90172
90670
|
if (this.device?.isWebGL2) {
|
|
90173
|
-
y =
|
|
90671
|
+
y = renderTarget.height - (y + height);
|
|
90174
90672
|
}
|
|
90175
90673
|
const rect = this.sanitizeRect(x, y, width, height);
|
|
90176
|
-
return
|
|
90177
|
-
|
|
90178
|
-
|
|
90179
|
-
}).then((pixels)=>{
|
|
90180
|
-
return this.decodePixels(pixels, this.mapping);
|
|
90674
|
+
return texture.read(rect.x, rect.y, rect.z, rect.w, {
|
|
90675
|
+
immediate: true,
|
|
90676
|
+
renderTarget: renderTarget
|
|
90181
90677
|
});
|
|
90182
90678
|
}
|
|
90679
|
+
async getWorldPointAsync(x, y) {
|
|
90680
|
+
const camera = this.renderPass.camera;
|
|
90681
|
+
if (!camera) {
|
|
90682
|
+
return null;
|
|
90683
|
+
}
|
|
90684
|
+
const viewProjMat = new Mat4().mul2(camera.camera.projectionMatrix, camera.camera.viewMatrix);
|
|
90685
|
+
const invViewProj = viewProjMat.invert();
|
|
90686
|
+
const depth = await this.getPointDepthAsync(x, y);
|
|
90687
|
+
if (depth === null) {
|
|
90688
|
+
return null;
|
|
90689
|
+
}
|
|
90690
|
+
const deviceCoord = new Vec4(x / this.width * 2 - 1, (1 - y / this.height) * 2 - 1, depth * 2 - 1, 1.0);
|
|
90691
|
+
invViewProj.transformVec4(deviceCoord, deviceCoord);
|
|
90692
|
+
deviceCoord.mulScalar(1.0 / deviceCoord.w);
|
|
90693
|
+
return new Vec3(deviceCoord.x, deviceCoord.y, deviceCoord.z);
|
|
90694
|
+
}
|
|
90695
|
+
async getPointDepthAsync(x, y) {
|
|
90696
|
+
if (!this.depthBuffer) {
|
|
90697
|
+
return null;
|
|
90698
|
+
}
|
|
90699
|
+
const pixels = await this._readTexture(this.depthBuffer, x, y, 1, 1, this.renderTargetDepth);
|
|
90700
|
+
const intBits = pixels[0] << 24 | pixels[1] << 16 | pixels[2] << 8 | pixels[3];
|
|
90701
|
+
if (intBits === 0xFFFFFFFF) {
|
|
90702
|
+
return null;
|
|
90703
|
+
}
|
|
90704
|
+
_int32View[0] = intBits;
|
|
90705
|
+
return _floatView[0];
|
|
90706
|
+
}
|
|
90183
90707
|
sanitizeRect(x, y, width, height) {
|
|
90184
90708
|
const maxWidth = this.renderTarget.width;
|
|
90185
90709
|
const maxHeight = this.renderTarget.height;
|
|
@@ -90214,8 +90738,8 @@ let Picker$1 = class Picker {
|
|
|
90214
90738
|
}
|
|
90215
90739
|
return selection;
|
|
90216
90740
|
}
|
|
90217
|
-
|
|
90218
|
-
|
|
90741
|
+
createTexture(name) {
|
|
90742
|
+
return new Texture(this.device, {
|
|
90219
90743
|
format: PIXELFORMAT_RGBA8,
|
|
90220
90744
|
width: this.width,
|
|
90221
90745
|
height: this.height,
|
|
@@ -90224,19 +90748,35 @@ let Picker$1 = class Picker {
|
|
|
90224
90748
|
magFilter: FILTER_NEAREST,
|
|
90225
90749
|
addressU: ADDRESS_CLAMP_TO_EDGE,
|
|
90226
90750
|
addressV: ADDRESS_CLAMP_TO_EDGE,
|
|
90227
|
-
name:
|
|
90751
|
+
name: name
|
|
90228
90752
|
});
|
|
90753
|
+
}
|
|
90754
|
+
allocateRenderTarget() {
|
|
90755
|
+
this.colorBuffer = this.createTexture('pick');
|
|
90756
|
+
const colorBuffers = [
|
|
90757
|
+
this.colorBuffer
|
|
90758
|
+
];
|
|
90759
|
+
if (this.depth) {
|
|
90760
|
+
this.depthBuffer = this.createTexture('pick-depth');
|
|
90761
|
+
colorBuffers.push(this.depthBuffer);
|
|
90762
|
+
this.renderTargetDepth = new RenderTarget({
|
|
90763
|
+
colorBuffer: this.depthBuffer,
|
|
90764
|
+
depth: false
|
|
90765
|
+
});
|
|
90766
|
+
}
|
|
90229
90767
|
this.renderTarget = new RenderTarget({
|
|
90230
|
-
|
|
90768
|
+
colorBuffers: colorBuffers,
|
|
90231
90769
|
depth: true
|
|
90232
90770
|
});
|
|
90233
90771
|
}
|
|
90234
90772
|
releaseRenderTarget() {
|
|
90235
|
-
|
|
90236
|
-
|
|
90237
|
-
|
|
90238
|
-
|
|
90239
|
-
|
|
90773
|
+
this.renderTarget?.destroyTextureBuffers();
|
|
90774
|
+
this.renderTarget?.destroy();
|
|
90775
|
+
this.renderTarget = null;
|
|
90776
|
+
this.renderTargetDepth?.destroy();
|
|
90777
|
+
this.renderTargetDepth = null;
|
|
90778
|
+
this.colorBuffer = null;
|
|
90779
|
+
this.depthBuffer = null;
|
|
90240
90780
|
}
|
|
90241
90781
|
prepare(camera, scene, layers) {
|
|
90242
90782
|
if (layers instanceof Layer) {
|
|
@@ -90244,17 +90784,14 @@ let Picker$1 = class Picker {
|
|
|
90244
90784
|
layers
|
|
90245
90785
|
];
|
|
90246
90786
|
}
|
|
90247
|
-
|
|
90248
|
-
|
|
90249
|
-
this.allocateRenderTarget();
|
|
90250
|
-
}
|
|
90787
|
+
this.renderTarget?.resize(this.width, this.height);
|
|
90788
|
+
this.renderTargetDepth?.resize(this.width, this.height);
|
|
90251
90789
|
this.mapping.clear();
|
|
90252
90790
|
const renderPass = this.renderPass;
|
|
90253
90791
|
renderPass.init(this.renderTarget);
|
|
90254
|
-
renderPass.
|
|
90255
|
-
renderPass.colorOps.clear = true;
|
|
90792
|
+
renderPass.setClearColor(Color.WHITE);
|
|
90256
90793
|
renderPass.depthStencilOps.clearDepth = true;
|
|
90257
|
-
renderPass.update(camera, scene, layers, this.mapping);
|
|
90794
|
+
renderPass.update(camera, scene, layers, this.mapping, this.depth);
|
|
90258
90795
|
renderPass.render();
|
|
90259
90796
|
}
|
|
90260
90797
|
resize(width, height) {
|
|
@@ -101689,31 +102226,47 @@ class Viewer {
|
|
|
101689
102226
|
}
|
|
101690
102227
|
else {
|
|
101691
102228
|
const { gsplat } = app.scene;
|
|
101692
|
-
//
|
|
101693
|
-
const
|
|
101694
|
-
|
|
101695
|
-
|
|
101696
|
-
|
|
101697
|
-
|
|
102229
|
+
// quality ranges
|
|
102230
|
+
const quality = {
|
|
102231
|
+
low: {
|
|
102232
|
+
range: [2, 8],
|
|
102233
|
+
splatBudget: 1
|
|
102234
|
+
},
|
|
102235
|
+
high: {
|
|
102236
|
+
range: [0, 8],
|
|
102237
|
+
splatBudget: 4
|
|
102238
|
+
}
|
|
102239
|
+
};
|
|
102240
|
+
// start in low quality mode so we can get user interacting asap
|
|
102241
|
+
gsplat.lodRangeMin = quality.low.range[0];
|
|
102242
|
+
gsplat.lodRangeMax = quality.low.range[1];
|
|
102243
|
+
results[0].gsplat.splatBudget = quality.low.splatBudget * 1000000;
|
|
101698
102244
|
// these two allow LOD behind camera to drop, saves lots of splats
|
|
101699
102245
|
gsplat.lodUpdateAngle = 90;
|
|
101700
102246
|
gsplat.lodBehindPenalty = 5;
|
|
101701
102247
|
// same performance, but rotating on slow devices does not give us unsorted splats on sides
|
|
101702
102248
|
gsplat.radialSorting = true;
|
|
101703
102249
|
const eventHandler = app.systems.gsplat;
|
|
101704
|
-
// force
|
|
102250
|
+
// we must force continuous rendering with streaming & lod system
|
|
101705
102251
|
this.forceRenderNextFrame = true;
|
|
101706
102252
|
let current = 0;
|
|
101707
102253
|
let watermark = 1;
|
|
101708
102254
|
const readyHandler = (camera, layer, ready, loading) => {
|
|
101709
|
-
if (ready &&
|
|
102255
|
+
if (ready && loading === 0) {
|
|
101710
102256
|
// scene is done loading
|
|
101711
102257
|
eventHandler.off('frame:ready', readyHandler);
|
|
101712
|
-
this.forceRenderNextFrame = false;
|
|
101713
102258
|
state.readyToRender = true;
|
|
101714
|
-
|
|
101715
|
-
|
|
101716
|
-
|
|
102259
|
+
// handle quality mode changes
|
|
102260
|
+
const updateLod = () => {
|
|
102261
|
+
const settings = state.hqMode ? quality.high : quality.low;
|
|
102262
|
+
gsplat.lodRangeMin = settings.range[0];
|
|
102263
|
+
gsplat.lodRangeMax = settings.range[1];
|
|
102264
|
+
results[0].gsplat.splatBudget = settings.splatBudget * 1000000;
|
|
102265
|
+
};
|
|
102266
|
+
events.on('hqMode:changed', updateLod);
|
|
102267
|
+
updateLod();
|
|
102268
|
+
// debug colorize lods
|
|
102269
|
+
gsplat.colorizeLod = config.colorize;
|
|
101717
102270
|
// wait for the first valid frame to complete rendering
|
|
101718
102271
|
app.once('frameend', () => {
|
|
101719
102272
|
events.fire('firstFrame');
|
|
@@ -101721,9 +102274,6 @@ class Viewer {
|
|
|
101721
102274
|
window.firstFrame?.();
|
|
101722
102275
|
});
|
|
101723
102276
|
}
|
|
101724
|
-
if (ready) {
|
|
101725
|
-
app.renderNextFrame = true;
|
|
101726
|
-
}
|
|
101727
102277
|
// update loading status
|
|
101728
102278
|
if (loading !== current) {
|
|
101729
102279
|
watermark = Math.max(watermark, loading);
|
|
@@ -102345,7 +102895,7 @@ const initXr = (global) => {
|
|
|
102345
102895
|
});
|
|
102346
102896
|
};
|
|
102347
102897
|
|
|
102348
|
-
var version = "1.
|
|
102898
|
+
var version = "1.10.1";
|
|
102349
102899
|
|
|
102350
102900
|
const loadGsplat = async (app, config, progressCallback) => {
|
|
102351
102901
|
const { contents, contentUrl, unified, aa } = config;
|
|
@@ -102409,7 +102959,7 @@ const main = (app, camera, settingsJson, config) => {
|
|
|
102409
102959
|
const events = new EventHandler();
|
|
102410
102960
|
const state = observe(events, {
|
|
102411
102961
|
readyToRender: false,
|
|
102412
|
-
hqMode:
|
|
102962
|
+
hqMode: !platform.mobile,
|
|
102413
102963
|
progress: 0,
|
|
102414
102964
|
inputMode: 'desktop',
|
|
102415
102965
|
cameraMode: 'orbit',
|