From 47b6c332587ca45eddc98e75b3f563e2f17a0d47 Mon Sep 17 00:00:00 2001 From: Antonio Vazquez Date: Wed, 22 Jul 2020 11:16:45 +0200 Subject: GPencil: New BKE function for setting random vertex color This function is very handy for debug purposes. --- source/blender/blenkernel/BKE_gpencil_geom.h | 2 ++ source/blender/blenkernel/intern/gpencil_geom.c | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) (limited to 'source') diff --git a/source/blender/blenkernel/BKE_gpencil_geom.h b/source/blender/blenkernel/BKE_gpencil_geom.h index 1b22931483c..964764d99e7 100644 --- a/source/blender/blenkernel/BKE_gpencil_geom.h +++ b/source/blender/blenkernel/BKE_gpencil_geom.h @@ -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, diff --git a/source/blender/blenkernel/intern/gpencil_geom.c b/source/blender/blenkernel/intern/gpencil_geom.c index 0b965899689..5b7753428f7 100644 --- a/source/blender/blenkernel/intern/gpencil_geom.c +++ b/source/blender/blenkernel/intern/gpencil_geom.c @@ -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); + } +} /** \} */ -- cgit v1.2.3