@playcanvas/supersplat-viewer 1.6.2 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -37
- package/dist/index.js +1 -1
- package/package.json +21 -21
- package/public/index.js +1694 -429
- 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.1';
|
|
4
|
+
const revision = 'fd94a5b';
|
|
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);
|
|
18593
18774
|
}
|
|
18594
|
-
setIndirect(camera, slot) {
|
|
18595
|
-
|
|
18596
|
-
|
|
18597
|
-
|
|
18598
|
-
|
|
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
|
+
}
|
|
18818
|
+
}
|
|
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,22 @@ class GSplatSogsData {
|
|
|
35056
35424
|
this.packShMemory();
|
|
35057
35425
|
}
|
|
35058
35426
|
});
|
|
35427
|
+
if (this.destroyed || device._destroyed) return;
|
|
35428
|
+
await this.generateCenters();
|
|
35429
|
+
if (this.destroyed || device._destroyed) return;
|
|
35059
35430
|
this.packGpuMemory();
|
|
35060
35431
|
if (this.packedShN) {
|
|
35432
|
+
if (this.destroyed || device._destroyed) return;
|
|
35061
35433
|
this.packShMemory();
|
|
35062
35434
|
}
|
|
35063
35435
|
}
|
|
35064
35436
|
reorderData() {
|
|
35065
35437
|
return this.prepareGpuData();
|
|
35066
35438
|
}
|
|
35439
|
+
constructor(){
|
|
35440
|
+
this._centers = null;
|
|
35441
|
+
this.destroyed = false;
|
|
35442
|
+
}
|
|
35067
35443
|
}
|
|
35068
35444
|
|
|
35069
35445
|
const mat = new Mat4();
|
|
@@ -35116,6 +35492,7 @@ class GSplatInstance {
|
|
|
35116
35492
|
this.setHighQualitySH(options.highQualitySH ?? false);
|
|
35117
35493
|
}
|
|
35118
35494
|
destroy() {
|
|
35495
|
+
this.orderTexture?.destroy();
|
|
35119
35496
|
this.resolveSH?.destroy();
|
|
35120
35497
|
this.material?.destroy();
|
|
35121
35498
|
this.meshInstance?.destroy();
|
|
@@ -35853,10 +36230,7 @@ class Asset extends EventHandler {
|
|
|
35853
36230
|
this.registry._loader.clearCache(this.getFileUrl(), this.type);
|
|
35854
36231
|
}
|
|
35855
36232
|
for(let i = 0; i < old.length; ++i){
|
|
35856
|
-
|
|
35857
|
-
if (resource && resource.destroy) {
|
|
35858
|
-
resource.destroy();
|
|
35859
|
-
}
|
|
36233
|
+
old[i]?.destroy?.();
|
|
35860
36234
|
}
|
|
35861
36235
|
}
|
|
35862
36236
|
static fetchArrayBuffer(loadUrl, callback, asset, maxRetries = 0) {
|
|
@@ -37780,6 +38154,7 @@ class ApplicationStats {
|
|
|
37780
38154
|
morphTime: 0,
|
|
37781
38155
|
instancingTime: 0,
|
|
37782
38156
|
triangles: 0,
|
|
38157
|
+
gsplats: 0,
|
|
37783
38158
|
otherPrimitives: 0,
|
|
37784
38159
|
shaders: 0,
|
|
37785
38160
|
materials: 0,
|
|
@@ -39651,20 +40026,19 @@ var gsplatPS$1 = `
|
|
|
39651
40026
|
varying float vLinearDepth;
|
|
39652
40027
|
#include "floatAsUintPS"
|
|
39653
40028
|
#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
40029
|
varying mediump vec2 gaussianUV;
|
|
39661
40030
|
varying mediump vec4 gaussianColor;
|
|
40031
|
+
const float EXP4 = exp(-4.0);
|
|
40032
|
+
const float INV_EXP4 = 1.0 / (1.0 - EXP4);
|
|
40033
|
+
float normExp(float x) {
|
|
40034
|
+
return (exp(x * -4.0) - EXP4) * INV_EXP4;
|
|
40035
|
+
}
|
|
39662
40036
|
void main(void) {
|
|
39663
40037
|
mediump float A = dot(gaussianUV, gaussianUV);
|
|
39664
40038
|
if (A > 1.0) {
|
|
39665
40039
|
discard;
|
|
39666
40040
|
}
|
|
39667
|
-
mediump float alpha =
|
|
40041
|
+
mediump float alpha = normExp(A) * gaussianColor.a;
|
|
39668
40042
|
#if defined(SHADOW_PASS) || defined(PICK_PASS) || defined(PREPASS_PASS)
|
|
39669
40043
|
if (alpha < alphaClip) {
|
|
39670
40044
|
discard;
|
|
@@ -44251,7 +44625,7 @@ var clusteredLightPS = `
|
|
|
44251
44625
|
#include "clusteredLightShadowsPS"
|
|
44252
44626
|
#endif
|
|
44253
44627
|
var clusterWorldTexture: texture_2d<f32>;
|
|
44254
|
-
var lightsTexture: texture_2d<
|
|
44628
|
+
var lightsTexture: texture_2d<uff>;
|
|
44255
44629
|
#ifdef CLUSTER_SHADOWS
|
|
44256
44630
|
var shadowAtlasTexture: texture_depth_2d;
|
|
44257
44631
|
var shadowAtlasTextureSampler: sampler_comparison;
|
|
@@ -45166,7 +45540,7 @@ fn initCenter(modelCenter: vec3f, center: ptr<function, SplatCenter>) -> bool {
|
|
|
45166
45540
|
`;
|
|
45167
45541
|
|
|
45168
45542
|
var gsplatColorVS = `
|
|
45169
|
-
var splatColor: texture_2d<
|
|
45543
|
+
var splatColor: texture_2d<uff>;
|
|
45170
45544
|
fn readColor(source: ptr<function, SplatSource>) -> vec4f {
|
|
45171
45545
|
return textureLoad(splatColor, source.uv, 0);
|
|
45172
45546
|
}
|
|
@@ -45190,7 +45564,7 @@ fn clipCorner(corner: ptr<function, SplatCorner>, alpha: f32) {
|
|
|
45190
45564
|
|
|
45191
45565
|
var gsplatCompressedDataVS = `
|
|
45192
45566
|
var packedTexture: texture_2d<u32>;
|
|
45193
|
-
var chunkTexture: texture_2d<
|
|
45567
|
+
var chunkTexture: texture_2d<uff>;
|
|
45194
45568
|
var<private> chunkDataA: vec4f;
|
|
45195
45569
|
var<private> chunkDataB: vec4f;
|
|
45196
45570
|
var<private> chunkDataC: vec4f;
|
|
@@ -45558,7 +45932,7 @@ fn initCorner(source: ptr<function, SplatSource>, center: ptr<function, SplatCen
|
|
|
45558
45932
|
|
|
45559
45933
|
var gsplatDataVS = `
|
|
45560
45934
|
var transformA: texture_2d<u32>;
|
|
45561
|
-
var transformB: texture_2d<
|
|
45935
|
+
var transformB: texture_2d<uff>;
|
|
45562
45936
|
var<private> tAw: u32;
|
|
45563
45937
|
fn readCenter(source: ptr<function, SplatSource>) -> vec3f {
|
|
45564
45938
|
let tA: vec4<u32> = textureLoad(transformA, source.uv, 0);
|
|
@@ -45615,11 +45989,10 @@ var gsplatPS = `
|
|
|
45615
45989
|
varying vLinearDepth: f32;
|
|
45616
45990
|
#include "floatAsUintPS"
|
|
45617
45991
|
#endif
|
|
45618
|
-
const
|
|
45619
|
-
const
|
|
45620
|
-
fn
|
|
45621
|
-
|
|
45622
|
-
return bitcast<f32>(i);
|
|
45992
|
+
const EXP4 = exp(-4.0);
|
|
45993
|
+
const INV_EXP4 = 1.0 / (1.0 - EXP4);
|
|
45994
|
+
fn normExp(x: f32) -> f32 {
|
|
45995
|
+
return (exp(x * -4.0) - EXP4) * INV_EXP4;
|
|
45623
45996
|
}
|
|
45624
45997
|
varying gaussianUV: vec2f;
|
|
45625
45998
|
varying gaussianColor: vec4f;
|
|
@@ -45631,7 +46004,7 @@ fn fragmentMain(input: FragmentInput) -> FragmentOutput {
|
|
|
45631
46004
|
discard;
|
|
45632
46005
|
return output;
|
|
45633
46006
|
}
|
|
45634
|
-
var alpha
|
|
46007
|
+
var alpha = normExp(A) * gaussianColor.a;
|
|
45635
46008
|
#if defined(SHADOW_PASS) || defined(PICK_PASS) || defined(PREPASS_PASS)
|
|
45636
46009
|
if (alpha < uniform.alphaClip) {
|
|
45637
46010
|
discard;
|
|
@@ -45826,10 +46199,10 @@ fn vertexMain(input: VertexInput) -> VertexOutput {
|
|
|
45826
46199
|
`;
|
|
45827
46200
|
|
|
45828
46201
|
var gsplatWorkBufferVS = `
|
|
45829
|
-
var center: texture_2d<
|
|
45830
|
-
var covA: texture_2d<
|
|
45831
|
-
var covB: texture_2d<
|
|
45832
|
-
var splatColor: texture_2d<
|
|
46202
|
+
var center: texture_2d<uff>;
|
|
46203
|
+
var covA: texture_2d<uff>;
|
|
46204
|
+
var covB: texture_2d<uff>;
|
|
46205
|
+
var splatColor: texture_2d<uff>;
|
|
45833
46206
|
fn readCenter(source: ptr<function, SplatSource>) -> vec3f {
|
|
45834
46207
|
return textureLoad(center, source.uv, 0).xyz;
|
|
45835
46208
|
}
|
|
@@ -48342,8 +48715,7 @@ fn vertexMain(input: VertexInput) -> VertexOutput {
|
|
|
48342
48715
|
`;
|
|
48343
48716
|
|
|
48344
48717
|
var screenDepthPS = `
|
|
48345
|
-
var uSceneDepthMap: texture_2d<
|
|
48346
|
-
var uSceneDepthMapSampler: sampler;
|
|
48718
|
+
var uSceneDepthMap: texture_2d<uff>;
|
|
48347
48719
|
#ifndef SCREENSIZE
|
|
48348
48720
|
#define SCREENSIZE
|
|
48349
48721
|
uniform uScreenSize: vec4f;
|
|
@@ -48374,19 +48746,12 @@ fn delinearizeDepth(linearDepth: f32) -> f32 {
|
|
|
48374
48746
|
}
|
|
48375
48747
|
}
|
|
48376
48748
|
fn getLinearScreenDepth(uv: vec2f) -> f32 {
|
|
48749
|
+
let textureSize = textureDimensions(uSceneDepthMap, 0);
|
|
48750
|
+
let texel: vec2i = vec2i(uv * vec2f(textureSize));
|
|
48377
48751
|
#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
|
|
48752
|
+
return textureLoad(uSceneDepthMap, texel, 0).r;
|
|
48388
48753
|
#else
|
|
48389
|
-
return linearizeDepth(
|
|
48754
|
+
return linearizeDepth(textureLoad(uSceneDepthMap, texel, 0).r);
|
|
48390
48755
|
#endif
|
|
48391
48756
|
}
|
|
48392
48757
|
#ifndef VERTEXSHADER
|
|
@@ -48683,7 +49048,7 @@ fn getShadowPCSS(shadowMap: texture_2d<f32>, shadowMapSampler: sampler, shadowCo
|
|
|
48683
49048
|
|
|
48684
49049
|
var skinBatchVS = `
|
|
48685
49050
|
attribute vertex_boneIndices: f32;
|
|
48686
|
-
var texture_poseMap: texture_2d<
|
|
49051
|
+
var texture_poseMap: texture_2d<uff>;
|
|
48687
49052
|
fn getBoneMatrix(indexFloat: f32) -> mat4x4f {
|
|
48688
49053
|
let width = i32(textureDimensions(texture_poseMap).x);
|
|
48689
49054
|
let index: i32 = i32(indexFloat + 0.5) * 3;
|
|
@@ -48704,7 +49069,7 @@ fn getBoneMatrix(indexFloat: f32) -> mat4x4f {
|
|
|
48704
49069
|
var skinVS = `
|
|
48705
49070
|
attribute vertex_boneWeights: vec4f;
|
|
48706
49071
|
attribute vertex_boneIndices: vec4f;
|
|
48707
|
-
var texture_poseMap: texture_2d<
|
|
49072
|
+
var texture_poseMap: texture_2d<uff>;
|
|
48708
49073
|
struct BoneMatrix {
|
|
48709
49074
|
v1: vec4f,
|
|
48710
49075
|
v2: vec4f,
|
|
@@ -50177,6 +50542,7 @@ class AppBase extends EventHandler {
|
|
|
50177
50542
|
}
|
|
50178
50543
|
this.stats.drawCalls.total = this.graphicsDevice._drawCallsPerFrame;
|
|
50179
50544
|
this.graphicsDevice._drawCallsPerFrame = 0;
|
|
50545
|
+
stats.gsplats = this.renderer._gsplatCount;
|
|
50180
50546
|
}
|
|
50181
50547
|
_fillFrameStats() {
|
|
50182
50548
|
let stats = this.stats.frame;
|
|
@@ -52690,7 +53056,7 @@ class AnimEvaluator {
|
|
|
52690
53056
|
for(const path in targets){
|
|
52691
53057
|
if (targets.hasOwnProperty(path)) {
|
|
52692
53058
|
const target = targets[path];
|
|
52693
|
-
if (binder.animComponent && target.target.
|
|
53059
|
+
if (binder.animComponent && target.target.usesLayerBlending) {
|
|
52694
53060
|
const animTarget = binder.animComponent.targets[path];
|
|
52695
53061
|
if (animTarget.counter === animTarget.layerCounter) {
|
|
52696
53062
|
animTarget.counter = 0;
|
|
@@ -52832,6 +53198,7 @@ class AnimTarget {
|
|
|
52832
53198
|
this._components = components;
|
|
52833
53199
|
this._targetPath = targetPath;
|
|
52834
53200
|
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';
|
|
53201
|
+
this._isWeight = this._targetPath.indexOf('weight.') !== -1;
|
|
52835
53202
|
}
|
|
52836
53203
|
get set() {
|
|
52837
53204
|
return this._set;
|
|
@@ -52851,6 +53218,12 @@ class AnimTarget {
|
|
|
52851
53218
|
get isTransform() {
|
|
52852
53219
|
return this._isTransform;
|
|
52853
53220
|
}
|
|
53221
|
+
get isWeight() {
|
|
53222
|
+
return this._isWeight;
|
|
53223
|
+
}
|
|
53224
|
+
get usesLayerBlending() {
|
|
53225
|
+
return this._isTransform || this._isWeight;
|
|
53226
|
+
}
|
|
52854
53227
|
}
|
|
52855
53228
|
|
|
52856
53229
|
class DefaultAnimBinder {
|
|
@@ -52920,26 +53293,28 @@ class DefaultAnimBinder {
|
|
|
52920
53293
|
weightName = Number(weightName);
|
|
52921
53294
|
}
|
|
52922
53295
|
const meshInstances = findMeshInstances(node);
|
|
52923
|
-
|
|
53296
|
+
const instances = [];
|
|
52924
53297
|
if (meshInstances) {
|
|
52925
53298
|
for(let i = 0; i < meshInstances.length; ++i){
|
|
52926
53299
|
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);
|
|
53300
|
+
instances.push(meshInstances[i].morphInstance);
|
|
52933
53301
|
}
|
|
52934
53302
|
}
|
|
52935
53303
|
}
|
|
52936
|
-
if (
|
|
52937
|
-
const
|
|
52938
|
-
|
|
52939
|
-
|
|
53304
|
+
if (instances.length > 0) {
|
|
53305
|
+
const func = {
|
|
53306
|
+
set: (value)=>{
|
|
53307
|
+
for(let i = 0; i < instances.length; ++i){
|
|
53308
|
+
instances[i].setWeight(weightName, value[0]);
|
|
53309
|
+
}
|
|
53310
|
+
},
|
|
53311
|
+
get: ()=>{
|
|
53312
|
+
return [
|
|
53313
|
+
instances[0].getWeight(weightName)
|
|
53314
|
+
];
|
|
52940
53315
|
}
|
|
52941
53316
|
};
|
|
52942
|
-
return DefaultAnimBinder.createAnimTarget(
|
|
53317
|
+
return DefaultAnimBinder.createAnimTarget(func, 'number', 1, node, `weight.${weightName}`);
|
|
52943
53318
|
}
|
|
52944
53319
|
return null;
|
|
52945
53320
|
},
|
|
@@ -65771,7 +66146,9 @@ uniform float graphNumSamples;
|
|
|
65771
66146
|
#define CAMERAPLANES
|
|
65772
66147
|
uniform vec4 camera_params;
|
|
65773
66148
|
#endif
|
|
65774
|
-
|
|
66149
|
+
#ifdef SOFT
|
|
66150
|
+
uniform float softening;
|
|
66151
|
+
#endif
|
|
65775
66152
|
uniform float colorMult;
|
|
65776
66153
|
float saturate(float x) {
|
|
65777
66154
|
return clamp(x, 0.0, 1.0);
|
|
@@ -66182,10 +66559,14 @@ uniform float numParticles;
|
|
|
66182
66559
|
uniform float lifetime;
|
|
66183
66560
|
uniform float stretch;
|
|
66184
66561
|
uniform float seed;
|
|
66185
|
-
uniform vec3 wrapBounds;
|
|
66186
66562
|
uniform vec3 emitterScale;
|
|
66187
66563
|
uniform vec3 faceTangent;
|
|
66188
66564
|
uniform vec3 faceBinorm;
|
|
66565
|
+
#ifdef PARTICLE_GPU
|
|
66566
|
+
#ifdef WRAP
|
|
66567
|
+
uniform vec3 wrapBounds;
|
|
66568
|
+
#endif
|
|
66569
|
+
#endif
|
|
66189
66570
|
#ifdef PARTICLE_GPU
|
|
66190
66571
|
uniform highp sampler2D internalTex0;
|
|
66191
66572
|
uniform highp sampler2D internalTex1;
|
|
@@ -66294,7 +66675,6 @@ uniform float numParticlesPot;
|
|
|
66294
66675
|
uniform float graphSampleSize;
|
|
66295
66676
|
uniform float graphNumSamples;
|
|
66296
66677
|
uniform float stretch;
|
|
66297
|
-
uniform vec3 wrapBounds;
|
|
66298
66678
|
uniform vec3 emitterScale;
|
|
66299
66679
|
uniform vec3 emitterPos;
|
|
66300
66680
|
uniform vec3 faceTangent;
|
|
@@ -66302,13 +66682,17 @@ uniform vec3 faceBinorm;
|
|
|
66302
66682
|
uniform float rate;
|
|
66303
66683
|
uniform float rateDiv;
|
|
66304
66684
|
uniform float lifetime;
|
|
66305
|
-
uniform float deltaRandomnessStatic;
|
|
66306
66685
|
uniform float scaleDivMult;
|
|
66307
66686
|
uniform float alphaDivMult;
|
|
66308
66687
|
uniform float seed;
|
|
66309
66688
|
uniform float delta;
|
|
66310
66689
|
uniform sampler2D particleTexOUT;
|
|
66311
66690
|
uniform sampler2D particleTexIN;
|
|
66691
|
+
#ifdef PARTICLE_GPU
|
|
66692
|
+
#ifdef WRAP
|
|
66693
|
+
uniform vec3 wrapBounds;
|
|
66694
|
+
#endif
|
|
66695
|
+
#endif
|
|
66312
66696
|
#ifdef PARTICLE_GPU
|
|
66313
66697
|
uniform highp sampler2D internalTex0;
|
|
66314
66698
|
uniform highp sampler2D internalTex1;
|
|
@@ -66608,7 +66992,9 @@ uniform graphNumSamples: f32;
|
|
|
66608
66992
|
#define CAMERAPLANES
|
|
66609
66993
|
uniform camera_params: vec4f;
|
|
66610
66994
|
#endif
|
|
66611
|
-
|
|
66995
|
+
#ifdef SOFT
|
|
66996
|
+
uniform softening: f32;
|
|
66997
|
+
#endif
|
|
66612
66998
|
uniform colorMult: f32;
|
|
66613
66999
|
fn saturate(x: f32) -> f32 {
|
|
66614
67000
|
return clamp(x, 0.0, 1.0);
|
|
@@ -66638,14 +67024,18 @@ struct TexLerpUnpackResult {
|
|
|
66638
67024
|
result: vec4f,
|
|
66639
67025
|
unpacked: vec3f
|
|
66640
67026
|
}
|
|
66641
|
-
fn tex1Dlod_lerp_simple(tex: texture_2d<f32>,
|
|
67027
|
+
fn tex1Dlod_lerp_simple(tex: texture_2d<f32>, textureSize: vec2u, tc: vec2f) -> vec4f {
|
|
66642
67028
|
let tc_next = tc + vec2f(uniform.graphSampleSize);
|
|
66643
|
-
|
|
67029
|
+
let texelA: vec2i = vec2i(tc * vec2f(textureSize));
|
|
67030
|
+
let texelB: vec2i = vec2i(tc_next * vec2f(textureSize));
|
|
67031
|
+
return mix( textureLoad(tex, texelA, 0), textureLoad(tex, texelB, 0), fract(tc.x * uniform.graphNumSamples) );
|
|
66644
67032
|
}
|
|
66645
|
-
fn tex1Dlod_lerp_unpack(tex: texture_2d<f32>,
|
|
67033
|
+
fn tex1Dlod_lerp_unpack(tex: texture_2d<f32>, textureSize: vec2u, tc: vec2f) -> TexLerpUnpackResult {
|
|
66646
67034
|
let tc_next = tc + vec2f(uniform.graphSampleSize);
|
|
66647
|
-
let
|
|
66648
|
-
let
|
|
67035
|
+
let texelA: vec2i = vec2i(tc * vec2f(textureSize));
|
|
67036
|
+
let texelB: vec2i = vec2i(tc_next * vec2f(textureSize));
|
|
67037
|
+
let a = textureLoad(tex, texelA, 0);
|
|
67038
|
+
let b = textureLoad(tex, texelB, 0);
|
|
66649
67039
|
let c = fract(tc.x * uniform.graphNumSamples);
|
|
66650
67040
|
let unpackedA = unpack3NFloats(a.w);
|
|
66651
67041
|
let unpackedB = unpack3NFloats(b.w);
|
|
@@ -66701,7 +67091,8 @@ fn vertexMain(input: VertexInput) -> VertexOutput {
|
|
|
66701
67091
|
}
|
|
66702
67092
|
let quadXY = meshLocalPos.xy;
|
|
66703
67093
|
let nlife = clamp(inLife / particleLifetime, 0.0, 1.0);
|
|
66704
|
-
let
|
|
67094
|
+
let internalTexSize = textureDimensions(internalTex2, 0);
|
|
67095
|
+
let lerp_result = tex1Dlod_lerp_unpack(internalTex2, internalTexSize, vec2f(nlife, 0.0));
|
|
66705
67096
|
let params = lerp_result.result;
|
|
66706
67097
|
let paramDiv = lerp_result.unpacked;
|
|
66707
67098
|
var scale = params.y;
|
|
@@ -66744,8 +67135,11 @@ var particleAnimTexVS = `
|
|
|
66744
67135
|
|
|
66745
67136
|
var particleInputFloatPS = `
|
|
66746
67137
|
fn readInput(uv: f32) {
|
|
66747
|
-
let
|
|
66748
|
-
let
|
|
67138
|
+
let textureSize = textureDimensions(particleTexIN, 0);
|
|
67139
|
+
let texel0: vec2i = vec2i(vec2f(uv, 0.25) * vec2f(textureSize));
|
|
67140
|
+
let texel1: vec2i = vec2i(vec2f(uv, 0.75) * vec2f(textureSize));
|
|
67141
|
+
let tex: vec4f = textureLoad(particleTexIN, texel0, 0);
|
|
67142
|
+
let tex2: vec4f = textureLoad(particleTexIN, texel1, 0);
|
|
66749
67143
|
inPos = tex.xyz;
|
|
66750
67144
|
inVel = tex2.xyz;
|
|
66751
67145
|
inAngle = abs(tex.w) - 1000.0;
|
|
@@ -66766,10 +67160,15 @@ fn decodeFloatRGBA( rgba: vec4f ) -> f32 {
|
|
|
66766
67160
|
return dot(rgba, vec4f(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 160581375.0));
|
|
66767
67161
|
}
|
|
66768
67162
|
fn readInput(uv: f32) {
|
|
66769
|
-
let
|
|
66770
|
-
let
|
|
66771
|
-
let
|
|
66772
|
-
let
|
|
67163
|
+
let textureSize = textureDimensions(particleTexIN, 0);
|
|
67164
|
+
let texel0: vec2i = vec2i(vec2f(uv, 0.125) * vec2f(textureSize));
|
|
67165
|
+
let texel1: vec2i = vec2i(vec2f(uv, 0.375) * vec2f(textureSize));
|
|
67166
|
+
let texel2: vec2i = vec2i(vec2f(uv, 0.625) * vec2f(textureSize));
|
|
67167
|
+
let texel3: vec2i = vec2i(vec2f(uv, 0.875) * vec2f(textureSize));
|
|
67168
|
+
let tex0 = textureLoad(particleTexIN, texel0, 0);
|
|
67169
|
+
let tex1 = textureLoad(particleTexIN, texel1, 0);
|
|
67170
|
+
let tex2 = textureLoad(particleTexIN, texel2, 0);
|
|
67171
|
+
let tex3 = textureLoad(particleTexIN, texel3, 0);
|
|
66773
67172
|
inPos = vec3f(decodeFloatRG(tex0.rg), decodeFloatRG(tex0.ba), decodeFloatRG(tex1.rg));
|
|
66774
67173
|
inPos = (inPos - vec3f(0.5)) * uniform.inBoundsSize + uniform.inBoundsCenter;
|
|
66775
67174
|
inVel = tex2.xyz;
|
|
@@ -66858,16 +67257,11 @@ var particleUpdaterEndPS = `
|
|
|
66858
67257
|
|
|
66859
67258
|
var particleUpdaterInitPS = `
|
|
66860
67259
|
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;
|
|
67260
|
+
var particleTexIN: texture_2d<uff>;
|
|
67261
|
+
var internalTex0: texture_2d<uff>;
|
|
67262
|
+
var internalTex1: texture_2d<uff>;
|
|
67263
|
+
var internalTex2: texture_2d<uff>;
|
|
67264
|
+
var internalTex3: texture_2d<uff>;
|
|
66871
67265
|
uniform emitterMatrix: mat3x3f;
|
|
66872
67266
|
uniform emitterMatrixInv: mat3x3f;
|
|
66873
67267
|
uniform emitterScale: vec3f;
|
|
@@ -66954,10 +67348,12 @@ struct TexLerpUnpackResult {
|
|
|
66954
67348
|
result: vec3f,
|
|
66955
67349
|
unpacked: vec3f
|
|
66956
67350
|
}
|
|
66957
|
-
fn tex1Dlod_lerp(tex: texture_2d<f32>,
|
|
67351
|
+
fn tex1Dlod_lerp(tex: texture_2d<f32>, textureSize: vec2u, tc: vec2f) -> TexLerpUnpackResult {
|
|
66958
67352
|
let tc_next = tc + vec2f(uniform.graphSampleSize);
|
|
66959
|
-
let
|
|
66960
|
-
let
|
|
67353
|
+
let texelA: vec2i = vec2i(tc * vec2f(textureSize));
|
|
67354
|
+
let texelB: vec2i = vec2i(tc_next * vec2f(textureSize));
|
|
67355
|
+
let a = textureLoad(tex, texelA, 0);
|
|
67356
|
+
let b = textureLoad(tex, texelB, 0);
|
|
66961
67357
|
let c = fract(tc.x * uniform.graphNumSamples);
|
|
66962
67358
|
let unpackedA = unpack3NFloats(a.w);
|
|
66963
67359
|
let unpackedB = unpack3NFloats(b.w);
|
|
@@ -66983,18 +67379,19 @@ fn fragmentMain(input : FragmentInput) -> FragmentOutput {
|
|
|
66983
67379
|
let particleRate = uniform.rate + uniform.rateDiv * rndFactor.x;
|
|
66984
67380
|
outLife = inLife + uniform.delta;
|
|
66985
67381
|
let nlife = clamp(outLife / uniform.lifetime, 0.0, 1.0);
|
|
66986
|
-
let
|
|
67382
|
+
let internalTexSize = textureDimensions(internalTex0, 0);
|
|
67383
|
+
let lerpResult0 = tex1Dlod_lerp(internalTex0, internalTexSize, vec2f(nlife, 0.0));
|
|
66987
67384
|
var localVelocity = lerpResult0.result;
|
|
66988
67385
|
let localVelocityDiv = lerpResult0.unpacked;
|
|
66989
|
-
let lerpResult1 = tex1Dlod_lerp(internalTex1,
|
|
67386
|
+
let lerpResult1 = tex1Dlod_lerp(internalTex1, internalTexSize, vec2f(nlife, 0.0));
|
|
66990
67387
|
var velocity = lerpResult1.result;
|
|
66991
67388
|
let velocityDiv = lerpResult1.unpacked;
|
|
66992
|
-
let lerpResult2 = tex1Dlod_lerp(internalTex2,
|
|
67389
|
+
let lerpResult2 = tex1Dlod_lerp(internalTex2, internalTexSize, vec2f(nlife, 0.0));
|
|
66993
67390
|
let params = lerpResult2.result;
|
|
66994
67391
|
let paramDiv = lerpResult2.unpacked;
|
|
66995
67392
|
var rotSpeed = params.x;
|
|
66996
67393
|
let rotSpeedDiv = paramDiv.y;
|
|
66997
|
-
let lerpResult3 = tex1Dlod_lerp(internalTex3,
|
|
67394
|
+
let lerpResult3 = tex1Dlod_lerp(internalTex3, internalTexSize, vec2f(nlife, 0.0));
|
|
66998
67395
|
let radialParams = lerpResult3.result;
|
|
66999
67396
|
let radialParamDiv = lerpResult3.unpacked;
|
|
67000
67397
|
let radialSpeed = radialParams.x;
|
|
@@ -67072,17 +67469,18 @@ uniform numParticles: f32;
|
|
|
67072
67469
|
uniform lifetime: f32;
|
|
67073
67470
|
uniform stretch: f32;
|
|
67074
67471
|
uniform seed: f32;
|
|
67075
|
-
uniform wrapBounds: vec3f;
|
|
67076
67472
|
uniform emitterScale: vec3f;
|
|
67077
67473
|
uniform faceTangent: vec3f;
|
|
67078
67474
|
uniform faceBinorm: vec3f;
|
|
67079
67475
|
#ifdef PARTICLE_GPU
|
|
67080
|
-
|
|
67081
|
-
|
|
67082
|
-
|
|
67083
|
-
|
|
67084
|
-
|
|
67085
|
-
var
|
|
67476
|
+
#ifdef WRAP
|
|
67477
|
+
uniform wrapBounds: vec3f;
|
|
67478
|
+
#endif
|
|
67479
|
+
#endif
|
|
67480
|
+
#ifdef PARTICLE_GPU
|
|
67481
|
+
var internalTex0: texture_2d<uff>;
|
|
67482
|
+
var internalTex1: texture_2d<uff>;
|
|
67483
|
+
var internalTex2: texture_2d<uff>;
|
|
67086
67484
|
#endif
|
|
67087
67485
|
uniform emitterPos: vec3f;
|
|
67088
67486
|
varying texCoordsAlphaLife: vec4f;
|
|
@@ -67196,7 +67594,6 @@ uniform numParticlesPot: f32;
|
|
|
67196
67594
|
uniform graphSampleSize: f32;
|
|
67197
67595
|
uniform graphNumSamples: f32;
|
|
67198
67596
|
uniform stretch: f32;
|
|
67199
|
-
uniform wrapBounds: vec3f;
|
|
67200
67597
|
uniform emitterScale: vec3f;
|
|
67201
67598
|
uniform emitterPos: vec3f;
|
|
67202
67599
|
uniform faceTangent: vec3f;
|
|
@@ -67204,22 +67601,21 @@ uniform faceBinorm: vec3f;
|
|
|
67204
67601
|
uniform rate: f32;
|
|
67205
67602
|
uniform rateDiv: f32;
|
|
67206
67603
|
uniform lifetime: f32;
|
|
67207
|
-
uniform deltaRandomnessStatic: f32;
|
|
67208
67604
|
uniform scaleDivMult: f32;
|
|
67209
67605
|
uniform alphaDivMult: f32;
|
|
67210
67606
|
uniform seed: f32;
|
|
67211
67607
|
uniform delta: f32;
|
|
67212
|
-
var particleTexOUT: texture_2d<f32>;
|
|
67213
|
-
var particleTexOUTSampler: sampler;
|
|
67214
|
-
var particleTexIN: texture_2d<f32>;
|
|
67215
|
-
var particleTexINSampler: sampler;
|
|
67216
67608
|
#ifdef PARTICLE_GPU
|
|
67217
|
-
|
|
67218
|
-
|
|
67219
|
-
|
|
67220
|
-
|
|
67221
|
-
|
|
67222
|
-
|
|
67609
|
+
#ifdef WRAP
|
|
67610
|
+
uniform wrapBounds: vec3f;
|
|
67611
|
+
#endif
|
|
67612
|
+
#endif
|
|
67613
|
+
var particleTexOUT: texture_2d<uff>;
|
|
67614
|
+
var particleTexIN: texture_2d<uff>;
|
|
67615
|
+
#ifdef PARTICLE_GPU
|
|
67616
|
+
var internalTex0: texture_2d<uff>;
|
|
67617
|
+
var internalTex1: texture_2d<uff>;
|
|
67618
|
+
var internalTex2: texture_2d<uff>;
|
|
67223
67619
|
#endif
|
|
67224
67620
|
#ifndef CAMERAPLANES
|
|
67225
67621
|
#define CAMERAPLANES
|
|
@@ -70670,14 +71066,14 @@ class ScrollViewComponent extends Component {
|
|
|
70670
71066
|
if (overshoot > 0) {
|
|
70671
71067
|
scrollValue.x = max + factor * Math.log10(1 + overshoot);
|
|
70672
71068
|
} else if (overshoot < 0) {
|
|
70673
|
-
scrollValue.x = -
|
|
71069
|
+
scrollValue.x = -factor * Math.log10(1 - overshoot);
|
|
70674
71070
|
}
|
|
70675
71071
|
max = this._getMaxScrollValue(ORIENTATION_VERTICAL);
|
|
70676
71072
|
overshoot = this._toOvershoot(scrollValue.y, ORIENTATION_VERTICAL);
|
|
70677
71073
|
if (overshoot > 0) {
|
|
70678
71074
|
scrollValue.y = max + factor * Math.log10(1 + overshoot);
|
|
70679
71075
|
} else if (overshoot < 0) {
|
|
70680
|
-
scrollValue.y = -
|
|
71076
|
+
scrollValue.y = -factor * Math.log10(1 - overshoot);
|
|
70681
71077
|
}
|
|
70682
71078
|
return scrollValue;
|
|
70683
71079
|
}
|
|
@@ -73407,6 +73803,12 @@ class CameraComponent extends Component {
|
|
|
73407
73803
|
get clearColorBuffer() {
|
|
73408
73804
|
return this._camera.clearColorBuffer;
|
|
73409
73805
|
}
|
|
73806
|
+
set clearDepth(value) {
|
|
73807
|
+
this._camera.clearDepth = value;
|
|
73808
|
+
}
|
|
73809
|
+
get clearDepth() {
|
|
73810
|
+
return this._camera.clearDepth;
|
|
73811
|
+
}
|
|
73410
73812
|
set clearDepthBuffer(value) {
|
|
73411
73813
|
this._camera.clearDepthBuffer = value;
|
|
73412
73814
|
this.dirtyLayerCompositionCameras();
|
|
@@ -73782,6 +74184,7 @@ class CameraComponentSystem extends ComponentSystem {
|
|
|
73782
74184
|
'calculateTransform',
|
|
73783
74185
|
'clearColor',
|
|
73784
74186
|
'clearColorBuffer',
|
|
74187
|
+
'clearDepth',
|
|
73785
74188
|
'clearDepthBuffer',
|
|
73786
74189
|
'clearStencilBuffer',
|
|
73787
74190
|
'renderSceneColorMap',
|
|
@@ -74300,7 +74703,7 @@ class LightComponent extends Component {
|
|
|
74300
74703
|
if (newValue) {
|
|
74301
74704
|
this.light.mask |= MASK_AFFECT_DYNAMIC;
|
|
74302
74705
|
} else {
|
|
74303
|
-
this.light.mask &=
|
|
74706
|
+
this.light.mask &= ~MASK_AFFECT_DYNAMIC;
|
|
74304
74707
|
}
|
|
74305
74708
|
this.light.layersDirty();
|
|
74306
74709
|
});
|
|
@@ -74312,9 +74715,9 @@ class LightComponent extends Component {
|
|
|
74312
74715
|
this._setValue('affectLightmapped', arg, function(newValue, oldValue) {
|
|
74313
74716
|
if (newValue) {
|
|
74314
74717
|
this.light.mask |= MASK_AFFECT_LIGHTMAPPED;
|
|
74315
|
-
if (this.bake) this.light.mask &=
|
|
74718
|
+
if (this.bake) this.light.mask &= ~MASK_BAKE;
|
|
74316
74719
|
} else {
|
|
74317
|
-
this.light.mask &=
|
|
74720
|
+
this.light.mask &= ~MASK_AFFECT_LIGHTMAPPED;
|
|
74318
74721
|
if (this.bake) this.light.mask |= MASK_BAKE;
|
|
74319
74722
|
}
|
|
74320
74723
|
});
|
|
@@ -74326,9 +74729,9 @@ class LightComponent extends Component {
|
|
|
74326
74729
|
this._setValue('bake', arg, function(newValue, oldValue) {
|
|
74327
74730
|
if (newValue) {
|
|
74328
74731
|
this.light.mask |= MASK_BAKE;
|
|
74329
|
-
if (this.affectLightmapped) this.light.mask &=
|
|
74732
|
+
if (this.affectLightmapped) this.light.mask &= ~MASK_AFFECT_LIGHTMAPPED;
|
|
74330
74733
|
} else {
|
|
74331
|
-
this.light.mask &=
|
|
74734
|
+
this.light.mask &= ~MASK_BAKE;
|
|
74332
74735
|
if (this.affectLightmapped) this.light.mask |= MASK_AFFECT_LIGHTMAPPED;
|
|
74333
74736
|
}
|
|
74334
74737
|
this.light.layersDirty();
|
|
@@ -75826,40 +76229,19 @@ class GSplatIntervalTexture {
|
|
|
75826
76229
|
addressV: ADDRESS_CLAMP_TO_EDGE
|
|
75827
76230
|
});
|
|
75828
76231
|
}
|
|
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
|
-
}
|
|
76232
|
+
update(intervals, totalIntervalSplats) {
|
|
75839
76233
|
const maxTextureSize = this.device.maxTextureSize;
|
|
75840
|
-
let textureWidth = Math.ceil(Math.sqrt(
|
|
76234
|
+
let textureWidth = Math.ceil(Math.sqrt(totalIntervalSplats));
|
|
75841
76235
|
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
|
-
}
|
|
76236
|
+
const textureHeight = Math.ceil(totalIntervalSplats / textureWidth);
|
|
76237
|
+
this.texture = this.createTexture('intervalsTexture', PIXELFORMAT_R32U, textureWidth, textureHeight);
|
|
76238
|
+
this.rt = new RenderTarget({
|
|
76239
|
+
colorBuffer: this.texture,
|
|
76240
|
+
depth: false
|
|
76241
|
+
});
|
|
75855
76242
|
const numIntervals = intervals.length / 2;
|
|
75856
76243
|
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
|
-
}
|
|
76244
|
+
this.intervalsDataTexture = this.createTexture('intervalsData', PIXELFORMAT_RG32U, dataTextureSize, dataTextureSize);
|
|
75863
76245
|
const intervalsData = this.intervalsDataTexture.lock();
|
|
75864
76246
|
let runningSum = 0;
|
|
75865
76247
|
for(let i = 0; i < numIntervals; i++){
|
|
@@ -75875,15 +76257,16 @@ class GSplatIntervalTexture {
|
|
|
75875
76257
|
scope.resolve('uIntervalsTexture').setValue(this.intervalsDataTexture);
|
|
75876
76258
|
scope.resolve('uNumIntervals').setValue(numIntervals);
|
|
75877
76259
|
scope.resolve('uTextureWidth').setValue(textureWidth);
|
|
75878
|
-
scope.resolve('uActiveSplats').setValue(
|
|
76260
|
+
scope.resolve('uActiveSplats').setValue(totalIntervalSplats);
|
|
75879
76261
|
this.device.setCullMode(CULLFACE_NONE);
|
|
75880
76262
|
this.device.setBlendState(BlendState.NOBLEND);
|
|
75881
76263
|
this.device.setDepthState(DepthState.NODEPTH);
|
|
75882
76264
|
drawQuadWithShader(this.device, this.rt, this.getShader());
|
|
75883
|
-
return
|
|
76265
|
+
return totalIntervalSplats;
|
|
75884
76266
|
}
|
|
75885
76267
|
}
|
|
75886
76268
|
|
|
76269
|
+
const vecs = [];
|
|
75887
76270
|
class GSplatInfo {
|
|
75888
76271
|
constructor(device, resource, placement){
|
|
75889
76272
|
this.activeSplats = 0;
|
|
@@ -75894,18 +76277,18 @@ class GSplatInfo {
|
|
|
75894
76277
|
this.viewport = new Vec4();
|
|
75895
76278
|
this.previousWorldTransform = new Mat4();
|
|
75896
76279
|
this.aabb = new BoundingBox();
|
|
76280
|
+
this.intervalTexture = null;
|
|
75897
76281
|
this.device = device;
|
|
75898
76282
|
this.resource = resource;
|
|
75899
76283
|
this.node = placement.node;
|
|
75900
76284
|
this.lodIndex = placement.lodIndex;
|
|
75901
|
-
this.numSplats = resource.
|
|
76285
|
+
this.numSplats = resource.numSplats;
|
|
75902
76286
|
this.aabb.copy(placement.aabb);
|
|
75903
|
-
this.intervalTexture = new GSplatIntervalTexture(device);
|
|
75904
76287
|
this.updateIntervals(placement.intervals);
|
|
75905
76288
|
}
|
|
75906
76289
|
destroy() {
|
|
75907
76290
|
this.intervals.length = 0;
|
|
75908
|
-
this.intervalTexture
|
|
76291
|
+
this.intervalTexture?.destroy();
|
|
75909
76292
|
}
|
|
75910
76293
|
setLines(start, count, textureSize, activeSplats) {
|
|
75911
76294
|
this.lineStart = start;
|
|
@@ -75918,10 +76301,37 @@ class GSplatInfo {
|
|
|
75918
76301
|
this.intervals.length = 0;
|
|
75919
76302
|
this.activeSplats = resource.numSplats;
|
|
75920
76303
|
if (intervals.size > 0) {
|
|
76304
|
+
let totalCount = 0;
|
|
76305
|
+
let used = 0;
|
|
75921
76306
|
for (const interval of intervals.values()){
|
|
75922
|
-
|
|
76307
|
+
totalCount += interval.y - interval.x + 1;
|
|
76308
|
+
vecs[used++] = interval;
|
|
76309
|
+
}
|
|
76310
|
+
if (totalCount !== this.numSplats) {
|
|
76311
|
+
vecs.length = used;
|
|
76312
|
+
vecs.sort((a, b)=>a.x - b.x);
|
|
76313
|
+
this.intervals.length = used * 2;
|
|
76314
|
+
let k = 0;
|
|
76315
|
+
let currentStart = vecs[0].x;
|
|
76316
|
+
let currentEnd = vecs[0].y;
|
|
76317
|
+
for(let i = 1; i < used; i++){
|
|
76318
|
+
const p = vecs[i];
|
|
76319
|
+
if (p.x === currentEnd + 1) {
|
|
76320
|
+
currentEnd = p.y;
|
|
76321
|
+
} else {
|
|
76322
|
+
this.intervals[k++] = currentStart;
|
|
76323
|
+
this.intervals[k++] = currentEnd + 1;
|
|
76324
|
+
currentStart = p.x;
|
|
76325
|
+
currentEnd = p.y;
|
|
76326
|
+
}
|
|
76327
|
+
}
|
|
76328
|
+
this.intervals[k++] = currentStart;
|
|
76329
|
+
this.intervals[k++] = currentEnd + 1;
|
|
76330
|
+
this.intervals.length = k;
|
|
76331
|
+
this.intervalTexture = new GSplatIntervalTexture(this.device);
|
|
76332
|
+
this.activeSplats = this.intervalTexture.update(this.intervals, totalCount);
|
|
75923
76333
|
}
|
|
75924
|
-
|
|
76334
|
+
vecs.length = 0;
|
|
75925
76335
|
}
|
|
75926
76336
|
}
|
|
75927
76337
|
update() {
|
|
@@ -75940,18 +76350,69 @@ function UnifiedSortWorker() {
|
|
|
75940
76350
|
let centersData;
|
|
75941
76351
|
let distances;
|
|
75942
76352
|
let countBuffer;
|
|
75943
|
-
|
|
76353
|
+
let _radialSort = false;
|
|
76354
|
+
const numBins = 32;
|
|
76355
|
+
const binBase = new Array(numBins).fill(0);
|
|
76356
|
+
const binDivider = new Array(numBins).fill(0);
|
|
76357
|
+
const weightTiers = [
|
|
76358
|
+
{
|
|
76359
|
+
maxDistance: 0,
|
|
76360
|
+
weight: 40.0
|
|
76361
|
+
},
|
|
76362
|
+
{
|
|
76363
|
+
maxDistance: 2,
|
|
76364
|
+
weight: 20.0
|
|
76365
|
+
},
|
|
76366
|
+
{
|
|
76367
|
+
maxDistance: 5,
|
|
76368
|
+
weight: 8.0
|
|
76369
|
+
},
|
|
76370
|
+
{
|
|
76371
|
+
maxDistance: 10,
|
|
76372
|
+
weight: 3.0
|
|
76373
|
+
},
|
|
76374
|
+
{
|
|
76375
|
+
maxDistance: Infinity,
|
|
76376
|
+
weight: 1.0
|
|
76377
|
+
}
|
|
76378
|
+
];
|
|
76379
|
+
const weightByDistance = new Array(numBins);
|
|
76380
|
+
for(let dist = 0; dist < numBins; ++dist){
|
|
76381
|
+
let weight = 1.0;
|
|
76382
|
+
for(let j = 0; j < weightTiers.length; ++j){
|
|
76383
|
+
if (dist <= weightTiers[j].maxDistance) {
|
|
76384
|
+
weight = weightTiers[j].weight;
|
|
76385
|
+
break;
|
|
76386
|
+
}
|
|
76387
|
+
}
|
|
76388
|
+
weightByDistance[dist] = weight;
|
|
76389
|
+
}
|
|
76390
|
+
const setupCameraRelativeBins = (cameraBin, bucketCount)=>{
|
|
76391
|
+
const totalBudget = bucketCount;
|
|
76392
|
+
const bitsPerBin = [];
|
|
76393
|
+
for(let i = 0; i < numBins; ++i){
|
|
76394
|
+
const distFromCamera = Math.abs(i - cameraBin);
|
|
76395
|
+
bitsPerBin[i] = weightByDistance[distFromCamera];
|
|
76396
|
+
}
|
|
76397
|
+
const totalWeight = bitsPerBin.reduce((a, b)=>a + b, 0);
|
|
76398
|
+
let accumulated = 0;
|
|
76399
|
+
for(let i = 0; i < numBins; ++i){
|
|
76400
|
+
binDivider[i] = Math.max(1, Math.floor(bitsPerBin[i] / totalWeight * totalBudget));
|
|
76401
|
+
binBase[i] = accumulated;
|
|
76402
|
+
accumulated += binDivider[i];
|
|
76403
|
+
}
|
|
76404
|
+
if (accumulated > bucketCount) {
|
|
76405
|
+
const excess = accumulated - bucketCount;
|
|
76406
|
+
binDivider[numBins - 1] = Math.max(1, binDivider[numBins - 1] - excess);
|
|
76407
|
+
}
|
|
76408
|
+
binBase[numBins] = binBase[numBins - 1] + binDivider[numBins - 1];
|
|
76409
|
+
binDivider[numBins] = 0;
|
|
76410
|
+
};
|
|
76411
|
+
const evaluateSortKeysCommon = (sortParams, minDist, range, distances, countBuffer, centersData, processSplatFn)=>{
|
|
75944
76412
|
const { ids, lineStarts, padding, intervals, textureSize } = centersData;
|
|
76413
|
+
const invBinRange = numBins / range;
|
|
75945
76414
|
for(let paramIdx = 0; paramIdx < sortParams.length; paramIdx++){
|
|
75946
76415
|
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
76416
|
const id = ids[paramIdx];
|
|
75956
76417
|
const centers = centersMap.get(id);
|
|
75957
76418
|
if (!centers) {
|
|
@@ -75965,14 +76426,7 @@ function UnifiedSortWorker() {
|
|
|
75965
76426
|
for(let i = 0; i < intervalsArray.length; i += 2){
|
|
75966
76427
|
const intervalStart = intervalsArray[i] * 3;
|
|
75967
76428
|
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
|
-
}
|
|
76429
|
+
targetIndex = processSplatFn(centers, params, intervalStart, intervalEnd, targetIndex, invBinRange, minDist, range, distances, countBuffer);
|
|
75976
76430
|
}
|
|
75977
76431
|
const pad = padding[paramIdx];
|
|
75978
76432
|
countBuffer[0] += pad;
|
|
@@ -75980,6 +76434,52 @@ function UnifiedSortWorker() {
|
|
|
75980
76434
|
targetIndex += pad;
|
|
75981
76435
|
}
|
|
75982
76436
|
};
|
|
76437
|
+
const evaluateSortKeysLinear = (sortParams, minDist, range, distances, countBuffer, centersData)=>{
|
|
76438
|
+
evaluateSortKeysCommon(sortParams, minDist, range, distances, countBuffer, centersData, (centers, params, intervalStart, intervalEnd, targetIndex, invBinRange, minDist, range, distances, countBuffer)=>{
|
|
76439
|
+
const { transformedDirection, offset, scale } = params;
|
|
76440
|
+
const dx = transformedDirection.x;
|
|
76441
|
+
const dy = transformedDirection.y;
|
|
76442
|
+
const dz = transformedDirection.z;
|
|
76443
|
+
const sdx = dx * scale;
|
|
76444
|
+
const sdy = dy * scale;
|
|
76445
|
+
const sdz = dz * scale;
|
|
76446
|
+
const add = offset - minDist;
|
|
76447
|
+
for(let srcIndex = intervalStart; srcIndex < intervalEnd; srcIndex += 3){
|
|
76448
|
+
const x = centers[srcIndex];
|
|
76449
|
+
const y = centers[srcIndex + 1];
|
|
76450
|
+
const z = centers[srcIndex + 2];
|
|
76451
|
+
const dist = x * sdx + y * sdy + z * sdz + add;
|
|
76452
|
+
const d = dist * invBinRange;
|
|
76453
|
+
const bin = d >>> 0;
|
|
76454
|
+
const sortKey = binBase[bin] + binDivider[bin] * (d - bin) >>> 0;
|
|
76455
|
+
distances[targetIndex++] = sortKey;
|
|
76456
|
+
countBuffer[sortKey]++;
|
|
76457
|
+
}
|
|
76458
|
+
return targetIndex;
|
|
76459
|
+
});
|
|
76460
|
+
};
|
|
76461
|
+
const evaluateSortKeysRadial = (sortParams, minDist, range, distances, countBuffer, centersData)=>{
|
|
76462
|
+
evaluateSortKeysCommon(sortParams, minDist, range, distances, countBuffer, centersData, (centers, params, intervalStart, intervalEnd, targetIndex, invBinRange, minDist, range, distances, countBuffer)=>{
|
|
76463
|
+
const { transformedPosition, scale } = params;
|
|
76464
|
+
const cx = transformedPosition.x;
|
|
76465
|
+
const cy = transformedPosition.y;
|
|
76466
|
+
const cz = transformedPosition.z;
|
|
76467
|
+
for(let srcIndex = intervalStart; srcIndex < intervalEnd; srcIndex += 3){
|
|
76468
|
+
const dx = centers[srcIndex] - cx;
|
|
76469
|
+
const dy = centers[srcIndex + 1] - cy;
|
|
76470
|
+
const dz = centers[srcIndex + 2] - cz;
|
|
76471
|
+
const distSq = dx * dx + dy * dy + dz * dz;
|
|
76472
|
+
const dist = Math.sqrt(distSq) * scale;
|
|
76473
|
+
const invertedDist = range - dist;
|
|
76474
|
+
const d = invertedDist * invBinRange;
|
|
76475
|
+
const bin = d >>> 0;
|
|
76476
|
+
const sortKey = binBase[bin] + binDivider[bin] * (d - bin) >>> 0;
|
|
76477
|
+
distances[targetIndex++] = sortKey;
|
|
76478
|
+
countBuffer[sortKey]++;
|
|
76479
|
+
}
|
|
76480
|
+
return targetIndex;
|
|
76481
|
+
});
|
|
76482
|
+
};
|
|
75983
76483
|
const countingSort = (bucketCount, countBuffer, numVertices, distances, order)=>{
|
|
75984
76484
|
for(let i = 1; i < bucketCount; i++){
|
|
75985
76485
|
countBuffer[i] += countBuffer[i - 1];
|
|
@@ -75990,7 +76490,7 @@ function UnifiedSortWorker() {
|
|
|
75990
76490
|
order[destIndex] = i;
|
|
75991
76491
|
}
|
|
75992
76492
|
};
|
|
75993
|
-
const
|
|
76493
|
+
const computeEffectiveDistanceRangeLinear = (sortParams)=>{
|
|
75994
76494
|
let minDist = Infinity;
|
|
75995
76495
|
let maxDist = -Infinity;
|
|
75996
76496
|
for(let paramIdx = 0; paramIdx < sortParams.length; paramIdx++){
|
|
@@ -76023,8 +76523,37 @@ function UnifiedSortWorker() {
|
|
|
76023
76523
|
maxDist
|
|
76024
76524
|
};
|
|
76025
76525
|
};
|
|
76526
|
+
const computeEffectiveDistanceRangeRadial = (sortParams)=>{
|
|
76527
|
+
let maxDist = -Infinity;
|
|
76528
|
+
for(let paramIdx = 0; paramIdx < sortParams.length; paramIdx++){
|
|
76529
|
+
const params = sortParams[paramIdx];
|
|
76530
|
+
const { transformedPosition, scale, aabbMin, aabbMax } = params;
|
|
76531
|
+
const cx = transformedPosition.x;
|
|
76532
|
+
const cy = transformedPosition.y;
|
|
76533
|
+
const cz = transformedPosition.z;
|
|
76534
|
+
for(let i = 0; i < 8; i++){
|
|
76535
|
+
const px = i & 1 ? aabbMax[0] : aabbMin[0];
|
|
76536
|
+
const py = i & 2 ? aabbMax[1] : aabbMin[1];
|
|
76537
|
+
const pz = i & 4 ? aabbMax[2] : aabbMin[2];
|
|
76538
|
+
const dx = px - cx;
|
|
76539
|
+
const dy = py - cy;
|
|
76540
|
+
const dz = pz - cz;
|
|
76541
|
+
const distSq = dx * dx + dy * dy + dz * dz;
|
|
76542
|
+
const dist = Math.sqrt(distSq) * scale;
|
|
76543
|
+
if (dist > maxDist) maxDist = dist;
|
|
76544
|
+
}
|
|
76545
|
+
}
|
|
76546
|
+
const minDist = 0;
|
|
76547
|
+
if (maxDist < 0) {
|
|
76548
|
+
maxDist = 0;
|
|
76549
|
+
}
|
|
76550
|
+
return {
|
|
76551
|
+
minDist,
|
|
76552
|
+
maxDist
|
|
76553
|
+
};
|
|
76554
|
+
};
|
|
76026
76555
|
const sort = (sortParams, order, centersData)=>{
|
|
76027
|
-
const { minDist, maxDist } =
|
|
76556
|
+
const { minDist, maxDist } = _radialSort ? computeEffectiveDistanceRangeRadial(sortParams) : computeEffectiveDistanceRangeLinear(sortParams);
|
|
76028
76557
|
const numVertices = centersData.totalUsedPixels;
|
|
76029
76558
|
const compareBits = Math.max(10, Math.min(20, Math.round(Math.log2(numVertices / 4))));
|
|
76030
76559
|
const bucketCount = 2 ** compareBits + 1;
|
|
@@ -76037,8 +76566,20 @@ function UnifiedSortWorker() {
|
|
|
76037
76566
|
countBuffer.fill(0);
|
|
76038
76567
|
}
|
|
76039
76568
|
const range = maxDist - minDist;
|
|
76040
|
-
|
|
76041
|
-
|
|
76569
|
+
let cameraBin;
|
|
76570
|
+
if (_radialSort) {
|
|
76571
|
+
cameraBin = numBins - 1;
|
|
76572
|
+
} else {
|
|
76573
|
+
const cameraOffsetFromRangeStart = 0 - minDist;
|
|
76574
|
+
const cameraBinFloat = cameraOffsetFromRangeStart / range * numBins;
|
|
76575
|
+
cameraBin = Math.max(0, Math.min(numBins - 1, Math.floor(cameraBinFloat)));
|
|
76576
|
+
}
|
|
76577
|
+
setupCameraRelativeBins(cameraBin, bucketCount);
|
|
76578
|
+
if (_radialSort) {
|
|
76579
|
+
evaluateSortKeysRadial(sortParams, minDist, range, distances, countBuffer, centersData);
|
|
76580
|
+
} else {
|
|
76581
|
+
evaluateSortKeysLinear(sortParams, minDist, range, distances, countBuffer, centersData);
|
|
76582
|
+
}
|
|
76042
76583
|
countingSort(bucketCount, countBuffer, numVertices, distances, order);
|
|
76043
76584
|
const count = numVertices;
|
|
76044
76585
|
const transferList = [
|
|
@@ -76066,6 +76607,7 @@ function UnifiedSortWorker() {
|
|
|
76066
76607
|
}
|
|
76067
76608
|
case 'sort':
|
|
76068
76609
|
{
|
|
76610
|
+
_radialSort = msgData.radialSorting || false;
|
|
76069
76611
|
const order = new Uint32Array(msgData.order);
|
|
76070
76612
|
sort(msgData.sortParams, order, centersData);
|
|
76071
76613
|
break;
|
|
@@ -76081,7 +76623,7 @@ function UnifiedSortWorker() {
|
|
|
76081
76623
|
|
|
76082
76624
|
class GSplatUnifiedSorter extends EventHandler {
|
|
76083
76625
|
constructor(){
|
|
76084
|
-
super(), this.bufferLength = 0, this.availableOrderData = [], this.jobsInFlight = 0, this.hasNewVersion = false, this.centersSet = new Set();
|
|
76626
|
+
super(), this.bufferLength = 0, this.availableOrderData = [], this.jobsInFlight = 0, this.hasNewVersion = false, this.centersSet = new Set(), this._destroyed = false;
|
|
76085
76627
|
const workerSource = `(${UnifiedSortWorker.toString()})()`;
|
|
76086
76628
|
if (platform.environment === 'node') {
|
|
76087
76629
|
this.worker = new Worker(workerSource, {
|
|
@@ -76098,6 +76640,9 @@ class GSplatUnifiedSorter extends EventHandler {
|
|
|
76098
76640
|
}
|
|
76099
76641
|
}
|
|
76100
76642
|
onSorted(message) {
|
|
76643
|
+
if (this._destroyed) {
|
|
76644
|
+
return;
|
|
76645
|
+
}
|
|
76101
76646
|
const msgData = message.data ?? message;
|
|
76102
76647
|
const orderData = new Uint32Array(msgData.order);
|
|
76103
76648
|
this.jobsInFlight--;
|
|
@@ -76107,6 +76652,7 @@ class GSplatUnifiedSorter extends EventHandler {
|
|
|
76107
76652
|
}
|
|
76108
76653
|
}
|
|
76109
76654
|
destroy() {
|
|
76655
|
+
this._destroyed = true;
|
|
76110
76656
|
this.worker.terminate();
|
|
76111
76657
|
this.worker = null;
|
|
76112
76658
|
}
|
|
@@ -76143,7 +76689,7 @@ class GSplatUnifiedSorter extends EventHandler {
|
|
|
76143
76689
|
}
|
|
76144
76690
|
this.worker.postMessage(payload);
|
|
76145
76691
|
}
|
|
76146
|
-
setSortParams(params) {
|
|
76692
|
+
setSortParams(params, radialSorting) {
|
|
76147
76693
|
if (this.hasNewVersion || this.jobsInFlight === 0) {
|
|
76148
76694
|
let orderData = this.availableOrderData.pop();
|
|
76149
76695
|
if (!orderData) {
|
|
@@ -76154,6 +76700,7 @@ class GSplatUnifiedSorter extends EventHandler {
|
|
|
76154
76700
|
this.worker.postMessage({
|
|
76155
76701
|
command: 'sort',
|
|
76156
76702
|
sortParams: params,
|
|
76703
|
+
radialSorting: radialSorting,
|
|
76157
76704
|
order: orderData.buffer
|
|
76158
76705
|
}, [
|
|
76159
76706
|
orderData.buffer
|
|
@@ -76163,15 +76710,20 @@ class GSplatUnifiedSorter extends EventHandler {
|
|
|
76163
76710
|
}
|
|
76164
76711
|
|
|
76165
76712
|
const _viewMat = new Mat4();
|
|
76166
|
-
const
|
|
76713
|
+
const _whiteColor = [
|
|
76714
|
+
1,
|
|
76715
|
+
1,
|
|
76716
|
+
1
|
|
76717
|
+
];
|
|
76167
76718
|
class GSplatWorkBufferRenderPass extends RenderPass {
|
|
76168
76719
|
init(renderTarget) {
|
|
76169
76720
|
super.init(renderTarget);
|
|
76170
76721
|
this.colorOps.clear = false;
|
|
76171
76722
|
this.depthStencilOps.clearDepth = false;
|
|
76172
76723
|
}
|
|
76173
|
-
update(splats, cameraNode) {
|
|
76724
|
+
update(splats, cameraNode, colorsByLod) {
|
|
76174
76725
|
this.splats.length = 0;
|
|
76726
|
+
this.colorsByLod = colorsByLod;
|
|
76175
76727
|
for(let i = 0; i < splats.length; i++){
|
|
76176
76728
|
const splatInfo = splats[i];
|
|
76177
76729
|
if (splatInfo.activeSplats > 0) {
|
|
@@ -76198,15 +76750,17 @@ class GSplatWorkBufferRenderPass extends RenderPass {
|
|
|
76198
76750
|
const { device, resource } = splatInfo;
|
|
76199
76751
|
const scope = device.scope;
|
|
76200
76752
|
const { intervals, activeSplats, lineStart, viewport, intervalTexture } = splatInfo;
|
|
76201
|
-
const workBufferRenderInfo = resource.getWorkBufferRenderInfo(intervals.length > 0
|
|
76753
|
+
const workBufferRenderInfo = resource.getWorkBufferRenderInfo(intervals.length > 0);
|
|
76202
76754
|
workBufferRenderInfo.material.setParameters(device);
|
|
76203
76755
|
scope.resolve('uTransform').setValue(splatInfo.node.getWorldTransform().data);
|
|
76204
|
-
if (intervalTexture
|
|
76756
|
+
if (intervalTexture) {
|
|
76205
76757
|
scope.resolve('uIntervalsTexture').setValue(intervalTexture.texture);
|
|
76206
76758
|
}
|
|
76207
76759
|
scope.resolve('uActiveSplats').setValue(activeSplats);
|
|
76208
76760
|
scope.resolve('uStartLine').setValue(lineStart);
|
|
76209
76761
|
scope.resolve('uViewportWidth').setValue(viewport.z);
|
|
76762
|
+
const color = this.colorsByLod?.[splatInfo.lodIndex] ?? _whiteColor;
|
|
76763
|
+
scope.resolve('uColorMultiply').setValue(color);
|
|
76210
76764
|
scope.resolve('matrix_model').setValue(splatInfo.node.getWorldTransform().data);
|
|
76211
76765
|
workBufferRenderInfo.quadRender.render(viewport);
|
|
76212
76766
|
}
|
|
@@ -76215,7 +76769,7 @@ class GSplatWorkBufferRenderPass extends RenderPass {
|
|
|
76215
76769
|
super.destroy();
|
|
76216
76770
|
}
|
|
76217
76771
|
constructor(...args){
|
|
76218
|
-
super(...args), this.splats = [];
|
|
76772
|
+
super(...args), this.splats = [], this.colorsByLod = undefined, this.cameraNode = null;
|
|
76219
76773
|
}
|
|
76220
76774
|
}
|
|
76221
76775
|
|
|
@@ -76279,8 +76833,8 @@ class GSplatWorkBuffer {
|
|
|
76279
76833
|
this.renderTarget.resize(textureSize, textureSize);
|
|
76280
76834
|
this.orderTexture.resize(textureSize, textureSize);
|
|
76281
76835
|
}
|
|
76282
|
-
render(splats, cameraNode) {
|
|
76283
|
-
if (this.renderPass.update(splats, cameraNode)) {
|
|
76836
|
+
render(splats, cameraNode, colorsByLod) {
|
|
76837
|
+
if (this.renderPass.update(splats, cameraNode, colorsByLod)) {
|
|
76284
76838
|
this.renderPass.render();
|
|
76285
76839
|
}
|
|
76286
76840
|
}
|
|
@@ -76288,8 +76842,8 @@ class GSplatWorkBuffer {
|
|
|
76288
76842
|
|
|
76289
76843
|
class GSplatRenderer {
|
|
76290
76844
|
constructor(device, node, cameraNode, layer, workBuffer){
|
|
76291
|
-
this.maxNumSplats = 0;
|
|
76292
76845
|
this.instanceIndices = null;
|
|
76846
|
+
this.instanceIndicesCount = 0;
|
|
76293
76847
|
this.viewportParams = [
|
|
76294
76848
|
0,
|
|
76295
76849
|
0
|
|
@@ -76342,8 +76896,9 @@ class GSplatRenderer {
|
|
|
76342
76896
|
this.meshInstance.visible = count > 0;
|
|
76343
76897
|
}
|
|
76344
76898
|
setMaxNumSplats(numSplats) {
|
|
76345
|
-
|
|
76346
|
-
|
|
76899
|
+
const roundedNumSplats = math.roundUp(numSplats, GSplatResourceBase.instanceSize);
|
|
76900
|
+
if (this.instanceIndicesCount < roundedNumSplats) {
|
|
76901
|
+
this.instanceIndicesCount = roundedNumSplats;
|
|
76347
76902
|
this.instanceIndices?.destroy();
|
|
76348
76903
|
this.instanceIndices = GSplatResourceBase.createInstanceIndices(this.device, numSplats);
|
|
76349
76904
|
this.meshInstance.setInstancing(this.instanceIndices, true);
|
|
@@ -76384,6 +76939,7 @@ class GSplatPlacement {
|
|
|
76384
76939
|
constructor(resource, node, lodIndex = 0){
|
|
76385
76940
|
this.intervals = new Map();
|
|
76386
76941
|
this.lodIndex = 0;
|
|
76942
|
+
this._lodDistances = null;
|
|
76387
76943
|
this._aabb = new BoundingBox();
|
|
76388
76944
|
this.resource = resource;
|
|
76389
76945
|
this.node = node;
|
|
@@ -76395,18 +76951,46 @@ class GSplatPlacement {
|
|
|
76395
76951
|
get aabb() {
|
|
76396
76952
|
return this._aabb;
|
|
76397
76953
|
}
|
|
76954
|
+
set lodDistances(distances) {
|
|
76955
|
+
const isOctree = !!(this.resource && this.resource.octree);
|
|
76956
|
+
if (isOctree) {
|
|
76957
|
+
if (distances) {
|
|
76958
|
+
this.resource.octree?.lodLevels ?? 1;
|
|
76959
|
+
this._lodDistances = distances.slice();
|
|
76960
|
+
} else {
|
|
76961
|
+
this._lodDistances = null;
|
|
76962
|
+
}
|
|
76963
|
+
}
|
|
76964
|
+
}
|
|
76965
|
+
get lodDistances() {
|
|
76966
|
+
return this._lodDistances ? this._lodDistances.slice() : null;
|
|
76967
|
+
}
|
|
76398
76968
|
}
|
|
76399
76969
|
|
|
76400
76970
|
const _invWorldMat = new Mat4();
|
|
76401
76971
|
const _localCameraPos = new Vec3();
|
|
76972
|
+
const _localCameraFwd = new Vec3();
|
|
76973
|
+
const _dirToNode = new Vec3();
|
|
76402
76974
|
const _tempCompletedUrls = [];
|
|
76975
|
+
new BoundingBox();
|
|
76976
|
+
[
|
|
76977
|
+
new Color(1, 0, 0),
|
|
76978
|
+
new Color(0, 1, 0),
|
|
76979
|
+
new Color(0, 0, 1),
|
|
76980
|
+
new Color(1, 1, 0),
|
|
76981
|
+
new Color(1, 0, 1)
|
|
76982
|
+
];
|
|
76403
76983
|
class GSplatOctreeInstance {
|
|
76404
76984
|
constructor(octree, placement, assetLoader){
|
|
76405
76985
|
this.activePlacements = new Set();
|
|
76406
76986
|
this.dirtyModifiedPlacements = false;
|
|
76407
76987
|
this.pending = new Set();
|
|
76408
76988
|
this.pendingDecrements = new Map();
|
|
76989
|
+
this.removedCandidates = new Set();
|
|
76409
76990
|
this.previousPosition = new Vec3();
|
|
76991
|
+
this.needsLodUpdate = false;
|
|
76992
|
+
this.prefetchPending = new Set();
|
|
76993
|
+
this.pendingVisibleAdds = new Map();
|
|
76410
76994
|
this.octree = octree;
|
|
76411
76995
|
this.placement = placement;
|
|
76412
76996
|
this.assetLoader = assetLoader;
|
|
@@ -76420,16 +77004,27 @@ class GSplatOctreeInstance {
|
|
|
76420
77004
|
this.pendingDecrements.clear();
|
|
76421
77005
|
this.filePlacements.length = 0;
|
|
76422
77006
|
}
|
|
76423
|
-
|
|
77007
|
+
getFileDecrements() {
|
|
77008
|
+
const toRelease = [];
|
|
77009
|
+
for(let i = 0; i < this.filePlacements.length; i++){
|
|
77010
|
+
if (this.filePlacements[i]) {
|
|
77011
|
+
toRelease.push(i);
|
|
77012
|
+
}
|
|
77013
|
+
}
|
|
77014
|
+
return toRelease;
|
|
77015
|
+
}
|
|
77016
|
+
calculateNodeLod(localCameraPosition, localCameraForward, nodeIndex, maxLod, lodDistances, lodBehindPenalty) {
|
|
76424
77017
|
const node = this.octree.nodes[nodeIndex];
|
|
76425
|
-
|
|
76426
|
-
|
|
76427
|
-
|
|
76428
|
-
|
|
76429
|
-
|
|
76430
|
-
|
|
76431
|
-
|
|
76432
|
-
|
|
77018
|
+
_dirToNode.copy(node.bounds.center).sub(localCameraPosition);
|
|
77019
|
+
let distance = _dirToNode.length();
|
|
77020
|
+
if (lodBehindPenalty > 1 && distance > 0.01) {
|
|
77021
|
+
const dotOverDistance = localCameraForward.dot(_dirToNode) / distance;
|
|
77022
|
+
if (dotOverDistance < 0) {
|
|
77023
|
+
const t = -dotOverDistance;
|
|
77024
|
+
const factor = 1 + t * (lodBehindPenalty - 1);
|
|
77025
|
+
distance *= factor;
|
|
77026
|
+
}
|
|
77027
|
+
}
|
|
76433
77028
|
for(let lod = 0; lod < maxLod; lod++){
|
|
76434
77029
|
if (distance < lodDistances[lod]) {
|
|
76435
77030
|
return lod;
|
|
@@ -76437,44 +77032,137 @@ class GSplatOctreeInstance {
|
|
|
76437
77032
|
}
|
|
76438
77033
|
return maxLod;
|
|
76439
77034
|
}
|
|
76440
|
-
|
|
77035
|
+
selectDesiredLodIndex(node, optimalLodIndex, maxLod, lodUnderfillLimit) {
|
|
77036
|
+
if (lodUnderfillLimit > 0) {
|
|
77037
|
+
const allowedMaxCoarseLod = Math.min(maxLod, optimalLodIndex + lodUnderfillLimit);
|
|
77038
|
+
for(let lod = optimalLodIndex; lod <= allowedMaxCoarseLod; lod++){
|
|
77039
|
+
const fi = node.lods[lod].fileIndex;
|
|
77040
|
+
if (fi !== -1 && this.octree.getFileResource(fi)) {
|
|
77041
|
+
return lod;
|
|
77042
|
+
}
|
|
77043
|
+
}
|
|
77044
|
+
for(let lod = allowedMaxCoarseLod; lod >= optimalLodIndex; lod--){
|
|
77045
|
+
const fi = node.lods[lod].fileIndex;
|
|
77046
|
+
if (fi !== -1) {
|
|
77047
|
+
return lod;
|
|
77048
|
+
}
|
|
77049
|
+
}
|
|
77050
|
+
}
|
|
77051
|
+
return optimalLodIndex;
|
|
77052
|
+
}
|
|
77053
|
+
prefetchNextLod(node, desiredLodIndex, optimalLodIndex) {
|
|
77054
|
+
if (desiredLodIndex === -1 || optimalLodIndex === -1) return;
|
|
77055
|
+
if (desiredLodIndex === optimalLodIndex) {
|
|
77056
|
+
const fi = node.lods[optimalLodIndex].fileIndex;
|
|
77057
|
+
if (fi !== -1) {
|
|
77058
|
+
this.octree.ensureFileResource(fi, this.assetLoader);
|
|
77059
|
+
if (!this.octree.getFileResource(fi)) {
|
|
77060
|
+
this.prefetchPending.add(fi);
|
|
77061
|
+
}
|
|
77062
|
+
}
|
|
77063
|
+
return;
|
|
77064
|
+
}
|
|
77065
|
+
const targetLod = Math.max(optimalLodIndex, desiredLodIndex - 1);
|
|
77066
|
+
for(let lod = targetLod; lod >= optimalLodIndex; lod--){
|
|
77067
|
+
const fi = node.lods[lod].fileIndex;
|
|
77068
|
+
if (fi !== -1) {
|
|
77069
|
+
this.octree.ensureFileResource(fi, this.assetLoader);
|
|
77070
|
+
if (!this.octree.getFileResource(fi)) {
|
|
77071
|
+
this.prefetchPending.add(fi);
|
|
77072
|
+
}
|
|
77073
|
+
break;
|
|
77074
|
+
}
|
|
77075
|
+
}
|
|
77076
|
+
}
|
|
77077
|
+
updateLod(cameraNode, params) {
|
|
76441
77078
|
const worldCameraPosition = cameraNode.getPosition();
|
|
76442
77079
|
const octreeWorldTransform = this.placement.node.getWorldTransform();
|
|
76443
77080
|
_invWorldMat.copy(octreeWorldTransform).invert();
|
|
76444
77081
|
const localCameraPosition = _invWorldMat.transformPoint(worldCameraPosition, _localCameraPos);
|
|
77082
|
+
const worldCameraForward = cameraNode.forward;
|
|
77083
|
+
const localCameraForward = _invWorldMat.transformVector(worldCameraForward, _localCameraFwd).normalize();
|
|
76445
77084
|
const maxLod = this.octree.lodLevels - 1;
|
|
77085
|
+
const lodDistances = this.placement.lodDistances || [
|
|
77086
|
+
5,
|
|
77087
|
+
10,
|
|
77088
|
+
15,
|
|
77089
|
+
20,
|
|
77090
|
+
25
|
|
77091
|
+
];
|
|
77092
|
+
const { lodBehindPenalty, lodRangeMin, lodRangeMax, lodUnderfillLimit = 0 } = params;
|
|
77093
|
+
const rangeMin = Math.max(0, Math.min(lodRangeMin ?? 0, maxLod));
|
|
77094
|
+
const rangeMax = Math.max(rangeMin, Math.min(lodRangeMax ?? maxLod, maxLod));
|
|
76446
77095
|
const nodes = this.octree.nodes;
|
|
76447
77096
|
for(let nodeIndex = 0; nodeIndex < nodes.length; nodeIndex++){
|
|
76448
77097
|
const node = nodes[nodeIndex];
|
|
76449
|
-
|
|
77098
|
+
let optimalLodIndex = this.calculateNodeLod(localCameraPosition, localCameraForward, nodeIndex, maxLod, lodDistances, lodBehindPenalty);
|
|
77099
|
+
if (optimalLodIndex < rangeMin) optimalLodIndex = rangeMin;
|
|
77100
|
+
if (optimalLodIndex > rangeMax) optimalLodIndex = rangeMax;
|
|
76450
77101
|
const currentLodIndex = this.nodeLods[nodeIndex];
|
|
76451
|
-
|
|
76452
|
-
|
|
76453
|
-
|
|
76454
|
-
|
|
76455
|
-
|
|
76456
|
-
|
|
76457
|
-
this.
|
|
76458
|
-
|
|
76459
|
-
|
|
77102
|
+
const desiredLodIndex = this.selectDesiredLodIndex(node, optimalLodIndex, maxLod, lodUnderfillLimit);
|
|
77103
|
+
if (desiredLodIndex !== currentLodIndex) {
|
|
77104
|
+
const currentFileIndex = currentLodIndex >= 0 ? node.lods[currentLodIndex].fileIndex : -1;
|
|
77105
|
+
const desiredFileIndex = desiredLodIndex >= 0 ? node.lods[desiredLodIndex].fileIndex : -1;
|
|
77106
|
+
const wasVisible = currentFileIndex !== -1;
|
|
77107
|
+
const willBeVisible = desiredFileIndex !== -1;
|
|
77108
|
+
const pendingEntry = this.pendingDecrements.get(nodeIndex);
|
|
77109
|
+
if (pendingEntry) {
|
|
77110
|
+
if (pendingEntry.newFileIndex !== desiredFileIndex) {
|
|
77111
|
+
const prevPendingPlacement = this.filePlacements[pendingEntry.newFileIndex];
|
|
77112
|
+
if (prevPendingPlacement) {
|
|
77113
|
+
this.decrementFileRef(pendingEntry.newFileIndex, nodeIndex);
|
|
77114
|
+
}
|
|
77115
|
+
if (wasVisible && willBeVisible) {
|
|
77116
|
+
this.pendingDecrements.set(nodeIndex, {
|
|
77117
|
+
oldFileIndex: pendingEntry.oldFileIndex,
|
|
77118
|
+
newFileIndex: desiredFileIndex
|
|
77119
|
+
});
|
|
77120
|
+
} else {
|
|
77121
|
+
this.pendingDecrements.delete(nodeIndex);
|
|
77122
|
+
}
|
|
77123
|
+
}
|
|
77124
|
+
}
|
|
76460
77125
|
if (!wasVisible && willBeVisible) {
|
|
76461
|
-
const
|
|
76462
|
-
|
|
77126
|
+
const prevPendingFi = this.pendingVisibleAdds.get(nodeIndex);
|
|
77127
|
+
if (prevPendingFi !== undefined && prevPendingFi !== desiredFileIndex) {
|
|
77128
|
+
this.decrementFileRef(prevPendingFi, nodeIndex);
|
|
77129
|
+
this.pendingVisibleAdds.delete(nodeIndex);
|
|
77130
|
+
}
|
|
77131
|
+
this.incrementFileRef(desiredFileIndex, nodeIndex, desiredLodIndex);
|
|
77132
|
+
const newPlacement = this.filePlacements[desiredFileIndex];
|
|
77133
|
+
if (newPlacement?.resource) {
|
|
77134
|
+
this.nodeLods[nodeIndex] = desiredLodIndex;
|
|
77135
|
+
this.pendingVisibleAdds.delete(nodeIndex);
|
|
77136
|
+
} else {
|
|
77137
|
+
this.pendingVisibleAdds.set(nodeIndex, desiredFileIndex);
|
|
77138
|
+
}
|
|
76463
77139
|
} else if (wasVisible && !willBeVisible) {
|
|
76464
|
-
const
|
|
76465
|
-
|
|
77140
|
+
const pendingEntry2 = this.pendingDecrements.get(nodeIndex);
|
|
77141
|
+
if (pendingEntry2) {
|
|
77142
|
+
this.decrementFileRef(pendingEntry2.newFileIndex, nodeIndex);
|
|
77143
|
+
this.pendingDecrements.delete(nodeIndex);
|
|
77144
|
+
}
|
|
77145
|
+
this.decrementFileRef(currentFileIndex, nodeIndex);
|
|
77146
|
+
this.nodeLods[nodeIndex] = -1;
|
|
77147
|
+
this.pendingVisibleAdds.delete(nodeIndex);
|
|
76466
77148
|
} else if (wasVisible && willBeVisible) {
|
|
76467
|
-
|
|
76468
|
-
const
|
|
76469
|
-
this.incrementFileRef(newFileIndex, nodeIndex, newLodIndex);
|
|
76470
|
-
const newPlacement = this.filePlacements[newFileIndex];
|
|
77149
|
+
this.incrementFileRef(desiredFileIndex, nodeIndex, desiredLodIndex);
|
|
77150
|
+
const newPlacement = this.filePlacements[desiredFileIndex];
|
|
76471
77151
|
if (newPlacement?.resource) {
|
|
76472
|
-
this.decrementFileRef(
|
|
77152
|
+
this.decrementFileRef(currentFileIndex, nodeIndex);
|
|
77153
|
+
this.pendingDecrements.delete(nodeIndex);
|
|
77154
|
+
this.nodeLods[nodeIndex] = desiredLodIndex;
|
|
77155
|
+
this.pendingVisibleAdds.delete(nodeIndex);
|
|
76473
77156
|
} else {
|
|
76474
|
-
this.pendingDecrements.set(nodeIndex,
|
|
77157
|
+
this.pendingDecrements.set(nodeIndex, {
|
|
77158
|
+
oldFileIndex: currentFileIndex,
|
|
77159
|
+
newFileIndex: desiredFileIndex
|
|
77160
|
+
});
|
|
77161
|
+
this.pendingVisibleAdds.delete(nodeIndex);
|
|
76475
77162
|
}
|
|
76476
77163
|
}
|
|
76477
77164
|
}
|
|
77165
|
+
this.prefetchNextLod(node, desiredLodIndex, optimalLodIndex);
|
|
76478
77166
|
}
|
|
76479
77167
|
}
|
|
76480
77168
|
incrementFileRef(fileIndex, nodeIndex, lodIndex) {
|
|
@@ -76483,9 +77171,12 @@ class GSplatOctreeInstance {
|
|
|
76483
77171
|
if (!placement) {
|
|
76484
77172
|
placement = new GSplatPlacement(null, this.placement.node, lodIndex);
|
|
76485
77173
|
this.filePlacements[fileIndex] = placement;
|
|
77174
|
+
const removeScheduled = this.removedCandidates.delete(fileIndex);
|
|
77175
|
+
if (!removeScheduled) {
|
|
77176
|
+
this.octree.incRefCount(fileIndex);
|
|
77177
|
+
}
|
|
76486
77178
|
if (!this.addFilePlacement(fileIndex)) {
|
|
76487
|
-
|
|
76488
|
-
this.octree.ensureFileResource(fileUrl, this.assetLoader);
|
|
77179
|
+
this.octree.ensureFileResource(fileIndex, this.assetLoader);
|
|
76489
77180
|
this.pending.add(fileIndex);
|
|
76490
77181
|
}
|
|
76491
77182
|
}
|
|
@@ -76499,6 +77190,9 @@ class GSplatOctreeInstance {
|
|
|
76499
77190
|
decrementFileRef(fileIndex, nodeIndex) {
|
|
76500
77191
|
if (fileIndex === -1) return;
|
|
76501
77192
|
const placement = this.filePlacements[fileIndex];
|
|
77193
|
+
if (!placement) {
|
|
77194
|
+
return;
|
|
77195
|
+
}
|
|
76502
77196
|
if (placement) {
|
|
76503
77197
|
placement.intervals.delete(nodeIndex);
|
|
76504
77198
|
this.dirtyModifiedPlacements = true;
|
|
@@ -76506,14 +77200,14 @@ class GSplatOctreeInstance {
|
|
|
76506
77200
|
if (placement.resource) {
|
|
76507
77201
|
this.activePlacements.delete(placement);
|
|
76508
77202
|
}
|
|
77203
|
+
this.removedCandidates.add(fileIndex);
|
|
76509
77204
|
this.filePlacements[fileIndex] = null;
|
|
76510
77205
|
this.pending.delete(fileIndex);
|
|
76511
77206
|
}
|
|
76512
77207
|
}
|
|
76513
77208
|
}
|
|
76514
77209
|
addFilePlacement(fileIndex) {
|
|
76515
|
-
const
|
|
76516
|
-
const res = this.octree.getFileResource(fileUrl);
|
|
77210
|
+
const res = this.octree.getFileResource(fileIndex);
|
|
76517
77211
|
if (res) {
|
|
76518
77212
|
const placement = this.filePlacements[fileIndex];
|
|
76519
77213
|
if (placement) {
|
|
@@ -76521,46 +77215,82 @@ class GSplatOctreeInstance {
|
|
|
76521
77215
|
placement.aabb.copy(res.aabb);
|
|
76522
77216
|
this.activePlacements.add(placement);
|
|
76523
77217
|
this.dirtyModifiedPlacements = true;
|
|
77218
|
+
this.removedCandidates.delete(fileIndex);
|
|
76524
77219
|
return true;
|
|
76525
77220
|
}
|
|
76526
77221
|
}
|
|
76527
77222
|
return false;
|
|
76528
77223
|
}
|
|
76529
|
-
testMoved() {
|
|
77224
|
+
testMoved(threshold) {
|
|
76530
77225
|
const position = this.placement.node.getPosition();
|
|
76531
77226
|
const length = position.distance(this.previousPosition);
|
|
76532
|
-
if (length >
|
|
76533
|
-
this.previousPosition.copy(position);
|
|
77227
|
+
if (length > threshold) {
|
|
76534
77228
|
return true;
|
|
76535
77229
|
}
|
|
76536
77230
|
return false;
|
|
76537
77231
|
}
|
|
76538
|
-
|
|
77232
|
+
updateMoved() {
|
|
77233
|
+
this.previousPosition.copy(this.placement.node.getPosition());
|
|
77234
|
+
}
|
|
77235
|
+
update(scene) {
|
|
76539
77236
|
if (this.pending.size) {
|
|
76540
77237
|
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)) {
|
|
77238
|
+
this.octree.ensureFileResource(fileIndex, this.assetLoader);
|
|
77239
|
+
if (this.addFilePlacement(fileIndex)) {
|
|
76545
77240
|
_tempCompletedUrls.push(fileIndex);
|
|
76546
|
-
for (const [nodeIndex] of
|
|
76547
|
-
|
|
76548
|
-
if (oldFileIndex !== undefined) {
|
|
77241
|
+
for (const [nodeIndex, { oldFileIndex, newFileIndex }] of this.pendingDecrements){
|
|
77242
|
+
if (newFileIndex === fileIndex) {
|
|
76549
77243
|
this.decrementFileRef(oldFileIndex, nodeIndex);
|
|
76550
77244
|
this.pendingDecrements.delete(nodeIndex);
|
|
77245
|
+
let newLodIndex = 0;
|
|
77246
|
+
const nodeLods = this.octree.nodes[nodeIndex].lods;
|
|
77247
|
+
for(let li = 0; li < nodeLods.length; li++){
|
|
77248
|
+
if (nodeLods[li].fileIndex === newFileIndex) {
|
|
77249
|
+
newLodIndex = li;
|
|
77250
|
+
break;
|
|
77251
|
+
}
|
|
77252
|
+
}
|
|
77253
|
+
this.nodeLods[nodeIndex] = newLodIndex;
|
|
76551
77254
|
}
|
|
76552
77255
|
}
|
|
76553
77256
|
}
|
|
76554
77257
|
}
|
|
77258
|
+
if (_tempCompletedUrls.length > 0) {
|
|
77259
|
+
this.needsLodUpdate = true;
|
|
77260
|
+
}
|
|
76555
77261
|
for (const fileIndex of _tempCompletedUrls){
|
|
76556
77262
|
this.pending.delete(fileIndex);
|
|
76557
77263
|
}
|
|
76558
77264
|
_tempCompletedUrls.length = 0;
|
|
76559
77265
|
}
|
|
77266
|
+
this.pollPrefetchCompletions();
|
|
76560
77267
|
const dirty = this.dirtyModifiedPlacements;
|
|
76561
77268
|
this.dirtyModifiedPlacements = false;
|
|
76562
77269
|
return dirty;
|
|
76563
77270
|
}
|
|
77271
|
+
debugRender(scene) {}
|
|
77272
|
+
consumeNeedsLodUpdate() {
|
|
77273
|
+
const v = this.needsLodUpdate;
|
|
77274
|
+
this.needsLodUpdate = false;
|
|
77275
|
+
return v;
|
|
77276
|
+
}
|
|
77277
|
+
pollPrefetchCompletions() {
|
|
77278
|
+
if (this.prefetchPending.size) {
|
|
77279
|
+
for (const fileIndex of this.prefetchPending){
|
|
77280
|
+
this.octree.ensureFileResource(fileIndex, this.assetLoader);
|
|
77281
|
+
if (this.octree.getFileResource(fileIndex)) {
|
|
77282
|
+
_tempCompletedUrls.push(fileIndex);
|
|
77283
|
+
}
|
|
77284
|
+
}
|
|
77285
|
+
if (_tempCompletedUrls.length > 0) {
|
|
77286
|
+
this.needsLodUpdate = true;
|
|
77287
|
+
}
|
|
77288
|
+
for (const fileIndex of _tempCompletedUrls){
|
|
77289
|
+
this.prefetchPending.delete(fileIndex);
|
|
77290
|
+
}
|
|
77291
|
+
_tempCompletedUrls.length = 0;
|
|
77292
|
+
}
|
|
77293
|
+
}
|
|
76564
77294
|
}
|
|
76565
77295
|
|
|
76566
77296
|
const tmpMin = new Vec3();
|
|
@@ -76575,13 +77305,19 @@ class GSplatOctreeNode {
|
|
|
76575
77305
|
}
|
|
76576
77306
|
}
|
|
76577
77307
|
|
|
77308
|
+
const _toDelete = [];
|
|
76578
77309
|
class GSplatOctree {
|
|
76579
77310
|
constructor(assetFileUrl, data){
|
|
76580
77311
|
this.fileResources = new Map();
|
|
76581
|
-
this.
|
|
77312
|
+
this.cooldowns = new Map();
|
|
76582
77313
|
this.lodLevels = data.lodLevels;
|
|
76583
77314
|
this.assetFileUrl = assetFileUrl;
|
|
76584
|
-
|
|
77315
|
+
const baseDir = path.getDirectory(assetFileUrl);
|
|
77316
|
+
this.files = data.filenames.map((url)=>({
|
|
77317
|
+
url: path.isRelativePath(url) ? path.join(baseDir, url) : url,
|
|
77318
|
+
lodLevel: -1
|
|
77319
|
+
}));
|
|
77320
|
+
this.fileRefCounts = new Int32Array(this.files.length);
|
|
76585
77321
|
const leafNodes = [];
|
|
76586
77322
|
this._extractLeafNodes(data.tree, leafNodes);
|
|
76587
77323
|
this.nodes = leafNodes.map((nodeData)=>{
|
|
@@ -76590,11 +77326,12 @@ class GSplatOctree {
|
|
|
76590
77326
|
const lodData = nodeData.lods[i.toString()];
|
|
76591
77327
|
if (lodData) {
|
|
76592
77328
|
lods.push({
|
|
76593
|
-
file: this.files[lodData.file] || '',
|
|
77329
|
+
file: this.files[lodData.file].url || '',
|
|
76594
77330
|
fileIndex: lodData.file,
|
|
76595
77331
|
offset: lodData.offset || 0,
|
|
76596
77332
|
count: lodData.count || 0
|
|
76597
77333
|
});
|
|
77334
|
+
this.files[lodData.file].lodLevel = i;
|
|
76598
77335
|
} else {
|
|
76599
77336
|
lods.push({
|
|
76600
77337
|
file: '',
|
|
@@ -76607,6 +77344,7 @@ class GSplatOctree {
|
|
|
76607
77344
|
return new GSplatOctreeNode(lods, nodeData.bound);
|
|
76608
77345
|
});
|
|
76609
77346
|
}
|
|
77347
|
+
_traceLodCounts() {}
|
|
76610
77348
|
_extractLeafNodes(node, leafNodes) {
|
|
76611
77349
|
if (node.lods) {
|
|
76612
77350
|
leafNodes.push({
|
|
@@ -76619,20 +77357,57 @@ class GSplatOctree {
|
|
|
76619
77357
|
}
|
|
76620
77358
|
}
|
|
76621
77359
|
}
|
|
76622
|
-
|
|
76623
|
-
return
|
|
77360
|
+
getFileResource(fileIndex) {
|
|
77361
|
+
return this.fileResources.get(fileIndex);
|
|
76624
77362
|
}
|
|
76625
|
-
|
|
76626
|
-
|
|
77363
|
+
incRefCount(fileIndex) {
|
|
77364
|
+
const count = this.fileRefCounts[fileIndex] + 1;
|
|
77365
|
+
this.fileRefCounts[fileIndex] = count;
|
|
77366
|
+
this.cooldowns.delete(fileIndex);
|
|
76627
77367
|
}
|
|
76628
|
-
|
|
76629
|
-
|
|
77368
|
+
decRefCount(fileIndex, cooldownTicks) {
|
|
77369
|
+
const count = this.fileRefCounts[fileIndex] - 1;
|
|
77370
|
+
this.fileRefCounts[fileIndex] = count;
|
|
77371
|
+
if (count === 0) {
|
|
77372
|
+
this.cooldowns.set(fileIndex, cooldownTicks);
|
|
77373
|
+
}
|
|
77374
|
+
}
|
|
77375
|
+
unloadResource(fileIndex, assetLoader) {
|
|
77376
|
+
if (this.fileResources.has(fileIndex)) {
|
|
77377
|
+
const fullUrl = this.files[fileIndex].url;
|
|
77378
|
+
assetLoader.unload(fullUrl);
|
|
77379
|
+
this.fileResources.delete(fileIndex);
|
|
77380
|
+
this._traceLodCounts();
|
|
77381
|
+
}
|
|
77382
|
+
}
|
|
77383
|
+
updateCooldownTick(assetLoader) {
|
|
77384
|
+
if (this.cooldowns.size > 0) {
|
|
77385
|
+
this.cooldowns.forEach((remaining, fileIndex)=>{
|
|
77386
|
+
if (remaining <= 1) {
|
|
77387
|
+
if (this.fileRefCounts[fileIndex] === 0) {
|
|
77388
|
+
this.unloadResource(fileIndex, assetLoader);
|
|
77389
|
+
}
|
|
77390
|
+
_toDelete.push(fileIndex);
|
|
77391
|
+
} else {
|
|
77392
|
+
this.cooldowns.set(fileIndex, remaining - 1);
|
|
77393
|
+
}
|
|
77394
|
+
});
|
|
77395
|
+
_toDelete.forEach((idx)=>this.cooldowns.delete(idx));
|
|
77396
|
+
_toDelete.length = 0;
|
|
77397
|
+
}
|
|
77398
|
+
}
|
|
77399
|
+
ensureFileResource(fileIndex, assetLoader) {
|
|
77400
|
+
if (this.fileResources.has(fileIndex)) {
|
|
76630
77401
|
return;
|
|
76631
77402
|
}
|
|
76632
|
-
const fullUrl = this.
|
|
77403
|
+
const fullUrl = this.files[fileIndex].url;
|
|
76633
77404
|
const res = assetLoader.getResource(fullUrl);
|
|
76634
77405
|
if (res) {
|
|
76635
|
-
this.fileResources.set(
|
|
77406
|
+
this.fileResources.set(fileIndex, res);
|
|
77407
|
+
if (this.fileRefCounts[fileIndex] === 0) {
|
|
77408
|
+
this.cooldowns.set(fileIndex, assetLoader.cooldownTicks);
|
|
77409
|
+
}
|
|
77410
|
+
this._traceLodCounts();
|
|
76636
77411
|
return;
|
|
76637
77412
|
}
|
|
76638
77413
|
assetLoader.load(fullUrl);
|
|
@@ -76655,6 +77430,7 @@ class GSplatWorldState {
|
|
|
76655
77430
|
this.splats = [];
|
|
76656
77431
|
this.textureSize = 0;
|
|
76657
77432
|
this.totalUsedPixels = 0;
|
|
77433
|
+
this.pendingReleases = [];
|
|
76658
77434
|
this.version = version;
|
|
76659
77435
|
this.splats = splats;
|
|
76660
77436
|
this.estimateTextureSize(this.splats, device.maxTextureSize);
|
|
@@ -76715,22 +77491,62 @@ const invModelMat = new Mat4();
|
|
|
76715
77491
|
const tempNonOctreePlacements = new Set();
|
|
76716
77492
|
const tempOctreePlacements = new Set();
|
|
76717
77493
|
const _updatedSplats = [];
|
|
77494
|
+
const tempOctreesTicked = new Set();
|
|
77495
|
+
const _lodColorsRaw = [
|
|
77496
|
+
[
|
|
77497
|
+
1,
|
|
77498
|
+
0,
|
|
77499
|
+
0
|
|
77500
|
+
],
|
|
77501
|
+
[
|
|
77502
|
+
0,
|
|
77503
|
+
1,
|
|
77504
|
+
0
|
|
77505
|
+
],
|
|
77506
|
+
[
|
|
77507
|
+
0,
|
|
77508
|
+
0,
|
|
77509
|
+
1
|
|
77510
|
+
],
|
|
77511
|
+
[
|
|
77512
|
+
1,
|
|
77513
|
+
1,
|
|
77514
|
+
0
|
|
77515
|
+
],
|
|
77516
|
+
[
|
|
77517
|
+
1,
|
|
77518
|
+
0,
|
|
77519
|
+
1
|
|
77520
|
+
]
|
|
77521
|
+
];
|
|
77522
|
+
[
|
|
77523
|
+
new Color(1, 0, 0),
|
|
77524
|
+
new Color(0, 1, 0),
|
|
77525
|
+
new Color(0, 0, 1),
|
|
77526
|
+
new Color(1, 1, 0),
|
|
77527
|
+
new Color(1, 0, 1)
|
|
77528
|
+
];
|
|
76718
77529
|
class GSplatManager {
|
|
76719
77530
|
constructor(device, director, layer, cameraNode){
|
|
76720
77531
|
this.node = new GraphNode('GSplatManager');
|
|
76721
77532
|
this.worldStates = new Map();
|
|
76722
77533
|
this.lastWorldStateVersion = 0;
|
|
76723
77534
|
this.sortedVersion = 0;
|
|
77535
|
+
this.framesTillFullUpdate = 0;
|
|
76724
77536
|
this.lastCameraPos = new Vec3(Infinity, Infinity, Infinity);
|
|
77537
|
+
this.lastCameraFwd = new Vec3(Infinity, Infinity, Infinity);
|
|
76725
77538
|
this.layerPlacements = [];
|
|
76726
77539
|
this.layerPlacementsDirty = false;
|
|
76727
77540
|
this.octreeInstances = new Map();
|
|
77541
|
+
this.octreeInstancesToDestroy = [];
|
|
76728
77542
|
this.device = device;
|
|
77543
|
+
this.scene = director.scene;
|
|
76729
77544
|
this.director = director;
|
|
76730
77545
|
this.cameraNode = cameraNode;
|
|
76731
77546
|
this.workBuffer = new GSplatWorkBuffer(device);
|
|
76732
77547
|
this.renderer = new GSplatRenderer(device, this.node, this.cameraNode, layer, this.workBuffer);
|
|
76733
77548
|
this.sorter = this.createSorter();
|
|
77549
|
+
this.cooldownTicks = this.director.assetLoader.cooldownTicks;
|
|
76734
77550
|
}
|
|
76735
77551
|
destroy() {
|
|
76736
77552
|
this.workBuffer.destroy();
|
|
@@ -76759,7 +77575,8 @@ class GSplatManager {
|
|
|
76759
77575
|
for (const [placement, inst] of this.octreeInstances){
|
|
76760
77576
|
if (!tempOctreePlacements.has(placement)) {
|
|
76761
77577
|
this.octreeInstances.delete(placement);
|
|
76762
|
-
|
|
77578
|
+
this.layerPlacementsDirty = true;
|
|
77579
|
+
this.octreeInstancesToDestroy.push(inst);
|
|
76763
77580
|
}
|
|
76764
77581
|
}
|
|
76765
77582
|
this.layerPlacementsDirty = this.layerPlacements.length !== tempNonOctreePlacements.size;
|
|
@@ -76780,9 +77597,6 @@ class GSplatManager {
|
|
|
76780
77597
|
tempOctreePlacements.clear();
|
|
76781
77598
|
}
|
|
76782
77599
|
updateWorldState() {
|
|
76783
|
-
for (const [, inst] of this.octreeInstances){
|
|
76784
|
-
this.layerPlacementsDirty ||= inst.update();
|
|
76785
|
-
}
|
|
76786
77600
|
const worldChanged = this.layerPlacementsDirty || this.worldStates.size === 0;
|
|
76787
77601
|
if (worldChanged) {
|
|
76788
77602
|
this.lastWorldStateVersion++;
|
|
@@ -76793,13 +77607,39 @@ class GSplatManager {
|
|
|
76793
77607
|
}
|
|
76794
77608
|
for (const [, inst] of this.octreeInstances){
|
|
76795
77609
|
inst.activePlacements.forEach((p)=>{
|
|
76796
|
-
|
|
77610
|
+
if (p.resource) {
|
|
77611
|
+
splats.push(new GSplatInfo(this.device, p.resource, p));
|
|
77612
|
+
}
|
|
76797
77613
|
});
|
|
76798
77614
|
}
|
|
76799
77615
|
splats.forEach((splat)=>{
|
|
76800
77616
|
this.sorter.setCenters(splat.resource.id, splat.resource.centers);
|
|
76801
77617
|
});
|
|
76802
77618
|
const newState = new GSplatWorldState(this.device, this.lastWorldStateVersion, splats);
|
|
77619
|
+
for (const [, inst] of this.octreeInstances){
|
|
77620
|
+
if (inst.removedCandidates && inst.removedCandidates.size) {
|
|
77621
|
+
for (const fileIndex of inst.removedCandidates){
|
|
77622
|
+
newState.pendingReleases.push([
|
|
77623
|
+
inst.octree,
|
|
77624
|
+
fileIndex
|
|
77625
|
+
]);
|
|
77626
|
+
}
|
|
77627
|
+
inst.removedCandidates.clear();
|
|
77628
|
+
}
|
|
77629
|
+
}
|
|
77630
|
+
if (this.octreeInstancesToDestroy.length) {
|
|
77631
|
+
for (const inst of this.octreeInstancesToDestroy){
|
|
77632
|
+
const toRelease = inst.getFileDecrements();
|
|
77633
|
+
for (const fileIndex of toRelease){
|
|
77634
|
+
newState.pendingReleases.push([
|
|
77635
|
+
inst.octree,
|
|
77636
|
+
fileIndex
|
|
77637
|
+
]);
|
|
77638
|
+
}
|
|
77639
|
+
inst.destroy();
|
|
77640
|
+
}
|
|
77641
|
+
this.octreeInstancesToDestroy.length = 0;
|
|
77642
|
+
}
|
|
76803
77643
|
this.worldStates.set(this.lastWorldStateVersion, newState);
|
|
76804
77644
|
this.layerPlacementsDirty = false;
|
|
76805
77645
|
}
|
|
@@ -76820,24 +77660,78 @@ class GSplatManager {
|
|
|
76820
77660
|
this.workBuffer.resize(textureSize);
|
|
76821
77661
|
this.renderer.setMaxNumSplats(textureSize * textureSize);
|
|
76822
77662
|
}
|
|
76823
|
-
this.
|
|
77663
|
+
const colorize = this.scene.gsplat.colorizeLod;
|
|
77664
|
+
this.workBuffer.render(worldState.splats, this.cameraNode, colorize ? _lodColorsRaw : undefined);
|
|
77665
|
+
if (worldState.pendingReleases && worldState.pendingReleases.length) {
|
|
77666
|
+
for (const [octree, fileIndex] of worldState.pendingReleases){
|
|
77667
|
+
octree.decRefCount(fileIndex, this.cooldownTicks);
|
|
77668
|
+
}
|
|
77669
|
+
worldState.pendingReleases.length = 0;
|
|
77670
|
+
}
|
|
77671
|
+
this.renderer.setNumSplats(count);
|
|
76824
77672
|
}
|
|
76825
77673
|
this.workBuffer.setOrderData(orderData);
|
|
76826
|
-
this.renderer.setNumSplats(count);
|
|
76827
77674
|
}
|
|
76828
77675
|
}
|
|
76829
|
-
|
|
77676
|
+
testCameraMoved() {
|
|
77677
|
+
const distanceThreshold = this.scene.gsplat.lodUpdateDistance;
|
|
77678
|
+
const currentCameraPos = this.cameraNode.getPosition();
|
|
77679
|
+
const cameraMoved = this.lastCameraPos.distance(currentCameraPos) > distanceThreshold;
|
|
77680
|
+
if (cameraMoved) {
|
|
77681
|
+
return true;
|
|
77682
|
+
}
|
|
77683
|
+
let cameraRotated = false;
|
|
77684
|
+
const lodUpdateAngleDeg = this.scene.gsplat.lodUpdateAngle;
|
|
77685
|
+
if (lodUpdateAngleDeg > 0) {
|
|
77686
|
+
if (Number.isFinite(this.lastCameraFwd.x)) {
|
|
77687
|
+
const currentCameraFwd = this.cameraNode.forward;
|
|
77688
|
+
const dot = Math.min(1, Math.max(-1, this.lastCameraFwd.dot(currentCameraFwd)));
|
|
77689
|
+
const angle = Math.acos(dot);
|
|
77690
|
+
const rotThreshold = lodUpdateAngleDeg * Math.PI / 180;
|
|
77691
|
+
cameraRotated = angle > rotThreshold;
|
|
77692
|
+
} else {
|
|
77693
|
+
cameraRotated = true;
|
|
77694
|
+
}
|
|
77695
|
+
}
|
|
77696
|
+
return cameraMoved || cameraRotated;
|
|
77697
|
+
}
|
|
77698
|
+
update() {
|
|
77699
|
+
let fullUpdate = false;
|
|
77700
|
+
this.framesTillFullUpdate--;
|
|
77701
|
+
if (this.framesTillFullUpdate <= 0) {
|
|
77702
|
+
this.framesTillFullUpdate = 10;
|
|
77703
|
+
if (this.sorter.jobsInFlight < 3) {
|
|
77704
|
+
fullUpdate = true;
|
|
77705
|
+
}
|
|
77706
|
+
}
|
|
77707
|
+
let anyInstanceNeedsLodUpdate = false;
|
|
76830
77708
|
let anyOctreeMoved = false;
|
|
76831
|
-
|
|
76832
|
-
|
|
77709
|
+
let cameraMovedOrRotated = false;
|
|
77710
|
+
if (fullUpdate) {
|
|
77711
|
+
for (const [, inst] of this.octreeInstances){
|
|
77712
|
+
const isDirty = inst.update(this.scene);
|
|
77713
|
+
this.layerPlacementsDirty ||= isDirty;
|
|
77714
|
+
const instNeeds = inst.consumeNeedsLodUpdate();
|
|
77715
|
+
anyInstanceNeedsLodUpdate ||= instNeeds;
|
|
77716
|
+
}
|
|
77717
|
+
const threshold = this.scene.gsplat.lodUpdateDistance;
|
|
77718
|
+
for (const [, inst] of this.octreeInstances){
|
|
77719
|
+
const moved = inst.testMoved(threshold);
|
|
77720
|
+
anyOctreeMoved ||= moved;
|
|
77721
|
+
}
|
|
77722
|
+
cameraMovedOrRotated = this.testCameraMoved();
|
|
76833
77723
|
}
|
|
76834
|
-
|
|
76835
|
-
|
|
76836
|
-
|
|
76837
|
-
if (
|
|
76838
|
-
this.
|
|
77724
|
+
if (this.scene.gsplat.dirty) {
|
|
77725
|
+
this.layerPlacementsDirty = true;
|
|
77726
|
+
}
|
|
77727
|
+
if (cameraMovedOrRotated || anyOctreeMoved || this.scene.gsplat.dirty || anyInstanceNeedsLodUpdate) {
|
|
77728
|
+
for (const [, inst] of this.octreeInstances){
|
|
77729
|
+
inst.updateMoved();
|
|
77730
|
+
}
|
|
77731
|
+
this.lastCameraPos.copy(this.cameraNode.getPosition());
|
|
77732
|
+
this.lastCameraFwd.copy(this.cameraNode.forward);
|
|
76839
77733
|
for (const [, inst] of this.octreeInstances){
|
|
76840
|
-
inst.updateLod(this.cameraNode);
|
|
77734
|
+
inst.updateLod(this.cameraNode, this.scene.gsplat);
|
|
76841
77735
|
}
|
|
76842
77736
|
}
|
|
76843
77737
|
this.updateWorldState();
|
|
@@ -76858,10 +77752,23 @@ class GSplatManager {
|
|
|
76858
77752
|
}
|
|
76859
77753
|
});
|
|
76860
77754
|
if (_updatedSplats.length > 0) {
|
|
76861
|
-
this.
|
|
77755
|
+
const colorize = this.scene.gsplat.colorizeLod;
|
|
77756
|
+
this.workBuffer.render(_updatedSplats, this.cameraNode, colorize ? _lodColorsRaw : undefined);
|
|
76862
77757
|
_updatedSplats.length = 0;
|
|
76863
77758
|
}
|
|
76864
77759
|
}
|
|
77760
|
+
if (this.octreeInstances.size) {
|
|
77761
|
+
for (const [, inst] of this.octreeInstances){
|
|
77762
|
+
const octree = inst.octree;
|
|
77763
|
+
if (!tempOctreesTicked.has(octree)) {
|
|
77764
|
+
tempOctreesTicked.add(octree);
|
|
77765
|
+
octree.updateCooldownTick(this.director.assetLoader);
|
|
77766
|
+
}
|
|
77767
|
+
}
|
|
77768
|
+
tempOctreesTicked.clear();
|
|
77769
|
+
}
|
|
77770
|
+
const { textureSize } = this.workBuffer;
|
|
77771
|
+
return textureSize * textureSize;
|
|
76865
77772
|
}
|
|
76866
77773
|
sort(lastState) {
|
|
76867
77774
|
const cameraNode = this.cameraNode;
|
|
@@ -76874,12 +77781,14 @@ class GSplatManager {
|
|
|
76874
77781
|
invModelMat.copy(modelMat).invert();
|
|
76875
77782
|
const uniformScale = modelMat.getScale().x;
|
|
76876
77783
|
const transformedDirection = invModelMat.transformVector(cameraDirection).normalize();
|
|
77784
|
+
const transformedPosition = invModelMat.transformPoint(cameraPosition);
|
|
76877
77785
|
modelMat.getTranslation(translation);
|
|
76878
77786
|
const offset = translation.sub(cameraPosition).dot(cameraDirection);
|
|
76879
77787
|
const aabbMin = splat.aabb.getMin();
|
|
76880
77788
|
const aabbMax = splat.aabb.getMax();
|
|
76881
77789
|
sorterRequest.push({
|
|
76882
77790
|
transformedDirection,
|
|
77791
|
+
transformedPosition,
|
|
76883
77792
|
offset,
|
|
76884
77793
|
scale: uniformScale,
|
|
76885
77794
|
modelMat: modelMat.data.slice(),
|
|
@@ -76895,7 +77804,7 @@ class GSplatManager {
|
|
|
76895
77804
|
]
|
|
76896
77805
|
});
|
|
76897
77806
|
});
|
|
76898
|
-
this.sorter.setSortParams(sorterRequest);
|
|
77807
|
+
this.sorter.setSortParams(sorterRequest, this.scene.gsplat.radialSorting);
|
|
76899
77808
|
this.renderer.updateViewport(cameraNode);
|
|
76900
77809
|
}
|
|
76901
77810
|
prepareSortParameters(worldState) {
|
|
@@ -76945,13 +77854,17 @@ class GSplatCameraData {
|
|
|
76945
77854
|
}
|
|
76946
77855
|
}
|
|
76947
77856
|
class GSplatDirector {
|
|
76948
|
-
constructor(device, scene, assetLoader){
|
|
77857
|
+
constructor(device, renderer, scene, assetLoader){
|
|
76949
77858
|
this.camerasMap = new Map();
|
|
76950
|
-
this.octrees = new Map();
|
|
76951
77859
|
this.device = device;
|
|
77860
|
+
this.renderer = renderer;
|
|
76952
77861
|
this.assetLoader = assetLoader;
|
|
76953
77862
|
this.scene = scene;
|
|
76954
77863
|
}
|
|
77864
|
+
destroy() {
|
|
77865
|
+
this.camerasMap.forEach((cameraData)=>cameraData.destroy());
|
|
77866
|
+
this.camerasMap.clear();
|
|
77867
|
+
}
|
|
76955
77868
|
getCameraData(camera) {
|
|
76956
77869
|
let cameraData = this.camerasMap.get(camera);
|
|
76957
77870
|
if (!cameraData) {
|
|
@@ -76974,6 +77887,7 @@ class GSplatDirector {
|
|
|
76974
77887
|
});
|
|
76975
77888
|
}
|
|
76976
77889
|
});
|
|
77890
|
+
let gsplatCount = 0;
|
|
76977
77891
|
const camerasComponents = comp.cameras;
|
|
76978
77892
|
for(let i = 0; i < camerasComponents.length; i++){
|
|
76979
77893
|
const camera = camerasComponents[i].camera;
|
|
@@ -76996,10 +77910,14 @@ class GSplatDirector {
|
|
|
76996
77910
|
}
|
|
76997
77911
|
}
|
|
76998
77912
|
}
|
|
76999
|
-
cameraData
|
|
77000
|
-
layerData.
|
|
77001
|
-
|
|
77913
|
+
if (cameraData) {
|
|
77914
|
+
for (const layerData of cameraData.layersMap.values()){
|
|
77915
|
+
gsplatCount += layerData.gsplatManager.update();
|
|
77916
|
+
}
|
|
77917
|
+
}
|
|
77002
77918
|
}
|
|
77919
|
+
this.renderer._gsplatCount = gsplatCount;
|
|
77920
|
+
this.scene.gsplat.dirty = false;
|
|
77003
77921
|
for(let i = 0; i < comp.layerList.length; i++){
|
|
77004
77922
|
comp.layerList[i].gsplatPlacementsDirty = false;
|
|
77005
77923
|
}
|
|
@@ -77010,7 +77928,13 @@ class GSplatComponent extends Component {
|
|
|
77010
77928
|
constructor(system, entity){
|
|
77011
77929
|
super(system, entity), this._layers = [
|
|
77012
77930
|
LAYERID_WORLD
|
|
77013
|
-
], this._instance = null, this._placement = null, this._materialTmp = null, this._highQualitySH = true, this.
|
|
77931
|
+
], this._instance = null, this._placement = null, this._materialTmp = null, this._highQualitySH = true, this._lodDistances = [
|
|
77932
|
+
5,
|
|
77933
|
+
10,
|
|
77934
|
+
15,
|
|
77935
|
+
20,
|
|
77936
|
+
25
|
|
77937
|
+
], this._customAabb = null, this._evtLayersChanged = null, this._evtLayerAdded = null, this._evtLayerRemoved = null, this._castShadows = false, this._unified = false;
|
|
77014
77938
|
this._assetReference = new AssetReference('asset', this, system.app.assets, {
|
|
77015
77939
|
add: this._onGSplatAssetAdded,
|
|
77016
77940
|
load: this._onGSplatAssetLoad,
|
|
@@ -77103,6 +78027,15 @@ class GSplatComponent extends Component {
|
|
|
77103
78027
|
get castShadows() {
|
|
77104
78028
|
return this._castShadows;
|
|
77105
78029
|
}
|
|
78030
|
+
set lodDistances(value) {
|
|
78031
|
+
this._lodDistances = Array.isArray(value) ? value.slice() : null;
|
|
78032
|
+
if (this._placement) {
|
|
78033
|
+
this._placement.lodDistances = this._lodDistances;
|
|
78034
|
+
}
|
|
78035
|
+
}
|
|
78036
|
+
get lodDistances() {
|
|
78037
|
+
return this._lodDistances ? this._lodDistances.slice() : null;
|
|
78038
|
+
}
|
|
77106
78039
|
set unified(value) {
|
|
77107
78040
|
if (this.enabled && this.entity.enabled) {
|
|
77108
78041
|
return;
|
|
@@ -77280,6 +78213,7 @@ class GSplatComponent extends Component {
|
|
|
77280
78213
|
this._placement = null;
|
|
77281
78214
|
if (asset) {
|
|
77282
78215
|
this._placement = new GSplatPlacement(asset.resource, this.entity);
|
|
78216
|
+
this._placement.lodDistances = this._lodDistances;
|
|
77283
78217
|
}
|
|
77284
78218
|
} else {
|
|
77285
78219
|
if (asset) {
|
|
@@ -77312,6 +78246,9 @@ class GSplatAssetLoaderBase {
|
|
|
77312
78246
|
load(url) {}
|
|
77313
78247
|
unload(url) {}
|
|
77314
78248
|
getResource(url) {}
|
|
78249
|
+
constructor(){
|
|
78250
|
+
this.cooldownTicks = 100;
|
|
78251
|
+
}
|
|
77315
78252
|
}
|
|
77316
78253
|
|
|
77317
78254
|
class GSplatAssetLoader extends GSplatAssetLoaderBase {
|
|
@@ -77338,6 +78275,7 @@ class GSplatAssetLoader extends GSplatAssetLoaderBase {
|
|
|
77338
78275
|
unload(url) {
|
|
77339
78276
|
const asset = this._urlToAsset.get(url);
|
|
77340
78277
|
if (asset) {
|
|
78278
|
+
this._registry.remove(asset);
|
|
77341
78279
|
asset.unload();
|
|
77342
78280
|
this._urlToAsset.delete(url);
|
|
77343
78281
|
}
|
|
@@ -77367,7 +78305,7 @@ class GSplatComponentSystem extends ComponentSystem {
|
|
|
77367
78305
|
this.DataType = GSplatComponentData;
|
|
77368
78306
|
this.schema = _schema;
|
|
77369
78307
|
const gsplatAssetLoader = new GSplatAssetLoader(app.assets);
|
|
77370
|
-
app.renderer.gsplatDirector = new GSplatDirector(app.graphicsDevice, app.scene, gsplatAssetLoader);
|
|
78308
|
+
app.renderer.gsplatDirector = new GSplatDirector(app.graphicsDevice, app.renderer, app.scene, gsplatAssetLoader);
|
|
77371
78309
|
this.on('beforeremove', this.onRemove, this);
|
|
77372
78310
|
}
|
|
77373
78311
|
initializeComponentData(component, _data, properties) {
|
|
@@ -81208,8 +82146,9 @@ class GSplatCompressedData {
|
|
|
81208
82146
|
result.halfExtents.set((Mx - mx) * 0.5, (My - my) * 0.5, (Mz - mz) * 0.5);
|
|
81209
82147
|
return true;
|
|
81210
82148
|
}
|
|
81211
|
-
getCenters(
|
|
82149
|
+
getCenters() {
|
|
81212
82150
|
const { vertexData, chunkData, numChunks, chunkSize } = this;
|
|
82151
|
+
const result = new Float32Array(this.numSplats * 3);
|
|
81213
82152
|
let mx, my, mz, Mx, My, Mz;
|
|
81214
82153
|
for(let c = 0; c < numChunks; ++c){
|
|
81215
82154
|
const off = c * chunkSize;
|
|
@@ -81230,6 +82169,7 @@ class GSplatCompressedData {
|
|
|
81230
82169
|
result[i * 3 + 2] = (1 - pz) * mz + pz * Mz;
|
|
81231
82170
|
}
|
|
81232
82171
|
}
|
|
82172
|
+
return result;
|
|
81233
82173
|
}
|
|
81234
82174
|
getChunks(result) {
|
|
81235
82175
|
const { chunkData, numChunks, chunkSize } = this;
|
|
@@ -82027,6 +82967,12 @@ class SogsParser {
|
|
|
82027
82967
|
});
|
|
82028
82968
|
});
|
|
82029
82969
|
const textureAssets = subs.map((sub)=>textures[sub]).flat();
|
|
82970
|
+
asset.once('unload', ()=>{
|
|
82971
|
+
textureAssets.forEach((t)=>{
|
|
82972
|
+
assets.remove(t);
|
|
82973
|
+
t.unload();
|
|
82974
|
+
});
|
|
82975
|
+
});
|
|
82030
82976
|
combineProgress(asset, textureAssets);
|
|
82031
82977
|
textureAssets.forEach((t)=>assets.load(t));
|
|
82032
82978
|
await Promise.allSettled(promises);
|
|
@@ -82042,8 +82988,10 @@ class SogsParser {
|
|
|
82042
82988
|
data.sh_labels = textures.shN?.[1]?.resource;
|
|
82043
82989
|
const decompress = asset.data?.decompress;
|
|
82044
82990
|
if (!decompress) {
|
|
82991
|
+
if (!this.app?.graphicsDevice || this.app?.graphicsDevice?._destroyed) return;
|
|
82045
82992
|
await data.prepareGpuData();
|
|
82046
82993
|
}
|
|
82994
|
+
if (!this.app?.graphicsDevice || this.app?.graphicsDevice?._destroyed) return;
|
|
82047
82995
|
const resource = decompress ? new GSplatResource(this.app.graphicsDevice, await data.decompress()) : new GSplatSogsResource(this.app.graphicsDevice, data);
|
|
82048
82996
|
callback(null, resource);
|
|
82049
82997
|
}
|
|
@@ -82145,13 +83093,49 @@ const inflate = async (compressed)=>{
|
|
|
82145
83093
|
const ab = await new Response(out).arrayBuffer();
|
|
82146
83094
|
return new Uint8Array(ab);
|
|
82147
83095
|
};
|
|
83096
|
+
const downloadArrayBuffer = async (url, asset)=>{
|
|
83097
|
+
const response = await (asset.file?.contents ?? fetch(url.load));
|
|
83098
|
+
if (!response) {
|
|
83099
|
+
throw new Error('Error loading resource');
|
|
83100
|
+
}
|
|
83101
|
+
if (response instanceof Response) {
|
|
83102
|
+
if (!response.ok) {
|
|
83103
|
+
throw new Error(`Error loading resource: ${response.status} ${response.statusText}`);
|
|
83104
|
+
}
|
|
83105
|
+
const totalLength = parseInt(response.headers.get('content-length') ?? '0', 10);
|
|
83106
|
+
if (!response.body || !response.body.getReader) {
|
|
83107
|
+
const buf = await response.arrayBuffer();
|
|
83108
|
+
asset.fire('progress', buf.byteLength, totalLength);
|
|
83109
|
+
return buf;
|
|
83110
|
+
}
|
|
83111
|
+
const reader = response.body.getReader();
|
|
83112
|
+
const chunks = [];
|
|
83113
|
+
let totalReceived = 0;
|
|
83114
|
+
try {
|
|
83115
|
+
while(true){
|
|
83116
|
+
const { done, value } = await reader.read();
|
|
83117
|
+
if (done) {
|
|
83118
|
+
break;
|
|
83119
|
+
}
|
|
83120
|
+
chunks.push(value);
|
|
83121
|
+
totalReceived += value.byteLength;
|
|
83122
|
+
asset.fire('progress', totalReceived, totalLength);
|
|
83123
|
+
}
|
|
83124
|
+
} finally{
|
|
83125
|
+
reader.releaseLock();
|
|
83126
|
+
}
|
|
83127
|
+
return new Blob(chunks).arrayBuffer();
|
|
83128
|
+
}
|
|
83129
|
+
return response;
|
|
83130
|
+
};
|
|
82148
83131
|
class SogBundleParser {
|
|
82149
83132
|
constructor(app, maxRetries = 3){
|
|
82150
83133
|
this.app = app;
|
|
82151
83134
|
this.maxRetries = maxRetries;
|
|
82152
83135
|
}
|
|
82153
|
-
load(url, callback, asset) {
|
|
82154
|
-
|
|
83136
|
+
async load(url, callback, asset) {
|
|
83137
|
+
try {
|
|
83138
|
+
const arrayBuffer = await downloadArrayBuffer(url, asset);
|
|
82155
83139
|
const files = parseZipArchive(arrayBuffer);
|
|
82156
83140
|
for (const file of files){
|
|
82157
83141
|
if (file.compression === 'deflate') {
|
|
@@ -82209,6 +83193,13 @@ class SogBundleParser {
|
|
|
82209
83193
|
}
|
|
82210
83194
|
Object.values(textures).forEach((t)=>this.app.assets.load(t));
|
|
82211
83195
|
await Promise.allSettled(promises);
|
|
83196
|
+
const { assets } = this.app;
|
|
83197
|
+
asset.once('unload', ()=>{
|
|
83198
|
+
Object.values(textures).forEach((t)=>{
|
|
83199
|
+
assets.remove(t);
|
|
83200
|
+
t.unload();
|
|
83201
|
+
});
|
|
83202
|
+
});
|
|
82212
83203
|
const data = new GSplatSogsData();
|
|
82213
83204
|
data.meta = meta;
|
|
82214
83205
|
data.numSplats = meta.count;
|
|
@@ -82225,14 +83216,9 @@ class SogBundleParser {
|
|
|
82225
83216
|
}
|
|
82226
83217
|
const resource = decompress ? new GSplatResource(this.app.graphicsDevice, await data.decompress()) : new GSplatSogsResource(this.app.graphicsDevice, data);
|
|
82227
83218
|
callback(null, resource);
|
|
82228
|
-
}
|
|
82229
|
-
|
|
82230
|
-
|
|
82231
|
-
callback(error);
|
|
82232
|
-
} else {
|
|
82233
|
-
handleArrayBuffer(arrayBuffer);
|
|
82234
|
-
}
|
|
82235
|
-
}, asset, this.maxRetries);
|
|
83219
|
+
} catch (err) {
|
|
83220
|
+
callback(err);
|
|
83221
|
+
}
|
|
82236
83222
|
}
|
|
82237
83223
|
}
|
|
82238
83224
|
|
|
@@ -83822,6 +84808,13 @@ class Template {
|
|
|
83822
84808
|
const parser = new SceneParser(this._app, true);
|
|
83823
84809
|
this._templateRoot = parser.parse(this._data);
|
|
83824
84810
|
}
|
|
84811
|
+
set data(value) {
|
|
84812
|
+
this._data = value;
|
|
84813
|
+
this._templateRoot = null;
|
|
84814
|
+
}
|
|
84815
|
+
get data() {
|
|
84816
|
+
return this._data;
|
|
84817
|
+
}
|
|
83825
84818
|
}
|
|
83826
84819
|
|
|
83827
84820
|
class TemplateHandler extends ResourceHandler {
|
|
@@ -83854,6 +84847,13 @@ class TemplateHandler extends ResourceHandler {
|
|
|
83854
84847
|
this.decoder ??= new TextDecoder('utf-8');
|
|
83855
84848
|
return new Template(this._app, JSON.parse(this.decoder.decode(data)));
|
|
83856
84849
|
}
|
|
84850
|
+
patch(asset, registry) {
|
|
84851
|
+
if (!asset || !asset.resource || !asset.data || !asset.data.entities) {
|
|
84852
|
+
return;
|
|
84853
|
+
}
|
|
84854
|
+
const template = asset.resource;
|
|
84855
|
+
template.data = asset.data;
|
|
84856
|
+
}
|
|
83857
84857
|
}
|
|
83858
84858
|
|
|
83859
84859
|
class TextHandler extends ResourceHandler {
|
|
@@ -88684,7 +89684,8 @@ class MiniStats {
|
|
|
88684
89684
|
'7',
|
|
88685
89685
|
'8',
|
|
88686
89686
|
'9',
|
|
88687
|
-
'.'
|
|
89687
|
+
'.',
|
|
89688
|
+
'-'
|
|
88688
89689
|
].concat(this.graphs.map((graph)=>graph.name)).concat(options.stats ? options.stats.map((stat)=>stat.unitsName) : []).filter((item)=>!!item));
|
|
88689
89690
|
this.wordAtlas = new WordAtlas(device, words);
|
|
88690
89691
|
this.sizes = options.sizes;
|
|
@@ -94800,37 +95801,201 @@ class XrControllers extends Script {
|
|
|
94800
95801
|
/** @import { XrInputSource } from 'playcanvas' */
|
|
94801
95802
|
|
|
94802
95803
|
/**
|
|
94803
|
-
* Handles VR
|
|
94804
|
-
*
|
|
94805
|
-
*
|
|
94806
|
-
*
|
|
95804
|
+
* Handles VR navigation with support for both teleportation and smooth locomotion.
|
|
95805
|
+
* Both methods can be enabled simultaneously, allowing users to choose their preferred
|
|
95806
|
+
* navigation method on the fly.
|
|
95807
|
+
*
|
|
95808
|
+
* Teleportation: Point and teleport using trigger/pinch gestures
|
|
95809
|
+
* Smooth Locomotion: Use left thumbstick for movement and right thumbstick for snap turning
|
|
94807
95810
|
*
|
|
94808
95811
|
* This script should be attached to a parent entity of the camera entity used for the XR
|
|
94809
|
-
* session.
|
|
94810
|
-
* the
|
|
95812
|
+
* session. The entity hierarchy should be: XrNavigationEntity > CameraEntity for proper
|
|
95813
|
+
* locomotion handling. Use it in conjunction with the `XrControllers` script.
|
|
94811
95814
|
*/
|
|
94812
95815
|
class XrNavigation extends Script {
|
|
94813
95816
|
static scriptName = 'xrNavigation';
|
|
94814
95817
|
|
|
95818
|
+
/**
|
|
95819
|
+
* Enable teleportation navigation using trigger/pinch gestures.
|
|
95820
|
+
* @attribute
|
|
95821
|
+
*/
|
|
95822
|
+
enableTeleport = true;
|
|
95823
|
+
|
|
95824
|
+
/**
|
|
95825
|
+
* Enable smooth locomotion using thumbsticks.
|
|
95826
|
+
* @attribute
|
|
95827
|
+
*/
|
|
95828
|
+
enableMove = true;
|
|
95829
|
+
|
|
95830
|
+
/**
|
|
95831
|
+
* Speed of smooth locomotion movement in meters per second.
|
|
95832
|
+
* @attribute
|
|
95833
|
+
* @range [0.1, 10]
|
|
95834
|
+
* @enabledif {enableMove}
|
|
95835
|
+
*/
|
|
95836
|
+
movementSpeed = 1.5;
|
|
95837
|
+
|
|
95838
|
+
/**
|
|
95839
|
+
* Angle in degrees for each snap turn.
|
|
95840
|
+
* @attribute
|
|
95841
|
+
* @range [15, 180]
|
|
95842
|
+
* @enabledif {enableMove}
|
|
95843
|
+
*/
|
|
95844
|
+
rotateSpeed = 45;
|
|
95845
|
+
|
|
95846
|
+
/**
|
|
95847
|
+
* Thumbstick deadzone threshold for movement.
|
|
95848
|
+
* @attribute
|
|
95849
|
+
* @range [0, 0.5]
|
|
95850
|
+
* @precision 0.01
|
|
95851
|
+
* @enabledif {enableMove}
|
|
95852
|
+
*/
|
|
95853
|
+
movementThreshold = 0.1;
|
|
95854
|
+
|
|
95855
|
+
/**
|
|
95856
|
+
* Thumbstick threshold to trigger snap turning.
|
|
95857
|
+
* @attribute
|
|
95858
|
+
* @range [0.1, 1]
|
|
95859
|
+
* @precision 0.01
|
|
95860
|
+
* @enabledif {enableMove}
|
|
95861
|
+
*/
|
|
95862
|
+
rotateThreshold = 0.5;
|
|
95863
|
+
|
|
95864
|
+
/**
|
|
95865
|
+
* Thumbstick threshold to reset snap turn state.
|
|
95866
|
+
* @attribute
|
|
95867
|
+
* @range [0.05, 0.5]
|
|
95868
|
+
* @precision 0.01
|
|
95869
|
+
* @enabledif {enableMove}
|
|
95870
|
+
*/
|
|
95871
|
+
rotateResetThreshold = 0.25;
|
|
95872
|
+
|
|
95873
|
+
/**
|
|
95874
|
+
* Maximum distance for teleportation in meters.
|
|
95875
|
+
* @attribute
|
|
95876
|
+
* @range [1, 50]
|
|
95877
|
+
* @enabledif {enableTeleport}
|
|
95878
|
+
*/
|
|
95879
|
+
maxTeleportDistance = 10;
|
|
95880
|
+
|
|
95881
|
+
/**
|
|
95882
|
+
* Radius of the teleport target indicator circle.
|
|
95883
|
+
* @attribute
|
|
95884
|
+
* @range [0.1, 2]
|
|
95885
|
+
* @precision 0.1
|
|
95886
|
+
* @enabledif {enableTeleport}
|
|
95887
|
+
*/
|
|
95888
|
+
teleportIndicatorRadius = 0.2;
|
|
95889
|
+
|
|
95890
|
+
/**
|
|
95891
|
+
* Number of segments for the teleport indicator circle.
|
|
95892
|
+
* @attribute
|
|
95893
|
+
* @range [8, 64]
|
|
95894
|
+
* @enabledif {enableTeleport}
|
|
95895
|
+
*/
|
|
95896
|
+
teleportIndicatorSegments = 16;
|
|
95897
|
+
|
|
95898
|
+
/**
|
|
95899
|
+
* Color for valid teleportation areas.
|
|
95900
|
+
* @attribute
|
|
95901
|
+
* @enabledif {enableTeleport}
|
|
95902
|
+
*/
|
|
95903
|
+
validTeleportColor = new Color(0, 1, 0);
|
|
95904
|
+
|
|
95905
|
+
/**
|
|
95906
|
+
* Color for invalid teleportation areas.
|
|
95907
|
+
* @attribute
|
|
95908
|
+
* @enabledif {enableTeleport}
|
|
95909
|
+
*/
|
|
95910
|
+
invalidTeleportColor = new Color(1, 0, 0);
|
|
95911
|
+
|
|
95912
|
+
/**
|
|
95913
|
+
* Color for controller rays.
|
|
95914
|
+
* @attribute
|
|
95915
|
+
* @enabledif {enableMove}
|
|
95916
|
+
*/
|
|
95917
|
+
controllerRayColor = new Color(1, 1, 1);
|
|
95918
|
+
|
|
94815
95919
|
/** @type {Set<XrInputSource>} */
|
|
94816
95920
|
inputSources = new Set();
|
|
94817
95921
|
|
|
94818
95922
|
/** @type {Map<XrInputSource, boolean>} */
|
|
94819
95923
|
activePointers = new Map();
|
|
94820
95924
|
|
|
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
95925
|
/** @type {Map<XrInputSource, { handleSelectStart: Function, handleSelectEnd: Function }>} */
|
|
94826
95926
|
inputHandlers = new Map();
|
|
94827
95927
|
|
|
95928
|
+
// Rotation state for snap turning
|
|
95929
|
+
lastRotateValue = 0;
|
|
95930
|
+
|
|
95931
|
+
// Pre-allocated objects for performance (object pooling)
|
|
95932
|
+
tmpVec2A = new Vec2();
|
|
95933
|
+
|
|
95934
|
+
tmpVec2B = new Vec2();
|
|
95935
|
+
|
|
95936
|
+
tmpVec3A = new Vec3();
|
|
95937
|
+
|
|
95938
|
+
tmpVec3B = new Vec3();
|
|
95939
|
+
|
|
95940
|
+
// Color objects
|
|
95941
|
+
validColor = new Color();
|
|
95942
|
+
|
|
95943
|
+
invalidColor = new Color();
|
|
95944
|
+
|
|
95945
|
+
rayColor = new Color();
|
|
95946
|
+
|
|
95947
|
+
// Camera reference for movement calculations
|
|
95948
|
+
/** @type {import('playcanvas').Entity | null} */
|
|
95949
|
+
cameraEntity = null;
|
|
95950
|
+
|
|
94828
95951
|
initialize() {
|
|
94829
95952
|
if (!this.app.xr) {
|
|
94830
95953
|
console.error('XrNavigation script requires XR to be enabled on the application');
|
|
94831
95954
|
return;
|
|
94832
95955
|
}
|
|
94833
95956
|
|
|
95957
|
+
// Log enabled navigation methods
|
|
95958
|
+
const methods = [];
|
|
95959
|
+
if (this.enableTeleport) methods.push('teleportation');
|
|
95960
|
+
if (this.enableMove) methods.push('smooth movement');
|
|
95961
|
+
console.log(`XrNavigation: Enabled methods - ${methods.join(', ')}`);
|
|
95962
|
+
|
|
95963
|
+
if (!this.enableTeleport && !this.enableMove) {
|
|
95964
|
+
console.warn('XrNavigation: Both teleportation and movement are disabled. Navigation will not work.');
|
|
95965
|
+
}
|
|
95966
|
+
|
|
95967
|
+
// Initialize color objects from Color attributes
|
|
95968
|
+
this.validColor.copy(this.validTeleportColor);
|
|
95969
|
+
this.invalidColor.copy(this.invalidTeleportColor);
|
|
95970
|
+
this.rayColor.copy(this.controllerRayColor);
|
|
95971
|
+
|
|
95972
|
+
// Find camera entity - should be a child of this entity
|
|
95973
|
+
const cameraComponent = this.entity.findComponent('camera');
|
|
95974
|
+
this.cameraEntity = cameraComponent ? cameraComponent.entity : null;
|
|
95975
|
+
|
|
95976
|
+
if (!this.cameraEntity) {
|
|
95977
|
+
console.warn('XrNavigation: Camera entity not found. Looking for camera in children...');
|
|
95978
|
+
|
|
95979
|
+
// First try to find by name - cast to Entity since we know it should be one
|
|
95980
|
+
const foundByName = this.entity.findByName('camera');
|
|
95981
|
+
this.cameraEntity = /** @type {import('playcanvas').Entity | null} */ (foundByName);
|
|
95982
|
+
|
|
95983
|
+
// If not found, search children for entity with camera component
|
|
95984
|
+
if (!this.cameraEntity) {
|
|
95985
|
+
for (const child of this.entity.children) {
|
|
95986
|
+
const childEntity = /** @type {import('playcanvas').Entity} */ (child);
|
|
95987
|
+
if (childEntity.camera) {
|
|
95988
|
+
this.cameraEntity = childEntity;
|
|
95989
|
+
break;
|
|
95990
|
+
}
|
|
95991
|
+
}
|
|
95992
|
+
}
|
|
95993
|
+
|
|
95994
|
+
if (!this.cameraEntity) {
|
|
95995
|
+
console.error('XrNavigation: No camera entity found. Movement calculations may not work correctly.');
|
|
95996
|
+
}
|
|
95997
|
+
}
|
|
95998
|
+
|
|
94834
95999
|
this.app.xr.input.on('add', (inputSource) => {
|
|
94835
96000
|
const handleSelectStart = () => {
|
|
94836
96001
|
this.activePointers.set(inputSource, true);
|
|
@@ -94888,9 +96053,91 @@ class XrNavigation extends Script {
|
|
|
94888
96053
|
}
|
|
94889
96054
|
}
|
|
94890
96055
|
|
|
94891
|
-
update() {
|
|
96056
|
+
update(dt) {
|
|
96057
|
+
// Handle smooth locomotion and snap turning
|
|
96058
|
+
if (this.enableMove) {
|
|
96059
|
+
this.handleSmoothLocomotion(dt);
|
|
96060
|
+
}
|
|
96061
|
+
|
|
96062
|
+
// Handle teleportation
|
|
96063
|
+
if (this.enableTeleport) {
|
|
96064
|
+
this.handleTeleportation();
|
|
96065
|
+
}
|
|
96066
|
+
|
|
96067
|
+
// Always show controller rays for debugging/visualization
|
|
96068
|
+
this.renderControllerRays();
|
|
96069
|
+
}
|
|
96070
|
+
|
|
96071
|
+
handleSmoothLocomotion(dt) {
|
|
96072
|
+
if (!this.cameraEntity) return;
|
|
96073
|
+
|
|
96074
|
+
for (const inputSource of this.inputSources) {
|
|
96075
|
+
// Only process controllers with gamepads
|
|
96076
|
+
if (!inputSource.gamepad) continue;
|
|
96077
|
+
|
|
96078
|
+
// Left controller - movement
|
|
96079
|
+
if (inputSource.handedness === 'left') {
|
|
96080
|
+
// Get thumbstick input (axes[2] = X, axes[3] = Y)
|
|
96081
|
+
this.tmpVec2A.set(inputSource.gamepad.axes[2], inputSource.gamepad.axes[3]);
|
|
96082
|
+
|
|
96083
|
+
// Check if input exceeds deadzone
|
|
96084
|
+
if (this.tmpVec2A.length() > this.movementThreshold) {
|
|
96085
|
+
this.tmpVec2A.normalize();
|
|
96086
|
+
|
|
96087
|
+
// Calculate camera-relative movement direction
|
|
96088
|
+
const forward = this.cameraEntity.forward;
|
|
96089
|
+
this.tmpVec2B.x = forward.x;
|
|
96090
|
+
this.tmpVec2B.y = forward.z;
|
|
96091
|
+
this.tmpVec2B.normalize();
|
|
96092
|
+
|
|
96093
|
+
// Calculate rotation angle based on camera yaw
|
|
96094
|
+
const rad = Math.atan2(this.tmpVec2B.x, this.tmpVec2B.y) - Math.PI / 2;
|
|
96095
|
+
|
|
96096
|
+
// Apply rotation to movement vector
|
|
96097
|
+
const t = this.tmpVec2A.x * Math.sin(rad) - this.tmpVec2A.y * Math.cos(rad);
|
|
96098
|
+
this.tmpVec2A.y = this.tmpVec2A.y * Math.sin(rad) + this.tmpVec2A.x * Math.cos(rad);
|
|
96099
|
+
this.tmpVec2A.x = t;
|
|
96100
|
+
|
|
96101
|
+
// Scale by movement speed and delta time
|
|
96102
|
+
this.tmpVec2A.mulScalar(this.movementSpeed * dt);
|
|
96103
|
+
|
|
96104
|
+
// Apply movement to camera parent (this entity)
|
|
96105
|
+
this.entity.translate(this.tmpVec2A.x, 0, this.tmpVec2A.y);
|
|
96106
|
+
}
|
|
96107
|
+
} else if (inputSource.handedness === 'right') { // Right controller - snap turning
|
|
96108
|
+
this.handleSnapTurning(inputSource);
|
|
96109
|
+
}
|
|
96110
|
+
}
|
|
96111
|
+
}
|
|
96112
|
+
|
|
96113
|
+
handleSnapTurning(inputSource) {
|
|
96114
|
+
// Get rotation input from right thumbstick X-axis
|
|
96115
|
+
const rotate = -inputSource.gamepad.axes[2];
|
|
96116
|
+
|
|
96117
|
+
// Hysteresis system to prevent multiple rotations from single gesture
|
|
96118
|
+
if (this.lastRotateValue > 0 && rotate < this.rotateResetThreshold) {
|
|
96119
|
+
this.lastRotateValue = 0;
|
|
96120
|
+
} else if (this.lastRotateValue < 0 && rotate > -this.rotateResetThreshold) {
|
|
96121
|
+
this.lastRotateValue = 0;
|
|
96122
|
+
}
|
|
96123
|
+
|
|
96124
|
+
// Only rotate when thumbstick crosses threshold from neutral position
|
|
96125
|
+
if (this.lastRotateValue === 0 && Math.abs(rotate) > this.rotateThreshold) {
|
|
96126
|
+
this.lastRotateValue = Math.sign(rotate);
|
|
96127
|
+
|
|
96128
|
+
if (this.cameraEntity) {
|
|
96129
|
+
// Rotate around camera position, not entity origin
|
|
96130
|
+
this.tmpVec3A.copy(this.cameraEntity.getLocalPosition());
|
|
96131
|
+
this.entity.translateLocal(this.tmpVec3A);
|
|
96132
|
+
this.entity.rotateLocal(0, Math.sign(rotate) * this.rotateSpeed, 0);
|
|
96133
|
+
this.entity.translateLocal(this.tmpVec3A.mulScalar(-1));
|
|
96134
|
+
}
|
|
96135
|
+
}
|
|
96136
|
+
}
|
|
96137
|
+
|
|
96138
|
+
handleTeleportation() {
|
|
94892
96139
|
for (const inputSource of this.inputSources) {
|
|
94893
|
-
// Only show ray when trigger is pressed
|
|
96140
|
+
// Only show teleportation ray when trigger/select is pressed
|
|
94894
96141
|
if (!this.activePointers.get(inputSource)) continue;
|
|
94895
96142
|
|
|
94896
96143
|
const start = inputSource.getOrigin();
|
|
@@ -94898,24 +96145,42 @@ class XrNavigation extends Script {
|
|
|
94898
96145
|
|
|
94899
96146
|
const hitPoint = this.findPlaneIntersection(start, direction);
|
|
94900
96147
|
|
|
94901
|
-
if (hitPoint) {
|
|
96148
|
+
if (hitPoint && this.isValidTeleportDistance(hitPoint)) {
|
|
94902
96149
|
// Draw line to intersection point
|
|
94903
96150
|
this.app.drawLine(start, hitPoint, this.validColor);
|
|
94904
96151
|
this.drawTeleportIndicator(hitPoint);
|
|
94905
96152
|
} else {
|
|
94906
|
-
// Draw full length ray if no intersection
|
|
94907
|
-
|
|
94908
|
-
|
|
94909
|
-
);
|
|
94910
|
-
this.app.drawLine(start, end, this.invalidColor);
|
|
96153
|
+
// Draw full length ray if no intersection or invalid distance
|
|
96154
|
+
this.tmpVec3B.copy(direction).mulScalar(this.maxTeleportDistance).add(start);
|
|
96155
|
+
this.app.drawLine(start, this.tmpVec3B, this.invalidColor);
|
|
94911
96156
|
}
|
|
94912
96157
|
}
|
|
94913
96158
|
}
|
|
94914
96159
|
|
|
96160
|
+
renderControllerRays() {
|
|
96161
|
+
// Only render controller rays when smooth movement is enabled
|
|
96162
|
+
// (teleport rays are handled separately in handleTeleportation)
|
|
96163
|
+
if (!this.enableMove) return;
|
|
96164
|
+
|
|
96165
|
+
for (const inputSource of this.inputSources) {
|
|
96166
|
+
// Skip if currently teleporting (handled by handleTeleportation)
|
|
96167
|
+
if (this.activePointers.get(inputSource)) continue;
|
|
96168
|
+
|
|
96169
|
+
const start = inputSource.getOrigin();
|
|
96170
|
+
this.tmpVec3B.copy(inputSource.getDirection()).mulScalar(2).add(start);
|
|
96171
|
+
this.app.drawLine(start, this.tmpVec3B, this.rayColor);
|
|
96172
|
+
}
|
|
96173
|
+
}
|
|
96174
|
+
|
|
96175
|
+
isValidTeleportDistance(hitPoint) {
|
|
96176
|
+
const distance = hitPoint.distance(this.entity.getPosition());
|
|
96177
|
+
return distance <= this.maxTeleportDistance;
|
|
96178
|
+
}
|
|
96179
|
+
|
|
94915
96180
|
drawTeleportIndicator(point) {
|
|
94916
|
-
// Draw a circle at the teleport point
|
|
94917
|
-
const segments =
|
|
94918
|
-
const radius =
|
|
96181
|
+
// Draw a circle at the teleport point using configurable attributes
|
|
96182
|
+
const segments = this.teleportIndicatorSegments;
|
|
96183
|
+
const radius = this.teleportIndicatorRadius;
|
|
94919
96184
|
|
|
94920
96185
|
for (let i = 0; i < segments; i++) {
|
|
94921
96186
|
const angle1 = (i / segments) * Math.PI * 2;
|
|
@@ -94926,11 +96191,11 @@ class XrNavigation extends Script {
|
|
|
94926
96191
|
const x2 = point.x + Math.cos(angle2) * radius;
|
|
94927
96192
|
const z2 = point.z + Math.sin(angle2) * radius;
|
|
94928
96193
|
|
|
94929
|
-
|
|
94930
|
-
|
|
94931
|
-
|
|
94932
|
-
|
|
94933
|
-
);
|
|
96194
|
+
// Use pre-allocated vectors to avoid garbage collection
|
|
96195
|
+
this.tmpVec3A.set(x1, 0.01, z1); // Slightly above ground to avoid z-fighting
|
|
96196
|
+
this.tmpVec3B.set(x2, 0.01, z2);
|
|
96197
|
+
|
|
96198
|
+
this.app.drawLine(this.tmpVec3A, this.tmpVec3B, this.validColor);
|
|
94934
96199
|
}
|
|
94935
96200
|
}
|
|
94936
96201
|
}
|