diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2013-04-16 03:12:40 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2013-04-16 03:12:40 +0400 |
commit | afb4b65167165613f177a531bd3d4dcb3649c1c6 (patch) | |
tree | 32e1446b5fc3ce8ec00fa0e8b9e0fcb2eedda127 /source/blender/bmesh/operators | |
parent | 638b084f824bc345468bc8e02422b5da65a641a7 (diff) |
Random number generator: replace a bunch of usage of the global random number
generator with a local one. It's not thread safe and will not give repeatable
results, so in most cases it should not be used.
Also fixes #34992 where the noise texture of a displacement modifier was not
properly random in opengl animation render, because the seed got reset to a
fixed value by an unrelated function while for final render it changed each
frame.
Diffstat (limited to 'source/blender/bmesh/operators')
-rw-r--r-- | source/blender/bmesh/operators/bmo_edgenet.c | 7 | ||||
-rw-r--r-- | source/blender/bmesh/operators/bmo_subdivide.c | 10 |
2 files changed, 11 insertions, 6 deletions
diff --git a/source/blender/bmesh/operators/bmo_edgenet.c b/source/blender/bmesh/operators/bmo_edgenet.c index a4af570ded0..b6d6af1e6da 100644 --- a/source/blender/bmesh/operators/bmo_edgenet.c +++ b/source/blender/bmesh/operators/bmo_edgenet.c @@ -362,6 +362,7 @@ static void init_rotsys(BMesh *bm, EdgeData *edata, VertData *vdata) BMEdge **edges = NULL; BLI_array_staticdeclare(edges, BM_DEFAULT_NGON_STACK_SIZE); BMVert *v; + RNG *rng; /* BMVert **verts = NULL; */ /* BLI_array_staticdeclare(verts, BM_DEFAULT_NGON_STACK_SIZE); */ /* UNUSE */ int i; @@ -427,7 +428,7 @@ static void init_rotsys(BMesh *bm, EdgeData *edata, VertData *vdata) copy_v3_v3(vdata[BM_elem_index_get(v2)].sco, vec1); } - BLI_srandom(0); + rng = BLI_rng_new_srandom(0); /* first, ensure no 0 or 180 angles between adjacent * (and that adjacent's adjacent) edges */ @@ -471,7 +472,7 @@ static void init_rotsys(BMesh *bm, EdgeData *edata, VertData *vdata) copy_v3_v3(cent, v->co); for (j = 0; j < 3; j++) { - float fac = (BLI_frand() - 0.5f) * size; + float fac = (BLI_rng_get_float(rng) - 0.5f) * size; cent[j] += fac; } @@ -488,6 +489,8 @@ static void init_rotsys(BMesh *bm, EdgeData *edata, VertData *vdata) } } + BLI_rng_free(rng); + copy_v3_v3(vdata[BM_elem_index_get(v)].offco, cent); //copy_v3_v3(v->co, cent); diff --git a/source/blender/bmesh/operators/bmo_subdivide.c b/source/blender/bmesh/operators/bmo_subdivide.c index aaa2914e6ae..8df52c3a6ae 100644 --- a/source/blender/bmesh/operators/bmo_subdivide.c +++ b/source/blender/bmesh/operators/bmo_subdivide.c @@ -831,11 +831,13 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) params.origkey = skey; if (params.use_fractal) { - BLI_srandom(seed); + RNG *rng = BLI_rng_new_srandom(seed); - params.fractal_ofs[0] = (float)BLI_drand() * 200.0f; - params.fractal_ofs[1] = (float)BLI_drand() * 200.0f; - params.fractal_ofs[2] = (float)BLI_drand() * 200.0f; + params.fractal_ofs[0] = BLI_rng_get_float(rng) * 200.0f; + params.fractal_ofs[1] = BLI_rng_get_float(rng) * 200.0f; + params.fractal_ofs[2] = BLI_rng_get_float(rng) * 200.0f; + + BLI_rng_free(rng); } BMO_slot_map_to_flag(bm, op->slots_in, "custom_patterns", |