Skip to main content
skill CX Codex

add-mouse-driven-orbit — Claude Code skill: what it does

Adds subtle mouse-driven orbit and parallax to Three.js hero sections without OrbitControls. Useful for cinematic headers that react to cursor movement.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add MengTo/Skills --skill add-mouse-driven-orbit -a claude-code
Open on GitHub

What add-mouse-driven-orbit does

This skill implements subtle pointer-driven parallax for Three.js hero sections. Instead of direct inspection via OrbitControls, it damps a single pointer target and distributes the motion across camera translation, look-at tracking, and minor object rotations.

The pointer handler records only normalized coordinates from -1 to 1, while viewport boundaries come from a cached ResizeObserver. Damping runs in the render loop with an alpha formula tied to delta time, clamped to 1/30 s to avoid jumps after tab switching. Motion splits across layers: foreground elements rotate slightly more than background groups, and camera look-at retains 42% carry to pin the subject.

Calling getBoundingClientRect() inside pointermove triggers synchronous layout spikes that ruin framerates. For users with prefers-reduced-motion, the skill falls back to an authored three-quarter still pose without autonomous easing.

What it helps with

  • add subtle pointer parallax to a Three.js hero section
  • split camera translation and layered object rotations
  • eliminate layout thrashing from getBoundingClientRect calls
  • display an authored static pose for prefers-reduced-motion

Example prompts for the agent

  • Add mouse-driven parallax and subtle camera orbit to our Three.js hero section
  • Configure damped pointer tracking with split camera translation and layer rotation

How to install add-mouse-driven-orbit

1Skills CLI (Vercel)

npx skills add MengTo/Skills --skill add-mouse-driven-orbit -a claude-code

2Manually: put the files in place

~/.claude/skills/add-mouse-driven-orbit/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/add-mouse-driven-orbit/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about add-mouse-driven-orbit

How to install add-mouse-driven-orbit in Claude Code?

Run npx skills add MengTo/Skills --skill add-mouse-driven-orbit -a claude-code in your terminal. The skill file is placed in ~/.claude/skills/add-mouse-driven-orbit/SKILL.md.

How does this differ from OrbitControls?

OrbitControls offers direct 3D model inspection via dragging. This skill creates passive cinematic depth that keeps the subject pinned relative to headline typography and DOM elements.

How does it handle touch screens and reduced motion?

Touch pointers ignore dragging and maintain the centered layout. When prefers-reduced-motion is active, it renders an authored three-quarter still pose without autonomous movement.

Source text

SKILL.md · MIT
---
name: add-mouse-driven-orbit
description: Add restrained mouse-driven orbit and parallax depth to a Three.js hero by damping one pointer target and splitting it across camera translation, look-at, and small object rotations. Use for passive cinematic 3D heroes, pointer-responsive scenes, organic model parallax, and interactive depth where OrbitControls would feel like a product viewer.
---

# Add Mouse-Driven Orbit

Turn one damped pointer target into a shallow camera arc and smaller object rotations. Reach for `threejs` with `OrbitControls` when the user must inspect a product directly; reach for `build-game-camera-controls` for drag, zoom, occlusion, or gameplay cameras. This Skill is passive cinematic depth, not direct manipulation.

Extracted from `inner-green-3d.html`, where a procedural moss root had to turn toward the pointer without sliding away from the headline, cards, and pinned silhouette landmarks.

## Record intent, not layout

In the pointer handler, write normalized coordinates only:

```js
function recordPointer(event) {
  if (event.pointerType === "touch") return;
  target.x = (event.clientX / viewport.width) * 2 - 1;
  target.y = (event.clientY / viewport.height) * 2 - 1;
}
```

Cache the interactive rectangle from `ResizeObserver`. Do not call `getBoundingClientRect()` for every layer on every `pointermove`; synchronous layout turns a light effect into frame spikes.

On `pointerleave`, set the target back to `0, 0`. On coarse pointers, keep the authored center pose. Passive orbit should never require touch dragging to reveal content.

## Dampen in the frame loop

The source uses 0.055 per 60 Hz frame. Preserve that feel across refresh rates:

```js
const alpha = 1 - Math.pow(1 - 0.055, dt * 60);
smooth.x += (target.x - smooth.x) * alpha;
smooth.y += (target.y - smooth.y) * alpha;
```

Clamp `dt` to 1/30 s and reset the time base after resume. A fixed per-frame lerp feels heavy at 30 Hz and twitchy at 120 Hz; an unclamped delta jumps after backgrounding.

Stop style or uniform writes once the rounded value settles. Three decimals are finer than one pixel of the landed travel:

```js
const x = Math.round(smooth.x * 1000) / 1000;
const y = Math.round(smooth.y * 1000) / 1000;
if (x !== lastX || y !== lastY) publish(x, y);
```

## Split the motion

Use opposing, unequal layers so the scene pivots rather than translates as one slab:

```js
camera.position.x = -smooth.x * 26;
camera.position.y =  smooth.y * 16;
camera.lookAt(camera.position.x * 0.42, camera.position.y * 0.42, 0);

nearGroup.rotation.y = smooth.x * 0.055;
nearGroup.rotation.x = smooth.y * 0.026;
farGroup.rotation.y  = smooth.x * 0.030;
```

Treat these as the landed values for a scene framed in stage-pixel world units:

| layer | horizontal | vertical | reason |
| --- | ---: | ---: | --- |
| camera translation | -26 | +16 | establishes the shallow arc |
| camera look-at carry | 42% | 42% | keeps the subject near its pinned composition |
| near object yaw | 0.055 rad | — | exposes surface depth without showing its flank |
| near object pitch | — | 0.026 rad | prevents the top surface from flattening |
| far object yaw | 0.030 rad | — | separates planes without matching the foreground |

Do not rotate everything by the same amount. Equal movement reads as a flat poster following the cursor. Do not aim the camera at the fixed origin while translating it; the subject visibly slides away from the layout.

Apply CSS parallax from the same `smooth` pair, but give text and controls smaller depth coefficients than the 3D form. Keep transforms free for parallax; use clip, opacity, or child wrappers for unrelated reveals so animations do not overwrite each other.

## Preserve framing across sizes

Build the center pose first at every breakpoint. Recalculate camera aspect and any stage-to-world scale from a `ResizeObserver`, guard zero-sized roots, then apply orbit offsets. Verify both extreme pointer corners: no copy collision, card clipping, or exposed empty edge.

Use keyboard-operable X and Y range controls in a demo or configurator. They prove the orbit is parameterised and give non-pointer users access to the same authored states. Keep focus visible and announce motion-mode changes.

## Respect motion and lifecycle

- Under `prefers-reduced-motion: reduce`, render a designed three-quarter still at approximately `x=.28, y=-.12`; keep the range controls live and redraw their selected still without interpolation.
- Pause while hidden or offscreen and resume with a reset time base.
- Cap DPR at 2 and clamp `dt` to 1/30 s.
- Keep the canvas decorative unless the 3D object carries information. Preserve all labels and controls in semantic HTML.
- On teardown, cancel the frame, disconnect observers, remove pointer/media listeners, and dispose Three.js resources.

## State the cost honestly

The orbit math is negligible. The expensive work is the scene already being redrawn and any DOM style invalidation layered on top. Share one frame loop, round settled values, avoid layout reads in pointer handlers, and profile the underlying draw before removing the interaction. Moving the camera does not make a dense scene cheaper.

## Verify

- Compare center and four-corner poses with the source at 1440×900.
- Confirm camera and objects move by different, opposing amounts.
- Move quickly across the viewport; the scene must ease through the path, not snap.
- Leave the viewport; confirm a smooth return to center.
- Test 390×844 and coarse/touch input; center composition remains complete.
- Tab through X/Y controls, change them with arrow keys, and confirm visible focus.
- Test `?reduced=1`: stable designed still, no autonomous easing, live controls.
- Hide/show and scroll away/back; confirm no jump and only one frame loop.
- Confirm a clean console at both sizes.

Use [demo/index.html](demo/index.html) as the working proof and [demo/PROMPT.md](demo/PROMPT.md) to recreate or remix it.

© MengTo · MIT · MengTo/Skills

Similar skills

Everything for Frontend and UI →

From the same set148

build-game-camera-controls A skill for building and tuning Three.js game cameras: isometric framing, follow, orbit limits, occlusion, lock-on, shake and touch gestures. CX Codex +1 1,300installs publish-project-to-github Packages a local project into a GitHub repository, audits files for leaked secrets, generates a verified README, and configures GitHub Pages. CX Codex +1 1,100installs build-interactive-particle-trail A skill for pointer-driven particle trails: the cursor or finger leaves discrete motes that fly on their own path. Useful in 3D scenes and landing pages. CX Codex +1 1,100installs web-technique-to-skill Turns a visual or interaction technique you already built into a reusable web-design skill, with a demo that proves both the mechanism and the visual fidelity. CX Codex +1 1,100installs 3d-virtual-tour A skill for building virtual tours through a 3D scene: authored camera paths, room navigation, orbit inspection. Useful for architectural walkthroughs and showrooms in Three.js. CX Codex +1 527installs 3d-retina-resolution Keeps 3D canvases sharp on Retina and HiDPI displays, including fixed 200% rendering. Useful for blurry WebGL previews and display-density changes. CX Codex +1 512installs 3d-high-resolution-textures Picks texture resolution and PBR maps so close-up surfaces stay sharp without blowing up GPU memory. CX Codex +1 508installs 3d-sky-rays A skill that adds crepuscular rays to a Three.js scene, shaped by roofs and foliage. Useful for golden-hour architectural shots. CX Codex +1 506installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor