diff options
author | Lukas Tönne <lukas.toenne@gmail.com> | 2014-09-11 16:19:52 +0400 |
---|---|---|
committer | Lukas Tönne <lukas.toenne@gmail.com> | 2015-01-20 11:29:59 +0300 |
commit | d115bdb50510c2912ffedd22100e38a646827b52 (patch) | |
tree | f50461760144f8c6d473c4de8ff5ea79e662e477 /source/blender/blenkernel | |
parent | da01c884e54bc1546b2243c3517d50ff961859e9 (diff) |
Added new data in the cloth modifier for hair root information.
This will allow us to implement moving reference frames for hair and
make "fictitious" forces optional, aiding in creating stable and
controllable hair systems.
Adding data in this place is a nasty hack, but it's too difficult to
encode as a DM data layer and the whole cloth modifier/DM intermediate
data copying for hair should be removed anyway.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_cloth.h | 5 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/particle_system.c | 12 |
2 files changed, 17 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_cloth.h b/source/blender/blenkernel/BKE_cloth.h index df118276809..10a336a075a 100644 --- a/source/blender/blenkernel/BKE_cloth.h +++ b/source/blender/blenkernel/BKE_cloth.h @@ -59,6 +59,11 @@ struct PartDeflect; #define CLOTH_VERT_FLAG_PINNED 1 #define CLOTH_VERT_FLAG_NOSELFCOLL 2 /* vertex NOT used for self collisions */ +typedef struct ClothHairRoot { + float loc[3]; + float rot[3][3]; +} ClothHairRoot; + /** * This structure describes a cloth object against which the * simulation can run. diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index 71656240369..14082af4cbd 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -4010,12 +4010,19 @@ static void do_hair_dynamics(ParticleSimulationData *sim) if (dm && (totpoint != dm->getNumVerts(dm) || totedge != dm->getNumEdges(dm))) { dm->release(dm); dm = psys->hair_in_dm = NULL; + + MEM_freeN(psys->clmd->roots); + psys->clmd->roots = NULL; } if (!dm) { dm = psys->hair_in_dm = CDDM_new(totpoint, totedge, 0, 0, 0); DM_add_vert_layer(dm, CD_MDEFORMVERT, CD_CALLOC, NULL); } + + if (!psys->clmd->roots) { + psys->clmd->roots = MEM_mallocN(sizeof(ClothHairRoot) * totpoint, "hair roots"); + } mvert = CDDM_get_verts(dm); medge = CDDM_get_edges(dm); @@ -4032,6 +4039,7 @@ static void do_hair_dynamics(ParticleSimulationData *sim) psys_mat_hair_to_object(sim->ob, sim->psmd->dm, psys->part->from, pa, hairmat); for (k=0, key=pa->hair; k<pa->totkey; k++,key++) { + ClothHairRoot *root = &psys->clmd->roots[pa->hair_index + k - 1]; /* create fake root before actual root to resist bending */ if (k==0) { @@ -4057,6 +4065,10 @@ static void do_hair_dynamics(ParticleSimulationData *sim) } } + /* store root transform in cloth data */ + copy_v3_v3(root->loc, hairmat[3]); + copy_m3_m4(root->rot, hairmat); + copy_v3_v3(mvert->co, key->co); mul_m4_v3(hairmat, mvert->co); mvert++; |