К основному содержанию
скилл CX Codex

add-mouse-driven-orbit — скилл для Claude Code: что делает

Добавляет плавный параллакс и кинематографичное вращение сцены Three.js вслед за курсором мыши без OrbitControls. Пригодится для интерактивных hero-секций.

Установить в Claude Code · Через Skills CLI (Vercel) Все способы и платформы ↓
npx skills add MengTo/Skills --skill add-mouse-driven-orbit -a claude-code
Открыть на GitHub

Что делает add-mouse-driven-orbit

Скилл настраивает ненавязчивый параллакс для Three.js: курсор мыши задаёт сглаженную цель, которая распределяется между сдвигом камеры, точкой взгляда lookAt и лёгким вращением 3D-объектов. Такой подход нужен для фоновых витрин и первых экранов, где стандартный OrbitControls ломает вёрстку заголовков и превращает страницу в просмотрщик 3D-моделей.

В обработчике пишутся только нормализованные координаты от -1 до 1, а размеры берутся из кэша ResizeObserver. Расчёт сглаживания привязан к частоте кадров через коэффициент затухания и ограничение шага времени в 1/30 секунды. Движение разделяется по слоям: передний план поворачивается сильнее заднего, а камера плавно компенсирует смещение на 42%, удерживая композицию.

Попытка вызвать getBoundingClientRect() на каждый pointermove сразу создаст просадки кадров из-за пересчёта разметки. Для пользователей с prefers-reduced-motion скилл требует фиксировать статический ракурс три четверти и отключать анимацию.

Какие задачи решает

  • оживить трёхмерный hero-блок движением курсора
  • разделить параллакс между камерой и отдельными слоями сцены
  • избежать просадок кадров от частых вызовов getBoundingClientRect
  • настроить статичный ракурс для prefers-reduced-motion

Примеры запросов агенту

  • Добавь в Three.js плавный параллакс за курсором для главного баннера без OrbitControls
  • Настрой сглаженное движение камеры и поворот объекта по координатам мыши

Как установить add-mouse-driven-orbit

1Через Skills CLI (Vercel)

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

2Вручную: положить файлы

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

Папка скилла целиком; для одного проекта — .claude/skills/add-mouse-driven-orbit/

По шагам, с командами для каждой платформы: Как установить скилл в Claude Code: пять способов

Из того же набора148

build-game-camera-controls Скилл для настройки игровых камер в Three.js: изометрия, слежение, орбита, окклюзия, тряска и тач-жесты. CX Codex +1 1 300установок publish-project-to-github Упаковывает локальный проект в репозиторий GitHub, создаёт README со скриншотом, запускает аудит секретов и настраивает GitHub Pages. Пригодится для публикации пет-проектов и демо. CX Codex +1 1 100установок build-interactive-particle-trail Скилл для интерактивных частиц: курсор или палец оставляет след из точек, которые летят по своей траектории. Пригодится в 3D-сценах и на лендингах. CX Codex +1 1 100установок web-technique-to-skill Помогает превратить готовый визуальный или интерактивный приём в переиспользуемый скилл для веб-дизайна — с демо, которое доказывает и механику, и точность. CX Codex +1 1 100установок 3d-virtual-tour Скилл для сборки виртуальных туров по 3D-сцене: маршрут камеры, переходы между комнатами, осмотр модели. Пригодится для архитектурных обходов и шоурумов на Three.js. CX Codex +1 527установок 3d-retina-resolution Настраивает чёткий 3D-рендеринг на Retina и HiDPI, включая фиксированный масштаб 200%. Нужен для WebGL-превью, где картинка теряет резкость. CX Codex +1 512установок 3d-high-resolution-textures Помогает подобрать разрешение и PBR-карты для 3D-материалов, чтобы близкие планы выглядели резко, а GPU-память не улетала в потолок. CX Codex +1 508установок 3d-sky-rays Скилл добавляет в Three.js-сцену лучи света из-за крыш и сквозь листву. Пригодится, когда нужен золотой час в архитектурном рендере. CX Codex +1 506установок

Похожие

orbit-card heygen-com Скилл для встраивания готового 10-секундного 3D-блока HyperFrames: карточка фичи облетает сферу из точек по траектории камеры из Blender. CX Codex +1 10 000установок frost-sequence-camera-orbit heygen-com Скилл собирает 22.5-секундную сцену: камера облетает ледяной логотип, он рассыпается, собирается в два текста и растворяется. CX Codex +1 10 000установок add-feature OpusGameLabs Добавляет игровую механику в браузерную игру на Three.js или Phaser. Пригодится, когда нужно внедрить бонусы, комбо или двойной прыжок без поломки архитектуры проекта. CX Codex +1 977установок title-sequence-3d charlie947 Скилл собирает кинематографичный 3D-опенер на Three.js в одном HTML-файле. Пригодится, когда для видеоролика или рассылки нужна яркая заставка с неоновыми вывесками и логотипами. CX Codex +1 1 500установок threejs-fundamentals CloudAI-X Помогает настроить базовую сцену Three.js r186: рендерер, камеры, цикл анимации с THREE.Timer и import map для WebGL или WebGPU с TSL. CX Codex +1 17 400установок threejs-interaction CloudAI-X Скилл учит агента настраивать выбор объектов, перемещение по плоскости и управление камерой в three.js для WebGL и WebGPU. CX Codex +1 14 300установок

Рядом в теме «Фронтенд и UI»

Всё по теме «Фронтенд и UI» →

Вопросы о add-mouse-driven-orbit

Как установить add-mouse-driven-orbit в Claude Code?

Выполните команду npx skills add MengTo/Skills --skill add-mouse-driven-orbit -a claude-code в терминале. Файл скилла запишется в ~/.claude/skills/add-mouse-driven-orbit/SKILL.md.

Чем этот подход отличается от OrbitControls?

OrbitControls предназначен для свободного вращения и осмотра 3D-модели пользователем. Этот скилл создаёт фоновую кинематографичную глубину, не позволяя объекту уплывать от заголовков и карточек интерфейса.

Как обрабатываются тачскрины и режим reduced motion?

На сенсорных экранах сохраняется центральная композиция без необходимости перетаскивания. При включённом правиле prefers-reduced-motion сцена фиксируется в статичном ракурсе три четверти без сглаживания.

Исходный текст

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

Смотрите также

Спонсоры проекта

Компании, которые помогают держать аналитику открытой