Atlaslog
Atlaslog / three.js / API reference / BufferAttribute
three.js · API reference

BufferAttribute

Quick answer

BufferAttribute wraps a TypedArray and describes how many components belong to each vertex, powering position, normal, color, and uv data on a BufferGeometry. Use it to build custom meshes or update vertex data in place before re-uploading to the GPU. Set needsUpdate after writes so the next frame pushes the buffer to the GPU.

Last verified 2026-11-03 · three.js 0.160.0 · Cite this page
new THREE.BufferAttribute ( array , itemSize , normalized )
Key points
Example
const positions = new Float32Array([
  -1, -1, 0,
   1, -1, 0,
   0,  1, 0
]);

const colors = new Float32Array([
  1, 0.3, 0.2,
  0.2, 1, 0.5,
  0.3, 0.5, 1
]);

const geometry = new THREE.BufferGeometry();
geometry.setAttribute('position', new THREE.BufferAttribute(positions, 3));
geometry.setAttribute('color', new THREE.BufferAttribute(colors, 3));

const material = new THREE.MeshBasicMaterial({ vertexColors: true, side: THREE.DoubleSide });
const mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
const position = geometry.getAttribute('position');
position.setUsage(THREE.DynamicDrawUsage);

function animateWave(t) {
  for (let i = 0; i < position.count; i++) {
    position.setY(i, Math.sin(t * 0.002 + i * 0.35) * 0.6);
  }
  position.needsUpdate = true;   // 缺少这一行,画面不会变化
}
Notes
Runnable examplesChinese originalAll API references
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Cite this page

Atlaslog (2026). BufferAttribute. https://www.jingweizhi.com/en/three/api/buffer-attribute.html (accessed 2026-11-03).