Welcome to mirror list, hosted at ThFree Co, Russian Federation.

paint_mask.c « sculpt_paint « editors « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 05ffb80d8a1f40b4c89787c8bf2a29a2e3aac586 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
/*
 * 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.
 */

/** \file
 * \ingroup edsculpt
 */

#include "MEM_guardedalloc.h"

#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
#include "DNA_vec_types.h"

#include "BLI_bitmap_draw_2d.h"
#include "BLI_lasso_2d.h"
#include "BLI_math_geom.h"
#include "BLI_math_matrix.h"
#include "BLI_task.h"
#include "BLI_utildefines.h"

#include "BKE_ccg.h"
#include "BKE_context.h"
#include "BKE_multires.h"
#include "BKE_paint.h"
#include "BKE_pbvh.h"
#include "BKE_subsurf.h"

#include "DEG_depsgraph.h"

#include "RNA_access.h"
#include "RNA_define.h"

#include "WM_api.h"
#include "WM_types.h"

#include "ED_screen.h"
#include "ED_sculpt.h"
#include "ED_view3d.h"

#include "bmesh.h"

#include "paint_intern.h"

/* For undo push. */
#include "sculpt_intern.h"

#include <stdlib.h>

static const EnumPropertyItem mode_items[] = {
    {PAINT_MASK_FLOOD_VALUE,
     "VALUE",
     0,
     "Value",
     "Set mask to the level specified by the 'value' property"},
    {PAINT_MASK_FLOOD_VALUE_INVERSE,
     "VALUE_INVERSE",
     0,
     "Value Inverted",
     "Set mask to the level specified by the inverted 'value' property"},
    {PAINT_MASK_INVERT, "INVERT", 0, "Invert", "Invert the mask"},
    {0}};

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_FLOOD_VALUE_INVERSE:
      (*elem) = 1.0f - value;
      break;
    case PAINT_MASK_INVERT:
      (*elem) = 1.0f - (*elem);
      break;
  }
}

typedef struct MaskTaskData {
  Object *ob;
  PBVH *pbvh;
  PBVHNode **nodes;
  bool multires;

  PaintMaskFloodMode mode;
  float value;
  float (*clip_planes_final)[4];

  bool front_faces_only;
  float view_normal[3];
} MaskTaskData;

static void mask_flood_fill_task_cb(void *__restrict userdata,
                                    const int i,
                                    const TaskParallelTLS *__restrict UNUSED(tls))
{
  MaskTaskData *data = userdata;

  PBVHNode *node = data->nodes[i];

  const PaintMaskFloodMode mode = data->mode;
  const float value = data->value;
  bool redraw = false;

  PBVHVertexIter vi;

  SCULPT_undo_push_node(data->ob, node, SCULPT_UNDO_MASK);

  BKE_pbvh_vertex_iter_begin(data->pbvh, node, vi, PBVH_ITER_UNIQUE)
  {
    float prevmask = *vi.mask;
    mask_flood_fill_set_elem(vi.mask, mode, value);
    if (prevmask != *vi.mask) {
      redraw = true;
    }
  }
  BKE_pbvh_vertex_iter_end;

  if (redraw) {
    BKE_pbvh_node_mark_update_mask(node);
    if (data->multires) {
      BKE_pbvh_node_mark_normals_update(node);
    }
  }
}

static int mask_flood_fill_exec(bContext *C, wmOperator *op)
{
  ARegion *region = CTX_wm_region(C);
  Object *ob = CTX_data_active_object(C);
  Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
  PaintMaskFloodMode mode;
  float value;
  PBVH *pbvh;
  PBVHNode **nodes;
  int totnode;
  bool multires;

  mode = RNA_enum_get(op->ptr, "mode");
  value = RNA_float_get(op->ptr, "value");

  BKE_sculpt_update_object_for_edit(depsgraph, ob, false, true, false);
  pbvh = ob->sculpt->pbvh;
  multires = (BKE_pbvh_type(pbvh) == PBVH_GRIDS);

  BKE_pbvh_search_gather(pbvh, NULL, NULL, &nodes, &totnode);

  SCULPT_undo_push_begin("Mask flood fill");

  MaskTaskData data = {
      .ob = ob,
      .pbvh = pbvh,
      .nodes = nodes,
      .multires = multires,
      .mode = mode,
      .value = value,
  };

  TaskParallelSettings settings;
  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
  BLI_task_parallel_range(0, totnode, &data, mask_flood_fill_task_cb, &settings);

  if (multires) {
    multires_mark_as_modified(depsgraph, ob, MULTIRES_COORDS_MODIFIED);
  }

  BKE_pbvh_update_vertex_data(pbvh, PBVH_UpdateMask);

  SCULPT_undo_push_end();

  if (nodes) {
    MEM_freeN(nodes);
  }

  ED_region_tag_redraw(region);

  WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);

  return OPERATOR_FINISHED;
}

void PAINT_OT_mask_flood_fill(struct wmOperatorType *ot)
{
  /* Identifiers. */
  ot->name = "Mask Flood Fill";
  ot->idname = "PAINT_OT_mask_flood_fill";
  ot->description = "Fill the whole mask with a given value, or invert its values";

  /* 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.0f,
      0.0f,
      1.0f,
      "Value",
      "Mask level to use when mode is 'Value'; zero means no masking and one is fully masked",
      0.0f,
      1.0f);
}

/* Box select, operator is VIEW3D_OT_select_box, defined in view3d_select.c. */

static bool is_effected(float planes[4][4], const float co[3])
{
  return isect_point_planes_v3(planes, 4, co);
}

static void flip_plane(float out[4], const float in[4], const char symm)
{
  if (symm & PAINT_SYMM_X) {
    out[0] = -in[0];
  }
  else {
    out[0] = in[0];
  }
  if (symm & PAINT_SYMM_Y) {
    out[1] = -in[1];
  }
  else {
    out[1] = in[1];
  }
  if (symm & PAINT_SYMM_Z) {
    out[2] = -in[2];
  }
  else {
    out[2] = in[2];
  }

  out[3] = in[3];
}

static void mask_box_select_task_cb(void *__restrict userdata,
                                    const int i,
                                    const TaskParallelTLS *__restrict UNUSED(tls))
{
  MaskTaskData *data = userdata;

  PBVHNode *node = data->nodes[i];

  const PaintMaskFloodMode mode = data->mode;
  const float value = data->value;
  float(*clip_planes_final)[4] = data->clip_planes_final;

  PBVHVertexIter vi;
  bool any_masked = false;
  bool redraw = false;

  float vertex_normal[3];

  BKE_pbvh_vertex_iter_begin(data->pbvh, node, vi, PBVH_ITER_UNIQUE)
  {
    SCULPT_vertex_normal_get(data->ob->sculpt, vi.index, vertex_normal);
    float dot = dot_v3v3(data->view_normal, vertex_normal);
    const bool is_effected_front_face = !(data->front_faces_only && dot < 0.0f);

    if (is_effected_front_face && is_effected(clip_planes_final, vi.co)) {
      float prevmask = *vi.mask;
      if (!any_masked) {
        any_masked = true;

        SCULPT_undo_push_node(data->ob, node, SCULPT_UNDO_MASK);

        if (data->multires) {
          BKE_pbvh_node_mark_normals_update(node);
        }
      }
      mask_flood_fill_set_elem(vi.mask, mode, value);
      if (prevmask != *vi.mask) {
        redraw = true;
      }
    }
  }
  BKE_pbvh_vertex_iter_end;

  if (redraw) {
    BKE_pbvh_node_mark_update_mask(node);
  }
}

static int paint_mask_gesture_box_exec(bContext *C, wmOperator *op)
{
  ViewContext vc;
  Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
  ED_view3d_viewcontext_init(C, &vc, depsgraph);

  Sculpt *sd = vc.scene->toolsettings->sculpt;
  BoundBox bb;
  float clip_planes[4][4];
  float clip_planes_final[4][4];
  ARegion *region = vc.region;
  Object *ob = vc.obact;
  bool multires;
  PBVH *pbvh;
  PBVHNode **nodes;
  int totnode;
  int symm = sd->paint.symmetry_flags & PAINT_SYMM_AXIS_ALL;

  const PaintMaskFloodMode mode = RNA_enum_get(op->ptr, "mode");
  const float value = RNA_float_get(op->ptr, "value");
  const bool front_faces_only = RNA_boolean_get(op->ptr, "use_front_faces_only");

  rcti rect;
  WM_operator_properties_border_to_rcti(op, &rect);

  /* Transform the clip planes in object space. */
  ED_view3d_clipping_calc(&bb, clip_planes, vc.region, vc.obact, &rect);

  BKE_sculpt_update_object_for_edit(depsgraph, ob, false, true, false);
  pbvh = ob->sculpt->pbvh;
  multires = (BKE_pbvh_type(pbvh) == PBVH_GRIDS);

  SCULPT_undo_push_begin("Mask box fill");

  /* Calculate the view normal in object space. */
  float mat[3][3];
  float view_dir[3] = {0.0f, 0.0f, 1.0f};
  float true_view_normal[3];
  copy_m3_m4(mat, vc.rv3d->viewinv);
  mul_m3_v3(mat, view_dir);
  copy_m3_m4(mat, ob->imat);
  mul_m3_v3(mat, view_dir);
  normalize_v3_v3(true_view_normal, view_dir);

  for (int symmpass = 0; symmpass <= symm; symmpass++) {
    if (symmpass == 0 || (symm & symmpass && (symm != 5 || symmpass != 3) &&
                          (symm != 6 || (symmpass != 3 && symmpass != 5)))) {

      /* Flip the planes symmetrically as needed. */
      for (int j = 0; j < 4; j++) {
        flip_plane(clip_planes_final[j], clip_planes[j], symmpass);
      }

      PBVHFrustumPlanes frustum = {.planes = clip_planes_final, .num_planes = 4};
      BKE_pbvh_search_gather(pbvh, BKE_pbvh_node_frustum_contain_AABB, &frustum, &nodes, &totnode);

      negate_m4(clip_planes_final);

      MaskTaskData data = {
          .ob = ob,
          .pbvh = pbvh,
          .nodes = nodes,
          .multires = multires,
          .mode = mode,
          .value = value,
          .clip_planes_final = clip_planes_final,
          .front_faces_only = front_faces_only,
      };

      flip_v3_v3(data.view_normal, true_view_normal, symmpass);

      TaskParallelSettings settings;
      BKE_pbvh_parallel_range_settings(&settings, true, totnode);
      BLI_task_parallel_range(0, totnode, &data, mask_box_select_task_cb, &settings);

      if (nodes) {
        MEM_freeN(nodes);
      }
    }
  }

  if (multires) {
    multires_mark_as_modified(depsgraph, ob, MULTIRES_COORDS_MODIFIED);
  }

  BKE_pbvh_update_vertex_data(pbvh, PBVH_UpdateMask);

  SCULPT_undo_push_end();

  ED_region_tag_redraw(region);

  WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);

  return true;
}

typedef struct LassoMaskData {
  struct ViewContext *vc;
  float projviewobjmat[4][4];
  BLI_bitmap *px;
  int width;
  /* Bounding box for scanfilling. */
  rcti rect;
  int symmpass;

  MaskTaskData task_data;
} LassoMaskData;

/**
 * Lasso select. This could be defined as part of #VIEW3D_OT_select_lasso,
 * still the shortcuts conflict, so we will use a separate operator.
 */
static bool is_effected_lasso(LassoMaskData *data, const float co[3])
{
  float scr_co_f[2];
  int scr_co_s[2];
  float co_final[3];

  flip_v3_v3(co_final, co, data->symmpass);
  /* First project point to 2d space. */
  ED_view3d_project_float_v2_m4(data->vc->region, co_final, scr_co_f, data->projviewobjmat);

  scr_co_s[0] = scr_co_f[0];
  scr_co_s[1] = scr_co_f[1];

  /* Clip against screen, because lasso is limited to screen only. */
  if ((scr_co_s[0] < data->rect.xmin) || (scr_co_s[1] < data->rect.ymin) ||
      (scr_co_s[0] >= data->rect.xmax) || (scr_co_s[1] >= data->rect.ymax)) {
    return false;
  }

  scr_co_s[0] -= data->rect.xmin;
  scr_co_s[1] -= data->rect.ymin;

  return BLI_BITMAP_TEST_BOOL(data->px, scr_co_s[1] * data->width + scr_co_s[0]);
}

static void mask_lasso_px_cb(int x, int x_end, int y, void *user_data)
{
  LassoMaskData *data = user_data;
  int index = (y * data->width) + x;
  int index_end = (y * data->width) + x_end;
  do {
    BLI_BITMAP_ENABLE(data->px, index);
  } while (++index != index_end);
}

static void mask_gesture_lasso_task_cb(void *__restrict userdata,
                                       const int i,
                                       const TaskParallelTLS *__restrict UNUSED(tls))
{
  LassoMaskData *lasso_data = userdata;
  MaskTaskData *data = &lasso_data->task_data;

  PBVHNode *node = data->nodes[i];

  const PaintMaskFloodMode mode = data->mode;
  const float value = data->value;

  PBVHVertexIter vi;
  bool any_masked = false;

  float vertex_normal[3];

  BKE_pbvh_vertex_iter_begin(data->pbvh, node, vi, PBVH_ITER_UNIQUE)
  {
    SCULPT_vertex_normal_get(data->ob->sculpt, vi.index, vertex_normal);
    float dot = dot_v3v3(lasso_data->task_data.view_normal, vertex_normal);
    const bool is_effected_front_face = !(data->front_faces_only && dot < 0.0f);

    if (is_effected_front_face && is_effected_lasso(lasso_data, vi.co)) {
      if (!any_masked) {
        any_masked = true;

        SCULPT_undo_push_node(data->ob, node, SCULPT_UNDO_MASK);

        BKE_pbvh_node_mark_redraw(node);
        if (data->multires) {
          BKE_pbvh_node_mark_normals_update(node);
        }
      }

      mask_flood_fill_set_elem(vi.mask, mode, value);
    }
  }
  BKE_pbvh_vertex_iter_end;
}

static int paint_mask_gesture_lasso_exec(bContext *C, wmOperator *op)
{
  int mcoords_len;
  const int(*mcoords)[2] = WM_gesture_lasso_path_to_array(C, op, &mcoords_len);

  if (mcoords) {
    Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
    float clip_planes[4][4], clip_planes_final[4][4];
    BoundBox bb;
    Object *ob;
    ViewContext vc;
    LassoMaskData data;
    Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
    int symm = sd->paint.symmetry_flags & PAINT_SYMM_AXIS_ALL;
    PBVH *pbvh;
    PBVHNode **nodes;
    int totnode;
    bool multires;
    PaintMaskFloodMode mode = RNA_enum_get(op->ptr, "mode");
    float value = RNA_float_get(op->ptr, "value");
    const bool front_faces_only = RNA_boolean_get(op->ptr, "use_front_faces_only");

    /* Calculations of individual vertices are done in 2D screen space to diminish the amount of
     * calculations done. Bounding box PBVH collision is not computed against enclosing rectangle
     * of lasso. */
    ED_view3d_viewcontext_init(C, &vc, depsgraph);

    /* Lasso data calculations. */
    data.vc = &vc;
    ob = vc.obact;
    ED_view3d_ob_project_mat_get(vc.rv3d, ob, data.projviewobjmat);

    BLI_lasso_boundbox(&data.rect, mcoords, mcoords_len);
    data.width = data.rect.xmax - data.rect.xmin;
    data.px = BLI_BITMAP_NEW(data.width * (data.rect.ymax - data.rect.ymin), __func__);

    BLI_bitmap_draw_2d_poly_v2i_n(data.rect.xmin,
                                  data.rect.ymin,
                                  data.rect.xmax,
                                  data.rect.ymax,
                                  mcoords,
                                  mcoords_len,
                                  mask_lasso_px_cb,
                                  &data);

    ED_view3d_clipping_calc(&bb, clip_planes, vc.region, vc.obact, &data.rect);

    BKE_sculpt_update_object_for_edit(depsgraph, ob, false, true, false);
    pbvh = ob->sculpt->pbvh;
    multires = (BKE_pbvh_type(pbvh) == PBVH_GRIDS);

    SCULPT_undo_push_begin("Mask lasso fill");

    /* Calculate the view normal in object space. */
    float mat[3][3];
    float view_dir[3] = {0.0f, 0.0f, 1.0f};
    float true_view_normal[3];
    copy_m3_m4(mat, vc.rv3d->viewinv);
    mul_m3_v3(mat, view_dir);
    copy_m3_m4(mat, ob->imat);
    mul_m3_v3(mat, view_dir);
    normalize_v3_v3(true_view_normal, view_dir);

    for (int symmpass = 0; symmpass <= symm; symmpass++) {
      if ((symmpass == 0) || (symm & symmpass && (symm != 5 || symmpass != 3) &&
                              (symm != 6 || (symmpass != 3 && symmpass != 5)))) {

        /* Flip the planes symmetrically as needed. */
        for (int j = 0; j < 4; j++) {
          flip_plane(clip_planes_final[j], clip_planes[j], symmpass);
        }

        flip_v3_v3(data.task_data.view_normal, true_view_normal, symmpass);

        data.symmpass = symmpass;

        /* Gather nodes inside lasso's enclosing rectangle
         * (should greatly help with bigger meshes). */
        PBVHFrustumPlanes frustum = {.planes = clip_planes_final, .num_planes = 4};
        BKE_pbvh_search_gather(
            pbvh, BKE_pbvh_node_frustum_contain_AABB, &frustum, &nodes, &totnode);

        negate_m4(clip_planes_final);

        data.task_data.ob = ob;
        data.task_data.pbvh = pbvh;
        data.task_data.nodes = nodes;
        data.task_data.multires = multires;
        data.task_data.mode = mode;
        data.task_data.value = value;
        data.task_data.front_faces_only = front_faces_only;

        TaskParallelSettings settings;
        BKE_pbvh_parallel_range_settings(&settings, true, totnode);
        BLI_task_parallel_range(0, totnode, &data, mask_gesture_lasso_task_cb, &settings);

        if (nodes) {
          MEM_freeN(nodes);
        }
      }
    }

    if (multires) {
      multires_mark_as_modified(depsgraph, ob, MULTIRES_COORDS_MODIFIED);
    }

    BKE_pbvh_update_vertex_data(pbvh, PBVH_UpdateMask);

    SCULPT_undo_push_end();

    ED_region_tag_redraw(vc.region);
    MEM_freeN((void *)mcoords);
    MEM_freeN(data.px);

    WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);

    return OPERATOR_FINISHED;
  }
  return OPERATOR_PASS_THROUGH;
}

void PAINT_OT_mask_lasso_gesture(wmOperatorType *ot)
{
  ot->name = "Mask Lasso Gesture";
  ot->idname = "PAINT_OT_mask_lasso_gesture";
  ot->description = "Add mask within the lasso as you move the brush";

  ot->invoke = WM_gesture_lasso_invoke;
  ot->modal = WM_gesture_lasso_modal;
  ot->exec = paint_mask_gesture_lasso_exec;

  ot->poll = SCULPT_mode_poll;

  ot->flag = OPTYPE_REGISTER;

  /* Properties. */
  WM_operator_properties_gesture_lasso(ot);

  RNA_def_enum(ot->srna, "mode", mode_items, PAINT_MASK_FLOOD_VALUE, "Mode", NULL);
  RNA_def_float(
      ot->srna,
      "value",
      1.0f,
      0.0f,
      1.0f,
      "Value",
      "Mask level to use when mode is 'Value'; zero means no masking and one is fully masked",
      0.0f,
      1.0f);
  RNA_def_boolean(ot->srna,
                  "use_front_faces_only",
                  false,
                  "Front Faces Only",
                  "Affect only faces facing towards the view");
}

void PAINT_OT_mask_box_gesture(wmOperatorType *ot)
{
  ot->name = "Mask Box Gesture";
  ot->idname = "PAINT_OT_mask_box_gesture";
  ot->description = "Add mask within the box as you move the brush";

  ot->invoke = WM_gesture_box_invoke;
  ot->modal = WM_gesture_box_modal;
  ot->exec = paint_mask_gesture_box_exec;

  ot->poll = SCULPT_mode_poll;

  ot->flag = OPTYPE_REGISTER;

  /* Properties. */
  WM_operator_properties_border(ot);

  RNA_def_enum(ot->srna, "mode", mode_items, PAINT_MASK_FLOOD_VALUE, "Mode", NULL);
  RNA_def_float(
      ot->srna,
      "value",
      1.0f,
      0.0f,
      1.0f,
      "Value",
      "Mask level to use when mode is 'Value'; zero means no masking and one is fully masked",
      0.0f,
      1.0f);
  RNA_def_boolean(ot->srna,
                  "use_front_faces_only",
                  false,
                  "Front Faces Only",
                  "Affect only faces facing towards the view");
}