[Bf-blender-cvs] [676f742] alembic: Yet another iterator for looping over strands, this time for triples of consecutive vertices ("bends").
Lukas Tönne
noreply at git.blender.org
Tue Apr 7 18:18:59 CEST 2015
Commit: 676f742a6cc630aad32d4228c2ad3d241b271c0d
Author: Lukas Tönne
Date: Tue Apr 7 18:17:21 2015 +0200
Branches: alembic
https://developer.blender.org/rB676f742a6cc630aad32d4228c2ad3d241b271c0d
Yet another iterator for looping over strands, this time for triples
of consecutive vertices ("bends").
This will be useful for calculating bending forces, without making basic
iteration a big headache.
===================================================================
M source/blender/blenkernel/BKE_strands.h
===================================================================
diff --git a/source/blender/blenkernel/BKE_strands.h b/source/blender/blenkernel/BKE_strands.h
index 7462e18..1780bae 100644
--- a/source/blender/blenkernel/BKE_strands.h
+++ b/source/blender/blenkernel/BKE_strands.h
@@ -183,4 +183,56 @@ BLI_INLINE size_t BKE_strand_edge_iter_vertex1_offset(Strands *strands, StrandEd
return iter->vertex1 - strands->verts;
}
+
+typedef struct StrandBendIterator {
+ int index, tot;
+ StrandsVertex *vertex0, *vertex1, *vertex2;
+ StrandsMotionState *state0, *state1, *state2;
+} StrandBendIterator;
+
+BLI_INLINE void BKE_strand_bend_iter_init(StrandBendIterator *iter, StrandIterator *strand_iter)
+{
+ iter->tot = strand_iter->curve->numverts - 2;
+ iter->index = 0;
+ iter->vertex0 = strand_iter->verts;
+ iter->state0 = strand_iter->state;
+ iter->vertex1 = strand_iter->verts + 1;
+ iter->state1 = strand_iter->state + 1;
+ iter->vertex2 = strand_iter->verts + 2;
+ iter->state2 = strand_iter->state + 2;
+}
+
+BLI_INLINE bool BKE_strand_bend_iter_valid(StrandBendIterator *iter)
+{
+ return iter->index < iter->tot;
+}
+
+BLI_INLINE void BKE_strand_bend_iter_next(StrandBendIterator *iter)
+{
+ ++iter->vertex0;
+ ++iter->vertex1;
+ ++iter->vertex2;
+ if (iter->state0) {
+ ++iter->state0;
+ ++iter->state1;
+ ++iter->state2;
+ }
+ ++iter->index;
+}
+
+BLI_INLINE size_t BKE_strand_bend_iter_vertex0_offset(Strands *strands, StrandBendIterator *iter)
+{
+ return iter->vertex0 - strands->verts;
+}
+
+BLI_INLINE size_t BKE_strand_bend_iter_vertex1_offset(Strands *strands, StrandBendIterator *iter)
+{
+ return iter->vertex1 - strands->verts;
+}
+
+BLI_INLINE size_t BKE_strand_bend_iter_vertex2_offset(Strands *strands, StrandBendIterator *iter)
+{
+ return iter->vertex2 - strands->verts;
+}
+
#endif /* __BKE_STRANDS_H__ */
More information about the Bf-blender-cvs
mailing list