@playcanvas/supersplat-viewer 1.6.2 → 1.7.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 +16 -37
- package/dist/index.js +1 -1
- package/package.json +21 -21
- package/public/index.js +1752 -436
- 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 = '2.
|
|
4
|
-
const revision = '
|
|
3
|
+
const version = '2.12.3';
|
|
4
|
+
const revision = '49d2399';
|
|
5
5
|
function extend(target, ex) {
|
|
6
6
|
for(const prop in ex){
|
|
7
7
|
const copy = ex[prop];
|
|
@@ -3911,6 +3911,11 @@ const FUNC_ALWAYS = 7;
|
|
|
3911
3911
|
const INDEXFORMAT_UINT8 = 0;
|
|
3912
3912
|
const INDEXFORMAT_UINT16 = 1;
|
|
3913
3913
|
const INDEXFORMAT_UINT32 = 2;
|
|
3914
|
+
const indexFormatByteSize = [
|
|
3915
|
+
1,
|
|
3916
|
+
2,
|
|
3917
|
+
4
|
|
3918
|
+
];
|
|
3914
3919
|
const PIXELFORMAT_A8 = 0;
|
|
3915
3920
|
const PIXELFORMAT_L8 = 1;
|
|
3916
3921
|
const PIXELFORMAT_LA8 = 2;
|
|
@@ -5326,6 +5331,7 @@ class Texture {
|
|
|
5326
5331
|
resize(width, height, depth = 1) {
|
|
5327
5332
|
const device = this.device;
|
|
5328
5333
|
this.adjustVramSizeTracking(device._vram, -this._gpuSize);
|
|
5334
|
+
this._gpuSize = 0;
|
|
5329
5335
|
this.impl.destroy(device);
|
|
5330
5336
|
this._clearLevels();
|
|
5331
5337
|
this._width = Math.floor(width);
|
|
@@ -6443,7 +6449,7 @@ class GraphicsDevice extends EventHandler {
|
|
|
6443
6449
|
this.EVENT_RESIZE = 'resizecanvas';
|
|
6444
6450
|
}
|
|
6445
6451
|
constructor(canvas, options){
|
|
6446
|
-
super(), this.backBuffer = null, this.backBufferSize = new Vec2(), this.backBufferAntialias = false, this.isWebGPU = false, this.isWebGL2 = false, this.isHdr = false, this.maxIndirectDrawCount = 1024, this.maxColorAttachments = 1, this.maxSamples = 1, this.supportsCompute = false, this.supportsStorageTextureRead = false, this.renderTarget = null, this.shaders = [], this.textures = [], this.targets = new Set(), this.renderVersion = 0, this.insideRenderPass = false, this.supportsUniformBuffers = false, this.supportsClipDistances = false, this.textureRG11B10Renderable = false, this.textureFloatFilterable = false, this.blendState = new BlendState(), this.depthState = new DepthState(), this.stencilEnabled = false, this.stencilFront = new StencilParameters(), this.stencilBack = new StencilParameters(), this.defaultClearOptions = {
|
|
6452
|
+
super(), this.backBuffer = null, this.backBufferSize = new Vec2(), this.backBufferAntialias = false, this.isWebGPU = false, this.isWebGL2 = false, this.isHdr = false, this.maxIndirectDrawCount = 1024, this.maxColorAttachments = 1, this.maxSamples = 1, this.supportsMultiDraw = true, this.supportsCompute = false, this.supportsStorageTextureRead = false, this.renderTarget = null, this.shaders = [], this.textures = [], this.targets = new Set(), this.renderVersion = 0, this.insideRenderPass = false, this.supportsUniformBuffers = false, this.supportsClipDistances = false, this.textureRG11B10Renderable = false, this.textureFloatFilterable = false, this.blendState = new BlendState(), this.depthState = new DepthState(), this.stencilEnabled = false, this.stencilFront = new StencilParameters(), this.stencilBack = new StencilParameters(), this._destroyed = false, this.defaultClearOptions = {
|
|
6447
6453
|
color: [
|
|
6448
6454
|
0,
|
|
6449
6455
|
0,
|
|
@@ -6525,6 +6531,7 @@ class GraphicsDevice extends EventHandler {
|
|
|
6525
6531
|
capsDefines.clear();
|
|
6526
6532
|
if (this.textureFloatFilterable) capsDefines.set('CAPS_TEXTURE_FLOAT_FILTERABLE', '');
|
|
6527
6533
|
if (this.textureFloatRenderable) capsDefines.set('CAPS_TEXTURE_FLOAT_RENDERABLE', '');
|
|
6534
|
+
if (this.supportsMultiDraw) capsDefines.set('CAPS_MULTI_DRAW', '');
|
|
6528
6535
|
}
|
|
6529
6536
|
destroy() {
|
|
6530
6537
|
this.fire('destroy');
|
|
@@ -6534,6 +6541,7 @@ class GraphicsDevice extends EventHandler {
|
|
|
6534
6541
|
this.dynamicBuffers = null;
|
|
6535
6542
|
this.gpuProfiler?.destroy();
|
|
6536
6543
|
this.gpuProfiler = null;
|
|
6544
|
+
this._destroyed = true;
|
|
6537
6545
|
}
|
|
6538
6546
|
onDestroyShader(shader) {
|
|
6539
6547
|
this.fire('destroy:shader', shader);
|
|
@@ -6603,7 +6611,7 @@ class GraphicsDevice extends EventHandler {
|
|
|
6603
6611
|
clearVertexBuffer() {
|
|
6604
6612
|
this.vertexBuffers.length = 0;
|
|
6605
6613
|
}
|
|
6606
|
-
getIndirectDrawSlot() {
|
|
6614
|
+
getIndirectDrawSlot(count = 1) {
|
|
6607
6615
|
return 0;
|
|
6608
6616
|
}
|
|
6609
6617
|
get indirectDrawBuffer() {
|
|
@@ -6617,7 +6625,7 @@ class GraphicsDevice extends EventHandler {
|
|
|
6617
6625
|
target.init();
|
|
6618
6626
|
this.targets.add(target);
|
|
6619
6627
|
}
|
|
6620
|
-
draw(primitive, indexBuffer, numInstances,
|
|
6628
|
+
draw(primitive, indexBuffer, numInstances, drawCommands, first = true, last = true) {}
|
|
6621
6629
|
_isBrowserInterface(texture) {
|
|
6622
6630
|
return this._isImageBrowserInterface(texture) || this._isImageCanvasInterface(texture) || this._isImageVideoInterface(texture);
|
|
6623
6631
|
}
|
|
@@ -9849,6 +9857,7 @@ layout(location = 7) out highp outType_7 pcFragColor7;
|
|
|
9849
9857
|
`;
|
|
9850
9858
|
|
|
9851
9859
|
var gles3VS = `
|
|
9860
|
+
#extension GL_ANGLE_multi_draw : enable
|
|
9852
9861
|
#define attribute in
|
|
9853
9862
|
#define varying out
|
|
9854
9863
|
#define texture2D texture
|
|
@@ -10067,6 +10076,7 @@ class ShaderDefinitionUtils {
|
|
|
10067
10076
|
vincludes: options.vertexIncludes,
|
|
10068
10077
|
fincludes: options.fragmentIncludes,
|
|
10069
10078
|
fshader: fragCode,
|
|
10079
|
+
feedbackVaryings: options.feedbackVaryings,
|
|
10070
10080
|
useTransformFeedback: options.useTransformFeedback,
|
|
10071
10081
|
meshUniformBufferFormat: options.meshUniformBufferFormat,
|
|
10072
10082
|
meshBindGroupFormat: options.meshBindGroupFormat
|
|
@@ -10862,6 +10872,9 @@ class GpuProfiler {
|
|
|
10862
10872
|
this.pastFrameAllocations.delete(renderVersion);
|
|
10863
10873
|
}
|
|
10864
10874
|
getSlot(name) {
|
|
10875
|
+
if (this.frameAllocations.length >= this.maxCount) {
|
|
10876
|
+
return -1;
|
|
10877
|
+
}
|
|
10865
10878
|
const slot = this.frameAllocations.length;
|
|
10866
10879
|
this.frameAllocations.push(name);
|
|
10867
10880
|
return slot;
|
|
@@ -10875,6 +10888,7 @@ class GpuProfiler {
|
|
|
10875
10888
|
this._enabled = false;
|
|
10876
10889
|
this._enableRequest = false;
|
|
10877
10890
|
this._frameTime = 0;
|
|
10891
|
+
this.maxCount = 9999;
|
|
10878
10892
|
}
|
|
10879
10893
|
}
|
|
10880
10894
|
|
|
@@ -10947,7 +10961,8 @@ class WebgpuGpuProfiler extends GpuProfiler {
|
|
|
10947
10961
|
constructor(device){
|
|
10948
10962
|
super();
|
|
10949
10963
|
this.device = device;
|
|
10950
|
-
this.
|
|
10964
|
+
this.maxCount = 1024;
|
|
10965
|
+
this.timestampQueriesSet = device.supportsTimestampQuery ? new WebgpuQuerySet(device, true, 2 * this.maxCount) : null;
|
|
10951
10966
|
}
|
|
10952
10967
|
destroy() {
|
|
10953
10968
|
this.timestampQueriesSet?.destroy();
|
|
@@ -11165,6 +11180,38 @@ class StorageBuffer {
|
|
|
11165
11180
|
}
|
|
11166
11181
|
}
|
|
11167
11182
|
|
|
11183
|
+
class WebgpuDrawCommands {
|
|
11184
|
+
constructor(device){
|
|
11185
|
+
this.gpuIndirect = null;
|
|
11186
|
+
this.gpuIndirectSigned = null;
|
|
11187
|
+
this.storage = null;
|
|
11188
|
+
this.device = device;
|
|
11189
|
+
}
|
|
11190
|
+
allocate(maxCount) {
|
|
11191
|
+
this.gpuIndirect = new Uint32Array(5 * maxCount);
|
|
11192
|
+
this.gpuIndirectSigned = new Int32Array(this.gpuIndirect.buffer);
|
|
11193
|
+
this.storage = new StorageBuffer(this.device, this.gpuIndirect.byteLength, BUFFERUSAGE_INDIRECT | BUFFERUSAGE_COPY_DST);
|
|
11194
|
+
}
|
|
11195
|
+
add(i, indexOrVertexCount, instanceCount, firstIndexOrVertex, baseVertex = 0, firstInstance = 0) {
|
|
11196
|
+
const o = i * 5;
|
|
11197
|
+
this.gpuIndirect[o + 0] = indexOrVertexCount;
|
|
11198
|
+
this.gpuIndirect[o + 1] = instanceCount;
|
|
11199
|
+
this.gpuIndirect[o + 2] = firstIndexOrVertex;
|
|
11200
|
+
this.gpuIndirectSigned[o + 3] = baseVertex;
|
|
11201
|
+
this.gpuIndirect[o + 4] = firstInstance;
|
|
11202
|
+
}
|
|
11203
|
+
update(count) {
|
|
11204
|
+
if (this.storage && count > 0) {
|
|
11205
|
+
const used = count * 5;
|
|
11206
|
+
this.storage.write(0, this.gpuIndirect, 0, used);
|
|
11207
|
+
}
|
|
11208
|
+
}
|
|
11209
|
+
destroy() {
|
|
11210
|
+
this.storage?.destroy();
|
|
11211
|
+
this.storage = null;
|
|
11212
|
+
}
|
|
11213
|
+
}
|
|
11214
|
+
|
|
11168
11215
|
const _uniqueLocations = new Map();
|
|
11169
11216
|
const _indirectEntryByteSize = 5 * 4;
|
|
11170
11217
|
class WebgpuGraphicsDevice extends GraphicsDevice {
|
|
@@ -11384,6 +11431,9 @@ class WebgpuGraphicsDevice extends GraphicsDevice {
|
|
|
11384
11431
|
createShaderImpl(shader) {
|
|
11385
11432
|
return new WebgpuShader(shader);
|
|
11386
11433
|
}
|
|
11434
|
+
createDrawCommandImpl(drawCommands) {
|
|
11435
|
+
return new WebgpuDrawCommands(this);
|
|
11436
|
+
}
|
|
11387
11437
|
createTextureImpl(texture) {
|
|
11388
11438
|
return new WebgpuTexture(texture);
|
|
11389
11439
|
}
|
|
@@ -11409,14 +11459,15 @@ class WebgpuGraphicsDevice extends GraphicsDevice {
|
|
|
11409
11459
|
this._indirectDrawBuffer = null;
|
|
11410
11460
|
}
|
|
11411
11461
|
if (this._indirectDrawBuffer === null) {
|
|
11412
|
-
this._indirectDrawBuffer = new StorageBuffer(this, this.maxIndirectDrawCount *
|
|
11462
|
+
this._indirectDrawBuffer = new StorageBuffer(this, this.maxIndirectDrawCount * _indirectEntryByteSize, BUFFERUSAGE_INDIRECT | BUFFERUSAGE_COPY_DST);
|
|
11413
11463
|
this._indirectDrawBufferCount = this.maxIndirectDrawCount;
|
|
11414
11464
|
}
|
|
11415
11465
|
}
|
|
11416
|
-
getIndirectDrawSlot() {
|
|
11466
|
+
getIndirectDrawSlot(count = 1) {
|
|
11417
11467
|
this.allocateIndirectDrawBuffer();
|
|
11418
11468
|
const slot = this._indirectDrawNextIndex;
|
|
11419
|
-
this._indirectDrawNextIndex
|
|
11469
|
+
const nextIndex = this._indirectDrawNextIndex + count;
|
|
11470
|
+
this._indirectDrawNextIndex = nextIndex;
|
|
11420
11471
|
return slot;
|
|
11421
11472
|
}
|
|
11422
11473
|
setBindGroup(index, bindGroup, offsets) {
|
|
@@ -11453,7 +11504,7 @@ class WebgpuGraphicsDevice extends GraphicsDevice {
|
|
|
11453
11504
|
validateVB(vb1);
|
|
11454
11505
|
_uniqueLocations.clear();
|
|
11455
11506
|
}
|
|
11456
|
-
draw(primitive, indexBuffer, numInstances = 1,
|
|
11507
|
+
draw(primitive, indexBuffer, numInstances = 1, drawCommands, first = true, last = true) {
|
|
11457
11508
|
if (this.shader.ready && !this.shader.failed) {
|
|
11458
11509
|
const passEncoder = this.passEncoder;
|
|
11459
11510
|
let pipeline = this.pipeline;
|
|
@@ -11475,13 +11526,17 @@ class WebgpuGraphicsDevice extends GraphicsDevice {
|
|
|
11475
11526
|
if (indexBuffer) {
|
|
11476
11527
|
passEncoder.setIndexBuffer(indexBuffer.impl.buffer, indexBuffer.impl.format);
|
|
11477
11528
|
}
|
|
11478
|
-
if (
|
|
11479
|
-
const
|
|
11480
|
-
const indirectBuffer =
|
|
11481
|
-
|
|
11482
|
-
|
|
11483
|
-
|
|
11484
|
-
|
|
11529
|
+
if (drawCommands) {
|
|
11530
|
+
const storage = drawCommands.impl?.storage ?? this.indirectDrawBuffer;
|
|
11531
|
+
const indirectBuffer = storage.impl.buffer;
|
|
11532
|
+
const drawsCount = drawCommands.count;
|
|
11533
|
+
for(let d = 0; d < drawsCount; d++){
|
|
11534
|
+
const indirectOffset = (drawCommands.slotIndex + d) * _indirectEntryByteSize;
|
|
11535
|
+
if (indexBuffer) {
|
|
11536
|
+
passEncoder.drawIndexedIndirect(indirectBuffer, indirectOffset);
|
|
11537
|
+
} else {
|
|
11538
|
+
passEncoder.drawIndirect(indirectBuffer, indirectOffset);
|
|
11539
|
+
}
|
|
11485
11540
|
}
|
|
11486
11541
|
} else {
|
|
11487
11542
|
if (indexBuffer) {
|
|
@@ -11551,12 +11606,14 @@ class WebgpuGraphicsDevice extends GraphicsDevice {
|
|
|
11551
11606
|
if (this.gpuProfiler._enabled) {
|
|
11552
11607
|
if (this.gpuProfiler.timestampQueriesSet) {
|
|
11553
11608
|
const slot = this.gpuProfiler.getSlot(name);
|
|
11554
|
-
|
|
11555
|
-
|
|
11556
|
-
|
|
11557
|
-
|
|
11558
|
-
|
|
11559
|
-
|
|
11609
|
+
if (slot === -1) ; else {
|
|
11610
|
+
passDesc = passDesc ?? {};
|
|
11611
|
+
passDesc.timestampWrites = {
|
|
11612
|
+
querySet: this.gpuProfiler.timestampQueriesSet.querySet,
|
|
11613
|
+
beginningOfPassWriteIndex: slot * 2,
|
|
11614
|
+
endOfPassWriteIndex: slot * 2 + 1
|
|
11615
|
+
};
|
|
11616
|
+
}
|
|
11560
11617
|
}
|
|
11561
11618
|
}
|
|
11562
11619
|
return passDesc;
|
|
@@ -11992,10 +12049,13 @@ class WebglShader {
|
|
|
11992
12049
|
const definition = shader.definition;
|
|
11993
12050
|
const attrs = definition.attributes;
|
|
11994
12051
|
if (definition.useTransformFeedback) {
|
|
11995
|
-
|
|
11996
|
-
|
|
11997
|
-
|
|
11998
|
-
|
|
12052
|
+
let outNames = definition.feedbackVaryings;
|
|
12053
|
+
if (!outNames) {
|
|
12054
|
+
outNames = [];
|
|
12055
|
+
for(const attr in attrs){
|
|
12056
|
+
if (attrs.hasOwnProperty(attr)) {
|
|
12057
|
+
outNames.push(`out_${attr}`);
|
|
12058
|
+
}
|
|
11999
12059
|
}
|
|
12000
12060
|
}
|
|
12001
12061
|
gl.transformFeedbackVaryings(glProgram, outNames, gl.INTERLEAVED_ATTRIBS);
|
|
@@ -12066,6 +12126,9 @@ class WebglShader {
|
|
|
12066
12126
|
for(let i = 0; i < numUniforms; i++){
|
|
12067
12127
|
const info = gl.getActiveUniform(glProgram, i);
|
|
12068
12128
|
const location = gl.getUniformLocation(glProgram, info.name);
|
|
12129
|
+
if (_vertexShaderBuiltins.has(info.name)) {
|
|
12130
|
+
continue;
|
|
12131
|
+
}
|
|
12069
12132
|
const shaderInput = new WebglShaderInput(device, info.name, device.pcUniformType[info.type], location);
|
|
12070
12133
|
if (samplerTypes.has(info.type)) {
|
|
12071
12134
|
this.samplers.push(shaderInput);
|
|
@@ -12123,6 +12186,25 @@ class WebglShader {
|
|
|
12123
12186
|
}
|
|
12124
12187
|
}
|
|
12125
12188
|
|
|
12189
|
+
class WebglDrawCommands {
|
|
12190
|
+
constructor(indexSizeBytes){
|
|
12191
|
+
this.glCounts = null;
|
|
12192
|
+
this.glOffsetsBytes = null;
|
|
12193
|
+
this.glInstanceCounts = null;
|
|
12194
|
+
this.indexSizeBytes = indexSizeBytes;
|
|
12195
|
+
}
|
|
12196
|
+
allocate(maxCount) {
|
|
12197
|
+
this.glCounts = new Int32Array(maxCount);
|
|
12198
|
+
this.glOffsetsBytes = new Int32Array(maxCount);
|
|
12199
|
+
this.glInstanceCounts = new Int32Array(maxCount);
|
|
12200
|
+
}
|
|
12201
|
+
add(i, indexOrVertexCount, instanceCount, firstIndexOrVertex) {
|
|
12202
|
+
this.glCounts[i] = indexOrVertexCount;
|
|
12203
|
+
this.glOffsetsBytes[i] = firstIndexOrVertex * this.indexSizeBytes;
|
|
12204
|
+
this.glInstanceCounts[i] = instanceCount;
|
|
12205
|
+
}
|
|
12206
|
+
}
|
|
12207
|
+
|
|
12126
12208
|
function downsampleImage(image, size) {
|
|
12127
12209
|
const srcW = image.width;
|
|
12128
12210
|
const srcH = image.height;
|
|
@@ -13458,6 +13540,9 @@ class WebglGraphicsDevice extends GraphicsDevice {
|
|
|
13458
13540
|
createShaderImpl(shader) {
|
|
13459
13541
|
return new WebglShader(shader);
|
|
13460
13542
|
}
|
|
13543
|
+
createDrawCommandImpl(drawCommands) {
|
|
13544
|
+
return new WebglDrawCommands(drawCommands.indexSizeBytes);
|
|
13545
|
+
}
|
|
13461
13546
|
createTextureImpl(texture) {
|
|
13462
13547
|
return new WebglTexture(texture);
|
|
13463
13548
|
}
|
|
@@ -13515,6 +13600,8 @@ class WebglGraphicsDevice extends GraphicsDevice {
|
|
|
13515
13600
|
this.extFloatBlend = this.getExtension('EXT_float_blend');
|
|
13516
13601
|
this.extTextureFilterAnisotropic = this.getExtension('EXT_texture_filter_anisotropic', 'WEBKIT_EXT_texture_filter_anisotropic');
|
|
13517
13602
|
this.extParallelShaderCompile = this.getExtension('KHR_parallel_shader_compile');
|
|
13603
|
+
this.extMultiDraw = this.getExtension('WEBGL_multi_draw');
|
|
13604
|
+
this.supportsMultiDraw = !!this.extMultiDraw;
|
|
13518
13605
|
this.extCompressedTextureETC1 = this.getExtension('WEBGL_compressed_texture_etc1');
|
|
13519
13606
|
this.extCompressedTextureETC = this.getExtension('WEBGL_compressed_texture_etc');
|
|
13520
13607
|
this.extCompressedTexturePVRTC = this.getExtension('WEBGL_compressed_texture_pvrtc', 'WEBKIT_WEBGL_compressed_texture_pvrtc');
|
|
@@ -14014,7 +14101,34 @@ class WebglGraphicsDevice extends GraphicsDevice {
|
|
|
14014
14101
|
const bufferId = indexBuffer ? indexBuffer.impl.bufferId : null;
|
|
14015
14102
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, bufferId);
|
|
14016
14103
|
}
|
|
14017
|
-
|
|
14104
|
+
_multiDrawLoopFallback(mode, primitive, indexBuffer, numInstances, drawCommands) {
|
|
14105
|
+
const gl = this.gl;
|
|
14106
|
+
if (primitive.indexed) {
|
|
14107
|
+
const format = indexBuffer.impl.glFormat;
|
|
14108
|
+
const { glCounts, glOffsetsBytes, glInstanceCounts, count } = drawCommands.impl;
|
|
14109
|
+
if (numInstances > 0) {
|
|
14110
|
+
for(let i = 0; i < count; i++){
|
|
14111
|
+
gl.drawElementsInstanced(mode, glCounts[i], format, glOffsetsBytes[i], glInstanceCounts[i]);
|
|
14112
|
+
}
|
|
14113
|
+
} else {
|
|
14114
|
+
for(let i = 0; i < count; i++){
|
|
14115
|
+
gl.drawElements(mode, glCounts[i], format, glOffsetsBytes[i]);
|
|
14116
|
+
}
|
|
14117
|
+
}
|
|
14118
|
+
} else {
|
|
14119
|
+
const { glCounts, glOffsetsBytes, glInstanceCounts, count } = drawCommands.impl;
|
|
14120
|
+
if (numInstances > 0) {
|
|
14121
|
+
for(let i = 0; i < count; i++){
|
|
14122
|
+
gl.drawArraysInstanced(mode, glOffsetsBytes[i], glCounts[i], glInstanceCounts[i]);
|
|
14123
|
+
}
|
|
14124
|
+
} else {
|
|
14125
|
+
for(let i = 0; i < count; i++){
|
|
14126
|
+
gl.drawArrays(mode, glOffsetsBytes[i], glCounts[i]);
|
|
14127
|
+
}
|
|
14128
|
+
}
|
|
14129
|
+
}
|
|
14130
|
+
}
|
|
14131
|
+
draw(primitive, indexBuffer, numInstances, drawCommands, first = true, last = true) {
|
|
14018
14132
|
const shader = this.shader;
|
|
14019
14133
|
if (shader) {
|
|
14020
14134
|
this.activateShader();
|
|
@@ -14081,20 +14195,42 @@ class WebglGraphicsDevice extends GraphicsDevice {
|
|
|
14081
14195
|
}
|
|
14082
14196
|
const mode = this.glPrimitive[primitive.type];
|
|
14083
14197
|
const count = primitive.count;
|
|
14084
|
-
if (
|
|
14085
|
-
|
|
14086
|
-
|
|
14087
|
-
|
|
14088
|
-
|
|
14198
|
+
if (drawCommands) {
|
|
14199
|
+
if (this.extMultiDraw) {
|
|
14200
|
+
const impl = drawCommands.impl;
|
|
14201
|
+
if (primitive.indexed) {
|
|
14202
|
+
const format = indexBuffer.impl.glFormat;
|
|
14203
|
+
if (numInstances > 0) {
|
|
14204
|
+
this.extMultiDraw.multiDrawElementsInstancedWEBGL(mode, impl.glCounts, 0, format, impl.glOffsetsBytes, 0, impl.glInstanceCounts, 0, drawCommands.count);
|
|
14205
|
+
} else {
|
|
14206
|
+
this.extMultiDraw.multiDrawElementsWEBGL(mode, impl.glCounts, 0, format, impl.glOffsetsBytes, 0, drawCommands.count);
|
|
14207
|
+
}
|
|
14208
|
+
} else {
|
|
14209
|
+
if (numInstances > 0) {
|
|
14210
|
+
this.extMultiDraw.multiDrawArraysInstancedWEBGL(mode, impl.glOffsetsBytes, 0, impl.glCounts, 0, impl.glInstanceCounts, 0, drawCommands.count);
|
|
14211
|
+
} else {
|
|
14212
|
+
this.extMultiDraw.multiDrawArraysWEBGL(mode, impl.glOffsetsBytes, 0, impl.glCounts, 0, drawCommands.count);
|
|
14213
|
+
}
|
|
14214
|
+
}
|
|
14089
14215
|
} else {
|
|
14090
|
-
|
|
14216
|
+
this._multiDrawLoopFallback(mode, primitive, indexBuffer, numInstances, drawCommands);
|
|
14091
14217
|
}
|
|
14092
14218
|
} else {
|
|
14093
|
-
|
|
14094
|
-
|
|
14095
|
-
|
|
14219
|
+
if (primitive.indexed) {
|
|
14220
|
+
const format = indexBuffer.impl.glFormat;
|
|
14221
|
+
const offset = primitive.base * indexBuffer.bytesPerIndex;
|
|
14222
|
+
if (numInstances > 0) {
|
|
14223
|
+
gl.drawElementsInstanced(mode, count, format, offset, numInstances);
|
|
14224
|
+
} else {
|
|
14225
|
+
gl.drawElements(mode, count, format, offset);
|
|
14226
|
+
}
|
|
14096
14227
|
} else {
|
|
14097
|
-
|
|
14228
|
+
const first = primitive.base;
|
|
14229
|
+
if (numInstances > 0) {
|
|
14230
|
+
gl.drawArraysInstanced(mode, first, count, numInstances);
|
|
14231
|
+
} else {
|
|
14232
|
+
gl.drawArrays(mode, first, count);
|
|
14233
|
+
}
|
|
14098
14234
|
}
|
|
14099
14235
|
}
|
|
14100
14236
|
if (this.transformFeedbackBuffer) {
|
|
@@ -14206,6 +14342,7 @@ class WebglGraphicsDevice extends GraphicsDevice {
|
|
|
14206
14342
|
this.initRenderTarget(renderTarget);
|
|
14207
14343
|
return new Promise((resolve, reject)=>{
|
|
14208
14344
|
this.readPixelsAsync(x, y, width, height, data).then((data)=>{
|
|
14345
|
+
if (this._destroyed) return;
|
|
14209
14346
|
if (!options.renderTarget) {
|
|
14210
14347
|
renderTarget.destroy();
|
|
14211
14348
|
}
|
|
@@ -14526,6 +14663,10 @@ class NullVertexBuffer {
|
|
|
14526
14663
|
unlock(vertexBuffer) {}
|
|
14527
14664
|
}
|
|
14528
14665
|
|
|
14666
|
+
class NullDrawCommands {
|
|
14667
|
+
add(i, indexOrVertexCount, instanceCount, firstIndexOrVertex) {}
|
|
14668
|
+
}
|
|
14669
|
+
|
|
14529
14670
|
class NullGraphicsDevice extends GraphicsDevice {
|
|
14530
14671
|
constructor(canvas, options = {}){
|
|
14531
14672
|
super(canvas, options);
|
|
@@ -14591,7 +14732,10 @@ class NullGraphicsDevice extends GraphicsDevice {
|
|
|
14591
14732
|
createRenderTargetImpl(renderTarget) {
|
|
14592
14733
|
return new NullRenderTarget(renderTarget);
|
|
14593
14734
|
}
|
|
14594
|
-
|
|
14735
|
+
createDrawCommandImpl(drawCommands) {
|
|
14736
|
+
return new NullDrawCommands();
|
|
14737
|
+
}
|
|
14738
|
+
draw(primitive, indexBuffer, numInstances, drawCommands, first = true, last = true) {}
|
|
14595
14739
|
setShader(shader, asyncCompile = false) {}
|
|
14596
14740
|
setBlendState(blendState) {}
|
|
14597
14741
|
setDepthState(depthState) {}
|
|
@@ -14663,6 +14807,39 @@ function createGraphicsDevice(canvas, options = {}) {
|
|
|
14663
14807
|
});
|
|
14664
14808
|
}
|
|
14665
14809
|
|
|
14810
|
+
class DrawCommands {
|
|
14811
|
+
get maxCount() {
|
|
14812
|
+
return this._maxCount;
|
|
14813
|
+
}
|
|
14814
|
+
get count() {
|
|
14815
|
+
return this._count;
|
|
14816
|
+
}
|
|
14817
|
+
constructor(device, indexSizeBytes = 0){
|
|
14818
|
+
this._maxCount = 0;
|
|
14819
|
+
this.impl = null;
|
|
14820
|
+
this._count = 1;
|
|
14821
|
+
this.slotIndex = 0;
|
|
14822
|
+
this.device = device;
|
|
14823
|
+
this.indexSizeBytes = indexSizeBytes;
|
|
14824
|
+
this.impl = device.createDrawCommandImpl(this);
|
|
14825
|
+
}
|
|
14826
|
+
destroy() {
|
|
14827
|
+
this.impl?.destroy?.();
|
|
14828
|
+
this.impl = null;
|
|
14829
|
+
}
|
|
14830
|
+
allocate(maxCount) {
|
|
14831
|
+
this._maxCount = maxCount;
|
|
14832
|
+
this.impl.allocate?.(maxCount);
|
|
14833
|
+
}
|
|
14834
|
+
add(i, indexOrVertexCount, instanceCount, firstIndexOrVertex, baseVertex = 0, firstInstance = 0) {
|
|
14835
|
+
this.impl.add(i, indexOrVertexCount, instanceCount, firstIndexOrVertex, baseVertex, firstInstance);
|
|
14836
|
+
}
|
|
14837
|
+
update(count) {
|
|
14838
|
+
this._count = count;
|
|
14839
|
+
this.impl.update?.(count);
|
|
14840
|
+
}
|
|
14841
|
+
}
|
|
14842
|
+
|
|
14666
14843
|
let id$6 = 0;
|
|
14667
14844
|
class IndexBuffer {
|
|
14668
14845
|
constructor(graphicsDevice, format, numIndices, usage = BUFFER_STATIC, initialData, options){
|
|
@@ -14897,13 +15074,13 @@ class RenderPass {
|
|
|
14897
15074
|
}
|
|
14898
15075
|
}
|
|
14899
15076
|
setClearDepth(depthValue) {
|
|
14900
|
-
if (depthValue) {
|
|
15077
|
+
if (depthValue !== undefined) {
|
|
14901
15078
|
this.depthStencilOps.clearDepthValue = depthValue;
|
|
14902
15079
|
}
|
|
14903
15080
|
this.depthStencilOps.clearDepth = depthValue !== undefined;
|
|
14904
15081
|
}
|
|
14905
15082
|
setClearStencil(stencilValue) {
|
|
14906
|
-
if (stencilValue) {
|
|
15083
|
+
if (stencilValue !== undefined) {
|
|
14907
15084
|
this.depthStencilOps.clearStencilValue = stencilValue;
|
|
14908
15085
|
}
|
|
14909
15086
|
this.depthStencilOps.clearStencil = stencilValue !== undefined;
|
|
@@ -17120,9 +17297,11 @@ class ShaderChunkMap extends Map {
|
|
|
17120
17297
|
}
|
|
17121
17298
|
return super.set(name, code);
|
|
17122
17299
|
}
|
|
17123
|
-
add(object) {
|
|
17300
|
+
add(object, override = true) {
|
|
17124
17301
|
for (const [key, value] of Object.entries(object)){
|
|
17125
|
-
this.
|
|
17302
|
+
if (override || !this.has(key)) {
|
|
17303
|
+
this.set(key, value);
|
|
17304
|
+
}
|
|
17126
17305
|
}
|
|
17127
17306
|
return this;
|
|
17128
17307
|
}
|
|
@@ -18222,15 +18401,6 @@ class InstancingData {
|
|
|
18222
18401
|
this.vertexBuffer = null;
|
|
18223
18402
|
}
|
|
18224
18403
|
}
|
|
18225
|
-
class IndirectData {
|
|
18226
|
-
get(camera) {
|
|
18227
|
-
return this.map.get(camera) ?? this.map.get(null);
|
|
18228
|
-
}
|
|
18229
|
-
constructor(){
|
|
18230
|
-
this.map = new Map();
|
|
18231
|
-
this.meshMetaData = new Int32Array(4);
|
|
18232
|
-
}
|
|
18233
|
-
}
|
|
18234
18404
|
class ShaderInstance {
|
|
18235
18405
|
getBindGroup(device) {
|
|
18236
18406
|
if (!this.bindGroup) {
|
|
@@ -18274,6 +18444,8 @@ class MeshInstance {
|
|
|
18274
18444
|
this.isVisibleFunc = null;
|
|
18275
18445
|
this.instancingData = null;
|
|
18276
18446
|
this.indirectData = null;
|
|
18447
|
+
this.drawCommands = null;
|
|
18448
|
+
this.meshMetaData = null;
|
|
18277
18449
|
this.parameters = {};
|
|
18278
18450
|
this.pick = true;
|
|
18279
18451
|
this.stencilFront = null;
|
|
@@ -18465,21 +18637,21 @@ class MeshInstance {
|
|
|
18465
18637
|
set receiveShadow(val) {
|
|
18466
18638
|
if (this._receiveShadow !== val) {
|
|
18467
18639
|
this._receiveShadow = val;
|
|
18468
|
-
this._updateShaderDefs(val ? this._shaderDefs &
|
|
18640
|
+
this._updateShaderDefs(val ? this._shaderDefs & ~SHADERDEF_NOSHADOW : this._shaderDefs | SHADERDEF_NOSHADOW);
|
|
18469
18641
|
}
|
|
18470
18642
|
}
|
|
18471
18643
|
get receiveShadow() {
|
|
18472
18644
|
return this._receiveShadow;
|
|
18473
18645
|
}
|
|
18474
18646
|
set batching(val) {
|
|
18475
|
-
this._updateShaderDefs(val ? this._shaderDefs | SHADERDEF_BATCH : this._shaderDefs &
|
|
18647
|
+
this._updateShaderDefs(val ? this._shaderDefs | SHADERDEF_BATCH : this._shaderDefs & ~SHADERDEF_BATCH);
|
|
18476
18648
|
}
|
|
18477
18649
|
get batching() {
|
|
18478
18650
|
return (this._shaderDefs & SHADERDEF_BATCH) !== 0;
|
|
18479
18651
|
}
|
|
18480
18652
|
set skinInstance(val) {
|
|
18481
18653
|
this._skinInstance = val;
|
|
18482
|
-
this._updateShaderDefs(val ? this._shaderDefs | SHADERDEF_SKIN : this._shaderDefs &
|
|
18654
|
+
this._updateShaderDefs(val ? this._shaderDefs | SHADERDEF_SKIN : this._shaderDefs & ~SHADERDEF_SKIN);
|
|
18483
18655
|
this._setupSkinUpdate();
|
|
18484
18656
|
}
|
|
18485
18657
|
get skinInstance() {
|
|
@@ -18489,9 +18661,9 @@ class MeshInstance {
|
|
|
18489
18661
|
this._morphInstance?.destroy();
|
|
18490
18662
|
this._morphInstance = val;
|
|
18491
18663
|
let shaderDefs = this._shaderDefs;
|
|
18492
|
-
shaderDefs = val && val.morph.morphPositions ? shaderDefs | SHADERDEF_MORPH_POSITION : shaderDefs &
|
|
18493
|
-
shaderDefs = val && val.morph.morphNormals ? shaderDefs | SHADERDEF_MORPH_NORMAL : shaderDefs &
|
|
18494
|
-
shaderDefs = val && val.morph.intRenderFormat ? shaderDefs | SHADERDEF_MORPH_TEXTURE_BASED_INT : shaderDefs &
|
|
18664
|
+
shaderDefs = val && val.morph.morphPositions ? shaderDefs | SHADERDEF_MORPH_POSITION : shaderDefs & ~SHADERDEF_MORPH_POSITION;
|
|
18665
|
+
shaderDefs = val && val.morph.morphNormals ? shaderDefs | SHADERDEF_MORPH_NORMAL : shaderDefs & ~SHADERDEF_MORPH_NORMAL;
|
|
18666
|
+
shaderDefs = val && val.morph.intRenderFormat ? shaderDefs | SHADERDEF_MORPH_TEXTURE_BASED_INT : shaderDefs & ~SHADERDEF_MORPH_TEXTURE_BASED_INT;
|
|
18495
18667
|
this._updateShaderDefs(shaderDefs);
|
|
18496
18668
|
}
|
|
18497
18669
|
get morphInstance() {
|
|
@@ -18500,7 +18672,7 @@ class MeshInstance {
|
|
|
18500
18672
|
set screenSpace(val) {
|
|
18501
18673
|
if (this._screenSpace !== val) {
|
|
18502
18674
|
this._screenSpace = val;
|
|
18503
|
-
this._updateShaderDefs(val ? this._shaderDefs | SHADERDEF_SCREENSPACE : this._shaderDefs &
|
|
18675
|
+
this._updateShaderDefs(val ? this._shaderDefs | SHADERDEF_SCREENSPACE : this._shaderDefs & ~SHADERDEF_SCREENSPACE);
|
|
18504
18676
|
}
|
|
18505
18677
|
}
|
|
18506
18678
|
get screenSpace() {
|
|
@@ -18544,6 +18716,15 @@ class MeshInstance {
|
|
|
18544
18716
|
this.clearShaders();
|
|
18545
18717
|
this.material = null;
|
|
18546
18718
|
this.instancingData?.destroy();
|
|
18719
|
+
this.destroyDrawCommands();
|
|
18720
|
+
}
|
|
18721
|
+
destroyDrawCommands() {
|
|
18722
|
+
if (this.drawCommands) {
|
|
18723
|
+
for (const cmd of this.drawCommands.values()){
|
|
18724
|
+
cmd?.destroy();
|
|
18725
|
+
}
|
|
18726
|
+
this.drawCommands = null;
|
|
18727
|
+
}
|
|
18547
18728
|
}
|
|
18548
18729
|
static{
|
|
18549
18730
|
this.lightmapParamNames = [
|
|
@@ -18589,28 +18770,65 @@ class MeshInstance {
|
|
|
18589
18770
|
this.instancingData = null;
|
|
18590
18771
|
this.cull = true;
|
|
18591
18772
|
}
|
|
18592
|
-
this._updateShaderDefs(vertexBuffer ? this._shaderDefs | SHADERDEF_INSTANCING : this._shaderDefs &
|
|
18773
|
+
this._updateShaderDefs(vertexBuffer ? this._shaderDefs | SHADERDEF_INSTANCING : this._shaderDefs & ~SHADERDEF_INSTANCING);
|
|
18774
|
+
}
|
|
18775
|
+
setIndirect(camera, slot, count = 1) {
|
|
18776
|
+
const key = camera?.camera ?? null;
|
|
18777
|
+
if (slot === -1) {
|
|
18778
|
+
this._deleteDrawCommandsKey(key);
|
|
18779
|
+
} else {
|
|
18780
|
+
this.drawCommands ??= new Map();
|
|
18781
|
+
const cmd = this.drawCommands.get(key) ?? new DrawCommands(this.mesh.device);
|
|
18782
|
+
cmd.slotIndex = slot;
|
|
18783
|
+
cmd.update(count);
|
|
18784
|
+
this.drawCommands.set(key, cmd);
|
|
18785
|
+
const device = this.mesh.device;
|
|
18786
|
+
device.mapsToClear.add(this.drawCommands);
|
|
18787
|
+
}
|
|
18788
|
+
}
|
|
18789
|
+
setMultiDraw(camera, maxCount = 1) {
|
|
18790
|
+
const key = camera?.camera ?? null;
|
|
18791
|
+
let cmd;
|
|
18792
|
+
if (maxCount === 0) {
|
|
18793
|
+
this._deleteDrawCommandsKey(key);
|
|
18794
|
+
} else {
|
|
18795
|
+
this.drawCommands ??= new Map();
|
|
18796
|
+
cmd = this.drawCommands.get(key);
|
|
18797
|
+
if (!cmd) {
|
|
18798
|
+
const indexBuffer = this.mesh.indexBuffer?.[0];
|
|
18799
|
+
const indexFormat = indexBuffer?.format;
|
|
18800
|
+
const indexSizeBytes = indexFormat !== undefined ? indexFormatByteSize[indexFormat] : 0;
|
|
18801
|
+
cmd = new DrawCommands(this.mesh.device, indexSizeBytes);
|
|
18802
|
+
this.drawCommands.set(key, cmd);
|
|
18803
|
+
}
|
|
18804
|
+
cmd.allocate(maxCount);
|
|
18805
|
+
}
|
|
18806
|
+
return cmd;
|
|
18807
|
+
}
|
|
18808
|
+
_deleteDrawCommandsKey(key) {
|
|
18809
|
+
const cmds = this.drawCommands;
|
|
18810
|
+
if (cmds) {
|
|
18811
|
+
const cmd = cmds.get(key);
|
|
18812
|
+
cmd?.destroy();
|
|
18813
|
+
cmds.delete(key);
|
|
18814
|
+
if (cmds.size === 0) {
|
|
18815
|
+
this.destroyDrawCommands();
|
|
18816
|
+
}
|
|
18817
|
+
}
|
|
18593
18818
|
}
|
|
18594
|
-
|
|
18595
|
-
this.
|
|
18596
|
-
|
|
18597
|
-
|
|
18598
|
-
device.mapsToClear.add(this.indirectData.map);
|
|
18819
|
+
getDrawCommands(camera) {
|
|
18820
|
+
const cmds = this.drawCommands;
|
|
18821
|
+
if (!cmds) return undefined;
|
|
18822
|
+
return cmds.get(camera) ?? cmds.get(null);
|
|
18599
18823
|
}
|
|
18600
18824
|
getIndirectMetaData() {
|
|
18601
|
-
this._allocIndirectData();
|
|
18602
18825
|
const prim = this.mesh?.primitive[this.renderStyle];
|
|
18603
|
-
const data = this.
|
|
18826
|
+
const data = this.meshMetaData ?? (this.meshMetaData = new Int32Array(4));
|
|
18604
18827
|
data[0] = prim.count;
|
|
18605
18828
|
data[1] = prim.base;
|
|
18606
18829
|
data[2] = prim.baseVertex;
|
|
18607
18830
|
return data;
|
|
18608
18831
|
}
|
|
18609
|
-
_allocIndirectData() {
|
|
18610
|
-
if (!this.indirectData) {
|
|
18611
|
-
this.indirectData = new IndirectData();
|
|
18612
|
-
}
|
|
18613
|
-
}
|
|
18614
18832
|
ensureMaterial(device) {
|
|
18615
18833
|
if (!this.material) {
|
|
18616
18834
|
this.material = getDefaultMaterial(device);
|
|
@@ -22489,8 +22707,8 @@ class ShadowRenderer {
|
|
|
22489
22707
|
renderer.setMeshInstanceMatrices(meshInstance);
|
|
22490
22708
|
renderer.setupMeshUniformBuffers(shaderInstance);
|
|
22491
22709
|
const style = meshInstance.renderStyle;
|
|
22492
|
-
const
|
|
22493
|
-
device.draw(mesh.primitive[style], mesh.indexBuffer[style], instancingData?.count,
|
|
22710
|
+
const indirectData = meshInstance.getDrawCommands(camera);
|
|
22711
|
+
device.draw(mesh.primitive[style], mesh.indexBuffer[style], instancingData?.count, indirectData);
|
|
22494
22712
|
renderer._shadowDrawCalls++;
|
|
22495
22713
|
if (instancingData) {
|
|
22496
22714
|
renderer._instancedDrawCalls++;
|
|
@@ -22986,6 +23204,7 @@ class Renderer {
|
|
|
22986
23204
|
this._numDrawCallsCulled = 0;
|
|
22987
23205
|
this._camerasRendered = 0;
|
|
22988
23206
|
this._lightClusters = 0;
|
|
23207
|
+
this._gsplatCount = 0;
|
|
22989
23208
|
const scope = graphicsDevice.scope;
|
|
22990
23209
|
this.boneTextureId = scope.resolve('texture_poseMap');
|
|
22991
23210
|
this.modelMatrixId = scope.resolve('matrix_model');
|
|
@@ -23032,6 +23251,8 @@ class Renderer {
|
|
|
23032
23251
|
this._renderPassUpdateClustered = null;
|
|
23033
23252
|
this.lightTextureAtlas.destroy();
|
|
23034
23253
|
this.lightTextureAtlas = null;
|
|
23254
|
+
this.gsplatDirector?.destroy();
|
|
23255
|
+
this.gsplatDirector = null;
|
|
23035
23256
|
}
|
|
23036
23257
|
setupViewport(camera, renderTarget) {
|
|
23037
23258
|
const device = this.device;
|
|
@@ -24254,7 +24475,7 @@ class ForwardRenderer extends Renderer {
|
|
|
24254
24475
|
const style = drawCall.renderStyle;
|
|
24255
24476
|
const indexBuffer = mesh.indexBuffer[style];
|
|
24256
24477
|
drawCallback?.(drawCall, i);
|
|
24257
|
-
const
|
|
24478
|
+
const indirectData = drawCall.getDrawCommands(camera);
|
|
24258
24479
|
if (viewList) {
|
|
24259
24480
|
for(let v = 0; v < viewList.length; v++){
|
|
24260
24481
|
const view = viewList[v];
|
|
@@ -24267,14 +24488,14 @@ class ForwardRenderer extends Renderer {
|
|
|
24267
24488
|
}
|
|
24268
24489
|
const first = v === 0;
|
|
24269
24490
|
const last = v === viewList.length - 1;
|
|
24270
|
-
device.draw(mesh.primitive[style], indexBuffer, instancingData?.count,
|
|
24491
|
+
device.draw(mesh.primitive[style], indexBuffer, instancingData?.count, indirectData, first, last);
|
|
24271
24492
|
this._forwardDrawCalls++;
|
|
24272
24493
|
if (drawCall.instancingData) {
|
|
24273
24494
|
this._instancedDrawCalls++;
|
|
24274
24495
|
}
|
|
24275
24496
|
}
|
|
24276
24497
|
} else {
|
|
24277
|
-
device.draw(mesh.primitive[style], indexBuffer, instancingData?.count,
|
|
24498
|
+
device.draw(mesh.primitive[style], indexBuffer, instancingData?.count, indirectData);
|
|
24278
24499
|
this._forwardDrawCalls++;
|
|
24279
24500
|
if (drawCall.instancingData) {
|
|
24280
24501
|
this._instancedDrawCalls++;
|
|
@@ -25507,7 +25728,7 @@ class Light {
|
|
|
25507
25728
|
value = SHADOW_PCF3_32F;
|
|
25508
25729
|
}
|
|
25509
25730
|
const device = this.device;
|
|
25510
|
-
if (value === SHADOW_PCSS_32F && !device.textureFloatRenderable
|
|
25731
|
+
if (value === SHADOW_PCSS_32F && (!device.textureFloatRenderable || !device.textureFloatFilterable)) {
|
|
25511
25732
|
value = SHADOW_PCF3_32F;
|
|
25512
25733
|
}
|
|
25513
25734
|
if (this._type === LIGHTTYPE_OMNI && value !== SHADOW_PCF1_32F && value !== SHADOW_PCF3_32F && value !== SHADOW_PCF1_16F && value !== SHADOW_PCF3_16F && value !== SHADOW_PCSS_32F) {
|
|
@@ -27011,6 +27232,7 @@ class ParticleGPUUpdater {
|
|
|
27011
27232
|
this.constantMaxVel = gd.scope.resolve('maxVel');
|
|
27012
27233
|
this.constantFaceTangent = gd.scope.resolve('faceTangent');
|
|
27013
27234
|
this.constantFaceBinorm = gd.scope.resolve('faceBinorm');
|
|
27235
|
+
this.constantRadialSpeedDivMult = gd.scope.resolve('radialSpeedDivMult');
|
|
27014
27236
|
}
|
|
27015
27237
|
_setInputBounds() {
|
|
27016
27238
|
this.inBoundsSizeUniform[0] = this._emitter.prevWorldBoundsSize.x;
|
|
@@ -27033,6 +27255,7 @@ class ParticleGPUUpdater {
|
|
|
27033
27255
|
device.setDepthState(DepthState.NODEPTH);
|
|
27034
27256
|
device.setCullMode(CULLFACE_NONE);
|
|
27035
27257
|
this.randomize();
|
|
27258
|
+
this.constantRadialSpeedDivMult.setValue(emitter.material.getParameter('radialSpeedDivMult').data);
|
|
27036
27259
|
this.constantGraphSampleSize.setValue(1.0 / emitter.precision);
|
|
27037
27260
|
this.constantGraphNumSamples.setValue(emitter.precision);
|
|
27038
27261
|
this.constantNumParticles.setValue(emitter.numParticles);
|
|
@@ -28296,6 +28519,67 @@ class ParticleEmitter {
|
|
|
28296
28519
|
}
|
|
28297
28520
|
}
|
|
28298
28521
|
|
|
28522
|
+
class GSplatParams {
|
|
28523
|
+
set colorizeLod(value) {
|
|
28524
|
+
if (this._colorizeLod !== value) {
|
|
28525
|
+
this._colorizeLod = value;
|
|
28526
|
+
this.dirty = true;
|
|
28527
|
+
}
|
|
28528
|
+
}
|
|
28529
|
+
get colorizeLod() {
|
|
28530
|
+
return this._colorizeLod;
|
|
28531
|
+
}
|
|
28532
|
+
set lodBehindPenalty(value) {
|
|
28533
|
+
if (this._lodBehindPenalty !== value) {
|
|
28534
|
+
this._lodBehindPenalty = value;
|
|
28535
|
+
this.dirty = true;
|
|
28536
|
+
}
|
|
28537
|
+
}
|
|
28538
|
+
get lodBehindPenalty() {
|
|
28539
|
+
return this._lodBehindPenalty;
|
|
28540
|
+
}
|
|
28541
|
+
set lodRangeMin(value) {
|
|
28542
|
+
if (this._lodRangeMin !== value) {
|
|
28543
|
+
this._lodRangeMin = value;
|
|
28544
|
+
this.dirty = true;
|
|
28545
|
+
}
|
|
28546
|
+
}
|
|
28547
|
+
get lodRangeMin() {
|
|
28548
|
+
return this._lodRangeMin;
|
|
28549
|
+
}
|
|
28550
|
+
set lodRangeMax(value) {
|
|
28551
|
+
if (this._lodRangeMax !== value) {
|
|
28552
|
+
this._lodRangeMax = value;
|
|
28553
|
+
this.dirty = true;
|
|
28554
|
+
}
|
|
28555
|
+
}
|
|
28556
|
+
get lodRangeMax() {
|
|
28557
|
+
return this._lodRangeMax;
|
|
28558
|
+
}
|
|
28559
|
+
set lodUnderfillLimit(value) {
|
|
28560
|
+
if (this._lodUnderfillLimit !== value) {
|
|
28561
|
+
this._lodUnderfillLimit = value;
|
|
28562
|
+
this.dirty = true;
|
|
28563
|
+
}
|
|
28564
|
+
}
|
|
28565
|
+
get lodUnderfillLimit() {
|
|
28566
|
+
return this._lodUnderfillLimit;
|
|
28567
|
+
}
|
|
28568
|
+
constructor(){
|
|
28569
|
+
this.debugAabbs = false;
|
|
28570
|
+
this.radialSorting = false;
|
|
28571
|
+
this.debugNodeAabbs = false;
|
|
28572
|
+
this.dirty = false;
|
|
28573
|
+
this._colorizeLod = false;
|
|
28574
|
+
this.lodUpdateDistance = 1;
|
|
28575
|
+
this.lodUpdateAngle = 0;
|
|
28576
|
+
this._lodBehindPenalty = 1;
|
|
28577
|
+
this._lodRangeMin = 0;
|
|
28578
|
+
this._lodRangeMax = 10;
|
|
28579
|
+
this._lodUnderfillLimit = 0;
|
|
28580
|
+
}
|
|
28581
|
+
}
|
|
28582
|
+
|
|
28299
28583
|
class ShaderGeneratorShader extends ShaderGenerator {
|
|
28300
28584
|
generateKey(options) {
|
|
28301
28585
|
const desc = options.shaderDesc;
|
|
@@ -28807,7 +29091,7 @@ class DomeGeometry extends SphereGeometry {
|
|
|
28807
29091
|
if (y < 0) {
|
|
28808
29092
|
y *= 0.3;
|
|
28809
29093
|
if (x * x + z * z < curvatureRadiusSq) {
|
|
28810
|
-
y = -
|
|
29094
|
+
y = -bottomLimit;
|
|
28811
29095
|
}
|
|
28812
29096
|
}
|
|
28813
29097
|
y += bottomLimit;
|
|
@@ -29938,6 +30222,7 @@ class Scene extends EventHandler {
|
|
|
29938
30222
|
this._lightingParams = new LightingParams(this.device.supportsAreaLights, this.device.maxTextureSize, ()=>{
|
|
29939
30223
|
this.updateShaders = true;
|
|
29940
30224
|
});
|
|
30225
|
+
this._gsplatParams = new GSplatParams();
|
|
29941
30226
|
this._sky = new Sky(this);
|
|
29942
30227
|
this._stats = {
|
|
29943
30228
|
meshInstances: 0,
|
|
@@ -30013,6 +30298,9 @@ class Scene extends EventHandler {
|
|
|
30013
30298
|
get lighting() {
|
|
30014
30299
|
return this._lightingParams;
|
|
30015
30300
|
}
|
|
30301
|
+
get gsplat() {
|
|
30302
|
+
return this._gsplatParams;
|
|
30303
|
+
}
|
|
30016
30304
|
get fog() {
|
|
30017
30305
|
return this._fogParams;
|
|
30018
30306
|
}
|
|
@@ -33231,15 +33519,17 @@ class GSplatData {
|
|
|
33231
33519
|
}
|
|
33232
33520
|
return !first;
|
|
33233
33521
|
}
|
|
33234
|
-
getCenters(
|
|
33522
|
+
getCenters() {
|
|
33235
33523
|
const x = this.getProp('x');
|
|
33236
33524
|
const y = this.getProp('y');
|
|
33237
33525
|
const z = this.getProp('z');
|
|
33526
|
+
const result = new Float32Array(this.numSplats * 3);
|
|
33238
33527
|
for(let i = 0; i < this.numSplats; ++i){
|
|
33239
33528
|
result[i * 3 + 0] = x[i];
|
|
33240
33529
|
result[i * 3 + 1] = y[i];
|
|
33241
33530
|
result[i * 3 + 2] = z[i];
|
|
33242
33531
|
}
|
|
33532
|
+
return result;
|
|
33243
33533
|
}
|
|
33244
33534
|
calcFocalPoint(result, pred) {
|
|
33245
33535
|
const x = this.getProp('x');
|
|
@@ -33411,9 +33701,7 @@ uniform int uViewportWidth;
|
|
|
33411
33701
|
#ifdef GSPLAT_LOD
|
|
33412
33702
|
uniform usampler2D uIntervalsTexture;
|
|
33413
33703
|
#endif
|
|
33414
|
-
|
|
33415
|
-
uniform vec3 uLodColor;
|
|
33416
|
-
#endif
|
|
33704
|
+
uniform vec3 uColorMultiply;
|
|
33417
33705
|
uniform int uActiveSplats;
|
|
33418
33706
|
void main(void) {
|
|
33419
33707
|
ivec2 localFragCoords = ivec2(int(gl_FragCoord.x), int(gl_FragCoord.y) - uStartLine);
|
|
@@ -33464,9 +33752,7 @@ void main(void) {
|
|
|
33464
33752
|
readSHData(source, sh, scale);
|
|
33465
33753
|
color.xyz += evalSH(sh, dir) * scale;
|
|
33466
33754
|
#endif
|
|
33467
|
-
|
|
33468
|
-
color.xyz *= uLodColor;
|
|
33469
|
-
#endif
|
|
33755
|
+
color.xyz *= uColorMultiply;
|
|
33470
33756
|
pcFragColor0 = color;
|
|
33471
33757
|
pcFragColor1 = vec4(modelCenter, 1.0);
|
|
33472
33758
|
pcFragColor2 = vec4(covA, 1.0);
|
|
@@ -33488,9 +33774,7 @@ uniform uViewportWidth: i32;
|
|
|
33488
33774
|
#ifdef GSPLAT_LOD
|
|
33489
33775
|
var uIntervalsTexture: texture_2d<u32>;
|
|
33490
33776
|
#endif
|
|
33491
|
-
|
|
33492
|
-
uniform uLodColor: vec3f;
|
|
33493
|
-
#endif
|
|
33777
|
+
uniform uColorMultiply: vec3f;
|
|
33494
33778
|
uniform uActiveSplats: i32;
|
|
33495
33779
|
@fragment
|
|
33496
33780
|
fn fragmentMain(input: FragmentInput) -> FragmentOutput {
|
|
@@ -33547,9 +33831,7 @@ fn fragmentMain(input: FragmentInput) -> FragmentOutput {
|
|
|
33547
33831
|
readSHData(&source, &sh, &scale);
|
|
33548
33832
|
color = vec4f(color.xyz + evalSH(&sh, dir) * scale, color.w);
|
|
33549
33833
|
#endif
|
|
33550
|
-
|
|
33551
|
-
color = vec4f(color.xyz * uniform.uLodColor, color.w);
|
|
33552
|
-
#endif
|
|
33834
|
+
color = vec4f(color.xyz * uniform.uColorMultiply, color.w);
|
|
33553
33835
|
output.color = color;
|
|
33554
33836
|
output.color1 = vec4f(modelCenter, 1.0);
|
|
33555
33837
|
output.color2 = vec4f(covA, 1.0);
|
|
@@ -33591,8 +33873,7 @@ class GSplatResourceBase {
|
|
|
33591
33873
|
this.workBufferRenderInfos = new Map();
|
|
33592
33874
|
this.device = device;
|
|
33593
33875
|
this.gsplatData = gsplatData;
|
|
33594
|
-
this.centers =
|
|
33595
|
-
gsplatData.getCenters(this.centers);
|
|
33876
|
+
this.centers = gsplatData.getCenters();
|
|
33596
33877
|
this.aabb = new BoundingBox();
|
|
33597
33878
|
gsplatData.calcAabb(this.aabb);
|
|
33598
33879
|
this.mesh = GSplatResourceBase.createMesh(device);
|
|
@@ -33606,10 +33887,9 @@ class GSplatResourceBase {
|
|
|
33606
33887
|
this.workBufferRenderInfos.forEach((info)=>info.destroy());
|
|
33607
33888
|
this.workBufferRenderInfos.clear();
|
|
33608
33889
|
}
|
|
33609
|
-
getWorkBufferRenderInfo(useIntervals
|
|
33890
|
+
getWorkBufferRenderInfo(useIntervals) {
|
|
33610
33891
|
this.configureMaterialDefines(tempMap);
|
|
33611
33892
|
if (useIntervals) tempMap.set('GSPLAT_LOD', '');
|
|
33612
|
-
if (colorizeLod) tempMap.set('GSPLAT_COLORIZE', '');
|
|
33613
33893
|
const key = Array.from(tempMap.entries()).map(([k, v])=>`${k}=${v}`).join(';');
|
|
33614
33894
|
let info = this.workBufferRenderInfos.get(key);
|
|
33615
33895
|
if (!info) {
|
|
@@ -34668,6 +34948,54 @@ fn resolveCodebook(s: vec3f, codebook: ptr<uniform, array<vec4f, 64>>) -> vec3f
|
|
|
34668
34948
|
}
|
|
34669
34949
|
`;
|
|
34670
34950
|
|
|
34951
|
+
var glslSogsCentersPS = `
|
|
34952
|
+
#include "gsplatPackingPS"
|
|
34953
|
+
uniform highp sampler2D means_l;
|
|
34954
|
+
uniform highp sampler2D means_u;
|
|
34955
|
+
uniform highp uint numSplats;
|
|
34956
|
+
uniform highp vec3 means_mins;
|
|
34957
|
+
uniform highp vec3 means_maxs;
|
|
34958
|
+
void main(void) {
|
|
34959
|
+
int w = int(textureSize(means_l, 0).x);
|
|
34960
|
+
ivec2 uv = ivec2(gl_FragCoord.xy);
|
|
34961
|
+
if (uint(uv.x + uv.y * w) >= numSplats) {
|
|
34962
|
+
discard;
|
|
34963
|
+
}
|
|
34964
|
+
vec3 l = texelFetch(means_l, uv, 0).xyz;
|
|
34965
|
+
vec3 u = texelFetch(means_u, uv, 0).xyz;
|
|
34966
|
+
vec3 n = (l * 255.0 + u * 255.0 * 256.0) / 65535.0;
|
|
34967
|
+
vec3 v = mix(means_mins, means_maxs, n);
|
|
34968
|
+
vec3 center = sign(v) * (exp(abs(v)) - 1.0);
|
|
34969
|
+
pcFragColor0 = uvec4(floatBitsToUint(center), 0u);
|
|
34970
|
+
}
|
|
34971
|
+
`;
|
|
34972
|
+
|
|
34973
|
+
var wgslSogsCentersPS = `
|
|
34974
|
+
var means_l: texture_2d<f32>;
|
|
34975
|
+
var means_u: texture_2d<f32>;
|
|
34976
|
+
uniform numSplats: u32;
|
|
34977
|
+
uniform means_mins: vec3f;
|
|
34978
|
+
uniform means_maxs: vec3f;
|
|
34979
|
+
@fragment
|
|
34980
|
+
fn fragmentMain(input: FragmentInput) -> FragmentOutput {
|
|
34981
|
+
var output: FragmentOutput;
|
|
34982
|
+
let w: u32 = textureDimensions(means_l, 0).x;
|
|
34983
|
+
let uv: vec2<i32> = vec2<i32>(input.position.xy);
|
|
34984
|
+
if (u32(uv.x + uv.y * i32(w)) >= uniform.numSplats) {
|
|
34985
|
+
discard;
|
|
34986
|
+
return output;
|
|
34987
|
+
}
|
|
34988
|
+
let l: vec3f = textureLoad(means_l, uv, 0).xyz;
|
|
34989
|
+
let u: vec3f = textureLoad(means_u, uv, 0).xyz;
|
|
34990
|
+
let n: vec3f = (l * 255.0 + u * 255.0 * 256.0) / 65535.0;
|
|
34991
|
+
let v: vec3f = mix(uniform.means_mins, uniform.means_maxs, n);
|
|
34992
|
+
let center: vec3f = sign(v) * (exp(abs(v)) - 1.0);
|
|
34993
|
+
let packed: vec4<u32> = bitcast<vec4<u32>>(vec4f(center, 0.0));
|
|
34994
|
+
output.color = packed;
|
|
34995
|
+
return output;
|
|
34996
|
+
}
|
|
34997
|
+
`;
|
|
34998
|
+
|
|
34671
34999
|
const SH_C0$1 = 0.28209479177387814;
|
|
34672
35000
|
const readImageDataAsync = (texture)=>{
|
|
34673
35001
|
return texture.read(0, 0, texture.width, texture.height, {
|
|
@@ -34779,7 +35107,7 @@ class GSplatSogsIterator {
|
|
|
34779
35107
|
}
|
|
34780
35108
|
}
|
|
34781
35109
|
class GSplatSogsData {
|
|
34782
|
-
|
|
35110
|
+
_destroyGpuResources() {
|
|
34783
35111
|
this.means_l?.destroy();
|
|
34784
35112
|
this.means_u?.destroy();
|
|
34785
35113
|
this.quats?.destroy();
|
|
@@ -34791,6 +35119,10 @@ class GSplatSogsData {
|
|
|
34791
35119
|
this.packedSh0?.destroy();
|
|
34792
35120
|
this.packedShN?.destroy();
|
|
34793
35121
|
}
|
|
35122
|
+
destroy() {
|
|
35123
|
+
this.destroyed = true;
|
|
35124
|
+
this._destroyGpuResources();
|
|
35125
|
+
}
|
|
34794
35126
|
createIter(p, r, s, c, sh) {
|
|
34795
35127
|
return new GSplatSogsIterator(this, p, r, s, c, sh);
|
|
34796
35128
|
}
|
|
@@ -34800,34 +35132,10 @@ class GSplatSogsData {
|
|
|
34800
35132
|
result.center.set((map(mins[0]) + map(maxs[0])) * 0.5, (map(mins[1]) + map(maxs[1])) * 0.5, (map(mins[2]) + map(maxs[2])) * 0.5);
|
|
34801
35133
|
result.halfExtents.set((map(maxs[0]) - map(mins[0])) * 0.5, (map(maxs[1]) - map(mins[1])) * 0.5, (map(maxs[2]) - map(mins[2])) * 0.5);
|
|
34802
35134
|
}
|
|
34803
|
-
getCenters(
|
|
34804
|
-
const
|
|
34805
|
-
|
|
34806
|
-
|
|
34807
|
-
const means_l_data = new Uint32Array(means_l._levels[0].buffer);
|
|
34808
|
-
const mx = means.mins[0] / 65535;
|
|
34809
|
-
const my = means.mins[1] / 65535;
|
|
34810
|
-
const mz = means.mins[2] / 65535;
|
|
34811
|
-
const Mx = means.maxs[0] / 65535;
|
|
34812
|
-
const My = means.maxs[1] / 65535;
|
|
34813
|
-
const Mz = means.maxs[2] / 65535;
|
|
34814
|
-
for(let i = 0; i < numSplats; i++){
|
|
34815
|
-
const idx = i;
|
|
34816
|
-
const means_u = means_u_data[idx];
|
|
34817
|
-
const means_l = means_l_data[idx];
|
|
34818
|
-
const wx = means_u << 8 & 0xff00 | means_l & 0xff;
|
|
34819
|
-
const wy = means_u & 0xff00 | means_l >>> 8 & 0xff;
|
|
34820
|
-
const wz = means_u >>> 8 & 0xff00 | means_l >>> 16 & 0xff;
|
|
34821
|
-
const nx = mx * (65535 - wx) + Mx * wx;
|
|
34822
|
-
const ny = my * (65535 - wy) + My * wy;
|
|
34823
|
-
const nz = mz * (65535 - wz) + Mz * wz;
|
|
34824
|
-
const ax = nx < 0 ? -nx : nx;
|
|
34825
|
-
const ay = ny < 0 ? -ny : ny;
|
|
34826
|
-
const az = nz < 0 ? -nz : nz;
|
|
34827
|
-
result[i * 3] = (nx < 0 ? -1 : 1) * (Math.exp(ax) - 1);
|
|
34828
|
-
result[i * 3 + 1] = (ny < 0 ? -1 : 1) * (Math.exp(ay) - 1);
|
|
34829
|
-
result[i * 3 + 2] = (nz < 0 ? -1 : 1) * (Math.exp(az) - 1);
|
|
34830
|
-
}
|
|
35135
|
+
getCenters() {
|
|
35136
|
+
const centers = this._centers;
|
|
35137
|
+
this._centers = null;
|
|
35138
|
+
return centers;
|
|
34831
35139
|
}
|
|
34832
35140
|
calcFocalPoint(result, pred) {
|
|
34833
35141
|
const { mins, maxs } = this.meta.means;
|
|
@@ -34925,6 +35233,67 @@ class GSplatSogsData {
|
|
|
34925
35233
|
}
|
|
34926
35234
|
]);
|
|
34927
35235
|
}
|
|
35236
|
+
async generateCenters() {
|
|
35237
|
+
const { device, width, height } = this.means_l;
|
|
35238
|
+
const { scope } = device;
|
|
35239
|
+
const centersTexture = new Texture(device, {
|
|
35240
|
+
name: 'sogsCentersTexture',
|
|
35241
|
+
width,
|
|
35242
|
+
height,
|
|
35243
|
+
format: PIXELFORMAT_RGBA32U,
|
|
35244
|
+
mipmaps: false
|
|
35245
|
+
});
|
|
35246
|
+
const shader = ShaderUtils.createShader(device, {
|
|
35247
|
+
uniqueName: 'GsplatSogsCentersShader',
|
|
35248
|
+
attributes: {
|
|
35249
|
+
vertex_position: SEMANTIC_POSITION
|
|
35250
|
+
},
|
|
35251
|
+
vertexChunk: 'fullscreenQuadVS',
|
|
35252
|
+
fragmentGLSL: glslSogsCentersPS,
|
|
35253
|
+
fragmentWGSL: wgslSogsCentersPS,
|
|
35254
|
+
fragmentOutputTypes: [
|
|
35255
|
+
'uvec4'
|
|
35256
|
+
],
|
|
35257
|
+
fragmentIncludes: new Map([
|
|
35258
|
+
[
|
|
35259
|
+
'gsplatPackingPS',
|
|
35260
|
+
device.isWebGPU ? gsplatPackingPS : gsplatPackingPS$1
|
|
35261
|
+
]
|
|
35262
|
+
])
|
|
35263
|
+
});
|
|
35264
|
+
const renderTarget = new RenderTarget({
|
|
35265
|
+
colorBuffer: centersTexture,
|
|
35266
|
+
depth: false,
|
|
35267
|
+
mipLevel: 0
|
|
35268
|
+
});
|
|
35269
|
+
device.setCullMode(CULLFACE_NONE);
|
|
35270
|
+
device.setBlendState(BlendState.NOBLEND);
|
|
35271
|
+
device.setDepthState(DepthState.NODEPTH);
|
|
35272
|
+
resolve(scope, {
|
|
35273
|
+
means_l: this.means_l,
|
|
35274
|
+
means_u: this.means_u,
|
|
35275
|
+
numSplats: this.numSplats,
|
|
35276
|
+
means_mins: this.meta.means.mins,
|
|
35277
|
+
means_maxs: this.meta.means.maxs
|
|
35278
|
+
});
|
|
35279
|
+
drawQuadWithShader(device, renderTarget, shader);
|
|
35280
|
+
renderTarget.destroy();
|
|
35281
|
+
const u32 = await readImageDataAsync(centersTexture);
|
|
35282
|
+
if (this.destroyed || device._destroyed) {
|
|
35283
|
+
centersTexture.destroy();
|
|
35284
|
+
return;
|
|
35285
|
+
}
|
|
35286
|
+
const asFloat = new Float32Array(u32.buffer);
|
|
35287
|
+
const result = new Float32Array(this.numSplats * 3);
|
|
35288
|
+
for(let i = 0; i < this.numSplats; i++){
|
|
35289
|
+
const base = i * 4;
|
|
35290
|
+
result[i * 3 + 0] = asFloat[base + 0];
|
|
35291
|
+
result[i * 3 + 1] = asFloat[base + 1];
|
|
35292
|
+
result[i * 3 + 2] = asFloat[base + 2];
|
|
35293
|
+
}
|
|
35294
|
+
this._centers = result;
|
|
35295
|
+
centersTexture.destroy();
|
|
35296
|
+
}
|
|
34928
35297
|
packGpuMemory() {
|
|
34929
35298
|
const { meta, means_l, means_u, quats, scales, sh0, sh_labels, numSplats } = this;
|
|
34930
35299
|
const { device } = means_l;
|
|
@@ -35027,8 +35396,7 @@ class GSplatSogsData {
|
|
|
35027
35396
|
}
|
|
35028
35397
|
async prepareGpuData() {
|
|
35029
35398
|
const { device, height, width } = this.means_l;
|
|
35030
|
-
this.
|
|
35031
|
-
this.means_u._levels[0] = await readImageDataAsync(this.means_u);
|
|
35399
|
+
if (this.destroyed || device._destroyed) return;
|
|
35032
35400
|
this.packedTexture = new Texture(device, {
|
|
35033
35401
|
name: 'sogsPackedTexture',
|
|
35034
35402
|
width,
|
|
@@ -35056,14 +35424,32 @@ class GSplatSogsData {
|
|
|
35056
35424
|
this.packShMemory();
|
|
35057
35425
|
}
|
|
35058
35426
|
});
|
|
35427
|
+
[
|
|
35428
|
+
'scales',
|
|
35429
|
+
'sh0',
|
|
35430
|
+
'shN'
|
|
35431
|
+
].forEach((name)=>{
|
|
35432
|
+
const codebook = this.meta[name]?.codebook;
|
|
35433
|
+
if (codebook?.[0] === null) {
|
|
35434
|
+
codebook[0] = codebook[1] + (codebook[1] - codebook[255]) / 255;
|
|
35435
|
+
}
|
|
35436
|
+
});
|
|
35437
|
+
if (this.destroyed || device._destroyed) return;
|
|
35438
|
+
await this.generateCenters();
|
|
35439
|
+
if (this.destroyed || device._destroyed) return;
|
|
35059
35440
|
this.packGpuMemory();
|
|
35060
35441
|
if (this.packedShN) {
|
|
35442
|
+
if (this.destroyed || device._destroyed) return;
|
|
35061
35443
|
this.packShMemory();
|
|
35062
35444
|
}
|
|
35063
35445
|
}
|
|
35064
35446
|
reorderData() {
|
|
35065
35447
|
return this.prepareGpuData();
|
|
35066
35448
|
}
|
|
35449
|
+
constructor(){
|
|
35450
|
+
this._centers = null;
|
|
35451
|
+
this.destroyed = false;
|
|
35452
|
+
}
|
|
35067
35453
|
}
|
|
35068
35454
|
|
|
35069
35455
|
const mat = new Mat4();
|
|
@@ -35116,6 +35502,7 @@ class GSplatInstance {
|
|
|
35116
35502
|
this.setHighQualitySH(options.highQualitySH ?? false);
|
|
35117
35503
|
}
|
|
35118
35504
|
destroy() {
|
|
35505
|
+
this.orderTexture?.destroy();
|
|
35119
35506
|
this.resolveSH?.destroy();
|
|
35120
35507
|
this.material?.destroy();
|
|
35121
35508
|
this.meshInstance?.destroy();
|
|
@@ -35853,10 +36240,7 @@ class Asset extends EventHandler {
|
|
|
35853
36240
|
this.registry._loader.clearCache(this.getFileUrl(), this.type);
|
|
35854
36241
|
}
|
|
35855
36242
|
for(let i = 0; i < old.length; ++i){
|
|
35856
|
-
|
|
35857
|
-
if (resource && resource.destroy) {
|
|
35858
|
-
resource.destroy();
|
|
35859
|
-
}
|
|
36243
|
+
old[i]?.destroy?.();
|
|
35860
36244
|
}
|
|
35861
36245
|
}
|
|
35862
36246
|
static fetchArrayBuffer(loadUrl, callback, asset, maxRetries = 0) {
|
|
@@ -37780,6 +38164,7 @@ class ApplicationStats {
|
|
|
37780
38164
|
morphTime: 0,
|
|
37781
38165
|
instancingTime: 0,
|
|
37782
38166
|
triangles: 0,
|
|
38167
|
+
gsplats: 0,
|
|
37783
38168
|
otherPrimitives: 0,
|
|
37784
38169
|
shaders: 0,
|
|
37785
38170
|
materials: 0,
|
|
@@ -39651,20 +40036,19 @@ var gsplatPS$1 = `
|
|
|
39651
40036
|
varying float vLinearDepth;
|
|
39652
40037
|
#include "floatAsUintPS"
|
|
39653
40038
|
#endif
|
|
39654
|
-
const float EXP_A = 12102203.0;
|
|
39655
|
-
const int EXP_BC_RMS = 1064866808;
|
|
39656
|
-
float fastExp(float x) {
|
|
39657
|
-
int i = int(EXP_A * x) + EXP_BC_RMS;
|
|
39658
|
-
return intBitsToFloat(i);
|
|
39659
|
-
}
|
|
39660
40039
|
varying mediump vec2 gaussianUV;
|
|
39661
40040
|
varying mediump vec4 gaussianColor;
|
|
40041
|
+
const float EXP4 = exp(-4.0);
|
|
40042
|
+
const float INV_EXP4 = 1.0 / (1.0 - EXP4);
|
|
40043
|
+
float normExp(float x) {
|
|
40044
|
+
return (exp(x * -4.0) - EXP4) * INV_EXP4;
|
|
40045
|
+
}
|
|
39662
40046
|
void main(void) {
|
|
39663
40047
|
mediump float A = dot(gaussianUV, gaussianUV);
|
|
39664
40048
|
if (A > 1.0) {
|
|
39665
40049
|
discard;
|
|
39666
40050
|
}
|
|
39667
|
-
mediump float alpha =
|
|
40051
|
+
mediump float alpha = normExp(A) * gaussianColor.a;
|
|
39668
40052
|
#if defined(SHADOW_PASS) || defined(PICK_PASS) || defined(PREPASS_PASS)
|
|
39669
40053
|
if (alpha < alphaClip) {
|
|
39670
40054
|
discard;
|
|
@@ -44251,7 +44635,7 @@ var clusteredLightPS = `
|
|
|
44251
44635
|
#include "clusteredLightShadowsPS"
|
|
44252
44636
|
#endif
|
|
44253
44637
|
var clusterWorldTexture: texture_2d<f32>;
|
|
44254
|
-
var lightsTexture: texture_2d<
|
|
44638
|
+
var lightsTexture: texture_2d<uff>;
|
|
44255
44639
|
#ifdef CLUSTER_SHADOWS
|
|
44256
44640
|
var shadowAtlasTexture: texture_depth_2d;
|
|
44257
44641
|
var shadowAtlasTextureSampler: sampler_comparison;
|
|
@@ -45166,7 +45550,7 @@ fn initCenter(modelCenter: vec3f, center: ptr<function, SplatCenter>) -> bool {
|
|
|
45166
45550
|
`;
|
|
45167
45551
|
|
|
45168
45552
|
var gsplatColorVS = `
|
|
45169
|
-
var splatColor: texture_2d<
|
|
45553
|
+
var splatColor: texture_2d<uff>;
|
|
45170
45554
|
fn readColor(source: ptr<function, SplatSource>) -> vec4f {
|
|
45171
45555
|
return textureLoad(splatColor, source.uv, 0);
|
|
45172
45556
|
}
|
|
@@ -45190,7 +45574,7 @@ fn clipCorner(corner: ptr<function, SplatCorner>, alpha: f32) {
|
|
|
45190
45574
|
|
|
45191
45575
|
var gsplatCompressedDataVS = `
|
|
45192
45576
|
var packedTexture: texture_2d<u32>;
|
|
45193
|
-
var chunkTexture: texture_2d<
|
|
45577
|
+
var chunkTexture: texture_2d<uff>;
|
|
45194
45578
|
var<private> chunkDataA: vec4f;
|
|
45195
45579
|
var<private> chunkDataB: vec4f;
|
|
45196
45580
|
var<private> chunkDataC: vec4f;
|
|
@@ -45558,7 +45942,7 @@ fn initCorner(source: ptr<function, SplatSource>, center: ptr<function, SplatCen
|
|
|
45558
45942
|
|
|
45559
45943
|
var gsplatDataVS = `
|
|
45560
45944
|
var transformA: texture_2d<u32>;
|
|
45561
|
-
var transformB: texture_2d<
|
|
45945
|
+
var transformB: texture_2d<uff>;
|
|
45562
45946
|
var<private> tAw: u32;
|
|
45563
45947
|
fn readCenter(source: ptr<function, SplatSource>) -> vec3f {
|
|
45564
45948
|
let tA: vec4<u32> = textureLoad(transformA, source.uv, 0);
|
|
@@ -45615,11 +45999,10 @@ var gsplatPS = `
|
|
|
45615
45999
|
varying vLinearDepth: f32;
|
|
45616
46000
|
#include "floatAsUintPS"
|
|
45617
46001
|
#endif
|
|
45618
|
-
const
|
|
45619
|
-
const
|
|
45620
|
-
fn
|
|
45621
|
-
|
|
45622
|
-
return bitcast<f32>(i);
|
|
46002
|
+
const EXP4 = exp(-4.0);
|
|
46003
|
+
const INV_EXP4 = 1.0 / (1.0 - EXP4);
|
|
46004
|
+
fn normExp(x: f32) -> f32 {
|
|
46005
|
+
return (exp(x * -4.0) - EXP4) * INV_EXP4;
|
|
45623
46006
|
}
|
|
45624
46007
|
varying gaussianUV: vec2f;
|
|
45625
46008
|
varying gaussianColor: vec4f;
|
|
@@ -45631,7 +46014,7 @@ fn fragmentMain(input: FragmentInput) -> FragmentOutput {
|
|
|
45631
46014
|
discard;
|
|
45632
46015
|
return output;
|
|
45633
46016
|
}
|
|
45634
|
-
var alpha
|
|
46017
|
+
var alpha = normExp(A) * gaussianColor.a;
|
|
45635
46018
|
#if defined(SHADOW_PASS) || defined(PICK_PASS) || defined(PREPASS_PASS)
|
|
45636
46019
|
if (alpha < uniform.alphaClip) {
|
|
45637
46020
|
discard;
|
|
@@ -45826,10 +46209,10 @@ fn vertexMain(input: VertexInput) -> VertexOutput {
|
|
|
45826
46209
|
`;
|
|
45827
46210
|
|
|
45828
46211
|
var gsplatWorkBufferVS = `
|
|
45829
|
-
var center: texture_2d<
|
|
45830
|
-
var covA: texture_2d<
|
|
45831
|
-
var covB: texture_2d<
|
|
45832
|
-
var splatColor: texture_2d<
|
|
46212
|
+
var center: texture_2d<uff>;
|
|
46213
|
+
var covA: texture_2d<uff>;
|
|
46214
|
+
var covB: texture_2d<uff>;
|
|
46215
|
+
var splatColor: texture_2d<uff>;
|
|
45833
46216
|
fn readCenter(source: ptr<function, SplatSource>) -> vec3f {
|
|
45834
46217
|
return textureLoad(center, source.uv, 0).xyz;
|
|
45835
46218
|
}
|
|
@@ -48342,8 +48725,7 @@ fn vertexMain(input: VertexInput) -> VertexOutput {
|
|
|
48342
48725
|
`;
|
|
48343
48726
|
|
|
48344
48727
|
var screenDepthPS = `
|
|
48345
|
-
var uSceneDepthMap: texture_2d<
|
|
48346
|
-
var uSceneDepthMapSampler: sampler;
|
|
48728
|
+
var uSceneDepthMap: texture_2d<uff>;
|
|
48347
48729
|
#ifndef SCREENSIZE
|
|
48348
48730
|
#define SCREENSIZE
|
|
48349
48731
|
uniform uScreenSize: vec4f;
|
|
@@ -48374,19 +48756,12 @@ fn delinearizeDepth(linearDepth: f32) -> f32 {
|
|
|
48374
48756
|
}
|
|
48375
48757
|
}
|
|
48376
48758
|
fn getLinearScreenDepth(uv: vec2f) -> f32 {
|
|
48759
|
+
let textureSize = textureDimensions(uSceneDepthMap, 0);
|
|
48760
|
+
let texel: vec2i = vec2i(uv * vec2f(textureSize));
|
|
48377
48761
|
#ifdef SCENE_DEPTHMAP_LINEAR
|
|
48378
|
-
|
|
48379
|
-
return textureSample(uSceneDepthMap, uSceneDepthMapSampler, uv).r;
|
|
48380
|
-
#else
|
|
48381
|
-
let textureSize = textureDimensions(uSceneDepthMap, 0);
|
|
48382
|
-
let texel: vec2i = vec2i(uv * vec2f(textureSize));
|
|
48383
|
-
let data: vec4f = textureLoad(uSceneDepthMap, texel, 0);
|
|
48384
|
-
let data_u32: vec4u = vec4u(data * 255.0);
|
|
48385
|
-
let intBits: u32 = (data_u32.r << 24u) | (data_u32.g << 16u) | (data_u32.b << 8u) | data_u32.a;
|
|
48386
|
-
return bitcast<f32>(intBits);
|
|
48387
|
-
#endif
|
|
48762
|
+
return textureLoad(uSceneDepthMap, texel, 0).r;
|
|
48388
48763
|
#else
|
|
48389
|
-
return linearizeDepth(
|
|
48764
|
+
return linearizeDepth(textureLoad(uSceneDepthMap, texel, 0).r);
|
|
48390
48765
|
#endif
|
|
48391
48766
|
}
|
|
48392
48767
|
#ifndef VERTEXSHADER
|
|
@@ -48683,7 +49058,7 @@ fn getShadowPCSS(shadowMap: texture_2d<f32>, shadowMapSampler: sampler, shadowCo
|
|
|
48683
49058
|
|
|
48684
49059
|
var skinBatchVS = `
|
|
48685
49060
|
attribute vertex_boneIndices: f32;
|
|
48686
|
-
var texture_poseMap: texture_2d<
|
|
49061
|
+
var texture_poseMap: texture_2d<uff>;
|
|
48687
49062
|
fn getBoneMatrix(indexFloat: f32) -> mat4x4f {
|
|
48688
49063
|
let width = i32(textureDimensions(texture_poseMap).x);
|
|
48689
49064
|
let index: i32 = i32(indexFloat + 0.5) * 3;
|
|
@@ -48704,7 +49079,7 @@ fn getBoneMatrix(indexFloat: f32) -> mat4x4f {
|
|
|
48704
49079
|
var skinVS = `
|
|
48705
49080
|
attribute vertex_boneWeights: vec4f;
|
|
48706
49081
|
attribute vertex_boneIndices: vec4f;
|
|
48707
|
-
var texture_poseMap: texture_2d<
|
|
49082
|
+
var texture_poseMap: texture_2d<uff>;
|
|
48708
49083
|
struct BoneMatrix {
|
|
48709
49084
|
v1: vec4f,
|
|
48710
49085
|
v2: vec4f,
|
|
@@ -50177,6 +50552,7 @@ class AppBase extends EventHandler {
|
|
|
50177
50552
|
}
|
|
50178
50553
|
this.stats.drawCalls.total = this.graphicsDevice._drawCallsPerFrame;
|
|
50179
50554
|
this.graphicsDevice._drawCallsPerFrame = 0;
|
|
50555
|
+
stats.gsplats = this.renderer._gsplatCount;
|
|
50180
50556
|
}
|
|
50181
50557
|
_fillFrameStats() {
|
|
50182
50558
|
let stats = this.stats.frame;
|
|
@@ -52690,7 +53066,7 @@ class AnimEvaluator {
|
|
|
52690
53066
|
for(const path in targets){
|
|
52691
53067
|
if (targets.hasOwnProperty(path)) {
|
|
52692
53068
|
const target = targets[path];
|
|
52693
|
-
if (binder.animComponent && target.target.
|
|
53069
|
+
if (binder.animComponent && target.target.usesLayerBlending) {
|
|
52694
53070
|
const animTarget = binder.animComponent.targets[path];
|
|
52695
53071
|
if (animTarget.counter === animTarget.layerCounter) {
|
|
52696
53072
|
animTarget.counter = 0;
|
|
@@ -52832,6 +53208,7 @@ class AnimTarget {
|
|
|
52832
53208
|
this._components = components;
|
|
52833
53209
|
this._targetPath = targetPath;
|
|
52834
53210
|
this._isTransform = this._targetPath.substring(this._targetPath.length - 13) === 'localRotation' || this._targetPath.substring(this._targetPath.length - 13) === 'localPosition' || this._targetPath.substring(this._targetPath.length - 10) === 'localScale';
|
|
53211
|
+
this._isWeight = this._targetPath.indexOf('weight.') !== -1;
|
|
52835
53212
|
}
|
|
52836
53213
|
get set() {
|
|
52837
53214
|
return this._set;
|
|
@@ -52851,6 +53228,12 @@ class AnimTarget {
|
|
|
52851
53228
|
get isTransform() {
|
|
52852
53229
|
return this._isTransform;
|
|
52853
53230
|
}
|
|
53231
|
+
get isWeight() {
|
|
53232
|
+
return this._isWeight;
|
|
53233
|
+
}
|
|
53234
|
+
get usesLayerBlending() {
|
|
53235
|
+
return this._isTransform || this._isWeight;
|
|
53236
|
+
}
|
|
52854
53237
|
}
|
|
52855
53238
|
|
|
52856
53239
|
class DefaultAnimBinder {
|
|
@@ -52920,26 +53303,28 @@ class DefaultAnimBinder {
|
|
|
52920
53303
|
weightName = Number(weightName);
|
|
52921
53304
|
}
|
|
52922
53305
|
const meshInstances = findMeshInstances(node);
|
|
52923
|
-
|
|
53306
|
+
const instances = [];
|
|
52924
53307
|
if (meshInstances) {
|
|
52925
53308
|
for(let i = 0; i < meshInstances.length; ++i){
|
|
52926
53309
|
if (meshInstances[i].node.name === node.name && meshInstances[i].morphInstance) {
|
|
52927
|
-
|
|
52928
|
-
const func = (value)=>{
|
|
52929
|
-
morphInstance.setWeight(weightName, value[0]);
|
|
52930
|
-
};
|
|
52931
|
-
if (!setters) setters = [];
|
|
52932
|
-
setters.push(func);
|
|
53310
|
+
instances.push(meshInstances[i].morphInstance);
|
|
52933
53311
|
}
|
|
52934
53312
|
}
|
|
52935
53313
|
}
|
|
52936
|
-
if (
|
|
52937
|
-
const
|
|
52938
|
-
|
|
52939
|
-
|
|
53314
|
+
if (instances.length > 0) {
|
|
53315
|
+
const func = {
|
|
53316
|
+
set: (value)=>{
|
|
53317
|
+
for(let i = 0; i < instances.length; ++i){
|
|
53318
|
+
instances[i].setWeight(weightName, value[0]);
|
|
53319
|
+
}
|
|
53320
|
+
},
|
|
53321
|
+
get: ()=>{
|
|
53322
|
+
return [
|
|
53323
|
+
instances[0].getWeight(weightName)
|
|
53324
|
+
];
|
|
52940
53325
|
}
|
|
52941
53326
|
};
|
|
52942
|
-
return DefaultAnimBinder.createAnimTarget(
|
|
53327
|
+
return DefaultAnimBinder.createAnimTarget(func, 'number', 1, node, `weight.${weightName}`);
|
|
52943
53328
|
}
|
|
52944
53329
|
return null;
|
|
52945
53330
|
},
|
|
@@ -65771,7 +66156,9 @@ uniform float graphNumSamples;
|
|
|
65771
66156
|
#define CAMERAPLANES
|
|
65772
66157
|
uniform vec4 camera_params;
|
|
65773
66158
|
#endif
|
|
65774
|
-
|
|
66159
|
+
#ifdef SOFT
|
|
66160
|
+
uniform float softening;
|
|
66161
|
+
#endif
|
|
65775
66162
|
uniform float colorMult;
|
|
65776
66163
|
float saturate(float x) {
|
|
65777
66164
|
return clamp(x, 0.0, 1.0);
|
|
@@ -66182,10 +66569,14 @@ uniform float numParticles;
|
|
|
66182
66569
|
uniform float lifetime;
|
|
66183
66570
|
uniform float stretch;
|
|
66184
66571
|
uniform float seed;
|
|
66185
|
-
uniform vec3 wrapBounds;
|
|
66186
66572
|
uniform vec3 emitterScale;
|
|
66187
66573
|
uniform vec3 faceTangent;
|
|
66188
66574
|
uniform vec3 faceBinorm;
|
|
66575
|
+
#ifdef PARTICLE_GPU
|
|
66576
|
+
#ifdef WRAP
|
|
66577
|
+
uniform vec3 wrapBounds;
|
|
66578
|
+
#endif
|
|
66579
|
+
#endif
|
|
66189
66580
|
#ifdef PARTICLE_GPU
|
|
66190
66581
|
uniform highp sampler2D internalTex0;
|
|
66191
66582
|
uniform highp sampler2D internalTex1;
|
|
@@ -66294,7 +66685,6 @@ uniform float numParticlesPot;
|
|
|
66294
66685
|
uniform float graphSampleSize;
|
|
66295
66686
|
uniform float graphNumSamples;
|
|
66296
66687
|
uniform float stretch;
|
|
66297
|
-
uniform vec3 wrapBounds;
|
|
66298
66688
|
uniform vec3 emitterScale;
|
|
66299
66689
|
uniform vec3 emitterPos;
|
|
66300
66690
|
uniform vec3 faceTangent;
|
|
@@ -66302,13 +66692,17 @@ uniform vec3 faceBinorm;
|
|
|
66302
66692
|
uniform float rate;
|
|
66303
66693
|
uniform float rateDiv;
|
|
66304
66694
|
uniform float lifetime;
|
|
66305
|
-
uniform float deltaRandomnessStatic;
|
|
66306
66695
|
uniform float scaleDivMult;
|
|
66307
66696
|
uniform float alphaDivMult;
|
|
66308
66697
|
uniform float seed;
|
|
66309
66698
|
uniform float delta;
|
|
66310
66699
|
uniform sampler2D particleTexOUT;
|
|
66311
66700
|
uniform sampler2D particleTexIN;
|
|
66701
|
+
#ifdef PARTICLE_GPU
|
|
66702
|
+
#ifdef WRAP
|
|
66703
|
+
uniform vec3 wrapBounds;
|
|
66704
|
+
#endif
|
|
66705
|
+
#endif
|
|
66312
66706
|
#ifdef PARTICLE_GPU
|
|
66313
66707
|
uniform highp sampler2D internalTex0;
|
|
66314
66708
|
uniform highp sampler2D internalTex1;
|
|
@@ -66608,7 +67002,9 @@ uniform graphNumSamples: f32;
|
|
|
66608
67002
|
#define CAMERAPLANES
|
|
66609
67003
|
uniform camera_params: vec4f;
|
|
66610
67004
|
#endif
|
|
66611
|
-
|
|
67005
|
+
#ifdef SOFT
|
|
67006
|
+
uniform softening: f32;
|
|
67007
|
+
#endif
|
|
66612
67008
|
uniform colorMult: f32;
|
|
66613
67009
|
fn saturate(x: f32) -> f32 {
|
|
66614
67010
|
return clamp(x, 0.0, 1.0);
|
|
@@ -66638,14 +67034,18 @@ struct TexLerpUnpackResult {
|
|
|
66638
67034
|
result: vec4f,
|
|
66639
67035
|
unpacked: vec3f
|
|
66640
67036
|
}
|
|
66641
|
-
fn tex1Dlod_lerp_simple(tex: texture_2d<f32>,
|
|
67037
|
+
fn tex1Dlod_lerp_simple(tex: texture_2d<f32>, textureSize: vec2u, tc: vec2f) -> vec4f {
|
|
66642
67038
|
let tc_next = tc + vec2f(uniform.graphSampleSize);
|
|
66643
|
-
|
|
67039
|
+
let texelA: vec2i = vec2i(tc * vec2f(textureSize));
|
|
67040
|
+
let texelB: vec2i = vec2i(tc_next * vec2f(textureSize));
|
|
67041
|
+
return mix( textureLoad(tex, texelA, 0), textureLoad(tex, texelB, 0), fract(tc.x * uniform.graphNumSamples) );
|
|
66644
67042
|
}
|
|
66645
|
-
fn tex1Dlod_lerp_unpack(tex: texture_2d<f32>,
|
|
67043
|
+
fn tex1Dlod_lerp_unpack(tex: texture_2d<f32>, textureSize: vec2u, tc: vec2f) -> TexLerpUnpackResult {
|
|
66646
67044
|
let tc_next = tc + vec2f(uniform.graphSampleSize);
|
|
66647
|
-
let
|
|
66648
|
-
let
|
|
67045
|
+
let texelA: vec2i = vec2i(tc * vec2f(textureSize));
|
|
67046
|
+
let texelB: vec2i = vec2i(tc_next * vec2f(textureSize));
|
|
67047
|
+
let a = textureLoad(tex, texelA, 0);
|
|
67048
|
+
let b = textureLoad(tex, texelB, 0);
|
|
66649
67049
|
let c = fract(tc.x * uniform.graphNumSamples);
|
|
66650
67050
|
let unpackedA = unpack3NFloats(a.w);
|
|
66651
67051
|
let unpackedB = unpack3NFloats(b.w);
|
|
@@ -66701,7 +67101,8 @@ fn vertexMain(input: VertexInput) -> VertexOutput {
|
|
|
66701
67101
|
}
|
|
66702
67102
|
let quadXY = meshLocalPos.xy;
|
|
66703
67103
|
let nlife = clamp(inLife / particleLifetime, 0.0, 1.0);
|
|
66704
|
-
let
|
|
67104
|
+
let internalTexSize = textureDimensions(internalTex2, 0);
|
|
67105
|
+
let lerp_result = tex1Dlod_lerp_unpack(internalTex2, internalTexSize, vec2f(nlife, 0.0));
|
|
66705
67106
|
let params = lerp_result.result;
|
|
66706
67107
|
let paramDiv = lerp_result.unpacked;
|
|
66707
67108
|
var scale = params.y;
|
|
@@ -66744,8 +67145,11 @@ var particleAnimTexVS = `
|
|
|
66744
67145
|
|
|
66745
67146
|
var particleInputFloatPS = `
|
|
66746
67147
|
fn readInput(uv: f32) {
|
|
66747
|
-
let
|
|
66748
|
-
let
|
|
67148
|
+
let textureSize = textureDimensions(particleTexIN, 0);
|
|
67149
|
+
let texel0: vec2i = vec2i(vec2f(uv, 0.25) * vec2f(textureSize));
|
|
67150
|
+
let texel1: vec2i = vec2i(vec2f(uv, 0.75) * vec2f(textureSize));
|
|
67151
|
+
let tex: vec4f = textureLoad(particleTexIN, texel0, 0);
|
|
67152
|
+
let tex2: vec4f = textureLoad(particleTexIN, texel1, 0);
|
|
66749
67153
|
inPos = tex.xyz;
|
|
66750
67154
|
inVel = tex2.xyz;
|
|
66751
67155
|
inAngle = abs(tex.w) - 1000.0;
|
|
@@ -66766,10 +67170,15 @@ fn decodeFloatRGBA( rgba: vec4f ) -> f32 {
|
|
|
66766
67170
|
return dot(rgba, vec4f(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 160581375.0));
|
|
66767
67171
|
}
|
|
66768
67172
|
fn readInput(uv: f32) {
|
|
66769
|
-
let
|
|
66770
|
-
let
|
|
66771
|
-
let
|
|
66772
|
-
let
|
|
67173
|
+
let textureSize = textureDimensions(particleTexIN, 0);
|
|
67174
|
+
let texel0: vec2i = vec2i(vec2f(uv, 0.125) * vec2f(textureSize));
|
|
67175
|
+
let texel1: vec2i = vec2i(vec2f(uv, 0.375) * vec2f(textureSize));
|
|
67176
|
+
let texel2: vec2i = vec2i(vec2f(uv, 0.625) * vec2f(textureSize));
|
|
67177
|
+
let texel3: vec2i = vec2i(vec2f(uv, 0.875) * vec2f(textureSize));
|
|
67178
|
+
let tex0 = textureLoad(particleTexIN, texel0, 0);
|
|
67179
|
+
let tex1 = textureLoad(particleTexIN, texel1, 0);
|
|
67180
|
+
let tex2 = textureLoad(particleTexIN, texel2, 0);
|
|
67181
|
+
let tex3 = textureLoad(particleTexIN, texel3, 0);
|
|
66773
67182
|
inPos = vec3f(decodeFloatRG(tex0.rg), decodeFloatRG(tex0.ba), decodeFloatRG(tex1.rg));
|
|
66774
67183
|
inPos = (inPos - vec3f(0.5)) * uniform.inBoundsSize + uniform.inBoundsCenter;
|
|
66775
67184
|
inVel = tex2.xyz;
|
|
@@ -66858,16 +67267,11 @@ var particleUpdaterEndPS = `
|
|
|
66858
67267
|
|
|
66859
67268
|
var particleUpdaterInitPS = `
|
|
66860
67269
|
varying vUv0: vec2f;
|
|
66861
|
-
var particleTexIN: texture_2d<
|
|
66862
|
-
var
|
|
66863
|
-
var
|
|
66864
|
-
var
|
|
66865
|
-
var
|
|
66866
|
-
var internalTex1Sampler: sampler;
|
|
66867
|
-
var internalTex2: texture_2d<f32>;
|
|
66868
|
-
var internalTex2Sampler: sampler;
|
|
66869
|
-
var internalTex3: texture_2d<f32>;
|
|
66870
|
-
var internalTex3Sampler: sampler;
|
|
67270
|
+
var particleTexIN: texture_2d<uff>;
|
|
67271
|
+
var internalTex0: texture_2d<uff>;
|
|
67272
|
+
var internalTex1: texture_2d<uff>;
|
|
67273
|
+
var internalTex2: texture_2d<uff>;
|
|
67274
|
+
var internalTex3: texture_2d<uff>;
|
|
66871
67275
|
uniform emitterMatrix: mat3x3f;
|
|
66872
67276
|
uniform emitterMatrixInv: mat3x3f;
|
|
66873
67277
|
uniform emitterScale: vec3f;
|
|
@@ -66954,10 +67358,12 @@ struct TexLerpUnpackResult {
|
|
|
66954
67358
|
result: vec3f,
|
|
66955
67359
|
unpacked: vec3f
|
|
66956
67360
|
}
|
|
66957
|
-
fn tex1Dlod_lerp(tex: texture_2d<f32>,
|
|
67361
|
+
fn tex1Dlod_lerp(tex: texture_2d<f32>, textureSize: vec2u, tc: vec2f) -> TexLerpUnpackResult {
|
|
66958
67362
|
let tc_next = tc + vec2f(uniform.graphSampleSize);
|
|
66959
|
-
let
|
|
66960
|
-
let
|
|
67363
|
+
let texelA: vec2i = vec2i(tc * vec2f(textureSize));
|
|
67364
|
+
let texelB: vec2i = vec2i(tc_next * vec2f(textureSize));
|
|
67365
|
+
let a = textureLoad(tex, texelA, 0);
|
|
67366
|
+
let b = textureLoad(tex, texelB, 0);
|
|
66961
67367
|
let c = fract(tc.x * uniform.graphNumSamples);
|
|
66962
67368
|
let unpackedA = unpack3NFloats(a.w);
|
|
66963
67369
|
let unpackedB = unpack3NFloats(b.w);
|
|
@@ -66983,18 +67389,19 @@ fn fragmentMain(input : FragmentInput) -> FragmentOutput {
|
|
|
66983
67389
|
let particleRate = uniform.rate + uniform.rateDiv * rndFactor.x;
|
|
66984
67390
|
outLife = inLife + uniform.delta;
|
|
66985
67391
|
let nlife = clamp(outLife / uniform.lifetime, 0.0, 1.0);
|
|
66986
|
-
let
|
|
67392
|
+
let internalTexSize = textureDimensions(internalTex0, 0);
|
|
67393
|
+
let lerpResult0 = tex1Dlod_lerp(internalTex0, internalTexSize, vec2f(nlife, 0.0));
|
|
66987
67394
|
var localVelocity = lerpResult0.result;
|
|
66988
67395
|
let localVelocityDiv = lerpResult0.unpacked;
|
|
66989
|
-
let lerpResult1 = tex1Dlod_lerp(internalTex1,
|
|
67396
|
+
let lerpResult1 = tex1Dlod_lerp(internalTex1, internalTexSize, vec2f(nlife, 0.0));
|
|
66990
67397
|
var velocity = lerpResult1.result;
|
|
66991
67398
|
let velocityDiv = lerpResult1.unpacked;
|
|
66992
|
-
let lerpResult2 = tex1Dlod_lerp(internalTex2,
|
|
67399
|
+
let lerpResult2 = tex1Dlod_lerp(internalTex2, internalTexSize, vec2f(nlife, 0.0));
|
|
66993
67400
|
let params = lerpResult2.result;
|
|
66994
67401
|
let paramDiv = lerpResult2.unpacked;
|
|
66995
67402
|
var rotSpeed = params.x;
|
|
66996
67403
|
let rotSpeedDiv = paramDiv.y;
|
|
66997
|
-
let lerpResult3 = tex1Dlod_lerp(internalTex3,
|
|
67404
|
+
let lerpResult3 = tex1Dlod_lerp(internalTex3, internalTexSize, vec2f(nlife, 0.0));
|
|
66998
67405
|
let radialParams = lerpResult3.result;
|
|
66999
67406
|
let radialParamDiv = lerpResult3.unpacked;
|
|
67000
67407
|
let radialSpeed = radialParams.x;
|
|
@@ -67072,17 +67479,18 @@ uniform numParticles: f32;
|
|
|
67072
67479
|
uniform lifetime: f32;
|
|
67073
67480
|
uniform stretch: f32;
|
|
67074
67481
|
uniform seed: f32;
|
|
67075
|
-
uniform wrapBounds: vec3f;
|
|
67076
67482
|
uniform emitterScale: vec3f;
|
|
67077
67483
|
uniform faceTangent: vec3f;
|
|
67078
67484
|
uniform faceBinorm: vec3f;
|
|
67079
67485
|
#ifdef PARTICLE_GPU
|
|
67080
|
-
|
|
67081
|
-
|
|
67082
|
-
|
|
67083
|
-
|
|
67084
|
-
|
|
67085
|
-
var
|
|
67486
|
+
#ifdef WRAP
|
|
67487
|
+
uniform wrapBounds: vec3f;
|
|
67488
|
+
#endif
|
|
67489
|
+
#endif
|
|
67490
|
+
#ifdef PARTICLE_GPU
|
|
67491
|
+
var internalTex0: texture_2d<uff>;
|
|
67492
|
+
var internalTex1: texture_2d<uff>;
|
|
67493
|
+
var internalTex2: texture_2d<uff>;
|
|
67086
67494
|
#endif
|
|
67087
67495
|
uniform emitterPos: vec3f;
|
|
67088
67496
|
varying texCoordsAlphaLife: vec4f;
|
|
@@ -67196,7 +67604,6 @@ uniform numParticlesPot: f32;
|
|
|
67196
67604
|
uniform graphSampleSize: f32;
|
|
67197
67605
|
uniform graphNumSamples: f32;
|
|
67198
67606
|
uniform stretch: f32;
|
|
67199
|
-
uniform wrapBounds: vec3f;
|
|
67200
67607
|
uniform emitterScale: vec3f;
|
|
67201
67608
|
uniform emitterPos: vec3f;
|
|
67202
67609
|
uniform faceTangent: vec3f;
|
|
@@ -67204,22 +67611,21 @@ uniform faceBinorm: vec3f;
|
|
|
67204
67611
|
uniform rate: f32;
|
|
67205
67612
|
uniform rateDiv: f32;
|
|
67206
67613
|
uniform lifetime: f32;
|
|
67207
|
-
uniform deltaRandomnessStatic: f32;
|
|
67208
67614
|
uniform scaleDivMult: f32;
|
|
67209
67615
|
uniform alphaDivMult: f32;
|
|
67210
67616
|
uniform seed: f32;
|
|
67211
67617
|
uniform delta: f32;
|
|
67212
|
-
var particleTexOUT: texture_2d<f32>;
|
|
67213
|
-
var particleTexOUTSampler: sampler;
|
|
67214
|
-
var particleTexIN: texture_2d<f32>;
|
|
67215
|
-
var particleTexINSampler: sampler;
|
|
67216
67618
|
#ifdef PARTICLE_GPU
|
|
67217
|
-
|
|
67218
|
-
|
|
67219
|
-
|
|
67220
|
-
|
|
67221
|
-
|
|
67222
|
-
|
|
67619
|
+
#ifdef WRAP
|
|
67620
|
+
uniform wrapBounds: vec3f;
|
|
67621
|
+
#endif
|
|
67622
|
+
#endif
|
|
67623
|
+
var particleTexOUT: texture_2d<uff>;
|
|
67624
|
+
var particleTexIN: texture_2d<uff>;
|
|
67625
|
+
#ifdef PARTICLE_GPU
|
|
67626
|
+
var internalTex0: texture_2d<uff>;
|
|
67627
|
+
var internalTex1: texture_2d<uff>;
|
|
67628
|
+
var internalTex2: texture_2d<uff>;
|
|
67223
67629
|
#endif
|
|
67224
67630
|
#ifndef CAMERAPLANES
|
|
67225
67631
|
#define CAMERAPLANES
|
|
@@ -70670,14 +71076,14 @@ class ScrollViewComponent extends Component {
|
|
|
70670
71076
|
if (overshoot > 0) {
|
|
70671
71077
|
scrollValue.x = max + factor * Math.log10(1 + overshoot);
|
|
70672
71078
|
} else if (overshoot < 0) {
|
|
70673
|
-
scrollValue.x = -
|
|
71079
|
+
scrollValue.x = -factor * Math.log10(1 - overshoot);
|
|
70674
71080
|
}
|
|
70675
71081
|
max = this._getMaxScrollValue(ORIENTATION_VERTICAL);
|
|
70676
71082
|
overshoot = this._toOvershoot(scrollValue.y, ORIENTATION_VERTICAL);
|
|
70677
71083
|
if (overshoot > 0) {
|
|
70678
71084
|
scrollValue.y = max + factor * Math.log10(1 + overshoot);
|
|
70679
71085
|
} else if (overshoot < 0) {
|
|
70680
|
-
scrollValue.y = -
|
|
71086
|
+
scrollValue.y = -factor * Math.log10(1 - overshoot);
|
|
70681
71087
|
}
|
|
70682
71088
|
return scrollValue;
|
|
70683
71089
|
}
|
|
@@ -73407,6 +73813,12 @@ class CameraComponent extends Component {
|
|
|
73407
73813
|
get clearColorBuffer() {
|
|
73408
73814
|
return this._camera.clearColorBuffer;
|
|
73409
73815
|
}
|
|
73816
|
+
set clearDepth(value) {
|
|
73817
|
+
this._camera.clearDepth = value;
|
|
73818
|
+
}
|
|
73819
|
+
get clearDepth() {
|
|
73820
|
+
return this._camera.clearDepth;
|
|
73821
|
+
}
|
|
73410
73822
|
set clearDepthBuffer(value) {
|
|
73411
73823
|
this._camera.clearDepthBuffer = value;
|
|
73412
73824
|
this.dirtyLayerCompositionCameras();
|
|
@@ -73782,6 +74194,7 @@ class CameraComponentSystem extends ComponentSystem {
|
|
|
73782
74194
|
'calculateTransform',
|
|
73783
74195
|
'clearColor',
|
|
73784
74196
|
'clearColorBuffer',
|
|
74197
|
+
'clearDepth',
|
|
73785
74198
|
'clearDepthBuffer',
|
|
73786
74199
|
'clearStencilBuffer',
|
|
73787
74200
|
'renderSceneColorMap',
|
|
@@ -74300,7 +74713,7 @@ class LightComponent extends Component {
|
|
|
74300
74713
|
if (newValue) {
|
|
74301
74714
|
this.light.mask |= MASK_AFFECT_DYNAMIC;
|
|
74302
74715
|
} else {
|
|
74303
|
-
this.light.mask &=
|
|
74716
|
+
this.light.mask &= ~MASK_AFFECT_DYNAMIC;
|
|
74304
74717
|
}
|
|
74305
74718
|
this.light.layersDirty();
|
|
74306
74719
|
});
|
|
@@ -74312,9 +74725,9 @@ class LightComponent extends Component {
|
|
|
74312
74725
|
this._setValue('affectLightmapped', arg, function(newValue, oldValue) {
|
|
74313
74726
|
if (newValue) {
|
|
74314
74727
|
this.light.mask |= MASK_AFFECT_LIGHTMAPPED;
|
|
74315
|
-
if (this.bake) this.light.mask &=
|
|
74728
|
+
if (this.bake) this.light.mask &= ~MASK_BAKE;
|
|
74316
74729
|
} else {
|
|
74317
|
-
this.light.mask &=
|
|
74730
|
+
this.light.mask &= ~MASK_AFFECT_LIGHTMAPPED;
|
|
74318
74731
|
if (this.bake) this.light.mask |= MASK_BAKE;
|
|
74319
74732
|
}
|
|
74320
74733
|
});
|
|
@@ -74326,9 +74739,9 @@ class LightComponent extends Component {
|
|
|
74326
74739
|
this._setValue('bake', arg, function(newValue, oldValue) {
|
|
74327
74740
|
if (newValue) {
|
|
74328
74741
|
this.light.mask |= MASK_BAKE;
|
|
74329
|
-
if (this.affectLightmapped) this.light.mask &=
|
|
74742
|
+
if (this.affectLightmapped) this.light.mask &= ~MASK_AFFECT_LIGHTMAPPED;
|
|
74330
74743
|
} else {
|
|
74331
|
-
this.light.mask &=
|
|
74744
|
+
this.light.mask &= ~MASK_BAKE;
|
|
74332
74745
|
if (this.affectLightmapped) this.light.mask |= MASK_AFFECT_LIGHTMAPPED;
|
|
74333
74746
|
}
|
|
74334
74747
|
this.light.layersDirty();
|
|
@@ -75826,40 +76239,19 @@ class GSplatIntervalTexture {
|
|
|
75826
76239
|
addressV: ADDRESS_CLAMP_TO_EDGE
|
|
75827
76240
|
});
|
|
75828
76241
|
}
|
|
75829
|
-
update(intervals) {
|
|
75830
|
-
if (!intervals || intervals.length === 0) {
|
|
75831
|
-
return 0;
|
|
75832
|
-
}
|
|
75833
|
-
let totalSplats = 0;
|
|
75834
|
-
for(let i = 0; i < intervals.length; i += 2){
|
|
75835
|
-
const start = intervals[i];
|
|
75836
|
-
const end = intervals[i + 1];
|
|
75837
|
-
totalSplats += end - start;
|
|
75838
|
-
}
|
|
76242
|
+
update(intervals, totalIntervalSplats) {
|
|
75839
76243
|
const maxTextureSize = this.device.maxTextureSize;
|
|
75840
|
-
let textureWidth = Math.ceil(Math.sqrt(
|
|
76244
|
+
let textureWidth = Math.ceil(Math.sqrt(totalIntervalSplats));
|
|
75841
76245
|
textureWidth = Math.min(textureWidth, maxTextureSize);
|
|
75842
|
-
const textureHeight = Math.ceil(
|
|
75843
|
-
|
|
75844
|
-
|
|
75845
|
-
|
|
75846
|
-
|
|
75847
|
-
|
|
75848
|
-
colorBuffer: this.texture,
|
|
75849
|
-
depth: false
|
|
75850
|
-
});
|
|
75851
|
-
}
|
|
75852
|
-
if (this.rt.width !== textureWidth || this.rt.height !== textureHeight) {
|
|
75853
|
-
this.rt.resize(textureWidth, textureHeight);
|
|
75854
|
-
}
|
|
76246
|
+
const textureHeight = Math.ceil(totalIntervalSplats / textureWidth);
|
|
76247
|
+
this.texture = this.createTexture('intervalsTexture', PIXELFORMAT_R32U, textureWidth, textureHeight);
|
|
76248
|
+
this.rt = new RenderTarget({
|
|
76249
|
+
colorBuffer: this.texture,
|
|
76250
|
+
depth: false
|
|
76251
|
+
});
|
|
75855
76252
|
const numIntervals = intervals.length / 2;
|
|
75856
76253
|
const dataTextureSize = Math.ceil(Math.sqrt(numIntervals));
|
|
75857
|
-
|
|
75858
|
-
this.intervalsDataTexture = this.createTexture('intervalsData', PIXELFORMAT_RG32U, dataTextureSize, dataTextureSize);
|
|
75859
|
-
}
|
|
75860
|
-
if (this.intervalsDataTexture.width !== dataTextureSize) {
|
|
75861
|
-
this.intervalsDataTexture.resize(dataTextureSize, dataTextureSize);
|
|
75862
|
-
}
|
|
76254
|
+
this.intervalsDataTexture = this.createTexture('intervalsData', PIXELFORMAT_RG32U, dataTextureSize, dataTextureSize);
|
|
75863
76255
|
const intervalsData = this.intervalsDataTexture.lock();
|
|
75864
76256
|
let runningSum = 0;
|
|
75865
76257
|
for(let i = 0; i < numIntervals; i++){
|
|
@@ -75875,15 +76267,16 @@ class GSplatIntervalTexture {
|
|
|
75875
76267
|
scope.resolve('uIntervalsTexture').setValue(this.intervalsDataTexture);
|
|
75876
76268
|
scope.resolve('uNumIntervals').setValue(numIntervals);
|
|
75877
76269
|
scope.resolve('uTextureWidth').setValue(textureWidth);
|
|
75878
|
-
scope.resolve('uActiveSplats').setValue(
|
|
76270
|
+
scope.resolve('uActiveSplats').setValue(totalIntervalSplats);
|
|
75879
76271
|
this.device.setCullMode(CULLFACE_NONE);
|
|
75880
76272
|
this.device.setBlendState(BlendState.NOBLEND);
|
|
75881
76273
|
this.device.setDepthState(DepthState.NODEPTH);
|
|
75882
76274
|
drawQuadWithShader(this.device, this.rt, this.getShader());
|
|
75883
|
-
return
|
|
76275
|
+
return totalIntervalSplats;
|
|
75884
76276
|
}
|
|
75885
76277
|
}
|
|
75886
76278
|
|
|
76279
|
+
const vecs = [];
|
|
75887
76280
|
class GSplatInfo {
|
|
75888
76281
|
constructor(device, resource, placement){
|
|
75889
76282
|
this.activeSplats = 0;
|
|
@@ -75894,18 +76287,18 @@ class GSplatInfo {
|
|
|
75894
76287
|
this.viewport = new Vec4();
|
|
75895
76288
|
this.previousWorldTransform = new Mat4();
|
|
75896
76289
|
this.aabb = new BoundingBox();
|
|
76290
|
+
this.intervalTexture = null;
|
|
75897
76291
|
this.device = device;
|
|
75898
76292
|
this.resource = resource;
|
|
75899
76293
|
this.node = placement.node;
|
|
75900
76294
|
this.lodIndex = placement.lodIndex;
|
|
75901
|
-
this.numSplats = resource.
|
|
76295
|
+
this.numSplats = resource.numSplats;
|
|
75902
76296
|
this.aabb.copy(placement.aabb);
|
|
75903
|
-
this.intervalTexture = new GSplatIntervalTexture(device);
|
|
75904
76297
|
this.updateIntervals(placement.intervals);
|
|
75905
76298
|
}
|
|
75906
76299
|
destroy() {
|
|
75907
76300
|
this.intervals.length = 0;
|
|
75908
|
-
this.intervalTexture
|
|
76301
|
+
this.intervalTexture?.destroy();
|
|
75909
76302
|
}
|
|
75910
76303
|
setLines(start, count, textureSize, activeSplats) {
|
|
75911
76304
|
this.lineStart = start;
|
|
@@ -75918,10 +76311,37 @@ class GSplatInfo {
|
|
|
75918
76311
|
this.intervals.length = 0;
|
|
75919
76312
|
this.activeSplats = resource.numSplats;
|
|
75920
76313
|
if (intervals.size > 0) {
|
|
76314
|
+
let totalCount = 0;
|
|
76315
|
+
let used = 0;
|
|
75921
76316
|
for (const interval of intervals.values()){
|
|
75922
|
-
|
|
76317
|
+
totalCount += interval.y - interval.x + 1;
|
|
76318
|
+
vecs[used++] = interval;
|
|
76319
|
+
}
|
|
76320
|
+
if (totalCount !== this.numSplats) {
|
|
76321
|
+
vecs.length = used;
|
|
76322
|
+
vecs.sort((a, b)=>a.x - b.x);
|
|
76323
|
+
this.intervals.length = used * 2;
|
|
76324
|
+
let k = 0;
|
|
76325
|
+
let currentStart = vecs[0].x;
|
|
76326
|
+
let currentEnd = vecs[0].y;
|
|
76327
|
+
for(let i = 1; i < used; i++){
|
|
76328
|
+
const p = vecs[i];
|
|
76329
|
+
if (p.x === currentEnd + 1) {
|
|
76330
|
+
currentEnd = p.y;
|
|
76331
|
+
} else {
|
|
76332
|
+
this.intervals[k++] = currentStart;
|
|
76333
|
+
this.intervals[k++] = currentEnd + 1;
|
|
76334
|
+
currentStart = p.x;
|
|
76335
|
+
currentEnd = p.y;
|
|
76336
|
+
}
|
|
76337
|
+
}
|
|
76338
|
+
this.intervals[k++] = currentStart;
|
|
76339
|
+
this.intervals[k++] = currentEnd + 1;
|
|
76340
|
+
this.intervals.length = k;
|
|
76341
|
+
this.intervalTexture = new GSplatIntervalTexture(this.device);
|
|
76342
|
+
this.activeSplats = this.intervalTexture.update(this.intervals, totalCount);
|
|
75923
76343
|
}
|
|
75924
|
-
|
|
76344
|
+
vecs.length = 0;
|
|
75925
76345
|
}
|
|
75926
76346
|
}
|
|
75927
76347
|
update() {
|
|
@@ -75940,18 +76360,69 @@ function UnifiedSortWorker() {
|
|
|
75940
76360
|
let centersData;
|
|
75941
76361
|
let distances;
|
|
75942
76362
|
let countBuffer;
|
|
75943
|
-
|
|
76363
|
+
let _radialSort = false;
|
|
76364
|
+
const numBins = 32;
|
|
76365
|
+
const binBase = new Array(numBins).fill(0);
|
|
76366
|
+
const binDivider = new Array(numBins).fill(0);
|
|
76367
|
+
const weightTiers = [
|
|
76368
|
+
{
|
|
76369
|
+
maxDistance: 0,
|
|
76370
|
+
weight: 40.0
|
|
76371
|
+
},
|
|
76372
|
+
{
|
|
76373
|
+
maxDistance: 2,
|
|
76374
|
+
weight: 20.0
|
|
76375
|
+
},
|
|
76376
|
+
{
|
|
76377
|
+
maxDistance: 5,
|
|
76378
|
+
weight: 8.0
|
|
76379
|
+
},
|
|
76380
|
+
{
|
|
76381
|
+
maxDistance: 10,
|
|
76382
|
+
weight: 3.0
|
|
76383
|
+
},
|
|
76384
|
+
{
|
|
76385
|
+
maxDistance: Infinity,
|
|
76386
|
+
weight: 1.0
|
|
76387
|
+
}
|
|
76388
|
+
];
|
|
76389
|
+
const weightByDistance = new Array(numBins);
|
|
76390
|
+
for(let dist = 0; dist < numBins; ++dist){
|
|
76391
|
+
let weight = 1.0;
|
|
76392
|
+
for(let j = 0; j < weightTiers.length; ++j){
|
|
76393
|
+
if (dist <= weightTiers[j].maxDistance) {
|
|
76394
|
+
weight = weightTiers[j].weight;
|
|
76395
|
+
break;
|
|
76396
|
+
}
|
|
76397
|
+
}
|
|
76398
|
+
weightByDistance[dist] = weight;
|
|
76399
|
+
}
|
|
76400
|
+
const setupCameraRelativeBins = (cameraBin, bucketCount)=>{
|
|
76401
|
+
const totalBudget = bucketCount;
|
|
76402
|
+
const bitsPerBin = [];
|
|
76403
|
+
for(let i = 0; i < numBins; ++i){
|
|
76404
|
+
const distFromCamera = Math.abs(i - cameraBin);
|
|
76405
|
+
bitsPerBin[i] = weightByDistance[distFromCamera];
|
|
76406
|
+
}
|
|
76407
|
+
const totalWeight = bitsPerBin.reduce((a, b)=>a + b, 0);
|
|
76408
|
+
let accumulated = 0;
|
|
76409
|
+
for(let i = 0; i < numBins; ++i){
|
|
76410
|
+
binDivider[i] = Math.max(1, Math.floor(bitsPerBin[i] / totalWeight * totalBudget));
|
|
76411
|
+
binBase[i] = accumulated;
|
|
76412
|
+
accumulated += binDivider[i];
|
|
76413
|
+
}
|
|
76414
|
+
if (accumulated > bucketCount) {
|
|
76415
|
+
const excess = accumulated - bucketCount;
|
|
76416
|
+
binDivider[numBins - 1] = Math.max(1, binDivider[numBins - 1] - excess);
|
|
76417
|
+
}
|
|
76418
|
+
binBase[numBins] = binBase[numBins - 1] + binDivider[numBins - 1];
|
|
76419
|
+
binDivider[numBins] = 0;
|
|
76420
|
+
};
|
|
76421
|
+
const evaluateSortKeysCommon = (sortParams, minDist, range, distances, countBuffer, centersData, processSplatFn)=>{
|
|
75944
76422
|
const { ids, lineStarts, padding, intervals, textureSize } = centersData;
|
|
76423
|
+
const invBinRange = numBins / range;
|
|
75945
76424
|
for(let paramIdx = 0; paramIdx < sortParams.length; paramIdx++){
|
|
75946
76425
|
const params = sortParams[paramIdx];
|
|
75947
|
-
const { transformedDirection, offset, scale } = params;
|
|
75948
|
-
const dx = transformedDirection.x;
|
|
75949
|
-
const dy = transformedDirection.y;
|
|
75950
|
-
const dz = transformedDirection.z;
|
|
75951
|
-
const sdx = dx * scale * divider;
|
|
75952
|
-
const sdy = dy * scale * divider;
|
|
75953
|
-
const sdz = dz * scale * divider;
|
|
75954
|
-
const add = (offset - minDist) * divider;
|
|
75955
76426
|
const id = ids[paramIdx];
|
|
75956
76427
|
const centers = centersMap.get(id);
|
|
75957
76428
|
if (!centers) {
|
|
@@ -75965,14 +76436,7 @@ function UnifiedSortWorker() {
|
|
|
75965
76436
|
for(let i = 0; i < intervalsArray.length; i += 2){
|
|
75966
76437
|
const intervalStart = intervalsArray[i] * 3;
|
|
75967
76438
|
const intervalEnd = intervalsArray[i + 1] * 3;
|
|
75968
|
-
|
|
75969
|
-
const x = centers[srcIndex];
|
|
75970
|
-
const y = centers[srcIndex + 1];
|
|
75971
|
-
const z = centers[srcIndex + 2];
|
|
75972
|
-
const sortKey = Math.floor(x * sdx + y * sdy + z * sdz + add);
|
|
75973
|
-
distances[targetIndex++] = sortKey;
|
|
75974
|
-
countBuffer[sortKey]++;
|
|
75975
|
-
}
|
|
76439
|
+
targetIndex = processSplatFn(centers, params, intervalStart, intervalEnd, targetIndex, invBinRange, minDist, range, distances, countBuffer);
|
|
75976
76440
|
}
|
|
75977
76441
|
const pad = padding[paramIdx];
|
|
75978
76442
|
countBuffer[0] += pad;
|
|
@@ -75980,6 +76444,52 @@ function UnifiedSortWorker() {
|
|
|
75980
76444
|
targetIndex += pad;
|
|
75981
76445
|
}
|
|
75982
76446
|
};
|
|
76447
|
+
const evaluateSortKeysLinear = (sortParams, minDist, range, distances, countBuffer, centersData)=>{
|
|
76448
|
+
evaluateSortKeysCommon(sortParams, minDist, range, distances, countBuffer, centersData, (centers, params, intervalStart, intervalEnd, targetIndex, invBinRange, minDist, range, distances, countBuffer)=>{
|
|
76449
|
+
const { transformedDirection, offset, scale } = params;
|
|
76450
|
+
const dx = transformedDirection.x;
|
|
76451
|
+
const dy = transformedDirection.y;
|
|
76452
|
+
const dz = transformedDirection.z;
|
|
76453
|
+
const sdx = dx * scale;
|
|
76454
|
+
const sdy = dy * scale;
|
|
76455
|
+
const sdz = dz * scale;
|
|
76456
|
+
const add = offset - minDist;
|
|
76457
|
+
for(let srcIndex = intervalStart; srcIndex < intervalEnd; srcIndex += 3){
|
|
76458
|
+
const x = centers[srcIndex];
|
|
76459
|
+
const y = centers[srcIndex + 1];
|
|
76460
|
+
const z = centers[srcIndex + 2];
|
|
76461
|
+
const dist = x * sdx + y * sdy + z * sdz + add;
|
|
76462
|
+
const d = dist * invBinRange;
|
|
76463
|
+
const bin = d >>> 0;
|
|
76464
|
+
const sortKey = binBase[bin] + binDivider[bin] * (d - bin) >>> 0;
|
|
76465
|
+
distances[targetIndex++] = sortKey;
|
|
76466
|
+
countBuffer[sortKey]++;
|
|
76467
|
+
}
|
|
76468
|
+
return targetIndex;
|
|
76469
|
+
});
|
|
76470
|
+
};
|
|
76471
|
+
const evaluateSortKeysRadial = (sortParams, minDist, range, distances, countBuffer, centersData)=>{
|
|
76472
|
+
evaluateSortKeysCommon(sortParams, minDist, range, distances, countBuffer, centersData, (centers, params, intervalStart, intervalEnd, targetIndex, invBinRange, minDist, range, distances, countBuffer)=>{
|
|
76473
|
+
const { transformedPosition, scale } = params;
|
|
76474
|
+
const cx = transformedPosition.x;
|
|
76475
|
+
const cy = transformedPosition.y;
|
|
76476
|
+
const cz = transformedPosition.z;
|
|
76477
|
+
for(let srcIndex = intervalStart; srcIndex < intervalEnd; srcIndex += 3){
|
|
76478
|
+
const dx = centers[srcIndex] - cx;
|
|
76479
|
+
const dy = centers[srcIndex + 1] - cy;
|
|
76480
|
+
const dz = centers[srcIndex + 2] - cz;
|
|
76481
|
+
const distSq = dx * dx + dy * dy + dz * dz;
|
|
76482
|
+
const dist = Math.sqrt(distSq) * scale;
|
|
76483
|
+
const invertedDist = range - dist;
|
|
76484
|
+
const d = invertedDist * invBinRange;
|
|
76485
|
+
const bin = d >>> 0;
|
|
76486
|
+
const sortKey = binBase[bin] + binDivider[bin] * (d - bin) >>> 0;
|
|
76487
|
+
distances[targetIndex++] = sortKey;
|
|
76488
|
+
countBuffer[sortKey]++;
|
|
76489
|
+
}
|
|
76490
|
+
return targetIndex;
|
|
76491
|
+
});
|
|
76492
|
+
};
|
|
75983
76493
|
const countingSort = (bucketCount, countBuffer, numVertices, distances, order)=>{
|
|
75984
76494
|
for(let i = 1; i < bucketCount; i++){
|
|
75985
76495
|
countBuffer[i] += countBuffer[i - 1];
|
|
@@ -75990,7 +76500,7 @@ function UnifiedSortWorker() {
|
|
|
75990
76500
|
order[destIndex] = i;
|
|
75991
76501
|
}
|
|
75992
76502
|
};
|
|
75993
|
-
const
|
|
76503
|
+
const computeEffectiveDistanceRangeLinear = (sortParams)=>{
|
|
75994
76504
|
let minDist = Infinity;
|
|
75995
76505
|
let maxDist = -Infinity;
|
|
75996
76506
|
for(let paramIdx = 0; paramIdx < sortParams.length; paramIdx++){
|
|
@@ -76023,8 +76533,37 @@ function UnifiedSortWorker() {
|
|
|
76023
76533
|
maxDist
|
|
76024
76534
|
};
|
|
76025
76535
|
};
|
|
76536
|
+
const computeEffectiveDistanceRangeRadial = (sortParams)=>{
|
|
76537
|
+
let maxDist = -Infinity;
|
|
76538
|
+
for(let paramIdx = 0; paramIdx < sortParams.length; paramIdx++){
|
|
76539
|
+
const params = sortParams[paramIdx];
|
|
76540
|
+
const { transformedPosition, scale, aabbMin, aabbMax } = params;
|
|
76541
|
+
const cx = transformedPosition.x;
|
|
76542
|
+
const cy = transformedPosition.y;
|
|
76543
|
+
const cz = transformedPosition.z;
|
|
76544
|
+
for(let i = 0; i < 8; i++){
|
|
76545
|
+
const px = i & 1 ? aabbMax[0] : aabbMin[0];
|
|
76546
|
+
const py = i & 2 ? aabbMax[1] : aabbMin[1];
|
|
76547
|
+
const pz = i & 4 ? aabbMax[2] : aabbMin[2];
|
|
76548
|
+
const dx = px - cx;
|
|
76549
|
+
const dy = py - cy;
|
|
76550
|
+
const dz = pz - cz;
|
|
76551
|
+
const distSq = dx * dx + dy * dy + dz * dz;
|
|
76552
|
+
const dist = Math.sqrt(distSq) * scale;
|
|
76553
|
+
if (dist > maxDist) maxDist = dist;
|
|
76554
|
+
}
|
|
76555
|
+
}
|
|
76556
|
+
const minDist = 0;
|
|
76557
|
+
if (maxDist < 0) {
|
|
76558
|
+
maxDist = 0;
|
|
76559
|
+
}
|
|
76560
|
+
return {
|
|
76561
|
+
minDist,
|
|
76562
|
+
maxDist
|
|
76563
|
+
};
|
|
76564
|
+
};
|
|
76026
76565
|
const sort = (sortParams, order, centersData)=>{
|
|
76027
|
-
const { minDist, maxDist } =
|
|
76566
|
+
const { minDist, maxDist } = _radialSort ? computeEffectiveDistanceRangeRadial(sortParams) : computeEffectiveDistanceRangeLinear(sortParams);
|
|
76028
76567
|
const numVertices = centersData.totalUsedPixels;
|
|
76029
76568
|
const compareBits = Math.max(10, Math.min(20, Math.round(Math.log2(numVertices / 4))));
|
|
76030
76569
|
const bucketCount = 2 ** compareBits + 1;
|
|
@@ -76037,8 +76576,20 @@ function UnifiedSortWorker() {
|
|
|
76037
76576
|
countBuffer.fill(0);
|
|
76038
76577
|
}
|
|
76039
76578
|
const range = maxDist - minDist;
|
|
76040
|
-
|
|
76041
|
-
|
|
76579
|
+
let cameraBin;
|
|
76580
|
+
if (_radialSort) {
|
|
76581
|
+
cameraBin = numBins - 1;
|
|
76582
|
+
} else {
|
|
76583
|
+
const cameraOffsetFromRangeStart = 0 - minDist;
|
|
76584
|
+
const cameraBinFloat = cameraOffsetFromRangeStart / range * numBins;
|
|
76585
|
+
cameraBin = Math.max(0, Math.min(numBins - 1, Math.floor(cameraBinFloat)));
|
|
76586
|
+
}
|
|
76587
|
+
setupCameraRelativeBins(cameraBin, bucketCount);
|
|
76588
|
+
if (_radialSort) {
|
|
76589
|
+
evaluateSortKeysRadial(sortParams, minDist, range, distances, countBuffer, centersData);
|
|
76590
|
+
} else {
|
|
76591
|
+
evaluateSortKeysLinear(sortParams, minDist, range, distances, countBuffer, centersData);
|
|
76592
|
+
}
|
|
76042
76593
|
countingSort(bucketCount, countBuffer, numVertices, distances, order);
|
|
76043
76594
|
const count = numVertices;
|
|
76044
76595
|
const transferList = [
|
|
@@ -76066,6 +76617,7 @@ function UnifiedSortWorker() {
|
|
|
76066
76617
|
}
|
|
76067
76618
|
case 'sort':
|
|
76068
76619
|
{
|
|
76620
|
+
_radialSort = msgData.radialSorting || false;
|
|
76069
76621
|
const order = new Uint32Array(msgData.order);
|
|
76070
76622
|
sort(msgData.sortParams, order, centersData);
|
|
76071
76623
|
break;
|
|
@@ -76081,7 +76633,7 @@ function UnifiedSortWorker() {
|
|
|
76081
76633
|
|
|
76082
76634
|
class GSplatUnifiedSorter extends EventHandler {
|
|
76083
76635
|
constructor(){
|
|
76084
|
-
super(), this.bufferLength = 0, this.availableOrderData = [], this.jobsInFlight = 0, this.hasNewVersion = false, this.centersSet = new Set();
|
|
76636
|
+
super(), this.bufferLength = 0, this.availableOrderData = [], this.jobsInFlight = 0, this.hasNewVersion = false, this.centersSet = new Set(), this._destroyed = false;
|
|
76085
76637
|
const workerSource = `(${UnifiedSortWorker.toString()})()`;
|
|
76086
76638
|
if (platform.environment === 'node') {
|
|
76087
76639
|
this.worker = new Worker(workerSource, {
|
|
@@ -76098,6 +76650,9 @@ class GSplatUnifiedSorter extends EventHandler {
|
|
|
76098
76650
|
}
|
|
76099
76651
|
}
|
|
76100
76652
|
onSorted(message) {
|
|
76653
|
+
if (this._destroyed) {
|
|
76654
|
+
return;
|
|
76655
|
+
}
|
|
76101
76656
|
const msgData = message.data ?? message;
|
|
76102
76657
|
const orderData = new Uint32Array(msgData.order);
|
|
76103
76658
|
this.jobsInFlight--;
|
|
@@ -76107,6 +76662,7 @@ class GSplatUnifiedSorter extends EventHandler {
|
|
|
76107
76662
|
}
|
|
76108
76663
|
}
|
|
76109
76664
|
destroy() {
|
|
76665
|
+
this._destroyed = true;
|
|
76110
76666
|
this.worker.terminate();
|
|
76111
76667
|
this.worker = null;
|
|
76112
76668
|
}
|
|
@@ -76143,7 +76699,7 @@ class GSplatUnifiedSorter extends EventHandler {
|
|
|
76143
76699
|
}
|
|
76144
76700
|
this.worker.postMessage(payload);
|
|
76145
76701
|
}
|
|
76146
|
-
setSortParams(params) {
|
|
76702
|
+
setSortParams(params, radialSorting) {
|
|
76147
76703
|
if (this.hasNewVersion || this.jobsInFlight === 0) {
|
|
76148
76704
|
let orderData = this.availableOrderData.pop();
|
|
76149
76705
|
if (!orderData) {
|
|
@@ -76154,6 +76710,7 @@ class GSplatUnifiedSorter extends EventHandler {
|
|
|
76154
76710
|
this.worker.postMessage({
|
|
76155
76711
|
command: 'sort',
|
|
76156
76712
|
sortParams: params,
|
|
76713
|
+
radialSorting: radialSorting,
|
|
76157
76714
|
order: orderData.buffer
|
|
76158
76715
|
}, [
|
|
76159
76716
|
orderData.buffer
|
|
@@ -76163,15 +76720,20 @@ class GSplatUnifiedSorter extends EventHandler {
|
|
|
76163
76720
|
}
|
|
76164
76721
|
|
|
76165
76722
|
const _viewMat = new Mat4();
|
|
76166
|
-
const
|
|
76723
|
+
const _whiteColor = [
|
|
76724
|
+
1,
|
|
76725
|
+
1,
|
|
76726
|
+
1
|
|
76727
|
+
];
|
|
76167
76728
|
class GSplatWorkBufferRenderPass extends RenderPass {
|
|
76168
76729
|
init(renderTarget) {
|
|
76169
76730
|
super.init(renderTarget);
|
|
76170
76731
|
this.colorOps.clear = false;
|
|
76171
76732
|
this.depthStencilOps.clearDepth = false;
|
|
76172
76733
|
}
|
|
76173
|
-
update(splats, cameraNode) {
|
|
76734
|
+
update(splats, cameraNode, colorsByLod) {
|
|
76174
76735
|
this.splats.length = 0;
|
|
76736
|
+
this.colorsByLod = colorsByLod;
|
|
76175
76737
|
for(let i = 0; i < splats.length; i++){
|
|
76176
76738
|
const splatInfo = splats[i];
|
|
76177
76739
|
if (splatInfo.activeSplats > 0) {
|
|
@@ -76198,15 +76760,17 @@ class GSplatWorkBufferRenderPass extends RenderPass {
|
|
|
76198
76760
|
const { device, resource } = splatInfo;
|
|
76199
76761
|
const scope = device.scope;
|
|
76200
76762
|
const { intervals, activeSplats, lineStart, viewport, intervalTexture } = splatInfo;
|
|
76201
|
-
const workBufferRenderInfo = resource.getWorkBufferRenderInfo(intervals.length > 0
|
|
76763
|
+
const workBufferRenderInfo = resource.getWorkBufferRenderInfo(intervals.length > 0);
|
|
76202
76764
|
workBufferRenderInfo.material.setParameters(device);
|
|
76203
76765
|
scope.resolve('uTransform').setValue(splatInfo.node.getWorldTransform().data);
|
|
76204
|
-
if (intervalTexture
|
|
76766
|
+
if (intervalTexture) {
|
|
76205
76767
|
scope.resolve('uIntervalsTexture').setValue(intervalTexture.texture);
|
|
76206
76768
|
}
|
|
76207
76769
|
scope.resolve('uActiveSplats').setValue(activeSplats);
|
|
76208
76770
|
scope.resolve('uStartLine').setValue(lineStart);
|
|
76209
76771
|
scope.resolve('uViewportWidth').setValue(viewport.z);
|
|
76772
|
+
const color = this.colorsByLod?.[splatInfo.lodIndex] ?? _whiteColor;
|
|
76773
|
+
scope.resolve('uColorMultiply').setValue(color);
|
|
76210
76774
|
scope.resolve('matrix_model').setValue(splatInfo.node.getWorldTransform().data);
|
|
76211
76775
|
workBufferRenderInfo.quadRender.render(viewport);
|
|
76212
76776
|
}
|
|
@@ -76215,7 +76779,7 @@ class GSplatWorkBufferRenderPass extends RenderPass {
|
|
|
76215
76779
|
super.destroy();
|
|
76216
76780
|
}
|
|
76217
76781
|
constructor(...args){
|
|
76218
|
-
super(...args), this.splats = [];
|
|
76782
|
+
super(...args), this.splats = [], this.colorsByLod = undefined, this.cameraNode = null;
|
|
76219
76783
|
}
|
|
76220
76784
|
}
|
|
76221
76785
|
|
|
@@ -76279,8 +76843,8 @@ class GSplatWorkBuffer {
|
|
|
76279
76843
|
this.renderTarget.resize(textureSize, textureSize);
|
|
76280
76844
|
this.orderTexture.resize(textureSize, textureSize);
|
|
76281
76845
|
}
|
|
76282
|
-
render(splats, cameraNode) {
|
|
76283
|
-
if (this.renderPass.update(splats, cameraNode)) {
|
|
76846
|
+
render(splats, cameraNode, colorsByLod) {
|
|
76847
|
+
if (this.renderPass.update(splats, cameraNode, colorsByLod)) {
|
|
76284
76848
|
this.renderPass.render();
|
|
76285
76849
|
}
|
|
76286
76850
|
}
|
|
@@ -76288,8 +76852,8 @@ class GSplatWorkBuffer {
|
|
|
76288
76852
|
|
|
76289
76853
|
class GSplatRenderer {
|
|
76290
76854
|
constructor(device, node, cameraNode, layer, workBuffer){
|
|
76291
|
-
this.maxNumSplats = 0;
|
|
76292
76855
|
this.instanceIndices = null;
|
|
76856
|
+
this.instanceIndicesCount = 0;
|
|
76293
76857
|
this.viewportParams = [
|
|
76294
76858
|
0,
|
|
76295
76859
|
0
|
|
@@ -76342,8 +76906,9 @@ class GSplatRenderer {
|
|
|
76342
76906
|
this.meshInstance.visible = count > 0;
|
|
76343
76907
|
}
|
|
76344
76908
|
setMaxNumSplats(numSplats) {
|
|
76345
|
-
|
|
76346
|
-
|
|
76909
|
+
const roundedNumSplats = math.roundUp(numSplats, GSplatResourceBase.instanceSize);
|
|
76910
|
+
if (this.instanceIndicesCount < roundedNumSplats) {
|
|
76911
|
+
this.instanceIndicesCount = roundedNumSplats;
|
|
76347
76912
|
this.instanceIndices?.destroy();
|
|
76348
76913
|
this.instanceIndices = GSplatResourceBase.createInstanceIndices(this.device, numSplats);
|
|
76349
76914
|
this.meshInstance.setInstancing(this.instanceIndices, true);
|
|
@@ -76384,6 +76949,7 @@ class GSplatPlacement {
|
|
|
76384
76949
|
constructor(resource, node, lodIndex = 0){
|
|
76385
76950
|
this.intervals = new Map();
|
|
76386
76951
|
this.lodIndex = 0;
|
|
76952
|
+
this._lodDistances = null;
|
|
76387
76953
|
this._aabb = new BoundingBox();
|
|
76388
76954
|
this.resource = resource;
|
|
76389
76955
|
this.node = node;
|
|
@@ -76395,18 +76961,46 @@ class GSplatPlacement {
|
|
|
76395
76961
|
get aabb() {
|
|
76396
76962
|
return this._aabb;
|
|
76397
76963
|
}
|
|
76964
|
+
set lodDistances(distances) {
|
|
76965
|
+
const isOctree = !!(this.resource && this.resource.octree);
|
|
76966
|
+
if (isOctree) {
|
|
76967
|
+
if (distances) {
|
|
76968
|
+
this.resource.octree?.lodLevels ?? 1;
|
|
76969
|
+
this._lodDistances = distances.slice();
|
|
76970
|
+
} else {
|
|
76971
|
+
this._lodDistances = null;
|
|
76972
|
+
}
|
|
76973
|
+
}
|
|
76974
|
+
}
|
|
76975
|
+
get lodDistances() {
|
|
76976
|
+
return this._lodDistances ? this._lodDistances.slice() : null;
|
|
76977
|
+
}
|
|
76398
76978
|
}
|
|
76399
76979
|
|
|
76400
76980
|
const _invWorldMat = new Mat4();
|
|
76401
76981
|
const _localCameraPos = new Vec3();
|
|
76982
|
+
const _localCameraFwd = new Vec3();
|
|
76983
|
+
const _dirToNode = new Vec3();
|
|
76402
76984
|
const _tempCompletedUrls = [];
|
|
76985
|
+
new BoundingBox();
|
|
76986
|
+
[
|
|
76987
|
+
new Color(1, 0, 0),
|
|
76988
|
+
new Color(0, 1, 0),
|
|
76989
|
+
new Color(0, 0, 1),
|
|
76990
|
+
new Color(1, 1, 0),
|
|
76991
|
+
new Color(1, 0, 1)
|
|
76992
|
+
];
|
|
76403
76993
|
class GSplatOctreeInstance {
|
|
76404
76994
|
constructor(octree, placement, assetLoader){
|
|
76405
76995
|
this.activePlacements = new Set();
|
|
76406
76996
|
this.dirtyModifiedPlacements = false;
|
|
76407
76997
|
this.pending = new Set();
|
|
76408
76998
|
this.pendingDecrements = new Map();
|
|
76999
|
+
this.removedCandidates = new Set();
|
|
76409
77000
|
this.previousPosition = new Vec3();
|
|
77001
|
+
this.needsLodUpdate = false;
|
|
77002
|
+
this.prefetchPending = new Set();
|
|
77003
|
+
this.pendingVisibleAdds = new Map();
|
|
76410
77004
|
this.octree = octree;
|
|
76411
77005
|
this.placement = placement;
|
|
76412
77006
|
this.assetLoader = assetLoader;
|
|
@@ -76420,16 +77014,27 @@ class GSplatOctreeInstance {
|
|
|
76420
77014
|
this.pendingDecrements.clear();
|
|
76421
77015
|
this.filePlacements.length = 0;
|
|
76422
77016
|
}
|
|
76423
|
-
|
|
77017
|
+
getFileDecrements() {
|
|
77018
|
+
const toRelease = [];
|
|
77019
|
+
for(let i = 0; i < this.filePlacements.length; i++){
|
|
77020
|
+
if (this.filePlacements[i]) {
|
|
77021
|
+
toRelease.push(i);
|
|
77022
|
+
}
|
|
77023
|
+
}
|
|
77024
|
+
return toRelease;
|
|
77025
|
+
}
|
|
77026
|
+
calculateNodeLod(localCameraPosition, localCameraForward, nodeIndex, maxLod, lodDistances, lodBehindPenalty) {
|
|
76424
77027
|
const node = this.octree.nodes[nodeIndex];
|
|
76425
|
-
|
|
76426
|
-
|
|
76427
|
-
|
|
76428
|
-
|
|
76429
|
-
|
|
76430
|
-
|
|
76431
|
-
|
|
76432
|
-
|
|
77028
|
+
_dirToNode.copy(node.bounds.center).sub(localCameraPosition);
|
|
77029
|
+
let distance = _dirToNode.length();
|
|
77030
|
+
if (lodBehindPenalty > 1 && distance > 0.01) {
|
|
77031
|
+
const dotOverDistance = localCameraForward.dot(_dirToNode) / distance;
|
|
77032
|
+
if (dotOverDistance < 0) {
|
|
77033
|
+
const t = -dotOverDistance;
|
|
77034
|
+
const factor = 1 + t * (lodBehindPenalty - 1);
|
|
77035
|
+
distance *= factor;
|
|
77036
|
+
}
|
|
77037
|
+
}
|
|
76433
77038
|
for(let lod = 0; lod < maxLod; lod++){
|
|
76434
77039
|
if (distance < lodDistances[lod]) {
|
|
76435
77040
|
return lod;
|
|
@@ -76437,44 +77042,137 @@ class GSplatOctreeInstance {
|
|
|
76437
77042
|
}
|
|
76438
77043
|
return maxLod;
|
|
76439
77044
|
}
|
|
76440
|
-
|
|
77045
|
+
selectDesiredLodIndex(node, optimalLodIndex, maxLod, lodUnderfillLimit) {
|
|
77046
|
+
if (lodUnderfillLimit > 0) {
|
|
77047
|
+
const allowedMaxCoarseLod = Math.min(maxLod, optimalLodIndex + lodUnderfillLimit);
|
|
77048
|
+
for(let lod = optimalLodIndex; lod <= allowedMaxCoarseLod; lod++){
|
|
77049
|
+
const fi = node.lods[lod].fileIndex;
|
|
77050
|
+
if (fi !== -1 && this.octree.getFileResource(fi)) {
|
|
77051
|
+
return lod;
|
|
77052
|
+
}
|
|
77053
|
+
}
|
|
77054
|
+
for(let lod = allowedMaxCoarseLod; lod >= optimalLodIndex; lod--){
|
|
77055
|
+
const fi = node.lods[lod].fileIndex;
|
|
77056
|
+
if (fi !== -1) {
|
|
77057
|
+
return lod;
|
|
77058
|
+
}
|
|
77059
|
+
}
|
|
77060
|
+
}
|
|
77061
|
+
return optimalLodIndex;
|
|
77062
|
+
}
|
|
77063
|
+
prefetchNextLod(node, desiredLodIndex, optimalLodIndex) {
|
|
77064
|
+
if (desiredLodIndex === -1 || optimalLodIndex === -1) return;
|
|
77065
|
+
if (desiredLodIndex === optimalLodIndex) {
|
|
77066
|
+
const fi = node.lods[optimalLodIndex].fileIndex;
|
|
77067
|
+
if (fi !== -1) {
|
|
77068
|
+
this.octree.ensureFileResource(fi, this.assetLoader);
|
|
77069
|
+
if (!this.octree.getFileResource(fi)) {
|
|
77070
|
+
this.prefetchPending.add(fi);
|
|
77071
|
+
}
|
|
77072
|
+
}
|
|
77073
|
+
return;
|
|
77074
|
+
}
|
|
77075
|
+
const targetLod = Math.max(optimalLodIndex, desiredLodIndex - 1);
|
|
77076
|
+
for(let lod = targetLod; lod >= optimalLodIndex; lod--){
|
|
77077
|
+
const fi = node.lods[lod].fileIndex;
|
|
77078
|
+
if (fi !== -1) {
|
|
77079
|
+
this.octree.ensureFileResource(fi, this.assetLoader);
|
|
77080
|
+
if (!this.octree.getFileResource(fi)) {
|
|
77081
|
+
this.prefetchPending.add(fi);
|
|
77082
|
+
}
|
|
77083
|
+
break;
|
|
77084
|
+
}
|
|
77085
|
+
}
|
|
77086
|
+
}
|
|
77087
|
+
updateLod(cameraNode, params) {
|
|
76441
77088
|
const worldCameraPosition = cameraNode.getPosition();
|
|
76442
77089
|
const octreeWorldTransform = this.placement.node.getWorldTransform();
|
|
76443
77090
|
_invWorldMat.copy(octreeWorldTransform).invert();
|
|
76444
77091
|
const localCameraPosition = _invWorldMat.transformPoint(worldCameraPosition, _localCameraPos);
|
|
77092
|
+
const worldCameraForward = cameraNode.forward;
|
|
77093
|
+
const localCameraForward = _invWorldMat.transformVector(worldCameraForward, _localCameraFwd).normalize();
|
|
76445
77094
|
const maxLod = this.octree.lodLevels - 1;
|
|
77095
|
+
const lodDistances = this.placement.lodDistances || [
|
|
77096
|
+
5,
|
|
77097
|
+
10,
|
|
77098
|
+
15,
|
|
77099
|
+
20,
|
|
77100
|
+
25
|
|
77101
|
+
];
|
|
77102
|
+
const { lodBehindPenalty, lodRangeMin, lodRangeMax, lodUnderfillLimit = 0 } = params;
|
|
77103
|
+
const rangeMin = Math.max(0, Math.min(lodRangeMin ?? 0, maxLod));
|
|
77104
|
+
const rangeMax = Math.max(rangeMin, Math.min(lodRangeMax ?? maxLod, maxLod));
|
|
76446
77105
|
const nodes = this.octree.nodes;
|
|
76447
77106
|
for(let nodeIndex = 0; nodeIndex < nodes.length; nodeIndex++){
|
|
76448
77107
|
const node = nodes[nodeIndex];
|
|
76449
|
-
|
|
77108
|
+
let optimalLodIndex = this.calculateNodeLod(localCameraPosition, localCameraForward, nodeIndex, maxLod, lodDistances, lodBehindPenalty);
|
|
77109
|
+
if (optimalLodIndex < rangeMin) optimalLodIndex = rangeMin;
|
|
77110
|
+
if (optimalLodIndex > rangeMax) optimalLodIndex = rangeMax;
|
|
76450
77111
|
const currentLodIndex = this.nodeLods[nodeIndex];
|
|
76451
|
-
|
|
76452
|
-
|
|
76453
|
-
|
|
76454
|
-
|
|
76455
|
-
|
|
76456
|
-
|
|
76457
|
-
this.
|
|
76458
|
-
|
|
76459
|
-
|
|
77112
|
+
const desiredLodIndex = this.selectDesiredLodIndex(node, optimalLodIndex, maxLod, lodUnderfillLimit);
|
|
77113
|
+
if (desiredLodIndex !== currentLodIndex) {
|
|
77114
|
+
const currentFileIndex = currentLodIndex >= 0 ? node.lods[currentLodIndex].fileIndex : -1;
|
|
77115
|
+
const desiredFileIndex = desiredLodIndex >= 0 ? node.lods[desiredLodIndex].fileIndex : -1;
|
|
77116
|
+
const wasVisible = currentFileIndex !== -1;
|
|
77117
|
+
const willBeVisible = desiredFileIndex !== -1;
|
|
77118
|
+
const pendingEntry = this.pendingDecrements.get(nodeIndex);
|
|
77119
|
+
if (pendingEntry) {
|
|
77120
|
+
if (pendingEntry.newFileIndex !== desiredFileIndex) {
|
|
77121
|
+
const prevPendingPlacement = this.filePlacements[pendingEntry.newFileIndex];
|
|
77122
|
+
if (prevPendingPlacement) {
|
|
77123
|
+
this.decrementFileRef(pendingEntry.newFileIndex, nodeIndex);
|
|
77124
|
+
}
|
|
77125
|
+
if (wasVisible && willBeVisible) {
|
|
77126
|
+
this.pendingDecrements.set(nodeIndex, {
|
|
77127
|
+
oldFileIndex: pendingEntry.oldFileIndex,
|
|
77128
|
+
newFileIndex: desiredFileIndex
|
|
77129
|
+
});
|
|
77130
|
+
} else {
|
|
77131
|
+
this.pendingDecrements.delete(nodeIndex);
|
|
77132
|
+
}
|
|
77133
|
+
}
|
|
77134
|
+
}
|
|
76460
77135
|
if (!wasVisible && willBeVisible) {
|
|
76461
|
-
const
|
|
76462
|
-
|
|
77136
|
+
const prevPendingFi = this.pendingVisibleAdds.get(nodeIndex);
|
|
77137
|
+
if (prevPendingFi !== undefined && prevPendingFi !== desiredFileIndex) {
|
|
77138
|
+
this.decrementFileRef(prevPendingFi, nodeIndex);
|
|
77139
|
+
this.pendingVisibleAdds.delete(nodeIndex);
|
|
77140
|
+
}
|
|
77141
|
+
this.incrementFileRef(desiredFileIndex, nodeIndex, desiredLodIndex);
|
|
77142
|
+
const newPlacement = this.filePlacements[desiredFileIndex];
|
|
77143
|
+
if (newPlacement?.resource) {
|
|
77144
|
+
this.nodeLods[nodeIndex] = desiredLodIndex;
|
|
77145
|
+
this.pendingVisibleAdds.delete(nodeIndex);
|
|
77146
|
+
} else {
|
|
77147
|
+
this.pendingVisibleAdds.set(nodeIndex, desiredFileIndex);
|
|
77148
|
+
}
|
|
76463
77149
|
} else if (wasVisible && !willBeVisible) {
|
|
76464
|
-
const
|
|
76465
|
-
|
|
77150
|
+
const pendingEntry2 = this.pendingDecrements.get(nodeIndex);
|
|
77151
|
+
if (pendingEntry2) {
|
|
77152
|
+
this.decrementFileRef(pendingEntry2.newFileIndex, nodeIndex);
|
|
77153
|
+
this.pendingDecrements.delete(nodeIndex);
|
|
77154
|
+
}
|
|
77155
|
+
this.decrementFileRef(currentFileIndex, nodeIndex);
|
|
77156
|
+
this.nodeLods[nodeIndex] = -1;
|
|
77157
|
+
this.pendingVisibleAdds.delete(nodeIndex);
|
|
76466
77158
|
} else if (wasVisible && willBeVisible) {
|
|
76467
|
-
|
|
76468
|
-
const
|
|
76469
|
-
this.incrementFileRef(newFileIndex, nodeIndex, newLodIndex);
|
|
76470
|
-
const newPlacement = this.filePlacements[newFileIndex];
|
|
77159
|
+
this.incrementFileRef(desiredFileIndex, nodeIndex, desiredLodIndex);
|
|
77160
|
+
const newPlacement = this.filePlacements[desiredFileIndex];
|
|
76471
77161
|
if (newPlacement?.resource) {
|
|
76472
|
-
this.decrementFileRef(
|
|
77162
|
+
this.decrementFileRef(currentFileIndex, nodeIndex);
|
|
77163
|
+
this.pendingDecrements.delete(nodeIndex);
|
|
77164
|
+
this.nodeLods[nodeIndex] = desiredLodIndex;
|
|
77165
|
+
this.pendingVisibleAdds.delete(nodeIndex);
|
|
76473
77166
|
} else {
|
|
76474
|
-
this.pendingDecrements.set(nodeIndex,
|
|
77167
|
+
this.pendingDecrements.set(nodeIndex, {
|
|
77168
|
+
oldFileIndex: currentFileIndex,
|
|
77169
|
+
newFileIndex: desiredFileIndex
|
|
77170
|
+
});
|
|
77171
|
+
this.pendingVisibleAdds.delete(nodeIndex);
|
|
76475
77172
|
}
|
|
76476
77173
|
}
|
|
76477
77174
|
}
|
|
77175
|
+
this.prefetchNextLod(node, desiredLodIndex, optimalLodIndex);
|
|
76478
77176
|
}
|
|
76479
77177
|
}
|
|
76480
77178
|
incrementFileRef(fileIndex, nodeIndex, lodIndex) {
|
|
@@ -76483,9 +77181,12 @@ class GSplatOctreeInstance {
|
|
|
76483
77181
|
if (!placement) {
|
|
76484
77182
|
placement = new GSplatPlacement(null, this.placement.node, lodIndex);
|
|
76485
77183
|
this.filePlacements[fileIndex] = placement;
|
|
77184
|
+
const removeScheduled = this.removedCandidates.delete(fileIndex);
|
|
77185
|
+
if (!removeScheduled) {
|
|
77186
|
+
this.octree.incRefCount(fileIndex);
|
|
77187
|
+
}
|
|
76486
77188
|
if (!this.addFilePlacement(fileIndex)) {
|
|
76487
|
-
|
|
76488
|
-
this.octree.ensureFileResource(fileUrl, this.assetLoader);
|
|
77189
|
+
this.octree.ensureFileResource(fileIndex, this.assetLoader);
|
|
76489
77190
|
this.pending.add(fileIndex);
|
|
76490
77191
|
}
|
|
76491
77192
|
}
|
|
@@ -76499,6 +77200,9 @@ class GSplatOctreeInstance {
|
|
|
76499
77200
|
decrementFileRef(fileIndex, nodeIndex) {
|
|
76500
77201
|
if (fileIndex === -1) return;
|
|
76501
77202
|
const placement = this.filePlacements[fileIndex];
|
|
77203
|
+
if (!placement) {
|
|
77204
|
+
return;
|
|
77205
|
+
}
|
|
76502
77206
|
if (placement) {
|
|
76503
77207
|
placement.intervals.delete(nodeIndex);
|
|
76504
77208
|
this.dirtyModifiedPlacements = true;
|
|
@@ -76506,14 +77210,14 @@ class GSplatOctreeInstance {
|
|
|
76506
77210
|
if (placement.resource) {
|
|
76507
77211
|
this.activePlacements.delete(placement);
|
|
76508
77212
|
}
|
|
77213
|
+
this.removedCandidates.add(fileIndex);
|
|
76509
77214
|
this.filePlacements[fileIndex] = null;
|
|
76510
77215
|
this.pending.delete(fileIndex);
|
|
76511
77216
|
}
|
|
76512
77217
|
}
|
|
76513
77218
|
}
|
|
76514
77219
|
addFilePlacement(fileIndex) {
|
|
76515
|
-
const
|
|
76516
|
-
const res = this.octree.getFileResource(fileUrl);
|
|
77220
|
+
const res = this.octree.getFileResource(fileIndex);
|
|
76517
77221
|
if (res) {
|
|
76518
77222
|
const placement = this.filePlacements[fileIndex];
|
|
76519
77223
|
if (placement) {
|
|
@@ -76521,46 +77225,82 @@ class GSplatOctreeInstance {
|
|
|
76521
77225
|
placement.aabb.copy(res.aabb);
|
|
76522
77226
|
this.activePlacements.add(placement);
|
|
76523
77227
|
this.dirtyModifiedPlacements = true;
|
|
77228
|
+
this.removedCandidates.delete(fileIndex);
|
|
76524
77229
|
return true;
|
|
76525
77230
|
}
|
|
76526
77231
|
}
|
|
76527
77232
|
return false;
|
|
76528
77233
|
}
|
|
76529
|
-
testMoved() {
|
|
77234
|
+
testMoved(threshold) {
|
|
76530
77235
|
const position = this.placement.node.getPosition();
|
|
76531
77236
|
const length = position.distance(this.previousPosition);
|
|
76532
|
-
if (length >
|
|
76533
|
-
this.previousPosition.copy(position);
|
|
77237
|
+
if (length > threshold) {
|
|
76534
77238
|
return true;
|
|
76535
77239
|
}
|
|
76536
77240
|
return false;
|
|
76537
77241
|
}
|
|
76538
|
-
|
|
77242
|
+
updateMoved() {
|
|
77243
|
+
this.previousPosition.copy(this.placement.node.getPosition());
|
|
77244
|
+
}
|
|
77245
|
+
update(scene) {
|
|
76539
77246
|
if (this.pending.size) {
|
|
76540
77247
|
for (const fileIndex of this.pending){
|
|
76541
|
-
|
|
76542
|
-
this.
|
|
76543
|
-
const placement = this.filePlacements[fileIndex];
|
|
76544
|
-
if (placement && placement.intervals.size > 0 && this.addFilePlacement(fileIndex)) {
|
|
77248
|
+
this.octree.ensureFileResource(fileIndex, this.assetLoader);
|
|
77249
|
+
if (this.addFilePlacement(fileIndex)) {
|
|
76545
77250
|
_tempCompletedUrls.push(fileIndex);
|
|
76546
|
-
for (const [nodeIndex] of
|
|
76547
|
-
|
|
76548
|
-
if (oldFileIndex !== undefined) {
|
|
77251
|
+
for (const [nodeIndex, { oldFileIndex, newFileIndex }] of this.pendingDecrements){
|
|
77252
|
+
if (newFileIndex === fileIndex) {
|
|
76549
77253
|
this.decrementFileRef(oldFileIndex, nodeIndex);
|
|
76550
77254
|
this.pendingDecrements.delete(nodeIndex);
|
|
77255
|
+
let newLodIndex = 0;
|
|
77256
|
+
const nodeLods = this.octree.nodes[nodeIndex].lods;
|
|
77257
|
+
for(let li = 0; li < nodeLods.length; li++){
|
|
77258
|
+
if (nodeLods[li].fileIndex === newFileIndex) {
|
|
77259
|
+
newLodIndex = li;
|
|
77260
|
+
break;
|
|
77261
|
+
}
|
|
77262
|
+
}
|
|
77263
|
+
this.nodeLods[nodeIndex] = newLodIndex;
|
|
76551
77264
|
}
|
|
76552
77265
|
}
|
|
76553
77266
|
}
|
|
76554
77267
|
}
|
|
77268
|
+
if (_tempCompletedUrls.length > 0) {
|
|
77269
|
+
this.needsLodUpdate = true;
|
|
77270
|
+
}
|
|
76555
77271
|
for (const fileIndex of _tempCompletedUrls){
|
|
76556
77272
|
this.pending.delete(fileIndex);
|
|
76557
77273
|
}
|
|
76558
77274
|
_tempCompletedUrls.length = 0;
|
|
76559
77275
|
}
|
|
77276
|
+
this.pollPrefetchCompletions();
|
|
76560
77277
|
const dirty = this.dirtyModifiedPlacements;
|
|
76561
77278
|
this.dirtyModifiedPlacements = false;
|
|
76562
77279
|
return dirty;
|
|
76563
77280
|
}
|
|
77281
|
+
debugRender(scene) {}
|
|
77282
|
+
consumeNeedsLodUpdate() {
|
|
77283
|
+
const v = this.needsLodUpdate;
|
|
77284
|
+
this.needsLodUpdate = false;
|
|
77285
|
+
return v;
|
|
77286
|
+
}
|
|
77287
|
+
pollPrefetchCompletions() {
|
|
77288
|
+
if (this.prefetchPending.size) {
|
|
77289
|
+
for (const fileIndex of this.prefetchPending){
|
|
77290
|
+
this.octree.ensureFileResource(fileIndex, this.assetLoader);
|
|
77291
|
+
if (this.octree.getFileResource(fileIndex)) {
|
|
77292
|
+
_tempCompletedUrls.push(fileIndex);
|
|
77293
|
+
}
|
|
77294
|
+
}
|
|
77295
|
+
if (_tempCompletedUrls.length > 0) {
|
|
77296
|
+
this.needsLodUpdate = true;
|
|
77297
|
+
}
|
|
77298
|
+
for (const fileIndex of _tempCompletedUrls){
|
|
77299
|
+
this.prefetchPending.delete(fileIndex);
|
|
77300
|
+
}
|
|
77301
|
+
_tempCompletedUrls.length = 0;
|
|
77302
|
+
}
|
|
77303
|
+
}
|
|
76564
77304
|
}
|
|
76565
77305
|
|
|
76566
77306
|
const tmpMin = new Vec3();
|
|
@@ -76575,13 +77315,19 @@ class GSplatOctreeNode {
|
|
|
76575
77315
|
}
|
|
76576
77316
|
}
|
|
76577
77317
|
|
|
77318
|
+
const _toDelete = [];
|
|
76578
77319
|
class GSplatOctree {
|
|
76579
77320
|
constructor(assetFileUrl, data){
|
|
76580
77321
|
this.fileResources = new Map();
|
|
76581
|
-
this.
|
|
77322
|
+
this.cooldowns = new Map();
|
|
76582
77323
|
this.lodLevels = data.lodLevels;
|
|
76583
77324
|
this.assetFileUrl = assetFileUrl;
|
|
76584
|
-
|
|
77325
|
+
const baseDir = path.getDirectory(assetFileUrl);
|
|
77326
|
+
this.files = data.filenames.map((url)=>({
|
|
77327
|
+
url: path.isRelativePath(url) ? path.join(baseDir, url) : url,
|
|
77328
|
+
lodLevel: -1
|
|
77329
|
+
}));
|
|
77330
|
+
this.fileRefCounts = new Int32Array(this.files.length);
|
|
76585
77331
|
const leafNodes = [];
|
|
76586
77332
|
this._extractLeafNodes(data.tree, leafNodes);
|
|
76587
77333
|
this.nodes = leafNodes.map((nodeData)=>{
|
|
@@ -76590,11 +77336,12 @@ class GSplatOctree {
|
|
|
76590
77336
|
const lodData = nodeData.lods[i.toString()];
|
|
76591
77337
|
if (lodData) {
|
|
76592
77338
|
lods.push({
|
|
76593
|
-
file: this.files[lodData.file] || '',
|
|
77339
|
+
file: this.files[lodData.file].url || '',
|
|
76594
77340
|
fileIndex: lodData.file,
|
|
76595
77341
|
offset: lodData.offset || 0,
|
|
76596
77342
|
count: lodData.count || 0
|
|
76597
77343
|
});
|
|
77344
|
+
this.files[lodData.file].lodLevel = i;
|
|
76598
77345
|
} else {
|
|
76599
77346
|
lods.push({
|
|
76600
77347
|
file: '',
|
|
@@ -76607,6 +77354,7 @@ class GSplatOctree {
|
|
|
76607
77354
|
return new GSplatOctreeNode(lods, nodeData.bound);
|
|
76608
77355
|
});
|
|
76609
77356
|
}
|
|
77357
|
+
_traceLodCounts() {}
|
|
76610
77358
|
_extractLeafNodes(node, leafNodes) {
|
|
76611
77359
|
if (node.lods) {
|
|
76612
77360
|
leafNodes.push({
|
|
@@ -76619,20 +77367,57 @@ class GSplatOctree {
|
|
|
76619
77367
|
}
|
|
76620
77368
|
}
|
|
76621
77369
|
}
|
|
76622
|
-
|
|
76623
|
-
return
|
|
77370
|
+
getFileResource(fileIndex) {
|
|
77371
|
+
return this.fileResources.get(fileIndex);
|
|
77372
|
+
}
|
|
77373
|
+
incRefCount(fileIndex) {
|
|
77374
|
+
const count = this.fileRefCounts[fileIndex] + 1;
|
|
77375
|
+
this.fileRefCounts[fileIndex] = count;
|
|
77376
|
+
this.cooldowns.delete(fileIndex);
|
|
77377
|
+
}
|
|
77378
|
+
decRefCount(fileIndex, cooldownTicks) {
|
|
77379
|
+
const count = this.fileRefCounts[fileIndex] - 1;
|
|
77380
|
+
this.fileRefCounts[fileIndex] = count;
|
|
77381
|
+
if (count === 0) {
|
|
77382
|
+
this.cooldowns.set(fileIndex, cooldownTicks);
|
|
77383
|
+
}
|
|
77384
|
+
}
|
|
77385
|
+
unloadResource(fileIndex, assetLoader) {
|
|
77386
|
+
if (this.fileResources.has(fileIndex)) {
|
|
77387
|
+
const fullUrl = this.files[fileIndex].url;
|
|
77388
|
+
assetLoader.unload(fullUrl);
|
|
77389
|
+
this.fileResources.delete(fileIndex);
|
|
77390
|
+
this._traceLodCounts();
|
|
77391
|
+
}
|
|
76624
77392
|
}
|
|
76625
|
-
|
|
76626
|
-
|
|
77393
|
+
updateCooldownTick(assetLoader) {
|
|
77394
|
+
if (this.cooldowns.size > 0) {
|
|
77395
|
+
this.cooldowns.forEach((remaining, fileIndex)=>{
|
|
77396
|
+
if (remaining <= 1) {
|
|
77397
|
+
if (this.fileRefCounts[fileIndex] === 0) {
|
|
77398
|
+
this.unloadResource(fileIndex, assetLoader);
|
|
77399
|
+
}
|
|
77400
|
+
_toDelete.push(fileIndex);
|
|
77401
|
+
} else {
|
|
77402
|
+
this.cooldowns.set(fileIndex, remaining - 1);
|
|
77403
|
+
}
|
|
77404
|
+
});
|
|
77405
|
+
_toDelete.forEach((idx)=>this.cooldowns.delete(idx));
|
|
77406
|
+
_toDelete.length = 0;
|
|
77407
|
+
}
|
|
76627
77408
|
}
|
|
76628
|
-
ensureFileResource(
|
|
76629
|
-
if (this.fileResources.has(
|
|
77409
|
+
ensureFileResource(fileIndex, assetLoader) {
|
|
77410
|
+
if (this.fileResources.has(fileIndex)) {
|
|
76630
77411
|
return;
|
|
76631
77412
|
}
|
|
76632
|
-
const fullUrl = this.
|
|
77413
|
+
const fullUrl = this.files[fileIndex].url;
|
|
76633
77414
|
const res = assetLoader.getResource(fullUrl);
|
|
76634
77415
|
if (res) {
|
|
76635
|
-
this.fileResources.set(
|
|
77416
|
+
this.fileResources.set(fileIndex, res);
|
|
77417
|
+
if (this.fileRefCounts[fileIndex] === 0) {
|
|
77418
|
+
this.cooldowns.set(fileIndex, assetLoader.cooldownTicks);
|
|
77419
|
+
}
|
|
77420
|
+
this._traceLodCounts();
|
|
76636
77421
|
return;
|
|
76637
77422
|
}
|
|
76638
77423
|
assetLoader.load(fullUrl);
|
|
@@ -76655,6 +77440,7 @@ class GSplatWorldState {
|
|
|
76655
77440
|
this.splats = [];
|
|
76656
77441
|
this.textureSize = 0;
|
|
76657
77442
|
this.totalUsedPixels = 0;
|
|
77443
|
+
this.pendingReleases = [];
|
|
76658
77444
|
this.version = version;
|
|
76659
77445
|
this.splats = splats;
|
|
76660
77446
|
this.estimateTextureSize(this.splats, device.maxTextureSize);
|
|
@@ -76715,22 +77501,62 @@ const invModelMat = new Mat4();
|
|
|
76715
77501
|
const tempNonOctreePlacements = new Set();
|
|
76716
77502
|
const tempOctreePlacements = new Set();
|
|
76717
77503
|
const _updatedSplats = [];
|
|
77504
|
+
const tempOctreesTicked = new Set();
|
|
77505
|
+
const _lodColorsRaw = [
|
|
77506
|
+
[
|
|
77507
|
+
1,
|
|
77508
|
+
0,
|
|
77509
|
+
0
|
|
77510
|
+
],
|
|
77511
|
+
[
|
|
77512
|
+
0,
|
|
77513
|
+
1,
|
|
77514
|
+
0
|
|
77515
|
+
],
|
|
77516
|
+
[
|
|
77517
|
+
0,
|
|
77518
|
+
0,
|
|
77519
|
+
1
|
|
77520
|
+
],
|
|
77521
|
+
[
|
|
77522
|
+
1,
|
|
77523
|
+
1,
|
|
77524
|
+
0
|
|
77525
|
+
],
|
|
77526
|
+
[
|
|
77527
|
+
1,
|
|
77528
|
+
0,
|
|
77529
|
+
1
|
|
77530
|
+
]
|
|
77531
|
+
];
|
|
77532
|
+
[
|
|
77533
|
+
new Color(1, 0, 0),
|
|
77534
|
+
new Color(0, 1, 0),
|
|
77535
|
+
new Color(0, 0, 1),
|
|
77536
|
+
new Color(1, 1, 0),
|
|
77537
|
+
new Color(1, 0, 1)
|
|
77538
|
+
];
|
|
76718
77539
|
class GSplatManager {
|
|
76719
77540
|
constructor(device, director, layer, cameraNode){
|
|
76720
77541
|
this.node = new GraphNode('GSplatManager');
|
|
76721
77542
|
this.worldStates = new Map();
|
|
76722
77543
|
this.lastWorldStateVersion = 0;
|
|
76723
77544
|
this.sortedVersion = 0;
|
|
77545
|
+
this.framesTillFullUpdate = 0;
|
|
76724
77546
|
this.lastCameraPos = new Vec3(Infinity, Infinity, Infinity);
|
|
77547
|
+
this.lastCameraFwd = new Vec3(Infinity, Infinity, Infinity);
|
|
76725
77548
|
this.layerPlacements = [];
|
|
76726
77549
|
this.layerPlacementsDirty = false;
|
|
76727
77550
|
this.octreeInstances = new Map();
|
|
77551
|
+
this.octreeInstancesToDestroy = [];
|
|
76728
77552
|
this.device = device;
|
|
77553
|
+
this.scene = director.scene;
|
|
76729
77554
|
this.director = director;
|
|
76730
77555
|
this.cameraNode = cameraNode;
|
|
76731
77556
|
this.workBuffer = new GSplatWorkBuffer(device);
|
|
76732
77557
|
this.renderer = new GSplatRenderer(device, this.node, this.cameraNode, layer, this.workBuffer);
|
|
76733
77558
|
this.sorter = this.createSorter();
|
|
77559
|
+
this.cooldownTicks = this.director.assetLoader.cooldownTicks;
|
|
76734
77560
|
}
|
|
76735
77561
|
destroy() {
|
|
76736
77562
|
this.workBuffer.destroy();
|
|
@@ -76759,7 +77585,8 @@ class GSplatManager {
|
|
|
76759
77585
|
for (const [placement, inst] of this.octreeInstances){
|
|
76760
77586
|
if (!tempOctreePlacements.has(placement)) {
|
|
76761
77587
|
this.octreeInstances.delete(placement);
|
|
76762
|
-
|
|
77588
|
+
this.layerPlacementsDirty = true;
|
|
77589
|
+
this.octreeInstancesToDestroy.push(inst);
|
|
76763
77590
|
}
|
|
76764
77591
|
}
|
|
76765
77592
|
this.layerPlacementsDirty = this.layerPlacements.length !== tempNonOctreePlacements.size;
|
|
@@ -76780,9 +77607,6 @@ class GSplatManager {
|
|
|
76780
77607
|
tempOctreePlacements.clear();
|
|
76781
77608
|
}
|
|
76782
77609
|
updateWorldState() {
|
|
76783
|
-
for (const [, inst] of this.octreeInstances){
|
|
76784
|
-
this.layerPlacementsDirty ||= inst.update();
|
|
76785
|
-
}
|
|
76786
77610
|
const worldChanged = this.layerPlacementsDirty || this.worldStates.size === 0;
|
|
76787
77611
|
if (worldChanged) {
|
|
76788
77612
|
this.lastWorldStateVersion++;
|
|
@@ -76793,13 +77617,39 @@ class GSplatManager {
|
|
|
76793
77617
|
}
|
|
76794
77618
|
for (const [, inst] of this.octreeInstances){
|
|
76795
77619
|
inst.activePlacements.forEach((p)=>{
|
|
76796
|
-
|
|
77620
|
+
if (p.resource) {
|
|
77621
|
+
splats.push(new GSplatInfo(this.device, p.resource, p));
|
|
77622
|
+
}
|
|
76797
77623
|
});
|
|
76798
77624
|
}
|
|
76799
77625
|
splats.forEach((splat)=>{
|
|
76800
77626
|
this.sorter.setCenters(splat.resource.id, splat.resource.centers);
|
|
76801
77627
|
});
|
|
76802
77628
|
const newState = new GSplatWorldState(this.device, this.lastWorldStateVersion, splats);
|
|
77629
|
+
for (const [, inst] of this.octreeInstances){
|
|
77630
|
+
if (inst.removedCandidates && inst.removedCandidates.size) {
|
|
77631
|
+
for (const fileIndex of inst.removedCandidates){
|
|
77632
|
+
newState.pendingReleases.push([
|
|
77633
|
+
inst.octree,
|
|
77634
|
+
fileIndex
|
|
77635
|
+
]);
|
|
77636
|
+
}
|
|
77637
|
+
inst.removedCandidates.clear();
|
|
77638
|
+
}
|
|
77639
|
+
}
|
|
77640
|
+
if (this.octreeInstancesToDestroy.length) {
|
|
77641
|
+
for (const inst of this.octreeInstancesToDestroy){
|
|
77642
|
+
const toRelease = inst.getFileDecrements();
|
|
77643
|
+
for (const fileIndex of toRelease){
|
|
77644
|
+
newState.pendingReleases.push([
|
|
77645
|
+
inst.octree,
|
|
77646
|
+
fileIndex
|
|
77647
|
+
]);
|
|
77648
|
+
}
|
|
77649
|
+
inst.destroy();
|
|
77650
|
+
}
|
|
77651
|
+
this.octreeInstancesToDestroy.length = 0;
|
|
77652
|
+
}
|
|
76803
77653
|
this.worldStates.set(this.lastWorldStateVersion, newState);
|
|
76804
77654
|
this.layerPlacementsDirty = false;
|
|
76805
77655
|
}
|
|
@@ -76820,24 +77670,78 @@ class GSplatManager {
|
|
|
76820
77670
|
this.workBuffer.resize(textureSize);
|
|
76821
77671
|
this.renderer.setMaxNumSplats(textureSize * textureSize);
|
|
76822
77672
|
}
|
|
76823
|
-
this.
|
|
77673
|
+
const colorize = this.scene.gsplat.colorizeLod;
|
|
77674
|
+
this.workBuffer.render(worldState.splats, this.cameraNode, colorize ? _lodColorsRaw : undefined);
|
|
77675
|
+
if (worldState.pendingReleases && worldState.pendingReleases.length) {
|
|
77676
|
+
for (const [octree, fileIndex] of worldState.pendingReleases){
|
|
77677
|
+
octree.decRefCount(fileIndex, this.cooldownTicks);
|
|
77678
|
+
}
|
|
77679
|
+
worldState.pendingReleases.length = 0;
|
|
77680
|
+
}
|
|
77681
|
+
this.renderer.setNumSplats(count);
|
|
76824
77682
|
}
|
|
76825
77683
|
this.workBuffer.setOrderData(orderData);
|
|
76826
|
-
this.renderer.setNumSplats(count);
|
|
76827
77684
|
}
|
|
76828
77685
|
}
|
|
76829
|
-
|
|
77686
|
+
testCameraMoved() {
|
|
77687
|
+
const distanceThreshold = this.scene.gsplat.lodUpdateDistance;
|
|
77688
|
+
const currentCameraPos = this.cameraNode.getPosition();
|
|
77689
|
+
const cameraMoved = this.lastCameraPos.distance(currentCameraPos) > distanceThreshold;
|
|
77690
|
+
if (cameraMoved) {
|
|
77691
|
+
return true;
|
|
77692
|
+
}
|
|
77693
|
+
let cameraRotated = false;
|
|
77694
|
+
const lodUpdateAngleDeg = this.scene.gsplat.lodUpdateAngle;
|
|
77695
|
+
if (lodUpdateAngleDeg > 0) {
|
|
77696
|
+
if (Number.isFinite(this.lastCameraFwd.x)) {
|
|
77697
|
+
const currentCameraFwd = this.cameraNode.forward;
|
|
77698
|
+
const dot = Math.min(1, Math.max(-1, this.lastCameraFwd.dot(currentCameraFwd)));
|
|
77699
|
+
const angle = Math.acos(dot);
|
|
77700
|
+
const rotThreshold = lodUpdateAngleDeg * Math.PI / 180;
|
|
77701
|
+
cameraRotated = angle > rotThreshold;
|
|
77702
|
+
} else {
|
|
77703
|
+
cameraRotated = true;
|
|
77704
|
+
}
|
|
77705
|
+
}
|
|
77706
|
+
return cameraMoved || cameraRotated;
|
|
77707
|
+
}
|
|
77708
|
+
update() {
|
|
77709
|
+
let fullUpdate = false;
|
|
77710
|
+
this.framesTillFullUpdate--;
|
|
77711
|
+
if (this.framesTillFullUpdate <= 0) {
|
|
77712
|
+
this.framesTillFullUpdate = 10;
|
|
77713
|
+
if (this.sorter.jobsInFlight < 3) {
|
|
77714
|
+
fullUpdate = true;
|
|
77715
|
+
}
|
|
77716
|
+
}
|
|
77717
|
+
let anyInstanceNeedsLodUpdate = false;
|
|
76830
77718
|
let anyOctreeMoved = false;
|
|
76831
|
-
|
|
76832
|
-
|
|
77719
|
+
let cameraMovedOrRotated = false;
|
|
77720
|
+
if (fullUpdate) {
|
|
77721
|
+
for (const [, inst] of this.octreeInstances){
|
|
77722
|
+
const isDirty = inst.update(this.scene);
|
|
77723
|
+
this.layerPlacementsDirty ||= isDirty;
|
|
77724
|
+
const instNeeds = inst.consumeNeedsLodUpdate();
|
|
77725
|
+
anyInstanceNeedsLodUpdate ||= instNeeds;
|
|
77726
|
+
}
|
|
77727
|
+
const threshold = this.scene.gsplat.lodUpdateDistance;
|
|
77728
|
+
for (const [, inst] of this.octreeInstances){
|
|
77729
|
+
const moved = inst.testMoved(threshold);
|
|
77730
|
+
anyOctreeMoved ||= moved;
|
|
77731
|
+
}
|
|
77732
|
+
cameraMovedOrRotated = this.testCameraMoved();
|
|
76833
77733
|
}
|
|
76834
|
-
|
|
76835
|
-
|
|
76836
|
-
|
|
76837
|
-
if (
|
|
76838
|
-
this.lastCameraPos.copy(currentCameraPos);
|
|
77734
|
+
if (this.scene.gsplat.dirty) {
|
|
77735
|
+
this.layerPlacementsDirty = true;
|
|
77736
|
+
}
|
|
77737
|
+
if (cameraMovedOrRotated || anyOctreeMoved || this.scene.gsplat.dirty || anyInstanceNeedsLodUpdate) {
|
|
76839
77738
|
for (const [, inst] of this.octreeInstances){
|
|
76840
|
-
inst.
|
|
77739
|
+
inst.updateMoved();
|
|
77740
|
+
}
|
|
77741
|
+
this.lastCameraPos.copy(this.cameraNode.getPosition());
|
|
77742
|
+
this.lastCameraFwd.copy(this.cameraNode.forward);
|
|
77743
|
+
for (const [, inst] of this.octreeInstances){
|
|
77744
|
+
inst.updateLod(this.cameraNode, this.scene.gsplat);
|
|
76841
77745
|
}
|
|
76842
77746
|
}
|
|
76843
77747
|
this.updateWorldState();
|
|
@@ -76858,10 +77762,23 @@ class GSplatManager {
|
|
|
76858
77762
|
}
|
|
76859
77763
|
});
|
|
76860
77764
|
if (_updatedSplats.length > 0) {
|
|
76861
|
-
this.
|
|
77765
|
+
const colorize = this.scene.gsplat.colorizeLod;
|
|
77766
|
+
this.workBuffer.render(_updatedSplats, this.cameraNode, colorize ? _lodColorsRaw : undefined);
|
|
76862
77767
|
_updatedSplats.length = 0;
|
|
76863
77768
|
}
|
|
76864
77769
|
}
|
|
77770
|
+
if (this.octreeInstances.size) {
|
|
77771
|
+
for (const [, inst] of this.octreeInstances){
|
|
77772
|
+
const octree = inst.octree;
|
|
77773
|
+
if (!tempOctreesTicked.has(octree)) {
|
|
77774
|
+
tempOctreesTicked.add(octree);
|
|
77775
|
+
octree.updateCooldownTick(this.director.assetLoader);
|
|
77776
|
+
}
|
|
77777
|
+
}
|
|
77778
|
+
tempOctreesTicked.clear();
|
|
77779
|
+
}
|
|
77780
|
+
const { textureSize } = this.workBuffer;
|
|
77781
|
+
return textureSize * textureSize;
|
|
76865
77782
|
}
|
|
76866
77783
|
sort(lastState) {
|
|
76867
77784
|
const cameraNode = this.cameraNode;
|
|
@@ -76874,12 +77791,14 @@ class GSplatManager {
|
|
|
76874
77791
|
invModelMat.copy(modelMat).invert();
|
|
76875
77792
|
const uniformScale = modelMat.getScale().x;
|
|
76876
77793
|
const transformedDirection = invModelMat.transformVector(cameraDirection).normalize();
|
|
77794
|
+
const transformedPosition = invModelMat.transformPoint(cameraPosition);
|
|
76877
77795
|
modelMat.getTranslation(translation);
|
|
76878
77796
|
const offset = translation.sub(cameraPosition).dot(cameraDirection);
|
|
76879
77797
|
const aabbMin = splat.aabb.getMin();
|
|
76880
77798
|
const aabbMax = splat.aabb.getMax();
|
|
76881
77799
|
sorterRequest.push({
|
|
76882
77800
|
transformedDirection,
|
|
77801
|
+
transformedPosition,
|
|
76883
77802
|
offset,
|
|
76884
77803
|
scale: uniformScale,
|
|
76885
77804
|
modelMat: modelMat.data.slice(),
|
|
@@ -76895,7 +77814,7 @@ class GSplatManager {
|
|
|
76895
77814
|
]
|
|
76896
77815
|
});
|
|
76897
77816
|
});
|
|
76898
|
-
this.sorter.setSortParams(sorterRequest);
|
|
77817
|
+
this.sorter.setSortParams(sorterRequest, this.scene.gsplat.radialSorting);
|
|
76899
77818
|
this.renderer.updateViewport(cameraNode);
|
|
76900
77819
|
}
|
|
76901
77820
|
prepareSortParameters(worldState) {
|
|
@@ -76945,13 +77864,17 @@ class GSplatCameraData {
|
|
|
76945
77864
|
}
|
|
76946
77865
|
}
|
|
76947
77866
|
class GSplatDirector {
|
|
76948
|
-
constructor(device, scene, assetLoader){
|
|
77867
|
+
constructor(device, renderer, scene, assetLoader){
|
|
76949
77868
|
this.camerasMap = new Map();
|
|
76950
|
-
this.octrees = new Map();
|
|
76951
77869
|
this.device = device;
|
|
77870
|
+
this.renderer = renderer;
|
|
76952
77871
|
this.assetLoader = assetLoader;
|
|
76953
77872
|
this.scene = scene;
|
|
76954
77873
|
}
|
|
77874
|
+
destroy() {
|
|
77875
|
+
this.camerasMap.forEach((cameraData)=>cameraData.destroy());
|
|
77876
|
+
this.camerasMap.clear();
|
|
77877
|
+
}
|
|
76955
77878
|
getCameraData(camera) {
|
|
76956
77879
|
let cameraData = this.camerasMap.get(camera);
|
|
76957
77880
|
if (!cameraData) {
|
|
@@ -76974,6 +77897,7 @@ class GSplatDirector {
|
|
|
76974
77897
|
});
|
|
76975
77898
|
}
|
|
76976
77899
|
});
|
|
77900
|
+
let gsplatCount = 0;
|
|
76977
77901
|
const camerasComponents = comp.cameras;
|
|
76978
77902
|
for(let i = 0; i < camerasComponents.length; i++){
|
|
76979
77903
|
const camera = camerasComponents[i].camera;
|
|
@@ -76996,10 +77920,14 @@ class GSplatDirector {
|
|
|
76996
77920
|
}
|
|
76997
77921
|
}
|
|
76998
77922
|
}
|
|
76999
|
-
cameraData
|
|
77000
|
-
layerData.
|
|
77001
|
-
|
|
77923
|
+
if (cameraData) {
|
|
77924
|
+
for (const layerData of cameraData.layersMap.values()){
|
|
77925
|
+
gsplatCount += layerData.gsplatManager.update();
|
|
77926
|
+
}
|
|
77927
|
+
}
|
|
77002
77928
|
}
|
|
77929
|
+
this.renderer._gsplatCount = gsplatCount;
|
|
77930
|
+
this.scene.gsplat.dirty = false;
|
|
77003
77931
|
for(let i = 0; i < comp.layerList.length; i++){
|
|
77004
77932
|
comp.layerList[i].gsplatPlacementsDirty = false;
|
|
77005
77933
|
}
|
|
@@ -77010,7 +77938,13 @@ class GSplatComponent extends Component {
|
|
|
77010
77938
|
constructor(system, entity){
|
|
77011
77939
|
super(system, entity), this._layers = [
|
|
77012
77940
|
LAYERID_WORLD
|
|
77013
|
-
], this._instance = null, this._placement = null, this._materialTmp = null, this._highQualitySH = true, this.
|
|
77941
|
+
], this._instance = null, this._placement = null, this._materialTmp = null, this._highQualitySH = true, this._lodDistances = [
|
|
77942
|
+
5,
|
|
77943
|
+
10,
|
|
77944
|
+
15,
|
|
77945
|
+
20,
|
|
77946
|
+
25
|
|
77947
|
+
], this._customAabb = null, this._evtLayersChanged = null, this._evtLayerAdded = null, this._evtLayerRemoved = null, this._castShadows = false, this._unified = false;
|
|
77014
77948
|
this._assetReference = new AssetReference('asset', this, system.app.assets, {
|
|
77015
77949
|
add: this._onGSplatAssetAdded,
|
|
77016
77950
|
load: this._onGSplatAssetLoad,
|
|
@@ -77103,6 +78037,15 @@ class GSplatComponent extends Component {
|
|
|
77103
78037
|
get castShadows() {
|
|
77104
78038
|
return this._castShadows;
|
|
77105
78039
|
}
|
|
78040
|
+
set lodDistances(value) {
|
|
78041
|
+
this._lodDistances = Array.isArray(value) ? value.slice() : null;
|
|
78042
|
+
if (this._placement) {
|
|
78043
|
+
this._placement.lodDistances = this._lodDistances;
|
|
78044
|
+
}
|
|
78045
|
+
}
|
|
78046
|
+
get lodDistances() {
|
|
78047
|
+
return this._lodDistances ? this._lodDistances.slice() : null;
|
|
78048
|
+
}
|
|
77106
78049
|
set unified(value) {
|
|
77107
78050
|
if (this.enabled && this.entity.enabled) {
|
|
77108
78051
|
return;
|
|
@@ -77280,6 +78223,7 @@ class GSplatComponent extends Component {
|
|
|
77280
78223
|
this._placement = null;
|
|
77281
78224
|
if (asset) {
|
|
77282
78225
|
this._placement = new GSplatPlacement(asset.resource, this.entity);
|
|
78226
|
+
this._placement.lodDistances = this._lodDistances;
|
|
77283
78227
|
}
|
|
77284
78228
|
} else {
|
|
77285
78229
|
if (asset) {
|
|
@@ -77312,6 +78256,9 @@ class GSplatAssetLoaderBase {
|
|
|
77312
78256
|
load(url) {}
|
|
77313
78257
|
unload(url) {}
|
|
77314
78258
|
getResource(url) {}
|
|
78259
|
+
constructor(){
|
|
78260
|
+
this.cooldownTicks = 100;
|
|
78261
|
+
}
|
|
77315
78262
|
}
|
|
77316
78263
|
|
|
77317
78264
|
class GSplatAssetLoader extends GSplatAssetLoaderBase {
|
|
@@ -77338,6 +78285,7 @@ class GSplatAssetLoader extends GSplatAssetLoaderBase {
|
|
|
77338
78285
|
unload(url) {
|
|
77339
78286
|
const asset = this._urlToAsset.get(url);
|
|
77340
78287
|
if (asset) {
|
|
78288
|
+
this._registry.remove(asset);
|
|
77341
78289
|
asset.unload();
|
|
77342
78290
|
this._urlToAsset.delete(url);
|
|
77343
78291
|
}
|
|
@@ -77367,7 +78315,7 @@ class GSplatComponentSystem extends ComponentSystem {
|
|
|
77367
78315
|
this.DataType = GSplatComponentData;
|
|
77368
78316
|
this.schema = _schema;
|
|
77369
78317
|
const gsplatAssetLoader = new GSplatAssetLoader(app.assets);
|
|
77370
|
-
app.renderer.gsplatDirector = new GSplatDirector(app.graphicsDevice, app.scene, gsplatAssetLoader);
|
|
78318
|
+
app.renderer.gsplatDirector = new GSplatDirector(app.graphicsDevice, app.renderer, app.scene, gsplatAssetLoader);
|
|
77371
78319
|
this.on('beforeremove', this.onRemove, this);
|
|
77372
78320
|
}
|
|
77373
78321
|
initializeComponentData(component, _data, properties) {
|
|
@@ -81208,8 +82156,9 @@ class GSplatCompressedData {
|
|
|
81208
82156
|
result.halfExtents.set((Mx - mx) * 0.5, (My - my) * 0.5, (Mz - mz) * 0.5);
|
|
81209
82157
|
return true;
|
|
81210
82158
|
}
|
|
81211
|
-
getCenters(
|
|
82159
|
+
getCenters() {
|
|
81212
82160
|
const { vertexData, chunkData, numChunks, chunkSize } = this;
|
|
82161
|
+
const result = new Float32Array(this.numSplats * 3);
|
|
81213
82162
|
let mx, my, mz, Mx, My, Mz;
|
|
81214
82163
|
for(let c = 0; c < numChunks; ++c){
|
|
81215
82164
|
const off = c * chunkSize;
|
|
@@ -81230,6 +82179,7 @@ class GSplatCompressedData {
|
|
|
81230
82179
|
result[i * 3 + 2] = (1 - pz) * mz + pz * Mz;
|
|
81231
82180
|
}
|
|
81232
82181
|
}
|
|
82182
|
+
return result;
|
|
81233
82183
|
}
|
|
81234
82184
|
getChunks(result) {
|
|
81235
82185
|
const { chunkData, numChunks, chunkSize } = this;
|
|
@@ -82027,6 +82977,12 @@ class SogsParser {
|
|
|
82027
82977
|
});
|
|
82028
82978
|
});
|
|
82029
82979
|
const textureAssets = subs.map((sub)=>textures[sub]).flat();
|
|
82980
|
+
asset.once('unload', ()=>{
|
|
82981
|
+
textureAssets.forEach((t)=>{
|
|
82982
|
+
assets.remove(t);
|
|
82983
|
+
t.unload();
|
|
82984
|
+
});
|
|
82985
|
+
});
|
|
82030
82986
|
combineProgress(asset, textureAssets);
|
|
82031
82987
|
textureAssets.forEach((t)=>assets.load(t));
|
|
82032
82988
|
await Promise.allSettled(promises);
|
|
@@ -82042,8 +82998,10 @@ class SogsParser {
|
|
|
82042
82998
|
data.sh_labels = textures.shN?.[1]?.resource;
|
|
82043
82999
|
const decompress = asset.data?.decompress;
|
|
82044
83000
|
if (!decompress) {
|
|
83001
|
+
if (!this.app?.graphicsDevice || this.app?.graphicsDevice?._destroyed) return;
|
|
82045
83002
|
await data.prepareGpuData();
|
|
82046
83003
|
}
|
|
83004
|
+
if (!this.app?.graphicsDevice || this.app?.graphicsDevice?._destroyed) return;
|
|
82047
83005
|
const resource = decompress ? new GSplatResource(this.app.graphicsDevice, await data.decompress()) : new GSplatSogsResource(this.app.graphicsDevice, data);
|
|
82048
83006
|
callback(null, resource);
|
|
82049
83007
|
}
|
|
@@ -82145,13 +83103,49 @@ const inflate = async (compressed)=>{
|
|
|
82145
83103
|
const ab = await new Response(out).arrayBuffer();
|
|
82146
83104
|
return new Uint8Array(ab);
|
|
82147
83105
|
};
|
|
83106
|
+
const downloadArrayBuffer = async (url, asset)=>{
|
|
83107
|
+
const response = await (asset.file?.contents ?? fetch(url.load));
|
|
83108
|
+
if (!response) {
|
|
83109
|
+
throw new Error('Error loading resource');
|
|
83110
|
+
}
|
|
83111
|
+
if (response instanceof Response) {
|
|
83112
|
+
if (!response.ok) {
|
|
83113
|
+
throw new Error(`Error loading resource: ${response.status} ${response.statusText}`);
|
|
83114
|
+
}
|
|
83115
|
+
const totalLength = parseInt(response.headers.get('content-length') ?? '0', 10);
|
|
83116
|
+
if (!response.body || !response.body.getReader) {
|
|
83117
|
+
const buf = await response.arrayBuffer();
|
|
83118
|
+
asset.fire('progress', buf.byteLength, totalLength);
|
|
83119
|
+
return buf;
|
|
83120
|
+
}
|
|
83121
|
+
const reader = response.body.getReader();
|
|
83122
|
+
const chunks = [];
|
|
83123
|
+
let totalReceived = 0;
|
|
83124
|
+
try {
|
|
83125
|
+
while(true){
|
|
83126
|
+
const { done, value } = await reader.read();
|
|
83127
|
+
if (done) {
|
|
83128
|
+
break;
|
|
83129
|
+
}
|
|
83130
|
+
chunks.push(value);
|
|
83131
|
+
totalReceived += value.byteLength;
|
|
83132
|
+
asset.fire('progress', totalReceived, totalLength);
|
|
83133
|
+
}
|
|
83134
|
+
} finally{
|
|
83135
|
+
reader.releaseLock();
|
|
83136
|
+
}
|
|
83137
|
+
return new Blob(chunks).arrayBuffer();
|
|
83138
|
+
}
|
|
83139
|
+
return response;
|
|
83140
|
+
};
|
|
82148
83141
|
class SogBundleParser {
|
|
82149
83142
|
constructor(app, maxRetries = 3){
|
|
82150
83143
|
this.app = app;
|
|
82151
83144
|
this.maxRetries = maxRetries;
|
|
82152
83145
|
}
|
|
82153
|
-
load(url, callback, asset) {
|
|
82154
|
-
|
|
83146
|
+
async load(url, callback, asset) {
|
|
83147
|
+
try {
|
|
83148
|
+
const arrayBuffer = await downloadArrayBuffer(url, asset);
|
|
82155
83149
|
const files = parseZipArchive(arrayBuffer);
|
|
82156
83150
|
for (const file of files){
|
|
82157
83151
|
if (file.compression === 'deflate') {
|
|
@@ -82209,6 +83203,13 @@ class SogBundleParser {
|
|
|
82209
83203
|
}
|
|
82210
83204
|
Object.values(textures).forEach((t)=>this.app.assets.load(t));
|
|
82211
83205
|
await Promise.allSettled(promises);
|
|
83206
|
+
const { assets } = this.app;
|
|
83207
|
+
asset.once('unload', ()=>{
|
|
83208
|
+
Object.values(textures).forEach((t)=>{
|
|
83209
|
+
assets.remove(t);
|
|
83210
|
+
t.unload();
|
|
83211
|
+
});
|
|
83212
|
+
});
|
|
82212
83213
|
const data = new GSplatSogsData();
|
|
82213
83214
|
data.meta = meta;
|
|
82214
83215
|
data.numSplats = meta.count;
|
|
@@ -82225,14 +83226,9 @@ class SogBundleParser {
|
|
|
82225
83226
|
}
|
|
82226
83227
|
const resource = decompress ? new GSplatResource(this.app.graphicsDevice, await data.decompress()) : new GSplatSogsResource(this.app.graphicsDevice, data);
|
|
82227
83228
|
callback(null, resource);
|
|
82228
|
-
}
|
|
82229
|
-
|
|
82230
|
-
|
|
82231
|
-
callback(error);
|
|
82232
|
-
} else {
|
|
82233
|
-
handleArrayBuffer(arrayBuffer);
|
|
82234
|
-
}
|
|
82235
|
-
}, asset, this.maxRetries);
|
|
83229
|
+
} catch (err) {
|
|
83230
|
+
callback(err);
|
|
83231
|
+
}
|
|
82236
83232
|
}
|
|
82237
83233
|
}
|
|
82238
83234
|
|
|
@@ -83822,6 +84818,13 @@ class Template {
|
|
|
83822
84818
|
const parser = new SceneParser(this._app, true);
|
|
83823
84819
|
this._templateRoot = parser.parse(this._data);
|
|
83824
84820
|
}
|
|
84821
|
+
set data(value) {
|
|
84822
|
+
this._data = value;
|
|
84823
|
+
this._templateRoot = null;
|
|
84824
|
+
}
|
|
84825
|
+
get data() {
|
|
84826
|
+
return this._data;
|
|
84827
|
+
}
|
|
83825
84828
|
}
|
|
83826
84829
|
|
|
83827
84830
|
class TemplateHandler extends ResourceHandler {
|
|
@@ -83854,6 +84857,13 @@ class TemplateHandler extends ResourceHandler {
|
|
|
83854
84857
|
this.decoder ??= new TextDecoder('utf-8');
|
|
83855
84858
|
return new Template(this._app, JSON.parse(this.decoder.decode(data)));
|
|
83856
84859
|
}
|
|
84860
|
+
patch(asset, registry) {
|
|
84861
|
+
if (!asset || !asset.resource || !asset.data || !asset.data.entities) {
|
|
84862
|
+
return;
|
|
84863
|
+
}
|
|
84864
|
+
const template = asset.resource;
|
|
84865
|
+
template.data = asset.data;
|
|
84866
|
+
}
|
|
83857
84867
|
}
|
|
83858
84868
|
|
|
83859
84869
|
class TextHandler extends ResourceHandler {
|
|
@@ -88684,7 +89694,8 @@ class MiniStats {
|
|
|
88684
89694
|
'7',
|
|
88685
89695
|
'8',
|
|
88686
89696
|
'9',
|
|
88687
|
-
'.'
|
|
89697
|
+
'.',
|
|
89698
|
+
'-'
|
|
88688
89699
|
].concat(this.graphs.map((graph)=>graph.name)).concat(options.stats ? options.stats.map((stat)=>stat.unitsName) : []).filter((item)=>!!item));
|
|
88689
89700
|
this.wordAtlas = new WordAtlas(device, words);
|
|
88690
89701
|
this.sizes = options.sizes;
|
|
@@ -89081,6 +90092,38 @@ class InputController extends InputConsumer {
|
|
|
89081
90092
|
const DOUBLE_TAP_THRESHOLD = 250;
|
|
89082
90093
|
const DOUBLE_TAP_VARIANCE = 100;
|
|
89083
90094
|
|
|
90095
|
+
const movementState = ()=>{
|
|
90096
|
+
const state = new Map();
|
|
90097
|
+
return {
|
|
90098
|
+
down: (event)=>{
|
|
90099
|
+
state.set(event.pointerId, [
|
|
90100
|
+
event.screenX,
|
|
90101
|
+
event.screenY
|
|
90102
|
+
]);
|
|
90103
|
+
},
|
|
90104
|
+
move: (event)=>{
|
|
90105
|
+
if (!state.has(event.pointerId)) {
|
|
90106
|
+
return [
|
|
90107
|
+
0,
|
|
90108
|
+
0
|
|
90109
|
+
];
|
|
90110
|
+
}
|
|
90111
|
+
const prev = state.get(event.pointerId);
|
|
90112
|
+
const mvX = event.screenX - prev[0];
|
|
90113
|
+
const mvY = event.screenY - prev[1];
|
|
90114
|
+
prev[0] = event.screenX;
|
|
90115
|
+
prev[1] = event.screenY;
|
|
90116
|
+
return [
|
|
90117
|
+
mvX,
|
|
90118
|
+
mvY
|
|
90119
|
+
];
|
|
90120
|
+
},
|
|
90121
|
+
up: (event)=>{
|
|
90122
|
+
state.delete(event.pointerId);
|
|
90123
|
+
}
|
|
90124
|
+
};
|
|
90125
|
+
};
|
|
90126
|
+
|
|
89084
90127
|
const v$1 = new Vec2();
|
|
89085
90128
|
class VirtualJoystick {
|
|
89086
90129
|
constructor({ range } = {}){
|
|
@@ -89144,7 +90187,7 @@ class DualGestureSource extends InputSource {
|
|
|
89144
90187
|
doubleTap: [
|
|
89145
90188
|
0
|
|
89146
90189
|
]
|
|
89147
|
-
}), this._layout = 'joystick-touch', this._pointerData = new Map(), this._lastPointer = {
|
|
90190
|
+
}), this._movementState = movementState(), this._layout = 'joystick-touch', this._pointerData = new Map(), this._lastPointer = {
|
|
89148
90191
|
x: 0,
|
|
89149
90192
|
y: 0,
|
|
89150
90193
|
time: 0
|
|
@@ -89177,6 +90220,7 @@ class DualGestureSource extends InputSource {
|
|
|
89177
90220
|
}
|
|
89178
90221
|
_onPointerDown(event) {
|
|
89179
90222
|
const { pointerType, pointerId, clientX, clientY } = event;
|
|
90223
|
+
this._movementState.down(event);
|
|
89180
90224
|
if (pointerType !== 'touch') {
|
|
89181
90225
|
return;
|
|
89182
90226
|
}
|
|
@@ -89205,7 +90249,8 @@ class DualGestureSource extends InputSource {
|
|
|
89205
90249
|
}
|
|
89206
90250
|
}
|
|
89207
90251
|
_onPointerMove(event) {
|
|
89208
|
-
const { pointerType, pointerId, target, clientX, clientY
|
|
90252
|
+
const { pointerType, pointerId, target, clientX, clientY } = event;
|
|
90253
|
+
const [movementX, movementY] = this._movementState.move(event);
|
|
89209
90254
|
if (pointerType !== 'touch') {
|
|
89210
90255
|
return;
|
|
89211
90256
|
}
|
|
@@ -89241,6 +90286,7 @@ class DualGestureSource extends InputSource {
|
|
|
89241
90286
|
}
|
|
89242
90287
|
_onPointerUp(event) {
|
|
89243
90288
|
const { pointerType, pointerId } = event;
|
|
90289
|
+
this._movementState.up(event);
|
|
89244
90290
|
if (pointerType !== 'touch') {
|
|
89245
90291
|
return;
|
|
89246
90292
|
}
|
|
@@ -89309,7 +90355,7 @@ class MultiTouchSource extends InputSource {
|
|
|
89309
90355
|
pinch: [
|
|
89310
90356
|
0
|
|
89311
90357
|
]
|
|
89312
|
-
}), this._pointerEvents = new Map(), this._pointerPos = new Vec2(), this._pinchDist = -1;
|
|
90358
|
+
}), this._movementState = movementState(), this._pointerEvents = new Map(), this._pointerPos = new Vec2(), this._pinchDist = -1;
|
|
89313
90359
|
this._onPointerDown = this._onPointerDown.bind(this);
|
|
89314
90360
|
this._onPointerMove = this._onPointerMove.bind(this);
|
|
89315
90361
|
this._onPointerUp = this._onPointerUp.bind(this);
|
|
@@ -89317,6 +90363,7 @@ class MultiTouchSource extends InputSource {
|
|
|
89317
90363
|
}
|
|
89318
90364
|
_onPointerDown(event) {
|
|
89319
90365
|
const { pointerId, pointerType } = event;
|
|
90366
|
+
this._movementState.down(event);
|
|
89320
90367
|
if (pointerType !== 'touch') {
|
|
89321
90368
|
return;
|
|
89322
90369
|
}
|
|
@@ -89331,7 +90378,8 @@ class MultiTouchSource extends InputSource {
|
|
|
89331
90378
|
}
|
|
89332
90379
|
}
|
|
89333
90380
|
_onPointerMove(event) {
|
|
89334
|
-
const { pointerType, target, pointerId
|
|
90381
|
+
const { pointerType, target, pointerId } = event;
|
|
90382
|
+
const [movementX, movementY] = this._movementState.move(event);
|
|
89335
90383
|
if (pointerType !== 'touch') {
|
|
89336
90384
|
return;
|
|
89337
90385
|
}
|
|
@@ -89365,6 +90413,7 @@ class MultiTouchSource extends InputSource {
|
|
|
89365
90413
|
}
|
|
89366
90414
|
_onPointerUp(event) {
|
|
89367
90415
|
const { pointerType, pointerId } = event;
|
|
90416
|
+
this._movementState.up(event);
|
|
89368
90417
|
if (pointerType !== 'touch') {
|
|
89369
90418
|
return;
|
|
89370
90419
|
}
|
|
@@ -89491,7 +90540,7 @@ class KeyboardMouseSource extends InputSource {
|
|
|
89491
90540
|
wheel: [
|
|
89492
90541
|
0
|
|
89493
90542
|
]
|
|
89494
|
-
}), this._pointerId = -1, this._keyMap = new Map(), this._keyPrev = Array(KEY_COUNT).fill(0), this._keyNow = Array(KEY_COUNT).fill(0), this._button = Array(3).fill(0);
|
|
90543
|
+
}), this._movementState = movementState(), this._pointerId = -1, this._keyMap = new Map(), this._keyPrev = Array(KEY_COUNT).fill(0), this._keyNow = Array(KEY_COUNT).fill(0), this._button = Array(3).fill(0);
|
|
89495
90544
|
this._pointerLock = pointerLock ?? false;
|
|
89496
90545
|
const { keyCode } = KeyboardMouseSource;
|
|
89497
90546
|
for(let i = 0; i < 26; i++){
|
|
@@ -89526,6 +90575,7 @@ class KeyboardMouseSource extends InputSource {
|
|
|
89526
90575
|
]);
|
|
89527
90576
|
}
|
|
89528
90577
|
_onPointerDown(event) {
|
|
90578
|
+
this._movementState.down(event);
|
|
89529
90579
|
if (event.pointerType !== 'mouse') {
|
|
89530
90580
|
return;
|
|
89531
90581
|
}
|
|
@@ -89545,6 +90595,7 @@ class KeyboardMouseSource extends InputSource {
|
|
|
89545
90595
|
this._pointerId = event.pointerId;
|
|
89546
90596
|
}
|
|
89547
90597
|
_onPointerMove(event) {
|
|
90598
|
+
const [movementX, movementY] = this._movementState.move(event);
|
|
89548
90599
|
if (event.pointerType !== 'mouse') {
|
|
89549
90600
|
return;
|
|
89550
90601
|
}
|
|
@@ -89561,11 +90612,12 @@ class KeyboardMouseSource extends InputSource {
|
|
|
89561
90612
|
}
|
|
89562
90613
|
}
|
|
89563
90614
|
this.deltas.mouse.append([
|
|
89564
|
-
|
|
89565
|
-
|
|
90615
|
+
movementX,
|
|
90616
|
+
movementY
|
|
89566
90617
|
]);
|
|
89567
90618
|
}
|
|
89568
90619
|
_onPointerUp(event) {
|
|
90620
|
+
this._movementState.up(event);
|
|
89569
90621
|
if (event.pointerType !== 'mouse') {
|
|
89570
90622
|
return;
|
|
89571
90623
|
}
|
|
@@ -94800,37 +95852,201 @@ class XrControllers extends Script {
|
|
|
94800
95852
|
/** @import { XrInputSource } from 'playcanvas' */
|
|
94801
95853
|
|
|
94802
95854
|
/**
|
|
94803
|
-
* Handles VR
|
|
94804
|
-
*
|
|
94805
|
-
*
|
|
94806
|
-
*
|
|
95855
|
+
* Handles VR navigation with support for both teleportation and smooth locomotion.
|
|
95856
|
+
* Both methods can be enabled simultaneously, allowing users to choose their preferred
|
|
95857
|
+
* navigation method on the fly.
|
|
95858
|
+
*
|
|
95859
|
+
* Teleportation: Point and teleport using trigger/pinch gestures
|
|
95860
|
+
* Smooth Locomotion: Use left thumbstick for movement and right thumbstick for snap turning
|
|
94807
95861
|
*
|
|
94808
95862
|
* This script should be attached to a parent entity of the camera entity used for the XR
|
|
94809
|
-
* session.
|
|
94810
|
-
* the
|
|
95863
|
+
* session. The entity hierarchy should be: XrNavigationEntity > CameraEntity for proper
|
|
95864
|
+
* locomotion handling. Use it in conjunction with the `XrControllers` script.
|
|
94811
95865
|
*/
|
|
94812
95866
|
class XrNavigation extends Script {
|
|
94813
95867
|
static scriptName = 'xrNavigation';
|
|
94814
95868
|
|
|
95869
|
+
/**
|
|
95870
|
+
* Enable teleportation navigation using trigger/pinch gestures.
|
|
95871
|
+
* @attribute
|
|
95872
|
+
*/
|
|
95873
|
+
enableTeleport = true;
|
|
95874
|
+
|
|
95875
|
+
/**
|
|
95876
|
+
* Enable smooth locomotion using thumbsticks.
|
|
95877
|
+
* @attribute
|
|
95878
|
+
*/
|
|
95879
|
+
enableMove = true;
|
|
95880
|
+
|
|
95881
|
+
/**
|
|
95882
|
+
* Speed of smooth locomotion movement in meters per second.
|
|
95883
|
+
* @attribute
|
|
95884
|
+
* @range [0.1, 10]
|
|
95885
|
+
* @enabledif {enableMove}
|
|
95886
|
+
*/
|
|
95887
|
+
movementSpeed = 1.5;
|
|
95888
|
+
|
|
95889
|
+
/**
|
|
95890
|
+
* Angle in degrees for each snap turn.
|
|
95891
|
+
* @attribute
|
|
95892
|
+
* @range [15, 180]
|
|
95893
|
+
* @enabledif {enableMove}
|
|
95894
|
+
*/
|
|
95895
|
+
rotateSpeed = 45;
|
|
95896
|
+
|
|
95897
|
+
/**
|
|
95898
|
+
* Thumbstick deadzone threshold for movement.
|
|
95899
|
+
* @attribute
|
|
95900
|
+
* @range [0, 0.5]
|
|
95901
|
+
* @precision 0.01
|
|
95902
|
+
* @enabledif {enableMove}
|
|
95903
|
+
*/
|
|
95904
|
+
movementThreshold = 0.1;
|
|
95905
|
+
|
|
95906
|
+
/**
|
|
95907
|
+
* Thumbstick threshold to trigger snap turning.
|
|
95908
|
+
* @attribute
|
|
95909
|
+
* @range [0.1, 1]
|
|
95910
|
+
* @precision 0.01
|
|
95911
|
+
* @enabledif {enableMove}
|
|
95912
|
+
*/
|
|
95913
|
+
rotateThreshold = 0.5;
|
|
95914
|
+
|
|
95915
|
+
/**
|
|
95916
|
+
* Thumbstick threshold to reset snap turn state.
|
|
95917
|
+
* @attribute
|
|
95918
|
+
* @range [0.05, 0.5]
|
|
95919
|
+
* @precision 0.01
|
|
95920
|
+
* @enabledif {enableMove}
|
|
95921
|
+
*/
|
|
95922
|
+
rotateResetThreshold = 0.25;
|
|
95923
|
+
|
|
95924
|
+
/**
|
|
95925
|
+
* Maximum distance for teleportation in meters.
|
|
95926
|
+
* @attribute
|
|
95927
|
+
* @range [1, 50]
|
|
95928
|
+
* @enabledif {enableTeleport}
|
|
95929
|
+
*/
|
|
95930
|
+
maxTeleportDistance = 10;
|
|
95931
|
+
|
|
95932
|
+
/**
|
|
95933
|
+
* Radius of the teleport target indicator circle.
|
|
95934
|
+
* @attribute
|
|
95935
|
+
* @range [0.1, 2]
|
|
95936
|
+
* @precision 0.1
|
|
95937
|
+
* @enabledif {enableTeleport}
|
|
95938
|
+
*/
|
|
95939
|
+
teleportIndicatorRadius = 0.2;
|
|
95940
|
+
|
|
95941
|
+
/**
|
|
95942
|
+
* Number of segments for the teleport indicator circle.
|
|
95943
|
+
* @attribute
|
|
95944
|
+
* @range [8, 64]
|
|
95945
|
+
* @enabledif {enableTeleport}
|
|
95946
|
+
*/
|
|
95947
|
+
teleportIndicatorSegments = 16;
|
|
95948
|
+
|
|
95949
|
+
/**
|
|
95950
|
+
* Color for valid teleportation areas.
|
|
95951
|
+
* @attribute
|
|
95952
|
+
* @enabledif {enableTeleport}
|
|
95953
|
+
*/
|
|
95954
|
+
validTeleportColor = new Color(0, 1, 0);
|
|
95955
|
+
|
|
95956
|
+
/**
|
|
95957
|
+
* Color for invalid teleportation areas.
|
|
95958
|
+
* @attribute
|
|
95959
|
+
* @enabledif {enableTeleport}
|
|
95960
|
+
*/
|
|
95961
|
+
invalidTeleportColor = new Color(1, 0, 0);
|
|
95962
|
+
|
|
95963
|
+
/**
|
|
95964
|
+
* Color for controller rays.
|
|
95965
|
+
* @attribute
|
|
95966
|
+
* @enabledif {enableMove}
|
|
95967
|
+
*/
|
|
95968
|
+
controllerRayColor = new Color(1, 1, 1);
|
|
95969
|
+
|
|
94815
95970
|
/** @type {Set<XrInputSource>} */
|
|
94816
95971
|
inputSources = new Set();
|
|
94817
95972
|
|
|
94818
95973
|
/** @type {Map<XrInputSource, boolean>} */
|
|
94819
95974
|
activePointers = new Map();
|
|
94820
95975
|
|
|
94821
|
-
validColor = new Color(0, 1, 0); // Green for valid teleport
|
|
94822
|
-
|
|
94823
|
-
invalidColor = new Color(1, 0, 0); // Red for invalid teleport
|
|
94824
|
-
|
|
94825
95976
|
/** @type {Map<XrInputSource, { handleSelectStart: Function, handleSelectEnd: Function }>} */
|
|
94826
95977
|
inputHandlers = new Map();
|
|
94827
95978
|
|
|
95979
|
+
// Rotation state for snap turning
|
|
95980
|
+
lastRotateValue = 0;
|
|
95981
|
+
|
|
95982
|
+
// Pre-allocated objects for performance (object pooling)
|
|
95983
|
+
tmpVec2A = new Vec2();
|
|
95984
|
+
|
|
95985
|
+
tmpVec2B = new Vec2();
|
|
95986
|
+
|
|
95987
|
+
tmpVec3A = new Vec3();
|
|
95988
|
+
|
|
95989
|
+
tmpVec3B = new Vec3();
|
|
95990
|
+
|
|
95991
|
+
// Color objects
|
|
95992
|
+
validColor = new Color();
|
|
95993
|
+
|
|
95994
|
+
invalidColor = new Color();
|
|
95995
|
+
|
|
95996
|
+
rayColor = new Color();
|
|
95997
|
+
|
|
95998
|
+
// Camera reference for movement calculations
|
|
95999
|
+
/** @type {import('playcanvas').Entity | null} */
|
|
96000
|
+
cameraEntity = null;
|
|
96001
|
+
|
|
94828
96002
|
initialize() {
|
|
94829
96003
|
if (!this.app.xr) {
|
|
94830
96004
|
console.error('XrNavigation script requires XR to be enabled on the application');
|
|
94831
96005
|
return;
|
|
94832
96006
|
}
|
|
94833
96007
|
|
|
96008
|
+
// Log enabled navigation methods
|
|
96009
|
+
const methods = [];
|
|
96010
|
+
if (this.enableTeleport) methods.push('teleportation');
|
|
96011
|
+
if (this.enableMove) methods.push('smooth movement');
|
|
96012
|
+
console.log(`XrNavigation: Enabled methods - ${methods.join(', ')}`);
|
|
96013
|
+
|
|
96014
|
+
if (!this.enableTeleport && !this.enableMove) {
|
|
96015
|
+
console.warn('XrNavigation: Both teleportation and movement are disabled. Navigation will not work.');
|
|
96016
|
+
}
|
|
96017
|
+
|
|
96018
|
+
// Initialize color objects from Color attributes
|
|
96019
|
+
this.validColor.copy(this.validTeleportColor);
|
|
96020
|
+
this.invalidColor.copy(this.invalidTeleportColor);
|
|
96021
|
+
this.rayColor.copy(this.controllerRayColor);
|
|
96022
|
+
|
|
96023
|
+
// Find camera entity - should be a child of this entity
|
|
96024
|
+
const cameraComponent = this.entity.findComponent('camera');
|
|
96025
|
+
this.cameraEntity = cameraComponent ? cameraComponent.entity : null;
|
|
96026
|
+
|
|
96027
|
+
if (!this.cameraEntity) {
|
|
96028
|
+
console.warn('XrNavigation: Camera entity not found. Looking for camera in children...');
|
|
96029
|
+
|
|
96030
|
+
// First try to find by name - cast to Entity since we know it should be one
|
|
96031
|
+
const foundByName = this.entity.findByName('camera');
|
|
96032
|
+
this.cameraEntity = /** @type {import('playcanvas').Entity | null} */ (foundByName);
|
|
96033
|
+
|
|
96034
|
+
// If not found, search children for entity with camera component
|
|
96035
|
+
if (!this.cameraEntity) {
|
|
96036
|
+
for (const child of this.entity.children) {
|
|
96037
|
+
const childEntity = /** @type {import('playcanvas').Entity} */ (child);
|
|
96038
|
+
if (childEntity.camera) {
|
|
96039
|
+
this.cameraEntity = childEntity;
|
|
96040
|
+
break;
|
|
96041
|
+
}
|
|
96042
|
+
}
|
|
96043
|
+
}
|
|
96044
|
+
|
|
96045
|
+
if (!this.cameraEntity) {
|
|
96046
|
+
console.error('XrNavigation: No camera entity found. Movement calculations may not work correctly.');
|
|
96047
|
+
}
|
|
96048
|
+
}
|
|
96049
|
+
|
|
94834
96050
|
this.app.xr.input.on('add', (inputSource) => {
|
|
94835
96051
|
const handleSelectStart = () => {
|
|
94836
96052
|
this.activePointers.set(inputSource, true);
|
|
@@ -94888,9 +96104,91 @@ class XrNavigation extends Script {
|
|
|
94888
96104
|
}
|
|
94889
96105
|
}
|
|
94890
96106
|
|
|
94891
|
-
update() {
|
|
96107
|
+
update(dt) {
|
|
96108
|
+
// Handle smooth locomotion and snap turning
|
|
96109
|
+
if (this.enableMove) {
|
|
96110
|
+
this.handleSmoothLocomotion(dt);
|
|
96111
|
+
}
|
|
96112
|
+
|
|
96113
|
+
// Handle teleportation
|
|
96114
|
+
if (this.enableTeleport) {
|
|
96115
|
+
this.handleTeleportation();
|
|
96116
|
+
}
|
|
96117
|
+
|
|
96118
|
+
// Always show controller rays for debugging/visualization
|
|
96119
|
+
this.renderControllerRays();
|
|
96120
|
+
}
|
|
96121
|
+
|
|
96122
|
+
handleSmoothLocomotion(dt) {
|
|
96123
|
+
if (!this.cameraEntity) return;
|
|
96124
|
+
|
|
94892
96125
|
for (const inputSource of this.inputSources) {
|
|
94893
|
-
// Only
|
|
96126
|
+
// Only process controllers with gamepads
|
|
96127
|
+
if (!inputSource.gamepad) continue;
|
|
96128
|
+
|
|
96129
|
+
// Left controller - movement
|
|
96130
|
+
if (inputSource.handedness === 'left') {
|
|
96131
|
+
// Get thumbstick input (axes[2] = X, axes[3] = Y)
|
|
96132
|
+
this.tmpVec2A.set(inputSource.gamepad.axes[2], inputSource.gamepad.axes[3]);
|
|
96133
|
+
|
|
96134
|
+
// Check if input exceeds deadzone
|
|
96135
|
+
if (this.tmpVec2A.length() > this.movementThreshold) {
|
|
96136
|
+
this.tmpVec2A.normalize();
|
|
96137
|
+
|
|
96138
|
+
// Calculate camera-relative movement direction
|
|
96139
|
+
const forward = this.cameraEntity.forward;
|
|
96140
|
+
this.tmpVec2B.x = forward.x;
|
|
96141
|
+
this.tmpVec2B.y = forward.z;
|
|
96142
|
+
this.tmpVec2B.normalize();
|
|
96143
|
+
|
|
96144
|
+
// Calculate rotation angle based on camera yaw
|
|
96145
|
+
const rad = Math.atan2(this.tmpVec2B.x, this.tmpVec2B.y) - Math.PI / 2;
|
|
96146
|
+
|
|
96147
|
+
// Apply rotation to movement vector
|
|
96148
|
+
const t = this.tmpVec2A.x * Math.sin(rad) - this.tmpVec2A.y * Math.cos(rad);
|
|
96149
|
+
this.tmpVec2A.y = this.tmpVec2A.y * Math.sin(rad) + this.tmpVec2A.x * Math.cos(rad);
|
|
96150
|
+
this.tmpVec2A.x = t;
|
|
96151
|
+
|
|
96152
|
+
// Scale by movement speed and delta time
|
|
96153
|
+
this.tmpVec2A.mulScalar(this.movementSpeed * dt);
|
|
96154
|
+
|
|
96155
|
+
// Apply movement to camera parent (this entity)
|
|
96156
|
+
this.entity.translate(this.tmpVec2A.x, 0, this.tmpVec2A.y);
|
|
96157
|
+
}
|
|
96158
|
+
} else if (inputSource.handedness === 'right') { // Right controller - snap turning
|
|
96159
|
+
this.handleSnapTurning(inputSource);
|
|
96160
|
+
}
|
|
96161
|
+
}
|
|
96162
|
+
}
|
|
96163
|
+
|
|
96164
|
+
handleSnapTurning(inputSource) {
|
|
96165
|
+
// Get rotation input from right thumbstick X-axis
|
|
96166
|
+
const rotate = -inputSource.gamepad.axes[2];
|
|
96167
|
+
|
|
96168
|
+
// Hysteresis system to prevent multiple rotations from single gesture
|
|
96169
|
+
if (this.lastRotateValue > 0 && rotate < this.rotateResetThreshold) {
|
|
96170
|
+
this.lastRotateValue = 0;
|
|
96171
|
+
} else if (this.lastRotateValue < 0 && rotate > -this.rotateResetThreshold) {
|
|
96172
|
+
this.lastRotateValue = 0;
|
|
96173
|
+
}
|
|
96174
|
+
|
|
96175
|
+
// Only rotate when thumbstick crosses threshold from neutral position
|
|
96176
|
+
if (this.lastRotateValue === 0 && Math.abs(rotate) > this.rotateThreshold) {
|
|
96177
|
+
this.lastRotateValue = Math.sign(rotate);
|
|
96178
|
+
|
|
96179
|
+
if (this.cameraEntity) {
|
|
96180
|
+
// Rotate around camera position, not entity origin
|
|
96181
|
+
this.tmpVec3A.copy(this.cameraEntity.getLocalPosition());
|
|
96182
|
+
this.entity.translateLocal(this.tmpVec3A);
|
|
96183
|
+
this.entity.rotateLocal(0, Math.sign(rotate) * this.rotateSpeed, 0);
|
|
96184
|
+
this.entity.translateLocal(this.tmpVec3A.mulScalar(-1));
|
|
96185
|
+
}
|
|
96186
|
+
}
|
|
96187
|
+
}
|
|
96188
|
+
|
|
96189
|
+
handleTeleportation() {
|
|
96190
|
+
for (const inputSource of this.inputSources) {
|
|
96191
|
+
// Only show teleportation ray when trigger/select is pressed
|
|
94894
96192
|
if (!this.activePointers.get(inputSource)) continue;
|
|
94895
96193
|
|
|
94896
96194
|
const start = inputSource.getOrigin();
|
|
@@ -94898,24 +96196,42 @@ class XrNavigation extends Script {
|
|
|
94898
96196
|
|
|
94899
96197
|
const hitPoint = this.findPlaneIntersection(start, direction);
|
|
94900
96198
|
|
|
94901
|
-
if (hitPoint) {
|
|
96199
|
+
if (hitPoint && this.isValidTeleportDistance(hitPoint)) {
|
|
94902
96200
|
// Draw line to intersection point
|
|
94903
96201
|
this.app.drawLine(start, hitPoint, this.validColor);
|
|
94904
96202
|
this.drawTeleportIndicator(hitPoint);
|
|
94905
96203
|
} else {
|
|
94906
|
-
// Draw full length ray if no intersection
|
|
94907
|
-
|
|
94908
|
-
|
|
94909
|
-
);
|
|
94910
|
-
this.app.drawLine(start, end, this.invalidColor);
|
|
96204
|
+
// Draw full length ray if no intersection or invalid distance
|
|
96205
|
+
this.tmpVec3B.copy(direction).mulScalar(this.maxTeleportDistance).add(start);
|
|
96206
|
+
this.app.drawLine(start, this.tmpVec3B, this.invalidColor);
|
|
94911
96207
|
}
|
|
94912
96208
|
}
|
|
94913
96209
|
}
|
|
94914
96210
|
|
|
96211
|
+
renderControllerRays() {
|
|
96212
|
+
// Only render controller rays when smooth movement is enabled
|
|
96213
|
+
// (teleport rays are handled separately in handleTeleportation)
|
|
96214
|
+
if (!this.enableMove) return;
|
|
96215
|
+
|
|
96216
|
+
for (const inputSource of this.inputSources) {
|
|
96217
|
+
// Skip if currently teleporting (handled by handleTeleportation)
|
|
96218
|
+
if (this.activePointers.get(inputSource)) continue;
|
|
96219
|
+
|
|
96220
|
+
const start = inputSource.getOrigin();
|
|
96221
|
+
this.tmpVec3B.copy(inputSource.getDirection()).mulScalar(2).add(start);
|
|
96222
|
+
this.app.drawLine(start, this.tmpVec3B, this.rayColor);
|
|
96223
|
+
}
|
|
96224
|
+
}
|
|
96225
|
+
|
|
96226
|
+
isValidTeleportDistance(hitPoint) {
|
|
96227
|
+
const distance = hitPoint.distance(this.entity.getPosition());
|
|
96228
|
+
return distance <= this.maxTeleportDistance;
|
|
96229
|
+
}
|
|
96230
|
+
|
|
94915
96231
|
drawTeleportIndicator(point) {
|
|
94916
|
-
// Draw a circle at the teleport point
|
|
94917
|
-
const segments =
|
|
94918
|
-
const radius =
|
|
96232
|
+
// Draw a circle at the teleport point using configurable attributes
|
|
96233
|
+
const segments = this.teleportIndicatorSegments;
|
|
96234
|
+
const radius = this.teleportIndicatorRadius;
|
|
94919
96235
|
|
|
94920
96236
|
for (let i = 0; i < segments; i++) {
|
|
94921
96237
|
const angle1 = (i / segments) * Math.PI * 2;
|
|
@@ -94926,11 +96242,11 @@ class XrNavigation extends Script {
|
|
|
94926
96242
|
const x2 = point.x + Math.cos(angle2) * radius;
|
|
94927
96243
|
const z2 = point.z + Math.sin(angle2) * radius;
|
|
94928
96244
|
|
|
94929
|
-
|
|
94930
|
-
|
|
94931
|
-
|
|
94932
|
-
|
|
94933
|
-
);
|
|
96245
|
+
// Use pre-allocated vectors to avoid garbage collection
|
|
96246
|
+
this.tmpVec3A.set(x1, 0.01, z1); // Slightly above ground to avoid z-fighting
|
|
96247
|
+
this.tmpVec3B.set(x2, 0.01, z2);
|
|
96248
|
+
|
|
96249
|
+
this.app.drawLine(this.tmpVec3A, this.tmpVec3B, this.validColor);
|
|
94934
96250
|
}
|
|
94935
96251
|
}
|
|
94936
96252
|
}
|