@mml-io/3d-web-client-core 0.21.2 → 0.21.4

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/build/index.js CHANGED
@@ -19,8 +19,7 @@ var toArray = (origin, precision = 3) => {
19
19
  return array;
20
20
  };
21
21
  var getSpawnPositionInsideCircle = (radius, positions, id, yPos = 0) => {
22
- if (id > 0)
23
- id += 3;
22
+ if (id > 0) id += 3;
24
23
  const goldenAngle = Math.PI * (3 - Math.sqrt(5));
25
24
  const theta = id * goldenAngle;
26
25
  const scale = id / positions;
@@ -129,8 +128,7 @@ var CameraFolder = class {
129
128
  setupChangeEvent(cameraManager) {
130
129
  this.folder.on("change", (e) => {
131
130
  const target = e.target.key;
132
- if (!target)
133
- return;
131
+ if (!target) return;
134
132
  switch (target) {
135
133
  case "initialDistance": {
136
134
  const value = e.value;
@@ -628,8 +626,7 @@ var CharacterFolder = class {
628
626
  setupChangeEvent() {
629
627
  this.folder.on("change", (e) => {
630
628
  const target = e.target.key;
631
- if (!target)
632
- return;
629
+ if (!target) return;
633
630
  switch (target) {
634
631
  case "emissive": {
635
632
  const value = e.value;
@@ -828,8 +825,7 @@ var _CharacterModel = class _CharacterModel {
828
825
  }
829
826
  }
830
827
  applyCustomMaterials() {
831
- if (!this.mesh)
832
- return;
828
+ if (!this.mesh) return;
833
829
  const boundingBox = new Box3();
834
830
  this.mesh.updateWorldMatrix(true, true);
835
831
  boundingBox.expandByObject(this.mesh);
@@ -1162,8 +1158,7 @@ function printAtWordWrap(context, fullText, textAlign, y, lineHeight, fitWidth,
1162
1158
  const substring = word.substring(0, charIndex);
1163
1159
  const subWidth = context.measureText(substring).width;
1164
1160
  if (subWidth + padding * 2 > fitWidth) {
1165
- if (charIndex === 1)
1166
- charIndex = 2;
1161
+ if (charIndex === 1) charIndex = 2;
1167
1162
  context.fillText(
1168
1163
  word.substring(0, charIndex - 1),
1169
1164
  x + padding,
@@ -1495,8 +1490,7 @@ var Character = class extends Group {
1495
1490
  }
1496
1491
  update(time, deltaTime) {
1497
1492
  var _a;
1498
- if (!this.model)
1499
- return;
1493
+ if (!this.model) return;
1500
1494
  if (this.tooltip) {
1501
1495
  this.tooltip.update();
1502
1496
  }
@@ -1522,7 +1516,7 @@ var Character = class extends Group {
1522
1516
  color: new Color3(0.125, 0.125, 0.125)
1523
1517
  });
1524
1518
  this.add(tooltip);
1525
- this.chatTooltips.push(tooltip);
1519
+ this.chatTooltips.unshift(tooltip);
1526
1520
  tooltip.setText(message, () => {
1527
1521
  this.chatTooltips = this.chatTooltips.filter((t) => t !== tooltip);
1528
1522
  this.remove(tooltip);
@@ -1646,8 +1640,7 @@ var CharacterControlsFolder = class {
1646
1640
  setupChangeEvent(localController) {
1647
1641
  this.folder.on("change", (e) => {
1648
1642
  const target = e.target.key;
1649
- if (!target)
1650
- return;
1643
+ if (!target) return;
1651
1644
  switch (target) {
1652
1645
  case "gravity": {
1653
1646
  const value = e.value;
@@ -1818,8 +1811,7 @@ var LocalController = class {
1818
1811
  this.updateNetworkState();
1819
1812
  }
1820
1813
  getTargetAnimation() {
1821
- if (!this.config.character)
1822
- return 0 /* idle */;
1814
+ if (!this.config.character) return 0 /* idle */;
1823
1815
  const jumpHeight = this.characterVelocity.y > 0 ? 0.2 : 1.8;
1824
1816
  if (this.currentHeight > jumpHeight && !this.characterOnGround) {
1825
1817
  if (this.doubleJumpUsed) {
@@ -2842,8 +2834,7 @@ var BrightnessContrastSaturationFolder = class {
2842
2834
  setupChangeEvent(brightnessContrastSaturation) {
2843
2835
  this.folder.on("change", (e) => {
2844
2836
  const target = e.target.key;
2845
- if (!target)
2846
- return;
2837
+ if (!target) return;
2847
2838
  switch (target) {
2848
2839
  case "brightness":
2849
2840
  brightnessContrastSaturation.uniforms.brightness.value = e.value;
@@ -2949,8 +2940,7 @@ var EnvironmentFolder = class {
2949
2940
  setupChangeEvent(scene, setHDR, setSkyboxAzimuthalAngle, setSkyboxPolarAngle, setAmbientLight, setFog, sun) {
2950
2941
  this.sun.on("change", (e) => {
2951
2942
  const target = e.target.key;
2952
- if (!target)
2953
- return;
2943
+ if (!target) return;
2954
2944
  switch (target) {
2955
2945
  case "sunAzimuthalAngle": {
2956
2946
  const value = e.value;
@@ -2986,8 +2976,7 @@ var EnvironmentFolder = class {
2986
2976
  });
2987
2977
  this.envMap.on("change", (e) => {
2988
2978
  const target = e.target.key;
2989
- if (!target)
2990
- return;
2979
+ if (!target) return;
2991
2980
  switch (target) {
2992
2981
  case "envMapIntensity":
2993
2982
  scene.environmentIntensity = e.value;
@@ -2996,8 +2985,7 @@ var EnvironmentFolder = class {
2996
2985
  });
2997
2986
  this.skybox.on("change", (e) => {
2998
2987
  const target = e.target.key;
2999
- if (!target)
3000
- return;
2988
+ if (!target) return;
3001
2989
  switch (target) {
3002
2990
  case "skyboxAzimuthalAngle": {
3003
2991
  const value = e.value;
@@ -3020,8 +3008,7 @@ var EnvironmentFolder = class {
3020
3008
  });
3021
3009
  this.ambient.on("change", (e) => {
3022
3010
  const target = e.target.key;
3023
- if (!target)
3024
- return;
3011
+ if (!target) return;
3025
3012
  switch (target) {
3026
3013
  case "ambientLightIntensity": {
3027
3014
  envValues.ambientLight.ambientLightIntensity = e.value;
@@ -3042,8 +3029,7 @@ var EnvironmentFolder = class {
3042
3029
  });
3043
3030
  this.fog.on("change", (e) => {
3044
3031
  const target = e.target.key;
3045
- if (!target)
3046
- return;
3032
+ if (!target) return;
3047
3033
  switch (target) {
3048
3034
  case "fogNear": {
3049
3035
  envValues.fog.fogNear = e.value;
@@ -3092,8 +3078,7 @@ var PostExtrasFolder = class {
3092
3078
  setupChangeEvent(bloomEffect, gaussGrainEffect) {
3093
3079
  this.folder.on("change", (e) => {
3094
3080
  const target = e.target.key;
3095
- if (!target)
3096
- return;
3081
+ if (!target) return;
3097
3082
  switch (target) {
3098
3083
  case "bloom":
3099
3084
  bloomEffect.intensity = e.value;
@@ -3159,8 +3144,7 @@ var RendererFolder = class {
3159
3144
  setupChangeEvent(renderer, toneMappingFolder, toneMappingPass) {
3160
3145
  this.folder.on("change", (e) => {
3161
3146
  const target = e.target.key;
3162
- if (!target)
3163
- return;
3147
+ if (!target) return;
3164
3148
  switch (target) {
3165
3149
  case "shadowMap": {
3166
3150
  const value2 = e.value;
@@ -3388,8 +3372,7 @@ var SSAOFolder = class {
3388
3372
  setupChangeEvent(composer, normalPass, ppssaoEffect, ppssaoPass, n8aopass) {
3389
3373
  this.ppssao.on("change", (e) => {
3390
3374
  const target = e.target.key;
3391
- if (!target)
3392
- return;
3375
+ if (!target) return;
3393
3376
  switch (target) {
3394
3377
  case "enabled": {
3395
3378
  const value = e.value;
@@ -3433,8 +3416,7 @@ var SSAOFolder = class {
3433
3416
  });
3434
3417
  this.n8ssao.on("change", (e) => {
3435
3418
  const target = e.target.key;
3436
- if (!target)
3437
- return;
3419
+ if (!target) return;
3438
3420
  switch (target) {
3439
3421
  case "enabled":
3440
3422
  if (e.value === true) {
@@ -3546,8 +3528,7 @@ var ToneMappingFolder = class {
3546
3528
  setupChangeEvent(toneMappingEffect) {
3547
3529
  this.folder.on("change", (e) => {
3548
3530
  const target = e.target.key;
3549
- if (!target)
3550
- return;
3531
+ if (!target) return;
3551
3532
  if (target === "mode") {
3552
3533
  setCustomToneMappingType(e.value);
3553
3534
  }
@@ -3895,22 +3876,17 @@ var Sun = class extends Group4 {
3895
3876
  }
3896
3877
  }
3897
3878
  updateCharacterPosition(position) {
3898
- if (!position)
3899
- return;
3879
+ if (!position) return;
3900
3880
  this.target = position;
3901
3881
  this.setSunPosition(this.sunOffset.x, this.sunOffset.y);
3902
3882
  }
3903
3883
  setAzimuthalAngle(angle) {
3904
- if (this.sunOffset)
3905
- this.sunOffset.x = angle;
3906
- if (this.target)
3907
- this.updateCharacterPosition(this.target);
3884
+ if (this.sunOffset) this.sunOffset.x = angle;
3885
+ if (this.target) this.updateCharacterPosition(this.target);
3908
3886
  }
3909
3887
  setPolarAngle(angle) {
3910
- if (this.sunOffset)
3911
- this.sunOffset.y = angle;
3912
- if (this.target)
3913
- this.updateCharacterPosition(this.target);
3888
+ if (this.sunOffset) this.sunOffset.y = angle;
3889
+ if (this.target) this.updateCharacterPosition(this.target);
3914
3890
  }
3915
3891
  setIntensity(intensity) {
3916
3892
  this.directionalLight.intensity = intensity;
@@ -3923,8 +3899,7 @@ var Sun = class extends Group4 {
3923
3899
  );
3924
3900
  }
3925
3901
  setSunPosition(azimuthalAngle, polarAngle) {
3926
- if (!this.target)
3927
- return;
3902
+ if (!this.target) return;
3928
3903
  const distance = this.sunOffset.z;
3929
3904
  const sphericalPosition = new Vector310(
3930
3905
  distance * Math.sin(polarAngle) * Math.cos(azimuthalAngle),
@@ -4102,7 +4077,6 @@ import {
4102
4077
  Uniform as Uniform7,
4103
4078
  Vector2 as Vector26,
4104
4079
  Vector3 as Vector314,
4105
- WebGLMultipleRenderTargets,
4106
4080
  WebGLRenderTarget
4107
4081
  } from "three";
4108
4082
 
@@ -4364,11 +4338,15 @@ var EffectCompositer = {
4364
4338
  vec4 clipSpacePosition = vec4(coord * 2.0 - 1.0, z, 1.0);
4365
4339
  vec4 viewSpacePosition = projectionMatrixInv * clipSpacePosition;
4366
4340
 
4367
- vec4 worldSpacePosition = viewSpacePosition;
4368
- worldSpacePosition.xyz /= worldSpacePosition.w;
4369
- return worldSpacePosition.xyz;
4341
+ if (abs(viewSpacePosition.w) < 1e-6) {
4342
+ discard;
4343
+ }
4344
+
4345
+ viewSpacePosition /= viewSpacePosition.w;
4346
+ return (viewMatrixInv * viewSpacePosition).xyz;
4370
4347
  }
4371
4348
 
4349
+
4372
4350
  vec3 computeNormal(vec3 worldPos, vec2 vUv) {
4373
4351
  ivec2 p = ivec2(vUv * resolution);
4374
4352
  float c0 = texelFetch(sceneDepth, p, 0).x;
@@ -5076,22 +5054,18 @@ var N8SSAOPass = class extends Pass {
5076
5054
  }
5077
5055
  configureHalfResTargets() {
5078
5056
  if (this.configuration.halfRes) {
5079
- this.depthDownsampleTarget = new WebGLMultipleRenderTargets(
5080
- this.width / 2,
5081
- this.height / 2,
5082
- 2,
5083
- {
5084
- depthBuffer: false
5085
- }
5086
- );
5087
- this.depthDownsampleTarget.texture[0].format = RedFormat;
5088
- this.depthDownsampleTarget.texture[0].type = FloatType;
5089
- this.depthDownsampleTarget.texture[0].minFilter = NearestFilter;
5090
- this.depthDownsampleTarget.texture[0].magFilter = NearestFilter;
5091
- this.depthDownsampleTarget.texture[1].format = RGBAFormat2;
5092
- this.depthDownsampleTarget.texture[1].type = HalfFloatType;
5093
- this.depthDownsampleTarget.texture[1].minFilter = NearestFilter;
5094
- this.depthDownsampleTarget.texture[1].magFilter = NearestFilter;
5057
+ this.depthDownsampleTarget = new WebGLRenderTarget(this.width / 2, this.height / 2, {
5058
+ count: 2,
5059
+ depthBuffer: false
5060
+ });
5061
+ this.depthDownsampleTarget.textures[0].format = RedFormat;
5062
+ this.depthDownsampleTarget.textures[0].type = FloatType;
5063
+ this.depthDownsampleTarget.textures[0].minFilter = NearestFilter;
5064
+ this.depthDownsampleTarget.textures[0].magFilter = NearestFilter;
5065
+ this.depthDownsampleTarget.textures[1].format = RGBAFormat2;
5066
+ this.depthDownsampleTarget.textures[1].type = HalfFloatType;
5067
+ this.depthDownsampleTarget.textures[1].minFilter = NearestFilter;
5068
+ this.depthDownsampleTarget.textures[1].magFilter = NearestFilter;
5095
5069
  this.depthDownsampleQuad = new FullScreenTriangle(new ShaderMaterial4(DepthDownSample));
5096
5070
  } else {
5097
5071
  if (this.depthDownsampleTarget) {
@@ -5251,12 +5225,11 @@ var N8SSAOPass = class extends Pass {
5251
5225
  depthDownsampleUniforms.logDepth.value = this.configuration.logarithmicDepthBuffer;
5252
5226
  this.depthDownsampleQuad.render(renderer);
5253
5227
  }
5254
- if (!this.effectShaderQuad)
5255
- return;
5228
+ if (!this.effectShaderQuad) return;
5256
5229
  const effectShaderUniforms = this.effectShaderQuad.material.uniforms;
5257
5230
  effectShaderUniforms.sceneDiffuse.value = inputBuffer.texture;
5258
- effectShaderUniforms.sceneDepth.value = this.configuration.halfRes ? this.depthDownsampleTarget.texture[0] : this.depthTexture;
5259
- effectShaderUniforms.sceneNormal.value = this.configuration.halfRes ? this.depthDownsampleTarget.texture[1] : null;
5231
+ effectShaderUniforms.sceneDepth.value = this.configuration.halfRes ? this.depthDownsampleTarget.textures[0] : this.depthTexture;
5232
+ effectShaderUniforms.sceneNormal.value = this.configuration.halfRes ? this.depthDownsampleTarget.textures[1] : null;
5260
5233
  effectShaderUniforms.projMat.value = this.camera.projectionMatrix;
5261
5234
  effectShaderUniforms.viewMat.value = this.camera.matrixWorldInverse;
5262
5235
  effectShaderUniforms.projViewMat.value = this.camera.projectionMatrix.clone().multiply(this.camera.matrixWorldInverse.clone());
@@ -5279,14 +5252,13 @@ var N8SSAOPass = class extends Pass {
5279
5252
  this.effectShaderQuad.render(renderer);
5280
5253
  const poissonBlurUniforms = this.poissonBlurQuad.material.uniforms;
5281
5254
  for (let i = 0; i < this.configuration.denoiseIterations; i++) {
5282
- if (!poissonBlurUniforms || !this.poissonBlurQuad)
5283
- return;
5255
+ if (!poissonBlurUniforms || !this.poissonBlurQuad) return;
5284
5256
  [this.writeTargetInternal, this.readTargetInternal] = [
5285
5257
  this.readTargetInternal,
5286
5258
  this.writeTargetInternal
5287
5259
  ];
5288
5260
  poissonBlurUniforms.tDiffuse.value = this.readTargetInternal.texture;
5289
- poissonBlurUniforms.sceneDepth.value = this.configuration.halfRes ? this.depthDownsampleTarget.texture[0] : this.depthTexture;
5261
+ poissonBlurUniforms.sceneDepth.value = this.configuration.halfRes ? this.depthDownsampleTarget.textures[0] : this.depthTexture;
5290
5262
  poissonBlurUniforms.projMat.value = this.camera.projectionMatrix;
5291
5263
  poissonBlurUniforms.viewMat.value = this.camera.matrixWorldInverse;
5292
5264
  poissonBlurUniforms.projectionMatrixInv.value = this.camera.projectionMatrixInverse;
@@ -5308,8 +5280,7 @@ var N8SSAOPass = class extends Pass {
5308
5280
  this.poissonBlurQuad.render(renderer);
5309
5281
  }
5310
5282
  const effectCompositerUniforms = this.effectCompositerQuad.material.uniforms;
5311
- if (!effectCompositerUniforms || !this.effectCompositerQuad)
5312
- return;
5283
+ if (!effectCompositerUniforms || !this.effectCompositerQuad) return;
5313
5284
  effectCompositerUniforms.sceneDiffuse.value = inputBuffer.texture;
5314
5285
  effectCompositerUniforms.sceneDepth.value = this.depthTexture;
5315
5286
  effectCompositerUniforms.near.value = this.camera.near;
@@ -5318,7 +5289,7 @@ var N8SSAOPass = class extends Pass {
5318
5289
  effectCompositerUniforms.viewMatrixInv.value = this.camera.matrixWorld;
5319
5290
  effectCompositerUniforms.logDepth.value = renderer.capabilities.logarithmicDepthBuffer;
5320
5291
  effectCompositerUniforms.ortho.value = this.camera instanceof OrthographicCamera3;
5321
- effectCompositerUniforms.downsampledDepth.value = this.configuration.halfRes ? this.depthDownsampleTarget.texture[0] : this.depthTexture;
5292
+ effectCompositerUniforms.downsampledDepth.value = this.configuration.halfRes ? this.depthDownsampleTarget.textures[0] : this.depthTexture;
5322
5293
  effectCompositerUniforms.resolution.value = this.r;
5323
5294
  effectCompositerUniforms.blueNoise.value = this.bluenoise;
5324
5295
  effectCompositerUniforms.intensity.value = this.configuration.intensity;
@@ -5714,8 +5685,7 @@ var Composer = class {
5714
5685
  });
5715
5686
  }
5716
5687
  setHDRIFromFile() {
5717
- if (!this.renderer)
5718
- return;
5688
+ if (!this.renderer) return;
5719
5689
  const fileInput = document.createElement("input");
5720
5690
  fileInput.type = "file";
5721
5691
  fileInput.accept = ".hdr,.jpg";
@@ -5858,8 +5828,7 @@ var TimeManager = class {
5858
5828
  this.frame++;
5859
5829
  this.time += this.rawDeltaTime;
5860
5830
  this.deltaTimes.push(this.rawDeltaTime);
5861
- if (this.deltaTimes.length > this.maxAverageFrames)
5862
- this.deltaTimes.shift();
5831
+ if (this.deltaTimes.length > this.maxAverageFrames) this.deltaTimes.shift();
5863
5832
  this.targetAverageDeltaTime = this.deltaTimes.reduce((prev, curr) => prev + curr, 0) / this.deltaTimes.length;
5864
5833
  this.lerpedAverageMagDelta += ease(
5865
5834
  this.targetAverageDeltaTime * this.roundMagnitude,
@@ -5985,23 +5954,41 @@ var CollisionsManager = class {
5985
5954
  group.traverse((child) => {
5986
5955
  const asMesh = child;
5987
5956
  if (asMesh.isMesh) {
5988
- const clonedGeometry = asMesh.geometry.clone();
5989
- if (child !== group) {
5957
+ const asInstancedMesh = asMesh;
5958
+ if (asInstancedMesh.isInstancedMesh) {
5959
+ for (let i = 0; i < asInstancedMesh.count; i++) {
5960
+ const clonedGeometry = asInstancedMesh.geometry.clone();
5961
+ for (const key in clonedGeometry.attributes) {
5962
+ if (key !== "position") {
5963
+ clonedGeometry.deleteAttribute(key);
5964
+ }
5965
+ }
5966
+ clonedGeometry.applyMatrix4(
5967
+ this.tempMatrix2.fromArray(asInstancedMesh.instanceMatrix.array, i * 16)
5968
+ );
5969
+ if (clonedGeometry.index) {
5970
+ geometries.push(clonedGeometry.toNonIndexed());
5971
+ } else {
5972
+ geometries.push(clonedGeometry);
5973
+ }
5974
+ }
5975
+ } else {
5976
+ const clonedGeometry = asMesh.geometry.clone();
5990
5977
  asMesh.updateWorldMatrix(true, false);
5978
+ for (const key in clonedGeometry.attributes) {
5979
+ if (key !== "position") {
5980
+ clonedGeometry.deleteAttribute(key);
5981
+ }
5982
+ }
5991
5983
  clonedGeometry.applyMatrix4(
5992
5984
  this.tempMatrix2.multiplyMatrices(invertedRootMatrix, asMesh.matrixWorld)
5993
5985
  );
5994
- }
5995
- for (const key in clonedGeometry.attributes) {
5996
- if (key !== "position") {
5997
- clonedGeometry.deleteAttribute(key);
5986
+ if (clonedGeometry.index) {
5987
+ geometries.push(clonedGeometry.toNonIndexed());
5988
+ } else {
5989
+ geometries.push(clonedGeometry);
5998
5990
  }
5999
5991
  }
6000
- if (clonedGeometry.index) {
6001
- geometries.push(clonedGeometry.toNonIndexed());
6002
- } else {
6003
- geometries.push(clonedGeometry);
6004
- }
6005
5992
  }
6006
5993
  });
6007
5994
  const newBufferGeometry = BufferGeometryUtils.mergeGeometries(geometries, false);