Skip to content

Instantly share code, notes, and snippets.

@1502shivam-singh
Last active February 17, 2021 23:36
Show Gist options
  • Save 1502shivam-singh/3184d15dab135c4138bd962cae3c90f6 to your computer and use it in GitHub Desktop.
Save 1502shivam-singh/3184d15dab135c4138bd962cae3c90f6 to your computer and use it in GitHub Desktop.
Snippet to add a custom attribute to each vertex of buffergeometry in three.js
// Snippet to look under a buffergeometry and add a custom attribute for each vertex
let geometry = new THREE.PlaneBufferGeometry(5, 5, 5, 5); // for example
let count = geometry.attributes.position.length;
let arrSize = new THREE.BufferAttribute(new Float32Array(count), 1); // Here "1" is the places the attribute would take
for(let i=0;i<arrSize.count; i++){
arrSize.array[i] = Math.random(); // Assigning a random value as attribute here
}
geometry.addAttribute("aSize", arrSize, 1); // Access in shader later
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment