44 const bool face_normal,
45 const float normal_precalc[3])
47 auto create_tri = [&](
int i1,
int i2,
int i3) {
48 (*tri)[0] = face_start + i1;
49 (*tri)[1] = face_start + i2;
50 (*tri)[2] = face_start + i3;
64 positions[corner_verts[(*tri_a)[1]]],
65 positions[corner_verts[(*tri_a)[2]]],
66 positions[corner_verts[(*tri_b)[2]]])))
69 (*tri_a)[2] = (*tri_b)[2];
70 (*tri_b)[0] = (*tri_a)[1];
78 if (face_normal ==
false) {
80 const float *co_curr, *co_prev;
85 co_prev = positions[corner_verts[face_start + face_size - 1]];
86 for (
int j = 0; j < face_size; j++) {
87 co_curr = positions[corner_verts[face_start + j]];
100 const int totfilltri = face_size - 2;
103 if (
UNLIKELY(pf_arena ==
nullptr)) {
107 uint(*tris)[3] =
static_cast<uint(*)[3]
>(
109 float(*projverts)[2] =
static_cast<float(*)[2]
>(
112 for (
int j = 0; j < face_size; j++) {
113 mul_v2_m3v3(projverts[j], axis_mat, positions[corner_verts[face_start + j]]);
119 for (
int j = 0; j < totfilltri; j++, tri++) {
120 create_tri(
int(tris[j][0]),
int(tris[j][1]),
int(tris[j][2]));
132 const int face_start,
138 corner_verts, positions, face_start, face_size, tri, pf_arena_p,
false,
nullptr);
143 const int face_start,
147 const float normal_precalc[3])
150 corner_verts, positions, face_start, face_size, tri, pf_arena_p,
true, normal_precalc);
173 LocalData &local_data = all_local_data.local();
174 for (const int64_t i : range) {
175 const int face_start = int(faces[i].start());
176 const int face_size = int(faces[i].size());
177 const int tris_start = poly_to_tri_count(int(i), face_start);
178 mesh_calc_tessellation_for_face(corner_verts,
182 &corner_tris[tris_start],
183 &local_data.pf_arena);
189 LocalData &local_data = all_local_data.local();
190 for (const int64_t i : range) {
191 const int face_start = int(faces[i].start());
192 const int face_size = int(faces[i].size());
193 const int tris_start = poly_to_tri_count(int(i), face_start);
194 mesh_calc_tessellation_for_face_with_normal(corner_verts,
198 &corner_tris[tris_start],
199 &local_data.pf_arena,
216 threading::parallel_for(faces.index_range(), 1024, [&](
const IndexRange range) {
217 for (const int64_t i : range) {
218 const IndexRange face = faces[i];
219 const int start = poly_to_tri_count(int(i), int(face.start()));
220 const int num = face_triangles_num(int(face.size()));
221 tri_faces.slice(start, num).fill(int(i));
242 array_utils::gather(corner_verts, corner_tris.
cast<
int>(), vert_tris.
cast<
int>());
248 const int3 &corner_tri)
251 for (
int i = 2, i_next = 0; i_next < 3; i = i_next++) {
252 const int corner_1 =
int(corner_tri[i]);
253 const int corner_2 =
int(corner_tri[i_next]);
254 const int vert_1 = corner_verts[corner_1];
255 const int vert_2 = corner_verts[corner_2];
256 const int edge_i = corner_edges[corner_1];
257 const int2 edge = edges[edge_i];
259 const bool is_real = (vert_1 == edge[0] && vert_2 == edge[1]) ||
260 (vert_1 == edge[1] && vert_2 == edge[0]);
262 real_edges[i] = is_real ? edge_i : -1;
bool is_quad_flip_v3_first_third_fast(const float v1[3], const float v2[3], const float v3[3], const float v4[3])
void axis_dominant_v3_to_m3_negate(float r_mat[3][3], const float normal[3])
void mul_v2_m3v3(float r[2], const float M[3][3], const float a[3])
MINLINE void add_newell_cross_v3_v3v3(float n[3], const float v_prev[3], const float v_curr[3])
MINLINE void zero_v3(float r[3])
MINLINE float normalize_v3(float n[3])
void * BLI_memarena_alloc(struct MemArena *ma, size_t size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_ALLOC_SIZE(2)
void BLI_memarena_free(struct MemArena *ma) ATTR_NONNULL(1)
struct MemArena * BLI_memarena_new(size_t bufsize, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(2) ATTR_MALLOC
#define BLI_MEMARENA_STD_BUFSIZE
void void BLI_memarena_clear(MemArena *ma) ATTR_NONNULL(1)
void BLI_polyfill_calc_arena(const float(*coords)[2], unsigned int coords_num, int coords_sign, unsigned int(*r_tris)[3], struct MemArena *arena)
constexpr MutableSpan< NewT > cast() const
Span< NewT > constexpr cast() const
constexpr bool is_empty() const
draw_view in_light_buf[] float
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
BLI_INLINE void mesh_calc_tessellation_for_face_impl(const Span< int > corner_verts, const Span< float3 > positions, const int face_start, const int face_size, int3 *tri, MemArena **pf_arena_p, const bool face_normal, const float normal_precalc[3])
void corner_tris_calc(Span< float3 > vert_positions, OffsetIndices< int > faces, Span< int > corner_verts, MutableSpan< int3 > corner_tris)
static void corner_tris_calc_impl(const Span< float3 > positions, const OffsetIndices< int > faces, const Span< int > corner_verts, const Span< float3 > face_normals, MutableSpan< int3 > corner_tris)
static void mesh_calc_tessellation_for_face_with_normal(const Span< int > corner_verts, const Span< float3 > positions, const int face_start, const int face_size, int3 *tri, MemArena **pf_arena_p, const float normal_precalc[3])
void vert_tris_from_corner_tris(Span< int > corner_verts, Span< int3 > corner_tris, MutableSpan< int3 > vert_tris)
void corner_tris_calc_with_normals(Span< float3 > vert_positions, OffsetIndices< int > faces, Span< int > corner_verts, Span< float3 > face_normals, MutableSpan< int3 > corner_tris)
void corner_tris_calc_face_indices(OffsetIndices< int > faces, MutableSpan< int > tri_faces)
static void mesh_calc_tessellation_for_face(const Span< int > corner_verts, const Span< float3 > positions, const int face_start, const int face_size, int3 *tri, MemArena **pf_arena_p)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))