minerender 2.1.0-alpha.34 → 2.1.0-alpha.35
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/index.d.mts +5 -8
- package/dist/browser/index.d.ts +5 -8
- package/dist/browser/index.js +22 -54
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +23 -55
- package/dist/browser/index.mjs.map +1 -1
- package/dist/bundle.js +22 -54
- package/dist/bundle.js.map +1 -1
- package/dist/node/index.d.mts +5 -8
- package/dist/node/index.d.ts +5 -8
- package/dist/node/index.js +22 -54
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +23 -55
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/bundle.js
CHANGED
|
@@ -87553,9 +87553,6 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
|
|
|
87553
87553
|
init_process2();
|
|
87554
87554
|
var MineRenderWorld = class {
|
|
87555
87555
|
constructor(scene) {
|
|
87556
|
-
this._size = 4;
|
|
87557
|
-
//TODO: expandable
|
|
87558
|
-
this._blockSize = this._size * 16;
|
|
87559
87556
|
this._chunks = /* @__PURE__ */ new Map();
|
|
87560
87557
|
this.scene = scene;
|
|
87561
87558
|
}
|
|
@@ -87566,12 +87563,8 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
|
|
|
87566
87563
|
if (isTripleArray(posOrX)) {
|
|
87567
87564
|
return this.getBlockAt(new Vector3(posOrX[0], posOrX[1], posOrX[2]));
|
|
87568
87565
|
}
|
|
87569
|
-
const chunk = this.getChunkAt(posOrX);
|
|
87570
|
-
if (typeof chunk === "undefined") {
|
|
87571
|
-
return void 0;
|
|
87572
|
-
}
|
|
87573
87566
|
this.validatePosBounds(posOrX);
|
|
87574
|
-
return
|
|
87567
|
+
return this.getChunkAt(posOrX)?.getBlockAt(posOrX);
|
|
87575
87568
|
}
|
|
87576
87569
|
async setBlockAt(posOrX, yOrBlock, z4, block) {
|
|
87577
87570
|
if (typeof posOrX == "number") {
|
|
@@ -87581,8 +87574,9 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
|
|
|
87581
87574
|
return this.setBlockAt(new Vector3(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
|
|
87582
87575
|
}
|
|
87583
87576
|
this.validatePosBounds(posOrX);
|
|
87584
|
-
const
|
|
87585
|
-
|
|
87577
|
+
const value = yOrBlock;
|
|
87578
|
+
const chunk = Chunk.isAir(value) ? this.getChunkAt(posOrX) : this.getOrCreateChunkAt(posOrX);
|
|
87579
|
+
return chunk?.setBlockAt(posOrX, value);
|
|
87586
87580
|
}
|
|
87587
87581
|
async placeMultiBlock(multiblock, useBatches = true, executor = new BatchedExecutor()) {
|
|
87588
87582
|
const keys = new Set(multiblock.blocks.map((block) => AssetKey.parse("blockstates", block.type)));
|
|
@@ -87603,10 +87597,8 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
|
|
|
87603
87597
|
}
|
|
87604
87598
|
}
|
|
87605
87599
|
async clear() {
|
|
87606
|
-
|
|
87607
|
-
|
|
87608
|
-
console.log("dispose chunk", chunk);
|
|
87609
|
-
await chunk?.dispose();
|
|
87600
|
+
for (const chunk of this._chunks.values()) {
|
|
87601
|
+
await chunk.dispose();
|
|
87610
87602
|
}
|
|
87611
87603
|
this._chunks.clear();
|
|
87612
87604
|
}
|
|
@@ -87620,8 +87612,7 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
|
|
|
87620
87612
|
return chunk;
|
|
87621
87613
|
}
|
|
87622
87614
|
getChunkAt(pos) {
|
|
87623
|
-
|
|
87624
|
-
return this._chunks[index];
|
|
87615
|
+
return this._chunks.get(this.worldPosToChunkKey(pos));
|
|
87625
87616
|
}
|
|
87626
87617
|
static worldToScenePosition(pos) {
|
|
87627
87618
|
return new Vector3(
|
|
@@ -87637,12 +87628,6 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
|
|
|
87637
87628
|
pos.z / 16
|
|
87638
87629
|
);
|
|
87639
87630
|
}
|
|
87640
|
-
worldPosToChunkIndex(pos) {
|
|
87641
|
-
const chunkX = Math.floor(pos.x / 16);
|
|
87642
|
-
const chunkY = Math.floor(pos.y / 16);
|
|
87643
|
-
const chunkZ = Math.floor(pos.z / 16);
|
|
87644
|
-
return chunkZ * this._size * this._size + chunkY * this._size + chunkX;
|
|
87645
|
-
}
|
|
87646
87631
|
worldPosToChunkKey(pos) {
|
|
87647
87632
|
const chunkX = Math.floor(pos.x / 16);
|
|
87648
87633
|
const chunkY = Math.floor(pos.y / 16);
|
|
@@ -87650,12 +87635,9 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
|
|
|
87650
87635
|
return `${chunkX}_${chunkY}_${chunkZ}`;
|
|
87651
87636
|
}
|
|
87652
87637
|
validatePosBounds(pos) {
|
|
87653
|
-
if (pos.x
|
|
87654
|
-
|
|
87655
|
-
|
|
87656
|
-
if (pos.x > this._blockSize) throw new Error("x>" + this._blockSize);
|
|
87657
|
-
if (pos.y > this._blockSize) throw new Error("y>" + this._blockSize);
|
|
87658
|
-
if (pos.z > this._blockSize) throw new Error("z>" + this._blockSize);
|
|
87638
|
+
if (![pos.x, pos.y, pos.z].every(Number.isInteger)) {
|
|
87639
|
+
throw new RangeError("Block coordinates must be integers");
|
|
87640
|
+
}
|
|
87659
87641
|
}
|
|
87660
87642
|
};
|
|
87661
87643
|
|
|
@@ -87668,16 +87650,6 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
|
|
|
87668
87650
|
this.x = x4;
|
|
87669
87651
|
this.y = y5;
|
|
87670
87652
|
this.z = z4;
|
|
87671
|
-
let anchor = new Object3D();
|
|
87672
|
-
this._anchor = anchor;
|
|
87673
|
-
scene.add(anchor);
|
|
87674
|
-
anchor.position.set(this.x * 256 + 128 - 8, this.y * 256 + 128 - 8, this.z * 256 + 128 - 8);
|
|
87675
|
-
addBox3WireframeToObject(
|
|
87676
|
-
new Box3(new Vector3(0, 0, 0), new Vector3(256, 256, 256)),
|
|
87677
|
-
anchor,
|
|
87678
|
-
16776960,
|
|
87679
|
-
4
|
|
87680
|
-
);
|
|
87681
87653
|
}
|
|
87682
87654
|
getBlockAt(posOrX, y5, z4) {
|
|
87683
87655
|
if (typeof posOrX == "number") {
|
|
@@ -87703,7 +87675,7 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
|
|
|
87703
87675
|
return this.setBlockInChunkAt(pos, block, worldPos);
|
|
87704
87676
|
}
|
|
87705
87677
|
/**
|
|
87706
|
-
* Set block at
|
|
87678
|
+
* Set a block at integer chunk-local coordinates from 0 to 15.
|
|
87707
87679
|
*/
|
|
87708
87680
|
async setBlockInChunkAt(pos, block, worldPos) {
|
|
87709
87681
|
if (typeof worldPos === "undefined") {
|
|
@@ -87716,15 +87688,13 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
|
|
|
87716
87688
|
current.object.removeFromScene();
|
|
87717
87689
|
delete this._blocks[index];
|
|
87718
87690
|
}
|
|
87719
|
-
if (
|
|
87691
|
+
if (!block || _Chunk.isAir(block)) return void 0;
|
|
87720
87692
|
const blockState = await BlockStates.get(AssetKey.parse("blockstates", block.type));
|
|
87721
87693
|
if (blockState) {
|
|
87722
87694
|
const blockObject = await this.scene.addBlock(blockState, {
|
|
87723
87695
|
mergeMeshes: true,
|
|
87724
87696
|
instanceMeshes: true,
|
|
87725
|
-
wireframe: true,
|
|
87726
87697
|
maxInstanceCount: 2e3
|
|
87727
|
-
//TODO: setting this to high kills FPS; increase on demand somehow?
|
|
87728
87698
|
});
|
|
87729
87699
|
if (block.properties) {
|
|
87730
87700
|
await blockObject.setState(block.properties);
|
|
@@ -87740,23 +87710,21 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
|
|
|
87740
87710
|
return void 0;
|
|
87741
87711
|
}
|
|
87742
87712
|
async clear() {
|
|
87743
|
-
|
|
87744
|
-
|
|
87745
|
-
for (let x4 = 0; x4 < 16; x4++) {
|
|
87746
|
-
for (let z4 = 0; z4 < 16; z4++) {
|
|
87747
|
-
for (let y5 = 0; y5 < 16; y5++) {
|
|
87748
|
-
promises.push(this.setBlockInChunkAt(pos.set(x4, y5, z4), void 0));
|
|
87749
|
-
}
|
|
87750
|
-
}
|
|
87751
|
-
}
|
|
87752
|
-
return Promise.all(promises).then((ignored) => {
|
|
87753
|
-
});
|
|
87713
|
+
this._blocks.forEach((block) => block.object.removeFromScene());
|
|
87714
|
+
this._blocks.length = 0;
|
|
87754
87715
|
}
|
|
87755
87716
|
async dispose() {
|
|
87756
87717
|
await this.clear();
|
|
87757
|
-
|
|
87718
|
+
}
|
|
87719
|
+
static isAir(block) {
|
|
87720
|
+
if (typeof block === "undefined" || typeof block.type === "undefined") return true;
|
|
87721
|
+
const key = AssetKey.parse("blockstates", block.type);
|
|
87722
|
+
return key.namespace === "minecraft" && !key.type && ["air", "cave_air", "void_air"].includes(key.path);
|
|
87758
87723
|
}
|
|
87759
87724
|
static chunkPosToBlockIndex(pos) {
|
|
87725
|
+
if ([pos.x, pos.y, pos.z].some((value) => !Number.isInteger(value) || value < 0 || value >= 16)) {
|
|
87726
|
+
throw new RangeError("Block coordinates must be integers from 0 to 15 within a chunk");
|
|
87727
|
+
}
|
|
87760
87728
|
return pos.y * 16 * 16 + pos.z * 16 + pos.x;
|
|
87761
87729
|
}
|
|
87762
87730
|
worldPosToChunkPos(pos) {
|