[Bf-blender-cvs] [fd34e3e] strand_editmode: Fix for verts-of-strand iterator: This requires a second pointer in addition to the edge, otherwise the last point is omitted.
Lukas Tönne
noreply at git.blender.org
Mon Apr 20 14:23:04 CEST 2015
Commit: fd34e3efbc1587de14718a0d7706cfa3fb6bc870
Author: Lukas Tönne
Date: Fri Nov 28 14:02:06 2014 +0100
Branches: strand_editmode
https://developer.blender.org/rBfd34e3efbc1587de14718a0d7706cfa3fb6bc870
Fix for verts-of-strand iterator: This requires a second pointer in
addition to the edge, otherwise the last point is omitted.
===================================================================
M source/blender/bmesh/intern/bmesh_strands.c
M source/blender/bmesh/intern/bmesh_strands.h
===================================================================
diff --git a/source/blender/bmesh/intern/bmesh_strands.c b/source/blender/bmesh/intern/bmesh_strands.c
index 1fdd880..09bc574 100644
--- a/source/blender/bmesh/intern/bmesh_strands.c
+++ b/source/blender/bmesh/intern/bmesh_strands.c
@@ -56,27 +56,33 @@ void *bmstranditer__strands_of_mesh_step(struct BMIter__elem_of_mesh *iter)
* VERTS OF STRAND CALLBACKS
*/
-void bmstranditer__verts_of_strand_begin(struct BMIter__vert_of_edge *UNUSED(iter))
+/* BMIter__vert_of_strand is not included in the union in BMIter, just make sure it is big enough */
+BLI_STATIC_ASSERT(sizeof(BMIter__vert_of_strand) <= sizeof(BMIter), "BMIter must be at least as large as BMIter__vert_of_strand")
+
+void bmstranditer__verts_of_strand_begin(struct BMIter__vert_of_strand *iter)
{
+ iter->e_next = iter->v_next->e;
}
-void *bmstranditer__verts_of_strand_step(struct BMIter__vert_of_edge *iter)
+void *bmstranditer__verts_of_strand_step(struct BMIter__vert_of_strand *iter)
{
- if (iter->edata) {
- /* by definition the all strand edges run in the same direction,
- * with the root being v1 of the first edge.
- */
- BMVert *v_curr = iter->edata->v1;
- BMEdge *e_first = iter->edata;
+ BMVert *v_curr = iter->v_next;
+
+ if (iter->e_next) {
+ BMEdge *e_first = iter->e_next;
+
+ /* select the other vertex of the current edge */
+ iter->v_next = (iter->v_next == iter->e_next->v1 ? iter->e_next->v2 : iter->e_next->v1);
- iter->edata = bmesh_disk_edge_next(iter->edata, iter->edata->v2);
- if (iter->edata == e_first) {
+ /* select the next edge of the current vertex */
+ iter->e_next = bmesh_disk_edge_next(iter->e_next, iter->v_next);
+ if (iter->e_next == e_first) {
/* only one edge means the last segment, terminate */
- iter->edata = NULL;
+ iter->e_next = NULL;
}
-
- return v_curr;
}
else
- return NULL;
+ iter->v_next = NULL; /* last vertex, terminate */
+
+ return v_curr;
}
diff --git a/source/blender/bmesh/intern/bmesh_strands.h b/source/blender/bmesh/intern/bmesh_strands.h
index a912c4f..f2c8bf5 100644
--- a/source/blender/bmesh/intern/bmesh_strands.h
+++ b/source/blender/bmesh/intern/bmesh_strands.h
@@ -64,11 +64,16 @@ typedef enum BMStrandsIterType {
#define BM_ITER_STRANDS_ELEM(ele, iter, data, itype) \
for (ele = BM_strand_iter_new(iter, NULL, itype, data); ele; ele = BM_iter_step(iter))
+typedef struct BMIter__vert_of_strand {
+ BMVert *v_next;
+ BMEdge *e_next;
+} BMIter__vert_of_strand;
+
void bmstranditer__strands_of_mesh_begin(struct BMIter__elem_of_mesh *iter);
void *bmstranditer__strands_of_mesh_step(struct BMIter__elem_of_mesh *iter);
-void bmstranditer__verts_of_strand_begin(struct BMIter__vert_of_edge *iter);
-void *bmstranditer__verts_of_strand_step(struct BMIter__vert_of_edge *iter);
+void bmstranditer__verts_of_strand_begin(struct BMIter__vert_of_strand *iter);
+void *bmstranditer__verts_of_strand_step(struct BMIter__vert_of_strand *iter);
BLI_INLINE bool BM_strand_iter_init(BMIter *iter, BMesh *bm, const char itype, void *data)
{
@@ -93,10 +98,7 @@ BLI_INLINE bool BM_strand_iter_init(BMIter *iter, BMesh *bm, const char itype, v
BLI_assert(BM_strands_vert_is_root(root));
iter->begin = (BMIter__begin_cb)bmstranditer__verts_of_strand_begin;
iter->step = (BMIter__step_cb)bmstranditer__verts_of_strand_step;
- /* Note: Iterating over a strand is in fact more like a vertices-of-vertex iterator,
- * but due to strand topology we can start with the first edge as well.
- */
- iter->data.vert_of_edge.edata = root->e;
+ ((BMIter__vert_of_strand *)(&iter->data))->v_next = root;
break;
}
default:
More information about the Bf-blender-cvs
mailing list