minerender 2.1.0-alpha.67 → 2.1.0-alpha.68

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.
@@ -4247,8 +4247,8 @@ var init_EntityObject = __esm({
4247
4247
  // src/three/BufferGeometryUtils.js
4248
4248
  import {
4249
4249
  BufferAttribute as BufferAttribute4,
4250
- BufferGeometry as BufferGeometry2,
4251
- Float32BufferAttribute as Float32BufferAttribute4,
4250
+ BufferGeometry as BufferGeometry3,
4251
+ Float32BufferAttribute as Float32BufferAttribute5,
4252
4252
  InterleavedBuffer,
4253
4253
  InterleavedBufferAttribute,
4254
4254
  TriangleFanDrawMode,
@@ -4267,7 +4267,7 @@ function mergeBufferGeometries(geometries, useGroups = false) {
4267
4267
  const attributes = {};
4268
4268
  const morphAttributes = {};
4269
4269
  const morphTargetsRelative = geometries[0].morphTargetsRelative;
4270
- const mergedGeometry = new BufferGeometry2();
4270
+ const mergedGeometry = new BufferGeometry3();
4271
4271
  let offset = 0;
4272
4272
  for (let i = 0; i < geometries.length; ++i) {
4273
4273
  const geometry = geometries[i];
@@ -4776,8 +4776,8 @@ function computeMorphedAttributes(object) {
4776
4776
  }
4777
4777
  }
4778
4778
  }
4779
- const morphedPositionAttribute = new Float32BufferAttribute4(modifiedPosition, 3);
4780
- const morphedNormalAttribute = new Float32BufferAttribute4(modifiedNormal, 3);
4779
+ const morphedPositionAttribute = new Float32BufferAttribute5(modifiedPosition, 3);
4780
+ const morphedNormalAttribute = new Float32BufferAttribute5(modifiedNormal, 3);
4781
4781
  return {
4782
4782
  positionAttribute,
4783
4783
  normalAttribute,
@@ -5270,7 +5270,7 @@ var init_fluidBlocks = __esm({
5270
5270
  });
5271
5271
 
5272
5272
  // src/model/fluid/FluidGeometry.ts
5273
- import { BufferGeometry as BufferGeometry4, Float32BufferAttribute as Float32BufferAttribute5 } from "three";
5273
+ import { BufferGeometry as BufferGeometry5, Float32BufferAttribute as Float32BufferAttribute6 } from "three";
5274
5274
  function getBlockFluidState(key, state) {
5275
5275
  const rule = key && fluidRules[key.toNamespacedString()];
5276
5276
  if (rule) return {
@@ -5288,7 +5288,7 @@ function ownHeight(sample) {
5288
5288
  return (level === 0 || level >= 8 ? 8 : 8 - level) / 9;
5289
5289
  }
5290
5290
  function createFluidGeometry(kind, sample) {
5291
- const geometry = new BufferGeometry4();
5291
+ const geometry = new BufferGeometry5();
5292
5292
  const positions = [], normals = [], uvs = [], indices = [];
5293
5293
  const self = sample(0, 0, 0);
5294
5294
  const height = (x, z) => {
@@ -5387,9 +5387,9 @@ function createFluidGeometry(kind, sample) {
5387
5387
  1
5388
5388
  );
5389
5389
  }
5390
- geometry.setAttribute("position", new Float32BufferAttribute5(positions, 3));
5391
- geometry.setAttribute("normal", new Float32BufferAttribute5(normals, 3));
5392
- geometry.setAttribute("uv", new Float32BufferAttribute5(uvs, 2));
5390
+ geometry.setAttribute("position", new Float32BufferAttribute6(positions, 3));
5391
+ geometry.setAttribute("normal", new Float32BufferAttribute6(normals, 3));
5392
+ geometry.setAttribute("uv", new Float32BufferAttribute6(uvs, 2));
5393
5393
  geometry.setIndex(indices);
5394
5394
  return geometry;
5395
5395
  }
@@ -8793,6 +8793,85 @@ var GuiHelper = class {
8793
8793
  }
8794
8794
  };
8795
8795
 
8796
+ // src/gui/GuiTextureGeometry.ts
8797
+ import { BufferGeometry as BufferGeometry2, Float32BufferAttribute as Float32BufferAttribute4, PlaneGeometry } from "three";
8798
+ function createGuiTextureGeometry(width, height, imageWidth, imageHeight, crop, scaling) {
8799
+ if (crop || !scaling || scaling.type === "stretch") {
8800
+ const [x, y, w, h] = crop ?? [0, 0, imageWidth, imageHeight];
8801
+ const geometry = new PlaneGeometry(width, height);
8802
+ const uv = geometry.getAttribute("uv");
8803
+ for (let i = 0; i < uv.count; i++) {
8804
+ uv.setXY(
8805
+ i,
8806
+ (x + uv.getX(i) * w) / imageWidth,
8807
+ 1 - (y + (1 - uv.getY(i)) * h) / imageHeight
8808
+ );
8809
+ }
8810
+ return geometry;
8811
+ }
8812
+ const sw = scaling.width, sh = scaling.height;
8813
+ if (![sw, sh].every((value) => Number.isInteger(value) && value > 0)) {
8814
+ throw new Error("GUI sprite dimensions must be positive integers");
8815
+ }
8816
+ if (![width, height].every((value) => Number.isFinite(value) && value >= 0)) {
8817
+ throw new Error("GUI output dimensions must be finite and nonnegative");
8818
+ }
8819
+ const positions = [], uvs = [], normals = [], indices = [];
8820
+ function quad(x, y, w, h, u, v, uw, vh) {
8821
+ if (w <= 0 || h <= 0) return;
8822
+ const index = positions.length / 3;
8823
+ const left = x - width / 2, top = height / 2 - y;
8824
+ positions.push(left, top, 0, left + w, top, 0, left, top - h, 0, left + w, top - h, 0);
8825
+ uvs.push(
8826
+ u / sw,
8827
+ 1 - v / sh,
8828
+ (u + uw) / sw,
8829
+ 1 - v / sh,
8830
+ u / sw,
8831
+ 1 - (v + vh) / sh,
8832
+ (u + uw) / sw,
8833
+ 1 - (v + vh) / sh
8834
+ );
8835
+ normals.push(0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1);
8836
+ indices.push(index, index + 2, index + 1, index + 2, index + 3, index + 1);
8837
+ }
8838
+ function tile(x, y, w, h, u, v, tw, th) {
8839
+ for (let dy = 0; dy < h; dy += th) {
8840
+ for (let dx = 0; dx < w; dx += tw) {
8841
+ const cw = Math.min(tw, w - dx), ch = Math.min(th, h - dy);
8842
+ quad(x + dx, y + dy, cw, ch, u, v, cw, ch);
8843
+ }
8844
+ }
8845
+ }
8846
+ if (scaling.type === "tile") {
8847
+ tile(0, 0, width, height, 0, 0, sw, sh);
8848
+ } else {
8849
+ let segments = function(size, sourceSize, start, end) {
8850
+ if (size === sourceSize) return [[0, size, 0, sourceSize]];
8851
+ start = Math.min(start, Math.floor(size / 2));
8852
+ end = Math.min(end, Math.floor(size / 2));
8853
+ return [
8854
+ [0, start, 0, start],
8855
+ [start, size - start - end, start, sourceSize - start - end],
8856
+ [size - end, end, sourceSize - end, end]
8857
+ ];
8858
+ };
8859
+ const border = typeof scaling.border === "number" ? { left: scaling.border, top: scaling.border, right: scaling.border, bottom: scaling.border } : scaling.border;
8860
+ if (!border || typeof scaling.border === "number" && scaling.border <= 0 || ![border.left, border.top, border.right, border.bottom].every((value) => Number.isInteger(value) && value >= 0) || border.left + border.right >= sw || border.top + border.bottom >= sh) {
8861
+ throw new Error("GUI nine-slice borders must be nonnegative integers with a nonempty center");
8862
+ }
8863
+ const columns = segments(width, sw, border.left, border.right);
8864
+ const rows = segments(height, sh, border.top, border.bottom);
8865
+ for (const [y, h, v, vh] of rows) {
8866
+ for (const [x, w, u, uw] of columns) {
8867
+ if (w <= 0 || h <= 0) continue;
8868
+ (scaling.stretch_inner ? quad : tile)(x, y, w, h, u, v, uw, vh);
8869
+ }
8870
+ }
8871
+ }
8872
+ return new BufferGeometry2().setAttribute("position", new Float32BufferAttribute4(positions, 3)).setAttribute("normal", new Float32BufferAttribute4(normals, 3)).setAttribute("uv", new Float32BufferAttribute4(uvs, 2)).setIndex(indices);
8873
+ }
8874
+
8796
8875
  // src/gui/scene/GuiObject.ts
8797
8876
  init_AssetKey();
8798
8877
  init_ModelTextures();
@@ -8803,7 +8882,7 @@ init_Materials();
8803
8882
  init_ModelObject();
8804
8883
  init_DisplayPosition();
8805
8884
  init_GuiLight();
8806
- import { Box2, Box3 as Box32, Matrix4 as Matrix410, Mesh as Mesh6, PlaneGeometry, Vector2 as Vector23 } from "three";
8885
+ import { Box2, Box3 as Box32, Matrix4 as Matrix410, Mesh as Mesh6, Vector2 as Vector23 } from "three";
8807
8886
  var GuiObject = class extends SceneObject {
8808
8887
  constructor(textureLayers, options) {
8809
8888
  super({ ...options, instanceMeshes: false, mergeMeshes: false });
@@ -8844,18 +8923,10 @@ var GuiObject = class extends SceneObject {
8844
8923
  const key = typeof layer.texture === "string" ? AssetKey.parse("textures", layer.texture) : layer.texture;
8845
8924
  const material = await this.loadMaterial(key);
8846
8925
  const image = material.map.image;
8847
- const [cropX, cropY, cropWidth, cropHeight] = layer.crop ?? [0, 0, image.width, image.height];
8848
- const [width, height] = layer.size ?? [cropWidth, cropHeight];
8849
- const geometry = new PlaneGeometry(width, height);
8926
+ const scaling = layer.crop ? void 0 : (await ModelTextures.getMeta(key))?.gui?.scaling;
8927
+ const [width, height] = layer.size ?? (layer.crop ? layer.crop.slice(2) : scaling && scaling.type !== "stretch" ? [scaling.width, scaling.height] : [image.width, image.height]);
8928
+ const geometry = createGuiTextureGeometry(width, height, image.width, image.height, layer.crop, scaling);
8850
8929
  this.geometries.add(geometry);
8851
- const uv = geometry.getAttribute("uv");
8852
- for (let i = 0; i < uv.count; i++) {
8853
- uv.setXY(
8854
- i,
8855
- (cropX + uv.getX(i) * cropWidth) / image.width,
8856
- 1 - (cropY + (1 - uv.getY(i)) * cropHeight) / image.height
8857
- );
8858
- }
8859
8930
  const mesh = new Mesh6(geometry, material);
8860
8931
  mesh.name = `mesh:${layer.name ?? index}`;
8861
8932
  mesh.position.set(x + width / 2, -y - height / 2, depth);
@@ -14782,7 +14853,7 @@ init_Model();
14782
14853
  // src/world/SectionMesh.ts
14783
14854
  init_CanvasCompat();
14784
14855
  init_Materials();
14785
- import { BufferGeometry as BufferGeometry6, Float32BufferAttribute as Float32BufferAttribute6, Group, Mesh as Mesh9 } from "three";
14856
+ import { BufferGeometry as BufferGeometry7, Float32BufferAttribute as Float32BufferAttribute7, Group, Mesh as Mesh9 } from "three";
14786
14857
  var SectionMesh = class _SectionMesh extends Group {
14787
14858
  constructor() {
14788
14859
  super(...arguments);
@@ -14856,11 +14927,11 @@ var SectionMesh = class _SectionMesh extends Group {
14856
14927
  for (let corner = 0; corner < 6; corner++) indices.push(start + sourceIndices.getX(face * 6 + corner) - face * 4);
14857
14928
  }
14858
14929
  }
14859
- const geometry = new BufferGeometry6();
14860
- geometry.setAttribute("position", new Float32BufferAttribute6(positions, 3));
14861
- geometry.setAttribute("normal", new Float32BufferAttribute6(normals, 3));
14862
- geometry.setAttribute("uv", new Float32BufferAttribute6(uvs, 2));
14863
- geometry.setAttribute("color", new Float32BufferAttribute6(colors, 3));
14930
+ const geometry = new BufferGeometry7();
14931
+ geometry.setAttribute("position", new Float32BufferAttribute7(positions, 3));
14932
+ geometry.setAttribute("normal", new Float32BufferAttribute7(normals, 3));
14933
+ geometry.setAttribute("uv", new Float32BufferAttribute7(uvs, 2));
14934
+ geometry.setAttribute("color", new Float32BufferAttribute7(colors, 3));
14864
14935
  geometry.setIndex(indices);
14865
14936
  geometry.computeBoundingBox();
14866
14937
  geometry.computeBoundingSphere();
@@ -15185,6 +15256,7 @@ export {
15185
15256
  computeTangents,
15186
15257
  createCanvas,
15187
15258
  createFluidGeometry,
15259
+ createGuiTextureGeometry,
15188
15260
  createImage,
15189
15261
  entityAnimationTime,
15190
15262
  estimateBytesUsed,