minerender 2.1.0-alpha.69 → 2.1.0-alpha.70

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.
@@ -689,6 +689,25 @@ var init_ImageLoader = __esm({
689
689
  };
690
690
  }
691
691
  static async loadInfo(src) {
692
+ if (/^data:/i.test(src.trimStart())) {
693
+ const url = new URL(src);
694
+ url.hash = "";
695
+ const comma = url.href.indexOf(",");
696
+ if (comma < 0) {
697
+ throw new Error("Invalid image data URL");
698
+ }
699
+ let bytes = url.href.slice(comma + 1).replace(
700
+ /%([\da-f]{2})/gi,
701
+ (_, hex) => String.fromCharCode(parseInt(hex, 16))
702
+ );
703
+ if (/; *base64 *$/i.test(url.href.slice(5, comma))) {
704
+ bytes = atob(bytes);
705
+ }
706
+ return this.processResponse({
707
+ url: src,
708
+ data: Uint8Array.from(bytes, (char) => char.charCodeAt(0)).buffer
709
+ });
710
+ }
692
711
  return Requests.genericRequest({
693
712
  url: src,
694
713
  responseType: "arraybuffer"
@@ -764,7 +783,7 @@ var init_TextureLoader = __esm({
764
783
  });
765
784
 
766
785
  // src/texture/Textures.ts
767
- import { CanvasTexture, Texture as Texture2 } from "three";
786
+ import { CanvasTexture, DataTexture, Texture as Texture2 } from "three";
768
787
  import * as THREE2 from "three";
769
788
  var Textures;
770
789
  var init_Textures = __esm({
@@ -773,6 +792,26 @@ var init_Textures = __esm({
773
792
  init_Caching();
774
793
  init_CacheKey();
775
794
  Textures = class _Textures {
795
+ /** Creates the shared checkerboard from pixels without fetching or decoding an image. */
796
+ static getMissing() {
797
+ return Caching.textureCache.get("builtin:missing-texture", () => {
798
+ const size = 64;
799
+ const data = new Uint8Array(size * size * 4);
800
+ for (let y = 0; y < size; y++) {
801
+ for (let x = 0; x < size; x++) {
802
+ const offset = (y * size + x) * 4;
803
+ const color = (x + y) % 2 === 0 ? 255 : 0;
804
+ data[offset] = data[offset + 2] = color;
805
+ data[offset + 3] = 255;
806
+ }
807
+ }
808
+ const texture = new DataTexture(data, size, size);
809
+ texture.colorSpace = THREE2.SRGBColorSpace;
810
+ texture.flipY = true;
811
+ texture.needsUpdate = true;
812
+ return this.initTextureProps(texture);
813
+ });
814
+ }
776
815
  static initTextureProps(texture) {
777
816
  texture.magFilter = THREE2.NearestFilter;
778
817
  texture.minFilter = THREE2.NearestFilter;
@@ -806,18 +845,19 @@ var init_Textures = __esm({
806
845
 
807
846
  // src/Materials.ts
808
847
  import { Color, CustomBlending, DoubleSide, OneFactor, OneMinusSrcAlphaFactor, RepeatWrapping, FrontSide, MeshBasicMaterial, MeshStandardMaterial, ShaderChunk, ShaderMaterial } from "three";
809
- var _Materials, Materials;
848
+ var Materials;
810
849
  var init_Materials = __esm({
811
850
  "src/Materials.ts"() {
812
851
  init_CacheKey();
813
852
  init_Textures();
814
853
  init_TextureLoader();
815
854
  init_Caching();
816
- _Materials = class _Materials {
817
- // resolved lazily: as a static field this decoded an image the moment the library was
818
- // imported, which needs both a DOM and an EnvProvider to already be in place
855
+ Materials = class _Materials {
819
856
  static get MISSING_TEXTURE() {
820
- return _Materials.getImage({ texture: { src: _Materials.MISSING_TEXTURE_SRC } });
857
+ return Caching.materialCache.get("builtin:missing-texture", () => new MeshBasicMaterial({
858
+ map: Textures.getMissing(),
859
+ alphaTest: 0.5
860
+ }));
821
861
  }
822
862
  static createImage(key) {
823
863
  const transparent = key.transparent || false;
@@ -1088,8 +1128,6 @@ var init_Materials = __esm({
1088
1128
  }
1089
1129
  }
1090
1130
  };
1091
- _Materials.MISSING_TEXTURE_SRC = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAQMAAACQp+OdAAAABlBMVEX/AP8AAACfphTyAAAAFUlEQVQoz2MIhQKGVVAwKjIqQrwIAHRz/wFI17TEAAAAAElFTkSuQmCC";
1092
- Materials = _Materials;
1093
1131
  }
1094
1132
  });
1095
1133
 
@@ -2615,7 +2653,7 @@ var init_UVMapper = __esm({
2615
2653
  init_CanvasImage();
2616
2654
  init_TextureAtlas();
2617
2655
  init_Caching();
2618
- init_ImageLoader();
2656
+ init_Textures();
2619
2657
  init_AssetKey();
2620
2658
  init_ModelGenerator();
2621
2659
  init_log();
@@ -2902,11 +2940,12 @@ var init_UVMapper = __esm({
2902
2940
  const size = Math.ceil(s * maxWidth);
2903
2941
  console.debug(p5, "Atlas size:", size);
2904
2942
  const squaredSize = size * size;
2905
- const missing = await ImageLoader.getData("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAQMAAACQp+OdAAAABlBMVEX/AP8AAACfphTyAAAAFUlEQVQoz2MIhQKGVVAwKjIqQrwIAHRz/wFI17TEAAAAAElFTkSuQmCC");
2906
- const empty = await ImageLoader.getData("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAQMAAACQp+OdAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAA5JREFUKM9jGAWjgAIAAAJAAAFSSwuTAAAAAElFTkSuQmCC");
2907
2943
  const image = new CanvasImage(size, size);
2908
- image.putData(missing, 0, 0);
2909
- image.putData(empty, 0, 0, 0, 0, maxWidth, maxWidth);
2944
+ const missing = Textures.getMissing().image;
2945
+ const missingPixels = image.context.createImageData(missing.width, missing.height);
2946
+ missingPixels.data.set(missing.data);
2947
+ image.putData(missingPixels, 0, 0);
2948
+ image.context.clearRect(0, 0, maxWidth, maxWidth);
2910
2949
  const positions = {};
2911
2950
  let hasTransparency = false;
2912
2951
  let hasAnimation = false;
@@ -2972,8 +3011,6 @@ var init_UVMapper = __esm({
2972
3011
  ty++;
2973
3012
  }
2974
3013
  }
2975
- const atlasImageData = image.toDataURL();
2976
- console.log(p5, "Atlas Image for", model.key, atlasImageData);
2977
3014
  this.fillMissingTextureKeys(model.textures, positions);
2978
3015
  if (isItemModel) {
2979
3016
  console.debug(p5, "Generating item model for", model);
@@ -12826,7 +12863,7 @@ init_util();
12826
12863
  init_Caching();
12827
12864
  init_CacheKey();
12828
12865
  init_MineRenderError();
12829
- import { DataTexture as DataTexture2, DoubleSide as DoubleSide5, FrontSide as FrontSide2, MeshBasicMaterial as MeshBasicMaterial6, SRGBColorSpace as SRGBColorSpace6 } from "three";
12866
+ import { DataTexture as DataTexture3, DoubleSide as DoubleSide5, FrontSide as FrontSide2, MeshBasicMaterial as MeshBasicMaterial6, SRGBColorSpace as SRGBColorSpace6 } from "three";
12830
12867
 
12831
12868
  // src/skin/SkinImage.ts
12832
12869
  init_Caching();
@@ -12907,7 +12944,7 @@ var SkinTextures = class {
12907
12944
  });
12908
12945
  }
12909
12946
  static createMaterial(pixels, width, height, transparent = true) {
12910
- const texture = Textures.initTextureProps(new DataTexture2(pixels, width, height));
12947
+ const texture = Textures.initTextureProps(new DataTexture3(pixels, width, height));
12911
12948
  texture.colorSpace = SRGBColorSpace6;
12912
12949
  texture.flipY = true;
12913
12950
  texture.needsUpdate = true;