Assign automatic/envelope weights in weight paint mode is back,
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Tue, 26 Jan 2010 11:11:53 +0000 (11:11 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Tue, 26 Jan 2010 11:11:53 +0000 (11:11 +0000)
accessible from W key and in new Weights menu in the header.

release/scripts/ui/space_view3d.py
source/blender/editors/armature/editarmature.c
source/blender/editors/armature/poseobject.c
source/blender/editors/include/ED_armature.h
source/blender/editors/object/object_relations.c
source/blender/editors/sculpt_paint/paint_intern.h
source/blender/editors/sculpt_paint/paint_ops.c
source/blender/editors/sculpt_paint/paint_vertex.c

index dd1fb090ba6fcb52d61c6718135a7c822d48b650..ab33ea9dc182451f269d5f6665dbadb2dbf673a9 100644 (file)
@@ -49,7 +49,7 @@ class VIEW3D_HT_header(bpy.types.Header):
             if edit_object:
                 sub.menu("VIEW3D_MT_edit_%s" % edit_object.type.lower())
             elif obj:
-                if mode_string not in ('PAINT_WEIGHT', 'PAINT_TEXTURE'):
+                if mode_string not in ('PAINT_TEXTURE'):
                     sub.menu("VIEW3D_MT_%s" % mode_string.lower())
             else:
                 sub.menu("VIEW3D_MT_object")
@@ -848,6 +848,24 @@ class VIEW3D_MT_vertex_group(bpy.types.Menu):
             layout.operator("object.vertex_group_remove", text="Remove Active Group")
             layout.operator("object.vertex_group_remove", text="Remove All Groups").all = True
 
+# ********** Weight paint menu **********
+
+class VIEW3D_MT_paint_weight(bpy.types.Menu):
+    bl_label = "Weights"
+
+    def draw(self, context):
+        layout = self.layout
+
+        layout.operator("paint.weight_from_bones", text="Assign Automatic From Bones").type = 'AUTOMATIC'
+        layout.operator("paint.weight_from_bones", text="Assign From Bone Envelopes").type = 'ENVELOPES'
+
+        layout.separator()
+
+        layout.operator("object.vertex_group_normalize_all", text="Normalize All")
+        layout.operator("object.vertex_group_normalize", text="Normalize")
+        layout.operator("object.vertex_group_invert", text="Invert")
+        layout.operator("object.vertex_group_clean", text="Clean")
+        layout.operator("object.vertex_group_levels", text="Levels")
 
 # ********** Sculpt menu **********
 
@@ -1978,8 +1996,8 @@ bpy.types.register(VIEW3D_MT_hook)
 bpy.types.register(VIEW3D_MT_vertex_group)
 
 bpy.types.register(VIEW3D_MT_sculpt) # Sculpt Menu
-
 bpy.types.register(VIEW3D_MT_paint_vertex)
+bpy.types.register(VIEW3D_MT_paint_weight)
 
 bpy.types.register(VIEW3D_MT_particle)# Particle Menu
 bpy.types.register(VIEW3D_MT_particle_specials)
index 992ca8909c15a790ccb757428a822c139661d34c..b2e193ebf71f831ee6bb5e9a3e2bef2052365e5e 100644 (file)
@@ -4774,7 +4774,7 @@ void add_verts_to_dgroups(Scene *scene, Object *ob, Object *par, int heat, int m
        MEM_freeN(verts);
 }
 
-void create_vgroups_from_armature(Scene *scene, Object *ob, Object *par, int mode)
+void create_vgroups_from_armature(Scene *scene, Object *ob, Object *par, int mode, int mirror)
 {
        /* Lets try to create some vertex groups 
         * based on the bones of the parent armature.
@@ -4795,7 +4795,7 @@ void create_vgroups_from_armature(Scene *scene, Object *ob, Object *par, int mod
                 * that are populated with the vertices for which the
                 * bone is closest.
                 */
-               add_verts_to_dgroups(scene, ob, par, (mode == ARM_GROUPS_AUTO), 0);
+               add_verts_to_dgroups(scene, ob, par, (mode == ARM_GROUPS_AUTO), mirror);
        }
 } 
 /* ************* Clear Pose *****************************/
index 1e94817100cf6b657d5916ac2efd8402e0aea2be..e4fb378aff24514a16d1611d1ef07b9ba79d4170 100644 (file)
@@ -1115,31 +1115,6 @@ void POSE_OT_paste (wmOperatorType *ot)
 
 /* ********************************************** */
 
-/* context weightpaint and deformer in posemode */
-void pose_adds_vgroups(Scene *scene, Object *meshobj, int heatweights)
-{
-// XXX extern VPaint Gwp;         /* from vpaint */
-       Object *poseobj= modifiers_isDeformedByArmature(meshobj);
-
-       if(poseobj==NULL || (poseobj->mode & OB_MODE_POSE)==0) {
-               error("The active object must have a deforming armature in pose mode");
-               return;
-       }
-
-// XXX add_verts_to_dgroups(meshobj, poseobj, heatweights, ((Mesh *)(meshobj->data))->editflag & ME_EDIT_MIRROR_X);
-
-       if(heatweights)
-               BIF_undo_push("Apply Bone Heat Weights to Vertex Groups");
-       else
-               BIF_undo_push("Apply Bone Envelopes to Vertex Groups");
-
-       
-       // and all its relations
-       DAG_id_flush_update(&meshobj->id, OB_RECALC_DATA);
-}
-
-/* ********************************************** */
-
 
 static int pose_group_add_exec (bContext *C, wmOperator *op)
 {
index 9d35121032c2e0b925bfa742814528175756435d..6d44c1255248c4555cdcbd49db6cd055df879169 100644 (file)
@@ -129,7 +129,7 @@ void ED_armature_apply_transform(struct Object *ob, float mat[4][4]);
 #define ARM_GROUPS_ENVELOPE    2
 #define ARM_GROUPS_AUTO                3
 
-void create_vgroups_from_armature(struct Scene *scene, struct Object *ob, struct Object *par, int mode);
+void create_vgroups_from_armature(struct Scene *scene, struct Object *ob, struct Object *par, int mode, int mirror);
 
 void auto_align_armature(struct Scene *scene, struct View3D *v3d, short mode);
 void unique_editbone_name(struct ListBase *ebones, char *name, EditBone *bone); /* if bone is already in list, pass it as param to ignore it */
index 3a7ab3a101de192dae1b9ef217b6c7354fe635cb..46b90725d7f8169a49d6a1c11bcb55ddafdca14d 100644 (file)
@@ -630,11 +630,11 @@ static int parent_set_exec(bContext *C, wmOperator *op)
                                }
                                else if(pararm && ob->type==OB_MESH && par->type == OB_ARMATURE) {
                                        if(partype == PAR_ARMATURE_NAME)
-                                               create_vgroups_from_armature(scene, ob, par, ARM_GROUPS_NAME);
+                                               create_vgroups_from_armature(scene, ob, par, ARM_GROUPS_NAME, 0);
                                        else if(partype == PAR_ARMATURE_ENVELOPE)
-                                               create_vgroups_from_armature(scene, ob, par, ARM_GROUPS_ENVELOPE);
+                                               create_vgroups_from_armature(scene, ob, par, ARM_GROUPS_ENVELOPE, 0);
                                        else if(partype == PAR_ARMATURE_AUTO)
-                                               create_vgroups_from_armature(scene, ob, par, ARM_GROUPS_AUTO);
+                                               create_vgroups_from_armature(scene, ob, par, ARM_GROUPS_AUTO, 0);
                                        
                                        /* get corrected inverse */
                                        ob->partype= PAROBJECT;
index 6bb5f432b0df33ae91197cbc4d82f4c0e04e8271..bcbc0666782b9953adbf9d28cc412ead63695a1e 100644 (file)
@@ -64,6 +64,7 @@ void paint_cursor_start(struct bContext *C, int (*poll)(struct bContext *C));
 
 /* paint_vertex.c */
 int weight_paint_poll(struct bContext *C);
+int weight_paint_mode_poll(struct bContext *C);
 int vertex_paint_poll(struct bContext *C);
 int vertex_paint_mode_poll(struct bContext *C);
 
@@ -74,6 +75,7 @@ void PAINT_OT_weight_paint_toggle(struct wmOperatorType *ot);
 void PAINT_OT_weight_paint_radial_control(struct wmOperatorType *ot);
 void PAINT_OT_weight_paint(struct wmOperatorType *ot);
 void PAINT_OT_weight_set(struct wmOperatorType *ot);
+void PAINT_OT_weight_from_bones(struct wmOperatorType *ot);
 
 void PAINT_OT_vertex_paint_radial_control(struct wmOperatorType *ot);
 void PAINT_OT_vertex_paint_toggle(struct wmOperatorType *ot);
index a901b27b38f92d239b10bcfe664e89ceb8eb2dad..c00b6b560726cffc9c5312c2ecc8116a1649aba8 100644 (file)
@@ -127,6 +127,7 @@ void ED_operatortypes_paint(void)
        WM_operatortype_append(PAINT_OT_weight_paint_radial_control);
        WM_operatortype_append(PAINT_OT_weight_paint);
        WM_operatortype_append(PAINT_OT_weight_set);
+       WM_operatortype_append(PAINT_OT_weight_from_bones);
 
        /* vertex */
        WM_operatortype_append(PAINT_OT_vertex_paint_radial_control);
@@ -263,7 +264,7 @@ void ED_keymap_paint(wmKeyConfig *keyconf)
 
        /* Vertex Paint mode */
        keymap= WM_keymap_find(keyconf, "Vertex Paint", 0, 0);
-       keymap->poll= vertex_paint_poll;
+       keymap->poll= vertex_paint_mode_poll;
 
        RNA_enum_set(WM_keymap_add_item(keymap, "PAINT_OT_vertex_paint_radial_control", FKEY, KM_PRESS, 0, 0)->ptr, "mode", WM_RADIALCONTROL_SIZE);
        RNA_enum_set(WM_keymap_add_item(keymap, "PAINT_OT_vertex_paint_radial_control", FKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", WM_RADIALCONTROL_STRENGTH);
@@ -281,7 +282,7 @@ void ED_keymap_paint(wmKeyConfig *keyconf)
 
        /* Weight Paint mode */
        keymap= WM_keymap_find(keyconf, "Weight Paint", 0, 0);
-       keymap->poll= weight_paint_poll;
+       keymap->poll= weight_paint_mode_poll;
 
        RNA_enum_set(WM_keymap_add_item(keymap, "PAINT_OT_weight_paint_radial_control", FKEY, KM_PRESS, 0, 0)->ptr, "mode", WM_RADIALCONTROL_SIZE);
        RNA_enum_set(WM_keymap_add_item(keymap, "PAINT_OT_weight_paint_radial_control", FKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", WM_RADIALCONTROL_STRENGTH);
@@ -297,6 +298,8 @@ void ED_keymap_paint(wmKeyConfig *keyconf)
        kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", MKEY, KM_PRESS, 0, 0); /* mask toggle */
        RNA_string_set(kmi->ptr, "path", "weight_paint_object.data.use_paint_mask");
 
+       WM_keymap_verify_item(keymap, "PAINT_OT_weight_from_bones", WKEY, KM_PRESS, 0, 0);
+
        /* Image/Texture Paint mode */
        keymap= WM_keymap_find(keyconf, "Image Paint", 0, 0);
        keymap->poll= image_texture_paint_poll;
index 64dbe4e4c5c90ea0dd01e4a31841e655b2bef9ac..debdf4a3118437c977c7173879bb596a28c73556 100644 (file)
@@ -88,6 +88,7 @@
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
 
+#include "ED_armature.h"
 #include "ED_mesh.h"
 #include "ED_object.h"
 #include "ED_screen.h"
@@ -135,6 +136,13 @@ int vertex_paint_poll(bContext *C)
        return 0;
 }
 
+int weight_paint_mode_poll(bContext *C)
+{
+       Object *ob = CTX_data_active_object(C);
+
+       return ob && ob->mode == OB_MODE_WEIGHT_PAINT;
+}
+
 int weight_paint_poll(bContext *C)
 {
        Object *ob = CTX_data_active_object(C);
@@ -1980,3 +1988,51 @@ void PAINT_OT_vertex_paint(wmOperatorType *ot)
        RNA_def_collection_runtime(ot->srna, "stroke", &RNA_OperatorStrokeElement, "Stroke", "");
 }
 
+/* ********************** weight from bones operator ******************* */
+
+static int weight_from_bones_poll(bContext *C)
+{
+       Object *ob= CTX_data_active_object(C);
+
+       return (ob && (ob->mode & OB_MODE_WEIGHT_PAINT) && modifiers_isDeformedByArmature(ob));
+}
+
+static int weight_from_bones_exec(bContext *C, wmOperator *op)
+{
+       Scene *scene= CTX_data_scene(C);
+       Object *ob= CTX_data_active_object(C);
+       Object *armob= modifiers_isDeformedByArmature(ob);
+       Mesh *me= ob->data;
+       int type= RNA_enum_get(op->ptr, "type");
+
+       create_vgroups_from_armature(scene, ob, armob, type, (me->editflag & ME_EDIT_MIRROR_X));
+
+       DAG_id_flush_update(&me->id, OB_RECALC_DATA);
+       WM_event_add_notifier(C, NC_GEOM|ND_DATA, me);
+
+       return OPERATOR_FINISHED;
+}
+
+void PAINT_OT_weight_from_bones(wmOperatorType *ot)
+{
+       static EnumPropertyItem type_items[]= {
+               {ARM_GROUPS_AUTO, "AUTOMATIC", 0, "Automatic", "Automatic weights froms bones."},
+               {ARM_GROUPS_ENVELOPE, "ENVELOPES", 0, "From Envelopes", "Weights from envelopes with user defined radius."},
+               {0, NULL, 0, NULL, NULL}};
+
+       /* identifiers */
+       ot->name= "Weight from Bones";
+       ot->idname= "PAINT_OT_weight_from_bones";
+       
+       /* api callbacks */
+       ot->exec= weight_from_bones_exec;
+       ot->invoke= WM_menu_invoke;
+       ot->poll= weight_from_bones_poll;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       /* properties */
+       ot->prop= RNA_def_enum(ot->srna, "type", type_items, 0, "Type", "Method to use for assigning weights.");
+}
+