#Color change for indexed BufferGeometry faces

3 messages · Page 1 of 1 (latest)

silk crest
#

I use AR.js to view my models. I have a GLB model that is converted to BufferGeometry (indexed, see screenshot). I want to change the color of the faces. I am adding an array of colors to the geometry like this:
let colors = new Float32Array(node.geometry.attributes.position.count * 3);
for(index = 0; index < node.geometry.attributes.position.count; index+=3) {
ccolors[index] = 1.0;
colors[index+1] = 0.0;
colors[index+2] = 0.0;
}
node.geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) )
var material = new THREE.MeshBasicMaterial( { vertexColors: THREE.VertexColors, side: THREE.DoubleSide } );
node = new THREE.Mesh( node.geometry, material )
In theory, after that, the edges should turn red, but nothing happens. What am I doing wrong? I generally need to change the color of only some faces, not all.

minor raft
#

what three.js version?

#

if it's anything recent then you'd need vertexColors: true, a boolean rather than a constant