diff options
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r-- | source/blender/makesrna/intern/rna_modifier.c | 11 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_object.c | 101 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_particle.c | 6 |
3 files changed, 98 insertions, 20 deletions
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index 7def9bdb636..ca219e83fc2 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -602,6 +602,7 @@ const EnumPropertyItem rna_enum_axis_flag_xyz_items[] = { # include "BKE_cachefile.h" # include "BKE_context.h" +# include "BKE_deform.h" # include "BKE_mesh_runtime.h" # include "BKE_modifier.h" # include "BKE_object.h" @@ -1250,12 +1251,13 @@ static const EnumPropertyItem *rna_DataTransferModifier_layers_select_src_itemf( # endif if (ob_src) { - bDeformGroup *dg; + const bDeformGroup *dg; int i; RNA_enum_item_add_separator(&item, &totitem); - for (i = 0, dg = ob_src->defbase.first; dg; i++, dg = dg->next) { + const ListBase *defbase = BKE_object_defgroup_list(ob_src); + for (i = 0, dg = defbase->first; dg; i++, dg = dg->next) { tmp_item.value = i; tmp_item.identifier = tmp_item.name = dg->name; RNA_enum_item_add(&item, &totitem, &tmp_item); @@ -1349,12 +1351,13 @@ static const EnumPropertyItem *rna_DataTransferModifier_layers_select_dst_itemf( Object *ob_dst = CTX_data_active_object(C); /* XXX Is this OK? */ if (ob_dst) { - bDeformGroup *dg; + const bDeformGroup *dg; int i; RNA_enum_item_add_separator(&item, &totitem); - for (i = 0, dg = ob_dst->defbase.first; dg; i++, dg = dg->next) { + const ListBase *defbase = BKE_object_defgroup_list(ob_dst); + for (i = 0, dg = defbase->first; dg; i++, dg = dg->next) { tmp_item.value = i; tmp_item.identifier = tmp_item.name = dg->name; RNA_enum_item_add(&item, &totitem, &tmp_item); diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c index 7c012922c2c..e110459eeea 100644 --- a/source/blender/makesrna/intern/rna_object.c +++ b/source/blender/makesrna/intern/rna_object.c @@ -790,9 +790,27 @@ static void rna_Object_dup_collection_set(PointerRNA *ptr, } } +static void rna_Object_vertex_groups_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) +{ + Object *ob = (Object *)ptr->data; + if (!BKE_object_supports_vertex_groups(ob)) { + iter->valid = 0; + return; + } + + ListBase *defbase = BKE_object_defgroup_list_mutable(ob); + iter->valid = defbase != NULL; + + rna_iterator_listbase_begin(iter, defbase, NULL); +} + static void rna_VertexGroup_name_set(PointerRNA *ptr, const char *value) { Object *ob = (Object *)ptr->owner_id; + if (!BKE_object_supports_vertex_groups(ob)) { + return; + } + bDeformGroup *dg = (bDeformGroup *)ptr->data; BLI_strncpy_utf8(dg->name, value, sizeof(dg->name)); BKE_object_defgroup_unique_name(dg, ob); @@ -801,15 +819,25 @@ static void rna_VertexGroup_name_set(PointerRNA *ptr, const char *value) static int rna_VertexGroup_index_get(PointerRNA *ptr) { Object *ob = (Object *)ptr->owner_id; + if (!BKE_object_supports_vertex_groups(ob)) { + return -1; + } - return BLI_findindex(&ob->defbase, ptr->data); + const ListBase *defbase = BKE_object_defgroup_list(ob); + return BLI_findindex(defbase, ptr->data); } static PointerRNA rna_Object_active_vertex_group_get(PointerRNA *ptr) { Object *ob = (Object *)ptr->owner_id; + if (!BKE_object_supports_vertex_groups(ob)) { + return PointerRNA_NULL; + } + + const ListBase *defbase = BKE_object_defgroup_list(ob); + return rna_pointer_inherit_refine( - ptr, &RNA_VertexGroup, BLI_findlink(&ob->defbase, ob->actdef - 1)); + ptr, &RNA_VertexGroup, BLI_findlink(defbase, BKE_object_defgroup_active_index_get(ob) - 1)); } static void rna_Object_active_vertex_group_set(PointerRNA *ptr, @@ -817,7 +845,13 @@ static void rna_Object_active_vertex_group_set(PointerRNA *ptr, struct ReportList *reports) { Object *ob = (Object *)ptr->owner_id; - int index = BLI_findindex(&ob->defbase, value.data); + if (!BKE_object_supports_vertex_groups(ob)) { + return; + } + + const ListBase *defbase = BKE_object_defgroup_list(ob); + + int index = BLI_findindex(defbase, value.data); if (index == -1) { BKE_reportf(reports, RPT_ERROR, @@ -827,19 +861,27 @@ static void rna_Object_active_vertex_group_set(PointerRNA *ptr, return; } - ob->actdef = index + 1; + BKE_object_defgroup_active_index_set(ob, index + 1); } static int rna_Object_active_vertex_group_index_get(PointerRNA *ptr) { Object *ob = (Object *)ptr->owner_id; - return ob->actdef - 1; + if (!BKE_object_supports_vertex_groups(ob)) { + return -1; + } + + return BKE_object_defgroup_active_index_get(ob) - 1; } static void rna_Object_active_vertex_group_index_set(PointerRNA *ptr, int value) { Object *ob = (Object *)ptr->owner_id; - ob->actdef = value + 1; + if (!BKE_object_supports_vertex_groups(ob)) { + return; + } + + BKE_object_defgroup_active_index_set(ob, value + 1); } static void rna_Object_active_vertex_group_index_range( @@ -848,15 +890,24 @@ static void rna_Object_active_vertex_group_index_range( Object *ob = (Object *)ptr->owner_id; *min = 0; - *max = max_ii(0, BLI_listbase_count(&ob->defbase) - 1); + if (!BKE_object_supports_vertex_groups(ob)) { + *max = 0; + return; + } + const ListBase *defbase = BKE_object_defgroup_list(ob); + *max = max_ii(0, BLI_listbase_count(defbase) - 1); } void rna_object_vgroup_name_index_get(PointerRNA *ptr, char *value, int index) { Object *ob = (Object *)ptr->owner_id; - bDeformGroup *dg; + if (!BKE_object_supports_vertex_groups(ob)) { + value[0] = '\0'; + return; + } - dg = BLI_findlink(&ob->defbase, index - 1); + const ListBase *defbase = BKE_object_defgroup_list(ob); + const bDeformGroup *dg = BLI_findlink(defbase, index - 1); if (dg) { BLI_strncpy(value, dg->name, sizeof(dg->name)); @@ -869,21 +920,34 @@ void rna_object_vgroup_name_index_get(PointerRNA *ptr, char *value, int index) int rna_object_vgroup_name_index_length(PointerRNA *ptr, int index) { Object *ob = (Object *)ptr->owner_id; - bDeformGroup *dg; + if (!BKE_object_supports_vertex_groups(ob)) { + return 0; + } - dg = BLI_findlink(&ob->defbase, index - 1); + const ListBase *defbase = BKE_object_defgroup_list(ob); + bDeformGroup *dg = BLI_findlink(defbase, index - 1); return (dg) ? strlen(dg->name) : 0; } void rna_object_vgroup_name_index_set(PointerRNA *ptr, const char *value, short *index) { Object *ob = (Object *)ptr->owner_id; + if (!BKE_object_supports_vertex_groups(ob)) { + *index = -1; + return; + } + *index = BKE_object_defgroup_name_index(ob, value) + 1; } void rna_object_vgroup_name_set(PointerRNA *ptr, const char *value, char *result, int maxlen) { Object *ob = (Object *)ptr->owner_id; + if (!BKE_object_supports_vertex_groups(ob)) { + result[0] = '\0'; + return; + } + bDeformGroup *dg = BKE_object_defgroup_find_name(ob, value); if (dg) { /* No need for BLI_strncpy_utf8, since this matches an existing group. */ @@ -1960,7 +2024,9 @@ static void rna_Object_vgroup_remove(Object *ob, PointerRNA *defgroup_ptr) { bDeformGroup *defgroup = defgroup_ptr->data; - if (BLI_findindex(&ob->defbase, defgroup) == -1) { + ListBase *defbase = BKE_object_defgroup_list_mutable(ob); + + if (BLI_findindex(defbase, defgroup) == -1) { BKE_reportf(reports, RPT_ERROR, "DeformGroup '%s' not in object '%s'", @@ -2687,7 +2753,6 @@ static void rna_def_object_vertex_groups(BlenderRNA *brna, PropertyRNA *cprop) prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED); RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); - RNA_def_property_int_sdna(prop, NULL, "actdef"); RNA_def_property_int_funcs(prop, "rna_Object_active_vertex_group_index_get", "rna_Object_active_vertex_group_index_set", @@ -3274,7 +3339,15 @@ static void rna_def_object(BlenderRNA *brna) /* vertex groups */ prop = RNA_def_property(srna, "vertex_groups", PROP_COLLECTION, PROP_NONE); - RNA_def_property_collection_sdna(prop, NULL, "defbase", NULL); + RNA_def_property_collection_funcs(prop, + "rna_Object_vertex_groups_begin", + "rna_iterator_listbase_next", + "rna_iterator_listbase_end", + "rna_iterator_listbase_get", + NULL, + NULL, + NULL, + NULL); RNA_def_property_struct_type(prop, "VertexGroup"); RNA_def_property_override_clear_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY); RNA_def_property_ui_text(prop, "Vertex Groups", "Vertex groups of the object"); diff --git a/source/blender/makesrna/intern/rna_particle.c b/source/blender/makesrna/intern/rna_particle.c index 8edb80f68c5..de4cfb2b61a 100644 --- a/source/blender/makesrna/intern/rna_particle.c +++ b/source/blender/makesrna/intern/rna_particle.c @@ -1430,9 +1430,10 @@ static void psys_vg_name_get__internal(PointerRNA *ptr, char *value, int index) { Object *ob = (Object *)ptr->owner_id; ParticleSystem *psys = (ParticleSystem *)ptr->data; + const ListBase *defbase = BKE_object_defgroup_list(ob); if (psys->vgroup[index] > 0) { - bDeformGroup *defGroup = BLI_findlink(&ob->defbase, psys->vgroup[index] - 1); + bDeformGroup *defGroup = BLI_findlink(defbase, psys->vgroup[index] - 1); if (defGroup) { strcpy(value, defGroup->name); @@ -1448,7 +1449,8 @@ static int psys_vg_name_len__internal(PointerRNA *ptr, int index) ParticleSystem *psys = (ParticleSystem *)ptr->data; if (psys->vgroup[index] > 0) { - bDeformGroup *defGroup = BLI_findlink(&ob->defbase, psys->vgroup[index] - 1); + const ListBase *defbase = BKE_object_defgroup_list(ob); + bDeformGroup *defGroup = BLI_findlink(defbase, psys->vgroup[index] - 1); if (defGroup) { return strlen(defGroup->name); |