diff options
author | Antony Riakiotakis <kalast@gmail.com> | 2013-10-27 07:31:19 +0400 |
---|---|---|
committer | Antony Riakiotakis <kalast@gmail.com> | 2013-10-27 07:31:19 +0400 |
commit | aed672ac1e1363b3fd4a7b5cbd415f5eda167306 (patch) | |
tree | 31c612ef317c627811a8e9d004c31d259623ef59 /source | |
parent | 01da2c0e53e8a3faf08375027ced7e7fb153726b (diff) |
Border select for sculpting, using B shortcut, warmup for more advanced
masking, like lasso selection.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/include/ED_sculpt.h | 4 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_intern.h | 1 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_mask.c | 71 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_select.c | 6 |
4 files changed, 78 insertions, 4 deletions
diff --git a/source/blender/editors/include/ED_sculpt.h b/source/blender/editors/include/ED_sculpt.h index a50a8a50eaa..e85f11e5b78 100644 --- a/source/blender/editors/include/ED_sculpt.h +++ b/source/blender/editors/include/ED_sculpt.h @@ -37,6 +37,8 @@ struct Object; struct RegionView3D; struct wmKeyConfig; struct wmWindowManager; +struct ViewContext; +struct rcti; /* sculpt.c */ void ED_operatortypes_sculpt(void); @@ -48,6 +50,8 @@ void ED_sculpt_get_average_stroke(struct Object *ob, float stroke[3]); int ED_sculpt_minmax(struct bContext *C, float min[3], float max[3]); int ED_sculpt_mask_layers_ensure(struct Object *ob, struct MultiresModifierData *mmd); +int do_sculpt_mask_box_select(struct ViewContext *vc, struct rcti *rect, bool select, bool extend); + enum { ED_SCULPT_MASK_LAYER_CALC_VERT = (1 << 0), ED_SCULPT_MASK_LAYER_CALC_LOOP = (1 << 1) diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h index 2545328ec65..86b223ec2a0 100644 --- a/source/blender/editors/sculpt_paint/paint_intern.h +++ b/source/blender/editors/sculpt_paint/paint_intern.h @@ -264,5 +264,6 @@ typedef enum { } PaintMaskFloodMode; void PAINT_OT_mask_flood_fill(struct wmOperatorType *ot); +void PAINT_OT_mask_box_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 index 8767b080355..13f11c8a816 100644 --- a/source/blender/editors/sculpt_paint/paint_mask.c +++ b/source/blender/editors/sculpt_paint/paint_mask.c @@ -36,6 +36,10 @@ #include "DNA_meshdata_types.h" #include "DNA_object_types.h" +#include "BIF_glutil.h" + +#include "BLI_math_matrix.h" +#include "BLI_math_geom.h" #include "BLI_utildefines.h" #include "BKE_pbvh.h" #include "BKE_ccg.h" @@ -53,6 +57,7 @@ #include "ED_screen.h" #include "ED_sculpt.h" +#include "ED_view3d.h" #include "bmesh.h" @@ -148,3 +153,69 @@ void PAINT_OT_mask_flood_fill(struct wmOperatorType *ot) 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); } + +/* Box select, operator is VIEW3D_OT_select_border, defined in view3d_select.c */ + +static int is_effected(float planes[4][4], const float co[3]) +{ + return isect_point_planes_v3(planes, 4, co); +} + +int do_sculpt_mask_box_select(ViewContext *vc, rcti *rect, bool select, bool UNUSED(extend)) +{ + BoundBox bb; + bglMats mats = {{0}}; + float clip_planes[4][4]; + ARegion *ar = vc->ar; + struct Scene *scene = vc->scene; + Object *ob = vc->obact; + struct MultiresModifierData *mmd = sculpt_multires_active(scene, ob); + PaintMaskFloodMode mode; + float value; + DerivedMesh *dm; + PBVH *pbvh; + PBVHNode **nodes; + int totnode, i; + + mode = PAINT_MASK_FLOOD_VALUE; + value = select ? 1.0 : 0.0; + + /* transform the */ + view3d_get_transformation(vc->ar, vc->rv3d, vc->obact, &mats); + ED_view3d_clipping_calc(&bb, clip_planes, &mats, rect); + mul_m4_fl(clip_planes, -1.0f); + + ED_sculpt_mask_layers_ensure(ob, mmd); + + dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH); + pbvh = dm->getPBVH(ob, dm); + ob->sculpt->pbvh = pbvh; + + BKE_pbvh_search_gather(pbvh, BKE_pbvh_node_planes_contain_AABB, clip_planes, &nodes, &totnode); + + sculpt_undo_push_begin("Mask box fill"); + + for (i = 0; i < totnode; i++) { + PBVHVertexIter vi; + + sculpt_undo_push_node(ob, nodes[i], SCULPT_UNDO_MASK); + + BKE_pbvh_vertex_iter_begin(pbvh, nodes[i], vi, PBVH_ITER_UNIQUE) { + if (is_effected(clip_planes, vi.co)) + mask_flood_fill_set_elem(vi.mask, mode, value); + } BKE_pbvh_vertex_iter_end; + + BKE_pbvh_node_mark_update(nodes[i]); + if (BKE_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; +} diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index ff17c2eedc1..a6ef70a5e33 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -89,6 +89,7 @@ #include "ED_mesh.h" #include "ED_object.h" #include "ED_screen.h" +#include "ED_sculpt.h" #include "ED_mball.h" #include "UI_interface.h" @@ -272,9 +273,6 @@ static int view3d_selectable_data(bContext *C) } } else { - if (ob->mode & OB_MODE_SCULPT) { - return 0; - } if ((ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT)) && !paint_facesel_test(ob) && !paint_vertsel_test(ob)) { @@ -2125,7 +2123,7 @@ static int view3d_borderselect_exec(bContext *C, wmOperator *op) } else { /* no editmode, unified for bones and objects */ if (vc.obact && vc.obact->mode & OB_MODE_SCULPT) { - /* pass */ + ret = do_sculpt_mask_box_select(&vc, &rect, select, extend); } else if (vc.obact && paint_facesel_test(vc.obact)) { ret = do_paintface_box_select(&vc, &rect, select, extend); |