36 dst[i] = src[indices[i]];
45 return src.
slice(indices[0], indices.
size());
66 return src_mesh.face_normals();
68 if (selection_size > src_mesh.
faces_num / 4) {
69 return src_mesh.face_normals();
77 if (src_cache.is_cached() && src_cache.data().mask.is_empty()) {
78 dst.tag_loose_verts_none();
108 if (flip_flag & (1 << 0)) [[unlikely]] {
111 if (flip_flag & (1 << 1)) [[unlikely]] {
156 positions[verts[0]], positions[verts[1]], positions[verts[2]], positions[verts[3]]);
171 switch (directions[i]) {
179 const int src_face_start = face_offsets[i];
180 for (
int &i : quad_map) {
202 data.directions.reinitialize(quads.
size());
223 dst_offsets[i] = offset;
224 offset += src_offsets[selection[i]].
size();
226 dst_offsets.
last() = offset;
237 [&](
const int face,
const int mask) {
260 Heap *heap =
nullptr;
280 data.offset_data.reinitialize(ngons.
size() + 1);
282 src_faces, ngons,
data.offset_data);
285 data.projections.reinitialize(ngons.
size());
289 const IndexRange src_face = src_faces[ngons[i]];
302 data.projected_positions.reinitialize(local_corner_offsets.
total_size());
305 const IndexRange src_face = src_faces[ngons[i]];
307 const float3x3 &matrix = projections[i];
311 mul_v2_m3v3(positions_2d[i], matrix.
ptr(), positions[face_verts[i]]);
326 const Span<float2> positions_2d = projected_positions.
slice(local_corner_offsets[i]);
327 const IndexRange tris_range = tris_by_ngon[pos + i];
332 reinterpret_cast<uint(*)[3]
>(map.
data()));
336 reinterpret_cast<uint(*)[3]
>(map.
data()),
346 const IndexRange tris_range = tris_by_ngon[pos + i];
347 const int src_face_start = src_faces[ngons[i]].start();
349 for (
int &vert : map) {
350 vert += src_face_start;
369 BLI_assert(std::is_sorted(&tri_verts[0], &tri_verts[0] + 3));
381 BLI_assert(std::is_sorted(&value[0], &value[0] + 3));
396 return b.tri_lower_vert == a[0] &&
tris[
b.tri_index] == a;
403 res[0] = std::min({tri[0], tri[1], tri[2]});
404 res[2] = std::max({tri[0], tri[1], tri[2]});
405 res[1] = (tri[0] - res[0]) + (tri[2] - res[2]) + tri[1];
412 for (int3 &tri : tris.slice(range)) {
413 tri = tri_to_ordered(tri);
435 return universe_segment.
offset();
440 const int face = int(universe_segment.
offset() + i);
441 if (src_faces[face].size() == 3) {
445 return universe_segment.
offset();
462 const int3 corner_tri(&corner_verts[faces[face_i].start()]);
471 for (const int face_i : range) {
472 indices[face_i] = faces[face_i].tri_index;
481 [&](
const int index,
const int pos) {
482 indices[2 * pos + 0] =
index;
483 indices[2 * pos + 1] =
index;
505 const Span<float3> positions = src_mesh.vert_positions();
507 const Span<int> src_corner_verts = src_mesh.corner_verts();
520 selection, memory, [&](
const int i) {
return src_faces[i].
size() == 4; });
522 selection, memory, [&](
const int i) {
return src_faces[i].
size() > 4; });
523 if (quads.
is_empty() && ngons.is_empty()) {
530 Array<int> tris_by_ngon_data(ngons.size() + 1);
532 const int ngon_tris_num = tris_by_ngon.
total_size();
533 const int quad_tris_num = quads.
size() * 2;
534 const IndexRange tris_range(ngon_tris_num + quad_tris_num);
538 Array<int3> corner_tris(ngon_tris_num + quad_tris_num);
540 if (!ngons.is_empty()) {
563 Array<int3> vert_tris(ngon_tris_num + quad_tris_num);
565 corner_tris.
as_span().cast<
int>(),
583 for (
const int face_i : ordered_vert_tris.
index_range()) {
584 const TriKey face_key(face_i, ordered_vert_tris);
585 unique_tris.add(face_key);
587 const int unique_tri_num = unique_tris.size();
593 src_tris, src_faces, src_corner_verts, unique_tris, memory);
600 const IndexRange unique_faces_range(unique_tri_num + unique_src_faces.
size());
615 const int total_new_tri_corners = unique_tri_range.
size() * 3;
619 total_new_tri_corners,
634 mesh->attribute_storage.wrap().add(attr.name(), attr.domain(), attr.data_type(), attr.data());
639 const bool has_duplicate_faces = unique_tri_num != (ngon_tris_num + quad_tris_num);
641 Array<int> dst_tri_to_src_face(unique_tri_num);
645 if (has_duplicate_faces) {
653 Array<int> src_to_unique_map(ngon_tris_num + quad_tris_num);
656 ngons, tris_by_ngon, src_to_unique_map.
as_mutable_span().slice(ngon_tris_range));
663 const Span<int3> unique_corner_tris = has_duplicate_faces ? unique_corner_tris_data.
as_span() :
691 faces.
slice(unique_src_faces_range),
696 unique_corner_tris.
cast<
int>(),
697 corner_verts.take_front(total_new_tri_corners));
704 {
".corner_vert",
".corner_edge"})))
713 unique_corner_tris.
cast<
int>(),
714 attribute.dst.span.slice(0, unique_tri_num * 3));
723 if (src_mesh.no_overlapping_topology()) {
724 mesh->tag_overlapping_none();
CustomData interface, see also DNA_customdata_types.h.
A min-heap / priority queue ADT.
#define BLI_POLYFILL_ARENA_SIZE
#define BLI_POLYFILL_ALLOC_NGON_RESERVE
Span< T > as_span() const
MutableSpan< T > as_mutable_span()
void reinitialize(const int64_t new_size)
static IndexMask from_predicate(const IndexMask &universe, LinearAllocator<> &memory, Fn &&predicate, exec_mode::Mode mode=exec_mode::parallel)
static IndexMask from_difference(const IndexMask &mask_a, const IndexMask &mask_b, LinearAllocator<> &memory)
static IndexMask from_batch_predicate(const IndexMask &universe, LinearAllocator<> &memory, FunctionRef< int64_t(const IndexMaskSegment &universe_segment, IndexRangesBuilder< int16_t > &builder)> batch_predicate, exec_mode::Mode mode=exec_mode::parallel)
constexpr int64_t one_after_last() const
constexpr IndexRange shift(int64_t n) const
constexpr int64_t size() const
constexpr int64_t start() const
constexpr IndexRange take_back(int64_t n) const
constexpr IndexRange take_front(int64_t n) const
bool add_range(const T start, const T end)
constexpr int64_t size() const
constexpr MutableSpan slice(const int64_t start, const int64_t size) const
constexpr MutableSpan< NewT > cast() const
constexpr MutableSpan take_back(const int64_t n) const
constexpr T * data() const
constexpr void fill(const T &value) const
constexpr IndexRange index_range() const
constexpr void copy_from(Span< T > values) const
constexpr MutableSpan take_front(const int64_t n) const
constexpr T & last(const int64_t n=0) const
IndexRange index_range() const
Span< BaseT > base_span() const
constexpr Span drop_front(int64_t n) const
Span< NewT > constexpr cast() const
constexpr Span slice(int64_t start, int64_t size) const
constexpr const T * data() const
constexpr int64_t size() const
constexpr IndexRange index_range() const
constexpr bool is_empty() const
void reinitialize(const int64_t new_size)
Span< T > as_span() const
bool add(const StringRef name, const AttrDomain domain, const AttrType data_type, const AttributeInit &initializer)
const DifferenceExpr & subtract(const Term &main_term, const Span< Term > subtract_terms)
void foreach_index_optimized(Fn &&fn, Mode mode=exec_mode::serial) const
void foreach_segment(Fn &&fn, Mode mode=exec_mode::serial) const
IndexRange index_range() const
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
IndexRange index_range() const
OffsetIndices slice(const IndexRange range) const
void gather(const GVArray &src, const IndexMask &indices, GMutableSpan dst, exec_mode::Mode mode=exec_mode::parallel)
void gather_group_to_group(const OffsetIndices< int > src_offsets, const OffsetIndices< int > dst_offsets, const IndexMask &selection, const Span< T > src, MutableSpan< T > dst)
void gather(GSpan src, Span< int > map, GMutableSpan dst)
void gather_group_to_group(OffsetIndices< int > src_offsets, OffsetIndices< int > dst_offsets, const IndexMask &selection, GSpan src, GMutableSpan dst)
float3 face_normal_calc(Span< float3 > vert_positions, Span< int > face_verts)
int face_triangles_num(const int face_size)
auto attribute_filter_with_skip_ref(const AttributeFilter &filter, const Span< StringRef > skip)
bool mesh_is_valid(const Mesh &mesh, bool verbose=true)
Vector< AttributeTransferData > retrieve_attributes_for_transfer(const AttributeAccessor src_attributes, MutableAttributeAccessor dst_attributes, Span< AttrDomain > domains, const AttributeFilter &attribute_filter={})
Mesh * mesh_new_no_attributes(int verts_num, int edges_num, int faces_num, int corners_num)
void mesh_calc_edges(Mesh &mesh, bool keep_existing_edges, bool select_new_edges)
constexpr ParallelGrainSize grain_size(int grain_size)
static void calc_corner_tris(const Span< float3 > positions, const OffsetIndices< int > src_faces, const Span< int > src_corner_verts, const Span< float3 > face_normals, const IndexMask &ngons, const OffsetIndices< int > tris_by_ngon, const TriangulateNGonMode ngon_mode, MutableSpan< int3 > corner_tris)
static OffsetIndices< int > calc_tris_by_ngon(const OffsetIndices< int > src_faces, const IndexMask &ngons, MutableSpan< int > face_offset_data)
static void calc_corner_tris(const Span< int > face_offsets, const Span< QuadDirection > directions, MutableSpan< int3 > corner_tris)
static void calc_quad_directions(const Span< float3 > positions, const Span< int > face_offsets, const Span< int > corner_verts, const TriangulateQuadMode quad_mode, MutableSpan< QuadDirection > directions)
static QuadDirection calc_quad_direction_beauty(const float3 &v0, const float3 &v1, const float3 &v2, const float3 &v3)
std::optional< Mesh * > mesh_triangulate(const Mesh &src_mesh, const IndexMask &selection, TriangulateNGonMode ngon_mode, TriangulateQuadMode quad_mode, const bke::AttributeFilter &attribute_filter)
static void ngon_indices_of_tris(const IndexMask &ngons, const OffsetIndices< int > tris_by_ngon, MutableSpan< int > indices)
static void gather(const Span< int > src, const Span< int16_t > indices, MutableSpan< int > dst)
static Span< int3 > tri_to_ordered_tri(MutableSpan< int3 > tris)
static void quad_indices_of_tris(const IndexMask &quads, MutableSpan< int > indices)
static int3 tri_to_ordered(const int3 tri)
static void face_keys_to_face_indices(const Span< TriKey > faces, MutableSpan< int > indices)
static OffsetIndices< int > gather_selected_offsets(const OffsetIndices< int > src_offsets, const IndexMaskSegment selection, MutableSpan< int > dst_offsets)
static Span< float3 > face_normals_if_worthwhile(const Mesh &src_mesh, const int selection_size)
static Span< int > gather_or_reference(const Span< int > src, const Span< int16_t > indices, Vector< int > &dst)
static IndexMask face_tris_mask(const OffsetIndices< int > src_faces, const IndexMask &mask, IndexMaskMemory &memory)
static void copy_loose_vert_hint(const Mesh &src, Mesh &dst)
static IndexMask tris_in_set(const IndexMask &tri_mask, const OffsetIndices< int > faces, const Span< int > corner_verts, const VectorSet< TriKey, 4, DefaultProbingStrategy, FaceHash, FacesEquality, SimpleVectorSetSlot< TriKey, int > > &unique_tris, IndexMaskMemory &memory)
IndexMask evaluate_expression(const Expr &expression, LinearAllocator<> &memory)
T distance_squared(const VecBase< T, Size > &a, const VecBase< T, Size > &b)
OffsetIndices< int > accumulate_counts_to_offsets(MutableSpan< int > counts_to_offsets, int start_offset=0)
void fill_constant_group_size(int size, int start_offset, MutableSpan< int > offsets)
OffsetIndices< int > gather_selected_offsets(OffsetIndices< int > src_offsets, const IndexMask &selection, int start_offset, MutableSpan< int > dst_offsets)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
bool non_empty_is_range(const Span< T > indices)
IndexRange non_empty_as_range(const Span< T > indices)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
Heap * BLI_heap_new_ex(unsigned int reserve_num) ATTR_WARN_UNUSED_RESULT
MemArena * BLI_memarena_new(size_t bufsize, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(2) ATTR_MALLOC
bool CustomData_has_layer(const CustomData *data, eCustomDataType type)
void BLI_polyfill_calc(const float(*coords)[2], unsigned int coords_num, int coords_sign, unsigned int(*r_tris)[3])
void mul_v2_m3v3(float r[2], const float M[3][3], const float a[3])
void BLI_heap_free(Heap *heap, HeapFreeFP ptrfreefp) ATTR_NONNULL(1)
void BKE_mesh_copy_parameters_for_eval(Mesh *me_dst, const Mesh *me_src)
VecBase< int32_t, 3 > int3
float BLI_polyfill_edge_calc_rotate_beauty__area(const float v1[3], const float v2[3], const float v3[3], const float v4[3], bool lock_degenerate)
BMesh const char void * data
void BLI_memarena_clear(MemArena *ma) ATTR_NONNULL(1)
const void * CustomData_get_layer(const CustomData *data, eCustomDataType type)
bool CustomData_merge(const CustomData *source, CustomData *dest, eCustomDataMask mask, int totelem)
MatBase< float, 3, 3 > float3x3
ATTR_WARN_UNUSED_RESULT const BMVert * v2
const CustomData_MeshMasks CD_MASK_MESH
PythonProbingStrategy<> DefaultProbingStrategy
int is_quad_flip_v3(const float v1[3], const float v2[3], const float v3[3], const float v4[3])
VecBase< float, 3 > float3
void BLI_polyfill_beautify(const float(*coords)[2], unsigned int coords_num, unsigned int(*tris)[3], struct MemArena *arena, struct Heap *eheap)
void BLI_memarena_free(MemArena *ma) ATTR_NONNULL(1)
void axis_dominant_v3_to_m3_negate(float r_mat[3][3], const float normal[3])
void * CustomData_add_layer(CustomData *data, eCustomDataType type, eCDAllocType alloctype, int totelem)
const c_style_mat & ptr() const
struct AttributeStorage attribute_storage
bke::MeshRuntime * runtime
SharedCache< Bounds< float3 > > bounds_cache
SharedCache< NormalsCache > face_normals_cache
SharedCache< LooseGeomCache > loose_verts_cache
uint64_t operator()(const TriKey value) const
uint64_t operator()(const int3 value) const
bool operator()(const TriKey a, const TriKey b) const
bool operator()(const int3 a, const TriKey b) const
TriKey(const int tri_index, Span< int3 > tris)