diff options
author | Lukas Tönne <lukas.toenne@gmail.com> | 2014-12-22 13:54:24 +0300 |
---|---|---|
committer | Lukas Tönne <lukas.toenne@gmail.com> | 2015-01-20 11:30:09 +0300 |
commit | 1b6f5ecbf4aad9c6d4c58460b3e5596cd5f12399 (patch) | |
tree | e5ed7e20c0fd180dd2050df9af6ec21c8228cdda /source/blender/physics/intern | |
parent | bb76e96339ec26cafff57d5d7a8b015c4b1d6ef9 (diff) |
Fix for invalid access to undefined hair data in edge-only cloth meshes.
Cloth data is used both for hair and actual cloth, which makes things
really difficult. The face number was used for distinguishing the two
types (no faces == hair mesh), but the extra hair data necessary for
hair sim is generated by particles and not available for edge-only cloth
meshes. This really needs to be sanitized ...
Conflicts:
source/blender/physics/intern/BPH_mass_spring.cpp
Diffstat (limited to 'source/blender/physics/intern')
-rw-r--r-- | source/blender/physics/intern/BPH_mass_spring.cpp | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp index 9e58a13fa6e..a77593d31a4 100644 --- a/source/blender/physics/intern/BPH_mass_spring.cpp +++ b/source/blender/physics/intern/BPH_mass_spring.cpp @@ -51,6 +51,8 @@ extern "C" { #include "BPH_mass_spring.h"
#include "implicit.h"
+static float I3[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}};
+
/* Number of off-diagonal non-zero matrix blocks.
* Basically there is one of these for each vertex-vertex interaction.
*/
@@ -118,10 +120,16 @@ void BKE_cloth_solver_set_positions(ClothModifierData *clmd) Implicit_Data *id = cloth->implicit;
for (i = 0; i < numverts; i++) {
- ClothHairData *root = &cloth_hairdata[i];
-
BPH_mass_spring_set_rest_transform(id, i, root->rot);
BPH_mass_spring_set_motion_state(id, i, verts[i].x, verts[i].v);
+ if (cloth_hairdata) {
+ ClothHairData *root = &cloth_hairdata[i];
+ BPH_mass_spring_set_rest_transform(id, i, root->rot);
+ }
+ else
+ BPH_mass_spring_set_rest_transform(id, i, I3);
+
+ BPH_mass_spring_set_motion_state(id, i, verts[i].x, verts[i].v);
}
}
@@ -504,19 +512,29 @@ static void cloth_calc_force(ClothModifierData *clmd, float UNUSED(frame), ListB for (LinkNode *link = cloth->springs; link; link = link->next) {
ClothSpring *spring = (ClothSpring *)link->link;
if (spring->type == CLOTH_SPRING_TYPE_STRUCTURAL)
- hair_ij = &hairdata[spring->ij];
- hair_kl = &hairdata[spring->kl];
- BPH_mass_spring_force_edge_wind(data, spring->ij, spring->kl, hair_ij->radius, hair_kl->radius, winvec);
- }
+ if (hairdata) {
+ hair_ij = &hairdata[spring->ij];
+ hair_kl = &hairdata[spring->kl];
+ BPH_mass_spring_force_edge_wind(data, spring->ij, spring->kl, hair_ij->radius, hair_kl->radius, winvec);
+ }
+ else
+ BPH_mass_spring_force_edge_wind(data, spring->ij, spring->kl, 1.0f, 1.0f, winvec);
+ }
}
#else
ClothHairData *hairdata = clmd->hairdata;
vert = cloth->verts;
for (i = 0; i < cloth->numverts; i++, vert++) {
- ClothHairData *hair = &hairdata[i];
+ if (vert->solver_index < 0)
+ continue;
- BPH_mass_spring_force_vertex_wind(data, i, hair->radius, winvec);
+ if (hairdata) {
+ ClothHairData *hair = &hairdata[i];
+ BPH_mass_spring_force_vertex_wind(data, i, hair->radius, winvec);
+ }
+ else
+ BPH_mass_spring_force_vertex_wind(data, i, 1.0f, winvec);
}
#endif
|