diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-01-07 12:50:23 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-01-07 12:50:23 +0300 |
commit | 57a3cff3b890d93089a1b45c40bdc14d8101fb5e (patch) | |
tree | 32212f25dfe1dc064ee2d3d2dac747f415795f8d /source/blender/makesrna/intern/rna_object.c | |
parent | 41c00063dd43f1a653747129bdb29dcdb13818dd (diff) |
patch [#25440] Object.vertex_group fixin'
from Dan Eicher (dna)
From the tracker (with minor edits)
========================
cube = bpy.data.objects['Cube']
foo = cube.vertex_groups.new('foo')
foo.add([1,3,5,7], 1.0, 'ADD')
for i in range(len(cube.data.vertices)):
try:
weight = foo.weight(i)
print('vert: %i weight: %f' % (i, weight))
except:
pass
foo.remove([1,3])
cube.vertex_groups.remove(foo)
Diffstat (limited to 'source/blender/makesrna/intern/rna_object.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_object.c | 114 |
1 files changed, 92 insertions, 22 deletions
diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c index 978171997ef..6cb5a074c03 100644 --- a/source/blender/makesrna/intern/rna_object.c +++ b/source/blender/makesrna/intern/rna_object.c @@ -125,6 +125,7 @@ EnumPropertyItem object_type_curve_items[] = { #include "DNA_key_types.h" #include "DNA_constraint_types.h" +#include "DNA_lattice_types.h" #include "BKE_armature.h" #include "BKE_bullet.h" @@ -1114,10 +1115,60 @@ static void rna_Object_boundbox_get(PointerRNA *ptr, float *values) } -static void rna_Object_add_vertex_to_group(Object *ob, int index_len, int *index, bDeformGroup *def, float weight, int assignmode) +static bDeformGroup *rna_Object_vgroup_new(Object *ob, const char *name) { + bDeformGroup *defgroup = ED_vgroup_add_name(ob, name); + + WM_main_add_notifier(NC_OBJECT|ND_DRAW, ob); + + return defgroup; +} + +static void rna_Object_vgroup_remove(Object *ob, bDeformGroup *defgroup) +{ + ED_vgroup_delete(ob, defgroup); + + WM_main_add_notifier(NC_OBJECT|ND_DRAW, ob); +} + +static void rna_VertexGroup_vertex_add(ID *id, bDeformGroup *def, ReportList *reports, int index_len, int *index, float weight, int assignmode) +{ + Object *ob = (Object *)id; + + if(ED_vgroup_object_is_edit_mode(ob)) { + BKE_reportf(reports, RPT_ERROR, "VertexGroup.add(): Can't be called while object is in edit mode."); + return; + } + while(index_len--) - ED_vgroup_vert_add(ob, def, *index++, weight, assignmode); + ED_vgroup_vert_add(ob, def, *index++, weight, assignmode); /* XXX, not efficient calling within loop*/ + + WM_main_add_notifier(NC_GEOM|ND_DATA, (ID *)ob->data); +} + +static void rna_VertexGroup_vertex_remove(ID *id, bDeformGroup *dg, ReportList *reports, int index_len, int *index) +{ + Object *ob = (Object *)id; + + if(ED_vgroup_object_is_edit_mode(ob)) { + BKE_reportf(reports, RPT_ERROR, "VertexGroup.remove(): Can't be called while object is in edit mode."); + return; + } + + while(index_len--) + ED_vgroup_vert_remove(ob, dg, *index++); + + WM_main_add_notifier(NC_GEOM|ND_DATA, (ID *)ob->data); +} + +static float rna_VertexGroup_weight(ID *id, bDeformGroup *dg, ReportList *reports, int index) +{ + float weight = ED_vgroup_vert_weight((Object *)id, dg, index); + + if(weight < 0) { + BKE_reportf(reports, RPT_ERROR, "Vertex not in group"); + } + return weight; } /* generic poll functions */ @@ -1154,6 +1205,14 @@ static void rna_def_vertex_group(BlenderRNA *brna) { StructRNA *srna; PropertyRNA *prop; + FunctionRNA *func; + + static EnumPropertyItem assign_mode_items[] = { + {WEIGHT_REPLACE, "REPLACE", 0, "Replace", "Replace"}, + {WEIGHT_ADD, "ADD", 0, "Add", "Add"}, + {WEIGHT_SUBTRACT, "SUBTRACT", 0, "Subtract", "Subtract"}, + {0, NULL, 0, NULL, NULL} + }; srna= RNA_def_struct(brna, "VertexGroup", NULL); RNA_def_struct_sdna(srna, "bDeformGroup"); @@ -1169,6 +1228,32 @@ static void rna_def_vertex_group(BlenderRNA *brna) RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_int_funcs(prop, "rna_VertexGroup_index_get", NULL, NULL); RNA_def_property_ui_text(prop, "Index", "Index number of the vertex group"); + + 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 shouldnt be used */ + prop= RNA_def_int_array(func, "index", 1, NULL, 0, 0, "", "Index List.", 0, 0); + RNA_def_property_flag(prop, PROP_DYNAMIC|PROP_REQUIRED); + prop= RNA_def_float(func, "weight", 0, 0.0f, 1.0f, "", "Vertex weight.", 0.0f, 1.0f); + RNA_def_property_flag(prop, PROP_REQUIRED); + prop= RNA_def_enum(func, "type", assign_mode_items, 0, "", "Vertex assign mode."); + RNA_def_property_flag(prop, PROP_REQUIRED); + + func= RNA_def_function(srna, "remove", "rna_VertexGroup_vertex_remove"); + RNA_def_function_ui_description(func, "Remove a vertex from the group."); + RNA_def_function_flag(func, FUNC_USE_REPORTS|FUNC_USE_SELF_ID); + /* TODO, see how array size of 0 works, this shouldnt be used */ + prop= RNA_def_int_array(func, "index", 1, NULL, 0, 0, "", "Index List.", 0, 0); + RNA_def_property_flag(prop, PROP_DYNAMIC|PROP_REQUIRED); + + func= RNA_def_function(srna, "weight", "rna_VertexGroup_weight"); + RNA_def_function_ui_description(func, "Get a vertex weight from the group."); + RNA_def_function_flag(func, FUNC_USE_REPORTS|FUNC_USE_SELF_ID); + prop=RNA_def_int(func, "index", 0, 0, INT_MAX, "Index", "The index of the vertex.", 0, INT_MAX); + RNA_def_property_flag(prop, PROP_REQUIRED); + prop= RNA_def_float(func, "weight", 0, 0.0f, 1.0f, "", "Vertex weight.", 0.0f, 1.0f); + RNA_def_function_return(func, prop); } static void rna_def_material_slot(BlenderRNA *brna) @@ -1545,13 +1630,6 @@ static void rna_def_object_particle_systems(BlenderRNA *brna, PropertyRNA *cprop /* object.vertex_groups */ static void rna_def_object_vertex_groups(BlenderRNA *brna, PropertyRNA *cprop) { - static EnumPropertyItem assign_mode_items[] = { - {WEIGHT_REPLACE, "REPLACE", 0, "Replace", "Replace"}, - {WEIGHT_ADD, "ADD", 0, "Add", "Add"}, - {WEIGHT_SUBTRACT, "SUBTRACT", 0, "Subtract", "Subtract"}, - {0, NULL, 0, NULL, NULL} - }; - StructRNA *srna; PropertyRNA *prop; @@ -1578,24 +1656,16 @@ static void rna_def_object_vertex_groups(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_property_update(prop, NC_GEOM|ND_DATA, "rna_Object_internal_update_data"); /* vertex groups */ // add_vertex_group - func= RNA_def_function(srna, "new", "ED_vgroup_add_name"); + func= RNA_def_function(srna, "new", "rna_Object_vgroup_new"); RNA_def_function_ui_description(func, "Add vertex group to object."); parm= RNA_def_string(func, "name", "Group", 0, "", "Vertex group name."); /* optional */ parm= RNA_def_pointer(func, "group", "VertexGroup", "", "New vertex group."); RNA_def_function_return(func, parm); - func= RNA_def_function(srna, "assign", "rna_Object_add_vertex_to_group"); - RNA_def_function_ui_description(func, "Add vertex to a vertex group."); - /* TODO, see how array size of 0 works, this shouldnt be used */ - parm= RNA_def_int_array(func, "index", 1, NULL, 0, 0, "", "Index List.", 0, 0); - RNA_def_property_flag(parm, PROP_DYNAMIC); - RNA_def_property_flag(parm, PROP_REQUIRED); - parm= RNA_def_pointer(func, "group", "VertexGroup", "", "Vertex group to add vertex to."); - RNA_def_property_flag(parm, PROP_REQUIRED); - parm= RNA_def_float(func, "weight", 0, 0.0f, 1.0f, "", "Vertex weight.", 0.0f, 1.0f); - RNA_def_property_flag(parm, PROP_REQUIRED); - parm= RNA_def_enum(func, "type", assign_mode_items, 0, "", "Vertex assign mode."); - RNA_def_property_flag(parm, PROP_REQUIRED); + func= RNA_def_function(srna, "remove", "rna_Object_vgroup_remove"); + RNA_def_function_ui_description(func, "Delete vertex group from object."); + parm= RNA_def_pointer(func, "group", "VertexGroup", "", "Vertex group to remove."); + RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL); } |