How get the face sets color by the id

I’m want to replicate the algorithm to get the rgb value of the face sets.
I found the way to get the face set id
image
But now in the list I need the colors to have the right correspondance.

I can’t read c++ code of blender, I found some functions, but I cant replicate the right color.
There is a way to know how it works?

Hi,

If you want to use blender python API, I recommend to you to watch this video:

Title : Beginner Blender Python Tutorial: Assigning materials to faces of a mesh (Part 1)
By Victor Stepanov
See Here

I think this might help you.

P.

It is the same response of chatGPT.
Sorry, but I need the exact color of the Sculpt Face sets.
There are a lot of combination, for now I found the algorithm that generate the random seed, but the result is an int number, the most problably solution is that there is a list of color somewere.

As far as I can tell, this is not currently possible.
You can get the index, as you have already done, but it looks like the color is randomly assigned in C code, as you’ve said:

/* Returns the Face Set random color for rendering in the overlay given its ID and a color seed. */
#define GOLDEN_RATIO_CONJUGATE 0.618033988749895f
void BKE_paint_face_set_overlay_color_get(const int face_set, const int seed, uchar r_color[4])
{
  float rgba[4];
  float random_mod_hue = GOLDEN_RATIO_CONJUGATE * (face_set + (seed % 10));
  random_mod_hue = random_mod_hue - floorf(random_mod_hue);
  const float random_mod_sat = BLI_hash_int_01(face_set + seed + 1);
  const float random_mod_val = BLI_hash_int_01(face_set + seed + 2);
  hsv_to_rgb(random_mod_hue,
             0.6f + (random_mod_sat * 0.25f),
             1.0f - (random_mod_val * 0.35f),
             &rgba[0],
             &rgba[1],
             &rgba[2]);
  rgba_float_to_uchar(r_color, rgba);
}

It looks to me like it’s setting a 4 Vector float (RGBA) and then additional floats for randomizing hue, saturation and value.

2 Likes

Yes is the last piece of the puzzle, I hope it works, I have the function BLI_hash_int_01 and the seed.