[Bf-blender-cvs] [b5dfa1108d1] greasepencil-object: Move random array function to BLI_rand

Antonio Vazquez noreply at git.blender.org
Sun May 20 11:20:02 CEST 2018


Commit: b5dfa1108d1f82f485fc6f0bddcbe677010ea1c4
Author: Antonio Vazquez
Date:   Sun May 20 11:17:43 2018 +0200
Branches: greasepencil-object
https://developer.blender.org/rBb5dfa1108d1f82f485fc6f0bddcbe677010ea1c4

Move random array function to BLI_rand

This function fills an array of random numbers

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

M	source/blender/blenlib/BLI_rand.h
M	source/blender/blenlib/intern/rand.c
M	source/blender/modifiers/intern/MOD_gpencil_util.c
M	source/blender/modifiers/intern/MOD_gpencil_util.h
M	source/blender/modifiers/intern/MOD_gpencilinstance.c

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

diff --git a/source/blender/blenlib/BLI_rand.h b/source/blender/blenlib/BLI_rand.h
index 69b23b2473f..c82017a1597 100644
--- a/source/blender/blenlib/BLI_rand.h
+++ b/source/blender/blenlib/BLI_rand.h
@@ -74,6 +74,9 @@ int     BLI_rand(void) ATTR_WARN_UNUSED_RESULT;
 float   BLI_frand(void) ATTR_WARN_UNUSED_RESULT;
 void    BLI_frand_unit_v3(float v[3]);
 
+/* fill an array with random numbers */
+void    BLI_array_frand(float *ar, int count, unsigned int seed);
+
 /** Return a pseudo-random (hash) float from an integer value */
 float	BLI_hash_frand(unsigned int seed) ATTR_WARN_UNUSED_RESULT;
 
diff --git a/source/blender/blenlib/intern/rand.c b/source/blender/blenlib/intern/rand.c
index 700524965f0..b731207b35b 100644
--- a/source/blender/blenlib/intern/rand.c
+++ b/source/blender/blenlib/intern/rand.c
@@ -288,6 +288,18 @@ void BLI_frand_unit_v3(float v[3])
 	BLI_rng_get_float_unit_v3(&theBLI_rng, v);
 }
 
+/* fill an array with random numbers */
+void BLI_array_frand(float *ar, int count, unsigned int seed)
+{
+	RNG rng;
+
+	BLI_rng_srandom(&rng, seed);
+
+	for (int i = 0; i < count; i++) {
+		ar[i] = BLI_rng_get_float(&rng);
+	}
+}
+
 float BLI_hash_frand(unsigned int seed)
 {
 	RNG rng;
diff --git a/source/blender/modifiers/intern/MOD_gpencil_util.c b/source/blender/modifiers/intern/MOD_gpencil_util.c
index eb233d514cd..b6284f2866e 100644
--- a/source/blender/modifiers/intern/MOD_gpencil_util.c
+++ b/source/blender/modifiers/intern/MOD_gpencil_util.c
@@ -54,14 +54,6 @@
 
 #include "MOD_gpencil_util.h"
 
-/* fill an array with random numbers */
-void gp_mod_fill_random_array(float *ar, int count)
-{
-	for (int i = 0; i < count; i++) {
-		ar[i] = BLI_frand();
-	}
-} 
-
 /* verify if valid layer and pass index */
 bool is_stroke_affected_by_modifier(
         Object *ob, char *mlayername, int mpassindex, int minpoints,
diff --git a/source/blender/modifiers/intern/MOD_gpencil_util.h b/source/blender/modifiers/intern/MOD_gpencil_util.h
index f36bf2232ab..50ac557042d 100644
--- a/source/blender/modifiers/intern/MOD_gpencil_util.h
+++ b/source/blender/modifiers/intern/MOD_gpencil_util.h
@@ -44,6 +44,4 @@ bool is_stroke_affected_by_modifier(
 
 float get_modifier_point_weight(struct MDeformVert *dvert, int inverse, int vindex);
 
-void gp_mod_fill_random_array(float *ar, int count);
-
 #endif  /* __MOD_GPENCIL_UTIL_H__ */
diff --git a/source/blender/modifiers/intern/MOD_gpencilinstance.c b/source/blender/modifiers/intern/MOD_gpencilinstance.c
index 26006bd9063..3521a40367e 100644
--- a/source/blender/modifiers/intern/MOD_gpencilinstance.c
+++ b/source/blender/modifiers/intern/MOD_gpencilinstance.c
@@ -37,6 +37,7 @@
 #include "DNA_gpencil_types.h"
 
 #include "BLI_blenlib.h"
+#include "BLI_rand.h"
 #include "BLI_math.h"
 #include "BLI_utildefines.h"
 
@@ -76,7 +77,7 @@ static void initData(ModifierData *md)
 	gpmd->flag |= GP_INSTANCE_MAKE_OBJECTS;
 	
 	/* fill random values */
-	gp_mod_fill_random_array(gpmd->rnd, 20);
+	BLI_array_frand(gpmd->rnd, 20, 1);
 	gpmd->rnd[0] = 1;
 }



More information about the Bf-blender-cvs mailing list