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.
@@ -1,5 +1,5 @@
1
1
  import * as three from 'three';
2
- import { Vector3, PixelFormat, BoxGeometry, Material, ColorRepresentation, MeshBasicMaterial, Mesh, Euler, Vector2, BufferAttribute, Float32BufferAttribute, BufferGeometry, Object3D, Box3, InstancedMesh, PerspectiveCamera, OrthographicCamera, Matrix4, Box2, Scene, Object3DEventMap, Texture, Camera, MOUSE, TOUCH, WebGLRenderer, EventDispatcher, Raycaster, Intersection, CanvasTexture, InterleavedBufferAttribute, TrianglesDrawModes, Line, Points, Group } from 'three';
2
+ import { Vector3, PixelFormat, BoxGeometry, Material, ColorRepresentation, MeshBasicMaterial, Mesh, Euler, Vector2, BufferAttribute, Float32BufferAttribute, BufferGeometry, Object3D, Box3, InstancedMesh, PerspectiveCamera, OrthographicCamera, Matrix4, Box2, Scene, Object3DEventMap, Texture, Camera, MOUSE, TOUCH, WebGLRenderer, EventDispatcher, Raycaster, Intersection, DataTexture, CanvasTexture, InterleavedBufferAttribute, TrianglesDrawModes, Line, Points, Group } from 'three';
3
3
  import * as nodeCanvas from 'canvas';
4
4
  import { ImageData as ImageData$1, CanvasRenderingContext2D } from 'canvas';
5
5
  import { Buffer } from 'buffer';
@@ -277,7 +277,6 @@ interface EntityModelCube {
277
277
  }
278
278
 
279
279
  declare class Materials {
280
- private static readonly MISSING_TEXTURE_SRC;
281
280
  static get MISSING_TEXTURE(): Material;
282
281
  static createImage(key: MaterialKey): Material;
283
282
  static createBasicCanvasMaterial(canvas: HTMLCanvasElement, transparent?: boolean, shade?: boolean): Material;
@@ -2315,6 +2314,8 @@ declare class TextureLoader {
2315
2314
  }
2316
2315
 
2317
2316
  declare class Textures {
2317
+ /** Creates the shared checkerboard from pixels without fetching or decoding an image. */
2318
+ static getMissing(): DataTexture;
2318
2319
  static initTextureProps<T extends Texture>(texture: T): T;
2319
2320
  static createImage(key: TextureKey): Texture;
2320
2321
  static createAsset(key: AssetKey): Texture;
@@ -1,5 +1,5 @@
1
1
  import * as three from 'three';
2
- import { Vector3, PixelFormat, BoxGeometry, Material, ColorRepresentation, MeshBasicMaterial, Mesh, Euler, Vector2, BufferAttribute, Float32BufferAttribute, BufferGeometry, Object3D, Box3, InstancedMesh, PerspectiveCamera, OrthographicCamera, Matrix4, Box2, Scene, Object3DEventMap, Texture, Camera, MOUSE, TOUCH, WebGLRenderer, EventDispatcher, Raycaster, Intersection, CanvasTexture, InterleavedBufferAttribute, TrianglesDrawModes, Line, Points, Group } from 'three';
2
+ import { Vector3, PixelFormat, BoxGeometry, Material, ColorRepresentation, MeshBasicMaterial, Mesh, Euler, Vector2, BufferAttribute, Float32BufferAttribute, BufferGeometry, Object3D, Box3, InstancedMesh, PerspectiveCamera, OrthographicCamera, Matrix4, Box2, Scene, Object3DEventMap, Texture, Camera, MOUSE, TOUCH, WebGLRenderer, EventDispatcher, Raycaster, Intersection, DataTexture, CanvasTexture, InterleavedBufferAttribute, TrianglesDrawModes, Line, Points, Group } from 'three';
3
3
  import * as nodeCanvas from 'canvas';
4
4
  import { ImageData as ImageData$1, CanvasRenderingContext2D } from 'canvas';
5
5
  import { Buffer } from 'buffer';
@@ -277,7 +277,6 @@ interface EntityModelCube {
277
277
  }
278
278
 
279
279
  declare class Materials {
280
- private static readonly MISSING_TEXTURE_SRC;
281
280
  static get MISSING_TEXTURE(): Material;
282
281
  static createImage(key: MaterialKey): Material;
283
282
  static createBasicCanvasMaterial(canvas: HTMLCanvasElement, transparent?: boolean, shade?: boolean): Material;
@@ -2315,6 +2314,8 @@ declare class TextureLoader {
2315
2314
  }
2316
2315
 
2317
2316
  declare class Textures {
2317
+ /** Creates the shared checkerboard from pixels without fetching or decoding an image. */
2318
+ static getMissing(): DataTexture;
2318
2319
  static initTextureProps<T extends Texture>(texture: T): T;
2319
2320
  static createImage(key: TextureKey): Texture;
2320
2321
  static createAsset(key: AssetKey): Texture;
@@ -690,6 +690,25 @@ var init_ImageLoader = __esm({
690
690
  };
691
691
  }
692
692
  static async loadInfo(src) {
693
+ if (/^data:/i.test(src.trimStart())) {
694
+ const url = new URL(src);
695
+ url.hash = "";
696
+ const comma = url.href.indexOf(",");
697
+ if (comma < 0) {
698
+ throw new Error("Invalid image data URL");
699
+ }
700
+ let bytes = url.href.slice(comma + 1).replace(
701
+ /%([\da-f]{2})/gi,
702
+ (_, hex) => String.fromCharCode(parseInt(hex, 16))
703
+ );
704
+ if (/; *base64 *$/i.test(url.href.slice(5, comma))) {
705
+ bytes = atob(bytes);
706
+ }
707
+ return this.processResponse({
708
+ url: src,
709
+ data: Uint8Array.from(bytes, (char) => char.charCodeAt(0)).buffer
710
+ });
711
+ }
693
712
  return Requests.genericRequest({
694
713
  url: src,
695
714
  responseType: "arraybuffer"
@@ -774,6 +793,26 @@ var init_Textures = __esm({
774
793
  init_CacheKey();
775
794
  THREE2 = __toESM(require("three"));
776
795
  Textures = class _Textures {
796
+ /** Creates the shared checkerboard from pixels without fetching or decoding an image. */
797
+ static getMissing() {
798
+ return Caching.textureCache.get("builtin:missing-texture", () => {
799
+ const size = 64;
800
+ const data = new Uint8Array(size * size * 4);
801
+ for (let y = 0; y < size; y++) {
802
+ for (let x = 0; x < size; x++) {
803
+ const offset = (y * size + x) * 4;
804
+ const color = (x + y) % 2 === 0 ? 255 : 0;
805
+ data[offset] = data[offset + 2] = color;
806
+ data[offset + 3] = 255;
807
+ }
808
+ }
809
+ const texture = new import_three4.DataTexture(data, size, size);
810
+ texture.colorSpace = THREE2.SRGBColorSpace;
811
+ texture.flipY = true;
812
+ texture.needsUpdate = true;
813
+ return this.initTextureProps(texture);
814
+ });
815
+ }
777
816
  static initTextureProps(texture) {
778
817
  texture.magFilter = THREE2.NearestFilter;
779
818
  texture.minFilter = THREE2.NearestFilter;
@@ -806,7 +845,7 @@ var init_Textures = __esm({
806
845
  });
807
846
 
808
847
  // src/Materials.ts
809
- var import_three5, _Materials, Materials;
848
+ var import_three5, Materials;
810
849
  var init_Materials = __esm({
811
850
  "src/Materials.ts"() {
812
851
  init_CacheKey();
@@ -814,11 +853,12 @@ var init_Materials = __esm({
814
853
  init_Textures();
815
854
  init_TextureLoader();
816
855
  init_Caching();
817
- _Materials = class _Materials {
818
- // resolved lazily: as a static field this decoded an image the moment the library was
819
- // imported, which needs both a DOM and an EnvProvider to already be in place
856
+ Materials = class _Materials {
820
857
  static get MISSING_TEXTURE() {
821
- return _Materials.getImage({ texture: { src: _Materials.MISSING_TEXTURE_SRC } });
858
+ return Caching.materialCache.get("builtin:missing-texture", () => new import_three5.MeshBasicMaterial({
859
+ map: Textures.getMissing(),
860
+ alphaTest: 0.5
861
+ }));
822
862
  }
823
863
  static createImage(key) {
824
864
  const transparent = key.transparent || false;
@@ -1089,8 +1129,6 @@ var init_Materials = __esm({
1089
1129
  }
1090
1130
  }
1091
1131
  };
1092
- _Materials.MISSING_TEXTURE_SRC = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAQMAAACQp+OdAAAABlBMVEX/AP8AAACfphTyAAAAFUlEQVQoz2MIhQKGVVAwKjIqQrwIAHRz/wFI17TEAAAAAElFTkSuQmCC";
1093
- Materials = _Materials;
1094
1132
  }
1095
1133
  });
1096
1134
 
@@ -2617,7 +2655,7 @@ var init_UVMapper = __esm({
2617
2655
  init_CanvasImage();
2618
2656
  init_TextureAtlas();
2619
2657
  init_Caching();
2620
- init_ImageLoader();
2658
+ init_Textures();
2621
2659
  init_AssetKey();
2622
2660
  init_ModelGenerator();
2623
2661
  init_log();
@@ -2904,11 +2942,12 @@ var init_UVMapper = __esm({
2904
2942
  const size = Math.ceil(s * maxWidth);
2905
2943
  console.debug(p5, "Atlas size:", size);
2906
2944
  const squaredSize = size * size;
2907
- const missing = await ImageLoader.getData("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAQMAAACQp+OdAAAABlBMVEX/AP8AAACfphTyAAAAFUlEQVQoz2MIhQKGVVAwKjIqQrwIAHRz/wFI17TEAAAAAElFTkSuQmCC");
2908
- const empty = await ImageLoader.getData("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAQMAAACQp+OdAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAA5JREFUKM9jGAWjgAIAAAJAAAFSSwuTAAAAAElFTkSuQmCC");
2909
2945
  const image = new CanvasImage(size, size);
2910
- image.putData(missing, 0, 0);
2911
- image.putData(empty, 0, 0, 0, 0, maxWidth, maxWidth);
2946
+ const missing = Textures.getMissing().image;
2947
+ const missingPixels = image.context.createImageData(missing.width, missing.height);
2948
+ missingPixels.data.set(missing.data);
2949
+ image.putData(missingPixels, 0, 0);
2950
+ image.context.clearRect(0, 0, maxWidth, maxWidth);
2912
2951
  const positions = {};
2913
2952
  let hasTransparency = false;
2914
2953
  let hasAnimation = false;
@@ -2974,8 +3013,6 @@ var init_UVMapper = __esm({
2974
3013
  ty++;
2975
3014
  }
2976
3015
  }
2977
- const atlasImageData = image.toDataURL();
2978
- console.log(p5, "Atlas Image for", model.key, atlasImageData);
2979
3016
  this.fillMissingTextureKeys(model.textures, positions);
2980
3017
  if (isItemModel) {
2981
3018
  console.debug(p5, "Generating item model for", model);