threejs-syntax-geometries

Create and manage Three.js BufferGeometry, built-in geometries, and InstancedMesh with correct GPU handling.

1|Updated Aug 20, 2023
One-click install
npx skills add https://github.com/imanlangaran/mini-projects --skill threejs-syntax-geometries-imanlangaran
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: threejs-syntax-geometries
Source: https://github.com/imanlangaran/mini-projects/tree/main/react/three-gsap/.claude/skills/threejs-syntax-geometries
Command: npx skills add https://github.com/imanlangaran/mini-projects --skill threejs-syntax-geometries-imanlangaran

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires three, and includes references (resource) components.

What problem does it solve? Working with Three.js geometry involves subtle pitfalls: forgetting needsUpdate on BufferAttribute, leaking GPU memory by skipping dispose(), rendering black meshes due to missing normals, or creating thousands of individual meshes instead of using InstancedMesh. This Skill provides the correct API signatures, parameters, and anti-patterns to avoid these mistakes. ## Core Features & Use Cases - Complete Geometry Reference: Covers BufferGeometry, BufferAttribute, all 21 built-in geometries, ExtrudeGeometry options, Shape path drawing, morph targets, and InterleavedBuffer. - InstancedMesh Guidance: Explains setMatrixAt, setColorAt, per-instance attributes, and performance thresholds for when to switch from individual meshes to instancing. - Anti-Pattern Prevention: Documents 11 common mistakes such as in-place transforms in animation loops, missing computeVertexNormals, and incorrect usage hints. - Use Case: When building a particle system or custom mesh in Three.js r160+, consult this Skill to write correct BufferAttribute code with proper disposal and update flags. ## Quick Start Use the threejs-syntax-geometries skill to create a custom indexed BufferGeometry with positions, UVs, and computed normals for a lit material.

Frequently Asked Questions about threejs-syntax-geometries

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create custom BufferGeometry in Three.js?

Create a BufferGeometry, set a position attribute with Float32BufferAttribute, optionally set an index buffer and UVs, then call computeVertexNormals for lighting. Always call computeBoundingSphere for frustum culling and dispose when removing the mesh.

When should I use InstancedMesh instead of individual meshes in Three.js?

Use InstancedMesh when rendering 100 or more copies of the same geometry, since it renders all instances in a single draw call. Below 10 instances, individual Mesh objects are fine; above 10,000, consider BatchedMesh or spatial subdivision.

Why is my Three.js mesh rendering black with MeshStandardMaterial?

The mesh renders black because the geometry lacks normal vectors required for lighting calculations. Call geometry.computeVertexNormals() after building custom geometry so lit materials can compute light interaction correctly.

Why does my BufferAttribute update not show on screen in Three.js?

Three.js does not automatically detect changes to typed arrays, so the GPU buffer stays stale. After modifying attribute data with setXYZ or direct array writes, set attribute.needsUpdate = true to re-upload the data.

Does Three.js free GPU memory when a geometry is garbage collected?

No, the JavaScript garbage collector only frees JS objects, not GPU-side vertex buffers. You must explicitly call geometry.dispose() when permanently removing geometry from the scene to avoid GPU memory leaks.

Should I use indexed or non-indexed geometry in Three.js?

Use indexed geometry for smooth-shaded meshes with shared vertices since it uses less memory and benefits from GPU vertex caching. Convert to non-indexed with toNonIndexed() only when you need per-face attributes like flat-shaded normals.