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_node_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,
@@ -1473,7 +1474,7 @@ var Models = class _Models {
1473
1474
  }
1474
1475
  static async getItemModel(key) {
1475
1476
  const itemKey = new AssetKey(key.namespace, key.path, "items", void 0, key.rootType, ".json", key.root);
1476
- const model = await this.PERSISTENT_CACHE.getOrLoad(itemKey.serialize(), async () => {
1477
+ const model = await this.PERSISTENT_CACHE.getOrLoad(AssetLoader.persistentKey(itemKey.serialize()), async () => {
1477
1478
  const result = await AssetLoader.getFirst([itemKey, key], "json" /* JSON */);
1478
1479
  if (!result) return void 0;
1479
1480
  if (result.key.assetType !== "items") return { ...result.asset, key };
@@ -1519,7 +1520,7 @@ var Models = class _Models {
1519
1520
  }
1520
1521
  const keyStr = key.serialize();
1521
1522
  return Caching.rawModelCache.get(keyStr, (k) => {
1522
- return this.PERSISTENT_CACHE.getOrLoad(keyStr, (k1) => {
1523
+ return this.PERSISTENT_CACHE.getOrLoad(AssetLoader.persistentKey(keyStr), (k1) => {
1523
1524
  return AssetLoader.get(key, "model" /* MODEL */);
1524
1525
  });
1525
1526
  }).then((asset) => {
@@ -1591,7 +1592,7 @@ var BlockStates = class {
1591
1592
  }
1592
1593
  const keyStr = key.serialize();
1593
1594
  return Caching.blockStateCache.get(keyStr, (k) => {
1594
- return this.PERSISTENT_CACHE.getOrLoad(keyStr, (k1) => {
1595
+ return this.PERSISTENT_CACHE.getOrLoad(AssetLoader.persistentKey(keyStr), (k1) => {
1595
1596
  return AssetLoader.get(key, "blockstate" /* BLOCKSTATE */);
1596
1597
  });
1597
1598
  }).then((asset) => {
@@ -1637,6 +1638,14 @@ var Assets = class {
1637
1638
  var AssetSource = class {
1638
1639
  constructor() {
1639
1640
  }
1641
+ /**
1642
+ * Identifies this source's content across sessions for persistent caching. Sources that
1643
+ * cannot tell whether their content changed (an unnamed archive, for example) return
1644
+ * undefined, which keeps their results out of long-lived caches.
1645
+ */
1646
+ get cacheId() {
1647
+ return void 0;
1648
+ }
1640
1649
  };
1641
1650
  var AssetLoadError = class extends Error {
1642
1651
  constructor(source, key, path, cause) {
@@ -1925,6 +1934,9 @@ var HostedAssetSource = class _HostedAssetSource extends AssetSource {
1925
1934
  get root() {
1926
1935
  return this._root;
1927
1936
  }
1937
+ get cacheId() {
1938
+ return `hosted:${this._root}`;
1939
+ }
1928
1940
  get options() {
1929
1941
  return this._options;
1930
1942
  }
@@ -1940,9 +1952,10 @@ var HostedAssetSource = class _HostedAssetSource extends AssetSource {
1940
1952
  // src/assets/source/archive/BrowserArchiveProxy.ts
1941
1953
  var import_zip = require("@zip.js/zip.js");
1942
1954
  var BrowserArchiveProxy = class {
1943
- constructor(blob) {
1955
+ constructor(blob, id) {
1944
1956
  this._blob = blob;
1945
1957
  this._reader = new import_zip.ZipReader(new import_zip.BlobReader(this._blob));
1958
+ this.id = id ?? (typeof File !== "undefined" && blob instanceof File ? `${blob.name}:${blob.size}:${blob.lastModified}` : void 0);
1946
1959
  }
1947
1960
  async getEntries() {
1948
1961
  return (await this._reader.getEntries()).map((e) => {
@@ -1967,6 +1980,10 @@ var ArchiveAssetSource = class _ArchiveAssetSource extends AssetSource {
1967
1980
  static blob(blob) {
1968
1981
  return new _ArchiveAssetSource(new BrowserArchiveProxy(blob));
1969
1982
  }
1983
+ get cacheId() {
1984
+ const id = this._archiveProxy.id;
1985
+ return id === void 0 ? void 0 : `archive:${id}`;
1986
+ }
1970
1987
  async getEntries() {
1971
1988
  return this._archiveProxy.getEntries();
1972
1989
  }
@@ -2009,6 +2026,7 @@ var ArchiveAssetSource = class _ArchiveAssetSource extends AssetSource {
2009
2026
 
2010
2027
  // src/assets/AssetLoader.ts
2011
2028
  var p4 = prefix("AssetLoader");
2029
+ var FALLBACK_ROOT = "https://raw.githubusercontent.com/InventivetalentDev/minerender-fallback-assets/master";
2012
2030
  var AssetLoader = class {
2013
2031
  static {
2014
2032
  this.ROOT = DEFAULT_ROOT;
@@ -2016,6 +2034,10 @@ var AssetLoader = class {
2016
2034
  static {
2017
2035
  this._SOURCES = [];
2018
2036
  }
2037
+ static {
2038
+ /** Used when a registered source cannot identify its content, so nothing persists past this session. */
2039
+ this.SESSION_SCOPE = `session:${Date.now().toString(36)}:${Math.random().toString(36).slice(2)}`;
2040
+ }
2019
2041
  static get version() {
2020
2042
  return this.ROOT.substring(this.ROOT.lastIndexOf("/") + 1);
2021
2043
  }
@@ -2030,6 +2052,28 @@ var AssetLoader = class {
2030
2052
  }
2031
2053
  Caching.clear();
2032
2054
  }
2055
+ /**
2056
+ * Scope for persistent cache keys. Empty with only the default vanilla sources, so their
2057
+ * entries stay valid across sessions; otherwise it names every added source (resource packs,
2058
+ * mirrors) so their results never masquerade as vanilla assets after a reload.
2059
+ */
2060
+ static get persistentScope() {
2061
+ const parts = [];
2062
+ for (const { key, source } of this._SOURCES) {
2063
+ const id = source.cacheId;
2064
+ if (key === "mcassets" && id === `hosted:${this.ROOT}`) continue;
2065
+ if (key === "mcassets-fallback" && id === `hosted:${FALLBACK_ROOT}`) continue;
2066
+ if (id === void 0) return this.SESSION_SCOPE;
2067
+ parts.push(`${key}=${id}`);
2068
+ }
2069
+ return parts.join("|");
2070
+ }
2071
+ /** Prefixes a persistent cache key with the current source scope. */
2072
+ static persistentKey(key) {
2073
+ const scope = this.persistentScope;
2074
+ return scope ? `${scope}
2075
+ ${key}` : key;
2076
+ }
2033
2077
  static addSource(key, source, override = true) {
2034
2078
  if (override) {
2035
2079
  const existing = this.removeSource(key);
@@ -2051,7 +2095,7 @@ var AssetLoader = class {
2051
2095
  return void 0;
2052
2096
  }
2053
2097
  static {
2054
- this.addSource("mcassets-fallback", new HostedAssetSource("https://raw.githubusercontent.com/InventivetalentDev/minerender-fallback-assets/master", { retryDefaults: false }));
2098
+ this.addSource("mcassets-fallback", new HostedAssetSource(FALLBACK_ROOT, { retryDefaults: false }));
2055
2099
  this.addSource("mcassets", new HostedAssetSource(this.ROOT, { retryDefaults: false }));
2056
2100
  }
2057
2101
  static async getAll(key, parser) {
@@ -2133,7 +2177,7 @@ var ModelTextures = class {
2133
2177
  }
2134
2178
  const keyStr = key.serialize();
2135
2179
  return Caching.textureMetaCache.get(keyStr, (k) => {
2136
- return this.PERSISTENT_META_CACHE.getOrLoad(keyStr, (k1) => {
2180
+ return this.PERSISTENT_META_CACHE.getOrLoad(AssetLoader.persistentKey(keyStr), (k1) => {
2137
2181
  return AssetLoader.get(key, "meta" /* META */).then((asset) => {
2138
2182
  if (asset)
2139
2183
  asset.key = key;
@@ -4803,7 +4847,9 @@ var BlockObject = class _BlockObject extends SceneObject {
4803
4847
  if (typeof variant.y !== "undefined") {
4804
4848
  rotation.y = toRadians(clampRotationDegrees(typeof variant.x !== "undefined" ? variant.y : 360 - variant.y));
4805
4849
  }
4806
- const model = await Models.getMerged(AssetKey.parse("models", variant.model));
4850
+ const modelKey = AssetKey.parse("models", variant.model);
4851
+ modelKey.root = this.blockState.key?.root;
4852
+ const model = await Models.getMerged(modelKey);
4807
4853
  const options = {
4808
4854
  ...this.options,
4809
4855
  tints: model ? await BlockTints.get(this.blockState.key, this.state, model, this.options.tints) : this.options.tints,
@@ -4958,7 +5004,7 @@ var StructureParser = class {
4958
5004
  };
4959
5005
 
4960
5006
  // src/renderer/MineRenderScene.ts
4961
- var import_three18 = require("three");
5007
+ var import_three19 = require("three");
4962
5008
  var import_ts_deepmerge8 = __toESM(require_dist());
4963
5009
 
4964
5010
  // src/skin/SkinPart.ts
@@ -5595,56 +5641,12 @@ var baseSkinCoordinates = {
5595
5641
  }
5596
5642
  },
5597
5643
  cape: {
5598
- //TODO
5599
- east: {
5600
- uv: [
5601
- 0,
5602
- 36,
5603
- 4,
5604
- 48
5605
- ]
5606
- },
5607
- west: {
5608
- uv: [
5609
- 8,
5610
- 36,
5611
- 12,
5612
- 48
5613
- ]
5614
- },
5615
- north: {
5616
- uv: [
5617
- 4,
5618
- 36,
5619
- 8,
5620
- 48
5621
- ]
5622
- },
5623
- south: {
5624
- uv: [
5625
- 12,
5626
- 36,
5627
- 16,
5628
- 48
5629
- ]
5630
- },
5631
- up: {
5632
- uv: [
5633
- 4,
5634
- 32,
5635
- 8,
5636
- 36
5637
- ]
5638
- },
5639
- down: {
5640
- uv: [
5641
- 8,
5642
- 32,
5643
- 12,
5644
- 36
5645
- ],
5646
- rotation: 180
5647
- }
5644
+ east: { uv: [0, 1, 1, 17] },
5645
+ west: { uv: [11, 1, 12, 17] },
5646
+ north: { uv: [1, 1, 11, 17] },
5647
+ south: { uv: [12, 1, 22, 17] },
5648
+ up: { uv: [11, 1, 1, 0] },
5649
+ down: { uv: [21, 0, 11, 1] }
5648
5650
  }
5649
5651
  };
5650
5652
  var classicSkinTextureCoordinates = {
@@ -5725,14 +5727,110 @@ var slimSkinGeometries = {
5725
5727
 
5726
5728
  // src/skin/scene/SkinObject.ts
5727
5729
  var import_ts_deepmerge7 = __toESM(require_dist());
5730
+
5731
+ // src/skin/SkinTextures.ts
5732
+ var import_three18 = require("three");
5733
+ var SkinTextures = class {
5734
+ static async get(src, legacy) {
5735
+ const image = await ImageLoader.getData(src);
5736
+ const scale = image.width / 64;
5737
+ if (!Number.isInteger(scale) || scale < 1 || image.height !== image.width && image.height !== image.width / 2) {
5738
+ throw new MineRenderError(`Invalid skin dimensions ${image.width}x${image.height}; expected 64x64 or 64x32, or an integer-scaled equivalent`);
5739
+ }
5740
+ const isLegacy = legacy ?? image.height === image.width / 2;
5741
+ if (!isLegacy && image.height !== image.width) {
5742
+ throw new MineRenderError(`Invalid skin dimensions ${image.width}x${image.height}; non-legacy skins must be square`);
5743
+ }
5744
+ const slim = !isLegacy && this.isSlim(image, scale);
5745
+ const key = `skin:${serializeImageKey({ src })}:${isLegacy}`;
5746
+ const material = Caching.materialCache.get(key, () => {
5747
+ const pixels = isLegacy ? this.normalizeLegacy(image, scale) : new Uint8Array(image.data);
5748
+ return this.createMaterial(pixels, image.width, image.width);
5749
+ });
5750
+ return { material, slim, legacy: isLegacy };
5751
+ }
5752
+ static async getCape(src) {
5753
+ const image = await ImageLoader.getData(src);
5754
+ const scale = image.width / 64;
5755
+ if (!Number.isInteger(scale) || scale < 1 || image.height !== image.width / 2) {
5756
+ throw new MineRenderError(`Invalid cape dimensions ${image.width}x${image.height}; expected 64x32 or an integer-scaled equivalent`);
5757
+ }
5758
+ return Caching.materialCache.get(`cape:${serializeImageKey({ src })}`, () => {
5759
+ return this.createMaterial(new Uint8Array(image.data), image.width, image.height, false);
5760
+ });
5761
+ }
5762
+ static createMaterial(pixels, width, height, transparent = true) {
5763
+ const texture = Textures.initTextureProps(new import_three18.DataTexture(pixels, width, height));
5764
+ texture.colorSpace = import_three18.SRGBColorSpace;
5765
+ texture.flipY = true;
5766
+ texture.needsUpdate = true;
5767
+ return new import_three18.MeshBasicMaterial({ map: texture, transparent, side: transparent ? import_three18.DoubleSide : import_three18.FrontSide, alphaTest: transparent ? 0.5 : 0 });
5768
+ }
5769
+ static isSlim(image, scale) {
5770
+ for (const [x, y] of [[46, 52], [54, 20]]) {
5771
+ for (let row = y * scale; row < (y + 12) * scale; row++) {
5772
+ for (let column = x * scale; column < (x + 1) * scale; column++) {
5773
+ if (image.data[(row * image.width + column) * 4 + 3] !== 0) return false;
5774
+ }
5775
+ }
5776
+ }
5777
+ return true;
5778
+ }
5779
+ static normalizeLegacy(image, scale) {
5780
+ const pixels = new Uint8Array(image.width * image.width * 4);
5781
+ pixels.set(image.data.subarray(0, image.width * image.width / 2 * 4));
5782
+ for (const [sx, sy, dx, dy, width, height] of [
5783
+ [4, 16, 20, 48, 4, 4],
5784
+ [8, 16, 24, 48, 4, 4],
5785
+ [0, 20, 24, 52, 4, 12],
5786
+ [4, 20, 20, 52, 4, 12],
5787
+ [8, 20, 16, 52, 4, 12],
5788
+ [12, 20, 28, 52, 4, 12],
5789
+ [44, 16, 36, 48, 4, 4],
5790
+ [48, 16, 40, 48, 4, 4],
5791
+ [40, 20, 40, 52, 4, 12],
5792
+ [44, 20, 36, 52, 4, 12],
5793
+ [48, 20, 32, 52, 4, 12],
5794
+ [52, 20, 44, 52, 4, 12]
5795
+ ]) {
5796
+ for (let y = 0; y < height * scale; y++) {
5797
+ for (let x = 0; x < width * scale; x++) {
5798
+ const source = ((sy * scale + y) * image.width + sx * scale + x) * 4;
5799
+ const target = ((dy * scale + y) * image.width + (dx + width) * scale - 1 - x) * 4;
5800
+ pixels.set(image.data.subarray(source, source + 4), target);
5801
+ }
5802
+ }
5803
+ }
5804
+ let clearHat = true;
5805
+ for (let y = 0; y < 32 * scale; y++) {
5806
+ for (let x = 32 * scale; x < image.width; x++) {
5807
+ if (pixels[(y * image.width + x) * 4 + 3] < 128) clearHat = false;
5808
+ }
5809
+ }
5810
+ for (let y = 0; y < image.width; y++) {
5811
+ for (let x = 0; x < image.width; x++) {
5812
+ const alpha = (y * image.width + x) * 4 + 3;
5813
+ if (x < 32 * scale && y < 16 * scale || y >= 16 * scale && y < 32 * scale || x >= 16 * scale && x < 48 * scale && y >= 48 * scale) {
5814
+ pixels[alpha] = 255;
5815
+ } else if (clearHat && x >= 32 * scale && y < 32 * scale) {
5816
+ pixels[alpha] = 0;
5817
+ }
5818
+ }
5819
+ }
5820
+ return pixels;
5821
+ }
5822
+ };
5823
+
5824
+ // src/skin/scene/SkinObject.ts
5728
5825
  var SkinObject = class extends SceneObject {
5729
5826
  constructor(options) {
5730
5827
  super();
5731
5828
  this.slim = false;
5732
- this.legacy = false;
5733
- this.skinTextureWidth = 64;
5734
- this.skinTextureHeight = 64;
5829
+ this.detectedSlim = false;
5830
+ this.skinLoad = 0;
5831
+ this.capeLoad = 0;
5735
5832
  this.options = (0, import_ts_deepmerge7.default)({}, SceneObject.DEFAULT_OPTIONS, options ?? {});
5833
+ this.slim = this.options.slim ?? false;
5736
5834
  }
5737
5835
  async init() {
5738
5836
  this.createMeshes();
@@ -5741,15 +5839,13 @@ var SkinObject = class extends SceneObject {
5741
5839
  }
5742
5840
  createMeshes() {
5743
5841
  console.log("#createMeshes");
5744
- const mat = Materials.MISSING_TEXTURE;
5842
+ const mat = this.skinMaterial ?? Materials.MISSING_TEXTURE;
5745
5843
  {
5746
5844
  const headGroup = this.createAndAddGroup("head", 0, 28, 0, "y" /* Y */, -4);
5747
5845
  const headGeo = this.getBoxGeometry("head" /* HEAD */);
5748
5846
  const head = this.createAndAddMesh("head", headGroup, headGeo, mat, "y" /* Y */, 4);
5749
- if (!this.legacy) {
5750
- const hatGeo = this.getBoxGeometry("hat" /* HAT */);
5751
- const hat = this.createAndAddMesh("hat", headGroup, hatGeo, mat, "y" /* Y */, 4);
5752
- }
5847
+ const hatGeo = this.getBoxGeometry("hat" /* HAT */);
5848
+ const hat = this.createAndAddMesh("hat", headGroup, hatGeo, mat, "y" /* Y */, 4);
5753
5849
  }
5754
5850
  {
5755
5851
  const bodyGroup = this.createAndAddGroup("body", 0, 18, 0);
@@ -5792,21 +5888,58 @@ var SkinObject = class extends SceneObject {
5792
5888
  }
5793
5889
  console.log("#createMeshes done");
5794
5890
  }
5795
- setSkinTexture(src) {
5891
+ async setSkinTexture(src) {
5796
5892
  if (typeof src === "undefined") return;
5797
- const mat = Materials.getImage({
5798
- texture: { src },
5799
- transparent: true
5800
- });
5801
- for (let part of SKIN_PARTS) {
5802
- let mesh = this.getMeshByName(part);
5893
+ this.skinTextureSrc = src;
5894
+ const load = ++this.skinLoad;
5895
+ const texture = await SkinTextures.get(src, this.options.legacy);
5896
+ if (load !== this.skinLoad) return;
5897
+ this.skinMaterial = texture.material;
5898
+ this.detectedSlim = texture.slim;
5899
+ this.updateSlim(this.options.slim ?? this.detectedSlim);
5900
+ for (const part of SKIN_PARTS) {
5901
+ if (part === "cape" /* CAPE */) continue;
5902
+ const mesh = this.getMeshByName(part);
5803
5903
  if (mesh) {
5804
- mesh.material = mat;
5904
+ mesh.material = texture.material;
5805
5905
  }
5806
5906
  }
5907
+ this.notifyDirty();
5908
+ }
5909
+ /** Load a vanilla cape texture, or pass undefined to remove the cape. */
5910
+ async setCapeTexture(src) {
5911
+ const load = ++this.capeLoad;
5912
+ if (src === void 0) {
5913
+ const group = this.getGroupByName("cape" /* CAPE */);
5914
+ if (group) this.remove(group);
5915
+ this.notifyDirty();
5916
+ return;
5917
+ }
5918
+ const material = await SkinTextures.getCape(src);
5919
+ if (load !== this.capeLoad) return;
5920
+ const mesh = this.getMeshByName("cape" /* CAPE */);
5921
+ if (mesh) {
5922
+ mesh.material = material;
5923
+ } else {
5924
+ const group = this.createAndAddGroup("cape" /* CAPE */, 0, 24, 2);
5925
+ group.rotation.set(toRadians(-6), Math.PI, 0);
5926
+ const geometry = this._getBoxGeometryFromDimensions(
5927
+ classicSkinGeometries.cape,
5928
+ classicSkinTextureCoordinates.cape,
5929
+ [64, 32],
5930
+ [64, 32]
5931
+ );
5932
+ const cape = this.createAndAddMesh("cape" /* CAPE */, group, geometry, material);
5933
+ cape.position.set(0, -8, -0.5);
5934
+ }
5935
+ this.notifyDirty();
5807
5936
  }
5808
- //TODO: cape
5937
+ /** Select the arm model, or pass undefined to use texture detection. */
5809
5938
  setSlim(slim) {
5939
+ this.options.slim = slim;
5940
+ this.updateSlim(slim ?? this.detectedSlim);
5941
+ }
5942
+ updateSlim(slim) {
5810
5943
  if (slim === this.slim) return;
5811
5944
  this.slim = slim;
5812
5945
  for (const part of ["leftArm" /* LEFT_ARM */, "leftSleeve" /* LEFT_SLEEVE */, "rightArm" /* RIGHT_ARM */, "rightSleeve" /* RIGHT_SLEEVE */]) {
@@ -5820,22 +5953,28 @@ var SkinObject = class extends SceneObject {
5820
5953
  if (rightArm) rightArm.position.x -= offset;
5821
5954
  this.notifyDirty();
5822
5955
  }
5823
- setLegacy(legacy) {
5824
- if (legacy !== this.legacy) {
5825
- }
5826
- this.legacy = legacy;
5956
+ /** Select the texture layout, or pass undefined to detect it from image dimensions. */
5957
+ async setLegacy(legacy) {
5958
+ if (legacy === this.options.legacy) return;
5959
+ this.options.legacy = legacy;
5960
+ if (this.skinTextureSrc) await this.setSkinTexture(this.skinTextureSrc);
5961
+ }
5962
+ dispose() {
5963
+ this.skinLoad++;
5964
+ this.capeLoad++;
5965
+ super.dispose();
5827
5966
  }
5828
5967
  //TODO: layer toggles
5829
5968
  getBoxGeometry(part) {
5830
5969
  console.log("slim", this.slim);
5831
5970
  const coordinates = this.slim ? slimSkinTextureCoordinates : classicSkinTextureCoordinates;
5832
5971
  const geometries = this.slim ? slimSkinGeometries : classicSkinGeometries;
5833
- return this._getBoxGeometryFromDimensions(geometries[part], coordinates[part], [64, 64], [this.skinTextureWidth, this.skinTextureHeight]);
5972
+ return this._getBoxGeometryFromDimensions(geometries[part], coordinates[part], [64, 64], [64, 64]);
5834
5973
  }
5835
5974
  };
5836
5975
 
5837
5976
  // src/renderer/MineRenderScene.ts
5838
- var MineRenderScene = class _MineRenderScene extends import_three18.Scene {
5977
+ var MineRenderScene = class _MineRenderScene extends import_three19.Scene {
5839
5978
  constructor(options) {
5840
5979
  super();
5841
5980
  this.isMineRenderScene = true;
@@ -5943,10 +6082,10 @@ var MineRenderScene = class _MineRenderScene extends import_three18.Scene {
5943
6082
  this.dirty = true;
5944
6083
  const obj = new SkinObject(options);
5945
6084
  obj.scene = this;
5946
- await obj.init();
5947
6085
  if (skin) {
5948
- obj.setSkinTexture(skin);
6086
+ await obj.setSkinTexture(skin);
5949
6087
  }
6088
+ await obj.init();
5950
6089
  parent.add(obj);
5951
6090
  return obj;
5952
6091
  }
@@ -5959,17 +6098,17 @@ function isMineRenderScene(obj) {
5959
6098
  }
5960
6099
 
5961
6100
  // src/renderer/Renderer.ts
5962
- var import_three20 = require("three");
6101
+ var import_three21 = require("three");
5963
6102
  var import_ts_deepmerge9 = __toESM(require_dist());
5964
6103
  var import_stats = __toESM(require("stats.js"));
5965
6104
  var import_postprocessing = require("postprocessing");
5966
6105
 
5967
6106
  // src/three/OrbitControls.js
5968
- var import_three19 = require("three");
6107
+ var import_three20 = require("three");
5969
6108
  var _changeEvent = { type: "change" };
5970
6109
  var _startEvent = { type: "start" };
5971
6110
  var _endEvent = { type: "end" };
5972
- var OrbitControls = class extends import_three19.EventDispatcher {
6111
+ var OrbitControls = class extends import_three20.EventDispatcher {
5973
6112
  constructor(object, domElement) {
5974
6113
  super();
5975
6114
  if (domElement === void 0) console.warn('THREE.OrbitControls: The second parameter "domElement" is now mandatory.');
@@ -5978,7 +6117,7 @@ var OrbitControls = class extends import_three19.EventDispatcher {
5978
6117
  this.domElement = domElement;
5979
6118
  this.domElement.style.touchAction = "none";
5980
6119
  this.enabled = true;
5981
- this.target = new import_three19.Vector3();
6120
+ this.target = new import_three20.Vector3();
5982
6121
  this.minDistance = 0;
5983
6122
  this.maxDistance = Infinity;
5984
6123
  this.minZoom = 0;
@@ -6000,8 +6139,8 @@ var OrbitControls = class extends import_three19.EventDispatcher {
6000
6139
  this.autoRotate = false;
6001
6140
  this.autoRotateSpeed = 2;
6002
6141
  this.keys = { LEFT: "ArrowLeft", UP: "ArrowUp", RIGHT: "ArrowRight", BOTTOM: "ArrowDown" };
6003
- this.mouseButtons = { LEFT: import_three19.MOUSE.ROTATE, MIDDLE: import_three19.MOUSE.DOLLY, RIGHT: import_three19.MOUSE.PAN };
6004
- this.touches = { ONE: import_three19.TOUCH.ROTATE, TWO: import_three19.TOUCH.DOLLY_PAN };
6142
+ this.mouseButtons = { LEFT: import_three20.MOUSE.ROTATE, MIDDLE: import_three20.MOUSE.DOLLY, RIGHT: import_three20.MOUSE.PAN };
6143
+ this.touches = { ONE: import_three20.TOUCH.ROTATE, TWO: import_three20.TOUCH.DOLLY_PAN };
6005
6144
  this.target0 = this.target.clone();
6006
6145
  this.position0 = this.object.position.clone();
6007
6146
  this.zoom0 = this.object.zoom;
@@ -6030,11 +6169,11 @@ var OrbitControls = class extends import_three19.EventDispatcher {
6030
6169
  state = STATE.NONE;
6031
6170
  };
6032
6171
  this.update = function() {
6033
- const offset = new import_three19.Vector3();
6034
- const quat = new import_three19.Quaternion().setFromUnitVectors(object.up, new import_three19.Vector3(0, 1, 0));
6172
+ const offset = new import_three20.Vector3();
6173
+ const quat = new import_three20.Quaternion().setFromUnitVectors(object.up, new import_three20.Vector3(0, 1, 0));
6035
6174
  const quatInverse = quat.clone().invert();
6036
- const lastPosition = new import_three19.Vector3();
6037
- const lastQuaternion = new import_three19.Quaternion();
6175
+ const lastPosition = new import_three20.Vector3();
6176
+ const lastQuaternion = new import_three20.Quaternion();
6038
6177
  const twoPI = 2 * Math.PI;
6039
6178
  return function update() {
6040
6179
  const position = scope.object.position;
@@ -6120,20 +6259,20 @@ var OrbitControls = class extends import_three19.EventDispatcher {
6120
6259
  };
6121
6260
  let state = STATE.NONE;
6122
6261
  const EPS = 1e-6;
6123
- const spherical = new import_three19.Spherical();
6124
- const sphericalDelta = new import_three19.Spherical();
6262
+ const spherical = new import_three20.Spherical();
6263
+ const sphericalDelta = new import_three20.Spherical();
6125
6264
  let scale = 1;
6126
- const panOffset = new import_three19.Vector3();
6265
+ const panOffset = new import_three20.Vector3();
6127
6266
  let zoomChanged = false;
6128
- const rotateStart = new import_three19.Vector2();
6129
- const rotateEnd = new import_three19.Vector2();
6130
- const rotateDelta = new import_three19.Vector2();
6131
- const panStart = new import_three19.Vector2();
6132
- const panEnd = new import_three19.Vector2();
6133
- const panDelta = new import_three19.Vector2();
6134
- const dollyStart = new import_three19.Vector2();
6135
- const dollyEnd = new import_three19.Vector2();
6136
- const dollyDelta = new import_three19.Vector2();
6267
+ const rotateStart = new import_three20.Vector2();
6268
+ const rotateEnd = new import_three20.Vector2();
6269
+ const rotateDelta = new import_three20.Vector2();
6270
+ const panStart = new import_three20.Vector2();
6271
+ const panEnd = new import_three20.Vector2();
6272
+ const panDelta = new import_three20.Vector2();
6273
+ const dollyStart = new import_three20.Vector2();
6274
+ const dollyEnd = new import_three20.Vector2();
6275
+ const dollyDelta = new import_three20.Vector2();
6137
6276
  const pointers = [];
6138
6277
  const pointerPositions = {};
6139
6278
  function getAutoRotationAngle() {
@@ -6149,7 +6288,7 @@ var OrbitControls = class extends import_three19.EventDispatcher {
6149
6288
  sphericalDelta.phi -= angle;
6150
6289
  }
6151
6290
  const panLeft = function() {
6152
- const v = new import_three19.Vector3();
6291
+ const v = new import_three20.Vector3();
6153
6292
  return function panLeft2(distance, objectMatrix) {
6154
6293
  v.setFromMatrixColumn(objectMatrix, 0);
6155
6294
  v.multiplyScalar(-distance);
@@ -6157,7 +6296,7 @@ var OrbitControls = class extends import_three19.EventDispatcher {
6157
6296
  };
6158
6297
  }();
6159
6298
  const panUp = function() {
6160
- const v = new import_three19.Vector3();
6299
+ const v = new import_three20.Vector3();
6161
6300
  return function panUp2(distance, objectMatrix) {
6162
6301
  if (scope.screenSpacePanning === true) {
6163
6302
  v.setFromMatrixColumn(objectMatrix, 1);
@@ -6170,7 +6309,7 @@ var OrbitControls = class extends import_three19.EventDispatcher {
6170
6309
  };
6171
6310
  }();
6172
6311
  const pan = function() {
6173
- const offset = new import_three19.Vector3();
6312
+ const offset = new import_three20.Vector3();
6174
6313
  return function pan2(deltaX, deltaY) {
6175
6314
  const element = scope.domElement;
6176
6315
  if (scope.object.isPerspectiveCamera) {
@@ -6419,12 +6558,12 @@ var OrbitControls = class extends import_three19.EventDispatcher {
6419
6558
  mouseAction = -1;
6420
6559
  }
6421
6560
  switch (mouseAction) {
6422
- case import_three19.MOUSE.DOLLY:
6561
+ case import_three20.MOUSE.DOLLY:
6423
6562
  if (scope.enableZoom === false) return;
6424
6563
  handleMouseDownDolly(event);
6425
6564
  state = STATE.DOLLY;
6426
6565
  break;
6427
- case import_three19.MOUSE.ROTATE:
6566
+ case import_three20.MOUSE.ROTATE:
6428
6567
  if (event.ctrlKey || event.metaKey || event.shiftKey) {
6429
6568
  if (scope.enablePan === false) return;
6430
6569
  handleMouseDownPan(event);
@@ -6435,7 +6574,7 @@ var OrbitControls = class extends import_three19.EventDispatcher {
6435
6574
  state = STATE.ROTATE;
6436
6575
  }
6437
6576
  break;
6438
- case import_three19.MOUSE.PAN:
6577
+ case import_three20.MOUSE.PAN:
6439
6578
  if (event.ctrlKey || event.metaKey || event.shiftKey) {
6440
6579
  if (scope.enableRotate === false) return;
6441
6580
  handleMouseDownRotate(event);
@@ -6491,12 +6630,12 @@ var OrbitControls = class extends import_three19.EventDispatcher {
6491
6630
  switch (pointers.length) {
6492
6631
  case 1:
6493
6632
  switch (scope.touches.ONE) {
6494
- case import_three19.TOUCH.ROTATE:
6633
+ case import_three20.TOUCH.ROTATE:
6495
6634
  if (scope.enableRotate === false) return;
6496
6635
  handleTouchStartRotate();
6497
6636
  state = STATE.TOUCH_ROTATE;
6498
6637
  break;
6499
- case import_three19.TOUCH.PAN:
6638
+ case import_three20.TOUCH.PAN:
6500
6639
  if (scope.enablePan === false) return;
6501
6640
  handleTouchStartPan();
6502
6641
  state = STATE.TOUCH_PAN;
@@ -6507,12 +6646,12 @@ var OrbitControls = class extends import_three19.EventDispatcher {
6507
6646
  break;
6508
6647
  case 2:
6509
6648
  switch (scope.touches.TWO) {
6510
- case import_three19.TOUCH.DOLLY_PAN:
6649
+ case import_three20.TOUCH.DOLLY_PAN:
6511
6650
  if (scope.enableZoom === false && scope.enablePan === false) return;
6512
6651
  handleTouchStartDollyPan();
6513
6652
  state = STATE.TOUCH_DOLLY_PAN;
6514
6653
  break;
6515
- case import_three19.TOUCH.DOLLY_ROTATE:
6654
+ case import_three20.TOUCH.DOLLY_ROTATE:
6516
6655
  if (scope.enableZoom === false && scope.enableRotate === false) return;
6517
6656
  handleTouchStartDollyRotate();
6518
6657
  state = STATE.TOUCH_DOLLY_ROTATE;
@@ -6579,7 +6718,7 @@ var OrbitControls = class extends import_three19.EventDispatcher {
6579
6718
  function trackPointer(event) {
6580
6719
  let position = pointerPositions[event.pointerId];
6581
6720
  if (position === void 0) {
6582
- position = new import_three19.Vector2();
6721
+ position = new import_three20.Vector2();
6583
6722
  pointerPositions[event.pointerId] = position;
6584
6723
  }
6585
6724
  position.set(event.pageX, event.pageY);
@@ -6599,10 +6738,10 @@ var MapControls = class extends OrbitControls {
6599
6738
  constructor(object, domElement) {
6600
6739
  super(object, domElement);
6601
6740
  this.screenSpacePanning = false;
6602
- this.mouseButtons.LEFT = import_three19.MOUSE.PAN;
6603
- this.mouseButtons.RIGHT = import_three19.MOUSE.ROTATE;
6604
- this.touches.ONE = import_three19.TOUCH.PAN;
6605
- this.touches.TWO = import_three19.TOUCH.DOLLY_ROTATE;
6741
+ this.mouseButtons.LEFT = import_three20.MOUSE.PAN;
6742
+ this.mouseButtons.RIGHT = import_three20.MOUSE.ROTATE;
6743
+ this.touches.ONE = import_three20.TOUCH.PAN;
6744
+ this.touches.TWO = import_three20.TOUCH.DOLLY_ROTATE;
6606
6745
  }
6607
6746
  };
6608
6747
 
@@ -6647,8 +6786,8 @@ var Renderer = class _Renderer {
6647
6786
  top: void 0,
6648
6787
  bottom: void 0
6649
6788
  },
6650
- position: new import_three20.Vector3(50, 50, 50),
6651
- lookingAt: new import_three20.Vector3(0, 0, 0)
6789
+ position: new import_three21.Vector3(50, 50, 50),
6790
+ lookingAt: new import_three21.Vector3(0, 0, 0)
6652
6791
  },
6653
6792
  render: {
6654
6793
  fpsLimit: 60,
@@ -6678,14 +6817,14 @@ var Renderer = class _Renderer {
6678
6817
  switch (this.options.camera.type) {
6679
6818
  case "perspective":
6680
6819
  default:
6681
- return new import_three20.PerspectiveCamera(
6820
+ return new import_three21.PerspectiveCamera(
6682
6821
  this.options.camera.perspective.fov,
6683
6822
  this.options.camera.perspective.aspect ?? this.viewWidth / this.viewHeight,
6684
6823
  this.options.camera.near,
6685
6824
  this.options.camera.far
6686
6825
  );
6687
6826
  case "orthographic":
6688
- return new import_three20.OrthographicCamera(
6827
+ return new import_three21.OrthographicCamera(
6689
6828
  this.options.camera.orthographic.left ?? this.viewWidth / -2,
6690
6829
  this.options.camera.orthographic.right ?? this.viewWidth / 2,
6691
6830
  this.options.camera.orthographic.top ?? this.viewHeight / 2,
@@ -6696,7 +6835,7 @@ var Renderer = class _Renderer {
6696
6835
  }
6697
6836
  }
6698
6837
  createRenderer() {
6699
- const renderer = new import_three20.WebGLRenderer({
6838
+ const renderer = new import_three21.WebGLRenderer({
6700
6839
  antialias: this.options.render.antialias,
6701
6840
  alpha: true,
6702
6841
  powerPreference: "high-performance",
@@ -6704,8 +6843,8 @@ var Renderer = class _Renderer {
6704
6843
  });
6705
6844
  renderer.setClearColor(0, 0);
6706
6845
  renderer.shadowMap.enabled = true;
6707
- renderer.shadowMap.type = import_three20.PCFSoftShadowMap;
6708
- renderer.outputColorSpace = import_three20.SRGBColorSpace;
6846
+ renderer.shadowMap.type = import_three21.PCFSoftShadowMap;
6847
+ renderer.outputColorSpace = import_three21.SRGBColorSpace;
6709
6848
  renderer.setSize(this.viewWidth, this.viewHeight);
6710
6849
  return renderer;
6711
6850
  }
@@ -6739,20 +6878,20 @@ var Renderer = class _Renderer {
6739
6878
  window["__THREE_DEVTOOLS__"].dispatchEvent(new CustomEvent("observe", { detail: this.scene }));
6740
6879
  }
6741
6880
  if (this.options.debug.grid) {
6742
- const gridHelper = new import_three20.GridHelper(128, 16);
6881
+ const gridHelper = new import_three21.GridHelper(128, 16);
6743
6882
  this._debugHelpers.push(gridHelper);
6744
6883
  this.scene.add(gridHelper);
6745
- const gridHelper2 = new import_three20.GridHelper(128, 16);
6884
+ const gridHelper2 = new import_three21.GridHelper(128, 16);
6746
6885
  this._debugHelpers.push(gridHelper2);
6747
6886
  gridHelper2.rotation.x = 90 * (Math.PI / 180);
6748
6887
  this.scene.add(gridHelper2);
6749
- const gridHelper3 = new import_three20.GridHelper(128, 16);
6888
+ const gridHelper3 = new import_three21.GridHelper(128, 16);
6750
6889
  this._debugHelpers.push(gridHelper3);
6751
6890
  gridHelper3.rotation.z = 90 * (Math.PI / 180);
6752
6891
  this.scene.add(gridHelper3);
6753
6892
  }
6754
6893
  if (this.options.debug.axes) {
6755
- const axesHelper = new import_three20.AxesHelper(64);
6894
+ const axesHelper = new import_three21.AxesHelper(64);
6756
6895
  this._debugHelpers.push(axesHelper);
6757
6896
  this.scene.add(axesHelper);
6758
6897
  }
@@ -7113,10 +7252,10 @@ var Skins = class {
7113
7252
  };
7114
7253
 
7115
7254
  // src/world/Chunk.ts
7116
- var import_three23 = require("three");
7255
+ var import_three24 = require("three");
7117
7256
 
7118
7257
  // src/world/MineRenderWorld.ts
7119
- var import_three22 = require("three");
7258
+ var import_three23 = require("three");
7120
7259
  var MineRenderWorld = class {
7121
7260
  constructor(scene) {
7122
7261
  this._size = 4;
@@ -7127,10 +7266,10 @@ var MineRenderWorld = class {
7127
7266
  }
7128
7267
  getBlockAt(posOrX, y, z) {
7129
7268
  if (typeof posOrX == "number") {
7130
- return this.getBlockAt(new import_three22.Vector3(posOrX, y, z));
7269
+ return this.getBlockAt(new import_three23.Vector3(posOrX, y, z));
7131
7270
  }
7132
7271
  if (isTripleArray(posOrX)) {
7133
- return this.getBlockAt(new import_three22.Vector3(posOrX[0], posOrX[1], posOrX[2]));
7272
+ return this.getBlockAt(new import_three23.Vector3(posOrX[0], posOrX[1], posOrX[2]));
7134
7273
  }
7135
7274
  const chunk = this.getChunkAt(posOrX);
7136
7275
  if (typeof chunk === "undefined") {
@@ -7141,10 +7280,10 @@ var MineRenderWorld = class {
7141
7280
  }
7142
7281
  async setBlockAt(posOrX, yOrBlock, z, block) {
7143
7282
  if (typeof posOrX == "number") {
7144
- return this.setBlockAt(new import_three22.Vector3(posOrX, yOrBlock, z), block);
7283
+ return this.setBlockAt(new import_three23.Vector3(posOrX, yOrBlock, z), block);
7145
7284
  }
7146
7285
  if (isTripleArray(posOrX)) {
7147
- return this.setBlockAt(new import_three22.Vector3(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
7286
+ return this.setBlockAt(new import_three23.Vector3(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
7148
7287
  }
7149
7288
  this.validatePosBounds(posOrX);
7150
7289
  const chunk = this.getOrCreateChunkAt(posOrX);
@@ -7190,14 +7329,14 @@ var MineRenderWorld = class {
7190
7329
  return this._chunks[index];
7191
7330
  }
7192
7331
  static worldToScenePosition(pos) {
7193
- return new import_three22.Vector3(
7332
+ return new import_three23.Vector3(
7194
7333
  pos.x * 16,
7195
7334
  pos.y * 16,
7196
7335
  pos.z * 16
7197
7336
  );
7198
7337
  }
7199
7338
  static sceneToWorldPosition(pos) {
7200
- return new import_three22.Vector3(
7339
+ return new import_three23.Vector3(
7201
7340
  pos.x / 16,
7202
7341
  pos.y / 16,
7203
7342
  pos.z / 16
@@ -7234,12 +7373,12 @@ var Chunk = class _Chunk {
7234
7373
  this.x = x;
7235
7374
  this.y = y;
7236
7375
  this.z = z;
7237
- let anchor = new import_three23.Object3D();
7376
+ let anchor = new import_three24.Object3D();
7238
7377
  this._anchor = anchor;
7239
7378
  scene.add(anchor);
7240
7379
  anchor.position.set(this.x * 256 + 128 - 8, this.y * 256 + 128 - 8, this.z * 256 + 128 - 8);
7241
7380
  addBox3WireframeToObject(
7242
- new import_three23.Box3(new import_three23.Vector3(0, 0, 0), new import_three23.Vector3(256, 256, 256)),
7381
+ new import_three24.Box3(new import_three24.Vector3(0, 0, 0), new import_three24.Vector3(256, 256, 256)),
7243
7382
  anchor,
7244
7383
  16776960,
7245
7384
  4
@@ -7247,10 +7386,10 @@ var Chunk = class _Chunk {
7247
7386
  }
7248
7387
  getBlockAt(posOrX, y, z) {
7249
7388
  if (typeof posOrX == "number") {
7250
- return this.getBlockAt(new import_three23.Vector3(posOrX, y, z));
7389
+ return this.getBlockAt(new import_three24.Vector3(posOrX, y, z));
7251
7390
  }
7252
7391
  if (isTripleArray(posOrX)) {
7253
- return this.getBlockAt(new import_three23.Vector3(posOrX[0], posOrX[1], posOrX[2]));
7392
+ return this.getBlockAt(new import_three24.Vector3(posOrX[0], posOrX[1], posOrX[2]));
7254
7393
  }
7255
7394
  const pos = this.worldPosToChunkPos(posOrX);
7256
7395
  const index = _Chunk.chunkPosToBlockIndex(pos);
@@ -7258,10 +7397,10 @@ var Chunk = class _Chunk {
7258
7397
  }
7259
7398
  async setBlockAt(posOrX, yOrBlock, z, block) {
7260
7399
  if (typeof posOrX == "number") {
7261
- return this.setBlockAt(new import_three23.Vector3(posOrX, yOrBlock, z), block);
7400
+ return this.setBlockAt(new import_three24.Vector3(posOrX, yOrBlock, z), block);
7262
7401
  }
7263
7402
  if (isTripleArray(posOrX)) {
7264
- return this.setBlockAt(new import_three23.Vector3(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
7403
+ return this.setBlockAt(new import_three24.Vector3(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
7265
7404
  }
7266
7405
  const worldPos = posOrX;
7267
7406
  const pos = this.worldPosToChunkPos(worldPos);
@@ -7307,7 +7446,7 @@ var Chunk = class _Chunk {
7307
7446
  }
7308
7447
  async clear() {
7309
7448
  let promises = [];
7310
- let pos = new import_three23.Vector3();
7449
+ let pos = new import_three24.Vector3();
7311
7450
  for (let x = 0; x < 16; x++) {
7312
7451
  for (let z = 0; z < 16; z++) {
7313
7452
  for (let y = 0; y < 16; y++) {
@@ -7326,14 +7465,14 @@ var Chunk = class _Chunk {
7326
7465
  return pos.y * 16 * 16 + pos.z * 16 + pos.x;
7327
7466
  }
7328
7467
  worldPosToChunkPos(pos) {
7329
- return new import_three23.Vector3(
7468
+ return new import_three24.Vector3(
7330
7469
  pos.x - this.x * 16,
7331
7470
  pos.y - this.y * 16,
7332
7471
  pos.z - this.z * 16
7333
7472
  );
7334
7473
  }
7335
7474
  chunkPosToWorldPos(pos) {
7336
- return new import_three23.Vector3(
7475
+ return new import_three24.Vector3(
7337
7476
  this.x * 16 + pos.x,
7338
7477
  this.y * 16 + pos.y,
7339
7478
  this.z * 16 + pos.z
@@ -7413,6 +7552,7 @@ var Chunk = class _Chunk {
7413
7552
  SchematicParser,
7414
7553
  SkinObject,
7415
7554
  SkinPart,
7555
+ SkinTextures,
7416
7556
  Skins,
7417
7557
  StructureParser,
7418
7558
  TextureAtlas,