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.js
CHANGED
|
@@ -19679,6 +19679,9 @@ var SectionWorker = class _SectionWorker {
|
|
|
19679
19679
|
};
|
|
19680
19680
|
|
|
19681
19681
|
// src/world/SectionMesh.ts
|
|
19682
|
+
var BLOCK_SIZE = 16;
|
|
19683
|
+
var QUAD_VERTICES = 4;
|
|
19684
|
+
var QUAD_INDICES = 6;
|
|
19682
19685
|
var templateCache = /* @__PURE__ */ new WeakMap();
|
|
19683
19686
|
var WATER_TINT = new import_three46.Color(4159204).toArray();
|
|
19684
19687
|
function toInput(entries, maxAtlasSize, fluids, lighting) {
|
|
@@ -19715,8 +19718,8 @@ function toInput(entries, maxAtlasSize, fluids, lighting) {
|
|
|
19715
19718
|
if (!data) {
|
|
19716
19719
|
const indices = template.geometry.getIndex();
|
|
19717
19720
|
const position = template.geometry.getAttribute("position");
|
|
19718
|
-
const quads = indices.count /
|
|
19719
|
-
if (indices.count %
|
|
19721
|
+
const quads = indices.count / QUAD_INDICES;
|
|
19722
|
+
if (indices.count % QUAD_INDICES !== 0 || position.count !== quads * QUAD_VERTICES) {
|
|
19720
19723
|
throw new RangeError("Section template geometry must hold four vertices and six indices per quad");
|
|
19721
19724
|
}
|
|
19722
19725
|
data = {
|
|
@@ -19726,8 +19729,8 @@ function toInput(entries, maxAtlasSize, fluids, lighting) {
|
|
|
19726
19729
|
uvs: new Float32Array(quads * 8),
|
|
19727
19730
|
uvBounds: new Float32Array(quads * 16),
|
|
19728
19731
|
colors: new Float32Array(quads * 12),
|
|
19729
|
-
shade: new Float32Array(quads *
|
|
19730
|
-
indices: new Uint16Array(quads *
|
|
19732
|
+
shade: new Float32Array(quads * QUAD_VERTICES),
|
|
19733
|
+
indices: new Uint16Array(quads * QUAD_INDICES),
|
|
19731
19734
|
cullFaces: new Uint8Array(template.cullFaces),
|
|
19732
19735
|
biomeTint: template.biomeTint ? new Uint8Array(template.biomeTint) : void 0,
|
|
19733
19736
|
atlas: 0,
|
|
@@ -19739,7 +19742,7 @@ function toInput(entries, maxAtlasSize, fluids, lighting) {
|
|
|
19739
19742
|
const bounds = template.geometry.getAttribute("uvBounds");
|
|
19740
19743
|
const color2 = template.geometry.getAttribute("color");
|
|
19741
19744
|
const shade = template.geometry.getAttribute("shade");
|
|
19742
|
-
for (let vertex = 0; vertex < quads *
|
|
19745
|
+
for (let vertex = 0; vertex < quads * QUAD_VERTICES; vertex++) {
|
|
19743
19746
|
data.positions.set([position.getX(vertex), position.getY(vertex), position.getZ(vertex)], vertex * 3);
|
|
19744
19747
|
data.normals.set([normal.getX(vertex), normal.getY(vertex), normal.getZ(vertex)], vertex * 3);
|
|
19745
19748
|
data.uvs.set([uv.getX(vertex), uv.getY(vertex)], vertex * 2);
|
|
@@ -19752,7 +19755,7 @@ function toInput(entries, maxAtlasSize, fluids, lighting) {
|
|
|
19752
19755
|
data.colors.set([color2?.getX(vertex) ?? 1, color2?.getY(vertex) ?? 1, color2?.getZ(vertex) ?? 1], vertex * 3);
|
|
19753
19756
|
data.shade[vertex] = shade?.getX(vertex) ?? 1;
|
|
19754
19757
|
}
|
|
19755
|
-
for (let i2 = 0; i2 < data.indices.length; i2++) data.indices[i2] = indices.getX(i2) -
|
|
19758
|
+
for (let i2 = 0; i2 < data.indices.length; i2++) data.indices[i2] = indices.getX(i2) - QUAD_VERTICES * Math.floor(i2 / QUAD_INDICES);
|
|
19756
19759
|
templateCache.set(template, data);
|
|
19757
19760
|
}
|
|
19758
19761
|
id = input.templateData.length;
|
|
@@ -19785,6 +19788,54 @@ function toInput(entries, maxAtlasSize, fluids, lighting) {
|
|
|
19785
19788
|
}
|
|
19786
19789
|
return { input, atlases: atlases2 };
|
|
19787
19790
|
}
|
|
19791
|
+
function sortTransparentQuads(mesh) {
|
|
19792
|
+
const index = mesh.geometry.getIndex();
|
|
19793
|
+
if (index.count <= QUAD_INDICES) return;
|
|
19794
|
+
index.setUsage(import_three46.DynamicDrawUsage);
|
|
19795
|
+
const count = index.count / QUAD_INDICES;
|
|
19796
|
+
let source, centers, depths, order;
|
|
19797
|
+
const view = new import_three46.Matrix4(), localCamera = new import_three46.Vector3(), key = new import_three46.Vector3(), previous = new import_three46.Vector3();
|
|
19798
|
+
let previousOrthographic;
|
|
19799
|
+
mesh.onBeforeRender = (_renderer, _scene, camera) => {
|
|
19800
|
+
localCamera.setFromMatrixPosition(camera.matrixWorld).applyMatrix4(view.copy(mesh.matrixWorld).invert());
|
|
19801
|
+
const orthographic = !!camera.isOrthographicCamera;
|
|
19802
|
+
if (orthographic) {
|
|
19803
|
+
view.multiplyMatrices(camera.matrixWorldInverse, mesh.matrixWorld);
|
|
19804
|
+
key.set(view.elements[2], view.elements[6], view.elements[10]);
|
|
19805
|
+
} else {
|
|
19806
|
+
key.copy(localCamera).divideScalar(BLOCK_SIZE).floor();
|
|
19807
|
+
}
|
|
19808
|
+
if (orthographic === previousOrthographic && key.equals(previous)) return;
|
|
19809
|
+
previous.copy(key);
|
|
19810
|
+
previousOrthographic = orthographic;
|
|
19811
|
+
if (!centers) {
|
|
19812
|
+
source = new Uint32Array(index.array);
|
|
19813
|
+
centers = new Float32Array(count * 3);
|
|
19814
|
+
depths = new Float32Array(count);
|
|
19815
|
+
order = Uint32Array.from({ length: count }, (_, quad) => quad);
|
|
19816
|
+
const positions = mesh.geometry.getAttribute("position");
|
|
19817
|
+
for (let quad = 0; quad < count; quad++) {
|
|
19818
|
+
for (let axis = 0; axis < 3; axis++) {
|
|
19819
|
+
let center = 0;
|
|
19820
|
+
for (let corner = 0; corner < QUAD_VERTICES; corner++) center += positions.getComponent(quad * QUAD_VERTICES + corner, axis);
|
|
19821
|
+
centers[quad * 3 + axis] = center / QUAD_VERTICES;
|
|
19822
|
+
}
|
|
19823
|
+
}
|
|
19824
|
+
}
|
|
19825
|
+
for (let quad = 0; quad < count; quad++) {
|
|
19826
|
+
const x = centers[quad * 3], y = centers[quad * 3 + 1], z = centers[quad * 3 + 2];
|
|
19827
|
+
depths[quad] = orthographic ? key.x * x + key.y * y + key.z * z : -((x - localCamera.x) ** 2 + (y - localCamera.y) ** 2 + (z - localCamera.z) ** 2);
|
|
19828
|
+
}
|
|
19829
|
+
order.sort((a, b) => depths[a] - depths[b] || a - b);
|
|
19830
|
+
if (!order.some((quad, offset) => index.array[offset * QUAD_INDICES] !== source[quad * QUAD_INDICES])) return;
|
|
19831
|
+
for (let offset = 0; offset < count; offset++) {
|
|
19832
|
+
for (let indexOffset = 0; indexOffset < QUAD_INDICES; indexOffset++) {
|
|
19833
|
+
index.array[offset * QUAD_INDICES + indexOffset] = source[order[offset] * QUAD_INDICES + indexOffset];
|
|
19834
|
+
}
|
|
19835
|
+
}
|
|
19836
|
+
index.needsUpdate = true;
|
|
19837
|
+
};
|
|
19838
|
+
}
|
|
19788
19839
|
var SectionMesh = class _SectionMesh extends import_three46.Group {
|
|
19789
19840
|
constructor() {
|
|
19790
19841
|
super(...arguments);
|
|
@@ -19794,7 +19845,11 @@ var SectionMesh = class _SectionMesh extends import_three46.Group {
|
|
|
19794
19845
|
/** Returns the owning section cell for a triangle hit on this mesh's merged geometry. */
|
|
19795
19846
|
getBlockIndex(hit) {
|
|
19796
19847
|
if (hit.faceIndex === void 0 || hit.faceIndex === null) return void 0;
|
|
19797
|
-
|
|
19848
|
+
const mesh = hit.object;
|
|
19849
|
+
const owners = this.blockIndices.get(mesh);
|
|
19850
|
+
if (!owners) return void 0;
|
|
19851
|
+
const vertex = mesh.geometry.getIndex().getX(hit.faceIndex * 3);
|
|
19852
|
+
return owners[Math.floor(vertex / QUAD_VERTICES)];
|
|
19798
19853
|
}
|
|
19799
19854
|
/** Builds section-local meshes from visible quads. `maxAtlasSize` limits each atlas dimension in pixels. */
|
|
19800
19855
|
static build(entries, maxAtlasSize = 2048, fluids, lighting) {
|
|
@@ -19830,13 +19885,14 @@ var SectionMesh = class _SectionMesh extends import_three46.Group {
|
|
|
19830
19885
|
const material = Materials.createShadedCanvasMaterial(canvas, transparent, false, true);
|
|
19831
19886
|
material.side = import_three46.FrontSide;
|
|
19832
19887
|
if (page.layer === 2) {
|
|
19888
|
+
material.depthWrite = !material.transparent;
|
|
19833
19889
|
material.side = import_three46.DoubleSide;
|
|
19834
19890
|
material.forceSinglePass = true;
|
|
19835
|
-
material.depthWrite = !material.transparent;
|
|
19836
19891
|
}
|
|
19837
19892
|
material.vertexColors = true;
|
|
19838
19893
|
const texture = material.uniforms?.map?.value ?? material.map;
|
|
19839
19894
|
const mesh = new import_three46.Mesh(geometry, material);
|
|
19895
|
+
if (transparent) sortTransparentQuads(mesh);
|
|
19840
19896
|
section.add(mesh);
|
|
19841
19897
|
section.blockIndices.set(mesh, page.blockIndices);
|
|
19842
19898
|
const unsubscribe = [];
|