Use when building or debugging interactive 3D scenes on the web with Three.js (scene/camera/renderer, lights/materials, GLTF loading, controls, performance). He
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-threejs-87b735388878 ,按照其中的说明把「threejs」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
Scene (root graph)Camera (Perspective/Orthographic)Renderer (WebGLRenderer)Mesh = Geometry + MaterialrequestAnimationFrame(animate)renderer.render(scene, camera)const renderer = new THREE.WebGLRenderer({ canvas, antialias, alpha })renderer.setSize(width, height, false)renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))camera.aspect = width / height; camera.updateProjectionMatrix()scene.add(object) / object.position/rotation/scaleGLTFLoader (models), TextureLoader (images), DRACOLoader (compressed glTF)OrbitControls (debug/product), PointerLockControls (FPS), custom pointer handlersgeometry.dispose(), material.dispose(), texture.dispose(), renderer.dispose()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);
prefers-reduced-motion: reduce, render a still frame (no RAF) or slow updates.