[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34148] trunk/blender/source/blender: patch [#25440] Object.vertex_group fixin'
Campbell Barton
ideasman42 at gmail.com
Fri Jan 7 10:50:23 CET 2011
Revision: 34148
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=34148
Author: campbellbarton
Date: 2011-01-07 09:50:23 +0000 (Fri, 07 Jan 2011)
Log Message:
-----------
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)
Modified Paths:
--------------
trunk/blender/source/blender/editors/include/ED_mesh.h
trunk/blender/source/blender/editors/object/object_vgroup.c
trunk/blender/source/blender/makesrna/intern/rna_object.c
Modified: trunk/blender/source/blender/editors/include/ED_mesh.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_mesh.h 2011-01-07 09:47:05 UTC (rev 34147)
+++ trunk/blender/source/blender/editors/include/ED_mesh.h 2011-01-07 09:50:23 UTC (rev 34148)
@@ -193,12 +193,15 @@
struct bDeformGroup *ED_vgroup_add(struct Object *ob);
struct bDeformGroup *ED_vgroup_add_name(struct Object *ob, const char *name);
+void ED_vgroup_delete(struct Object *ob, struct bDeformGroup *defgroup);
void ED_vgroup_select_by_name(struct Object *ob, char *name);
void ED_vgroup_data_create(struct ID *id);
int ED_vgroup_give_array(struct ID *id, struct MDeformVert **dvert_arr, int *dvert_tot);
int ED_vgroup_copy_array(struct Object *ob, struct Object *ob_from);
void ED_vgroup_mirror(struct Object *ob, int mirror_weights, int flip_vgroups);
+int ED_vgroup_object_is_edit_mode(struct Object *ob);
+
void ED_vgroup_vert_add(struct Object *ob, struct bDeformGroup *dg, int vertnum, float weight, int assignmode);
void ED_vgroup_vert_remove(struct Object *ob, struct bDeformGroup *dg, int vertnum);
float ED_vgroup_vert_weight(struct Object *ob, struct bDeformGroup *dg, int vertnum);
Modified: trunk/blender/source/blender/editors/object/object_vgroup.c
===================================================================
--- trunk/blender/source/blender/editors/object/object_vgroup.c 2011-01-07 09:47:05 UTC (rev 34147)
+++ trunk/blender/source/blender/editors/object/object_vgroup.c 2011-01-07 09:50:23 UTC (rev 34148)
@@ -68,6 +68,8 @@
/************************ Exported Functions **********************/
static void vgroup_remap_update_users(Object *ob, int *map);
+static void vgroup_delete_edit_mode(Object *ob, bDeformGroup *defgroup);
+static void vgroup_delete_object_mode(Object *ob, bDeformGroup *dg);
static Lattice *vgroup_edit_lattice(Object *ob)
{
@@ -79,6 +81,16 @@
return NULL;
}
+int ED_vgroup_object_is_edit_mode(Object *ob)
+{
+ if(ob->type == OB_MESH)
+ return (((Mesh*)ob->data)->edit_mesh != NULL);
+ else if(ob->type == OB_LATTICE)
+ return (((Lattice*)ob->data)->editlatt != NULL);
+
+ return 0;
+}
+
bDeformGroup *ED_vgroup_add_name(Object *ob, const char *name)
{
bDeformGroup *defgroup;
@@ -103,6 +115,25 @@
return ED_vgroup_add_name(ob, "Group");
}
+void ED_vgroup_delete(Object *ob, bDeformGroup *defgroup)
+{
+ bDeformGroup *dg = (bDeformGroup *)ob->defbase.first;
+
+ while (dg) {
+ if (dg == defgroup)
+ break;
+ dg = dg->next;
+ }
+
+ if (dg == NULL)
+ return;
+
+ if(ED_vgroup_object_is_edit_mode(ob))
+ vgroup_delete_edit_mode(ob, dg);
+ else
+ vgroup_delete_object_mode(ob, dg);
+}
+
void ED_vgroup_data_create(ID *id)
{
/* create deform verts */
@@ -508,7 +539,7 @@
}
if(dvert==NULL)
- return 0.0f;
+ return -1;
dvert += vertnum;
@@ -516,17 +547,17 @@
if(dvert->dw[i].def_nr == def_nr)
return dvert->dw[i].weight;
- return 0.0f;
+ return -1;
}
float ED_vgroup_vert_weight(Object *ob, bDeformGroup *dg, int vertnum)
{
int def_nr;
- if(!ob) return 0.0f;
+ if(!ob) return -1;
def_nr = defgroup_find_index(ob, dg);
- if(def_nr < 0) return 0.0f;
+ if(def_nr < 0) return -1;
return get_vert_def_nr(ob, def_nr, vertnum);
}
@@ -1094,16 +1125,11 @@
}
-static void vgroup_delete_object_mode(Object *ob)
+static void vgroup_delete_object_mode(Object *ob, bDeformGroup *dg)
{
- bDeformGroup *dg;
MDeformVert *dvert, *dvert_array=NULL;
int i, e, dvert_tot=0;
- dg = BLI_findlink(&ob->defbase, (ob->actdef-1));
- if(!dg)
- return;
-
ED_vgroup_give_array(ob->data, &dvert_array, &dvert_tot);
if(dvert_array) {
@@ -1199,18 +1225,13 @@
}
}
-static void vgroup_delete_edit_mode(Object *ob)
+static void vgroup_delete_edit_mode(Object *ob, bDeformGroup *defgroup)
{
- bDeformGroup *defgroup;
int i;
if(!ob->actdef)
return;
- defgroup = BLI_findlink(&ob->defbase, ob->actdef-1);
- if(!defgroup)
- return;
-
/* Make sure that no verts are using this group */
vgroup_active_remove_verts(ob, 1);
@@ -1286,10 +1307,14 @@
static void vgroup_delete(Object *ob)
{
+ bDeformGroup *dg = BLI_findlink(&ob->defbase, ob->actdef-1);
+ if(!dg)
+ return;
+
if(vgroup_object_in_edit_mode(ob))
- vgroup_delete_edit_mode(ob);
+ vgroup_delete_edit_mode(ob, dg);
else
- vgroup_delete_object_mode(ob);
+ vgroup_delete_object_mode(ob, dg);
}
static void vgroup_delete_all(Object *ob)
Modified: trunk/blender/source/blender/makesrna/intern/rna_object.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_object.c 2011-01-07 09:47:05 UTC (rev 34147)
+++ trunk/blender/source/blender/makesrna/intern/rna_object.c 2011-01-07 09:50:23 UTC (rev 34148)
@@ -125,6 +125,7 @@
#include "DNA_key_types.h"
#include "DNA_constraint_types.h"
+#include "DNA_lattice_types.h"
#include "BKE_armature.h"
#include "BKE_bullet.h"
@@ -1114,12 +1115,62 @@
}
-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 */
int rna_Lattice_object_poll(PointerRNA *ptr, PointerRNA value)
{
@@ -1154,7 +1205,15 @@
{
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");
RNA_def_struct_ui_text(srna, "Vertex Group", "Group of vertices, used for armature deform and other purposes");
@@ -1169,6 +1228,32 @@
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 @@
/* 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 @@
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");
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list