52 mesh.runtime->vert_normals_true_cache.ensure(
58 mesh.runtime->vert_normals_true_cache.ensure(
59 [&](
Vector<float3> &r_data) { r_data = std::move(vert_normals); });
70 return std::get<Vector<float3>>(this->
data).as_mutable_span();
76 return vector->as_span();
78 return std::get<Span<float3>>(this->
data);
84 this->data =
data.get_internal_span();
100 return mesh->runtime->vert_normals_cache.is_dirty();
105 return mesh->runtime->face_normals_cache.is_dirty();
128 const float *v_prev = vert_positions[face_verts.
last()];
130 const float *v_curr = vert_positions[face_verts[i]];
146 if (face_verts.
size() == 4) {
148 vert_positions[face_verts[0]],
149 vert_positions[face_verts[1]],
150 vert_positions[face_verts[2]],
151 vert_positions[face_verts[3]]);
153 else if (face_verts.
size() == 3) {
155 vert_positions[face_verts[1]],
156 vert_positions[face_verts[2]]);
188 for (const int i : range) {
189 face_normals[i] = normal_calc_ngon(positions, corner_verts.slice(faces[i]));
204 for (const int vert : range) {
205 const Span<int> vert_faces = vert_to_face_map[vert];
206 if (vert_faces.is_empty()) {
207 vert_normals[vert] = math::normalize(positions[vert]);
211 float3 vert_normal(0);
212 for (const int face : vert_faces) {
213 const int2 adjacent_verts = face_find_adjacent_verts(faces[face], corner_verts, vert);
214 const float3 dir_prev = math::normalize(positions[adjacent_verts[0]] - positions[vert]);
215 const float3 dir_next = math::normalize(positions[adjacent_verts[1]] - positions[vert]);
216 const float factor = math::safe_acos_approx(math::dot(dir_prev, dir_next));
218 vert_normal += face_normals[face] * factor;
221 vert_normals[vert] = math::normalize(vert_normal);
238 for (const int vert : range) {
239 const Span<int> vert_faces = vert_to_face_map[vert];
240 if (vert_faces.is_empty()) {
241 vert_normals[vert] = math::normalize(positions[vert]);
245 float3 vert_normal(0);
246 for (const int face : vert_faces) {
247 const int corner = mesh::face_find_corner_from_vert(faces[face], corner_verts, vert);
248 const int2 adjacent_verts{corner_verts[mesh::face_corner_prev(faces[face], corner)],
249 corner_verts[mesh::face_corner_next(faces[face], corner)]};
251 const float3 dir_prev = math::normalize(positions[adjacent_verts[0]] - positions[vert]);
252 const float3 dir_next = math::normalize(positions[adjacent_verts[1]] - positions[vert]);
253 const float factor = math::safe_acos_approx(math::dot(dir_prev, dir_next));
255 vert_normal += corner_normals[corner] * factor;
258 vert_normals[vert] = math::normalize(vert_normal);
270 for (const int face : range) {
272 for (const int vert : corner_verts.slice(faces[face])) {
273 sum += vert_normals[vert];
275 face_normals[face] = math::normalize(sum);
286 for (const int face : range) {
287 const Span<float3> face_corner_normals = corner_normals.slice(faces[face]);
288 const float3 sum = std::accumulate(
289 face_corner_normals.begin(), face_corner_normals.end(), float3(0));
290 face_normals[face] = math::normalize(sum);
301bke::MeshNormalDomain Mesh::normals_domain()
const
304 if (this->faces_num == 0) {
311 switch (custom->domain) {
312 case AttrDomain::Point:
313 return MeshNormalDomain::Point;
314 case AttrDomain::Edge:
316 case AttrDomain::Face:
317 return MeshNormalDomain::Face;
318 case AttrDomain::Corner:
319 return MeshNormalDomain::Corner;
326 "sharp_face", AttrDomain::Face,
false);
328 const array_utils::BooleanMix face_mix = array_utils::booleans_mix_calc(sharp_faces);
329 if (face_mix == array_utils::BooleanMix::AllTrue) {
330 return MeshNormalDomain::Face;
334 "sharp_edge", AttrDomain::Edge,
false);
335 const array_utils::BooleanMix edge_mix = array_utils::booleans_mix_calc(sharp_edges);
336 if (edge_mix == array_utils::BooleanMix::AllTrue) {
337 return MeshNormalDomain::Face;
340 if (edge_mix == array_utils::BooleanMix::AllFalse &&
341 face_mix == array_utils::BooleanMix::AllFalse)
343 return MeshNormalDomain::Point;
346 return MeshNormalDomain::Corner;
351 using namespace blender::bke;
352 this->
runtime->vert_normals_cache.ensure([&](NormalsCache &r_data) {
353 if (
const GAttributeReader custom = this->
attributes().
lookup(
"custom_normal")) {
354 if (custom.varray.type().is<
float3>()) {
355 if (custom.domain == AttrDomain::Point) {
359 if (custom.domain == AttrDomain::Face) {
360 mesh::normals_calc_verts(this->vert_positions(),
362 this->corner_verts(),
363 this->vert_to_face_map(),
364 VArraySpan<float3>(custom.varray.typed<
float3>()),
369 if (custom.domain == AttrDomain::Corner) {
370 mesh::mix_normals_corner_to_vert(this->vert_positions(),
372 this->corner_verts(),
373 this->vert_to_face_map(),
374 VArraySpan<float3>(custom.varray.typed<
float3>()),
379 else if (custom.varray.type().is<
short2>() && custom.domain == AttrDomain::Corner) {
380 mesh::mix_normals_corner_to_vert(this->vert_positions(),
382 this->corner_verts(),
383 this->vert_to_face_map(),
384 this->corner_normals(),
389 r_data.
data = NormalsCache::UseTrueCache();
391 if (std::holds_alternative<NormalsCache::UseTrueCache>(
392 this->
runtime->vert_normals_cache.data().data))
394 return this->vert_normals_true();
397 return this->
runtime->vert_normals_cache.
data().get_span();
402 using namespace blender::bke;
403 this->
runtime->vert_normals_true_cache.ensure([&](Vector<float3> &r_data) {
405 mesh::normals_calc_verts(this->vert_positions(),
407 this->corner_verts(),
408 this->vert_to_face_map(),
409 this->face_normals_true(),
412 return this->
runtime->vert_normals_true_cache.
data();
417 using namespace blender::bke;
421 this->
runtime->face_normals_cache.ensure([&](NormalsCache &r_data) {
422 if (
const GAttributeReader custom = this->
attributes().
lookup(
"custom_normal")) {
423 if (custom.varray.type().is<
float3>()) {
424 if (custom.domain == AttrDomain::Face) {
428 if (custom.domain == AttrDomain::Point) {
429 mesh::mix_normals_vert_to_face(this->faces(),
430 this->corner_verts(),
431 VArraySpan<float3>(custom.varray.typed<
float3>()),
435 if (custom.domain == AttrDomain::Corner) {
436 mesh::mix_normals_corner_to_face(this->faces(),
437 VArraySpan<float3>(custom.varray.typed<
float3>()),
442 else if (custom.varray.type().is<
short2>() && custom.domain == AttrDomain::Corner) {
443 mesh::mix_normals_corner_to_face(
448 r_data.
data = NormalsCache::UseTrueCache();
450 if (std::holds_alternative<NormalsCache::UseTrueCache>(
451 this->
runtime->face_normals_cache.data().data))
453 return this->face_normals_true();
455 return this->
runtime->face_normals_cache.
data().get_span();
460 using namespace blender::bke;
461 this->
runtime->face_normals_true_cache.ensure([&](Vector<float3> &r_data) {
463 mesh::normals_calc_faces(this->vert_positions(), this->faces(), this->corner_verts(), r_data);
465 return this->
runtime->face_normals_true_cache.
data();
470 using namespace blender::bke;
474 this->
runtime->corner_normals_cache.ensure([&](NormalsCache &r_data) {
475 const OffsetIndices<int> faces = this->faces();
476 switch (this->normals_domain()) {
477 case MeshNormalDomain::Point: {
479 array_utils::gather(this->vert_normals(), this->corner_verts(), data);
482 case MeshNormalDomain::Face: {
484 const Span<float3> face_normals = this->face_normals();
485 array_utils::gather_to_groups(faces, faces.
index_range(), face_normals, data);
488 case MeshNormalDomain::Corner: {
492 if (custom.
domain == bke::AttrDomain::Corner) {
498 const VArraySpan sharp_edges = *
attributes.
lookup<
bool>(
"sharp_edge", AttrDomain::Edge);
499 const VArraySpan sharp_faces = *
attributes.
lookup<
bool>(
"sharp_face", AttrDomain::Face);
500 mesh::normals_calc_corners(this->vert_positions(),
502 this->corner_verts(),
503 this->corner_edges(),
504 this->vert_to_face_map(),
505 this->face_normals_true(),
514 return this->
runtime->corner_normals_cache.
data().get_span();
519 const char data_type)
524 if (!lnors_spacearr->
mem) {
527 mem = lnors_spacearr->
mem;
548 *lnors_spacearr_tls = *lnors_spacearr;
560 lnors_spacearr_tls->
mem =
nullptr;
569 if (lnors_spacearr->
mem !=
nullptr) {
580 lnors_spacearr->
mem =
nullptr;
591#define LNOR_SPACE_TRIGO_THRESHOLD (1.0f - 1e-4f)
602 const float dtp_ref =
math::dot(vec_ref, lnor);
603 const float dtp_other =
math::dot(vec_other, lnor);
619 for (
const float3 &vec : edge_vectors) {
661 const float vec_ref[3],
662 const float vec_other[3],
678 const bool is_single)
683 lnors_spacearr->
lspacearr[corner] = lnor_space;
684 if (bm_loop ==
nullptr) {
715 if (clnor_data[0] == 0 || lnor_space.
ref_alpha == 0.0f || lnor_space.
ref_beta == 0.0f) {
725 const float alpha = (alphafac > 0.0f ? lnor_space.
ref_alpha : pi2 - lnor_space.
ref_alpha) *
731 if (betafac == 0.0f) {
735 const float sinalpha =
sinf(alpha);
748 const short clnor_data[2],
749 float r_custom_lnor[3])
764 const float3 &custom_lnor)
814 const float custom_lnor[3],
815 short r_clnor_data[2])
831#define INDEX_UNSET INT_MIN
832#define INDEX_INVALID -1
834#define IS_EDGE_SHARP(_e2l) ELEM((_e2l)[1], INDEX_UNSET, INDEX_INVALID)
843 const float split_angle,
847 const float split_angle_cos =
cosf(split_angle);
848 auto face_is_smooth = [&](
const int face_i) {
849 return sharp_faces.
is_empty() || !sharp_faces[face_i];
853 for (
const int corner : faces[face_i]) {
854 const int vert = corner_verts[corner];
855 const int edge = corner_edges[corner];
857 int2 &e2l = edge_to_corners[edge];
860 if ((e2l[0] | e2l[1]) == 0) {
867 const bool is_angle_sharp =
math::dot(face_normals[corner_to_face_map[e2l[0]]],
868 face_normals[face_i]) < split_angle_cos;
874 if (!face_is_smooth(face_i) || (!sharp_edges.
is_empty() && sharp_edges[edge]) ||
875 vert == corner_verts[e2l[0]] || is_angle_sharp)
882 if (is_angle_sharp) {
883 r_sharp_edges[edge] =
true;
896 r_sharp_edges[edge] =
false;
909 const float split_angle,
912 if (split_angle >=
float(
M_PI)) {
957 const int face = vert_faces[i];
958 r_corner_infos[i].face = face;
960 r_corner_infos[i].corner_prev =
face_corner_prev(faces[face], r_corner_infos[i].corner);
961 r_corner_infos[i].corner_next =
face_corner_next(faces[face], r_corner_infos[i].corner);
962 r_corner_infos[i].vert_prev = corner_verts[r_corner_infos[i].corner_prev];
963 r_corner_infos[i].vert_next = corner_verts[r_corner_infos[i].corner_next];
996using VertEdgeInfo = std::variant<EdgeUninitialized, EdgeOneCorner, EdgeTwoCorners, EdgeSharp>;
1000 const int local_corner,
1002 const int other_corner,
1003 const bool winding_torwards_vert,
1006 if (std::holds_alternative<EdgeUninitialized>(info)) {
1011 if (sharp_edges[corner_edges[winding_torwards_vert ? other_corner : corner]]) {
1018 else if (
const EdgeOneCorner *info_one_edge = std::get_if<EdgeOneCorner>(&info)) {
1024 if (info_one_edge->winding_torwards_vert == winding_torwards_vert) {
1028 info =
EdgeTwoCorners{info_one_edge->local_corner_1, local_corner};
1053 r_other_vert_to_edge.
reserve(corner_infos.
size());
1055 info.local_edge_prev = r_other_vert_to_edge.
index_of_or_add(info.vert_prev);
1056 info.local_edge_next = r_other_vert_to_edge.
index_of_or_add(info.vert_next);
1066 for (
const int local_corner : corner_infos.
index_range()) {
1068 if (!sharp_faces.
is_empty() && sharp_faces[info.
face]) {
1099 const int start_local_corner,
1102 result_fan.
append(start_local_corner);
1108 int current = start_local_corner;
1109 int local_edge = corner_infos[current].local_edge_next;
1110 bool found_cyclic_fan =
false;
1111 while (
const EdgeTwoCorners *edge = std::get_if<EdgeTwoCorners>(&edge_infos[local_edge])) {
1113 if (current == start_local_corner) {
1114 found_cyclic_fan =
true;
1117 result_fan.
append(current);
1118 local_edge = corner_infos[current].local_edge_next;
1123 if (found_cyclic_fan) {
1126 int *fan_first_corner = std::min_element(
1127 result_fan.
begin(), result_fan.
end(), [&](
const int a,
const int b) {
1128 return corner_infos[a].corner < corner_infos[b].corner;
1130 std::rotate(result_fan.
begin(), fan_first_corner, result_fan.
end());
1136 int current = start_local_corner;
1137 int local_edge = corner_infos[current].local_edge_prev;
1138 while (
const EdgeTwoCorners *edge = std::get_if<EdgeTwoCorners>(&edge_infos[local_edge])) {
1139 current = current == edge->local_corner_1 ? edge->local_corner_2 : edge->local_corner_1;
1141 result_fan.
append(current);
1142 local_edge = corner_infos[current].local_edge_prev;
1153 const float3 &vert_position,
1156 for (
const int i : local_edge_by_vert.
index_range()) {
1157 edge_dirs[i] =
math::normalize(vert_positions[local_edge_by_vert[i]] - vert_position);
1167 if (local_corners_in_fan.
size() == 1) {
1170 return face_normals[corner_infos[local_corners_in_fan.
first()].face];
1173 for (
const int local_corner : local_corners_in_fan) {
1178 fan_normal += face_normals[info.
face] * factor;
1199 const int local_edge_first = corner_infos[local_corners_in_fan.
first()].local_edge_next;
1200 const int local_edge_last = corner_infos[local_corners_in_fan.
last()].local_edge_prev;
1203 if (local_corners_in_fan.
size() > 1) {
1204 fan_edge_dirs.
reserve(local_corners_in_fan.
size() + 1);
1205 for (
const int local_corner : local_corners_in_fan) {
1209 if (local_edge_last != local_edge_first) {
1215 fan_normal, edge_dirs[local_edge_first], edge_dirs[local_edge_last], fan_edge_dirs);
1218 int2 average_custom_normal(0);
1219 for (
const int local_corner : local_corners_in_fan) {
1221 average_custom_normal +=
int2(custom_normals[info.
corner]);
1223 average_custom_normal /= local_corners_in_fan.size();
1227 if (!r_fan_spaces) {
1232 for (
const int i : local_corners_in_fan.
index_range()) {
1233 const VertCornerInfo &info = corner_infos[local_corners_in_fan[i]];
1234 fan_corners[i] = info.
corner;
1236 r_local_space_groups->
append({std::move(fan_corners), fan_space});
1265 Vector<VertCornerInfo, 16> corner_infos;
1266 LocalEdgeVectorSet local_edge_by_vert;
1267 Vector<VertEdgeInfo, 16> edge_infos;
1268 Vector<float3, 16> edge_dirs;
1269 Vector<bool, 16> local_corner_visited;
1270 Vector<int, 16> corners_in_fan;
1272 Vector<CornerSpaceGroup, 0> *local_space_groups = r_fan_spaces ? &space_groups.local() :
1275 for (const int vert : range) {
1276 const float3 vert_position = vert_positions[vert];
1277 const Span<int> vert_faces = vert_to_face_map[vert];
1281 if (vert_faces.is_empty()) {
1285 corner_infos.resize(vert_faces.size());
1286 collect_corner_info(faces, corner_verts, vert_faces, vert, corner_infos);
1288 local_edge_by_vert.clear_and_keep_capacity();
1289 calc_local_edge_indices(corner_infos, local_edge_by_vert);
1292 edge_infos.resize(local_edge_by_vert.size());
1293 calc_connecting_edge_info(corner_edges, sharp_edges, sharp_faces, corner_infos, edge_infos);
1295 edge_dirs.resize(edge_infos.size());
1296 calc_edge_directions(vert_positions, local_edge_by_vert, vert_position, edge_dirs);
1303 int visited_count = 0;
1304 local_corner_visited.resize(vert_faces.size());
1305 local_corner_visited.fill(false);
1307 int start_local_corner = 0;
1309 corners_in_fan.clear();
1310 traverse_fan_local_corners(corner_infos, edge_infos, start_local_corner, corners_in_fan);
1312 float3 fan_normal = accumulate_fan_normal(
1313 corner_infos, edge_dirs, face_normals, corners_in_fan);
1315 if (!custom_normals.is_empty() || r_fan_spaces) {
1316 handle_fan_result_and_custom_normals(custom_normals,
1322 local_space_groups);
1325 for (const int local_corner : corners_in_fan) {
1326 const VertCornerInfo &info = corner_infos[local_corner];
1327 r_corner_normals[info.corner] = fan_normal;
1330 visited_count += corners_in_fan.size();
1331 if (visited_count == corner_infos.size()) {
1335 local_corner_visited.as_mutable_span().fill_indices(corners_in_fan.as_span(), true);
1336 BLI_assert(!local_corner_visited.as_span().take_front(start_local_corner).contains(false));
1337 BLI_assert(local_corner_visited.as_span().drop_front(start_local_corner).contains(false));
1339 while (local_corner_visited[start_local_corner]) {
1340 start_local_corner++;
1343 BLI_assert(visited_count == corner_infos.size());
1347 if (!r_fan_spaces) {
1355 space_groups_count.
append(groups.size());
1356 all_space_groups.
append(std::move(groups));
1358 space_groups_count.
append(0);
1360 space_groups_count);
1362 r_fan_spaces->spaces.reinitialize(space_offsets.
total_size());
1363 r_fan_spaces->corner_space_indices.reinitialize(corner_verts.size());
1364 if (r_fan_spaces->create_corners_by_space) {
1365 r_fan_spaces->corners_by_space.reinitialize(space_offsets.
total_size());
1371 const int64_t mean_size = std::max<int64_t>(1,
1374 threading::parallel_for(all_space_groups.
index_range(), grain_size, [&](
const IndexRange range) {
1375 for (const int thread_i : range) {
1376 Vector<CornerSpaceGroup, 0> &local_space_groups = all_space_groups[thread_i];
1377 for (const int group_i : local_space_groups.index_range()) {
1378 const int space_index = space_offsets[thread_i][group_i];
1379 r_fan_spaces->spaces[space_index] = local_space_groups[group_i].space;
1380 r_fan_spaces->corner_space_indices.as_mutable_span().fill_indices(
1381 local_space_groups[group_i].fan_corners.as_span(), space_index);
1383 if (!r_fan_spaces->create_corners_by_space) {
1386 for (const int group_i : local_space_groups.index_range()) {
1387 const int space_index = space_offsets[thread_i][group_i];
1388 r_fan_spaces->corners_by_space[space_index] = std::move(
1389 local_space_groups[group_i].fan_corners);
1417 const bool use_vertices,
1450 if (
is_zero_v3(r_custom_corner_normals[i])) {
1451 copy_v3_v3(r_custom_corner_normals[i], vert_normals[i]);
1457 if (
is_zero_v3(r_custom_corner_normals[i])) {
1458 copy_v3_v3(r_custom_corner_normals[i], corner_normals[i]);
1470 done_corners.
fill(
true);
1474 if (done_corners[i]) {
1491 done_corners[i].set();
1495 int prev_corner = -1;
1496 const float *org_nor =
nullptr;
1499 const int corner = fan_corners[i];
1500 float *nor = r_custom_corner_normals[corner];
1510 const IndexRange face = faces[corner_to_face[corner]];
1512 const int edge = corner_edges[corner];
1513 const int edge_prev = corner_edges[corner_prev];
1514 const int prev_edge = corner_edges[prev_corner];
1515 sharp_edges[prev_edge == edge_prev ? prev_edge : edge] =
true;
1520 prev_corner = corner;
1521 done_corners[corner].set();
1528 if (fan_corners.
size() > 1 && org_nor) {
1529 const int corner = fan_corners.
last();
1530 float *nor = r_custom_corner_normals[corner];
1533 const IndexRange face = faces[corner_to_face[corner]];
1535 const int edge = corner_edges[corner];
1536 const int edge_prev = corner_edges[corner_prev];
1537 const int prev_edge = corner_edges[prev_corner];
1538 sharp_edges[prev_edge == edge_prev ? prev_edge : edge] =
true;
1561 done_corners[i].reset();
1563 printf(
"WARNING! Still getting invalid nullptr corner space in second for loop %d!\n", i);
1567 if (!done_corners[i]) {
1577 if (fan_corners.
size() < 2) {
1578 const int nidx = use_vertices ? corner_verts[i] : i;
1580 r_custom_corner_normals[nidx]);
1581 done_corners[i].reset();
1585 for (
const int corner : fan_corners) {
1586 const int nidx = use_vertices ? corner_verts[corner] : corner;
1587 avg_nor += r_custom_corner_normals[nidx];
1588 done_corners[corner].reset();
1591 mul_v3_fl(avg_nor, 1.0f /
float(fan_corners.size()));
1593 lnors_spacearr.
spaces[space_index], avg_nor);
1595 r_clnors_data.
fill_indices(fan_corners, clnor_data_tmp);
1621 r_custom_corner_normals,
1647 r_custom_vert_normals,
1654 const bool use_vertices)
1659 if (!custom_normals) {
1668 mesh.corner_verts(),
1669 mesh.corner_edges(),
1670 mesh.vert_to_face_map(),
1671 mesh.vert_normals_true(),
1672 mesh.face_normals_true(),
1677 custom_normals.
span);
1688 for (const int i : range) {
1689 normals[i] = math::normalize(normals[i]);
1774 const std::optional<bke::AttributeMetaData> custom_normal = attributes.
lookup_meta_data(
1776 if (!custom_normal) {
1797#undef LNOR_SPACE_TRIGO_THRESHOLD
#define BLI_ASSERT_UNIT_V3(v)
#define BLI_MEMARENA_STD_BUFSIZE
#define PRF_scope(category)
#define BLI_assert_unreachable()
#define POINTER_FROM_INT(i)
constexpr const T * data() const
const CPPType & type() const
VArray< T > typed() const
constexpr int64_t last(const int64_t n=0) const
constexpr int64_t size() const
constexpr IndexRange index_range() const
constexpr void fill_indices(Span< IndexT > indices, const T &value) const
constexpr const T & first() const
constexpr int64_t size() const
constexpr const T & last(const int64_t n=0) const
constexpr IndexRange index_range() const
constexpr bool is_empty() const
int64_t index_of_or_add(const Key &key)
void reserve(const int64_t n)
void append(const T &value)
IndexRange index_range() const
MutableSpan< T > as_mutable_span()
void append_unchecked(const T &value)
void reserve(const int64_t min_capacity)
void reinitialize(const int64_t new_size)
void fill(const bool value)
GAttributeReader lookup_or_default(StringRef name, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
std::optional< AttributeMetaData > lookup_meta_data(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())
void store_varray(const VArray< float3 > &data)
std::variant< UseTrueCache, Vector< float3 >, Span< float3 > > data
MutableSpan< float3 > ensure_vector_size(const int size)
Span< float3 > get_span() const
void store_vector(Vector< float3 > &&data)
void add_corner_fan_normals()
std::optional< bke::AttrDomain > result_domain
void add_domain(bke::AttrDomain domain)
void add_free_normals(bke::AttrDomain domain)
void add_no_custom_normals(bke::MeshNormalDomain domain)
void add_mesh(const Mesh &mesh)
IndexRange index_range() const
VecBase< short, 2 > short2
VecBase< float, 3 > float3
ccl_device_inline float beta(const float x, const float y)
#define LNOR_SPACE_TRIGO_THRESHOLD
#define IS_EDGE_SHARP(_e2l)
std::monostate EdgeUninitialized
int edge_other_vert(const int2 edge, const int vert)
static CornerNormalSpace corner_fan_space_define(const float3 &lnor, const float3 &vec_ref, const float3 &vec_other, const Span< float3 > edge_vectors)
static float3 normal_calc_ngon(const Span< float3 > vert_positions, const Span< int > face_verts)
static void mesh_normals_corner_custom_set(const Span< float3 > positions, const OffsetIndices< int > faces, const Span< int > corner_verts, const Span< int > corner_edges, const GroupedSpan< int > vert_to_face_map, const Span< float3 > vert_normals, const Span< float3 > face_normals, const Span< bool > sharp_faces, const bool use_vertices, MutableSpan< float3 > r_custom_corner_normals, MutableSpan< bool > sharp_edges, MutableSpan< short2 > r_clnors_data)
static float3 corner_space_custom_data_to_normal(const CornerNormalSpace &lnor_space, const short2 clnor_data)
constexpr AttributeMetaData CORNER_FAN_META_DATA
float3 face_normal_calc(Span< float3 > vert_positions, Span< int > face_verts)
static void calc_edge_directions(const Span< float3 > vert_positions, const Span< int > local_edge_by_vert, const float3 &vert_position, MutableSpan< float3 > edge_dirs)
static void mix_normals_vert_to_face(const OffsetIndices< int > faces, const Span< int > corner_verts, const Span< float3 > vert_normals, MutableSpan< float3 > face_normals)
int face_corner_prev(const IndexRange face, const int corner)
static void mix_normals_corner_to_vert(const Span< float3 > vert_positions, const OffsetIndices< int > faces, const Span< int > corner_verts, const GroupedSpan< int > vert_to_face_map, const Span< float3 > corner_normals, MutableSpan< float3 > vert_normals)
int face_find_corner_from_vert(const IndexRange face, const Span< int > corner_verts, const int vert)
static void calc_local_edge_indices(MutableSpan< VertCornerInfo > corner_infos, LocalEdgeVectorSet &r_other_vert_to_edge)
static void mesh_set_custom_normals(Mesh &mesh, MutableSpan< float3 > r_custom_nors, const bool use_vertices)
static void traverse_fan_local_corners(const Span< VertCornerInfo > corner_infos, const Span< VertEdgeInfo > edge_infos, const int start_local_corner, Vector< int, 16 > &result_fan)
static float3 accumulate_fan_normal(const Span< VertCornerInfo > corner_infos, const Span< float3 > edge_dirs, const Span< float3 > face_normals, const Span< int > local_corners_in_fan)
static void calc_connecting_edge_info(const Span< int > corner_edges, const Span< bool > sharp_edges, const Span< bool > sharp_faces, const Span< VertCornerInfo > corner_infos, MutableSpan< VertEdgeInfo > edge_infos)
Array< int > build_corner_to_face_map(OffsetIndices< int > faces)
static void add_corner_to_edge(const Span< int > corner_edges, const Span< bool > sharp_edges, const int local_corner, const int corner, const int other_corner, const bool winding_torwards_vert, VertEdgeInfo &info)
static void mix_normals_corner_to_face(const OffsetIndices< int > faces, const Span< float3 > corner_normals, MutableSpan< float3 > face_normals)
bool is_corner_fan_normals(const AttributeMetaData &meta_data)
void normals_calc_corners(Span< float3 > vert_positions, OffsetIndices< int > faces, Span< int > corner_verts, Span< int > corner_edges, GroupedSpan< int > vert_to_face_map, Span< float3 > face_normals, Span< bool > sharp_edges, Span< bool > sharp_faces, Span< short2 > custom_normals, CornerNormalSpaceArray *r_fan_spaces, MutableSpan< float3 > r_corner_normals)
void normals_corner_custom_set_from_verts(Span< float3 > vert_positions, OffsetIndices< int > faces, Span< int > corner_verts, Span< int > corner_edges, GroupedSpan< int > vert_to_face_map, Span< float3 > vert_normals, Span< float3 > face_normals, Span< bool > sharp_faces, MutableSpan< bool > sharp_edges, MutableSpan< float3 > r_custom_vert_normals, MutableSpan< short2 > r_clnors_data)
static bke::AttrDomain normal_domain_to_domain(bke::MeshNormalDomain domain)
VectorSet< int, 16, DefaultProbingStrategy, DefaultHash< int >, DefaultEquality< int >, SimpleVectorSetSlot< int, int >, GuardedAllocator > LocalEdgeVectorSet
static void collect_corner_info(const OffsetIndices< int > faces, const Span< int > corner_verts, const Span< int > vert_faces, const int vert, MutableSpan< VertCornerInfo > r_corner_infos)
short2 corner_space_custom_normal_to_data(const CornerNormalSpace &lnor_space, const float3 &custom_lnor)
void edges_sharp_from_angle_set(OffsetIndices< int > faces, Span< int > corner_verts, Span< int > corner_edges, Span< float3 > face_normals, Span< int > corner_to_face, Span< bool > sharp_faces, const float split_angle, MutableSpan< bool > sharp_edges)
int face_corner_next(const IndexRange face, const int corner)
void normals_calc_verts(Span< float3 > vert_positions, OffsetIndices< int > faces, Span< int > corner_verts, GroupedSpan< int > vert_to_face_map, Span< float3 > face_normals, MutableSpan< float3 > vert_normals)
static void mesh_edges_sharp_tag(const OffsetIndices< int > faces, const Span< int > corner_verts, const Span< int > corner_edges, const Span< int > corner_to_face_map, const Span< float3 > face_normals, const Span< bool > sharp_faces, const Span< bool > sharp_edges, const float split_angle, MutableSpan< int2 > edge_to_corners, MutableSpan< bool > r_sharp_edges)
static BLI_NOINLINE void handle_fan_result_and_custom_normals(const Span< short2 > custom_normals, const Span< VertCornerInfo > corner_infos, const Span< float3 > edge_dirs, const Span< int > local_corners_in_fan, float3 &fan_normal, CornerNormalSpaceArray *r_fan_spaces, Vector< CornerSpaceGroup, 0 > *r_local_space_groups)
void normals_corner_custom_set(Span< float3 > vert_positions, OffsetIndices< int > faces, Span< int > corner_verts, Span< int > corner_edges, GroupedSpan< int > vert_to_face_map, Span< float3 > vert_normals, Span< float3 > face_normals, Span< bool > sharp_faces, MutableSpan< bool > sharp_edges, MutableSpan< float3 > r_custom_corner_normals, MutableSpan< short2 > r_clnors_data)
std::variant< EdgeUninitialized, EdgeOneCorner, EdgeTwoCorners, EdgeSharp > VertEdgeInfo
void normals_calc_faces(Span< float3 > vert_positions, OffsetIndices< int > faces, Span< int > corner_verts, MutableSpan< float3 > face_normals)
static void normalize_vecs(MutableSpan< float3 > normals)
void mesh_set_custom_normals_normalized(Mesh &mesh, MutableSpan< float3 > corner_normals)
void mesh_set_custom_normals_from_verts(Mesh &mesh, MutableSpan< float3 > vert_normals)
void mesh_vert_normals_assign(Mesh &mesh, Span< float3 > vert_normals)
void mesh_set_custom_normals_from_verts_normalized(Mesh &mesh, MutableSpan< float3 > vert_normals)
void mesh_set_custom_normals(Mesh &mesh, MutableSpan< float3 > corner_normals)
constexpr ParallelGrainSize grain_size(int grain_size)
const MultiFunction & lookup(UString id)
VecBase< T, 3 > normal_tri(const VecBase< T, 3 > &v1, const VecBase< T, 3 > &v2, const VecBase< T, 3 > &v3)
float safe_acos_approx(float x)
T dot(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
AxisSigned cross(const AxisSigned a, const AxisSigned b)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
OffsetIndices< int > accumulate_counts_to_offsets(MutableSpan< int > counts_to_offsets, int start_offset=0)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void BLI_memarena_merge(MemArena *ma_dst, MemArena *ma_src)
MemArena * BLI_memarena_new(size_t bufsize, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(2) ATTR_MALLOC
MINLINE void copy_v3_v3(float r[3], const float a[3])
void BKE_lnor_spacearr_tls_join(MLoopNorSpaceArray *lnors_spacearr, MLoopNorSpaceArray *lnors_spacearr_tls)
MINLINE void mul_v3_fl(float r[3], float f)
void BKE_lnor_spacearr_tls_init(MLoopNorSpaceArray *lnors_spacearr, MLoopNorSpaceArray *lnors_spacearr_tls)
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
VecBase< int32_t, 2 > int2
void BKE_lnor_space_define(MLoopNorSpace *lnor_space, const float lnor[3], const float vec_ref[3], const float vec_other[3], Span< float3 > edge_vectors)
void BKE_lnor_spacearr_init(MLoopNorSpaceArray *lnors_spacearr, int numLoops, char data_type)
BMesh const char void * data
float normal_quad_v3(float n[3], const float v1[3], const float v2[3], const float v3[3], const float v4[3])
void BKE_lnor_spacearr_clear(MLoopNorSpaceArray *lnors_spacearr)
void BLI_linklist_prepend_nlink(LinkNode **listp, void *ptr, LinkNode *nlink) ATTR_NONNULL(1
void BLI_memarena_clear(MemArena *ma) ATTR_NONNULL(1)
MINLINE void copy_v2_v2_short(short r[2], const short a[2])
void BKE_lnor_space_custom_normal_to_data(const MLoopNorSpace *lnor_space, const float custom_lnor[3], short r_clnor_data[2])
void BKE_lnor_space_add_loop(MLoopNorSpaceArray *lnors_spacearr, MLoopNorSpace *lnor_space, int corner, void *bm_loop, bool is_single)
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
void * BLI_memarena_alloc(MemArena *ma, size_t size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_ALLOC_SIZE(2)
MINLINE float normalize_v3(float n[3])
void BKE_lnor_spacearr_free(MLoopNorSpaceArray *lnors_spacearr)
@ MLNOR_SPACEARR_LOOP_INDEX
@ MLNOR_SPACEARR_BMLOOP_PTR
MINLINE bool compare_v3v3(const float v1[3], const float v2[3], float limit) ATTR_WARN_UNUSED_RESULT
VecBase< int16_t, 2 > short2
PythonProbingStrategy<> DefaultProbingStrategy
MINLINE void add_newell_cross_v3_v3v3(float n[3], const float v_prev[3], const float v_curr[3])
void BKE_lnor_space_custom_data_to_normal(const MLoopNorSpace *lnor_space, const short clnor_data[2], float r_custom_lnor[3])
bool BKE_mesh_vert_normals_are_dirty(const Mesh *mesh)
VecBase< float, 3 > float3
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
void * BLI_memarena_calloc(MemArena *ma, size_t size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_ALLOC_SIZE(2)
MINLINE bool is_zero_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
MINLINE float unit_short_to_float(const short val)
bool BKE_mesh_face_normals_are_dirty(const Mesh *mesh)
void BLI_memarena_free(MemArena *ma) ATTR_NONNULL(1)
MLoopNorSpace * BKE_lnor_space_create(MLoopNorSpaceArray *lnors_spacearr)
MINLINE short unit_float_to_short(const float val)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
struct LinkNode * loops_pool
MLoopNorSpace ** lspacearr
bke::MeshRuntime * runtime
MutableVArraySpan< T > span
bool create_corners_by_space
Array< int > corner_space_indices
Vector< Array< int > > corners_by_space
Vector< CornerNormalSpace > spaces
bool winding_torwards_vert
OffsetIndices< int > offsets