Border select for sculpting, using B shortcut, warmup for more advanced

masking, like lasso selection.
This commit is contained in:
Antony Riakiotakis
2013-10-27 03:31:19 +00:00
parent 01da2c0e53
commit aed672ac1e
4 changed files with 78 additions and 4 deletions

View File

@@ -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)

View File

@@ -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__ */

View File

@@ -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;
}

View File

@@ -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);