Skip to content

Commit

Permalink
feat: Make options for FlexibleControls available outside Reveal + Ad…
Browse files Browse the repository at this point in the history
…d speed option (#4618)

* Make options available

* Update reveal.api.md

* Update FlexibleControls.ts
  • Loading branch information
nilscognite authored Jun 19, 2024
1 parent 41c1152 commit 2c9fa9d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ export class FlexibleCameraManager extends PointerEvents implements IFlexibleCam
this.updateControlsSensitivity(modelBoundingBox);
}

public get options(): FlexibleControlsOptions {
return this._controls.options;
}

//================================================
// OVERRIDES of PointerEvents
//================================================
Expand Down Expand Up @@ -293,10 +297,6 @@ export class FlexibleCameraManager extends PointerEvents implements IFlexibleCam
// INSTANCE METHODS: Setters and getters
//================================================

public get options(): FlexibleControlsOptions {
return this._controls.options;
}

public get controls(): FlexibleControls {
return this._controls;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -975,9 +975,9 @@ export class FlexibleControls {
if (!this.isStationary) {
this.setControlsType(FlexibleControlsType.FirstPerson);
}
const speedFactor = this._keyboard.isShiftPressed() ? this._options.keyboardFastMoveFactor : 1;
const speedXY = timeScale * speedFactor * this._options.keyboardPanSpeed;
const speedZ = timeScale * speedFactor * this._options.keyboardDollySpeed;
const keyboardSpeed = this._options.getKeyboardSpeed(this._keyboard.isShiftPressed());
const speedXY = timeScale * keyboardSpeed * this._options.keyboardPanSpeed;
const speedZ = timeScale * keyboardSpeed * this._options.keyboardDollySpeed;

this.pan(speedXY * deltaX, speedXY * deltaY, speedZ * deltaZ, true);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ export class FlexibleControlsOptions {
// INSTANCE FIELDS
//================================================

// Main behaivor
// Main behavior
public controlsType = FlexibleControlsType.Orbit;

// Mouse click, double click and wheel behaivor
// Mouse click, double click and wheel behavior
public mouseWheelAction = FlexibleWheelZoomType.Auto;
public mouseClickType = FlexibleMouseActionType.SetTarget;
public mouseDoubleClickType = FlexibleMouseActionType.SetTargetAndCameraPosition;
Expand All @@ -41,7 +41,7 @@ export class FlexibleControlsOptions {
public minAzimuthAngle = -Infinity;
public maxAzimuthAngle = Infinity;

// Dampning
// Damping
public enableDamping = true;
public dampingFactor = 0.25;

Expand Down Expand Up @@ -72,6 +72,7 @@ export class FlexibleControlsOptions {
public mouseDollySpeed = 100;

// Keyboard speed for dolly and pan
public keyboardSpeed = 1;
public keyboardPanSpeed = 100;
public keyboardDollySpeed = 200;
public keyboardFastMoveFactor = 5;
Expand Down Expand Up @@ -117,6 +118,13 @@ export class FlexibleControlsOptions {
}
}

public getKeyboardSpeed(shift: boolean): number {
if (!shift) {
return this.keyboardSpeed;
}
return this.keyboardFastMoveFactor * this.keyboardSpeed;
}

//================================================
// INSTANCE METHODS: Getters
//================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

import { CameraManager } from '../CameraManager';
import { FlexibleControlsOptions } from './FlexibleControlsOptions';
import { FlexibleControlsType } from './FlexibleControlsType';
import { Vector3 } from 'three';

Expand All @@ -12,23 +13,29 @@ import { Vector3 } from 'three';
export type FlexibleControlsTypeChangeDelegate = (controlsType: FlexibleControlsType) => void;

/**
* Flexible implementation of {@link CameraManager}. The user can switch between Orbit, FirstPersion or OrbitInCenter
* Flexible implementation of {@link CameraManager}. The user can switch between Orbit, FirstPerson or OrbitInCenter
* Supports automatic update of camera near and far planes and animated change of camera position and target.
* It provides additional functionality for controlling camera behavior and rotation.
* @beta
*/

export interface IFlexibleCameraManager extends CameraManager {
/**
* Get curent FlexibleControlsType type
* Get current FlexibleControlsType type
*/
get controlsType(): FlexibleControlsType;

/**
* Set curent FlexibleControlsType type
* Set current FlexibleControlsType type
*/
set controlsType(value: FlexibleControlsType);

/**
* Set the options for the camera manager
* @beta
*/
get options(): FlexibleControlsOptions;

/**
* Rotates the camera to look in the specified direction.
* Supports automatic update of camera near and far planes and animated change of camera position and target.
Expand Down
5 changes: 5 additions & 0 deletions viewer/reveal.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,8 @@ export class FlexibleControlsOptions {
// (undocumented)
enableKeyboardNavigation: boolean;
// (undocumented)
getKeyboardSpeed(shift: boolean): number;
// (undocumented)
getLegalAzimuthAngle(azimuthAngle: number): number;
// (undocumented)
getLegalFov(fov: number): number;
Expand All @@ -942,6 +944,8 @@ export class FlexibleControlsOptions {
// (undocumented)
keyboardRotationSpeedPolar: number;
// (undocumented)
keyboardSpeed: number;
// (undocumented)
maxAzimuthAngle: number;
// (undocumented)
maximumFov: number;
Expand Down Expand Up @@ -1126,6 +1130,7 @@ export interface IFlexibleCameraManager extends CameraManager {
onPointerDrag(event: PointerEvent, leftButton: boolean): Promise<void>;
onPointerUp(event: PointerEvent, leftButton: boolean): Promise<void>;
onWheel(event: WheelEvent, delta: number): Promise<void>;
get options(): FlexibleControlsOptions;
removeControlsTypeChangeListener(callback: FlexibleControlsTypeChangeDelegate): void;
rotateCameraTo(direction: Vector3, animationDuration: number): void;
}
Expand Down

0 comments on commit 2c9fa9d

Please sign in to comment.