ViewCube
Copying and pasting? We've got you covered! You can find the full source code of this tutorial here.
🧭 Navigating your 3D Scene with the ViewCube
Users navigating a 3D BIM scene lose track of orientation as they orbit and pan — without a reference indicator, recovering a specific view like front or top requires manual camera adjustments. The ViewCube is a compact 3D orientation indicator that stays in sync with the camera and lets users snap to predefined views by clicking its faces. This tutorial covers creating a basic 3D world with scene, camera, and renderer; placing the ViewCube inside the viewport element and linking it to the camera; keeping it synchronized by calling the orientation update on every camera control event; and handling a face click event to reposition the camera to a specific look-at target with animation. By the end, you'll have a viewport with a ViewCube that tracks camera orientation in real time and snaps the view on click.
🖖 Importing our Libraries
We'll need:
@thatopen/uifor UI initialization.@thatopen/componentsfor the 3D engine and scene management.- The local UI components package for extra UI features.
import * as BUI from "@thatopen/ui";
import * as OBC from "@thatopen/components";
import * as CUI from "../..";