minerender 2.1.0-alpha.62 → 2.1.0-alpha.63
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 +16 -0
- package/dist/browser/index.d.ts +16 -0
- package/dist/browser/index.js +105 -5
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +105 -5
- package/dist/browser/index.mjs.map +1 -1
- package/dist/bundle.js +105 -5
- package/dist/bundle.js.map +1 -1
- package/dist/node/index.d.mts +16 -0
- package/dist/node/index.d.ts +16 -0
- package/dist/node/index.js +105 -5
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +105 -5
- 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);
|
|
@@ -94859,6 +94919,16 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
|
|
|
94859
94919
|
const chunk = Chunk.isAir(value) ? this.getChunkAt(pos) : this.getOrCreateChunkAt(pos);
|
|
94860
94920
|
return chunk?.setBlockInChunkAt(chunk.worldPosToChunkPos(pos), value, pos, onBlocksChanged);
|
|
94861
94921
|
}
|
|
94922
|
+
async setBlockVisibleAt(posOrX, yOrVisible, z4, visible) {
|
|
94923
|
+
if (typeof posOrX === "number") {
|
|
94924
|
+
return this.setBlockVisibleAt(new Vector3(posOrX, yOrVisible, z4), visible);
|
|
94925
|
+
}
|
|
94926
|
+
if (isTripleArray(posOrX)) {
|
|
94927
|
+
return this.setBlockVisibleAt(new Vector3(...posOrX), yOrVisible);
|
|
94928
|
+
}
|
|
94929
|
+
this.validatePosBounds(posOrX);
|
|
94930
|
+
await this.getChunkAt(posOrX)?.setBlockVisibleAt(posOrX, yOrVisible);
|
|
94931
|
+
}
|
|
94862
94932
|
async placeMultiBlock(multiblock, useBatches = true, executor) {
|
|
94863
94933
|
const changes = /* @__PURE__ */ new Map();
|
|
94864
94934
|
try {
|
|
@@ -94974,12 +95044,14 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
|
|
|
94974
95044
|
if (!chunk) continue;
|
|
94975
95045
|
changed.add(chunk);
|
|
94976
95046
|
const block = chunk.getBlockAt(pos);
|
|
94977
|
-
if (!block)
|
|
95047
|
+
if (!block || !chunk.isBlockVisibleAt(pos)) {
|
|
95048
|
+
continue;
|
|
95049
|
+
}
|
|
94978
95050
|
if (block.object?.fluidKind) {
|
|
94979
95051
|
await block.object.updateFluid((x4, y5, z4) => {
|
|
94980
95052
|
const neighbor = pos.clone().add(new Vector3(x4, y5, z4));
|
|
94981
95053
|
const section = this.getChunkAt(neighbor);
|
|
94982
|
-
const object = section?.getBlockAt(neighbor)?.object;
|
|
95054
|
+
const object = section?.isBlockVisibleAt(neighbor) ? section.getBlockAt(neighbor)?.object : void 0;
|
|
94983
95055
|
return {
|
|
94984
95056
|
fluid: object?.fluidKind,
|
|
94985
95057
|
level: object?.fluidLevel,
|
|
@@ -95169,6 +95241,7 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
|
|
|
95169
95241
|
this.data = new ChunkData();
|
|
95170
95242
|
this.renderedBlocks = /* @__PURE__ */ new Map();
|
|
95171
95243
|
this.sectionBlocks = /* @__PURE__ */ new Map();
|
|
95244
|
+
this.hiddenBlocks = /* @__PURE__ */ new Set();
|
|
95172
95245
|
this.meshDirty = false;
|
|
95173
95246
|
this.scene = scene;
|
|
95174
95247
|
this.x = x4;
|
|
@@ -95206,6 +95279,7 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
|
|
|
95206
95279
|
worldPos = this.chunkPosToWorldPos(pos);
|
|
95207
95280
|
}
|
|
95208
95281
|
const index = _Chunk.chunkPosToBlockIndex(pos);
|
|
95282
|
+
this.hiddenBlocks.delete(index);
|
|
95209
95283
|
this.data.set(index, block);
|
|
95210
95284
|
const readBlock = this.data.snapshot(index);
|
|
95211
95285
|
this.renderedBlocks.get(index)?.object?.removeFromScene();
|
|
@@ -95247,9 +95321,31 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
|
|
|
95247
95321
|
await onBlocksChanged?.([worldPos]);
|
|
95248
95322
|
}
|
|
95249
95323
|
}
|
|
95324
|
+
async setBlockVisibleAt(pos, visible) {
|
|
95325
|
+
const index = _Chunk.chunkPosToBlockIndex(this.worldPosToChunkPos(pos));
|
|
95326
|
+
const block = this.renderedBlocks.get(index);
|
|
95327
|
+
if (!block || visible === !this.hiddenBlocks.has(index)) {
|
|
95328
|
+
return;
|
|
95329
|
+
}
|
|
95330
|
+
if (visible) {
|
|
95331
|
+
this.hiddenBlocks.delete(index);
|
|
95332
|
+
} else {
|
|
95333
|
+
this.hiddenBlocks.add(index);
|
|
95334
|
+
}
|
|
95335
|
+
block.object?.setVisible(visible);
|
|
95336
|
+
if (this.sectionBlocks.has(index)) {
|
|
95337
|
+
this.meshDirty = true;
|
|
95338
|
+
}
|
|
95339
|
+
this.scene.dirty = true;
|
|
95340
|
+
await this.onBlocksChanged?.([pos]);
|
|
95341
|
+
}
|
|
95342
|
+
isBlockVisibleAt(pos) {
|
|
95343
|
+
const index = _Chunk.chunkPosToBlockIndex(this.worldPosToChunkPos(pos));
|
|
95344
|
+
return this.renderedBlocks.has(index) && !this.hiddenBlocks.has(index);
|
|
95345
|
+
}
|
|
95250
95346
|
isOccludingAt(pos) {
|
|
95251
95347
|
const index = _Chunk.chunkPosToBlockIndex(this.worldPosToChunkPos(pos));
|
|
95252
|
-
return this.sectionBlocks.has(index) || (this.renderedBlocks.get(index)?.object?.isOccluding ?? false);
|
|
95348
|
+
return !this.hiddenBlocks.has(index) && (this.sectionBlocks.has(index) || (this.renderedBlocks.get(index)?.object?.isOccluding ?? false));
|
|
95253
95349
|
}
|
|
95254
95350
|
async setCullMaskAt(pos, mask) {
|
|
95255
95351
|
const index = _Chunk.chunkPosToBlockIndex(this.worldPosToChunkPos(pos));
|
|
@@ -95265,7 +95361,10 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
|
|
|
95265
95361
|
}
|
|
95266
95362
|
rebuildSectionMesh() {
|
|
95267
95363
|
if (!this.meshDirty) return;
|
|
95268
|
-
const next = this.sectionBlocks.size ? SectionMesh.build(
|
|
95364
|
+
const next = this.sectionBlocks.size ? SectionMesh.build(
|
|
95365
|
+
[...this.sectionBlocks.values()].filter((entry) => !this.hiddenBlocks.has(entry.index)),
|
|
95366
|
+
this.sectionModels.maxAtlasSize
|
|
95367
|
+
) : void 0;
|
|
95269
95368
|
this.sectionMesh?.dispose();
|
|
95270
95369
|
this.sectionMesh = next;
|
|
95271
95370
|
if (next) {
|
|
@@ -95285,6 +95384,7 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
|
|
|
95285
95384
|
this.sectionMesh = void 0;
|
|
95286
95385
|
this.meshDirty = false;
|
|
95287
95386
|
this.renderedBlocks.clear();
|
|
95387
|
+
this.hiddenBlocks.clear();
|
|
95288
95388
|
this.data.clear();
|
|
95289
95389
|
await onBlocksChanged?.(positions);
|
|
95290
95390
|
}
|