Blender V5.3
paint_hide.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2010 by Nicholas Bishop. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "paint_hide.hh"
10
11#include "MEM_guardedalloc.h"
12
13#include "BLI_array_utils.hh"
14#include "BLI_bit_span_ops.hh"
16#include "BLI_utildefines.hh"
17#include "BLI_vector.hh"
18
19#include "DNA_object_types.h"
20
21#include "BKE_attribute.hh"
22#include "BKE_ccg.hh"
23#include "BKE_context.hh"
24#include "BKE_mesh.hh"
25#include "BKE_multires.hh"
26#include "BKE_object_types.hh"
27#include "BKE_paint.hh"
28#include "BKE_paint_bvh.hh"
29#include "BKE_subdiv_ccg.hh"
30
31#include "DEG_depsgraph.hh"
32
33#include "WM_api.hh"
34#include "WM_types.hh"
35
36#include "ED_screen.hh"
37
38#include "RNA_access.hh"
39#include "RNA_define.hh"
40
41#include "bmesh.hh"
42
43#include "../paint_intern.hh"
44#include "mesh_brush_common.hh"
45#include "sculpt_gesture.hh"
46#include "sculpt_intern.hh"
47#include "sculpt_islands.hh"
48#include "sculpt_undo.hh"
49
51
52/* -------------------------------------------------------------------- */
55
57{
58 SculptSession &ss = *object.runtime->sculpt_session;
59 Mesh &mesh = *id_cast<Mesh *>(object.data);
60
62
63 switch (bke::object::pbvh_get(object)->type()) {
65 /* We may have adjusted the ".hide_poly" attribute, now make the hide status attributes for
66 * vertices and edges consistent. */
68 break;
69 }
71 /* In addition to making the hide status of the base mesh consistent, we also have to
72 * propagate the status to the Multires grids. */
75 break;
76 }
78 BMesh &bm = *ss.bm;
79 BMIter iter;
80 BMFace *f;
81
82 /* Hide all verts and edges attached to faces. */
83 BM_ITER_MESH (f, &iter, &bm, BM_FACES_OF_MESH) {
84 BMLoop *l = f->l_first;
85 do {
88 } while ((l = l->next) != f->l_first);
89 }
90
91 /* Unhide verts and edges attached to visible faces. */
92 BM_ITER_MESH (f, &iter, &bm, BM_FACES_OF_MESH) {
94 continue;
95 }
96
97 BMLoop *l = f->l_first;
98 do {
101 } while ((l = l->next) != f->l_first);
102 }
103 break;
104 }
105 }
106}
107
122
123void mesh_show_all(const Depsgraph &depsgraph, Object &object, const IndexMask &node_mask)
124{
127 Mesh &mesh = *id_cast<Mesh *>(object.data);
128 bke::MutableAttributeAccessor attributes = mesh.attributes_for_write();
129 const VArraySpan hide_vert = *attributes.lookup<bool>(".hide_vert", bke::AttrDomain::Point);
130
131 if (!hide_vert.is_empty()) {
132 IndexMaskMemory memory;
133 const IndexMask changed_nodes = IndexMask::from_predicate(
134 node_mask,
135 memory,
136 [&](const int i) {
137 const Span<int> verts = nodes[i].verts();
138 return std::any_of(
139 verts.begin(), verts.end(), [&](const int i) { return hide_vert[i]; });
140 },
142 undo::push_nodes(depsgraph, object, changed_nodes, undo::Type::HideVert);
143 pbvh.tag_visibility_changed(changed_nodes);
144 }
145
146 attributes.remove(".hide_vert");
148 pbvh.update_visibility(object);
149}
150
151void grids_show_all(Depsgraph &depsgraph, Object &object, const IndexMask &node_mask)
152{
155 SubdivCCG &subdiv_ccg = *object.runtime->sculpt_session->subdiv_ccg;
156 const BitGroupVector<> &grid_hidden = subdiv_ccg.grid_hidden;
157
158 if (!grid_hidden.is_empty()) {
159 IndexMaskMemory memory;
160 const IndexMask changed_nodes = IndexMask::from_predicate(
161 node_mask,
162 memory,
163 [&](const int i) {
164 const Span<int> grids = nodes[i].grids();
165 return std::any_of(grids.begin(), grids.end(), [&](const int i) {
166 return bits::any_bit_set(grid_hidden[i]);
167 });
168 },
170 if (changed_nodes.is_empty()) {
171 return;
172 }
173 undo::push_nodes(depsgraph, object, changed_nodes, undo::Type::HideVert);
174 pbvh.tag_visibility_changed(changed_nodes);
175 }
176
179 pbvh.update_visibility(object);
181}
182
184
185/* -------------------------------------------------------------------- */
189
190enum class VisAction {
191 Hide = 0,
192 Show = 1,
193};
194
195static bool action_to_hide(const VisAction action)
196{
197 return action == VisAction::Hide;
198}
199
200/* Calculates whether a face should be hidden based on all of its corner vertices. */
201static void calc_face_hide(const Span<int> node_faces,
202 const OffsetIndices<int> faces,
203 const Span<int> corner_verts,
204 const Span<bool> hide_vert,
205 MutableSpan<bool> hide_face)
206{
207 for (const int i : node_faces.index_range()) {
208 Span<int> face_verts = corner_verts.slice(faces[node_faces[i]]);
209 hide_face[i] = std::any_of(
210 face_verts.begin(), face_verts.end(), [&](const int v) { return hide_vert[v]; });
211 }
212}
213
214/* Updates a node's face's visibility based on the updated vertex visibility. */
217 const IndexMask &node_mask,
218 const Span<bool> hide_vert)
219{
220 bke::MutableAttributeAccessor attributes = mesh.attributes_for_write();
221
222 const OffsetIndices<int> faces = mesh.faces();
223 const Span<int> corner_verts = mesh.corner_verts();
224
226 ".hide_poly", bke::AttrDomain::Face);
227
229
230 Array<bool> node_changed(node_mask.min_array_size(), false);
231
232 struct TLS {
233 Vector<bool> new_hide;
234 };
236 node_mask.foreach_index(
237 [&](const int i) {
238 TLS &tls = all_tls.local();
239 const Span<int> node_faces = nodes[i].faces();
240
241 tls.new_hide.resize(node_faces.size());
242 gather_data_mesh(hide_poly.span.as_span(), node_faces, tls.new_hide.as_mutable_span());
243
244 calc_face_hide(node_faces, faces, corner_verts, hide_vert, tls.new_hide.as_mutable_span());
245
246 if (array_utils::indexed_data_equal<bool>(hide_poly.span, node_faces, tls.new_hide)) {
247 return;
248 }
249
250 scatter_data_mesh(tls.new_hide.as_span(), node_faces, hide_poly.span);
251 node_changed[i] = true;
253 },
255 hide_poly.finish();
256
257 IndexMaskMemory memory;
258 const IndexMask changed_nodes = IndexMask::from_bools(node_changed, memory);
259 if (changed_nodes.is_empty()) {
260 return;
261 }
262 pbvh.tag_visibility_changed(node_mask);
263}
264
265/* Updates a node's face's visibility based on the updated vertex visibility. */
266static void flush_face_changes(Mesh &mesh, const Span<bool> hide_vert)
267{
268 bke::MutableAttributeAccessor attributes = mesh.attributes_for_write();
269
271 ".hide_poly", bke::AttrDomain::Face);
272
273 bke::mesh_face_hide_from_vert(mesh.faces(), mesh.corner_verts(), hide_vert, hide_poly.span);
274 hide_poly.finish();
275}
276
277/* Updates all of a mesh's edge visibility based on vertex visibility. */
278static void flush_edge_changes(Mesh &mesh, const Span<bool> hide_vert)
279{
280 bke::MutableAttributeAccessor attributes = mesh.attributes_for_write();
281
283 ".hide_edge", bke::AttrDomain::Edge);
284 bke::mesh_edge_hide_from_vert(mesh.edges(), hide_vert, hide_edge.span);
285 hide_edge.finish();
286}
287
288static void vert_hide_update(const Depsgraph &depsgraph,
289 Object &object,
290 const IndexMask &node_mask,
291 const FunctionRef<void(Span<int>, MutableSpan<bool>)> calc_hide)
292{
295
296 Mesh &mesh = *id_cast<Mesh *>(object.data);
297 bke::MutableAttributeAccessor attributes = mesh.attributes_for_write();
299 ".hide_vert", bke::AttrDomain::Point);
300
301 bool any_changed = false;
303 node_mask.foreach_index(
304 [&](const int i) {
305 Vector<bool> &new_hide = all_new_hide.local();
306 const Span<int> verts = nodes[i].verts();
307
308 new_hide.resize(verts.size());
309 gather_data_mesh(hide_vert.span.as_span(), verts, new_hide.as_mutable_span());
310 calc_hide(verts, new_hide);
311 if (array_utils::indexed_data_equal<bool>(hide_vert.span, verts, new_hide)) {
312 return;
313 }
314
315 any_changed = true;
316 undo::push_node(depsgraph, object, &nodes[i], undo::Type::HideVert);
317 scatter_data_mesh(new_hide.as_span(), verts, hide_vert.span);
318 },
320
321 hide_vert.finish();
322 if (any_changed) {
323 /* We handle flushing ourselves at the node level instead of delegating to
324 * #bke::mesh_hide_vert_flush because we need to tag node visibility changes as well in cases
325 * where the vertices hidden are on a node boundary. */
326 flush_face_changes_node(mesh, pbvh, node_mask, hide_vert.span);
327 flush_edge_changes(mesh, hide_vert.span);
328 }
329}
330
331static void grid_hide_update(Depsgraph &depsgraph,
332 Object &object,
333 const IndexMask &node_mask,
334 const FunctionRef<void(const int, MutableBoundedBitSpan)> calc_hide)
335{
338
339 SubdivCCG &subdiv_ccg = *object.runtime->sculpt_session->subdiv_ccg;
340 BitGroupVector<> &grid_hidden = BKE_subdiv_ccg_grid_hidden_ensure(subdiv_ccg);
341
342 Array<bool> node_changed(node_mask.min_array_size(), false);
343
344 bool any_changed = false;
345 node_mask.foreach_index(
346 [&](const int i) {
347 const Span<int> grids = nodes[i].grids();
348 BitGroupVector<> new_hide(grids.size(), grid_hidden.group_size());
349 for (const int i : grids.index_range()) {
350 new_hide[i].copy_from(grid_hidden[grids[i]].as_span());
351 }
352
353 for (const int i : grids.index_range()) {
354 calc_hide(grids[i], new_hide[i]);
355 }
356
357 if (std::all_of(grids.index_range().begin(),
358 grids.index_range().end(),
359 [&](const int i) {
360 return bits::spans_equal(grid_hidden[grids[i]], new_hide[i]);
361 }))
362 {
363 return;
364 }
365
366 any_changed = true;
367 undo::push_node(depsgraph, object, &nodes[i], undo::Type::HideVert);
368
369 for (const int i : grids.index_range()) {
370 grid_hidden[grids[i]].copy_from(new_hide[i].as_span());
371 }
372
373 node_changed[i] = true;
375 },
377
378 IndexMaskMemory memory;
379 const IndexMask changed_nodes = IndexMask::from_bools(node_changed, memory);
380 if (changed_nodes.is_empty()) {
381 return;
382 }
383 pbvh.tag_visibility_changed(node_mask);
386}
387
389 const VisAction action,
390 const FunctionRef<bool(BMVert *v)> should_update,
391 bool *any_changed,
392 bool *any_visible)
393{
394 for (BMVert *v : verts) {
395 if (should_update(v)) {
396 if (action == VisAction::Hide) {
398 }
399 else {
401 }
402 (*any_changed) = true;
403 }
404
406 (*any_visible) = true;
407 }
408 }
409}
410
412{
413 for (BMFace *f : faces) {
416 }
417 else {
419 }
420 }
421}
422
423static void partialvis_update_bmesh_nodes(const Depsgraph &depsgraph,
424 Object &ob,
425 const IndexMask &node_mask,
426 const VisAction action,
427 const FunctionRef<bool(BMVert *v)> vert_test_fn)
428{
431
432 node_mask.foreach_index([&](const int i) {
433 bool any_changed = false;
434 bool any_visible = false;
435
436 undo::push_node(depsgraph, ob, &nodes[i], undo::Type::HideVert);
437
439 action,
440 vert_test_fn,
441 &any_changed,
442 &any_visible);
443
445 action,
446 vert_test_fn,
447 &any_changed,
448 &any_visible);
449
450 /* Finally loop over node faces and tag the ones that are fully hidden. */
452
453 if (any_changed) {
454 BKE_pbvh_node_fully_hidden_set(nodes[i], !any_visible);
455 }
456 });
457
458 pbvh.tag_visibility_changed(node_mask);
459 pbvh.update_visibility(ob);
460}
461
463
464/* -------------------------------------------------------------------- */
468
469static void partialvis_all_update_mesh(const Depsgraph &depsgraph,
470 Object &object,
471 const VisAction action,
472 const IndexMask &node_mask)
473{
474 Mesh &mesh = *id_cast<Mesh *>(object.data);
475 bke::MutableAttributeAccessor attributes = mesh.attributes_for_write();
476 if (action == VisAction::Show && !attributes.contains(".hide_vert")) {
477 /* If everything is already visible, don't do anything. */
478 return;
479 }
480
481 switch (action) {
482 case VisAction::Hide:
484 depsgraph, object, node_mask, [&](const Span<int> /*verts*/, MutableSpan<bool> hide) {
485 hide.fill(true);
486 });
487 break;
488 case VisAction::Show:
489 mesh_show_all(depsgraph, object, node_mask);
490 break;
491 }
492}
493
494static void partialvis_all_update_grids(Depsgraph &depsgraph,
495 Object &object,
496 const VisAction action,
497 const IndexMask &node_mask)
498{
499 switch (action) {
500 case VisAction::Hide:
501 grid_hide_update(depsgraph,
502 object,
503 node_mask,
504 [&](const int /*verts*/, MutableBoundedBitSpan hide) { hide.fill(true); });
505 break;
506 case VisAction::Show:
507 grids_show_all(depsgraph, object, node_mask);
508 break;
509 }
510}
511
512static void partialvis_all_update_bmesh(const Depsgraph &depsgraph,
513 Object &ob,
514 const VisAction action,
515 const IndexMask &node_mask)
516{
518 depsgraph, ob, node_mask, action, [](const BMVert * /*vert*/) { return true; });
519}
520
522{
523 const Scene &scene = *CTX_data_scene(C);
525 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
526
527 const VisAction action = VisAction(RNA_enum_get(op->ptr, "action"));
528
530
531 /* Start undo. */
532 switch (action) {
533 case VisAction::Hide:
534 undo::push_begin_ex(scene, ob, "Hide area");
535 break;
536 case VisAction::Show:
537 undo::push_begin_ex(scene, ob, "Show area");
538 break;
539 }
540
541 IndexMaskMemory memory;
542 const IndexMask node_mask = bke::pbvh::all_leaf_nodes(pbvh, memory);
543
544 switch (pbvh.type()) {
546 partialvis_all_update_mesh(*depsgraph, ob, action, node_mask);
547 break;
549 partialvis_all_update_grids(*depsgraph, ob, action, node_mask);
550 break;
552 partialvis_all_update_bmesh(*depsgraph, ob, action, node_mask);
553 break;
554 }
555
556 /* End undo. */
557 undo::push_end(ob);
558
561
562 return OPERATOR_FINISHED;
563}
564
565static void partialvis_masked_update_mesh(const Depsgraph &depsgraph,
566 Object &object,
567 const VisAction action,
568 const IndexMask &node_mask)
569{
570 Mesh &mesh = *id_cast<Mesh *>(object.data);
571 bke::MutableAttributeAccessor attributes = mesh.attributes_for_write();
572 if (action == VisAction::Show && !attributes.contains(".hide_vert")) {
573 /* If everything is already visible, don't do anything. */
574 return;
575 }
576
577 const bool value = action_to_hide(action);
578 const VArraySpan<float> mask = *attributes.lookup<float>(".sculpt_mask", bke::AttrDomain::Point);
579 if (action == VisAction::Show && mask.is_empty()) {
580 mesh_show_all(depsgraph, object, node_mask);
581 }
582 else if (!mask.is_empty()) {
584 depsgraph, object, node_mask, [&](const Span<int> verts, MutableSpan<bool> hide) {
585 for (const int i : verts.index_range()) {
586 if (mask[verts[i]] > 0.5f) {
587 hide[i] = value;
588 }
589 }
590 });
591 }
592}
593
594static void partialvis_masked_update_grids(Depsgraph &depsgraph,
595 Object &object,
596 const VisAction action,
597 const IndexMask &node_mask)
598{
599 SubdivCCG &subdiv_ccg = *object.runtime->sculpt_session->subdiv_ccg;
600
601 const bool value = action_to_hide(action);
602 const CCGKey key = BKE_subdiv_ccg_key_top_level(subdiv_ccg);
603 const Span<float> masks = subdiv_ccg.masks;
604 if (masks.is_empty()) {
605 grid_hide_update(depsgraph,
606 object,
607 node_mask,
608 [&](const int /*verts*/, MutableBoundedBitSpan hide) { hide.fill(value); });
609 }
610 else {
612 depsgraph, object, node_mask, [&](const int grid, MutableBoundedBitSpan hide) {
613 const Span<float> grid_masks = masks.slice(bke::ccg::grid_range(key, grid));
614 for (const int i : grid_masks.index_range()) {
615 if (grid_masks[i] > 0.5f) {
616 hide[i].set(value);
617 }
618 }
619 });
620 }
621}
622
623static void partialvis_masked_update_bmesh(const Depsgraph &depsgraph,
624 Object &ob,
625 const VisAction action,
626 const IndexMask &node_mask)
627{
629 const int mask_offset = CustomData_get_offset_named(&bm->vdata, CD_PROP_FLOAT, ".sculpt_mask");
630 const auto mask_test_fn = [&](const BMVert *v) {
631 const float vmask = BM_ELEM_CD_GET_FLOAT(v, mask_offset);
632 return vmask > 0.5f;
633 };
634
635 partialvis_update_bmesh_nodes(depsgraph, ob, node_mask, action, mask_test_fn);
636}
637
639{
640 const Scene &scene = *CTX_data_scene(C);
642 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
643
644 const VisAction action = VisAction(RNA_enum_get(op->ptr, "action"));
645
647
648 /* Start undo. */
649 switch (action) {
650 case VisAction::Hide:
651 undo::push_begin_ex(scene, ob, "Hide area");
652 break;
653 case VisAction::Show:
654 undo::push_begin_ex(scene, ob, "Show area");
655 break;
656 }
657
658 IndexMaskMemory memory;
659 const IndexMask node_mask = bke::pbvh::all_leaf_nodes(pbvh, memory);
660
661 switch (pbvh.type()) {
663 partialvis_masked_update_mesh(*depsgraph, ob, action, node_mask);
664 break;
666 partialvis_masked_update_grids(*depsgraph, ob, action, node_mask);
667 break;
669 partialvis_masked_update_bmesh(*depsgraph, ob, action, node_mask);
670 break;
671 }
672
673 /* End undo. */
674 undo::push_end(ob);
675
678
679 return OPERATOR_FINISHED;
680}
681
683{
684 static const EnumPropertyItem action_items[] = {
685 {int(VisAction::Hide), "HIDE", 0, "Hide", "Hide vertices"},
686 {int(VisAction::Show), "SHOW", 0, "Show", "Show vertices"},
687 {0, nullptr, 0, nullptr, nullptr},
688 };
689
690 RNA_def_enum(ot->srna,
691 "action",
692 action_items,
693 int(VisAction::Hide),
694 "Visibility Action",
695 "Whether to hide or show vertices");
696}
697
699{
700 ot->name = "Hide/Show Masked";
701 ot->idname = "PAINT_OT_hide_show_masked";
702 ot->description = "Hide/show all masked vertices above a threshold";
703
705 /* Sculpt-only for now. */
707
708 ot->flag = OPTYPE_REGISTER;
709
711}
712
714{
715 ot->name = "Hide/Show All";
716 ot->idname = "PAINT_OT_hide_show_all";
717 ot->description = "Hide/show all vertices";
718
720 /* Sculpt-only for now. */
722
723 ot->flag = OPTYPE_REGISTER;
724
726}
727
728static void invert_visibility_mesh(const Depsgraph &depsgraph,
729 Object &object,
730 const IndexMask &node_mask)
731{
734
735 Mesh &mesh = *id_cast<Mesh *>(object.data);
736 bke::MutableAttributeAccessor attributes = mesh.attributes_for_write();
738 ".hide_poly", bke::AttrDomain::Face);
739
740 undo::push_nodes(depsgraph, object, node_mask, undo::Type::HideFace);
741
742 node_mask.foreach_index(
743 [&](const int i) {
744 for (const int face : nodes[i].faces()) {
745 hide_poly.span[face] = !hide_poly.span[face];
746 }
747 },
749
750 hide_poly.finish();
752 pbvh.tag_visibility_changed(node_mask);
753 pbvh.update_visibility(object);
754}
755
756static void invert_visibility_grids(Depsgraph &depsgraph,
757 Object &object,
758 const IndexMask &node_mask)
759{
762 SubdivCCG &subdiv_ccg = *object.runtime->sculpt_session->subdiv_ccg;
763
764 undo::push_nodes(depsgraph, object, node_mask, undo::Type::HideVert);
765
766 BitGroupVector<> &grid_hidden = BKE_subdiv_ccg_grid_hidden_ensure(subdiv_ccg);
767 node_mask.foreach_index(
768 [&](const int i) {
769 for (const int i : nodes[i].grids()) {
770 bits::invert(grid_hidden[i]);
771 }
773 },
775
776 pbvh.tag_visibility_changed(node_mask);
779}
780
781static void invert_visibility_bmesh(const Depsgraph &depsgraph,
782 Object &object,
783 const IndexMask &node_mask)
784{
787 undo::push_nodes(depsgraph, object, node_mask, undo::Type::HideVert);
788
789 node_mask.foreach_index(
790 [&](const int i) {
791 bool fully_hidden = true;
794 fully_hidden &= BM_elem_flag_test_bool(vert, BM_ELEM_HIDDEN);
795 }
796 BKE_pbvh_node_fully_hidden_set(nodes[i], fully_hidden);
797 },
799 node_mask.foreach_index(
802 pbvh.tag_visibility_changed(node_mask);
803}
804
806{
807 const Scene &scene = *CTX_data_scene(C);
808 Object &object = *CTX_data_active_object(C);
809 Depsgraph &depsgraph = *CTX_data_ensure_evaluated_depsgraph(C);
810
811 bke::pbvh::Tree &pbvh = bke::object::pbvh_ensure(depsgraph, object);
812
813 IndexMaskMemory memory;
814 const IndexMask node_mask = bke::pbvh::all_leaf_nodes(pbvh, memory);
815 undo::push_begin(scene, object, op);
816 switch (pbvh.type()) {
818 invert_visibility_mesh(depsgraph, object, node_mask);
819 break;
821 invert_visibility_grids(depsgraph, object, node_mask);
822 break;
824 invert_visibility_bmesh(depsgraph, object, node_mask);
825 break;
826 }
827
828 undo::push_end(object);
829
830 islands::invalidate(*object.runtime->sculpt_session);
832
833 return OPERATOR_FINISHED;
834}
835
837{
838 ot->name = "Invert Visibility";
839 ot->idname = "PAINT_OT_visibility_invert";
840 ot->description = "Invert the visibility of all vertices";
841
844
845 ot->flag = OPTYPE_REGISTER;
846}
847
848/* Number of vertices per iteration step size when growing or shrinking visibility. */
849static constexpr float VERTEX_ITERATION_THRESHOLD = 50000.0f;
850
851/* Extracting the loop and comparing against / writing with a constant `false` or `true` instead of
852 * using #action_to_hide results in a nearly 600ms speedup on a mesh with 1.5m verts. */
853template<bool value>
854static void affect_visibility_mesh(const IndexRange face,
855 const Span<int> corner_verts,
856 const Span<bool> read_buffer,
857 MutableSpan<bool> write_buffer)
858{
859 for (const int corner : face) {
860 int vert = corner_verts[corner];
861 if (read_buffer[vert] != value) {
862 continue;
863 }
864
865 const int prev = bke::mesh::face_corner_prev(face, corner);
866 const int prev_vert = corner_verts[prev];
867 write_buffer[prev_vert] = value;
868
869 const int next = bke::mesh::face_corner_next(face, corner);
870 const int next_vert = corner_verts[next];
871 write_buffer[next_vert] = value;
872 }
873}
874
878
880 {
881 return count % 2 == 0 ? back.as_mutable_span() : front.as_mutable_span();
882 }
883
885 {
886 return count % 2 == 0 ? front.as_span() : back.as_span();
887 }
888};
889
891 DualBuffer &buffers,
892 const VArraySpan<bool> &hide_poly,
893 const VisAction action,
894 const int iterations)
895{
896 const OffsetIndices faces = mesh.faces();
897 const Span<int> corner_verts = mesh.corner_verts();
898
899 for (const int i : IndexRange(iterations)) {
900 Span<bool> read_buffer = buffers.read_buffer(i);
901 MutableSpan<bool> write_buffer = buffers.write_buffer(i);
902 threading::parallel_for(faces.index_range(), 1024, [&](const IndexRange range) {
903 for (const int face_index : range) {
904 if (!hide_poly[face_index]) {
905 continue;
906 }
907 const IndexRange face = faces[face_index];
908 if (action == VisAction::Hide) {
909 affect_visibility_mesh<true>(face, corner_verts, read_buffer, write_buffer);
910 }
911 else {
912 affect_visibility_mesh<false>(face, corner_verts, read_buffer, write_buffer);
913 }
914 }
915 });
916
917 flush_face_changes(mesh, write_buffer);
918 }
919}
920
921static void update_undo_state(const Depsgraph &depsgraph,
922 Object &object,
923 const IndexMask &node_mask,
924 const Span<bool> old_hide_vert,
925 const Span<bool> new_hide_vert)
926{
929
930 node_mask.foreach_index(
931 [&](const int i) {
932 for (const int vert : nodes[i].verts()) {
933 if (old_hide_vert[vert] != new_hide_vert[vert]) {
934 undo::push_node(depsgraph, object, &nodes[i], undo::Type::HideVert);
935 break;
936 }
937 }
938 },
940}
941
943 const IndexMask &node_mask,
944 const Span<bool> orig_hide_poly,
945 const Span<bool> new_hide_poly,
946 const Span<bool> hide_vert)
947{
949 Array<bool> node_changed(node_mask.min_array_size(), false);
950
951 node_mask.foreach_index(
952 [&](const int i) {
953 bool any_changed = false;
954 const Span<int> indices = nodes[i].faces();
955 for (const int face_index : indices) {
956 if (orig_hide_poly[face_index] != new_hide_poly[face_index]) {
957 any_changed = true;
958 break;
959 }
960 }
961
962 if (any_changed) {
963 node_changed[i] = true;
965 }
966 },
968
969 IndexMaskMemory memory;
970 const IndexMask changed_nodes = IndexMask::from_bools(node_changed, memory);
971 if (pbvh.draw_data) {
972 /* Only tag draw data. Nodes have already been updated above. */
973 pbvh.draw_data->tag_visibility_changed(changed_nodes);
974 }
975}
976
977static void grow_shrink_visibility_mesh(const Depsgraph &depsgraph,
978 Object &object,
979 const IndexMask &node_mask,
980 const VisAction action,
981 const int iterations)
982{
983 Mesh &mesh = *id_cast<Mesh *>(object.data);
984 bke::MutableAttributeAccessor attributes = mesh.attributes_for_write();
985 if (!attributes.contains(".hide_vert")) {
986 /* If the entire mesh is visible, we can neither grow nor shrink the boundary. */
987 return;
988 }
989
991 ".hide_vert", bke::AttrDomain::Point);
992 const VArraySpan hide_poly = *attributes.lookup_or_default<bool>(
993 ".hide_poly", bke::AttrDomain::Face, false);
994
995 DualBuffer buffers;
996 buffers.back.reinitialize(hide_vert.span.size());
997 buffers.front.reinitialize(hide_vert.span.size());
998 array_utils::copy(hide_vert.span.as_span(), buffers.back.as_mutable_span());
999 array_utils::copy(hide_vert.span.as_span(), buffers.front.as_mutable_span());
1000
1001 Array<bool> orig_hide_poly(hide_poly);
1002 propagate_vertex_visibility(mesh, buffers, hide_poly, action, iterations);
1003
1004 const Span<bool> last_buffer = buffers.write_buffer(iterations - 1);
1005
1006 update_undo_state(depsgraph, object, node_mask, hide_vert.span, last_buffer);
1007
1008 /* We can wait until after all iterations are done to flush edge changes as they are
1009 * not used for coarse filtering while iterating. */
1010 flush_edge_changes(mesh, last_buffer);
1011
1013 *bke::object::pbvh_get(object), node_mask, orig_hide_poly, hide_poly, last_buffer);
1014 array_utils::copy(last_buffer, hide_vert.span);
1015 hide_vert.finish();
1016}
1017
1021
1023 {
1024 return count % 2 == 0 ? back : front;
1025 }
1026
1028 {
1029 return count % 2 == 0 ? front : back;
1030 }
1031};
1032
1033static void grow_shrink_visibility_grid(Depsgraph &depsgraph,
1034 Object &object,
1035 const IndexMask &node_mask,
1036 const VisAction action,
1037 const int iterations)
1038{
1039 SculptSession &ss = *object.runtime->sculpt_session;
1042
1043 SubdivCCG &subdiv_ccg = *ss.subdiv_ccg;
1044
1045 BitGroupVector<> &grid_hidden = BKE_subdiv_ccg_grid_hidden_ensure(subdiv_ccg);
1046
1047 const bool desired_state = action_to_hide(action);
1048 const CCGKey key = BKE_subdiv_ccg_key_top_level(subdiv_ccg);
1049
1050 DualBitBuffer buffers;
1051 buffers.front = grid_hidden;
1052 buffers.back = grid_hidden;
1053
1054 Array<bool> node_changed(nodes.size(), false);
1055
1056 for (const int i : IndexRange(iterations)) {
1057 BitGroupVector<> &read_buffer = buffers.read_buffer(i);
1058 BitGroupVector<> &write_buffer = buffers.write_buffer(i);
1059
1060 node_mask.foreach_index(
1061 [&](const int i) {
1062 for (const int grid : nodes[i].grids()) {
1063 for (const int y : IndexRange(key.grid_size)) {
1064 for (const int x : IndexRange(key.grid_size)) {
1065 const int grid_elem_idx = CCG_grid_xy_to_index(key.grid_size, x, y);
1066 if (read_buffer[grid][grid_elem_idx] != desired_state) {
1067 continue;
1068 }
1069
1070 SubdivCCGCoord coord{};
1071 coord.grid_index = grid;
1072 coord.x = x;
1073 coord.y = y;
1074
1075 SubdivCCGNeighbors neighbors;
1076 BKE_subdiv_ccg_neighbor_coords_get(subdiv_ccg, coord, true, neighbors);
1077
1078 for (const SubdivCCGCoord neighbor : neighbors.coords) {
1079 const int neighbor_grid_elem_idx = CCG_grid_xy_to_index(
1080 key.grid_size, neighbor.x, neighbor.y);
1081
1082 write_buffer[neighbor.grid_index][neighbor_grid_elem_idx].set(desired_state);
1083 }
1084 }
1085 }
1086 }
1087
1088 node_changed[i] = true;
1089 },
1091 }
1092
1093 IndexMaskMemory memory;
1094 const IndexMask changed_nodes = IndexMask::from_bools(node_changed, memory);
1095
1096 undo::push_nodes(depsgraph, object, changed_nodes, undo::Type::HideVert);
1097
1098 BitGroupVector<> &last_buffer = buffers.write_buffer(iterations - 1);
1099 grid_hidden = std::move(last_buffer);
1100
1101 pbvh.tag_visibility_changed(node_mask);
1102 pbvh.update_visibility(object);
1103
1106}
1107
1109{
1110 const SculptSession &ss = *object.runtime->sculpt_session;
1111 BMesh &bm = *ss.bm;
1113 vert_random_access_ensure(const_cast<Object &>(object));
1114 for (const int i : result.index_range()) {
1116 }
1117 return result;
1118}
1119
1120static void grow_shrink_visibility_bmesh(const Depsgraph &depsgraph,
1121 Object &object,
1122 const IndexMask &node_mask,
1123 const VisAction action,
1124 const int iterations)
1125{
1126 for (const int i : IndexRange(iterations)) {
1127 UNUSED_VARS(i);
1128 const Array<bool> prev_visibility = duplicate_visibility_bmesh(object);
1129 partialvis_update_bmesh_nodes(depsgraph, object, node_mask, action, [&](BMVert *vert) {
1130 BMeshNeighborVerts neighbors;
1131 for (BMVert *neighbor : vert_neighbors_get_bmesh(*vert, neighbors)) {
1132 if (prev_visibility[BM_elem_index_get(neighbor)] == action_to_hide(action)) {
1133 return true;
1134 }
1135 }
1136 return false;
1137 });
1138 }
1139}
1140
1142{
1143 const Scene &scene = *CTX_data_scene(C);
1144 Object &object = *CTX_data_active_object(C);
1145 Depsgraph &depsgraph = *CTX_data_ensure_evaluated_depsgraph(C);
1146
1147 bke::pbvh::Tree &pbvh = bke::object::pbvh_ensure(depsgraph, object);
1148
1149 const VisAction mode = VisAction(RNA_enum_get(op->ptr, "action"));
1150
1151 IndexMaskMemory memory;
1152 const IndexMask node_mask = bke::pbvh::all_leaf_nodes(pbvh, memory);
1153
1154 int num_verts = vertex_count_get(object);
1155
1156 int iterations = RNA_int_get(op->ptr, "iterations");
1157
1158 if (RNA_boolean_get(op->ptr, "auto_iteration_count")) {
1159 /* Automatically adjust the number of iterations based on the number
1160 * of vertices in the mesh. */
1161 iterations = int(num_verts / VERTEX_ITERATION_THRESHOLD) + 1;
1162 }
1163
1164 undo::push_begin(scene, object, op);
1165 switch (pbvh.type()) {
1167 grow_shrink_visibility_mesh(depsgraph, object, node_mask, mode, iterations);
1168 break;
1170 grow_shrink_visibility_grid(depsgraph, object, node_mask, mode, iterations);
1171 break;
1173 grow_shrink_visibility_bmesh(depsgraph, object, node_mask, mode, iterations);
1174 break;
1175 }
1176 undo::push_end(object);
1177
1178 islands::invalidate(*object.runtime->sculpt_session);
1180
1181 return OPERATOR_FINISHED;
1182}
1183
1185{
1186 static EnumPropertyItem actions[] = {
1187 {int(VisAction::Show),
1188 "GROW",
1189 0,
1190 "Grow Visibility",
1191 "Grow the visibility by one face based on mesh topology"},
1192 {int(VisAction::Hide),
1193 "SHRINK",
1194 0,
1195 "Shrink Visibility",
1196 "Shrink the visibility by one face based on mesh topology"},
1197 {0, nullptr, 0, nullptr, nullptr},
1198 };
1199
1200 ot->name = "Visibility Filter";
1201 ot->idname = "PAINT_OT_visibility_filter";
1202 ot->description = "Edit the visibility of the current mesh";
1203
1206
1208
1209 RNA_def_enum(ot->srna, "action", actions, int(VisAction::Show), "Action", "");
1210
1211 RNA_def_int(ot->srna,
1212 "iterations",
1213 1,
1214 1,
1215 100,
1216 "Iterations",
1217 "Number of times that the filter is going to be applied",
1218 1,
1219 100);
1221 ot->srna,
1222 "auto_iteration_count",
1223 true,
1224 "Auto Iteration Count",
1225 "Use an automatic number of iterations based on the number of vertices of the sculpt");
1226}
1227
1229
1230/* -------------------------------------------------------------------- */
1234
1240
1242{
1243 HideShowOperation *operation = reinterpret_cast<HideShowOperation *>(gesture_data.operation);
1244 Object *object = gesture_data.vc.obact;
1245 const Depsgraph &depsgraph = *gesture_data.vc.depsgraph;
1246 const VisAction action = operation->action;
1247 const IndexMask &node_mask = gesture_data.node_mask;
1248
1249 Mesh *mesh = id_cast<Mesh *>(object->data);
1250 bke::MutableAttributeAccessor attributes = mesh->attributes_for_write();
1251 if (action == VisAction::Show && !attributes.contains(".hide_vert")) {
1252 /* If everything is already visible, don't do anything. */
1253 return;
1254 }
1255
1256 const View3D *v3d = gesture_data.vc.v3d;
1257 RegionView3D *rv3d = gesture_data.vc.rv3d;
1258 const bool clipping_enabled = RV3D_CLIPPING_ENABLED(v3d, rv3d);
1259 if (clipping_enabled) {
1260 ED_view3d_clipping_local(rv3d, object->object_to_world().ptr());
1261 }
1262 const bool value = action_to_hide(action);
1263 const Span<float3> positions = bke::pbvh::vert_positions_eval(depsgraph, *object);
1264 const Span<float3> normals = bke::pbvh::vert_normals_eval(depsgraph, *object);
1266 depsgraph, *object, node_mask, [&](const Span<int> verts, MutableSpan<bool> hide) {
1267 for (const int i : verts.index_range()) {
1268 if (clipping_enabled && ED_view3d_clipping_test(rv3d, positions[verts[i]], true)) {
1269 continue;
1270 }
1271 if (gesture::is_affected(gesture_data, positions[verts[i]], normals[verts[i]])) {
1272 hide[i] = value;
1273 }
1274 }
1275 });
1276}
1277
1278static void partialvis_gesture_update_grids(Depsgraph &depsgraph,
1279 gesture::GestureData &gesture_data)
1280{
1281 HideShowOperation *operation = reinterpret_cast<HideShowOperation *>(gesture_data.operation);
1282 Object *object = gesture_data.vc.obact;
1283 const VisAction action = operation->action;
1284 const IndexMask &node_mask = gesture_data.node_mask;
1285
1286 SubdivCCG &subdiv_ccg = *object->runtime->sculpt_session->subdiv_ccg;
1287
1288 const View3D *v3d = gesture_data.vc.v3d;
1289 RegionView3D *rv3d = gesture_data.vc.rv3d;
1290 const bool clipping_enabled = RV3D_CLIPPING_ENABLED(v3d, rv3d);
1291 if (clipping_enabled) {
1292 ED_view3d_clipping_local(rv3d, object->object_to_world().ptr());
1293 }
1294
1295 const bool value = action_to_hide(action);
1296 const CCGKey key = BKE_subdiv_ccg_key_top_level(subdiv_ccg);
1297 const Span<float3> positions = subdiv_ccg.positions;
1298 const Span<float3> normals = subdiv_ccg.normals;
1299 grid_hide_update(depsgraph, *object, node_mask, [&](const int grid, MutableBoundedBitSpan hide) {
1300 const Span<float3> grid_positions = positions.slice(bke::ccg::grid_range(key, grid));
1301 const Span<float3> grid_normals = normals.slice(bke::ccg::grid_range(key, grid));
1302 for (const int i : grid_positions.index_range()) {
1303 if (clipping_enabled && ED_view3d_clipping_test(rv3d, grid_positions[i], true)) {
1304 continue;
1305 }
1306 if (gesture::is_affected(gesture_data, grid_positions[i], grid_normals[i])) {
1307 hide[i].set(value);
1308 }
1309 }
1310 });
1311}
1312
1314{
1315 const View3D *v3d = gesture_data.vc.v3d;
1316 RegionView3D *rv3d = gesture_data.vc.rv3d;
1317 Object *object = gesture_data.vc.obact;
1318
1319 const bool clipping_enabled = RV3D_CLIPPING_ENABLED(v3d, rv3d);
1320 if (clipping_enabled) {
1321 ED_view3d_clipping_local(rv3d, object->object_to_world().ptr());
1322 }
1323
1324 const auto selection_test_fn = [&](const BMVert *v) {
1325 if (clipping_enabled && ED_view3d_clipping_test(rv3d, v->co, true)) {
1326 return false;
1327 }
1328 return gesture::is_affected(gesture_data, v->co, v->no);
1329 };
1330
1331 HideShowOperation *operation = reinterpret_cast<HideShowOperation *>(gesture_data.operation);
1332
1334 *gesture_data.vc.obact,
1335 gesture_data.node_mask,
1336 operation->action,
1337 selection_test_fn);
1338}
1339
1340static void hide_show_begin(bContext &C, wmOperator &op, gesture::GestureData & /*gesture_data*/)
1341{
1342 const Scene &scene = *CTX_data_scene(&C);
1344 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(&C);
1345
1346 undo::push_begin(scene, *ob, &op);
1347 bke::object::pbvh_ensure(*depsgraph, *ob);
1348}
1349
1351{
1352 Depsgraph *depsgraph = CTX_data_depsgraph_pointer(&C);
1353
1354 switch (bke::object::pbvh_get(*gesture_data.vc.obact)->type()) {
1356 partialvis_gesture_update_mesh(gesture_data);
1357 break;
1359 partialvis_gesture_update_grids(*depsgraph, gesture_data);
1360 break;
1362 partialvis_gesture_update_bmesh(gesture_data);
1363 break;
1364 }
1365}
1366static void hide_show_end(bContext &C, gesture::GestureData &gesture_data)
1367{
1370 undo::push_end(*gesture_data.vc.obact);
1371}
1372
1374 gesture::GestureData &gesture_data,
1375 wmOperator &op)
1376{
1377 gesture_data.operation = reinterpret_cast<gesture::Operation *>(
1379
1380 HideShowOperation *operation = reinterpret_cast<HideShowOperation *>(gesture_data.operation);
1381
1382 operation->op.begin = hide_show_begin;
1384 operation->op.end = hide_show_end;
1385
1386 operation->action = VisAction(RNA_enum_get(op.ptr, "action"));
1387 gesture_data.selection_type = gesture::SelectionType(RNA_enum_get(op.ptr, "area"));
1388}
1389
1391{
1392 std::unique_ptr<gesture::GestureData> gesture_data = gesture::init_from_box(C, op);
1393 if (!gesture_data) {
1394 return OPERATOR_CANCELLED;
1395 }
1396 hide_show_init_properties(*C, *gesture_data, *op);
1397 gesture::apply(*C, *gesture_data, *op);
1398 return OPERATOR_FINISHED;
1399}
1400
1402{
1403 std::unique_ptr<gesture::GestureData> gesture_data = gesture::init_from_lasso(C, op);
1404 if (!gesture_data) {
1405 return OPERATOR_CANCELLED;
1406 }
1407 hide_show_init_properties(*C, *gesture_data, *op);
1408 gesture::apply(*C, *gesture_data, *op);
1409 return OPERATOR_FINISHED;
1410}
1411
1413{
1414 std::unique_ptr<gesture::GestureData> gesture_data = gesture::init_from_line(C, op);
1415 if (!gesture_data) {
1416 return OPERATOR_CANCELLED;
1417 }
1418 hide_show_init_properties(*C, *gesture_data, *op);
1419 gesture::apply(*C, *gesture_data, *op);
1420 return OPERATOR_FINISHED;
1421}
1422
1424{
1425 std::unique_ptr<gesture::GestureData> gesture_data = gesture::init_from_polyline(C, op);
1426 if (!gesture_data) {
1427 return OPERATOR_CANCELLED;
1428 }
1429 hide_show_init_properties(*C, *gesture_data, *op);
1430 gesture::apply(*C, *gesture_data, *op);
1431 return OPERATOR_FINISHED;
1432}
1433
1435{
1436 static const EnumPropertyItem area_items[] = {
1437 {int(gesture::SelectionType::Outside),
1438 "OUTSIDE",
1439 0,
1440 "Outside",
1441 "Hide or show vertices outside the selection"},
1442 {int(gesture::SelectionType::Inside),
1443 "Inside",
1444 0,
1445 "Inside",
1446 "Hide or show vertices inside the selection"},
1447 {0, nullptr, 0, nullptr, nullptr},
1448 };
1449
1450 RNA_def_enum(ot->srna,
1451 "area",
1452 area_items,
1453 int(gesture::SelectionType::Inside),
1454 "Visibility Area",
1455 "Which vertices to hide or show");
1456}
1457
1459{
1460 ot->name = "Hide/Show";
1461 ot->idname = "PAINT_OT_hide_show";
1462 ot->description = "Hide/show some vertices";
1463
1467 /* Sculpt-only for now. */
1469
1470 ot->flag = OPTYPE_REGISTER;
1471
1476}
1477
1479{
1480 ot->name = "Hide/Show Lasso";
1481 ot->idname = "PAINT_OT_hide_show_lasso_gesture";
1482 ot->description = "Hide/show some vertices";
1483
1487 /* Sculpt-only for now. */
1489
1491
1496}
1497
1499{
1500 ot->name = "Hide/Show Line";
1501 ot->idname = "PAINT_OT_hide_show_line_gesture";
1502 ot->description = "Hide/show some vertices";
1503
1507 /* Sculpt-only for now. */
1509
1510 ot->flag = OPTYPE_REGISTER;
1511
1516}
1517
1519{
1520 ot->name = "Hide/Show Polyline";
1521 ot->idname = "PAINT_OT_hide_show_polyline_gesture";
1522 ot->description = "Hide/show some vertices";
1523
1527 /* Sculpt-only for now. */
1529
1531
1536}
1537
1539
1540} // namespace blender::ed::sculpt_paint::hide
A BVH for high poly meshes.
Object is a sort of wrapper for general info.
#define RV3D_CLIPPING_ENABLED(v3d, rv3d)
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define ND_DRAW
Definition WM_types.hh:502
#define NC_OBJECT
Definition WM_types.hh:392
#define UNUSED_VARS(...)
#define BM_ELEM_CD_GET_FLOAT(ele, offset)
#define BM_elem_index_get(ele)
#define BM_elem_flag_disable(ele, hflag)
#define BM_elem_flag_toggle(ele, hflag)
#define BM_elem_flag_test(ele, hflag)
#define BM_elem_flag_test_bool(ele, hflag)
#define BM_elem_flag_enable(ele, hflag)
#define BM_ITER_MESH(ele, iter, bm, itype)
Span< T > as_span() const
Definition BLI_array.hh:254
MutableSpan< T > as_mutable_span()
Definition BLI_array.hh:259
void reinitialize(const int64_t new_size)
Definition BLI_array.hh:430
static IndexMask from_predicate(const IndexMask &universe, LinearAllocator<> &memory, Fn &&predicate, exec_mode::Mode mode=exec_mode::parallel)
static IndexMask from_bools(Span< bool > bools, LinearAllocator<> &memory)
constexpr Iterator end() const
constexpr IndexRange()=default
constexpr Iterator begin() const
constexpr Span slice(int64_t start, int64_t size) const
Definition BLI_span.hh:141
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr const T * end() const
Definition BLI_span.hh:228
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
constexpr const T * begin() const
Definition BLI_span.hh:224
constexpr bool is_empty() const
Definition BLI_span.hh:264
void resize(const int64_t new_size)
MutableSpan< T > as_mutable_span()
Span< T > as_span() const
GAttributeReader lookup_or_default(StringRef name, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
bool contains(StringRef name) const
GAttributeReader lookup(const StringRef name) const
GSpanAttributeWriter lookup_or_add_for_write_span(StringRef name, AttrDomain domain, AttrType data_type, const AttributeInit &initializer=AttributeInitDefaultValue())
GSpanAttributeWriter lookup_or_add_for_write_only_span(StringRef name, AttrDomain domain, AttrType data_type)
constexpr bool is_empty() const
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
void copy(const GVArray &src, GMutableSpan dst, exec_mode::Mode mode=exec_mode::parallel)
bool indexed_data_equal(const Span< T > all_values, const Span< int > indices, const Span< T > values)
void invert(BitSpanT &&data)
IndexRange grid_range(const int grid_area, const int grid)
int face_corner_prev(const IndexRange face, const int corner)
Definition BKE_mesh.hh:306
int face_corner_next(const IndexRange face, const int corner)
Definition BKE_mesh.hh:315
pbvh::Tree & pbvh_ensure(Depsgraph &depsgraph, Object &object)
pbvh::Tree * pbvh_get(Object &object)
IndexMask all_leaf_nodes(const Tree &pbvh, IndexMaskMemory &memory)
Definition pbvh.cc:2522
void node_update_visibility_grids(const BitGroupVector<> &grid_hidden, GridsNode &node)
Definition pbvh.cc:1461
Span< float3 > vert_normals_eval(const Depsgraph &depsgraph, const Object &object_orig)
Definition pbvh.cc:952
Span< float3 > vert_positions_eval(const Depsgraph &depsgraph, const Object &object_orig)
Definition pbvh.cc:933
void node_update_visibility_mesh(Span< bool > hide_vert, MeshNode &node)
Definition pbvh.cc:1437
void mesh_face_hide_from_vert(OffsetIndices< int > faces, Span< int > corner_verts, Span< bool > hide_vert, MutableSpan< bool > hide_poly)
void mesh_hide_vert_flush(Mesh &mesh)
void mesh_hide_face_flush(Mesh &mesh)
void mesh_edge_hide_from_vert(Span< int2 > edges, Span< bool > hide_vert, MutableSpan< bool > hide_edge)
std::unique_ptr< GestureData > init_from_box(bContext *C, wmOperator *op)
void operator_properties(wmOperatorType *ot, ShapeType shapeType)
std::unique_ptr< GestureData > init_from_polyline(bContext *C, wmOperator *op)
std::unique_ptr< GestureData > init_from_line(bContext *C, const wmOperator *op)
void apply(bContext &C, GestureData &gesture_data, wmOperator &op)
std::unique_ptr< GestureData > init_from_lasso(bContext *C, wmOperator *op)
bool is_affected(const GestureData &gesture_data, const float3 &position, const float3 &normal)
static void invert_visibility_bmesh(const Depsgraph &depsgraph, Object &object, const IndexMask &node_mask)
static constexpr float VERTEX_ITERATION_THRESHOLD
static Array< bool > duplicate_visibility_bmesh(const Object &object)
static void flush_face_changes(Mesh &mesh, const Span< bool > hide_vert)
void PAINT_OT_hide_show_polyline_gesture(wmOperatorType *ot)
static void grow_shrink_visibility_bmesh(const Depsgraph &depsgraph, Object &object, const IndexMask &node_mask, const VisAction action, const int iterations)
static void partialvis_all_update_grids(Depsgraph &depsgraph, Object &object, const VisAction action, const IndexMask &node_mask)
static void partialvis_all_update_bmesh(const Depsgraph &depsgraph, Object &ob, const VisAction action, const IndexMask &node_mask)
void PAINT_OT_hide_show_masked(wmOperatorType *ot)
static void invert_visibility_mesh(const Depsgraph &depsgraph, Object &object, const IndexMask &node_mask)
void PAINT_OT_hide_show_line_gesture(wmOperatorType *ot)
static void grid_hide_update(Depsgraph &depsgraph, Object &object, const IndexMask &node_mask, const FunctionRef< void(const int, MutableBoundedBitSpan)> calc_hide)
void tag_update_visibility(const bContext &C)
static wmOperatorStatus hide_show_gesture_line_exec(bContext *C, wmOperator *op)
static void hide_show_end(bContext &C, gesture::GestureData &gesture_data)
static void affect_visibility_mesh(const IndexRange face, const Span< int > corner_verts, const Span< bool > read_buffer, MutableSpan< bool > write_buffer)
static void propagate_vertex_visibility(Mesh &mesh, DualBuffer &buffers, const VArraySpan< bool > &hide_poly, const VisAction action, const int iterations)
static void partialvis_gesture_update_bmesh(gesture::GestureData &gesture_data)
static void partialvis_gesture_update_grids(Depsgraph &depsgraph, gesture::GestureData &gesture_data)
static wmOperatorStatus hide_show_all_exec(bContext *C, wmOperator *op)
static void vert_hide_update(const Depsgraph &depsgraph, Object &object, const IndexMask &node_mask, const FunctionRef< void(Span< int >, MutableSpan< bool >)> calc_hide)
void PAINT_OT_visibility_invert(wmOperatorType *ot)
static wmOperatorStatus visibility_invert_exec(bContext *C, wmOperator *op)
static void calc_face_hide(const Span< int > node_faces, const OffsetIndices< int > faces, const Span< int > corner_verts, const Span< bool > hide_vert, MutableSpan< bool > hide_face)
static void hide_show_apply_for_symmetry_pass(bContext &C, gesture::GestureData &gesture_data)
void PAINT_OT_hide_show_lasso_gesture(wmOperatorType *ot)
void PAINT_OT_visibility_filter(wmOperatorType *ot)
static wmOperatorStatus hide_show_gesture_lasso_exec(bContext *C, wmOperator *op)
void grids_show_all(Depsgraph &depsgraph, Object &object, const IndexMask &node_mask)
static void partialvis_masked_update_grids(Depsgraph &depsgraph, Object &object, const VisAction action, const IndexMask &node_mask)
static void partialvis_masked_update_bmesh(const Depsgraph &depsgraph, Object &ob, const VisAction action, const IndexMask &node_mask)
static void grow_shrink_visibility_grid(Depsgraph &depsgraph, Object &object, const IndexMask &node_mask, const VisAction action, const int iterations)
static void partialvis_update_bmesh_nodes(const Depsgraph &depsgraph, Object &ob, const IndexMask &node_mask, const VisAction action, const FunctionRef< bool(BMVert *v)> vert_test_fn)
static wmOperatorStatus hide_show_masked_exec(bContext *C, wmOperator *op)
static void hide_show_init_properties(bContext &, gesture::GestureData &gesture_data, wmOperator &op)
static void partialvis_update_bmesh_faces(const Set< BMFace *, 0 > &faces)
static void update_node_visibility_from_face_changes(bke::pbvh::Tree &pbvh, const IndexMask &node_mask, const Span< bool > orig_hide_poly, const Span< bool > new_hide_poly, const Span< bool > hide_vert)
void mesh_show_all(const Depsgraph &depsgraph, Object &object, const IndexMask &node_mask)
void PAINT_OT_hide_show_all(wmOperatorType *ot)
static void invert_visibility_grids(Depsgraph &depsgraph, Object &object, const IndexMask &node_mask)
static void partialvis_all_update_mesh(const Depsgraph &depsgraph, Object &object, const VisAction action, const IndexMask &node_mask)
void sync_all_from_faces(Object &object)
Definition paint_hide.cc:56
static void flush_edge_changes(Mesh &mesh, const Span< bool > hide_vert)
static void grow_shrink_visibility_mesh(const Depsgraph &depsgraph, Object &object, const IndexMask &node_mask, const VisAction action, const int iterations)
static void hide_show_operator_gesture_properties(wmOperatorType *ot)
static wmOperatorStatus visibility_filter_exec(bContext *C, wmOperator *op)
static wmOperatorStatus hide_show_gesture_polyline_exec(bContext *C, wmOperator *op)
static void update_undo_state(const Depsgraph &depsgraph, Object &object, const IndexMask &node_mask, const Span< bool > old_hide_vert, const Span< bool > new_hide_vert)
void PAINT_OT_hide_show(wmOperatorType *ot)
static wmOperatorStatus hide_show_gesture_box_exec(bContext *C, wmOperator *op)
static void partialvis_gesture_update_mesh(gesture::GestureData &gesture_data)
static void flush_face_changes_node(Mesh &mesh, bke::pbvh::Tree &pbvh, const IndexMask &node_mask, const Span< bool > hide_vert)
static void partialvis_update_bmesh_verts(const Set< BMVert *, 0 > &verts, const VisAction action, const FunctionRef< bool(BMVert *v)> should_update, bool *any_changed, bool *any_visible)
static void partialvis_masked_update_mesh(const Depsgraph &depsgraph, Object &object, const VisAction action, const IndexMask &node_mask)
static void hide_show_begin(bContext &C, wmOperator &op, gesture::GestureData &)
static bool action_to_hide(const VisAction action)
static void hide_show_operator_properties(wmOperatorType *ot)
void invalidate(SculptSession &ss)
Definition sculpt.cc:6325
void push_nodes(const Depsgraph &depsgraph, Object &object, const IndexMask &node_mask, const Type type)
void push_begin_ex(const Scene &, Object &ob, const char *name)
void push_node(const Depsgraph &depsgraph, const Object &object, const bke::pbvh::Node *node, const Type type)
void push_begin(const Scene &scene, Object &ob, const wmOperator *op)
void vert_random_access_ensure(Object &object)
Definition sculpt.cc:154
Vector< BMVert *, 64 > BMeshNeighborVerts
int vertex_count_get(const Object &object)
Definition sculpt.cc:163
void scatter_data_mesh(Span< T > src, Span< int > indices, MutableSpan< T > dst)
bool sculpt_mode_poll_view3d(bContext *C)
Definition sculpt.cc:3806
Span< BMVert * > vert_neighbors_get_bmesh(BMVert &vert, BMeshNeighborVerts &r_neighbors)
Definition sculpt.cc:490
void gather_data_mesh(Span< T > src, Span< int > indices, MutableSpan< T > dst)
constexpr ParallelGrainSize grain_size(int grain_size)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
Definition BLI_task.hh:69
int RNA_enum_get(PointerRNA *ptr, const char *name)
wmOperatorStatus WM_gesture_polyline_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void multires_mark_as_modified(Depsgraph *depsgraph, Object *object, MultiresModifiedFlags flags)
Definition multires.cc:254
void ED_view3d_clipping_local(RegionView3D *rv3d, const float mat[4][4])
const Set< BMFace *, 0 > & BKE_pbvh_bmesh_node_faces(bke::pbvh::BMeshNode *node)
wmOperatorStatus WM_gesture_box_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void BKE_pbvh_node_fully_hidden_set(bke::pbvh::Node &node, int fully_hidden)
Definition pbvh.cc:1613
ATTR_WARN_UNUSED_RESULT const BMLoop * l
void BKE_sculpt_sync_face_visibility_to_grids(const Mesh &mesh, SubdivCCG &subdiv_ccg)
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
void WM_operator_properties_border(wmOperatorType *ot)
int RNA_int_get(PointerRNA *ptr, const char *name)
ATTR_WARN_UNUSED_RESULT const BMVert * v
wmOperatorStatus WM_gesture_straightline_active_side_invoke(bContext *C, wmOperator *op, const wmEvent *event)
wmOperatorStatus WM_gesture_lasso_modal(bContext *C, wmOperator *op, const wmEvent *event)
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:681
BitGroupVector & BKE_subdiv_ccg_grid_hidden_ensure(SubdivCCG &subdiv_ccg)
CCGKey BKE_subdiv_ccg_key_top_level(const SubdivCCG &subdiv_ccg)
void BKE_subdiv_ccg_grid_hidden_free(SubdivCCG &subdiv_ccg)
void BKE_subdiv_ccg_neighbor_coords_get(const SubdivCCG &subdiv_ccg, const SubdivCCGCoord &coord, bool include_duplicates, SubdivCCGNeighbors &r_neighbors)
void BKE_pbvh_sync_visibility_from_verts(Object &object)
Definition pbvh.cc:2441
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void DEG_id_tag_update(ID *id, unsigned int flags)
BMesh const char void * data
@ MULTIRES_HIDDEN_MODIFIED
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
int CustomData_get_offset_named(const CustomData *data, eCustomDataType type, StringRef name)
void WM_operator_properties_gesture_straightline(wmOperatorType *ot, int cursor)
const Set< BMVert *, 0 > & BKE_pbvh_bmesh_node_other_verts(bke::pbvh::BMeshNode *node)
RegionView3D * CTX_wm_region_view3d(const bContext *C)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
BLI_INLINE BMVert * BM_vert_at_index(BMesh *bm, const int index)
wmOperatorStatus WM_gesture_polyline_modal(bContext *C, wmOperator *op, const wmEvent *event)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
int CCG_grid_xy_to_index(const int grid_size, const int x, const int y)
Definition BKE_ccg.hh:75
wmOperatorStatus WM_gesture_box_modal(bContext *C, wmOperator *op, const wmEvent *event)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
bool ED_view3d_clipping_test(const RegionView3D *rv3d, const float co[3], bool is_local)
@ WM_CURSOR_EDIT
Definition wm_cursors.hh:21
bool BKE_sculptsession_use_pbvh_draw(const Object *ob, const RegionView3D *rv3d)
wmOperatorStatus WM_gesture_lasso_invoke(bContext *C, wmOperator *op, const wmEvent *event)
bool BKE_paint_is_bmesh_face_hidden(const BMFace *f)
@ ID_RECALC_SHADING
Definition DNA_ID.h:1094
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
Scene * CTX_data_scene(const bContext *C)
wmOperatorStatus WM_gesture_straightline_oneshot_modal(bContext *C, wmOperator *op, const wmEvent *event)
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
@ OPTYPE_DEPENDS_ON_CURSOR
Definition WM_types.hh:228
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void WM_operator_properties_gesture_polyline(wmOperatorType *ot)
Object * CTX_data_active_object(const bContext *C)
const Set< BMVert *, 0 > & BKE_pbvh_bmesh_node_unique_verts(bke::pbvh::BMeshNode *node)
ARegion * CTX_wm_region(const bContext *C)
void WM_operator_properties_gesture_lasso(wmOperatorType *ot)
struct BMLoop * next
struct BMEdge * e
struct BMVert * v
CustomData vdata
bke::ObjectRuntime * runtime
SubdivCCGNeighborCoords coords
Array< float3 > positions
Array< float3 > normals
Array< float > masks
RegionView3D * rv3d
Definition ED_view3d.hh:86
Depsgraph * depsgraph
Definition ED_view3d.hh:78
void(*) end(bContext &, GestureData &)
void(*) apply_for_symmetry_pass(bContext &, GestureData &)
void(*) begin(bContext &, wmOperator &, GestureData &)
MutableSpan< bool > write_buffer(int count)
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1157