minerender 2.1.0-alpha.27 → 2.1.0-alpha.29

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.
@@ -195,6 +195,7 @@ __export(index_browser_exports, {
195
195
  SchematicParser: () => SchematicParser,
196
196
  SkinObject: () => SkinObject,
197
197
  SkinPart: () => SkinPart,
198
+ SkinTextures: () => SkinTextures,
198
199
  Skins: () => Skins,
199
200
  StructureParser: () => StructureParser,
200
201
  TextureAtlas: () => TextureAtlas,
@@ -1467,7 +1468,7 @@ var Models = class _Models {
1467
1468
  }
1468
1469
  static async getItemModel(key) {
1469
1470
  const itemKey = new AssetKey(key.namespace, key.path, "items", void 0, key.rootType, ".json", key.root);
1470
- const model = await this.PERSISTENT_CACHE.getOrLoad(itemKey.serialize(), async () => {
1471
+ const model = await this.PERSISTENT_CACHE.getOrLoad(AssetLoader.persistentKey(itemKey.serialize()), async () => {
1471
1472
  const result = await AssetLoader.getFirst([itemKey, key], "json" /* JSON */);
1472
1473
  if (!result) return void 0;
1473
1474
  if (result.key.assetType !== "items") return { ...result.asset, key };
@@ -1513,7 +1514,7 @@ var Models = class _Models {
1513
1514
  }
1514
1515
  const keyStr = key.serialize();
1515
1516
  return Caching.rawModelCache.get(keyStr, (k) => {
1516
- return this.PERSISTENT_CACHE.getOrLoad(keyStr, (k1) => {
1517
+ return this.PERSISTENT_CACHE.getOrLoad(AssetLoader.persistentKey(keyStr), (k1) => {
1517
1518
  return AssetLoader.get(key, "model" /* MODEL */);
1518
1519
  });
1519
1520
  }).then((asset) => {
@@ -1585,7 +1586,7 @@ var BlockStates = class {
1585
1586
  }
1586
1587
  const keyStr = key.serialize();
1587
1588
  return Caching.blockStateCache.get(keyStr, (k) => {
1588
- return this.PERSISTENT_CACHE.getOrLoad(keyStr, (k1) => {
1589
+ return this.PERSISTENT_CACHE.getOrLoad(AssetLoader.persistentKey(keyStr), (k1) => {
1589
1590
  return AssetLoader.get(key, "blockstate" /* BLOCKSTATE */);
1590
1591
  });
1591
1592
  }).then((asset) => {
@@ -1631,6 +1632,14 @@ var Assets = class {
1631
1632
  var AssetSource = class {
1632
1633
  constructor() {
1633
1634
  }
1635
+ /**
1636
+ * Identifies this source's content across sessions for persistent caching. Sources that
1637
+ * cannot tell whether their content changed (an unnamed archive, for example) return
1638
+ * undefined, which keeps their results out of long-lived caches.
1639
+ */
1640
+ get cacheId() {
1641
+ return void 0;
1642
+ }
1634
1643
  };
1635
1644
  var AssetLoadError = class extends Error {
1636
1645
  constructor(source, key, path, cause) {
@@ -1843,6 +1852,9 @@ var _HostedAssetSource = class _HostedAssetSource extends AssetSource {
1843
1852
  get root() {
1844
1853
  return this._root;
1845
1854
  }
1855
+ get cacheId() {
1856
+ return `hosted:${this._root}`;
1857
+ }
1846
1858
  get options() {
1847
1859
  return this._options;
1848
1860
  }
@@ -1919,9 +1931,10 @@ var HostedAssetSource = _HostedAssetSource;
1919
1931
  // src/assets/source/archive/BrowserArchiveProxy.ts
1920
1932
  var import_zip = require("@zip.js/zip.js");
1921
1933
  var BrowserArchiveProxy = class {
1922
- constructor(blob) {
1934
+ constructor(blob, id) {
1923
1935
  this._blob = blob;
1924
1936
  this._reader = new import_zip.ZipReader(new import_zip.BlobReader(this._blob));
1937
+ this.id = id ?? (typeof File !== "undefined" && blob instanceof File ? `${blob.name}:${blob.size}:${blob.lastModified}` : void 0);
1925
1938
  }
1926
1939
  async getEntries() {
1927
1940
  return (await this._reader.getEntries()).map((e) => {
@@ -1946,6 +1959,10 @@ var ArchiveAssetSource = class _ArchiveAssetSource extends AssetSource {
1946
1959
  static blob(blob) {
1947
1960
  return new _ArchiveAssetSource(new BrowserArchiveProxy(blob));
1948
1961
  }
1962
+ get cacheId() {
1963
+ const id = this._archiveProxy.id;
1964
+ return id === void 0 ? void 0 : `archive:${id}`;
1965
+ }
1949
1966
  async getEntries() {
1950
1967
  return this._archiveProxy.getEntries();
1951
1968
  }
@@ -1988,6 +2005,7 @@ var ArchiveAssetSource = class _ArchiveAssetSource extends AssetSource {
1988
2005
 
1989
2006
  // src/assets/AssetLoader.ts
1990
2007
  var p4 = prefix("AssetLoader");
2008
+ var FALLBACK_ROOT = "https://raw.githubusercontent.com/InventivetalentDev/minerender-fallback-assets/master";
1991
2009
  var _AssetLoader = class _AssetLoader {
1992
2010
  static get version() {
1993
2011
  return this.ROOT.substring(this.ROOT.lastIndexOf("/") + 1);
@@ -2003,6 +2021,28 @@ var _AssetLoader = class _AssetLoader {
2003
2021
  }
2004
2022
  Caching.clear();
2005
2023
  }
2024
+ /**
2025
+ * Scope for persistent cache keys. Empty with only the default vanilla sources, so their
2026
+ * entries stay valid across sessions; otherwise it names every added source (resource packs,
2027
+ * mirrors) so their results never masquerade as vanilla assets after a reload.
2028
+ */
2029
+ static get persistentScope() {
2030
+ const parts = [];
2031
+ for (const { key, source } of this._SOURCES) {
2032
+ const id = source.cacheId;
2033
+ if (key === "mcassets" && id === `hosted:${this.ROOT}`) continue;
2034
+ if (key === "mcassets-fallback" && id === `hosted:${FALLBACK_ROOT}`) continue;
2035
+ if (id === void 0) return this.SESSION_SCOPE;
2036
+ parts.push(`${key}=${id}`);
2037
+ }
2038
+ return parts.join("|");
2039
+ }
2040
+ /** Prefixes a persistent cache key with the current source scope. */
2041
+ static persistentKey(key) {
2042
+ const scope = this.persistentScope;
2043
+ return scope ? `${scope}
2044
+ ${key}` : key;
2045
+ }
2006
2046
  static addSource(key, source, override = true) {
2007
2047
  if (override) {
2008
2048
  const existing = this.removeSource(key);
@@ -2064,7 +2104,9 @@ var _AssetLoader = class _AssetLoader {
2064
2104
  };
2065
2105
  _AssetLoader.ROOT = DEFAULT_ROOT;
2066
2106
  _AssetLoader._SOURCES = [];
2067
- _AssetLoader.addSource("mcassets-fallback", new HostedAssetSource("https://raw.githubusercontent.com/InventivetalentDev/minerender-fallback-assets/master", { retryDefaults: false }));
2107
+ /** Used when a registered source cannot identify its content, so nothing persists past this session. */
2108
+ _AssetLoader.SESSION_SCOPE = `session:${Date.now().toString(36)}:${Math.random().toString(36).slice(2)}`;
2109
+ _AssetLoader.addSource("mcassets-fallback", new HostedAssetSource(FALLBACK_ROOT, { retryDefaults: false }));
2068
2110
  _AssetLoader.addSource("mcassets", new HostedAssetSource(_AssetLoader.ROOT, { retryDefaults: false }));
2069
2111
  var AssetLoader = _AssetLoader;
2070
2112
 
@@ -2107,7 +2149,7 @@ var ModelTextures = class {
2107
2149
  }
2108
2150
  const keyStr = key.serialize();
2109
2151
  return Caching.textureMetaCache.get(keyStr, (k) => {
2110
- return this.PERSISTENT_META_CACHE.getOrLoad(keyStr, (k1) => {
2152
+ return this.PERSISTENT_META_CACHE.getOrLoad(AssetLoader.persistentKey(keyStr), (k1) => {
2111
2153
  return AssetLoader.get(key, "meta" /* META */).then((asset) => {
2112
2154
  if (asset)
2113
2155
  asset.key = key;
@@ -4754,7 +4796,9 @@ var _BlockObject = class _BlockObject extends SceneObject {
4754
4796
  if (typeof variant.y !== "undefined") {
4755
4797
  rotation.y = toRadians(clampRotationDegrees(typeof variant.x !== "undefined" ? variant.y : 360 - variant.y));
4756
4798
  }
4757
- const model = await Models.getMerged(AssetKey.parse("models", variant.model));
4799
+ const modelKey = AssetKey.parse("models", variant.model);
4800
+ modelKey.root = this.blockState.key?.root;
4801
+ const model = await Models.getMerged(modelKey);
4758
4802
  const options = {
4759
4803
  ...this.options,
4760
4804
  tints: model ? await BlockTints.get(this.blockState.key, this.state, model, this.options.tints) : this.options.tints,
@@ -4913,7 +4957,7 @@ var StructureParser = class {
4913
4957
  };
4914
4958
 
4915
4959
  // src/renderer/MineRenderScene.ts
4916
- var import_three18 = require("three");
4960
+ var import_three19 = require("three");
4917
4961
  var import_ts_deepmerge8 = __toESM(require_dist());
4918
4962
 
4919
4963
  // src/skin/SkinPart.ts
@@ -5550,56 +5594,12 @@ var baseSkinCoordinates = {
5550
5594
  }
5551
5595
  },
5552
5596
  cape: {
5553
- //TODO
5554
- east: {
5555
- uv: [
5556
- 0,
5557
- 36,
5558
- 4,
5559
- 48
5560
- ]
5561
- },
5562
- west: {
5563
- uv: [
5564
- 8,
5565
- 36,
5566
- 12,
5567
- 48
5568
- ]
5569
- },
5570
- north: {
5571
- uv: [
5572
- 4,
5573
- 36,
5574
- 8,
5575
- 48
5576
- ]
5577
- },
5578
- south: {
5579
- uv: [
5580
- 12,
5581
- 36,
5582
- 16,
5583
- 48
5584
- ]
5585
- },
5586
- up: {
5587
- uv: [
5588
- 4,
5589
- 32,
5590
- 8,
5591
- 36
5592
- ]
5593
- },
5594
- down: {
5595
- uv: [
5596
- 8,
5597
- 32,
5598
- 12,
5599
- 36
5600
- ],
5601
- rotation: 180
5602
- }
5597
+ east: { uv: [0, 1, 1, 17] },
5598
+ west: { uv: [11, 1, 12, 17] },
5599
+ north: { uv: [1, 1, 11, 17] },
5600
+ south: { uv: [12, 1, 22, 17] },
5601
+ up: { uv: [11, 1, 1, 0] },
5602
+ down: { uv: [21, 0, 11, 1] }
5603
5603
  }
5604
5604
  };
5605
5605
  var classicSkinTextureCoordinates = {
@@ -5680,14 +5680,110 @@ var slimSkinGeometries = {
5680
5680
 
5681
5681
  // src/skin/scene/SkinObject.ts
5682
5682
  var import_ts_deepmerge7 = __toESM(require_dist());
5683
+
5684
+ // src/skin/SkinTextures.ts
5685
+ var import_three18 = require("three");
5686
+ var SkinTextures = class {
5687
+ static async get(src, legacy) {
5688
+ const image = await ImageLoader.getData(src);
5689
+ const scale = image.width / 64;
5690
+ if (!Number.isInteger(scale) || scale < 1 || image.height !== image.width && image.height !== image.width / 2) {
5691
+ throw new MineRenderError(`Invalid skin dimensions ${image.width}x${image.height}; expected 64x64 or 64x32, or an integer-scaled equivalent`);
5692
+ }
5693
+ const isLegacy = legacy ?? image.height === image.width / 2;
5694
+ if (!isLegacy && image.height !== image.width) {
5695
+ throw new MineRenderError(`Invalid skin dimensions ${image.width}x${image.height}; non-legacy skins must be square`);
5696
+ }
5697
+ const slim = !isLegacy && this.isSlim(image, scale);
5698
+ const key = `skin:${serializeImageKey({ src })}:${isLegacy}`;
5699
+ const material = Caching.materialCache.get(key, () => {
5700
+ const pixels = isLegacy ? this.normalizeLegacy(image, scale) : new Uint8Array(image.data);
5701
+ return this.createMaterial(pixels, image.width, image.width);
5702
+ });
5703
+ return { material, slim, legacy: isLegacy };
5704
+ }
5705
+ static async getCape(src) {
5706
+ const image = await ImageLoader.getData(src);
5707
+ const scale = image.width / 64;
5708
+ if (!Number.isInteger(scale) || scale < 1 || image.height !== image.width / 2) {
5709
+ throw new MineRenderError(`Invalid cape dimensions ${image.width}x${image.height}; expected 64x32 or an integer-scaled equivalent`);
5710
+ }
5711
+ return Caching.materialCache.get(`cape:${serializeImageKey({ src })}`, () => {
5712
+ return this.createMaterial(new Uint8Array(image.data), image.width, image.height, false);
5713
+ });
5714
+ }
5715
+ static createMaterial(pixels, width, height, transparent = true) {
5716
+ const texture = Textures.initTextureProps(new import_three18.DataTexture(pixels, width, height));
5717
+ texture.colorSpace = import_three18.SRGBColorSpace;
5718
+ texture.flipY = true;
5719
+ texture.needsUpdate = true;
5720
+ return new import_three18.MeshBasicMaterial({ map: texture, transparent, side: transparent ? import_three18.DoubleSide : import_three18.FrontSide, alphaTest: transparent ? 0.5 : 0 });
5721
+ }
5722
+ static isSlim(image, scale) {
5723
+ for (const [x, y] of [[46, 52], [54, 20]]) {
5724
+ for (let row = y * scale; row < (y + 12) * scale; row++) {
5725
+ for (let column = x * scale; column < (x + 1) * scale; column++) {
5726
+ if (image.data[(row * image.width + column) * 4 + 3] !== 0) return false;
5727
+ }
5728
+ }
5729
+ }
5730
+ return true;
5731
+ }
5732
+ static normalizeLegacy(image, scale) {
5733
+ const pixels = new Uint8Array(image.width * image.width * 4);
5734
+ pixels.set(image.data.subarray(0, image.width * image.width / 2 * 4));
5735
+ for (const [sx, sy, dx, dy, width, height] of [
5736
+ [4, 16, 20, 48, 4, 4],
5737
+ [8, 16, 24, 48, 4, 4],
5738
+ [0, 20, 24, 52, 4, 12],
5739
+ [4, 20, 20, 52, 4, 12],
5740
+ [8, 20, 16, 52, 4, 12],
5741
+ [12, 20, 28, 52, 4, 12],
5742
+ [44, 16, 36, 48, 4, 4],
5743
+ [48, 16, 40, 48, 4, 4],
5744
+ [40, 20, 40, 52, 4, 12],
5745
+ [44, 20, 36, 52, 4, 12],
5746
+ [48, 20, 32, 52, 4, 12],
5747
+ [52, 20, 44, 52, 4, 12]
5748
+ ]) {
5749
+ for (let y = 0; y < height * scale; y++) {
5750
+ for (let x = 0; x < width * scale; x++) {
5751
+ const source = ((sy * scale + y) * image.width + sx * scale + x) * 4;
5752
+ const target = ((dy * scale + y) * image.width + (dx + width) * scale - 1 - x) * 4;
5753
+ pixels.set(image.data.subarray(source, source + 4), target);
5754
+ }
5755
+ }
5756
+ }
5757
+ let clearHat = true;
5758
+ for (let y = 0; y < 32 * scale; y++) {
5759
+ for (let x = 32 * scale; x < image.width; x++) {
5760
+ if (pixels[(y * image.width + x) * 4 + 3] < 128) clearHat = false;
5761
+ }
5762
+ }
5763
+ for (let y = 0; y < image.width; y++) {
5764
+ for (let x = 0; x < image.width; x++) {
5765
+ const alpha = (y * image.width + x) * 4 + 3;
5766
+ if (x < 32 * scale && y < 16 * scale || y >= 16 * scale && y < 32 * scale || x >= 16 * scale && x < 48 * scale && y >= 48 * scale) {
5767
+ pixels[alpha] = 255;
5768
+ } else if (clearHat && x >= 32 * scale && y < 32 * scale) {
5769
+ pixels[alpha] = 0;
5770
+ }
5771
+ }
5772
+ }
5773
+ return pixels;
5774
+ }
5775
+ };
5776
+
5777
+ // src/skin/scene/SkinObject.ts
5683
5778
  var SkinObject = class extends SceneObject {
5684
5779
  constructor(options) {
5685
5780
  super();
5686
5781
  this.slim = false;
5687
- this.legacy = false;
5688
- this.skinTextureWidth = 64;
5689
- this.skinTextureHeight = 64;
5782
+ this.detectedSlim = false;
5783
+ this.skinLoad = 0;
5784
+ this.capeLoad = 0;
5690
5785
  this.options = (0, import_ts_deepmerge7.default)({}, SceneObject.DEFAULT_OPTIONS, options ?? {});
5786
+ this.slim = this.options.slim ?? false;
5691
5787
  }
5692
5788
  async init() {
5693
5789
  this.createMeshes();
@@ -5696,15 +5792,13 @@ var SkinObject = class extends SceneObject {
5696
5792
  }
5697
5793
  createMeshes() {
5698
5794
  console.log("#createMeshes");
5699
- const mat = Materials.MISSING_TEXTURE;
5795
+ const mat = this.skinMaterial ?? Materials.MISSING_TEXTURE;
5700
5796
  {
5701
5797
  const headGroup = this.createAndAddGroup("head", 0, 28, 0, "y" /* Y */, -4);
5702
5798
  const headGeo = this.getBoxGeometry("head" /* HEAD */);
5703
5799
  const head = this.createAndAddMesh("head", headGroup, headGeo, mat, "y" /* Y */, 4);
5704
- if (!this.legacy) {
5705
- const hatGeo = this.getBoxGeometry("hat" /* HAT */);
5706
- const hat = this.createAndAddMesh("hat", headGroup, hatGeo, mat, "y" /* Y */, 4);
5707
- }
5800
+ const hatGeo = this.getBoxGeometry("hat" /* HAT */);
5801
+ const hat = this.createAndAddMesh("hat", headGroup, hatGeo, mat, "y" /* Y */, 4);
5708
5802
  }
5709
5803
  {
5710
5804
  const bodyGroup = this.createAndAddGroup("body", 0, 18, 0);
@@ -5747,21 +5841,58 @@ var SkinObject = class extends SceneObject {
5747
5841
  }
5748
5842
  console.log("#createMeshes done");
5749
5843
  }
5750
- setSkinTexture(src) {
5844
+ async setSkinTexture(src) {
5751
5845
  if (typeof src === "undefined") return;
5752
- const mat = Materials.getImage({
5753
- texture: { src },
5754
- transparent: true
5755
- });
5756
- for (let part of SKIN_PARTS) {
5757
- let mesh = this.getMeshByName(part);
5846
+ this.skinTextureSrc = src;
5847
+ const load = ++this.skinLoad;
5848
+ const texture = await SkinTextures.get(src, this.options.legacy);
5849
+ if (load !== this.skinLoad) return;
5850
+ this.skinMaterial = texture.material;
5851
+ this.detectedSlim = texture.slim;
5852
+ this.updateSlim(this.options.slim ?? this.detectedSlim);
5853
+ for (const part of SKIN_PARTS) {
5854
+ if (part === "cape" /* CAPE */) continue;
5855
+ const mesh = this.getMeshByName(part);
5758
5856
  if (mesh) {
5759
- mesh.material = mat;
5857
+ mesh.material = texture.material;
5760
5858
  }
5761
5859
  }
5860
+ this.notifyDirty();
5762
5861
  }
5763
- //TODO: cape
5862
+ /** Load a vanilla cape texture, or pass undefined to remove the cape. */
5863
+ async setCapeTexture(src) {
5864
+ const load = ++this.capeLoad;
5865
+ if (src === void 0) {
5866
+ const group = this.getGroupByName("cape" /* CAPE */);
5867
+ if (group) this.remove(group);
5868
+ this.notifyDirty();
5869
+ return;
5870
+ }
5871
+ const material = await SkinTextures.getCape(src);
5872
+ if (load !== this.capeLoad) return;
5873
+ const mesh = this.getMeshByName("cape" /* CAPE */);
5874
+ if (mesh) {
5875
+ mesh.material = material;
5876
+ } else {
5877
+ const group = this.createAndAddGroup("cape" /* CAPE */, 0, 24, 2);
5878
+ group.rotation.set(toRadians(-6), Math.PI, 0);
5879
+ const geometry = this._getBoxGeometryFromDimensions(
5880
+ classicSkinGeometries.cape,
5881
+ classicSkinTextureCoordinates.cape,
5882
+ [64, 32],
5883
+ [64, 32]
5884
+ );
5885
+ const cape = this.createAndAddMesh("cape" /* CAPE */, group, geometry, material);
5886
+ cape.position.set(0, -8, -0.5);
5887
+ }
5888
+ this.notifyDirty();
5889
+ }
5890
+ /** Select the arm model, or pass undefined to use texture detection. */
5764
5891
  setSlim(slim) {
5892
+ this.options.slim = slim;
5893
+ this.updateSlim(slim ?? this.detectedSlim);
5894
+ }
5895
+ updateSlim(slim) {
5765
5896
  if (slim === this.slim) return;
5766
5897
  this.slim = slim;
5767
5898
  for (const part of ["leftArm" /* LEFT_ARM */, "leftSleeve" /* LEFT_SLEEVE */, "rightArm" /* RIGHT_ARM */, "rightSleeve" /* RIGHT_SLEEVE */]) {
@@ -5775,22 +5906,28 @@ var SkinObject = class extends SceneObject {
5775
5906
  if (rightArm) rightArm.position.x -= offset;
5776
5907
  this.notifyDirty();
5777
5908
  }
5778
- setLegacy(legacy) {
5779
- if (legacy !== this.legacy) {
5780
- }
5781
- this.legacy = legacy;
5909
+ /** Select the texture layout, or pass undefined to detect it from image dimensions. */
5910
+ async setLegacy(legacy) {
5911
+ if (legacy === this.options.legacy) return;
5912
+ this.options.legacy = legacy;
5913
+ if (this.skinTextureSrc) await this.setSkinTexture(this.skinTextureSrc);
5914
+ }
5915
+ dispose() {
5916
+ this.skinLoad++;
5917
+ this.capeLoad++;
5918
+ super.dispose();
5782
5919
  }
5783
5920
  //TODO: layer toggles
5784
5921
  getBoxGeometry(part) {
5785
5922
  console.log("slim", this.slim);
5786
5923
  const coordinates = this.slim ? slimSkinTextureCoordinates : classicSkinTextureCoordinates;
5787
5924
  const geometries = this.slim ? slimSkinGeometries : classicSkinGeometries;
5788
- return this._getBoxGeometryFromDimensions(geometries[part], coordinates[part], [64, 64], [this.skinTextureWidth, this.skinTextureHeight]);
5925
+ return this._getBoxGeometryFromDimensions(geometries[part], coordinates[part], [64, 64], [64, 64]);
5789
5926
  }
5790
5927
  };
5791
5928
 
5792
5929
  // src/renderer/MineRenderScene.ts
5793
- var _MineRenderScene = class _MineRenderScene extends import_three18.Scene {
5930
+ var _MineRenderScene = class _MineRenderScene extends import_three19.Scene {
5794
5931
  constructor(options) {
5795
5932
  super();
5796
5933
  this.isMineRenderScene = true;
@@ -5895,10 +6032,10 @@ var _MineRenderScene = class _MineRenderScene extends import_three18.Scene {
5895
6032
  this.dirty = true;
5896
6033
  const obj = new SkinObject(options);
5897
6034
  obj.scene = this;
5898
- await obj.init();
5899
6035
  if (skin) {
5900
- obj.setSkinTexture(skin);
6036
+ await obj.setSkinTexture(skin);
5901
6037
  }
6038
+ await obj.init();
5902
6039
  parent.add(obj);
5903
6040
  return obj;
5904
6041
  }
@@ -5913,17 +6050,17 @@ function isMineRenderScene(obj) {
5913
6050
  }
5914
6051
 
5915
6052
  // src/renderer/Renderer.ts
5916
- var import_three20 = require("three");
6053
+ var import_three21 = require("three");
5917
6054
  var import_ts_deepmerge9 = __toESM(require_dist());
5918
6055
  var import_stats = __toESM(require("stats.js"));
5919
6056
  var import_postprocessing = require("postprocessing");
5920
6057
 
5921
6058
  // src/three/OrbitControls.js
5922
- var import_three19 = require("three");
6059
+ var import_three20 = require("three");
5923
6060
  var _changeEvent = { type: "change" };
5924
6061
  var _startEvent = { type: "start" };
5925
6062
  var _endEvent = { type: "end" };
5926
- var OrbitControls = class extends import_three19.EventDispatcher {
6063
+ var OrbitControls = class extends import_three20.EventDispatcher {
5927
6064
  constructor(object, domElement) {
5928
6065
  super();
5929
6066
  if (domElement === void 0) console.warn('THREE.OrbitControls: The second parameter "domElement" is now mandatory.');
@@ -5932,7 +6069,7 @@ var OrbitControls = class extends import_three19.EventDispatcher {
5932
6069
  this.domElement = domElement;
5933
6070
  this.domElement.style.touchAction = "none";
5934
6071
  this.enabled = true;
5935
- this.target = new import_three19.Vector3();
6072
+ this.target = new import_three20.Vector3();
5936
6073
  this.minDistance = 0;
5937
6074
  this.maxDistance = Infinity;
5938
6075
  this.minZoom = 0;
@@ -5954,8 +6091,8 @@ var OrbitControls = class extends import_three19.EventDispatcher {
5954
6091
  this.autoRotate = false;
5955
6092
  this.autoRotateSpeed = 2;
5956
6093
  this.keys = { LEFT: "ArrowLeft", UP: "ArrowUp", RIGHT: "ArrowRight", BOTTOM: "ArrowDown" };
5957
- this.mouseButtons = { LEFT: import_three19.MOUSE.ROTATE, MIDDLE: import_three19.MOUSE.DOLLY, RIGHT: import_three19.MOUSE.PAN };
5958
- this.touches = { ONE: import_three19.TOUCH.ROTATE, TWO: import_three19.TOUCH.DOLLY_PAN };
6094
+ this.mouseButtons = { LEFT: import_three20.MOUSE.ROTATE, MIDDLE: import_three20.MOUSE.DOLLY, RIGHT: import_three20.MOUSE.PAN };
6095
+ this.touches = { ONE: import_three20.TOUCH.ROTATE, TWO: import_three20.TOUCH.DOLLY_PAN };
5959
6096
  this.target0 = this.target.clone();
5960
6097
  this.position0 = this.object.position.clone();
5961
6098
  this.zoom0 = this.object.zoom;
@@ -5984,11 +6121,11 @@ var OrbitControls = class extends import_three19.EventDispatcher {
5984
6121
  state = STATE.NONE;
5985
6122
  };
5986
6123
  this.update = function() {
5987
- const offset = new import_three19.Vector3();
5988
- const quat = new import_three19.Quaternion().setFromUnitVectors(object.up, new import_three19.Vector3(0, 1, 0));
6124
+ const offset = new import_three20.Vector3();
6125
+ const quat = new import_three20.Quaternion().setFromUnitVectors(object.up, new import_three20.Vector3(0, 1, 0));
5989
6126
  const quatInverse = quat.clone().invert();
5990
- const lastPosition = new import_three19.Vector3();
5991
- const lastQuaternion = new import_three19.Quaternion();
6127
+ const lastPosition = new import_three20.Vector3();
6128
+ const lastQuaternion = new import_three20.Quaternion();
5992
6129
  const twoPI = 2 * Math.PI;
5993
6130
  return function update() {
5994
6131
  const position = scope.object.position;
@@ -6074,20 +6211,20 @@ var OrbitControls = class extends import_three19.EventDispatcher {
6074
6211
  };
6075
6212
  let state = STATE.NONE;
6076
6213
  const EPS = 1e-6;
6077
- const spherical = new import_three19.Spherical();
6078
- const sphericalDelta = new import_three19.Spherical();
6214
+ const spherical = new import_three20.Spherical();
6215
+ const sphericalDelta = new import_three20.Spherical();
6079
6216
  let scale = 1;
6080
- const panOffset = new import_three19.Vector3();
6217
+ const panOffset = new import_three20.Vector3();
6081
6218
  let zoomChanged = false;
6082
- const rotateStart = new import_three19.Vector2();
6083
- const rotateEnd = new import_three19.Vector2();
6084
- const rotateDelta = new import_three19.Vector2();
6085
- const panStart = new import_three19.Vector2();
6086
- const panEnd = new import_three19.Vector2();
6087
- const panDelta = new import_three19.Vector2();
6088
- const dollyStart = new import_three19.Vector2();
6089
- const dollyEnd = new import_three19.Vector2();
6090
- const dollyDelta = new import_three19.Vector2();
6219
+ const rotateStart = new import_three20.Vector2();
6220
+ const rotateEnd = new import_three20.Vector2();
6221
+ const rotateDelta = new import_three20.Vector2();
6222
+ const panStart = new import_three20.Vector2();
6223
+ const panEnd = new import_three20.Vector2();
6224
+ const panDelta = new import_three20.Vector2();
6225
+ const dollyStart = new import_three20.Vector2();
6226
+ const dollyEnd = new import_three20.Vector2();
6227
+ const dollyDelta = new import_three20.Vector2();
6091
6228
  const pointers = [];
6092
6229
  const pointerPositions = {};
6093
6230
  function getAutoRotationAngle() {
@@ -6103,7 +6240,7 @@ var OrbitControls = class extends import_three19.EventDispatcher {
6103
6240
  sphericalDelta.phi -= angle;
6104
6241
  }
6105
6242
  const panLeft = function() {
6106
- const v = new import_three19.Vector3();
6243
+ const v = new import_three20.Vector3();
6107
6244
  return function panLeft2(distance, objectMatrix) {
6108
6245
  v.setFromMatrixColumn(objectMatrix, 0);
6109
6246
  v.multiplyScalar(-distance);
@@ -6111,7 +6248,7 @@ var OrbitControls = class extends import_three19.EventDispatcher {
6111
6248
  };
6112
6249
  }();
6113
6250
  const panUp = function() {
6114
- const v = new import_three19.Vector3();
6251
+ const v = new import_three20.Vector3();
6115
6252
  return function panUp2(distance, objectMatrix) {
6116
6253
  if (scope.screenSpacePanning === true) {
6117
6254
  v.setFromMatrixColumn(objectMatrix, 1);
@@ -6124,7 +6261,7 @@ var OrbitControls = class extends import_three19.EventDispatcher {
6124
6261
  };
6125
6262
  }();
6126
6263
  const pan = function() {
6127
- const offset = new import_three19.Vector3();
6264
+ const offset = new import_three20.Vector3();
6128
6265
  return function pan2(deltaX, deltaY) {
6129
6266
  const element = scope.domElement;
6130
6267
  if (scope.object.isPerspectiveCamera) {
@@ -6373,12 +6510,12 @@ var OrbitControls = class extends import_three19.EventDispatcher {
6373
6510
  mouseAction = -1;
6374
6511
  }
6375
6512
  switch (mouseAction) {
6376
- case import_three19.MOUSE.DOLLY:
6513
+ case import_three20.MOUSE.DOLLY:
6377
6514
  if (scope.enableZoom === false) return;
6378
6515
  handleMouseDownDolly(event);
6379
6516
  state = STATE.DOLLY;
6380
6517
  break;
6381
- case import_three19.MOUSE.ROTATE:
6518
+ case import_three20.MOUSE.ROTATE:
6382
6519
  if (event.ctrlKey || event.metaKey || event.shiftKey) {
6383
6520
  if (scope.enablePan === false) return;
6384
6521
  handleMouseDownPan(event);
@@ -6389,7 +6526,7 @@ var OrbitControls = class extends import_three19.EventDispatcher {
6389
6526
  state = STATE.ROTATE;
6390
6527
  }
6391
6528
  break;
6392
- case import_three19.MOUSE.PAN:
6529
+ case import_three20.MOUSE.PAN:
6393
6530
  if (event.ctrlKey || event.metaKey || event.shiftKey) {
6394
6531
  if (scope.enableRotate === false) return;
6395
6532
  handleMouseDownRotate(event);
@@ -6445,12 +6582,12 @@ var OrbitControls = class extends import_three19.EventDispatcher {
6445
6582
  switch (pointers.length) {
6446
6583
  case 1:
6447
6584
  switch (scope.touches.ONE) {
6448
- case import_three19.TOUCH.ROTATE:
6585
+ case import_three20.TOUCH.ROTATE:
6449
6586
  if (scope.enableRotate === false) return;
6450
6587
  handleTouchStartRotate();
6451
6588
  state = STATE.TOUCH_ROTATE;
6452
6589
  break;
6453
- case import_three19.TOUCH.PAN:
6590
+ case import_three20.TOUCH.PAN:
6454
6591
  if (scope.enablePan === false) return;
6455
6592
  handleTouchStartPan();
6456
6593
  state = STATE.TOUCH_PAN;
@@ -6461,12 +6598,12 @@ var OrbitControls = class extends import_three19.EventDispatcher {
6461
6598
  break;
6462
6599
  case 2:
6463
6600
  switch (scope.touches.TWO) {
6464
- case import_three19.TOUCH.DOLLY_PAN:
6601
+ case import_three20.TOUCH.DOLLY_PAN:
6465
6602
  if (scope.enableZoom === false && scope.enablePan === false) return;
6466
6603
  handleTouchStartDollyPan();
6467
6604
  state = STATE.TOUCH_DOLLY_PAN;
6468
6605
  break;
6469
- case import_three19.TOUCH.DOLLY_ROTATE:
6606
+ case import_three20.TOUCH.DOLLY_ROTATE:
6470
6607
  if (scope.enableZoom === false && scope.enableRotate === false) return;
6471
6608
  handleTouchStartDollyRotate();
6472
6609
  state = STATE.TOUCH_DOLLY_ROTATE;
@@ -6533,7 +6670,7 @@ var OrbitControls = class extends import_three19.EventDispatcher {
6533
6670
  function trackPointer(event) {
6534
6671
  let position = pointerPositions[event.pointerId];
6535
6672
  if (position === void 0) {
6536
- position = new import_three19.Vector2();
6673
+ position = new import_three20.Vector2();
6537
6674
  pointerPositions[event.pointerId] = position;
6538
6675
  }
6539
6676
  position.set(event.pageX, event.pageY);
@@ -6553,10 +6690,10 @@ var MapControls = class extends OrbitControls {
6553
6690
  constructor(object, domElement) {
6554
6691
  super(object, domElement);
6555
6692
  this.screenSpacePanning = false;
6556
- this.mouseButtons.LEFT = import_three19.MOUSE.PAN;
6557
- this.mouseButtons.RIGHT = import_three19.MOUSE.ROTATE;
6558
- this.touches.ONE = import_three19.TOUCH.PAN;
6559
- this.touches.TWO = import_three19.TOUCH.DOLLY_ROTATE;
6693
+ this.mouseButtons.LEFT = import_three20.MOUSE.PAN;
6694
+ this.mouseButtons.RIGHT = import_three20.MOUSE.ROTATE;
6695
+ this.touches.ONE = import_three20.TOUCH.PAN;
6696
+ this.touches.TWO = import_three20.TOUCH.DOLLY_ROTATE;
6560
6697
  }
6561
6698
  };
6562
6699
 
@@ -6593,14 +6730,14 @@ var _Renderer = class _Renderer {
6593
6730
  switch (this.options.camera.type) {
6594
6731
  case "perspective":
6595
6732
  default:
6596
- return new import_three20.PerspectiveCamera(
6733
+ return new import_three21.PerspectiveCamera(
6597
6734
  this.options.camera.perspective.fov,
6598
6735
  this.options.camera.perspective.aspect ?? this.viewWidth / this.viewHeight,
6599
6736
  this.options.camera.near,
6600
6737
  this.options.camera.far
6601
6738
  );
6602
6739
  case "orthographic":
6603
- return new import_three20.OrthographicCamera(
6740
+ return new import_three21.OrthographicCamera(
6604
6741
  this.options.camera.orthographic.left ?? this.viewWidth / -2,
6605
6742
  this.options.camera.orthographic.right ?? this.viewWidth / 2,
6606
6743
  this.options.camera.orthographic.top ?? this.viewHeight / 2,
@@ -6611,7 +6748,7 @@ var _Renderer = class _Renderer {
6611
6748
  }
6612
6749
  }
6613
6750
  createRenderer() {
6614
- const renderer = new import_three20.WebGLRenderer({
6751
+ const renderer = new import_three21.WebGLRenderer({
6615
6752
  antialias: this.options.render.antialias,
6616
6753
  alpha: true,
6617
6754
  powerPreference: "high-performance",
@@ -6619,8 +6756,8 @@ var _Renderer = class _Renderer {
6619
6756
  });
6620
6757
  renderer.setClearColor(0, 0);
6621
6758
  renderer.shadowMap.enabled = true;
6622
- renderer.shadowMap.type = import_three20.PCFSoftShadowMap;
6623
- renderer.outputColorSpace = import_three20.SRGBColorSpace;
6759
+ renderer.shadowMap.type = import_three21.PCFSoftShadowMap;
6760
+ renderer.outputColorSpace = import_three21.SRGBColorSpace;
6624
6761
  renderer.setSize(this.viewWidth, this.viewHeight);
6625
6762
  return renderer;
6626
6763
  }
@@ -6654,20 +6791,20 @@ var _Renderer = class _Renderer {
6654
6791
  window["__THREE_DEVTOOLS__"].dispatchEvent(new CustomEvent("observe", { detail: this.scene }));
6655
6792
  }
6656
6793
  if (this.options.debug.grid) {
6657
- const gridHelper = new import_three20.GridHelper(128, 16);
6794
+ const gridHelper = new import_three21.GridHelper(128, 16);
6658
6795
  this._debugHelpers.push(gridHelper);
6659
6796
  this.scene.add(gridHelper);
6660
- const gridHelper2 = new import_three20.GridHelper(128, 16);
6797
+ const gridHelper2 = new import_three21.GridHelper(128, 16);
6661
6798
  this._debugHelpers.push(gridHelper2);
6662
6799
  gridHelper2.rotation.x = 90 * (Math.PI / 180);
6663
6800
  this.scene.add(gridHelper2);
6664
- const gridHelper3 = new import_three20.GridHelper(128, 16);
6801
+ const gridHelper3 = new import_three21.GridHelper(128, 16);
6665
6802
  this._debugHelpers.push(gridHelper3);
6666
6803
  gridHelper3.rotation.z = 90 * (Math.PI / 180);
6667
6804
  this.scene.add(gridHelper3);
6668
6805
  }
6669
6806
  if (this.options.debug.axes) {
6670
- const axesHelper = new import_three20.AxesHelper(64);
6807
+ const axesHelper = new import_three21.AxesHelper(64);
6671
6808
  this._debugHelpers.push(axesHelper);
6672
6809
  this.scene.add(axesHelper);
6673
6810
  }
@@ -6871,8 +7008,8 @@ _Renderer.DEFAULT_OPTIONS = (0, import_ts_deepmerge9.default)({}, {
6871
7008
  top: void 0,
6872
7009
  bottom: void 0
6873
7010
  },
6874
- position: new import_three20.Vector3(50, 50, 50),
6875
- lookingAt: new import_three20.Vector3(0, 0, 0)
7011
+ position: new import_three21.Vector3(50, 50, 50),
7012
+ lookingAt: new import_three21.Vector3(0, 0, 0)
6876
7013
  },
6877
7014
  render: {
6878
7015
  fpsLimit: 60,
@@ -7066,10 +7203,10 @@ var Skins = class {
7066
7203
  };
7067
7204
 
7068
7205
  // src/world/Chunk.ts
7069
- var import_three23 = require("three");
7206
+ var import_three24 = require("three");
7070
7207
 
7071
7208
  // src/world/MineRenderWorld.ts
7072
- var import_three22 = require("three");
7209
+ var import_three23 = require("three");
7073
7210
  var MineRenderWorld = class {
7074
7211
  constructor(scene) {
7075
7212
  this._size = 4;
@@ -7080,10 +7217,10 @@ var MineRenderWorld = class {
7080
7217
  }
7081
7218
  getBlockAt(posOrX, y, z) {
7082
7219
  if (typeof posOrX == "number") {
7083
- return this.getBlockAt(new import_three22.Vector3(posOrX, y, z));
7220
+ return this.getBlockAt(new import_three23.Vector3(posOrX, y, z));
7084
7221
  }
7085
7222
  if (isTripleArray(posOrX)) {
7086
- return this.getBlockAt(new import_three22.Vector3(posOrX[0], posOrX[1], posOrX[2]));
7223
+ return this.getBlockAt(new import_three23.Vector3(posOrX[0], posOrX[1], posOrX[2]));
7087
7224
  }
7088
7225
  const chunk = this.getChunkAt(posOrX);
7089
7226
  if (typeof chunk === "undefined") {
@@ -7094,10 +7231,10 @@ var MineRenderWorld = class {
7094
7231
  }
7095
7232
  async setBlockAt(posOrX, yOrBlock, z, block) {
7096
7233
  if (typeof posOrX == "number") {
7097
- return this.setBlockAt(new import_three22.Vector3(posOrX, yOrBlock, z), block);
7234
+ return this.setBlockAt(new import_three23.Vector3(posOrX, yOrBlock, z), block);
7098
7235
  }
7099
7236
  if (isTripleArray(posOrX)) {
7100
- return this.setBlockAt(new import_three22.Vector3(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
7237
+ return this.setBlockAt(new import_three23.Vector3(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
7101
7238
  }
7102
7239
  this.validatePosBounds(posOrX);
7103
7240
  const chunk = this.getOrCreateChunkAt(posOrX);
@@ -7143,14 +7280,14 @@ var MineRenderWorld = class {
7143
7280
  return this._chunks[index];
7144
7281
  }
7145
7282
  static worldToScenePosition(pos) {
7146
- return new import_three22.Vector3(
7283
+ return new import_three23.Vector3(
7147
7284
  pos.x * 16,
7148
7285
  pos.y * 16,
7149
7286
  pos.z * 16
7150
7287
  );
7151
7288
  }
7152
7289
  static sceneToWorldPosition(pos) {
7153
- return new import_three22.Vector3(
7290
+ return new import_three23.Vector3(
7154
7291
  pos.x / 16,
7155
7292
  pos.y / 16,
7156
7293
  pos.z / 16
@@ -7187,12 +7324,12 @@ var Chunk = class _Chunk {
7187
7324
  this.x = x;
7188
7325
  this.y = y;
7189
7326
  this.z = z;
7190
- let anchor = new import_three23.Object3D();
7327
+ let anchor = new import_three24.Object3D();
7191
7328
  this._anchor = anchor;
7192
7329
  scene.add(anchor);
7193
7330
  anchor.position.set(this.x * 256 + 128 - 8, this.y * 256 + 128 - 8, this.z * 256 + 128 - 8);
7194
7331
  addBox3WireframeToObject(
7195
- new import_three23.Box3(new import_three23.Vector3(0, 0, 0), new import_three23.Vector3(256, 256, 256)),
7332
+ new import_three24.Box3(new import_three24.Vector3(0, 0, 0), new import_three24.Vector3(256, 256, 256)),
7196
7333
  anchor,
7197
7334
  16776960,
7198
7335
  4
@@ -7200,10 +7337,10 @@ var Chunk = class _Chunk {
7200
7337
  }
7201
7338
  getBlockAt(posOrX, y, z) {
7202
7339
  if (typeof posOrX == "number") {
7203
- return this.getBlockAt(new import_three23.Vector3(posOrX, y, z));
7340
+ return this.getBlockAt(new import_three24.Vector3(posOrX, y, z));
7204
7341
  }
7205
7342
  if (isTripleArray(posOrX)) {
7206
- return this.getBlockAt(new import_three23.Vector3(posOrX[0], posOrX[1], posOrX[2]));
7343
+ return this.getBlockAt(new import_three24.Vector3(posOrX[0], posOrX[1], posOrX[2]));
7207
7344
  }
7208
7345
  const pos = this.worldPosToChunkPos(posOrX);
7209
7346
  const index = _Chunk.chunkPosToBlockIndex(pos);
@@ -7211,10 +7348,10 @@ var Chunk = class _Chunk {
7211
7348
  }
7212
7349
  async setBlockAt(posOrX, yOrBlock, z, block) {
7213
7350
  if (typeof posOrX == "number") {
7214
- return this.setBlockAt(new import_three23.Vector3(posOrX, yOrBlock, z), block);
7351
+ return this.setBlockAt(new import_three24.Vector3(posOrX, yOrBlock, z), block);
7215
7352
  }
7216
7353
  if (isTripleArray(posOrX)) {
7217
- return this.setBlockAt(new import_three23.Vector3(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
7354
+ return this.setBlockAt(new import_three24.Vector3(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
7218
7355
  }
7219
7356
  const worldPos = posOrX;
7220
7357
  const pos = this.worldPosToChunkPos(worldPos);
@@ -7260,7 +7397,7 @@ var Chunk = class _Chunk {
7260
7397
  }
7261
7398
  async clear() {
7262
7399
  let promises = [];
7263
- let pos = new import_three23.Vector3();
7400
+ let pos = new import_three24.Vector3();
7264
7401
  for (let x = 0; x < 16; x++) {
7265
7402
  for (let z = 0; z < 16; z++) {
7266
7403
  for (let y = 0; y < 16; y++) {
@@ -7279,14 +7416,14 @@ var Chunk = class _Chunk {
7279
7416
  return pos.y * 16 * 16 + pos.z * 16 + pos.x;
7280
7417
  }
7281
7418
  worldPosToChunkPos(pos) {
7282
- return new import_three23.Vector3(
7419
+ return new import_three24.Vector3(
7283
7420
  pos.x - this.x * 16,
7284
7421
  pos.y - this.y * 16,
7285
7422
  pos.z - this.z * 16
7286
7423
  );
7287
7424
  }
7288
7425
  chunkPosToWorldPos(pos) {
7289
- return new import_three23.Vector3(
7426
+ return new import_three24.Vector3(
7290
7427
  this.x * 16 + pos.x,
7291
7428
  this.y * 16 + pos.y,
7292
7429
  this.z * 16 + pos.z