[Bf-blender-cvs] [bc637d0] gooseberry: Randomness factor for hair bending stiffness.
Lukas Tönne
noreply at git.blender.org
Fri Nov 21 16:02:21 CET 2014
Commit: bc637d0e1a74c2fd18b8ba94e155a8017c6ddddf
Author: Lukas Tönne
Date: Mon Nov 17 19:44:42 2014 +0100
Branches: gooseberry
https://developer.blender.org/rBbc637d0e1a74c2fd18b8ba94e155a8017c6ddddf
Randomness factor for hair bending stiffness.
This helps to create some variation in a hair system, which can
otherwise become very uniform and boring. It's yet another confusing
setting in a system that should have been nodified, but only option for
now (broken windows ...)
===================================================================
M release/scripts/startup/bl_ui/properties_particle.py
M source/blender/blenkernel/BKE_cloth.h
M source/blender/blenkernel/intern/cloth.c
M source/blender/blenkernel/intern/particle_system.c
M source/blender/blenloader/intern/readfile.c
M source/blender/makesdna/DNA_modifier_types.h
M source/blender/makesdna/DNA_particle_types.h
M source/blender/makesrna/intern/rna_particle.c
M source/blender/modifiers/intern/MOD_cloth.c
M source/blender/physics/intern/BPH_mass_spring.cpp
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_particle.py b/release/scripts/startup/bl_ui/properties_particle.py
index 0bb779a..68df664 100644
--- a/release/scripts/startup/bl_ui/properties_particle.py
+++ b/release/scripts/startup/bl_ui/properties_particle.py
@@ -292,8 +292,10 @@ class PARTICLE_PT_hair_dynamics(ParticleButtonsPanel, Panel):
col = split.column()
col.label(text="Structure")
col.prop(cloth, "mass")
- sub = col.row(align=True)
- sub.prop(cloth, "bending_stiffness", text="Stiffness")
+ sub = col.column(align=True)
+ subsub = sub.row(align=True)
+ subsub.prop(cloth, "bending_stiffness", text="Stiffness")
+ subsub.prop(psys.settings, "bending_random", text="Random")
sub.prop(cloth, "bending_damping", text="Damping")
# XXX has no noticable effect with stiff hair structure springs
#col.prop(cloth, "spring_damping", text="Damping")
diff --git a/source/blender/blenkernel/BKE_cloth.h b/source/blender/blenkernel/BKE_cloth.h
index f09bf03..527d6c1 100644
--- a/source/blender/blenkernel/BKE_cloth.h
+++ b/source/blender/blenkernel/BKE_cloth.h
@@ -65,11 +65,12 @@ struct PartDeflect;
#define CLOTH_VERT_FLAG_NOSELFCOLL 2 /* vertex NOT used for self collisions */
#define CLOTH_VERT_FLAG_EXCLUDE 4 /* exclude vertex from the simulation */
-typedef struct ClothHairRoot {
+typedef struct ClothHairData {
float loc[3];
float rot[3][3];
float rest_target[3]; /* rest target direction for each segment */
-} ClothHairRoot;
+ float bending_stiffness;
+} ClothHairData;
typedef struct ClothSolverResult {
int status;
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index eaf65bc..78abf7b 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -1082,15 +1082,15 @@ static void cloth_update_bending_targets(ClothModifierData *clmd)
prev_mn = -1;
for (search = cloth->springs; search; search = search->next) {
ClothSpring *spring = search->link;
- ClothHairRoot *hair_ij, *hair_kl;
+ ClothHairData *hair_ij, *hair_kl;
bool is_root = spring->kl != prev_mn;
if (spring->type != CLOTH_SPRING_TYPE_BENDING_ANG) {
continue;
}
- hair_ij = &clmd->roots[spring->ij];
- hair_kl = &clmd->roots[spring->kl];
+ hair_ij = &clmd->hairdata[spring->ij];
+ hair_kl = &clmd->hairdata[spring->kl];
if (is_root) {
/* initial hair frame from root orientation */
copy_m3_m3(hair_frame, hair_ij->rot);
@@ -1154,15 +1154,15 @@ static void cloth_update_bending_rest_targets(ClothModifierData *clmd)
prev_mn = -1;
for (search = cloth->springs; search; search = search->next) {
ClothSpring *spring = search->link;
- ClothHairRoot *hair_ij, *hair_kl;
+ ClothHairData *hair_ij, *hair_kl;
bool is_root = spring->kl != prev_mn;
if (spring->type != CLOTH_SPRING_TYPE_BENDING_ANG) {
continue;
}
- hair_ij = &clmd->roots[spring->ij];
- hair_kl = &clmd->roots[spring->kl];
+ hair_ij = &clmd->hairdata[spring->ij];
+ hair_kl = &clmd->hairdata[spring->kl];
if (is_root) {
/* initial hair frame from root orientation */
copy_m3_m3(hair_frame, hair_ij->rot);
@@ -1208,6 +1208,16 @@ static void cloth_update_springs( ClothModifierData *clmd )
else if (spring->type == CLOTH_SPRING_TYPE_BENDING) {
spring->stiffness = (cloth->verts[spring->kl].bend_stiff + cloth->verts[spring->ij].bend_stiff) / 2.0f;
}
+ else if (spring->type == CLOTH_SPRING_TYPE_BENDING_ANG) {
+ ClothVertex *v1 = &cloth->verts[spring->ij];
+ ClothVertex *v2 = &cloth->verts[spring->kl];
+ if (clmd->hairdata) {
+ /* copy extra hair data to generic cloth vertices */
+ v1->bend_stiff = clmd->hairdata[spring->ij].bending_stiffness;
+ v2->bend_stiff = clmd->hairdata[spring->kl].bending_stiffness;
+ }
+ spring->stiffness = (v1->bend_stiff + v2->bend_stiff) / 2.0f;
+ }
else if (spring->type == CLOTH_SPRING_TYPE_GOAL) {
/* Warning: Appending NEW goal springs does not work because implicit solver would need reset! */
diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index 3e0add8..3fc7185 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -3108,11 +3108,12 @@ bool psys_hair_update_preview(ParticleSimulationData *sim)
#endif
}
-static void hair_create_input_dm(ParticleSimulationData *sim, int totpoint, int totedge, DerivedMesh **r_dm, ClothHairRoot **r_roots)
+static void hair_create_input_dm(ParticleSimulationData *sim, int totpoint, int totedge, DerivedMesh **r_dm, ClothHairData **r_hairdata)
{
ParticleSystem *psys = sim->psys;
+ ParticleSettings *part = psys->part;
DerivedMesh *dm;
- ClothHairRoot *roots;
+ ClothHairData *hairdata;
MVert *mvert;
MEdge *medge;
MDeformVert *dvert;
@@ -3133,9 +3134,9 @@ static void hair_create_input_dm(ParticleSimulationData *sim, int totpoint, int
medge = CDDM_get_edges(dm);
dvert = DM_get_vert_data_layer(dm, CD_MDEFORMVERT);
- roots = *r_roots;
- if (!roots) {
- *r_roots = roots = MEM_mallocN(sizeof(ClothHairRoot) * totpoint, "hair roots");
+ hairdata = *r_hairdata;
+ if (!hairdata) {
+ *r_hairdata = hairdata = MEM_mallocN(sizeof(ClothHairData) * totpoint, "hair data");
}
/* calculate maximum segment length */
@@ -3156,6 +3157,7 @@ static void hair_create_input_dm(ParticleSimulationData *sim, int totpoint, int
hair_index = 1;
LOOP_PARTICLES {
float root_mat[4][4];
+ float bending_stiffness;
bool use_hair;
pa->hair_index = hair_index;
@@ -3165,8 +3167,10 @@ static void hair_create_input_dm(ParticleSimulationData *sim, int totpoint, int
mul_m4_m4m4(root_mat, sim->ob->obmat, hairmat);
normalize_m4(root_mat);
+ bending_stiffness = 1.0f - part->bending_random * psys_frand(psys, p + 666);
+
for (k=0, key=pa->hair; k<pa->totkey; k++,key++) {
- ClothHairRoot *root;
+ ClothHairData *hair;
float *co, *co_next;
if (shapekey) {
@@ -3181,9 +3185,11 @@ static void hair_create_input_dm(ParticleSimulationData *sim, int totpoint, int
/* create fake root before actual root to resist bending */
if (k==0) {
- root = &psys->clmd->roots[pa->hair_index - 1];
- copy_v3_v3(root->loc, root_mat[3]);
- copy_m3_m4(root->rot, root_mat);
+ hair = &psys->clmd->hairdata[pa->hair_index - 1];
+ copy_v3_v3(hair->loc, root_mat[3]);
+ copy_m3_m4(hair->rot, root_mat);
+
+ hair->bending_stiffness = bending_stiffness;
add_v3_v3v3(mvert->co, co, co);
sub_v3_v3(mvert->co, co_next);
@@ -3205,9 +3211,11 @@ static void hair_create_input_dm(ParticleSimulationData *sim, int totpoint, int
}
/* store root transform in cloth data */
- root = &psys->clmd->roots[pa->hair_index + k];
- copy_v3_v3(root->loc, root_mat[3]);
- copy_m3_m4(root->rot, root_mat);
+ hair = &psys->clmd->hairdata[pa->hair_index + k];
+ copy_v3_v3(hair->loc, root_mat[3]);
+ copy_m3_m4(hair->rot, root_mat);
+
+ hair->bending_stiffness = bending_stiffness;
copy_v3_v3(mvert->co, co);
mul_m4_v3(hairmat, mvert->co);
@@ -3239,12 +3247,12 @@ static void hair_create_input_dm(ParticleSimulationData *sim, int totpoint, int
}
#ifdef USE_PARTICLE_PREVIEW
-static void hair_deform_preview_curve(ParticleSystem *psys, ParticleData *pa, float (*deformedVerts)[3], ClothHairRoot *roots)
+static void hair_deform_preview_curve(ParticleSystem *psys, ParticleData *pa, float (*deformedVerts)[3], ClothHairData *hairdata)
{
ParticleData *particles = psys->particles;
HairKey *hkey;
float (*vert)[3];
- ClothHairRoot *root;
+ ClothHairData *root;
int k;
float totlen, norm;
@@ -3262,7 +3270,7 @@ static void hair_deform_preview_curve(ParticleSystem *psys, ParticleData *pa, fl
totlen = 0.0f;
hkey = pa->hair;
vert = deformedVerts + pa->hair_index;
- root = roots + pa->hair_index;
+ root = hairdata + pa->hair_index;
for (k = 0; k < pa->totkey; ++k, ++hkey, ++vert, ++root) {
float param;
int w;
@@ -3276,7 +3284,7 @@ static void hair_deform_preview_curve(ParticleSystem *psys, ParticleData *pa, fl
for (w = 0; w < 4; ++w) {
ParticleData *blend_pa;
float (*blend_vert)[3];
- ClothHairRoot *blend_root;
+ ClothHairData *blend_hair;
float blend_key, blend_factor;
int blend_totkey, blend_index;
float co[3];
@@ -3301,18 +3309,18 @@ static void hair_deform_preview_curve(ParticleSystem *psys, ParticleData *pa, fl
* use it here to map to output mvert index
*/
blend_vert = deformedVerts + blend_pa->hair_index + blend_index;
- blend_root = roots + blend_pa->hair_index + blend_index;
+ blend_hair = hairdata + blend_pa->hair_index + blend_index;
interp_v3_v3v3(co, blend_vert[0], blend_vert[1], blend_factor);
/* transform parent vector from world to root space, then back into root space of the blended hair */
- sub_v3_v3(co, blend_root->loc);
+ sub_v3_v3(co, blend_hair->loc);
/* note: rotation transform disabled, this does not work nicely with global force directions (gravity, wind etc.)
* these forces would also get rotated, giving movement in a different direction than the force would actually incur.
* would have to split internal (stretch, bend) and external forces somehow to make this plausible
*/
#if 0
- mul_transposed_m3_v3(blend_root->rot, co);
+ mul_transposed_m3_v3(blend_hair->rot, co);
mul_m3_v3(root->rot, co);
#endif
add_v3_v3(co, root->loc);
@@ -3322,7 +3330,7 @@ static void hair_deform_preview_curve(ParticleSystem *psys, ParticleData *pa, fl
}
}
-static void hair_deform_preview_hairs(ParticleSimulationData *sim, float (*deformedVerts)[3], ClothHairRoot *roots)
+static void hair_deform_preview_hairs(ParticleSimulationData *sim, float (*deformedVerts)[3], ClothHairData *roots)
{
ParticleSystem *psys = sim->psys;
ParticleData *pa;
@@ -3379,14 +3387,14 @@ static void do_hair_dynamics(ParticleSimulationData *sim)
}
}
- if (!psys->hair_in_dm || !psys->clmd->roots || realloc_roots) {
- if (psys->clmd->roots) {
- MEM_freeN(psys->clmd->roots);
- psys->clmd->root
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list