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

Orbit WASDEQ Controls #3875

Merged
merged 39 commits into from
Jan 30, 2025
Merged
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
d012877
Updated the fly controller to use the z up basis
AlexandruPopovici Nov 21, 2024
e3a20bd
Fixed very important compiler error
AlexandruPopovici Nov 21, 2024
83063b0
Removed the annoying delay when first holding down WASD keys before m…
AlexandruPopovici Nov 21, 2024
59ae40d
Updated LegacyViewer to use the hybrid camera controls
AlexandruPopovici Nov 22, 2024
0b0cb8b
Merge branch 'main' into alex/advanced-camera-controls
AlexandruPopovici Nov 22, 2024
d1da6a7
Added big baker
AlexandruPopovici Nov 26, 2024
86d9d92
Merge branch 'main' into alex/advanced-camera-controls
AlexandruPopovici Nov 27, 2024
0ad6c44
Trying to figure out the essence of this
AlexandruPopovici Dec 11, 2024
d3d6d52
Partly works
AlexandruPopovici Dec 11, 2024
dabeefc
Pivotal coordinates now work
AlexandruPopovici Dec 18, 2024
fbab733
Smoothened out the math abit
AlexandruPopovici Dec 19, 2024
339cc79
Merged and removed debug spheres
AlexandruPopovici Dec 19, 2024
8fab92e
Fixed sandbox error
AlexandruPopovici Dec 19, 2024
28fff50
Enabled the pivot sphere
AlexandruPopovici Dec 20, 2024
688bb53
chore(viewer-lib): Merged with main
AlexandruPopovici Jan 9, 2025
8d6c043
Merge branch 'main' into alex/advanced-camera-controls
AlexandruPopovici Jan 9, 2025
3ded61f
feat(viewer-lib): Fixed some issues with orbiting around cursor
AlexandruPopovici Jan 9, 2025
a4dbf46
feat(viewer-lib): Updates to WEB-2313, orbiting around mouse cursor
AlexandruPopovici Jan 10, 2025
fc1cf44
feat(viewer-lib): Mouse orbiting now takes clipping planes into consi…
AlexandruPopovici Jan 10, 2025
8720874
chore(viewer-lib): Fixed sandbox build error
AlexandruPopovici Jan 10, 2025
b40e99e
fix(viewer-lib): Handled WEB-2449 and WEB-2450
AlexandruPopovici Jan 13, 2025
5de1bc5
fix(viewer-lib): Fixed the issue with focusing and other camera anima…
AlexandruPopovici Jan 13, 2025
cf0c1e8
Merge branch 'main' into alex/advanced-camera-controls
AlexandruPopovici Jan 14, 2025
572ae38
feat(viewer-lib): Updates on mouse orbiting:
AlexandruPopovici Jan 14, 2025
decb3d5
Merge branch 'main' into alex/advanced-camera-controls
AlexandruPopovici Jan 14, 2025
9be1585
feat(viewer-lib): Update for WASD aka fly mode:
AlexandruPopovici Jan 14, 2025
c6d71a8
fix(viewer-lib): Fixed sandbox compile error
AlexandruPopovici Jan 14, 2025
74b6ddc
feat(viewer-lib): Added the hybrid fly orbit controller to the legacy…
AlexandruPopovici Jan 14, 2025
886ef10
Merge branch 'main' into alex/advanced-camera-controls-wasd
AlexandruPopovici Jan 20, 2025
dd4556a
feat(viewer-lib): Added a slower movement speed to WASD navigation wh…
AlexandruPopovici Jan 20, 2025
ebf2322
fix(viewer-lib): Fixed the issue where opening the context menu while…
AlexandruPopovici Jan 21, 2025
59b5e15
Feat(viewer-lib): Update to WASD controls:
AlexandruPopovici Jan 22, 2025
e74227e
chore(viewer-lib): Tidied up a bit
AlexandruPopovici Jan 22, 2025
593768c
fix(viewer-lib): Fixed an ugly bug where the camera distance calculat…
AlexandruPopovici Jan 22, 2025
a6ec6e8
Merge branch 'main' into alex/advanced-camera-controls-wasd
AlexandruPopovici Jan 23, 2025
ead9c1f
chore(viewer-lib): Swapped E to up and Q to down
AlexandruPopovici Jan 23, 2025
a2c04d8
Re-nabled cursor orbiting
AlexandruPopovici Jan 29, 2025
be0635e
Merge branch 'main' into alex/advanced-camera-controls-wasd
AlexandruPopovici Jan 29, 2025
c6e39b0
Merge branch 'main' into alex/advanced-camera-controls-wasd
AlexandruPopovici Jan 29, 2025
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
Prev Previous commit
Next Next commit
chore(viewer-lib): Tidied up a bit
AlexandruPopovici committed Jan 22, 2025
commit e74227ef178ffac835ffc440a984120fc30a5eb0
37 changes: 16 additions & 21 deletions packages/viewer/src/modules/extensions/CameraController.ts
Original file line number Diff line number Diff line change
@@ -23,9 +23,6 @@ import {
SmoothOrbitControls
} from './controls/SmoothOrbitControls.js'

// const UP: Vector3 = new Vector3(0, 1, 0)
// const quatBuff = new Quaternion()

export enum NearPlaneCalculation {
EMPIRIC,
ACCURATE
@@ -111,7 +108,8 @@ export class CameraController extends Extension implements SpeckleCamera {
protected _lastCameraChanged: boolean = false
protected _options: Required<CameraControllerOptions> = DefaultOrbitControlsOptions
protected _activeControls: SpeckleControls
protected _controlsList: SpeckleControls[] = []
protected _orbitControls: SmoothOrbitControls
protected _flyControls: FlyControls

get renderingCamera(): PerspectiveCamera | OrthographicCamera {
return this._renderingCamera
@@ -152,9 +150,8 @@ export class CameraController extends Extension implements SpeckleCamera {

public set options(value: CameraControllerOptions) {
Object.assign(this._options, value)
this._controlsList.forEach((controls: SpeckleControls) => {
controls.options = value
})
this._orbitControls.options = value
this._flyControls.options = value
}

public constructor(viewer: IViewer) {
@@ -183,31 +180,28 @@ export class CameraController extends Extension implements SpeckleCamera {
/** Perspective camera as default on startup */
this.renderingCamera = this.perspectiveCamera

const flyControls = new FlyControls(
this._flyControls = new FlyControls(
this._renderingCamera,
this.viewer.getContainer(),
this.viewer.World,
this._options
)
flyControls.enabled = false
flyControls.setDamperDecayTime(30)
flyControls.up = new Vector3(0, 0, 1)
this._flyControls.enabled = false
this._flyControls.setDamperDecayTime(30)
this._flyControls.up = new Vector3(0, 0, 1)

const orbitControls = new SmoothOrbitControls(
this._orbitControls = new SmoothOrbitControls(
this.perspectiveCamera,
this.viewer.getContainer(),
this.viewer.World,
this.viewer.getRenderer(),
this._options
)
orbitControls.enabled = true
this._orbitControls.enabled = true

this.viewer.getRenderer().speckleCamera = this

this._controlsList.push(orbitControls)
this._controlsList.push(flyControls)

this._activeControls = orbitControls
this._activeControls = this._orbitControls

this.default()
}
@@ -240,9 +234,9 @@ export class CameraController extends Extension implements SpeckleCamera {
let newControls: SpeckleControls | undefined = undefined

if (this._activeControls instanceof SmoothOrbitControls) {
newControls = this._controlsList[1]
newControls = this._flyControls
} else if (this._activeControls instanceof FlyControls) {
newControls = this._controlsList[0]
newControls = this._orbitControls
}

if (!newControls) throw new Error('Not controls found!')
@@ -427,8 +421,9 @@ export class CameraController extends Extension implements SpeckleCamera {
fallback?: number
): number | undefined {
const minDist = this.getClosestGeometryDistance(fallback)
;(this._controlsList[0] as SmoothOrbitControls).minDist = minDist
;(this._controlsList[1] as FlyControls).minDist = minDist
this._flyControls.minDist = minDist
this._orbitControls.minDist = minDist

if (minDist === Number.POSITIVE_INFINITY) {
return this.computeNearCameraPlaneEmpiric(targetVolume, offsetScale)
}
18 changes: 3 additions & 15 deletions packages/viewer/src/modules/extensions/HybridCameraController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { clamp } from 'three/src/math/MathUtils.js'
import { IViewer } from '../../IViewer.js'
import { CameraController } from './CameraController.js'
type MoveType = 'forward' | 'back' | 'left' | 'right' | 'up' | 'down'
@@ -34,7 +33,6 @@ export class HybridCameraController extends CameraController {
}

protected onKeyDown(event: KeyboardEvent) {
let moveSpeed = this.options.moveSpeed ? this.options.moveSpeed : 1
switch (event.code) {
case 'ArrowUp':
case 'KeyW':
@@ -65,19 +63,9 @@ export class HybridCameraController extends CameraController {
case 'KeyE':
this.keyMap.down = true
break
case 'KeyF':
moveSpeed += 0.25
moveSpeed = clamp(moveSpeed, 0.1, 5)
this.options = { moveSpeed }
break
case 'KeyC':
moveSpeed -= 0.25
moveSpeed = clamp(moveSpeed, 0.1, 5)
this.options = { moveSpeed }
break
}
if (
!this._controlsList[1].enabled &&
!this._flyControls.enabled &&
Object.values(this.keyMap).some((v) => v === true)
)
this.toggleControls()
@@ -116,7 +104,7 @@ export class HybridCameraController extends CameraController {
break
}
if (
this._controlsList[1].enabled &&
this._flyControls.enabled &&
Object.values(this.keyMap).every((v) => v === false)
)
this.toggleControls()
@@ -134,7 +122,7 @@ export class HybridCameraController extends CameraController {
this.keyMap.left = false
this.keyMap.right = false
if (
this._controlsList[1].enabled &&
this._flyControls.enabled &&
Object.values(this.keyMap).every((v) => v === false)
)
this.toggleControls()
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ type MoveType = 'forward' | 'back' | 'left' | 'right' | 'up' | 'down'
const walkingSpeed = 1.42 // m/s
const closeRelativeFactor = 0.03
const farRelativeFactor = 0.2
const relativeTargetDistance = 0.01
const relativeMinTargetDistance = 0.01

export interface FlyControlsOptions {
[name: string]: unknown
@@ -250,7 +250,7 @@ class FlyControls extends SpeckleControls {
.normalize()
target.addScaledVector(
forward,
-this.world.getRelativeOffset(relativeTargetDistance)
-this.world.getRelativeOffset(relativeMinTargetDistance)
)
return target
}
@@ -279,7 +279,7 @@ class FlyControls extends SpeckleControls {
.normalize()
target.addScaledVector(
forward,
-this.world.getRelativeOffset(relativeTargetDistance)
-this.world.getRelativeOffset(relativeMinTargetDistance)
)
return target
}
Original file line number Diff line number Diff line change
@@ -114,6 +114,8 @@ export enum PointerChangeEvent {

const closeRelativeFactorPan = 0.06
const farRelativeFactorPan = 0.4
const relativeMinTargetDistance = 0.01
const relativeMaxTargetDistance = 0.2

/**
* SmoothControls is a Three.js helper for adding delightful pointer and
@@ -513,8 +515,8 @@ export class SmoothOrbitControls extends SpeckleControls {
)
worldSizeOffset = clamp(
worldSizeOffset,
this.world.getRelativeOffset(0.01),
this.world.getRelativeOffset(0.2)
this.world.getRelativeOffset(relativeMinTargetDistance),
this.world.getRelativeOffset(relativeMaxTargetDistance)
)
const zoomAmount = worldSizeOffset * Math.sign(deltaZoom) //deltaZoom * this.spherical.radius * Math.tan(fov * 0.5)

@@ -821,7 +823,6 @@ export class SmoothOrbitControls extends SpeckleControls {
? this.pivotPoint
: new Vector3().copy(this.origin).applyMatrix4(this._basisTransform)
)
this.orbitSphere.visible = true

return (
lastCameraPos.sub(this._targetCamera.position).length() > MOVEMENT_EPSILON ||
10 changes: 10 additions & 0 deletions packages/viewer/src/modules/extensions/controls/SpeckleControls.ts
Original file line number Diff line number Diff line change
@@ -3,13 +3,23 @@ import EventEmitter from '../../EventEmitter.js'

export abstract class SpeckleControls extends EventEmitter {
protected _up: Vector3 = new Vector3(0, 1, 0)
protected _minDist: number = 0

public get up() {
return this._up
}
public set up(value: Vector3) {
this._up.copy(value)
}

public get minDist() {
return this._minDist
}

public set minDist(value: number) {
this._minDist = value
}

abstract get options(): Partial<Record<string, unknown>>
abstract set options(value: Partial<Record<string, unknown>>)