The CameraControl class provides an interactive way to navigate a
View'sCamera through various input methods, including mouse, touch, and keyboard.
This controller supports multiple navigation modes: orbit, first-person, and plan-view. These modes allow
users to control the camera movement dynamically and intuitively, catering to different use cases and preferences.
Features include:
Pointer-following for dynamically adjusting the camera's target.
Context-aware movement scaling to move quickly in open spaces and slowly in confined spaces.
Pivot-about-point to orbit picked surface positions.
Axis-aligned views for precise positioning.
Configurable behaviors like vertical movement constraints and double-click object focusing.
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 CameraControl.
// Create a View for rendering constview = viewer.createView({ id:"myView", elementId:"myCanvas" });
// Configure the camera's initial position and orientation view.camera.eye = [1841982.93, 10.03, -5173286.74]; view.camera.look = [1842009.49, 9.68, -5173295.85]; view.camera.up = [0.0, 1.0, 0.0];
// Attach CameraControl for interactive navigation newCameraControl(view, {});
// Load a CityJSON model into the Scene constsceneModel = scene.createModel({ id:"myModel" }); fetch("model.json").then(response=>response.json()).then(fileData=> { CityJSONLoader({ fileData, sceneModel }).then(() => { sceneModel.build(); }); });
Navigation Modes
CameraControl provides three main navigation modes:
Orbit Mode: Enables the camera to orbit around a target point.
First-Person Mode: Allows free movement as if walking through the scene.
Plan-View Mode: Maintains a top-down perspective while allowing panning and zooming.
Orbit Mode
To activate orbit mode:
cameraControl.navMode = OrbitNavigationMode;
Orbit: Left-drag the mouse, tap-drag on a touchpad, or use arrow keys.
Dolly (Zoom): Scroll the mouse wheel, pinch on a touchpad, or press + and -.
Pan: Right-drag the mouse or use SHIFT while left-dragging.
First-Person Mode
Enables camera movement similar to a first-person video game.
Mouse and touch controller for a Viewer's Camera
Overview
The CameraControl class provides an interactive way to navigate a View's Camera through various input methods, including mouse, touch, and keyboard.
This controller supports multiple navigation modes: orbit, first-person, and plan-view. These modes allow users to control the camera movement dynamically and intuitively, catering to different use cases and preferences.
Features include:
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 CameraControl.
Navigation Modes
CameraControl 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).CameraControl Events
CameraControltriggers 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: