minerender 2.1.0-alpha.117 → 2.1.0-alpha.118

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.
@@ -2923,11 +2923,12 @@ interface FlyControlsEventMap {
2923
2923
  type FlyAction = "forward" | "back" | "left" | "right" | "up" | "down" | "sprint";
2924
2924
  /**
2925
2925
  * Creative-flight camera controls: WASD moves horizontally along the view direction, space and shift
2926
- * move up and down, control sprints, and the mouse turns the camera (pointer lock, or drag).
2926
+ * move up and down, R sprints, and the mouse turns the camera (pointer lock, or drag).
2927
2927
  *
2928
2928
  * Call {@link FlyControls.update} with the elapsed seconds once per frame; the `change` event marks the
2929
2929
  * renderer dirty while keys are held. Speeds use scene units (16 per block). The element becomes focusable
2930
- * and keys apply while it has focus or the pointer is locked. The wheel changes the speed, as in vanilla
2930
+ * and keys apply while it has focus or the pointer is locked. A key pressed with Control, Alt, or Command
2931
+ * stays a browser shortcut unless that modifier is bound. The wheel changes the speed, as in vanilla
2931
2932
  * spectator mode. Touch input uses the left half of the element as a joystick and the right half for looking.
2932
2933
  */
2933
2934
  declare class FlyControls extends Controls<FlyControlsEventMap, Camera> {
@@ -2959,9 +2960,13 @@ declare class FlyControls extends Controls<FlyControlsEventMap, Camera> {
2959
2960
  private _position0;
2960
2961
  private _quaternion0;
2961
2962
  private _dragPointer?;
2963
+ private _dragX;
2964
+ private _dragY;
2962
2965
  private _dragMoved;
2966
+ private _dragTravel;
2963
2967
  private _joystick?;
2964
2968
  private _locked;
2969
+ private _madeFocusable;
2965
2970
  private _lastTime?;
2966
2971
  private readonly _onKeyDown;
2967
2972
  private readonly _onKeyUp;
@@ -2999,12 +3004,15 @@ declare class FlyControls extends Controls<FlyControlsEventMap, Camera> {
2999
3004
  /**
3000
3005
  * Advances movement by `delta` seconds (measured since the previous call when omitted)
3001
3006
  * and dispatches `change` when the camera moved.
3007
+ * A step longer than 0.1 s is applied as 0.1 s.
3002
3008
  */
3003
3009
  update(delta?: number): void;
3004
3010
  private move;
3005
3011
  private notifyChange;
3006
3012
  private releaseKeys;
3007
3013
  private handleKey;
3014
+ /** A key pressed with Control, Alt, or Command stays a browser shortcut unless that modifier is bound to an action. */
3015
+ private isBrowserShortcut;
3008
3016
  private actionFor;
3009
3017
  private handlePointerDown;
3010
3018
  private onJoystickSide;
@@ -3060,6 +3068,7 @@ declare class Renderer implements Disposable {
3060
3068
  /**
3061
3069
  * Replaces renderer-owned controls with the selected mode, keeping the camera where it is.
3062
3070
  * Switching to orbit controls targets the point the camera looks at, at the previous orbit distance.
3071
+ * The previous controls object is disposed, so its listeners and settings do not carry over.
3063
3072
  * Returns the new controls, or undefined when controls were disabled at construction or after disposal.
3064
3073
  */
3065
3074
  setControlsMode(mode: ControlsMode): Maybe<RendererControls>;
@@ -2923,11 +2923,12 @@ interface FlyControlsEventMap {
2923
2923
  type FlyAction = "forward" | "back" | "left" | "right" | "up" | "down" | "sprint";
2924
2924
  /**
2925
2925
  * Creative-flight camera controls: WASD moves horizontally along the view direction, space and shift
2926
- * move up and down, control sprints, and the mouse turns the camera (pointer lock, or drag).
2926
+ * move up and down, R sprints, and the mouse turns the camera (pointer lock, or drag).
2927
2927
  *
2928
2928
  * Call {@link FlyControls.update} with the elapsed seconds once per frame; the `change` event marks the
2929
2929
  * renderer dirty while keys are held. Speeds use scene units (16 per block). The element becomes focusable
2930
- * and keys apply while it has focus or the pointer is locked. The wheel changes the speed, as in vanilla
2930
+ * and keys apply while it has focus or the pointer is locked. A key pressed with Control, Alt, or Command
2931
+ * stays a browser shortcut unless that modifier is bound. The wheel changes the speed, as in vanilla
2931
2932
  * spectator mode. Touch input uses the left half of the element as a joystick and the right half for looking.
2932
2933
  */
2933
2934
  declare class FlyControls extends Controls<FlyControlsEventMap, Camera> {
@@ -2959,9 +2960,13 @@ declare class FlyControls extends Controls<FlyControlsEventMap, Camera> {
2959
2960
  private _position0;
2960
2961
  private _quaternion0;
2961
2962
  private _dragPointer?;
2963
+ private _dragX;
2964
+ private _dragY;
2962
2965
  private _dragMoved;
2966
+ private _dragTravel;
2963
2967
  private _joystick?;
2964
2968
  private _locked;
2969
+ private _madeFocusable;
2965
2970
  private _lastTime?;
2966
2971
  private readonly _onKeyDown;
2967
2972
  private readonly _onKeyUp;
@@ -2999,12 +3004,15 @@ declare class FlyControls extends Controls<FlyControlsEventMap, Camera> {
2999
3004
  /**
3000
3005
  * Advances movement by `delta` seconds (measured since the previous call when omitted)
3001
3006
  * and dispatches `change` when the camera moved.
3007
+ * A step longer than 0.1 s is applied as 0.1 s.
3002
3008
  */
3003
3009
  update(delta?: number): void;
3004
3010
  private move;
3005
3011
  private notifyChange;
3006
3012
  private releaseKeys;
3007
3013
  private handleKey;
3014
+ /** A key pressed with Control, Alt, or Command stays a browser shortcut unless that modifier is bound to an action. */
3015
+ private isBrowserShortcut;
3008
3016
  private actionFor;
3009
3017
  private handlePointerDown;
3010
3018
  private onJoystickSide;
@@ -3060,6 +3068,7 @@ declare class Renderer implements Disposable {
3060
3068
  /**
3061
3069
  * Replaces renderer-owned controls with the selected mode, keeping the camera where it is.
3062
3070
  * Switching to orbit controls targets the point the camera looks at, at the previous orbit distance.
3071
+ * The previous controls object is disposed, so its listeners and settings do not carry over.
3063
3072
  * Returns the new controls, or undefined when controls were disabled at construction or after disposal.
3064
3073
  */
3065
3074
  setControlsMode(mode: ControlsMode): Maybe<RendererControls>;
@@ -13387,6 +13387,8 @@ var import_three35 = require("three");
13387
13387
  var VANILLA_FLY_SPEED = 10.89;
13388
13388
  var PITCH_LIMIT = Math.PI / 2;
13389
13389
  var MOVE_EPSILON = 1e-6;
13390
+ var MAX_STEP_SECONDS = 0.1;
13391
+ var CLICK_SLOP_PIXELS = 4;
13390
13392
  var _euler = new import_three35.Euler(0, 0, 0, "YXZ");
13391
13393
  var _forward = new import_three35.Vector3();
13392
13394
  var _right = new import_three35.Vector3();
@@ -13421,7 +13423,8 @@ var FlyControls = class extends import_three35.Controls {
13421
13423
  right: ["KeyD", "ArrowRight"],
13422
13424
  up: ["Space"],
13423
13425
  down: ["ShiftLeft", "ShiftRight"],
13424
- sprint: ["ControlLeft", "ControlRight"]
13426
+ // Not Control: Ctrl+W closes the browser tab on Windows and Linux, and a page cannot block it.
13427
+ sprint: ["KeyR"]
13425
13428
  };
13426
13429
  this._pressed = /* @__PURE__ */ new Set();
13427
13430
  this._velocity = new import_three35.Vector3();
@@ -13429,8 +13432,12 @@ var FlyControls = class extends import_three35.Controls {
13429
13432
  this._lastQuaternion = new import_three35.Quaternion();
13430
13433
  this._position0 = new import_three35.Vector3();
13431
13434
  this._quaternion0 = new import_three35.Quaternion();
13435
+ this._dragX = 0;
13436
+ this._dragY = 0;
13432
13437
  this._dragMoved = false;
13438
+ this._dragTravel = 0;
13433
13439
  this._locked = false;
13440
+ this._madeFocusable = false;
13434
13441
  this._onKeyDown = (event) => this.handleKey(event, true);
13435
13442
  this._onKeyUp = (event) => this.handleKey(event, false);
13436
13443
  this._onPointerDown = (event) => this.handlePointerDown(event);
@@ -13460,7 +13467,10 @@ var FlyControls = class extends import_three35.Controls {
13460
13467
  element.addEventListener("wheel", this._onWheel, { passive: false });
13461
13468
  element.addEventListener("blur", this._onBlur);
13462
13469
  element.style.touchAction = "none";
13463
- if (element.tabIndex < 0) element.tabIndex = 0;
13470
+ if (element.tabIndex < 0) {
13471
+ element.tabIndex = 0;
13472
+ this._madeFocusable = true;
13473
+ }
13464
13474
  }
13465
13475
  disconnect() {
13466
13476
  const element = this.domElement;
@@ -13478,6 +13488,10 @@ var FlyControls = class extends import_three35.Controls {
13478
13488
  element.removeEventListener("wheel", this._onWheel);
13479
13489
  element.removeEventListener("blur", this._onBlur);
13480
13490
  element.style.touchAction = "auto";
13491
+ if (this._madeFocusable) {
13492
+ element.removeAttribute("tabindex");
13493
+ this._madeFocusable = false;
13494
+ }
13481
13495
  this.unlock();
13482
13496
  this._locked = false;
13483
13497
  this.releaseKeys();
@@ -13548,6 +13562,7 @@ var FlyControls = class extends import_three35.Controls {
13548
13562
  /**
13549
13563
  * Advances movement by `delta` seconds (measured since the previous call when omitted)
13550
13564
  * and dispatches `change` when the camera moved.
13565
+ * A step longer than 0.1 s is applied as 0.1 s.
13551
13566
  */
13552
13567
  update(delta) {
13553
13568
  if (delta === void 0) {
@@ -13559,7 +13574,7 @@ var FlyControls = class extends import_three35.Controls {
13559
13574
  this._velocity.set(0, 0, 0);
13560
13575
  return;
13561
13576
  }
13562
- if (delta > 0) this.move(delta);
13577
+ if (delta > 0) this.move(Math.min(delta, MAX_STEP_SECONDS));
13563
13578
  this.notifyChange();
13564
13579
  }
13565
13580
  move(delta) {
@@ -13606,15 +13621,21 @@ var FlyControls = class extends import_three35.Controls {
13606
13621
  this._pressed.clear();
13607
13622
  }
13608
13623
  handleKey(event, down) {
13624
+ if (event.code === "MetaLeft" || event.code === "MetaRight") this.releaseKeys();
13609
13625
  const action = this.actionFor(event.code);
13610
13626
  if (!action) return;
13611
13627
  const ownsInput = this.enabled && (this._locked || event.target === this.domElement);
13612
- if (down && !ownsInput) return;
13628
+ if (down && (!ownsInput || this.isBrowserShortcut(event))) return;
13613
13629
  const pressed = this._pressed.has(action);
13614
13630
  if (down) this._pressed.add(action);
13615
13631
  else this._pressed.delete(action);
13616
13632
  if (ownsInput || this.enabled && pressed) event.preventDefault();
13617
13633
  }
13634
+ /** A key pressed with Control, Alt, or Command stays a browser shortcut unless that modifier is bound to an action. */
13635
+ isBrowserShortcut(event) {
13636
+ const bound = (modifier) => Object.values(this.keys).some((codes) => codes.some((code) => code.startsWith(modifier)));
13637
+ return event.ctrlKey && !bound("Control") || event.altKey && !bound("Alt") || event.metaKey && !bound("Meta");
13638
+ }
13618
13639
  actionFor(code) {
13619
13640
  for (const action in this.keys) {
13620
13641
  if (this.keys[action].includes(code)) return action;
@@ -13634,7 +13655,10 @@ var FlyControls = class extends import_three35.Controls {
13634
13655
  if (this._dragPointer !== void 0) return;
13635
13656
  if (event.pointerType === "mouse" && event.button !== 0 && event.button !== 2) return;
13636
13657
  this._dragPointer = event.pointerId;
13658
+ this._dragX = event.clientX;
13659
+ this._dragY = event.clientY;
13637
13660
  this._dragMoved = false;
13661
+ this._dragTravel = 0;
13638
13662
  element.setPointerCapture?.(event.pointerId);
13639
13663
  }
13640
13664
  onJoystickSide(event) {
@@ -13650,8 +13674,20 @@ var FlyControls = class extends import_three35.Controls {
13650
13674
  return;
13651
13675
  }
13652
13676
  if (!this._locked && event.pointerId !== this._dragPointer) return;
13653
- const dx = event.movementX ?? 0;
13654
- const dy = event.movementY ?? 0;
13677
+ let dx, dy;
13678
+ if (this._locked) {
13679
+ dx = event.movementX ?? 0;
13680
+ dy = event.movementY ?? 0;
13681
+ } else {
13682
+ dx = event.clientX - this._dragX;
13683
+ dy = event.clientY - this._dragY;
13684
+ this._dragX = event.clientX;
13685
+ this._dragY = event.clientY;
13686
+ if (!this._dragMoved) {
13687
+ this._dragTravel += Math.hypot(dx, dy);
13688
+ if (this._dragTravel <= CLICK_SLOP_PIXELS) return;
13689
+ }
13690
+ }
13655
13691
  if (!dx && !dy) return;
13656
13692
  this._dragMoved = true;
13657
13693
  this.turn(dx, dy);
@@ -15561,6 +15597,7 @@ var _Renderer = class _Renderer {
15561
15597
  /**
15562
15598
  * Replaces renderer-owned controls with the selected mode, keeping the camera where it is.
15563
15599
  * Switching to orbit controls targets the point the camera looks at, at the previous orbit distance.
15600
+ * The previous controls object is disposed, so its listeners and settings do not carry over.
15564
15601
  * Returns the new controls, or undefined when controls were disabled at construction or after disposal.
15565
15602
  */
15566
15603
  setControlsMode(mode) {