angular-three-soba/controls

December 31, 2025 ยท View on GitHub

This secondary entry point includes controls for manipulating the camera in your scene.

PackageDescription
camera-controlsrequired by NgtsCameraControls
maathrequired by NgtsScrollControls
npm install camera-controls maath
# yarn add camera-controls maath
# pnpm add camera-controls maath

TOC

NgtsCameraControls

A component that provides advanced camera controls based on the camera-controls library. It allows you to manipulate the camera's position, rotation, and other properties through various interactions.

Object Input (NgtsCameraControlsOptions)

PropertyDescriptionDefault Value
cameraAn instance of NgtCamera that the controls will manipulate.NgtStore.camera
domElementThe HTML element that the controls will listen for events on.NgtStore.gl.domElement
makeDefaultA boolean flag indicating whether these controls should be set as the default controls in the store.false
regressA boolean flag indicating whether to enable or disable performance regression for the controls.false

Other options are available in the camera-controls library. For more information, see the official documentation

Usage

@Component({
	template: `
		<ngt-mesh>
			<ngt-box-geometry />
			<ngt-mesh-basic-material color="red" [wireframe]="true" />
		</ngt-mesh>

		<ngt-grid-helper *args="[50, 50]" [position]="[0, -1, 0]" />

		<ngts-camera-controls />
	`,
	imports: [NgtsCameraControls, NgtArgs],
	schemas: [CUSTOM_ELEMENTS_SCHEMA],
	changeDetection: ChangeDetectionStrategy.OnPush,
})
class DefaultCameraControlsStory {
	rotate = input<keyof typeof rotations | 'none'>('none');

	cameraControlsRef = viewChild.required(NgtsCameraControls);

	constructor() {
		effect(() => {
			const [rotate, controls] = [this.rotate(), this.cameraControlsRef().controls()];
			if (rotate !== 'none') {
				const [theta, phi, animate] = rotations[rotate];
				void controls.rotate(theta, phi, animate);
			} else {
				void controls.reset(true);
			}
		});
	}
}

NgtsOrbitControls

A component that provides orbit controls for rotating the camera around a target point. It is based on the OrbitControls class from the three-stdlib library.

Object Input (NgtsOrbitControlsOptions)

PropertyDescriptionDefault Value
cameraAn instance of NgtCamera that the controls will manipulate.NgtStore.camera
domElementThe HTML element that the controls will listen for events on.NgtStore.gl.domElement
targetThe coordinates that the camera will orbit around.[0, 0, 0]
makeDefaultA boolean flag indicating whether these controls should be set as the default controls in the store.false
regressA boolean flag indicating whether to enable or disable performance regression for the controls.false
enableDampingA boolean flag indicating whether to enable or disable damping (smoothness) of the camera movement.true
keyEventsA boolean flag or an HTML element indicating whether to enable keyboard events for the controls.false

Other options can pass through to OrbitControls.

Usage

<ngts-orbit-controls [options]="{ autoRotate: true }" />

NgtsPointerLockControls

A component that provides first-person style controls by locking the mouse pointer. It is based on the PointerLockControls class from the three-stdlib library.

Object Input (NgtsPointerLockControlsOptions)

PropertyDescriptionDefault Value
cameraAn instance of THREE.Camera that the controls will manipulate.NgtStore.camera
domElementThe HTML element that the controls will listen for events on.NgtStore.gl.domElement
makeDefaultA boolean flag indicating whether these controls should be set as the default controls in the store.false
enabledA boolean flag indicating whether the controls are enabled.true
selectorA CSS selector for elements that will trigger pointer lock on click.undefined

Outputs

OutputDescription
lockEmits when the pointer is locked.
unlockEmits when the pointer is unlocked.
changeEmits when the camera orientation changes.

Usage

<ngts-pointer-lock-controls [options]="{ selector: '#lock-button' }" (lock)="onLock()" (unlock)="onUnlock()" />

NgtsScrollControls

A component that enables scroll-based interactions within a Three.js canvas. It creates a scrollable container that can be used to control animations and camera movements based on scroll position.

Object Input (NgtsScrollControlsOptions)

PropertyDescriptionDefault Value
epsPrecision threshold for detecting scroll changes.0.00001
horizontalWhether to enable horizontal scrolling instead of vertical.false
infiniteWhether to enable infinite/continuous scrolling (experimental).false
pagesDefines the length of the scroll area. Each page is height:100%.1
distanceA factor that increases scroll bar travel distance.1
dampingFriction/smoothing duration in seconds.0.25
maxSpeedMaximum scroll speed in units per second.Infinity
prependIf true, attaches the scroll container before the canvas element.false
enabledWhether scroll controls are enabled.true
styleAdditional CSS styles to apply to the scroll container.{}

Companion Directives

NgtsCanvasScrollContent

A directive that automatically positions a group based on scroll progress. Apply to an ngt-group element.

<ngt-group canvasScrollContent>
	<!-- 3D content that moves with scroll -->
</ngt-group>

NgtsHTMLScrollContent

A directive that automatically transforms an HTML element based on scroll progress. Apply to a div element.

<div htmlScrollContent>
	<!-- HTML content that scrolls in sync with 3D content -->
</div>

Properties and Methods

Property/MethodDescription
progressA model that tracks the current scroll progress (0-1).
offsetThe damped scroll offset value.
deltaThe change in offset since last frame.
range(from, distance, margin?)Returns linear progress (0-1) within a scroll range.
curve(from, distance, margin?)Returns sinusoidal progress (0-1) within a scroll range.
visible(from, distance, margin?)Returns true if currently within the specified range.

Usage

<ngts-scroll-controls [options]="{ pages: 3, damping: 0.1 }">
	<ngt-group canvasScrollContent>
		<!-- 3D content that moves with scroll -->
	</ngt-group>
</ngts-scroll-controls>
@Component({
	template: `
		<ngts-scroll-controls [options]="{ pages: 3 }">
			<ngt-group canvasScrollContent>
				<ngt-mesh [position]="[0, 0, 0]">
					<ngt-box-geometry />
					<ngt-mesh-standard-material />
				</ngt-mesh>
			</ngt-group>
		</ngts-scroll-controls>
	`,
	imports: [NgtsScrollControls, NgtsCanvasScrollContent],
	schemas: [CUSTOM_ELEMENTS_SCHEMA],
})
class ScrollScene {
	scrollControls = viewChild.required(NgtsScrollControls);

	constructor() {
		effect(() => {
			// Access scroll utilities
			const visible = this.scrollControls().visible(0, 1 / 3);
			const progress = this.scrollControls().range(0, 1 / 3);
		});
	}
}

NgtsTrackballControls

A component that provides trackball-style camera controls for the Three.js scene. Unlike OrbitControls, TrackballControls have no restrictions on vertical rotation, allowing the camera to flip upside down.

Object Input (NgtsTrackballControlsOptions)

PropertyDescriptionDefault Value
cameraAn instance of THREE.Camera that the controls will manipulate.NgtStore.camera
domElementThe HTML element that the controls will listen for events on.NgtStore.gl.domElement
targetThe target point to orbit around.[0, 0, 0]
makeDefaultA boolean flag indicating whether these controls should be set as the default controls in the store.false
regressA boolean flag indicating whether to enable or disable performance regression for the controls.false

Other options can pass through to TrackballControls.

Outputs

OutputDescription
changedEmits when the camera position/orientation changes.
startedEmits when user interaction starts.
endedEmits when user interaction ends.

Usage

<ngts-trackball-controls [options]="{ makeDefault: true }" (changed)="onControlsChange($event)" />