Skip to content

Instantly share code, notes, and snippets.

@adrienkaiser
Last active December 30, 2015 05:49
Show Gist options
  • Save adrienkaiser/7785600 to your computer and use it in GitHub Desktop.
Save adrienkaiser/7785600 to your computer and use it in GitHub Desktop.
Function to color vertices from an interpolation of its bones
void mesh::fill_color_from_weight(int nbBones)
{
srand(42);
std::vector<vec3> boneColor;
for(unsigned int b=0; b<nbBones; b++)
{
// float iBone = (float)b/(float)nbBones;
boneColor.push_back(vec3(float(rand())/RAND_MAX,float(rand())/RAND_MAX,float(rand())/RAND_MAX));
}
v_color.resize(v_vertices.size());
for(unsigned int k=0,N=v_vertices.size();k<N;++k)
{
vec3 color = vec3(0.0,0.0,0.0);
for (unsigned s = 0; s < 6; s+=1) // Pour tous les poids de skinning
{
int bone = v_skinning[k].bones[s]; // numero de l'os = ...
float weight = v_skinning[k].weights[s];// /sumweight; // poids de skinning = ...
color += weight * boneColor[bone];
}
v_color[k] = color;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment