[Bf-blender-cvs] [ef8c8a8] strand_gpu: Modified the guide strand creation operator to allow shorter-than-max strands.
Lukas Tönne
noreply at git.blender.org
Tue Jul 5 09:57:13 CEST 2016
Commit: ef8c8a8b665b50ee41b7310d15383c7353ca1292
Author: Lukas Tönne
Date: Sat Jul 2 14:16:46 2016 +0200
Branches: strand_gpu
https://developer.blender.org/rBef8c8a8b665b50ee41b7310d15383c7353ca1292
Modified the guide strand creation operator to allow shorter-than-max strands.
The guide strand format may change, but it should allow varying numbers of control
points.
===================================================================
M source/blender/blenkernel/intern/strands.c
M source/blender/gpu/intern/gpu_buffers.c
===================================================================
diff --git a/source/blender/blenkernel/intern/strands.c b/source/blender/blenkernel/intern/strands.c
index 0489831..53ed820 100644
--- a/source/blender/blenkernel/intern/strands.c
+++ b/source/blender/blenkernel/intern/strands.c
@@ -35,6 +35,7 @@
#include "BLI_kdtree.h"
#include "BLI_math.h"
+#include "BLI_rand.h"
#include "BKE_DerivedMesh.h"
#include "BKE_mesh_sample.h"
@@ -153,29 +154,24 @@ void BKE_strands_test_init(struct Strands *strands, struct DerivedMesh *scalp,
int totcurves, int maxverts,
unsigned int seed)
{
- const unsigned int totverts = totcurves * maxverts;
+ unsigned int seed2 = seed ^ 0xdeadbeef;
+ RNG *rng = BLI_rng_new(seed2);
MeshSampleGenerator *gen = BKE_mesh_sample_gen_surface_random(scalp, seed);
unsigned int i, k;
+ /* First generate all curves, to define vertex counts */
StrandCurve *curves = MEM_mallocN(sizeof(StrandCurve) * totcurves, "StrandCurve buffer");
- StrandVertex *verts = MEM_mallocN(sizeof(StrandVertex) * totverts, "StrandVertex buffer");
-
StrandCurve *c = curves;
- StrandVertex *v = verts;
- unsigned int verts_begin = 0;
+ unsigned int totverts = 0;
for (i = 0; i < totcurves; ++i, ++c) {
+ int num_verts = (int)(BLI_rng_get_float(rng) * (float)(maxverts + 1));
+ CLAMP(num_verts, 2, maxverts);
+
if (BKE_mesh_sample_generate(gen, &c->root)) {
- c->verts_begin = verts_begin;
- c->num_verts = maxverts;
-
- for (k = 0; k < c->num_verts; ++k, ++v) {
- v->co[0] = 0.0f;
- v->co[1] = 0.0f;
- v->co[2] = (c->num_verts > 1) ? (float)k / (c->num_verts - 1) : 0.0f;
- }
-
- verts_begin += c->num_verts;
+ c->verts_begin = totverts;
+ c->num_verts = num_verts;
+ totverts += num_verts;
}
else {
/* clear remaining samples */
@@ -184,6 +180,20 @@ void BKE_strands_test_init(struct Strands *strands, struct DerivedMesh *scalp,
}
}
+ /* Now generate vertices */
+ float segment_length = (maxverts > 1) ? 1.0f / (maxverts - 1) : 0.0f;
+
+ StrandVertex *verts = MEM_mallocN(sizeof(StrandVertex) * totverts, "StrandVertex buffer");
+ c = curves;
+ StrandVertex *v = verts;
+ for (i = 0; i < totcurves; ++i, ++c) {
+ for (k = 0; k < c->num_verts; ++k, ++v) {
+ v->co[0] = 0.0f;
+ v->co[1] = 0.0f;
+ v->co[2] = segment_length * k;
+ }
+ }
+
BKE_mesh_sample_free_generator(gen);
if (strands->curves)
@@ -194,6 +204,8 @@ void BKE_strands_test_init(struct Strands *strands, struct DerivedMesh *scalp,
strands->verts = verts;
strands->totcurves = totcurves;
strands->totverts = totverts;
+
+ BLI_rng_free(rng);
}
static void strands_calc_weights(const Strands *strands, struct DerivedMesh *scalp, StrandRoot *roots, int num_roots)
diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c
index abe59d2..3728119 100644
--- a/source/blender/gpu/intern/gpu_buffers.c
+++ b/source/blender/gpu/intern/gpu_buffers.c
@@ -2193,6 +2193,7 @@ static void strands_copy_edge_buffer(StrandData *strands, unsigned int (*varray)
StrandCurveData *curve = strands->curves;
for (c = 0; c < totcurves; ++c, ++curve) {
int verts_begin = curve->verts_begin, num_verts = curve->num_verts, v;
+ BLI_assert(num_verts >= 2);
StrandVertexData *vert = strands->verts + verts_begin;
for (v = 0; v < num_verts - 1; ++v, ++vert) {
More information about the Bf-blender-cvs
mailing list