Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically change Vertex Color in Three.js

Tags:

three.js

I am using Three.js 57 version. Now I am working in animation using JSONLoader. I got the animation successfully. But I want to update full vertex color of mesh for each frame in animation. Is this possibe in three.js

Thanks in Advance

like image 551
Crystal Avatar asked Sep 11 '25 21:09

Crystal


1 Answers

Vertex colors are currently not supported in CanvasRenderer.

Here is the pattern you need to follow for WebGLRenderer:

Set THREE.VertexColors when you create the material for the mesh;

material.vertexColors = THREE.VertexColors;

Also make sure that vertexColors are defined for each face of your geometry.

geometry.faces[ faceIndex ].vertexColors[ vertexIndex ] = new THREE.Color( 0xff0000 );

Then in your render loop, to change a vertex color, do this:

geometry.faces[ faceIndex ].vertexColors[ vertexIndex ].setHSL( Math.random(), 0.5, 0.5 );
mesh.geometry.colorsNeedUpdate = true;

three.js r.59

like image 72
WestLangley Avatar answered Sep 13 '25 14:09

WestLangley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!