[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7C4WD4652RRYX779F48AD0W":3,"skill-same:01M7C4WD4652RRYX779F48AD0W":49},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":26,"commitSha":27,"skillDirectory":28,"forksCount":29,"repositoryHtmlUrl":30,"repositoryHomepageUrl":31,"ownerHtmlUrl":32,"ownerBlogUrl":6,"ownerDescription":33,"updatedAt":34,"install":35,"resources":48},"01M7C4WD4652RRYX779F48AD0W","threejs-fundamentals",null,"Three.js scene setup, cameras, renderer, Object3D hierarchy, coordinate systems. Use when setting up 3D scenes, creating cameras, configuring renderers, managing object hierarchies, or working with transforms.","YYC-Cube\u002FYYC3-Knowledge-Base","YYC-Cube","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F235006543?v=4","01M79J2PH4SWD2X0825X6PN748","yyc3","01M79J2PHVK3F6ZBYT8K2SCZCW",1,"MIT","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-Skills-技能包\u002FYYC3-Skills-技能包-antigravity-awesome-skills\u002Fplugins\u002Fantigravity-awesome-skills-claude\u002Fskills\u002Fthreejs-fundamentals\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: threejs-fundamentals\ndescription: Three.js scene setup, cameras, renderer, Object3D hierarchy, coordinate systems. Use when setting up 3D scenes, creating cameras, configuring renderers, managing object hierarchies, or working with transforms.\nrisk: unknown\nsource: community\n---\n\n# Three.js Fundamentals\n\n## When to Use\n- You need to set up the core structure of a Three.js scene.\n- The task involves scenes, cameras, renderers, transforms, resize handling, or object hierarchy basics.\n- You want foundational Three.js guidance before working on specialized topics like shaders or post-processing.\n\n## Quick Start\n\n```javascript\nimport * as THREE from \"three\";\n\n\u002F\u002F Create scene, camera, renderer\nconst scene = new THREE.Scene();\nconst camera = new THREE.PerspectiveCamera(\n  75,\n  window.innerWidth \u002F window.innerHeight,\n  0.1,\n  1000,\n);\nconst renderer = new THREE.WebGLRenderer({ antialias: true });\n\nrenderer.setSize(window.innerWidth, window.innerHeight);\nrenderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));\ndocument.body.appendChild(renderer.domElement);\n\n\u002F\u002F Add a mesh\nconst geometry = new THREE.BoxGeometry(1, 1, 1);\nconst material = new THREE.MeshStandardMaterial({ color: 0x00ff00 });\nconst cube = new THREE.Mesh(geometry, material);\nscene.add(cube);\n\n\u002F\u002F Add light\nscene.add(new THREE.AmbientLight(0xffffff, 0.5));\nconst dirLight = new THREE.DirectionalLight(0xffffff, 1);\ndirLight.position.set(5, 5, 5);\nscene.add(dirLight);\n\ncamera.position.z = 5;\n\n\u002F\u002F Animation loop\nfunction animate() {\n  requestAnimationFrame(animate);\n  cube.rotation.x += 0.01;\n  cube.rotation.y += 0.01;\n  renderer.render(scene, camera);\n}\nanimate();\n\n\u002F\u002F Handle resize\nwindow.addEventListener(\"resize\", () => {\n  camera.aspect = window.innerWidth \u002F window.innerHeight;\n  camera.updateProjectionMatrix();\n  renderer.setSize(window.innerWidth, window.innerHeight);\n});\n```\n\n## Core Classes\n\n### Scene\n\nContainer for all 3D objects, lights, and cameras.\n\n```javascript\nconst scene = new THREE.Scene();\nscene.background = new THREE.Color(0x000000); \u002F\u002F Solid color\nscene.background = texture; \u002F\u002F Skybox texture\nscene.background = cubeTexture; \u002F\u002F Cubemap\nscene.environment = envMap; \u002F\u002F Environment map for PBR\nscene.fog = new THREE.Fog(0xffffff, 1, 100); \u002F\u002F Linear fog\nscene.fog = new THREE.FogExp2(0xffffff, 0.02); \u002F\u002F Exponential fog\n```\n\n### Cameras\n\n**PerspectiveCamera** - Most common, simulates human eye.\n\n```javascript\n\u002F\u002F PerspectiveCamera(fov, aspect, near, far)\nconst camera = new THREE.PerspectiveCamera(\n  75, \u002F\u002F Field of view (degrees)\n  window.innerWidth \u002F window.innerHeight, \u002F\u002F Aspect ratio\n  0.1, \u002F\u002F Near clipping plane\n  1000, \u002F\u002F Far clipping plane\n);\n\ncamera.position.set(0, 5, 10);\ncamera.lookAt(0, 0, 0);\ncamera.updateProjectionMatrix(); \u002F\u002F Call after changing fov, aspect, near, far\n```\n\n**OrthographicCamera** - No perspective distortion, good for 2D\u002Fisometric.\n\n```javascript\n\u002F\u002F OrthographicCamera(left, right, top, bottom, near, far)\nconst aspect = window.innerWidth \u002F window.innerHeight;\nconst frustumSize = 10;\nconst camera = new THREE.OrthographicCamera(\n  (frustumSize * aspect) \u002F -2,\n  (frustumSize * aspect) \u002F 2,\n  frustumSize \u002F 2,\n  frustumSize \u002F -2,\n  0.1,\n  1000,\n);\n```\n\n**ArrayCamera** - Multiple viewports with sub-cameras.\n\n```javascript\nconst cameras = [];\nfor (let i = 0; i \u003C 4; i++) {\n  const subcamera = new THREE.PerspectiveCamera(40, 1, 0.1, 100);\n  subcamera.viewport = new THREE.Vector4(\n    Math.floor(i % 2) * 0.5,\n    Math.floor(i \u002F 2) * 0.5,\n    0.5,\n    0.5,\n  );\n  cameras.push(subcamera);\n}\nconst arrayCamera = new THREE.ArrayCamera(cameras);\n```\n\n**CubeCamera** - Renders environment maps for reflections.\n\n```javascript\nconst cubeRenderTarget = new THREE.WebGLCubeRenderTarget(256);\nconst cubeCamera = new THREE.CubeCamera(0.1, 1000, cubeRenderTarget);\nscene.add(cubeCamera);\n\n\u002F\u002F Use for reflections\nmaterial.envMap = cubeRenderTarget.texture;\n\n\u002F\u002F Update each frame (expensive!)\ncubeCamera.position.copy(reflectiveMesh.position);\ncubeCamera.update(renderer, scene);\n```\n\n### WebGLRenderer\n\n```javascript\nconst renderer = new THREE.WebGLRenderer({\n  canvas: document.querySelector(\"#canvas\"), \u002F\u002F Optional existing canvas\n  antialias: true, \u002F\u002F Smooth edges\n  alpha: true, \u002F\u002F Transparent background\n  powerPreference: \"high-performance\", \u002F\u002F GPU hint\n  preserveDrawingBuffer: true, \u002F\u002F For screenshots\n});\n\nrenderer.setSize(width, height);\nrenderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));\n\n\u002F\u002F Tone mapping\nrenderer.toneMapping = THREE.ACESFilmicToneMapping;\nrenderer.toneMappingExposure = 1.0;\n\n\u002F\u002F Color space (Three.js r152+)\nrenderer.outputColorSpace = THREE.SRGBColorSpace;\n\n\u002F\u002F Shadows\nrenderer.shadowMap.enabled = true;\nrenderer.shadowMap.type = THREE.PCFSoftShadowMap;\n\n\u002F\u002F Clear color\nrenderer.setClearColor(0x000000, 1);\n\n\u002F\u002F Render\nrenderer.render(scene, camera);\n```\n\n### Object3D\n\nBase class for all 3D objects. Mesh, Group, Light, Camera all extend Object3D.\n\n```javascript\nconst obj = new THREE.Object3D();\n\n\u002F\u002F Transform\nobj.position.set(x, y, z);\nobj.rotation.set(x, y, z); \u002F\u002F Euler angles (radians)\nobj.quaternion.set(x, y, z, w); \u002F\u002F Quaternion rotation\nobj.scale.set(x, y, z);\n\n\u002F\u002F Local vs World transforms\nobj.getWorldPosition(targetVector);\nobj.getWorldQuaternion(targetQuaternion);\nobj.getWorldDirection(targetVector);\n\n\u002F\u002F Hierarchy\nobj.add(child);\nobj.remove(child);\nobj.parent;\nobj.children;\n\n\u002F\u002F Visibility\nobj.visible = false;\n\n\u002F\u002F Layers (for selective rendering\u002Fraycasting)\nobj.layers.set(1);\nobj.layers.enable(2);\nobj.layers.disable(0);\n\n\u002F\u002F Traverse hierarchy\nobj.traverse((child) => {\n  if (child.isMesh) child.material.color.set(0xff0000);\n});\n\n\u002F\u002F Matrix updates\nobj.matrixAutoUpdate = true; \u002F\u002F Default: auto-update matrices\nobj.updateMatrix(); \u002F\u002F Manual matrix update\nobj.updateMatrixWorld(true); \u002F\u002F Update world matrix recursively\n```\n\n### Group\n\nEmpty container for organizing objects.\n\n```javascript\nconst group = new THREE.Group();\ngroup.add(mesh1);\ngroup.add(mesh2);\nscene.add(group);\n\n\u002F\u002F Transform entire group\ngroup.position.x = 5;\ngroup.rotation.y = Math.PI \u002F 4;\n```\n\n### Mesh\n\nCombines geometry and material.\n\n```javascript\nconst mesh = new THREE.Mesh(geometry, material);\n\n\u002F\u002F Multiple materials (one per geometry group)\nconst mesh = new THREE.Mesh(geometry, [material1, material2]);\n\n\u002F\u002F Useful properties\nmesh.geometry;\nmesh.material;\nmesh.castShadow = true;\nmesh.receiveShadow = true;\n\n\u002F\u002F Frustum culling\nmesh.frustumCulled = true; \u002F\u002F Default: skip if outside camera view\n\n\u002F\u002F Render order\nmesh.renderOrder = 10; \u002F\u002F Higher = rendered later\n```\n\n## Coordinate System\n\nThree.js uses a **right-handed coordinate system**:\n\n- **+X** points right\n- **+Y** points up\n- **+Z** points toward viewer (out of screen)\n\n```javascript\n\u002F\u002F Axes helper\nconst axesHelper = new THREE.AxesHelper(5);\nscene.add(axesHelper); \u002F\u002F Red=X, Green=Y, Blue=Z\n```\n\n## Math Utilities\n\n### Vector3\n\n```javascript\nconst v = new THREE.Vector3(x, y, z);\nv.set(x, y, z);\nv.copy(otherVector);\nv.clone();\n\n\u002F\u002F Operations (modify in place)\nv.add(v2);\nv.sub(v2);\nv.multiply(v2);\nv.multiplyScalar(2);\nv.divideScalar(2);\nv.normalize();\nv.negate();\nv.clamp(min, max);\nv.lerp(target, alpha);\n\n\u002F\u002F Calculations (return new value)\nv.length();\nv.lengthSq(); \u002F\u002F Faster than length()\nv.distanceTo(v2);\nv.dot(v2);\nv.cross(v2); \u002F\u002F Modifies v\nv.angleTo(v2);\n\n\u002F\u002F Transform\nv.applyMatrix4(matrix);\nv.applyQuaternion(q);\nv.project(camera); \u002F\u002F World to NDC\nv.unproject(camera); \u002F\u002F NDC to world\n```\n\n### Matrix4\n\n```javascript\nconst m = new THREE.Matrix4();\nm.identity();\nm.copy(other);\nm.clone();\n\n\u002F\u002F Build transforms\nm.makeTranslation(x, y, z);\nm.makeRotationX(theta);\nm.makeRotationY(theta);\nm.makeRotationZ(theta);\nm.makeRotationFromQuaternion(q);\nm.makeScale(x, y, z);\n\n\u002F\u002F Compose\u002Fdecompose\nm.compose(position, quaternion, scale);\nm.decompose(position, quaternion, scale);\n\n\u002F\u002F Operations\nm.multiply(m2); \u002F\u002F m = m * m2\nm.premultiply(m2); \u002F\u002F m = m2 * m\nm.invert();\nm.transpose();\n\n\u002F\u002F Camera matrices\nm.makePerspective(left, right, top, bottom, near, far);\nm.makeOrthographic(left, right, top, bottom, near, far);\nm.lookAt(eye, target, up);\n```\n\n### Quaternion\n\n```javascript\nconst q = new THREE.Quaternion();\nq.setFromEuler(euler);\nq.setFromAxisAngle(axis, angle);\nq.setFromRotationMatrix(matrix);\n\nq.multiply(q2);\nq.slerp(target, t); \u002F\u002F Spherical interpolation\nq.normalize();\nq.invert();\n```\n\n### Euler\n\n```javascript\nconst euler = new THREE.Euler(x, y, z, \"XYZ\"); \u002F\u002F Order matters!\neuler.setFromQuaternion(q);\neuler.setFromRotationMatrix(m);\n\n\u002F\u002F Rotation orders: 'XYZ', 'YXZ', 'ZXY', 'XZY', 'YZX', 'ZYX'\n```\n\n### Color\n\n```javascript\nconst color = new THREE.Color(0xff0000);\nconst color = new THREE.Color(\"red\");\nconst color = new THREE.Color(\"rgb(255, 0, 0)\");\nconst color = new THREE.Color(\"#ff0000\");\n\ncolor.setHex(0x00ff00);\ncolor.setRGB(r, g, b); \u002F\u002F 0-1 range\ncolor.setHSL(h, s, l); \u002F\u002F 0-1 range\n\ncolor.lerp(otherColor, alpha);\ncolor.multiply(otherColor);\ncolor.multiplyScalar(2);\n```\n\n### MathUtils\n\n```javascript\nTHREE.MathUtils.clamp(value, min, max);\nTHREE.MathUtils.lerp(start, end, alpha);\nTHREE.MathUtils.mapLinear(value, inMin, inMax, outMin, outMax);\nTHREE.MathUtils.degToRad(degrees);\nTHREE.MathUtils.radToDeg(radians);\nTHREE.MathUtils.randFloat(min, max);\nTHREE.MathUtils.randInt(min, max);\nTHREE.MathUtils.smoothstep(x, min, max);\nTHREE.MathUtils.smootherstep(x, min, max);\n```\n\n## Common Patterns\n\n### Proper Cleanup\n\n```javascript\nfunction dispose() {\n  \u002F\u002F Dispose geometries\n  mesh.geometry.dispose();\n\n  \u002F\u002F Dispose materials\n  if (Array.isArray(mesh.material)) {\n    mesh.material.forEach((m) => m.dispose());\n  } else {\n    mesh.material.dispose();\n  }\n\n  \u002F\u002F Dispose textures\n  texture.dispose();\n\n  \u002F\u002F Remove from scene\n  scene.remove(mesh);\n\n  \u002F\u002F Dispose renderer\n  renderer.dispose();\n}\n```\n\n### Timer and Clock for Animation\n\n**Timer (recommended in r183)** - pauses when tab is hidden, cleaner API:\n\n```javascript\nconst timer = new THREE.Timer();\n\nrenderer.setAnimationLoop(() => {\n  timer.update();\n  const delta = timer.getDelta();\n  const elapsed = timer.getElapsed();\n\n  mesh.rotation.y += delta * 0.5;\n  renderer.render(scene, camera);\n});\n```\n\n**Clock (legacy, still works):**\n\n```javascript\nconst clock = new THREE.Clock();\n\nfunction animate() {\n  const delta = clock.getDelta(); \u002F\u002F Time since last frame (seconds)\n  const elapsed = clock.getElapsedTime(); \u002F\u002F Total time (seconds)\n\n  mesh.rotation.y += delta * 0.5; \u002F\u002F Consistent speed regardless of framerate\n\n  requestAnimationFrame(animate);\n  renderer.render(scene, camera);\n}\n```\n\n### Animation Loop\n\nPrefer `renderer.setAnimationLoop()` over manual `requestAnimationFrame`. It handles WebXR compatibility and is the standard Three.js pattern:\n\n```javascript\nrenderer.setAnimationLoop(() => {\n  controls.update();\n  renderer.render(scene, camera);\n});\n```\n\n### Responsive Canvas\n\n```javascript\nfunction onWindowResize() {\n  const width = window.innerWidth;\n  const height = window.innerHeight;\n\n  camera.aspect = width \u002F height;\n  camera.updateProjectionMatrix();\n\n  renderer.setSize(width, height);\n  renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));\n}\nwindow.addEventListener(\"resize\", onWindowResize);\n```\n\n### Loading Manager\n\n```javascript\nconst manager = new THREE.LoadingManager();\n\nmanager.onStart = (url, loaded, total) => console.log(\"Started loading\");\nmanager.onLoad = () => console.log(\"All loaded\");\nmanager.onProgress = (url, loaded, total) => console.log(`${loaded}\u002F${total}`);\nmanager.onError = (url) => console.error(`Error loading ${url}`);\n\nconst textureLoader = new THREE.TextureLoader(manager);\nconst gltfLoader = new GLTFLoader(manager);\n```\n\n## Performance Tips\n\n1. **Limit draw calls**: Merge geometries, use instancing, atlas textures\n2. **Frustum culling**: Enabled by default, ensure bounding boxes are correct\n3. **LOD (Level of Detail)**: Use `THREE.LOD` for distance-based mesh switching\n4. **Object pooling**: Reuse objects instead of creating\u002Fdestroying\n5. **Avoid `getWorldPosition` in loops**: Cache results\n\n```javascript\n\u002F\u002F Merge static geometries\nimport { mergeGeometries } from \"three\u002Fexamples\u002Fjsm\u002Futils\u002FBufferGeometryUtils.js\";\nconst merged = mergeGeometries([geo1, geo2, geo3]);\n\n\u002F\u002F LOD\nconst lod = new THREE.LOD();\nlod.addLevel(highDetailMesh, 0);\nlod.addLevel(medDetailMesh, 50);\nlod.addLevel(lowDetailMesh, 100);\nscene.add(lod);\n```\n\n## WebGPU Renderer (r183)\n\nThree.js includes an experimental WebGPU renderer as an alternative to WebGL:\n\n```javascript\nimport { WebGPURenderer } from \"three\u002Faddons\u002Frenderers\u002Fwebgpu\u002FWebGPURenderer.js\";\n\nconst renderer = new WebGPURenderer({ antialias: true });\nawait renderer.init();\nrenderer.setSize(window.innerWidth, window.innerHeight);\ndocument.body.appendChild(renderer.domElement);\n```\n\nWebGPU uses TSL (Three.js Shading Language) instead of GLSL. The WebGL renderer remains the default and is fully supported.\n\n## See Also\n\n- `threejs-geometry` - Geometry creation and manipulation\n- `threejs-materials` - Material types and properties\n- `threejs-lighting` - Light types and shadows\n\n## Limitations\n- Use this skill only when the task clearly matches the scope described above.\n- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.\n- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.\n","# Three.js Fundamentals\n\n## When to Use\n- You need to set up the core structure of a Three.js scene.\n- The task involves scenes, cameras, renderers, transforms, resize handling, or object hierarchy basics.\n- You want foundational Three.js guidance before working on specialized topics like shaders or post-processing.\n\n## Quick Start\n\n```javascript\nimport * as THREE from \"three\";\n\n\u002F\u002F Create scene, camera, renderer\nconst scene = new THREE.Scene();\nconst camera = new THREE.PerspectiveCamera(\n  75,\n  window.innerWidth \u002F window.innerHeight,\n  0.1,\n  1000,\n);\nconst renderer = new THREE.WebGLRenderer({ antialias: true });\n\nrenderer.setSize(window.innerWidth, window.innerHeight);\nrenderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));\ndocument.body.appendChild(renderer.domElement);\n\n\u002F\u002F Add a mesh\nconst geometry = new THREE.BoxGeometry(1, 1, 1);\nconst material = new THREE.MeshStandardMaterial({ color: 0x00ff00 });\nconst cube = new THREE.Mesh(geometry, material);\nscene.add(cube);\n\n\u002F\u002F Add light\nscene.add(new THREE.AmbientLight(0xffffff, 0.5));\nconst dirLight = new THREE.DirectionalLight(0xffffff, 1);\ndirLight.position.set(5, 5, 5);\nscene.add(dirLight);\n\ncamera.position.z = 5;\n\n\u002F\u002F Animation loop\nfunction animate() {\n  requestAnimationFrame(animate);\n  cube.rotation.x += 0.01;\n  cube.rotation.y += 0.01;\n  renderer.render(scene, camera);\n}\nanimate();\n\n\u002F\u002F Handle resize\nwindow.addEventListener(\"resize\", () => {\n  camera.aspect = window.innerWidth \u002F window.innerHeight;\n  camera.updateProjectionMatrix();\n  renderer.setSize(window.innerWidth, window.innerHeight);\n});\n```\n\n## Core Classes\n\n### Scene\n\nContainer for all 3D objects, lights, and cameras.\n\n```javascript\nconst scene = new THREE.Scene();\nscene.background = new THREE.Color(0x000000); \u002F\u002F Solid color\nscene.background = texture; \u002F\u002F Skybox texture\nscene.background = cubeTexture; \u002F\u002F Cubemap\nscene.environment = envMap; \u002F\u002F Environment map for PBR\nscene.fog = new THREE.Fog(0xffffff, 1, 100); \u002F\u002F Linear fog\nscene.fog = new THREE.FogExp2(0xffffff, 0.02); \u002F\u002F Exponential fog\n```\n\n### Cameras\n\n**PerspectiveCamera** - Most common, simulates human eye.\n\n```javascript\n\u002F\u002F PerspectiveCamera(fov, aspect, near, far)\nconst camera = new THREE.PerspectiveCamera(\n  75, \u002F\u002F Field of view (degrees)\n  window.innerWidth \u002F window.innerHeight, \u002F\u002F Aspect ratio\n  0.1, \u002F\u002F Near clipping plane\n  1000, \u002F\u002F Far clipping plane\n);\n\ncamera.position.set(0, 5, 10);\ncamera.lookAt(0, 0, 0);\ncamera.updateProjectionMatrix(); \u002F\u002F Call after changing fov, aspect, near, far\n```\n\n**OrthographicCamera** - No perspective distortion, good for 2D\u002Fisometric.\n\n```javascript\n\u002F\u002F OrthographicCamera(left, right, top, bottom, near, far)\nconst aspect = window.innerWidth \u002F window.innerHeight;\nconst frustumSize = 10;\nconst camera = new THREE.OrthographicCamera(\n  (frustumSize * aspect) \u002F -2,\n  (frustumSize * aspect) \u002F 2,\n  frustumSize \u002F 2,\n  frustumSize \u002F -2,\n  0.1,\n  1000,\n);\n```\n\n**ArrayCamera** - Multiple viewports with sub-cameras.\n\n```javascript\nconst cameras = [];\nfor (let i = 0; i \u003C 4; i++) {\n  const subcamera = new THREE.PerspectiveCamera(40, 1, 0.1, 100);\n  subcamera.viewport = new THREE.Vector4(\n    Math.floor(i % 2) * 0.5,\n    Math.floor(i \u002F 2) * 0.5,\n    0.5,\n    0.5,\n  );\n  cameras.push(subcamera);\n}\nconst arrayCamera = new THREE.ArrayCamera(cameras);\n```\n\n**CubeCamera** - Renders environment maps for reflections.\n\n```javascript\nconst cubeRenderTarget = new THREE.WebGLCubeRenderTarget(256);\nconst cubeCamera = new THREE.CubeCamera(0.1, 1000, cubeRenderTarget);\nscene.add(cubeCamera);\n\n\u002F\u002F Use for reflections\nmaterial.envMap = cubeRenderTarget.texture;\n\n\u002F\u002F Update each frame (expensive!)\ncubeCamera.position.copy(reflectiveMesh.position);\ncubeCamera.update(renderer, scene);\n```\n\n### WebGLRenderer\n\n```javascript\nconst renderer = new THREE.WebGLRenderer({\n  canvas: document.querySelector(\"#canvas\"), \u002F\u002F Optional existing canvas\n  antialias: true, \u002F\u002F Smooth edges\n  alpha: true, \u002F\u002F Transparent background\n  powerPreference: \"high-performance\", \u002F\u002F GPU hint\n  preserveDrawingBuffer: true, \u002F\u002F For screenshots\n});\n\nrenderer.setSize(width, height);\nrenderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));\n\n\u002F\u002F Tone mapping\nrenderer.toneMapping = THREE.ACESFilmicToneMapping;\nrenderer.toneMappingExposure = 1.0;\n\n\u002F\u002F Color space (Three.js r152+)\nrenderer.outputColorSpace = THREE.SRGBColorSpace;\n\n\u002F\u002F Shadows\nrenderer.shadowMap.enabled = true;\nrenderer.shadowMap.type = THREE.PCFSoftShadowMap;\n\n\u002F\u002F Clear color\nrenderer.setClearColor(0x000000, 1);\n\n\u002F\u002F Render\nrenderer.render(scene, camera);\n```\n\n### Object3D\n\nBase class for all 3D objects. Mesh, Group, Light, Camera all extend Object3D.\n\n```javascript\nconst obj = new THREE.Object3D();\n\n\u002F\u002F Transform\nobj.position.set(x, y, z);\nobj.rotation.set(x, y, z); \u002F\u002F Euler angles (radians)\nobj.quaternion.set(x, y, z, w); \u002F\u002F Quaternion rotation\nobj.scale.set(x, y, z);\n\n\u002F\u002F Local vs World transforms\nobj.getWorldPosition(targetVector);\nobj.getWorldQuaternion(targetQuaternion);\nobj.getWorldDirection(targetVector);\n\n\u002F\u002F Hierarchy\nobj.add(child);\nobj.remove(child);\nobj.parent;\nobj.children;\n\n\u002F\u002F Visibility\nobj.visible = false;\n\n\u002F\u002F Layers (for selective rendering\u002Fraycasting)\nobj.layers.set(1);\nobj.layers.enable(2);\nobj.layers.disable(0);\n\n\u002F\u002F Traverse hierarchy\nobj.traverse((child) => {\n  if (child.isMesh) child.material.color.set(0xff0000);\n});\n\n\u002F\u002F Matrix updates\nobj.matrixAutoUpdate = true; \u002F\u002F Default: auto-update matrices\nobj.updateMatrix(); \u002F\u002F Manual matrix update\nobj.updateMatrixWorld(true); \u002F\u002F Update world matrix recursively\n```\n\n### Group\n\nEmpty container for organizing objects.\n\n```javascript\nconst group = new THREE.Group();\ngroup.add(mesh1);\ngroup.add(mesh2);\nscene.add(group);\n\n\u002F\u002F Transform entire group\ngroup.position.x = 5;\ngroup.rotation.y = Math.PI \u002F 4;\n```\n\n### Mesh\n\nCombines geometry and material.\n\n```javascript\nconst mesh = new THREE.Mesh(geometry, material);\n\n\u002F\u002F Multiple materials (one per geometry group)\nconst mesh = new THREE.Mesh(geometry, [material1, material2]);\n\n\u002F\u002F Useful properties\nmesh.geometry;\nmesh.material;\nmesh.castShadow = true;\nmesh.receiveShadow = true;\n\n\u002F\u002F Frustum culling\nmesh.frustumCulled = true; \u002F\u002F Default: skip if outside camera view\n\n\u002F\u002F Render order\nmesh.renderOrder = 10; \u002F\u002F Higher = rendered later\n```\n\n## Coordinate System\n\nThree.js uses a **right-handed coordinate system**:\n\n- **+X** points right\n- **+Y** points up\n- **+Z** points toward viewer (out of screen)\n\n```javascript\n\u002F\u002F Axes helper\nconst axesHelper = new THREE.AxesHelper(5);\nscene.add(axesHelper); \u002F\u002F Red=X, Green=Y, Blue=Z\n```\n\n## Math Utilities\n\n### Vector3\n\n```javascript\nconst v = new THREE.Vector3(x, y, z);\nv.set(x, y, z);\nv.copy(otherVector);\nv.clone();\n\n\u002F\u002F Operations (modify in place)\nv.add(v2);\nv.sub(v2);\nv.multiply(v2);\nv.multiplyScalar(2);\nv.divideScalar(2);\nv.normalize();\nv.negate();\nv.clamp(min, max);\nv.lerp(target, alpha);\n\n\u002F\u002F Calculations (return new value)\nv.length();\nv.lengthSq(); \u002F\u002F Faster than length()\nv.distanceTo(v2);\nv.dot(v2);\nv.cross(v2); \u002F\u002F Modifies v\nv.angleTo(v2);\n\n\u002F\u002F Transform\nv.applyMatrix4(matrix);\nv.applyQuaternion(q);\nv.project(camera); \u002F\u002F World to NDC\nv.unproject(camera); \u002F\u002F NDC to world\n```\n\n### Matrix4\n\n```javascript\nconst m = new THREE.Matrix4();\nm.identity();\nm.copy(other);\nm.clone();\n\n\u002F\u002F Build transforms\nm.makeTranslation(x, y, z);\nm.makeRotationX(theta);\nm.makeRotationY(theta);\nm.makeRotationZ(theta);\nm.makeRotationFromQuaternion(q);\nm.makeScale(x, y, z);\n\n\u002F\u002F Compose\u002Fdecompose\nm.compose(position, quaternion, scale);\nm.decompose(position, quaternion, scale);\n\n\u002F\u002F Operations\nm.multiply(m2); \u002F\u002F m = m * m2\nm.premultiply(m2); \u002F\u002F m = m2 * m\nm.invert();\nm.transpose();\n\n\u002F\u002F Camera matrices\nm.makePerspective(left, right, top, bottom, near, far);\nm.makeOrthographic(left, right, top, bottom, near, far);\nm.lookAt(eye, target, up);\n```\n\n### Quaternion\n\n```javascript\nconst q = new THREE.Quaternion();\nq.setFromEuler(euler);\nq.setFromAxisAngle(axis, angle);\nq.setFromRotationMatrix(matrix);\n\nq.multiply(q2);\nq.slerp(target, t); \u002F\u002F Spherical interpolation\nq.normalize();\nq.invert();\n```\n\n### Euler\n\n```javascript\nconst euler = new THREE.Euler(x, y, z, \"XYZ\"); \u002F\u002F Order matters!\neuler.setFromQuaternion(q);\neuler.setFromRotationMatrix(m);\n\n\u002F\u002F Rotation orders: 'XYZ', 'YXZ', 'ZXY', 'XZY', 'YZX', 'ZYX'\n```\n\n### Color\n\n```javascript\nconst color = new THREE.Color(0xff0000);\nconst color = new THREE.Color(\"red\");\nconst color = new THREE.Color(\"rgb(255, 0, 0)\");\nconst color = new THREE.Color(\"#ff0000\");\n\ncolor.setHex(0x00ff00);\ncolor.setRGB(r, g, b); \u002F\u002F 0-1 range\ncolor.setHSL(h, s, l); \u002F\u002F 0-1 range\n\ncolor.lerp(otherColor, alpha);\ncolor.multiply(otherColor);\ncolor.multiplyScalar(2);\n```\n\n### MathUtils\n\n```javascript\nTHREE.MathUtils.clamp(value, min, max);\nTHREE.MathUtils.lerp(start, end, alpha);\nTHREE.MathUtils.mapLinear(value, inMin, inMax, outMin, outMax);\nTHREE.MathUtils.degToRad(degrees);\nTHREE.MathUtils.radToDeg(radians);\nTHREE.MathUtils.randFloat(min, max);\nTHREE.MathUtils.randInt(min, max);\nTHREE.MathUtils.smoothstep(x, min, max);\nTHREE.MathUtils.smootherstep(x, min, max);\n```\n\n## Common Patterns\n\n### Proper Cleanup\n\n```javascript\nfunction dispose() {\n  \u002F\u002F Dispose geometries\n  mesh.geometry.dispose();\n\n  \u002F\u002F Dispose materials\n  if (Array.isArray(mesh.material)) {\n    mesh.material.forEach((m) => m.dispose());\n  } else {\n    mesh.material.dispose();\n  }\n\n  \u002F\u002F Dispose textures\n  texture.dispose();\n\n  \u002F\u002F Remove from scene\n  scene.remove(mesh);\n\n  \u002F\u002F Dispose renderer\n  renderer.dispose();\n}\n```\n\n### Timer and Clock for Animation\n\n**Timer (recommended in r183)** - pauses when tab is hidden, cleaner API:\n\n```javascript\nconst timer = new THREE.Timer();\n\nrenderer.setAnimationLoop(() => {\n  timer.update();\n  const delta = timer.getDelta();\n  const elapsed = timer.getElapsed();\n\n  mesh.rotation.y += delta * 0.5;\n  renderer.render(scene, camera);\n});\n```\n\n**Clock (legacy, still works):**\n\n```javascript\nconst clock = new THREE.Clock();\n\nfunction animate() {\n  const delta = clock.getDelta(); \u002F\u002F Time since last frame (seconds)\n  const elapsed = clock.getElapsedTime(); \u002F\u002F Total time (seconds)\n\n  mesh.rotation.y += delta * 0.5; \u002F\u002F Consistent speed regardless of framerate\n\n  requestAnimationFrame(animate);\n  renderer.render(scene, camera);\n}\n```\n\n### Animation Loop\n\nPrefer `renderer.setAnimationLoop()` over manual `requestAnimationFrame`. It handles WebXR compatibility and is the standard Three.js pattern:\n\n```javascript\nrenderer.setAnimationLoop(() => {\n  controls.update();\n  renderer.render(scene, camera);\n});\n```\n\n### Responsive Canvas\n\n```javascript\nfunction onWindowResize() {\n  const width = window.innerWidth;\n  const height = window.innerHeight;\n\n  camera.aspect = width \u002F height;\n  camera.updateProjectionMatrix();\n\n  renderer.setSize(width, height);\n  renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));\n}\nwindow.addEventListener(\"resize\", onWindowResize);\n```\n\n### Loading Manager\n\n```javascript\nconst manager = new THREE.LoadingManager();\n\nmanager.onStart = (url, loaded, total) => console.log(\"Started loading\");\nmanager.onLoad = () => console.log(\"All loaded\");\nmanager.onProgress = (url, loaded, total) => console.log(`${loaded}\u002F${total}`);\nmanager.onError = (url) => console.error(`Error loading ${url}`);\n\nconst textureLoader = new THREE.TextureLoader(manager);\nconst gltfLoader = new GLTFLoader(manager);\n```\n\n## Performance Tips\n\n1. **Limit draw calls**: Merge geometries, use instancing, atlas textures\n2. **Frustum culling**: Enabled by default, ensure bounding boxes are correct\n3. **LOD (Level of Detail)**: Use `THREE.LOD` for distance-based mesh switching\n4. **Object pooling**: Reuse objects instead of creating\u002Fdestroying\n5. **Avoid `getWorldPosition` in loops**: Cache results\n\n```javascript\n\u002F\u002F Merge static geometries\nimport { mergeGeometries } from \"three\u002Fexamples\u002Fjsm\u002Futils\u002FBufferGeometryUtils.js\";\nconst merged = mergeGeometries([geo1, geo2, geo3]);\n\n\u002F\u002F LOD\nconst lod = new THREE.LOD();\nlod.addLevel(highDetailMesh, 0);\nlod.addLevel(medDetailMesh, 50);\nlod.addLevel(lowDetailMesh, 100);\nscene.add(lod);\n```\n\n## WebGPU Renderer (r183)\n\nThree.js includes an experimental WebGPU renderer as an alternative to WebGL:\n\n```javascript\nimport { WebGPURenderer } from \"three\u002Faddons\u002Frenderers\u002Fwebgpu\u002FWebGPURenderer.js\";\n\nconst renderer = new WebGPURenderer({ antialias: true });\nawait renderer.init();\nrenderer.setSize(window.innerWidth, window.innerHeight);\ndocument.body.appendChild(renderer.domElement);\n```\n\nWebGPU uses TSL (Three.js Shading Language) instead of GLSL. The WebGL renderer remains the default and is fully supported.\n\n## See Also\n\n- `threejs-geometry` - Geometry creation and manipulation\n- `threejs-materials` - Material types and properties\n- `threejs-lighting` - Light types and shadows\n\n## Limitations\n- Use this skill only when the task clearly matches the scope described above.\n- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.\n- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.\n",{"name":5,"risk":24,"source":25,"description":7},"unknown","community","main","87afe6ce96220accf50a345dea46784c8c9f210e","YYC3-Skills-技能包\u002FYYC3-Skills-技能包-antigravity-awesome-skills\u002Fplugins\u002Fantigravity-awesome-skills-claude\u002Fskills\u002Fthreejs-fundamentals",0,"https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base","https:\u002F\u002Fkb.yyc3.top\u002F","https:\u002F\u002Fgithub.com\u002FYYC-Cube","万象归元于云枢 | 深栈智启新纪元","2026-11-10 10:37:32",{"source":8,"skillName":5,"commands":36,"prompt":46,"zipAvailable":47},[37,40,43],{"tool":38,"command":39},"npx","npx skills add YYC-Cube\u002FYYC3-Knowledge-Base --skill threejs-fundamentals",{"tool":41,"command":42},"bunx","bunx skills add YYC-Cube\u002FYYC3-Knowledge-Base --skill threejs-fundamentals",{"tool":44,"command":45},"pnpm","pnpm dlx skills add YYC-Cube\u002FYYC3-Knowledge-Base --skill threejs-fundamentals","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-Skills-技能包\u002FYYC3-Skills-技能包-antigravity-awesome-skills\u002Fplugins\u002Fantigravity-awesome-skills-claude\u002Fskills\u002Fthreejs-fundamentals\u002FSKILL.md",true,[],[50,57,64,71,78,85],{"skillNo":51,"name":52,"nameZh":6,"description":53,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":54,"categories":55,"keywords":56,"publishedAt":19},"01M7CTDWHERCXPQCP0K03A86AS","vercel-sandbox","Run agent-browser + Chrome inside Vercel Sandbox microVMs for browser automation from any Vercel-deployed app. Use when the user needs browser automation in a Vercel app (Next.js, SvelteKit, Nuxt, Remix, Astro, etc.), wants to run headless Chrome without binary size limits, needs persistent browser sessions across commands, or wants ephemeral isolated browser environments. Triggers include \"Vercel Sandbox browser\", \"microVM Chrome\", \"agent-browser in sandbox\", \"browser automation on Vercel\", or any task requiring Chrome in a Vercel Sandbox.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-WebSpec-Web标准\u002FYYC3-WebSpec-Web标准-standards\u002Fbrowser-agent\u002Fskills\u002Fvercel-sandbox\u002FSKILL.md",[],[],{"skillNo":58,"name":59,"nameZh":6,"description":60,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":61,"categories":62,"keywords":63,"publishedAt":19},"01M7CTD8D2BNJY54S65M47HEJA","slack","Interact with Slack workspaces using browser automation. Use when the user needs to check unread channels, navigate Slack, send messages, extract data, find information, search conversations, or automate any Slack task. Triggers include \"check my Slack\", \"what channels have unreads\", \"send a message to\", \"search Slack for\", \"extract from Slack\", \"find who said\", or any task requiring programmatic Slack interaction.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-WebSpec-Web标准\u002FYYC3-WebSpec-Web标准-standards\u002Fbrowser-agent\u002Fskills\u002Fslack\u002FSKILL.md",[],[],{"skillNo":65,"name":66,"nameZh":6,"description":67,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":68,"categories":69,"keywords":70,"publishedAt":19},"01M7CTCSSB8ZP3Q58C3YZDZK1W","electron","Automate Electron desktop apps (VS Code, Slack, Discord, Figma, Notion, Spotify, etc.) using agent-browser via Chrome DevTools Protocol. Use when the user needs to interact with an Electron app, automate a desktop app, connect to a running app, control a native app, or test an Electron application. Triggers include \"automate Slack app\", \"control VS Code\", \"interact with Discord app\", \"test this Electron app\", \"connect to desktop app\", or any task requiring automation of a native Electron application.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-WebSpec-Web标准\u002FYYC3-WebSpec-Web标准-standards\u002Fbrowser-agent\u002Fskills\u002Felectron\u002FSKILL.md",[],[],{"skillNo":72,"name":73,"nameZh":6,"description":74,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":75,"categories":76,"keywords":77,"publishedAt":19},"01M7CTCBJY76688V4DCZGWFHGQ","dogfood","Systematically explore and test a web application to find bugs, UX issues, and other problems. Use when asked to \"dogfood\", \"QA\", \"exploratory test\", \"find issues\", \"bug hunt\", \"test this app\u002Fsite\u002Fplatform\", or review the quality of a web application. Produces a structured report with full reproduction evidence -- step-by-step screenshots, repro videos, and detailed repro steps for every issue -- so findings can be handed directly to the responsible teams.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-WebSpec-Web标准\u002FYYC3-WebSpec-Web标准-standards\u002Fbrowser-agent\u002Fskills\u002Fdogfood\u002FSKILL.md",[],[],{"skillNo":79,"name":80,"nameZh":6,"description":81,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":82,"categories":83,"keywords":84,"publishedAt":19},"01M7CTC4H0FFGVEAQR9PA4GA1A","agent-browser","Browser automation CLI for AI agents. Use when the user needs to interact with websites, including navigating pages, filling forms, clicking buttons, taking screenshots, extracting data, testing web apps, or automating any browser task. Triggers include requests to \"open a website\", \"fill out a form\", \"click a button\", \"take a screenshot\", \"scrape data from a page\", \"test this web app\", \"login to a site\", \"automate browser actions\", or any task requiring programmatic web interaction.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-WebSpec-Web标准\u002FYYC3-WebSpec-Web标准-standards\u002Fbrowser-agent\u002Fskills\u002Fagent-browser\u002FSKILL.md",[],[],{"skillNo":86,"name":87,"nameZh":6,"description":88,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":89,"categories":90,"keywords":91,"publishedAt":19},"01M7CTBKVFYBG78FDSABSDJTTQ","shadcn","Manages shadcn components and projects — adding, searching, fixing, debugging, styling, and composing UI, including chat interfaces. Provides project context, component docs, and usage examples. Applies when working with shadcn\u002Fui, component registries, presets, --preset codes, or any project with a components.json file. Also triggers for \"shadcn init\", \"create an app with --preset\", \"switch to --preset\", and for building a design system or applying a DESIGN.md or brand spec to shadcn\u002Fui.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-UI-界面组件\u002FYYC3-UI-界面组件-ui\u002Fskills\u002Fshadcn\u002FSKILL.md",[],[]]