diff options
author | Nicholas Bishop <nicholasbishop@gmail.com> | 2012-05-11 00:35:51 +0400 |
---|---|---|
committer | Nicholas Bishop <nicholasbishop@gmail.com> | 2012-05-11 00:35:51 +0400 |
commit | 5cb08c47c5ef793df33f867506d26afdf35d1f3d (patch) | |
tree | f5a164cbae6f01877ac69346c4c0d7e73636c200 /source | |
parent | 919b363d133a04b114970fb06282ced6bcbab186 (diff) |
Add a paint mask operator to clear, fill, or invert the mask.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/sculpt_paint/CMakeLists.txt | 1 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_intern.h | 10 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_mask.c | 143 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_ops.c | 3 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/sculpt_intern.h | 2 |
5 files changed, 158 insertions, 1 deletions
diff --git a/source/blender/editors/sculpt_paint/CMakeLists.txt b/source/blender/editors/sculpt_paint/CMakeLists.txt index cf8179b4d0e..043b7ecb5cb 100644 --- a/source/blender/editors/sculpt_paint/CMakeLists.txt +++ b/source/blender/editors/sculpt_paint/CMakeLists.txt @@ -42,6 +42,7 @@ set(SRC paint_cursor.c paint_hide.c paint_image.c + paint_mask.c paint_ops.c paint_stroke.c paint_undo.c diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h index 65fb65c1553..d21dca8b6a4 100644 --- a/source/blender/editors/sculpt_paint/paint_intern.h +++ b/source/blender/editors/sculpt_paint/paint_intern.h @@ -43,6 +43,7 @@ struct PaintStroke; struct PointerRNA; struct rcti; struct Scene; +struct RegionView3D; struct VPaint; struct ViewContext; struct wmEvent; @@ -184,4 +185,13 @@ typedef enum { void PAINT_OT_hide_show(struct wmOperatorType *ot); +/* paint_mask.c */ + +typedef enum { + PAINT_MASK_FLOOD_VALUE, + PAINT_MASK_INVERT +} PaintMaskFloodMode; + +void PAINT_OT_mask_flood_fill(struct wmOperatorType *ot); + #endif /* __PAINT_INTERN_H__ */ diff --git a/source/blender/editors/sculpt_paint/paint_mask.c b/source/blender/editors/sculpt_paint/paint_mask.c new file mode 100644 index 00000000000..000f43b0dec --- /dev/null +++ b/source/blender/editors/sculpt_paint/paint_mask.c @@ -0,0 +1,143 @@ +/* + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2012 by Nicholas Bishop + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): + * + * ***** END GPL LICENSE BLOCK ***** + * + */ + +/** \file blender/editors/sculpt_paint/paint_mask.c + * \ingroup edsculpt + */ + +#include "MEM_guardedalloc.h" + +#include "DNA_mesh_types.h" +#include "DNA_meshdata_types.h" +#include "DNA_object_types.h" + +#include "BLI_pbvh.h" + +#include "BKE_ccg.h" +#include "BKE_context.h" +#include "BKE_DerivedMesh.h" +#include "BKE_multires.h" +#include "BKE_paint.h" +#include "BKE_subsurf.h" + +#include "RNA_access.h" +#include "RNA_define.h" + +#include "WM_api.h" +#include "WM_types.h" + +#include "ED_screen.h" + +#include "paint_intern.h" +#include "sculpt_intern.h" /* for undo push */ + +#include <stdlib.h> + +static void mask_flood_fill_set_elem(float *elem, + PaintMaskFloodMode mode, + float value) +{ + switch(mode) { + case PAINT_MASK_FLOOD_VALUE: + (*elem) = value; + break; + case PAINT_MASK_INVERT: + (*elem) = 1.0f - (*elem); + break; + } +} + +static int mask_flood_fill_exec(bContext *C, wmOperator *op) +{ + ARegion *ar = CTX_wm_region(C); + Object *ob = CTX_data_active_object(C); + PaintMaskFloodMode mode; + float value; + DerivedMesh *dm; + PBVH *pbvh; + PBVHNode **nodes; + int totnode, i; + + mode = RNA_enum_get(op->ptr, "mode"); + value = RNA_float_get(op->ptr, "value"); + + dm = mesh_get_derived_final(CTX_data_scene(C), ob, CD_MASK_BAREMESH); + pbvh = dm->getPBVH(ob, dm); + ob->sculpt->pbvh = pbvh; + + BLI_pbvh_search_gather(pbvh, NULL, NULL, &nodes, &totnode); + + sculpt_undo_push_begin("Mask flood fill"); + + for(i = 0; i < totnode; i++) { + PBVHVertexIter vi; + + sculpt_undo_push_node(ob, nodes[i], SCULPT_UNDO_MASK); + + BLI_pbvh_vertex_iter_begin(pbvh, nodes[i], vi, PBVH_ITER_UNIQUE) { + mask_flood_fill_set_elem(vi.mask, mode, value); + } BLI_pbvh_vertex_iter_end; + + BLI_pbvh_node_mark_update(nodes[i]); + if(BLI_pbvh_type(pbvh) == PBVH_GRIDS) + multires_mark_as_modified(ob, MULTIRES_COORDS_MODIFIED); + } + + sculpt_undo_push_end(); + + if(nodes) + MEM_freeN(nodes); + + ED_region_tag_redraw(ar); + + return OPERATOR_FINISHED; +} + +void PAINT_OT_mask_flood_fill(struct wmOperatorType *ot) +{ + static EnumPropertyItem mode_items[] = { + {PAINT_MASK_FLOOD_VALUE, "VALUE", 0, "Value", "Set mask to the level specified by the \"value\" property"}, + {PAINT_MASK_INVERT, "INVERT", 0, "Invert", "Invert the mask"}, + {0}}; + + /* identifiers */ + ot->name = "Mask Flood Fill"; + ot->idname = "PAINT_OT_mask_flood_fill"; + + /* api callbacks */ + ot->exec = mask_flood_fill_exec; + ot->poll = sculpt_mode_poll; + + ot->flag = OPTYPE_REGISTER; + + /* rna */ + RNA_def_enum(ot->srna, "mode", mode_items, PAINT_MASK_FLOOD_VALUE, "Mode", NULL); + RNA_def_float(ot->srna, "value", 0, 0, 1, "Value", "Mask level to use when mode is \"Value\"; zero means no masking and one is fully masked", 0, 1); +} diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c index f4dd9392ec4..4efaae36543 100644 --- a/source/blender/editors/sculpt_paint/paint_ops.c +++ b/source/blender/editors/sculpt_paint/paint_ops.c @@ -498,6 +498,9 @@ void ED_operatortypes_paint(void) /* partial visibility */ WM_operatortype_append(PAINT_OT_hide_show); + + /* paint masking */ + WM_operatortype_append(PAINT_OT_mask_flood_fill); } diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h index 14fb122578a..b67206df6c8 100644 --- a/source/blender/editors/sculpt_paint/sculpt_intern.h +++ b/source/blender/editors/sculpt_paint/sculpt_intern.h @@ -53,7 +53,7 @@ struct SculptStroke; /* Interface */ struct MultiresModifierData *sculpt_multires_active(struct Scene *scene, struct Object *ob); -void sculpt(Sculpt *sd); +void sculpt(struct Sculpt *sd); int sculpt_mode_poll(struct bContext *C); int sculpt_poll(struct bContext *C); |