@mml-io/3d-web-client-core 0.5.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.js CHANGED
@@ -48,13 +48,13 @@ var CameraManager = class {
48
48
  constructor(collisionsManager) {
49
49
  this.collisionsManager = collisionsManager;
50
50
  __publicField(this, "camera");
51
- __publicField(this, "initialDistance", 2.5);
51
+ __publicField(this, "initialDistance", 3.3);
52
52
  __publicField(this, "minDistance", 0.1);
53
- __publicField(this, "maxDistance", 6);
54
- __publicField(this, "initialFOV", 80);
53
+ __publicField(this, "maxDistance", 8);
54
+ __publicField(this, "initialFOV", 60);
55
55
  __publicField(this, "fov", this.initialFOV);
56
- __publicField(this, "minFOV", 63);
57
- __publicField(this, "maxFOV", 85);
56
+ __publicField(this, "minFOV", 50);
57
+ __publicField(this, "maxFOV", 70);
58
58
  __publicField(this, "targetFOV", this.initialFOV);
59
59
  __publicField(this, "minPolarAngle", Math.PI * 0.25);
60
60
  __publicField(this, "maxPolarAngle", Math.PI * 0.95);
@@ -856,7 +856,6 @@ var defaultLabelHeight = 0.125;
856
856
  var defaultLabelCastShadows = true;
857
857
  var CharacterTooltip = class {
858
858
  constructor(parentModel) {
859
- __publicField(this, "texture");
860
859
  __publicField(this, "geometry");
861
860
  __publicField(this, "material");
862
861
  __publicField(this, "mesh");
@@ -877,7 +876,7 @@ var CharacterTooltip = class {
877
876
  });
878
877
  this.setText = this.setText.bind(this);
879
878
  this.material = new MeshBasicMaterial2({
880
- map: this.texture,
879
+ map: null,
881
880
  transparent: true,
882
881
  opacity: 0
883
882
  });
@@ -1013,13 +1012,13 @@ var LocalController = class {
1013
1012
  __publicField(this, "thirdPersonCamera", null);
1014
1013
  __publicField(this, "speed", 0);
1015
1014
  __publicField(this, "targetSpeed", 0);
1016
- __publicField(this, "networkState", {
1017
- id: 0,
1015
+ __publicField(this, "networkState");
1016
+ this.networkState = {
1017
+ id: this.id,
1018
1018
  position: { x: 0, y: 0, z: 0 },
1019
- rotation: { quaternionY: 0, quaternionW: 0 },
1019
+ rotation: { quaternionY: 0, quaternionW: 1 },
1020
1020
  state: 0 /* idle */
1021
- });
1022
- setInterval(() => this.update.bind(this), 3e3);
1021
+ };
1023
1022
  }
1024
1023
  update() {
1025
1024
  if (!this.model?.mesh || !this.model?.animationMixer)
@@ -1200,20 +1199,27 @@ var LocalController = class {
1200
1199
  }
1201
1200
  }
1202
1201
  updateNetworkState() {
1203
- if (!this.model?.mesh)
1204
- return;
1205
- const characterQuaternion = this.model.mesh.getWorldQuaternion(new Quaternion());
1206
- const positionUpdate = new Vector33(
1207
- this.model.mesh.position.x,
1208
- this.model.mesh.position.y,
1209
- this.model.mesh.position.z
1210
- );
1211
- this.networkState = {
1212
- id: this.id,
1213
- position: positionUpdate,
1214
- rotation: { quaternionY: characterQuaternion?.y, quaternionW: characterQuaternion?.w },
1215
- state: this.model.currentAnimation
1216
- };
1202
+ if (!this.model?.mesh) {
1203
+ this.networkState = {
1204
+ id: this.id,
1205
+ position: new Vector33(),
1206
+ rotation: { quaternionY: 0, quaternionW: 1 },
1207
+ state: 0 /* idle */
1208
+ };
1209
+ } else {
1210
+ const characterQuaternion = this.model.mesh.getWorldQuaternion(new Quaternion());
1211
+ const positionUpdate = new Vector33(
1212
+ this.model.mesh.position.x,
1213
+ this.model.mesh.position.y,
1214
+ this.model.mesh.position.z
1215
+ );
1216
+ this.networkState = {
1217
+ id: this.id,
1218
+ position: positionUpdate,
1219
+ rotation: { quaternionY: characterQuaternion.y, quaternionW: characterQuaternion.w },
1220
+ state: this.model.currentAnimation
1221
+ };
1222
+ }
1217
1223
  }
1218
1224
  resetPosition() {
1219
1225
  if (!this.model?.mesh)
@@ -1296,15 +1302,16 @@ var RemoteController = class {
1296
1302
  __publicField(this, "animationMixer", new AnimationMixer2(new Object3D4()));
1297
1303
  __publicField(this, "animations", /* @__PURE__ */ new Map());
1298
1304
  __publicField(this, "currentAnimation", 0 /* idle */);
1299
- __publicField(this, "networkState", {
1300
- id: 0,
1301
- position: { x: 0, y: 0, z: 0 },
1302
- rotation: { quaternionY: 0, quaternionW: 0 },
1303
- state: this.currentAnimation
1304
- });
1305
+ __publicField(this, "networkState");
1305
1306
  this.characterModel = this.character.model.mesh;
1306
1307
  this.characterModel.updateMatrixWorld();
1307
1308
  this.animationMixer = new AnimationMixer2(this.characterModel);
1309
+ this.networkState = {
1310
+ id: this.id,
1311
+ position: { x: 0, y: 0, z: 0 },
1312
+ rotation: { quaternionY: 0, quaternionW: 1 },
1313
+ state: this.currentAnimation
1314
+ };
1308
1315
  }
1309
1316
  update(clientUpdate, time, deltaTime) {
1310
1317
  if (!this.character)
@@ -1389,7 +1396,6 @@ var CharacterManager = class {
1389
1396
  __publicField(this, "cameraOffset", 0);
1390
1397
  __publicField(this, "group");
1391
1398
  this.group = new Group();
1392
- setInterval(() => this.update.bind(this), 3e3);
1393
1399
  }
1394
1400
  /* TODO:
1395
1401
  1) Separate this method into spawnLocalCharacter and spawnRemoteCharacter
@@ -1422,7 +1428,7 @@ var CharacterManager = class {
1422
1428
  y: spawnPosition.y,
1423
1429
  z: spawnPosition.z
1424
1430
  },
1425
- rotation: { quaternionY: 0, quaternionW: 0 },
1431
+ rotation: { quaternionY: 0, quaternionW: 1 },
1426
1432
  state: 0 /* idle */
1427
1433
  });
1428
1434
  }
@@ -1691,7 +1697,9 @@ import {
1691
1697
  NormalPass
1692
1698
  } from "postprocessing";
1693
1699
  import {
1694
- Color as Color5,
1700
+ AmbientLight,
1701
+ Color as Color6,
1702
+ Fog,
1695
1703
  HalfFloatType,
1696
1704
  LinearSRGBColorSpace,
1697
1705
  LoadingManager as LoadingManager2,
@@ -1701,6 +1709,109 @@ import {
1701
1709
  } from "three";
1702
1710
  import { RGBELoader } from "three/examples/jsm/loaders/RGBELoader.js";
1703
1711
 
1712
+ // src/sun/Sun.ts
1713
+ import { CameraHelper, Color as Color4, DirectionalLight, Group as Group3, OrthographicCamera, Vector3 as Vector37 } from "three";
1714
+
1715
+ // src/tweakpane/sunSettings.ts
1716
+ var sunValues = {
1717
+ sunPosition: {
1718
+ sunAzimuthalAngle: 39,
1719
+ sunPolarAngle: 50
1720
+ },
1721
+ sunIntensity: 0.5,
1722
+ sunColor: { r: 1, g: 1, b: 1 }
1723
+ };
1724
+ var sunOptions = {
1725
+ sunPosition: {
1726
+ sunAzimuthalAngle: { min: 0, max: 360, step: 1 },
1727
+ sunPolarAngle: { min: -90, max: 90, step: 1 }
1728
+ },
1729
+ sunIntensity: { min: 0, max: 1, step: 0.05 }
1730
+ };
1731
+
1732
+ // src/sun/Sun.ts
1733
+ var Sun = class extends Group3 {
1734
+ constructor() {
1735
+ super();
1736
+ __publicField(this, "debug", false);
1737
+ __publicField(this, "sunOffset", new Vector37(
1738
+ 39 * (Math.PI / 180),
1739
+ 50 * (Math.PI / 180),
1740
+ 100
1741
+ ));
1742
+ __publicField(this, "shadowResolution", 8192);
1743
+ __publicField(this, "shadowCamFrustum", 50);
1744
+ __publicField(this, "camHelper", null);
1745
+ __publicField(this, "shadowCamera");
1746
+ __publicField(this, "directionalLight");
1747
+ __publicField(this, "target", null);
1748
+ this.shadowCamera = new OrthographicCamera(
1749
+ -this.shadowCamFrustum,
1750
+ this.shadowCamFrustum,
1751
+ this.shadowCamFrustum,
1752
+ -this.shadowCamFrustum,
1753
+ 0.1,
1754
+ 200
1755
+ );
1756
+ if (this.debug === true) {
1757
+ this.camHelper = new CameraHelper(this.shadowCamera);
1758
+ }
1759
+ this.directionalLight = new DirectionalLight(16777215, 0.5);
1760
+ this.directionalLight.shadow.normalBias = 0.05;
1761
+ this.directionalLight.shadow.radius = 1.5;
1762
+ this.directionalLight.shadow.camera = this.shadowCamera;
1763
+ this.directionalLight.shadow.mapSize.set(this.shadowResolution, this.shadowResolution);
1764
+ this.directionalLight.castShadow = true;
1765
+ this.updateCharacterPosition(new Vector37(0, 0, 0));
1766
+ this.add(this.directionalLight);
1767
+ if (this.debug === true && this.camHelper instanceof CameraHelper) {
1768
+ this.add(this.camHelper);
1769
+ }
1770
+ }
1771
+ updateCharacterPosition(position) {
1772
+ if (!position)
1773
+ return;
1774
+ this.target = position;
1775
+ this.setSunPosition(this.sunOffset.x, this.sunOffset.y);
1776
+ }
1777
+ setAzimuthalAngle(angle) {
1778
+ if (this.sunOffset)
1779
+ this.sunOffset.x = angle;
1780
+ if (this.target)
1781
+ this.updateCharacterPosition(this.target);
1782
+ }
1783
+ setPolarAngle(angle) {
1784
+ if (this.sunOffset)
1785
+ this.sunOffset.y = angle;
1786
+ if (this.target)
1787
+ this.updateCharacterPosition(this.target);
1788
+ }
1789
+ setIntensity(intensity) {
1790
+ this.directionalLight.intensity = intensity;
1791
+ }
1792
+ setColor() {
1793
+ this.directionalLight.color = new Color4().setRGB(
1794
+ sunValues.sunColor.r,
1795
+ sunValues.sunColor.g,
1796
+ sunValues.sunColor.b
1797
+ );
1798
+ }
1799
+ setSunPosition(azimuthalAngle, polarAngle) {
1800
+ if (!this.target)
1801
+ return;
1802
+ const distance = this.sunOffset.z;
1803
+ const sphericalPosition = new Vector37(
1804
+ distance * Math.sin(polarAngle) * Math.cos(azimuthalAngle),
1805
+ distance * Math.cos(polarAngle),
1806
+ distance * Math.sin(polarAngle) * Math.sin(azimuthalAngle)
1807
+ );
1808
+ const newSunPosition = this.target.clone().add(sphericalPosition);
1809
+ this.directionalLight.position.set(newSunPosition.x, newSunPosition.y, newSunPosition.z);
1810
+ this.directionalLight.target.position.copy(this.target.clone());
1811
+ this.directionalLight.target.updateMatrixWorld();
1812
+ }
1813
+ };
1814
+
1704
1815
  // src/tweakpane/composerSettings.ts
1705
1816
  import { BlendFunction } from "postprocessing";
1706
1817
  var composerValues = {
@@ -1739,17 +1850,17 @@ var composerValues = {
1739
1850
  adaptationRate: 2
1740
1851
  },
1741
1852
  brightness: -0.03,
1742
- contrast: 1.3,
1853
+ contrast: 1.21,
1743
1854
  saturation: 0.91,
1744
1855
  grain: 0.061,
1745
- bloom: 0.45
1856
+ bloom: 0.25
1746
1857
  };
1747
1858
  var composerOptions = {
1748
1859
  renderer: {
1749
1860
  shadowMap: { min: 0, max: 2, step: 1 },
1750
1861
  toneMapping: { min: 0, max: 5, step: 1 },
1751
1862
  exposure: { min: 0, max: 3, step: 0.01 },
1752
- bgIntensity: { min: 0, max: 1, step: 0.01 },
1863
+ bgIntensity: { min: 0, max: 1.3, step: 0.01 },
1753
1864
  bgBlurriness: { min: 0, max: 0.1, step: 1e-3 }
1754
1865
  },
1755
1866
  ssao: {
@@ -1848,17 +1959,81 @@ var statsData = {
1848
1959
  FPS: "0"
1849
1960
  };
1850
1961
 
1962
+ // src/tweakpane/envSettings.ts
1963
+ var envValues = {
1964
+ ambientLight: {
1965
+ ambientLightIntensity: 0,
1966
+ ambientLightColor: { r: 1, g: 1, b: 1 }
1967
+ },
1968
+ fog: {
1969
+ fogNear: 30,
1970
+ fogFar: 210,
1971
+ fogColor: { r: 0.42, g: 0.48, b: 0.59 }
1972
+ }
1973
+ };
1974
+ var envOptions = {
1975
+ ambientLight: {
1976
+ ambientLightIntensity: { min: 0, max: 1, step: 0.01 }
1977
+ },
1978
+ fog: {
1979
+ fogNear: { min: 0, max: 80, step: 1 },
1980
+ fogFar: { min: 81, max: 300, step: 1 }
1981
+ }
1982
+ };
1983
+
1851
1984
  // src/tweakpane/TweakPane.ts
1852
1985
  import {
1853
1986
  BlendFunction as BlendFunction2
1854
1987
  } from "postprocessing";
1855
- import { Color as Color4 } from "three";
1988
+ import { Color as Color5 } from "three";
1856
1989
  import { Pane } from "tweakpane";
1857
1990
  var TweakPane = class {
1858
1991
  constructor(renderer, scene, composer) {
1859
1992
  __publicField(this, "renderer");
1860
1993
  __publicField(this, "scene");
1861
1994
  __publicField(this, "composer");
1995
+ __publicField(this, "guiStyle", `
1996
+ :root {
1997
+ --tp-base-background-color: hsla(0, 0%, 10%, 0.8);
1998
+ --tp-base-shadow-color: hsla(0, 0%, 0%, 0.2);
1999
+ --tp-button-background-color: hsla(0, 0%, 80%, 1);
2000
+ --tp-button-background-color-active: hsla(0, 0%, 100%, 1);
2001
+ --tp-button-background-color-focus: hsla(0, 0%, 95%, 1);
2002
+ --tp-button-background-color-hover: hsla(0, 0%, 85%, 1);
2003
+ --tp-button-foreground-color: hsla(0, 0%, 0%, 0.8);
2004
+ --tp-container-background-color: hsla(0, 0%, 0%, 0.3);
2005
+ --tp-container-background-color-active: hsla(0, 0%, 0%, 0.6);
2006
+ --tp-container-background-color-focus: hsla(0, 0%, 0%, 0.5);
2007
+ --tp-container-background-color-hover: hsla(0, 0%, 0%, 0.4);
2008
+ --tp-container-foreground-color: hsla(0, 0%, 100%, 0.5);
2009
+ --tp-groove-foreground-color: hsla(0, 0%, 0%, 0.2);
2010
+ --tp-input-background-color: hsla(0, 0%, 0%, 0.3);
2011
+ --tp-input-background-color-active: hsla(0, 0%, 0%, 0.6);
2012
+ --tp-input-background-color-focus: hsla(0, 0%, 0%, 0.5);
2013
+ --tp-input-background-color-hover: hsla(0, 0%, 0%, 0.4);
2014
+ --tp-input-foreground-color: hsla(0, 0%, 100%, 0.5);
2015
+ --tp-label-foreground-color: hsla(0, 0%, 100%, 0.5);
2016
+ --tp-monitor-background-color: hsla(0, 0%, 0%, 0.3);
2017
+ --tp-monitor-foreground-color: hsla(0, 0%, 100%, 0.3);
2018
+ }
2019
+
2020
+ .tp-brkv {
2021
+ -webkit-user-select: none;
2022
+ -ms-user-select: none;
2023
+ user-select: none;
2024
+ }
2025
+
2026
+ .tp-dfwv {
2027
+ width: 333px !important;
2028
+ display: none;
2029
+ }
2030
+
2031
+ .tp-lblv_l {
2032
+ font-size: 10px;
2033
+ padding-left: 0px !important;
2034
+ padding-right: 0px !important;
2035
+ }
2036
+ `);
1862
2037
  __publicField(this, "gui", new Pane());
1863
2038
  __publicField(this, "render");
1864
2039
  __publicField(this, "stats");
@@ -1868,6 +2043,10 @@ var TweakPane = class {
1868
2043
  __publicField(this, "post");
1869
2044
  __publicField(this, "export");
1870
2045
  __publicField(this, "characterMaterial");
2046
+ __publicField(this, "environment");
2047
+ __publicField(this, "sun");
2048
+ __publicField(this, "sunButton");
2049
+ __publicField(this, "ambient");
1871
2050
  __publicField(this, "saveVisibilityInLocalStorage", true);
1872
2051
  __publicField(this, "guiVisible", false);
1873
2052
  if (this.saveVisibilityInLocalStorage) {
@@ -1883,6 +2062,10 @@ var TweakPane = class {
1883
2062
  this.renderer = renderer;
1884
2063
  this.scene = scene;
1885
2064
  this.composer = composer;
2065
+ const styleElement = document.createElement("style");
2066
+ styleElement.type = "text/css";
2067
+ styleElement.appendChild(document.createTextNode(this.guiStyle));
2068
+ document.head.appendChild(styleElement);
1886
2069
  this.render = this.gui.addFolder({ title: "rendering", expanded: true });
1887
2070
  this.stats = this.render.addFolder({ title: "stats", expanded: true });
1888
2071
  this.renderOptions = this.render.addFolder({ title: "renderOptions", expanded: false });
@@ -1890,96 +2073,105 @@ var TweakPane = class {
1890
2073
  this.ssao = this.render.addFolder({ title: "ambientOcclusion", expanded: false });
1891
2074
  this.post = this.render.addFolder({ title: "post", expanded: false });
1892
2075
  this.toneMapping.hidden = composerValues.renderer.toneMapping === 5 ? false : true;
1893
- this.characterMaterial = this.gui.addFolder({ title: "characterMaterial", expanded: false });
1894
- this.characterMaterial.addInput(
1895
- characterValues.material,
1896
- "transmission",
1897
- characterOptions.material.transmission
1898
- );
1899
- this.characterMaterial.addInput(
1900
- characterValues.material,
1901
- "metalness",
1902
- characterOptions.material.metalness
1903
- );
1904
- this.characterMaterial.addInput(
1905
- characterValues.material,
1906
- "roughness",
1907
- characterOptions.material.roughness
1908
- );
1909
- this.characterMaterial.addInput(characterValues.material, "ior", characterOptions.material.ior);
1910
- this.characterMaterial.addInput(
1911
- characterValues.material,
1912
- "thickness",
1913
- characterOptions.material.thickness
1914
- );
1915
- this.characterMaterial.addInput(characterValues.material, "specularColor", {
1916
- color: { type: "float" }
1917
- });
1918
- this.characterMaterial.addInput(
1919
- characterValues.material,
1920
- "specularIntensity",
1921
- characterOptions.material.specularIntensity
1922
- );
1923
- this.characterMaterial.addInput(characterValues.material, "emissive", {
1924
- color: { type: "float" }
1925
- });
1926
- this.characterMaterial.addInput(
1927
- characterValues.material,
1928
- "emissiveIntensity",
1929
- characterOptions.material.emissiveIntensity
1930
- );
1931
- this.characterMaterial.addInput(
1932
- characterValues.material,
1933
- "envMapIntensity",
1934
- characterOptions.material.envMapIntensity
1935
- );
1936
- this.characterMaterial.addInput(characterValues.material, "sheenColor", {
1937
- color: { type: "float" }
1938
- });
1939
- this.characterMaterial.addInput(
1940
- characterValues.material,
1941
- "sheen",
1942
- characterOptions.material.sheen
1943
- );
1944
- this.characterMaterial.addInput(
1945
- characterValues.material,
1946
- "clearcoat",
1947
- characterOptions.material.clearcoat
1948
- );
1949
- this.characterMaterial.addInput(
1950
- characterValues.material,
1951
- "clearcoatRoughness",
1952
- characterOptions.material.clearcoatRoughness
1953
- );
1954
- this.characterMaterial.on("change", (e) => {
1955
- if (!e.presetKey) {
1956
- return;
1957
- }
1958
- if (e.presetKey === "specularColor") {
1959
- characterValues.material.specularColor = {
1960
- r: e.value.r,
1961
- g: e.value.g,
1962
- b: e.value.b
1963
- };
1964
- return;
1965
- }
1966
- if (e.presetKey === "emissive") {
1967
- characterValues.material.emissive = {
1968
- r: e.value.r,
1969
- g: e.value.g,
1970
- b: e.value.b
1971
- };
1972
- return;
1973
- }
1974
- if (e.presetKey === "sheenColor") {
1975
- characterValues.material.sheenColor = {
1976
- r: e.value.r,
1977
- g: e.value.g,
1978
- b: e.value.b
1979
- };
1980
- return;
1981
- }
1982
- });
2076
+ {
2077
+ this.characterMaterial = this.gui.addFolder({ title: "characterMaterial", expanded: false });
2078
+ this.characterMaterial.addInput(
2079
+ characterValues.material,
2080
+ "transmission",
2081
+ characterOptions.material.transmission
2082
+ );
2083
+ this.characterMaterial.addInput(
2084
+ characterValues.material,
2085
+ "metalness",
2086
+ characterOptions.material.metalness
2087
+ );
2088
+ this.characterMaterial.addInput(
2089
+ characterValues.material,
2090
+ "roughness",
2091
+ characterOptions.material.roughness
2092
+ );
2093
+ this.characterMaterial.addInput(
2094
+ characterValues.material,
2095
+ "ior",
2096
+ characterOptions.material.ior
2097
+ );
2098
+ this.characterMaterial.addInput(
2099
+ characterValues.material,
2100
+ "thickness",
2101
+ characterOptions.material.thickness
2102
+ );
2103
+ this.characterMaterial.addInput(characterValues.material, "specularColor", {
2104
+ color: { type: "float" }
2105
+ });
2106
+ this.characterMaterial.addInput(
2107
+ characterValues.material,
2108
+ "specularIntensity",
2109
+ characterOptions.material.specularIntensity
2110
+ );
2111
+ this.characterMaterial.addInput(characterValues.material, "emissive", {
2112
+ color: { type: "float" }
2113
+ });
2114
+ this.characterMaterial.addInput(
2115
+ characterValues.material,
2116
+ "emissiveIntensity",
2117
+ characterOptions.material.emissiveIntensity
2118
+ );
2119
+ this.characterMaterial.addInput(
2120
+ characterValues.material,
2121
+ "envMapIntensity",
2122
+ characterOptions.material.envMapIntensity
2123
+ );
2124
+ this.characterMaterial.addInput(characterValues.material, "sheenColor", {
2125
+ color: { type: "float" }
2126
+ });
2127
+ this.characterMaterial.addInput(
2128
+ characterValues.material,
2129
+ "sheen",
2130
+ characterOptions.material.sheen
2131
+ );
2132
+ this.characterMaterial.addInput(
2133
+ characterValues.material,
2134
+ "clearcoat",
2135
+ characterOptions.material.clearcoat
2136
+ );
2137
+ this.characterMaterial.addInput(
2138
+ characterValues.material,
2139
+ "clearcoatRoughness",
2140
+ characterOptions.material.clearcoatRoughness
2141
+ );
2142
+ this.characterMaterial.on("change", (e) => {
2143
+ if (!e.presetKey) {
2144
+ return;
2145
+ }
2146
+ if (e.presetKey === "specularColor") {
2147
+ characterValues.material.specularColor = {
2148
+ r: e.value.r,
2149
+ g: e.value.g,
2150
+ b: e.value.b
2151
+ };
2152
+ return;
2153
+ }
2154
+ if (e.presetKey === "emissive") {
2155
+ characterValues.material.emissive = {
2156
+ r: e.value.r,
2157
+ g: e.value.g,
2158
+ b: e.value.b
2159
+ };
2160
+ return;
2161
+ }
2162
+ if (e.presetKey === "sheenColor") {
2163
+ characterValues.material.sheenColor = {
2164
+ r: e.value.r,
2165
+ g: e.value.g,
2166
+ b: e.value.b
2167
+ };
2168
+ return;
2169
+ }
2170
+ });
2171
+ }
2172
+ this.environment = this.gui.addFolder({ title: "environment", expanded: false });
2173
+ this.sun = this.environment.addFolder({ title: "sun", expanded: true });
2174
+ this.ambient = this.environment.addFolder({ title: "ambient", expanded: true });
1983
2175
  this.export = this.gui.addFolder({ title: "import/export", expanded: false });
1984
2176
  window.addEventListener("keydown", this.processKey.bind(this));
1985
2177
  this.setupGUIListeners.bind(this)();
@@ -1997,201 +2189,308 @@ var TweakPane = class {
1997
2189
  this.gui.element.addEventListener("mouseup", () => setTweakpaneActive(false));
1998
2190
  this.gui.element.addEventListener("mouseleave", () => setTweakpaneActive(false));
1999
2191
  }
2000
- setupRenderPane(ssaoEffect, toneMappingEffect, toneMappingPass, brightnessContrastSaturation, bloomEffect, gaussGrainEffect) {
2001
- this.stats.addMonitor(statsData, "triangles");
2002
- this.stats.addMonitor(statsData, "geometries");
2003
- this.stats.addMonitor(statsData, "textures");
2004
- this.stats.addMonitor(statsData, "shaders");
2005
- this.stats.addMonitor(statsData, "postPasses");
2006
- this.stats.addMonitor(statsData, "drawCalls");
2007
- this.stats.addMonitor(statsData, "rawDeltaTime");
2008
- this.stats.addMonitor(statsData, "deltaTime");
2009
- this.stats.addMonitor(statsData, "FPS");
2010
- this.renderOptions.addInput(
2011
- composerValues.renderer,
2012
- "shadowMap",
2013
- composerOptions.renderer.shadowMap
2014
- );
2015
- this.renderOptions.addMonitor(rendererBlades, "shadowMapType");
2016
- this.renderOptions.addInput(
2017
- composerValues.renderer,
2018
- "toneMapping",
2019
- composerOptions.renderer.toneMapping
2020
- );
2021
- this.renderOptions.addMonitor(rendererBlades, "toneMappingType");
2022
- this.renderOptions.addInput(
2023
- composerValues.renderer,
2024
- "exposure",
2025
- composerOptions.renderer.exposure
2026
- );
2027
- this.renderOptions.addInput(
2028
- composerValues.renderer,
2029
- "bgIntensity",
2030
- composerOptions.renderer.bgIntensity
2031
- );
2032
- this.renderOptions.addInput(
2033
- composerValues.renderer,
2034
- "bgBlurriness",
2035
- composerOptions.renderer.bgBlurriness
2036
- );
2037
- this.renderOptions.on("change", (e) => {
2038
- const target = e.target;
2039
- switch (target.label) {
2040
- case "shadowMap":
2041
- this.renderer.shadowMap.type = e.value;
2042
- setShadowMapType(e.value);
2043
- break;
2044
- case "toneMapping":
2045
- this.renderer.toneMapping = e.value;
2046
- this.toneMapping.hidden = e.value !== 5;
2047
- toneMappingPass.enabled = e.value === 5 ? true : false;
2048
- setToneMappingType(e.value);
2049
- break;
2050
- case "exposure":
2051
- this.renderer.toneMappingExposure = e.value;
2052
- break;
2053
- case "bgIntensity":
2054
- this.scene.backgroundIntensity = e.value;
2055
- break;
2056
- case "bgBlurriness":
2057
- this.scene.backgroundBlurriness = e.value;
2058
- break;
2059
- default:
2060
- break;
2061
- }
2062
- });
2063
- this.ssao.addInput({ showEffectOnly: false }, "showEffectOnly");
2064
- this.ssao.addInput(composerValues.ssao, "samples", composerOptions.ssao.samples);
2065
- this.ssao.addInput(composerValues.ssao, "rings", composerOptions.ssao.rings);
2066
- this.ssao.addInput(
2067
- composerValues.ssao,
2068
- "luminanceInfluence",
2069
- composerOptions.ssao.luminanceInfluence
2070
- );
2071
- this.ssao.addInput(composerValues.ssao, "radius", composerOptions.ssao.radius);
2072
- this.ssao.addInput(composerValues.ssao, "intensity", composerOptions.ssao.intensity);
2073
- this.ssao.addInput(composerValues.ssao, "bias", composerOptions.ssao.bias);
2074
- this.ssao.addInput(composerValues.ssao, "fade", composerOptions.ssao.fade);
2075
- this.ssao.addInput(
2076
- composerValues.ssao,
2077
- "resolutionScale",
2078
- composerOptions.ssao.resolutionScale
2079
- );
2080
- this.ssao.addInput(
2081
- composerValues.ssao,
2082
- "worldDistanceThreshold",
2083
- composerOptions.ssao.worldDistanceThreshold
2084
- );
2085
- this.ssao.addInput(
2086
- composerValues.ssao,
2087
- "worldDistanceFalloff",
2088
- composerOptions.ssao.worldDistanceFalloff
2089
- );
2090
- this.ssao.addInput(
2091
- composerValues.ssao,
2092
- "worldProximityThreshold",
2093
- composerOptions.ssao.worldProximityThreshold
2094
- );
2095
- this.ssao.addInput(
2096
- composerValues.ssao,
2097
- "worldProximityFalloff",
2098
- composerOptions.ssao.worldProximityFalloff
2099
- );
2100
- this.ssao.addInput(composerValues.ssao, "color", {
2101
- color: { alpha: false, type: "float" }
2102
- });
2103
- this.ssao.on("change", (e) => {
2104
- if (!e.presetKey) {
2105
- return;
2106
- }
2107
- const preset = e.presetKey;
2108
- if (preset === "showEffectOnly") {
2109
- ssaoEffect.blendMode.blendFunction = e.value === true ? BlendFunction2.NORMAL : BlendFunction2.MULTIPLY;
2110
- return;
2111
- }
2112
- if (preset === "resolutionScale") {
2113
- ssaoEffect.resolution.scale = e.value;
2114
- return;
2115
- }
2116
- if (ssaoMaterialParams.includes(e.presetKey)) {
2117
- ssaoEffect.ssaoMaterial[preset] = e.value;
2118
- return;
2119
- }
2120
- if (e.presetKey === "color") {
2121
- ssaoEffect.color = new Color4().setRGB(e.value.r, e.value.g, e.value.b);
2122
- return;
2123
- }
2124
- ssaoEffect[preset] = e.value;
2125
- });
2126
- this.toneMapping.addInput(composerValues.toneMapping, "mode", composerOptions.toneMapping.mode);
2127
- this.toneMapping.addMonitor(customToneMappingBlade, "customToneMappingType");
2128
- this.toneMapping.addInput(
2129
- composerValues.toneMapping,
2130
- "whitePoint",
2131
- composerOptions.toneMapping.whitePoint
2132
- );
2133
- this.toneMapping.addInput(
2134
- composerValues.toneMapping,
2135
- "middleGrey",
2136
- composerOptions.toneMapping.middleGrey
2137
- );
2138
- const minLuminance = this.toneMapping.addInput(
2139
- composerValues.toneMapping,
2140
- "minLuminance",
2141
- composerOptions.toneMapping.minLuminance
2142
- );
2143
- minLuminance.hidden = composerValues.toneMapping.mode === 2 ? true : false;
2144
- const averageLuminance = this.toneMapping.addInput(
2145
- composerValues.toneMapping,
2146
- "averageLuminance",
2147
- composerOptions.toneMapping.averageLuminance
2148
- );
2149
- averageLuminance.hidden = composerValues.toneMapping.mode === 2 ? true : false;
2150
- this.toneMapping.addInput(
2151
- composerValues.toneMapping,
2152
- "adaptationRate",
2153
- composerOptions.toneMapping.adaptationRate
2154
- );
2155
- this.toneMapping.on("change", (e) => {
2156
- if (!e.presetKey) {
2192
+ setupRenderPane(ssaoEffect, toneMappingEffect, toneMappingPass, brightnessContrastSaturation, bloomEffect, gaussGrainEffect, hasLighting, sun, setHDR, setAmbientLight, setFog) {
2193
+ {
2194
+ this.stats.addMonitor(statsData, "triangles");
2195
+ this.stats.addMonitor(statsData, "geometries");
2196
+ this.stats.addMonitor(statsData, "textures");
2197
+ this.stats.addMonitor(statsData, "shaders");
2198
+ this.stats.addMonitor(statsData, "postPasses");
2199
+ this.stats.addMonitor(statsData, "drawCalls");
2200
+ this.stats.addMonitor(statsData, "rawDeltaTime");
2201
+ this.stats.addMonitor(statsData, "deltaTime");
2202
+ this.stats.addMonitor(statsData, "FPS");
2203
+ }
2204
+ {
2205
+ this.renderOptions.addInput(
2206
+ composerValues.renderer,
2207
+ "shadowMap",
2208
+ composerOptions.renderer.shadowMap
2209
+ );
2210
+ this.renderOptions.addMonitor(rendererBlades, "shadowMapType");
2211
+ this.renderOptions.addInput(
2212
+ composerValues.renderer,
2213
+ "toneMapping",
2214
+ composerOptions.renderer.toneMapping
2215
+ );
2216
+ this.renderOptions.addMonitor(rendererBlades, "toneMappingType");
2217
+ this.renderOptions.addInput(
2218
+ composerValues.renderer,
2219
+ "exposure",
2220
+ composerOptions.renderer.exposure
2221
+ );
2222
+ this.renderOptions.addInput(
2223
+ composerValues.renderer,
2224
+ "bgIntensity",
2225
+ composerOptions.renderer.bgIntensity
2226
+ );
2227
+ this.renderOptions.addInput(
2228
+ composerValues.renderer,
2229
+ "bgBlurriness",
2230
+ composerOptions.renderer.bgBlurriness
2231
+ );
2232
+ this.renderOptions.on("change", (e) => {
2233
+ const target = e.target;
2234
+ switch (target.label) {
2235
+ case "shadowMap":
2236
+ this.renderer.shadowMap.type = e.value;
2237
+ setShadowMapType(e.value);
2238
+ break;
2239
+ case "toneMapping":
2240
+ this.renderer.toneMapping = e.value;
2241
+ this.toneMapping.hidden = e.value !== 5;
2242
+ toneMappingPass.enabled = e.value === 5 ? true : false;
2243
+ setToneMappingType(e.value);
2244
+ break;
2245
+ case "exposure":
2246
+ this.renderer.toneMappingExposure = e.value;
2247
+ break;
2248
+ case "bgIntensity":
2249
+ this.scene.backgroundIntensity = e.value;
2250
+ break;
2251
+ case "bgBlurriness":
2252
+ this.scene.backgroundBlurriness = e.value;
2253
+ break;
2254
+ default:
2255
+ break;
2256
+ }
2257
+ });
2258
+ }
2259
+ {
2260
+ this.ssao.addInput({ showEffectOnly: false }, "showEffectOnly");
2261
+ this.ssao.addInput(composerValues.ssao, "samples", composerOptions.ssao.samples);
2262
+ this.ssao.addInput(composerValues.ssao, "rings", composerOptions.ssao.rings);
2263
+ this.ssao.addInput(
2264
+ composerValues.ssao,
2265
+ "luminanceInfluence",
2266
+ composerOptions.ssao.luminanceInfluence
2267
+ );
2268
+ this.ssao.addInput(composerValues.ssao, "radius", composerOptions.ssao.radius);
2269
+ this.ssao.addInput(composerValues.ssao, "intensity", composerOptions.ssao.intensity);
2270
+ this.ssao.addInput(composerValues.ssao, "bias", composerOptions.ssao.bias);
2271
+ this.ssao.addInput(composerValues.ssao, "fade", composerOptions.ssao.fade);
2272
+ this.ssao.addInput(
2273
+ composerValues.ssao,
2274
+ "resolutionScale",
2275
+ composerOptions.ssao.resolutionScale
2276
+ );
2277
+ this.ssao.addInput(
2278
+ composerValues.ssao,
2279
+ "worldDistanceThreshold",
2280
+ composerOptions.ssao.worldDistanceThreshold
2281
+ );
2282
+ this.ssao.addInput(
2283
+ composerValues.ssao,
2284
+ "worldDistanceFalloff",
2285
+ composerOptions.ssao.worldDistanceFalloff
2286
+ );
2287
+ this.ssao.addInput(
2288
+ composerValues.ssao,
2289
+ "worldProximityThreshold",
2290
+ composerOptions.ssao.worldProximityThreshold
2291
+ );
2292
+ this.ssao.addInput(
2293
+ composerValues.ssao,
2294
+ "worldProximityFalloff",
2295
+ composerOptions.ssao.worldProximityFalloff
2296
+ );
2297
+ this.ssao.addInput(composerValues.ssao, "color", {
2298
+ color: { alpha: false, type: "float" }
2299
+ });
2300
+ this.ssao.on("change", (e) => {
2301
+ if (!e.presetKey) {
2302
+ return;
2303
+ }
2304
+ const preset = e.presetKey;
2305
+ if (preset === "showEffectOnly") {
2306
+ ssaoEffect.blendMode.blendFunction = e.value === true ? BlendFunction2.NORMAL : BlendFunction2.MULTIPLY;
2307
+ return;
2308
+ }
2309
+ if (preset === "resolutionScale") {
2310
+ ssaoEffect.resolution.scale = e.value;
2311
+ return;
2312
+ }
2313
+ if (ssaoMaterialParams.includes(e.presetKey)) {
2314
+ ssaoEffect.ssaoMaterial[preset] = e.value;
2315
+ return;
2316
+ }
2317
+ if (e.presetKey === "color") {
2318
+ ssaoEffect.color = new Color5().setRGB(e.value.r, e.value.g, e.value.b);
2319
+ return;
2320
+ }
2321
+ ssaoEffect[preset] = e.value;
2322
+ });
2323
+ }
2324
+ {
2325
+ this.toneMapping.addInput(
2326
+ composerValues.toneMapping,
2327
+ "mode",
2328
+ composerOptions.toneMapping.mode
2329
+ );
2330
+ this.toneMapping.addMonitor(customToneMappingBlade, "customToneMappingType");
2331
+ this.toneMapping.addInput(
2332
+ composerValues.toneMapping,
2333
+ "whitePoint",
2334
+ composerOptions.toneMapping.whitePoint
2335
+ );
2336
+ this.toneMapping.addInput(
2337
+ composerValues.toneMapping,
2338
+ "middleGrey",
2339
+ composerOptions.toneMapping.middleGrey
2340
+ );
2341
+ const minLuminance = this.toneMapping.addInput(
2342
+ composerValues.toneMapping,
2343
+ "minLuminance",
2344
+ composerOptions.toneMapping.minLuminance
2345
+ );
2346
+ minLuminance.hidden = composerValues.toneMapping.mode === 2 ? true : false;
2347
+ const averageLuminance = this.toneMapping.addInput(
2348
+ composerValues.toneMapping,
2349
+ "averageLuminance",
2350
+ composerOptions.toneMapping.averageLuminance
2351
+ );
2352
+ averageLuminance.hidden = composerValues.toneMapping.mode === 2 ? true : false;
2353
+ this.toneMapping.addInput(
2354
+ composerValues.toneMapping,
2355
+ "adaptationRate",
2356
+ composerOptions.toneMapping.adaptationRate
2357
+ );
2358
+ this.toneMapping.on("change", (e) => {
2359
+ if (!e.presetKey) {
2360
+ return;
2361
+ }
2362
+ const preset = e.presetKey;
2363
+ if (preset === "mode") {
2364
+ minLuminance.hidden = composerValues.toneMapping.mode === 2 ? true : false;
2365
+ averageLuminance.hidden = composerValues.toneMapping.mode === 2 ? true : false;
2366
+ setCustomToneMappingType(e.value);
2367
+ }
2368
+ toneMappingEffect[preset] = e.value;
2157
2369
  return;
2158
- }
2159
- const preset = e.presetKey;
2160
- if (preset === "mode") {
2161
- minLuminance.hidden = composerValues.toneMapping.mode === 2 ? true : false;
2162
- averageLuminance.hidden = composerValues.toneMapping.mode === 2 ? true : false;
2163
- setCustomToneMappingType(e.value);
2164
- }
2165
- toneMappingEffect[preset] = e.value;
2166
- return;
2167
- });
2168
- this.post.addInput(composerValues, "brightness", composerOptions.brightness.amount);
2169
- this.post.addInput(composerValues, "contrast", composerOptions.contrast.amount);
2170
- this.post.addInput(composerValues, "saturation", composerOptions.saturation.amount);
2171
- this.post.addInput(composerValues, "bloom", composerOptions.bloom.amount);
2172
- this.post.addInput(composerValues, "grain", composerOptions.grain.amount);
2173
- this.post.on("change", (e) => {
2174
- const target = e.presetKey;
2175
- switch (target) {
2176
- case "brightness":
2177
- brightnessContrastSaturation.uniforms.brightness.value = e.value;
2178
- break;
2179
- case "contrast":
2180
- brightnessContrastSaturation.uniforms.contrast.value = e.value;
2181
- break;
2182
- case "saturation":
2183
- brightnessContrastSaturation.uniforms.saturation.value = e.value;
2184
- break;
2185
- case "bloom":
2186
- bloomEffect.intensity = e.value;
2187
- break;
2188
- case "grain":
2189
- gaussGrainEffect.uniforms.amount.value = e.value;
2190
- break;
2191
- default:
2192
- break;
2193
- }
2194
- });
2370
+ });
2371
+ }
2372
+ {
2373
+ this.post.addInput(composerValues, "brightness", composerOptions.brightness.amount);
2374
+ this.post.addInput(composerValues, "contrast", composerOptions.contrast.amount);
2375
+ this.post.addInput(composerValues, "saturation", composerOptions.saturation.amount);
2376
+ this.post.addInput(composerValues, "bloom", composerOptions.bloom.amount);
2377
+ this.post.addInput(composerValues, "grain", composerOptions.grain.amount);
2378
+ this.post.on("change", (e) => {
2379
+ const target = e.presetKey;
2380
+ switch (target) {
2381
+ case "brightness":
2382
+ brightnessContrastSaturation.uniforms.brightness.value = e.value;
2383
+ break;
2384
+ case "contrast":
2385
+ brightnessContrastSaturation.uniforms.contrast.value = e.value;
2386
+ break;
2387
+ case "saturation":
2388
+ brightnessContrastSaturation.uniforms.saturation.value = e.value;
2389
+ break;
2390
+ case "bloom":
2391
+ bloomEffect.intensity = e.value;
2392
+ break;
2393
+ case "grain":
2394
+ gaussGrainEffect.uniforms.amount.value = e.value;
2395
+ break;
2396
+ default:
2397
+ break;
2398
+ }
2399
+ });
2400
+ }
2401
+ {
2402
+ this.environment.hidden = hasLighting === false || sun === null;
2403
+ this.sun.addInput(
2404
+ sunValues.sunPosition,
2405
+ "sunAzimuthalAngle",
2406
+ sunOptions.sunPosition.sunAzimuthalAngle
2407
+ );
2408
+ this.sun.addInput(
2409
+ sunValues.sunPosition,
2410
+ "sunPolarAngle",
2411
+ sunOptions.sunPosition.sunPolarAngle
2412
+ );
2413
+ this.sun.addInput(sunValues, "sunIntensity", sunOptions.sunIntensity);
2414
+ this.sun.addInput(sunValues, "sunColor", {
2415
+ color: { type: "float" }
2416
+ });
2417
+ this.sunButton = this.sun.addButton({ title: "Set HDRI" });
2418
+ this.sunButton.on("click", () => {
2419
+ setHDR();
2420
+ });
2421
+ this.sun.on("change", (e) => {
2422
+ const target = e.presetKey;
2423
+ switch (target) {
2424
+ case "sunAzimuthalAngle":
2425
+ sun?.setAzimuthalAngle(e.value * (Math.PI / 180));
2426
+ break;
2427
+ case "sunPolarAngle":
2428
+ sun?.setPolarAngle(e.value * (Math.PI / 180));
2429
+ break;
2430
+ case "sunIntensity":
2431
+ sun?.setIntensity(e.value);
2432
+ break;
2433
+ case "sunColor":
2434
+ sunValues.sunColor = {
2435
+ r: e.value.r,
2436
+ g: e.value.g,
2437
+ b: e.value.b
2438
+ };
2439
+ sun?.setColor();
2440
+ break;
2441
+ default:
2442
+ break;
2443
+ }
2444
+ });
2445
+ this.ambient.addInput(
2446
+ envValues.ambientLight,
2447
+ "ambientLightIntensity",
2448
+ envOptions.ambientLight.ambientLightIntensity
2449
+ );
2450
+ this.ambient.addInput(envValues.ambientLight, "ambientLightColor", {
2451
+ color: { type: "float" }
2452
+ });
2453
+ this.ambient.addInput(envValues.fog, "fogNear", envOptions.fog.fogNear);
2454
+ this.ambient.addInput(envValues.fog, "fogFar", envOptions.fog.fogFar);
2455
+ this.ambient.addInput(envValues.fog, "fogColor", {
2456
+ color: { type: "float" }
2457
+ });
2458
+ this.ambient.on("change", (e) => {
2459
+ const target = e.presetKey;
2460
+ switch (target) {
2461
+ case "ambientLightIntensity":
2462
+ envValues.ambientLight.ambientLightIntensity = e.value;
2463
+ setAmbientLight();
2464
+ break;
2465
+ case "ambientLightColor":
2466
+ envValues.ambientLight.ambientLightColor = {
2467
+ r: e.value.r,
2468
+ g: e.value.g,
2469
+ b: e.value.b
2470
+ };
2471
+ setAmbientLight();
2472
+ break;
2473
+ case "fogNear":
2474
+ envValues.fog.fogNear = e.value;
2475
+ setFog();
2476
+ break;
2477
+ case "fogFar":
2478
+ envValues.fog.fogFar = e.value;
2479
+ setFog();
2480
+ break;
2481
+ case "fogColor":
2482
+ envValues.fog.fogColor = {
2483
+ r: e.value.r,
2484
+ g: e.value.g,
2485
+ b: e.value.b
2486
+ };
2487
+ setFog();
2488
+ break;
2489
+ default:
2490
+ break;
2491
+ }
2492
+ });
2493
+ }
2195
2494
  const exportButton = this.export.addButton({ title: "export" });
2196
2495
  exportButton.on("click", () => {
2197
2496
  this.downloadSettingsAsJSON(this.gui.exportPreset());
@@ -2414,7 +2713,7 @@ var GaussGrainEffect = new ShaderMaterial2({
2414
2713
 
2415
2714
  // src/rendering/composer.ts
2416
2715
  var Composer = class {
2417
- constructor(scene, camera) {
2716
+ constructor(scene, camera, spawnSun = false) {
2418
2717
  __publicField(this, "width", window.innerWidth);
2419
2718
  __publicField(this, "height", window.innerHeight);
2420
2719
  __publicField(this, "resolution", new Vector22(this.width, this.height));
@@ -2440,9 +2739,13 @@ var Composer = class {
2440
2739
  __publicField(this, "bcsPass");
2441
2740
  __publicField(this, "gaussGrainEffect", GaussGrainEffect);
2442
2741
  __publicField(this, "gaussGrainPass");
2742
+ __publicField(this, "ambientLight", null);
2743
+ __publicField(this, "sun", null);
2744
+ __publicField(this, "spawnSun");
2443
2745
  __publicField(this, "tweakPane");
2444
2746
  this.scene = scene;
2445
2747
  this.camera = camera;
2748
+ this.spawnSun = spawnSun;
2446
2749
  this.renderer = new WebGLRenderer3({
2447
2750
  powerPreference: "high-performance",
2448
2751
  antialias: false,
@@ -2455,6 +2758,8 @@ var Composer = class {
2455
2758
  this.renderer.shadowMap.type = composerValues.renderer.shadowMap;
2456
2759
  this.renderer.toneMapping = composerValues.renderer.toneMapping;
2457
2760
  this.renderer.toneMappingExposure = composerValues.renderer.exposure;
2761
+ this.setAmbientLight();
2762
+ this.setFog();
2458
2763
  document.body.appendChild(this.renderer.domElement);
2459
2764
  this.composer = new EffectComposer2(this.renderer, {
2460
2765
  frameBufferType: HalfFloatType
@@ -2482,7 +2787,7 @@ var Composer = class {
2482
2787
  bias: composerValues.ssao.bias,
2483
2788
  fade: composerValues.ssao.fade,
2484
2789
  resolutionScale: composerValues.ssao.resolutionScale,
2485
- color: new Color5().setRGB(composerValues.ssao.color.r, composerValues.ssao.color.g, composerValues.ssao.color.b),
2790
+ color: new Color6().setRGB(composerValues.ssao.color.r, composerValues.ssao.color.g, composerValues.ssao.color.b),
2486
2791
  worldDistanceThreshold: composerValues.ssao.worldDistanceThreshold,
2487
2792
  worldDistanceFalloff: composerValues.ssao.worldDistanceFalloff,
2488
2793
  worldProximityThreshold: composerValues.ssao.worldProximityThreshold,
@@ -2522,13 +2827,22 @@ var Composer = class {
2522
2827
  this.composer.addPass(this.toneMappingPass);
2523
2828
  this.composer.addPass(this.bcsPass);
2524
2829
  this.composer.addPass(this.gaussGrainPass);
2830
+ if (this.spawnSun === true) {
2831
+ this.sun = new Sun();
2832
+ this.scene.add(this.sun);
2833
+ }
2525
2834
  this.tweakPane.setupRenderPane(
2526
2835
  this.ssaoEffect,
2527
2836
  this.toneMappingEffect,
2528
2837
  this.toneMappingPass,
2529
2838
  this.bcs,
2530
2839
  this.bloomEffect,
2531
- this.gaussGrainEffect
2840
+ this.gaussGrainEffect,
2841
+ this.spawnSun,
2842
+ this.sun,
2843
+ this.setHDRIFromFile.bind(this),
2844
+ this.setAmbientLight.bind(this),
2845
+ this.setFog.bind(this)
2532
2846
  );
2533
2847
  window.addEventListener("resize", () => this.updateProjection());
2534
2848
  this.updateProjection();
@@ -2562,8 +2876,8 @@ var Composer = class {
2562
2876
  this.tweakPane.updateStats(timeManager);
2563
2877
  }
2564
2878
  }
2565
- useHDRI(url) {
2566
- if (this.isEnvHDRI || !this.renderer)
2879
+ useHDRI(url, fromFile = false) {
2880
+ if (this.isEnvHDRI && fromFile === false || !this.renderer)
2567
2881
  return;
2568
2882
  const pmremGenerator = new PMREMGenerator(this.renderer);
2569
2883
  new RGBELoader(new LoadingManager2()).load(
@@ -2588,6 +2902,52 @@ var Composer = class {
2588
2902
  }
2589
2903
  );
2590
2904
  }
2905
+ setHDRIFromFile() {
2906
+ if (!this.renderer)
2907
+ return;
2908
+ const fileInput = document.createElement("input");
2909
+ fileInput.type = "file";
2910
+ fileInput.accept = ".hdr";
2911
+ fileInput.addEventListener("change", () => {
2912
+ const file = fileInput.files?.[0];
2913
+ if (!file) {
2914
+ console.log("no file");
2915
+ return;
2916
+ }
2917
+ const fileURL = URL.createObjectURL(file);
2918
+ if (fileURL) {
2919
+ this.useHDRI(fileURL, true);
2920
+ URL.revokeObjectURL(fileURL);
2921
+ document.body.removeChild(fileInput);
2922
+ }
2923
+ });
2924
+ document.body.appendChild(fileInput);
2925
+ fileInput.click();
2926
+ }
2927
+ setFog() {
2928
+ const fogColor = new Color6().setRGB(
2929
+ envValues.fog.fogColor.r,
2930
+ envValues.fog.fogColor.g,
2931
+ envValues.fog.fogColor.b
2932
+ );
2933
+ this.scene.fog = new Fog(fogColor, envValues.fog.fogNear, envValues.fog.fogFar);
2934
+ }
2935
+ setAmbientLight() {
2936
+ if (this.ambientLight) {
2937
+ this.scene.remove(this.ambientLight);
2938
+ this.ambientLight.dispose();
2939
+ }
2940
+ const ambientLightColor = new Color6().setRGB(
2941
+ envValues.ambientLight.ambientLightColor.r,
2942
+ envValues.ambientLight.ambientLightColor.g,
2943
+ envValues.ambientLight.ambientLightColor.b
2944
+ );
2945
+ this.ambientLight = new AmbientLight(
2946
+ ambientLightColor,
2947
+ envValues.ambientLight.ambientLightIntensity
2948
+ );
2949
+ this.scene.add(this.ambientLight);
2950
+ }
2591
2951
  };
2592
2952
 
2593
2953
  // src/time/TimeManager.ts
@@ -2642,13 +3002,13 @@ import {
2642
3002
  getRelativePositionAndRotationRelativeToObject
2643
3003
  } from "mml-web";
2644
3004
  import {
2645
- Color as Color6,
3005
+ Color as Color7,
2646
3006
  DoubleSide,
2647
3007
  Euler,
2648
3008
  FrontSide as FrontSide2,
2649
3009
  Mesh as Mesh3,
2650
3010
  MeshStandardMaterial as MeshStandardMaterial2,
2651
- Vector3 as Vector37
3011
+ Vector3 as Vector38
2652
3012
  } from "three";
2653
3013
  import * as BufferGeometryUtils from "three/examples/jsm/utils/BufferGeometryUtils.js";
2654
3014
  import { MeshBVH, MeshBVHVisualizer } from "three-mesh-bvh";
@@ -2656,8 +3016,8 @@ var CollisionsManager = class {
2656
3016
  constructor(scene) {
2657
3017
  __publicField(this, "debug", false);
2658
3018
  __publicField(this, "scene");
2659
- __publicField(this, "tempVector", new Vector37());
2660
- __publicField(this, "tempVector2", new Vector37());
3019
+ __publicField(this, "tempVector", new Vector38());
3020
+ __publicField(this, "tempVector2", new Vector38());
2661
3021
  __publicField(this, "collisionMeshState", /* @__PURE__ */ new Map());
2662
3022
  __publicField(this, "collisionTrigger");
2663
3023
  this.scene = scene;
@@ -2680,7 +3040,7 @@ var CollisionsManager = class {
2680
3040
  group.traverse((child) => {
2681
3041
  if (child.type === "Mesh") {
2682
3042
  const mesh = child;
2683
- mesh.localToWorld(new Vector37());
3043
+ mesh.localToWorld(new Vector38());
2684
3044
  mesh.updateMatrixWorld();
2685
3045
  const clonedGeometry = mesh.geometry.clone();
2686
3046
  clonedGeometry.applyMatrix4(mesh.matrixWorld);
@@ -2707,7 +3067,7 @@ var CollisionsManager = class {
2707
3067
  );
2708
3068
  mergedMesh.geometry.boundsTree = meshBVH;
2709
3069
  const visualizer = new MeshBVHVisualizer(mergedMesh, 3);
2710
- visualizer.edgeMaterial.color = new Color6(255);
3070
+ visualizer.edgeMaterial.color = new Color7(255);
2711
3071
  visualizer.update();
2712
3072
  return { source: group, visualizer, meshBVH };
2713
3073
  }
@@ -2754,7 +3114,7 @@ var CollisionsManager = class {
2754
3114
  const distance = tri.closestPointToSegment(tempSegment, triPoint, capsulePoint);
2755
3115
  if (distance < radius) {
2756
3116
  const depth = radius - distance;
2757
- collisionPosition = new Vector37().copy(capsulePoint);
3117
+ collisionPosition = new Vector38().copy(capsulePoint);
2758
3118
  const direction = capsulePoint.sub(triPoint).normalize();
2759
3119
  tempSegment.start.addScaledVector(direction, depth);
2760
3120
  tempSegment.end.addScaledVector(direction, depth);
@@ -2794,6 +3154,7 @@ export {
2794
3154
  Composer,
2795
3155
  KeyInputManager,
2796
3156
  MMLCompositionScene,
3157
+ Sun,
2797
3158
  TimeManager
2798
3159
  };
2799
3160
  //# sourceMappingURL=index.js.map