Commit: e0a780d9a76501744c16936448af2ab9cf6a7829
Author: Lukas Tönne
Date:   Tue May 5 14:41:04 2015 +0200
Branches: alembic
https://developer.blender.org/rBe0a780d9a76501744c16936448af2ab9cf6a7829

Strand edit functions for storing edit data in the Cache Shape Key
modifier and editing in hair edit mode.

===================================================================

M       source/blender/blenkernel/BKE_cache_library.h
M       source/blender/blenkernel/BKE_editstrands.h
M       source/blender/blenkernel/intern/cache_library.c
M       source/blender/blenkernel/intern/editstrands.c
M       source/blender/blenloader/intern/readfile.c
M       source/blender/bmesh/intern/bmesh_strands_conv.c
M       source/blender/bmesh/intern/bmesh_strands_conv.h
M       source/blender/editors/hair/CMakeLists.txt
M       source/blender/editors/hair/hair_edit.c
M       source/blender/editors/hair/hair_intern.h
A       source/blender/editors/hair/hair_object_cachelib.c
M       source/blender/editors/hair/hair_object_particles.c
M       source/blender/editors/hair/hair_undo.c
M       source/blender/editors/io/io_cache_shapekey.c
M       source/blender/editors/object/object_edit.c
M       source/blender/makesdna/DNA_cache_library_types.h

===================================================================

diff --git a/source/blender/blenkernel/BKE_cache_library.h 
b/source/blender/blenkernel/BKE_cache_library.h
index 435cd7b..6c27fe6 100644
--- a/source/blender/blenkernel/BKE_cache_library.h
+++ b/source/blender/blenkernel/BKE_cache_library.h
@@ -174,9 +174,10 @@ struct CacheModifier *BKE_cache_modifier_copy(struct 
CacheLibrary *cachelib, str
 void BKE_cache_modifier_foreachIDLink(struct CacheLibrary *cachelib, struct 
CacheModifier *md, CacheModifier_IDWalkFunc walk, void *userdata);
 
 bool BKE_cache_modifier_find_object(struct DupliCache *dupcache, struct Object 
*ob, struct DupliObjectData **r_data);
-bool BKE_cache_modifier_find_strands(struct DupliCache *dupcache, struct 
Object *ob, int hair_system, struct DupliObjectData **r_data, struct Strands 
**r_strands);
+bool BKE_cache_modifier_find_strands(struct DupliCache *dupcache, struct 
Object *ob, int hair_system, struct DupliObjectData **r_data, struct Strands 
**r_strands, const char **r_name);
 
 struct KeyBlock *BKE_cache_modifier_strands_key_insert_key(struct 
StrandsKeyCacheModifier *md, struct Strands *strands, const char *name, const 
bool from_mix);
+bool BKE_cache_modifier_strands_key_get(struct Object *ob, struct 
StrandsKeyCacheModifier **r_skmd, struct DerivedMesh **r_dm, struct Strands 
**r_strands, struct DupliObjectData **r_dobdata, const char **r_name);
 
 /* ========================================================================= */
 
diff --git a/source/blender/blenkernel/BKE_editstrands.h 
b/source/blender/blenkernel/BKE_editstrands.h
index 01082a0..0638e79 100644
--- a/source/blender/blenkernel/BKE_editstrands.h
+++ b/source/blender/blenkernel/BKE_editstrands.h
@@ -41,7 +41,9 @@
 
 struct BMesh;
 struct DerivedMesh;
+struct Key;
 struct Object;
+struct Strands;
 
 typedef struct BMEditStrands {
        struct BMesh *bm;
@@ -88,6 +90,12 @@ void BKE_editstrands_free_locations(BMEditStrandsLocations 
locs);
 void BKE_editstrands_solve_constraints(struct Object *ob, struct BMEditStrands 
*es, BMEditStrandsLocations orig);
 void BKE_editstrands_ensure(struct BMEditStrands *es);
 
+
+/* === cache shape key conversion === */
+
+struct BMesh *BKE_cache_strands_to_bmesh(struct Strands *strands, struct Key 
*key, int act_key_nr, struct DerivedMesh *dm);
+struct Strands *BKE_cache_strands_from_bmesh(struct BMEditStrands *edit, 
struct Key *key, struct DerivedMesh *dm);
+
 /* === particle conversion === */
 
 struct BMesh *BKE_particles_to_bmesh(struct Object *ob, struct ParticleSystem 
*psys);
diff --git a/source/blender/blenkernel/intern/cache_library.c 
b/source/blender/blenkernel/intern/cache_library.c
index f187282..6fff160 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -57,6 +57,7 @@
 #include "BKE_context.h"
 #include "BKE_depsgraph.h"
 #include "BKE_DerivedMesh.h"
+#include "BKE_editstrands.h"
 #include "BKE_effect.h"
 #include "BKE_global.h"
 #include "BKE_group.h"
@@ -848,7 +849,7 @@ bool BKE_cache_modifier_find_object(DupliCache *dupcache, 
Object *ob, DupliObjec
        return true;
 }
 
-bool BKE_cache_modifier_find_strands(DupliCache *dupcache, Object *ob, int 
hair_system, DupliObjectData **r_data, Strands **r_strands)
+bool BKE_cache_modifier_find_strands(DupliCache *dupcache, Object *ob, int 
hair_system, DupliObjectData **r_data, Strands **r_strands, const char **r_name)
 {
        DupliObjectData *dobdata;
        ParticleSystem *psys;
@@ -877,6 +878,7 @@ bool BKE_cache_modifier_find_strands(DupliCache *dupcache, 
Object *ob, int hair_
        
        if (r_data) *r_data = dobdata;
        if (r_strands) *r_strands = strands;
+       if (r_name) *r_name = psys->name;
        return true;
 }
 
@@ -951,7 +953,7 @@ static void hairsim_process(HairSimCacheModifier *hsmd, 
CacheProcessContext *ctx
 //     if (eval_mode != CACHE_LIBRARY_EVAL_REALTIME)
 //             return;
        
-       if (!BKE_cache_modifier_find_strands(data->dupcache, ob, 
hsmd->hair_system, NULL, &strands))
+       if (!BKE_cache_modifier_find_strands(data->dupcache, ob, 
hsmd->hair_system, NULL, &strands, NULL))
                return;
        
        /* Note: motion state data should always be created regardless of 
actual sim.
@@ -1179,7 +1181,7 @@ static void shrinkwrap_process(ShrinkWrapCacheModifier 
*smd, CacheProcessContext
        
        ShrinkWrapCacheData shrinkwrap;
        
-       if (!BKE_cache_modifier_find_strands(data->dupcache, ob, 
smd->hair_system, NULL, &strands))
+       if (!BKE_cache_modifier_find_strands(data->dupcache, ob, 
smd->hair_system, NULL, &strands, NULL))
                return;
        if (!BKE_cache_modifier_find_object(data->dupcache, smd->target, 
&target_data))
                return;
@@ -1230,11 +1232,19 @@ static void strandskey_init(StrandsKeyCacheModifier 
*skmd)
 static void strandskey_copy(StrandsKeyCacheModifier *skmd, 
StrandsKeyCacheModifier *tskmd)
 {
        tskmd->key = BKE_key_copy(skmd->key);
+       
+       tskmd->edit = NULL;
 }
 
 static void strandskey_free(StrandsKeyCacheModifier *skmd)
 {
        BKE_key_free(skmd->key);
+       
+       if (skmd->edit) {
+               BKE_editstrands_free(skmd->edit);
+               MEM_freeN(skmd->edit);
+               skmd->edit = NULL;
+       }
 }
 
 static void strandskey_foreach_id_link(StrandsKeyCacheModifier *skmd, 
CacheLibrary *cachelib, CacheModifier_IDWalkFunc walk, void *userdata)
@@ -1249,7 +1259,7 @@ static void strandskey_process(StrandsKeyCacheModifier 
*skmd, CacheProcessContex
        KeyBlock *actkb;
        float *shape;
        
-       if (!BKE_cache_modifier_find_strands(data->dupcache, ob, 
skmd->hair_system, NULL, &strands))
+       if (!BKE_cache_modifier_find_strands(data->dupcache, ob, 
skmd->hair_system, NULL, &strands, NULL))
                return;
        
        actkb = BLI_findlink(&skmd->key->block, skmd->shapenr);
@@ -1319,6 +1329,35 @@ KeyBlock 
*BKE_cache_modifier_strands_key_insert_key(StrandsKeyCacheModifier *skm
        return kb;
 }
 
+bool BKE_cache_modifier_strands_key_get(Object *ob, StrandsKeyCacheModifier 
**r_skmd, DerivedMesh **r_dm, Strands **r_strands, DupliObjectData **r_dobdata, 
const char **r_name)
+{
+       CacheLibrary *cachelib = ob->cache_library;
+       CacheModifier *md;
+       
+       if (!cachelib)
+               return false;
+       
+       /* ignore when the object is not actually using the cachelib */
+       if (!((ob->transflag & OB_DUPLIGROUP) && ob->dup_group && 
ob->dup_cache))
+               return false;
+       
+       for (md = cachelib->modifiers.first; md; md = md->next) {
+               if (md->type == eCacheModifierType_StrandsKey) {
+                       StrandsKeyCacheModifier *skmd = 
(StrandsKeyCacheModifier *)md;
+                       DupliObjectData *dobdata;
+                       
+                       if (BKE_cache_modifier_find_strands(ob->dup_cache, 
skmd->object, skmd->hair_system, &dobdata, r_strands, r_name)) {
+                               if (r_skmd) *r_skmd = skmd;
+                               if (r_dm) *r_dm = dobdata->dm;
+                               if (r_dobdata) *r_dobdata = dobdata;
+                               return true;
+                       }
+               }
+       }
+       
+       return false;
+}
+
 void BKE_cache_modifier_init(void)
 {
        cache_modifier_type_set(eCacheModifierType_HairSimulation, 
&cacheModifierType_HairSimulation);
diff --git a/source/blender/blenkernel/intern/editstrands.c 
b/source/blender/blenkernel/intern/editstrands.c
index 642eee3..741af51 100644
--- a/source/blender/blenkernel/intern/editstrands.c
+++ b/source/blender/blenkernel/intern/editstrands.c
@@ -34,12 +34,15 @@
 #include "BLI_math.h"
 #include "BLI_mempool.h"
 
+#include "DNA_cache_library_types.h"
 #include "DNA_customdata_types.h"
 #include "DNA_modifier_types.h"
 #include "DNA_object_types.h"
 #include "DNA_particle_types.h"
+#include "DNA_strands_types.h"
 
 #include "BKE_bvhutils.h"
+#include "BKE_cache_library.h"
 #include "BKE_customdata.h"
 #include "BKE_cdderivedmesh.h"
 #include "BKE_DerivedMesh.h"
@@ -78,10 +81,20 @@ BMEditStrands *BKE_editstrands_copy(BMEditStrands *es)
  */
 BMEditStrands *BKE_editstrands_from_object(Object *ob)
 {
-       ParticleSystem *psys = psys_get_current(ob);
-       if (psys) {
-               return psys->hairedit;
+       {
+               ParticleSystem *psys = psys_get_current(ob);
+               if (psys && psys->hairedit)
+                       return psys->hairedit;
        }
+       
+       {
+               StrandsKeyCacheModifier *skmd;
+               if (BKE_cache_modifier_strands_key_get(ob, &skmd, NULL, NULL, 
NULL, NULL)) {
+                       if (skmd->edit)
+                               return skmd->edit;
+               }
+       }
+       
        return NULL;
 }
 
@@ -161,6 +174,43 @@ void BKE_editstrands_ensure(BMEditStrands *es)
 }
 
 
+/* === cache shape key conversion === */
+
+BMesh *BKE_cache_strands_to_bmesh(struct Strands *strands, struct Key *key, 
int act_key_nr, DerivedMesh *dm)
+{
+       const BMAllocTemplate allocsize = 
BMALLOC_TEMPLATE_FROM_STRANDS(strands);
+       BMesh *bm;
+       
+       DM_ensure_tessface(dm);
+       
+       bm = BM_mesh_create(&allocsize);
+       BM_strands_bm_from_strands(bm, strands, key, dm, true, act_key_nr);
+       editstrands_calc_segment_lengths(bm);
+       
+       return bm;
+}
+
+struct Strands *BKE_cache_strands_from_bmesh(BMEditStrands *edit, struct Key 
*key, DerivedMesh *dm)
+{
+       BMesh *bm = edit ? edit->bm : NULL;
+       Strands *strands = NULL;
+       
+       if (bm && dm) {
+               BVHTreeFromMesh bvhtree = {NULL};
+               
+               DM_ensure_tessface(dm);
+               
+               bvhtree_from_mesh_faces(&bvhtree, dm, 0.0, 2, 6);
+               
+               strands = BM_strands_bm_to_strands(bm, strands, key, dm, 
&bvhtree);
+               
+               free_bvhtree_from_mesh(&bvhtree);
+       }
+       
+       return strands;
+}
+
+
 /* === particle conversion === */
 
 BMesh *BKE_particles_to_bmesh(Object *ob, ParticleSystem *psys)
diff --git a/source/blender/blenloader/intern/readfile.c 
b/source/blender/blenloader/intern/readfile.c
index 4fbb0fc..8b311be 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -2054,6 +2054,11 @@ static void direct_link_cache_modifiers(FileData *fd, 
ListBase *modifiers)
                                        direct_link_curvemapping(fd, 
hsmd->sim_params.goal_stiffness_mapping);
                                break;
                        }
+                       case eCacheModifierType_StrandsKey: {
+                               StrandsKeyCacheModifier *skmd = 
(StrandsKeyCacheModifier *)md;
+                               skmd->edit = NULL;
+                               break;
+                       }
                }
        }
 }
diff --git a/source/blender/bmesh/intern/bmesh_strands_conv.c 
b/source/blender/bmesh/intern/bmesh_strands_conv.c
index 3e63dd2..821c372 100644
--- a/source/blender/bmesh/intern/bmesh_strands_conv.c
+++ b/source/blender/bmesh/intern/bmesh_strands_conv.c
@@ -26,20 +26,24 @@
  * BM mesh conversion functions.
  */
 
+#include "DNA_cache_library_types.h"
 #include "DNA_meshdata_types.h"
 #include "DNA_object_types.h"
 #include "DNA_particle_types.h"
 #include "DNA_key_types.h"
+#include "DNA_strands_types.h"
 
 #include "MEM_guardedalloc.h"
 
 #include "BLI_listbase.h"
 #include "BLI_math.h"
 
+#includ

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to