[Bf-blender-cvs] [47b6c332587] master: GPencil: New BKE function for setting random vertex color

Antonio Vazquez noreply at git.blender.org
Wed Jul 22 11:17:04 CEST 2020


Commit: 47b6c332587ca45eddc98e75b3f563e2f17a0d47
Author: Antonio Vazquez
Date:   Wed Jul 22 11:16:45 2020 +0200
Branches: master
https://developer.blender.org/rB47b6c332587ca45eddc98e75b3f563e2f17a0d47

GPencil: New BKE function for setting random vertex color

This function is very handy for debug purposes.

===================================================================

M	source/blender/blenkernel/BKE_gpencil_geom.h
M	source/blender/blenkernel/intern/gpencil_geom.c

===================================================================

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);
+  }
+}
 /** \} */



More information about the Bf-blender-cvs mailing list