Last active
February 17, 2021 23:36
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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