minerender 2.1.0-alpha.122 → 2.1.0-alpha.124

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
@@ -88859,11 +88859,14 @@ ${key}` : key;
88859
88859
  });
88860
88860
  }
88861
88861
  static fillMissingTextureKeys(textures, target) {
88862
- for (let faceName of CUBE_FACES) {
88863
- let v5 = textures[faceName];
88864
- if (v5 && v5.startsWith("#")) {
88865
- target[faceName] = target[v5.substr(1)];
88862
+ for (const key in textures) {
88863
+ let name2 = key;
88864
+ const seen = /* @__PURE__ */ new Set();
88865
+ while (textures[name2]?.startsWith("#") && !seen.has(name2)) {
88866
+ seen.add(name2);
88867
+ name2 = textures[name2].substr(1);
88866
88868
  }
88869
+ if (name2 !== key) target[key] = target[name2];
88867
88870
  }
88868
88871
  return target;
88869
88872
  }
@@ -107853,11 +107856,77 @@ gl_FragDepth=readDepth(vUv);
107853
107856
 
107854
107857
  // src/world/_entities/WorldEntities.ts
107855
107858
  init_BannerPatterns();
107859
+ init_three_module();
107860
+
107861
+ // src/world/_picking/Picking.ts
107862
+ init_dirname();
107863
+ init_buffer2();
107864
+ init_process2();
107865
+ init_three_module();
107866
+ init_three();
107867
+ function pickableMeshes(root, scene, raycaster) {
107868
+ const result = [];
107869
+ let attached = false;
107870
+ for (let parent = root; parent; parent = parent.parent) {
107871
+ if (!parent.visible) return result;
107872
+ if (parent === scene) attached = true;
107873
+ }
107874
+ if (!attached) return result;
107875
+ root.updateWorldMatrix(true, true);
107876
+ root.traverseVisible((object4) => {
107877
+ if (isMesh(object4) && raycaster.layers.test(object4.layers)) result.push(object4);
107878
+ });
107879
+ return result;
107880
+ }
107881
+ function visibleHits(raycaster, meshes) {
107882
+ return raycaster.intersectObjects(meshes, false).filter((hit) => {
107883
+ if (!hit.face) return false;
107884
+ const mesh = hit.object;
107885
+ const material = Array.isArray(mesh.material) ? mesh.material[hit.face.materialIndex] : mesh.material;
107886
+ return material?.visible;
107887
+ });
107888
+ }
107889
+ function hitNormal(hit) {
107890
+ const mesh = hit.object;
107891
+ const matrix = mesh.matrixWorld.clone();
107892
+ if (isInstancedMesh(mesh) && hit.instanceId !== void 0) {
107893
+ const instance = new Matrix4();
107894
+ mesh.getMatrixAt(hit.instanceId, instance);
107895
+ matrix.multiply(instance);
107896
+ }
107897
+ return hit.face.normal.clone().applyNormalMatrix(new Matrix3().getNormalMatrix(matrix));
107898
+ }
107899
+
107900
+ // src/world/_entities/WorldEntities.ts
107856
107901
  var WorldEntities = class {
107857
107902
  constructor(scene) {
107858
107903
  this.scene = scene;
107859
107904
  this.columns = /* @__PURE__ */ new Map();
107860
107905
  }
107906
+ /** Finds the nearest visible triangle belonging to an entity owned by this world. */
107907
+ raycast(raycaster) {
107908
+ const owners = /* @__PURE__ */ new Map();
107909
+ for (const column of this.columns.values()) {
107910
+ for (const [object4, placement] of column) {
107911
+ for (const mesh of pickableMeshes(object4, this.scene, raycaster)) {
107912
+ owners.set(mesh, { object: object4, ...placement });
107913
+ }
107914
+ }
107915
+ }
107916
+ for (const hit of visibleHits(raycaster, [...owners.keys()])) {
107917
+ const mesh = hit.object;
107918
+ const owner = owners.get(mesh);
107919
+ return {
107920
+ type: owner.type,
107921
+ position: new Vector3(...owner.position),
107922
+ object: owner.object,
107923
+ point: hit.point.clone(),
107924
+ normal: hitNormal(hit),
107925
+ distance: hit.distance
107926
+ };
107927
+ }
107928
+ return void 0;
107929
+ }
107861
107930
  /** Captures column ownership before asynchronous block or asset loading starts. */
107862
107931
  prepare(entities = [], column) {
107863
107932
  const placements = entities.flatMap((entity) => {
@@ -107866,7 +107935,7 @@ gl_FragDepth=readDepth(vUv);
107866
107935
  const position = [...entity.position];
107867
107936
  const key = column?.join(",") ?? `${Math.floor(position[0] / 16)},${Math.floor(position[2] / 16)}`;
107868
107937
  let owner = this.columns.get(key);
107869
- if (!owner) this.columns.set(key, owner = /* @__PURE__ */ new Set());
107938
+ if (!owner) this.columns.set(key, owner = /* @__PURE__ */ new Map());
107870
107939
  return [{ ...resolved, position, column: key, owner }];
107871
107940
  });
107872
107941
  return async () => {
@@ -107892,7 +107961,7 @@ gl_FragDepth=readDepth(vUv);
107892
107961
  object4.rotation.y = placement.yaw;
107893
107962
  await object4.init();
107894
107963
  if (!current()) return;
107895
- placement.owner.add(object4);
107964
+ placement.owner.set(object4, { type: placement.key.toNamespacedString(), position: placement.position });
107896
107965
  this.scene.add(object4);
107897
107966
  } catch (error2) {
107898
107967
  console.warn(`Could not draw saved entity ${placement.key.toNamespacedString()}, skipping it`, error2);
@@ -107907,7 +107976,7 @@ gl_FragDepth=readDepth(vUv);
107907
107976
  const objects = this.columns.get(key);
107908
107977
  this.columns.delete(key);
107909
107978
  if (!objects) return;
107910
- for (const object4 of objects) {
107979
+ for (const object4 of objects.keys()) {
107911
107980
  object4.removeFromScene();
107912
107981
  object4.dispose();
107913
107982
  }
@@ -107978,6 +108047,14 @@ gl_FragDepth=readDepth(vUv);
107978
108047
  raycast(raycaster) {
107979
108048
  return Chunk.raycast(this._chunks.values(), raycaster);
107980
108049
  }
108050
+ /**
108051
+ * Returns the nearest visible mob geometry hit when renderEntities is enabled.
108052
+ * Respects layers and near/far; compare its distance with raycast() to account for blocks.
108053
+ * Texture alpha does not change triangle intersections.
108054
+ */
108055
+ raycastEntities(raycaster) {
108056
+ return this.entities?.raycast(raycaster);
108057
+ }
107981
108058
  /** Whether neighboring opaque cubes shade block-face corners. Defaults to false. */
107982
108059
  get ambientOcclusion() {
107983
108060
  return this._ambientOcclusion;
@@ -108993,7 +109070,6 @@ gl_FragDepth=readDepth(vUv);
108993
109070
  init_FluidQuads();
108994
109071
  init_CubeFace();
108995
109072
  init_InstanceReference();
108996
- init_three();
108997
109073
  var WATER_TINT2 = new Color(4159204).toArray();
108998
109074
  var Chunk = class _Chunk {
108999
109075
  constructor(scene, x4, y5, z4, onBlocksChanged, sectionModels, neighborCell, biomeAt, onBiomesChanged, lightAt, onLightCleared, ambientLight = 0) {
@@ -109026,18 +109102,8 @@ gl_FragDepth=readDepth(vUv);
109026
109102
  const meshes = (root, scene) => {
109027
109103
  const cached2 = roots.get(root);
109028
109104
  if (cached2) return cached2;
109029
- const result = [];
109105
+ const result = pickableMeshes(root, scene, raycaster);
109030
109106
  roots.set(root, result);
109031
- let attached = false;
109032
- for (let parent = root; parent; parent = parent.parent) {
109033
- if (!parent.visible) return result;
109034
- if (parent === scene) attached = true;
109035
- }
109036
- if (!attached) return result;
109037
- root.updateWorldMatrix(true, true);
109038
- root.traverseVisible((object4) => {
109039
- if (isMesh(object4) && raycaster.layers.test(object4.layers)) result.push(object4);
109040
- });
109041
109107
  return result;
109042
109108
  };
109043
109109
  const add = (root, owner, reference) => {
@@ -109068,11 +109134,8 @@ gl_FragDepth=readDepth(vUv);
109068
109134
  }
109069
109135
  }
109070
109136
  }
109071
- for (const hit of raycaster.intersectObjects([...targets.keys()], false)) {
109072
- if (!hit.face) continue;
109137
+ for (const hit of visibleHits(raycaster, [...targets.keys()])) {
109073
109138
  const mesh = hit.object;
109074
- const material = Array.isArray(mesh.material) ? mesh.material[hit.face.materialIndex] : mesh.material;
109075
- if (!material?.visible) continue;
109076
109139
  const entry = targets.get(mesh);
109077
109140
  let owner = entry.owners.get(hit.instanceId) ?? entry.owners.get(void 0);
109078
109141
  if (entry.section) {
@@ -109082,12 +109145,6 @@ gl_FragDepth=readDepth(vUv);
109082
109145
  if (!owner || owner.chunk.hiddenBlocks.has(owner.index)) continue;
109083
109146
  const info = owner.chunk.renderedBlocks.get(owner.index);
109084
109147
  if (!info) continue;
109085
- const matrix = mesh.matrixWorld.clone();
109086
- if (isInstancedMesh(mesh) && hit.instanceId !== void 0) {
109087
- const instance = new Matrix4();
109088
- mesh.getMatrixAt(hit.instanceId, instance);
109089
- matrix.multiply(instance);
109090
- }
109091
109148
  return {
109092
109149
  position: new Vector3(
109093
109150
  owner.chunk.x * 16 + owner.index % 16,
@@ -109096,7 +109153,7 @@ gl_FragDepth=readDepth(vUv);
109096
109153
  ),
109097
109154
  block: info.block,
109098
109155
  point: hit.point.clone(),
109099
- normal: hit.face.normal.clone().applyNormalMatrix(new Matrix3().getNormalMatrix(matrix)),
109156
+ normal: hitNormal(hit),
109100
109157
  distance: hit.distance
109101
109158
  };
109102
109159
  }
@@ -109678,6 +109735,11 @@ gl_FragDepth=readDepth(vUv);
109678
109735
  init_buffer2();
109679
109736
  init_process2();
109680
109737
 
109738
+ // src/world/WorldEntityIntersection.ts
109739
+ init_dirname();
109740
+ init_buffer2();
109741
+ init_process2();
109742
+
109681
109743
  // src/world/WorldStreamer.ts
109682
109744
  init_dirname();
109683
109745
  init_buffer2();