Blender V5.3
sculpt_hide.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "sculpt_hide.hh"
10
11#include "BKE_paint_bvh.hh"
12#include "BKE_subdiv_ccg.hh"
13
14#include "DNA_mesh_types.h"
15
16#include "bmesh.hh"
17
19
21 const Span<bool> hide_vert,
23{
25 return {};
26 }
27 const Span<int> verts = node.verts();
28 if (hide_vert.is_empty()) {
29 return verts;
30 }
31 indices.resize(verts.size());
32 const int *end = std::copy_if(verts.begin(), verts.end(), indices.begin(), [&](const int vert) {
33 return !hide_vert[vert];
34 });
35 indices.resize(end - indices.begin());
36 return indices;
37}
38
40 const Span<bool> hide_vert,
41 Vector<int> &indices)
42{
44 return {};
45 }
46 const Span<int> verts = node.all_verts().slice(node.verts().size(),
47 node.all_verts().size() - node.verts().size());
48 if (hide_vert.is_empty()) {
49 return verts;
50 }
51 indices.resize(verts.size());
52 const int *end = std::copy_if(verts.begin(), verts.end(), indices.begin(), [&](const int vert) {
53 return !hide_vert[vert];
54 });
55 indices.resize(end - indices.begin());
56 return indices;
57}
58
60 const Span<bool> hide_vert,
61 Vector<int> &indices,
62 int &visible_unique_verts_num)
63{
65 return {};
66 }
67 const Span<int> verts = node.all_verts();
68 const int unique_verts_num = node.verts().size();
69 if (hide_vert.is_empty()) {
70 visible_unique_verts_num = unique_verts_num;
71 return verts;
72 }
73 indices.resize(verts.size());
74 int write_i = 0;
75 for (const int i : verts.index_range()) {
76 const int vert = verts[i];
77 if (!hide_vert[vert]) {
78 indices[write_i++] = vert;
79 if (i < unique_verts_num) {
80 visible_unique_verts_num++;
81 }
82 }
83 }
84 indices.resize(write_i);
85 return indices;
86}
87
89 const GroupedSpan<int> vert_to_face_map,
90 const int vert)
91{
92 if (hide_poly.is_empty()) {
93 return true;
94 }
95
96 for (const int face : vert_to_face_map[vert]) {
97 if (hide_poly[face]) {
98 return false;
99 }
100 }
101 return true;
102}
103
105 const SubdivCCG &subdiv_ccg,
106 const SubdivCCGCoord vert)
107{
108 const int face_index = BKE_subdiv_ccg_grid_to_face_index(subdiv_ccg, vert.grid_index);
109 return hide_poly[face_index];
110}
111
113{
114 BMEdge *edge = vert->e;
115
116 if (!edge) {
117 return true;
118 }
119
120 do {
121 BMLoop *loop = edge->l;
122
123 if (!loop) {
124 continue;
125 }
126
127 do {
128 if (BM_elem_flag_test(loop->f, BM_ELEM_HIDDEN)) {
129 return false;
130 }
131 } while ((loop = loop->radial_next) != edge->l);
132 } while ((edge = BM_DISK_EDGE_NEXT(edge, vert)) != vert->e);
133
134 return true;
135}
136} // namespace blender::ed::sculpt_paint::hide
A BVH for high poly meshes.
#define BM_DISK_EDGE_NEXT(e, v)
#define BM_elem_flag_test(ele, hflag)
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)
Span< int > node_visible_all_verts(const bke::pbvh::MeshNode &node, const Span< bool > hide_vert, Vector< int > &indices, int &visible_unique_verts_num)
Span< int > node_visible_shared_verts(const bke::pbvh::MeshNode &node, const Span< bool > hide_vert, Vector< int > &indices)
Span< int > node_visible_verts(const bke::pbvh::MeshNode &node, const Span< bool > hide_vert, Vector< int, bke::pbvh::MESH_LEAF_LIMIT > &indices)
bool vert_all_faces_visible_get(const Span< bool > hide_poly, const GroupedSpan< int > vert_to_face_map, const int vert)
int BKE_subdiv_ccg_grid_to_face_index(const SubdivCCG &subdiv_ccg, const int grid_index)
bool BKE_pbvh_node_fully_hidden_get(const bke::pbvh::Node &node)
Definition pbvh.cc:1625
struct BMLoop * l
struct BMLoop * radial_next
struct BMFace * f