minerender 2.1.0-alpha.52 → 2.1.0-alpha.53

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.
@@ -3450,48 +3450,6 @@ var init_SceneObject = __esm({
3450
3450
  }
3451
3451
  });
3452
3452
 
3453
- // src/model/ModelCulling.ts
3454
- import { Vector3 as Vector39 } from "three";
3455
- var ModelCulling;
3456
- var init_ModelCulling = __esm({
3457
- "src/model/ModelCulling.ts"() {
3458
- init_CubeFace();
3459
- ModelCulling = class {
3460
- static toLocalMask(worldMask, rotation) {
3461
- let localMask = 0;
3462
- for (const [localFace, offset] of CUBE_FACE_OFFSETS.entries()) {
3463
- const normal = new Vector39(...offset).applyEuler(rotation);
3464
- const worldFace = CUBE_FACE_OFFSETS.findIndex(([x, y, z]) => Math.abs(normal.x - x) < 1e-6 && Math.abs(normal.y - y) < 1e-6 && Math.abs(normal.z - z) < 1e-6);
3465
- if (worldFace < 0) return 0;
3466
- if (worldMask & 1 << worldFace) localMask |= 1 << localFace;
3467
- }
3468
- return localMask;
3469
- }
3470
- static isOpaqueFullCube(atlas) {
3471
- if (!atlas || atlas.hasTransparency !== false || atlas.model.elements?.length !== 1) return false;
3472
- const element = atlas.model.elements[0];
3473
- if (element.from.length !== 3 || !element.from.every((value) => value === 0) || element.to.length !== 3 || !element.to.every((value) => value === 16) || element.rotation && element.rotation.angle !== 0 || element.mappedUv?.length !== 48 || !element.mappedUv.every(Number.isFinite)) return false;
3474
- if (!(atlas.image.width > 0 && atlas.image.height > 0)) return false;
3475
- return CUBE_FACES.every((face, faceIndex) => {
3476
- const texture = element.faces[face]?.texture;
3477
- if (!texture?.startsWith("#")) return false;
3478
- const key = texture.slice(1);
3479
- const position = atlas.positions[key];
3480
- const size = atlas.sizes[key];
3481
- if (position?.length !== 2 || !position.every(Number.isFinite) || size?.length !== 2 || !size.every((value) => value > 0 && Number.isFinite(value))) return false;
3482
- for (let vertex = 0; vertex < 4; vertex++) {
3483
- const uvIndex = (faceIndex * 4 + vertex) * 2;
3484
- const x = element.mappedUv[uvIndex] * atlas.image.width;
3485
- const y = (1 - element.mappedUv[uvIndex + 1]) * atlas.image.height;
3486
- if (x < position[0] - 1e-6 || x > position[0] + size[0] + 1e-6 || y < position[1] - 1e-6 || y > position[1] + size[1] + 1e-6) return false;
3487
- }
3488
- return true;
3489
- });
3490
- }
3491
- };
3492
- }
3493
- });
3494
-
3495
3453
  // src/three/BufferGeometryUtils.js
3496
3454
  import {
3497
3455
  BufferAttribute as BufferAttribute4,
@@ -3502,7 +3460,7 @@ import {
3502
3460
  TriangleFanDrawMode,
3503
3461
  TriangleStripDrawMode,
3504
3462
  TrianglesDrawMode,
3505
- Vector3 as Vector310
3463
+ Vector3 as Vector39
3506
3464
  } from "three";
3507
3465
  function computeTangents(geometry) {
3508
3466
  geometry.computeTangents();
@@ -3821,15 +3779,15 @@ function computeMorphedAttributes(object) {
3821
3779
  console.error("THREE.BufferGeometryUtils: Geometry is not of type BufferGeometry.");
3822
3780
  return null;
3823
3781
  }
3824
- const _vA = new Vector310();
3825
- const _vB = new Vector310();
3826
- const _vC = new Vector310();
3827
- const _tempA = new Vector310();
3828
- const _tempB = new Vector310();
3829
- const _tempC = new Vector310();
3830
- const _morphA = new Vector310();
3831
- const _morphB = new Vector310();
3832
- const _morphC = new Vector310();
3782
+ const _vA = new Vector39();
3783
+ const _vB = new Vector39();
3784
+ const _vC = new Vector39();
3785
+ const _tempA = new Vector39();
3786
+ const _tempB = new Vector39();
3787
+ const _tempC = new Vector39();
3788
+ const _morphA = new Vector39();
3789
+ const _morphB = new Vector39();
3790
+ const _morphC = new Vector39();
3833
3791
  function _calculateMorphedAttributeData(object2, material2, attribute, morphAttribute, morphTargetsRelative2, a2, b2, c2, modifiedAttributeArray) {
3834
3792
  _vA.fromBufferAttribute(attribute, a2);
3835
3793
  _vB.fromBufferAttribute(attribute, b2);
@@ -4038,12 +3996,54 @@ var init_BufferGeometryUtils = __esm({
4038
3996
  }
4039
3997
  });
4040
3998
 
3999
+ // src/model/ModelCulling.ts
4000
+ import { Vector3 as Vector310 } from "three";
4001
+ var ModelCulling;
4002
+ var init_ModelCulling = __esm({
4003
+ "src/model/ModelCulling.ts"() {
4004
+ init_CubeFace();
4005
+ ModelCulling = class {
4006
+ static toLocalMask(worldMask, rotation) {
4007
+ let localMask = 0;
4008
+ for (const [localFace, offset] of CUBE_FACE_OFFSETS.entries()) {
4009
+ const normal = new Vector310(...offset).applyEuler(rotation);
4010
+ const worldFace = CUBE_FACE_OFFSETS.findIndex(([x, y, z]) => Math.abs(normal.x - x) < 1e-6 && Math.abs(normal.y - y) < 1e-6 && Math.abs(normal.z - z) < 1e-6);
4011
+ if (worldFace < 0) return 0;
4012
+ if (worldMask & 1 << worldFace) localMask |= 1 << localFace;
4013
+ }
4014
+ return localMask;
4015
+ }
4016
+ static isOpaqueFullCube(atlas) {
4017
+ if (!atlas || atlas.hasTransparency !== false || atlas.model.elements?.length !== 1) return false;
4018
+ const element = atlas.model.elements[0];
4019
+ if (element.from.length !== 3 || !element.from.every((value) => value === 0) || element.to.length !== 3 || !element.to.every((value) => value === 16) || element.rotation && element.rotation.angle !== 0 || element.mappedUv?.length !== 48 || !element.mappedUv.every(Number.isFinite)) return false;
4020
+ if (!(atlas.image.width > 0 && atlas.image.height > 0)) return false;
4021
+ return CUBE_FACES.every((face, faceIndex) => {
4022
+ const texture = element.faces[face]?.texture;
4023
+ if (!texture?.startsWith("#")) return false;
4024
+ const key = texture.slice(1);
4025
+ const position = atlas.positions[key];
4026
+ const size = atlas.sizes[key];
4027
+ if (position?.length !== 2 || !position.every(Number.isFinite) || size?.length !== 2 || !size.every((value) => value > 0 && Number.isFinite(value))) return false;
4028
+ for (let vertex = 0; vertex < 4; vertex++) {
4029
+ const uvIndex = (faceIndex * 4 + vertex) * 2;
4030
+ const x = element.mappedUv[uvIndex] * atlas.image.width;
4031
+ const y = (1 - element.mappedUv[uvIndex + 1]) * atlas.image.height;
4032
+ if (x < position[0] - 1e-6 || x > position[0] + size[0] + 1e-6 || y < position[1] - 1e-6 || y > position[1] + size[1] + 1e-6) return false;
4033
+ }
4034
+ return true;
4035
+ });
4036
+ }
4037
+ };
4038
+ }
4039
+ });
4040
+
4041
4041
  // src/model/scene/ModelObject.ts
4042
- import { BoxGeometry as BoxGeometry5, BufferAttribute as BufferAttribute5, Color as Color7, Euler as Euler6, Matrix4 as Matrix46 } from "three";
4042
+ import { BoxGeometry as BoxGeometry5, BufferAttribute as BufferAttribute5, Color as Color7, Euler as Euler5, Matrix4 as Matrix46 } from "three";
4043
4043
  function isModelObject(obj) {
4044
4044
  return obj.isModelObject;
4045
4045
  }
4046
- var import_ts_deepmerge5, p9, _ModelObject, ModelObject;
4046
+ var import_ts_deepmerge5, p7, _ModelObject, ModelObject;
4047
4047
  var init_ModelObject = __esm({
4048
4048
  "src/model/scene/ModelObject.ts"() {
4049
4049
  init_SceneObject();
@@ -4056,7 +4056,7 @@ var init_ModelObject = __esm({
4056
4056
  init_CubeFace();
4057
4057
  init_DisplayTransforms();
4058
4058
  init_ModelCulling();
4059
- p9 = prefix("ModelObject");
4059
+ p7 = prefix("ModelObject");
4060
4060
  _ModelObject = class _ModelObject extends SceneObject {
4061
4061
  constructor(originalModel, options) {
4062
4062
  super(options);
@@ -4102,7 +4102,7 @@ var init_ModelObject = __esm({
4102
4102
  elGeo.clearGroups();
4103
4103
  }
4104
4104
  if (this.options.uvLockRotation) {
4105
- UVMapper.lockUvs(elGeo, el.faces, this.atlas, new Euler6(...this.options.uvLockRotation));
4105
+ UVMapper.lockUvs(elGeo, el.faces, this.atlas, new Euler5(...this.options.uvLockRotation));
4106
4106
  }
4107
4107
  if (this.options.tints) {
4108
4108
  const colors = new Float32Array(elGeo.getAttribute("position").count * 3).fill(1);
@@ -4135,10 +4135,10 @@ var init_ModelObject = __esm({
4135
4135
  }
4136
4136
  });
4137
4137
  } else {
4138
- console.debug(p9, this.atlas.model, "has no elements");
4138
+ console.debug(p7, this.atlas.model, "has no elements");
4139
4139
  }
4140
4140
  } else {
4141
- console.debug(p9, "Missing atlas for", this);
4141
+ console.debug(p7, "Missing atlas for", this);
4142
4142
  }
4143
4143
  if (this.options.mergeMeshes) {
4144
4144
  let combinedGeo;
@@ -4238,7 +4238,7 @@ var init_fluidBlocks = __esm({
4238
4238
  });
4239
4239
 
4240
4240
  // src/model/fluid/FluidGeometry.ts
4241
- import { BufferGeometry as BufferGeometry3, Float32BufferAttribute as Float32BufferAttribute5 } from "three";
4241
+ import { BufferGeometry as BufferGeometry4, Float32BufferAttribute as Float32BufferAttribute5 } from "three";
4242
4242
  function getBlockFluidState(key, state) {
4243
4243
  const rule = key && fluidRules[key.toNamespacedString()];
4244
4244
  if (rule) return {
@@ -4256,7 +4256,7 @@ function ownHeight(sample) {
4256
4256
  return (level === 0 || level >= 8 ? 8 : 8 - level) / 9;
4257
4257
  }
4258
4258
  function createFluidGeometry(kind, sample) {
4259
- const geometry = new BufferGeometry3();
4259
+ const geometry = new BufferGeometry4();
4260
4260
  const positions = [], normals = [], uvs = [], indices = [];
4261
4261
  const self = sample(0, 0, 0);
4262
4262
  const height = (x, z) => {
@@ -7551,10 +7551,22 @@ var GuiHelper = class {
7551
7551
  // src/gui/scene/GuiObject.ts
7552
7552
  init_AssetKey();
7553
7553
  init_ModelTextures();
7554
+ init_Models();
7554
7555
  init_Caching();
7555
7556
  init_SceneObject();
7556
7557
  init_Materials();
7557
- import { Box2, Mesh as Mesh6, PlaneGeometry as PlaneGeometry2, Vector2 as Vector23 } from "three";
7558
+ init_ModelObject();
7559
+ init_DisplayPosition();
7560
+ import { Box2, Box3 as Box32, Mesh as Mesh7, PlaneGeometry as PlaneGeometry2, Vector2 as Vector23 } from "three";
7561
+
7562
+ // src/model/GuiLight.ts
7563
+ var GuiLight = /* @__PURE__ */ ((GuiLight2) => {
7564
+ GuiLight2["FRONT"] = "front";
7565
+ GuiLight2["SIDE"] = "side";
7566
+ return GuiLight2;
7567
+ })(GuiLight || {});
7568
+
7569
+ // src/gui/scene/GuiObject.ts
7558
7570
  var GuiObject = class extends SceneObject {
7559
7571
  constructor(textureLayers, options) {
7560
7572
  super({ ...options, instanceMeshes: false, mergeMeshes: false });
@@ -7569,13 +7581,34 @@ var GuiObject = class extends SceneObject {
7569
7581
  async init() {
7570
7582
  if (this.initialized) return;
7571
7583
  try {
7584
+ let depth = 0;
7572
7585
  for (const [index, layer] of this.textureLayers.entries()) {
7586
+ const [x, y] = layer.position ?? [0, 0];
7587
+ if ("item" in layer) {
7588
+ const [width2, height2] = layer.size ?? [16, 16];
7589
+ const item = await this.createItem(layer, index);
7590
+ item.position.set(x + width2 / 2, -y - height2 / 2, 0);
7591
+ item.scale.set(width2 / 16, height2 / 16, width2 / 16);
7592
+ item.updateMatrix();
7593
+ const bounds = new Box32();
7594
+ item.iterateAllMeshes((mesh2) => {
7595
+ mesh2.geometry.computeBoundingBox();
7596
+ bounds.union(mesh2.geometry.boundingBox);
7597
+ });
7598
+ bounds.applyMatrix4(item.matrix);
7599
+ item.position.z = depth - bounds.min.z;
7600
+ depth += bounds.max.z - bounds.min.z + 0.01;
7601
+ this.bounds.expandByPoint(new Vector23(x, y));
7602
+ this.bounds.expandByPoint(new Vector23(x + width2, y + height2));
7603
+ this.bounds.expandByPoint(new Vector23(bounds.min.x, -bounds.max.y));
7604
+ this.bounds.expandByPoint(new Vector23(bounds.max.x, -bounds.min.y));
7605
+ continue;
7606
+ }
7573
7607
  const key = typeof layer.texture === "string" ? AssetKey.parse("textures", layer.texture) : layer.texture;
7574
7608
  const material = await this.loadMaterial(key);
7575
7609
  const image = material.map.image;
7576
7610
  const [cropX, cropY, cropWidth, cropHeight] = layer.crop ?? [0, 0, image.width, image.height];
7577
7611
  const [width, height] = layer.size ?? [cropWidth, cropHeight];
7578
- const [x, y] = layer.position ?? [0, 0];
7579
7612
  const geometry = new PlaneGeometry2(width, height);
7580
7613
  this.geometries.add(geometry);
7581
7614
  const uv = geometry.getAttribute("uv");
@@ -7586,14 +7619,16 @@ var GuiObject = class extends SceneObject {
7586
7619
  1 - (cropY + (1 - uv.getY(i)) * cropHeight) / image.height
7587
7620
  );
7588
7621
  }
7589
- const mesh = new Mesh6(geometry, material);
7622
+ const mesh = new Mesh7(geometry, material);
7590
7623
  mesh.name = `mesh:${layer.name ?? index}`;
7591
- mesh.position.set(x + width / 2, -y - height / 2, 0);
7624
+ mesh.position.set(x + width / 2, -y - height / 2, depth);
7592
7625
  mesh.renderOrder = index;
7593
7626
  this.add(mesh);
7594
7627
  this.bounds.expandByPoint(new Vector23(x, y));
7595
7628
  this.bounds.expandByPoint(new Vector23(x + width, y + height));
7629
+ depth += 0.01;
7596
7630
  }
7631
+ for (const child of this.children) child.position.z -= depth - 0.01;
7597
7632
  this.initialized = true;
7598
7633
  this.notifyDirty();
7599
7634
  } catch (error) {
@@ -7601,6 +7636,32 @@ var GuiObject = class extends SceneObject {
7601
7636
  throw error;
7602
7637
  }
7603
7638
  }
7639
+ async createItem(layer, index) {
7640
+ const key = typeof layer.item === "string" ? AssetKey.parse("models", layer.item) : layer.item;
7641
+ const model = await Models.getMerged(key);
7642
+ if (!model) throw new Error(`Could not load GUI item ${key.toNamespacedString()}`);
7643
+ const item = new ModelObject(model, {
7644
+ displayPosition: "gui" /* GUI */,
7645
+ tints: layer.tints,
7646
+ instanceMeshes: false,
7647
+ mergeMeshes: true
7648
+ });
7649
+ item.name = `group:${layer.name ?? index}`;
7650
+ this.add(item);
7651
+ await item.init();
7652
+ item.iterateAllMeshes((mesh) => {
7653
+ this.geometries.add(mesh.geometry);
7654
+ mesh.name = `mesh:${layer.name ?? index}`;
7655
+ mesh.renderOrder = index;
7656
+ for (const material of Array.isArray(mesh.material) ? mesh.material : [mesh.material]) {
7657
+ material.transparent = true;
7658
+ if (model.gui_light === "front" /* FRONT */ && material.uniforms?.SHADE) {
7659
+ material.uniforms.SHADE.value = false;
7660
+ }
7661
+ }
7662
+ });
7663
+ return item;
7664
+ }
7604
7665
  async loadMaterial(key) {
7605
7666
  const assetKey = key.serialize();
7606
7667
  const materialKey = `gui:${assetKey}`;
@@ -7644,7 +7705,7 @@ init_util();
7644
7705
  import { Raycaster, Vector2 as Vector24 } from "three";
7645
7706
  init_log();
7646
7707
  init_three();
7647
- var p7 = prefix("SceneInspector");
7708
+ var p8 = prefix("SceneInspector");
7648
7709
  var help = "<span>Ctrl/Cmd+Click to Select<br/></span><br/>";
7649
7710
  var SceneInspector = class {
7650
7711
  constructor(renderer) {
@@ -7738,7 +7799,7 @@ var SceneInspector = class {
7738
7799
  }
7739
7800
  selectObject(targetObject, targetIntersection, instance = this.getIntersectionInstance(targetIntersection)) {
7740
7801
  this.selectedObject = targetObject;
7741
- console.log(p7, "selected", targetObject);
7802
+ console.log(p8, "selected", targetObject);
7742
7803
  this.redraw(targetObject, targetIntersection, instance);
7743
7804
  }
7744
7805
  redraw(targetObject, targetIntersection, instance) {
@@ -7997,7 +8058,7 @@ var SceneStatsDisplay = class {
7997
8058
 
7998
8059
  // src/instance/InstanceManager.ts
7999
8060
  init_log();
8000
- var p8 = prefix("InstanceManager");
8061
+ var p9 = prefix("InstanceManager");
8001
8062
  var InstanceManager = class {
8002
8063
  constructor() {
8003
8064
  this.isInstanceManager = true;
@@ -8005,7 +8066,7 @@ var InstanceManager = class {
8005
8066
  }
8006
8067
  async get(key) {
8007
8068
  if (key in this.instanceCache) {
8008
- console.debug(p8, "key in cache", key);
8069
+ console.debug(p9, "key in cache", key);
8009
8070
  return (await this.instanceCache[key]).nextInstance();
8010
8071
  }
8011
8072
  return void 0;
@@ -8014,7 +8075,7 @@ var InstanceManager = class {
8014
8075
  if (key in this.instanceCache) {
8015
8076
  return await this.get(key);
8016
8077
  }
8017
- console.debug(p8, "key not in cache", key);
8078
+ console.debug(p9, "key not in cache", key);
8018
8079
  const pending = Promise.resolve().then(supplier).then((obj) => obj.nextInstance());
8019
8080
  this.instanceCache[key] = pending;
8020
8081
  try {
@@ -8048,13 +8109,6 @@ function isInstanceable(obj) {
8048
8109
  init_DisplayPosition();
8049
8110
  init_DisplayTransforms();
8050
8111
 
8051
- // src/model/GuiLight.ts
8052
- var GuiLight = /* @__PURE__ */ ((GuiLight2) => {
8053
- GuiLight2["FRONT"] = "front";
8054
- GuiLight2["SIDE"] = "side";
8055
- return GuiLight2;
8056
- })(GuiLight || {});
8057
-
8058
8112
  // src/model/Model.ts
8059
8113
  var ITEM_GENERATED = "item/generated";
8060
8114
  var BUILTIN_GENERATED = "builtin/generated";
@@ -8079,7 +8133,7 @@ init_ModelMerger();
8079
8133
  init_BlockStates();
8080
8134
  init_MineRenderError();
8081
8135
  init_util();
8082
- import { Euler as Euler5 } from "three";
8136
+ import { Euler as Euler6 } from "three";
8083
8137
  function matchesCondition(condition, state) {
8084
8138
  return Object.entries(condition).every(([key, value]) => {
8085
8139
  if (Array.isArray(value)) {
@@ -8154,7 +8208,7 @@ var BlockStateResolver = class {
8154
8208
  return variants[variants.length - 1];
8155
8209
  }
8156
8210
  static rotation(variant) {
8157
- const rotation = new Euler5();
8211
+ const rotation = new Euler6();
8158
8212
  if (typeof variant.x !== "undefined") {
8159
8213
  rotation.x = toRadians(clampRotationDegrees(variant.x));
8160
8214
  }
@@ -13400,7 +13454,7 @@ var MineRenderWorld = class {
13400
13454
  // src/world/SectionMesh.ts
13401
13455
  init_CanvasCompat();
13402
13456
  init_Materials();
13403
- import { BufferGeometry as BufferGeometry5, Float32BufferAttribute as Float32BufferAttribute6, Group, Mesh as Mesh10 } from "three";
13457
+ import { BufferGeometry as BufferGeometry6, Float32BufferAttribute as Float32BufferAttribute6, Group, Mesh as Mesh10 } from "three";
13404
13458
  var SectionMesh = class _SectionMesh extends Group {
13405
13459
  constructor() {
13406
13460
  super(...arguments);
@@ -13474,7 +13528,7 @@ var SectionMesh = class _SectionMesh extends Group {
13474
13528
  for (let corner = 0; corner < 6; corner++) indices.push(start + sourceIndices.getX(face * 6 + corner) - face * 4);
13475
13529
  }
13476
13530
  }
13477
- const geometry = new BufferGeometry5();
13531
+ const geometry = new BufferGeometry6();
13478
13532
  geometry.setAttribute("position", new Float32BufferAttribute6(positions, 3));
13479
13533
  geometry.setAttribute("normal", new Float32BufferAttribute6(normals, 3));
13480
13534
  geometry.setAttribute("uv", new Float32BufferAttribute6(uvs, 2));