Skip to content

Commit

Permalink
New mouse movement damping
Browse files Browse the repository at this point in the history
  • Loading branch information
mistic100 committed Oct 12, 2024
1 parent 6e82414 commit ae23e17
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 161 deletions.
6 changes: 3 additions & 3 deletions docs/guide/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,10 @@ requestHeaders: (url) => ({

#### `moveInertia`

- type: `boolean`
- default: `true`
- type: `boolean | number`
- default: `0.8`

Enabled smooth animation after a manual move.
Applies damping to the camera movement, higher value mean stronger damping (`true` is default damping factor, `false` is not damping).

#### `withCredentials`

Expand Down
5 changes: 5 additions & 0 deletions examples/adapter-equirectangular.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
// mousewheelCtrlKey: true,
// moveSpeed: 2,
// zoomSpeed: 2,
// moveInertia: false,
keyboard: 'always',
navbar: [
'zoom',
Expand Down Expand Up @@ -129,6 +130,10 @@
},
});

viewer.addEventListener('click', ({ data }) => {
console.log('click', data);
});

window.viewer = viewer;
</script>
</body>
Expand Down
11 changes: 10 additions & 1 deletion packages/core/src/data/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const DEFAULTS: Required<ParsedViewerConfig> = {
sphereCorrection: null,
moveSpeed: 1,
zoomSpeed: 1,
moveInertia: true,
moveInertia: 0.8,
mousewheel: true,
mousemove: true,
mousewheelCtrlKey: false,
Expand Down Expand Up @@ -153,6 +153,15 @@ export const CONFIG_PARSERS: ConfigParsers<ViewerConfig, ParsedViewerConfig> = {
// maxFov between 1 and 179
return MathUtils.clamp(maxFov, 1, 179);
},
moveInertia: (moveInertia, { defValue }) => {
if (moveInertia === true) {
return defValue;
}
if (moveInertia === false) {
return 0;
}
return moveInertia;
},
lang: (lang) => {
return {
...DEFAULTS.lang,
Expand Down
5 changes: 0 additions & 5 deletions packages/core/src/data/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ export const TWOFINGERSOVERLAY_DELAY = 100;
*/
export const CTRLZOOM_TIMEOUT = 2000;

/**
* Duration of the mouse position history used to compute inertia
*/
export const INERTIA_WINDOW = 300;

/**
* Radius of the SphereGeometry, Half-length of the BoxGeometry
*/
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,8 @@ export type ViewerConfig = {
moveSpeed?: number;
/** @default 1 */
zoomSpeed?: number;
/** @default true */
moveInertia?: boolean;
/** @default 0.8 */
moveInertia?: boolean | number;
/** @default true */
mousewheel?: boolean;
/** @default true */
Expand Down Expand Up @@ -386,6 +386,7 @@ export type ParsedViewerConfig = Omit<
| 'plugins'
| 'defaultYaw'
| 'defaultPitch'
| 'moveInertia'
| 'fisheye'
| 'requestHeaders'
| 'navbar'
Expand All @@ -395,6 +396,7 @@ export type ParsedViewerConfig = Omit<
plugins?: Array<[PluginConstructor, any]>;
defaultYaw?: number;
defaultPitch?: number;
moveInertia?: number;
fisheye?: number;
requestHeaders?: (url: string) => Record<string, string>;
navbar?: Array<string | NavbarCustomButton>;
Expand Down
Loading

0 comments on commit ae23e17

Please sign in to comment.