GPencil: New BKE function for setting random vertex color

This function is very handy for debug purposes.
This commit is contained in:
Antonio Vazquez 2020-07-22 11:16:45 +02:00
parent 8f658ec27c
commit 47b6c33258
2 changed files with 23 additions and 0 deletions

View File

@ -112,6 +112,8 @@ bool BKE_gpencil_stroke_shrink(struct bGPDstroke *gps, const float dist);
float BKE_gpencil_stroke_length(const struct bGPDstroke *gps, bool use_3d);
void BKE_gpencil_stroke_set_random_color(struct bGPDstroke *gps);
void BKE_gpencil_convert_mesh(struct Main *bmain,
struct Depsgraph *depsgraph,
struct Scene *scene,

View File

@ -33,6 +33,7 @@
#include "BLI_blenlib.h"
#include "BLI_ghash.h"
#include "BLI_hash.h"
#include "BLI_math_vector.h"
#include "BLI_polyfill_2d.h"
@ -2587,4 +2588,24 @@ void BKE_gpencil_point_coords_apply_with_mat4(bGPdata *gpd,
}
}
}
/**
* Set a random color to stroke using vertex color.
* \param gps: Stroke
*/
void BKE_gpencil_stroke_set_random_color(bGPDstroke *gps)
{
BLI_assert(gps->totpoints > 0);
float color[4] = {1.0f, 1.0f, 1.0f, 1.0f};
bGPDspoint *pt = &gps->points[0];
color[0] *= BLI_hash_int_01(BLI_hash_int_2d(gps->totpoints, pt->x));
color[1] *= BLI_hash_int_01(BLI_hash_int_2d(gps->totpoints, pt->y));
color[2] *= BLI_hash_int_01(BLI_hash_int_2d(gps->totpoints, pt->z));
for (int i = 0; i < gps->totpoints; i++) {
pt = &gps->points[i];
copy_v4_v4(pt->vert_color, color);
}
}
/** \} */