Claude-skill-registry threejs-syntax-controls
git clone https://github.com/majiayu000/claude-skill-registry
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/other/other/threejs-syntax-controls" ~/.claude/skills/majiayu000-claude-skill-registry-threejs-syntax-controls && rm -rf "$T"
skills/other/other/threejs-syntax-controls/SKILL.mdthreejs-syntax-controls
Quick Reference
Control Selection Decision Tree
| Use Case | Control | Why |
|---|---|---|
| Inspect a 3D model from all angles | OrbitControls | Orbit/pan/zoom around a target point |
| Top-down map or 2D-style navigation | MapControls | Left-drag pans, right-drag rotates |
| Free-flight editor or space scene | FlyControls | Six degrees of freedom, WASD + mouse |
| First-person game with pointer lock | PointerLockControls | Hides cursor, captures mouse movement |
| First-person without pointer lock | FirstPersonControls | Mouse-look without browser lock API |
| Move/rotate/scale objects via gizmo | TransformControls | Interactive translate/rotate/scale handles |
| Drag objects along a plane | DragControls | Click-and-drag object repositioning |
| Unconstrained rotation (no gimbal lock) | ArcballControls | Full spherical rotation with animation |
| Unconstrained rotation (simpler) | TrackballControls | Like OrbitControls but no pole constraint |
Import Paths (Three.js r160+)
import { OrbitControls } from 'three/addons/controls/OrbitControls.js'; import { MapControls } from 'three/addons/controls/MapControls.js'; import { FlyControls } from 'three/addons/controls/FlyControls.js'; import { FirstPersonControls } from 'three/addons/controls/FirstPersonControls.js'; import { PointerLockControls } from 'three/addons/controls/PointerLockControls.js'; import { TransformControls } from 'three/addons/controls/TransformControls.js'; import { TrackballControls } from 'three/addons/controls/TrackballControls.js'; import { ArcballControls } from 'three/addons/controls/ArcballControls.js'; import { DragControls } from 'three/addons/controls/DragControls.js';
ALWAYS use
'three/addons/controls/...' for r160+. The legacy path 'three/examples/jsm/controls/...' still works but is deprecated.
Critical Warnings
ALWAYS call
controls.update() in the animation loop when enableDamping or autoRotate is true. Failing to do so causes the camera to freeze after user interaction ends.
ALWAYS call
controls.dispose() when removing controls. Failing to do so leaks DOM event listeners (pointermove, wheel, keydown) that cause memory leaks and ghost interactions.
NEVER attach two camera-control classes to the same camera simultaneously without disabling one. OrbitControls + FlyControls on the same camera causes erratic movement.
ALWAYS disable OrbitControls while TransformControls is dragging. Listen to the
dragging-changed event and toggle orbitControls.enabled.
ALWAYS call
PointerLockControls.lock() from a user gesture (click handler). Browsers reject pointer lock requests without user interaction.
ALWAYS pass
delta time to FlyControls.update(delta). Passing no argument or passing elapsed time causes speed to depend on frame rate.
Controls Lifecycle
Every control follows the same lifecycle pattern:
construct --> configure --> attach to loop --> dispose on cleanup
Step 1: Construct
const controls = new OrbitControls(camera, renderer.domElement);
ALWAYS pass
renderer.domElement as the second argument. Passing document or document.body causes controls to capture events globally, breaking UI overlays.
Step 2: Configure
controls.enableDamping = true; controls.dampingFactor = 0.05; controls.minDistance = 2; controls.maxDistance = 50; controls.target.set(0, 1, 0);
Step 3: Update in Render Loop
function animate() { requestAnimationFrame(animate); controls.update(); // REQUIRED when enableDamping or autoRotate is true renderer.render(scene, camera); } animate();
Step 4: Dispose on Cleanup
controls.dispose();
OrbitControls
The most commonly used control. Orbits, pans, and zooms around a target point.
Constructor
new OrbitControls(camera: THREE.Camera, domElement: HTMLElement)
Key Properties
| Property | Type | Default | Description |
|---|---|---|---|
| | | Enable/disable all interaction |
| | | Orbit focus point |
| | | Smooth inertial movement |
| | | Inertia strength (0-1) |
| | | Auto-rotate around target |
| | | Degrees/sec at 60fps |
| | | Allow panning |
| | | Allow rotation |
| | | Allow zooming |
| | | Min zoom distance (PerspectiveCamera) |
| | | Max zoom distance (PerspectiveCamera) |
| | | Min zoom (OrthographicCamera) |
| | | Max zoom (OrthographicCamera) |
| | | Min vertical angle (radians) |
| | | Max vertical angle (radians) |
| | | Min horizontal angle (radians) |
| | | Max horizontal angle (radians) |
| | | Pan in screen plane (true) or horizontal plane (false) |
| | | Zoom towards cursor position |
| | | Pan speed multiplier |
| | | Rotation speed multiplier |
| | | Zoom speed multiplier |
| | | Mouse button mapping |
| | | Touch gesture mapping |
| | | Arrow key codes for panning |
Methods
| Method | Signature | Description |
|---|---|---|
| | Update controls state. MUST call every frame with damping/autoRotate |
| | Remove all event listeners |
| | Save current camera position/target/zoom |
| | Restore to last saved state |
| | Distance from camera to target |
| | Vertical angle in radians |
| | Horizontal angle in radians |
| | Enable keyboard panning |
| | Disable keyboard panning |
Events
| Event | Trigger |
|---|---|
| Camera position or target changed |
| User interaction began (pointerdown) |
| User interaction ended (pointerup) |
MapControls
Subclass of OrbitControls optimized for top-down map navigation.
| Button | OrbitControls | MapControls |
|---|---|---|
| Left mouse | Rotate | Pan |
| Middle mouse | Dolly | Dolly |
| Right mouse | Pan | Rotate |
All properties, methods, and events are identical to OrbitControls. The ONLY differences are the default
mouseButtons mapping and screenSpacePanning defaulting to true.
FlyControls
Six-degrees-of-freedom flight camera. WASD for movement, QE for roll, RF for up/down.
Key Properties
| Property | Type | Default | Description |
|---|---|---|---|
| | | Translation speed |
| | | Roll rotation speed |
| | | Require mouse drag to rotate (vs. always follow mouse) |
| | | Move forward automatically |
Methods
-- ALWAYS passupdate(delta)
time from the clock. NEVER omit this argument.delta
-- Remove event listeners.dispose()
PointerLockControls
First-person camera using the Pointer Lock API. Hides and captures the mouse cursor.
Key Properties
| Property | Type | Default | Description |
|---|---|---|---|
| | read-only | Whether pointer is currently locked |
| | | Max vertical look angle |
| | | Min vertical look angle |
| | | Mouse sensitivity multiplier |
Methods
| Method | Description |
|---|---|
| Request pointer lock (MUST call from user gesture) |
| Exit pointer lock |
| Attach event listeners |
| Remove event listeners |
| Full cleanup (calls disconnect) |
| Returns the controlled camera |
| Write look direction into target Vector3 |
| Move camera forward |
| Move camera sideways |
Events
| Event | Trigger |
|---|---|
| Camera orientation changed |
| Pointer lock acquired |
| Pointer lock released |
ALWAYS implement your own WASD movement in the animation loop. PointerLockControls handles look direction only, NOT position.
TransformControls
Interactive gizmo for moving, rotating, and scaling scene objects.
Key Properties
| Property | Type | Default | Description |
|---|---|---|---|
| | | , , or |
| | | or coordinate space |
| | | Show X axis handle |
| | | Show Y axis handle |
| | | Show Z axis handle |
| | | Gizmo visual scale |
| `number | null` | |
| `number | null` | |
| `number | null` | |
| | read-only | User is currently dragging |
Methods
| Method | Description |
|---|---|
| Attach gizmo to a scene object |
| Remove gizmo from current object |
| Set transform mode |
| Set coordinate space |
| Set gizmo scale |
| Set position snap |
| Set rotation snap |
| Set scale snap |
| Access internal raycaster |
| Cleanup |
Events
| Event | Trigger |
|---|---|
| Gizmo visual changed |
| is when dragging starts, when it ends |
| Attached object's transform was modified |
| Pointer pressed on gizmo |
| Pointer released from gizmo |
Critical Integration Pattern
ALWAYS disable camera controls during gizmo drag:
transformControls.addEventListener('dragging-changed', (event) => { orbitControls.enabled = !event.value; });
ALWAYS add TransformControls to the scene:
scene.add(transformControls.getHelper()) or scene.add(transformControls).
Brief Overview: Other Controls
ArcballControls
Unconstrained rotation with animation states. No polar angle limit -- the camera rotates freely in all directions. Best for CAD-style model inspection.
TrackballControls
Like OrbitControls without the polar angle constraint. The camera can rotate past the poles. Properties:
rotateSpeed, zoomSpeed, panSpeed, staticMoving, dynamicDampingFactor.
DragControls
Drag scene objects along a plane. Constructor:
new DragControls(objects, camera, domElement). Events: dragstart, drag, dragend, hoveron, hoveroff.
FirstPersonControls
Mouse-look camera without pointer lock. Properties:
movementSpeed, lookSpeed, activeLook, constrainVertical, verticalMin, verticalMax.
Reference Links
- references/methods.md -- Full API signatures for all controls
- references/examples.md -- Working code examples for each control type
- references/anti-patterns.md -- What NOT to do
Official Sources
- https://threejs.org/docs/#examples/en/controls/OrbitControls
- https://threejs.org/docs/#examples/en/controls/MapControls
- https://threejs.org/docs/#examples/en/controls/FlyControls
- https://threejs.org/docs/#examples/en/controls/PointerLockControls
- https://threejs.org/docs/#examples/en/controls/TransformControls