27 const int src_verts_num,
39 vert_mask.
size() > 1024,
41 face_mask.foreach_index(
42 [&](const int64_t src_i, const int64_t dst_i) {
43 const IndexRange src_face = src_faces[src_i];
44 const IndexRange dst_face = dst_faces[dst_i];
45 for (const int i : src_face.index_range()) {
46 dst_corner_verts[dst_face[i]] = map[src_corner_verts[src_face[i]]];
52 edge_mask.foreach_index(
54 dst_edges[dst_i][0] = map[src_edges[src_i][0]];
55 dst_edges[dst_i][1] = map[src_edges[src_i][1]];
63 const int src_edges_num,
76 dst_corner_edges[dst_face[i]] = map[src_corner_edges[src_face[i]]];
85 if (src_cache.is_cached() && src_cache.data().mask.is_empty()) {
86 dst.tag_loose_verts_none();
93 if (src_cache.is_cached() && src_cache.data().mask.is_empty()) {
94 dst.tag_loose_edges_none();
100 if (src.no_overlapping_topology()) {
101 dst.tag_overlapping_none();
113 vertex_group_names.
add(group.
name);
127 mesh_dst.attributes_for_write());
136 const Span<int2> src_edges = src_mesh.edges();
138 const Span<int> src_corner_verts = src_mesh.corner_verts();
139 const Span<int> src_corner_edges = src_mesh.corner_edges();
145 if (
const std::optional<bool> single = selection.
get_if_single()) {
146 return *single ? std::nullopt : std::make_optional<Mesh *>(
nullptr);
153 switch (selection_domain) {
158 [&]() { vert_mask = IndexMask::from_bools(span, memory.local()); },
159 [&]() { edge_mask = edge_selection_from_vert(src_edges, span, memory.local()); },
161 face_mask = face_selection_from_vert(
162 src_faces, src_corner_verts, span, memory.local());
169 src_edges.
size() > 1024,
171 edge_mask = IndexMask::from_bools(span, memory.local());
172 vert_mask = vert_selection_from_edge(
173 src_edges, edge_mask, src_mesh.verts_num, memory.local());
176 face_mask = face_selection_from_edge(
177 src_faces, src_corner_edges, span, memory.local());
185 face_mask.
size() > 1024,
187 vert_mask = vert_selection_from_face(
188 src_faces, face_mask, src_corner_verts, src_mesh.verts_num, memory.local());
191 edge_mask = edge_selection_from_face(
192 src_faces, face_mask, src_corner_edges, src_mesh.edges_num, memory.local());
204 const bool same_verts = vert_mask.
size() == src_mesh.
verts_num;
205 const bool same_edges = edge_mask.
size() == src_mesh.
edges_num;
206 const bool same_faces = face_mask.
size() == src_mesh.
faces_num;
207 if (same_verts && same_edges && same_faces) {
212 vert_mask.
size(), edge_mask.
size(), face_mask.
size(), 0);
219 src_faces, face_mask, dst_mesh->face_offsets_for_write());
227 vert_mask.
size() > 1024,
229 remap_verts(src_faces,
241 remap_edges(src_faces,
250 gather_vert_attributes(src_mesh, attribute_filter, vert_mask, *dst_mesh);
251 bke::gather_attributes(
253 bke::AttrDomain::Edge,
254 bke::AttrDomain::Edge,
255 bke::attribute_filter_with_skip_ref(attribute_filter, {
".edge_verts"}),
269 {
".corner_edge",
".corner_vert"}),
279 else if (selection_domain == bke::AttrDomain::Face) {
280 copy_loose_vert_hint(src_mesh, *dst_mesh);
281 copy_loose_edge_hint(src_mesh, *dst_mesh);
293 const Span<int2> src_edges = src_mesh.edges();
295 const Span<int> src_corner_verts = src_mesh.corner_verts();
296 const Span<int> src_corner_edges = src_mesh.corner_edges();
306 switch (selection_domain) {
310 src_edges.
size() > 1024,
311 [&]() { edge_mask = edge_selection_from_vert(src_edges, span, memory.local()); },
313 face_mask = face_selection_from_vert(
314 src_faces, src_corner_verts, span, memory.local());
321 src_edges.
size() > 1024,
322 [&]() { edge_mask = IndexMask::from_bools(span, memory.local()); },
324 face_mask = face_selection_from_edge(
325 src_faces, src_corner_edges, span, memory.local());
333 src_faces, face_mask, src_corner_edges, src_edges.
size(), memory.
local());
341 const bool same_edges = edge_mask.
size() == src_mesh.
edges_num;
342 const bool same_faces = face_mask.
size() == src_mesh.
faces_num;
343 if (same_edges && same_faces) {
353 src_faces, face_mask, dst_mesh->face_offsets_for_write());
421 switch (selection_domain) {
424 src_faces, src_mesh.corner_verts(),
VArraySpan(selection), memory);
428 src_faces, src_mesh.corner_edges(),
VArraySpan(selection), memory);
438 const bool same_faces = face_mask.
size() == src_mesh.
faces_num;
449 src_faces, face_mask, dst_mesh->face_offsets_for_write());
Object is a sort of wrapper for general info.
#define PRF_scope(category)
#define BLI_assert_unreachable()
static IndexMask from_bools(Span< bool > bools, LinearAllocator<> &memory)
constexpr IndexRange index_range() const
constexpr int64_t size() const
constexpr bool is_empty() const
std::optional< T > get_if_single() const
bool add(const StringRef name, const AttrDomain domain, const AttrType data_type, const AttributeInit &initializer)
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
auto attribute_filter_with_skip_ref(const AttributeFilter &filter, const Span< StringRef > skip)
void copy_attributes(const AttributeAccessor src_attributes, AttrDomain src_domain, AttrDomain dst_domain, const AttributeFilter &attribute_filter, MutableAttributeAccessor dst_attributes)
void gather_attributes(AttributeAccessor src_attributes, AttrDomain src_domain, AttrDomain dst_domain, const AttributeFilter &attribute_filter, const IndexMask &selection, MutableAttributeAccessor dst_attributes)
Mesh * mesh_new_no_attributes(int verts_num, int edges_num, int faces_num, int corners_num)
void gather_deform_verts(Span< MDeformVert > src, Span< int > indices, MutableSpan< MDeformVert > dst)
void gather_attributes_group_to_group(AttributeAccessor src_attributes, AttrDomain src_domain, AttrDomain dst_domain, const AttributeFilter &attribute_filter, OffsetIndices< int > src_offsets, OffsetIndices< int > dst_offsets, const IndexMask &selection, MutableAttributeAccessor dst_attributes)
constexpr ParallelGrainSize grain_size(int grain_size)
static void copy_loose_edge_hint(const Mesh &src, Mesh &dst)
static void copy_overlapping_hint(const Mesh &src, Mesh &dst)
static void gather_vert_attributes(const Mesh &mesh_src, const bke::AttributeFilter &attribute_filter, const IndexMask &vert_mask, Mesh &mesh_dst)
IndexMask edge_selection_from_face(OffsetIndices< int > faces, const IndexMask &face_mask, Span< int > corner_edges, int edges_num, IndexMaskMemory &memory)
std::optional< Mesh * > mesh_copy_selection_keep_edges(const Mesh &mesh, const VArray< bool > &selection, bke::AttrDomain selection_domain, const bke::AttributeFilter &attribute_filter={})
static void remap_verts(const OffsetIndices< int > src_faces, const OffsetIndices< int > dst_faces, const int src_verts_num, const IndexMask &vert_mask, const IndexMask &edge_mask, const IndexMask &face_mask, const Span< int2 > src_edges, const Span< int > src_corner_verts, MutableSpan< int2 > dst_edges, MutableSpan< int > dst_corner_verts)
static void remap_edges(const OffsetIndices< int > src_faces, const OffsetIndices< int > dst_faces, const int src_edges_num, const IndexMask &edge_mask, const IndexMask &face_mask, const Span< int > src_corner_edges, MutableSpan< int > dst_corner_edges)
std::optional< Mesh * > mesh_copy_selection_keep_verts(const Mesh &src_mesh, const VArray< bool > &selection, bke::AttrDomain selection_domain, const bke::AttributeFilter &attribute_filter={})
IndexMask face_selection_from_edge(OffsetIndices< int > faces, Span< int > corner_edges, Span< bool > edge_mask, IndexMaskMemory &memory)
IndexMask face_selection_from_vert(OffsetIndices< int > faces, Span< int > corner_verts, Span< bool > vert_selection, IndexMaskMemory &memory)
std::optional< Mesh * > mesh_copy_selection(const Mesh &src_mesh, const VArray< bool > &selection, bke::AttrDomain selection_domain, const bke::AttributeFilter &attribute_filter={})
static void copy_loose_vert_hint(const Mesh &src, Mesh &dst)
void build_reverse_map(const IndexMask &mask, MutableSpan< T > r_map)
template void build_reverse_map< int >(const IndexMask &mask, MutableSpan< int > r_map)
OffsetIndices< int > gather_selected_offsets(OffsetIndices< int > src_offsets, const IndexMask &selection, int start_offset, MutableSpan< int > dst_offsets)
void parallel_invoke(Functions &&...functions)
static void copy_loose_vert_hint(const Mesh &src, Mesh &dst)
void BKE_mesh_copy_parameters_for_eval(Mesh *me_dst, const Mesh *me_src)
VecBase< int32_t, 2 > int2
ListBaseT< bDeformGroup > vertex_group_names
bke::MeshRuntime * runtime
SharedCache< Bounds< float3 > > bounds_cache
SharedCache< LooseGeomCache > loose_edges_cache
SharedCache< LooseGeomCache > loose_verts_cache