minerender 2.1.0-alpha.141 → 2.1.0-alpha.142
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/browser/esm/world/SectionMesh.mjs +65 -9
- package/dist/browser/esm/world/SectionMesh.mjs.map +1 -1
- package/dist/browser/index.js +64 -8
- package/dist/browser/index.js.map +1 -1
- package/dist/bundle.js +66 -9
- package/dist/bundle.js.map +1 -1
- package/dist/node/index.js +64 -8
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +80 -24
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/node/index.mjs
CHANGED
|
@@ -17924,7 +17924,7 @@ var AnvilWorldSource = class {
|
|
|
17924
17924
|
};
|
|
17925
17925
|
|
|
17926
17926
|
// src/world/Chunk.ts
|
|
17927
|
-
import { Color as Color13, Vector3 as
|
|
17927
|
+
import { Color as Color13, Vector3 as Vector321 } from "three";
|
|
17928
17928
|
init_BlockStates();
|
|
17929
17929
|
init_AssetKey();
|
|
17930
17930
|
|
|
@@ -19184,7 +19184,7 @@ init_BlockEntities();
|
|
|
19184
19184
|
// src/world/SectionMesh.ts
|
|
19185
19185
|
init_CanvasCompat();
|
|
19186
19186
|
init_Materials();
|
|
19187
|
-
import { BufferGeometry as BufferGeometry9, Color as Color12, DoubleSide as DoubleSide8, Float32BufferAttribute as Float32BufferAttribute10, FrontSide as FrontSide4, Group as Group3, Mesh as Mesh12, Uint32BufferAttribute } from "three";
|
|
19187
|
+
import { BufferGeometry as BufferGeometry9, Color as Color12, DoubleSide as DoubleSide8, DynamicDrawUsage, Float32BufferAttribute as Float32BufferAttribute10, FrontSide as FrontSide4, Group as Group3, Matrix4 as Matrix413, Mesh as Mesh12, Uint32BufferAttribute, Vector3 as Vector320 } from "three";
|
|
19188
19188
|
|
|
19189
19189
|
// src/world/SectionGeometry.ts
|
|
19190
19190
|
init_FluidQuads();
|
|
@@ -19511,6 +19511,9 @@ var SectionWorker = class _SectionWorker {
|
|
|
19511
19511
|
};
|
|
19512
19512
|
|
|
19513
19513
|
// src/world/SectionMesh.ts
|
|
19514
|
+
var BLOCK_SIZE = 16;
|
|
19515
|
+
var QUAD_VERTICES = 4;
|
|
19516
|
+
var QUAD_INDICES = 6;
|
|
19514
19517
|
var templateCache = /* @__PURE__ */ new WeakMap();
|
|
19515
19518
|
var WATER_TINT = new Color12(4159204).toArray();
|
|
19516
19519
|
function toInput(entries, maxAtlasSize, fluids, lighting) {
|
|
@@ -19547,8 +19550,8 @@ function toInput(entries, maxAtlasSize, fluids, lighting) {
|
|
|
19547
19550
|
if (!data) {
|
|
19548
19551
|
const indices = template.geometry.getIndex();
|
|
19549
19552
|
const position = template.geometry.getAttribute("position");
|
|
19550
|
-
const quads = indices.count /
|
|
19551
|
-
if (indices.count %
|
|
19553
|
+
const quads = indices.count / QUAD_INDICES;
|
|
19554
|
+
if (indices.count % QUAD_INDICES !== 0 || position.count !== quads * QUAD_VERTICES) {
|
|
19552
19555
|
throw new RangeError("Section template geometry must hold four vertices and six indices per quad");
|
|
19553
19556
|
}
|
|
19554
19557
|
data = {
|
|
@@ -19558,8 +19561,8 @@ function toInput(entries, maxAtlasSize, fluids, lighting) {
|
|
|
19558
19561
|
uvs: new Float32Array(quads * 8),
|
|
19559
19562
|
uvBounds: new Float32Array(quads * 16),
|
|
19560
19563
|
colors: new Float32Array(quads * 12),
|
|
19561
|
-
shade: new Float32Array(quads *
|
|
19562
|
-
indices: new Uint16Array(quads *
|
|
19564
|
+
shade: new Float32Array(quads * QUAD_VERTICES),
|
|
19565
|
+
indices: new Uint16Array(quads * QUAD_INDICES),
|
|
19563
19566
|
cullFaces: new Uint8Array(template.cullFaces),
|
|
19564
19567
|
biomeTint: template.biomeTint ? new Uint8Array(template.biomeTint) : void 0,
|
|
19565
19568
|
atlas: 0,
|
|
@@ -19571,7 +19574,7 @@ function toInput(entries, maxAtlasSize, fluids, lighting) {
|
|
|
19571
19574
|
const bounds = template.geometry.getAttribute("uvBounds");
|
|
19572
19575
|
const color2 = template.geometry.getAttribute("color");
|
|
19573
19576
|
const shade = template.geometry.getAttribute("shade");
|
|
19574
|
-
for (let vertex = 0; vertex < quads *
|
|
19577
|
+
for (let vertex = 0; vertex < quads * QUAD_VERTICES; vertex++) {
|
|
19575
19578
|
data.positions.set([position.getX(vertex), position.getY(vertex), position.getZ(vertex)], vertex * 3);
|
|
19576
19579
|
data.normals.set([normal.getX(vertex), normal.getY(vertex), normal.getZ(vertex)], vertex * 3);
|
|
19577
19580
|
data.uvs.set([uv.getX(vertex), uv.getY(vertex)], vertex * 2);
|
|
@@ -19584,7 +19587,7 @@ function toInput(entries, maxAtlasSize, fluids, lighting) {
|
|
|
19584
19587
|
data.colors.set([color2?.getX(vertex) ?? 1, color2?.getY(vertex) ?? 1, color2?.getZ(vertex) ?? 1], vertex * 3);
|
|
19585
19588
|
data.shade[vertex] = shade?.getX(vertex) ?? 1;
|
|
19586
19589
|
}
|
|
19587
|
-
for (let i2 = 0; i2 < data.indices.length; i2++) data.indices[i2] = indices.getX(i2) -
|
|
19590
|
+
for (let i2 = 0; i2 < data.indices.length; i2++) data.indices[i2] = indices.getX(i2) - QUAD_VERTICES * Math.floor(i2 / QUAD_INDICES);
|
|
19588
19591
|
templateCache.set(template, data);
|
|
19589
19592
|
}
|
|
19590
19593
|
id = input.templateData.length;
|
|
@@ -19617,6 +19620,54 @@ function toInput(entries, maxAtlasSize, fluids, lighting) {
|
|
|
19617
19620
|
}
|
|
19618
19621
|
return { input, atlases: atlases2 };
|
|
19619
19622
|
}
|
|
19623
|
+
function sortTransparentQuads(mesh) {
|
|
19624
|
+
const index = mesh.geometry.getIndex();
|
|
19625
|
+
if (index.count <= QUAD_INDICES) return;
|
|
19626
|
+
index.setUsage(DynamicDrawUsage);
|
|
19627
|
+
const count = index.count / QUAD_INDICES;
|
|
19628
|
+
let source, centers, depths, order;
|
|
19629
|
+
const view = new Matrix413(), localCamera = new Vector320(), key = new Vector320(), previous = new Vector320();
|
|
19630
|
+
let previousOrthographic;
|
|
19631
|
+
mesh.onBeforeRender = (_renderer, _scene, camera) => {
|
|
19632
|
+
localCamera.setFromMatrixPosition(camera.matrixWorld).applyMatrix4(view.copy(mesh.matrixWorld).invert());
|
|
19633
|
+
const orthographic = !!camera.isOrthographicCamera;
|
|
19634
|
+
if (orthographic) {
|
|
19635
|
+
view.multiplyMatrices(camera.matrixWorldInverse, mesh.matrixWorld);
|
|
19636
|
+
key.set(view.elements[2], view.elements[6], view.elements[10]);
|
|
19637
|
+
} else {
|
|
19638
|
+
key.copy(localCamera).divideScalar(BLOCK_SIZE).floor();
|
|
19639
|
+
}
|
|
19640
|
+
if (orthographic === previousOrthographic && key.equals(previous)) return;
|
|
19641
|
+
previous.copy(key);
|
|
19642
|
+
previousOrthographic = orthographic;
|
|
19643
|
+
if (!centers) {
|
|
19644
|
+
source = new Uint32Array(index.array);
|
|
19645
|
+
centers = new Float32Array(count * 3);
|
|
19646
|
+
depths = new Float32Array(count);
|
|
19647
|
+
order = Uint32Array.from({ length: count }, (_, quad) => quad);
|
|
19648
|
+
const positions = mesh.geometry.getAttribute("position");
|
|
19649
|
+
for (let quad = 0; quad < count; quad++) {
|
|
19650
|
+
for (let axis = 0; axis < 3; axis++) {
|
|
19651
|
+
let center = 0;
|
|
19652
|
+
for (let corner = 0; corner < QUAD_VERTICES; corner++) center += positions.getComponent(quad * QUAD_VERTICES + corner, axis);
|
|
19653
|
+
centers[quad * 3 + axis] = center / QUAD_VERTICES;
|
|
19654
|
+
}
|
|
19655
|
+
}
|
|
19656
|
+
}
|
|
19657
|
+
for (let quad = 0; quad < count; quad++) {
|
|
19658
|
+
const x = centers[quad * 3], y = centers[quad * 3 + 1], z = centers[quad * 3 + 2];
|
|
19659
|
+
depths[quad] = orthographic ? key.x * x + key.y * y + key.z * z : -((x - localCamera.x) ** 2 + (y - localCamera.y) ** 2 + (z - localCamera.z) ** 2);
|
|
19660
|
+
}
|
|
19661
|
+
order.sort((a, b) => depths[a] - depths[b] || a - b);
|
|
19662
|
+
if (!order.some((quad, offset) => index.array[offset * QUAD_INDICES] !== source[quad * QUAD_INDICES])) return;
|
|
19663
|
+
for (let offset = 0; offset < count; offset++) {
|
|
19664
|
+
for (let indexOffset = 0; indexOffset < QUAD_INDICES; indexOffset++) {
|
|
19665
|
+
index.array[offset * QUAD_INDICES + indexOffset] = source[order[offset] * QUAD_INDICES + indexOffset];
|
|
19666
|
+
}
|
|
19667
|
+
}
|
|
19668
|
+
index.needsUpdate = true;
|
|
19669
|
+
};
|
|
19670
|
+
}
|
|
19620
19671
|
var SectionMesh = class _SectionMesh extends Group3 {
|
|
19621
19672
|
constructor() {
|
|
19622
19673
|
super(...arguments);
|
|
@@ -19626,7 +19677,11 @@ var SectionMesh = class _SectionMesh extends Group3 {
|
|
|
19626
19677
|
/** Returns the owning section cell for a triangle hit on this mesh's merged geometry. */
|
|
19627
19678
|
getBlockIndex(hit) {
|
|
19628
19679
|
if (hit.faceIndex === void 0 || hit.faceIndex === null) return void 0;
|
|
19629
|
-
|
|
19680
|
+
const mesh = hit.object;
|
|
19681
|
+
const owners = this.blockIndices.get(mesh);
|
|
19682
|
+
if (!owners) return void 0;
|
|
19683
|
+
const vertex = mesh.geometry.getIndex().getX(hit.faceIndex * 3);
|
|
19684
|
+
return owners[Math.floor(vertex / QUAD_VERTICES)];
|
|
19630
19685
|
}
|
|
19631
19686
|
/** Builds section-local meshes from visible quads. `maxAtlasSize` limits each atlas dimension in pixels. */
|
|
19632
19687
|
static build(entries, maxAtlasSize = 2048, fluids, lighting) {
|
|
@@ -19662,13 +19717,14 @@ var SectionMesh = class _SectionMesh extends Group3 {
|
|
|
19662
19717
|
const material = Materials.createShadedCanvasMaterial(canvas, transparent, false, true);
|
|
19663
19718
|
material.side = FrontSide4;
|
|
19664
19719
|
if (page.layer === 2) {
|
|
19720
|
+
material.depthWrite = !material.transparent;
|
|
19665
19721
|
material.side = DoubleSide8;
|
|
19666
19722
|
material.forceSinglePass = true;
|
|
19667
|
-
material.depthWrite = !material.transparent;
|
|
19668
19723
|
}
|
|
19669
19724
|
material.vertexColors = true;
|
|
19670
19725
|
const texture = material.uniforms?.map?.value ?? material.map;
|
|
19671
19726
|
const mesh = new Mesh12(geometry, material);
|
|
19727
|
+
if (transparent) sortTransparentQuads(mesh);
|
|
19672
19728
|
section.add(mesh);
|
|
19673
19729
|
section.blockIndices.set(mesh, page.blockIndices);
|
|
19674
19730
|
const unsubscribe = [];
|
|
@@ -19727,7 +19783,7 @@ var Chunk = class _Chunk {
|
|
|
19727
19783
|
this.sectionBlocks = /* @__PURE__ */ new Map();
|
|
19728
19784
|
this.hiddenBlocks = /* @__PURE__ */ new Set();
|
|
19729
19785
|
this.fluidCells = new Uint8Array(4096);
|
|
19730
|
-
this.blockPosition = new
|
|
19786
|
+
this.blockPosition = new Vector321();
|
|
19731
19787
|
this.meshDirty = false;
|
|
19732
19788
|
this.meshGeneration = 0;
|
|
19733
19789
|
this.blockChanges = /* @__PURE__ */ new Set();
|
|
@@ -19787,7 +19843,7 @@ var Chunk = class _Chunk {
|
|
|
19787
19843
|
const info = owner.chunk.renderedBlocks.get(owner.index);
|
|
19788
19844
|
if (!info) continue;
|
|
19789
19845
|
return {
|
|
19790
|
-
position: new
|
|
19846
|
+
position: new Vector321(
|
|
19791
19847
|
owner.chunk.x * 16 + owner.index % 16,
|
|
19792
19848
|
owner.chunk.y * 16 + Math.floor(owner.index / 256),
|
|
19793
19849
|
owner.chunk.z * 16 + Math.floor(owner.index / 16) % 16
|
|
@@ -19802,18 +19858,18 @@ var Chunk = class _Chunk {
|
|
|
19802
19858
|
}
|
|
19803
19859
|
getBlockAt(posOrX, y, z) {
|
|
19804
19860
|
if (typeof posOrX == "number") {
|
|
19805
|
-
return this.getBlockAt(new
|
|
19861
|
+
return this.getBlockAt(new Vector321(posOrX, y, z));
|
|
19806
19862
|
}
|
|
19807
19863
|
if (isTripleArray(posOrX)) {
|
|
19808
|
-
return this.getBlockAt(new
|
|
19864
|
+
return this.getBlockAt(new Vector321(posOrX[0], posOrX[1], posOrX[2]));
|
|
19809
19865
|
}
|
|
19810
19866
|
const pos = this.blockPosition.set(posOrX.x - this.x * 16, posOrX.y - this.y * 16, posOrX.z - this.z * 16);
|
|
19811
19867
|
const index = _Chunk.chunkPosToBlockIndex(pos);
|
|
19812
19868
|
return this.renderedBlocks.get(index);
|
|
19813
19869
|
}
|
|
19814
19870
|
getBiomeAt(posOrX, y, z) {
|
|
19815
|
-
if (typeof posOrX === "number") return this.getBiomeAt(new
|
|
19816
|
-
if (isTripleArray(posOrX)) return this.getBiomeAt(new
|
|
19871
|
+
if (typeof posOrX === "number") return this.getBiomeAt(new Vector321(posOrX, y, z));
|
|
19872
|
+
if (isTripleArray(posOrX)) return this.getBiomeAt(new Vector321(...posOrX));
|
|
19817
19873
|
const pos = this.worldPosToChunkPos(posOrX);
|
|
19818
19874
|
_Chunk.chunkPosToBlockIndex(pos);
|
|
19819
19875
|
return this.biomeAt ? this.biomeAt(posOrX.x, posOrX.y, posOrX.z) : this.biomes?.[Math.floor(pos.x / 4) + Math.floor(pos.z / 4) * 4 + Math.floor(pos.y / 4) * 16];
|
|
@@ -19891,17 +19947,17 @@ var Chunk = class _Chunk {
|
|
|
19891
19947
|
this.hiddenBlocks.add(index);
|
|
19892
19948
|
this.renderedBlocks.get(index)?.object?.setVisible(false);
|
|
19893
19949
|
}
|
|
19894
|
-
const positions = blocks.map(({ index }) => new
|
|
19950
|
+
const positions = blocks.map(({ index }) => new Vector321(...this.positionAt(index)));
|
|
19895
19951
|
if (this.onBlocksChanged) await this.onBlocksChanged(positions, deferCulling);
|
|
19896
19952
|
else await this.rebuildSectionMesh();
|
|
19897
19953
|
}
|
|
19898
19954
|
}
|
|
19899
19955
|
async setBlockAt(posOrX, yOrBlock, z, block) {
|
|
19900
19956
|
if (typeof posOrX == "number") {
|
|
19901
|
-
return this.setBlockAt(new
|
|
19957
|
+
return this.setBlockAt(new Vector321(posOrX, yOrBlock, z), block);
|
|
19902
19958
|
}
|
|
19903
19959
|
if (isTripleArray(posOrX)) {
|
|
19904
|
-
return this.setBlockAt(new
|
|
19960
|
+
return this.setBlockAt(new Vector321(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
|
|
19905
19961
|
}
|
|
19906
19962
|
const worldPos = posOrX;
|
|
19907
19963
|
const pos = this.worldPosToChunkPos(worldPos);
|
|
@@ -19974,7 +20030,7 @@ var Chunk = class _Chunk {
|
|
|
19974
20030
|
this.fluidCells[index] = 0;
|
|
19975
20031
|
this.renderedBlocks.delete(index);
|
|
19976
20032
|
this.objectBlocks.delete(index);
|
|
19977
|
-
const worldPos = new
|
|
20033
|
+
const worldPos = new Vector321(
|
|
19978
20034
|
this.x * 16 + index % 16,
|
|
19979
20035
|
this.y * 16 + Math.floor(index / 256),
|
|
19980
20036
|
this.z * 16 + Math.floor(index / 16) % 16
|
|
@@ -20112,7 +20168,7 @@ var Chunk = class _Chunk {
|
|
|
20112
20168
|
biome,
|
|
20113
20169
|
biomePosition: this.biomePosition(index, blockState3, this.data.stateAt(this.data.idAt(index)))
|
|
20114
20170
|
});
|
|
20115
|
-
object4.setPosition(new
|
|
20171
|
+
object4.setPosition(new Vector321(
|
|
20116
20172
|
this.x * 256 + index % 16 * 16,
|
|
20117
20173
|
this.y * 256 + Math.floor(index / 256) * 16,
|
|
20118
20174
|
this.z * 256 + Math.floor(index / 16) % 16 * 16
|
|
@@ -20419,7 +20475,7 @@ var Chunk = class _Chunk {
|
|
|
20419
20475
|
async clear(notify = true) {
|
|
20420
20476
|
if (this.blockChanges.size) await Promise.allSettled(this.blockChanges);
|
|
20421
20477
|
const positions = notify && this.onBlocksChanged ? [...this.renderedBlocks.keys()].map((index) => this.chunkPosToWorldPos(
|
|
20422
|
-
new
|
|
20478
|
+
new Vector321(index % 16, Math.floor(index / 256), Math.floor(index / 16) % 16)
|
|
20423
20479
|
)) : [];
|
|
20424
20480
|
for (const info of this.renderedBlocks.values()) info.object?.removeFromScene();
|
|
20425
20481
|
this.sectionBlocks.clear();
|
|
@@ -20455,14 +20511,14 @@ var Chunk = class _Chunk {
|
|
|
20455
20511
|
return pos.y * 16 * 16 + pos.z * 16 + pos.x;
|
|
20456
20512
|
}
|
|
20457
20513
|
worldPosToChunkPos(pos) {
|
|
20458
|
-
return new
|
|
20514
|
+
return new Vector321(
|
|
20459
20515
|
pos.x - this.x * 16,
|
|
20460
20516
|
pos.y - this.y * 16,
|
|
20461
20517
|
pos.z - this.z * 16
|
|
20462
20518
|
);
|
|
20463
20519
|
}
|
|
20464
20520
|
chunkPosToWorldPos(pos) {
|
|
20465
|
-
return new
|
|
20521
|
+
return new Vector321(
|
|
20466
20522
|
this.x * 16 + pos.x,
|
|
20467
20523
|
this.y * 16 + pos.y,
|
|
20468
20524
|
this.z * 16 + pos.z
|