ViewportGizmo
A 3D camera orientation controller that provides a visual interface for manipulating the camera's viewing angle. The widget displays the current camera orientation and allows users to adjust the view directly by clicking or dragging.
Constructor
constructor( camera: PerspectiveCamera | OrthographicCamera, renderer: WebGLRenderer, options?: GizmoOptions )
camera—PerspectiveCamera | OrthographicCameraThe camera to be controlled by the gizmo.
renderer—WebGLRendererThe renderer used to render the scene.
options— GizmoOptions (optional)Configuration options for the gizmo.
Events
start— Triggered when a view change interaction begins.Occurs when:
- Dragging starts
- Clicking an axis initiates a view transition
change— Triggered during view changes.Occurs when:
- Dragging updates the view
- View transition animations are in progress
- Any camera orientation updates happen
end— Triggered when a view change interaction ends.Occurs when:
- Dragging stops
- View transition animation completes
Properties
enabled—booleanSpecifies if the gizmo is active and responsive to user input.
camera—OrthographicCamera | PerspectiveCameraThe camera controlled by this gizmo.
target—Vector3The point around which the camera rotates.
placement—booleanSets and update the placement of the gizmo relative to its container.
animated—booleanSpecifies if view changes should be animated.
speed—numberControls animation speed, where higher values result in faster animations.
animating—boolean(readonly)Trueif the gizmo is currently animating view changes.
Methods
set—( options?: GizmoOptions ): ViewportGizmoRegenerates the gizmo with the new options.
WARNING
- Not recommended for use in real-time rendering or animation loops
- Provides a way to completely rebuild the gizmo with new options
- Can be computationally expensive, so use sparingly
render—(): ViewportGizmoRenders the gizmo within the viewport.
domUpdate—(): ViewportGizmoUpdates the gizmo's DOM properties based on position and size in the document.
cameraUpdate—(): ViewportGizmoUpdates the gizmo's orientation to match the current camera orientation.
update—( controls?: boolean ): ViewportGizmoPerforms a full update of the gizmo, including DOM and camera-related updates.
attachControls—( controls: OrbitControls ): voidLinks
OrbitControlswith the gizmo, managing interaction states and updates.detachControls—(): voidRemoves all event listeners and detaches controls if previously attached.
dispose—(): voidCleans up all resources, including geometries, materials, textures, and event listeners.
Interfaces
GizmoOptions
type GizmoOptions = {
container?: HTMLElement | string;
type?: "sphere" | "cube" | "rounded-cube";
size?: number;
placement?:
| "top-left"
| "top-center"
| "top-right"
| "center-left"
| "center-center"
| "center-right"
| "bottom-left"
| "bottom-center"
| "bottom-right";
offset?: {
left?: number;
top?: number;
right?: number;
bottom?: number;
};
animated?: boolean;
speed?: number;
resolution?: number;
lineWidth?: number;
id?: string;
className?: string;
font?: {
family?: string;
weight?: string | number;
};
background?: {
enabled?: boolean;
color?: ColorRepresentation;
opacity?: number;
hover?: {
color?: ColorRepresentation;
opacity?: number;
};
};
corners?: {
enabled?: boolean;
color?: ColorRepresentation;
opacity?: number;
scale?: number;
radius?: number;
smoothness?: number;
hover?: {
color?: ColorRepresentation;
opacity?: number;
scale?: number;
};
};
edges?: {
enabled?: boolean;
color?: ColorRepresentation;
opacity?: number;
scale?: number;
radius?: number;
smoothness?: number;
hover?: {
color?: ColorRepresentation;
opacity?: number;
scale?: number;
};
};
radius?: number;
smoothness?: number;
x?: GizmoAxisOptions;
y?: GizmoAxisOptions;
z?: GizmoAxisOptions;
nx?: GizmoAxisOptions;
ny?: GizmoAxisOptions;
nz?: GizmoAxisOptions;
right?: GizmoAxisOptions;
top?: GizmoAxisOptions;
front?: GizmoAxisOptions;
left?: GizmoAxisOptions;
bottom?: GizmoAxisOptions;
back?: GizmoAxisOptions;
};
type GizmoAxisOptions = {
enabled?: boolean;
label?: string;
opacity?: number;
scale?: number;
line?: boolean;
color?: ColorRepresentation;
labelColor?: ColorRepresentation;
border?: {
size: number;
color: ColorRepresentation;
};
hover?: {
color?: ColorRepresentation;
labelColor?: ColorRepresentation;
opacity?: number;
scale?: number;
border?: {
size: number;
color: ColorRepresentation;
};
};
};Defines comprehensive configuration options for the ViewportGizmo. Each option customizes the appearance or behavior of the gizmo in the viewport.
container—HTMLElement | stringSpecifies the parent container for the gizmo. Can be an HTML element or a CSS selector string.
type—"sphere" | "cube" | "rounded-cube"Determines the gizmo configuration type. Defaults to
"sphere".size—numberSets the size of the gizmo widget in pixels. Defaults to
128.placement—GizmoDomPlacementDetermines the position of the gizmo in the viewport. Valid values include:
"top-left""top-center""top-right""center-left""center-center""center-right""bottom-left""bottom-center""bottom-right"
offset—objectConfigures offset from container edges in pixels.
left—numberOffset from the left edge.
top—numberOffset from the top edge.
right—numberOffset from the right edge.
bottom—numberOffset from the bottom edge.
animated—booleanEnables or disables animations for view changes. Defaults to
true.speed—numberAdjusts the animation speed for view transitions. Defaults to
1.resolution—numberAdjusts the texture resolution. Defaults to
64for sphere,128for cube.lineWidth—numberSets the width of the axes lines in pixels.
id—stringSets the HTML
idattribute for the gizmo container element.className—stringSets the HTML
classattribute for the gizmo container element.font—objectConfiguration for the font used in axis labels.
family—string- Specifies the font family for the axis labels.
weight—string | number- Sets the font weight for axis labels.
radius—numberSets the axes edge radius. When using
rounded-cubetype, this will be the radius of the rounded edges and corners. Defaults to1forsphereand0.2forrounded-cube.background—objectConfigures the background sphere/cube.
enabled—booleanEnables or disables the background.
color—ColorRepresentationSets the background color in normal state.
opacity—numberSets the background opacity in normal state.
hover—objectcolor—ColorRepresentationSets the background color when hovered.
opacity—numberSets the background opacity when hovered.
corners—objectConfigures corner indicators.
enabled—booleanEnables or disables corner indicators.
color—ColorRepresentationSets the base color of corner indicators.opacity—numberSets the opacity of corner indicators.scale—numberSets the scale multiplier for corner indicators.radius—numberSets the radius of corner indicators.smoothness—numberControls the smoothness of corner indicators.hover—objectcolor—ColorRepresentationSets the color of corner indicators when hovered.
opacity—numberSets the opacity of corner indicators when hovered.
scale—numberSets the scale of corner indicators when hovered.
edges—objectConfigures edge indicators.
enabled—boolean- Enables or disables edge indicators.
color—ColorRepresentation- Sets the base color of edge indicators.
opacity—number- Sets the opacity of edge indicators.
scale—number- Sets the scale multiplier for edge indicators.
radius—number- Sets the radius of edge indicators.
smoothness—number- Controls the smoothness of edge indicators.
hover—objectcolor—ColorRepresentation- Sets the color of edge indicators when hovered.
opacity—number- Sets the opacity of edge indicators when hovered.
scale—number- Sets the scale of edge indicators when hovered.
Axis Configurations
- Configurations for
x,y,z,nx,ny,nzaxes - Alias names for cube mode:
right,left,top,bottom,front,back
Each axis configuration supports:
enabled—booleanToggles the axis visibility.
label—stringCustom text label for the axis.
opacity—numberSets the axis opacity.
scale—numberSets the scale multiplier for the indicator size.
line—booleanToggles the axis line visibility.
color—ColorRepresentationSets the axis indicator background color.
labelColor—ColorRepresentationSets the axis label color.
border—objectsize—numberSets the border size around the axis indicator.
color—ColorRepresentationSets the border color around the axis indicator.
hover—objectcolor—ColorRepresentationSets the fill color on hover.
labelColor—ColorRepresentationSets the label text color on hover.
opacity—numberSets the opacity when hovered.
scale—numberSets the indicator scale when hovered.
border—objectsize—numberSets the hover border size.
color—ColorRepresentationSets the hover border color.
- Configurations for
ViewportGizmoEventMap
Defines custom events emitted by ViewportGizmo. This extends Object3DEventMap with additional events for gizmo interactions.
start— Triggered when a view change interaction begins.change— Triggered during view changes.end— Triggered when a view change interaction ends.