[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [24139] trunk/blender/source/blender: Added support for custom RNA properties on Bones, only worked for

Brecht Van Lommel brecht at blender.org
Wed Oct 28 16:33:45 CET 2009


Revision: 24139
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=24139
Author:   blendix
Date:     2009-10-28 16:33:45 +0100 (Wed, 28 Oct 2009)

Log Message:
-----------
Added support for custom RNA properties on Bones, only worked for
PoseChannel previously.

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

Modified: trunk/blender/source/blender/blenkernel/BKE_armature.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_armature.h	2009-10-28 11:55:58 UTC (rev 24138)
+++ trunk/blender/source/blender/blenkernel/BKE_armature.h	2009-10-28 15:33:45 UTC (rev 24139)
@@ -72,8 +72,7 @@
 
 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);

Modified: trunk/blender/source/blender/blenkernel/intern/armature.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/armature.c	2009-10-28 11:55:58 UTC (rev 24138)
+++ trunk/blender/source/blender/blenkernel/intern/armature.c	2009-10-28 15:33:45 UTC (rev 24139)
@@ -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 @@
 	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) {

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2009-10-28 11:55:58 UTC (rev 24138)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2009-10-28 15:33:45 UTC (rev 24139)
@@ -2345,12 +2345,14 @@
 	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)

Modified: trunk/blender/source/blender/blenloader/intern/writefile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/writefile.c	2009-10-28 11:55:58 UTC (rev 24138)
+++ trunk/blender/source/blender/blenloader/intern/writefile.c	2009-10-28 15:33:45 UTC (rev 24139)
@@ -2131,6 +2131,11 @@
 		
 	// 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;

Modified: trunk/blender/source/blender/editors/armature/editarmature.c
===================================================================
--- trunk/blender/source/blender/editors/armature/editarmature.c	2009-10-28 11:55:58 UTC (rev 24138)
+++ trunk/blender/source/blender/editors/armature/editarmature.c	2009-10-28 15:33:45 UTC (rev 24139)
@@ -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 @@
 		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 @@
 	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 @@
 		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 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;
 	}

Modified: trunk/blender/source/blender/editors/include/ED_armature.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_armature.h	2009-10-28 11:55:58 UTC (rev 24138)
+++ trunk/blender/source/blender/editors/include/ED_armature.h	2009-10-28 15:33:45 UTC (rev 24139)
@@ -41,10 +41,12 @@
 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.	*/

Modified: trunk/blender/source/blender/makesdna/DNA_armature_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_armature_types.h	2009-10-28 11:55:58 UTC (rev 24138)
+++ trunk/blender/source/blender/makesdna/DNA_armature_types.h	2009-10-28 15:33:45 UTC (rev 24139)
@@ -44,6 +44,7 @@
 
 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 */

Modified: trunk/blender/source/blender/makesrna/intern/rna_armature.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_armature.c	2009-10-28 11:55:58 UTC (rev 24138)
+++ trunk/blender/source/blender/makesrna/intern/rna_armature.c	2009-10-28 15:33:45 UTC (rev 24139)
@@ -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 @@
 	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 @@
 	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 @@
 	
 	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);
 	





More information about the Bf-blender-cvs mailing list