@playcanvas/supersplat-viewer 1.16.12 → 1.17.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/public/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const TRACEID_GPU_TIMINGS = 'GpuTimings';
2
2
 
3
- const version$1 = '2.17.0-preview.1';
4
- const revision = 'de9389a';
3
+ const version$1 = '2.17.0';
4
+ const revision = '4322c03';
5
5
  function extend(target, ex) {
6
6
  for(const prop in ex){
7
7
  const copy = ex[prop];
@@ -3675,6 +3675,8 @@ const CLEARFLAG_STENCIL = 4;
3675
3675
  const CULLFACE_NONE = 0;
3676
3676
  const CULLFACE_BACK = 1;
3677
3677
  const CULLFACE_FRONT = 2;
3678
+ const FRONTFACE_CCW = 0;
3679
+ const FRONTFACE_CW = 1;
3678
3680
  const FILTER_NEAREST = 0;
3679
3681
  const FILTER_LINEAR = 1;
3680
3682
  const FILTER_NEAREST_MIPMAP_NEAREST = 2;
@@ -6544,6 +6546,7 @@ class GraphicsDevice extends EventHandler {
6544
6546
  this.blendState = new BlendState();
6545
6547
  this.depthState = new DepthState();
6546
6548
  this.cullMode = CULLFACE_BACK;
6549
+ this.frontFace = FRONTFACE_CCW;
6547
6550
  this.vx = this.vy = this.vw = this.vh = 0;
6548
6551
  this.sx = this.sy = this.sw = this.sh = 0;
6549
6552
  this.blendColor = new Color(0, 0, 0, 0);
@@ -6553,6 +6556,14 @@ class GraphicsDevice extends EventHandler {
6553
6556
  setBlendColor(r, g, b, a) {}
6554
6557
  setDepthState(depthState) {}
6555
6558
  setCullMode(cullMode) {}
6559
+ setFrontFace(frontFace) {}
6560
+ setDrawStates(blendState = BlendState.NOBLEND, depthState = DepthState.NODEPTH, cullMode = CULLFACE_NONE, frontFace = FRONTFACE_CCW, stencilFront, stencilBack) {
6561
+ this.setBlendState(blendState);
6562
+ this.setDepthState(depthState);
6563
+ this.setCullMode(cullMode);
6564
+ this.setFrontFace(frontFace);
6565
+ this.setStencilState(stencilFront, stencilBack);
6566
+ }
6556
6567
  setRenderTarget(renderTarget) {
6557
6568
  this.renderTarget = renderTarget;
6558
6569
  }
@@ -7409,6 +7420,10 @@ const _cullModes = [
7409
7420
  'back',
7410
7421
  'front'
7411
7422
  ];
7423
+ const _frontFace = [
7424
+ 'ccw',
7425
+ 'cw'
7426
+ ];
7412
7427
  const _stencilOps = [
7413
7428
  'keep',
7414
7429
  'zero',
@@ -7427,7 +7442,7 @@ const _indexFormat = [
7427
7442
  let CacheEntry$1 = class CacheEntry {
7428
7443
  };
7429
7444
  class WebgpuRenderPipeline extends WebgpuPipeline {
7430
- get(primitive, vertexFormat0, vertexFormat1, ibFormat, shader, renderTarget, bindGroupFormats, blendState, depthState, cullMode, stencilEnabled, stencilFront, stencilBack) {
7445
+ get(primitive, vertexFormat0, vertexFormat1, ibFormat, shader, renderTarget, bindGroupFormats, blendState, depthState, cullMode, stencilEnabled, stencilFront, stencilBack, frontFace) {
7431
7446
  const primitiveType = primitive.type;
7432
7447
  if (ibFormat && primitiveType !== PRIMITIVE_LINESTRIP && primitiveType !== PRIMITIVE_TRISTRIP) {
7433
7448
  ibFormat = undefined;
@@ -7447,6 +7462,7 @@ class WebgpuRenderPipeline extends WebgpuPipeline {
7447
7462
  lookupHashes[11] = stencilEnabled ? stencilFront.key : 0;
7448
7463
  lookupHashes[12] = stencilEnabled ? stencilBack.key : 0;
7449
7464
  lookupHashes[13] = ibFormat ?? 0;
7465
+ lookupHashes[14] = frontFace;
7450
7466
  const hash = hash32Fnv1a(lookupHashes);
7451
7467
  let cacheEntries = this.cache.get(hash);
7452
7468
  if (cacheEntries) {
@@ -7462,7 +7478,7 @@ class WebgpuRenderPipeline extends WebgpuPipeline {
7462
7478
  const vertexBufferLayout = this.vertexBufferLayout.get(vertexFormat0, vertexFormat1);
7463
7479
  const cacheEntry = new CacheEntry$1();
7464
7480
  cacheEntry.hashes = new Uint32Array(lookupHashes);
7465
- cacheEntry.pipeline = this.create(primitiveTopology, ibFormat, shader, renderTarget, pipelineLayout, blendState, depthState, vertexBufferLayout, cullMode, stencilEnabled, stencilFront, stencilBack);
7481
+ cacheEntry.pipeline = this.create(primitiveTopology, ibFormat, shader, renderTarget, pipelineLayout, blendState, depthState, vertexBufferLayout, cullMode, stencilEnabled, stencilFront, stencilBack, frontFace);
7466
7482
  if (cacheEntries) {
7467
7483
  cacheEntries.push(cacheEntry);
7468
7484
  } else {
@@ -7527,7 +7543,7 @@ class WebgpuRenderPipeline extends WebgpuPipeline {
7527
7543
  }
7528
7544
  return depthStencil;
7529
7545
  }
7530
- create(primitiveTopology, ibFormat, shader, renderTarget, pipelineLayout, blendState, depthState, vertexBufferLayout, cullMode, stencilEnabled, stencilFront, stencilBack) {
7546
+ create(primitiveTopology, ibFormat, shader, renderTarget, pipelineLayout, blendState, depthState, vertexBufferLayout, cullMode, stencilEnabled, stencilFront, stencilBack, frontFace) {
7531
7547
  const wgpu = this.device.wgpu;
7532
7548
  const webgpuShader = shader.impl;
7533
7549
  const desc = {
@@ -7538,7 +7554,7 @@ class WebgpuRenderPipeline extends WebgpuPipeline {
7538
7554
  },
7539
7555
  primitive: {
7540
7556
  topology: primitiveTopology,
7541
- frontFace: 'ccw',
7557
+ frontFace: _frontFace[frontFace],
7542
7558
  cullMode: _cullModes[cullMode]
7543
7559
  },
7544
7560
  depthStencil: this.getDepthStencil(depthState, renderTarget, stencilEnabled, stencilFront, stencilBack, primitiveTopology),
@@ -7575,7 +7591,7 @@ class WebgpuRenderPipeline extends WebgpuPipeline {
7575
7591
  return pipeline;
7576
7592
  }
7577
7593
  constructor(device){
7578
- super(device), this.lookupHashes = new Uint32Array(14);
7594
+ super(device), this.lookupHashes = new Uint32Array(15);
7579
7595
  this.vertexBufferLayout = new WebgpuVertexBufferLayout();
7580
7596
  this.cache = new Map();
7581
7597
  }
@@ -10705,25 +10721,27 @@ class WebgpuClearRenderer {
10705
10721
  uniformBuffer.startUpdate(dynamicBindGroup);
10706
10722
  device.setBindGroup(BINDGROUP_MESH_UB, dynamicBindGroup.bindGroup, dynamicBindGroup.offsets);
10707
10723
  device.setBindGroup(BINDGROUP_MESH, device.emptyBindGroup);
10724
+ let blendState;
10708
10725
  if (flags & CLEARFLAG_COLOR && (renderTarget.colorBuffer || renderTarget.impl.assignedColorTexture)) {
10709
10726
  const color = options.color ?? defaultOptions.color;
10710
10727
  this.colorData.set(color);
10711
- device.setBlendState(BlendState.NOBLEND);
10728
+ blendState = BlendState.NOBLEND;
10712
10729
  } else {
10713
- device.setBlendState(BlendState.NOWRITE);
10730
+ blendState = BlendState.NOWRITE;
10714
10731
  }
10715
10732
  uniformBuffer.set('color', this.colorData);
10733
+ let depthState;
10716
10734
  if (flags & CLEARFLAG_DEPTH && renderTarget.depth) {
10717
10735
  const depth = options.depth ?? defaultOptions.depth;
10718
10736
  uniformBuffer.set('depth', depth);
10719
- device.setDepthState(DepthState.WRITEDEPTH);
10737
+ depthState = DepthState.WRITEDEPTH;
10720
10738
  } else {
10721
10739
  uniformBuffer.set('depth', 1);
10722
- device.setDepthState(DepthState.NODEPTH);
10740
+ depthState = DepthState.NODEPTH;
10723
10741
  }
10724
10742
  if (flags & CLEARFLAG_STENCIL && renderTarget.stencil) ;
10725
10743
  uniformBuffer.endUpdate();
10726
- device.setCullMode(CULLFACE_NONE);
10744
+ device.setDrawStates(blendState, depthState);
10727
10745
  device.setShader(this.shader);
10728
10746
  device.draw(primitive);
10729
10747
  }
@@ -11830,7 +11848,7 @@ class WebgpuGraphicsDevice extends GraphicsDevice {
11830
11848
  this.submitVertexBuffer(vb1, vbSlot);
11831
11849
  }
11832
11850
  }
11833
- pipeline = this.renderPipeline.get(primitive, vb0?.format, vb1?.format, indexBuffer?.format, this.shader, this.renderTarget, this.bindGroupFormats, this.blendState, this.depthState, this.cullMode, this.stencilEnabled, this.stencilFront, this.stencilBack);
11851
+ pipeline = this.renderPipeline.get(primitive, vb0?.format, vb1?.format, indexBuffer?.format, this.shader, this.renderTarget, this.bindGroupFormats, this.blendState, this.depthState, this.cullMode, this.stencilEnabled, this.stencilFront, this.stencilBack, this.frontFace);
11834
11852
  if (this.pipeline !== pipeline) {
11835
11853
  this.pipeline = pipeline;
11836
11854
  passEncoder.setPipeline(pipeline);
@@ -11900,6 +11918,9 @@ class WebgpuGraphicsDevice extends GraphicsDevice {
11900
11918
  setCullMode(cullMode) {
11901
11919
  this.cullMode = cullMode;
11902
11920
  }
11921
+ setFrontFace(frontFace) {
11922
+ this.frontFace = frontFace;
11923
+ }
11903
11924
  setAlphaToCoverage(state) {}
11904
11925
  initializeContextCaches() {
11905
11926
  super.initializeContextCaches();
@@ -14717,6 +14738,13 @@ class WebglGraphicsDevice extends GraphicsDevice {
14717
14738
  this.cullMode = cullMode;
14718
14739
  }
14719
14740
  }
14741
+ setFrontFace(frontFace) {
14742
+ if (this.frontFace !== frontFace) {
14743
+ const mode = this.glFrontFace[frontFace];
14744
+ this.gl.frontFace(mode);
14745
+ this.frontFace = frontFace;
14746
+ }
14747
+ }
14720
14748
  setShader(shader, asyncCompile = false) {
14721
14749
  if (shader !== this.shader) {
14722
14750
  this.shader = shader;
@@ -14918,6 +14946,10 @@ class WebglGraphicsDevice extends GraphicsDevice {
14918
14946
  gl.FRONT,
14919
14947
  gl.FRONT_AND_BACK
14920
14948
  ];
14949
+ this.glFrontFace = [
14950
+ gl.CCW,
14951
+ gl.CW
14952
+ ];
14921
14953
  this.glFilter = [
14922
14954
  gl.NEAREST,
14923
14955
  gl.LINEAR,
@@ -15268,6 +15300,7 @@ class NullGraphicsDevice extends GraphicsDevice {
15268
15300
  setStencilState(stencilFront, stencilBack) {}
15269
15301
  setBlendColor(r, g, b, a) {}
15270
15302
  setCullMode(cullMode) {}
15303
+ setFrontFace(frontFace) {}
15271
15304
  setAlphaToCoverage(state) {}
15272
15305
  initializeContextCaches() {
15273
15306
  super.initializeContextCaches();
@@ -17216,9 +17249,7 @@ class QuadRender {
17216
17249
  class RenderPassQuad extends RenderPass {
17217
17250
  execute() {
17218
17251
  const { device } = this;
17219
- device.setCullMode(CULLFACE_NONE);
17220
- device.setDepthState(DepthState.NODEPTH);
17221
- device.setStencilState(null, null);
17252
+ device.setDrawStates();
17222
17253
  this.quad.render(this.rect, this.scissorRect);
17223
17254
  }
17224
17255
  constructor(device, quad, rect, scissorRect){
@@ -21025,6 +21056,7 @@ class Material {
21025
21056
  this._blendState.copy(source._blendState);
21026
21057
  this._depthState.copy(source._depthState);
21027
21058
  this.cull = source.cull;
21059
+ this.frontFace = source.frontFace;
21028
21060
  this.stencilFront = source.stencilFront?.clone();
21029
21061
  if (source.stencilBack) {
21030
21062
  this.stencilBack = source.stencilFront === source.stencilBack ? this.stencilFront : source.stencilBack.clone();
@@ -21177,6 +21209,7 @@ class Material {
21177
21209
  this._blendState = new BlendState();
21178
21210
  this._depthState = new DepthState();
21179
21211
  this.cull = CULLFACE_BACK;
21212
+ this.frontFace = FRONTFACE_CCW;
21180
21213
  this.stencilFront = null;
21181
21214
  this.stencilBack = null;
21182
21215
  this._shaderChunks = null;
@@ -21652,7 +21685,7 @@ class ShadowRenderer {
21652
21685
  material.updateUniforms(device, scene);
21653
21686
  material.dirty = false;
21654
21687
  }
21655
- renderer.setupCullMode(true, flipFactor, meshInstance);
21688
+ renderer.setupCullModeAndFrontFace(true, flipFactor, meshInstance);
21656
21689
  material.setParameters(device);
21657
21690
  meshInstance.setParameters(device, passFlags);
21658
21691
  const shaderInstance = meshInstance.getShaderInstance(shadowPass, 0, scene, cameraShaderParams, this.viewUniformFormat, this.viewBindGroupFormat);
@@ -21978,10 +22011,7 @@ class RenderPassCookieRenderer extends RenderPass {
21978
22011
  }
21979
22012
  execute() {
21980
22013
  const device = this.device;
21981
- device.setBlendState(BlendState.NOBLEND);
21982
- device.setCullMode(CULLFACE_NONE);
21983
- device.setDepthState(DepthState.NODEPTH);
21984
- device.setStencilState();
22014
+ device.setDrawStates();
21985
22015
  const renderTargetWidth = this.renderTarget.colorBuffer.width;
21986
22016
  const cubeSlotsOffsets = this._cubeSlotsOffsets;
21987
22017
  const filteredLights = this._filteredLights;
@@ -22276,24 +22306,18 @@ class Renderer {
22276
22306
  });
22277
22307
  }
22278
22308
  }
22279
- setupCullMode(cullFaces, flipFactor, drawCall) {
22309
+ setupCullModeAndFrontFace(cullFaces, flipFactor, drawCall) {
22280
22310
  const material = drawCall.material;
22281
- let mode = CULLFACE_NONE;
22282
- if (cullFaces) {
22283
- let flipFaces = 1;
22284
- if (material.cull === CULLFACE_FRONT || material.cull === CULLFACE_BACK) {
22285
- flipFaces = flipFactor * drawCall.flipFacesFactor * drawCall.node.worldScaleSign;
22286
- }
22287
- if (flipFaces < 0) {
22288
- mode = material.cull === CULLFACE_FRONT ? CULLFACE_BACK : CULLFACE_FRONT;
22289
- } else {
22290
- mode = material.cull;
22291
- }
22292
- }
22293
- this.device.setCullMode(mode);
22294
- if (mode === CULLFACE_NONE && material.cull === CULLFACE_NONE) {
22295
- this.twoSidedLightingNegScaleFactorId.setValue(drawCall.node.worldScaleSign);
22311
+ const flipFaces = flipFactor * drawCall.flipFacesFactor * drawCall.node.worldScaleSign;
22312
+ let frontFace = material.frontFace;
22313
+ if (flipFaces < 0) {
22314
+ frontFace = frontFace === FRONTFACE_CCW ? FRONTFACE_CW : FRONTFACE_CCW;
22296
22315
  }
22316
+ this.device.setCullMode(cullFaces ? material.cull : CULLFACE_NONE);
22317
+ this.device.setFrontFace(frontFace);
22318
+ }
22319
+ setupCullMode(cullFaces, flipFactor, drawCall) {
22320
+ this.setupCullModeAndFrontFace(cullFaces, flipFactor, drawCall);
22297
22321
  }
22298
22322
  updateCameraFrustum(camera) {
22299
22323
  if (camera.xr && camera.xr.views.list.length) {
@@ -22325,6 +22349,7 @@ class Renderer {
22325
22349
  }
22326
22350
  setBaseConstants(device, material) {
22327
22351
  device.setCullMode(material.cull);
22352
+ device.setFrontFace(material.frontFace);
22328
22353
  if (material.opacityMap) {
22329
22354
  this.opacityMapId.setValue(material.opacityMap);
22330
22355
  }
@@ -22786,8 +22811,6 @@ class Renderer {
22786
22811
  this.alphaTestId = scope.resolve('alpha_ref');
22787
22812
  this.opacityMapId = scope.resolve('texture_opacityMap');
22788
22813
  this.exposureId = scope.resolve('exposure');
22789
- this.twoSidedLightingNegScaleFactorId = scope.resolve('twoSidedLightingNegScaleFactor');
22790
- this.twoSidedLightingNegScaleFactorId.setValue(0);
22791
22814
  this.morphPositionTex = scope.resolve('morphPositionTex');
22792
22815
  this.morphNormalTex = scope.resolve('morphNormalTex');
22793
22816
  this.morphTexParams = scope.resolve('morph_tex_params');
@@ -23354,7 +23377,7 @@ class ForwardRenderer extends Renderer {
23354
23377
  device.setDepthState(material.depthState);
23355
23378
  device.setAlphaToCoverage(material.alphaToCoverage);
23356
23379
  }
23357
- this.setupCullMode(camera._cullFaces, flipFactor, drawCall);
23380
+ this.setupCullModeAndFrontFace(camera._cullFaces, flipFactor, drawCall);
23358
23381
  const stencilFront = drawCall.stencilFront ?? material.stencilFront;
23359
23382
  const stencilBack = drawCall.stencilBack ?? material.stencilBack;
23360
23383
  device.setStencilState(stencilFront, stencilBack);
@@ -29034,15 +29057,11 @@ class RenderPassShaderQuad extends RenderPass {
29034
29057
  return this._shader;
29035
29058
  }
29036
29059
  execute() {
29037
- const device = this.device;
29038
- device.setBlendState(this.blendState);
29039
- device.setCullMode(this.cullMode);
29040
- device.setDepthState(this.depthState);
29041
- device.setStencilState(this.stencilFront, this.stencilBack);
29060
+ this.device.setDrawStates(this.blendState, this.depthState, this.cullMode, this.frontFace, this.stencilFront, this.stencilBack);
29042
29061
  this.quadRender?.render(this.viewport, this.scissor);
29043
29062
  }
29044
29063
  constructor(...args){
29045
- super(...args), this._shader = null, this.quadRender = null, this.cullMode = CULLFACE_NONE, this.blendState = BlendState.NOBLEND, this.depthState = DepthState.NODEPTH, this.stencilFront = null, this.stencilBack = null;
29064
+ super(...args), this._shader = null, this.quadRender = null, this.cullMode = CULLFACE_NONE, this.frontFace = FRONTFACE_CCW, this.blendState = BlendState.NOBLEND, this.depthState = DepthState.NODEPTH, this.stencilFront = null, this.stencilBack = null;
29046
29065
  }
29047
29066
  }
29048
29067
 
@@ -31843,10 +31862,7 @@ class GSplatWorkBufferRenderPass extends RenderPass {
31843
31862
  }
31844
31863
  execute() {
31845
31864
  const { device, splats, cameraNode, _partialData } = this;
31846
- device.setBlendState(BlendState.NOBLEND);
31847
- device.setCullMode(CULLFACE_NONE);
31848
- device.setDepthState(DepthState.NODEPTH);
31849
- device.setStencilState();
31865
+ device.setDrawStates();
31850
31866
  const viewInvMat = cameraNode.getWorldTransform();
31851
31867
  const viewMat = _viewMat.copy(viewInvMat).invert();
31852
31868
  device.scope.resolve('matrix_view').setValue(viewMat.data);
@@ -32952,10 +32968,7 @@ class GSplatResolveSH {
32952
32968
  shN_mins: meta.shN.mins,
32953
32969
  shN_maxs: meta.shN.maxs
32954
32970
  });
32955
- device.setCullMode(CULLFACE_NONE);
32956
- device.setDepthState(DepthState.NODEPTH);
32957
- device.setStencilState(null, null);
32958
- device.setBlendState(BlendState.NOBLEND);
32971
+ device.setDrawStates();
32959
32972
  this.quadRender.render();
32960
32973
  };
32961
32974
  this.renderPass.executeCallback = execute;
@@ -42271,9 +42284,8 @@ void getRefraction() {
42271
42284
  `;
42272
42285
 
42273
42286
  var twoSidedLightingPS$1 = `
42274
- uniform float twoSidedLightingNegScaleFactor;
42275
42287
  void handleTwoSidedLighting() {
42276
- dTBN[2] *= gl_FrontFacing ? twoSidedLightingNegScaleFactor : -twoSidedLightingNegScaleFactor;
42288
+ if (!gl_FrontFacing) dTBN[2] = -dTBN[2];
42277
42289
  }
42278
42290
  `;
42279
42291
 
@@ -47593,9 +47605,8 @@ fn getRefraction() {
47593
47605
  `;
47594
47606
 
47595
47607
  var twoSidedLightingPS = `
47596
- uniform twoSidedLightingNegScaleFactor: f32;
47597
47608
  fn handleTwoSidedLighting() {
47598
- dTBN[2] = dTBN[2] * select(-uniform.twoSidedLightingNegScaleFactor, uniform.twoSidedLightingNegScaleFactor, pcFrontFacing);
47609
+ if (!pcFrontFacing) { dTBN[2] = -dTBN[2]; }
47599
47610
  }
47600
47611
  `;
47601
47612
 
@@ -53189,6 +53200,24 @@ class GSplatRenderer {
53189
53200
  const GsplatAllocId = new NumericIds();
53190
53201
 
53191
53202
  class GSplatPlacement {
53203
+ set lodBaseDistance(value) {
53204
+ if (this._lodBaseDistance !== value) {
53205
+ this._lodBaseDistance = value;
53206
+ this.lodDirty = true;
53207
+ }
53208
+ }
53209
+ get lodBaseDistance() {
53210
+ return this._lodBaseDistance;
53211
+ }
53212
+ set lodMultiplier(value) {
53213
+ if (this._lodMultiplier !== value) {
53214
+ this._lodMultiplier = value;
53215
+ this.lodDirty = true;
53216
+ }
53217
+ }
53218
+ get lodMultiplier() {
53219
+ return this._lodMultiplier;
53220
+ }
53192
53221
  destroy() {
53193
53222
  this._streams?.destroy();
53194
53223
  this._streams = null;
@@ -53225,19 +53254,8 @@ class GSplatPlacement {
53225
53254
  const aabb = this._aabb ?? this.resource?.aabb;
53226
53255
  return aabb;
53227
53256
  }
53228
- set lodDistances(distances) {
53229
- const isOctree = !!(this.resource && this.resource.octree);
53230
- if (isOctree) {
53231
- if (distances) {
53232
- this.resource.octree?.lodLevels ?? 1;
53233
- this._lodDistances = distances.slice();
53234
- } else {
53235
- this._lodDistances = null;
53236
- }
53237
- }
53238
- }
53239
- get lodDistances() {
53240
- return this._lodDistances ? this._lodDistances.slice() : null;
53257
+ getLodDistance(level) {
53258
+ return this.lodBaseDistance * Math.pow(this.lodMultiplier, level);
53241
53259
  }
53242
53260
  getInstanceTexture(name, device) {
53243
53261
  const resource = this.resource;
@@ -53270,10 +53288,12 @@ class GSplatPlacement {
53270
53288
  this.id = 0;
53271
53289
  this.allocId = GsplatAllocId.get();
53272
53290
  this.lodIndex = 0;
53273
- this._lodDistances = null;
53291
+ this._lodBaseDistance = 5;
53292
+ this._lodMultiplier = 3;
53274
53293
  this._aabb = null;
53275
53294
  this.parameters = null;
53276
53295
  this._streams = null;
53296
+ this.lodDirty = false;
53277
53297
  this.renderDirty = false;
53278
53298
  this.workBufferUpdate = WORKBUFFER_UPDATE_AUTO;
53279
53299
  this._lastFormatVersion = -1;
@@ -53294,6 +53314,7 @@ const _localCameraFwd = new Vec3();
53294
53314
  const _dirToNode = new Vec3();
53295
53315
  const _tempCompletedUrls = [];
53296
53316
  new BoundingBox();
53317
+ const REF_TAN_HALF_FOV = Math.tan(22.5 * math.DEG_TO_RAD);
53297
53318
  [
53298
53319
  new Color(1, 0, 0),
53299
53320
  new Color(0, 1, 0),
@@ -53311,7 +53332,6 @@ class NodeInfo {
53311
53332
  this.optimalLod = -1;
53312
53333
  this.worldDistance = 0;
53313
53334
  this.inst = null;
53314
- this.nodeIndex = 0;
53315
53335
  this.lods = null;
53316
53336
  this.allocId = GsplatAllocId.get();
53317
53337
  }
@@ -53388,26 +53408,6 @@ class GSplatOctreeInstance {
53388
53408
  }
53389
53409
  return toRelease;
53390
53410
  }
53391
- calculateNodeLod(localCameraPosition, localCameraForward, nodeIndex, maxLod, lodDistances, lodBehindPenalty) {
53392
- const node = this.octree.nodes[nodeIndex];
53393
- node.bounds.closestPoint(localCameraPosition, _dirToNode);
53394
- _dirToNode.sub(localCameraPosition);
53395
- let distance = _dirToNode.length();
53396
- if (lodBehindPenalty > 1 && distance > 0.01) {
53397
- const dotOverDistance = localCameraForward.dot(_dirToNode) / distance;
53398
- if (dotOverDistance < 0) {
53399
- const t = -dotOverDistance;
53400
- const factor = 1 + t * (lodBehindPenalty - 1);
53401
- distance *= factor;
53402
- }
53403
- }
53404
- for(let lod = 0; lod < maxLod; lod++){
53405
- if (distance < lodDistances[lod]) {
53406
- return lod;
53407
- }
53408
- }
53409
- return maxLod;
53410
- }
53411
53411
  selectDesiredLodIndex(node, optimalLodIndex, maxLod, lodUnderfillLimit) {
53412
53412
  if (lodUnderfillLimit > 0) {
53413
53413
  const allowedMaxCoarseLod = Math.min(maxLod, optimalLodIndex + lodUnderfillLimit);
@@ -53452,29 +53452,24 @@ class GSplatOctreeInstance {
53452
53452
  }
53453
53453
  updateLod(cameraNode, params) {
53454
53454
  const maxLod = this.octree.lodLevels - 1;
53455
- const lodDistances = this.placement.lodDistances || [
53456
- 5,
53457
- 10,
53458
- 15,
53459
- 20,
53460
- 25,
53461
- 30,
53462
- 35,
53463
- 40,
53464
- 45,
53465
- 50,
53466
- 55,
53467
- 60
53468
- ];
53455
+ const { lodBaseDistance, lodMultiplier } = this.placement;
53469
53456
  const { lodRangeMin, lodRangeMax } = params;
53470
53457
  const rangeMin = Math.max(0, Math.min(lodRangeMin ?? 0, maxLod));
53471
53458
  const rangeMax = Math.max(rangeMin, Math.min(lodRangeMax ?? maxLod, maxLod));
53472
53459
  const uniformScale = this.placement.node.getWorldTransform().getScale().x;
53473
- this.evaluateNodeLods(cameraNode, maxLod, lodDistances, rangeMin, rangeMax, params, uniformScale);
53460
+ this.evaluateNodeLods(cameraNode, maxLod, lodBaseDistance, lodMultiplier, rangeMin, rangeMax, params, uniformScale);
53474
53461
  this.applyLodChanges(maxLod, params);
53475
53462
  }
53476
- evaluateNodeLods(cameraNode, maxLod, lodDistances, rangeMin, rangeMax, params, uniformScale) {
53463
+ evaluateNodeLods(cameraNode, maxLod, lodBaseDistance, lodMultiplier, rangeMin, rangeMax, params, uniformScale) {
53477
53464
  const { lodBehindPenalty } = params;
53465
+ const camera = cameraNode.camera;
53466
+ let tanHalfVFov = Math.tan(camera.fov * 0.5 * math.DEG_TO_RAD);
53467
+ if (camera.horizontalFov) {
53468
+ tanHalfVFov /= camera.aspectRatio;
53469
+ }
53470
+ const tanHalfHFov = tanHalfVFov * camera.aspectRatio;
53471
+ const fovScale = Math.min(tanHalfVFov, tanHalfHFov) / REF_TAN_HALF_FOV;
53472
+ const invLogMult = 1.0 / Math.log(lodMultiplier);
53478
53473
  const worldCameraPosition = cameraNode.getPosition();
53479
53474
  const octreeWorldTransform = this.placement.node.getWorldTransform();
53480
53475
  _invWorldMat.copy(octreeWorldTransform).invert();
@@ -53499,18 +53494,18 @@ class GSplatOctreeInstance {
53499
53494
  penalizedDistance = actualDistance * factor;
53500
53495
  }
53501
53496
  }
53502
- let optimalLodIndex = maxLod;
53503
- for(let lod = 0; lod < maxLod; lod++){
53504
- if (penalizedDistance < lodDistances[lod]) {
53505
- optimalLodIndex = lod;
53506
- break;
53507
- }
53497
+ const fovAdjustedDistance = penalizedDistance * fovScale;
53498
+ let optimalLodIndex;
53499
+ if (fovAdjustedDistance < lodBaseDistance) {
53500
+ optimalLodIndex = 0;
53501
+ } else {
53502
+ const rawLod = 1 + Math.log(fovAdjustedDistance / lodBaseDistance) * invLogMult;
53503
+ optimalLodIndex = Math.min(maxLod, rawLod | 0);
53508
53504
  }
53509
53505
  if (optimalLodIndex < rangeMin) optimalLodIndex = rangeMin;
53510
53506
  if (optimalLodIndex > rangeMax) optimalLodIndex = rangeMax;
53511
- const worldDistance = actualDistance * uniformScale;
53512
53507
  nodeInfo.optimalLod = optimalLodIndex;
53513
- nodeInfo.worldDistance = worldDistance;
53508
+ nodeInfo.worldDistance = fovAdjustedDistance * uniformScale;
53514
53509
  const lod = nodes[nodeIndex].lods[optimalLodIndex];
53515
53510
  if (lod && lod.count) {
53516
53511
  totalSplats += lod.count;
@@ -53518,29 +53513,18 @@ class GSplatOctreeInstance {
53518
53513
  }
53519
53514
  return totalSplats;
53520
53515
  }
53521
- evaluateOptimalLods(cameraNode, params) {
53516
+ evaluateOptimalLods(cameraNode, params, budgetScale = 1) {
53522
53517
  const maxLod = this.octree.lodLevels - 1;
53523
- const lodDistances = this.placement.lodDistances || [
53524
- 5,
53525
- 10,
53526
- 15,
53527
- 20,
53528
- 25,
53529
- 30,
53530
- 35,
53531
- 40,
53532
- 45,
53533
- 50,
53534
- 55,
53535
- 60
53536
- ];
53518
+ const { lodBaseDistance, lodMultiplier } = this.placement;
53537
53519
  const { lodRangeMin, lodRangeMax } = params;
53538
53520
  const rangeMin = Math.max(0, Math.min(lodRangeMin ?? 0, maxLod));
53539
53521
  const rangeMax = Math.max(rangeMin, Math.min(lodRangeMax ?? maxLod, maxLod));
53540
53522
  this.rangeMin = rangeMin;
53541
53523
  this.rangeMax = rangeMax;
53542
53524
  const uniformScale = this.placement.node.getWorldTransform().getScale().x;
53543
- return this.evaluateNodeLods(cameraNode, maxLod, lodDistances, rangeMin, rangeMax, params, uniformScale);
53525
+ const effectiveBase = lodBaseDistance * budgetScale;
53526
+ const effectiveMult = Math.max(1.2, lodMultiplier * Math.pow(budgetScale, -0.2));
53527
+ return this.evaluateNodeLods(cameraNode, maxLod, effectiveBase, effectiveMult, rangeMin, rangeMax, params, uniformScale);
53544
53528
  }
53545
53529
  applyLodChanges(maxLod, params) {
53546
53530
  const nodes = this.octree.nodes;
@@ -53689,6 +53673,10 @@ class GSplatOctreeInstance {
53689
53673
  this.previousPosition.copy(this.placement.node.getPosition());
53690
53674
  }
53691
53675
  update() {
53676
+ if (this.placement.lodDirty) {
53677
+ this.placement.lodDirty = false;
53678
+ this.needsLodUpdate = true;
53679
+ }
53692
53680
  if (this.pending.size) {
53693
53681
  for (const fileIndex of this.pending){
53694
53682
  this.octree.ensureFileResource(fileIndex);
@@ -53785,7 +53773,6 @@ class GSplatOctreeInstance {
53785
53773
  for(let i = 0; i < octree.nodes.length; i++){
53786
53774
  const nodeInfo = new NodeInfo();
53787
53775
  nodeInfo.inst = this;
53788
- nodeInfo.nodeIndex = i;
53789
53776
  this.nodeInfos[i] = nodeInfo;
53790
53777
  }
53791
53778
  const numFiles = octree.files.length;
@@ -55264,10 +55251,11 @@ class GSplatBudgetBalancer {
55264
55251
  return;
55265
55252
  }
55266
55253
  const isOverBudget = currentSplats > budget;
55267
- while(isOverBudget ? currentSplats > budget : currentSplats < budget){
55254
+ let done = false;
55255
+ while(!done && (isOverBudget ? currentSplats > budget : currentSplats < budget)){
55268
55256
  let modified = false;
55269
55257
  if (isOverBudget) {
55270
- for(let b = NUM_BUCKETS - 1; b >= 0 && currentSplats > budget; b--){
55258
+ for(let b = NUM_BUCKETS - 1; b >= 0 && !done; b--){
55271
55259
  const bucket = this._buckets[b];
55272
55260
  for(let i = 0, len = bucket.length; i < len; i++){
55273
55261
  const nodeInfo = bucket[i];
@@ -55277,12 +55265,15 @@ class GSplatBudgetBalancer {
55277
55265
  currentSplats -= lods[optimalLod].count - lods[optimalLod + 1].count;
55278
55266
  nodeInfo.optimalLod = optimalLod + 1;
55279
55267
  modified = true;
55280
- if (currentSplats <= budget) break;
55268
+ if (currentSplats <= budget) {
55269
+ done = true;
55270
+ break;
55271
+ }
55281
55272
  }
55282
55273
  }
55283
55274
  }
55284
55275
  } else {
55285
- for(let b = 0; b < NUM_BUCKETS && currentSplats < budget; b++){
55276
+ for(let b = 0; b < NUM_BUCKETS && !done; b++){
55286
55277
  const bucket = this._buckets[b];
55287
55278
  for(let i = 0, len = bucket.length; i < len; i++){
55288
55279
  const nodeInfo = bucket[i];
@@ -55294,7 +55285,13 @@ class GSplatBudgetBalancer {
55294
55285
  nodeInfo.optimalLod = optimalLod - 1;
55295
55286
  currentSplats += splatsAdded;
55296
55287
  modified = true;
55297
- if (currentSplats >= budget) break;
55288
+ if (currentSplats >= budget) {
55289
+ done = true;
55290
+ break;
55291
+ }
55292
+ } else {
55293
+ done = true;
55294
+ break;
55298
55295
  }
55299
55296
  }
55300
55297
  }
@@ -56128,7 +56125,9 @@ class GSplatManager {
56128
56125
  cameraRotated = true;
56129
56126
  }
56130
56127
  }
56131
- return cameraMoved || cameraRotated;
56128
+ const currentFov = this.cameraNode.camera.fov;
56129
+ const fovChanged = this.lastLodCameraFov < 0 || Math.abs(currentFov - this.lastLodCameraFov) > this.lastLodCameraFov * 0.02;
56130
+ return cameraMoved || cameraRotated || fovChanged;
56132
56131
  }
56133
56132
  testCameraMovedForSort() {
56134
56133
  const epsilon = 0.001;
@@ -56226,8 +56225,9 @@ class GSplatManager {
56226
56225
  }
56227
56226
  const octreeBudget = Math.max(1, budget - fixedSplats);
56228
56227
  const globalMaxDistance = this.computeGlobalMaxDistance();
56228
+ let totalOptimalSplats = 0;
56229
56229
  for (const [, inst] of this.octreeInstances){
56230
- inst.evaluateOptimalLods(this.cameraNode, this.scene.gsplat);
56230
+ totalOptimalSplats += inst.evaluateOptimalLods(this.cameraNode, this.scene.gsplat, this._budgetScale);
56231
56231
  for (const placement of inst.activePlacements){
56232
56232
  const resource = placement.resource;
56233
56233
  const numSplats = resource?.numSplats ?? 0;
@@ -56235,6 +56235,16 @@ class GSplatManager {
56235
56235
  }
56236
56236
  }
56237
56237
  const adjustedBudget = Math.max(1, octreeBudget - paddingEstimate);
56238
+ if (totalOptimalSplats > 0) {
56239
+ const ratio = totalOptimalSplats / adjustedBudget;
56240
+ const budgetScaleDeadZone = 0.4;
56241
+ const budgetScaleBlendRate = 0.3;
56242
+ if (ratio > 1 + budgetScaleDeadZone || ratio < 1 - budgetScaleDeadZone) {
56243
+ const invCorrection = 1 / Math.sqrt(ratio);
56244
+ this._budgetScale *= 1 + (invCorrection - 1) * budgetScaleBlendRate;
56245
+ this._budgetScale = Math.max(0.01, Math.min(this._budgetScale, 100.0));
56246
+ }
56247
+ }
56238
56248
  this._budgetBalancer.balance(this.octreeInstances, adjustedBudget, globalMaxDistance);
56239
56249
  for (const [, inst] of this.octreeInstances){
56240
56250
  const maxLod = inst.octree.lodLevels - 1;
@@ -56319,12 +56329,15 @@ class GSplatManager {
56319
56329
  for (const [, inst] of this.octreeInstances){
56320
56330
  inst.updateMoved();
56321
56331
  }
56322
- this.lastLodCameraPos.copy(this.cameraNode.getPosition());
56323
- this.lastLodCameraFwd.copy(this.cameraNode.forward);
56332
+ const cameraNode = this.cameraNode;
56333
+ this.lastLodCameraPos.copy(cameraNode.getPosition());
56334
+ this.lastLodCameraFwd.copy(cameraNode.forward);
56335
+ this.lastLodCameraFov = cameraNode.camera.fov;
56324
56336
  const budget = this.scene.gsplat.splatBudget;
56325
56337
  if (budget > 0) {
56326
56338
  this._enforceBudget(budget);
56327
56339
  } else {
56340
+ this._budgetScale = 1.0;
56328
56341
  for (const [, inst] of this.octreeInstances){
56329
56342
  inst.updateLod(this.cameraNode, this.scene.gsplat);
56330
56343
  }
@@ -56618,12 +56631,14 @@ class GSplatManager {
56618
56631
  this.framesTillFullUpdate = 0;
56619
56632
  this.lastLodCameraPos = new Vec3(Infinity, Infinity, Infinity);
56620
56633
  this.lastLodCameraFwd = new Vec3(Infinity, Infinity, Infinity);
56634
+ this.lastLodCameraFov = -1;
56621
56635
  this.lastSortCameraPos = new Vec3(Infinity, Infinity, Infinity);
56622
56636
  this.lastSortCameraFwd = new Vec3(Infinity, Infinity, Infinity);
56623
56637
  this.lastCullingCameraFwd = new Vec3(Infinity, Infinity, Infinity);
56624
56638
  this.lastCullingProjMat = new Mat4();
56625
56639
  this.sortNeeded = true;
56626
56640
  this._budgetBalancer = new GSplatBudgetBalancer();
56641
+ this._budgetScale = 1.0;
56627
56642
  this._allocationMap = new Map();
56628
56643
  this.lastColorUpdateCameraPos = new Vec3(Infinity, Infinity, Infinity);
56629
56644
  this.lastColorUpdateCameraFwd = new Vec3(Infinity, Infinity, Infinity);
@@ -56935,14 +56950,32 @@ class GSplatComponent extends Component {
56935
56950
  get castShadows() {
56936
56951
  return this._castShadows;
56937
56952
  }
56938
- set lodDistances(value) {
56939
- this._lodDistances = Array.isArray(value) ? value.slice() : null;
56953
+ set lodBaseDistance(value) {
56954
+ this._lodBaseDistance = Math.max(0.1, value);
56940
56955
  if (this._placement) {
56941
- this._placement.lodDistances = this._lodDistances;
56956
+ this._placement.lodBaseDistance = this._lodBaseDistance;
56957
+ }
56958
+ }
56959
+ get lodBaseDistance() {
56960
+ return this._lodBaseDistance;
56961
+ }
56962
+ set lodMultiplier(value) {
56963
+ this._lodMultiplier = Math.max(1.2, value);
56964
+ if (this._placement) {
56965
+ this._placement.lodMultiplier = this._lodMultiplier;
56966
+ }
56967
+ }
56968
+ get lodMultiplier() {
56969
+ return this._lodMultiplier;
56970
+ }
56971
+ set lodDistances(value) {
56972
+ if (Array.isArray(value) && value.length > 0) {
56973
+ this.lodBaseDistance = value[0];
56974
+ this.lodMultiplier = 3;
56942
56975
  }
56943
56976
  }
56944
56977
  get lodDistances() {
56945
- return this._lodDistances ? this._lodDistances.slice() : null;
56978
+ return [];
56946
56979
  }
56947
56980
  set splatBudget(value) {}
56948
56981
  get splatBudget() {
@@ -57207,7 +57240,8 @@ class GSplatComponent extends Component {
57207
57240
  if (this.unified) {
57208
57241
  this._placement = null;
57209
57242
  this._placement = new GSplatPlacement(resource, this.entity, 0, this._parameters, null, this._id);
57210
- this._placement.lodDistances = this._lodDistances;
57243
+ this._placement.lodBaseDistance = this._lodBaseDistance;
57244
+ this._placement.lodMultiplier = this._lodMultiplier;
57211
57245
  this._placement.workBufferUpdate = this._workBufferUpdate;
57212
57246
  this._placement.workBufferModifier = this._workBufferModifier;
57213
57247
  if (this.enabled && this.entity.enabled) {
@@ -57231,20 +57265,7 @@ class GSplatComponent extends Component {
57231
57265
  constructor(system, entity){
57232
57266
  super(system, entity), this._layers = [
57233
57267
  LAYERID_WORLD
57234
- ], this._instance = null, this._placement = null, this._id = PickerId.get(), this._materialTmp = null, this._highQualitySH = true, this._lodDistances = [
57235
- 5,
57236
- 10,
57237
- 15,
57238
- 20,
57239
- 25,
57240
- 30,
57241
- 35,
57242
- 40,
57243
- 45,
57244
- 50,
57245
- 55,
57246
- 60
57247
- ], this._customAabb = null, this._resource = null, this._evtLayersChanged = null, this._evtLayerAdded = null, this._evtLayerRemoved = null, this._castShadows = false, this._unified = false, this._parameters = new Map(), this._workBufferUpdate = WORKBUFFER_UPDATE_AUTO, this._workBufferModifier = null;
57268
+ ], this._instance = null, this._placement = null, this._id = PickerId.get(), this._materialTmp = null, this._highQualitySH = true, this._lodBaseDistance = 5, this._lodMultiplier = 3, this._customAabb = null, this._resource = null, this._evtLayersChanged = null, this._evtLayerAdded = null, this._evtLayerRemoved = null, this._castShadows = false, this._unified = false, this._parameters = new Map(), this._workBufferUpdate = WORKBUFFER_UPDATE_AUTO, this._workBufferModifier = null;
57248
57269
  this._assetReference = new AssetReference('asset', this, system.app.assets, {
57249
57270
  add: this._onGSplatAssetAdded,
57250
57271
  load: this._onGSplatAssetLoad,
@@ -58816,7 +58837,8 @@ const _schema = [
58816
58837
  ];
58817
58838
  const _properties = [
58818
58839
  'unified',
58819
- 'lodDistances',
58840
+ 'lodBaseDistance',
58841
+ 'lodMultiplier',
58820
58842
  'castShadows',
58821
58843
  'material',
58822
58844
  'highQualitySH',
@@ -62667,6 +62689,7 @@ class PlyParser {
62667
62689
 
62668
62690
  const combineProgress = (target, assets)=>{
62669
62691
  const map = new Map();
62692
+ const count = assets.length;
62670
62693
  const fire = ()=>{
62671
62694
  let loaded = 0;
62672
62695
  let total = 0;
@@ -62674,6 +62697,10 @@ const combineProgress = (target, assets)=>{
62674
62697
  loaded += value.loaded;
62675
62698
  total += value.total;
62676
62699
  });
62700
+ const reporting = map.size;
62701
+ if (reporting > 0 && reporting < count) {
62702
+ total = Math.ceil(total * count / reporting);
62703
+ }
62677
62704
  target.fire('progress', loaded, total);
62678
62705
  };
62679
62706
  assets.forEach((asset)=>{
@@ -67236,37 +67263,37 @@ varying uv0: vec2f;
67236
67263
  @fragment
67237
67264
  fn fragmentMain(input: FragmentInput) -> FragmentOutput {
67238
67265
  var output: FragmentOutput;
67239
- let e: vec3f = textureSample(sourceTexture, sourceTextureSampler, input.uv0).rgb;
67266
+ let e: half3 = half3(textureSample(sourceTexture, sourceTextureSampler, input.uv0).rgb);
67240
67267
  #ifdef BOXFILTER
67241
- var value: vec3f = e;
67268
+ var value: half3 = e;
67242
67269
  #ifdef PREMULTIPLY
67243
- let premultiply: f32 = textureSample(premultiplyTexture, premultiplyTextureSampler, input.uv0).{PREMULTIPLY_SRC_CHANNEL};
67244
- value = value * vec3f(premultiply);
67270
+ let premultiply: half = half(textureSample(premultiplyTexture, premultiplyTextureSampler, input.uv0).{PREMULTIPLY_SRC_CHANNEL});
67271
+ value *= premultiply;
67245
67272
  #endif
67246
67273
  #else
67247
67274
  let x: f32 = uniform.sourceInvResolution.x;
67248
67275
  let y: f32 = uniform.sourceInvResolution.y;
67249
- let a: vec3f = textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x - 2.0 * x, input.uv0.y + 2.0 * y)).rgb;
67250
- let b: vec3f = textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x, input.uv0.y + 2.0 * y)).rgb;
67251
- let c: vec3f = textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x + 2.0 * x, input.uv0.y + 2.0 * y)).rgb;
67252
- let d: vec3f = textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x - 2.0 * x, input.uv0.y)).rgb;
67253
- let f: vec3f = textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x + 2.0 * x, input.uv0.y)).rgb;
67254
- let g: vec3f = textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x - 2.0 * x, input.uv0.y - 2.0 * y)).rgb;
67255
- let h: vec3f = textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x, input.uv0.y - 2.0 * y)).rgb;
67256
- let i: vec3f = textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x + 2.0 * x, input.uv0.y - 2.0 * y)).rgb;
67257
- let j: vec3f = textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x - x, input.uv0.y + y)).rgb;
67258
- let k: vec3f = textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x + x, input.uv0.y + y)).rgb;
67259
- let l: vec3f = textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x - x, input.uv0.y - y)).rgb;
67260
- let m: vec3f = textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x + x, input.uv0.y - y)).rgb;
67261
- var value: vec3f = e * 0.125;
67262
- value = value + (a + c + g + i) * 0.03125;
67263
- value = value + (b + d + f + h) * 0.0625;
67264
- value = value + (j + k + l + m) * 0.125;
67276
+ let a: half3 = half3(textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x - 2.0 * x, input.uv0.y + 2.0 * y)).rgb);
67277
+ let b: half3 = half3(textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x, input.uv0.y + 2.0 * y)).rgb);
67278
+ let c: half3 = half3(textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x + 2.0 * x, input.uv0.y + 2.0 * y)).rgb);
67279
+ let d: half3 = half3(textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x - 2.0 * x, input.uv0.y)).rgb);
67280
+ let f: half3 = half3(textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x + 2.0 * x, input.uv0.y)).rgb);
67281
+ let g: half3 = half3(textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x - 2.0 * x, input.uv0.y - 2.0 * y)).rgb);
67282
+ let h: half3 = half3(textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x, input.uv0.y - 2.0 * y)).rgb);
67283
+ let i: half3 = half3(textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x + 2.0 * x, input.uv0.y - 2.0 * y)).rgb);
67284
+ let j: half3 = half3(textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x - x, input.uv0.y + y)).rgb);
67285
+ let k: half3 = half3(textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x + x, input.uv0.y + y)).rgb);
67286
+ let l: half3 = half3(textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x - x, input.uv0.y - y)).rgb);
67287
+ let m: half3 = half3(textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x + x, input.uv0.y - y)).rgb);
67288
+ var value: half3 = e * half(0.125);
67289
+ value += (a + c + g + i) * half(0.03125);
67290
+ value += (b + d + f + h) * half(0.0625);
67291
+ value += (j + k + l + m) * half(0.125);
67265
67292
  #endif
67266
67293
  #ifdef REMOVE_INVALID
67267
- value = max(value, vec3f(0.0));
67294
+ value = max(value, half3(0.0));
67268
67295
  #endif
67269
- output.color = vec4f(value, 1.0);
67296
+ output.color = vec4f(vec3f(value), 1.0);
67270
67297
  return output;
67271
67298
  }
67272
67299
  `;
@@ -67332,10 +67359,9 @@ var glslUpsamplePS = `
67332
67359
  vec3 g = texture2D (sourceTexture, vec2 (uv0.x - x, uv0.y - y)).rgb;
67333
67360
  vec3 h = texture2D (sourceTexture, vec2 (uv0.x, uv0.y - y)).rgb;
67334
67361
  vec3 i = texture2D (sourceTexture, vec2 (uv0.x + x, uv0.y - y)).rgb;
67335
- vec3 value = e * 4.0;
67336
- value += (b + d + f + h) * 2.0;
67337
- value += (a + c + g + i);
67338
- value *= 1.0 / 16.0;
67362
+ vec3 value = e * 0.25;
67363
+ value += (b + d + f + h) * 0.125;
67364
+ value += (a + c + g + i) * 0.0625;
67339
67365
  gl_FragColor = vec4(value, 1.0);
67340
67366
  }
67341
67367
  `;
@@ -67350,20 +67376,19 @@ var wgslUpsamplePS = `
67350
67376
  var output: FragmentOutput;
67351
67377
  let x: f32 = uniform.sourceInvResolution.x;
67352
67378
  let y: f32 = uniform.sourceInvResolution.y;
67353
- let a: vec3f = textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x - x, input.uv0.y + y)).rgb;
67354
- let b: vec3f = textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x, input.uv0.y + y)).rgb;
67355
- let c: vec3f = textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x + x, input.uv0.y + y)).rgb;
67356
- let d: vec3f = textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x - x, input.uv0.y)).rgb;
67357
- let e: vec3f = textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x, input.uv0.y)).rgb;
67358
- let f: vec3f = textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x + x, input.uv0.y)).rgb;
67359
- let g: vec3f = textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x - x, input.uv0.y - y)).rgb;
67360
- let h: vec3f = textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x, input.uv0.y - y)).rgb;
67361
- let i: vec3f = textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x + x, input.uv0.y - y)).rgb;
67362
- var value: vec3f = e * 4.0;
67363
- value = value + (b + d + f + h) * 2.0;
67364
- value = value + (a + c + g + i);
67365
- value = value * (1.0 / 16.0);
67366
- output.color = vec4f(value, 1.0);
67379
+ let a: half3 = half3(textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x - x, input.uv0.y + y)).rgb);
67380
+ let b: half3 = half3(textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x, input.uv0.y + y)).rgb);
67381
+ let c: half3 = half3(textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x + x, input.uv0.y + y)).rgb);
67382
+ let d: half3 = half3(textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x - x, input.uv0.y)).rgb);
67383
+ let e: half3 = half3(textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x, input.uv0.y)).rgb);
67384
+ let f: half3 = half3(textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x + x, input.uv0.y)).rgb);
67385
+ let g: half3 = half3(textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x - x, input.uv0.y - y)).rgb);
67386
+ let h: half3 = half3(textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x, input.uv0.y - y)).rgb);
67387
+ let i: half3 = half3(textureSample(sourceTexture, sourceTextureSampler, vec2f(input.uv0.x + x, input.uv0.y - y)).rgb);
67388
+ var value: half3 = e * half(0.25);
67389
+ value += (b + d + f + h) * half(0.125);
67390
+ value += (a + c + g + i) * half(0.0625);
67391
+ output.color = vec4f(vec3f(value), 1.0);
67367
67392
  return output;
67368
67393
  }
67369
67394
  `;
@@ -67754,9 +67779,14 @@ var composeFringingPS$1 = `
67754
67779
  var composeCasPS$1 = `
67755
67780
  #ifdef CAS
67756
67781
  uniform float sharpness;
67757
- float maxComponent(float x, float y, float z) { return max(x, max(y, z)); }
67758
- vec3 toSDR(vec3 c) { return c / (1.0 + maxComponent(c.r, c.g, c.b)); }
67759
- vec3 toHDR(vec3 c) { return c / (1.0 - maxComponent(c.r, c.g, c.b)); }
67782
+ #ifdef CAS_HDR
67783
+ float maxComponent(float x, float y, float z) { return max(x, max(y, z)); }
67784
+ vec3 toSDR(vec3 c) { return c / (1.0 + maxComponent(c.r, c.g, c.b)); }
67785
+ vec3 toHDR(vec3 c) { return c / (1.0 - maxComponent(c.r, c.g, c.b)); }
67786
+ #else
67787
+ vec3 toSDR(vec3 c) { return c; }
67788
+ vec3 toHDR(vec3 c) { return c; }
67789
+ #endif
67760
67790
  vec3 applyCas(vec3 color, vec2 uv, float sharpness) {
67761
67791
  float x = sceneTextureInvRes.x;
67762
67792
  float y = sceneTextureInvRes.y;
@@ -68090,24 +68120,29 @@ var composeFringingPS = `
68090
68120
  var composeCasPS = `
68091
68121
  #ifdef CAS
68092
68122
  uniform sharpness: f32;
68093
- fn maxComponent(x: f32, y: f32, z: f32) -> f32 { return max(x, max(y, z)); }
68094
- fn toSDR(c: vec3f) -> vec3f { return c / (1.0 + maxComponent(c.r, c.g, c.b)); }
68095
- fn toHDR(c: vec3f) -> vec3f { return c / (1.0 - maxComponent(c.r, c.g, c.b)); }
68123
+ #ifdef CAS_HDR
68124
+ fn maxComponent(x: f32, y: f32, z: f32) -> f32 { return max(x, max(y, z)); }
68125
+ fn toSDR(c: vec3f) -> vec3f { return c / (1.0 + maxComponent(c.r, c.g, c.b)); }
68126
+ fn toHDR(c: vec3f) -> vec3f { return c / (1.0 - maxComponent(c.r, c.g, c.b)); }
68127
+ #else
68128
+ fn toSDR(c: vec3f) -> vec3f { return c; }
68129
+ fn toHDR(c: vec3f) -> vec3f { return c; }
68130
+ #endif
68096
68131
  fn applyCas(color: vec3f, uv: vec2f, sharpness: f32) -> vec3f {
68097
68132
  let x = uniform.sceneTextureInvRes.x;
68098
68133
  let y = uniform.sceneTextureInvRes.y;
68099
- let a = toSDR(textureSampleLevel(sceneTexture, sceneTextureSampler, uv + vec2f(0.0, -y), 0.0).rgb);
68100
- let b = toSDR(textureSampleLevel(sceneTexture, sceneTextureSampler, uv + vec2f(-x, 0.0), 0.0).rgb);
68101
- let c = toSDR(color.rgb);
68102
- let d = toSDR(textureSampleLevel(sceneTexture, sceneTextureSampler, uv + vec2f(x, 0.0), 0.0).rgb);
68103
- let e = toSDR(textureSampleLevel(sceneTexture, sceneTextureSampler, uv + vec2f(0.0, y), 0.0).rgb);
68134
+ let a: half3 = half3(toSDR(textureSampleLevel(sceneTexture, sceneTextureSampler, uv + vec2f(0.0, -y), 0.0).rgb));
68135
+ let b: half3 = half3(toSDR(textureSampleLevel(sceneTexture, sceneTextureSampler, uv + vec2f(-x, 0.0), 0.0).rgb));
68136
+ let c: half3 = half3(toSDR(color.rgb));
68137
+ let d: half3 = half3(toSDR(textureSampleLevel(sceneTexture, sceneTextureSampler, uv + vec2f(x, 0.0), 0.0).rgb));
68138
+ let e: half3 = half3(toSDR(textureSampleLevel(sceneTexture, sceneTextureSampler, uv + vec2f(0.0, y), 0.0).rgb));
68104
68139
  let min_g = min(a.g, min(b.g, min(c.g, min(d.g, e.g))));
68105
68140
  let max_g = max(a.g, max(b.g, max(c.g, max(d.g, e.g))));
68106
- let sharpening_amount = sqrt(min(1.0 - max_g, min_g) / max_g);
68107
- let w = sharpening_amount * uniform.sharpness;
68108
- var res = (w * (a + b + d + e) + c) / (4.0 * w + 1.0);
68109
- res = max(res, vec3f(0.0));
68110
- return toHDR(res);
68141
+ let sharpening_amount = sqrt(min(half(1.0) - max_g, min_g) / max_g);
68142
+ let w = sharpening_amount * half(uniform.sharpness);
68143
+ var res = (w * (a + b + d + e) + c) / (half(4.0) * w + half(1.0));
68144
+ res = max(res, half3(0.0));
68145
+ return toHDR(vec3f(res));
68111
68146
  }
68112
68147
  #endif
68113
68148
  `;
@@ -68267,6 +68302,15 @@ class RenderPassCompose extends RenderPassShaderQuad {
68267
68302
  get isSharpnessEnabled() {
68268
68303
  return this._sharpness > 0;
68269
68304
  }
68305
+ set hdrScene(value) {
68306
+ if (this._hdrScene !== value) {
68307
+ this._hdrScene = value;
68308
+ this._shaderDirty = true;
68309
+ }
68310
+ }
68311
+ get hdrScene() {
68312
+ return this._hdrScene;
68313
+ }
68270
68314
  postInit() {
68271
68315
  this.setClearColor(Color.BLACK);
68272
68316
  this.setClearDepth(1.0);
@@ -68295,7 +68339,7 @@ class RenderPassCompose extends RenderPassShaderQuad {
68295
68339
  const declHash = hashCode(customChunks.get('composeDeclarationsPS') ?? '');
68296
68340
  const startHash = hashCode(customChunks.get('composeMainStartPS') ?? '');
68297
68341
  const endHash = hashCode(customChunks.get('composeMainEndPS') ?? '');
68298
- const key = `${this.toneMapping}` + `-${gammaCorrectionName}` + `-${this.bloomTexture ? 'bloom' : 'nobloom'}` + `-${this.cocTexture ? 'dof' : 'nodof'}` + `-${this.blurTextureUpscale ? 'dofupscale' : ''}` + `-${this.ssaoTexture ? 'ssao' : 'nossao'}` + `-${this.gradingEnabled ? 'grading' : 'nograding'}` + `-${this.colorEnhanceEnabled ? 'colorenhance' : 'nocolorenhance'}` + `-${this.colorLUT ? 'colorlut' : 'nocolorlut'}` + `-${this.vignetteEnabled ? 'vignette' : 'novignette'}` + `-${this.fringingEnabled ? 'fringing' : 'nofringing'}` + `-${this.taaEnabled ? 'taa' : 'notaa'}` + `-${this.isSharpnessEnabled ? 'cas' : 'nocas'}` + `-${this._debug ?? ''}` + `-decl${declHash}-start${startHash}-end${endHash}`;
68342
+ const key = `${this.toneMapping}` + `-${gammaCorrectionName}` + `-${this.bloomTexture ? 'bloom' : 'nobloom'}` + `-${this.cocTexture ? 'dof' : 'nodof'}` + `-${this.blurTextureUpscale ? 'dofupscale' : ''}` + `-${this.ssaoTexture ? 'ssao' : 'nossao'}` + `-${this.gradingEnabled ? 'grading' : 'nograding'}` + `-${this.colorEnhanceEnabled ? 'colorenhance' : 'nocolorenhance'}` + `-${this.colorLUT ? 'colorlut' : 'nocolorlut'}` + `-${this.vignetteEnabled ? 'vignette' : 'novignette'}` + `-${this.fringingEnabled ? 'fringing' : 'nofringing'}` + `-${this.taaEnabled ? 'taa' : 'notaa'}` + `-${this.isSharpnessEnabled ? this._hdrScene ? 'cashdr' : 'cas' : 'nocas'}` + `-${this._debug ?? ''}` + `-decl${declHash}-start${startHash}-end${endHash}`;
68299
68343
  if (this._key !== key) {
68300
68344
  this._key = key;
68301
68345
  const defines = new Map();
@@ -68311,7 +68355,10 @@ class RenderPassCompose extends RenderPassShaderQuad {
68311
68355
  if (this.vignetteEnabled) defines.set('VIGNETTE', true);
68312
68356
  if (this.fringingEnabled) defines.set('FRINGING', true);
68313
68357
  if (this.taaEnabled) defines.set('TAA', true);
68314
- if (this.isSharpnessEnabled) defines.set('CAS', true);
68358
+ if (this.isSharpnessEnabled) {
68359
+ defines.set('CAS', true);
68360
+ if (this._hdrScene) defines.set('CAS_HDR', true);
68361
+ }
68315
68362
  if (this._debug) defines.set('DEBUG_COMPOSE', this._debug);
68316
68363
  const includes = new Map(shaderChunks);
68317
68364
  this.shader = ShaderUtils.createShader(this.device, {
@@ -68396,7 +68443,7 @@ class RenderPassCompose extends RenderPassShaderQuad {
68396
68443
  super.execute();
68397
68444
  }
68398
68445
  constructor(graphicsDevice){
68399
- super(graphicsDevice), this.sceneTexture = null, this.bloomIntensity = 0.01, this._bloomTexture = null, this._cocTexture = null, this.blurTexture = null, this.blurTextureUpscale = false, this._ssaoTexture = null, this._toneMapping = TONEMAP_LINEAR, this._gradingEnabled = false, this.gradingSaturation = 1, this.gradingContrast = 1, this.gradingBrightness = 1, this.gradingTint = new Color(1, 1, 1, 1), this._shaderDirty = true, this._vignetteEnabled = false, this.vignetteInner = 0.5, this.vignetteOuter = 1.0, this.vignetteCurvature = 0.5, this.vignetteIntensity = 0.3, this.vignetteColor = new Color(0, 0, 0), this._fringingEnabled = false, this.fringingIntensity = 10, this._colorEnhanceEnabled = false, this.colorEnhanceShadows = 0, this.colorEnhanceHighlights = 0, this.colorEnhanceVibrance = 0, this.colorEnhanceDehaze = 0, this.colorEnhanceMidtones = 0, this._taaEnabled = false, this._sharpness = 0.5, this._gammaCorrection = GAMMA_SRGB, this._colorLUT = null, this.colorLUTIntensity = 1, this._key = '', this._debug = null, this._customComposeChunks = new Map([
68446
+ super(graphicsDevice), this.sceneTexture = null, this.bloomIntensity = 0.01, this._bloomTexture = null, this._cocTexture = null, this.blurTexture = null, this.blurTextureUpscale = false, this._ssaoTexture = null, this._toneMapping = TONEMAP_LINEAR, this._gradingEnabled = false, this.gradingSaturation = 1, this.gradingContrast = 1, this.gradingBrightness = 1, this.gradingTint = new Color(1, 1, 1, 1), this._shaderDirty = true, this._vignetteEnabled = false, this.vignetteInner = 0.5, this.vignetteOuter = 1.0, this.vignetteCurvature = 0.5, this.vignetteIntensity = 0.3, this.vignetteColor = new Color(0, 0, 0), this._fringingEnabled = false, this.fringingIntensity = 10, this._colorEnhanceEnabled = false, this.colorEnhanceShadows = 0, this.colorEnhanceHighlights = 0, this.colorEnhanceVibrance = 0, this.colorEnhanceDehaze = 0, this.colorEnhanceMidtones = 0, this._taaEnabled = false, this._hdrScene = true, this._sharpness = 0.5, this._gammaCorrection = GAMMA_SRGB, this._colorLUT = null, this.colorLUTIntensity = 1, this._key = '', this._debug = null, this._customComposeChunks = new Map([
68400
68447
  [
68401
68448
  'composeDeclarationsPS',
68402
68449
  ''
@@ -69838,6 +69885,7 @@ class RenderPassCameraFrame extends RenderPass {
69838
69885
  setupComposePass(options) {
69839
69886
  this.composePass = new RenderPassCompose(this.device);
69840
69887
  this.composePass.bloomTexture = this.bloomPass?.bloomTexture;
69888
+ this.composePass.hdrScene = this.hdrFormat !== PIXELFORMAT_RGBA8;
69841
69889
  this.composePass.taaEnabled = options.taaEnabled;
69842
69890
  this.composePass.cocTexture = this.dofPass?.cocTexture;
69843
69891
  this.composePass.blurTexture = this.dofPass?.blurTexture;
@@ -71254,30 +71302,13 @@ class MiniStats {
71254
71302
  this.resize(this.sizes[value].width, this.sizes[value].height, this.sizes[value].graphs);
71255
71303
  this.opacity = value > 0 ? 0.85 : 0.7;
71256
71304
  if (value < this.gpuTimingMinSize && this.gpuPassGraphs) {
71257
- for (const passData of this.gpuPassGraphs.values()){
71258
- const index = this.graphs.indexOf(passData.graph);
71259
- if (index !== -1) {
71260
- this.graphs.splice(index, 1);
71261
- }
71262
- this.freeRow(passData.graph);
71263
- passData.graph.destroy();
71264
- }
71265
- this.gpuPassGraphs.clear();
71266
- const gpuGraph = this.graphs.find((g)=>g.name === 'GPU');
71267
- if (gpuGraph) gpuGraph.graphType = 0.33;
71305
+ this.clearSubGraphs(this.gpuPassGraphs, 'GPU', 0.33);
71268
71306
  }
71269
71307
  if (value < this.cpuTimingMinSize && this.cpuGraphs) {
71270
- for (const statData of this.cpuGraphs.values()){
71271
- const index = this.graphs.indexOf(statData.graph);
71272
- if (index !== -1) {
71273
- this.graphs.splice(index, 1);
71274
- }
71275
- this.freeRow(statData.graph);
71276
- statData.graph.destroy();
71277
- }
71278
- this.cpuGraphs.clear();
71279
- const cpuGraph = this.graphs.find((g)=>g.name === 'CPU');
71280
- if (cpuGraph) cpuGraph.graphType = 0.66;
71308
+ this.clearSubGraphs(this.cpuGraphs, 'CPU', 0.66);
71309
+ }
71310
+ if (value < this.vramTimingMinSize && this.vramGraphs) {
71311
+ this.clearSubGraphs(this.vramGraphs);
71281
71312
  }
71282
71313
  }
71283
71314
  get activeSizeIndex() {
@@ -71508,6 +71539,21 @@ class MiniStats {
71508
71539
  this.graphRows.delete(graph);
71509
71540
  }
71510
71541
  }
71542
+ clearSubGraphs(subGraphs, mainGraphName, graphType) {
71543
+ for (const statData of subGraphs.values()){
71544
+ const index = this.graphs.indexOf(statData.graph);
71545
+ if (index !== -1) {
71546
+ this.graphs.splice(index, 1);
71547
+ }
71548
+ this.freeRow(statData.graph);
71549
+ statData.graph.destroy();
71550
+ }
71551
+ subGraphs.clear();
71552
+ if (mainGraphName) {
71553
+ const mainGraph = this.graphs.find((g)=>g.name === mainGraphName);
71554
+ if (mainGraph) mainGraph.graphType = graphType;
71555
+ }
71556
+ }
71511
71557
  ensureTextureHeight(requiredRows) {
71512
71558
  const maxWidth = this.sizes[this.sizes.length - 1].width;
71513
71559
  const requiredWidth = math.nextPowerOfTwo(maxWidth);
@@ -73714,29 +73760,34 @@ const right$1 = new Vec3();
73714
73760
  const offset = new Vec3();
73715
73761
  const rotation = new Quat();
73716
73762
  /**
73717
- * First-person shooter style camera controller with gravity and capsule collision.
73763
+ * First-person camera controller with spring-damper suspension over voxel terrain.
73718
73764
  *
73719
73765
  * Movement is constrained to the horizontal plane (XZ) relative to the camera yaw.
73720
- * Vertical motion is driven by gravity and resolved by capsule collision with the
73721
- * voxel grid. The camera is positioned at eye height within the capsule.
73766
+ * Vertical positioning uses a spring-damper system that hovers the capsule above the
73767
+ * voxel surface, filtering out terrain noise for smooth camera motion. Capsule
73768
+ * collision handles walls and obstacles. When airborne, normal gravity applies.
73722
73769
  */
73723
73770
  class WalkController {
73724
73771
  /**
73725
73772
  * Optional voxel collider for capsule collision with sliding
73726
73773
  */
73727
73774
  collider = null;
73775
+ /**
73776
+ * Field of view in degrees for walk mode.
73777
+ */
73778
+ fov = 102;
73728
73779
  /**
73729
73780
  * Total capsule height in meters (default: human proportion)
73730
73781
  */
73731
- capsuleHeight = 1.8;
73782
+ capsuleHeight = 1.5;
73732
73783
  /**
73733
73784
  * Capsule radius in meters
73734
73785
  */
73735
- capsuleRadius = 0.3;
73786
+ capsuleRadius = 0.2;
73736
73787
  /**
73737
73788
  * Camera height from the bottom of the capsule in meters
73738
73789
  */
73739
- eyeHeight = 1.6;
73790
+ eyeHeight = 1.3;
73740
73791
  /**
73741
73792
  * Gravity acceleration in m/s^2
73742
73793
  */
@@ -73744,11 +73795,11 @@ class WalkController {
73744
73795
  /**
73745
73796
  * Jump velocity in m/s
73746
73797
  */
73747
- jumpSpeed = 5;
73798
+ jumpSpeed = 4;
73748
73799
  /**
73749
73800
  * Movement speed in m/s when grounded
73750
73801
  */
73751
- moveGroundSpeed = 10;
73802
+ moveGroundSpeed = 7;
73752
73803
  /**
73753
73804
  * Movement speed in m/s when in the air (for air control)
73754
73805
  */
@@ -73765,38 +73816,91 @@ class WalkController {
73765
73816
  * Velocity damping factor when grounded (0 = no damping, 1 = full damping)
73766
73817
  */
73767
73818
  velocityDampingGround = 0.99;
73819
+ /**
73820
+ * Velocity damping factor when grounded with no movement input.
73821
+ * More aggressive than normal ground damping to prevent slope drift.
73822
+ */
73823
+ velocityDampingIdle = 0.9;
73768
73824
  /**
73769
73825
  * Velocity damping factor when in the air (0 = no damping, 1 = full damping)
73770
73826
  */
73771
- velocityDampingAir = 0.99925;
73827
+ velocityDampingAir = 0.997;
73828
+ /**
73829
+ * Target clearance from capsule bottom to ground surface in meters.
73830
+ * The capsule hovers this far above terrain to avoid bouncing on noisy voxels.
73831
+ */
73832
+ hoverHeight = 0.2;
73833
+ /**
73834
+ * Spring stiffness for ground-following suspension (higher = stiffer tracking).
73835
+ */
73836
+ springStiffness = 800;
73837
+ /**
73838
+ * Damping coefficient for ground-following suspension.
73839
+ * Critical damping is approximately 2 * sqrt(springStiffness).
73840
+ */
73841
+ springDamping = 57;
73842
+ /**
73843
+ * Maximum downward raycast distance to search for ground below the capsule.
73844
+ */
73845
+ groundProbeRange = 1.0;
73772
73846
  _position = new Vec3();
73773
73847
  _angles = new Vec3();
73774
73848
  _velocity = new Vec3();
73775
73849
  _grounded = false;
73776
73850
  _jumping = false;
73851
+ _jumpHeld = false;
73777
73852
  onEnter(camera) {
73778
73853
  this.goto(camera);
73779
73854
  if (this.collider) {
73780
- this._checkCollision(this._position, d);
73781
- if (d.y > 0) {
73855
+ const groundY = this._probeGround(this._position);
73856
+ if (groundY !== null) {
73782
73857
  this._grounded = true;
73783
73858
  this._velocity.y = 0;
73859
+ this._position.y = groundY + this.hoverHeight + this.eyeHeight;
73784
73860
  }
73785
73861
  }
73786
73862
  }
73787
73863
  update(deltaTime, inputFrame, camera) {
73788
73864
  const { move, rotate } = inputFrame.read();
73789
- // jump
73865
+ const hasInput = move[0] !== 0 || move[2] !== 0;
73866
+ // ground probe: cast a ray downward to find the terrain surface
73867
+ const groundY = this._probeGround(this._position);
73868
+ const hasGround = groundY !== null;
73869
+ // jump (require release before re-triggering)
73790
73870
  if (this._velocity.y < 0) {
73791
73871
  this._jumping = false;
73792
73872
  }
73793
- if (move[1] && !this._jumping && this._grounded) {
73873
+ if (move[1] && !this._jumping && this._grounded && !this._jumpHeld) {
73794
73874
  this._jumping = true;
73795
73875
  this._velocity.y = this.jumpSpeed;
73796
73876
  this._grounded = false;
73797
73877
  }
73798
- // gravity
73799
- this._velocity.y -= this.gravity * deltaTime;
73878
+ this._jumpHeld = !!move[1];
73879
+ // vertical force: spring-damper when ground is detected, gravity when airborne
73880
+ if (hasGround && !this._jumping) {
73881
+ const targetY = groundY + this.hoverHeight + this.eyeHeight;
73882
+ const displacement = this._position.y - targetY;
73883
+ if (displacement > 0.1) {
73884
+ // well above target (jump/ledge): freefall, snap to rest height on arrival
73885
+ this._velocity.y -= this.gravity * deltaTime;
73886
+ const nextY = this._position.y + this._velocity.y * deltaTime;
73887
+ if (nextY <= targetY) {
73888
+ this._position.y = targetY;
73889
+ this._velocity.y = 0;
73890
+ }
73891
+ this._grounded = false;
73892
+ }
73893
+ else {
73894
+ // at or near target (walking/slopes): spring tracks terrain
73895
+ const springForce = -this.springStiffness * displacement - this.springDamping * this._velocity.y;
73896
+ this._velocity.y += springForce * deltaTime;
73897
+ this._grounded = true;
73898
+ }
73899
+ }
73900
+ else {
73901
+ this._velocity.y -= this.gravity * deltaTime;
73902
+ this._grounded = false;
73903
+ }
73800
73904
  // rotate
73801
73905
  this._angles.add(v.set(-rotate[1], -rotate[0], 0));
73802
73906
  this._angles.x = math.clamp(this._angles.x, -90, 90);
@@ -73808,15 +73912,20 @@ class WalkController {
73808
73912
  offset.add(forward.mulScalar(move[2]));
73809
73913
  offset.add(right$1.mulScalar(move[0]));
73810
73914
  this._velocity.add(offset.mulScalar(this._grounded ? this.moveGroundSpeed : this.moveAirSpeed));
73811
- const alpha = damp(this._grounded ? this.velocityDampingGround : this.velocityDampingAir, deltaTime);
73915
+ // horizontal damping: aggressive when grounded with no input to prevent slope drift
73916
+ const dampFactor = this._grounded ?
73917
+ (hasInput ? this.velocityDampingGround : this.velocityDampingIdle) :
73918
+ this.velocityDampingAir;
73919
+ const alpha = damp(dampFactor, deltaTime);
73812
73920
  this._velocity.x = math.lerp(this._velocity.x, 0, alpha);
73813
73921
  this._velocity.z = math.lerp(this._velocity.z, 0, alpha);
73814
73922
  this._position.add(v.copy(this._velocity).mulScalar(deltaTime));
73815
- // collision check
73923
+ // capsule collision: walls, ceiling, and fallback floor contact
73816
73924
  this._checkCollision(this._position, d);
73817
73925
  // update camera
73818
73926
  camera.position.copy(this._position);
73819
73927
  camera.angles.set(this._angles.x, this._angles.y, 0);
73928
+ camera.fov = this.fov;
73820
73929
  }
73821
73930
  onExit(_camera) {
73822
73931
  // nothing to clean up
@@ -73837,16 +73946,48 @@ class WalkController {
73837
73946
  this._jumping = false;
73838
73947
  }
73839
73948
  /**
73840
- * Check for collision and apply displacement to the position.
73949
+ * Cast multiple rays downward to find the average ground surface height.
73950
+ * Uses 5 rays (center + 4 cardinal at capsule radius) to spatially filter
73951
+ * noisy voxel heights, giving the spring a smoother target.
73841
73952
  *
73842
- * @param pos - eye position in playcanvas world space
73843
- * @param disp - pre-allocated vector to receive the collision push-out displacement
73844
- * @returns - the displaced position (same as input position vector for chaining)
73953
+ * @param pos - Eye position in PlayCanvas world space.
73954
+ * @returns Average ground surface Y in PlayCanvas space, or null if no ground found.
73955
+ */
73956
+ _probeGround(pos) {
73957
+ if (!this.collider)
73958
+ return null;
73959
+ const vy = -(pos.y - this.eyeHeight);
73960
+ const r = this.capsuleRadius;
73961
+ const range = this.groundProbeRange;
73962
+ let totalY = 0;
73963
+ let hitCount = 0;
73964
+ for (let i = 0; i < 5; i++) {
73965
+ let vx = -pos.x;
73966
+ let vz = pos.z;
73967
+ if (i === 1)
73968
+ vx -= r;
73969
+ else if (i === 2)
73970
+ vx += r;
73971
+ else if (i === 3)
73972
+ vz += r;
73973
+ else if (i === 4)
73974
+ vz -= r;
73975
+ const hit = this.collider.queryRay(vx, vy, vz, 0, 1, 0, range);
73976
+ if (hit) {
73977
+ totalY += -hit.y;
73978
+ hitCount++;
73979
+ }
73980
+ }
73981
+ return hitCount > 0 ? totalY / hitCount : null;
73982
+ }
73983
+ /**
73984
+ * Check for capsule collision and apply push-out displacement.
73985
+ * Handles walls, ceiling hits, and fallback floor contact when airborne.
73986
+ *
73987
+ * @param pos - Eye position in PlayCanvas world space.
73988
+ * @param disp - Pre-allocated vector to receive the collision push-out displacement.
73845
73989
  */
73846
73990
  _checkCollision(pos, disp) {
73847
- // derive capsule center from eye position in PlayCanvas space:
73848
- // bottom of capsule = eyePos.y - eyeHeight
73849
- // capsule center = eyePos.y - eyeHeight + capsuleHeight / 2
73850
73991
  const center = pos.y - this.eyeHeight + this.capsuleHeight * 0.5;
73851
73992
  const half = this.capsuleHeight * 0.5 - this.capsuleRadius;
73852
73993
  // convert to voxel space (negate X, negate Y, keep Z)
@@ -73854,21 +73995,18 @@ class WalkController {
73854
73995
  const vy = -center;
73855
73996
  const vz = pos.z;
73856
73997
  if (this.collider.queryCapsule(vx, vy, vz, half, this.capsuleRadius, out)) {
73857
- // push out vector to playcanvas space
73858
73998
  disp.set(-out.x, -out.y, out.z);
73859
- // apply displacement
73860
73999
  pos.add(disp);
73861
- // ground collision: if pushed upward and falling, cancel downward velocity and set grounded
73862
- if (disp.y > 0 && this._velocity.y < 0) {
74000
+ // ceiling collision: cancel upward velocity
74001
+ if (disp.y < 0 && this._velocity.y > 0) {
73863
74002
  this._velocity.y = 0;
73864
- this._grounded = true;
73865
74003
  }
73866
- // ceiling collision: if pushed downward and rising, cancel upward velocity
73867
- if (disp.y < 0 && this._velocity.y > 0) {
74004
+ // airborne floor collision: transition to grounded as a fallback safety net
74005
+ if (!this._grounded && disp.y > 0 && this._velocity.y < 0) {
73868
74006
  this._velocity.y = 0;
74007
+ this._grounded = true;
73869
74008
  }
73870
74009
  }
73871
- return disp;
73872
74010
  }
73873
74011
  }
73874
74012
 
@@ -74036,13 +74174,14 @@ class CameraManager {
74036
74174
  state.hasAnimation = !!controllers.anim;
74037
74175
  state.animationDuration = controllers.anim ? controllers.anim.animState.cursor.duration : 0;
74038
74176
  // initialize camera mode and initial camera position
74039
- state.cameraMode = state.hasAnimation ? 'anim' : (isObjectExperience ? 'orbit' : 'fly');
74177
+ state.cameraMode = state.hasAnimation ? 'anim' : (isObjectExperience ? 'orbit' : (collider ? 'walk' : 'fly'));
74040
74178
  this.camera.copy(resetCamera);
74041
74179
  const target = new Camera(this.camera); // the active controller updates this
74042
74180
  const from = new Camera(this.camera); // stores the previous camera state during transition
74043
- let fromMode = isObjectExperience ? 'orbit' : 'fly';
74181
+ const defaultMode = isObjectExperience ? 'orbit' : (collider ? 'walk' : 'fly');
74182
+ let fromMode = defaultMode;
74044
74183
  // tracks the mode to restore when exiting FPS
74045
- let preWalkMode = 'fly';
74184
+ let preWalkMode = defaultMode;
74046
74185
  // enter the initial controller
74047
74186
  getController(state.cameraMode).onEnter(this.camera);
74048
74187
  // transition state
@@ -74064,6 +74203,10 @@ class CameraManager {
74064
74203
  walkSource.update(dt, this.camera.position, this.camera.angles, frame);
74065
74204
  }
74066
74205
  controller.update(dt, frame, target);
74206
+ // walk controller sets its own FOV; all other modes use the authored FOV
74207
+ if (state.cameraMode !== 'walk') {
74208
+ target.fov = resetCamera.fov;
74209
+ }
74067
74210
  if (transitionTimer < 1) {
74068
74211
  // lerp away from previous camera during transition
74069
74212
  this.camera.lerp(from, target, easeOut(transitionTimer));
@@ -74618,11 +74761,9 @@ class InputController {
74618
74761
  case 'h':
74619
74762
  events.fire('inputEvent', 'toggleHelp');
74620
74763
  break;
74621
- case 'w':
74622
- case 'a':
74623
- case 's':
74624
- case 'd':
74625
- if (state.cameraMode === 'walk' && state.inputMode === 'desktop' && !state.gamingControls) {
74764
+ default:
74765
+ if ((event.code === 'KeyW' || event.code === 'KeyA' || event.code === 'KeyS' || event.code === 'KeyD') &&
74766
+ state.cameraMode === 'walk' && state.inputMode === 'desktop' && !state.gamingControls) {
74626
74767
  state.gamingControls = true;
74627
74768
  }
74628
74769
  break;
@@ -75480,8 +75621,8 @@ class VoxelDebugOverlay {
75480
75621
 
75481
75622
  const SVGNS = 'http://www.w3.org/2000/svg';
75482
75623
  const NUM_SAMPLES = 12;
75483
- const CIRCLE_OUTER_RADIUS = 0.3;
75484
- const CIRCLE_INNER_RADIUS = 0.22;
75624
+ const CIRCLE_OUTER_RADIUS = 0.2;
75625
+ const CIRCLE_INNER_RADIUS = 0.17;
75485
75626
  const BEZIER_K = 1 / 6;
75486
75627
  const NORMAL_SMOOTH_FACTOR = 0.25;
75487
75628
  const tmpV = new Vec3();
@@ -75980,8 +76121,23 @@ class Viewer {
75980
76121
  // same performance, but rotating on slow devices does not give us unsorted splats on sides
75981
76122
  gsplat.radialSorting = true;
75982
76123
  const eventHandler = app.systems.gsplat;
75983
- // we must force continuous rendering with streaming & lod system
76124
+ // idle timer: force continuous rendering until 4s of inactivity
76125
+ let idleTime = 0;
75984
76126
  this.forceRenderNextFrame = true;
76127
+ app.on('update', (dt) => {
76128
+ idleTime += dt;
76129
+ this.forceRenderNextFrame = idleTime < 4;
76130
+ });
76131
+ events.on('inputEvent', (type) => {
76132
+ if (type !== 'interact') {
76133
+ idleTime = 0;
76134
+ }
76135
+ });
76136
+ eventHandler.on('frame:ready', (_camera, _layer, ready, loading) => {
76137
+ if (loading > 0 || !ready) {
76138
+ idleTime = 0;
76139
+ }
76140
+ });
75985
76141
  let current = 0;
75986
76142
  let watermark = 1;
75987
76143
  const readyHandler = (camera, layer, ready, loading) => {
@@ -76077,6 +76233,69 @@ const SOLID_LEAF_MARKER = 0xFF000000 >>> 0;
76077
76233
  const PENETRATION_EPSILON = 1e-4;
76078
76234
  /** Half-extent of the flatness sampling patch (5x5 when R=2). */
76079
76235
  const FLAT_R = 2;
76236
+ /** 1/sqrt(2), used to normalise 45-degree diagonal normals. */
76237
+ const INV_SQRT2 = 1 / Math.sqrt(2);
76238
+ /**
76239
+ * Surface normal candidate directions for querySurfaceNormal.
76240
+ * Each entry: [dx, dy, dz, t1x, t1y, t1z, t2x, t2y, t2z]
76241
+ * (dx,dy,dz) = canonical normal direction (components 0 or +/-1)
76242
+ * (t1,t2) = orthogonal tangent vectors spanning the perpendicular sampling plane
76243
+ */
76244
+ const SURFACE_CANDIDATES = [
76245
+ // Axis-aligned
76246
+ [1, 0, 0, 0, 1, 0, 0, 0, 1],
76247
+ [0, 1, 0, 1, 0, 0, 0, 0, 1],
76248
+ [0, 0, 1, 1, 0, 0, 0, 1, 0],
76249
+ // XZ diagonals (vertical walls at 45 degrees)
76250
+ [1, 0, 1, 0, 1, 0, -1, 0, 1],
76251
+ [1, 0, -1, 0, 1, 0, 1, 0, 1],
76252
+ // XY diagonals (walls tilted from vertical)
76253
+ [1, 1, 0, 0, 0, 1, -1, 1, 0],
76254
+ [1, -1, 0, 0, 0, 1, 1, 1, 0],
76255
+ // YZ diagonals (sloped floors/ceilings)
76256
+ [0, 1, 1, 1, 0, 0, 0, -1, 1],
76257
+ [0, 1, -1, 1, 0, 0, 0, 1, 1]
76258
+ ];
76259
+ /**
76260
+ * Score a surface candidate direction by sampling a 5x5 patch at three depth layers
76261
+ * shifted along the step direction. Returns the best (maximum) layer score. A "surface
76262
+ * hit" at each sample is a solid voxel whose neighbour in the step direction is empty.
76263
+ *
76264
+ * @param collider - The voxel collider instance.
76265
+ * @param ix - Voxel X index of the surface point.
76266
+ * @param iy - Voxel Y index of the surface point.
76267
+ * @param iz - Voxel Z index of the surface point.
76268
+ * @param sx - Step X component (camera-facing direction).
76269
+ * @param sy - Step Y component.
76270
+ * @param sz - Step Z component.
76271
+ * @param t1x - First tangent vector X.
76272
+ * @param t1y - First tangent vector Y.
76273
+ * @param t1z - First tangent vector Z.
76274
+ * @param t2x - Second tangent vector X.
76275
+ * @param t2y - Second tangent vector Y.
76276
+ * @param t2z - Second tangent vector Z.
76277
+ * @returns The best score across the three depth layers.
76278
+ */
76279
+ function scoreSurfaceCandidate(collider, ix, iy, iz, sx, sy, sz, t1x, t1y, t1z, t2x, t2y, t2z) {
76280
+ let best = 0;
76281
+ for (let depth = 1; depth >= -1; depth--) {
76282
+ let s = 0;
76283
+ for (let da = -FLAT_R; da <= FLAT_R; da++) {
76284
+ for (let db = -FLAT_R; db <= FLAT_R; db++) {
76285
+ const px = ix + da * t1x + db * t2x - sx * depth;
76286
+ const py = iy + da * t1y + db * t2y - sy * depth;
76287
+ const pz = iz + da * t1z + db * t2z - sz * depth;
76288
+ if (collider.isVoxelSolid(px, py, pz) &&
76289
+ !collider.isVoxelSolid(px + sx, py + sy, pz + sz)) {
76290
+ s++;
76291
+ }
76292
+ }
76293
+ }
76294
+ if (s > best)
76295
+ best = s;
76296
+ }
76297
+ return best;
76298
+ }
76080
76299
  /**
76081
76300
  * Count the number of set bits in a 32-bit integer.
76082
76301
  *
@@ -76267,12 +76486,12 @@ class VoxelCollider {
76267
76486
  return this.isVoxelSolid(ix, iy, iz);
76268
76487
  }
76269
76488
  /**
76270
- * Compute a stable, axis-aligned surface normal at a world-space position using
76271
- * flatness-probability sampling. The camera can see at most 3 axis-aligned faces of any
76272
- * voxel (one per axis, determined by ray direction sign). For each candidate axis a 5x5
76273
- * patch of voxels in the perpendicular plane is sampled: a voxel counts as a "surface hit"
76274
- * if it is solid and the adjacent voxel toward the camera is empty. The axis with the
76275
- * highest hit count is the surface orientation.
76489
+ * Compute a stable surface normal at a world-space position using flatness-probability
76490
+ * sampling. Tests 9 candidate directions: 3 axis-aligned and 6 diagonal (45-degree in
76491
+ * each pair of axes). For each camera-facing candidate a 5x5 patch of voxels in the
76492
+ * perpendicular plane is sampled: a voxel counts as a "surface hit" if it is solid and
76493
+ * the adjacent voxel toward the camera is empty. The candidate with the highest hit
76494
+ * count is the surface orientation.
76276
76495
  *
76277
76496
  * @param x - World X coordinate of the surface point.
76278
76497
  * @param y - World Y coordinate of the surface point.
@@ -76280,7 +76499,7 @@ class VoxelCollider {
76280
76499
  * @param rdx - Ray direction X (toward the surface, in voxel space).
76281
76500
  * @param rdy - Ray direction Y.
76282
76501
  * @param rdz - Ray direction Z.
76283
- * @returns Object with nx, ny, nz components of the axis-aligned surface normal.
76502
+ * @returns Object with nx, ny, nz components of the surface normal.
76284
76503
  */
76285
76504
  querySurfaceNormal(x, y, z, rdx, rdy, rdz) {
76286
76505
  // Nudge the query point slightly along the ray direction so that a hit point
@@ -76292,84 +76511,29 @@ class VoxelCollider {
76292
76511
  const iy = Math.floor((y + Math.sign(rdy) * nudge - this._gridMinY) / this._voxelResolution);
76293
76512
  const iz = Math.floor((z + Math.sign(rdz) * nudge - this._gridMinZ) / this._voxelResolution);
76294
76513
  const result = this._normalResult;
76295
- // For each axis, the camera-facing step is opposite to the ray direction component.
76296
- const stepX = rdx < 0 ? 1 : -1;
76297
- const stepY = rdy < 0 ? 1 : -1;
76298
- const stepZ = rdz < 0 ? 1 : -1;
76299
76514
  let bestScore = -1;
76300
76515
  let bestNx = 0;
76301
76516
  let bestNy = 1;
76302
76517
  let bestNz = 0;
76303
- // Axis X: sample 5x5 in YZ plane at x = ix ± 1
76304
- if (Math.abs(rdx) > 1e-6) {
76305
- let score = 0;
76306
- for (let depth = 1; depth >= -1; depth--) {
76307
- let s = 0;
76308
- const px = ix - stepX * depth;
76309
- for (let da = -FLAT_R; da <= FLAT_R; da++) {
76310
- for (let db = -FLAT_R; db <= FLAT_R; db++) {
76311
- if (this.isVoxelSolid(px, iy + da, iz + db) &&
76312
- !this.isVoxelSolid(px + stepX, iy + da, iz + db)) {
76313
- s++;
76314
- }
76315
- }
76316
- }
76317
- if (s > score)
76318
- score = s;
76319
- }
76320
- if (score > bestScore) {
76321
- bestScore = score;
76322
- bestNx = stepX;
76323
- bestNy = 0;
76324
- bestNz = 0;
76325
- }
76326
- }
76327
- // Axis Y: sample 5x5 in XZ plane at y = iy ± 1
76328
- if (Math.abs(rdy) > 1e-6) {
76329
- let score = 0;
76330
- for (let depth = 1; depth >= -1; depth--) {
76331
- let s = 0;
76332
- const py = iy - stepY * depth;
76333
- for (let da = -FLAT_R; da <= FLAT_R; da++) {
76334
- for (let db = -FLAT_R; db <= FLAT_R; db++) {
76335
- if (this.isVoxelSolid(ix + da, py, iz + db) &&
76336
- !this.isVoxelSolid(ix + da, py + stepY, iz + db)) {
76337
- s++;
76338
- }
76339
- }
76340
- }
76341
- if (s > score)
76342
- score = s;
76343
- }
76344
- if (score > bestScore) {
76345
- bestScore = score;
76346
- bestNx = 0;
76347
- bestNy = stepY;
76348
- bestNz = 0;
76349
- }
76350
- }
76351
- // Axis Z: sample 5x5 in XY plane at z = iz ± 1
76352
- if (Math.abs(rdz) > 1e-6) {
76353
- let score = 0;
76354
- for (let depth = 1; depth >= -1; depth--) {
76355
- let s = 0;
76356
- const pz = iz - stepZ * depth;
76357
- for (let da = -FLAT_R; da <= FLAT_R; da++) {
76358
- for (let db = -FLAT_R; db <= FLAT_R; db++) {
76359
- if (this.isVoxelSolid(ix + da, iy + db, pz) &&
76360
- !this.isVoxelSolid(ix + da, iy + db, pz + stepZ)) {
76361
- s++;
76362
- }
76363
- }
76364
- }
76365
- if (s > score)
76366
- score = s;
76367
- }
76518
+ for (let c = 0; c < SURFACE_CANDIDATES.length; c++) {
76519
+ const cand = SURFACE_CANDIDATES[c];
76520
+ const dx = cand[0];
76521
+ const dy = cand[1];
76522
+ const dz = cand[2];
76523
+ const dot = rdx * dx + rdy * dy + rdz * dz;
76524
+ if (Math.abs(dot) < 1e-6)
76525
+ continue;
76526
+ const sign = dot < 0 ? 1 : -1;
76527
+ const sx = dx * sign;
76528
+ const sy = dy * sign;
76529
+ const sz = dz * sign;
76530
+ const score = scoreSurfaceCandidate(this, ix, iy, iz, sx, sy, sz, cand[3], cand[4], cand[5], cand[6], cand[7], cand[8]);
76368
76531
  if (score > bestScore) {
76369
76532
  bestScore = score;
76370
- bestNx = 0;
76371
- bestNy = 0;
76372
- bestNz = stepZ;
76533
+ const mag = (Math.abs(dx) + Math.abs(dy) + Math.abs(dz)) > 1 ? INV_SQRT2 : 1;
76534
+ bestNx = sx * mag;
76535
+ bestNy = sy * mag;
76536
+ bestNz = sz * mag;
76373
76537
  }
76374
76538
  }
76375
76539
  result.nx = bestNx;
@@ -77922,7 +78086,7 @@ const initXr = (global) => {
77922
78086
  });
77923
78087
  };
77924
78088
 
77925
- var version = "1.16.12";
78089
+ var version = "1.17.0";
77926
78090
 
77927
78091
  const loadGsplat = async (app, config, progressCallback) => {
77928
78092
  const { contents, contentUrl, unified, aa } = config;