Add Mouse Driven Orbit
Meng ToCommunityCreated by Meng To
- Skill
- Guidelines
- Software development
- MIT
- Low risk
- Has scripts
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill provides a pattern for creating passive, pointer-responsive 3D scenes in Three.js. Instead of direct user manipulation like OrbitControls, this approach uses a damped pointer target to subtly shift the camera and rotate objects, creating a cinematic sense of depth. It emphasizes performance by avoiding synchronous layout reads, using frame-rate independent damping, and splitting motion across different scene layers to prevent a flat, poster-like appearance.
What it does
- Normalizes pointer coordinates to drive scene motion.
- Implements frame-rate independent damping for smooth movement.
- Splits motion across camera translation, look-at, and object rotations.
- Provides guidelines for responsive framing and layout preservation.
- Includes accessibility considerations for reduced motion and keyboard users.
- Optimizes performance by rounding values and sharing a single frame loop.
When to use it
- When building cinematic 3D hero sections that require passive depth.
- When you want pointer-responsive scenes without the direct control of OrbitControls.
- When creating organic model parallax that should not feel like a product viewer.
- When you need to maintain specific layout landmarks while adding 3D movement.
Advantages
- Prevents frame spikes by avoiding synchronous layout reads.
- Ensures consistent feel across different refresh rates.
- Creates a more natural, layered depth effect than simple camera movement.
- Respects user accessibility preferences for reduced motion.
- Maintains stable composition across different screen sizes.
Usage examples
- “How do I implement a mouse-driven parallax effect for a Three.js hero section?”
- The agent provides the logic for normalizing pointer coordinates, applying frame-rate independent damping, and splitting the motion across camera and object layers.
- “How can I ensure my Three.js orbit effect is performant and accessible?”
- The agent explains how to avoid layout thrashing, implement prefers-reduced-motion support, and provide keyboard-operable controls for the orbit parameters.
Install
1 of its files are not mirrored here, so install it from its source:
https://github.com/MengTo/Skills/tree/5ea1661a0e05d82b054553daaa6baf6d0233c33c/agent-skills/web-design/add-mouse-driven-orbit
Documentation by Meng To
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:
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:
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:
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:
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 approximatelyx=.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
dtto 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 as the working proof and demo/PROMPT.md to recreate or remix it.
Files
- ATTRIBUTION.mdAdded by AutoGineer866 B
- LICENSELicence file added by AutoGineer1.0 KiB
- SKILL.md5.8 KiB
- agents/openai.yaml244 B
- demo/PROMPT.md1.7 KiB
- demo/assets/card-ethos.jpg309.3 KiB
- demo/assets/lexend-latin.woff2(opens on GitHub)Not mirrored: opens on GitHub38.8 KiB
- demo/assets/three.min.jsScript593.8 KiB
- demo/index.html13.1 KiB
- demo/preview.jpg106.9 KiB
demo/PROMPT.md
Mouse-Driven Orbit Demo Prompts
Minimal prompt
Use $add-mouse-driven-orbit to give this Three.js hero restrained pointer depth without turning it into a draggable product viewer.Recreate the demo
Use $add-mouse-driven-orbit to recreate Sylva — Living Orbit as a standalone local HTML demo.
Preserve the grey-green field, low light pool, white Lexend headline, pale field card, ghost wordmark, and procedural root silhouette.
Build the complete centered composition first. Pointer motion must be an enhancement.
Record one normalized pointer target, damp it with the 0.055-at-60-Hz equivalent, and split it across camera translation, a 42% carried look-at, 0.055/0.026-radian near-root rotation, and 0.030-radian far-layer yaw.
Ignore touch pointer movement and return smoothly to center on pointer leave.
Add keyboard-operable Horizontal and Vertical range controls plus a Motion button. Announce changes in a live region.
Avoid layout reads in
pointermove; cache dimensions viaResizeObserver.Cap DPR at 2, clamp
dtto 1/30 s, and pause offscreen or hidden.Under reduced motion, show the designed
x=.28, y=-.12three-quarter still; let the range controls select other still poses without easing.Support 390px through 1440px, visible focus, and a clean console.
Keep dependencies local in
demo/assets/.
Remix prompt
Use $add-mouse-driven-orbit for a pale museum plinth holding a cobalt ceramic form. Change the subject, palette, type, and composition, but keep the centered base pose, one damped normalized target, split camera/object motion, pointer-leave return, touch-safe center state, keyboard pose controls, reduced-motion still, and lifecycle budgets.Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Needs Node.js
Security
What our scanner noticed· Low risk
- Scripts that your agent may run
This skill includes scripts that your agent may run. Read them before you use it.
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Created by
- Meng To
- Publisher
- Meng To (Community)
- Source
- MengTo/Skills · agent-skills/web-design/add-mouse-driven-orbit · commit 5ea1661
- Licence
- MIT License (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by Meng To or Meng To.
Get it from the source
1 of this skill’s files are not mirrored here, so there is no ZIP. Get the complete skill from its source: MengTo/Skills