Added support for custom RNA properties on Bones, only worked for
PoseChannel previously.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user