2.5/Vertex paint:
authorNicholas Bishop <nicholasbishop@gmail.com>
Sat, 22 Aug 2009 02:27:37 +0000 (02:27 +0000)
committerNicholas Bishop <nicholasbishop@gmail.com>
Sat, 22 Aug 2009 02:27:37 +0000 (02:27 +0000)
* Added operator for filling vertex colors with the brush color
* Pythonized the vertex paint menu

release/ui/space_view3d.py
source/blender/editors/sculpt_paint/paint_intern.h
source/blender/editors/sculpt_paint/paint_ops.c
source/blender/editors/sculpt_paint/paint_vertex.c
source/blender/editors/space_view3d/view3d_header.c

index 0b08b213cd4ed0fda9a898f65fc2f30c66944297..ae04c8875ce3d032d5efa39ee721093be98e5cf9 100644 (file)
@@ -12,6 +12,7 @@ class VIEW3D_HT_header(bpy.types.Header):
                view = context.space_data
                mode_string = context.mode
                edit_object = context.edit_object
+               object = context.active_object
                
                row = layout.row(align=True)
                row.template_header()
@@ -26,12 +27,14 @@ class VIEW3D_HT_header(bpy.types.Header):
                        if mode_string not in ('EDIT_TEXT', 'SCULPT', 'PAINT_WEIGHT', 'PAINT_VERTEX', 'PAINT_TEXTURE', 'PARTICLE'):
                                # XXX: Particle Mode has Select Menu.
                                sub.itemM("VIEW3D_MT_select_%s" % mode_string)
-                       
-                       if mode_string == 'OBJECT':
+                               
+                       if object.mode == 'OBJECT':
                                sub.itemM("VIEW3D_MT_object")
-                       elif mode_string == 'SCULPT':
+                       elif object.mode == 'SCULPT':
                                sub.itemM("VIEW3D_MT_sculpt")
-                       elif edit_object:
+                       elif object.mode == 'VERTEX_PAINT':
+                               sub.itemM("VIEW3D_MT_vertex_paint")
+                       elif object.mode:
                                sub.itemM("VIEW3D_MT_edit_%s" % edit_object.type)
 
                layout.template_header_3D()
@@ -480,6 +483,21 @@ class VIEW3D_MT_object_show(bpy.types.Menu):
                layout.itemO("object.restrictview_set")
                layout.item_booleanO("object.restrictview_set", "unselected", True, text="Hide Unselected")
 
+# ********** Vertex paint menu **********      
+       
+class VIEW3D_MT_vertex_paint(bpy.types.Menu):
+       __space_type__ = "VIEW_3D"
+       __label__ = "Paint"
+
+       def draw(self, context):
+               layout = self.layout
+               
+               sculpt = context.tool_settings.sculpt
+
+               layout.itemO("paint.vertex_color_set")
+               props = layout.itemO("paint.vertex_color_set", text="Set Selected Vertex Colors", properties=True)
+               props.selected = True
+
 # ********** Sculpt menu **********    
        
 class VIEW3D_MT_sculpt(bpy.types.Menu):
@@ -1076,6 +1094,8 @@ bpy.types.register(VIEW3D_MT_object_show)
 
 bpy.types.register(VIEW3D_MT_sculpt) # Sculpt Menu
 
+bpy.types.register(VIEW3D_MT_vertex_paint)
+
 bpy.types.register(VIEW3D_MT_edit_snap) # Edit Menus
 
 bpy.types.register(VIEW3D_MT_edit_MESH)
index a0187566c433b20607492243f9f9587d8a4785bb..ba1b57a1bef0a12cafb5f44d2df87310fc79eef8 100644 (file)
@@ -57,6 +57,9 @@ int paint_poll(bContext *C);
 void paint_cursor_start(struct bContext *C, int (*poll)(struct bContext *C));
 
 /* paint_vertex.c */
+int vertex_paint_mode_poll(bContext *C);
+void clear_vpaint(Scene *scene, int selected);
+
 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);
index 1ea612c0aa5de2d4e2be71660c6c20727b274bc4..c38b36007e9df7d1c3d452b1913fe622384d92c7 100644 (file)
@@ -77,6 +77,32 @@ void BRUSH_OT_add(wmOperatorType *ot)
        RNA_def_enum(ot->srna, "type", brush_type_items, OB_MODE_VERTEX_PAINT, "Type", "Which paint mode to create the brush for.");
 }
 
+static int vertex_color_set_exec(bContext *C, wmOperator *op)
+{
+       int selected = RNA_boolean_get(op->ptr, "selected");
+       Scene *scene = CTX_data_scene(C);
+
+       clear_vpaint(scene, selected);
+       
+       return OPERATOR_FINISHED;
+}
+
+void PAINT_OT_vertex_color_set(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Set Vertex Colors";
+       ot->idname= "PAINT_OT_vertex_color_set";
+       
+       /* api callbacks */
+       ot->exec= vertex_color_set_exec;
+       ot->poll= vertex_paint_mode_poll;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       RNA_def_boolean(ot->srna, "selected", 0, "Type", "Only color selected faces.");
+}
+
 /**************************** registration **********************************/
 
 void ED_operatortypes_paint(void)
@@ -103,5 +129,6 @@ void ED_operatortypes_paint(void)
        WM_operatortype_append(PAINT_OT_vertex_paint_radial_control);
        WM_operatortype_append(PAINT_OT_vertex_paint_toggle);
        WM_operatortype_append(PAINT_OT_vertex_paint);
+       WM_operatortype_append(PAINT_OT_vertex_color_set);
 }
 
index bc2ac480657998cba398352d08ddedeacd29164c..ee3d9e5baa1599dfe86dcde59dd8515a09b8a3cb 100644 (file)
@@ -110,11 +110,18 @@ static void error() {}
 
 /* polling - retrieve whether cursor should be set or operator should be done */
 
-static int vp_poll(bContext *C)
+
+/* Returns true if vertex paint mode is active */
+int vertex_paint_mode_poll(bContext *C)
 {
        Object *ob = CTX_data_active_object(C);
 
-       if(ob && ob->mode & OB_MODE_VERTEX_PAINT &&
+       return ob && ob->mode == OB_MODE_VERTEX_PAINT;
+}
+
+static int vp_poll(bContext *C)
+{
+       if(vertex_paint_mode_poll(C) && 
           paint_brush(&CTX_data_tool_settings(C)->vpaint->paint)) {
                ScrArea *sa= CTX_wm_area(C);
                if(sa->spacetype==SPACE_VIEW3D) {
@@ -323,34 +330,7 @@ static void copy_wpaint_prev (VPaint *wp, MDeformVert *dverts, int dcount)
 }
 
 
-void clear_vpaint(Scene *scene)
-{
-       Mesh *me;
-       Object *ob;
-       unsigned int *to, paintcol;
-       int a;
-       
-       ob= OBACT;
-       me= get_mesh(ob);
-       if(!ob || ob->id.lib) return;
-
-       if(!(ob->mode & OB_MODE_VERTEX_PAINT)) return;
-
-       if(me==0 || me->mcol==0 || me->totface==0) return;
-
-       paintcol= vpaint_get_current_col(scene->toolsettings->vpaint);
-
-       to= (unsigned int *)me->mcol;
-       a= 4*me->totface;
-       while(a--) {
-               *to= paintcol;
-               to++; 
-       }
-       DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
-       
-}
-
-void clear_vpaint_selectedfaces(Scene *scene)
+void clear_vpaint(Scene *scene, int selected)
 {
        Mesh *me;
        MFace *mf;
@@ -370,7 +350,7 @@ void clear_vpaint_selectedfaces(Scene *scene)
        mf = me->mface;
        mcol = (unsigned int*)me->mcol;
        for (i = 0; i < me->totface; i++, mf++, mcol+=4) {
-               if (mf->flag & ME_FACE_SEL) {
+               if (!selected || mf->flag & ME_FACE_SEL) {
                        mcol[0] = paintcol;
                        mcol[1] = paintcol;
                        mcol[2] = paintcol;
index 9fa1b2228680c478f832f8fb53296d8b589d70d2..73cd65cafcd5a5081bf5bdc39dcc6211d4fc0236 100644 (file)
@@ -2426,71 +2426,6 @@ static void view3d_pose_armaturemenu(bContext *C, uiLayout *layout, void *arg_un
 #endif
 }
 
-
-/* vertex paint menu */
-static void do_view3d_vpaintmenu(bContext *C, void *arg, int event)
-{
-#if 0
-       /* events >= 3 are registered bpython scripts */
-#ifndef DISABLE_PYTHON
-       if (event >= 3) BPY_menu_do_python(PYMENU_VERTEXPAINT, event - 3);
-#endif
-       switch(event) {
-       case 0: /* undo vertex painting */
-               BIF_undo();
-               break;
-       case 1: /* set vertex colors/weight */
-               if(paint_facesel_test(CTX_data_active_object(C)))
-                       clear_vpaint_selectedfaces();
-               else /* we know were in vertex paint mode */
-                       clear_vpaint();
-               break;
-       case 2:
-               make_vertexcol(1);
-               break;
-       }
-#endif
-}
-
-static uiBlock *view3d_vpaintmenu(bContext *C, ARegion *ar, void *arg_unused)
-{
-       uiBlock *block;
-       short yco= 0, menuwidth=120;
-#ifndef DISABLE_PYTHON
-// XXX BPyMenu *pym;
-//     int i=0;
-#endif
-       
-       block= uiBeginBlock(C, ar, "view3d_paintmenu", UI_EMBOSSP);
-       uiBlockSetButmFunc(block, do_view3d_vpaintmenu, NULL);
-       
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Undo Vertex Painting|U",         0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Set Vertex Colors|Shift K",              0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Set Shaded Vertex Colors",               0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
-       
-#ifndef DISABLE_PYTHON
-       /* note that we account for the 3 previous entries with i+3:
-       even if the last item isnt displayed, it dosent matter */
-//     for (pym = BPyMenuTable[PYMENU_VERTEXPAINT]; pym; pym = pym->next, i++) {
-//             uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20,
-//                     menuwidth, 19, NULL, 0.0, 0.0, 1, i+3,
-//                     pym->tooltip?pym->tooltip:pym->filename);
-//     }
-#endif
-
-       if(ar->alignment==RGN_ALIGN_TOP) {
-               uiBlockSetDirection(block, UI_DOWN);
-       }
-       else {
-               uiBlockSetDirection(block, UI_TOP);
-               uiBlockFlipOrder(block);
-       }
-
-       uiTextBoundsBlock(block, 50);
-       return block;
-}
-
-
 /* texture paint menu (placeholder, no items yet??) */
 static void do_view3d_tpaintmenu(bContext *C, void *arg, int event)
 {
@@ -3050,11 +2985,6 @@ static void view3d_header_pulldowns(const bContext *C, uiBlock *block, Object *o
                uiDefPulldownBut(block, view3d_wpaintmenu, NULL, "Paint", xco,yco, xmax-3, 20, "");
                xco+= xmax;
        }
-       else if (ob && ob->mode & OB_MODE_VERTEX_PAINT) {
-               xmax= GetButStringLength("Paint");
-               uiDefPulldownBut(block, view3d_vpaintmenu, NULL, "Paint", xco,yco, xmax-3, 20, "");
-               xco+= xmax;
-       } 
        else if (ob && ob->mode & OB_MODE_TEXTURE_PAINT) {
                xmax= GetButStringLength("Paint");
                uiDefPulldownBut(block, view3d_tpaintmenu, NULL, "Paint", xco,yco, xmax-3, 20, "");