[Bf-blender-cvs] [1550f09] alembic: "Structural" spring forces for strands.
Lukas Tönne
noreply at git.blender.org
Fri Apr 3 12:35:50 CEST 2015
Commit: 1550f092baa6ec21df0c6fc9123b7c431d884682
Author: Lukas Tönne
Date: Fri Apr 3 12:32:50 2015 +0200
Branches: alembic
https://developer.blender.org/rB1550f092baa6ec21df0c6fc9123b7c431d884682
"Structural" spring forces for strands.
These connect strand points to ensure constant length and form the main
spring system in strand simulation.
Note that parameters are still hardcoded.
===================================================================
M source/blender/blenkernel/BKE_strands.h
M source/blender/physics/intern/BPH_mass_spring.cpp
===================================================================
diff --git a/source/blender/blenkernel/BKE_strands.h b/source/blender/blenkernel/BKE_strands.h
index f45ac0f..9475d5c 100644
--- a/source/blender/blenkernel/BKE_strands.h
+++ b/source/blender/blenkernel/BKE_strands.h
@@ -96,6 +96,16 @@ BLI_INLINE void BKE_strand_iter_next(StrandIterator *iter)
iter->state += numverts;
}
+BLI_INLINE size_t BKE_strand_iter_curve_offset(Strands *strands, StrandIterator *iter)
+{
+ return iter->curve - strands->curves;
+}
+
+BLI_INLINE size_t BKE_strand_iter_vertex_offset(Strands *strands, StrandIterator *iter)
+{
+ return iter->verts - strands->verts;
+}
+
typedef struct StrandVertexIterator {
int index, tot;
@@ -124,4 +134,9 @@ BLI_INLINE void BKE_strand_vertex_iter_next(StrandVertexIterator *iter)
++iter->index;
}
+BLI_INLINE size_t BKE_strand_vertex_iter_vertex_offset(Strands *strands, StrandVertexIterator *iter)
+{
+ return iter->vertex - strands->verts;
+}
+
#endif /* __BKE_STRANDS_H__ */
diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp
index 555213d..22eeaad0 100644
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@ -1258,15 +1258,26 @@ static void strands_calc_force(Strands *strands, StrandSimParams *params, Implic
}
#endif
-#if 0
- // calculate spring forces
- for (LinkNode *link = cloth->springs; link; link = link->next) {
- ClothSpring *spring = (ClothSpring *)link->link;
- // only handle active springs
- if (!(spring->flags & CLOTH_SPRING_FLAG_DEACTIVATE))
- cloth_calc_spring_force(clmd, spring, step);
+ /* spring forces */
+ StrandIterator it_strand;
+ for (BKE_strand_iter_init(&it_strand, strands); BKE_strand_iter_valid(&it_strand); BKE_strand_iter_next(&it_strand)) {
+ StrandVertexIterator it_vert, it_vert_prev;
+ BKE_strand_vertex_iter_init(&it_vert, &it_strand);
+ if (BKE_strand_vertex_iter_valid(&it_vert)) {
+ it_vert_prev = it_vert;
+ BKE_strand_vertex_iter_next(&it_vert);
+ for (; BKE_strand_vertex_iter_valid(&it_vert); BKE_strand_vertex_iter_next(&it_vert)) {
+
+ int vi = BKE_strand_vertex_iter_vertex_offset(strands, &it_vert);
+ int vj = BKE_strand_vertex_iter_vertex_offset(strands, &it_vert_prev);
+ float restlen = len_v3v3(it_vert.vertex->co, it_vert_prev.vertex->co);
+
+ BPH_mass_spring_force_spring_linear(data, vi, vj, restlen, 1000.0f, 1000.0f, true, 0.0f, NULL, NULL, NULL);
+ }
+ }
+
+ i += it_strand.curve->numverts;
}
-#endif
}
bool BPH_strands_solve(Strands *strands, Implicit_Data *id, StrandSimParams *params, float frame, float frame_prev, Scene *scene, ListBase *effectors)
More information about the Bf-blender-cvs
mailing list