11
$\begingroup$

Say I have a mesh and I have colored the vertices using vertex paint, how can I then get the average of the colors or rather the color in the middle of the face or the color under the normal (shown below) using blender python?

enter image description here

$\endgroup$
  • 1
    $\begingroup$ I'm sort of guessing here but I think that point can be obtained using some barycentric coordinates function. $\endgroup$ – MarcClintDion Feb 25 '15 at 0:26
  • $\begingroup$ The "middle" of the face might be vague. See wikipedia for the different definitions of midpoints. I think you refer to the median / centroid according to the site linked. $\endgroup$ – pink vertex Feb 28 '15 at 19:35
  • $\begingroup$ Btw there exists a function to deal with barycentric coordinates -> mathutils.geometry.barycentric_transform though this is not needed for the median $\endgroup$ – pink vertex Feb 28 '15 at 19:35
8
$\begingroup$

In the middle of a face is an average color of all the vertices. For triangle this means:

Col_RGB = ((R1+R2+R3)/3, (G1+G2+G3)/3, (B1+B2+B3)/3)

Where each vert has color in form of (Rn, Gn, Bn) for n in (1..3).

$\endgroup$
  • 7
    $\begingroup$ It's cheaper to add all vertex vectors and divide once by the number of vertices. $\endgroup$ – CodeManX Feb 24 '15 at 22:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.