Commit: 02d660165728b15653ddd247397d6fd03f1e30bd
Author: Lukas Tönne
Date:   Thu May 21 17:35:40 2015 +0200
Branches: alembic
https://developer.blender.org/rB02d660165728b15653ddd247397d6fd03f1e30bd

Use a flag to explicitly apply shape keys to either the goal positions
or the motion state.

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

M       release/scripts/startup/bl_ui/properties_object.py
M       source/blender/blenkernel/BKE_key.h
M       source/blender/blenkernel/intern/cache_library.c
M       source/blender/blenkernel/intern/key.c
M       source/blender/editors/io/io_cache_shapekey.c
M       source/blender/makesdna/DNA_cache_library_types.h
M       source/blender/makesrna/intern/rna_cache_library.c

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

diff --git a/release/scripts/startup/bl_ui/properties_object.py 
b/release/scripts/startup/bl_ui/properties_object.py
index f3f960d..d781e0d 100644
--- a/release/scripts/startup/bl_ui/properties_object.py
+++ b/release/scripts/startup/bl_ui/properties_object.py
@@ -600,6 +600,8 @@ class OBJECT_PT_cache_library(ObjectButtonsPanel, Panel):
         #sub.operator("object.shape_key_remove", icon='ZOOMOUT', text="").all 
= False
         sub.menu("CACHELIB_MT_shape_key_specials", icon='DOWNARROW_HLT', 
text="")
 
+        col.prop(md, "use_motion_state")
+
         if kb:
             col.separator()
 
diff --git a/source/blender/blenkernel/BKE_key.h 
b/source/blender/blenkernel/BKE_key.h
index cf8d2f8..c5769fd 100644
--- a/source/blender/blenkernel/BKE_key.h
+++ b/source/blender/blenkernel/BKE_key.h
@@ -73,7 +73,7 @@ float *BKE_key_evaluate_strands_ex(
         int *r_totelem, float *arr, size_t arr_size);
 float *BKE_key_evaluate_strands(
         struct Strands *strand, struct Key *key, struct KeyBlock *actkbs, bool 
lock_shape,
-        int *r_totelem, bool use_motion_basis);
+        int *r_totelem, bool use_motion);
 
 struct Key      *BKE_key_from_object(struct Object *ob);
 struct KeyBlock *BKE_keyblock_from_object(struct Object *ob);
@@ -114,9 +114,9 @@ void    BKE_keyblock_update_from_mesh(struct Mesh *me, 
struct KeyBlock *kb);
 void    BKE_keyblock_convert_from_mesh(struct Mesh *me, struct KeyBlock *kb);
 void    BKE_keyblock_convert_to_mesh(struct KeyBlock *kb, struct Mesh *me);
 
-void    BKE_keyblock_update_from_strands(struct Strands *strands, struct 
KeyBlock *kb);
-void    BKE_keyblock_convert_from_strands(struct Strands *strands, struct Key 
*key, struct KeyBlock *kb);
-void    BKE_keyblock_convert_to_strands(struct KeyBlock *kb, struct Strands 
*strands);
+void    BKE_keyblock_update_from_strands(struct Strands *strands, struct 
KeyBlock *kb, bool use_motion);
+void    BKE_keyblock_convert_from_strands(struct Strands *strands, struct Key 
*key, struct KeyBlock *kb, bool use_motion);
+void    BKE_keyblock_convert_to_strands(struct KeyBlock *kb, struct Strands 
*strands, bool use_motion);
 
 void    BKE_keyblock_update_from_vertcos(struct Object *ob, struct KeyBlock 
*kb, float (*vertCos)[3]);
 void    BKE_keyblock_convert_from_vertcos(struct Object *ob, struct KeyBlock 
*kb, float (*vertCos)[3]);
diff --git a/source/blender/blenkernel/intern/cache_library.c 
b/source/blender/blenkernel/intern/cache_library.c
index dbccbed..68e0a50 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -1518,6 +1518,7 @@ static void 
strandskey_foreach_id_link(StrandsKeyCacheModifier *skmd, CacheLibra
 
 static void strandskey_process(StrandsKeyCacheModifier *skmd, 
CacheProcessContext *UNUSED(ctx), CacheProcessData *data, int UNUSED(frame), 
int UNUSED(frame_prev), eCacheLibrary_EvalMode UNUSED(eval_mode))
 {
+       const bool use_motion = skmd->flag & 
eStrandsKeyCacheModifier_Flag_UseMotionState;
        Object *ob = skmd->object;
        Strands *strands;
        KeyBlock *actkb;
@@ -1525,41 +1526,31 @@ static void strandskey_process(StrandsKeyCacheModifier 
*skmd, CacheProcessContex
        
        if (!BKE_cache_modifier_find_strands(data->dupcache, ob, 
skmd->hair_system, NULL, &strands, NULL))
                return;
+       if (use_motion && !strands->state)
+               return;
        
        actkb = BLI_findlink(&skmd->key->block, skmd->shapenr);
-       shape = BKE_key_evaluate_strands(strands, skmd->key, actkb, skmd->flag 
& eStrandsKeyCacheModifier_Flag_ShapeLock, NULL, false);
+       shape = BKE_key_evaluate_strands(strands, skmd->key, actkb, skmd->flag 
& eStrandsKeyCacheModifier_Flag_ShapeLock, NULL, use_motion);
        if (shape) {
                StrandsVertex *vert = strands->verts;
+               StrandsMotionState *state = use_motion ? strands->state : NULL;
                int totvert = strands->totverts;
                int i;
                
                float *fp = shape;
                for (i = 0; i < totvert; ++i) {
-                       copy_v3_v3(vert->co, fp);
-                       ++vert;
-                       fp += 3;
-               }
-               
-               MEM_freeN(shape);
-       }
-       
-       /* motion shape, if needed */
-       if (strands->state) {
-               shape = BKE_key_evaluate_strands(strands, skmd->key, actkb, 
skmd->flag & eStrandsKeyCacheModifier_Flag_ShapeLock, NULL, true);
-               if (shape) {
-                       StrandsMotionState *state = strands->state;
-                       int totvert = strands->totverts;
-                       int i;
-                       
-                       float *fp = shape;
-                       for (i = 0; i < totvert; ++i) {
+                       if (state) {
                                copy_v3_v3(state->co, fp);
                                ++state;
-                               fp += 3;
                        }
-                       
-                       MEM_freeN(shape);
+                       else {
+                               copy_v3_v3(vert->co, fp);
+                               ++vert;
+                       }
+                       fp += 3;
                }
+               
+               MEM_freeN(shape);
        }
 }
 
@@ -1577,6 +1568,7 @@ CacheModifierTypeInfo cacheModifierType_StrandsKey = {
 
 KeyBlock *BKE_cache_modifier_strands_key_insert_key(StrandsKeyCacheModifier 
*skmd, Strands *strands, const char *name, const bool from_mix)
 {
+       const bool use_motion = skmd->flag & 
eStrandsKeyCacheModifier_Flag_UseMotionState;
        Key *key = skmd->key;
        KeyBlock *kb;
        bool newkey = false;
@@ -1593,14 +1585,14 @@ KeyBlock 
*BKE_cache_modifier_strands_key_insert_key(StrandsKeyCacheModifier *skm
        if (newkey || from_mix == false) {
                /* create from mesh */
                kb = BKE_keyblock_add_ctime(key, name, false);
-               BKE_keyblock_convert_from_strands(strands, key, kb);
+               BKE_keyblock_convert_from_strands(strands, key, kb, use_motion);
        }
        else {
                /* copy from current values */
                KeyBlock *actkb = BLI_findlink(&skmd->key->block, 
skmd->shapenr);
                bool shape_lock = skmd->flag & 
eStrandsKeyCacheModifier_Flag_ShapeLock;
                int totelem;
-               float *data = BKE_key_evaluate_strands(strands, key, actkb, 
shape_lock, &totelem, false);
+               float *data = BKE_key_evaluate_strands(strands, key, actkb, 
shape_lock, &totelem, use_motion);
                
                /* create new block with prepared data */
                kb = BKE_keyblock_add_ctime(key, name, false);
diff --git a/source/blender/blenkernel/intern/key.c 
b/source/blender/blenkernel/intern/key.c
index c5f4da3..3bcb1bf 100644
--- a/source/blender/blenkernel/intern/key.c
+++ b/source/blender/blenkernel/intern/key.c
@@ -1866,7 +1866,7 @@ float *BKE_key_evaluate_strands_ex(Strands *strands, Key 
*key, KeyBlock *actkb,
        return (float *)out;
 }
 
-float *BKE_key_evaluate_strands(Strands *strands, Key *key, KeyBlock *actkb, 
bool lock_shape, int *r_totelem, bool use_motion_basis)
+float *BKE_key_evaluate_strands(Strands *strands, Key *key, KeyBlock *actkb, 
bool lock_shape, int *r_totelem, bool use_motion)
 {
        size_t size = sizeof(float) * 3 * strands->totverts;
        float *data = MEM_mallocN(size, "strands shape key data");
@@ -1874,7 +1874,7 @@ float *BKE_key_evaluate_strands(Strands *strands, Key 
*key, KeyBlock *actkb, boo
        float *fp;
        int i;
        
-       if (use_motion_basis && strands->state) {
+       if (use_motion && strands->state) {
                for (i = 0, fp = data; i < strands->totverts; ++i, fp += 3)
                        copy_v3_v3(fp, strands->state[i].co);
        }
@@ -2261,9 +2261,8 @@ void BKE_keyblock_convert_to_mesh(KeyBlock *kb, Mesh *me)
 }
 
 /************************* Strands ************************/
-void BKE_keyblock_update_from_strands(Strands *strands, KeyBlock *kb)
+void BKE_keyblock_update_from_strands(Strands *strands, KeyBlock *kb, bool 
use_motion)
 {
-       StrandsVertex *vert;
        float (*fp)[3];
        int a, tot;
 
@@ -2272,14 +2271,23 @@ void BKE_keyblock_update_from_strands(Strands *strands, 
KeyBlock *kb)
        tot = strands->totverts;
        if (tot == 0) return;
 
-       vert = strands->verts;
        fp = kb->data;
-       for (a = 0; a < tot; a++, fp++, vert++) {
-               copy_v3_v3(*fp, vert->co);
+       /* use vertex locations as fallback, so we always get a valid shape */
+       if (use_motion && strands->state) {
+               StrandsMotionState *state = strands->state;
+               for (a = 0; a < tot; a++, fp++, state++) {
+                       copy_v3_v3(*fp, state->co);
+               }
+       }
+       else {
+               StrandsVertex *vert = strands->verts;
+               for (a = 0; a < tot; a++, fp++, vert++) {
+                       copy_v3_v3(*fp, vert->co);
+               }
        }
 }
 
-void BKE_keyblock_convert_from_strands(Strands *strands, Key *key, KeyBlock 
*kb)
+void BKE_keyblock_convert_from_strands(Strands *strands, Key *key, KeyBlock 
*kb, bool use_motion)
 {
        int tot = strands->totverts;
 
@@ -2290,22 +2298,31 @@ void BKE_keyblock_convert_from_strands(Strands 
*strands, Key *key, KeyBlock *kb)
        kb->data = MEM_mallocN(key->elemsize * tot, __func__);
        kb->totelem = tot;
 
-       BKE_keyblock_update_from_strands(strands, kb);
+       BKE_keyblock_update_from_strands(strands, kb, use_motion);
 }
 
-void BKE_keyblock_convert_to_strands(KeyBlock *kb, Strands *strands)
+void BKE_keyblock_convert_to_strands(KeyBlock *kb, Strands *strands, bool 
use_motion)
 {
-       StrandsVertex *vert;
        const float (*fp)[3];
        int a, tot;
 
-       vert = strands->verts;
        fp = kb->data;
 
        tot = min_ii(kb->totelem, strands->totverts);
 
-       for (a = 0; a < tot; a++, fp++, vert++) {
-               copy_v3_v3(vert->co, *fp);
+       if (use_motion) {
+               if (strands->state) {
+                       StrandsMotionState *state = strands->state;
+                       for (a = 0; a < tot; a++, fp++, state++) {
+                               copy_v3_v3(state->co, *fp);
+                       }
+               }
+       }
+       else {
+               StrandsVertex *vert = strands->verts;
+               for (a = 0; a < tot; a++, fp++, vert++) {
+                       copy_v3_v3(vert->co, *fp);
+               }
        }
 }
 
diff --git a/source/blender/editors/io/io_cache_shapekey.c 
b/source/blender/editors/io/io_cache_shapekey.c
index b9bcbf1..33490d8 100644
--- a/source/blender/editors/io/io_cache_shapekey.c
+++ b/source/blender/editors/io/io_cache_shapekey.c
@@ -134,7 +134,7 @@ static bool 
ED_cache_shape_key_remove(StrandsKeyCacheModifier *skmd, Strands *st
        
                        if (key->refkey) {
                                /* apply new basis key on original data */
-                               BKE_keyblock_convert_to_strands(key->refkey, 
strands);
+                               BKE_keyblock_convert_to_strands(key->refkey, 
strands, skmd->flag & eStrandsKeyCacheModifier_Flag_UseMotionState);
                        }
                }
                
diff --git a/source/blender/makesdna/DNA_cache_library_types.h 
b/source/blender/makesdna/DNA_cache_library_types.h
index 9a16cee..4ae73e2 100644
--- a/source/blender/makesdna/DNA_cache_library_types.h
+++ b/source/blender/makesdna/DNA_cache_library_types.h
@@ -265,6 +265,7 @@ typedef struct StrandsKeyCacheModifier {
 
 typedef enum eStrandsKeyCacheModifier_Flag {
        eStrandsKeyCacheModifier_Flag_ShapeLock             = (1 << 0),
+       eStrandsKeyCacheModifier_Flag_UseMotionState        = (1 << 1),
 } eStrandsKeyCacheModifier_Flag;
 
 #endif
diff --git a/source/blende

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to