AGENT SKILL

threejs

Use when building or debugging interactive 3D scenes on the web with Three.js (scene/camera/renderer, lights/materials, GLTF loading, controls, performance). Helpful for designers shipping 3D UI moments.

License 许可
MIT
所属仓库
getedgehq/skills
最近更新
2026-11-12
Stars
★ 5
Forks
0

01 前言 Front Matter

name
threejs
metadata
{ "author": "Meng To", "source": "https://github.com/MengTo/skills/tree/a965851e27dc179e693fde1bee94457a64e1a7a5/agent-skills/web-design/threejs", "license": "MIT" }
description
Use when building or debugging interactive 3D scenes on the web with Three.js (scene/camera/renderer, lights/materials, GLTF loading, controls, performance). Helpful for designers shipping 3D UI moments.

02 资源文件 6

03 SKILL.md 正文

Three.js — WebGL 3D Scenes Skill

When to use

  • Real 3D: product spins, interactive hero scenes, shaders/material effects, 3D data viz
  • You need full control beyond “background effects”
  • You can budget time for asset pipeline + performance tuning

Core mental model

  • Create:
    • Scene (root graph)
    • Camera (Perspective/Orthographic)
    • Renderer (WebGLRenderer)
    • Mesh = Geometry + Material
    • Lights (if using non-unlit materials)
  • Render loop:
    • requestAnimationFrame(animate)
    • Update time-based animations, controls, mixers, then renderer.render(scene, camera)

Key APIs/patterns

  • Setup:
    • const renderer = new THREE.WebGLRenderer({ canvas, antialias, alpha })
    • renderer.setSize(width, height, false)
    • renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
  • Camera:
    • camera.aspect = width / height; camera.updateProjectionMatrix()
  • Scene graph:
    • scene.add(object) / object.position/rotation/scale
  • Loading assets:
    • GLTFLoader (models), TextureLoader (images), DRACOLoader (compressed glTF)
  • Controls (common):
    • OrbitControls (debug/product), PointerLockControls (FPS), custom pointer handlers
  • Cleanup (important in SPAs):
    • geometry.dispose(), material.dispose(), texture.dispose(), renderer.dispose()
    • Remove event listeners; cancel RAF.

Common pitfalls

  • Not handling resize → stretched/cropped rendering
  • Too high devicePixelRatio → mobile GPU meltdown
  • Leaking WebGL resources (not disposing) → crashes after route changes
  • Loading huge textures/models → slow start; use compressed textures, Draco/KTX2, smaller maps
  • Using too many lights/shadows → expensive; fake lighting with baked textures when possible

Quick recipes

1) Minimal spinning cube

import * as THREE from "three";

const canvas = document.querySelector("#c");
const renderer = new THREE.WebGLRenderer({ canvas, antialias: true, alpha: true });

const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(45, 1, 0.1, 100);
camera.position.set(0, 0, 4);

const geom = new THREE.BoxGeometry(1, 1, 1);
const mat = new THREE.MeshStandardMaterial({ color: 0x7c3aed });
const mesh = new THREE.Mesh(geom, mat);
scene.add(mesh);

scene.add(new THREE.AmbientLight(0xffffff, 0.8));
const dir = new THREE.DirectionalLight(0xffffff, 0.8);
dir.position.set(2, 2, 2);
scene.add(dir);

function resize() {
  const w = canvas.clientWidth;
  const h = canvas.clientHeight;
  renderer.setSize(w, h, false);
  renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
  camera.aspect = w / h;
  camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();

function animate(t) {
  mesh.rotation.y = t * 0.0006;
  renderer.render(scene, camera);
  requestAnimationFrame(animate);
}
requestAnimationFrame(animate);

2) Respect reduced motion

  • If prefers-reduced-motion: reduce, render a still frame (no RAF) or slow updates.

What to ask the user

  • Is this decorative (hero) or functional 3D (product viewer)?
  • Target devices: mobile? older iPhones?
  • Asset format availability (glTF, HDRI, textures) and file size constraints
  • Accessibility/reduced motion requirements

04 同仓库更多 Skills

getedgehq
getedgehq/skills

zero-downtime-cloud-move

Runbook for moving a live app from one cloud to another (Google Cloud to AWS, AWS to Google Cloud, a PaaS to your own account, or one storage provider to another) without downtime. The agent inventories what is really running, builds the new stack next to the old one, keeps a one-line rollback for every phase, proves the new stack with real workloads before any traffic moves, cuts over with a checklist, watches a fixed window after the switch, copies data with an idempotent job whose second pass must report 0 left, and deletes the old cloud last. Use when someone asks to migrate, move or replatform a production app, switch cloud providers, move a backend, database files or object storage, plan a DNS cutover, or decommission an old cloud account.

★ 5
getedgehq
getedgehq/skills

zayats-ceo-branding

Build an evidence-based CEO positioning paper, Personal Branding Roadmap, and editorial workflow using Marina Zayats's public method. Use for executive branding, LinkedIn ghostwriting briefs, profile strategy, and recurring CEO-approved content planning.

★ 5
getedgehq
getedgehq/skills

yc-app-roast

YC App Roast: roast a YC or a16z Speedrun application. Use when a founder wants their YC or Speedrun answers scored, asks "what would a YC partner think", wants the weak answers found or rewritten, or wants their draft checked before they submit. Scores every answer 0-10 against public advice from YC and Speedrun partners, names the top issue with the exact words that cost points, and writes a rewrite from the founder's own facts. Works for YC and a16z Speedrun. Not affiliated with Y Combinator or a16z.

★ 5
getedgehq
getedgehq/skills

yc-app-review

YC App Review: get a YC or a16z Speedrun application reviewed by people you trust. Use when a founder wants friends, mentors or alumni to review their YC or Speedrun application, or asks to share their draft for feedback. Builds a shareable review page (one HTML file, application-portal look) where reviewers leave notes per question and press "Send my notes" to send them back as text, then parses the notes into proposed rewrites. Optional tracked private links per reviewer. Works for YC and a16z Speedrun. Not affiliated with Y Combinator or a16z.

★ 5
getedgehq
getedgehq/skills

x-growth-playbook

X Growth Playbook. Analyse a person's own X (Twitter) posts and tell them what to post next, with the numbers behind every claim. Compares quote posts vs originals, links vs no links, short vs long, time of day in their timezone, media vs text and the topics they name, reports medians with n, then writes a 10-step plan and the next 7 posts in their voice. Use when the user says "analyse my X posts", "what works on my Twitter", "how do I grow on X", "what should I post next on X", "audit my X account", or shares an X data archive, X API export or a list of their posts. Runs on the user's computer.

★ 5
getedgehq
getedgehq/skills

workplan

Create, update, or close work plans for multi-step tasks. Use when starting refactors, bug lists, feature work, migrations, or any task with 2+ steps. Also use after auto-compaction to re-orient. Triggers: "workplan", "work plan", "create a plan", "what's the plan", "where was I", or when Claude detects a multi-step task that needs tracking.

★ 5