Added support for custom RNA properties on Bones, only worked for
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 28 Oct 2009 15:33:45 +0000 (15:33 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 28 Oct 2009 15:33:45 +0000 (15:33 +0000)
PoseChannel previously.

source/blender/blenkernel/BKE_armature.h
source/blender/blenkernel/intern/armature.c
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/writefile.c
source/blender/editors/armature/editarmature.c
source/blender/editors/include/ED_armature.h
source/blender/makesdna/DNA_armature_types.h
source/blender/makesrna/intern/rna_armature.c

index 8f109034e3ea1466b7648961b89f32d651feaeb6..19c2662054b9310729fd2e18c54df2df1ca610b8 100644 (file)
@@ -72,8 +72,7 @@ extern "C" {
 
 struct bArmature *add_armature(char *name);
 struct bArmature *get_armature(struct Object *ob);
-void free_boneChildren(struct Bone *bone);
-void free_bones (struct bArmature *arm);
+void free_bonelist (struct ListBase *lb);
 void free_armature(struct bArmature *arm);
 void make_local_armature(struct bArmature *arm);
 struct bArmature *copy_armature(struct bArmature *arm);
index 504450e033414894cc02c8fbfc5a99f0b0f0bc4c..139ff9d6b19a8379e17a8d5274abd6c0b3da8578 100644 (file)
@@ -60,6 +60,7 @@
 #include "BKE_DerivedMesh.h"
 #include "BKE_displist.h"
 #include "BKE_global.h"
+#include "BKE_idprop.h"
 #include "BKE_library.h"
 #include "BKE_lattice.h"
 #include "BKE_main.h"
@@ -93,43 +94,25 @@ bArmature *get_armature(Object *ob)
        return NULL;
 }
 
-void free_boneChildren(Bone *bone)
-{ 
-       Bone *child;
-       
-       if (bone) {
-               
-               child=bone->childbase.first;
-               if (child){
-                       while (child){
-                               free_boneChildren (child);
-                               child=child->next;
-                       }
-                       BLI_freelistN (&bone->childbase);
-               }
-       }
-}
-
-void free_bones (bArmature *arm)
+void free_bonelist (ListBase *lb)
 {
        Bone *bone;
-       /*      Free children (if any)  */
-       bone= arm->bonebase.first;
-       if (bone) {
-               while (bone){
-                       free_boneChildren (bone);
-                       bone=bone->next;
+
+       for(bone=lb->first; bone; bone=bone->next) {
+               if(bone->prop) {
+                       IDP_FreeProperty(bone->prop);
+                       MEM_freeN(bone->prop);
                }
+               free_bonelist(&bone->childbase);
        }
        
-       
-       BLI_freelistN(&arm->bonebase);
+       BLI_freelistN(lb);
 }
 
 void free_armature(bArmature *arm)
 {
        if (arm) {
-               free_bones(arm);
+               free_bonelist(&arm->bonebase);
                
                /* free editmode data */
                if (arm->edbo) {
index 6ced440f5a5212c651363f281b3cdb87a73b7f4e..5d6338af4098b395d674d846f32aa529f5197edc 100644 (file)
@@ -2345,12 +2345,14 @@ static void direct_link_bones(FileData *fd, Bone* bone)
        Bone    *child;
 
        bone->parent= newdataadr(fd, bone->parent);
+       bone->prop= newdataadr(fd, bone->prop);
+       if(bone->prop)
+               IDP_DirectLinkProperty(bone->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
 
        link_list(fd, &bone->childbase);
 
-       for (child=bone->childbase.first; child; child=child->next) {
+       for(child=bone->childbase.first; child; child=child->next)
                direct_link_bones(fd, child);
-       }
 }
 
 static void direct_link_armature(FileData *fd, bArmature *arm)
index 7368663f64abd6662e217ecb30575600e5ae99f0..ee84ae59974eb60e437ea6d6c7a6f60899497186 100644 (file)
@@ -2131,6 +2131,11 @@ static void write_bone(WriteData *wd, Bone* bone)
                
        // Write this bone
        writestruct(wd, DATA, "Bone", 1, bone);
+
+       /* Write ID Properties -- and copy this comment EXACTLY for easy finding
+        of library blocks that implement this.*/
+       if (bone->prop)
+               IDP_WriteProperty(bone->prop, wd);
        
        // Write Children
        cbone= bone->childbase.first;
index 266e4fbdbb4b780981276dc4eb4c7d37f043253f..1e94e1b440c04c0a5c8b6df10cad5f1da28343b4 100644 (file)
@@ -64,6 +64,7 @@
 #include "BKE_depsgraph.h"
 #include "BKE_DerivedMesh.h"
 #include "BKE_global.h"
+#include "BKE_idprop.h"
 #include "BKE_main.h"
 #include "BKE_object.h"
 #include "BKE_report.h"
@@ -186,6 +187,9 @@ void make_boneList(ListBase *edbo, ListBase *bones, EditBone *parent)
                eBone->rad_tail= curBone->rad_tail;
                eBone->segments = curBone->segments;            
                eBone->layer = curBone->layer;
+
+               if(curBone->prop)
+                       eBone->prop= IDP_CopyProperty(curBone->prop);
                
                BLI_addtail(edbo, eBone);
                
@@ -251,7 +255,7 @@ void ED_armature_from_edit(Object *obedit)
        Object *obt;
        
        /* armature bones */
-       free_bones(arm);
+       free_bonelist(&arm->bonebase);
        
        /* remove zero sized bones, this gives instable restposes */
        for (eBone=arm->edbo->first; eBone; eBone= neBone) {
@@ -294,6 +298,9 @@ void ED_armature_from_edit(Object *obedit)
                newBone->rad_tail= eBone->rad_tail;
                newBone->segments= eBone->segments;
                newBone->layer = eBone->layer;
+
+               if(eBone->prop)
+                       newBone->prop= IDP_CopyProperty(eBone->prop);
        }
        
        /*      Fix parenting in a separate pass to ensure ebone->bone connections
@@ -1902,11 +1909,21 @@ void mouse_armature(bContext *C, short mval[2], int extend)
 void ED_armature_edit_free(struct Object *ob)
 {
        bArmature *arm= ob->data;
+       EditBone *eBone;
        
        /*      Clear the editbones list */
        if (arm->edbo) {
-               if (arm->edbo->first)
+               if (arm->edbo->first) {
+                       for (eBone=arm->edbo->first; eBone; eBone=eBone->next) {
+                               if (eBone->prop) {
+                                       IDP_FreeProperty(eBone->prop);
+                                       MEM_freeN(eBone->prop);
+                               }
+                       }
+
                        BLI_freelistN(arm->edbo);
+               }
+
                MEM_freeN(arm->edbo);
                arm->edbo= NULL;
        }
index 0204acd6fbe1247a9feab99c5591089bbb5764de..4898f70201e0202b28ea3119c820a75c659605c1 100644 (file)
@@ -41,10 +41,12 @@ struct View3D;
 struct ViewContext;
 struct RegionView3D;
 struct SK_Sketch;
+struct IDProperty;
 
 typedef struct EditBone
 {
        struct EditBone *next, *prev;
+       struct IDProperty               *prop;                  /* User-Defined Properties on this Bone */
        struct EditBone *parent;/*      Editbones have a one-way link  (i.e. children refer
                                                                        to parents.  This is converted to a two-way link for
                                                                        normal bones when leaving editmode.     */
index 590e7dadcdcaec9c5676acf787fdd559b2ba911c..0f80fb4821f5149c8aebef8a385dff9f57e72955 100644 (file)
@@ -44,6 +44,7 @@ struct AnimData;
 
 typedef struct Bone {
        struct Bone             *next, *prev;   /*      Next/prev elements within this list     */
+       IDProperty              *prop;                  /* User-Defined Properties on this Bone */
        struct Bone             *parent;                /*      Parent (ik parent if appropriate flag is set            */
        ListBase                childbase;              /*      Children        */
        char                    name[32];               /*  Name of the bone - must be unique within the armature */
index 6c9d9263eebb7d06170d38024e8303e501583711..889f23e0d391eaf5250cf363f2370c84c00f54ab 100644 (file)
@@ -42,6 +42,7 @@
 
 #include "BKE_context.h"
 #include "BKE_depsgraph.h"
+#include "BKE_idprop.h"
 #include "BKE_main.h"
 
 #include "ED_armature.h"
@@ -67,6 +68,30 @@ static char *rna_Bone_path(PointerRNA *ptr)
        return BLI_sprintfN("bones[\"%s\"]", ((Bone*)ptr->data)->name);
 }
 
+static IDProperty *rna_Bone_idproperties(PointerRNA *ptr, int create)
+{
+       Bone *bone= ptr->data;
+
+       if(create && !bone->prop) {
+               IDPropertyTemplate val = {0};
+               bone->prop= IDP_New(IDP_GROUP, val, "RNA_Bone ID properties");
+       }
+
+       return bone->prop;
+}
+
+static IDProperty *rna_EditBone_idproperties(PointerRNA *ptr, int create)
+{
+       EditBone *ebone= ptr->data;
+
+       if(create && !ebone->prop) {
+               IDPropertyTemplate val = {0};
+               ebone->prop= IDP_New(IDP_GROUP, val, "RNA_EditBone ID properties");
+       }
+
+       return ebone->prop;
+}
+
 static void rna_bone_layer_set(short *layer, const int *values)
 {
        int i, tot= 0;
@@ -442,6 +467,7 @@ static void rna_def_bone(BlenderRNA *brna)
        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");
+       RNA_def_struct_idproperties_func(srna, "rna_Bone_idproperties");
        
        /* pointers/collections */
                /* parent (pointer) */
@@ -509,6 +535,7 @@ static void rna_def_edit_bone(BlenderRNA *brna)
        
        srna= RNA_def_struct(brna, "EditBone", NULL);
        RNA_def_struct_sdna(srna, "EditBone");
+       RNA_def_struct_idproperties_func(srna, "rna_Bone_idproperties");
        RNA_def_struct_ui_text(srna, "Edit Bone", "Editmode bone in an Armature datablock.");
        RNA_def_struct_ui_icon(srna, ICON_BONE_DATA);