minerender 2.1.0-alpha.62 → 2.1.0-alpha.64
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 +21 -1
- package/dist/browser/index.d.ts +21 -1
- package/dist/browser/index.js +114 -9
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +114 -9
- package/dist/browser/index.mjs.map +1 -1
- package/dist/bundle.js +114 -9
- package/dist/bundle.js.map +1 -1
- package/dist/node/index.d.mts +21 -1
- package/dist/node/index.d.ts +21 -1
- package/dist/node/index.js +114 -9
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +114 -9
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/bundle.js
CHANGED
|
@@ -79155,6 +79155,9 @@ ${key}` : key;
|
|
|
79155
79155
|
setMatrix(matrix) {
|
|
79156
79156
|
this.activeInstanceable.setMatrixAt(this.index, matrix);
|
|
79157
79157
|
}
|
|
79158
|
+
setVisible(visible) {
|
|
79159
|
+
this.activeInstanceable.setInstanceVisibleAt(this.index, visible);
|
|
79160
|
+
}
|
|
79158
79161
|
setPositionRotationScale(position, rotation, scale) {
|
|
79159
79162
|
this.activeInstanceable.setPositionRotationScaleAt(this.index, position, rotation, scale);
|
|
79160
79163
|
}
|
|
@@ -79212,6 +79215,7 @@ ${key}` : key;
|
|
|
79212
79215
|
this._instanceCounter = 0;
|
|
79213
79216
|
this.instanceReferences = /* @__PURE__ */ new Map();
|
|
79214
79217
|
this.freeInstanceIndices = [];
|
|
79218
|
+
this.hiddenInstanceMatrices = /* @__PURE__ */ new Map();
|
|
79215
79219
|
this.options = (0, import_ts_deepmerge3.default)({}, _SceneObject.DEFAULT_OPTIONS, options ?? {});
|
|
79216
79220
|
console.log("SceneObject options", this.options);
|
|
79217
79221
|
}
|
|
@@ -79406,6 +79410,7 @@ ${key}` : key;
|
|
|
79406
79410
|
removeInstanceAt(index) {
|
|
79407
79411
|
if (!this.instanceReferences.has(index)) return;
|
|
79408
79412
|
const mesh = this.instanceMesh;
|
|
79413
|
+
this.hiddenInstanceMatrices.delete(index);
|
|
79409
79414
|
this.setMatrixAt(index, new Matrix4().makeScale(0, 0, 0));
|
|
79410
79415
|
this.instanceReferences.delete(index);
|
|
79411
79416
|
this.freeInstanceIndices.push(index);
|
|
@@ -79438,18 +79443,46 @@ ${key}` : key;
|
|
|
79438
79443
|
//<editor-fold desc="TRANSFORMATION">
|
|
79439
79444
|
getMatrixAt(index, matrix = new Matrix4()) {
|
|
79440
79445
|
if (!this.instanceReferences.has(index)) throw new MineRenderError("Instance is not active");
|
|
79446
|
+
const hidden = this.hiddenInstanceMatrices.get(index);
|
|
79447
|
+
if (hidden) {
|
|
79448
|
+
return matrix.copy(hidden);
|
|
79449
|
+
}
|
|
79441
79450
|
this.instanceMesh.getMatrixAt(index, matrix);
|
|
79442
79451
|
return matrix;
|
|
79443
79452
|
}
|
|
79444
79453
|
setMatrixAt(index, matrix) {
|
|
79445
79454
|
if (!this.instanceReferences.has(index)) throw new MineRenderError("Instance is not active");
|
|
79446
79455
|
const mesh = this.instanceMesh;
|
|
79447
|
-
|
|
79456
|
+
const hidden = this.hiddenInstanceMatrices.get(index);
|
|
79457
|
+
if (hidden) {
|
|
79458
|
+
hidden.copy(matrix);
|
|
79459
|
+
}
|
|
79460
|
+
mesh.setMatrixAt(index, hidden ? new Matrix4().makeScale(0, 0, 0) : matrix);
|
|
79448
79461
|
mesh.instanceMatrix.needsUpdate = true;
|
|
79449
79462
|
mesh.boundingBox = null;
|
|
79450
79463
|
mesh.boundingSphere = null;
|
|
79451
79464
|
this.notifyDirty();
|
|
79452
79465
|
}
|
|
79466
|
+
setInstanceVisibleAt(index, visible) {
|
|
79467
|
+
if (!this.instanceReferences.has(index)) {
|
|
79468
|
+
throw new MineRenderError("Instance is not active");
|
|
79469
|
+
}
|
|
79470
|
+
const hidden = this.hiddenInstanceMatrices.get(index);
|
|
79471
|
+
if (visible) {
|
|
79472
|
+
if (!hidden) {
|
|
79473
|
+
return;
|
|
79474
|
+
}
|
|
79475
|
+
this.hiddenInstanceMatrices.delete(index);
|
|
79476
|
+
this.setMatrixAt(index, hidden);
|
|
79477
|
+
} else {
|
|
79478
|
+
if (hidden) {
|
|
79479
|
+
return;
|
|
79480
|
+
}
|
|
79481
|
+
const matrix = this.getMatrixAt(index);
|
|
79482
|
+
this.hiddenInstanceMatrices.set(index, matrix);
|
|
79483
|
+
this.setMatrixAt(index, matrix);
|
|
79484
|
+
}
|
|
79485
|
+
}
|
|
79453
79486
|
setPositionRotationScaleAt(index, position, rotation, scale) {
|
|
79454
79487
|
if (!this.isInstanced) throw new MineRenderError("Object is not instanced");
|
|
79455
79488
|
const oldPosition = new Vector3();
|
|
@@ -79589,6 +79622,7 @@ ${key}` : key;
|
|
|
79589
79622
|
if (this._scene) this._scene.stats.instanceCount -= this.instanceReferences.size;
|
|
79590
79623
|
this.instanceReferences.clear();
|
|
79591
79624
|
this.freeInstanceIndices.length = 0;
|
|
79625
|
+
this.hiddenInstanceMatrices.clear();
|
|
79592
79626
|
this._instanceCounter = 0;
|
|
79593
79627
|
this.instanceMesh.count = 0;
|
|
79594
79628
|
this.instanceMesh.dispose();
|
|
@@ -88039,6 +88073,21 @@ property list uchar int vertex_index
|
|
|
88039
88073
|
get blockEntities() {
|
|
88040
88074
|
return this._entities;
|
|
88041
88075
|
}
|
|
88076
|
+
/** Sets visibility for this block's model instances and block entities. */
|
|
88077
|
+
setVisible(visible) {
|
|
88078
|
+
this.visible = visible;
|
|
88079
|
+
for (const model of this._models) {
|
|
88080
|
+
if (isInstanceReference(model)) {
|
|
88081
|
+
model.setVisible(visible);
|
|
88082
|
+
} else {
|
|
88083
|
+
model.visible = visible;
|
|
88084
|
+
}
|
|
88085
|
+
}
|
|
88086
|
+
for (const entity of this._entities) {
|
|
88087
|
+
entity.visible = visible;
|
|
88088
|
+
}
|
|
88089
|
+
this.notifyDirty();
|
|
88090
|
+
}
|
|
88042
88091
|
/**
|
|
88043
88092
|
* Draws the block through the dataset's block-entity index. Returns false, leaving nothing behind,
|
|
88044
88093
|
* when the block is not listed or one of its models cannot be loaded.
|
|
@@ -88072,6 +88121,7 @@ property list uchar int vertex_index
|
|
|
88072
88121
|
BlockEntities.matrix(resolved, this._entityPlacement);
|
|
88073
88122
|
this._entities = created;
|
|
88074
88123
|
this.placeEntities();
|
|
88124
|
+
this.setVisible(this.visible);
|
|
88075
88125
|
return true;
|
|
88076
88126
|
}
|
|
88077
88127
|
placeEntities() {
|
|
@@ -88081,6 +88131,9 @@ property list uchar int vertex_index
|
|
|
88081
88131
|
}
|
|
88082
88132
|
}
|
|
88083
88133
|
get isOccluding() {
|
|
88134
|
+
if (!this.visible) {
|
|
88135
|
+
return false;
|
|
88136
|
+
}
|
|
88084
88137
|
return this._models.some((model) => {
|
|
88085
88138
|
const object = isInstanceReference(model) ? model.instanceable : model;
|
|
88086
88139
|
return object.isOpaqueFullCube && this.getModelCullMask(model, 63) === 63;
|
|
@@ -88136,6 +88189,9 @@ property list uchar int vertex_index
|
|
|
88136
88189
|
this._models = replacements;
|
|
88137
88190
|
this._cullMask = worldMask;
|
|
88138
88191
|
this.removeModels(previous.filter((model) => !replacements.includes(model)));
|
|
88192
|
+
if (!this.visible) {
|
|
88193
|
+
this.setVisible(false);
|
|
88194
|
+
}
|
|
88139
88195
|
this.notifyDirty();
|
|
88140
88196
|
}
|
|
88141
88197
|
get state() {
|
|
@@ -88171,6 +88227,9 @@ property list uchar int vertex_index
|
|
|
88171
88227
|
this._isInstanced || (this._isInstanced = isInstanceReference(replacement));
|
|
88172
88228
|
this._instanceCounter = this._isInstanced ? 1 : 0;
|
|
88173
88229
|
if (previous) this.removeModels([previous]);
|
|
88230
|
+
if (!this.visible) {
|
|
88231
|
+
this.setVisible(false);
|
|
88232
|
+
}
|
|
88174
88233
|
this.notifyDirty();
|
|
88175
88234
|
}
|
|
88176
88235
|
nextInstance() {
|
|
@@ -88199,6 +88258,7 @@ property list uchar int vertex_index
|
|
|
88199
88258
|
this._models.push(await this.createVariant(blockStateVariant));
|
|
88200
88259
|
}
|
|
88201
88260
|
await this.updateFluid(this._fluidSampler);
|
|
88261
|
+
this.setVisible(this.visible);
|
|
88202
88262
|
}
|
|
88203
88263
|
async hasGeometry(variant) {
|
|
88204
88264
|
const modelKey = AssetKey.parse("models", variant.model);
|
|
@@ -90052,7 +90112,11 @@ property list uchar int vertex_index
|
|
|
90052
90112
|
|
|
90053
90113
|
// src/model/multiblock/SchematicParser.ts
|
|
90054
90114
|
var SchematicParser = class {
|
|
90055
|
-
|
|
90115
|
+
/**
|
|
90116
|
+
* Parses a legacy schematic using custom mappings before the bundled defaults.
|
|
90117
|
+
* Keys are `id:metadata`; values are block states such as `minecraft:oak_log[axis=x]`.
|
|
90118
|
+
*/
|
|
90119
|
+
static async parse(nbt, customMappings = {}) {
|
|
90056
90120
|
const tags = nbt.value;
|
|
90057
90121
|
if (tags.Materials?.type !== "string" || tags.Materials.value !== "Alpha") {
|
|
90058
90122
|
throw new MineRenderError("Schematic Materials must be Alpha");
|
|
@@ -90094,15 +90158,16 @@ property list uchar int vertex_index
|
|
|
90094
90158
|
const high = packed >> (index & 1) * 4 & 15;
|
|
90095
90159
|
const id = high << 8 | ids.value[index] & 255;
|
|
90096
90160
|
const metadata = data.value[index] & 255;
|
|
90097
|
-
const
|
|
90161
|
+
const key = `${id}:${metadata}`;
|
|
90162
|
+
const mapped = customMappings[key] ?? mapping[key];
|
|
90098
90163
|
if (!mapped) throw new MineRenderError(`Unsupported legacy block ${id}:${metadata} at schematic index ${index}`);
|
|
90099
90164
|
const [type, state] = mapped.split("[");
|
|
90100
90165
|
if (type === "minecraft:air") continue;
|
|
90101
90166
|
const properties = {};
|
|
90102
90167
|
if (state) {
|
|
90103
90168
|
for (const property of state.slice(0, -1).split(",")) {
|
|
90104
|
-
const [
|
|
90105
|
-
properties[
|
|
90169
|
+
const [key2, value] = property.split("=");
|
|
90170
|
+
properties[key2] = value;
|
|
90106
90171
|
}
|
|
90107
90172
|
}
|
|
90108
90173
|
blocks.push({
|
|
@@ -94859,6 +94924,16 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
|
|
|
94859
94924
|
const chunk = Chunk.isAir(value) ? this.getChunkAt(pos) : this.getOrCreateChunkAt(pos);
|
|
94860
94925
|
return chunk?.setBlockInChunkAt(chunk.worldPosToChunkPos(pos), value, pos, onBlocksChanged);
|
|
94861
94926
|
}
|
|
94927
|
+
async setBlockVisibleAt(posOrX, yOrVisible, z4, visible) {
|
|
94928
|
+
if (typeof posOrX === "number") {
|
|
94929
|
+
return this.setBlockVisibleAt(new Vector3(posOrX, yOrVisible, z4), visible);
|
|
94930
|
+
}
|
|
94931
|
+
if (isTripleArray(posOrX)) {
|
|
94932
|
+
return this.setBlockVisibleAt(new Vector3(...posOrX), yOrVisible);
|
|
94933
|
+
}
|
|
94934
|
+
this.validatePosBounds(posOrX);
|
|
94935
|
+
await this.getChunkAt(posOrX)?.setBlockVisibleAt(posOrX, yOrVisible);
|
|
94936
|
+
}
|
|
94862
94937
|
async placeMultiBlock(multiblock, useBatches = true, executor) {
|
|
94863
94938
|
const changes = /* @__PURE__ */ new Map();
|
|
94864
94939
|
try {
|
|
@@ -94974,12 +95049,14 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
|
|
|
94974
95049
|
if (!chunk) continue;
|
|
94975
95050
|
changed.add(chunk);
|
|
94976
95051
|
const block = chunk.getBlockAt(pos);
|
|
94977
|
-
if (!block)
|
|
95052
|
+
if (!block || !chunk.isBlockVisibleAt(pos)) {
|
|
95053
|
+
continue;
|
|
95054
|
+
}
|
|
94978
95055
|
if (block.object?.fluidKind) {
|
|
94979
95056
|
await block.object.updateFluid((x4, y5, z4) => {
|
|
94980
95057
|
const neighbor = pos.clone().add(new Vector3(x4, y5, z4));
|
|
94981
95058
|
const section = this.getChunkAt(neighbor);
|
|
94982
|
-
const object = section?.getBlockAt(neighbor)?.object;
|
|
95059
|
+
const object = section?.isBlockVisibleAt(neighbor) ? section.getBlockAt(neighbor)?.object : void 0;
|
|
94983
95060
|
return {
|
|
94984
95061
|
fluid: object?.fluidKind,
|
|
94985
95062
|
level: object?.fluidLevel,
|
|
@@ -95169,6 +95246,7 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
|
|
|
95169
95246
|
this.data = new ChunkData();
|
|
95170
95247
|
this.renderedBlocks = /* @__PURE__ */ new Map();
|
|
95171
95248
|
this.sectionBlocks = /* @__PURE__ */ new Map();
|
|
95249
|
+
this.hiddenBlocks = /* @__PURE__ */ new Set();
|
|
95172
95250
|
this.meshDirty = false;
|
|
95173
95251
|
this.scene = scene;
|
|
95174
95252
|
this.x = x4;
|
|
@@ -95206,6 +95284,7 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
|
|
|
95206
95284
|
worldPos = this.chunkPosToWorldPos(pos);
|
|
95207
95285
|
}
|
|
95208
95286
|
const index = _Chunk.chunkPosToBlockIndex(pos);
|
|
95287
|
+
this.hiddenBlocks.delete(index);
|
|
95209
95288
|
this.data.set(index, block);
|
|
95210
95289
|
const readBlock = this.data.snapshot(index);
|
|
95211
95290
|
this.renderedBlocks.get(index)?.object?.removeFromScene();
|
|
@@ -95247,9 +95326,31 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
|
|
|
95247
95326
|
await onBlocksChanged?.([worldPos]);
|
|
95248
95327
|
}
|
|
95249
95328
|
}
|
|
95329
|
+
async setBlockVisibleAt(pos, visible) {
|
|
95330
|
+
const index = _Chunk.chunkPosToBlockIndex(this.worldPosToChunkPos(pos));
|
|
95331
|
+
const block = this.renderedBlocks.get(index);
|
|
95332
|
+
if (!block || visible === !this.hiddenBlocks.has(index)) {
|
|
95333
|
+
return;
|
|
95334
|
+
}
|
|
95335
|
+
if (visible) {
|
|
95336
|
+
this.hiddenBlocks.delete(index);
|
|
95337
|
+
} else {
|
|
95338
|
+
this.hiddenBlocks.add(index);
|
|
95339
|
+
}
|
|
95340
|
+
block.object?.setVisible(visible);
|
|
95341
|
+
if (this.sectionBlocks.has(index)) {
|
|
95342
|
+
this.meshDirty = true;
|
|
95343
|
+
}
|
|
95344
|
+
this.scene.dirty = true;
|
|
95345
|
+
await this.onBlocksChanged?.([pos]);
|
|
95346
|
+
}
|
|
95347
|
+
isBlockVisibleAt(pos) {
|
|
95348
|
+
const index = _Chunk.chunkPosToBlockIndex(this.worldPosToChunkPos(pos));
|
|
95349
|
+
return this.renderedBlocks.has(index) && !this.hiddenBlocks.has(index);
|
|
95350
|
+
}
|
|
95250
95351
|
isOccludingAt(pos) {
|
|
95251
95352
|
const index = _Chunk.chunkPosToBlockIndex(this.worldPosToChunkPos(pos));
|
|
95252
|
-
return this.sectionBlocks.has(index) || (this.renderedBlocks.get(index)?.object?.isOccluding ?? false);
|
|
95353
|
+
return !this.hiddenBlocks.has(index) && (this.sectionBlocks.has(index) || (this.renderedBlocks.get(index)?.object?.isOccluding ?? false));
|
|
95253
95354
|
}
|
|
95254
95355
|
async setCullMaskAt(pos, mask) {
|
|
95255
95356
|
const index = _Chunk.chunkPosToBlockIndex(this.worldPosToChunkPos(pos));
|
|
@@ -95265,7 +95366,10 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
|
|
|
95265
95366
|
}
|
|
95266
95367
|
rebuildSectionMesh() {
|
|
95267
95368
|
if (!this.meshDirty) return;
|
|
95268
|
-
const next = this.sectionBlocks.size ? SectionMesh.build(
|
|
95369
|
+
const next = this.sectionBlocks.size ? SectionMesh.build(
|
|
95370
|
+
[...this.sectionBlocks.values()].filter((entry) => !this.hiddenBlocks.has(entry.index)),
|
|
95371
|
+
this.sectionModels.maxAtlasSize
|
|
95372
|
+
) : void 0;
|
|
95269
95373
|
this.sectionMesh?.dispose();
|
|
95270
95374
|
this.sectionMesh = next;
|
|
95271
95375
|
if (next) {
|
|
@@ -95285,6 +95389,7 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
|
|
|
95285
95389
|
this.sectionMesh = void 0;
|
|
95286
95390
|
this.meshDirty = false;
|
|
95287
95391
|
this.renderedBlocks.clear();
|
|
95392
|
+
this.hiddenBlocks.clear();
|
|
95288
95393
|
this.data.clear();
|
|
95289
95394
|
await onBlocksChanged?.(positions);
|
|
95290
95395
|
}
|