跳到正文
Skillpedia
网站与界面(前端)7.2k · #13392

add-mouse-driven-orbit

它能做什么

这个技能指导 AI 智能体为网页上的 3D 场景添加轻微的、由指针驱动的景深效果。适合希望获得平静、电影感首屏、而不是让访客随意旋转的产品查看器的设计师。

适用场景

  • ✓你希望页面上的 3D 首屏能对鼠标做出轻柔的反应的时候。
  • ✓场景需要显得有生命力,同时不让访客拖动它的时候。
  • ✓3D 背景移动时,标题和卡片需要保持可读的时候。

技能链接

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

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/MengTo/Skills/blob/main/agent-skills/web-design/add-mouse-driven-orbit/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请让我的首页 3D 背景随鼠标移动轻微偏移,并且不遮挡文字。”

每周 5 个新技能,1 分钟读完。

工作原理

智能体会记录指针的位置并随时间平滑处理。然后,它会轻微移动镜头,让物体略微转动,并在指针离开时重置场景。触屏设备保持正常视图。

技术内容(原始 SKILL.md)

作者在 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

常见问题

访客可以旋转场景吗?

不可以。这一效果用于被动的景深,访客不能拖动或缩放场景。

在手机上会发生什么?

在触屏设备上,技能会保持设定的中心姿态,因此不会出现意外的移动。

这和 OrbitControls 一样吗?

不一样。OrbitControls 允许用户直接查看产品,而这一效果只增加轻柔的动态。

详情

作者的原始描述

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

热度

GitHub 星标
7.2k
排名
#13392
许可证
MIT
更新时间
2026/11/1

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能