minerender 2.1.0-alpha.114 → 2.1.0-alpha.115

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.
@@ -7549,6 +7549,7 @@ __export(index_browser_exports, {
7549
7549
  EntityObject: () => EntityObject,
7550
7550
  Env: () => Env,
7551
7551
  FluidModelObject: () => FluidModelObject,
7552
+ FlyControls: () => FlyControls,
7552
7553
  Fonts: () => Fonts,
7553
7554
  GUI_CONTAINER_LAYOUTS: () => GUI_CONTAINER_LAYOUTS,
7554
7555
  Geometries: () => Geometries,
@@ -7651,6 +7652,7 @@ __export(index_browser_exports, {
7651
7652
  isDisposable: () => isDisposable,
7652
7653
  isDoubleArray: () => isDoubleArray,
7653
7654
  isEntityObject: () => isEntityObject,
7655
+ isFlyControls: () => isFlyControls,
7654
7656
  isGuiObject: () => isGuiObject,
7655
7657
  isInstanceManager: () => isInstanceManager,
7656
7658
  isInstanceReference: () => isInstanceReference,
@@ -13267,8 +13269,323 @@ init_ModelObject();
13267
13269
  // src/index.ts
13268
13270
  init_nbt();
13269
13271
 
13270
- // src/renderer/MineRenderScene.ts
13272
+ // src/renderer/FlyControls.ts
13271
13273
  var import_three35 = require("three");
13274
+ var VANILLA_FLY_SPEED = 10.89;
13275
+ var PITCH_LIMIT = Math.PI / 2;
13276
+ var MOVE_EPSILON = 1e-6;
13277
+ var _euler = new import_three35.Euler(0, 0, 0, "YXZ");
13278
+ var _forward = new import_three35.Vector3();
13279
+ var _right = new import_three35.Vector3();
13280
+ var _targetVelocity = new import_three35.Vector3();
13281
+ var FlyControls = class extends import_three35.Controls {
13282
+ constructor(camera, domElement) {
13283
+ super(camera, domElement ?? null);
13284
+ this.isFlyControls = true;
13285
+ /** Horizontal and vertical speed in scene units per second; vanilla creative flight by default. */
13286
+ this.movementSpeed = 16 * VANILLA_FLY_SPEED;
13287
+ /** Speed multiplier while the sprint key is held. */
13288
+ this.sprintMultiplier = 2;
13289
+ /** Radians per pixel of pointer movement. */
13290
+ this.lookSpeed = 2e-3;
13291
+ /** Smooth acceleration and deceleration, approximating vanilla flight momentum. */
13292
+ this.enableDamping = true;
13293
+ /** Portion of the remaining velocity change applied per 60 Hz frame (0–1) when damping is enabled. */
13294
+ this.dampingFactor = 0.25;
13295
+ /** Capture the pointer on click so the mouse turns the camera without dragging; dragging works regardless. */
13296
+ this.pointerLock = true;
13297
+ /** Scroll the wheel to change `movementSpeed` within `speedRange`. */
13298
+ this.enableWheelSpeed = true;
13299
+ /** Minimum and maximum `movementSpeed` reachable with the wheel. */
13300
+ this.speedRange = [16, 16 * 500];
13301
+ /** Touch joystick travel in CSS pixels for full speed. */
13302
+ this.joystickRadius = 64;
13303
+ /** Key bindings by `KeyboardEvent.code`. */
13304
+ this.keys = {
13305
+ forward: ["KeyW", "ArrowUp"],
13306
+ back: ["KeyS", "ArrowDown"],
13307
+ left: ["KeyA", "ArrowLeft"],
13308
+ right: ["KeyD", "ArrowRight"],
13309
+ up: ["Space"],
13310
+ down: ["ShiftLeft", "ShiftRight"],
13311
+ sprint: ["ControlLeft", "ControlRight"]
13312
+ };
13313
+ this._pressed = /* @__PURE__ */ new Set();
13314
+ this._velocity = new import_three35.Vector3();
13315
+ this._lastPosition = new import_three35.Vector3();
13316
+ this._lastQuaternion = new import_three35.Quaternion();
13317
+ this._position0 = new import_three35.Vector3();
13318
+ this._quaternion0 = new import_three35.Quaternion();
13319
+ this._dragMoved = false;
13320
+ this._locked = false;
13321
+ this._onKeyDown = (event) => this.handleKey(event, true);
13322
+ this._onKeyUp = (event) => this.handleKey(event, false);
13323
+ this._onPointerDown = (event) => this.handlePointerDown(event);
13324
+ this._onPointerMove = (event) => this.handlePointerMove(event);
13325
+ this._onPointerUp = (event) => this.handlePointerUp(event);
13326
+ this._onPointerLockChange = () => this.handlePointerLockChange();
13327
+ this._onContextMenu = (event) => event.preventDefault();
13328
+ this._onWheel = (event) => this.handleWheel(event);
13329
+ this._onBlur = () => this.releaseKeys();
13330
+ this._lastPosition.copy(camera.position);
13331
+ this._lastQuaternion.copy(camera.quaternion);
13332
+ this.saveState();
13333
+ if (domElement) this.connect(domElement);
13334
+ }
13335
+ connect(element) {
13336
+ super.connect(element);
13337
+ const document2 = element.ownerDocument;
13338
+ document2.addEventListener("keydown", this._onKeyDown);
13339
+ document2.addEventListener("keyup", this._onKeyUp);
13340
+ document2.addEventListener("pointerlockchange", this._onPointerLockChange);
13341
+ document2.defaultView?.addEventListener("blur", this._onBlur);
13342
+ element.addEventListener("pointerdown", this._onPointerDown);
13343
+ element.addEventListener("pointermove", this._onPointerMove);
13344
+ element.addEventListener("pointerup", this._onPointerUp);
13345
+ element.addEventListener("pointercancel", this._onPointerUp);
13346
+ element.addEventListener("contextmenu", this._onContextMenu);
13347
+ element.addEventListener("wheel", this._onWheel, { passive: false });
13348
+ element.addEventListener("blur", this._onBlur);
13349
+ element.style.touchAction = "none";
13350
+ if (element.tabIndex < 0) element.tabIndex = 0;
13351
+ }
13352
+ disconnect() {
13353
+ const element = this.domElement;
13354
+ if (!element) return;
13355
+ const document2 = element.ownerDocument;
13356
+ document2.removeEventListener("keydown", this._onKeyDown);
13357
+ document2.removeEventListener("keyup", this._onKeyUp);
13358
+ document2.removeEventListener("pointerlockchange", this._onPointerLockChange);
13359
+ document2.defaultView?.removeEventListener("blur", this._onBlur);
13360
+ element.removeEventListener("pointerdown", this._onPointerDown);
13361
+ element.removeEventListener("pointermove", this._onPointerMove);
13362
+ element.removeEventListener("pointerup", this._onPointerUp);
13363
+ element.removeEventListener("pointercancel", this._onPointerUp);
13364
+ element.removeEventListener("contextmenu", this._onContextMenu);
13365
+ element.removeEventListener("wheel", this._onWheel);
13366
+ element.removeEventListener("blur", this._onBlur);
13367
+ element.style.touchAction = "auto";
13368
+ this.unlock();
13369
+ this._locked = false;
13370
+ this.releaseKeys();
13371
+ this._dragPointer = void 0;
13372
+ this._joystick = void 0;
13373
+ }
13374
+ dispose() {
13375
+ this.disconnect();
13376
+ }
13377
+ /** Whether mouse look currently owns the pointer. */
13378
+ get locked() {
13379
+ return this._locked;
13380
+ }
13381
+ /** Requests pointer capture; browsers only allow this from a user gesture. */
13382
+ lock() {
13383
+ const element = this.domElement;
13384
+ if (!element || this._locked || typeof element.requestPointerLock !== "function") return;
13385
+ try {
13386
+ const result = element.requestPointerLock();
13387
+ if (result instanceof Promise) result.catch(() => void 0);
13388
+ } catch {
13389
+ }
13390
+ }
13391
+ /** Releases a captured pointer. */
13392
+ unlock() {
13393
+ const document2 = this.domElement?.ownerDocument;
13394
+ if (document2?.pointerLockElement && document2.pointerLockElement === this.domElement) {
13395
+ document2.exitPointerLock();
13396
+ }
13397
+ }
13398
+ /** Stores the camera pose that {@link reset} restores. */
13399
+ saveState() {
13400
+ this._position0.copy(this.object.position);
13401
+ this._quaternion0.copy(this.object.quaternion);
13402
+ }
13403
+ /** Restores the saved camera pose and stops movement. */
13404
+ reset() {
13405
+ this.object.position.copy(this._position0);
13406
+ this.object.quaternion.copy(this._quaternion0);
13407
+ this._velocity.set(0, 0, 0);
13408
+ this.notifyChange();
13409
+ }
13410
+ /** Horizontal yaw in radians, where zero looks toward -Z. */
13411
+ get yaw() {
13412
+ return _euler.setFromQuaternion(this.object.quaternion).y;
13413
+ }
13414
+ /** Vertical pitch in radians, positive looking up. */
13415
+ get pitch() {
13416
+ return _euler.setFromQuaternion(this.object.quaternion).x;
13417
+ }
13418
+ /** Turns the camera; pitch is clamped to straight up and down. */
13419
+ setRotation(yaw, pitch) {
13420
+ _euler.set(import_three35.MathUtils.clamp(pitch, -PITCH_LIMIT, PITCH_LIMIT), yaw, 0);
13421
+ this.object.quaternion.setFromEuler(_euler);
13422
+ this.notifyChange();
13423
+ }
13424
+ /** Points the camera at a position without rolling it. */
13425
+ lookAt(target) {
13426
+ _forward.copy(target).sub(this.object.position);
13427
+ if (_forward.lengthSq() < MOVE_EPSILON) return;
13428
+ _forward.normalize();
13429
+ this.setRotation(Math.atan2(-_forward.x, -_forward.z), Math.asin(import_three35.MathUtils.clamp(_forward.y, -1, 1)));
13430
+ }
13431
+ /** Whether an action's key is held. */
13432
+ isPressed(action) {
13433
+ return this._pressed.has(action);
13434
+ }
13435
+ /**
13436
+ * Advances movement by `delta` seconds (measured since the previous call when omitted)
13437
+ * and dispatches `change` when the camera moved.
13438
+ */
13439
+ update(delta) {
13440
+ if (delta === void 0) {
13441
+ const now = typeof performance !== "undefined" ? performance.now() : Date.now();
13442
+ delta = this._lastTime === void 0 ? 0 : (now - this._lastTime) / 1e3;
13443
+ this._lastTime = now;
13444
+ }
13445
+ if (!this.enabled) {
13446
+ this._velocity.set(0, 0, 0);
13447
+ return;
13448
+ }
13449
+ if (delta > 0) this.move(delta);
13450
+ this.notifyChange();
13451
+ }
13452
+ move(delta) {
13453
+ const camera = this.object;
13454
+ let forward = (this._pressed.has("forward") ? 1 : 0) - (this._pressed.has("back") ? 1 : 0);
13455
+ let strafe = (this._pressed.has("right") ? 1 : 0) - (this._pressed.has("left") ? 1 : 0);
13456
+ const climb = (this._pressed.has("up") ? 1 : 0) - (this._pressed.has("down") ? 1 : 0);
13457
+ const joystick = this._joystick;
13458
+ if (joystick) {
13459
+ const radius = Math.max(this.joystickRadius, 1);
13460
+ forward = import_three35.MathUtils.clamp(forward + (joystick.originY - joystick.y) / radius, -1, 1);
13461
+ strafe = import_three35.MathUtils.clamp(strafe + (joystick.x - joystick.originX) / radius, -1, 1);
13462
+ }
13463
+ _euler.setFromQuaternion(camera.quaternion);
13464
+ const yaw = _euler.y;
13465
+ _forward.set(-Math.sin(yaw), 0, -Math.cos(yaw));
13466
+ _right.set(Math.cos(yaw), 0, -Math.sin(yaw));
13467
+ _targetVelocity.set(0, 0, 0);
13468
+ if (forward || strafe || climb) {
13469
+ _targetVelocity.addScaledVector(_forward, forward).addScaledVector(_right, strafe);
13470
+ if (_targetVelocity.lengthSq() > 1) _targetVelocity.normalize();
13471
+ _targetVelocity.y = climb;
13472
+ const speed = this.movementSpeed * (this._pressed.has("sprint") ? this.sprintMultiplier : 1);
13473
+ _targetVelocity.multiplyScalar(speed);
13474
+ }
13475
+ if (this.enableDamping) {
13476
+ const blend = 1 - Math.pow(1 - import_three35.MathUtils.clamp(this.dampingFactor, 0, 1), delta * 60);
13477
+ this._velocity.lerp(_targetVelocity, blend);
13478
+ if (_targetVelocity.lengthSq() === 0 && this._velocity.lengthSq() < MOVE_EPSILON) this._velocity.set(0, 0, 0);
13479
+ } else {
13480
+ this._velocity.copy(_targetVelocity);
13481
+ }
13482
+ camera.position.addScaledVector(this._velocity, delta);
13483
+ }
13484
+ notifyChange() {
13485
+ const camera = this.object;
13486
+ if (this._lastPosition.distanceToSquared(camera.position) > MOVE_EPSILON || 8 * (1 - this._lastQuaternion.dot(camera.quaternion)) > MOVE_EPSILON) {
13487
+ this._lastPosition.copy(camera.position);
13488
+ this._lastQuaternion.copy(camera.quaternion);
13489
+ this.dispatchEvent({ type: "change" });
13490
+ }
13491
+ }
13492
+ releaseKeys() {
13493
+ this._pressed.clear();
13494
+ }
13495
+ handleKey(event, down) {
13496
+ const action = this.actionFor(event.code);
13497
+ if (!action) return;
13498
+ const ownsInput = this.enabled && (this._locked || event.target === this.domElement);
13499
+ if (down && !ownsInput) return;
13500
+ const pressed = this._pressed.has(action);
13501
+ if (down) this._pressed.add(action);
13502
+ else this._pressed.delete(action);
13503
+ if (ownsInput || this.enabled && pressed) event.preventDefault();
13504
+ }
13505
+ actionFor(code) {
13506
+ for (const action in this.keys) {
13507
+ if (this.keys[action].includes(code)) return action;
13508
+ }
13509
+ return void 0;
13510
+ }
13511
+ handlePointerDown(event) {
13512
+ const element = this.domElement;
13513
+ if (!this.enabled || !element) return;
13514
+ element.focus?.({ preventScroll: true });
13515
+ if (this._locked) return;
13516
+ if (event.pointerType === "touch" && !this._joystick && this.onJoystickSide(event)) {
13517
+ this._joystick = { id: event.pointerId, originX: event.clientX, originY: event.clientY, x: event.clientX, y: event.clientY };
13518
+ element.setPointerCapture?.(event.pointerId);
13519
+ return;
13520
+ }
13521
+ if (this._dragPointer !== void 0) return;
13522
+ if (event.pointerType === "mouse" && event.button !== 0 && event.button !== 2) return;
13523
+ this._dragPointer = event.pointerId;
13524
+ this._dragMoved = false;
13525
+ element.setPointerCapture?.(event.pointerId);
13526
+ }
13527
+ onJoystickSide(event) {
13528
+ const rect = this.domElement?.getBoundingClientRect?.();
13529
+ return !!rect && event.clientX < rect.left + rect.width / 2;
13530
+ }
13531
+ handlePointerMove(event) {
13532
+ if (!this.enabled) return;
13533
+ const joystick = this._joystick;
13534
+ if (joystick && event.pointerId === joystick.id) {
13535
+ joystick.x = event.clientX;
13536
+ joystick.y = event.clientY;
13537
+ return;
13538
+ }
13539
+ if (!this._locked && event.pointerId !== this._dragPointer) return;
13540
+ const dx = event.movementX ?? 0;
13541
+ const dy = event.movementY ?? 0;
13542
+ if (!dx && !dy) return;
13543
+ this._dragMoved = true;
13544
+ this.turn(dx, dy);
13545
+ }
13546
+ handlePointerUp(event) {
13547
+ if (this._joystick?.id === event.pointerId) {
13548
+ this._joystick = void 0;
13549
+ this.domElement?.releasePointerCapture?.(event.pointerId);
13550
+ return;
13551
+ }
13552
+ if (event.pointerId !== this._dragPointer) return;
13553
+ this._dragPointer = void 0;
13554
+ this.domElement?.releasePointerCapture?.(event.pointerId);
13555
+ if (this.enabled && this.pointerLock && !this._dragMoved && event.pointerType === "mouse" && event.button === 0) {
13556
+ this.lock();
13557
+ }
13558
+ }
13559
+ handleWheel(event) {
13560
+ if (!this.enabled || !this.enableWheelSpeed) return;
13561
+ event.preventDefault();
13562
+ const steps = event.deltaMode === 0 ? event.deltaY / 100 : event.deltaY;
13563
+ const [min, max] = this.speedRange;
13564
+ this.movementSpeed = import_three35.MathUtils.clamp(this.movementSpeed * Math.pow(1.15, -steps), Math.min(min, max), Math.max(min, max));
13565
+ }
13566
+ handlePointerLockChange() {
13567
+ const document2 = this.domElement?.ownerDocument;
13568
+ const locked = !!document2 && document2.pointerLockElement === this.domElement;
13569
+ if (locked === this._locked) return;
13570
+ this._locked = locked;
13571
+ if (!locked) this.releaseKeys();
13572
+ this.dispatchEvent({ type: locked ? "lock" : "unlock" });
13573
+ }
13574
+ turn(dx, dy) {
13575
+ _euler.setFromQuaternion(this.object.quaternion);
13576
+ _euler.y -= dx * this.lookSpeed;
13577
+ _euler.x = import_three35.MathUtils.clamp(_euler.x - dy * this.lookSpeed, -PITCH_LIMIT, PITCH_LIMIT);
13578
+ _euler.z = 0;
13579
+ this.object.quaternion.setFromEuler(_euler);
13580
+ this.notifyChange();
13581
+ }
13582
+ };
13583
+ function isFlyControls(obj) {
13584
+ return obj?.isFlyControls === true;
13585
+ }
13586
+
13587
+ // src/renderer/MineRenderScene.ts
13588
+ var import_three36 = require("three");
13272
13589
  init_SceneObject();
13273
13590
  var import_ts_deepmerge8 = __toESM(require_dist());
13274
13591
  init_ModelObject();
@@ -14178,7 +14495,7 @@ var SkinObject = class extends SceneObject {
14178
14495
  // src/renderer/MineRenderScene.ts
14179
14496
  init_EntityObject();
14180
14497
  init_ItemTints();
14181
- var _MineRenderScene = class _MineRenderScene extends import_three35.Scene {
14498
+ var _MineRenderScene = class _MineRenderScene extends import_three36.Scene {
14182
14499
  constructor(options) {
14183
14500
  super();
14184
14501
  this.isMineRenderScene = true;
@@ -14333,7 +14650,7 @@ function isMineRenderScene(obj) {
14333
14650
  }
14334
14651
 
14335
14652
  // src/renderer/Renderer.ts
14336
- var import_three37 = require("three");
14653
+ var import_three38 = require("three");
14337
14654
  var import_ts_deepmerge9 = __toESM(require_dist());
14338
14655
  var import_stats = __toESM(require("stats.js"));
14339
14656
  var import_postprocessing = require("postprocessing");
@@ -14342,11 +14659,11 @@ init_Model();
14342
14659
  init_three();
14343
14660
 
14344
14661
  // src/three/OrbitControls.js
14345
- var import_three36 = require("three");
14662
+ var import_three37 = require("three");
14346
14663
  var _changeEvent = { type: "change" };
14347
14664
  var _startEvent = { type: "start" };
14348
14665
  var _endEvent = { type: "end" };
14349
- var OrbitControls = class extends import_three36.EventDispatcher {
14666
+ var OrbitControls = class extends import_three37.EventDispatcher {
14350
14667
  constructor(object4, domElement) {
14351
14668
  super();
14352
14669
  if (domElement === void 0) console.warn('THREE.OrbitControls: The second parameter "domElement" is now mandatory.');
@@ -14355,7 +14672,7 @@ var OrbitControls = class extends import_three36.EventDispatcher {
14355
14672
  this.domElement = domElement;
14356
14673
  this.domElement.style.touchAction = "none";
14357
14674
  this.enabled = true;
14358
- this.target = new import_three36.Vector3();
14675
+ this.target = new import_three37.Vector3();
14359
14676
  this.minDistance = 0;
14360
14677
  this.maxDistance = Infinity;
14361
14678
  this.minZoom = 0;
@@ -14377,8 +14694,8 @@ var OrbitControls = class extends import_three36.EventDispatcher {
14377
14694
  this.autoRotate = false;
14378
14695
  this.autoRotateSpeed = 2;
14379
14696
  this.keys = { LEFT: "ArrowLeft", UP: "ArrowUp", RIGHT: "ArrowRight", BOTTOM: "ArrowDown" };
14380
- this.mouseButtons = { LEFT: import_three36.MOUSE.ROTATE, MIDDLE: import_three36.MOUSE.DOLLY, RIGHT: import_three36.MOUSE.PAN };
14381
- this.touches = { ONE: import_three36.TOUCH.ROTATE, TWO: import_three36.TOUCH.DOLLY_PAN };
14697
+ this.mouseButtons = { LEFT: import_three37.MOUSE.ROTATE, MIDDLE: import_three37.MOUSE.DOLLY, RIGHT: import_three37.MOUSE.PAN };
14698
+ this.touches = { ONE: import_three37.TOUCH.ROTATE, TWO: import_three37.TOUCH.DOLLY_PAN };
14382
14699
  this.target0 = this.target.clone();
14383
14700
  this.position0 = this.object.position.clone();
14384
14701
  this.zoom0 = this.object.zoom;
@@ -14407,11 +14724,11 @@ var OrbitControls = class extends import_three36.EventDispatcher {
14407
14724
  state = STATE.NONE;
14408
14725
  };
14409
14726
  this.update = function() {
14410
- const offset = new import_three36.Vector3();
14411
- const quat = new import_three36.Quaternion().setFromUnitVectors(object4.up, new import_three36.Vector3(0, 1, 0));
14727
+ const offset = new import_three37.Vector3();
14728
+ const quat = new import_three37.Quaternion().setFromUnitVectors(object4.up, new import_three37.Vector3(0, 1, 0));
14412
14729
  const quatInverse = quat.clone().invert();
14413
- const lastPosition = new import_three36.Vector3();
14414
- const lastQuaternion = new import_three36.Quaternion();
14730
+ const lastPosition = new import_three37.Vector3();
14731
+ const lastQuaternion = new import_three37.Quaternion();
14415
14732
  const twoPI = 2 * Math.PI;
14416
14733
  return function update() {
14417
14734
  const position = scope.object.position;
@@ -14497,20 +14814,20 @@ var OrbitControls = class extends import_three36.EventDispatcher {
14497
14814
  };
14498
14815
  let state = STATE.NONE;
14499
14816
  const EPS = 1e-6;
14500
- const spherical = new import_three36.Spherical();
14501
- const sphericalDelta = new import_three36.Spherical();
14817
+ const spherical = new import_three37.Spherical();
14818
+ const sphericalDelta = new import_three37.Spherical();
14502
14819
  let scale = 1;
14503
- const panOffset = new import_three36.Vector3();
14820
+ const panOffset = new import_three37.Vector3();
14504
14821
  let zoomChanged = false;
14505
- const rotateStart = new import_three36.Vector2();
14506
- const rotateEnd = new import_three36.Vector2();
14507
- const rotateDelta = new import_three36.Vector2();
14508
- const panStart = new import_three36.Vector2();
14509
- const panEnd = new import_three36.Vector2();
14510
- const panDelta = new import_three36.Vector2();
14511
- const dollyStart = new import_three36.Vector2();
14512
- const dollyEnd = new import_three36.Vector2();
14513
- const dollyDelta = new import_three36.Vector2();
14822
+ const rotateStart = new import_three37.Vector2();
14823
+ const rotateEnd = new import_three37.Vector2();
14824
+ const rotateDelta = new import_three37.Vector2();
14825
+ const panStart = new import_three37.Vector2();
14826
+ const panEnd = new import_three37.Vector2();
14827
+ const panDelta = new import_three37.Vector2();
14828
+ const dollyStart = new import_three37.Vector2();
14829
+ const dollyEnd = new import_three37.Vector2();
14830
+ const dollyDelta = new import_three37.Vector2();
14514
14831
  const pointers = [];
14515
14832
  const pointerPositions = {};
14516
14833
  function getAutoRotationAngle() {
@@ -14526,7 +14843,7 @@ var OrbitControls = class extends import_three36.EventDispatcher {
14526
14843
  sphericalDelta.phi -= angle;
14527
14844
  }
14528
14845
  const panLeft = function() {
14529
- const v = new import_three36.Vector3();
14846
+ const v = new import_three37.Vector3();
14530
14847
  return function panLeft2(distance, objectMatrix) {
14531
14848
  v.setFromMatrixColumn(objectMatrix, 0);
14532
14849
  v.multiplyScalar(-distance);
@@ -14534,7 +14851,7 @@ var OrbitControls = class extends import_three36.EventDispatcher {
14534
14851
  };
14535
14852
  }();
14536
14853
  const panUp = function() {
14537
- const v = new import_three36.Vector3();
14854
+ const v = new import_three37.Vector3();
14538
14855
  return function panUp2(distance, objectMatrix) {
14539
14856
  if (scope.screenSpacePanning === true) {
14540
14857
  v.setFromMatrixColumn(objectMatrix, 1);
@@ -14547,7 +14864,7 @@ var OrbitControls = class extends import_three36.EventDispatcher {
14547
14864
  };
14548
14865
  }();
14549
14866
  const pan = function() {
14550
- const offset = new import_three36.Vector3();
14867
+ const offset = new import_three37.Vector3();
14551
14868
  return function pan2(deltaX, deltaY) {
14552
14869
  const element = scope.domElement;
14553
14870
  if (scope.object.isPerspectiveCamera) {
@@ -14796,12 +15113,12 @@ var OrbitControls = class extends import_three36.EventDispatcher {
14796
15113
  mouseAction = -1;
14797
15114
  }
14798
15115
  switch (mouseAction) {
14799
- case import_three36.MOUSE.DOLLY:
15116
+ case import_three37.MOUSE.DOLLY:
14800
15117
  if (scope.enableZoom === false) return;
14801
15118
  handleMouseDownDolly(event);
14802
15119
  state = STATE.DOLLY;
14803
15120
  break;
14804
- case import_three36.MOUSE.ROTATE:
15121
+ case import_three37.MOUSE.ROTATE:
14805
15122
  if (event.ctrlKey || event.metaKey || event.shiftKey) {
14806
15123
  if (scope.enablePan === false) return;
14807
15124
  handleMouseDownPan(event);
@@ -14812,7 +15129,7 @@ var OrbitControls = class extends import_three36.EventDispatcher {
14812
15129
  state = STATE.ROTATE;
14813
15130
  }
14814
15131
  break;
14815
- case import_three36.MOUSE.PAN:
15132
+ case import_three37.MOUSE.PAN:
14816
15133
  if (event.ctrlKey || event.metaKey || event.shiftKey) {
14817
15134
  if (scope.enableRotate === false) return;
14818
15135
  handleMouseDownRotate(event);
@@ -14868,12 +15185,12 @@ var OrbitControls = class extends import_three36.EventDispatcher {
14868
15185
  switch (pointers.length) {
14869
15186
  case 1:
14870
15187
  switch (scope.touches.ONE) {
14871
- case import_three36.TOUCH.ROTATE:
15188
+ case import_three37.TOUCH.ROTATE:
14872
15189
  if (scope.enableRotate === false) return;
14873
15190
  handleTouchStartRotate();
14874
15191
  state = STATE.TOUCH_ROTATE;
14875
15192
  break;
14876
- case import_three36.TOUCH.PAN:
15193
+ case import_three37.TOUCH.PAN:
14877
15194
  if (scope.enablePan === false) return;
14878
15195
  handleTouchStartPan();
14879
15196
  state = STATE.TOUCH_PAN;
@@ -14884,12 +15201,12 @@ var OrbitControls = class extends import_three36.EventDispatcher {
14884
15201
  break;
14885
15202
  case 2:
14886
15203
  switch (scope.touches.TWO) {
14887
- case import_three36.TOUCH.DOLLY_PAN:
15204
+ case import_three37.TOUCH.DOLLY_PAN:
14888
15205
  if (scope.enableZoom === false && scope.enablePan === false) return;
14889
15206
  handleTouchStartDollyPan();
14890
15207
  state = STATE.TOUCH_DOLLY_PAN;
14891
15208
  break;
14892
- case import_three36.TOUCH.DOLLY_ROTATE:
15209
+ case import_three37.TOUCH.DOLLY_ROTATE:
14893
15210
  if (scope.enableZoom === false && scope.enableRotate === false) return;
14894
15211
  handleTouchStartDollyRotate();
14895
15212
  state = STATE.TOUCH_DOLLY_ROTATE;
@@ -14956,7 +15273,7 @@ var OrbitControls = class extends import_three36.EventDispatcher {
14956
15273
  function trackPointer(event) {
14957
15274
  let position = pointerPositions[event.pointerId];
14958
15275
  if (position === void 0) {
14959
- position = new import_three36.Vector2();
15276
+ position = new import_three37.Vector2();
14960
15277
  pointerPositions[event.pointerId] = position;
14961
15278
  }
14962
15279
  position.set(event.pageX, event.pageY);
@@ -14976,10 +15293,10 @@ var MapControls = class extends OrbitControls {
14976
15293
  constructor(object4, domElement) {
14977
15294
  super(object4, domElement);
14978
15295
  this.screenSpacePanning = false;
14979
- this.mouseButtons.LEFT = import_three36.MOUSE.PAN;
14980
- this.mouseButtons.RIGHT = import_three36.MOUSE.ROTATE;
14981
- this.touches.ONE = import_three36.TOUCH.PAN;
14982
- this.touches.TWO = import_three36.TOUCH.DOLLY_ROTATE;
15296
+ this.mouseButtons.LEFT = import_three37.MOUSE.PAN;
15297
+ this.mouseButtons.RIGHT = import_three37.MOUSE.ROTATE;
15298
+ this.touches.ONE = import_three37.TOUCH.PAN;
15299
+ this.touches.TWO = import_three37.TOUCH.DOLLY_ROTATE;
14983
15300
  }
14984
15301
  };
14985
15302
 
@@ -15050,14 +15367,14 @@ var _Renderer = class _Renderer {
15050
15367
  switch (this.options.camera.type) {
15051
15368
  case "perspective":
15052
15369
  default:
15053
- return new import_three37.PerspectiveCamera(
15370
+ return new import_three38.PerspectiveCamera(
15054
15371
  this.options.camera.perspective.fov,
15055
15372
  this.options.camera.perspective.aspect ?? this.viewWidth / this.viewHeight,
15056
15373
  this.options.camera.near,
15057
15374
  this.options.camera.far
15058
15375
  );
15059
15376
  case "orthographic":
15060
- return new import_three37.OrthographicCamera(
15377
+ return new import_three38.OrthographicCamera(
15061
15378
  this.options.camera.orthographic.left ?? this.viewWidth / -2,
15062
15379
  this.options.camera.orthographic.right ?? this.viewWidth / 2,
15063
15380
  this.options.camera.orthographic.top ?? this.viewHeight / 2,
@@ -15073,7 +15390,7 @@ var _Renderer = class _Renderer {
15073
15390
  }
15074
15391
  const pixelRatio = this.options.render.pixelRatio ?? 1;
15075
15392
  this._surface?.resize?.(Math.floor(this.viewWidth * pixelRatio), Math.floor(this.viewHeight * pixelRatio));
15076
- const renderer = new import_three37.WebGLRenderer({
15393
+ const renderer = new import_three38.WebGLRenderer({
15077
15394
  canvas: this._surface?.canvas,
15078
15395
  context: this._surface?.context,
15079
15396
  antialias: this.options.render.antialias,
@@ -15083,8 +15400,8 @@ var _Renderer = class _Renderer {
15083
15400
  });
15084
15401
  renderer.setClearColor(0, 0);
15085
15402
  renderer.shadowMap.enabled = true;
15086
- renderer.shadowMap.type = import_three37.PCFShadowMap;
15087
- renderer.outputColorSpace = import_three37.SRGBColorSpace;
15403
+ renderer.shadowMap.type = import_three38.PCFShadowMap;
15404
+ renderer.outputColorSpace = import_three38.SRGBColorSpace;
15088
15405
  if (this._surface) {
15089
15406
  renderer.setDrawingBufferSize(this.viewWidth, this.viewHeight, pixelRatio);
15090
15407
  } else {
@@ -15102,20 +15419,77 @@ var _Renderer = class _Renderer {
15102
15419
  }
15103
15420
  createControls() {
15104
15421
  if (!this.options.controls?.enabled) return void 0;
15105
- const position = this.camera.position.clone();
15106
- const controls = new OrbitControls(this.camera, this.renderer.domElement);
15107
- this.camera.position.copy(position);
15422
+ return this.createControlsFor(this.options.controls.mode ?? "orbit", this.initialTarget());
15423
+ }
15424
+ initialTarget() {
15108
15425
  const target = this.options.camera.lookingAt;
15109
- if (isVector3(target)) {
15426
+ if (isVector3(target)) return target.clone();
15427
+ if (isTripleArray(target)) return new import_three38.Vector3(target[0], target[1], target[2]);
15428
+ return new import_three38.Vector3();
15429
+ }
15430
+ createControlsFor(mode, target) {
15431
+ let controls;
15432
+ if (mode === "fly") {
15433
+ controls = new FlyControls(this.camera, this.renderer.domElement);
15434
+ controls.lookAt(target);
15435
+ controls.saveState();
15436
+ } else {
15437
+ const position = this.camera.position.clone();
15438
+ controls = new OrbitControls(this.camera, this.renderer.domElement);
15439
+ this.camera.position.copy(position);
15110
15440
  controls.target.copy(target);
15111
- } else if (isTripleArray(target)) {
15112
- controls.target.set(target[0], target[1], target[2]);
15441
+ controls.update();
15442
+ controls.saveState();
15113
15443
  }
15114
- controls.update();
15115
- controls.saveState();
15444
+ this._controlsTime = void 0;
15116
15445
  this.registerEventDispatcher(controls);
15117
15446
  return controls;
15118
15447
  }
15448
+ /**
15449
+ * Replaces renderer-owned controls with the selected mode, keeping the camera where it is.
15450
+ * Switching to orbit controls targets the point the camera looks at, at the previous orbit distance.
15451
+ * Returns the new controls, or undefined when controls were disabled at construction or after disposal.
15452
+ */
15453
+ setControlsMode(mode) {
15454
+ const current = this._controls;
15455
+ if (this._disposed || !current) return void 0;
15456
+ if (this.controlsMode === mode) return current;
15457
+ let target;
15458
+ if (isFlyControls(current)) {
15459
+ const distance = this._orbitDistance ?? (this.camera.position.distanceTo(this.initialTarget()) || 1);
15460
+ target = new import_three38.Vector3(0, 0, -distance).applyQuaternion(this.camera.quaternion).add(this.camera.position);
15461
+ } else {
15462
+ target = current.target.clone();
15463
+ this._orbitDistance = this.camera.position.distanceTo(target);
15464
+ }
15465
+ const enabled = current.enabled;
15466
+ this.disposeControls(current);
15467
+ this._controls = this.createControlsFor(mode, target);
15468
+ this._controls.enabled = enabled;
15469
+ this.dirty = true;
15470
+ return this._controls;
15471
+ }
15472
+ disposeControls(controls) {
15473
+ this._controls = void 0;
15474
+ this.unregisterEventDispatcher(controls);
15475
+ controls.enabled = false;
15476
+ controls.dispose();
15477
+ }
15478
+ /** Advances owned controls; without a frame time, flight movement does not progress. */
15479
+ updateControls(time) {
15480
+ const controls = this._controls;
15481
+ if (!controls?.enabled) {
15482
+ this._controlsTime = void 0;
15483
+ return;
15484
+ }
15485
+ if (!isFlyControls(controls)) {
15486
+ controls.update();
15487
+ return;
15488
+ }
15489
+ const previous = this._controlsTime;
15490
+ if (time !== void 0) this._controlsTime = time;
15491
+ controls.update(time === void 0 || previous === void 0 ? 0 : (time - previous) / 1e3);
15492
+ }
15119
15493
  //</editor-fold>
15120
15494
  init() {
15121
15495
  if (this._disposed) return;
@@ -15123,20 +15497,20 @@ var _Renderer = class _Renderer {
15123
15497
  window["__THREE_DEVTOOLS__"].dispatchEvent(new CustomEvent("observe", { detail: this.scene }));
15124
15498
  }
15125
15499
  if (this.options.debug.grid) {
15126
- const gridHelper = new import_three37.GridHelper(128, 16);
15500
+ const gridHelper = new import_three38.GridHelper(128, 16);
15127
15501
  this._debugHelpers.push(gridHelper);
15128
15502
  this.scene.add(gridHelper);
15129
- const gridHelper2 = new import_three37.GridHelper(128, 16);
15503
+ const gridHelper2 = new import_three38.GridHelper(128, 16);
15130
15504
  this._debugHelpers.push(gridHelper2);
15131
15505
  gridHelper2.rotation.x = 90 * (Math.PI / 180);
15132
15506
  this.scene.add(gridHelper2);
15133
- const gridHelper3 = new import_three37.GridHelper(128, 16);
15507
+ const gridHelper3 = new import_three38.GridHelper(128, 16);
15134
15508
  this._debugHelpers.push(gridHelper3);
15135
15509
  gridHelper3.rotation.z = 90 * (Math.PI / 180);
15136
15510
  this.scene.add(gridHelper3);
15137
15511
  }
15138
15512
  if (this.options.debug.axes) {
15139
- const axesHelper = new import_three37.AxesHelper(64);
15513
+ const axesHelper = new import_three38.AxesHelper(64);
15140
15514
  this._debugHelpers.push(axesHelper);
15141
15515
  this.scene.add(axesHelper);
15142
15516
  }
@@ -15192,6 +15566,12 @@ var _Renderer = class _Renderer {
15192
15566
  events.add(changeEvent2);
15193
15567
  dispatcher.addEventListener(changeEvent2, this._changeListener);
15194
15568
  }
15569
+ unregisterEventDispatcher(dispatcher) {
15570
+ const events = this._eventDispatchers.get(dispatcher);
15571
+ if (!events) return;
15572
+ for (const event of events) dispatcher.removeEventListener(event, this._changeListener);
15573
+ this._eventDispatchers.delete(dispatcher);
15574
+ }
15195
15575
  /** Updates the camera and canvas size. Width and height are in CSS pixels. */
15196
15576
  resize(width, height) {
15197
15577
  if (this._disposed) return;
@@ -15268,6 +15648,7 @@ var _Renderer = class _Renderer {
15268
15648
  this.renderer.setAnimationLoop(null);
15269
15649
  }
15270
15650
  this._nextFrameTime = void 0;
15651
+ this._controlsTime = void 0;
15271
15652
  for (const subscription of this._frameCallbacks.values()) subscription.previous = void 0;
15272
15653
  }
15273
15654
  /**
@@ -15297,10 +15678,7 @@ var _Renderer = class _Renderer {
15297
15678
  }
15298
15679
  this._element = void 0;
15299
15680
  if (this._controls) {
15300
- const controls = this._controls;
15301
- this._controls = void 0;
15302
- controls.enabled = false;
15303
- controls.dispose();
15681
+ this.disposeControls(this._controls);
15304
15682
  }
15305
15683
  this.scene.clear();
15306
15684
  for (const helper of this._debugHelpers) {
@@ -15317,9 +15695,7 @@ var _Renderer = class _Renderer {
15317
15695
  }
15318
15696
  animate(t = performance.now()) {
15319
15697
  if (!this._running) return;
15320
- if (this._controls?.enabled) {
15321
- this._controls.update();
15322
- }
15698
+ this.updateControls(t);
15323
15699
  if (!this._running) return;
15324
15700
  if (!this.dirty && !this.options.render.renderAlways && !this._frameCallbacks.size && !this._videoExporter) return;
15325
15701
  const interval = this._frameInterval;
@@ -15356,7 +15732,7 @@ var _Renderer = class _Renderer {
15356
15732
  /** Draws a fresh frame without starting the animation loop or invoking frame callbacks. */
15357
15733
  renderOnce() {
15358
15734
  if (this._disposed) throw new Error("Cannot render a disposed renderer");
15359
- if (this._controls?.enabled) this._controls.update();
15735
+ this.updateControls();
15360
15736
  this.drawFrame();
15361
15737
  }
15362
15738
  /**
@@ -15386,7 +15762,7 @@ var _Renderer = class _Renderer {
15386
15762
  try {
15387
15763
  if (!wasRunning) this.start();
15388
15764
  this._videoExporter = exporter;
15389
- if (this._controls?.enabled) this._controls.update();
15765
+ this.updateControls();
15390
15766
  this.drawFrame();
15391
15767
  } catch (error) {
15392
15768
  exporter.cancel(error);
@@ -15437,6 +15813,19 @@ var _Renderer = class _Renderer {
15437
15813
  get controls() {
15438
15814
  return this._controls;
15439
15815
  }
15816
+ /** Renderer-owned OrbitControls, or undefined in fly mode or without controls. */
15817
+ get orbitControls() {
15818
+ return this._controls && !isFlyControls(this._controls) ? this._controls : void 0;
15819
+ }
15820
+ /** Renderer-owned {@link FlyControls}, or undefined in orbit mode or without controls. */
15821
+ get flyControls() {
15822
+ return isFlyControls(this._controls) ? this._controls : void 0;
15823
+ }
15824
+ /** The active renderer-owned controls mode, or undefined without controls. */
15825
+ get controlsMode() {
15826
+ if (!this._controls) return void 0;
15827
+ return isFlyControls(this._controls) ? "fly" : "orbit";
15828
+ }
15440
15829
  ///
15441
15830
  };
15442
15831
  _Renderer.DEFAULT_OPTIONS = (0, import_ts_deepmerge9.default)({}, {
@@ -15454,8 +15843,8 @@ _Renderer.DEFAULT_OPTIONS = (0, import_ts_deepmerge9.default)({}, {
15454
15843
  top: void 0,
15455
15844
  bottom: void 0
15456
15845
  },
15457
- position: new import_three37.Vector3(50, 50, 50),
15458
- lookingAt: new import_three37.Vector3(0, 0, 0)
15846
+ position: new import_three38.Vector3(50, 50, 50),
15847
+ lookingAt: new import_three38.Vector3(0, 0, 0)
15459
15848
  },
15460
15849
  render: {
15461
15850
  fpsLimit: 60,
@@ -15470,7 +15859,8 @@ _Renderer.DEFAULT_OPTIONS = (0, import_ts_deepmerge9.default)({}, {
15470
15859
  enabled: true
15471
15860
  },
15472
15861
  controls: {
15473
- enabled: false
15862
+ enabled: false,
15863
+ mode: "orbit"
15474
15864
  },
15475
15865
  debug: {
15476
15866
  grid: false,
@@ -15724,7 +16114,7 @@ function parseSceneDocument(value) {
15724
16114
  }
15725
16115
 
15726
16116
  // src/scene/SceneDocumentLoader.ts
15727
- var import_three39 = require("three");
16117
+ var import_three40 = require("three");
15728
16118
  init_AssetKey();
15729
16119
  init_AssetLoader();
15730
16120
  init_BlockStates();
@@ -15785,7 +16175,7 @@ var SceneDocumentLoader = class {
15785
16175
  if (definition.minecraftVersion !== void 0 && definition.minecraftVersion !== AssetLoader.version) {
15786
16176
  throw new Error(`Scene requires Minecraft ${definition.minecraftVersion}; call AssetLoader.setVersion("${definition.minecraftVersion}") before loading it`);
15787
16177
  }
15788
- const root = new import_three39.Group();
16178
+ const root = new import_three40.Group();
15789
16179
  root.name = "MineRender scene document";
15790
16180
  const objects = [];
15791
16181
  let disposed = false;
@@ -15825,7 +16215,7 @@ var SceneDocumentLoader = class {
15825
16215
  return this.loadValidatedObject(scene, definition, parent);
15826
16216
  }
15827
16217
  static async loadValidatedObject(scene, definition, parent) {
15828
- const root = new import_three39.Group();
16218
+ const root = new import_three40.Group();
15829
16219
  root.name = definition.name ?? definition.id;
15830
16220
  root.userData.sceneObjectId = definition.id;
15831
16221
  root.position.fromArray(definition.position ?? [0, 0, 0]);
@@ -16703,12 +17093,12 @@ var AnvilWorldSource = class {
16703
17093
  };
16704
17094
 
16705
17095
  // src/world/Chunk.ts
16706
- var import_three43 = require("three");
17096
+ var import_three44 = require("three");
16707
17097
  init_BlockStates();
16708
17098
  init_AssetKey();
16709
17099
 
16710
17100
  // src/world/MineRenderWorld.ts
16711
- var import_three41 = require("three");
17101
+ var import_three42 = require("three");
16712
17102
  init_Model();
16713
17103
  init_util();
16714
17104
  init_AssetKey();
@@ -16716,7 +17106,7 @@ init_BlockStates();
16716
17106
  init_CubeFace();
16717
17107
 
16718
17108
  // src/world/SectionModels.ts
16719
- var import_three40 = require("three");
17109
+ var import_three41 = require("three");
16720
17110
  init_AssetKey();
16721
17111
  init_Models();
16722
17112
  init_CubeFace();
@@ -16740,7 +17130,7 @@ function cached(map, key, load) {
16740
17130
  }
16741
17131
  function compactQuads(geometry, keep) {
16742
17132
  const quads = keep.flatMap((kept, index) => kept ? [index] : []);
16743
- const compact = new import_three40.BufferGeometry();
17133
+ const compact = new import_three41.BufferGeometry();
16744
17134
  for (const [name, size] of Object.entries({ position: 3, normal: 3, uv: 2, uvBounds: 4, color: 3 })) {
16745
17135
  const source2 = geometry.getAttribute(name);
16746
17136
  const defaults = name === "uvBounds" ? [0, 0, 1, 1] : name === "color" ? [1, 1, 1] : void 0;
@@ -16752,7 +17142,7 @@ function compactQuads(geometry, keep) {
16752
17142
  }
16753
17143
  }
16754
17144
  }
16755
- compact.setAttribute(name, new import_three40.BufferAttribute(values, size));
17145
+ compact.setAttribute(name, new import_three41.BufferAttribute(values, size));
16756
17146
  }
16757
17147
  const source = geometry.getIndex();
16758
17148
  const indices = [];
@@ -16826,7 +17216,7 @@ var SectionModels = class {
16826
17216
  });
16827
17217
  await object4.init();
16828
17218
  let geometry = object4.children[0].geometry;
16829
- geometry.applyMatrix4(new import_three40.Matrix4().makeRotationFromEuler(rotation));
17219
+ geometry.applyMatrix4(new import_three41.Matrix4().makeRotationFromEuler(rotation));
16830
17220
  object4.clear();
16831
17221
  const keep = [];
16832
17222
  const cullFaces = [];
@@ -16840,7 +17230,7 @@ var SectionModels = class {
16840
17230
  cullFaces.push(0);
16841
17231
  continue;
16842
17232
  }
16843
- const normal = new import_three40.Vector3(...CUBE_FACE_OFFSETS[local]).applyEuler(rotation);
17233
+ const normal = new import_three41.Vector3(...CUBE_FACE_OFFSETS[local]).applyEuler(rotation);
16844
17234
  const world = CUBE_FACE_OFFSETS.findIndex(([x, y, z]) => Math.abs(normal.x - x) < 1e-6 && Math.abs(normal.y - y) < 1e-6 && Math.abs(normal.z - z) < 1e-6);
16845
17235
  cullFaces.push(world < 0 ? 0 : 1 << world);
16846
17236
  }
@@ -17036,17 +17426,17 @@ var MineRenderWorld = class {
17036
17426
  }
17037
17427
  getBlockAt(posOrX, y, z) {
17038
17428
  if (typeof posOrX == "number") {
17039
- return this.getBlockAt(new import_three41.Vector3(posOrX, y, z));
17429
+ return this.getBlockAt(new import_three42.Vector3(posOrX, y, z));
17040
17430
  }
17041
17431
  if (isTripleArray(posOrX)) {
17042
- return this.getBlockAt(new import_three41.Vector3(posOrX[0], posOrX[1], posOrX[2]));
17432
+ return this.getBlockAt(new import_three42.Vector3(posOrX[0], posOrX[1], posOrX[2]));
17043
17433
  }
17044
17434
  this.validatePosBounds(posOrX);
17045
17435
  return this.getChunkAt(posOrX)?.getBlockAt(posOrX);
17046
17436
  }
17047
17437
  getBiomeAt(posOrX, y, z) {
17048
- if (typeof posOrX === "number") return this.getBiomeAt(new import_three41.Vector3(posOrX, y, z));
17049
- if (isTripleArray(posOrX)) return this.getBiomeAt(new import_three41.Vector3(...posOrX));
17438
+ if (typeof posOrX === "number") return this.getBiomeAt(new import_three42.Vector3(posOrX, y, z));
17439
+ if (isTripleArray(posOrX)) return this.getBiomeAt(new import_three42.Vector3(...posOrX));
17050
17440
  this.validatePosBounds(posOrX);
17051
17441
  const cx = Math.floor(posOrX.x / 16), cy = Math.floor(posOrX.y / 16), cz = Math.floor(posOrX.z / 16);
17052
17442
  const lx = posOrX.x - cx * 16, ly = posOrX.y - cy * 16, lz = posOrX.z - cz * 16;
@@ -17054,10 +17444,10 @@ var MineRenderWorld = class {
17054
17444
  }
17055
17445
  async setBlockAt(posOrX, yOrBlock, z, block) {
17056
17446
  if (typeof posOrX == "number") {
17057
- return this.setBlockAt(new import_three41.Vector3(posOrX, yOrBlock, z), block);
17447
+ return this.setBlockAt(new import_three42.Vector3(posOrX, yOrBlock, z), block);
17058
17448
  }
17059
17449
  if (isTripleArray(posOrX)) {
17060
- return this.setBlockAt(new import_three41.Vector3(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
17450
+ return this.setBlockAt(new import_three42.Vector3(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
17061
17451
  }
17062
17452
  return this.placeBlock(posOrX, yOrBlock);
17063
17453
  }
@@ -17068,10 +17458,10 @@ var MineRenderWorld = class {
17068
17458
  }
17069
17459
  async setBlockVisibleAt(posOrX, yOrVisible, z, visible) {
17070
17460
  if (typeof posOrX === "number") {
17071
- return this.setBlockVisibleAt(new import_three41.Vector3(posOrX, yOrVisible, z), visible);
17461
+ return this.setBlockVisibleAt(new import_three42.Vector3(posOrX, yOrVisible, z), visible);
17072
17462
  }
17073
17463
  if (isTripleArray(posOrX)) {
17074
- return this.setBlockVisibleAt(new import_three41.Vector3(...posOrX), yOrVisible);
17464
+ return this.setBlockVisibleAt(new import_three42.Vector3(...posOrX), yOrVisible);
17075
17465
  }
17076
17466
  this.validatePosBounds(posOrX);
17077
17467
  await this.getChunkAt(posOrX)?.setBlockVisibleAt(posOrX, yOrVisible);
@@ -17097,7 +17487,7 @@ var MineRenderWorld = class {
17097
17487
  const collect = async (positions2) => {
17098
17488
  for (const pos of positions2) changes.set(pos.toArray().join(","), pos);
17099
17489
  };
17100
- const place = (block) => this.placeBlock(new import_three41.Vector3(...block.position), block, collect);
17490
+ const place = (block) => this.placeBlock(new import_three42.Vector3(...block.position), block, collect);
17101
17491
  const keys = /* @__PURE__ */ new Map();
17102
17492
  const types = /* @__PURE__ */ new Set();
17103
17493
  for (const block of multiblock.blocks) {
@@ -17113,7 +17503,7 @@ var MineRenderWorld = class {
17113
17503
  }
17114
17504
  if (!executor) {
17115
17505
  const groups2 = /* @__PURE__ */ new Map();
17116
- const position = new import_three41.Vector3();
17506
+ const position = new import_three42.Vector3();
17117
17507
  for (const block of multiblock.blocks) {
17118
17508
  const [x, y, z] = block.position;
17119
17509
  this.validatePosBounds(position.set(x, y, z));
@@ -17153,7 +17543,7 @@ var MineRenderWorld = class {
17153
17543
  try {
17154
17544
  positions = await chunk.placeBlocks(blocks);
17155
17545
  } finally {
17156
- positions ?? (positions = blocks.map(({ index }) => new import_three41.Vector3(
17546
+ positions ?? (positions = blocks.map(({ index }) => new import_three42.Vector3(
17157
17547
  chunk.x * 16 + index % 16,
17158
17548
  chunk.y * 16 + Math.floor(index / 256),
17159
17549
  chunk.z * 16 + Math.floor(index / 16) % 16
@@ -17192,7 +17582,7 @@ var MineRenderWorld = class {
17192
17582
  let sliceStart = performance.now();
17193
17583
  for (const section of chunk.sections) {
17194
17584
  if (section.biomes) {
17195
- const position = new import_three41.Vector3(chunk.x * 16, section.y * 16, chunk.z * 16);
17585
+ const position = new import_three42.Vector3(chunk.x * 16, section.y * 16, chunk.z * 16);
17196
17586
  this.validatePosBounds(position);
17197
17587
  const copy = [...section.biomes];
17198
17588
  if (copy.length !== 64 || !copy.every((id) => typeof id === "string" && id.length > 0)) {
@@ -17205,7 +17595,7 @@ var MineRenderWorld = class {
17205
17595
  }
17206
17596
  if (!executor) {
17207
17597
  if (!occupiedSections.has(section.y)) continue;
17208
- const position = new import_three41.Vector3(chunk.x * 16, section.y * 16, chunk.z * 16);
17598
+ const position = new import_three42.Vector3(chunk.x * 16, section.y * 16, chunk.z * 16);
17209
17599
  this.validatePosBounds(position);
17210
17600
  const target = this.getOrCreateChunkAt(position);
17211
17601
  try {
@@ -17299,7 +17689,7 @@ var MineRenderWorld = class {
17299
17689
  this.sectionModels?.clear();
17300
17690
  }
17301
17691
  updateCulling(positions) {
17302
- const neighbor = new import_three41.Vector3();
17692
+ const neighbor = new import_three42.Vector3();
17303
17693
  for (const pos of positions) {
17304
17694
  const cx = Math.floor(pos.x / 16), cy = Math.floor(pos.y / 16), cz = Math.floor(pos.z / 16);
17305
17695
  const chunk = this._chunks.get(`${cx}_${cy}_${cz}`);
@@ -17391,7 +17781,7 @@ var MineRenderWorld = class {
17391
17781
  }
17392
17782
  /** Converts block coordinates to scene units by multiplying each component by 16. */
17393
17783
  static worldToScenePosition(pos) {
17394
- return new import_three41.Vector3(
17784
+ return new import_three42.Vector3(
17395
17785
  pos.x * 16,
17396
17786
  pos.y * 16,
17397
17787
  pos.z * 16
@@ -17399,7 +17789,7 @@ var MineRenderWorld = class {
17399
17789
  }
17400
17790
  /** Converts scene units to block coordinates without rounding to an integer block. */
17401
17791
  static sceneToWorldPosition(pos) {
17402
- return new import_three41.Vector3(
17792
+ return new import_three42.Vector3(
17403
17793
  pos.x / 16,
17404
17794
  pos.y / 16,
17405
17795
  pos.z / 16
@@ -17422,7 +17812,7 @@ var MineRenderWorld = class {
17422
17812
  init_Model();
17423
17813
 
17424
17814
  // src/world/SectionMesh.ts
17425
- var import_three42 = require("three");
17815
+ var import_three43 = require("three");
17426
17816
  init_CanvasCompat();
17427
17817
  init_Materials();
17428
17818
 
@@ -17650,7 +18040,7 @@ var SectionWorker = _SectionWorker;
17650
18040
 
17651
18041
  // src/world/SectionMesh.ts
17652
18042
  var templateCache = /* @__PURE__ */ new WeakMap();
17653
- var WATER_TINT = new import_three42.Color(4159204).toArray();
18043
+ var WATER_TINT = new import_three43.Color(4159204).toArray();
17654
18044
  function toInput(entries, maxAtlasSize, fluids) {
17655
18045
  if (!Number.isInteger(maxAtlasSize) || maxAtlasSize < 1) throw new RangeError("Section atlas size must be a positive integer");
17656
18046
  const atlases = [];
@@ -17745,7 +18135,7 @@ function toInput(entries, maxAtlasSize, fluids) {
17745
18135
  }
17746
18136
  return { input, atlases };
17747
18137
  }
17748
- var SectionMesh = class _SectionMesh extends import_three42.Group {
18138
+ var SectionMesh = class _SectionMesh extends import_three43.Group {
17749
18139
  constructor() {
17750
18140
  super(...arguments);
17751
18141
  this.ownedMeshes = [];
@@ -17770,26 +18160,26 @@ var SectionMesh = class _SectionMesh extends import_three42.Group {
17770
18160
  for (const { atlas, x, y } of page.placements) {
17771
18161
  context.drawImage(atlases[atlas].image.canvas, x, y);
17772
18162
  }
17773
- const geometry = new import_three42.BufferGeometry();
17774
- geometry.setAttribute("position", new import_three42.Float32BufferAttribute(page.positions.buffer, 3));
17775
- geometry.setAttribute("normal", new import_three42.Float32BufferAttribute(page.normals.buffer, 3));
17776
- geometry.setAttribute("uv", new import_three42.Float32BufferAttribute(page.uvs.buffer, 2));
17777
- geometry.setAttribute("uvBounds", new import_three42.Float32BufferAttribute(page.uvBounds.buffer, 4));
17778
- geometry.setAttribute("color", new import_three42.Float32BufferAttribute(page.colors.buffer, 3));
17779
- geometry.setIndex(new import_three42.Uint32BufferAttribute(page.indices.buffer, 1));
18163
+ const geometry = new import_three43.BufferGeometry();
18164
+ geometry.setAttribute("position", new import_three43.Float32BufferAttribute(page.positions.buffer, 3));
18165
+ geometry.setAttribute("normal", new import_three43.Float32BufferAttribute(page.normals.buffer, 3));
18166
+ geometry.setAttribute("uv", new import_three43.Float32BufferAttribute(page.uvs.buffer, 2));
18167
+ geometry.setAttribute("uvBounds", new import_three43.Float32BufferAttribute(page.uvBounds.buffer, 4));
18168
+ geometry.setAttribute("color", new import_three43.Float32BufferAttribute(page.colors.buffer, 3));
18169
+ geometry.setIndex(new import_three43.Uint32BufferAttribute(page.indices.buffer, 1));
17780
18170
  geometry.computeBoundingBox();
17781
18171
  geometry.computeBoundingSphere();
17782
18172
  const transparent = page.layer === 2 ? atlases[page.placements[0].atlas].hasTranslucency : page.layer === 1;
17783
18173
  const material = Materials.createShadedCanvasMaterial(canvas, transparent, false, true);
17784
- material.side = import_three42.FrontSide;
18174
+ material.side = import_three43.FrontSide;
17785
18175
  if (page.layer === 2) {
17786
- material.side = import_three42.DoubleSide;
18176
+ material.side = import_three43.DoubleSide;
17787
18177
  material.forceSinglePass = true;
17788
18178
  material.depthWrite = !material.transparent;
17789
18179
  }
17790
18180
  material.vertexColors = true;
17791
18181
  const texture = material.uniforms?.map?.value ?? material.map;
17792
- const mesh = new import_three42.Mesh(geometry, material);
18182
+ const mesh = new import_three43.Mesh(geometry, material);
17793
18183
  section.add(mesh);
17794
18184
  const unsubscribe = [];
17795
18185
  for (const { atlas: id, x, y } of page.placements) {
@@ -17835,7 +18225,7 @@ var Chunk = class _Chunk {
17835
18225
  this.sectionBlocks = /* @__PURE__ */ new Map();
17836
18226
  this.hiddenBlocks = /* @__PURE__ */ new Set();
17837
18227
  this.fluidCells = new Uint8Array(4096);
17838
- this.blockPosition = new import_three43.Vector3();
18228
+ this.blockPosition = new import_three44.Vector3();
17839
18229
  this.meshDirty = false;
17840
18230
  this.meshGeneration = 0;
17841
18231
  this.scene = scene;
@@ -17845,10 +18235,10 @@ var Chunk = class _Chunk {
17845
18235
  }
17846
18236
  getBlockAt(posOrX, y, z) {
17847
18237
  if (typeof posOrX == "number") {
17848
- return this.getBlockAt(new import_three43.Vector3(posOrX, y, z));
18238
+ return this.getBlockAt(new import_three44.Vector3(posOrX, y, z));
17849
18239
  }
17850
18240
  if (isTripleArray(posOrX)) {
17851
- return this.getBlockAt(new import_three43.Vector3(posOrX[0], posOrX[1], posOrX[2]));
18241
+ return this.getBlockAt(new import_three44.Vector3(posOrX[0], posOrX[1], posOrX[2]));
17852
18242
  }
17853
18243
  const pos = this.blockPosition.set(posOrX.x - this.x * 16, posOrX.y - this.y * 16, posOrX.z - this.z * 16);
17854
18244
  const index = _Chunk.chunkPosToBlockIndex(pos);
@@ -17856,10 +18246,10 @@ var Chunk = class _Chunk {
17856
18246
  }
17857
18247
  async setBlockAt(posOrX, yOrBlock, z, block) {
17858
18248
  if (typeof posOrX == "number") {
17859
- return this.setBlockAt(new import_three43.Vector3(posOrX, yOrBlock, z), block);
18249
+ return this.setBlockAt(new import_three44.Vector3(posOrX, yOrBlock, z), block);
17860
18250
  }
17861
18251
  if (isTripleArray(posOrX)) {
17862
- return this.setBlockAt(new import_three43.Vector3(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
18252
+ return this.setBlockAt(new import_three44.Vector3(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
17863
18253
  }
17864
18254
  const worldPos = posOrX;
17865
18255
  const pos = this.worldPosToChunkPos(worldPos);
@@ -17912,7 +18302,7 @@ var Chunk = class _Chunk {
17912
18302
  if (this.fluidCells[index]) this.meshDirty = true;
17913
18303
  this.fluidCells[index] = 0;
17914
18304
  this.renderedBlocks.delete(index);
17915
- const worldPos = new import_three43.Vector3(
18305
+ const worldPos = new import_three44.Vector3(
17916
18306
  this.x * 16 + index % 16,
17917
18307
  this.y * 16 + Math.floor(index / 256),
17918
18308
  this.z * 16 + Math.floor(index / 16) % 16
@@ -18037,7 +18427,7 @@ var Chunk = class _Chunk {
18037
18427
  this.z * 16 + Math.floor(index / 16) % 16
18038
18428
  ]
18039
18429
  });
18040
- object4.setPosition(new import_three43.Vector3(
18430
+ object4.setPosition(new import_three44.Vector3(
18041
18431
  this.x * 256 + index % 16 * 16,
18042
18432
  this.y * 256 + Math.floor(index / 256) * 16,
18043
18433
  this.z * 256 + Math.floor(index / 16) % 16 * 16
@@ -18188,7 +18578,7 @@ var Chunk = class _Chunk {
18188
18578
  /** Removes stored blocks and render objects. Set `notify` to false to skip the owning world's update. */
18189
18579
  async clear(notify = true) {
18190
18580
  const positions = notify && this.onBlocksChanged ? [...this.renderedBlocks.keys()].map((index) => this.chunkPosToWorldPos(
18191
- new import_three43.Vector3(index % 16, Math.floor(index / 256), Math.floor(index / 16) % 16)
18581
+ new import_three44.Vector3(index % 16, Math.floor(index / 256), Math.floor(index / 16) % 16)
18192
18582
  )) : [];
18193
18583
  for (const info of this.renderedBlocks.values()) info.object?.removeFromScene();
18194
18584
  this.sectionBlocks.clear();
@@ -18216,14 +18606,14 @@ var Chunk = class _Chunk {
18216
18606
  return pos.y * 16 * 16 + pos.z * 16 + pos.x;
18217
18607
  }
18218
18608
  worldPosToChunkPos(pos) {
18219
- return new import_three43.Vector3(
18609
+ return new import_three44.Vector3(
18220
18610
  pos.x - this.x * 16,
18221
18611
  pos.y - this.y * 16,
18222
18612
  pos.z - this.z * 16
18223
18613
  );
18224
18614
  }
18225
18615
  chunkPosToWorldPos(pos) {
18226
- return new import_three43.Vector3(
18616
+ return new import_three44.Vector3(
18227
18617
  this.x * 16 + pos.x,
18228
18618
  this.y * 16 + pos.y,
18229
18619
  this.z * 16 + pos.z