Aller au contenu
Skillpedia
Sites et interfaces (frontend)7.2k · #13392

add-mouse-driven-orbit

Ce qu’il fait

Ce skill guide un agent IA pour ajouter une profondeur légère, pilotée par le pointeur, à une scène 3D d'une page web. Il s'adresse aux designers qui veulent un héros calme et cinématographique, et non un visualiseur de produit que les visiteurs peuvent faire tourner.

Quand l’utiliser

  • ✓Quand vous voulez qu'un héros 3D d'une page réagisse doucement à la souris.
  • ✓Quand une scène doit donner une impression de vie sans que les visiteurs puissent la faire glisser.
  • ✓Quand le titre et les cartes doivent rester lisibles pendant que le fond 3D bouge.

Lien du skill

https://github.com/MengTo/Skills/blob/main/agent-skills/web-design/add-mouse-driven-orbit/SKILL.md

Copiez-le et collez-le dans votre IA (Claude, ChatGPT ou Cursor) en lui demandant de suivre les instructions.

Comment l’utiliser

Le plus simple : copiez le message et collez-le dans votre IA. Elle lit le skill et suit les instructions.

Message prêt à coller

Utilise ce skill pour m’aider : https://github.com/MengTo/Skills/blob/main/agent-skills/web-design/add-mouse-driven-orbit/SKILL.md Lis le fichier SKILL.md de ce lien et suis ses instructions pour ma tâche.
Envie que votre IA trouve seule des skills comme celui-ci ?Installez le MCP gratuit de Skillpedia : une ligne, et elle cherche parmi 15 000+ skills avant chaque tâche.Installer en 1 minute →

Exemple de demande à votre IA

“Fais bouger légèrement le fond 3D de ma page d'accueil quand la souris bouge, sans gêner le texte.”

5 nouveaux skills par semaine. 1 minute de lecture.

Comment ça marche

L'agent enregistre la position du pointeur et la lisse dans le temps. Il déplace légèrement la caméra et tourne un peu les objets, puis réinitialise la scène quand le pointeur quitte la zone. Les écrans tactiles gardent la vue normale.

Contenu technique (SKILL.md original)

Texte original de l’auteur, en anglais, directement depuis GitHub.

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 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

Questions fréquentes

Les visiteurs peuvent-ils faire tourner la scène ?

Non. Le skill vise une profondeur passive, donc les visiteurs ne glissent pas et ne zooment pas sur la scène.

Que se passe-t-il sur les téléphones ?

Sur les écrans tactiles, le skill garde la pose centrale définie, pour que rien ne bouge de façon inattendue.

Est-ce la même chose qu'OrbitControls ?

Non. OrbitControls permet d'inspecter directement un produit, alors que cet effet ajoute seulement un mouvement doux.

Détails

Description originale de l’auteur

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.

repo: MengTo/Skills

Popularité

Étoiles GitHub
7.2k
Position au classement
#13392
Licence
MIT
Mis à jour
01/11/2026

Ce skill vous est-il utile ?

0

Connectez-vous pour voter.

Commentaires

  • …

Autres skills de ce dépôt

Skills similaires