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.
@@ -737,6 +737,25 @@ var init_ImageLoader = __esm({
737
737
  };
738
738
  }
739
739
  static async loadInfo(src) {
740
+ if (/^data:/i.test(src.trimStart())) {
741
+ const url = new URL(src);
742
+ url.hash = "";
743
+ const comma = url.href.indexOf(",");
744
+ if (comma < 0) {
745
+ throw new Error("Invalid image data URL");
746
+ }
747
+ let bytes = url.href.slice(comma + 1).replace(
748
+ /%([\da-f]{2})/gi,
749
+ (_, hex) => String.fromCharCode(parseInt(hex, 16))
750
+ );
751
+ if (/; *base64 *$/i.test(url.href.slice(5, comma))) {
752
+ bytes = atob(bytes);
753
+ }
754
+ return this.processResponse({
755
+ url: src,
756
+ data: Uint8Array.from(bytes, (char) => char.charCodeAt(0)).buffer
757
+ });
758
+ }
740
759
  return Requests.genericRequest({
741
760
  url: src,
742
761
  responseType: "arraybuffer"
@@ -814,7 +833,7 @@ var init_TextureLoader = __esm({
814
833
  });
815
834
 
816
835
  // src/texture/Textures.ts
817
- import { CanvasTexture, Texture as Texture2 } from "three";
836
+ import { CanvasTexture, DataTexture, Texture as Texture2 } from "three";
818
837
  import * as THREE2 from "three";
819
838
  var Textures;
820
839
  var init_Textures = __esm({
@@ -823,6 +842,26 @@ var init_Textures = __esm({
823
842
  init_Caching();
824
843
  init_CacheKey();
825
844
  Textures = class _Textures {
845
+ /** Creates the shared checkerboard from pixels without fetching or decoding an image. */
846
+ static getMissing() {
847
+ return Caching.textureCache.get("builtin:missing-texture", () => {
848
+ const size = 64;
849
+ const data = new Uint8Array(size * size * 4);
850
+ for (let y = 0; y < size; y++) {
851
+ for (let x = 0; x < size; x++) {
852
+ const offset = (y * size + x) * 4;
853
+ const color = (x + y) % 2 === 0 ? 255 : 0;
854
+ data[offset] = data[offset + 2] = color;
855
+ data[offset + 3] = 255;
856
+ }
857
+ }
858
+ const texture = new DataTexture(data, size, size);
859
+ texture.colorSpace = THREE2.SRGBColorSpace;
860
+ texture.flipY = true;
861
+ texture.needsUpdate = true;
862
+ return this.initTextureProps(texture);
863
+ });
864
+ }
826
865
  static initTextureProps(texture) {
827
866
  texture.magFilter = THREE2.NearestFilter;
828
867
  texture.minFilter = THREE2.NearestFilter;
@@ -864,13 +903,11 @@ var init_Materials = __esm({
864
903
  init_TextureLoader();
865
904
  init_Caching();
866
905
  Materials = class _Materials {
867
- static {
868
- this.MISSING_TEXTURE_SRC = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAQMAAACQp+OdAAAABlBMVEX/AP8AAACfphTyAAAAFUlEQVQoz2MIhQKGVVAwKjIqQrwIAHRz/wFI17TEAAAAAElFTkSuQmCC";
869
- }
870
- // resolved lazily: as a static field this decoded an image the moment the library was
871
- // imported, which needs both a DOM and an EnvProvider to already be in place
872
906
  static get MISSING_TEXTURE() {
873
- return _Materials.getImage({ texture: { src: _Materials.MISSING_TEXTURE_SRC } });
907
+ return Caching.materialCache.get("builtin:missing-texture", () => new MeshBasicMaterial({
908
+ map: Textures.getMissing(),
909
+ alphaTest: 0.5
910
+ }));
874
911
  }
875
912
  static createImage(key) {
876
913
  const transparent = key.transparent || false;
@@ -2703,7 +2740,7 @@ var init_UVMapper = __esm({
2703
2740
  init_CanvasImage();
2704
2741
  init_TextureAtlas();
2705
2742
  init_Caching();
2706
- init_ImageLoader();
2743
+ init_Textures();
2707
2744
  init_AssetKey();
2708
2745
  init_ModelGenerator();
2709
2746
  init_log();
@@ -2990,11 +3027,12 @@ var init_UVMapper = __esm({
2990
3027
  const size = Math.ceil(s * maxWidth);
2991
3028
  console.debug(p5, "Atlas size:", size);
2992
3029
  const squaredSize = size * size;
2993
- const missing = await ImageLoader.getData("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAQMAAACQp+OdAAAABlBMVEX/AP8AAACfphTyAAAAFUlEQVQoz2MIhQKGVVAwKjIqQrwIAHRz/wFI17TEAAAAAElFTkSuQmCC");
2994
- const empty = await ImageLoader.getData("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAQMAAACQp+OdAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAA5JREFUKM9jGAWjgAIAAAJAAAFSSwuTAAAAAElFTkSuQmCC");
2995
3030
  const image = new CanvasImage(size, size);
2996
- image.putData(missing, 0, 0);
2997
- image.putData(empty, 0, 0, 0, 0, maxWidth, maxWidth);
3031
+ const missing = Textures.getMissing().image;
3032
+ const missingPixels = image.context.createImageData(missing.width, missing.height);
3033
+ missingPixels.data.set(missing.data);
3034
+ image.putData(missingPixels, 0, 0);
3035
+ image.context.clearRect(0, 0, maxWidth, maxWidth);
2998
3036
  const positions = {};
2999
3037
  let hasTransparency = false;
3000
3038
  let hasAnimation = false;
@@ -3060,8 +3098,6 @@ var init_UVMapper = __esm({
3060
3098
  ty++;
3061
3099
  }
3062
3100
  }
3063
- const atlasImageData = image.toDataURL();
3064
- console.log(p5, "Atlas Image for", model.key, atlasImageData);
3065
3101
  this.fillMissingTextureKeys(model.textures, positions);
3066
3102
  if (isItemModel) {
3067
3103
  console.debug(p5, "Generating item model for", model);
@@ -12880,7 +12916,7 @@ init_util();
12880
12916
  init_Caching();
12881
12917
  init_CacheKey();
12882
12918
  init_MineRenderError();
12883
- import { DataTexture as DataTexture2, DoubleSide as DoubleSide5, FrontSide as FrontSide2, MeshBasicMaterial as MeshBasicMaterial6, SRGBColorSpace as SRGBColorSpace6 } from "three";
12919
+ import { DataTexture as DataTexture3, DoubleSide as DoubleSide5, FrontSide as FrontSide2, MeshBasicMaterial as MeshBasicMaterial6, SRGBColorSpace as SRGBColorSpace6 } from "three";
12884
12920
 
12885
12921
  // src/skin/SkinImage.ts
12886
12922
  init_Caching();
@@ -12961,7 +12997,7 @@ var SkinTextures = class {
12961
12997
  });
12962
12998
  }
12963
12999
  static createMaterial(pixels, width, height, transparent = true) {
12964
- const texture = Textures.initTextureProps(new DataTexture2(pixels, width, height));
13000
+ const texture = Textures.initTextureProps(new DataTexture3(pixels, width, height));
12965
13001
  texture.colorSpace = SRGBColorSpace6;
12966
13002
  texture.flipY = true;
12967
13003
  texture.needsUpdate = true;