Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorAntonio Vazquez <blendergit@gmail.com>2020-07-22 12:16:45 +0300
committerAntonio Vazquez <blendergit@gmail.com>2020-07-22 12:16:45 +0300
commit47b6c332587ca45eddc98e75b3f563e2f17a0d47 (patch)
treedb6787d5dc40d691a2a7fe74526364a45c8d85fc /source
parent8f658ec27c4fa51f9be8181eda063969fb14af84 (diff)
GPencil: New BKE function for setting random vertex color
This function is very handy for debug purposes.
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/BKE_gpencil_geom.h2
-rw-r--r--source/blender/blenkernel/intern/gpencil_geom.c21
2 files changed, 23 insertions, 0 deletions
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);
+ }
+}
/** \} */