@playcanvas/supersplat-viewer 1.15.0 → 1.16.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.16.1';
4
- const revision = '4486208';
3
+ const version$1 = '2.16.2';
4
+ const revision = '5c8389e';
5
5
  function extend(target, ex) {
6
6
  for(const prop in ex){
7
7
  const copy = ex[prop];
@@ -8725,8 +8725,12 @@ class WebgpuShaderProcessorWGSL {
8725
8725
  }
8726
8726
  static generateFragmentOutputStruct(src, numRenderTargets) {
8727
8727
  let structCode = 'struct FragmentOutput {\n';
8728
+ const colorName = (i)=>`color${i > 0 ? i : ''}`;
8728
8729
  for(let i = 0; i < numRenderTargets; i++){
8729
- structCode += ` @location(${i}) color${i > 0 ? i : ''} : pcOutType${i},\n`;
8730
+ const name = colorName(i);
8731
+ if (src.search(new RegExp(`\\.${name}\\s*=`)) !== -1) {
8732
+ structCode += ` @location(${i}) ${name} : pcOutType${i},\n`;
8733
+ }
8730
8734
  }
8731
8735
  const needsFragDepth = src.search(/\.fragDepth\s*=/) !== -1;
8732
8736
  if (needsFragDepth) {
@@ -14264,7 +14268,8 @@ class WebglGraphicsDevice extends GraphicsDevice {
14264
14268
  });
14265
14269
  const rgbaChannels = getPixelFormatChannelsForRgbaReadback(texture._format);
14266
14270
  const needsRgbaReadback = rgbaChannels > 0;
14267
- const outputData = options.data ?? new (getPixelFormatArrayType(texture._format))(TextureUtils.calcLevelGpuSize(width, height, 1, texture._format));
14271
+ const ArrayType = getPixelFormatArrayType(texture._format);
14272
+ const outputData = options.data ?? new ArrayType(TextureUtils.calcLevelGpuSize(width, height, 1, texture._format) / ArrayType.BYTES_PER_ELEMENT);
14268
14273
  const readBuffer = needsRgbaReadback ? new Uint8Array(width * height * 4) : outputData;
14269
14274
  this.setRenderTarget(renderTarget);
14270
14275
  this.initRenderTarget(renderTarget);
@@ -19210,7 +19215,7 @@ const tmpMat4 = new Mat4();
19210
19215
  const tmpQuat = new Quat();
19211
19216
  const position = new Vec3();
19212
19217
  const invParentWtm = new Mat4();
19213
- const rotation$4 = new Quat();
19218
+ const rotation$5 = new Quat();
19214
19219
  const invParentRot = new Quat();
19215
19220
  const matrix = new Mat4();
19216
19221
  const target = new Vec3();
@@ -19584,16 +19589,16 @@ class GraphNode extends EventHandler {
19584
19589
  }
19585
19590
  setRotation(x, y, z, w) {
19586
19591
  if (x instanceof Quat) {
19587
- rotation$4.copy(x);
19592
+ rotation$5.copy(x);
19588
19593
  } else {
19589
- rotation$4.set(x, y, z, w);
19594
+ rotation$5.set(x, y, z, w);
19590
19595
  }
19591
19596
  if (this._parent === null) {
19592
- this.localRotation.copy(rotation$4);
19597
+ this.localRotation.copy(rotation$5);
19593
19598
  } else {
19594
19599
  const parentRot = this._parent.getRotation();
19595
19600
  invParentRot.copy(parentRot).invert();
19596
- this.localRotation.copy(invParentRot).mul(rotation$4);
19601
+ this.localRotation.copy(invParentRot).mul(rotation$5);
19597
19602
  }
19598
19603
  if (!this._dirtyLocal) {
19599
19604
  this._dirtifyLocal();
@@ -19758,8 +19763,8 @@ class GraphNode extends EventHandler {
19758
19763
  up$1.set(ux, uy, uz);
19759
19764
  }
19760
19765
  matrix.setLookAt(this.getPosition(), target, up$1);
19761
- rotation$4.setFromMat4(matrix);
19762
- this.setRotation(rotation$4);
19766
+ rotation$5.setFromMat4(matrix);
19767
+ this.setRotation(rotation$5);
19763
19768
  }
19764
19769
  translate(x, y, z) {
19765
19770
  if (x instanceof Vec3) {
@@ -19783,23 +19788,23 @@ class GraphNode extends EventHandler {
19783
19788
  }
19784
19789
  }
19785
19790
  rotate(x, y, z) {
19786
- rotation$4.setFromEulerAngles(x, y, z);
19791
+ rotation$5.setFromEulerAngles(x, y, z);
19787
19792
  if (this._parent === null) {
19788
- this.localRotation.mul2(rotation$4, this.localRotation);
19793
+ this.localRotation.mul2(rotation$5, this.localRotation);
19789
19794
  } else {
19790
19795
  const rot = this.getRotation();
19791
19796
  const parentRot = this._parent.getRotation();
19792
19797
  invParentRot.copy(parentRot).invert();
19793
- rotation$4.mul2(invParentRot, rotation$4);
19794
- this.localRotation.mul2(rotation$4, rot);
19798
+ rotation$5.mul2(invParentRot, rotation$5);
19799
+ this.localRotation.mul2(rotation$5, rot);
19795
19800
  }
19796
19801
  if (!this._dirtyLocal) {
19797
19802
  this._dirtifyLocal();
19798
19803
  }
19799
19804
  }
19800
19805
  rotateLocal(x, y, z) {
19801
- rotation$4.setFromEulerAngles(x, y, z);
19802
- this.localRotation.mul(rotation$4);
19806
+ rotation$5.setFromEulerAngles(x, y, z);
19807
+ this.localRotation.mul(rotation$5);
19803
19808
  if (!this._dirtyLocal) {
19804
19809
  this._dirtifyLocal();
19805
19810
  }
@@ -31623,7 +31628,7 @@ class GSplatResourceBase {
31623
31628
  return this._format;
31624
31629
  }
31625
31630
  getTexture(name) {
31626
- return this.streams.getTexture(name);
31631
+ return this.streams.getTexture(name) ?? null;
31627
31632
  }
31628
31633
  get textureDimensions() {
31629
31634
  return this.streams.textureDimensions;
@@ -32650,8 +32655,20 @@ fn fragmentMain(input: FragmentInput) -> FragmentOutput {
32650
32655
  let sh0 = pack111110(resolve(uniform.sh0Mins.xyz, uniform.sh0Maxs.xyz, sh0Sample.xyz));
32651
32656
  let alpha = sigmoid(mix(uniform.sh0Mins.w, uniform.sh0Maxs.w, sh0Sample.w));
32652
32657
  #else
32653
- let scale = pack101010(resolveCodebook(scalesSample, &uniform.scales_codebook));
32654
- let sh0 = pack111110(resolveCodebook(sh0Sample.xyz, &uniform.sh0_codebook));
32658
+ let scalesIdx = vec3u(scalesSample * 255.0);
32659
+ let scalesV = vec3f(
32660
+ uniform.scales_codebook[scalesIdx.x >> 2u][scalesIdx.x & 3u],
32661
+ uniform.scales_codebook[scalesIdx.y >> 2u][scalesIdx.y & 3u],
32662
+ uniform.scales_codebook[scalesIdx.z >> 2u][scalesIdx.z & 3u]
32663
+ );
32664
+ let scale = pack101010((scalesV - uniform.scales_codebook[0].x) / (uniform.scales_codebook[63].w - uniform.scales_codebook[0].x));
32665
+ let sh0Idx = vec3u(sh0Sample.xyz * 255.0);
32666
+ let sh0V = vec3f(
32667
+ uniform.sh0_codebook[sh0Idx.x >> 2u][sh0Idx.x & 3u],
32668
+ uniform.sh0_codebook[sh0Idx.y >> 2u][sh0Idx.y & 3u],
32669
+ uniform.sh0_codebook[sh0Idx.z >> 2u][sh0Idx.z & 3u]
32670
+ );
32671
+ let sh0 = pack111110((sh0V - uniform.sh0_codebook[0].x) / (uniform.sh0_codebook[63].w - uniform.sh0_codebook[0].x));
32655
32672
  let alpha = sh0Sample.w;
32656
32673
  #endif
32657
32674
  let qmode = u32(quatsSample.w * 255.0) - 252u;
@@ -32726,7 +32743,13 @@ fn fragmentMain(input: FragmentInput) -> FragmentOutput {
32726
32743
  #ifdef REORDER_V1
32727
32744
  output.color = unpack8888(pack111110(shNSample));
32728
32745
  #else
32729
- output.color = unpack8888(pack111110(resolveCodebook(shNSample, &uniform.shN_codebook)));
32746
+ let shNIdx = vec3u(shNSample * 255.0);
32747
+ let shNV = vec3f(
32748
+ uniform.shN_codebook[shNIdx.x >> 2u][shNIdx.x & 3u],
32749
+ uniform.shN_codebook[shNIdx.y >> 2u][shNIdx.y & 3u],
32750
+ uniform.shN_codebook[shNIdx.z >> 2u][shNIdx.z & 3u]
32751
+ );
32752
+ output.color = unpack8888(pack111110((shNV - uniform.shN_codebook[0].x) / (uniform.shN_codebook[63].w - uniform.shN_codebook[0].x)));
32730
32753
  #endif
32731
32754
  return output;
32732
32755
  }
@@ -32753,17 +32776,7 @@ fn unpack101010(v: u32) -> vec3f {
32753
32776
  }
32754
32777
  fn unpack111110(v: u32) -> vec3f {
32755
32778
  return vec3f((vec3u(v) >> vec3u(21u, 10u, 0u)) & vec3u(0x7ffu, 0x7ffu, 0x3ffu)) / vec3f(2047.0, 2047.0, 1023.0);
32756
- }
32757
- fn resolveCodebook(s: vec3f, codebook: ptr<uniform, array<vec4f, 64>>) -> vec3f {
32758
- let idx = vec3u(s * 255.0);
32759
- let v = vec3f(
32760
- codebook[idx.x >> 2u][idx.x & 3u],
32761
- codebook[idx.y >> 2u][idx.y & 3u],
32762
- codebook[idx.z >> 2u][idx.z & 3u]
32763
- );
32764
- return (v - codebook[0].x) / (codebook[63].w - codebook[0].x);
32765
- }
32766
- `;
32779
+ }`;
32767
32780
 
32768
32781
  var glslSogCentersPS = `
32769
32782
  #include "gsplatPackingPS"
@@ -36688,7 +36701,6 @@ uniform ivec3 clusterCellsDot;
36688
36701
  uniform ivec3 clusterCellsMax;
36689
36702
  uniform vec2 shadowAtlasParams;
36690
36703
  struct ClusterLightData {
36691
- uint flags;
36692
36704
  vec3 halfWidth;
36693
36705
  bool isSpot;
36694
36706
  vec3 halfHeight;
@@ -36703,10 +36715,8 @@ struct ClusterLightData {
36703
36715
  float range;
36704
36716
  vec4 cookieChannelMask;
36705
36717
  float biasesData;
36706
- uint colorBFlagsData;
36707
36718
  float shadowBias;
36708
36719
  float shadowNormalBias;
36709
- float anglesData;
36710
36720
  float innerConeAngleCos;
36711
36721
  float outerConeAngleCos;
36712
36722
  float cookieIntensity;
@@ -36714,35 +36724,38 @@ struct ClusterLightData {
36714
36724
  bool isLightmapped;
36715
36725
  };
36716
36726
  mat4 lightProjectionMatrix;
36727
+ uint clusterLightData_flags;
36728
+ float clusterLightData_anglesData;
36729
+ uint clusterLightData_colorBFlagsData;
36717
36730
  vec4 sampleLightTextureF(const ClusterLightData clusterLightData, int index) {
36718
36731
  return texelFetch(lightsTexture, ivec2(index, clusterLightData.lightIndex), 0);
36719
36732
  }
36720
36733
  void decodeClusterLightCore(inout ClusterLightData clusterLightData, int lightIndex) {
36721
36734
  clusterLightData.lightIndex = lightIndex;
36722
36735
  vec4 halfData = sampleLightTextureF(clusterLightData, {CLUSTER_TEXTURE_COLOR_ANGLES_BIAS});
36723
- clusterLightData.anglesData = halfData.z;
36736
+ clusterLightData_anglesData = halfData.z;
36724
36737
  clusterLightData.biasesData = halfData.w;
36725
- clusterLightData.colorBFlagsData = floatBitsToUint(halfData.y);
36738
+ clusterLightData_colorBFlagsData = floatBitsToUint(halfData.y);
36726
36739
  vec2 colorRG = unpackHalf2x16(floatBitsToUint(halfData.x));
36727
- vec2 colorB_flags = unpackHalf2x16(clusterLightData.colorBFlagsData);
36740
+ vec2 colorB_flags = unpackHalf2x16(clusterLightData_colorBFlagsData);
36728
36741
  clusterLightData.color = vec3(colorRG, colorB_flags.x) * {LIGHT_COLOR_DIVIDER};
36729
36742
  vec4 lightPosRange = sampleLightTextureF(clusterLightData, {CLUSTER_TEXTURE_POSITION_RANGE});
36730
36743
  clusterLightData.position = lightPosRange.xyz;
36731
36744
  clusterLightData.range = lightPosRange.w;
36732
36745
  vec4 lightDir_Flags = sampleLightTextureF(clusterLightData, {CLUSTER_TEXTURE_DIRECTION_FLAGS});
36733
36746
  clusterLightData.direction = lightDir_Flags.xyz;
36734
- clusterLightData.flags = floatBitsToUint(lightDir_Flags.w);
36735
- clusterLightData.isSpot = (clusterLightData.flags & (1u << 30u)) != 0u;
36736
- clusterLightData.shape = (clusterLightData.flags >> 28u) & 0x3u;
36737
- clusterLightData.falloffModeLinear = (clusterLightData.flags & (1u << 27u)) == 0u;
36738
- clusterLightData.shadowIntensity = float((clusterLightData.flags >> 0u) & 0xFFu) / 255.0;
36739
- clusterLightData.cookieIntensity = float((clusterLightData.flags >> 8u) & 0xFFu) / 255.0;
36740
- clusterLightData.isDynamic = (clusterLightData.flags & (1u << 22u)) != 0u;
36741
- clusterLightData.isLightmapped = (clusterLightData.flags & (1u << 21u)) != 0u;
36747
+ clusterLightData_flags = floatBitsToUint(lightDir_Flags.w);
36748
+ clusterLightData.isSpot = (clusterLightData_flags & (1u << 30u)) != 0u;
36749
+ clusterLightData.shape = (clusterLightData_flags >> 28u) & 0x3u;
36750
+ clusterLightData.falloffModeLinear = (clusterLightData_flags & (1u << 27u)) == 0u;
36751
+ clusterLightData.shadowIntensity = float((clusterLightData_flags >> 0u) & 0xFFu) / 255.0;
36752
+ clusterLightData.cookieIntensity = float((clusterLightData_flags >> 8u) & 0xFFu) / 255.0;
36753
+ clusterLightData.isDynamic = (clusterLightData_flags & (1u << 22u)) != 0u;
36754
+ clusterLightData.isLightmapped = (clusterLightData_flags & (1u << 21u)) != 0u;
36742
36755
  }
36743
36756
  void decodeClusterLightSpot(inout ClusterLightData clusterLightData) {
36744
- uint angleFlags = (clusterLightData.colorBFlagsData >> 16u) & 0xFFFFu;
36745
- vec2 angleValues = unpackHalf2x16(floatBitsToUint(clusterLightData.anglesData));
36757
+ uint angleFlags = (clusterLightData_colorBFlagsData >> 16u) & 0xFFFFu;
36758
+ vec2 angleValues = unpackHalf2x16(floatBitsToUint(clusterLightData_anglesData));
36746
36759
  float innerVal = angleValues.x;
36747
36760
  float outerVal = angleValues.y;
36748
36761
  float innerIsVersine = float(angleFlags & 1u);
@@ -36772,7 +36785,7 @@ void decodeClusterLightShadowData(inout ClusterLightData clusterLightData) {
36772
36785
  clusterLightData.shadowNormalBias = biases.y;
36773
36786
  }
36774
36787
  void decodeClusterLightCookieData(inout ClusterLightData clusterLightData) {
36775
- uint cookieFlags = (clusterLightData.flags >> 23u) & 0x0Fu;
36788
+ uint cookieFlags = (clusterLightData_flags >> 23u) & 0x0Fu;
36776
36789
  clusterLightData.cookieChannelMask = vec4(uvec4(cookieFlags) & uvec4(1u, 2u, 4u, 8u));
36777
36790
  clusterLightData.cookieChannelMask = step(1.0, clusterLightData.cookieChannelMask);
36778
36791
  }
@@ -54690,9 +54703,9 @@ class GSplatComponent extends Component {
54690
54703
  }
54691
54704
  getInstanceTexture(name) {
54692
54705
  if (!this._placement) {
54693
- return undefined;
54706
+ return null;
54694
54707
  }
54695
- return this._placement.getInstanceTexture(name, this.system.app.graphicsDevice);
54708
+ return this._placement.getInstanceTexture(name, this.system.app.graphicsDevice) ?? null;
54696
54709
  }
54697
54710
  _onGSplatAssetAdded() {
54698
54711
  if (!this._assetReference.asset) {
@@ -68451,7 +68464,7 @@ class CameraFrame {
68451
68464
  }
68452
68465
 
68453
68466
  const tmpV1$1 = new Vec3();
68454
- const rotation$3 = new Quat();
68467
+ const rotation$4 = new Quat();
68455
68468
  class Pose {
68456
68469
  copy(other) {
68457
68470
  return this.set(other.position, other.angles, other.distance);
@@ -68502,7 +68515,7 @@ class Pose {
68502
68515
  return this;
68503
68516
  }
68504
68517
  getFocus(out) {
68505
- return rotation$3.setFromEulerAngles(this.angles).transformVector(Vec3.FORWARD, out).mulScalar(this.distance).add(this.position);
68518
+ return rotation$4.setFromEulerAngles(this.angles).transformVector(Vec3.FORWARD, out).mulScalar(this.distance).add(this.position);
68506
68519
  }
68507
68520
  constructor(position = Vec3.ZERO, angles = Vec3.ZERO, distance = 0){
68508
68521
  this.position = new Vec3();
@@ -69081,12 +69094,12 @@ GamepadSource.buttonCode = BUTTON_CODES;
69081
69094
 
69082
69095
  const damp$1 = (damping, dt)=>1 - Math.pow(damping, dt * 1000);
69083
69096
 
69084
- const offset$1 = new Vec3();
69097
+ const offset$2 = new Vec3();
69085
69098
  const angles$1 = new Vec3();
69086
- const forward = new Vec3();
69087
- const right = new Vec3();
69099
+ const forward$1 = new Vec3();
69100
+ const right$1 = new Vec3();
69088
69101
  const up = new Vec3();
69089
- const rotation$2 = new Quat();
69102
+ const rotation$3 = new Quat();
69090
69103
  let FlyController$1 = class FlyController extends InputController$1 {
69091
69104
  set pitchRange(value) {
69092
69105
  this._targetPose.pitchRange.copy(value);
@@ -69114,15 +69127,15 @@ let FlyController$1 = class FlyController extends InputController$1 {
69114
69127
  update(frame, dt) {
69115
69128
  const { move, rotate } = frame.read();
69116
69129
  this._targetPose.rotate(angles$1.set(-rotate[1], -rotate[0], 0));
69117
- rotation$2.setFromEulerAngles(this._pose.angles);
69118
- rotation$2.transformVector(Vec3.FORWARD, forward);
69119
- rotation$2.transformVector(Vec3.RIGHT, right);
69120
- rotation$2.transformVector(Vec3.UP, up);
69121
- offset$1.set(0, 0, 0);
69122
- offset$1.add(forward.mulScalar(move[2]));
69123
- offset$1.add(right.mulScalar(move[0]));
69124
- offset$1.add(up.mulScalar(move[1]));
69125
- this._targetPose.move(offset$1);
69130
+ rotation$3.setFromEulerAngles(this._pose.angles);
69131
+ rotation$3.transformVector(Vec3.FORWARD, forward$1);
69132
+ rotation$3.transformVector(Vec3.RIGHT, right$1);
69133
+ rotation$3.transformVector(Vec3.UP, up);
69134
+ offset$2.set(0, 0, 0);
69135
+ offset$2.add(forward$1.mulScalar(move[2]));
69136
+ offset$2.add(right$1.mulScalar(move[0]));
69137
+ offset$2.add(up.mulScalar(move[1]));
69138
+ this._targetPose.move(offset$2);
69126
69139
  return this._pose.lerp(this._pose, this._targetPose, damp$1(this.moveDamping, dt), damp$1(this.rotateDamping, dt));
69127
69140
  }
69128
69141
  destroy() {
@@ -69134,9 +69147,9 @@ let FlyController$1 = class FlyController extends InputController$1 {
69134
69147
  };
69135
69148
 
69136
69149
  const dir = new Vec3();
69137
- const offset = new Vec3();
69150
+ const offset$1 = new Vec3();
69138
69151
  const angles = new Vec3();
69139
- const rotation$1 = new Quat();
69152
+ const rotation$2 = new Quat();
69140
69153
  let OrbitController$1 = class OrbitController extends InputController$1 {
69141
69154
  set pitchRange(range) {
69142
69155
  this._targetRootPose.pitchRange.copy(range);
@@ -69173,16 +69186,16 @@ let OrbitController$1 = class OrbitController extends InputController$1 {
69173
69186
  }
69174
69187
  update(frame, dt) {
69175
69188
  const { move, rotate } = frame.read();
69176
- offset.set(move[0], move[1], 0);
69177
- rotation$1.setFromEulerAngles(this._rootPose.angles).transformVector(offset, offset);
69178
- this._targetRootPose.move(offset);
69189
+ offset$1.set(move[0], move[1], 0);
69190
+ rotation$2.setFromEulerAngles(this._rootPose.angles).transformVector(offset$1, offset$1);
69191
+ this._targetRootPose.move(offset$1);
69179
69192
  const { z: dist } = this._targetChildPose.position;
69180
- this._targetChildPose.move(offset.set(0, 0, dist * (1 + move[2]) - dist));
69193
+ this._targetChildPose.move(offset$1.set(0, 0, dist * (1 + move[2]) - dist));
69181
69194
  this._targetRootPose.rotate(angles.set(-rotate[1], -rotate[0], 0));
69182
69195
  this._rootPose.lerp(this._rootPose, this._targetRootPose, damp$1(this.moveDamping, dt), damp$1(this.rotateDamping, dt), 1);
69183
69196
  this._childPose.lerp(this._childPose, this._targetChildPose, damp$1(this.zoomDamping, dt), 1, 1);
69184
- rotation$1.setFromEulerAngles(this._rootPose.angles).transformVector(this._childPose.position, offset).add(this._rootPose.position);
69185
- return this._pose.set(offset, this._rootPose.angles, this._childPose.position.z);
69197
+ rotation$2.setFromEulerAngles(this._rootPose.angles).transformVector(this._childPose.position, offset$1).add(this._rootPose.position);
69198
+ return this._pose.set(offset$1, this._rootPose.angles, this._childPose.position.z);
69186
69199
  }
69187
69200
  destroy() {
69188
69201
  this.detach();
@@ -69446,12 +69459,12 @@ class Tooltip {
69446
69459
 
69447
69460
  // Initialize the touch joystick for fly mode camera control
69448
69461
  const initJoystick = (dom, events, state) => {
69449
- // Joystick dimensions (matches SCSS: base height=120, stick size=48)
69450
- const joystickHeight = 120;
69451
- const stickSize = 48;
69452
- const stickCenterY = (joystickHeight - stickSize) / 2; // 36px - top position when centered
69453
- const stickCenterX = (joystickHeight - stickSize) / 2; // 36px - left position when centered (for 2D mode)
69454
- const maxStickTravel = stickCenterY; // can travel 36px up or down from center
69462
+ // Joystick dimensions (matches SCSS: base height=100, stick size=40)
69463
+ const joystickHeight = 100;
69464
+ const stickSize = 40;
69465
+ const stickCenterY = (joystickHeight - stickSize) / 2; // 30px - top position when centered
69466
+ const stickCenterX = (joystickHeight - stickSize) / 2; // 30px - left position when centered (for 2D mode)
69467
+ const maxStickTravel = stickCenterY; // can travel 30px up or down from center
69455
69468
  // Fixed joystick position (bottom-left corner with safe area)
69456
69469
  const joystickFixedX = 70;
69457
69470
  const joystickFixedY = () => window.innerHeight - 140;
@@ -69465,7 +69478,7 @@ const initJoystick = (dom, events, state) => {
69465
69478
  let lastTapTime = 0;
69466
69479
  // Update joystick visibility based on camera mode and input mode
69467
69480
  const updateJoystickVisibility = () => {
69468
- if ((state.cameraMode === 'fly' || state.cameraMode === 'fps') && state.inputMode === 'touch') {
69481
+ if ((state.cameraMode === 'fly' || state.cameraMode === 'fps') && state.inputMode === 'touch' && state.touchControlScheme === 'joystick') {
69469
69482
  dom.joystickBase.classList.remove('hidden');
69470
69483
  dom.joystickBase.classList.toggle('mode-2d', joystickMode === '2d');
69471
69484
  dom.joystickBase.style.left = `${joystickFixedX}px`;
@@ -69485,6 +69498,7 @@ const initJoystick = (dom, events, state) => {
69485
69498
  };
69486
69499
  events.on('cameraMode:changed', updateJoystickVisibility);
69487
69500
  events.on('inputMode:changed', updateJoystickVisibility);
69501
+ events.on('touchControlScheme:changed', updateJoystickVisibility);
69488
69502
  window.addEventListener('resize', updateJoystickVisibility);
69489
69503
  // Handle joystick touch input directly on the joystick element
69490
69504
  const updateJoystickStick = (clientX, clientY) => {
@@ -69635,6 +69649,9 @@ const initUI = (global) => {
69635
69649
  'settings', 'settingsPanel',
69636
69650
  'orbitCamera', 'flyCamera', 'fpsCamera',
69637
69651
  'hqCheck', 'hqOption', 'lqCheck', 'lqOption',
69652
+ 'touchControlsDivider', 'joystickSchemeRow', 'pinchSchemeRow',
69653
+ 'joystickSchemeCheck', 'joystickSchemeOption', 'pinchSchemeCheck', 'pinchSchemeOption',
69654
+ 'touchFlyJoystick', 'touchFlyPinch',
69638
69655
  'reset', 'frame',
69639
69656
  'loadingText', 'loadingBar',
69640
69657
  'joystickBase', 'joystick',
@@ -69693,9 +69710,17 @@ const initUI = (global) => {
69693
69710
  state.isFullscreen = false;
69694
69711
  }
69695
69712
  };
69713
+ let shouldRestoreFullscreen = false;
69714
+ events.on('restoreFullscreen', () => {
69715
+ shouldRestoreFullscreen = true;
69716
+ });
69696
69717
  if (hasFullscreenAPI) {
69697
69718
  document.addEventListener('fullscreenchange', () => {
69698
69719
  state.isFullscreen = !!document.fullscreenElement;
69720
+ if (!document.fullscreenElement && shouldRestoreFullscreen) {
69721
+ shouldRestoreFullscreen = false;
69722
+ requestFullscreen();
69723
+ }
69699
69724
  });
69700
69725
  }
69701
69726
  dom.enterFullscreen.addEventListener('click', requestFullscreen);
@@ -69726,10 +69751,36 @@ const initUI = (global) => {
69726
69751
  dom.hqCheck.classList[state.hqMode ? 'add' : 'remove']('active');
69727
69752
  dom.lqCheck.classList[state.hqMode ? 'remove' : 'add']('active');
69728
69753
  };
69729
- events.on('hqMode:changed', (value) => {
69754
+ events.on('hqMode:changed', () => {
69730
69755
  updateHQ();
69756
+ localStorage.setItem('hqMode', String(state.hqMode));
69731
69757
  });
69732
69758
  updateHQ();
69759
+ // Touch control scheme toggle (only visible on touch devices)
69760
+ dom.joystickSchemeOption.addEventListener('click', () => {
69761
+ state.touchControlScheme = 'joystick';
69762
+ });
69763
+ dom.pinchSchemeOption.addEventListener('click', () => {
69764
+ state.touchControlScheme = 'pinch';
69765
+ });
69766
+ const updateTouchControlScheme = () => {
69767
+ const isJoystick = state.touchControlScheme === 'joystick';
69768
+ dom.joystickSchemeCheck.classList.toggle('active', isJoystick);
69769
+ dom.pinchSchemeCheck.classList.toggle('active', !isJoystick);
69770
+ dom.touchFlyJoystick.classList.toggle('hidden', !isJoystick);
69771
+ dom.touchFlyPinch.classList.toggle('hidden', isJoystick);
69772
+ localStorage.setItem('touchControlScheme', state.touchControlScheme);
69773
+ };
69774
+ const updateTouchControlsVisibility = () => {
69775
+ const isTouch = state.inputMode === 'touch';
69776
+ dom.touchControlsDivider.classList.toggle('hidden', !isTouch);
69777
+ dom.joystickSchemeRow.classList.toggle('hidden', !isTouch);
69778
+ dom.pinchSchemeRow.classList.toggle('hidden', !isTouch);
69779
+ };
69780
+ events.on('touchControlScheme:changed', updateTouchControlScheme);
69781
+ events.on('inputMode:changed', updateTouchControlsVisibility);
69782
+ updateTouchControlScheme();
69783
+ updateTouchControlsVisibility();
69733
69784
  // AR/VR
69734
69785
  const arChanged = () => dom.arMode.classList[state.hasAR ? 'remove' : 'add']('hidden');
69735
69786
  const vrChanged = () => dom.vrMode.classList[state.hasVR ? 'remove' : 'add']('hidden');
@@ -70848,7 +70899,7 @@ class AnimController {
70848
70899
  }
70849
70900
  }
70850
70901
 
70851
- const rotation = new Quat();
70902
+ const rotation$1 = new Quat();
70852
70903
  const avec = new Vec3();
70853
70904
  const bvec = new Vec3();
70854
70905
  class Camera {
@@ -70883,7 +70934,7 @@ class Camera {
70883
70934
  vecToAngles(this.angles, dir);
70884
70935
  }
70885
70936
  calcFocusPoint(result) {
70886
- rotation.setFromEulerAngles(this.angles)
70937
+ rotation$1.setFromEulerAngles(this.angles)
70887
70938
  .transformVector(Vec3.FORWARD, result)
70888
70939
  .mulScalar(this.distance)
70889
70940
  .add(this.position);
@@ -70894,7 +70945,7 @@ class Camera {
70894
70945
  const CAMERA_RADIUS = 0.2;
70895
70946
  const p$1 = new Pose();
70896
70947
  /** Pre-allocated push-out vector for sphere collision */
70897
- const pushOut$1 = { x: 0, y: 0, z: 0 };
70948
+ const pushOut = { x: 0, y: 0, z: 0 };
70898
70949
  class FlyController {
70899
70950
  controller;
70900
70951
  /** Optional voxel collider for sphere collision with sliding */
@@ -70924,19 +70975,19 @@ class FlyController {
70924
70975
  const tvx = -target.position.x;
70925
70976
  const tvy = -target.position.y;
70926
70977
  const tvz = target.position.z;
70927
- if (this.collider.querySphere(tvx, tvy, tvz, CAMERA_RADIUS, pushOut$1)) {
70928
- target.position.x += -pushOut$1.x;
70929
- target.position.y += -pushOut$1.y;
70930
- target.position.z += pushOut$1.z;
70978
+ if (this.collider.querySphere(tvx, tvy, tvz, CAMERA_RADIUS, pushOut)) {
70979
+ target.position.x += -pushOut.x;
70980
+ target.position.y += -pushOut.y;
70981
+ target.position.z += pushOut.z;
70931
70982
  }
70932
70983
  // Now resolve collision on the interpolated pose (_pose).
70933
70984
  const vx = -pose.position.x;
70934
70985
  const vy = -pose.position.y;
70935
70986
  const vz = pose.position.z;
70936
- if (this.collider.querySphere(vx, vy, vz, CAMERA_RADIUS, pushOut$1)) {
70937
- pose.position.x += -pushOut$1.x;
70938
- pose.position.y += -pushOut$1.y;
70939
- pose.position.z += pushOut$1.z;
70987
+ if (this.collider.querySphere(vx, vy, vz, CAMERA_RADIUS, pushOut)) {
70988
+ pose.position.x += -pushOut.x;
70989
+ pose.position.y += -pushOut.y;
70990
+ pose.position.z += pushOut.z;
70940
70991
  }
70941
70992
  }
70942
70993
  camera.position.copy(pose.position);
@@ -70949,7 +71000,13 @@ class FlyController {
70949
71000
  }
70950
71001
 
70951
71002
  /** Pre-allocated push-out vector for capsule collision */
70952
- const pushOut = { x: 0, y: 0, z: 0 };
71003
+ const out = { x: 0, y: 0, z: 0 };
71004
+ const v = new Vec3();
71005
+ const d = new Vec3();
71006
+ const forward = new Vec3();
71007
+ const right = new Vec3();
71008
+ const offset = new Vec3();
71009
+ const rotation = new Quat();
70953
71010
  /**
70954
71011
  * First-person shooter style camera controller with gravity and capsule collision.
70955
71012
  *
@@ -70958,97 +71015,102 @@ const pushOut = { x: 0, y: 0, z: 0 };
70958
71015
  * voxel grid. The camera is positioned at eye height within the capsule.
70959
71016
  */
70960
71017
  class FpsController {
70961
- /** Optional voxel collider for capsule collision with sliding */
71018
+ /**
71019
+ * Optional voxel collider for capsule collision with sliding
71020
+ */
70962
71021
  collider = null;
70963
- /** Total capsule height in meters (default: human proportion) */
71022
+ /**
71023
+ * Total capsule height in meters (default: human proportion)
71024
+ */
70964
71025
  capsuleHeight = 1.8;
70965
- /** Capsule radius in meters */
71026
+ /**
71027
+ * Capsule radius in meters
71028
+ */
70966
71029
  capsuleRadius = 0.3;
70967
- /** Camera height from the bottom of the capsule in meters */
71030
+ /**
71031
+ * Camera height from the bottom of the capsule in meters
71032
+ */
70968
71033
  eyeHeight = 1.6;
70969
- /** Gravity acceleration in m/s^2 */
71034
+ /**
71035
+ * Gravity acceleration in m/s^2
71036
+ */
70970
71037
  gravity = 9.8;
70971
- /** Jump velocity in m/s */
71038
+ /**
71039
+ * Jump velocity in m/s
71040
+ */
70972
71041
  jumpSpeed = 5;
70973
- /** Movement damping factor (0 = no damping, 1 = full damping) */
71042
+ /**
71043
+ * Movement speed in m/s when grounded
71044
+ */
71045
+ moveGroundSpeed = 10;
71046
+ /**
71047
+ * Movement speed in m/s when in the air (for air control)
71048
+ */
71049
+ moveAirSpeed = 1;
71050
+ /**
71051
+ * Movement damping factor (0 = no damping, 1 = full damping)
71052
+ */
70974
71053
  moveDamping = 0.97;
70975
- /** Rotation damping factor (0 = no damping, 1 = full damping) */
71054
+ /**
71055
+ * Rotation damping factor (0 = no damping, 1 = full damping)
71056
+ */
70976
71057
  rotateDamping = 0.97;
70977
- // Target state (where input drives)
70978
- _targetPosition = new Vec3();
70979
- _targetYaw = 0;
70980
- _targetPitch = 0;
70981
- // Smoothed state (lerps toward target)
71058
+ /**
71059
+ * Velocity damping factor when grounded (0 = no damping, 1 = full damping)
71060
+ */
71061
+ velocityDampingGround = 0.99;
71062
+ /**
71063
+ * Velocity damping factor when in the air (0 = no damping, 1 = full damping)
71064
+ */
71065
+ velocityDampingAir = 0.99925;
70982
71066
  _position = new Vec3();
70983
- _yaw = 0;
70984
- _pitch = 0;
70985
- // Vertical velocity for gravity
70986
- _velocityY = 0;
70987
- // Whether the capsule is resting on the ground
70988
- _onGround = false;
71067
+ _angles = new Vec3();
71068
+ _velocity = new Vec3();
71069
+ _grounded = false;
71070
+ _jumping = false;
70989
71071
  onEnter(camera) {
70990
- this._position.copy(camera.position);
70991
- this._targetPosition.copy(camera.position);
70992
- // angles.x = pitch, angles.y = yaw
70993
- this._pitch = camera.angles.x;
70994
- this._targetPitch = camera.angles.x;
70995
- this._yaw = camera.angles.y;
70996
- this._targetYaw = camera.angles.y;
70997
- this._velocityY = 0;
70998
- this._onGround = false;
71072
+ this.goto(camera);
71073
+ if (this.collider) {
71074
+ this._checkCollision(this._position, d);
71075
+ if (d.y > 0) {
71076
+ this._grounded = true;
71077
+ this._velocity.y = 0;
71078
+ }
71079
+ }
70999
71080
  }
71000
71081
  update(deltaTime, inputFrame, camera) {
71001
71082
  const { move, rotate } = inputFrame.read();
71002
- // --- Rotation ---
71003
- this._targetYaw -= rotate[0];
71004
- this._targetPitch = math.clamp(this._targetPitch - rotate[1], -90, 90);
71005
- const rotateLerp = damp(this.rotateDamping, deltaTime);
71006
- this._yaw = math.lerpAngle(this._yaw, this._targetYaw, rotateLerp);
71007
- this._pitch = math.lerp(this._pitch, this._targetPitch, rotateLerp);
71008
- // Normalize yaw to prevent floating-point drift over long sessions.
71009
- // Shift both values by the same multiple of 360 to preserve their delta.
71010
- const yawOffset = Math.round(this._yaw / 360) * 360;
71011
- if (yawOffset !== 0) {
71012
- this._yaw -= yawOffset;
71013
- this._targetYaw -= yawOffset;
71014
- }
71015
- // --- Horizontal movement ---
71016
- // Compute forward/right from yaw only (ignore pitch for movement)
71017
- const yawRad = this._targetYaw * math.DEG_TO_RAD;
71018
- const sinYaw = Math.sin(yawRad);
71019
- const cosYaw = Math.cos(yawRad);
71020
- // PlayCanvas convention: forward = -Z, right = +X
71021
- const forwardX = -sinYaw;
71022
- const forwardZ = -cosYaw;
71023
- const rightX = cosYaw;
71024
- const rightZ = -sinYaw;
71025
- const moveLerp = damp(this.moveDamping, deltaTime);
71026
- this._targetPosition.x += rightX * move[0] + forwardX * move[2];
71027
- this._targetPosition.z += rightZ * move[0] + forwardZ * move[2];
71028
- // --- Jump ---
71029
- if (move[1] > 0 && this._onGround) {
71030
- this._velocityY = this.jumpSpeed;
71031
- this._onGround = false;
71083
+ // jump
71084
+ if (this._velocity.y < 0) {
71085
+ this._jumping = false;
71032
71086
  }
71033
- // --- Gravity ---
71034
- this._velocityY -= this.gravity * deltaTime;
71035
- this._targetPosition.y += this._velocityY * deltaTime;
71036
- // --- Capsule collision on target position ---
71037
- if (this.collider) {
71038
- this._resolveCapsuleCollision(this._targetPosition, true);
71039
- }
71040
- // --- Smooth horizontal position toward target ---
71041
- this._position.x = math.lerp(this._position.x, this._targetPosition.x, moveLerp);
71042
- this._position.z = math.lerp(this._position.z, this._targetPosition.z, moveLerp);
71043
- // No smoothing on Y for crisp ground contact
71044
- this._position.y = this._targetPosition.y;
71045
- // --- Capsule collision on smoothed position ---
71046
- if (this.collider) {
71047
- this._resolveCapsuleCollision(this._position, false);
71087
+ if (move[1] && !this._jumping && this._grounded) {
71088
+ this._jumping = true;
71089
+ this._velocity.y = this.jumpSpeed;
71090
+ this._grounded = false;
71048
71091
  }
71049
- // --- Output to camera ---
71092
+ // gravity
71093
+ this._velocity.y -= this.gravity * deltaTime;
71094
+ // rotate
71095
+ this._angles.add(v.set(-rotate[1], -rotate[0], 0));
71096
+ this._angles.x = math.clamp(this._angles.x, -90, 90);
71097
+ // move
71098
+ rotation.setFromEulerAngles(0, this._angles.y, 0);
71099
+ rotation.transformVector(Vec3.FORWARD, forward);
71100
+ rotation.transformVector(Vec3.RIGHT, right);
71101
+ offset.set(0, 0, 0);
71102
+ offset.add(forward.mulScalar(move[2]));
71103
+ offset.add(right.mulScalar(move[0]));
71104
+ this._velocity.add(offset.mulScalar(this._grounded ? this.moveGroundSpeed : this.moveAirSpeed));
71105
+ const alpha = damp(this._grounded ? this.velocityDampingGround : this.velocityDampingAir, deltaTime);
71106
+ this._velocity.x = math.lerp(this._velocity.x, 0, alpha);
71107
+ this._velocity.z = math.lerp(this._velocity.z, 0, alpha);
71108
+ this._position.add(v.copy(this._velocity).mulScalar(deltaTime));
71109
+ // collision check
71110
+ this._checkCollision(this._position, d);
71111
+ // update camera
71050
71112
  camera.position.copy(this._position);
71051
- camera.angles.set(this._pitch, this._yaw, 0);
71113
+ camera.angles.set(this._angles.x, this._angles.y, 0);
71052
71114
  }
71053
71115
  onExit(_camera) {
71054
71116
  // nothing to clean up
@@ -71059,54 +71121,48 @@ class FpsController {
71059
71121
  * @param camera - The camera state to jump to.
71060
71122
  */
71061
71123
  goto(camera) {
71124
+ // position
71062
71125
  this._position.copy(camera.position);
71063
- this._targetPosition.copy(camera.position);
71064
- this._pitch = camera.angles.x;
71065
- this._targetPitch = camera.angles.x;
71066
- this._yaw = camera.angles.y;
71067
- this._targetYaw = camera.angles.y;
71068
- this._velocityY = 0;
71069
- this._onGround = false;
71126
+ // angles (clamp pitch to avoid gimbal lock)
71127
+ this._angles.set(camera.angles.x, camera.angles.y, 0);
71128
+ // reset velocity and state
71129
+ this._velocity.set(0, 0, 0);
71130
+ this._grounded = false;
71131
+ this._jumping = false;
71070
71132
  }
71071
71133
  /**
71072
- * Resolve capsule collision for a given eye position, modifying it in place.
71073
- * Converts from PlayCanvas space to voxel space, queries the capsule, and
71074
- * applies the push-out vector back to PlayCanvas space.
71134
+ * Check for collision and apply displacement to the position.
71075
71135
  *
71076
- * @param eyePos - Eye position to resolve (modified in place).
71077
- * @param isTarget - Whether this is the target position (updates velocity on ground contact).
71136
+ * @param pos - eye position in playcanvas world space
71137
+ * @param disp - pre-allocated vector to receive the collision push-out displacement
71138
+ * @returns - the displaced position (same as input position vector for chaining)
71078
71139
  */
71079
- _resolveCapsuleCollision(eyePos, isTarget) {
71080
- // Derive capsule center from eye position in PlayCanvas space:
71140
+ _checkCollision(pos, disp) {
71141
+ // derive capsule center from eye position in PlayCanvas space:
71081
71142
  // bottom of capsule = eyePos.y - eyeHeight
71082
71143
  // capsule center = eyePos.y - eyeHeight + capsuleHeight / 2
71083
- const capsuleCenterPCY = eyePos.y - this.eyeHeight + this.capsuleHeight * 0.5;
71084
- const halfHeight = this.capsuleHeight * 0.5 - this.capsuleRadius;
71085
- // Convert to voxel space (negate X, negate Y, keep Z)
71086
- const vx = -eyePos.x;
71087
- const vy = -capsuleCenterPCY;
71088
- const vz = eyePos.z;
71089
- if (this.collider.queryCapsule(vx, vy, vz, halfHeight, this.capsuleRadius, pushOut)) {
71090
- // Convert push-out back to PlayCanvas space
71091
- const pushPCX = -pushOut.x;
71092
- const pushPCY = -pushOut.y;
71093
- const pushPCZ = pushOut.z;
71094
- eyePos.x += pushPCX;
71095
- // Push-out applies to capsule center; eye moves by the same amount
71096
- eyePos.y += pushPCY;
71097
- eyePos.z += pushPCZ;
71098
- // Ground detection: if pushed upward and falling, cancel downward velocity
71099
- if (isTarget) {
71100
- if (pushPCY > 0 && this._velocityY < 0) {
71101
- this._velocityY = 0;
71102
- this._onGround = true;
71103
- }
71104
- // Ceiling detection: if pushed downward and rising, cancel upward velocity
71105
- if (pushPCY < 0 && this._velocityY > 0) {
71106
- this._velocityY = 0;
71107
- }
71144
+ const center = pos.y - this.eyeHeight + this.capsuleHeight * 0.5;
71145
+ const half = this.capsuleHeight * 0.5 - this.capsuleRadius;
71146
+ // convert to voxel space (negate X, negate Y, keep Z)
71147
+ const vx = -pos.x;
71148
+ const vy = -center;
71149
+ const vz = pos.z;
71150
+ if (this.collider.queryCapsule(vx, vy, vz, half, this.capsuleRadius, out)) {
71151
+ // push out vector to playcanvas space
71152
+ disp.set(-out.x, -out.y, out.z);
71153
+ // apply displacement
71154
+ pos.add(disp);
71155
+ // ground collision: if pushed upward and falling, cancel downward velocity and set grounded
71156
+ if (disp.y > 0 && this._velocity.y < 0) {
71157
+ this._velocity.y = 0;
71158
+ this._grounded = true;
71159
+ }
71160
+ // ceiling collision: if pushed downward and rising, cancel upward velocity
71161
+ if (disp.y < 0 && this._velocity.y > 0) {
71162
+ this._velocity.y = 0;
71108
71163
  }
71109
71164
  }
71165
+ return disp;
71110
71166
  }
71111
71167
  }
71112
71168
 
@@ -71272,13 +71328,15 @@ class CameraManager {
71272
71328
  }
71273
71329
  }
71274
71330
  break;
71331
+ case 'exitFps':
71332
+ if (state.cameraMode === 'fps') {
71333
+ state.cameraMode = preFpsMode;
71334
+ }
71335
+ break;
71275
71336
  case 'cancel':
71276
71337
  if (state.cameraMode === 'anim') {
71277
71338
  state.cameraMode = fromMode;
71278
71339
  }
71279
- else if (state.cameraMode === 'fps') {
71280
- state.cameraMode = preFpsMode;
71281
- }
71282
71340
  break;
71283
71341
  case 'interrupt':
71284
71342
  if (state.cameraMode === 'anim') {
@@ -71499,6 +71557,7 @@ const tmpV1 = new Vec3();
71499
71557
  const tmpV2 = new Vec3();
71500
71558
  const mouseRotate = new Vec3();
71501
71559
  const flyMove = new Vec3();
71560
+ const flyTouchPan = new Vec3();
71502
71561
  const pinchMove = new Vec3();
71503
71562
  const orbitRotate = new Vec3();
71504
71563
  const flyRotate = new Vec3();
@@ -71577,9 +71636,16 @@ class InputController {
71577
71636
  move: [0, 0, 0],
71578
71637
  rotate: [0, 0, 0]
71579
71638
  });
71580
- // Touch joystick input values (-1 to 1)
71581
- _touchJoystickX = 0; // negative = left, positive = right
71582
- _touchJoystickY = 0; // negative = forward, positive = backward
71639
+ // Touch joystick input values [x, y] (-1 to 1)
71640
+ _touchJoystick = [0, 0];
71641
+ // Accumulated forward/backward velocity from pinch gesture (-1 to 1)
71642
+ _pinchVelocity = 0;
71643
+ // Accumulated strafe/vertical velocity from two-finger pan [x, y] (-1 to 1)
71644
+ _panVelocity = [0, 0];
71645
+ // Sensitivity for pinch delta → velocity conversion
71646
+ pinchVelocitySensitivity = 0.006;
71647
+ // Sensitivity for two-finger pan delta → velocity conversion
71648
+ panVelocitySensitivity = 0.005;
71583
71649
  // this gets overridden by the viewer based on scene size
71584
71650
  moveSpeed = 4;
71585
71651
  orbitSpeed = 18;
@@ -71593,8 +71659,8 @@ class InputController {
71593
71659
  this._orbitInput.attach(canvas);
71594
71660
  // Listen for joystick input from the UI (touch joystick element)
71595
71661
  events.on('joystickInput', (value) => {
71596
- this._touchJoystickX = value.x;
71597
- this._touchJoystickY = value.y;
71662
+ this._touchJoystick[0] = value.x;
71663
+ this._touchJoystick[1] = value.y;
71598
71664
  });
71599
71665
  this.global = global;
71600
71666
  // Generate input events
@@ -71645,48 +71711,97 @@ class InputController {
71645
71711
  state.inputMode = event.pointerType === 'touch' ? 'touch' : 'desktop';
71646
71712
  });
71647
71713
  });
71714
+ let recentlyExitedFps = false;
71648
71715
  // handle keyboard events
71649
71716
  window.addEventListener('keydown', (event) => {
71650
71717
  if (event.key === 'Escape') {
71651
- events.fire('inputEvent', 'cancel', event);
71718
+ if (recentlyExitedFps) ;
71719
+ else if (state.cameraMode === 'fps') {
71720
+ events.fire('inputEvent', 'exitFps', event);
71721
+ }
71722
+ else {
71723
+ events.fire('inputEvent', 'cancel', event);
71724
+ }
71652
71725
  }
71653
- else if (state.cameraMode !== 'fps' && !event.ctrlKey && !event.altKey && !event.metaKey) {
71726
+ else if (!event.ctrlKey && !event.altKey && !event.metaKey) {
71654
71727
  switch (event.key) {
71655
- case 'f':
71656
- events.fire('inputEvent', 'frame', event);
71728
+ case '1':
71729
+ state.cameraMode = 'orbit';
71657
71730
  break;
71658
- case 'r':
71659
- events.fire('inputEvent', 'reset', event);
71731
+ case '2':
71732
+ state.cameraMode = 'fly';
71660
71733
  break;
71661
- case ' ':
71662
- events.fire('inputEvent', 'playPause', event);
71734
+ case '3':
71735
+ events.fire('inputEvent', 'toggleFps');
71663
71736
  break;
71664
71737
  }
71738
+ if (state.cameraMode !== 'fps') {
71739
+ switch (event.key) {
71740
+ case 'f':
71741
+ events.fire('inputEvent', 'frame', event);
71742
+ break;
71743
+ case 'r':
71744
+ events.fire('inputEvent', 'reset', event);
71745
+ break;
71746
+ case ' ':
71747
+ events.fire('inputEvent', 'playPause', event);
71748
+ break;
71749
+ }
71750
+ }
71665
71751
  }
71666
71752
  });
71753
+ // Lock/unlock Escape key in fullscreen to prevent the browser from
71754
+ // exiting both pointer lock and fullscreen on the same Escape press.
71755
+ const lockEscape = () => {
71756
+ if ('keyboard' in navigator && 'lock' in navigator.keyboard) {
71757
+ navigator.keyboard.lock(['Escape']).catch(() => { });
71758
+ }
71759
+ };
71760
+ const unlockKeyboard = () => {
71761
+ if ('keyboard' in navigator && 'unlock' in navigator.keyboard) {
71762
+ navigator.keyboard.unlock();
71763
+ }
71764
+ };
71667
71765
  // Pointer lock management for FPS mode on desktop
71668
71766
  events.on('cameraMode:changed', (value, prev) => {
71669
71767
  if (value === 'fps' && state.inputMode === 'desktop') {
71670
71768
  this._desktopInput._pointerLock = true;
71671
71769
  canvas.requestPointerLock();
71770
+ if (state.isFullscreen) {
71771
+ lockEscape();
71772
+ }
71672
71773
  }
71673
71774
  else if (prev === 'fps') {
71775
+ unlockKeyboard();
71674
71776
  this._desktopInput._pointerLock = false;
71675
71777
  if (document.pointerLockElement === canvas) {
71778
+ if (state.isFullscreen) {
71779
+ events.fire('restoreFullscreen');
71780
+ }
71676
71781
  document.exitPointerLock();
71677
71782
  }
71678
71783
  }
71679
71784
  });
71785
+ // Also lock Escape if entering fullscreen while already in FPS mode
71786
+ events.on('isFullscreen:changed', (value) => {
71787
+ if (value && state.cameraMode === 'fps' && state.inputMode === 'desktop') {
71788
+ lockEscape();
71789
+ }
71790
+ });
71680
71791
  document.addEventListener('pointerlockchange', () => {
71681
71792
  if (!document.pointerLockElement && state.cameraMode === 'fps') {
71682
- events.fire('inputEvent', 'cancel');
71793
+ recentlyExitedFps = true;
71794
+ requestAnimationFrame(() => {
71795
+ recentlyExitedFps = false;
71796
+ });
71797
+ events.fire('inputEvent', 'exitFps');
71683
71798
  }
71684
71799
  });
71685
71800
  // Pointer lock request rejected (e.g., no user gesture, document hidden).
71686
71801
  // Revert to avoid being stuck in FPS mode without mouse capture.
71687
71802
  document.addEventListener('pointerlockerror', () => {
71688
71803
  this._desktopInput._pointerLock = false;
71689
- events.fire('inputEvent', 'cancel');
71804
+ events.fire('inputEvent', 'exitFps');
71690
71805
  });
71691
71806
  }
71692
71807
  /**
@@ -71713,6 +71828,22 @@ class InputController {
71713
71828
  this._state.ctrl += key[keyCode.CTRL];
71714
71829
  const isFps = state.cameraMode === 'fps';
71715
71830
  const isFirstPerson = state.cameraMode === 'fly' || isFps;
71831
+ // Accumulate pinch and pan deltas into velocity when using pinch control scheme
71832
+ // pinch[0] = oldDist - newDist: negative when spreading, positive when closing
71833
+ // Spreading = forward → subtract pinch delta
71834
+ if (isFirstPerson && state.touchControlScheme === 'pinch' && this._state.touches > 1) {
71835
+ this._pinchVelocity -= pinch[0] * this.pinchVelocitySensitivity;
71836
+ this._pinchVelocity = math.clamp(this._pinchVelocity, -1, 1.0);
71837
+ this._panVelocity[0] += touch[0] * this.panVelocitySensitivity;
71838
+ this._panVelocity[0] = math.clamp(this._panVelocity[0], -1, 1.0);
71839
+ this._panVelocity[1] += touch[1] * this.panVelocitySensitivity;
71840
+ this._panVelocity[1] = math.clamp(this._panVelocity[1], -1, 1.0);
71841
+ }
71842
+ else if (isFirstPerson && this._state.touches <= 1) {
71843
+ this._pinchVelocity = 0;
71844
+ this._panVelocity[0] = 0;
71845
+ this._panVelocity[1] = 0;
71846
+ }
71716
71847
  if (!isFirstPerson && this._state.axis.length() > 0) {
71717
71848
  events.fire('inputEvent', 'requestFirstPerson');
71718
71849
  }
@@ -71730,7 +71861,10 @@ class InputController {
71730
71861
  keyMove.y = 0;
71731
71862
  }
71732
71863
  keyMove.normalize();
71733
- v.add(keyMove.mulScalar(fly * this.moveSpeed * (this._state.shift ? 4 : this._state.ctrl ? 0.25 : 1) * dt));
71864
+ const shiftMul = isFps ? 2 : 4;
71865
+ const ctrlMul = isFps ? 0.5 : 0.25;
71866
+ const speed = this.moveSpeed * (this._state.shift ? shiftMul : this._state.ctrl ? ctrlMul : 1);
71867
+ v.add(keyMove.mulScalar(fly * speed * dt));
71734
71868
  if (isFps) {
71735
71869
  // Pass jump signal as raw Y; FPS controller uses move[1] > 0 as boolean trigger
71736
71870
  v.y = this._state.jump > 0 ? 1 : 0;
@@ -71750,9 +71884,19 @@ class InputController {
71750
71884
  v.set(0, 0, 0);
71751
71885
  const orbitMove = screenToWorld(camera, touch[0], touch[1], distance);
71752
71886
  v.add(orbitMove.mulScalar(orbit * pan));
71753
- // Use touch joystick values for fly movement (X = strafe, Y = forward/backward)
71754
- flyMove.set(this._touchJoystickX, 0, -this._touchJoystickY);
71755
- v.add(flyMove.mulScalar(fly * this.moveSpeed * dt));
71887
+ if (state.touchControlScheme === 'joystick') {
71888
+ // Use touch joystick values for fly movement (X = strafe, Y = forward/backward)
71889
+ flyMove.set(this._touchJoystick[0], 0, -this._touchJoystick[1]);
71890
+ v.add(flyMove.mulScalar(fly * this.moveSpeed * dt));
71891
+ }
71892
+ else {
71893
+ // Pan velocity → strafe (X) and vertical (Y, fly only — FPS uses gravity)
71894
+ flyTouchPan.set(this._panVelocity[0], isFps ? 0 : -this._panVelocity[1], 0);
71895
+ v.add(flyTouchPan.mulScalar(fly * 1.5 * this.moveSpeed * dt));
71896
+ // Pinch velocity → forward/backward
71897
+ flyMove.set(0, 0, this._pinchVelocity);
71898
+ v.add(flyMove.mulScalar(fly * 1.5 * this.moveSpeed * dt));
71899
+ }
71756
71900
  pinchMove.set(0, 0, pinch[0]);
71757
71901
  v.add(pinchMove.mulScalar(orbit * double * this.pinchSpeed * dt));
71758
71902
  deltas.move.append([v.x, v.y, v.z]);
@@ -71760,9 +71904,8 @@ class InputController {
71760
71904
  v.set(0, 0, 0);
71761
71905
  orbitRotate.set(touch[0], touch[1], 0);
71762
71906
  v.add(orbitRotate.mulScalar(orbit * (1 - pan) * this.orbitSpeed * dt));
71763
- // In fly mode, use any touch for look-around (joystick captures its own touches)
71764
- // Exclude multi-touch (double) to avoid interference with pinch gestures
71765
- // 1.25x sensitivity for touch look-around
71907
+ // In fly mode, use single touch for look-around (inverted direction)
71908
+ // Exclude multi-touch (double) to avoid interference with pinch/strafe gestures
71766
71909
  flyRotate.set(touch[0], touch[1], 0);
71767
71910
  v.add(flyRotate.mulScalar(fly * (1 - double) * this.orbitSpeed * orbitFactor * 1.25 * dt));
71768
71911
  deltas.rotate.append([v.x, v.y, v.z]);
@@ -72210,21 +72353,21 @@ class VoxelDebugOverlay {
72210
72353
  const nodesByteSize = Math.max(nodesData.byteLength, 4);
72211
72354
  this.nodesBuffer = new StorageBuffer(device, nodesByteSize, BUFFERUSAGE_COPY_DST);
72212
72355
  if (nodesData.byteLength > 0) {
72213
- this.nodesBuffer.write(0, nodesData.buffer, nodesData.byteOffset, nodesData.byteLength);
72356
+ this.nodesBuffer.write(0, nodesData, 0, nodesData.length);
72214
72357
  }
72215
72358
  // Upload leaf data as a read-only storage buffer
72216
72359
  const leafDataArr = collider.leafData;
72217
72360
  const leafByteSize = Math.max(leafDataArr.byteLength, 4);
72218
72361
  this.leafDataBuffer = new StorageBuffer(device, leafByteSize, BUFFERUSAGE_COPY_DST);
72219
72362
  if (leafDataArr.byteLength > 0) {
72220
- this.leafDataBuffer.write(0, leafDataArr.buffer, leafDataArr.byteOffset, leafDataArr.byteLength);
72363
+ this.leafDataBuffer.write(0, leafDataArr, 0, leafDataArr.length);
72221
72364
  }
72222
72365
  // Create the initial storage texture (will be resized on first update)
72223
72366
  this.currentWidth = Math.max(device.width, 1);
72224
72367
  this.currentHeight = Math.max(device.height, 1);
72225
72368
  this.storageTexture = this.createStorageTexture(this.currentWidth, this.currentHeight);
72226
72369
  // Create compute shader
72227
- const shader = new Shader(device, {
72370
+ const shaderDefinition = {
72228
72371
  name: 'VoxelDebugOverlay',
72229
72372
  shaderLanguage: SHADERLANGUAGE_WGSL,
72230
72373
  cshader: voxelOverlayWGSL,
@@ -72253,7 +72396,8 @@ class VoxelDebugOverlay {
72253
72396
  new BindStorageBufferFormat('leafData', SHADERSTAGE_COMPUTE, true),
72254
72397
  new BindStorageTextureFormat('outputTexture', PIXELFORMAT_RGBA8, TEXTUREDIMENSION_2D)
72255
72398
  ])
72256
- });
72399
+ };
72400
+ const shader = new Shader(device, shaderDefinition);
72257
72401
  // Create compute instance
72258
72402
  this.compute = new Compute(device, shader, 'VoxelDebugOverlay');
72259
72403
  // Create overlay material with premultiplied alpha blending and a custom
@@ -72481,20 +72625,11 @@ class Viewer {
72481
72625
  wgsl.set('skyboxPS', wgsl.get('skyboxPS').replace('mapRoughnessUv(uv, uniform.mipLevel)', 'uv'));
72482
72626
  // disable auto render, we'll render only when camera changes
72483
72627
  app.autoRender = false;
72484
- // apply camera animation settings
72485
- camera.camera.aspectRatio = graphicsDevice.width / graphicsDevice.height;
72486
72628
  // configure the camera
72487
72629
  this.configureCamera(settings);
72488
72630
  // reconfigure camera when entering/exiting XR
72489
72631
  app.xr.on('start', () => this.configureCamera(settings));
72490
72632
  app.xr.on('end', () => this.configureCamera(settings));
72491
- // handle horizontal fov on canvas resize
72492
- const updateHorizontalFov = () => {
72493
- camera.camera.horizontalFov = graphicsDevice.width > graphicsDevice.height;
72494
- app.renderNextFrame = true;
72495
- };
72496
- graphicsDevice.on('resizecanvas', updateHorizontalFov);
72497
- updateHorizontalFov();
72498
72633
  // construct debug ministats
72499
72634
  if (config.ministats) {
72500
72635
  const options = MiniStats.getDefaultOptions();
@@ -72549,6 +72684,7 @@ class Viewer {
72549
72684
  cameraEntity.setPosition(camera.position);
72550
72685
  cameraEntity.setEulerAngles(camera.angles);
72551
72686
  cameraEntity.camera.fov = camera.fov;
72687
+ cameraEntity.camera.horizontalFov = graphicsDevice.width > graphicsDevice.height;
72552
72688
  // fit clipping planes to bounding box
72553
72689
  const boundRadius = sceneBound.halfExtents.length();
72554
72690
  // calculate the forward distance between the camera to the bound center
@@ -73288,7 +73424,7 @@ class VoxelCollider {
73288
73424
  const distNegZ = cz - vMinZ;
73289
73425
  const distPosZ = vMaxZ - cz;
73290
73426
  const escapeX = distNegX < distPosX ? -(distNegX + radius) : (distPosX + radius);
73291
- const escapeY = distNegY < distPosY ? -(distNegY + radius) : (distPosY + radius);
73427
+ const escapeY = distNegY <= distPosY ? -(distNegY + radius) : (distPosY + radius);
73292
73428
  const escapeZ = distNegZ < distPosZ ? -(distNegZ + radius) : (distPosZ + radius);
73293
73429
  const absX = Math.abs(escapeX);
73294
73430
  const absY = Math.abs(escapeY);
@@ -73296,14 +73432,14 @@ class VoxelCollider {
73296
73432
  px = 0;
73297
73433
  py = 0;
73298
73434
  pz = 0;
73299
- if (absX <= absY && absX <= absZ) {
73300
- px = escapeX;
73301
- penetration = absX;
73302
- }
73303
- else if (absY <= absZ) {
73435
+ if (absY <= absX && absY <= absZ) {
73304
73436
  py = escapeY;
73305
73437
  penetration = absY;
73306
73438
  }
73439
+ else if (absX <= absZ) {
73440
+ px = escapeX;
73441
+ penetration = absX;
73442
+ }
73307
73443
  else {
73308
73444
  pz = escapeZ;
73309
73445
  penetration = absZ;
@@ -73319,6 +73455,24 @@ class VoxelCollider {
73319
73455
  }
73320
73456
  }
73321
73457
  }
73458
+ // Column-based Y fallback: the per-voxel sphere test loses Y information
73459
+ // when the capsule segment passes through a voxel (segY lands inside the
73460
+ // AABB, zeroing dy). Recover it by finding the topmost solid voxel in the
73461
+ // capsule-center column and computing a direct capsule-bottom push.
73462
+ if (found && Math.abs(bestPushY) <= PENETRATION_EPSILON) {
73463
+ const icx = Math.floor((cx - gridMinX) / voxelResolution);
73464
+ const icz = Math.floor((cz - gridMinZ) / voxelResolution);
73465
+ const capsuleBottom = segTopY + radius;
73466
+ for (let iy = iyMin; iy <= iyMax; iy++) {
73467
+ if (this.isVoxelSolid(icx, iy, icz)) {
73468
+ const surfaceY = gridMinY + iy * voxelResolution;
73469
+ if (capsuleBottom > surfaceY + PENETRATION_EPSILON) {
73470
+ bestPushY = surfaceY - capsuleBottom;
73471
+ }
73472
+ break;
73473
+ }
73474
+ }
73475
+ }
73322
73476
  if (found) {
73323
73477
  this._push.x = bestPushX;
73324
73478
  this._push.y = bestPushY;
@@ -74314,7 +74468,7 @@ const initXr = (global) => {
74314
74468
  });
74315
74469
  };
74316
74470
 
74317
- var version = "1.15.0";
74471
+ var version = "1.16.0";
74318
74472
 
74319
74473
  const loadGsplat = async (app, config, progressCallback) => {
74320
74474
  const { contents, contentUrl, unified, aa } = config;
@@ -74462,7 +74616,7 @@ const main = async (canvas, settingsJson, config) => {
74462
74616
  const state = observe(events, {
74463
74617
  loaded: false,
74464
74618
  readyToRender: false,
74465
- hqMode: true,
74619
+ hqMode: localStorage.getItem('hqMode') !== 'false',
74466
74620
  progress: 0,
74467
74621
  inputMode: platform.mobile ? 'touch' : 'desktop',
74468
74622
  cameraMode: 'orbit',
@@ -74476,7 +74630,8 @@ const main = async (canvas, settingsJson, config) => {
74476
74630
  hasVoxelOverlay: false,
74477
74631
  voxelOverlayEnabled: false,
74478
74632
  isFullscreen: false,
74479
- controlsHidden: false
74633
+ controlsHidden: false,
74634
+ touchControlScheme: localStorage.getItem('touchControlScheme') || 'joystick'
74480
74635
  });
74481
74636
  const global = {
74482
74637
  app,