Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/makesrna/intern/rna_object.c')
-rw-r--r--source/blender/makesrna/intern/rna_object.c144
1 files changed, 118 insertions, 26 deletions
diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c
index a208e520d02..ed681291e29 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. */
@@ -1706,6 +1770,8 @@ static void rna_Object_active_modifier_set(PointerRNA *ptr, PointerRNA value, Re
Object *ob = (Object *)ptr->owner_id;
ModifierData *md = value.data;
+ WM_main_add_notifier(NC_OBJECT | ND_MODIFIER, ob);
+
if (RNA_pointer_is_null(&value)) {
BKE_object_modifier_set_active(ob, NULL);
return;
@@ -1931,16 +1997,25 @@ static void rna_Object_boundbox_get(PointerRNA *ptr, float *values)
}
}
+static bool check_object_vgroup_support_and_warn(const Object *ob,
+ const char *op_name,
+ ReportList *reports)
+{
+ if (!BKE_object_supports_vertex_groups(ob)) {
+ const char *ob_type_name = "Unknown";
+ RNA_enum_name_from_value(rna_enum_object_type_items, ob->type, &ob_type_name);
+ BKE_reportf(reports, RPT_ERROR, "%s is not supported for '%s' objects", op_name, ob_type_name);
+ return false;
+ }
+ return true;
+}
+
static bDeformGroup *rna_Object_vgroup_new(Object *ob,
Main *bmain,
ReportList *reports,
const char *name)
{
- if (!OB_TYPE_SUPPORT_VGROUP(ob->type)) {
- const char *ob_type_name = "Unknown";
- RNA_enum_name_from_value(rna_enum_object_type_items, ob->type, &ob_type_name);
- BKE_reportf(
- reports, RPT_ERROR, "VertexGroups.new(): is not supported for '%s' objects", ob_type_name);
+ if (!check_object_vgroup_support_and_warn(ob, "VertexGroups.new()", reports)) {
return NULL;
}
@@ -1957,8 +2032,14 @@ static void rna_Object_vgroup_remove(Object *ob,
ReportList *reports,
PointerRNA *defgroup_ptr)
{
+ if (!check_object_vgroup_support_and_warn(ob, "VertexGroups.remove()", reports)) {
+ return;
+ }
+
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'",
@@ -1974,8 +2055,12 @@ static void rna_Object_vgroup_remove(Object *ob,
WM_main_add_notifier(NC_OBJECT | ND_DRAW, ob);
}
-static void rna_Object_vgroup_clear(Object *ob, Main *bmain)
+static void rna_Object_vgroup_clear(Object *ob, Main *bmain, ReportList *reports)
{
+ if (!check_object_vgroup_support_and_warn(ob, "VertexGroups.clear()", reports)) {
+ return;
+ }
+
BKE_object_defgroup_remove_all(ob);
DEG_relations_tag_update(bmain);
@@ -2268,7 +2353,7 @@ static void rna_def_vertex_group(BlenderRNA *brna)
func = RNA_def_function(srna, "add", "rna_VertexGroup_vertex_add");
RNA_def_function_ui_description(func, "Add vertices to the group");
RNA_def_function_flag(func, FUNC_USE_REPORTS | FUNC_USE_SELF_ID);
- /* TODO, see how array size of 0 works, this shouldn't be used */
+ /* TODO: see how array size of 0 works, this shouldn't be used. */
parm = RNA_def_int_array(func, "index", 1, NULL, 0, 0, "", "List of indices", 0, 0);
RNA_def_parameter_flags(parm, PROP_DYNAMIC, PARM_REQUIRED);
parm = RNA_def_float(func, "weight", 0, 0.0f, 1.0f, "", "Vertex weight", 0.0f, 1.0f);
@@ -2279,7 +2364,7 @@ static void rna_def_vertex_group(BlenderRNA *brna)
func = RNA_def_function(srna, "remove", "rna_VertexGroup_vertex_remove");
RNA_def_function_ui_description(func, "Remove vertices from the group");
RNA_def_function_flag(func, FUNC_USE_REPORTS | FUNC_USE_SELF_ID);
- /* TODO, see how array size of 0 works, this shouldn't be used */
+ /* TODO: see how array size of 0 works, this shouldn't be used. */
parm = RNA_def_int_array(func, "index", 1, NULL, 0, 0, "", "List of indices", 0, 0);
RNA_def_parameter_flags(parm, PROP_DYNAMIC, PARM_REQUIRED);
@@ -2326,14 +2411,14 @@ static void rna_def_face_map(BlenderRNA *brna)
func = RNA_def_function(srna, "add", "rna_FaceMap_face_add");
RNA_def_function_ui_description(func, "Add faces to the face-map");
RNA_def_function_flag(func, FUNC_USE_REPORTS | FUNC_USE_SELF_ID);
- /* TODO, see how array size of 0 works, this shouldn't be used */
+ /* TODO: see how array size of 0 works, this shouldn't be used. */
parm = RNA_def_int_array(func, "index", 1, NULL, 0, 0, "", "List of indices", 0, 0);
RNA_def_parameter_flags(parm, PROP_DYNAMIC, PARM_REQUIRED);
func = RNA_def_function(srna, "remove", "rna_FaceMap_face_remove");
RNA_def_function_ui_description(func, "Remove faces from the face-map");
RNA_def_function_flag(func, FUNC_USE_REPORTS | FUNC_USE_SELF_ID);
- /* TODO, see how array size of 0 works, this shouldn't be used */
+ /* TODO: see how array size of 0 works, this shouldn't be used. */
parm = RNA_def_int_array(func, "index", 1, NULL, 0, 0, "", "List of indices", 0, 0);
RNA_def_parameter_flags(parm, PROP_DYNAMIC, PARM_REQUIRED);
}
@@ -2488,7 +2573,7 @@ static void rna_def_object_modifiers(BlenderRNA *brna, PropertyRNA *cprop)
/*RNA_def_property_update(prop, 0, "rna_Armature_act_editbone_update"); */
RNA_def_property_pointer_funcs(prop, NULL, "rna_Armature_act_edit_bone_set", NULL, NULL);
- /* todo, redraw */
+ /* TODO: redraw. */
/* RNA_def_property_collection_active(prop, prop_act); */
# endif
@@ -2685,7 +2770,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",
@@ -2710,7 +2794,7 @@ static void rna_def_object_vertex_groups(BlenderRNA *brna, PropertyRNA *cprop)
RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0);
func = RNA_def_function(srna, "clear", "rna_Object_vgroup_clear");
- RNA_def_function_flag(func, FUNC_USE_MAIN);
+ RNA_def_function_flag(func, FUNC_USE_MAIN | FUNC_USE_REPORTS);
RNA_def_function_ui_description(func, "Delete all vertex groups from object");
}
@@ -3272,7 +3356,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");