Shape Keys
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Thu, 22 Oct 2009 17:12:28 +0000 (17:12 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Thu, 22 Oct 2009 17:12:28 +0000 (17:12 +0000)
Active shape key can now be changed while in edit mode. This is based
on exit/enter editmode again in the background, which is not ideal,
as that loses the undo history. But that already happened anyway when
you did exit/change-active/enter manually.

release/scripts/ui/buttons_data_mesh.py
source/blender/blenlib/BLI_editVert.h
source/blender/editors/interface/interface_templates.c
source/blender/editors/mesh/editmesh.c
source/blender/editors/object/object_edit.c
source/blender/makesrna/intern/rna_object.c

index e29166a505fd67416193f6188a03e0e10386a390..77c6f83407313d4caad586f8a341a3559cbaaf7f 100644 (file)
@@ -154,6 +154,7 @@ class DATA_PT_shape_keys(DataButtonsPanel):
                        sub.alignment = 'RIGHT'
 
                        subrow = sub.row(align=True)
+                       subrow.active= enable_edit_value
                        subrow.itemR(ob, "shape_key_lock", icon='ICON_UNPINNED', text="")
                        subrow.itemR(kb, "mute", icon='ICON_MUTE_IPO_OFF', text="")
                        subrow.itemO("object.shape_key_clear", icon='ICON_X', text="")
@@ -163,31 +164,30 @@ class DATA_PT_shape_keys(DataButtonsPanel):
                        sub.itemR(ob, "shape_key_edit_mode", text="")
 
                        row = layout.row()
-                       row.enabled = enable_edit_value
                        row.itemR(kb, "name")
 
                        if key.relative:
                                if ob.active_shape_key_index != 0:
                                        row = layout.row()
-                                       row.enabled = enable_edit_value
+                                       row.active = enable_edit_value
                                        row.itemR(kb, "value")
                                        
                                        split = layout.split()
                                        sub = split.column(align=True)
-                                       sub.enabled = enable_edit_value
+                                       sub.active = enable_edit_value
                                        sub.itemL(text="Range:")
                                        sub.itemR(kb, "slider_min", text="Min")
                                        sub.itemR(kb, "slider_max", text="Max")
                                        
                                        sub = split.column(align=True)
-                                       sub.enabled = enable_edit_value
+                                       sub.active = enable_edit_value
                                        sub.itemL(text="Blend:")
                                        sub.item_pointerR(kb, "vertex_group", ob, "vertex_groups", text="")
                                        sub.item_pointerR(kb, "relative_key", key, "keys", text="")
                                        
                        else:
                                row = layout.row()
-                               row.enabled = enable_edit
+                               row.active = enable_edit_value
                                row.itemR(key, "slurph")
 
 class DATA_PT_uv_texture(DataButtonsPanel):
index 56a20d8462aa77bd5fe8d4a3e6975d3698b5229c..350810867832cff8be0be9f8998a9e0f4ddd5a91 100644 (file)
@@ -173,6 +173,8 @@ typedef struct EditMesh
        short mat_nr;
        /* stats */
        int totvert, totedge, totface, totvertsel, totedgesel, totfacesel;
+       /* shape key being edited */
+       int shapenr;
        
        struct DerivedMesh *derivedCage, *derivedFinal;
        /* the custom data layer mask that was last used to calculate
index 75ae475435a08e361a5b341c325b7b15769d2d1d..06735badebf6460997869223bc7870872d9aa923 100644 (file)
@@ -1960,7 +1960,7 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe
        Object *ob;
        uiBlock *block= uiLayoutGetBlock(layout);
        uiBut *but;
-       uiLayout *split, *overlap, *sub;
+       uiLayout *split, *overlap, *sub, *row;
        char *name, *namebuf;
        int icon;
 
@@ -1971,7 +1971,8 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe
 
        if(itemptr->type == &RNA_ShapeKey) {
                ob= (Object*)activeptr->data;
-               uiLayoutSetEnabled(sub, ob->mode != OB_MODE_EDIT);
+               if(ob->mode == OB_MODE_EDIT && !(ob->type == OB_MESH))
+                       uiLayoutSetEnabled(sub, 0);
        }
 
        but= uiDefButR(block, LISTROW, 0, "", 0,0, UI_UNIT_X*10,UI_UNIT_Y, activeptr, activepropname, 0, 0, i, 0, 0, "");
@@ -2005,11 +2006,13 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe
 
                uiItemL(split, name, icon);
 
-               if(i == 0) uiItemL(split, "", 0);
-               else uiItemR(split, "", 0, itemptr, "value", 0);
-               if(ob->mode == OB_MODE_EDIT && !(ob->shapeflag & OB_SHAPE_EDIT_MODE))
-                       uiLayoutSetEnabled(split, 0);
-               //uiItemR(split, "", ICON_MUTE_IPO_OFF, itemptr, "mute", 0);
+               row= uiLayoutRow(split, 1);
+               if(i == 0) uiItemL(row, "", 0);
+               else uiItemR(row, "", 0, itemptr, "value", 0);
+
+               if(ob->mode == OB_MODE_EDIT && !((ob->shapeflag & OB_SHAPE_EDIT_MODE) && ob->type == OB_MESH))
+                       uiLayoutSetActive(row, 0);
+               //uiItemR(row, "", ICON_MUTE_IPO_OFF, itemptr, "mute", 0);
        }
        else
                uiItemL(sub, name, icon);
index 408c793751be143a95c20efe3f3e52e02dc67be0..8b9de0f6348532635e6e10d21f1bc218582bccb0 100644 (file)
@@ -785,6 +785,7 @@ void make_editMesh(Scene *scene, Object *ob)
                /* undo-ing in past for previous editmode sessions gives corrupt 'keyindex' values */
                undo_editmode_clear();
                keyco= actkey->data;
+               em->shapenr= ob->shapenr;
        }
 
        /* make editverts */
@@ -1184,7 +1185,8 @@ void load_editMesh(Scene *scene, Object *ob)
 
        /* are there keys? */
        if(me->key) {
-               KeyBlock *currkey, *actkey = ob_get_keyblock(ob);
+               KeyBlock *currkey;
+               KeyBlock *actkey= BLI_findlink(&me->key->block, em->shapenr-1);
 
                /* Lets reorder the key data so that things line up roughly
                 * with the way things were before editmode */
index bd8b865a6c9963d9751d55b11be5e3c83548156c..3c332fa395324745f15179b79045a3b1c995c038 100644 (file)
@@ -480,7 +480,6 @@ void ED_object_enter_editmode(bContext *C, int flag)
 
 static int editmode_toggle_exec(bContext *C, wmOperator *op)
 {
-       
        if(!CTX_data_edit_object(C))
                ED_object_enter_editmode(C, EM_WAITCURSOR);
        else
index f81e3d5d66563b33a4f29dffd7d5c9d589ad91b4..13ecfd911145608489054026b40128b31a7e8315 100644 (file)
@@ -121,6 +121,21 @@ void rna_Object_update_data(bContext *C, PointerRNA *ptr)
        WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ptr->id.data);
 }
 
+void rna_Object_active_shape_update(bContext *C, PointerRNA *ptr)
+{
+       Object *ob= ptr->id.data;
+       Scene *scene= CTX_data_scene(C);
+       int editmode= (scene->obedit == ob && ob->type == OB_MESH);
+
+       if(editmode) {
+               /* exit/enter editmode to get new shape */
+               ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO);
+               ED_object_enter_editmode(C, EM_WAITCURSOR);
+       }
+
+       rna_Object_update_data(C, ptr);
+}
+
 static void rna_Object_dependency_update(bContext *C, PointerRNA *ptr)
 {
        DAG_id_flush_update(ptr->id.data, OB_RECALC_OB);
@@ -1657,7 +1672,7 @@ static void rna_def_object(BlenderRNA *brna)
        RNA_def_property_int_sdna(prop, NULL, "shapenr");
        RNA_def_property_int_funcs(prop, "rna_Object_active_shape_key_index_get", "rna_Object_active_shape_key_index_set", "rna_Object_active_shape_key_index_range");
        RNA_def_property_ui_text(prop, "Active Shape Key Index", "Current shape key index.");
-       RNA_def_property_update(prop, 0, "rna_Object_update_data");
+       RNA_def_property_update(prop, 0, "rna_Object_active_shape_update");
 
        RNA_api_object(srna);
 }