Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Make options for FlexibleControls available outside Reveal + Add speed option #4618

Merged
merged 4 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
nilscognite marked this conversation as resolved.
Show resolved Hide resolved
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
Loading