minerender 2.1.0-alpha.32 → 2.1.0-alpha.34

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.
@@ -2922,26 +2922,40 @@ var Entities = class {
2922
2922
  };
2923
2923
  return collect("");
2924
2924
  }
2925
- static async getEntity(modelKey, textureKey, options) {
2925
+ static async getModelFile(modelKey) {
2926
2926
  const path = isAssetKey(modelKey) ? modelKey.getFullPath() : modelKey.path;
2927
2927
  const key = new AssetKey(modelKey.namespace, path, void 0, void 0, "entity-models", ".json");
2928
- const model = await Caching.entityModelCache.get(key.serialize(), () => AssetLoader.get(key, "json" /* JSON */));
2928
+ return Caching.entityModelCache.get(key.serialize(), () => AssetLoader.get(key, "json" /* JSON */));
2929
+ }
2930
+ static async getLayerList(modelKey) {
2931
+ return Object.keys((await this.getModelFile(modelKey))?.layers ?? {});
2932
+ }
2933
+ static async getEntity(modelKey, textureKey, options) {
2934
+ const model = await this.getModelFile(modelKey);
2929
2935
  if (!model) return void 0;
2930
- const layerName = options?.layer ?? "main";
2931
- const layer = model.layers[layerName];
2932
- if (!layer) {
2933
- throw new MineRenderError(`Entity ${model.id} has no layer "${layerName}". Available layers: ${Object.keys(model.layers).join(", ")}`);
2934
- }
2935
- let texture;
2936
- if (textureKey) {
2937
- const path2 = isAssetKey(textureKey) ? textureKey.getFullPath() : textureKey.path;
2938
- texture = isAssetKey(textureKey) && textureKey.assetType === "textures" && path2.startsWith("entity/") ? textureKey : new AssetKey(textureKey.namespace, path2, "textures", "entity", "assets", ".png", isAssetKey(textureKey) ? textureKey.root : void 0);
2939
- } else if (layer.textureLocation !== void 0) {
2940
- texture = AssetKey.parse("textures", layer.textureLocation.replace(/^([^:]+:)?textures\//, "$1"));
2941
- } else {
2942
- texture = await this.resolveTexture(modelKey);
2943
- }
2944
- return { key: textureKey ?? modelKey, texture, layer, id: model.id };
2936
+ const names = [...new Set(options?.layers ?? [options?.layer ?? "main"])];
2937
+ if (names.length === 0) throw new MineRenderError(`Entity ${model.id} requires at least one layer`);
2938
+ const selected = names.map((name) => {
2939
+ const layer = model.layers[name];
2940
+ if (!layer) {
2941
+ throw new MineRenderError(`Entity ${model.id} has no layer "${name}". Available layers: ${Object.keys(model.layers).join(", ")}`);
2942
+ }
2943
+ return { name, layer };
2944
+ });
2945
+ const layers = Object.fromEntries(await Promise.all(selected.map(async ({ name, layer }, index) => {
2946
+ const override = options?.textures?.[name] ?? (index === 0 ? textureKey : void 0);
2947
+ let texture;
2948
+ if (override) {
2949
+ const path = isAssetKey(override) ? override.getFullPath() : override.path;
2950
+ texture = isAssetKey(override) && override.assetType === "textures" && path.startsWith("entity/") ? override : new AssetKey(override.namespace, path, "textures", "entity", "assets", ".png", isAssetKey(override) ? override.root : void 0);
2951
+ } else if (layer.textureLocation !== void 0) {
2952
+ texture = AssetKey.parse("textures", layer.textureLocation.replace(/^([^:]+:)?textures\//, "$1"));
2953
+ } else {
2954
+ texture = await this.resolveTexture(modelKey);
2955
+ }
2956
+ return [name, { key: override ?? modelKey, texture, layer }];
2957
+ })));
2958
+ return { ...layers[names[0]], id: model.id, layers };
2945
2959
  }
2946
2960
  static async resolveTexture(modelKey) {
2947
2961
  const path = isAssetKey(modelKey) ? modelKey.getFullPath() : modelKey.path;
@@ -2987,32 +3001,42 @@ var InstanceReference = class {
2987
3001
  nextInstance() {
2988
3002
  return this.instanceable.nextInstance();
2989
3003
  }
3004
+ get activeInstanceable() {
3005
+ if (!this.instanceable.isInstanceActive(this.index, this)) throw new MineRenderError("Instance has been removed");
3006
+ return this.instanceable;
3007
+ }
3008
+ removeFromScene() {
3009
+ if (this.instanceable.isInstanceActive(this.index, this)) this.instanceable.removeInstanceAt(this.index);
3010
+ }
3011
+ dispose() {
3012
+ this.removeFromScene();
3013
+ }
2990
3014
  getMatrix(matrix) {
2991
- return this.instanceable.getMatrixAt(this.index, matrix);
3015
+ return this.activeInstanceable.getMatrixAt(this.index, matrix);
2992
3016
  }
2993
3017
  setMatrix(matrix) {
2994
- this.instanceable.setMatrixAt(this.index, matrix);
3018
+ this.activeInstanceable.setMatrixAt(this.index, matrix);
2995
3019
  }
2996
3020
  setPositionRotationScale(position, rotation, scale) {
2997
- this.instanceable.setPositionRotationScaleAt(this.index, position, rotation, scale);
3021
+ this.activeInstanceable.setPositionRotationScaleAt(this.index, position, rotation, scale);
2998
3022
  }
2999
3023
  setPosition(position) {
3000
- this.instanceable.setPositionAt(this.index, position);
3024
+ this.activeInstanceable.setPositionAt(this.index, position);
3001
3025
  }
3002
3026
  getPosition() {
3003
- return this.instanceable.getPositionAt(this.index);
3027
+ return this.activeInstanceable.getPositionAt(this.index);
3004
3028
  }
3005
3029
  setRotation(rotation) {
3006
- this.instanceable.setRotationAt(this.index, rotation);
3030
+ this.activeInstanceable.setRotationAt(this.index, rotation);
3007
3031
  }
3008
3032
  getRotation() {
3009
- return this.instanceable.getRotationAt(this.index);
3033
+ return this.activeInstanceable.getRotationAt(this.index);
3010
3034
  }
3011
3035
  setScale(scale) {
3012
- this.instanceable.setScaleAt(this.index, scale);
3036
+ this.activeInstanceable.setScaleAt(this.index, scale);
3013
3037
  }
3014
3038
  getScale() {
3015
- return this.instanceable.getScaleAt(this.index);
3039
+ return this.activeInstanceable.getScaleAt(this.index);
3016
3040
  }
3017
3041
  //TODO: support for custom methods e.g. setting block variants
3018
3042
  };
@@ -3030,6 +3054,8 @@ var SceneObject = class _SceneObject extends import_three10.Object3D {
3030
3054
  this.materialCallbacks = {};
3031
3055
  this._isInstanced = false;
3032
3056
  this._instanceCounter = 0;
3057
+ this.instanceReferences = /* @__PURE__ */ new Map();
3058
+ this.freeInstanceIndices = [];
3033
3059
  this.options = (0, import_ts_deepmerge3.default)({}, _SceneObject.DEFAULT_OPTIONS, options ?? {});
3034
3060
  console.log("SceneObject options", this.options);
3035
3061
  }
@@ -3133,6 +3159,8 @@ var SceneObject = class _SceneObject extends import_three10.Object3D {
3133
3159
  createInstancedMesh(name, geometry, material, count) {
3134
3160
  const mesh = new import_three10.InstancedMesh(geometry, material, count);
3135
3161
  mesh.count = 0;
3162
+ this.instanceMesh = mesh;
3163
+ this._isInstanced = true;
3136
3164
  if (name) {
3137
3165
  mesh.name = `mesh:${name}`;
3138
3166
  }
@@ -3200,40 +3228,70 @@ var SceneObject = class _SceneObject extends import_three10.Object3D {
3200
3228
  return new InstanceReference(this, i);
3201
3229
  }
3202
3230
  nextInstance() {
3203
- if (!this.isInstanced) throw new MineRenderError("Object is not instanced");
3204
- const i = this._instanceCounter++;
3205
- this.setMatrixAt(i, new import_three10.Matrix4());
3206
- const mesh = this.children[0];
3207
- if (mesh && isInstancedMesh(mesh)) {
3208
- mesh.count = Math.min(this._instanceCounter, mesh.instanceMatrix.count);
3209
- }
3210
- console.debug(p6, "nextInstance " + i);
3211
- if (i === this.options.maxInstanceCount) {
3212
- console.warn(p6, "Max instance count reached for " + this);
3213
- }
3214
- if (this.scene) {
3215
- this.scene.stats.instanceCount++;
3231
+ const mesh = this.instanceMesh;
3232
+ if (!mesh) throw new MineRenderError("Object is not instanced");
3233
+ const index = this.freeInstanceIndices.pop() ?? mesh.count;
3234
+ if (index >= mesh.instanceMatrix.count) this.growInstances(index + 1);
3235
+ const reference = this.constructInstanceReference(index);
3236
+ this.instanceReferences.set(index, reference);
3237
+ this._instanceCounter = this.instanceReferences.size;
3238
+ mesh.count = Math.max(mesh.count, index + 1);
3239
+ if (mesh.instanceColor) {
3240
+ mesh.setColorAt(index, new import_three10.Color(16777215));
3241
+ mesh.instanceColor.needsUpdate = true;
3242
+ }
3243
+ if (this._scene) this._scene.stats.instanceCount++;
3244
+ this.setMatrixAt(index, new import_three10.Matrix4());
3245
+ return reference;
3246
+ }
3247
+ isInstanceActive(index, reference) {
3248
+ return this.instanceReferences.get(index) === reference;
3249
+ }
3250
+ removeInstanceAt(index) {
3251
+ if (!this.instanceReferences.has(index)) return;
3252
+ const mesh = this.instanceMesh;
3253
+ this.setMatrixAt(index, new import_three10.Matrix4().makeScale(0, 0, 0));
3254
+ this.instanceReferences.delete(index);
3255
+ this.freeInstanceIndices.push(index);
3256
+ this._instanceCounter = this.instanceReferences.size;
3257
+ while (mesh.count > 0 && !this.instanceReferences.has(mesh.count - 1)) mesh.count--;
3258
+ if (this._scene) this._scene.stats.instanceCount--;
3259
+ }
3260
+ growInstances(required) {
3261
+ const mesh = this.instanceMesh;
3262
+ const capacity = Math.max(required, mesh.instanceMatrix.count * 2);
3263
+ const grow = (attribute, fill) => {
3264
+ const array = new Float32Array(capacity * attribute.itemSize).fill(fill);
3265
+ array.set(attribute.array);
3266
+ return new import_three10.InstancedBufferAttribute(array, attribute.itemSize, attribute.normalized, attribute.meshPerAttribute).setUsage(attribute.usage);
3267
+ };
3268
+ const matrix = grow(mesh.instanceMatrix, 0);
3269
+ const color = mesh.instanceColor ? grow(mesh.instanceColor, 1) : null;
3270
+ mesh.dispose();
3271
+ mesh.instanceMatrix = matrix;
3272
+ mesh.instanceColor = color;
3273
+ }
3274
+ *activeInstanceIndices() {
3275
+ if (this.instanceMesh) {
3276
+ yield* this.instanceReferences.keys();
3277
+ } else {
3278
+ for (let i = 0; i < this.instanceCounter; i++) yield i;
3216
3279
  }
3217
- this.notifyDirty();
3218
- return this.constructInstanceReference(i);
3219
3280
  }
3220
3281
  //</editor-fold>
3221
3282
  //<editor-fold desc="TRANSFORMATION">
3222
3283
  getMatrixAt(index, matrix = new import_three10.Matrix4()) {
3223
- if (!this.isInstanced) throw new MineRenderError("Object is not instanced");
3224
- const child = this.children[0];
3225
- if (child && isInstancedMesh(child)) {
3226
- child.getMatrixAt(index, matrix);
3227
- }
3284
+ if (!this.instanceReferences.has(index)) throw new MineRenderError("Instance is not active");
3285
+ this.instanceMesh.getMatrixAt(index, matrix);
3228
3286
  return matrix;
3229
3287
  }
3230
3288
  setMatrixAt(index, matrix) {
3231
- if (!this.isInstanced) throw new MineRenderError("Object is not instanced");
3232
- const child = this.children[0];
3233
- if (child && isInstancedMesh(child)) {
3234
- child.setMatrixAt(index, matrix);
3235
- child.instanceMatrix.needsUpdate = true;
3236
- }
3289
+ if (!this.instanceReferences.has(index)) throw new MineRenderError("Instance is not active");
3290
+ const mesh = this.instanceMesh;
3291
+ mesh.setMatrixAt(index, matrix);
3292
+ mesh.instanceMatrix.needsUpdate = true;
3293
+ mesh.boundingBox = null;
3294
+ mesh.boundingSphere = null;
3237
3295
  this.notifyDirty();
3238
3296
  }
3239
3297
  setPositionRotationScaleAt(index, position, rotation, scale) {
@@ -3284,7 +3342,7 @@ var SceneObject = class _SceneObject extends import_three10.Object3D {
3284
3342
  }
3285
3343
  setPositionRotationScale(position, rotation, scale) {
3286
3344
  if (this.isInstanced) {
3287
- for (let i = 0; i < this.instanceCounter; i++) {
3345
+ for (const i of this.activeInstanceIndices()) {
3288
3346
  this.setPositionRotationScaleAt(i, position, rotation, scale);
3289
3347
  }
3290
3348
  } else {
@@ -3302,7 +3360,7 @@ var SceneObject = class _SceneObject extends import_three10.Object3D {
3302
3360
  }
3303
3361
  setPosition(position) {
3304
3362
  if (this.isInstanced) {
3305
- for (let i = 0; i < this.instanceCounter; i++) {
3363
+ for (const i of this.activeInstanceIndices()) {
3306
3364
  this.setPositionRotationScaleAt(i, position);
3307
3365
  }
3308
3366
  } else {
@@ -3312,14 +3370,14 @@ var SceneObject = class _SceneObject extends import_three10.Object3D {
3312
3370
  }
3313
3371
  getPosition() {
3314
3372
  if (this.isInstanced) {
3315
- return this.getPositionAt(0);
3373
+ return this.getPositionAt(this.instanceReferences.keys().next().value ?? 0);
3316
3374
  } else {
3317
3375
  return this.position;
3318
3376
  }
3319
3377
  }
3320
3378
  setRotation(rotation) {
3321
3379
  if (this.isInstanced) {
3322
- for (let i = 0; i < this.instanceCounter; i++) {
3380
+ for (const i of this.activeInstanceIndices()) {
3323
3381
  this.setPositionRotationScaleAt(i, void 0, rotation);
3324
3382
  }
3325
3383
  } else {
@@ -3329,14 +3387,14 @@ var SceneObject = class _SceneObject extends import_three10.Object3D {
3329
3387
  }
3330
3388
  getRotation() {
3331
3389
  if (this.isInstanced) {
3332
- return this.getRotationAt(0);
3390
+ return this.getRotationAt(this.instanceReferences.keys().next().value ?? 0);
3333
3391
  } else {
3334
3392
  return this.rotation;
3335
3393
  }
3336
3394
  }
3337
3395
  setScale(scale) {
3338
3396
  if (this.isInstanced) {
3339
- for (let i = 0; i < this.instanceCounter; i++) {
3397
+ for (const i of this.activeInstanceIndices()) {
3340
3398
  this.setPositionRotationScaleAt(i, void 0, void 0, scale);
3341
3399
  }
3342
3400
  } else {
@@ -3346,7 +3404,7 @@ var SceneObject = class _SceneObject extends import_three10.Object3D {
3346
3404
  }
3347
3405
  getScale() {
3348
3406
  if (this.isInstanced) {
3349
- return this.getScaleAt(0);
3407
+ return this.getScaleAt(this.instanceReferences.keys().next().value ?? 0);
3350
3408
  } else {
3351
3409
  return this.scale;
3352
3410
  }
@@ -3370,6 +3428,17 @@ var SceneObject = class _SceneObject extends import_three10.Object3D {
3370
3428
  this.notifyDirty();
3371
3429
  }
3372
3430
  disposeAndRemoveAllChildren() {
3431
+ if (this.instanceMesh) {
3432
+ if (this._scene) this._scene.stats.instanceCount -= this.instanceReferences.size;
3433
+ this.instanceReferences.clear();
3434
+ this.freeInstanceIndices.length = 0;
3435
+ this._instanceCounter = 0;
3436
+ this.instanceMesh.count = 0;
3437
+ this.instanceMesh.dispose();
3438
+ this.instanceMesh.removeFromParent();
3439
+ this.instanceMesh = void 0;
3440
+ this._isInstanced = false;
3441
+ }
3373
3442
  while (this.children.length > 0) {
3374
3443
  let c = this.children[0];
3375
3444
  if (isDisposable(c)) {
@@ -3410,9 +3479,21 @@ var EntityObject = class _EntityObject extends SceneObject {
3410
3479
  dispose() {
3411
3480
  super.dispose();
3412
3481
  }
3413
- get textureKey() {
3414
- if (this.entity.texture) return this.entity.texture;
3415
- const key = this.entity.key;
3482
+ getLayerGroup(name) {
3483
+ return super.getGroupByName(`layer:${name}`);
3484
+ }
3485
+ getGroupByName(name, layerName) {
3486
+ return layerName === void 0 ? super.getGroupByName(name) : this.getLayerGroup(layerName)?.getObjectByName(`group:${name}`);
3487
+ }
3488
+ getMeshByName(name, layerName) {
3489
+ return layerName === void 0 ? super.getMeshByName(name) : this.getLayerGroup(layerName)?.getObjectByName(`mesh:${name}`);
3490
+ }
3491
+ get entityLayers() {
3492
+ return this.entity.layers ?? { main: this.entity };
3493
+ }
3494
+ getTextureKey(layer) {
3495
+ if (layer.texture) return layer.texture;
3496
+ const key = layer.key;
3416
3497
  return new AssetKey(
3417
3498
  key.namespace,
3418
3499
  isAssetKey(key) ? key.getFullPath() : key.path,
@@ -3422,18 +3503,22 @@ var EntityObject = class _EntityObject extends SceneObject {
3422
3503
  ".png"
3423
3504
  );
3424
3505
  }
3425
- async loadTextures() {
3426
- this.imageData = await ModelTextures.get(this.textureKey);
3506
+ async loadTextures(layer = this.entity) {
3507
+ return ModelTextures.get(this.getTextureKey(layer));
3427
3508
  }
3428
3509
  createMeshes(force = false) {
3429
3510
  if (this.meshesCreated && !force) return;
3430
3511
  const modelRoot = new import_three12.Object3D();
3431
3512
  if (this.options.flip) modelRoot.scale.set(-1, -1, 1);
3432
3513
  this.add(modelRoot);
3433
- this.createPart("root", this.entity.layer.root, modelRoot, this.entity.layer.texture, Materials.MISSING_TEXTURE);
3514
+ Object.entries(this.entityLayers).forEach(([name, layer], index) => {
3515
+ const group = this.createGroup(`layer:${name}`);
3516
+ modelRoot.add(group);
3517
+ this.createPart("root", layer.layer.root, group, layer.layer.texture, Materials.MISSING_TEXTURE, index);
3518
+ });
3434
3519
  this.meshesCreated = true;
3435
3520
  }
3436
- createPart(name, part, parent, textureSize, material) {
3521
+ createPart(name, part, parent, textureSize, material, renderOrder) {
3437
3522
  const anchor = this.createGroup(name);
3438
3523
  anchor.position.fromArray(part.pose.offset);
3439
3524
  anchor.rotation.set(...part.pose.rotation, "ZYX");
@@ -3453,30 +3538,31 @@ var EntityObject = class _EntityObject extends SceneObject {
3453
3538
  ).clone();
3454
3539
  geometry.translate(cube.origin[0] + width / 2, cube.origin[1] + height / 2, cube.origin[2] + depth / 2);
3455
3540
  const mesh = this.createMesh(name, geometry, material);
3541
+ mesh.renderOrder = renderOrder;
3456
3542
  anchor.add(mesh);
3457
3543
  if (this.options.wireframe) addWireframeToMesh(geometry, mesh);
3458
3544
  }
3459
3545
  for (const [childName, child] of Object.entries(part.children)) {
3460
- this.createPart(childName, child, anchor, size, material);
3546
+ this.createPart(childName, child, anchor, size, material, renderOrder);
3461
3547
  }
3462
3548
  }
3463
3549
  async applyTextures() {
3464
- const assetKeyStr = this.textureKey.serialize();
3465
- const keyStr = `entity:${assetKeyStr}`;
3466
- let mat = Caching.materialCache.getIfPresent(keyStr);
3467
- if (!mat) {
3468
- const pending = this.loadTextures();
3469
- const cachedAsset = Caching.textureAssetCache.getIfPresent(assetKeyStr);
3470
- await pending;
3471
- if (!this.imageData) return;
3472
- const canvas = this.imageData.data.canvas;
3473
- const createMaterial = () => Materials.createBasicCanvasMaterial(canvas);
3474
- mat = cachedAsset && Caching.textureAssetCache.getIfPresent(assetKeyStr) === cachedAsset ? Caching.materialCache.get(keyStr, createMaterial) : createMaterial();
3475
- this.imageData = void 0;
3476
- }
3477
- this.iterateAllMeshes((mesh) => {
3478
- mesh.material = mat;
3479
- });
3550
+ await Promise.all(Object.entries(this.entityLayers).map(async ([name, layer]) => {
3551
+ const assetKeyStr = this.getTextureKey(layer).serialize();
3552
+ const keyStr = `entity:${assetKeyStr}`;
3553
+ let mat = Caching.materialCache.getIfPresent(keyStr);
3554
+ if (!mat) {
3555
+ const cachedAsset = Caching.textureAssetCache.getIfPresent(assetKeyStr);
3556
+ const imageData = await this.loadTextures(layer);
3557
+ if (!imageData) return;
3558
+ const canvas = imageData.data.canvas;
3559
+ const createMaterial = () => Materials.createBasicCanvasMaterial(canvas);
3560
+ mat = cachedAsset && Caching.textureAssetCache.getIfPresent(assetKeyStr) === cachedAsset ? Caching.materialCache.get(keyStr, createMaterial) : createMaterial();
3561
+ }
3562
+ this.getLayerGroup(name)?.traverse((object) => {
3563
+ if (isMesh(object)) object.material = mat;
3564
+ });
3565
+ }));
3480
3566
  this.notifyDirty();
3481
3567
  }
3482
3568
  };
@@ -3490,16 +3576,16 @@ var GuiObject = class extends SceneObject {
3490
3576
  };
3491
3577
 
3492
3578
  // src/inspector/SceneInspector.ts
3493
- var import_three13 = require("three");
3579
+ var import_three14 = require("three");
3494
3580
  var p7 = prefix("SceneInspector");
3495
3581
  var help = "<span>Ctrl+Click to Select<br/></span><br/>";
3496
3582
  var SceneInspector = class {
3497
3583
  constructor(renderer) {
3498
3584
  this.renderer = renderer;
3499
- this.mouse = new import_three13.Vector2();
3585
+ this.mouse = new import_three14.Vector2();
3500
3586
  this.objectInfoContainer = document.createElement("div");
3501
3587
  this.objectControlsContainer = document.createElement("div");
3502
- this.raycaster = new import_three13.Raycaster();
3588
+ this.raycaster = new import_three14.Raycaster();
3503
3589
  this.init();
3504
3590
  }
3505
3591
  init() {
@@ -4010,10 +4096,10 @@ var BlockTints = class {
4010
4096
  };
4011
4097
 
4012
4098
  // src/model/scene/ModelObject.ts
4013
- var import_three16 = require("three");
4099
+ var import_three17 = require("three");
4014
4100
 
4015
4101
  // src/three/BufferGeometryUtils.js
4016
- var import_three15 = require("three");
4102
+ var import_three16 = require("three");
4017
4103
  function computeTangents(geometry) {
4018
4104
  geometry.computeTangents();
4019
4105
  console.warn("THREE.BufferGeometryUtils: .computeTangents() has been removed. Use BufferGeometry.computeTangents() instead.");
@@ -4025,7 +4111,7 @@ function mergeBufferGeometries(geometries, useGroups = false) {
4025
4111
  const attributes = {};
4026
4112
  const morphAttributes = {};
4027
4113
  const morphTargetsRelative = geometries[0].morphTargetsRelative;
4028
- const mergedGeometry = new import_three15.BufferGeometry();
4114
+ const mergedGeometry = new import_three16.BufferGeometry();
4029
4115
  let offset = 0;
4030
4116
  for (let i = 0; i < geometries.length; ++i) {
4031
4117
  const geometry = geometries[i];
@@ -4149,7 +4235,7 @@ function mergeBufferAttributes(attributes) {
4149
4235
  array.set(attributes[i].array, offset);
4150
4236
  offset += attributes[i].array.length;
4151
4237
  }
4152
- return new import_three15.BufferAttribute(array, itemSize, normalized);
4238
+ return new import_three16.BufferAttribute(array, itemSize, normalized);
4153
4239
  }
4154
4240
  function interleaveAttributes(attributes) {
4155
4241
  let TypedArray;
@@ -4165,7 +4251,7 @@ function interleaveAttributes(attributes) {
4165
4251
  arrayLength += attribute.array.length;
4166
4252
  stride += attribute.itemSize;
4167
4253
  }
4168
- const interleavedBuffer = new import_three15.InterleavedBuffer(new TypedArray(arrayLength), stride);
4254
+ const interleavedBuffer = new import_three16.InterleavedBuffer(new TypedArray(arrayLength), stride);
4169
4255
  let offset = 0;
4170
4256
  const res = [];
4171
4257
  const getters = ["getX", "getY", "getZ", "getW"];
@@ -4174,7 +4260,7 @@ function interleaveAttributes(attributes) {
4174
4260
  const attribute = attributes[j];
4175
4261
  const itemSize = attribute.itemSize;
4176
4262
  const count = attribute.count;
4177
- const iba = new import_three15.InterleavedBufferAttribute(interleavedBuffer, itemSize, offset, attribute.normalized);
4263
+ const iba = new import_three16.InterleavedBufferAttribute(interleavedBuffer, itemSize, offset, attribute.normalized);
4178
4264
  res.push(iba);
4179
4265
  offset += itemSize;
4180
4266
  for (let c = 0; c < count; c++) {
@@ -4258,13 +4344,13 @@ function mergeVertices(geometry, tolerance = 1e-4) {
4258
4344
  const name = attributeNames[i];
4259
4345
  const oldAttribute = geometry.getAttribute(name);
4260
4346
  const buffer = new oldAttribute.array.constructor(attrArrays[name]);
4261
- const attribute = new import_three15.BufferAttribute(buffer, oldAttribute.itemSize, oldAttribute.normalized);
4347
+ const attribute = new import_three16.BufferAttribute(buffer, oldAttribute.itemSize, oldAttribute.normalized);
4262
4348
  result.setAttribute(name, attribute);
4263
4349
  if (name in morphAttrsArrays) {
4264
4350
  for (let j = 0; j < morphAttrsArrays[name].length; j++) {
4265
4351
  const oldMorphAttribute = geometry.morphAttributes[name][j];
4266
4352
  const buffer2 = new oldMorphAttribute.array.constructor(morphAttrsArrays[name][j]);
4267
- const morphAttribute = new import_three15.BufferAttribute(buffer2, oldMorphAttribute.itemSize, oldMorphAttribute.normalized);
4353
+ const morphAttribute = new import_three16.BufferAttribute(buffer2, oldMorphAttribute.itemSize, oldMorphAttribute.normalized);
4268
4354
  result.morphAttributes[name][j] = morphAttribute;
4269
4355
  }
4270
4356
  }
@@ -4273,11 +4359,11 @@ function mergeVertices(geometry, tolerance = 1e-4) {
4273
4359
  return result;
4274
4360
  }
4275
4361
  function toTrianglesDrawMode(geometry, drawMode) {
4276
- if (drawMode === import_three15.TrianglesDrawMode) {
4362
+ if (drawMode === import_three16.TrianglesDrawMode) {
4277
4363
  console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles.");
4278
4364
  return geometry;
4279
4365
  }
4280
- if (drawMode === import_three15.TriangleFanDrawMode || drawMode === import_three15.TriangleStripDrawMode) {
4366
+ if (drawMode === import_three16.TriangleFanDrawMode || drawMode === import_three16.TriangleStripDrawMode) {
4281
4367
  let index = geometry.getIndex();
4282
4368
  if (index === null) {
4283
4369
  const indices = [];
@@ -4295,7 +4381,7 @@ function toTrianglesDrawMode(geometry, drawMode) {
4295
4381
  }
4296
4382
  const numberOfTriangles = index.count - 2;
4297
4383
  const newIndices = [];
4298
- if (drawMode === import_three15.TriangleFanDrawMode) {
4384
+ if (drawMode === import_three16.TriangleFanDrawMode) {
4299
4385
  for (let i = 1; i <= numberOfTriangles; i++) {
4300
4386
  newIndices.push(index.getX(0));
4301
4387
  newIndices.push(index.getX(i));
@@ -4331,15 +4417,15 @@ function computeMorphedAttributes(object) {
4331
4417
  console.error("THREE.BufferGeometryUtils: Geometry is not of type BufferGeometry.");
4332
4418
  return null;
4333
4419
  }
4334
- const _vA = new import_three15.Vector3();
4335
- const _vB = new import_three15.Vector3();
4336
- const _vC = new import_three15.Vector3();
4337
- const _tempA = new import_three15.Vector3();
4338
- const _tempB = new import_three15.Vector3();
4339
- const _tempC = new import_three15.Vector3();
4340
- const _morphA = new import_three15.Vector3();
4341
- const _morphB = new import_three15.Vector3();
4342
- const _morphC = new import_three15.Vector3();
4420
+ const _vA = new import_three16.Vector3();
4421
+ const _vB = new import_three16.Vector3();
4422
+ const _vC = new import_three16.Vector3();
4423
+ const _tempA = new import_three16.Vector3();
4424
+ const _tempB = new import_three16.Vector3();
4425
+ const _tempC = new import_three16.Vector3();
4426
+ const _morphA = new import_three16.Vector3();
4427
+ const _morphB = new import_three16.Vector3();
4428
+ const _morphC = new import_three16.Vector3();
4343
4429
  function _calculateMorphedAttributeData(object2, material2, attribute, morphAttribute, morphTargetsRelative2, a2, b2, c2, modifiedAttributeArray) {
4344
4430
  _vA.fromBufferAttribute(attribute, a2);
4345
4431
  _vB.fromBufferAttribute(attribute, b2);
@@ -4534,8 +4620,8 @@ function computeMorphedAttributes(object) {
4534
4620
  }
4535
4621
  }
4536
4622
  }
4537
- const morphedPositionAttribute = new import_three15.Float32BufferAttribute(modifiedPosition, 3);
4538
- const morphedNormalAttribute = new import_three15.Float32BufferAttribute(modifiedNormal, 3);
4623
+ const morphedPositionAttribute = new import_three16.Float32BufferAttribute(modifiedPosition, 3);
4624
+ const morphedNormalAttribute = new import_three16.Float32BufferAttribute(modifiedNormal, 3);
4539
4625
  return {
4540
4626
  positionAttribute,
4541
4627
  normalAttribute,
@@ -4565,10 +4651,6 @@ var ModelObject = class _ModelObject extends SceneObject {
4565
4651
  this.createMeshes();
4566
4652
  this.applyTextures();
4567
4653
  }
4568
- dispose() {
4569
- super.dispose();
4570
- this.atlas?.dispose();
4571
- }
4572
4654
  get textureAtlas() {
4573
4655
  return this.atlas;
4574
4656
  }
@@ -4586,7 +4668,7 @@ var ModelObject = class _ModelObject extends SceneObject {
4586
4668
  this.atlas.model.elements?.forEach((el) => {
4587
4669
  const elGeo = this._getBoxGeometryFromElement(el).clone();
4588
4670
  if (this.options.uvLockRotation) {
4589
- UVMapper.lockUvs(elGeo, el.faces, this.atlas, new import_three16.Euler(...this.options.uvLockRotation));
4671
+ UVMapper.lockUvs(elGeo, el.faces, this.atlas, new import_three17.Euler(...this.options.uvLockRotation));
4590
4672
  }
4591
4673
  if (this.options.tints) {
4592
4674
  const colors = new Float32Array(elGeo.getAttribute("position").count * 3).fill(1);
@@ -4595,19 +4677,19 @@ var ModelObject = class _ModelObject extends SceneObject {
4595
4677
  if (tintIndex === void 0 || tintIndex < 0) continue;
4596
4678
  const tint = this.options.tints[tintIndex];
4597
4679
  if (tint === void 0) continue;
4598
- const color = new import_three16.Color(tint);
4680
+ const color = new import_three17.Color(tint);
4599
4681
  for (let vertex = 0; vertex < 4; vertex++) {
4600
4682
  color.toArray(colors, (faceIndex * 4 + vertex) * 3);
4601
4683
  }
4602
4684
  }
4603
- elGeo.setAttribute("color", new import_three16.BufferAttribute(colors, 3));
4685
+ elGeo.setAttribute("color", new import_three17.BufferAttribute(colors, 3));
4604
4686
  }
4605
- elGeo.applyMatrix4(new import_three16.Matrix4().makeTranslation((el.to[0] - el.from[0]) / 2, (el.to[1] - el.from[1]) / 2, (el.to[2] - el.from[2]) / 2));
4606
- elGeo.applyMatrix4(new import_three16.Matrix4().makeTranslation(el.from[0], el.from[1], el.from[2]));
4687
+ elGeo.applyMatrix4(new import_three17.Matrix4().makeTranslation((el.to[0] - el.from[0]) / 2, (el.to[1] - el.from[1]) / 2, (el.to[2] - el.from[2]) / 2));
4688
+ elGeo.applyMatrix4(new import_three17.Matrix4().makeTranslation(el.from[0], el.from[1], el.from[2]));
4607
4689
  if (el.rotation) {
4608
4690
  applyElementRotation(el.rotation, elGeo);
4609
4691
  }
4610
- elGeo.applyMatrix4(new import_three16.Matrix4().makeTranslation(-8, -8, -8));
4692
+ elGeo.applyMatrix4(new import_three17.Matrix4().makeTranslation(-8, -8, -8));
4611
4693
  if (displayTransform) DisplayTransforms.apply(elGeo, displayTransform);
4612
4694
  if (this.options.mergeMeshes) {
4613
4695
  allGeos.push(elGeo);
@@ -4629,7 +4711,7 @@ var ModelObject = class _ModelObject extends SceneObject {
4629
4711
  if (allGeos.length > 0) {
4630
4712
  combinedGeo = mergeBufferGeometries(allGeos);
4631
4713
  } else {
4632
- combinedGeo = new import_three16.BoxGeometry(16, 16, 16);
4714
+ combinedGeo = new import_three17.BoxGeometry(16, 16, 16);
4633
4715
  if (displayTransform) DisplayTransforms.apply(combinedGeo, displayTransform);
4634
4716
  }
4635
4717
  combinedGeo.computeBoundingBox();
@@ -4682,7 +4764,7 @@ function isModelObject(obj) {
4682
4764
 
4683
4765
  // src/model/block/scene/BlockObject.ts
4684
4766
  var import_ts_deepmerge6 = __toESM(require_dist());
4685
- var import_three17 = require("three");
4767
+ var import_three18 = require("three");
4686
4768
  var p10 = prefix("BlockObject");
4687
4769
  function matchesCondition(condition, state) {
4688
4770
  return Object.entries(condition).every(([key, value]) => {
@@ -4737,18 +4819,21 @@ var BlockObject = class _BlockObject extends SceneObject {
4737
4819
  }
4738
4820
  }
4739
4821
  dispose() {
4822
+ this.clearModels();
4740
4823
  super.dispose();
4741
4824
  }
4742
4825
  removeFromScene() {
4743
- for (let model of this._models) {
4744
- if (isModelObject(model)) {
4745
- model.removeFromScene();
4746
- } else if (isInstanceReference(model)) {
4747
- model.setScale(new import_three17.Vector3(0, 0, 0));
4748
- }
4749
- }
4826
+ this.clearModels();
4750
4827
  super.removeFromScene();
4751
4828
  }
4829
+ clearModels() {
4830
+ for (const model of this._models.splice(0)) {
4831
+ model.removeFromScene();
4832
+ if (!isInstanceReference(model)) model.dispose();
4833
+ }
4834
+ this._isInstanced = false;
4835
+ this._instanceCounter = 0;
4836
+ }
4752
4837
  get state() {
4753
4838
  return this._state;
4754
4839
  }
@@ -4797,22 +4882,7 @@ var BlockObject = class _BlockObject extends SceneObject {
4797
4882
  return out;
4798
4883
  }
4799
4884
  async recreateModels() {
4800
- const instanceInfo = [];
4801
- if (this.isInstanced) {
4802
- for (let i = 0; i < this.instanceCounter; i++) {
4803
- instanceInfo[i] = this.getMatrixAt(i);
4804
- }
4805
- }
4806
- for (let model of this._models) {
4807
- if (isInstanceReference(model)) {
4808
- model.setScale(new import_three17.Vector3(0, 0, 0));
4809
- } else {
4810
- model.dispose();
4811
- }
4812
- }
4813
- while (this._models.length > 0) {
4814
- this._models.shift();
4815
- }
4885
+ this.clearModels();
4816
4886
  const variantsToCreate = await this.mapStateToVariant(this.state);
4817
4887
  this._variants = variantsToCreate;
4818
4888
  for (let blockStateVariant of variantsToCreate) {
@@ -4842,7 +4912,7 @@ var BlockObject = class _BlockObject extends SceneObject {
4842
4912
  await this.createVariant(variant);
4843
4913
  }
4844
4914
  async createVariant(variant) {
4845
- const rotation = new import_three17.Euler();
4915
+ const rotation = new import_three18.Euler();
4846
4916
  if (typeof variant.x !== "undefined") {
4847
4917
  rotation.x = toRadians(clampRotationDegrees(variant.x));
4848
4918
  }
@@ -4863,6 +4933,7 @@ var BlockObject = class _BlockObject extends SceneObject {
4863
4933
  this._instanceCounter = 1;
4864
4934
  }
4865
4935
  obj.setRotation(rotation);
4936
+ obj.setPosition(this.position);
4866
4937
  return obj;
4867
4938
  }
4868
4939
  async resetState() {
@@ -4931,7 +5002,7 @@ var BlockObject = class _BlockObject extends SceneObject {
4931
5002
  setPositionRotationScaleAt(index, position, rotation, scale) {
4932
5003
  super.setPositionRotationScaleAt(index, position, rotation, scale);
4933
5004
  }
4934
- getMatrixAt(index, matrix = new import_three17.Matrix4()) {
5005
+ getMatrixAt(index, matrix = new import_three18.Matrix4()) {
4935
5006
  if (!this.isInstanced) throw new MineRenderError("Object is not instanced");
4936
5007
  const child = this._models[0];
4937
5008
  if (child && isModelObject(child)) {
@@ -5006,7 +5077,7 @@ var StructureParser = class {
5006
5077
  };
5007
5078
 
5008
5079
  // src/renderer/MineRenderScene.ts
5009
- var import_three19 = require("three");
5080
+ var import_three20 = require("three");
5010
5081
  var import_ts_deepmerge8 = __toESM(require_dist());
5011
5082
 
5012
5083
  // src/skin/SkinPart.ts
@@ -5731,7 +5802,7 @@ var slimSkinGeometries = {
5731
5802
  var import_ts_deepmerge7 = __toESM(require_dist());
5732
5803
 
5733
5804
  // src/skin/SkinTextures.ts
5734
- var import_three18 = require("three");
5805
+ var import_three19 = require("three");
5735
5806
 
5736
5807
  // src/skin/SkinImage.ts
5737
5808
  var SkinImage = class {
@@ -5808,11 +5879,11 @@ var SkinTextures = class {
5808
5879
  });
5809
5880
  }
5810
5881
  static createMaterial(pixels, width, height, transparent = true) {
5811
- const texture = Textures.initTextureProps(new import_three18.DataTexture(pixels, width, height));
5812
- texture.colorSpace = import_three18.SRGBColorSpace;
5882
+ const texture = Textures.initTextureProps(new import_three19.DataTexture(pixels, width, height));
5883
+ texture.colorSpace = import_three19.SRGBColorSpace;
5813
5884
  texture.flipY = true;
5814
5885
  texture.needsUpdate = true;
5815
- return new import_three18.MeshBasicMaterial({ map: texture, transparent, side: transparent ? import_three18.DoubleSide : import_three18.FrontSide, alphaTest: transparent ? 0.1 : 0 });
5886
+ return new import_three19.MeshBasicMaterial({ map: texture, transparent, side: transparent ? import_three19.DoubleSide : import_three19.FrontSide, alphaTest: transparent ? 0.1 : 0 });
5816
5887
  }
5817
5888
  static isSlim(image, scale) {
5818
5889
  for (const [x, y] of [[46, 52], [54, 20]]) {
@@ -6039,7 +6110,7 @@ var SkinObject = class extends SceneObject {
6039
6110
  };
6040
6111
 
6041
6112
  // src/renderer/MineRenderScene.ts
6042
- var MineRenderScene = class _MineRenderScene extends import_three19.Scene {
6113
+ var MineRenderScene = class _MineRenderScene extends import_three20.Scene {
6043
6114
  constructor(options) {
6044
6115
  super();
6045
6116
  this.isMineRenderScene = true;
@@ -6163,17 +6234,17 @@ function isMineRenderScene(obj) {
6163
6234
  }
6164
6235
 
6165
6236
  // src/renderer/Renderer.ts
6166
- var import_three21 = require("three");
6237
+ var import_three22 = require("three");
6167
6238
  var import_ts_deepmerge9 = __toESM(require_dist());
6168
6239
  var import_stats = __toESM(require("stats.js"));
6169
6240
  var import_postprocessing = require("postprocessing");
6170
6241
 
6171
6242
  // src/three/OrbitControls.js
6172
- var import_three20 = require("three");
6243
+ var import_three21 = require("three");
6173
6244
  var _changeEvent = { type: "change" };
6174
6245
  var _startEvent = { type: "start" };
6175
6246
  var _endEvent = { type: "end" };
6176
- var OrbitControls = class extends import_three20.EventDispatcher {
6247
+ var OrbitControls = class extends import_three21.EventDispatcher {
6177
6248
  constructor(object, domElement) {
6178
6249
  super();
6179
6250
  if (domElement === void 0) console.warn('THREE.OrbitControls: The second parameter "domElement" is now mandatory.');
@@ -6182,7 +6253,7 @@ var OrbitControls = class extends import_three20.EventDispatcher {
6182
6253
  this.domElement = domElement;
6183
6254
  this.domElement.style.touchAction = "none";
6184
6255
  this.enabled = true;
6185
- this.target = new import_three20.Vector3();
6256
+ this.target = new import_three21.Vector3();
6186
6257
  this.minDistance = 0;
6187
6258
  this.maxDistance = Infinity;
6188
6259
  this.minZoom = 0;
@@ -6204,8 +6275,8 @@ var OrbitControls = class extends import_three20.EventDispatcher {
6204
6275
  this.autoRotate = false;
6205
6276
  this.autoRotateSpeed = 2;
6206
6277
  this.keys = { LEFT: "ArrowLeft", UP: "ArrowUp", RIGHT: "ArrowRight", BOTTOM: "ArrowDown" };
6207
- this.mouseButtons = { LEFT: import_three20.MOUSE.ROTATE, MIDDLE: import_three20.MOUSE.DOLLY, RIGHT: import_three20.MOUSE.PAN };
6208
- this.touches = { ONE: import_three20.TOUCH.ROTATE, TWO: import_three20.TOUCH.DOLLY_PAN };
6278
+ this.mouseButtons = { LEFT: import_three21.MOUSE.ROTATE, MIDDLE: import_three21.MOUSE.DOLLY, RIGHT: import_three21.MOUSE.PAN };
6279
+ this.touches = { ONE: import_three21.TOUCH.ROTATE, TWO: import_three21.TOUCH.DOLLY_PAN };
6209
6280
  this.target0 = this.target.clone();
6210
6281
  this.position0 = this.object.position.clone();
6211
6282
  this.zoom0 = this.object.zoom;
@@ -6234,11 +6305,11 @@ var OrbitControls = class extends import_three20.EventDispatcher {
6234
6305
  state = STATE.NONE;
6235
6306
  };
6236
6307
  this.update = function() {
6237
- const offset = new import_three20.Vector3();
6238
- const quat = new import_three20.Quaternion().setFromUnitVectors(object.up, new import_three20.Vector3(0, 1, 0));
6308
+ const offset = new import_three21.Vector3();
6309
+ const quat = new import_three21.Quaternion().setFromUnitVectors(object.up, new import_three21.Vector3(0, 1, 0));
6239
6310
  const quatInverse = quat.clone().invert();
6240
- const lastPosition = new import_three20.Vector3();
6241
- const lastQuaternion = new import_three20.Quaternion();
6311
+ const lastPosition = new import_three21.Vector3();
6312
+ const lastQuaternion = new import_three21.Quaternion();
6242
6313
  const twoPI = 2 * Math.PI;
6243
6314
  return function update() {
6244
6315
  const position = scope.object.position;
@@ -6324,20 +6395,20 @@ var OrbitControls = class extends import_three20.EventDispatcher {
6324
6395
  };
6325
6396
  let state = STATE.NONE;
6326
6397
  const EPS = 1e-6;
6327
- const spherical = new import_three20.Spherical();
6328
- const sphericalDelta = new import_three20.Spherical();
6398
+ const spherical = new import_three21.Spherical();
6399
+ const sphericalDelta = new import_three21.Spherical();
6329
6400
  let scale = 1;
6330
- const panOffset = new import_three20.Vector3();
6401
+ const panOffset = new import_three21.Vector3();
6331
6402
  let zoomChanged = false;
6332
- const rotateStart = new import_three20.Vector2();
6333
- const rotateEnd = new import_three20.Vector2();
6334
- const rotateDelta = new import_three20.Vector2();
6335
- const panStart = new import_three20.Vector2();
6336
- const panEnd = new import_three20.Vector2();
6337
- const panDelta = new import_three20.Vector2();
6338
- const dollyStart = new import_three20.Vector2();
6339
- const dollyEnd = new import_three20.Vector2();
6340
- const dollyDelta = new import_three20.Vector2();
6403
+ const rotateStart = new import_three21.Vector2();
6404
+ const rotateEnd = new import_three21.Vector2();
6405
+ const rotateDelta = new import_three21.Vector2();
6406
+ const panStart = new import_three21.Vector2();
6407
+ const panEnd = new import_three21.Vector2();
6408
+ const panDelta = new import_three21.Vector2();
6409
+ const dollyStart = new import_three21.Vector2();
6410
+ const dollyEnd = new import_three21.Vector2();
6411
+ const dollyDelta = new import_three21.Vector2();
6341
6412
  const pointers = [];
6342
6413
  const pointerPositions = {};
6343
6414
  function getAutoRotationAngle() {
@@ -6353,7 +6424,7 @@ var OrbitControls = class extends import_three20.EventDispatcher {
6353
6424
  sphericalDelta.phi -= angle;
6354
6425
  }
6355
6426
  const panLeft = function() {
6356
- const v = new import_three20.Vector3();
6427
+ const v = new import_three21.Vector3();
6357
6428
  return function panLeft2(distance, objectMatrix) {
6358
6429
  v.setFromMatrixColumn(objectMatrix, 0);
6359
6430
  v.multiplyScalar(-distance);
@@ -6361,7 +6432,7 @@ var OrbitControls = class extends import_three20.EventDispatcher {
6361
6432
  };
6362
6433
  }();
6363
6434
  const panUp = function() {
6364
- const v = new import_three20.Vector3();
6435
+ const v = new import_three21.Vector3();
6365
6436
  return function panUp2(distance, objectMatrix) {
6366
6437
  if (scope.screenSpacePanning === true) {
6367
6438
  v.setFromMatrixColumn(objectMatrix, 1);
@@ -6374,7 +6445,7 @@ var OrbitControls = class extends import_three20.EventDispatcher {
6374
6445
  };
6375
6446
  }();
6376
6447
  const pan = function() {
6377
- const offset = new import_three20.Vector3();
6448
+ const offset = new import_three21.Vector3();
6378
6449
  return function pan2(deltaX, deltaY) {
6379
6450
  const element = scope.domElement;
6380
6451
  if (scope.object.isPerspectiveCamera) {
@@ -6623,12 +6694,12 @@ var OrbitControls = class extends import_three20.EventDispatcher {
6623
6694
  mouseAction = -1;
6624
6695
  }
6625
6696
  switch (mouseAction) {
6626
- case import_three20.MOUSE.DOLLY:
6697
+ case import_three21.MOUSE.DOLLY:
6627
6698
  if (scope.enableZoom === false) return;
6628
6699
  handleMouseDownDolly(event);
6629
6700
  state = STATE.DOLLY;
6630
6701
  break;
6631
- case import_three20.MOUSE.ROTATE:
6702
+ case import_three21.MOUSE.ROTATE:
6632
6703
  if (event.ctrlKey || event.metaKey || event.shiftKey) {
6633
6704
  if (scope.enablePan === false) return;
6634
6705
  handleMouseDownPan(event);
@@ -6639,7 +6710,7 @@ var OrbitControls = class extends import_three20.EventDispatcher {
6639
6710
  state = STATE.ROTATE;
6640
6711
  }
6641
6712
  break;
6642
- case import_three20.MOUSE.PAN:
6713
+ case import_three21.MOUSE.PAN:
6643
6714
  if (event.ctrlKey || event.metaKey || event.shiftKey) {
6644
6715
  if (scope.enableRotate === false) return;
6645
6716
  handleMouseDownRotate(event);
@@ -6695,12 +6766,12 @@ var OrbitControls = class extends import_three20.EventDispatcher {
6695
6766
  switch (pointers.length) {
6696
6767
  case 1:
6697
6768
  switch (scope.touches.ONE) {
6698
- case import_three20.TOUCH.ROTATE:
6769
+ case import_three21.TOUCH.ROTATE:
6699
6770
  if (scope.enableRotate === false) return;
6700
6771
  handleTouchStartRotate();
6701
6772
  state = STATE.TOUCH_ROTATE;
6702
6773
  break;
6703
- case import_three20.TOUCH.PAN:
6774
+ case import_three21.TOUCH.PAN:
6704
6775
  if (scope.enablePan === false) return;
6705
6776
  handleTouchStartPan();
6706
6777
  state = STATE.TOUCH_PAN;
@@ -6711,12 +6782,12 @@ var OrbitControls = class extends import_three20.EventDispatcher {
6711
6782
  break;
6712
6783
  case 2:
6713
6784
  switch (scope.touches.TWO) {
6714
- case import_three20.TOUCH.DOLLY_PAN:
6785
+ case import_three21.TOUCH.DOLLY_PAN:
6715
6786
  if (scope.enableZoom === false && scope.enablePan === false) return;
6716
6787
  handleTouchStartDollyPan();
6717
6788
  state = STATE.TOUCH_DOLLY_PAN;
6718
6789
  break;
6719
- case import_three20.TOUCH.DOLLY_ROTATE:
6790
+ case import_three21.TOUCH.DOLLY_ROTATE:
6720
6791
  if (scope.enableZoom === false && scope.enableRotate === false) return;
6721
6792
  handleTouchStartDollyRotate();
6722
6793
  state = STATE.TOUCH_DOLLY_ROTATE;
@@ -6783,7 +6854,7 @@ var OrbitControls = class extends import_three20.EventDispatcher {
6783
6854
  function trackPointer(event) {
6784
6855
  let position = pointerPositions[event.pointerId];
6785
6856
  if (position === void 0) {
6786
- position = new import_three20.Vector2();
6857
+ position = new import_three21.Vector2();
6787
6858
  pointerPositions[event.pointerId] = position;
6788
6859
  }
6789
6860
  position.set(event.pageX, event.pageY);
@@ -6803,10 +6874,10 @@ var MapControls = class extends OrbitControls {
6803
6874
  constructor(object, domElement) {
6804
6875
  super(object, domElement);
6805
6876
  this.screenSpacePanning = false;
6806
- this.mouseButtons.LEFT = import_three20.MOUSE.PAN;
6807
- this.mouseButtons.RIGHT = import_three20.MOUSE.ROTATE;
6808
- this.touches.ONE = import_three20.TOUCH.PAN;
6809
- this.touches.TWO = import_three20.TOUCH.DOLLY_ROTATE;
6877
+ this.mouseButtons.LEFT = import_three21.MOUSE.PAN;
6878
+ this.mouseButtons.RIGHT = import_three21.MOUSE.ROTATE;
6879
+ this.touches.ONE = import_three21.TOUCH.PAN;
6880
+ this.touches.TWO = import_three21.TOUCH.DOLLY_ROTATE;
6810
6881
  }
6811
6882
  };
6812
6883
 
@@ -6851,8 +6922,8 @@ var Renderer = class _Renderer {
6851
6922
  top: void 0,
6852
6923
  bottom: void 0
6853
6924
  },
6854
- position: new import_three21.Vector3(50, 50, 50),
6855
- lookingAt: new import_three21.Vector3(0, 0, 0)
6925
+ position: new import_three22.Vector3(50, 50, 50),
6926
+ lookingAt: new import_three22.Vector3(0, 0, 0)
6856
6927
  },
6857
6928
  render: {
6858
6929
  fpsLimit: 60,
@@ -6882,14 +6953,14 @@ var Renderer = class _Renderer {
6882
6953
  switch (this.options.camera.type) {
6883
6954
  case "perspective":
6884
6955
  default:
6885
- return new import_three21.PerspectiveCamera(
6956
+ return new import_three22.PerspectiveCamera(
6886
6957
  this.options.camera.perspective.fov,
6887
6958
  this.options.camera.perspective.aspect ?? this.viewWidth / this.viewHeight,
6888
6959
  this.options.camera.near,
6889
6960
  this.options.camera.far
6890
6961
  );
6891
6962
  case "orthographic":
6892
- return new import_three21.OrthographicCamera(
6963
+ return new import_three22.OrthographicCamera(
6893
6964
  this.options.camera.orthographic.left ?? this.viewWidth / -2,
6894
6965
  this.options.camera.orthographic.right ?? this.viewWidth / 2,
6895
6966
  this.options.camera.orthographic.top ?? this.viewHeight / 2,
@@ -6900,7 +6971,7 @@ var Renderer = class _Renderer {
6900
6971
  }
6901
6972
  }
6902
6973
  createRenderer() {
6903
- const renderer = new import_three21.WebGLRenderer({
6974
+ const renderer = new import_three22.WebGLRenderer({
6904
6975
  antialias: this.options.render.antialias,
6905
6976
  alpha: true,
6906
6977
  powerPreference: "high-performance",
@@ -6908,8 +6979,8 @@ var Renderer = class _Renderer {
6908
6979
  });
6909
6980
  renderer.setClearColor(0, 0);
6910
6981
  renderer.shadowMap.enabled = true;
6911
- renderer.shadowMap.type = import_three21.PCFSoftShadowMap;
6912
- renderer.outputColorSpace = import_three21.SRGBColorSpace;
6982
+ renderer.shadowMap.type = import_three22.PCFSoftShadowMap;
6983
+ renderer.outputColorSpace = import_three22.SRGBColorSpace;
6913
6984
  renderer.setSize(this.viewWidth, this.viewHeight);
6914
6985
  return renderer;
6915
6986
  }
@@ -6943,20 +7014,20 @@ var Renderer = class _Renderer {
6943
7014
  window["__THREE_DEVTOOLS__"].dispatchEvent(new CustomEvent("observe", { detail: this.scene }));
6944
7015
  }
6945
7016
  if (this.options.debug.grid) {
6946
- const gridHelper = new import_three21.GridHelper(128, 16);
7017
+ const gridHelper = new import_three22.GridHelper(128, 16);
6947
7018
  this._debugHelpers.push(gridHelper);
6948
7019
  this.scene.add(gridHelper);
6949
- const gridHelper2 = new import_three21.GridHelper(128, 16);
7020
+ const gridHelper2 = new import_three22.GridHelper(128, 16);
6950
7021
  this._debugHelpers.push(gridHelper2);
6951
7022
  gridHelper2.rotation.x = 90 * (Math.PI / 180);
6952
7023
  this.scene.add(gridHelper2);
6953
- const gridHelper3 = new import_three21.GridHelper(128, 16);
7024
+ const gridHelper3 = new import_three22.GridHelper(128, 16);
6954
7025
  this._debugHelpers.push(gridHelper3);
6955
7026
  gridHelper3.rotation.z = 90 * (Math.PI / 180);
6956
7027
  this.scene.add(gridHelper3);
6957
7028
  }
6958
7029
  if (this.options.debug.axes) {
6959
- const axesHelper = new import_three21.AxesHelper(64);
7030
+ const axesHelper = new import_three22.AxesHelper(64);
6960
7031
  this._debugHelpers.push(axesHelper);
6961
7032
  this.scene.add(axesHelper);
6962
7033
  }
@@ -7311,10 +7382,10 @@ var Skins = class {
7311
7382
  };
7312
7383
 
7313
7384
  // src/world/Chunk.ts
7314
- var import_three24 = require("three");
7385
+ var import_three25 = require("three");
7315
7386
 
7316
7387
  // src/world/MineRenderWorld.ts
7317
- var import_three23 = require("three");
7388
+ var import_three24 = require("three");
7318
7389
  var MineRenderWorld = class {
7319
7390
  constructor(scene) {
7320
7391
  this._size = 4;
@@ -7325,10 +7396,10 @@ var MineRenderWorld = class {
7325
7396
  }
7326
7397
  getBlockAt(posOrX, y, z) {
7327
7398
  if (typeof posOrX == "number") {
7328
- return this.getBlockAt(new import_three23.Vector3(posOrX, y, z));
7399
+ return this.getBlockAt(new import_three24.Vector3(posOrX, y, z));
7329
7400
  }
7330
7401
  if (isTripleArray(posOrX)) {
7331
- return this.getBlockAt(new import_three23.Vector3(posOrX[0], posOrX[1], posOrX[2]));
7402
+ return this.getBlockAt(new import_three24.Vector3(posOrX[0], posOrX[1], posOrX[2]));
7332
7403
  }
7333
7404
  const chunk = this.getChunkAt(posOrX);
7334
7405
  if (typeof chunk === "undefined") {
@@ -7339,10 +7410,10 @@ var MineRenderWorld = class {
7339
7410
  }
7340
7411
  async setBlockAt(posOrX, yOrBlock, z, block) {
7341
7412
  if (typeof posOrX == "number") {
7342
- return this.setBlockAt(new import_three23.Vector3(posOrX, yOrBlock, z), block);
7413
+ return this.setBlockAt(new import_three24.Vector3(posOrX, yOrBlock, z), block);
7343
7414
  }
7344
7415
  if (isTripleArray(posOrX)) {
7345
- return this.setBlockAt(new import_three23.Vector3(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
7416
+ return this.setBlockAt(new import_three24.Vector3(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
7346
7417
  }
7347
7418
  this.validatePosBounds(posOrX);
7348
7419
  const chunk = this.getOrCreateChunkAt(posOrX);
@@ -7388,14 +7459,14 @@ var MineRenderWorld = class {
7388
7459
  return this._chunks[index];
7389
7460
  }
7390
7461
  static worldToScenePosition(pos) {
7391
- return new import_three23.Vector3(
7462
+ return new import_three24.Vector3(
7392
7463
  pos.x * 16,
7393
7464
  pos.y * 16,
7394
7465
  pos.z * 16
7395
7466
  );
7396
7467
  }
7397
7468
  static sceneToWorldPosition(pos) {
7398
- return new import_three23.Vector3(
7469
+ return new import_three24.Vector3(
7399
7470
  pos.x / 16,
7400
7471
  pos.y / 16,
7401
7472
  pos.z / 16
@@ -7432,12 +7503,12 @@ var Chunk = class _Chunk {
7432
7503
  this.x = x;
7433
7504
  this.y = y;
7434
7505
  this.z = z;
7435
- let anchor = new import_three24.Object3D();
7506
+ let anchor = new import_three25.Object3D();
7436
7507
  this._anchor = anchor;
7437
7508
  scene.add(anchor);
7438
7509
  anchor.position.set(this.x * 256 + 128 - 8, this.y * 256 + 128 - 8, this.z * 256 + 128 - 8);
7439
7510
  addBox3WireframeToObject(
7440
- new import_three24.Box3(new import_three24.Vector3(0, 0, 0), new import_three24.Vector3(256, 256, 256)),
7511
+ new import_three25.Box3(new import_three25.Vector3(0, 0, 0), new import_three25.Vector3(256, 256, 256)),
7441
7512
  anchor,
7442
7513
  16776960,
7443
7514
  4
@@ -7445,10 +7516,10 @@ var Chunk = class _Chunk {
7445
7516
  }
7446
7517
  getBlockAt(posOrX, y, z) {
7447
7518
  if (typeof posOrX == "number") {
7448
- return this.getBlockAt(new import_three24.Vector3(posOrX, y, z));
7519
+ return this.getBlockAt(new import_three25.Vector3(posOrX, y, z));
7449
7520
  }
7450
7521
  if (isTripleArray(posOrX)) {
7451
- return this.getBlockAt(new import_three24.Vector3(posOrX[0], posOrX[1], posOrX[2]));
7522
+ return this.getBlockAt(new import_three25.Vector3(posOrX[0], posOrX[1], posOrX[2]));
7452
7523
  }
7453
7524
  const pos = this.worldPosToChunkPos(posOrX);
7454
7525
  const index = _Chunk.chunkPosToBlockIndex(pos);
@@ -7456,10 +7527,10 @@ var Chunk = class _Chunk {
7456
7527
  }
7457
7528
  async setBlockAt(posOrX, yOrBlock, z, block) {
7458
7529
  if (typeof posOrX == "number") {
7459
- return this.setBlockAt(new import_three24.Vector3(posOrX, yOrBlock, z), block);
7530
+ return this.setBlockAt(new import_three25.Vector3(posOrX, yOrBlock, z), block);
7460
7531
  }
7461
7532
  if (isTripleArray(posOrX)) {
7462
- return this.setBlockAt(new import_three24.Vector3(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
7533
+ return this.setBlockAt(new import_three25.Vector3(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
7463
7534
  }
7464
7535
  const worldPos = posOrX;
7465
7536
  const pos = this.worldPosToChunkPos(worldPos);
@@ -7505,7 +7576,7 @@ var Chunk = class _Chunk {
7505
7576
  }
7506
7577
  async clear() {
7507
7578
  let promises = [];
7508
- let pos = new import_three24.Vector3();
7579
+ let pos = new import_three25.Vector3();
7509
7580
  for (let x = 0; x < 16; x++) {
7510
7581
  for (let z = 0; z < 16; z++) {
7511
7582
  for (let y = 0; y < 16; y++) {
@@ -7524,14 +7595,14 @@ var Chunk = class _Chunk {
7524
7595
  return pos.y * 16 * 16 + pos.z * 16 + pos.x;
7525
7596
  }
7526
7597
  worldPosToChunkPos(pos) {
7527
- return new import_three24.Vector3(
7598
+ return new import_three25.Vector3(
7528
7599
  pos.x - this.x * 16,
7529
7600
  pos.y - this.y * 16,
7530
7601
  pos.z - this.z * 16
7531
7602
  );
7532
7603
  }
7533
7604
  chunkPosToWorldPos(pos) {
7534
- return new import_three24.Vector3(
7605
+ return new import_three25.Vector3(
7535
7606
  this.x * 16 + pos.x,
7536
7607
  this.y * 16 + pos.y,
7537
7608
  this.z * 16 + pos.z