From 6c139156cf2b47ea9d8e7606204205cb01d4ad21 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Fri, 19 Jun 2009 14:56:49 +0000 Subject: RNA: * EditBone wrapped, using manual get/set function, and used in the UI code. Makes the RNA wrapping code here more complicated, but works. --- release/datafiles/blenderbuttons | Bin 177005 -> 175808 bytes release/ui/buttons_data_bone.py | 9 +- .../editors/space_buttons/buttons_context.c | 28 +- source/blender/makesrna/RNA_access.h | 1 + source/blender/makesrna/intern/makesrna.c | 4 +- source/blender/makesrna/intern/rna_ID.c | 1 - source/blender/makesrna/intern/rna_access.c | 2 +- source/blender/makesrna/intern/rna_armature.c | 552 ++++++++++++++++++--- 8 files changed, 504 insertions(+), 93 deletions(-) diff --git a/release/datafiles/blenderbuttons b/release/datafiles/blenderbuttons index 467e79f024a..963c76fcfa9 100644 Binary files a/release/datafiles/blenderbuttons and b/release/datafiles/blenderbuttons differ diff --git a/release/ui/buttons_data_bone.py b/release/ui/buttons_data_bone.py index 2abe76b93c1..044f7b93806 100644 --- a/release/ui/buttons_data_bone.py +++ b/release/ui/buttons_data_bone.py @@ -7,7 +7,7 @@ class BoneButtonsPanel(bpy.types.Panel): __context__ = "bone" def poll(self, context): - return (context.bone != None) + return (context.bone or context.edit_bone) class BONE_PT_bone(BoneButtonsPanel): __idname__ = "BONE_PT_bone" @@ -16,6 +16,8 @@ class BONE_PT_bone(BoneButtonsPanel): def draw(self, context): layout = self.layout bone = context.bone + if not bone: + bone = context.edit_bone split = layout.split() @@ -40,8 +42,7 @@ class BONE_PT_bone(BoneButtonsPanel): sub.itemL(text="Display:") sub.itemR(bone, "draw_wire", text="Wireframe") - sub.itemR(bone, "editmode_hidden", text="Hide (EditMode)") - sub.itemR(bone, "pose_channel_hidden", text="Hide (PoseMode)") + sub.itemR(bone, "hidden", text="Hide") sub.itemL(text="Curved Bones:") sub.itemR(bone, "bbone_segments", text="Segments") @@ -50,4 +51,4 @@ class BONE_PT_bone(BoneButtonsPanel): sub.itemR(bone, "cyclic_offset") -bpy.types.register(BONE_PT_bone) \ No newline at end of file +bpy.types.register(BONE_PT_bone) diff --git a/source/blender/editors/space_buttons/buttons_context.c b/source/blender/editors/space_buttons/buttons_context.c index 42180e7902f..fc280d9b551 100644 --- a/source/blender/editors/space_buttons/buttons_context.c +++ b/source/blender/editors/space_buttons/buttons_context.c @@ -54,6 +54,7 @@ #include "RNA_access.h" +#include "ED_armature.h" #include "ED_screen.h" #include "UI_interface.h" @@ -249,16 +250,29 @@ static int buttons_context_path_bone(ButsContextPath *path) { bArmature *arm; Bone *bone; + EditBone *edbo; /* if we have an armature, get the active bone */ if(buttons_context_path_data(path, OB_ARMATURE)) { arm= path->ptr[path->len-1].data; - bone= find_active_bone(arm->bonebase.first); - if(bone) { - RNA_pointer_create(&arm->id, &RNA_Bone, bone, &path->ptr[path->len]); - path->len++; - return 1; + if(arm->edbo) { + for(edbo=arm->edbo->first; edbo; edbo=edbo->next) { + if(edbo->flag & BONE_ACTIVE) { + RNA_pointer_create(&arm->id, &RNA_EditBone, edbo, &path->ptr[path->len]); + path->len++; + return 1; + } + } + } + else { + bone= find_active_bone(arm->bonebase.first); + + if(bone) { + RNA_pointer_create(&arm->id, &RNA_Bone, bone, &path->ptr[path->len]); + path->len++; + return 1; + } } } @@ -569,6 +583,10 @@ int buttons_context(const bContext *C, const char *member, bContextDataResult *r set_pointer_type(path, result, &RNA_Bone); return 1; } + else if(CTX_data_equals(member, "edit_bone")) { + set_pointer_type(path, result, &RNA_EditBone); + return 1; + } else if(CTX_data_equals(member, "particle_system")) { set_pointer_type(path, result, &RNA_ParticleSystem); return 1; diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index 1907b2cedb4..9b653bd924a 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -164,6 +164,7 @@ extern StructRNA RNA_DomainFluidSettings; extern StructRNA RNA_Driver; extern StructRNA RNA_DriverTarget; extern StructRNA RNA_EdgeSplitModifier; +extern StructRNA RNA_EditBone; extern StructRNA RNA_EffectSequence; extern StructRNA RNA_EnumProperty; extern StructRNA RNA_EnumPropertyItem; diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c index a8fe025fd46..c8273513711 100644 --- a/source/blender/makesrna/intern/makesrna.c +++ b/source/blender/makesrna/intern/makesrna.c @@ -702,8 +702,10 @@ static char *rna_def_property_begin_func(FILE *f, StructRNA *srna, PropertyRNA * else { if(manualfunc) fprintf(f, "\n %s(iter, ptr);\n", manualfunc); - else + else if(dp->dnapointerlevel == 0) fprintf(f, "\n rna_iterator_listbase_begin(iter, &data->%s, NULL);\n", dp->dnaname); + else + fprintf(f, "\n rna_iterator_listbase_begin(iter, data->%s, NULL);\n", dp->dnaname); } getfunc= rna_alloc_function_name(srna->identifier, prop->identifier, "get"); diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c index 52680e26afe..7d8bab8bee8 100644 --- a/source/blender/makesrna/intern/rna_ID.c +++ b/source/blender/makesrna/intern/rna_ID.c @@ -218,7 +218,6 @@ static void rna_def_ID(BlenderRNA *brna) { StructRNA *srna; PropertyRNA *prop; - FunctionRNA *func; srna= RNA_def_struct(brna, "ID", NULL); RNA_def_struct_ui_text(srna, "ID", "Base type for datablocks, defining a unique name, linking from other libraries and garbage collection."); diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index cfddb1daf10..8d0d87a72d3 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -1500,7 +1500,7 @@ void rna_iterator_listbase_begin(CollectionPropertyIterator *iter, ListBase *lb, ListBaseIterator *internal; internal= MEM_callocN(sizeof(ListBaseIterator), "ListBaseIterator"); - internal->link= lb->first; + internal->link= (lb)? lb->first: NULL; internal->skip= skip; iter->internal= internal; diff --git a/source/blender/makesrna/intern/rna_armature.c b/source/blender/makesrna/intern/rna_armature.c index 631550964d6..0f437f8f1a8 100644 --- a/source/blender/makesrna/intern/rna_armature.c +++ b/source/blender/makesrna/intern/rna_armature.c @@ -36,25 +36,32 @@ #ifdef RNA_RUNTIME -static void rna_Bone_layer_set(PointerRNA *ptr, const int *values) +#include "ED_armature.h" + +static void rna_bone_layer_set(short *layer, const int *values) { - Bone *bone= (Bone*)ptr->data; int i, tot= 0; /* ensure we always have some layer selected */ - for(i=0; i<20; i++) + for(i=0; i<16; i++) if(values[i]) tot++; if(tot==0) return; - for(i=0; i<20; i++) { - if(values[i]) bone->layer |= (1<layer &= ~(1<data; + rna_bone_layer_set(&bone->layer, values); +} + static void rna_Armature_layer_set(PointerRNA *ptr, const int *values) { bArmature *arm= (bArmature*)ptr->data; @@ -102,152 +109,529 @@ static void rna_Armature_path_end_frame_set(PointerRNA *ptr, int value) data->pathef= value; } +PointerRNA rna_EditBone_rna_type_get(PointerRNA *ptr) +{ + return rna_builtin_type_get(ptr); +} + +void rna_EditBone_name_get(PointerRNA *ptr, char *value) +{ + EditBone *data= (EditBone*)(ptr->data); + BLI_strncpy(value, data->name, sizeof(data->name)); +} + +int rna_EditBone_name_length(PointerRNA *ptr) +{ + EditBone *data= (EditBone*)(ptr->data); + return strlen(data->name); +} + +int rna_EditBone_active_get(PointerRNA *ptr) +{ + EditBone *data= (EditBone*)(ptr->data); + return (((data->flag) & BONE_ACTIVE) != 0); +} + +void rna_EditBone_active_set(PointerRNA *ptr, int value) +{ + EditBone *data= (EditBone*)(ptr->data); + if(value) data->flag |= BONE_ACTIVE; + else data->flag &= ~BONE_ACTIVE; +} + +float rna_EditBone_bbone_in_get(PointerRNA *ptr) +{ + EditBone *data= (EditBone*)(ptr->data); + return (float)(data->ease1); +} + +void rna_EditBone_bbone_in_set(PointerRNA *ptr, float value) +{ + EditBone *data= (EditBone*)(ptr->data); + data->ease1= CLAMPIS(value, 0.0f, 2.0f); +} + +float rna_EditBone_bbone_out_get(PointerRNA *ptr) +{ + EditBone *data= (EditBone*)(ptr->data); + return (float)(data->ease2); +} + +void rna_EditBone_bbone_out_set(PointerRNA *ptr, float value) +{ + EditBone *data= (EditBone*)(ptr->data); + data->ease2= CLAMPIS(value, 0.0f, 2.0f); +} + +int rna_EditBone_bbone_segments_get(PointerRNA *ptr) +{ + EditBone *data= (EditBone*)(ptr->data); + return (int)(data->segments); +} + +void rna_EditBone_bbone_segments_set(PointerRNA *ptr, int value) +{ + EditBone *data= (EditBone*)(ptr->data); + data->segments= CLAMPIS(value, 1, 32); +} + +void rna_EditBone_layer_get(PointerRNA *ptr, int values[16]) +{ + EditBone *data= (EditBone*)(ptr->data); + values[0]= ((data->layer & (1<<0)) != 0); + values[1]= ((data->layer & (1<<1)) != 0); + values[2]= ((data->layer & (1<<2)) != 0); + values[3]= ((data->layer & (1<<3)) != 0); + values[4]= ((data->layer & (1<<4)) != 0); + values[5]= ((data->layer & (1<<5)) != 0); + values[6]= ((data->layer & (1<<6)) != 0); + values[7]= ((data->layer & (1<<7)) != 0); + values[8]= ((data->layer & (1<<8)) != 0); + values[9]= ((data->layer & (1<<9)) != 0); + values[10]= ((data->layer & (1<<10)) != 0); + values[11]= ((data->layer & (1<<11)) != 0); + values[12]= ((data->layer & (1<<12)) != 0); + values[13]= ((data->layer & (1<<13)) != 0); + values[14]= ((data->layer & (1<<14)) != 0); + values[15]= ((data->layer & (1<<15)) != 0); +} + +void rna_EditBone_layer_set(PointerRNA *ptr, const int values[16]) +{ + EditBone *data= (EditBone*)(ptr->data); + rna_bone_layer_set(&data->layer, values); +} + +int rna_EditBone_connected_get(PointerRNA *ptr) +{ + EditBone *data= (EditBone*)(ptr->data); + return (((data->flag) & BONE_CONNECTED) != 0); +} + +void rna_EditBone_connected_set(PointerRNA *ptr, int value) +{ + EditBone *data= (EditBone*)(ptr->data); + if(value) data->flag |= BONE_CONNECTED; + else data->flag &= ~BONE_CONNECTED; +} + +int rna_EditBone_cyclic_offset_get(PointerRNA *ptr) +{ + EditBone *data= (EditBone*)(ptr->data); + return (!((data->flag) & BONE_NO_CYCLICOFFSET) != 0); +} + +void rna_EditBone_cyclic_offset_set(PointerRNA *ptr, int value) +{ + EditBone *data= (EditBone*)(ptr->data); + if(!value) data->flag |= BONE_NO_CYCLICOFFSET; + else data->flag &= ~BONE_NO_CYCLICOFFSET; +} + +int rna_EditBone_deform_get(PointerRNA *ptr) +{ + EditBone *data= (EditBone*)(ptr->data); + return (!((data->flag) & BONE_NO_DEFORM) != 0); +} + +void rna_EditBone_deform_set(PointerRNA *ptr, int value) +{ + EditBone *data= (EditBone*)(ptr->data); + if(!value) data->flag |= BONE_NO_DEFORM; + else data->flag &= ~BONE_NO_DEFORM; +} + +int rna_EditBone_draw_wire_get(PointerRNA *ptr) +{ + EditBone *data= (EditBone*)(ptr->data); + return (((data->flag) & BONE_DRAWWIRE) != 0); +} + +void rna_EditBone_draw_wire_set(PointerRNA *ptr, int value) +{ + EditBone *data= (EditBone*)(ptr->data); + if(value) data->flag |= BONE_DRAWWIRE; + else data->flag &= ~BONE_DRAWWIRE; +} + +float rna_EditBone_envelope_distance_get(PointerRNA *ptr) +{ + EditBone *data= (EditBone*)(ptr->data); + return (float)(data->dist); +} + +void rna_EditBone_envelope_distance_set(PointerRNA *ptr, float value) +{ + EditBone *data= (EditBone*)(ptr->data); + data->dist= CLAMPIS(value, 0.0f, 1000.0f); +} + +float rna_EditBone_envelope_weight_get(PointerRNA *ptr) +{ + EditBone *data= (EditBone*)(ptr->data); + return (float)(data->weight); +} + +void rna_EditBone_envelope_weight_set(PointerRNA *ptr, float value) +{ + EditBone *data= (EditBone*)(ptr->data); + data->weight= CLAMPIS(value, 0.0f, 1000.0f); +} + +float rna_EditBone_radius_head_get(PointerRNA *ptr) +{ + EditBone *data= (EditBone*)(ptr->data); + return (float)(data->rad_head); +} + +void rna_EditBone_radius_head_set(PointerRNA *ptr, float value) +{ + EditBone *data= (EditBone*)(ptr->data); + data->rad_head= value; +} + +float rna_EditBone_radius_tail_get(PointerRNA *ptr) +{ + EditBone *data= (EditBone*)(ptr->data); + return (float)(data->rad_tail); +} + +void rna_EditBone_radius_tail_set(PointerRNA *ptr, float value) +{ + EditBone *data= (EditBone*)(ptr->data); + data->rad_tail= value; +} + +void rna_EditBone_head_get(PointerRNA *ptr, float values[3]) +{ + EditBone *data= (EditBone*)(ptr->data); + values[0]= (float)(((float*)data->head)[0]); + values[1]= (float)(((float*)data->head)[1]); + values[2]= (float)(((float*)data->head)[2]); +} + +void rna_EditBone_head_set(PointerRNA *ptr, const float values[3]) +{ + EditBone *data= (EditBone*)(ptr->data); + ((float*)data->head)[0]= values[0]; + ((float*)data->head)[1]= values[1]; + ((float*)data->head)[2]= values[2]; +} + +int rna_EditBone_head_selected_get(PointerRNA *ptr) +{ + EditBone *data= (EditBone*)(ptr->data); + return (((data->flag) & BONE_ROOTSEL) != 0); +} + +void rna_EditBone_head_selected_set(PointerRNA *ptr, int value) +{ + EditBone *data= (EditBone*)(ptr->data); + if(value) data->flag |= BONE_ROOTSEL; + else data->flag &= ~BONE_ROOTSEL; +} + +int rna_EditBone_hidden_get(PointerRNA *ptr) +{ + EditBone *data= (EditBone*)(ptr->data); + return (((data->flag) & BONE_HIDDEN_A) != 0); +} + +void rna_EditBone_hidden_set(PointerRNA *ptr, int value) +{ + EditBone *data= (EditBone*)(ptr->data); + if(value) data->flag |= BONE_HIDDEN_A; + else data->flag &= ~BONE_HIDDEN_A; +} + +int rna_EditBone_hinge_get(PointerRNA *ptr) +{ + EditBone *data= (EditBone*)(ptr->data); + return (!((data->flag) & BONE_HINGE) != 0); +} + +void rna_EditBone_hinge_set(PointerRNA *ptr, int value) +{ + EditBone *data= (EditBone*)(ptr->data); + if(!value) data->flag |= BONE_HINGE; + else data->flag &= ~BONE_HINGE; +} + +int rna_EditBone_inherit_scale_get(PointerRNA *ptr) +{ + EditBone *data= (EditBone*)(ptr->data); + return (!((data->flag) & BONE_NO_SCALE) != 0); +} + +void rna_EditBone_inherit_scale_set(PointerRNA *ptr, int value) +{ + EditBone *data= (EditBone*)(ptr->data); + if(!value) data->flag |= BONE_NO_SCALE; + else data->flag &= ~BONE_NO_SCALE; +} + +int rna_EditBone_locked_get(PointerRNA *ptr) +{ + EditBone *data= (EditBone*)(ptr->data); + return (((data->flag) & BONE_EDITMODE_LOCKED) != 0); +} + +void rna_EditBone_locked_set(PointerRNA *ptr, int value) +{ + EditBone *data= (EditBone*)(ptr->data); + if(value) data->flag |= BONE_EDITMODE_LOCKED; + else data->flag &= ~BONE_EDITMODE_LOCKED; +} + +int rna_EditBone_multiply_vertexgroup_with_envelope_get(PointerRNA *ptr) +{ + EditBone *data= (EditBone*)(ptr->data); + return (((data->flag) & BONE_MULT_VG_ENV) != 0); +} + +void rna_EditBone_multiply_vertexgroup_with_envelope_set(PointerRNA *ptr, int value) +{ + EditBone *data= (EditBone*)(ptr->data); + if(value) data->flag |= BONE_MULT_VG_ENV; + else data->flag &= ~BONE_MULT_VG_ENV; +} + +PointerRNA rna_EditBone_parent_get(PointerRNA *ptr) +{ + EditBone *data= (EditBone*)(ptr->data); + return rna_pointer_inherit_refine(ptr, &RNA_EditBone, data->parent); +} + +float rna_EditBone_roll_get(PointerRNA *ptr) +{ + EditBone *data= (EditBone*)(ptr->data); + return (float)(data->roll); +} + +void rna_EditBone_roll_set(PointerRNA *ptr, float value) +{ + EditBone *data= (EditBone*)(ptr->data); + data->roll= value; +} + +void rna_EditBone_tail_get(PointerRNA *ptr, float values[3]) +{ + EditBone *data= (EditBone*)(ptr->data); + values[0]= (float)(((float*)data->tail)[0]); + values[1]= (float)(((float*)data->tail)[1]); + values[2]= (float)(((float*)data->tail)[2]); +} + +void rna_EditBone_tail_set(PointerRNA *ptr, const float values[3]) +{ + EditBone *data= (EditBone*)(ptr->data); + ((float*)data->tail)[0]= values[0]; + ((float*)data->tail)[1]= values[1]; + ((float*)data->tail)[2]= values[2]; +} + +int rna_EditBone_tail_selected_get(PointerRNA *ptr) +{ + EditBone *data= (EditBone*)(ptr->data); + return (((data->flag) & BONE_TIPSEL) != 0); +} + +void rna_EditBone_tail_selected_set(PointerRNA *ptr, int value) +{ + EditBone *data= (EditBone*)(ptr->data); + if(value) data->flag |= BONE_TIPSEL; + else data->flag &= ~BONE_TIPSEL; +} + #else -// err... bones should not be directly edited (only editbones should be...) -static void rna_def_bone(BlenderRNA *brna) +static void rna_def_bone_common(StructRNA *srna, int editbone) { - StructRNA *srna; PropertyRNA *prop; - - 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); - - /* pointers/collections */ - /* parent (pointer) */ - prop= RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE); - RNA_def_property_struct_type(prop, "Bone"); - RNA_def_property_pointer_sdna(prop, NULL, "parent"); - RNA_def_property_ui_text(prop, "Parent", "Parent bone (in same Armature)."); - - /* children (collection) */ - prop= RNA_def_property(srna, "children", PROP_COLLECTION, PROP_NONE); - RNA_def_property_collection_sdna(prop, NULL, "childbase", NULL); - RNA_def_property_struct_type(prop, "Bone"); - RNA_def_property_ui_text(prop, "Children", "Bones which are children of this bone"); - + /* strings */ prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* must be unique */ RNA_def_property_ui_text(prop, "Name", ""); RNA_def_struct_name_property(srna, prop); - + if(editbone) RNA_def_property_string_funcs(prop, "rna_EditBone_name_get", "rna_EditBone_name_length", "rna_EditBone_name_set"); + /* flags */ - /* layer */ prop= RNA_def_property(srna, "layer", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "layer", 1); RNA_def_property_array(prop, 16); RNA_def_property_ui_text(prop, "Bone Layers", "Layers bone exists in"); - RNA_def_property_boolean_funcs(prop, NULL, "rna_Bone_layer_set"); + if(editbone) RNA_def_property_boolean_funcs(prop, "rna_EditBone_layer_get", "rna_EditBone_layer_set"); + else { + RNA_def_property_boolean_funcs(prop, NULL, "rna_Bone_layer_set"); + RNA_def_property_boolean_sdna(prop, NULL, "layer", 1); + } - /* flag */ - prop= RNA_def_property(srna, "selected", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "flag", BONE_SELECTED); - RNA_def_property_ui_text(prop, "Selected", ""); - - prop= RNA_def_property(srna, "head_selected", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "flag", BONE_ROOTSEL); - RNA_def_property_ui_text(prop, "Head Selected", ""); - - prop= RNA_def_property(srna, "tail_selected", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "flag", BONE_TIPSEL); - RNA_def_property_ui_text(prop, "Tail Selected", ""); - prop= RNA_def_property(srna, "connected", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "flag", BONE_CONNECTED); + if(editbone) RNA_def_property_boolean_funcs(prop, "rna_EditBone_connected_get", "rna_EditBone_connected_set"); + else RNA_def_property_boolean_sdna(prop, NULL, "flag", BONE_CONNECTED); RNA_def_property_ui_text(prop, "Connected", "When bone has a parent, bone's head is struck to the parent's tail."); - // XXX should we define this in PoseChannel wrapping code instead? but PoseChannels directly get some of their flags from here... - prop= RNA_def_property(srna, "pose_channel_hidden", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "flag", BONE_HIDDEN_P); - RNA_def_property_ui_text(prop, "Pose Channel Hidden", "Bone is not visible when it is not in Edit Mode (i.e. in Object or Pose Modes)."); - prop= RNA_def_property(srna, "active", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "flag", BONE_ACTIVE); + if(editbone) RNA_def_property_boolean_funcs(prop, "rna_EditBone_active_get", "rna_EditBone_active_set"); + else RNA_def_property_boolean_sdna(prop, NULL, "flag", BONE_ACTIVE); RNA_def_property_ui_text(prop, "Active", "Bone was the last bone clicked on (most operations are applied to only this bone)"); prop= RNA_def_property(srna, "hinge", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", BONE_HINGE); + if(editbone) RNA_def_property_boolean_funcs(prop, "rna_EditBone_hinge_get", "rna_EditBone_hinge_set"); + else RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", BONE_HINGE); RNA_def_property_ui_text(prop, "Inherit Rotation", "Bone doesn't inherit rotation or scale from parent bone."); - prop= RNA_def_property(srna, "editmode_hidden", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "flag", BONE_HIDDEN_A); - RNA_def_property_ui_text(prop, "Edit Mode Hidden", "Bone is not visible when in Edit Mode"); - prop= RNA_def_property(srna, "multiply_vertexgroup_with_envelope", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "flag", BONE_MULT_VG_ENV); + if(editbone) RNA_def_property_boolean_funcs(prop, "rna_EditBone_multiply_vertexgroup_with_envelope_get", "rna_EditBone_multiply_vertexgroup_with_envelope_set"); + else RNA_def_property_boolean_sdna(prop, NULL, "flag", BONE_MULT_VG_ENV); RNA_def_property_ui_text(prop, "Multiply Vertex Group with Envelope", "When deforming bone, multiply effects of Vertex Group weights with Envelope influence."); prop= RNA_def_property(srna, "deform", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", BONE_NO_DEFORM); + if(editbone) RNA_def_property_boolean_funcs(prop, "rna_EditBone_deform_get", "rna_EditBone_deform_set"); + else RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", BONE_NO_DEFORM); RNA_def_property_ui_text(prop, "Deform", "Bone does not deform any geometry."); prop= RNA_def_property(srna, "inherit_scale", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", BONE_NO_SCALE); RNA_def_property_ui_text(prop, "Inherit Scale", "Bone inherits scaling from parent bone."); + if(editbone) RNA_def_property_boolean_funcs(prop, "rna_EditBone_inherit_scale_get", "rna_EditBone_inherit_scale_set"); + else RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", BONE_NO_SCALE); prop= RNA_def_property(srna, "draw_wire", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "flag", BONE_DRAWWIRE); + if(editbone) RNA_def_property_boolean_funcs(prop, "rna_EditBone_draw_wire_get", "rna_EditBone_draw_wire_set"); + else RNA_def_property_boolean_sdna(prop, NULL, "flag", BONE_DRAWWIRE); RNA_def_property_ui_text(prop, "Draw Wire", "Bone is always drawn as Wireframe regardless of viewport draw mode. Useful for non-obstructive custom bone shapes."); prop= RNA_def_property(srna, "cyclic_offset", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", BONE_NO_CYCLICOFFSET); + if(editbone) RNA_def_property_boolean_funcs(prop, "rna_EditBone_cyclic_offset_get", "rna_EditBone_cyclic_offset_set"); + else RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", BONE_NO_CYCLICOFFSET); RNA_def_property_ui_text(prop, "Cyclic Offset", "When bone doesn't have a parent, it receives cyclic offset effects."); - - prop= RNA_def_property(srna, "editmode_locked", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "flag", BONE_EDITMODE_LOCKED); - RNA_def_property_ui_text(prop, "Edit Mode Locked", "Bone is not able to be transformed when in Edit Mode."); - + /* Number values */ /* envelope deform settings */ prop= RNA_def_property(srna, "envelope_distance", PROP_FLOAT, PROP_NONE); - RNA_def_property_float_sdna(prop, NULL, "dist"); + if(editbone) RNA_def_property_float_funcs(prop, "rna_EditBone_envelope_distance_get", "rna_EditBone_envelope_distance_set", NULL); + else RNA_def_property_float_sdna(prop, NULL, "dist"); RNA_def_property_range(prop, 0.0f, 1000.0f); RNA_def_property_ui_text(prop, "Envelope Deform Distance", "Bone deformation distance (for Envelope deform only)."); prop= RNA_def_property(srna, "envelope_weight", PROP_FLOAT, PROP_NONE); - RNA_def_property_float_sdna(prop, NULL, "weight"); + if(editbone) RNA_def_property_float_funcs(prop, "rna_EditBone_envelope_weight_get", "rna_EditBone_envelope_weight_set", NULL); + else RNA_def_property_float_sdna(prop, NULL, "weight"); RNA_def_property_range(prop, 0.0f, 1000.0f); RNA_def_property_ui_text(prop, "Envelope Deform Weight", "Bone deformation weight (for Envelope deform only)."); prop= RNA_def_property(srna, "radius_head", PROP_FLOAT, PROP_NONE); - RNA_def_property_float_sdna(prop, NULL, "rad_head"); + if(editbone) RNA_def_property_float_funcs(prop, "rna_EditBone_radius_head_get", "rna_EditBone_radius_head_set", NULL); + else RNA_def_property_float_sdna(prop, NULL, "rad_head"); //RNA_def_property_range(prop, 0, 1000); // XXX range is 0 to lim, where lim= 10000.0f*MAX2(1.0, view3d->grid); RNA_def_property_ui_text(prop, "Envelope Radius Head", "Radius of head of bone (for Envelope deform only)."); prop= RNA_def_property(srna, "radius_tail", PROP_FLOAT, PROP_NONE); - RNA_def_property_float_sdna(prop, NULL, "rad_tail"); + if(editbone) RNA_def_property_float_funcs(prop, "rna_EditBone_radius_tail_get", "rna_EditBone_radius_tail_set", NULL); + else RNA_def_property_float_sdna(prop, NULL, "rad_tail"); //RNA_def_property_range(prop, 0, 1000); // XXX range is 0 to lim, where lim= 10000.0f*MAX2(1.0, view3d->grid); RNA_def_property_ui_text(prop, "Envelope Radius Tail", "Radius of tail of bone (for Envelope deform only)."); /* b-bones deform settings */ prop= RNA_def_property(srna, "bbone_segments", PROP_INT, PROP_NONE); - RNA_def_property_int_sdna(prop, NULL, "segments"); + if(editbone) RNA_def_property_int_funcs(prop, "rna_EditBone_bbone_segments_get", "rna_EditBone_bbone_segments_set", NULL); + else RNA_def_property_int_sdna(prop, NULL, "segments"); RNA_def_property_range(prop, 1, 32); RNA_def_property_ui_text(prop, "B-Bone Segments", "Number of subdivisions of bone (for B-Bones only)."); prop= RNA_def_property(srna, "bbone_in", PROP_FLOAT, PROP_NONE); - RNA_def_property_float_sdna(prop, NULL, "ease1"); + if(editbone) RNA_def_property_float_funcs(prop, "rna_EditBone_bbone_in_get", "rna_EditBone_bbone_in_set", NULL); + else RNA_def_property_float_sdna(prop, NULL, "ease1"); RNA_def_property_range(prop, 0.0f, 2.0f); RNA_def_property_ui_text(prop, "B-Bone Ease In", "Length of first Bezier Handle (for B-Bones only)."); prop= RNA_def_property(srna, "bbone_out", PROP_FLOAT, PROP_NONE); - RNA_def_property_float_sdna(prop, NULL, "ease2"); + if(editbone) RNA_def_property_float_funcs(prop, "rna_EditBone_bbone_out_get", "rna_EditBone_bbone_out_set", NULL); + else RNA_def_property_float_sdna(prop, NULL, "ease2"); RNA_def_property_range(prop, 0.0f, 2.0f); RNA_def_property_ui_text(prop, "B-Bone Ease Out", "Length of second Bezier Handle (for B-Bones only)."); +} + +// err... bones should not be directly edited (only editbones should be...) +static void rna_def_bone(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; - /* editmode bone coordinates */ - // XXX not sure if we want to wrap these here... besides, changing these requires changing the matrix? - prop= RNA_def_property(srna, "head", PROP_FLOAT, PROP_VECTOR); - RNA_def_property_ui_text(prop, "Bone Head Location", "In Edit Mode, the location of the 'head' of the bone."); + 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); - prop= RNA_def_property(srna, "tail", PROP_FLOAT, PROP_VECTOR); - RNA_def_property_ui_text(prop, "Bone Tail Location", "In Edit Mode, the location of the 'head' of the bone."); + /* pointers/collections */ + /* parent (pointer) */ + prop= RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE); + RNA_def_property_struct_type(prop, "Bone"); + RNA_def_property_pointer_sdna(prop, NULL, "parent"); + RNA_def_property_ui_text(prop, "Parent", "Parent bone (in same Armature)."); + + /* children (collection) */ + prop= RNA_def_property(srna, "children", PROP_COLLECTION, PROP_NONE); + RNA_def_property_collection_sdna(prop, NULL, "childbase", NULL); + RNA_def_property_struct_type(prop, "Bone"); + RNA_def_property_ui_text(prop, "Children", "Bones which are children of this bone"); + + rna_def_bone_common(srna, 0); + + // XXX should we define this in PoseChannel wrapping code instead? but PoseChannels directly get some of their flags from here... + prop= RNA_def_property(srna, "hidden", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", BONE_HIDDEN_P); + RNA_def_property_ui_text(prop, "Hidden", "Bone is not visible when it is not in Edit Mode (i.e. in Object or Pose Modes)."); + + prop= RNA_def_property(srna, "selected", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", BONE_SELECTED); + RNA_def_property_ui_text(prop, "Selected", ""); +} + +static void rna_def_edit_bone(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna= RNA_def_struct(brna, "EditBone", NULL); + RNA_def_struct_ui_text(srna, "Edit Bone", "Editmode bone in an Armature datablock."); + RNA_def_struct_ui_icon(srna, ICON_BONE_DATA); + + prop= RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE); + RNA_def_property_struct_type(prop, "EditBone"); + RNA_def_property_pointer_funcs(prop, "rna_EditBone_parent_get", NULL, NULL); + RNA_def_property_ui_text(prop, "Parent", "Parent edit bone (in same Armature)."); prop= RNA_def_property(srna, "roll", PROP_FLOAT, PROP_NONE); - RNA_def_property_range(prop, 0.0f, 2.0f); - RNA_def_property_ui_text(prop, "Bone Roll", "In Edit Mode, the 'roll' (i.e. rotation around the bone vector, equivalent to local Y-axis rotation)."); + RNA_def_property_float_funcs(prop, "rna_EditBone_roll_get", "rna_EditBone_roll_set", NULL); + RNA_def_property_ui_text(prop, "Roll", "Bone rotation around head-tail axis."); + + prop= RNA_def_property(srna, "head", PROP_FLOAT, PROP_VECTOR); + RNA_def_property_array(prop, 3); + RNA_def_property_float_funcs(prop, "rna_EditBone_head_get", "rna_EditBone_head_set", NULL); + RNA_def_property_ui_text(prop, "Head", "Location of head end of the bone."); + + prop= RNA_def_property(srna, "tail", PROP_FLOAT, PROP_VECTOR); + RNA_def_property_array(prop, 3); + RNA_def_property_float_funcs(prop, "rna_EditBone_tail_get", "rna_EditBone_tail_set", NULL); + RNA_def_property_ui_text(prop, "Tail", "Location of tail end of the bone."); + + rna_def_bone_common(srna, 1); + + prop= RNA_def_property(srna, "hidden", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_funcs(prop, "rna_EditBone_hidden_get", "rna_EditBone_hidden_set"); + RNA_def_property_ui_text(prop, "Hidden", "Bone is not visible when in Edit Mode"); + + prop= RNA_def_property(srna, "locked", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_funcs(prop, "rna_EditBone_locked_get", "rna_EditBone_locked_set"); + RNA_def_property_ui_text(prop, "Locked", "Bone is not able to be transformed when in Edit Mode."); + + prop= RNA_def_property(srna, "head_selected", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_funcs(prop, "rna_EditBone_head_selected_get", "rna_EditBone_head_selected_set"); + RNA_def_property_ui_text(prop, "Head Selected", ""); + + prop= RNA_def_property(srna, "tail_selected", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_funcs(prop, "rna_EditBone_tail_selected_get", "rna_EditBone_tail_selected_set"); + RNA_def_property_ui_text(prop, "Tail Selected", ""); } void rna_def_armature(BlenderRNA *brna) @@ -278,6 +662,11 @@ void rna_def_armature(BlenderRNA *brna) RNA_def_property_collection_sdna(prop, NULL, "bonebase", NULL); RNA_def_property_struct_type(prop, "Bone"); RNA_def_property_ui_text(prop, "Bones", ""); + + prop= RNA_def_property(srna, "edit_bones", PROP_COLLECTION, PROP_NONE); + RNA_def_property_collection_sdna(prop, NULL, "edbo", NULL); + RNA_def_property_struct_type(prop, "EditBone"); + RNA_def_property_ui_text(prop, "Edit Bones", ""); /* Enum values */ prop= RNA_def_property(srna, "drawtype", PROP_ENUM, PROP_NONE); @@ -436,6 +825,7 @@ void RNA_def_armature(BlenderRNA *brna) { rna_def_armature(brna); rna_def_bone(brna); + rna_def_edit_bone(brna); } #endif -- cgit v1.2.3