* Added AnimData for Armature data, for animating armature/bone settings.
authorMatt Ebb <matt@mke3.net>
Mon, 21 Sep 2009 06:43:20 +0000 (06:43 +0000)
committerMatt Ebb <matt@mke3.net>
Mon, 21 Sep 2009 06:43:20 +0000 (06:43 +0000)
This allows you to do funky things like animating the number of segments in a b-bone.

source/blender/blenkernel/intern/anim_sys.c
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/writefile.c
source/blender/editors/animation/anim_channels_defines.c
source/blender/editors/animation/anim_filter.c
source/blender/editors/include/ED_anim_api.h
source/blender/makesdna/DNA_action_types.h
source/blender/makesdna/DNA_armature_types.h
source/blender/makesrna/intern/rna_armature.c

index 8b761a2ee0e4639d2a3b5a51b6bc432ed18ac93d..af4bcd8b0f73da62d81ce9baa4d2a4b7d9b261c7 100644 (file)
@@ -72,7 +72,7 @@ static short id_has_animdata (ID *id)
        switch (GS(id->name)) {
                        /* has AnimData */
                case ID_OB:
-               case ID_MB: case ID_CU:
+               case ID_MB: case ID_CU: case ID_AR:
                case ID_KE:
                case ID_PA:
                case ID_MA: case ID_TE: case ID_NT:
@@ -1525,6 +1525,9 @@ void BKE_animsys_evaluate_all_animation (Main *main, float ctime)
                BKE_animsys_evaluate_animdata(id, adt, ctime, ADT_RECALC_ANIM);
        }
        
+       /* armatures */
+       EVAL_ANIM_IDS(main->armature.first, ADT_RECALC_ANIM);
+       
        /* meshes */
        // TODO...
        
index 78949d8bd8c764473b175b319e15baefd30caf1a..af7fda82fe45405ddc0dd491417dd68c7de129f1 100644 (file)
@@ -2331,6 +2331,7 @@ static void lib_link_armature(FileData *fd, Main *main)
 
        while(arm) {
                if(arm->id.flag & LIB_NEEDLINK) {
+                       if (arm->adt) lib_link_animdata(fd, &arm->id, arm->adt);
                        arm->id.flag -= LIB_NEEDLINK;
                }
                arm= arm->id.next;
@@ -2357,6 +2358,7 @@ static void direct_link_armature(FileData *fd, bArmature *arm)
        link_list(fd, &arm->bonebase);
        arm->edbo= NULL;
        arm->sketch = NULL;
+       arm->adt= newdataadr(fd, arm->adt);
        
        bone=arm->bonebase.first;
        while (bone) {
@@ -9697,15 +9699,8 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                sce->unit.scale_length= 1.0f;
                
                for(ob = main->object.first; ob; ob = ob->id.next) {
-                       ModifierData *md;
-
-                       /* add backwards pointer for fluidsim modifier RNA access */
-                       for (md=ob->modifiers.first; md; md = md->next) {
-                               if (md->type == eModifierType_Fluidsim) {
-                                       FluidsimModifierData *fluidmd= (FluidsimModifierData*) md;
-                                       fluidmd->fss->fmd = fluidmd;
-                               }
-                       }
+                       FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(ob, eModifierType_Fluidsim);
+                       if (fluidmd) fluidmd->fss->fmd = fluidmd;
                }
 
                for(sce= main->scene.first; sce; sce= sce->id.next)
@@ -10434,6 +10429,9 @@ static void expand_armature(FileData *fd, Main *mainvar, bArmature *arm)
 {
        Bone *curBone;
 
+       if(arm->adt)
+               expand_animdata(fd, mainvar, arm->adt);
+
        for (curBone = arm->bonebase.first; curBone; curBone=curBone->next) {
                expand_bones(fd, mainvar, curBone);
        }
index 98db27182ab2a1ca574c429aefa9a013ebbe0bc4..37d0ee58bb29d70d5b1aecc8e1eebb7d5a3ce727 100644 (file)
@@ -2116,6 +2116,8 @@ static void write_armatures(WriteData *wd, ListBase *idbase)
                        writestruct(wd, ID_AR, "bArmature", 1, arm);
                        if (arm->id.properties) IDP_WriteProperty(arm->id.properties, wd);
 
+                       if (arm->adt) write_animdata(wd, arm->adt);
+
                        /* Direct data */
                        bone= arm->bonebase.first;
                        while(bone) {
index e3418fa194ff5e62e758371d227a184d1e0cfeb3..7f0f2411bd08f09f525a6a45896baf9dd9ff0bf9 100644 (file)
@@ -1526,6 +1526,76 @@ static bAnimChannelType ACF_DSMBALL=
        acf_dsmball_setting_ptr                                 /* pointer for setting */
 };
 
+/* Armature Expander  ------------------------------------------- */
+
+// TODO: just get this from RNA?
+static int acf_dsarm_icon(bAnimListElem *ale)
+{
+       return ICON_ARMATURE_DATA;
+}
+
+/* get the appropriate flag(s) for the setting when it is valid  */
+static int acf_dsarm_setting_flag(int setting, short *neg)
+{
+       /* clear extra return data first */
+       *neg= 0;
+       
+       switch (setting) {
+               case ACHANNEL_SETTING_EXPAND: /* expanded */
+                       return ARM_DS_EXPAND;
+                       
+               case ACHANNEL_SETTING_MUTE: /* mute (only in NLA) */
+                       return ADT_NLA_EVAL_OFF;
+                       
+               case ACHANNEL_SETTING_VISIBLE: /* visible (only in Graph Editor) */
+                       *neg= 1;
+                       return ADT_CURVES_NOT_VISIBLE;
+               
+               default: /* unsupported */
+                       return 0;
+       }
+}
+
+/* get pointer to the setting */
+static void *acf_dsarm_setting_ptr(bAnimListElem *ale, int setting, short *type)
+{
+       bArmature *arm= (bArmature *)ale->data;
+       
+       /* clear extra return data first */
+       *type= 0;
+       
+       switch (setting) {
+               case ACHANNEL_SETTING_EXPAND: /* expanded */
+                       GET_ACF_FLAG_PTR(arm->flag);
+                       
+               case ACHANNEL_SETTING_MUTE: /* muted (for NLA only) */
+               case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */
+                       if (arm->adt)
+                               GET_ACF_FLAG_PTR(arm->adt->flag)
+                       else
+                               return NULL;
+               
+               default: /* unsupported */
+                       return NULL;
+       }
+}
+
+/* metaball expander type define */
+static bAnimChannelType ACF_DSARM= 
+{
+       acf_generic_dataexpand_backdrop,/* backdrop */
+       acf_generic_indention_1,                /* indent level */
+       acf_generic_basic_offset,               /* offset */
+       
+       acf_generic_idblock_name,               /* name */
+       acf_dsarm_icon,                         /* icon */
+       
+       acf_generic_dataexpand_setting_valid,   /* has setting */
+       acf_dsarm_setting_flag,                         /* flag for setting */
+       acf_dsarm_setting_ptr                                   /* pointer for setting */
+};
+
+
 /* ShapeKey Entry  ------------------------------------------- */
 // XXX ... this is currently obsolete...
 
@@ -1709,6 +1779,7 @@ void ANIM_init_channel_typeinfo_data (void)
                animchannelTypeInfo[type++]= &ACF_DSWOR;                /* World Channel */
                animchannelTypeInfo[type++]= &ACF_DSPART;               /* Particle Channel */
                animchannelTypeInfo[type++]= &ACF_DSMBALL;              /* MetaBall Channel */
+               animchannelTypeInfo[type++]= &ACF_DSARM;                /* Armature Channel */
                
                animchannelTypeInfo[type++]= NULL;                              /* ShapeKey */ // XXX this is no longer used for now...
                
index 55fb1ccace05006e7535040a369fa36b51ddcc30..38b702f81e040f5648d1f22b1cf022030306dc91 100644 (file)
@@ -52,6 +52,7 @@
 #include "DNA_ID.h"
 #include "DNA_anim_types.h"
 #include "DNA_action_types.h"
+#include "DNA_armature_types.h"
 #include "DNA_constraint_types.h"
 #include "DNA_camera_types.h"
 #include "DNA_curve_types.h"
@@ -1101,6 +1102,14 @@ static int animdata_filter_dopesheet_obdata (ListBase *anim_data, bDopeSheet *ad
                        expanded= FILTER_MBALL_OBJD(mb);
                }
                        break;
+               case OB_ARMATURE: /* ------- Armature ---------- */
+               {
+                       bArmature *arm= (bArmature *)ob->data;
+                       
+                       type= ANIMTYPE_DSARM;
+                       expanded= FILTER_ARM_OBJD(arm);
+               }
+                       break;
        }
        
        /* special exception for drivers instead of action */
@@ -1297,6 +1306,19 @@ static int animdata_filter_dopesheet_ob (ListBase *anim_data, bDopeSheet *ads, B
                        }
                }
                        break;
+               case OB_ARMATURE: /* ------- Armature ---------- */
+               {
+                       bArmature *arm= (bArmature *)ob->data;
+                       
+                       if ((ads->filterflag & ADS_FILTER_NOARM) == 0) {
+                               ANIMDATA_FILTER_CASES(arm,
+                                       { /* AnimData blocks - do nothing... */ },
+                                       obdata_ok= 1;,
+                                       obdata_ok= 1;,
+                                       obdata_ok= 1;)
+                       }
+               }
+                       break;
        }
        if (obdata_ok) 
                items += animdata_filter_dopesheet_obdata(anim_data, ads, base, filter_mode);
@@ -1652,6 +1674,23 @@ static int animdata_filter_dopesheet (ListBase *anim_data, bDopeSheet *ads, int
                                                        dataOk= !(ads->filterflag & ADS_FILTER_NOMBA);)
                                        }
                                                break;
+                                       case OB_ARMATURE: /* ------- Armature ---------- */
+                                       {
+                                               bArmature *arm= (bArmature *)ob->data;
+                                               dataOk= 0;
+                                               ANIMDATA_FILTER_CASES(arm, 
+                                                       if ((ads->filterflag & ADS_FILTER_NOARM)==0) {
+                                                               /* for the special AnimData blocks only case, we only need to add
+                                                                * the block if it is valid... then other cases just get skipped (hence ok=0)
+                                                                */
+                                                               ANIMDATA_ADD_ANIMDATA(arm);
+                                                               dataOk=0;
+                                                       },
+                                                       dataOk= !(ads->filterflag & ADS_FILTER_NOARM);, 
+                                                       dataOk= !(ads->filterflag & ADS_FILTER_NOARM);, 
+                                                       dataOk= !(ads->filterflag & ADS_FILTER_NOARM);)
+                                       }
+                                               break;
                                        default: /* --- other --- */
                                                dataOk= 0;
                                                break;
@@ -1734,6 +1773,12 @@ static int animdata_filter_dopesheet (ListBase *anim_data, bDopeSheet *ads, int
                                                dataOk= ANIMDATA_HAS_KEYS(mb);  
                                        }
                                                break;
+                                       case OB_ARMATURE: /* -------- Armature ---------- */
+                                       {
+                                               bArmature *arm= (bArmature *)ob->data;
+                                               dataOk= ANIMDATA_HAS_KEYS(arm); 
+                                       }
+                                               break;
                                        default: /* --- other --- */
                                                dataOk= 0;
                                                break;
index 799829a6e8783c666a7a2af3f13be27d059e5dfb..7e7aba8536374695570e4bc031c9f611a7e44c12 100644 (file)
@@ -137,6 +137,7 @@ typedef enum eAnim_ChannelType {
        ANIMTYPE_DSWOR,
        ANIMTYPE_DSPART,
        ANIMTYPE_DSMBALL,
+       ANIMTYPE_DSARM,
        
        ANIMTYPE_SHAPEKEY,              // XXX probably can become depreceated???
        
@@ -206,6 +207,7 @@ typedef enum eAnimFilter_Flags {
 #define FILTER_CUR_OBJD(cu) ((cu->flag & CU_DS_EXPAND))
 #define FILTER_PART_OBJD(part) ((part->flag & PART_DS_EXPAND))
 #define FILTER_MBALL_OBJD(mb) ((mb->flag2 & MB_DS_EXPAND))
+#define FILTER_ARM_OBJD(arm) ((arm->flag & ARM_DS_EXPAND))
        /* 'Sub-object/Action' channels (flags stored in Action) */
 #define SEL_ACTC(actc) ((actc->flag & ACT_SELECTED))
 #define EXPANDED_ACTC(actc) ((actc->flag & ACT_COLLAPSED)==0)
index 318204e3dd88ae4221998e65a7464a36872f8f87..42696eeb0924c01480a719e0923a58263cf2b9f4 100644 (file)
@@ -372,6 +372,7 @@ typedef enum DOPESHEET_FILTERFLAG {
        ADS_FILTER_NOSCE                        = (1<<15),
        ADS_FILTER_NOPART                       = (1<<16),
        ADS_FILTER_NOMBA                        = (1<<17),
+       ADS_FILTER_NOARM                        = (1<<18),
        
                /* NLA-specific filters */
        ADS_FILTER_NLA_NOACT            = (1<<20),      /* if the AnimData block has no NLA data, don't include to just show Action-line */
index bb60fb107ffc5548086f27d409b83c49cb864b14..590e7dadcdcaec9c5676acf787fdd559b2ba911c 100644 (file)
@@ -31,6 +31,8 @@
 #include "DNA_listBase.h"
 #include "DNA_ID.h"
 
+struct AnimData;
+
 /* this system works on different transformation space levels;
 
 1) Bone Space;         with each Bone having own (0,0,0) origin
@@ -69,6 +71,7 @@ typedef struct Bone {
 
 typedef struct bArmature {
        ID                      id;
+       struct AnimData *adt;
        ListBase        bonebase;
        ListBase        chainbase;
        ListBase        *edbo;                                  /* editbone listbase, we use pointer so we can check state */
@@ -102,7 +105,8 @@ typedef enum eArmature_Flag {
        ARM_AUTO_IK                     = (1<<9),
        ARM_NO_CUSTOM           = (1<<10),      /* made option negative, for backwards compat */
        ARM_COL_CUSTOM          = (1<<11),      /* draw custom colours  */
-       ARM_GHOST_ONLYSEL       = (1<<12)       /* when ghosting, only show selected bones (this should belong to ghostflag instead) */
+       ARM_GHOST_ONLYSEL       = (1<<12),      /* when ghosting, only show selected bones (this should belong to ghostflag instead) */
+       ARM_DS_EXPAND           = (1<<13)
 } eArmature_Flag;
 
 /* armature->drawtype */
index d06c8ccee03543b14e1b38afa6afda630ab37b1f..379ec208bc1f6db9c32f63f26c53efd98971e318 100644 (file)
@@ -62,6 +62,11 @@ static void rna_Armature_redraw_data(bContext *C, PointerRNA *ptr)
        WM_event_add_notifier(C, NC_GEOM|ND_DATA, id);
 }
 
+static char *rna_Bone_path(PointerRNA *ptr)
+{
+       return BLI_sprintfN("bones[\"%s\"]", ((Bone*)ptr->data)->name);
+}
+
 static void rna_bone_layer_set(short *layer, const int *values)
 {
        int i, tot= 0;
@@ -431,6 +436,7 @@ static void rna_def_bone(BlenderRNA *brna)
        srna= RNA_def_struct(brna, "Bone", NULL);
        RNA_def_struct_ui_text(srna, "Bone", "Bone in an Armature datablock.");
        RNA_def_struct_ui_icon(srna, ICON_BONE_DATA);
+       RNA_def_struct_path_func(srna, "rna_Bone_path");
        
        /* pointers/collections */
                /* parent (pointer) */
@@ -553,9 +559,10 @@ static void rna_def_armature(BlenderRNA *brna)
        srna= RNA_def_struct(brna, "Armature", "ID");
        RNA_def_struct_ui_text(srna, "Armature", "Armature datablock containing a hierarchy of bones, usually used for rigging characters.");
        RNA_def_struct_ui_icon(srna, ICON_ARMATURE_DATA);
-       
        RNA_def_struct_sdna(srna, "bArmature");
        
+       rna_def_animdata_common(srna);
+       
        /* Collections */
        prop= RNA_def_property(srna, "bones", PROP_COLLECTION, PROP_NONE);
        RNA_def_property_collection_sdna(prop, NULL, "bonebase", NULL);