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.
package/dist/bundle.js CHANGED
@@ -93384,6 +93384,7 @@ ${shader.fragmentShader}`.replace(
93384
93384
  computeTangents: () => computeTangents,
93385
93385
  createCanvas: () => createCanvas,
93386
93386
  createFluidGeometry: () => createFluidGeometry,
93387
+ createGuiTextureGeometry: () => createGuiTextureGeometry,
93387
93388
  createImage: () => createImage,
93388
93389
  entityAnimationTime: () => entityAnimationTime,
93389
93390
  estimateBytesUsed: () => estimateBytesUsed,
@@ -96858,6 +96859,88 @@ property list uchar int vertex_index
96858
96859
  init_buffer2();
96859
96860
  init_process2();
96860
96861
 
96862
+ // src/gui/GuiTextureGeometry.ts
96863
+ init_dirname();
96864
+ init_buffer2();
96865
+ init_process2();
96866
+ init_three_module();
96867
+ function createGuiTextureGeometry(width, height, imageWidth, imageHeight, crop, scaling) {
96868
+ if (crop || !scaling || scaling.type === "stretch") {
96869
+ const [x4, y5, w4, h5] = crop ?? [0, 0, imageWidth, imageHeight];
96870
+ const geometry = new PlaneGeometry(width, height);
96871
+ const uv = geometry.getAttribute("uv");
96872
+ for (let i4 = 0; i4 < uv.count; i4++) {
96873
+ uv.setXY(
96874
+ i4,
96875
+ (x4 + uv.getX(i4) * w4) / imageWidth,
96876
+ 1 - (y5 + (1 - uv.getY(i4)) * h5) / imageHeight
96877
+ );
96878
+ }
96879
+ return geometry;
96880
+ }
96881
+ const sw = scaling.width, sh = scaling.height;
96882
+ if (![sw, sh].every((value) => Number.isInteger(value) && value > 0)) {
96883
+ throw new Error("GUI sprite dimensions must be positive integers");
96884
+ }
96885
+ if (![width, height].every((value) => Number.isFinite(value) && value >= 0)) {
96886
+ throw new Error("GUI output dimensions must be finite and nonnegative");
96887
+ }
96888
+ const positions = [], uvs = [], normals = [], indices = [];
96889
+ function quad(x4, y5, w4, h5, u4, v5, uw, vh) {
96890
+ if (w4 <= 0 || h5 <= 0) return;
96891
+ const index = positions.length / 3;
96892
+ const left = x4 - width / 2, top = height / 2 - y5;
96893
+ positions.push(left, top, 0, left + w4, top, 0, left, top - h5, 0, left + w4, top - h5, 0);
96894
+ uvs.push(
96895
+ u4 / sw,
96896
+ 1 - v5 / sh,
96897
+ (u4 + uw) / sw,
96898
+ 1 - v5 / sh,
96899
+ u4 / sw,
96900
+ 1 - (v5 + vh) / sh,
96901
+ (u4 + uw) / sw,
96902
+ 1 - (v5 + vh) / sh
96903
+ );
96904
+ normals.push(0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1);
96905
+ indices.push(index, index + 2, index + 1, index + 2, index + 3, index + 1);
96906
+ }
96907
+ function tile(x4, y5, w4, h5, u4, v5, tw, th) {
96908
+ for (let dy = 0; dy < h5; dy += th) {
96909
+ for (let dx = 0; dx < w4; dx += tw) {
96910
+ const cw = Math.min(tw, w4 - dx), ch = Math.min(th, h5 - dy);
96911
+ quad(x4 + dx, y5 + dy, cw, ch, u4, v5, cw, ch);
96912
+ }
96913
+ }
96914
+ }
96915
+ if (scaling.type === "tile") {
96916
+ tile(0, 0, width, height, 0, 0, sw, sh);
96917
+ } else {
96918
+ let segments = function(size, sourceSize, start, end) {
96919
+ if (size === sourceSize) return [[0, size, 0, sourceSize]];
96920
+ start = Math.min(start, Math.floor(size / 2));
96921
+ end = Math.min(end, Math.floor(size / 2));
96922
+ return [
96923
+ [0, start, 0, start],
96924
+ [start, size - start - end, start, sourceSize - start - end],
96925
+ [size - end, end, sourceSize - end, end]
96926
+ ];
96927
+ };
96928
+ const border2 = typeof scaling.border === "number" ? { left: scaling.border, top: scaling.border, right: scaling.border, bottom: scaling.border } : scaling.border;
96929
+ if (!border2 || typeof scaling.border === "number" && scaling.border <= 0 || ![border2.left, border2.top, border2.right, border2.bottom].every((value) => Number.isInteger(value) && value >= 0) || border2.left + border2.right >= sw || border2.top + border2.bottom >= sh) {
96930
+ throw new Error("GUI nine-slice borders must be nonnegative integers with a nonempty center");
96931
+ }
96932
+ const columns = segments(width, sw, border2.left, border2.right);
96933
+ const rows = segments(height, sh, border2.top, border2.bottom);
96934
+ for (const [y5, h5, v5, vh] of rows) {
96935
+ for (const [x4, w4, u4, uw] of columns) {
96936
+ if (w4 <= 0 || h5 <= 0) continue;
96937
+ (scaling.stretch_inner ? quad : tile)(x4, y5, w4, h5, u4, v5, uw, vh);
96938
+ }
96939
+ }
96940
+ }
96941
+ return new BufferGeometry().setAttribute("position", new Float32BufferAttribute(positions, 3)).setAttribute("normal", new Float32BufferAttribute(normals, 3)).setAttribute("uv", new Float32BufferAttribute(uvs, 2)).setIndex(indices);
96942
+ }
96943
+
96861
96944
  // src/gui/scene/index.ts
96862
96945
  init_dirname();
96863
96946
  init_buffer2();
@@ -96917,18 +97000,10 @@ property list uchar int vertex_index
96917
97000
  const key = typeof layer.texture === "string" ? AssetKey.parse("textures", layer.texture) : layer.texture;
96918
97001
  const material = await this.loadMaterial(key);
96919
97002
  const image = material.map.image;
96920
- const [cropX, cropY, cropWidth, cropHeight] = layer.crop ?? [0, 0, image.width, image.height];
96921
- const [width, height] = layer.size ?? [cropWidth, cropHeight];
96922
- const geometry = new PlaneGeometry(width, height);
97003
+ const scaling = layer.crop ? void 0 : (await ModelTextures.getMeta(key))?.gui?.scaling;
97004
+ const [width, height] = layer.size ?? (layer.crop ? layer.crop.slice(2) : scaling && scaling.type !== "stretch" ? [scaling.width, scaling.height] : [image.width, image.height]);
97005
+ const geometry = createGuiTextureGeometry(width, height, image.width, image.height, layer.crop, scaling);
96923
97006
  this.geometries.add(geometry);
96924
- const uv = geometry.getAttribute("uv");
96925
- for (let i4 = 0; i4 < uv.count; i4++) {
96926
- uv.setXY(
96927
- i4,
96928
- (cropX + uv.getX(i4) * cropWidth) / image.width,
96929
- 1 - (cropY + (1 - uv.getY(i4)) * cropHeight) / image.height
96930
- );
96931
- }
96932
97007
  const mesh = new Mesh(geometry, material);
96933
97008
  mesh.name = `mesh:${layer.name ?? index}`;
96934
97009
  mesh.position.set(x4 + width / 2, -y5 - height / 2, depth);