Mouse, touch, and keyboard controller for a
View's
Camera. Three navigation modes
(orbit, first-person, plan-view), context-aware movement scaling,
pivot-about-pick, and per-event mouse / touch hooks.
The viewController module adds interactive camera navigation to a
View. One ViewController per View, configured with a
navigation mode and optional pick / key-map overrides.
Three navigation modes — OrbitNavigationMode (orbit
around a focus point), FirstPersonNavigationMode (free WASD
walking), PlanViewNavigationMode (top-down pan + zoom).
Switch live via viewController.navMode = ....
Pointer-following — dynamic camera target tracking that
responds to where the cursor is pointing.
Context-aware movement scaling — speed bigger in open
spaces, smaller in confined spaces; computed from the
under-cursor depth so the user doesn't need to tune speed
manually.
Pivot-about-pick — orbit around the picked world point
instead of a global origin, so rotating around a detail keeps
the detail centred.
Axis-aligned-view shortcuts — KEY_NUM_1 … KEY_NUM_6
snap to top / bottom / front / back / left / right views.
Per-event hooks — onHover, onPicked,
onDoublePicked, onRightClick, with onHoverEnter /
onHoverOut for transition-only handlers.
Configurable key map — QWERTYLayout (default) and
AZERTYLayout ship; arbitrary remaps via the keyMap
parameter on construction or live mutation afterwards.
Vertical constraint — constrainVertical: true clamps
pitch to [-90°, 90°] so the camera never flips upside-down.
Installation
Install the package using npm:
npminstall@xeokit/sdk
Usage
This example demonstrates how to set up a Viewer with a WebGLRenderer,
a Scene to manage geometry and materials, and an interactive camera controlled via ViewController.
xeokit View Controller
Mouse, touch, and keyboard controller for a View's Camera. Three navigation modes (orbit, first-person, plan-view), context-aware movement scaling, pivot-about-pick, and per-event mouse / touch hooks.
The
viewControllermodule adds interactive camera navigation to a View. One ViewController per View, configured with a navigation mode and optional pick / key-map overrides.Shape
Features
OrbitNavigationMode(orbit around a focus point),FirstPersonNavigationMode(free WASD walking),PlanViewNavigationMode(top-down pan + zoom). Switch live viaviewController.navMode = ....KEY_NUM_1…KEY_NUM_6snap to top / bottom / front / back / left / right views.onHover,onPicked,onDoublePicked,onRightClick, withonHoverEnter/onHoverOutfor transition-only handlers.QWERTYLayout(default) andAZERTYLayoutship; arbitrary remaps via thekeyMapparameter on construction or live mutation afterwards.constrainVertical: trueclamps pitch to[-90°, 90°]so the camera never flips upside-down.Installation
Install the package using npm:
Usage
This example demonstrates how to set up a Viewer with a WebGLRenderer, a Scene to manage geometry and materials, and an interactive camera controlled via ViewController.
Navigation Modes
ViewController provides three main navigation modes:
Orbit Mode
To activate orbit mode:
+and-.SHIFTwhile left-dragging.First-Person Mode
Enables camera movement similar to a first-person video game.
WandS(QWERTY) orZandS(AZERTY).AandD.Plan-View Mode
Keeps the camera locked to a top-down perspective.
W,A,S,D).ViewController Events
ViewControllertriggers events when interacting with ViewObjects using a mouse or touch input.Usage
To subscribe to an event:
To unsubscribe:
Event List
Hover Events
"hover"– Fired when the pointer moves over an entity."hoverOff"– Fired when the pointer moves over empty space."hoverEnter"– Fired when the pointer enters an entity."hoverOut"– Fired when the pointer leaves an entity.Click & Tap Events
"picked"– Fired on left-click/tap on an entity."pickedSurface"– Fired on left-click/tap on an entity's surface."pickedNothing"– Fired on left-click/tap on empty space.Double Click & Tap Events
"doublePicked"– Fired on double-click/tap on an entity."doublePickedSurface"– Fired on double-click/tap on an entity's surface."doublePickedNothing"– Fired on double-click/tap on empty space.Right Click Event
"rightClick"– Fired on right-click anywhere on the canvas.Custom Keyboard Mappings
The default key mappings can be overridden to fit specific layouts.
Alternatively, define custom mappings: