Community程式設計與開發github.com

cloudai-x/threejs-geometry

Three.js 幾何體建立 - 內建形狀、BufferGeometry、自訂幾何體、實例化。用於建立 3D 形狀、處理頂點、建構自訂網格,或透過實例化渲染進行最佳化。

threejs-geometry 是什麼?

此技能專注於 Three.js 中的幾何體建立,涵蓋從內建形狀到進階自訂幾何體的完整流程。它為開發者提供了 BufferGeometry 的操作指南,可用於處理頂點資料、建構複雜網格,並支援實例化渲染以提升大量物件的繪製效能。支援所有主流 Three.js 開發環境(如瀏覽器、Node.js),透過清晰的 API 範例與最佳實踐,協助使用者快速建立 3D 場景。此技能不僅簡化常見幾何體的創建,還深入探討頂點資料結構與自訂緩衝區的應用,適合從入門到進階的 3D 開發者使用。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/cloudai-x/threejs-skills/tree/main/skills/threejs-geometry

Installed? Explore more 程式設計與開發 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

threejs-geometry 是做什麼的?

Three.js 幾何體建立 - 內建形狀、BufferGeometry、自訂幾何體、實例化。用於建立 3D 形狀、處理頂點、建構自訂網格,或透過實例化渲染進行最佳化。

簡介

此技能提供使用 Three.js 建立幾何體的完整指南,涵蓋:

  • 使用內建形狀(如立方體、球體、圓柱體等)
  • 透過 BufferGeometry 建立自訂幾何體
  • 手動定義頂點、法線與 UV 座標
  • 使用 InstancedMesh 進行大量物件的實例化渲染

支援的平台

  • 瀏覽器:透過 CDN 或打包工具(如 Webpack、Vite)使用 Three.js
  • Node.js:使用 three npm 套件

核心功能

1. 建立內建形狀

import { BoxGeometry, SphereGeometry, CylinderGeometry } from 'three';

const box = new BoxGeometry(1, 1, 1);
const sphere = new SphereGeometry(1, 32, 16);
const cylinder = new CylinderGeometry(1, 1, 2, 16);

2. 自訂 BufferGeometry

可透過頂點陣列建立自訂幾何體:

import { BufferGeometry, Float32BufferAttribute } from 'three';

const geometry = new BufferGeometry();
const vertices = [
  -1.0, -1.0,  1.0,
   1.0, -1.0,  1.0,
   1.0,  1.0,  1.0,
];
geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
geometry.setIndex([0, 1, 2]);

3. 使用實例化渲染

適用於渲染大量相同幾何體:

import { InstancedMesh, Matrix4 } from 'three';

const mesh = new InstancedMesh(geometry, material, count);
const matrix = new Matrix4();
for (let i = 0; i < count; i++) {
  matrix.setPosition(x, y, z);
  mesh.setMatrixAt(i, matrix);
}
mesh.instanceMatrix.needsUpdate = true;

最佳實務

  • 使用 BufferGeometry 以獲得最佳效能
  • 調整細分數(segments)以平衡品質與效能
  • 對大量相同物件採用實例化渲染
  • 幾何體使用後進行 dispose() 以釋放記憶體

環境變數

  • THREE_GEOMETRY_DEBUG:設定為 true 以啟用除錯輸出

相關資源

Individual skills in this repo

This repo contains 9 individual skills — each has its own dedicated page.

cloudai-x/threejs-animation

Three.js animation - keyframe animation, skeletal animation, morph targets, animation mixing. Use when animating objects, playing GLTF animations, creating procedural motion, or blending animations.

cloudai-x/threejs-fundamentals

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.

cloudai-x/threejs-interaction

Three.js interaction - raycasting, controls, mouse/touch input, object selection. Use when handling user input, implementing click detection, adding camera controls, or creating interactive 3D experiences.

cloudai-x/threejs-lighting

Three.js lighting - light types, shadows, environment lighting. Use when adding lights, configuring shadows, setting up IBL, or optimizing lighting performance.

cloudai-x/threejs-loaders

Three.js asset loading - GLTF, textures, images, models, async patterns. Use when loading 3D models, textures, HDR environments, or managing loading progress.

cloudai-x/threejs-materials

Three.js materials - PBR, basic, phong, shader materials, material properties. Use when styling meshes, working with textures, creating custom shaders, or optimizing material performance.

cloudai-x/threejs-postprocessing

Three.js post-processing - EffectComposer, bloom, DOF, screen effects. Use when adding visual effects, color grading, blur, glow, or creating custom screen-space shaders.

cloudai-x/threejs-shaders

Three.js shaders - GLSL, ShaderMaterial, uniforms, custom effects. Use when creating custom visual effects, modifying vertices, writing fragment shaders, or extending built-in materials.

cloudai-x/threejs-textures

Three.js textures - texture types, UV mapping, environment maps, texture settings. Use when working with images, UV coordinates, cubemaps, HDR environments, or texture optimization.

相關技能