diff --git a/release/scripts/ui/space_view3d.py b/release/scripts/ui/space_view3d.py index dd1fb090ba6..ab33ea9dc18 100644 --- a/release/scripts/ui/space_view3d.py +++ b/release/scripts/ui/space_view3d.py @@ -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) diff --git a/source/blender/editors/armature/editarmature.c b/source/blender/editors/armature/editarmature.c index 992ca8909c1..b2e193ebf71 100644 --- a/source/blender/editors/armature/editarmature.c +++ b/source/blender/editors/armature/editarmature.c @@ -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 *****************************/ diff --git a/source/blender/editors/armature/poseobject.c b/source/blender/editors/armature/poseobject.c index 1e94817100c..e4fb378aff2 100644 --- a/source/blender/editors/armature/poseobject.c +++ b/source/blender/editors/armature/poseobject.c @@ -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) { diff --git a/source/blender/editors/include/ED_armature.h b/source/blender/editors/include/ED_armature.h index 9d35121032c..6d44c125524 100644 --- a/source/blender/editors/include/ED_armature.h +++ b/source/blender/editors/include/ED_armature.h @@ -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 */ diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c index 3a7ab3a101d..46b90725d7f 100644 --- a/source/blender/editors/object/object_relations.c +++ b/source/blender/editors/object/object_relations.c @@ -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; diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h index 6bb5f432b0d..bcbc0666782 100644 --- a/source/blender/editors/sculpt_paint/paint_intern.h +++ b/source/blender/editors/sculpt_paint/paint_intern.h @@ -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); diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c index a901b27b38f..c00b6b56072 100644 --- a/source/blender/editors/sculpt_paint/paint_ops.c +++ b/source/blender/editors/sculpt_paint/paint_ops.c @@ -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; diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 64dbe4e4c5c..debdf4a3118 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -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."); +} +