Blender V4.3
mesh_normals.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
13#include <climits>
14
15#include "MEM_guardedalloc.h"
16
17#include "BLI_math_geom.h"
18#include "BLI_math_vector.h"
19
20#include "BLI_array_utils.hh"
21#include "BLI_bit_vector.hh"
22#include "BLI_linklist.h"
23#include "BLI_math_base.hh"
24#include "BLI_math_vector.hh"
25#include "BLI_memarena.h"
26#include "BLI_span.hh"
27#include "BLI_task.hh"
28#include "BLI_utildefines.h"
29
30#include "BKE_attribute.hh"
31#include "BKE_customdata.hh"
32#include "BKE_global.hh"
33#include "BKE_mesh.hh"
34#include "BKE_mesh_mapping.hh"
35
36// #define DEBUG_TIME
37
38#ifdef DEBUG_TIME
39# include "BLI_timeit.hh"
40#endif
41
42/* -------------------------------------------------------------------- */
48namespace blender::bke {
49
51{
52 mesh.runtime->vert_normals_cache.ensure([&](Vector<float3> &r_data) { r_data = vert_normals; });
53}
54
56{
57 mesh.runtime->vert_normals_cache.ensure(
58 [&](Vector<float3> &r_data) { r_data = std::move(vert_normals); });
59}
60
61} // namespace blender::bke
62
64{
65 return mesh->runtime->vert_normals_cache.is_dirty();
66}
67
69{
70 return mesh->runtime->face_normals_cache.is_dirty();
71}
72
75namespace blender::bke::mesh {
76
77/* -------------------------------------------------------------------- */
81/*
82 * COMPUTE POLY NORMAL
83 *
84 * Computes the normal of a planar
85 * face See Graphics Gems for
86 * computing newell normal.
87 */
88static float3 normal_calc_ngon(const Span<float3> vert_positions, const Span<int> face_verts)
89{
90 float3 normal(0);
91
92 /* Newell's Method */
93 const float *v_prev = vert_positions[face_verts.last()];
94 for (const int i : face_verts.index_range()) {
95 const float *v_curr = vert_positions[face_verts[i]];
96 add_newell_cross_v3_v3v3(normal, v_prev, v_curr);
97 v_prev = v_curr;
98 }
99
100 if (UNLIKELY(normalize_v3(normal) == 0.0f)) {
101 /* Other axis are already set to zero. */
102 normal[2] = 1.0f;
103 }
104
105 return normal;
106}
107
108float3 face_normal_calc(const Span<float3> vert_positions, const Span<int> face_verts)
109{
110 float3 normal;
111 if (face_verts.size() == 4) {
112 normal_quad_v3(normal,
113 vert_positions[face_verts[0]],
114 vert_positions[face_verts[1]],
115 vert_positions[face_verts[2]],
116 vert_positions[face_verts[3]]);
117 }
118 else if (face_verts.size() == 3) {
119 normal = math::normal_tri(vert_positions[face_verts[0]],
120 vert_positions[face_verts[1]],
121 vert_positions[face_verts[2]]);
122 }
123 else {
124 BLI_assert(face_verts.size() > 4);
125 normal = normal_calc_ngon(vert_positions, face_verts);
126 }
127
128 if (UNLIKELY(math::is_zero(normal))) {
129 normal.z = 1.0f;
130 }
131
132 BLI_ASSERT_UNIT_V3(normal);
133 return normal;
134}
135
138/* -------------------------------------------------------------------- */
145void normals_calc_faces(const Span<float3> positions,
146 const OffsetIndices<int> faces,
147 const Span<int> corner_verts,
148 MutableSpan<float3> face_normals)
149{
150 BLI_assert(faces.size() == face_normals.size());
151 threading::parallel_for(faces.index_range(), 1024, [&](const IndexRange range) {
152 for (const int i : range) {
153 face_normals[i] = normal_calc_ngon(positions, corner_verts.slice(faces[i]));
154 }
155 });
156}
157
158void normals_calc_verts(const Span<float3> vert_positions,
159 const OffsetIndices<int> faces,
160 const Span<int> corner_verts,
161 const GroupedSpan<int> vert_to_face_map,
162 const Span<float3> face_normals,
163 MutableSpan<float3> vert_normals)
164{
165 const Span<float3> positions = vert_positions;
166 threading::parallel_for(positions.index_range(), 1024, [&](const IndexRange range) {
167 for (const int vert : range) {
168 const Span<int> vert_faces = vert_to_face_map[vert];
169 if (vert_faces.is_empty()) {
170 vert_normals[vert] = math::normalize(positions[vert]);
171 continue;
172 }
173
174 float3 vert_normal(0);
175 for (const int face : vert_faces) {
176 const int2 adjacent_verts = face_find_adjacent_verts(faces[face], corner_verts, vert);
177 const float3 dir_prev = math::normalize(positions[adjacent_verts[0]] - positions[vert]);
178 const float3 dir_next = math::normalize(positions[adjacent_verts[1]] - positions[vert]);
179 const float factor = math::safe_acos_approx(math::dot(dir_prev, dir_next));
180
181 vert_normal += face_normals[face] * factor;
182 }
183
184 vert_normals[vert] = math::normalize(vert_normal);
185 }
186 });
187}
188
191} // namespace blender::bke::mesh
192
193/* -------------------------------------------------------------------- */
197blender::bke::MeshNormalDomain Mesh::normals_domain(const bool support_sharp_face) const
198{
199 using namespace blender;
200 using namespace blender::bke;
201 if (this->faces_num == 0) {
202 return MeshNormalDomain::Point;
203 }
204
206 return MeshNormalDomain::Corner;
207 }
208
209 const AttributeAccessor attributes = this->attributes();
210 const VArray<bool> sharp_faces = *attributes.lookup_or_default<bool>(
211 "sharp_face", AttrDomain::Face, false);
212
213 const array_utils::BooleanMix face_mix = array_utils::booleans_mix_calc(sharp_faces);
214 if (face_mix == array_utils::BooleanMix::AllTrue) {
215 return MeshNormalDomain::Face;
216 }
217
218 const VArray<bool> sharp_edges = *attributes.lookup_or_default<bool>(
219 "sharp_edge", AttrDomain::Edge, false);
220 const array_utils::BooleanMix edge_mix = array_utils::booleans_mix_calc(sharp_edges);
221 if (edge_mix == array_utils::BooleanMix::AllTrue) {
222 return MeshNormalDomain::Face;
223 }
224
225 if (edge_mix == array_utils::BooleanMix::AllFalse &&
226 (face_mix == array_utils::BooleanMix::AllFalse || support_sharp_face))
227 {
228 return MeshNormalDomain::Point;
229 }
230
231 return MeshNormalDomain::Corner;
232}
233
234blender::Span<blender::float3> Mesh::vert_normals() const
235{
236 using namespace blender;
237 using namespace blender::bke;
238 if (this->runtime->vert_normals_cache.is_cached()) {
239 return this->runtime->vert_normals_cache.data();
240 }
241 const Span<float3> positions = this->vert_positions();
242 const OffsetIndices faces = this->faces();
243 const Span<int> corner_verts = this->corner_verts();
244 const Span<float3> face_normals = this->face_normals();
245 const GroupedSpan<int> vert_to_face = this->vert_to_face_map();
246 this->runtime->vert_normals_cache.ensure([&](Vector<float3> &r_data) {
247 r_data.reinitialize(positions.size());
248 mesh::normals_calc_verts(positions, faces, corner_verts, vert_to_face, face_normals, r_data);
249 });
250 return this->runtime->vert_normals_cache.data();
251}
252
253blender::Span<blender::float3> Mesh::face_normals() const
254{
255 using namespace blender;
256 this->runtime->face_normals_cache.ensure([&](Vector<float3> &r_data) {
257 const Span<float3> positions = this->vert_positions();
258 const OffsetIndices faces = this->faces();
259 const Span<int> corner_verts = this->corner_verts();
260 r_data.reinitialize(faces.size());
261 bke::mesh::normals_calc_faces(positions, faces, corner_verts, r_data);
262 });
263 return this->runtime->face_normals_cache.data();
264}
265
266blender::Span<blender::float3> Mesh::corner_normals() const
267{
268 using namespace blender;
269 using namespace blender::bke;
270 this->runtime->corner_normals_cache.ensure([&](Vector<float3> &r_data) {
271 r_data.reinitialize(this->corners_num);
272 const OffsetIndices<int> faces = this->faces();
273 switch (this->normals_domain()) {
274 case MeshNormalDomain::Point: {
275 array_utils::gather(this->vert_normals(), this->corner_verts(), r_data.as_mutable_span());
276 break;
277 }
278 case MeshNormalDomain::Face: {
279 const Span<float3> face_normals = this->face_normals();
280 threading::parallel_for(faces.index_range(), 1024, [&](const IndexRange range) {
281 for (const int i : range) {
282 r_data.as_mutable_span().slice(faces[i]).fill(face_normals[i]);
283 }
284 });
285 break;
286 }
287 case MeshNormalDomain::Corner: {
288 const AttributeAccessor attributes = this->attributes();
289 const VArraySpan sharp_edges = *attributes.lookup<bool>("sharp_edge", AttrDomain::Edge);
290 const VArraySpan sharp_faces = *attributes.lookup<bool>("sharp_face", AttrDomain::Face);
291 const short2 *custom_normals = static_cast<const short2 *>(
293 mesh::normals_calc_corners(this->vert_positions(),
294 this->edges(),
295 this->faces(),
296 this->corner_verts(),
297 this->corner_edges(),
298 this->corner_to_face_map(),
299 this->vert_normals(),
300 this->face_normals(),
301 sharp_edges,
302 sharp_faces,
303 custom_normals,
304 nullptr,
305 r_data);
306 break;
307 }
308 }
309 });
310 return this->runtime->corner_normals_cache.data();
311}
312
314 const int numLoops,
315 const char data_type)
316{
317 if (!(lnors_spacearr->lspacearr && lnors_spacearr->loops_pool)) {
318 MemArena *mem;
319
320 if (!lnors_spacearr->mem) {
321 lnors_spacearr->mem = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__);
322 }
323 mem = lnors_spacearr->mem;
324 if (numLoops > 0) {
325 lnors_spacearr->lspacearr = (MLoopNorSpace **)BLI_memarena_calloc(
326 mem, sizeof(MLoopNorSpace *) * size_t(numLoops));
327 lnors_spacearr->loops_pool = (LinkNode *)BLI_memarena_alloc(
328 mem, sizeof(LinkNode) * size_t(numLoops));
329 }
330 else {
331 lnors_spacearr->lspacearr = nullptr;
332 lnors_spacearr->loops_pool = nullptr;
333 }
334
335 lnors_spacearr->spaces_num = 0;
336 }
338 lnors_spacearr->data_type = data_type;
339}
340
342 MLoopNorSpaceArray *lnors_spacearr_tls)
343{
344 *lnors_spacearr_tls = *lnors_spacearr;
345 lnors_spacearr_tls->mem = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__);
346}
347
349 MLoopNorSpaceArray *lnors_spacearr_tls)
350{
351 BLI_assert(lnors_spacearr->data_type == lnors_spacearr_tls->data_type);
352 BLI_assert(lnors_spacearr->mem != lnors_spacearr_tls->mem);
353 lnors_spacearr->spaces_num += lnors_spacearr_tls->spaces_num;
354 BLI_memarena_merge(lnors_spacearr->mem, lnors_spacearr_tls->mem);
355 BLI_memarena_free(lnors_spacearr_tls->mem);
356 lnors_spacearr_tls->mem = nullptr;
357 BKE_lnor_spacearr_clear(lnors_spacearr_tls);
358}
359
361{
362 lnors_spacearr->spaces_num = 0;
363 lnors_spacearr->lspacearr = nullptr;
364 lnors_spacearr->loops_pool = nullptr;
365 if (lnors_spacearr->mem != nullptr) {
366 BLI_memarena_clear(lnors_spacearr->mem);
367 }
368}
369
371{
372 lnors_spacearr->spaces_num = 0;
373 lnors_spacearr->lspacearr = nullptr;
374 lnors_spacearr->loops_pool = nullptr;
375 BLI_memarena_free(lnors_spacearr->mem);
376 lnors_spacearr->mem = nullptr;
377}
378
380{
381 lnors_spacearr->spaces_num++;
382 return (MLoopNorSpace *)BLI_memarena_calloc(lnors_spacearr->mem, sizeof(MLoopNorSpace));
383}
384
385/* This threshold is a bit touchy (usual float precision issue), this value seems OK. */
386#define LNOR_SPACE_TRIGO_THRESHOLD (1.0f - 1e-4f)
387
388namespace blender::bke::mesh {
389
391 const float3 &vec_ref,
392 const float3 &vec_other,
393 const Span<float3> edge_vectors)
394{
395 CornerNormalSpace lnor_space{};
396 const float pi2 = float(M_PI) * 2.0f;
397 const float dtp_ref = math::dot(vec_ref, lnor);
398 const float dtp_other = math::dot(vec_other, lnor);
399
400 if (UNLIKELY(fabsf(dtp_ref) >= LNOR_SPACE_TRIGO_THRESHOLD ||
401 fabsf(dtp_other) >= LNOR_SPACE_TRIGO_THRESHOLD))
402 {
403 /* If vec_ref or vec_other are too much aligned with lnor, we can't build lnor space,
404 * tag it as invalid and abort. */
405 lnor_space.ref_alpha = lnor_space.ref_beta = 0.0f;
406 return lnor_space;
407 }
408
409 lnor_space.vec_lnor = lnor;
410
411 /* Compute ref alpha, average angle of all available edge vectors to lnor. */
412 if (!edge_vectors.is_empty()) {
413 float alpha = 0.0f;
414 for (const float3 &vec : edge_vectors) {
415 alpha += math::safe_acos_approx(math::dot(vec, lnor));
416 }
417 /* This piece of code shall only be called for more than one loop. */
418 /* NOTE: In theory, this could be `count > 2`,
419 * but there is one case where we only have two edges for two loops:
420 * a smooth vertex with only two edges and two faces (our Monkey's nose has that, e.g.).
421 */
422 BLI_assert(edge_vectors.size() >= 2);
423 lnor_space.ref_alpha = alpha / float(edge_vectors.size());
424 }
425 else {
426 lnor_space.ref_alpha = (math::safe_acos_approx(math::dot(vec_ref, lnor)) +
427 math::safe_acos_approx(math::dot(vec_other, lnor))) /
428 2.0f;
429 }
430
431 /* Project vec_ref on lnor's ortho plane. */
432 lnor_space.vec_ref = math::normalize(vec_ref - lnor * dtp_ref);
433 lnor_space.vec_ortho = math::normalize(math::cross(lnor, lnor_space.vec_ref));
434
435 /* Project vec_other on lnor's ortho plane. */
436 const float3 vec_other_proj = math::normalize(vec_other - lnor * dtp_other);
437
438 /* Beta is angle between ref_vec and other_vec, around lnor. */
439 const float dtp = math::dot(lnor_space.vec_ref, vec_other_proj);
441 const float beta = math::safe_acos_approx(dtp);
442 lnor_space.ref_beta = (math::dot(lnor_space.vec_ortho, vec_other_proj) < 0.0f) ? pi2 - beta :
443 beta;
444 }
445 else {
446 lnor_space.ref_beta = pi2;
447 }
448
449 return lnor_space;
450}
451
452} // namespace blender::bke::mesh
453
455 const float lnor[3],
456 const float vec_ref[3],
457 const float vec_other[3],
458 const blender::Span<blender::float3> edge_vectors)
459{
460 using namespace blender::bke::mesh;
461 const CornerNormalSpace space = corner_fan_space_define(lnor, vec_ref, vec_other, edge_vectors);
462 copy_v3_v3(lnor_space->vec_lnor, space.vec_lnor);
463 copy_v3_v3(lnor_space->vec_ref, space.vec_ref);
464 copy_v3_v3(lnor_space->vec_ortho, space.vec_ortho);
465 lnor_space->ref_alpha = space.ref_alpha;
466 lnor_space->ref_beta = space.ref_beta;
467}
468
470 MLoopNorSpace *lnor_space,
471 const int corner,
472 void *bm_loop,
473 const bool is_single)
474{
475 BLI_assert((lnors_spacearr->data_type == MLNOR_SPACEARR_LOOP_INDEX && bm_loop == nullptr) ||
476 (lnors_spacearr->data_type == MLNOR_SPACEARR_BMLOOP_PTR && bm_loop != nullptr));
477
478 lnors_spacearr->lspacearr[corner] = lnor_space;
479 if (bm_loop == nullptr) {
480 bm_loop = POINTER_FROM_INT(corner);
481 }
482 if (is_single) {
483 BLI_assert(lnor_space->loops == nullptr);
484 lnor_space->flags |= MLNOR_SPACE_IS_SINGLE;
485 lnor_space->loops = (LinkNode *)bm_loop;
486 }
487 else {
488 BLI_assert((lnor_space->flags & MLNOR_SPACE_IS_SINGLE) == 0);
489 BLI_linklist_prepend_nlink(&lnor_space->loops, bm_loop, &lnors_spacearr->loops_pool[corner]);
490 }
491}
492
493MINLINE float unit_short_to_float(const short val)
494{
495 return float(val) / float(SHRT_MAX);
496}
497
498MINLINE short unit_float_to_short(const float val)
499{
500 /* Rounding. */
501 return short(floorf(val * float(SHRT_MAX) + 0.5f));
502}
503
504namespace blender::bke::mesh {
505
507 const short2 clnor_data)
508{
509 /* NOP custom normal data or invalid lnor space, return. */
510 if (clnor_data[0] == 0 || lnor_space.ref_alpha == 0.0f || lnor_space.ref_beta == 0.0f) {
511 return lnor_space.vec_lnor;
512 }
513
514 float3 r_custom_lnor;
515
516 /* TODO: Check whether using #sincosf() gives any noticeable benefit
517 * (could not even get it working under linux though)! */
518 const float pi2 = float(M_PI * 2.0);
519 const float alphafac = unit_short_to_float(clnor_data[0]);
520 const float alpha = (alphafac > 0.0f ? lnor_space.ref_alpha : pi2 - lnor_space.ref_alpha) *
521 alphafac;
522 const float betafac = unit_short_to_float(clnor_data[1]);
523
524 mul_v3_v3fl(r_custom_lnor, lnor_space.vec_lnor, cosf(alpha));
525
526 if (betafac == 0.0f) {
527 madd_v3_v3fl(r_custom_lnor, lnor_space.vec_ref, sinf(alpha));
528 }
529 else {
530 const float sinalpha = sinf(alpha);
531 const float beta = (betafac > 0.0f ? lnor_space.ref_beta : pi2 - lnor_space.ref_beta) *
532 betafac;
533 madd_v3_v3fl(r_custom_lnor, lnor_space.vec_ref, sinalpha * cosf(beta));
534 madd_v3_v3fl(r_custom_lnor, lnor_space.vec_ortho, sinalpha * sinf(beta));
535 }
536
537 return r_custom_lnor;
538}
539
540} // namespace blender::bke::mesh
541
543 const short clnor_data[2],
544 float r_custom_lnor[3])
545{
546 using namespace blender::bke::mesh;
547 CornerNormalSpace space;
548 space.vec_lnor = lnor_space->vec_lnor;
549 space.vec_ref = lnor_space->vec_ref;
550 space.vec_ortho = lnor_space->vec_ortho;
551 space.ref_alpha = lnor_space->ref_alpha;
552 space.ref_beta = lnor_space->ref_beta;
553 copy_v3_v3(r_custom_lnor, corner_space_custom_data_to_normal(space, clnor_data));
554}
555
556namespace blender::bke::mesh {
557
559 const float3 &custom_lnor)
560{
561 /* We use zero vector as NOP custom normal (can be simpler than giving auto-computed `lnor`). */
562 if (is_zero_v3(custom_lnor) || compare_v3v3(lnor_space.vec_lnor, custom_lnor, 1e-4f)) {
563 return short2(0);
564 }
565
566 short2 r_clnor_data;
567
568 const float pi2 = float(M_PI * 2.0);
569 const float cos_alpha = math::dot(lnor_space.vec_lnor, custom_lnor);
570
571 const float alpha = math::safe_acos_approx(cos_alpha);
572 if (alpha > lnor_space.ref_alpha) {
573 /* Note we could stick to [0, pi] range here,
574 * but makes decoding more complex, not worth it. */
575 r_clnor_data[0] = unit_float_to_short(-(pi2 - alpha) / (pi2 - lnor_space.ref_alpha));
576 }
577 else {
578 r_clnor_data[0] = unit_float_to_short(alpha / lnor_space.ref_alpha);
579 }
580
581 /* Project custom lnor on (vec_ref, vec_ortho) plane. */
582 const float3 vec = math::normalize(lnor_space.vec_lnor * -cos_alpha + custom_lnor);
583
584 const float cos_beta = math::dot(lnor_space.vec_ref, vec);
585
586 if (cos_beta < LNOR_SPACE_TRIGO_THRESHOLD) {
587 float beta = math::safe_acos_approx(cos_beta);
588 if (math::dot(lnor_space.vec_ortho, vec) < 0.0f) {
589 beta = pi2 - beta;
590 }
591
592 if (beta > lnor_space.ref_beta) {
593 r_clnor_data[1] = unit_float_to_short(-(pi2 - beta) / (pi2 - lnor_space.ref_beta));
594 }
595 else {
596 r_clnor_data[1] = unit_float_to_short(beta / lnor_space.ref_beta);
597 }
598 }
599 else {
600 r_clnor_data[1] = 0;
601 }
602
603 return r_clnor_data;
604}
605
606} // namespace blender::bke::mesh
607
609 const float custom_lnor[3],
610 short r_clnor_data[2])
611{
612 using namespace blender::bke::mesh;
613 CornerNormalSpace space;
614 space.vec_lnor = lnor_space->vec_lnor;
615 space.vec_ref = lnor_space->vec_ref;
616 space.vec_ortho = lnor_space->vec_ortho;
617 space.ref_alpha = lnor_space->ref_alpha;
618 space.ref_beta = lnor_space->ref_beta;
619 copy_v2_v2_short(r_clnor_data, corner_space_custom_normal_to_data(space, custom_lnor));
620}
621
622namespace blender::bke::mesh {
623
643
644#define INDEX_UNSET INT_MIN
645#define INDEX_INVALID -1
646/* See comment about edge_to_corners below. */
647#define IS_EDGE_SHARP(_e2l) ELEM((_e2l)[1], INDEX_UNSET, INDEX_INVALID)
648
650 const Span<int> corner_verts,
651 const Span<int> corner_edges,
652 const Span<int> corner_to_face_map,
653 const Span<float3> face_normals,
654 const Span<bool> sharp_faces,
655 const Span<bool> sharp_edges,
656 const float split_angle,
657 MutableSpan<int2> edge_to_corners,
658 MutableSpan<bool> r_sharp_edges)
659{
660 const float split_angle_cos = cosf(split_angle);
661 auto face_is_smooth = [&](const int face_i) {
662 return sharp_faces.is_empty() || !sharp_faces[face_i];
663 };
664
665 for (const int face_i : faces.index_range()) {
666 for (const int corner : faces[face_i]) {
667 const int vert = corner_verts[corner];
668 const int edge = corner_edges[corner];
669
670 int2 &e2l = edge_to_corners[edge];
671
672 /* Check whether current edge might be smooth or sharp */
673 if ((e2l[0] | e2l[1]) == 0) {
674 /* 'Empty' edge until now, set e2l[0] (and e2l[1] to INDEX_UNSET to tag it as unset). */
675 e2l[0] = corner;
676 /* We have to check this here too, else we might miss some flat faces!!! */
677 e2l[1] = face_is_smooth(face_i) ? INDEX_UNSET : INDEX_INVALID;
678 }
679 else if (e2l[1] == INDEX_UNSET) {
680 const bool is_angle_sharp = math::dot(face_normals[corner_to_face_map[e2l[0]]],
681 face_normals[face_i]) < split_angle_cos;
682
683 /* Second corner using this edge, time to test its sharpness.
684 * An edge is sharp if it is tagged as such, or its face is not smooth,
685 * or both faces have opposed (flipped) normals, i.e. both corners on the same edge share
686 * the same vertex, or angle between both its faces' normals is above split_angle value. */
687 if (!face_is_smooth(face_i) || (!sharp_edges.is_empty() && sharp_edges[edge]) ||
688 vert == corner_verts[e2l[0]] || is_angle_sharp)
689 {
690 /* NOTE: we are sure that corner != 0 here ;). */
691 e2l[1] = INDEX_INVALID;
692
693 /* We want to avoid tagging edges as sharp when it is already defined as such by
694 * other causes than angle threshold. */
695 if (is_angle_sharp) {
696 r_sharp_edges[edge] = true;
697 }
698 }
699 else {
700 e2l[1] = corner;
701 }
702 }
703 else if (!IS_EDGE_SHARP(e2l)) {
704 /* More than two corners using this edge, tag as sharp if not yet done. */
705 e2l[1] = INDEX_INVALID;
706
707 /* We want to avoid tagging edges as sharp when it is already defined as such by
708 * other causes than angle threshold. */
709 r_sharp_edges[edge] = false;
710 }
711 /* Else, edge is already 'disqualified' (i.e. sharp)! */
712 }
713 }
714}
715
721 const Span<int> corner_verts,
722 const Span<int> corner_edges,
723 const Span<bool> sharp_faces,
724 const Span<bool> sharp_edges,
725 MutableSpan<int2> edge_to_corners)
726{
727 auto face_is_smooth = [&](const int face_i) {
728 return sharp_faces.is_empty() || !sharp_faces[face_i];
729 };
730
731 for (const int face_i : faces.index_range()) {
732 for (const int corner : faces[face_i]) {
733 const int vert = corner_verts[corner];
734 const int edge = corner_edges[corner];
735
736 int2 &e2l = edge_to_corners[edge];
737
738 /* Check whether current edge might be smooth or sharp */
739 if ((e2l[0] | e2l[1]) == 0) {
740 /* 'Empty' edge until now, set e2l[0] (and e2l[1] to INDEX_UNSET to tag it as unset). */
741 e2l[0] = corner;
742 /* We have to check this here too, else we might miss some flat faces!!! */
743 e2l[1] = !face_is_smooth(face_i) ? INDEX_INVALID : INDEX_UNSET;
744 }
745 else if (e2l[1] == INDEX_UNSET) {
746 /* Second corner using this edge, time to test its sharpness.
747 * An edge is sharp if it is tagged as such, or its face is not smooth,
748 * or both face have opposed (flipped) normals, i.e. both corners on the same edge share
749 * the same vertex. */
750 if (!face_is_smooth(face_i) || (!sharp_edges.is_empty() && sharp_edges[edge]) ||
751 vert == corner_verts[e2l[0]])
752 {
753 /* NOTE: we are sure that corner != 0 here ;). */
754 e2l[1] = INDEX_INVALID;
755 }
756 else {
757 e2l[1] = corner;
758 }
759 }
760 else if (!IS_EDGE_SHARP(e2l)) {
761 /* More than two corners using this edge, tag as sharp if not yet done. */
762 e2l[1] = INDEX_INVALID;
763 }
764 /* Else, edge is already 'disqualified' (i.e. sharp)! */
765 }
766 }
767}
768
770 const Span<int> corner_verts,
771 const Span<int> corner_edges,
772 const Span<float3> face_normals,
773 const Span<int> corner_to_face,
774 const Span<bool> sharp_faces,
775 const float split_angle,
776 MutableSpan<bool> sharp_edges)
777{
778 if (split_angle >= float(M_PI)) {
779 /* Nothing to do! */
780 return;
781 }
782
783 /* Mapping edge -> corners. See #bke::mesh::normals_calc_corners for details. */
784 Array<int2> edge_to_corners(sharp_edges.size(), int2(0));
785
787 corner_verts,
788 corner_edges,
789 corner_to_face,
790 face_normals,
791 sharp_faces,
792 sharp_edges,
793 split_angle,
794 edge_to_corners,
795 sharp_edges);
796}
797
798static void corner_manifold_fan_around_vert_next(const Span<int> corner_verts,
799 const OffsetIndices<int> faces,
800 const Span<int> corner_to_face,
801 const int2 e2lfan_curr,
802 const int vert_pivot,
803 int *r_fan_corner,
804 int *r_vert_corner)
805{
806 const int fan_corner_orig = *r_fan_corner;
807 const int vert_fan_orig = corner_verts[fan_corner_orig];
808
809 /* WARNING: This is rather complex!
810 * We have to find our next edge around the vertex (fan mode).
811 * First we find the next corner, which is either previous or next to fan_corner, depending
812 * whether both corners using current edge are in the same direction or not, and whether
813 * fan_corner actually uses the vertex we are fanning around!
814 * fan_corner is the index of the next corner here, and the next corner is not the real next one
815 * (i.e. not the future `fan_corner`). */
816 *r_fan_corner = (e2lfan_curr[0] == *r_fan_corner) ? e2lfan_curr[1] : e2lfan_curr[0];
817
818 BLI_assert(*r_fan_corner >= 0);
819
820 const int vert_fan_next = corner_verts[*r_fan_corner];
821 const IndexRange face_fan_next = faces[corner_to_face[*r_fan_corner]];
822 if ((vert_fan_orig == vert_fan_next && vert_fan_orig == vert_pivot) ||
823 !ELEM(vert_fan_orig, vert_fan_next, vert_pivot))
824 {
825 /* We need the previous corner, but current one is our vertex's corner. */
826 *r_vert_corner = *r_fan_corner;
827 *r_fan_corner = face_corner_prev(face_fan_next, *r_fan_corner);
828 }
829 else {
830 /* We need the next corner, which is also our vertex's corner. */
831 *r_fan_corner = face_corner_next(face_fan_next, *r_fan_corner);
832 *r_vert_corner = *r_fan_corner;
833 }
834}
835
837 const int corner,
838 const int space_index)
839{
840 const Span<int> corner_to_face = common_data->corner_to_face;
841 const Span<float3> face_normals = common_data->face_normals;
842 MutableSpan<float3> corner_normals = common_data->corner_normals;
843
844 corner_normals[corner] = face_normals[corner_to_face[corner]];
845
846 if (CornerNormalSpaceArray *lnors_spacearr = common_data->lnors_spacearr) {
847 const Span<float3> positions = common_data->positions;
848 const Span<int2> edges = common_data->edges;
849 const OffsetIndices faces = common_data->faces;
850 const Span<int> corner_verts = common_data->corner_verts;
851 const Span<int> corner_edges = common_data->corner_edges;
852 const Span<short2> clnors_data = common_data->clnors_data;
853
854 const int face_index = corner_to_face[corner];
855 const int corner_prev = mesh::face_corner_prev(faces[face_index], corner);
856
857 /* The vertex we are "fanning" around. */
858 const int vert_pivot = corner_verts[corner];
859 const int vert_2 = edge_other_vert(edges[corner_edges[corner]], vert_pivot);
860 const int vert_3 = edge_other_vert(edges[corner_edges[corner_prev]], vert_pivot);
861
862 const float3 vec_curr = math::normalize(positions[vert_2] - positions[vert_pivot]);
863 const float3 vec_prev = math::normalize(positions[vert_3] - positions[vert_pivot]);
864
865 CornerNormalSpace &space = lnors_spacearr->spaces[space_index];
866 space = corner_fan_space_define(corner_normals[corner], vec_curr, vec_prev, {});
867 lnors_spacearr->corner_space_indices[corner] = space_index;
868
869 if (!clnors_data.is_empty()) {
870 corner_normals[corner] = corner_space_custom_data_to_normal(space, clnors_data[corner]);
871 }
872
873 if (!lnors_spacearr->corners_by_space.is_empty()) {
874 lnors_spacearr->corners_by_space[space_index] = {corner};
875 }
876 }
877}
878
880 const int corner,
881 const int space_index,
882 Vector<float3, 16> *edge_vectors)
883{
884 CornerNormalSpaceArray *lnors_spacearr = common_data->lnors_spacearr;
885 MutableSpan<float3> corner_normals = common_data->corner_normals;
886
887 const Span<float3> positions = common_data->positions;
888 const Span<int2> edges = common_data->edges;
889 const OffsetIndices faces = common_data->faces;
890 const Span<int> corner_verts = common_data->corner_verts;
891 const Span<int> corner_edges = common_data->corner_edges;
892 const Span<int2> edge_to_corners = common_data->edge_to_corners;
893 const Span<int> corner_to_face = common_data->corner_to_face;
894 const Span<float3> face_normals = common_data->face_normals;
895 const Span<short2> clnors_data = common_data->clnors_data;
896
897 const int face_index = corner_to_face[corner];
898 const int corner_prev = face_corner_prev(faces[face_index], corner);
899
900 /* Sigh! we have to fan around current vertex, until we find the other non-smooth edge,
901 * and accumulate face normals into the vertex!
902 * Note in case this vertex has only one sharp edges, this is a waste because the normal is the
903 * same as the vertex normal, but I do not see any easy way to detect that (would need to count
904 * number of sharp edges per vertex, I doubt the additional memory usage would be worth it,
905 * especially as it should not be a common case in real-life meshes anyway). */
906 const int vert_pivot = corner_verts[corner]; /* The vertex we are "fanning" around! */
907
908 /* `corner` would be `corner_prev` if we needed that one. */
909 const int2 &edge_orig = edges[corner_edges[corner]];
910
911 float3 vec_curr;
912 float3 vec_prev;
913 float3 vec_org;
914 float3 lnor(0.0f);
915
916 int2 clnors_avg(0);
917
918 Vector<int, 32> processed_corners;
919
920 /* `vert_corner` the corner of our current edge might not be the corner of our current
921 * vertex!
922 */
923 int fan_corner = corner_prev;
924 int vert_corner = corner;
925
926 BLI_assert(fan_corner >= 0);
927 BLI_assert(vert_corner >= 0);
928
929 /* Only need to compute previous edge's vector once, then we can just reuse old current one! */
930 {
931 const int vert_2 = edge_other_vert(edge_orig, vert_pivot);
932 vec_org = math::normalize(positions[vert_2] - positions[vert_pivot]);
933 vec_prev = vec_org;
934
935 if (lnors_spacearr) {
936 edge_vectors->append(vec_org);
937 }
938 }
939
940 while (true) {
941 const int2 &edge = edges[corner_edges[fan_corner]];
942 /* Compute edge vectors.
943 * NOTE: We could pre-compute those into an array, in the first iteration, instead of computing
944 * them twice (or more) here. However, time gained is not worth memory and time lost,
945 * given the fact that this code should not be called that much in real-life meshes.
946 */
947 {
948 const int vert_2 = edge_other_vert(edge, vert_pivot);
949 vec_curr = math::normalize(positions[vert_2] - positions[vert_pivot]);
950 }
951
952 /* Code similar to accumulate_vertex_normals_poly_v3. */
953 /* Calculate angle between the two face edges incident on this vertex. */
954 lnor += face_normals[corner_to_face[fan_corner]] *
955 math::safe_acos_approx(math::dot(vec_curr, vec_prev));
956
957 processed_corners.append(vert_corner);
958
959 if (lnors_spacearr) {
960 if (edge != edge_orig) {
961 /* We store here all edges-normalized vectors processed. */
962 edge_vectors->append(vec_curr);
963 }
964 if (!lnors_spacearr->corners_by_space.is_empty()) {
965 lnors_spacearr->corners_by_space[space_index] = processed_corners.as_span();
966 }
967 if (!clnors_data.is_empty()) {
968 clnors_avg += int2(clnors_data[vert_corner]);
969 }
970 }
971
972 if (IS_EDGE_SHARP(edge_to_corners[corner_edges[fan_corner]]) || (edge == edge_orig)) {
973 /* Current edge is sharp and we have finished with this fan of faces around this vert,
974 * or this vert is smooth, and we have completed a full turn around it. */
975 break;
976 }
977
978 vec_prev = vec_curr;
979
980 /* Find next corner of the smooth fan. */
982 faces,
983 corner_to_face,
984 edge_to_corners[corner_edges[fan_corner]],
985 vert_pivot,
986 &fan_corner,
987 &vert_corner);
988 }
989
990 float length;
991 lnor = math::normalize_and_get_length(lnor, length);
992
993 /* If we are generating lnor spacearr, we can now define the one for this fan,
994 * and optionally compute final lnor from custom data too!
995 */
996 if (lnors_spacearr) {
997 if (UNLIKELY(length == 0.0f)) {
998 /* Use vertex normal as fallback! */
999 lnor = corner_normals[vert_corner];
1000 length = 1.0f;
1001 }
1002
1003 CornerNormalSpace &lnor_space = lnors_spacearr->spaces[space_index];
1004 lnor_space = corner_fan_space_define(lnor, vec_org, vec_curr, *edge_vectors);
1006 processed_corners.as_span(), space_index);
1007 edge_vectors->clear();
1008
1009 if (!clnors_data.is_empty()) {
1010 clnors_avg /= processed_corners.size();
1011 lnor = corner_space_custom_data_to_normal(lnor_space, short2(clnors_avg));
1012 }
1013 }
1014
1015 /* In case we get a zero normal here, just use vertex normal already set! */
1016 if (LIKELY(length != 0.0f)) {
1017 /* Copy back the final computed normal into all related corner-normals. */
1018 corner_normals.fill_indices(processed_corners.as_span(), lnor);
1019 }
1020}
1021
1028 const Span<int> corner_edges,
1029 const OffsetIndices<int> faces,
1030 const Span<int2> edge_to_corners,
1031 const Span<int> corner_to_face,
1032 const int2 e2l_prev,
1033 MutableBitSpan skip_corners,
1034 const int corner,
1035 const int corner_prev)
1036{
1037 /* The vertex we are "fanning" around. */
1038 const int vert_pivot = corner_verts[corner];
1039
1040 int2 e2lfan_curr = e2l_prev;
1041 if (IS_EDGE_SHARP(e2lfan_curr)) {
1042 /* Sharp corner, so not a cyclic smooth fan. */
1043 return false;
1044 }
1045
1046 /* `vert_corner` the corner of our current edge might not be the corner of our current
1047 * vertex!
1048 */
1049 int fan_corner = corner_prev;
1050 int vert_corner = corner;
1051
1052 BLI_assert(fan_corner >= 0);
1053 BLI_assert(vert_corner >= 0);
1054
1055 BLI_assert(!skip_corners[vert_corner]);
1056 skip_corners[vert_corner].set();
1057
1058 while (true) {
1059 /* Find next corner of the smooth fan. */
1061 corner_verts, faces, corner_to_face, e2lfan_curr, vert_pivot, &fan_corner, &vert_corner);
1062
1063 e2lfan_curr = edge_to_corners[corner_edges[fan_corner]];
1064
1065 if (IS_EDGE_SHARP(e2lfan_curr)) {
1066 /* Sharp corner/edge, so not a cyclic smooth fan. */
1067 return false;
1068 }
1069 /* Smooth corner/edge. */
1070 if (skip_corners[vert_corner]) {
1071 if (vert_corner == corner) {
1072 /* We walked around a whole cyclic smooth fan without finding any already-processed corner,
1073 * means we can use initial current / previous edge as start for this smooth fan. */
1074 return true;
1075 }
1076 /* Already checked in some previous looping, we can abort. */
1077 return false;
1078 }
1079
1080 /* We can skip it in future, and keep checking the smooth fan. */
1081 skip_corners[vert_corner].set();
1082 }
1083}
1084
1086 Vector<int, 32> &r_single_corners,
1087 Vector<int, 32> &r_fan_corners)
1088{
1089 const Span<int> corner_verts = common_data->corner_verts;
1090 const Span<int> corner_edges = common_data->corner_edges;
1091 const OffsetIndices faces = common_data->faces;
1092 const Span<int> corner_to_face = common_data->corner_to_face;
1093 const Span<int2> edge_to_corners = common_data->edge_to_corners;
1094
1095 BitVector<> skip_corners(corner_verts.size(), false);
1096
1097#ifdef DEBUG_TIME
1098 SCOPED_TIMER_AVERAGED(__func__);
1099#endif
1100
1101 /* We now know edges that can be smoothed (with their vector, and their two corners),
1102 * and edges that will be hard! Now, time to generate the normals.
1103 */
1104 for (const int face_index : faces.index_range()) {
1105 const IndexRange face = faces[face_index];
1106
1107 for (const int corner : face) {
1108 const int corner_prev = mesh::face_corner_prev(face, corner);
1109
1110#if 0
1111 printf("Checking corner %d / edge %u / vert %u (sharp edge: %d, skiploop: %d)",
1112 corner,
1113 corner_edges[corner],
1114 corner_verts[corner],
1115 IS_EDGE_SHARP(edge_to_corners[corner_edges[corner]]),
1116 skip_corners[corner]);
1117#endif
1118
1119 /* A smooth edge, we have to check for cyclic smooth fan case.
1120 * If we find a new, never-processed cyclic smooth fan, we can do it now using that
1121 * corner/edge as 'entry point', otherwise we can skip it. */
1122
1123 /* NOTE: In theory, we could make #corner_split_generator_check_cyclic_smooth_fan() store
1124 * vert_corner'es and edge indexes in two stacks, to avoid having to fan again around
1125 * the vert during actual computation of `clnor` & `clnorspace`.
1126 * However, this would complicate the code, add more memory usage, and despite its logical
1127 * complexity, #corner_manifold_fan_around_vert_next() is quite cheap in term of CPU cycles,
1128 * so really think it's not worth it. */
1129 if (!IS_EDGE_SHARP(edge_to_corners[corner_edges[corner]]) &&
1130 (skip_corners[corner] || !corner_split_generator_check_cyclic_smooth_fan(
1131 corner_verts,
1132 corner_edges,
1133 faces,
1134 edge_to_corners,
1135 corner_to_face,
1136 edge_to_corners[corner_edges[corner_prev]],
1137 skip_corners,
1138 corner,
1139 corner_prev)))
1140 {
1141 // printf("SKIPPING!\n");
1142 }
1143 else {
1144 if (IS_EDGE_SHARP(edge_to_corners[corner_edges[corner]]) &&
1145 IS_EDGE_SHARP(edge_to_corners[corner_edges[corner_prev]]))
1146 {
1147 /* Simple case (both edges around that vertex are sharp in current face),
1148 * this corner just takes its face normal. */
1149 r_single_corners.append(corner);
1150 }
1151 else {
1152 /* We do not need to check/tag corners as already computed. Due to the fact that a corner
1153 * only points to one of its two edges, the same fan will never be walked more than once.
1154 * Since we consider edges that have neighbor faces with inverted (flipped) normals as
1155 * sharp, we are sure that no fan will be skipped, even only considering the case (sharp
1156 * current edge, smooth previous edge), and not the alternative (smooth current edge,
1157 * sharp previous edge). All this due/thanks to the link between normals and corner
1158 * ordering (i.e. winding). */
1159 r_fan_corners.append(corner);
1160 }
1161 }
1162 }
1163 }
1164}
1165
1166void normals_calc_corners(const Span<float3> vert_positions,
1167 const Span<int2> edges,
1168 const OffsetIndices<int> faces,
1169 const Span<int> corner_verts,
1170 const Span<int> corner_edges,
1171 const Span<int> corner_to_face_map,
1172 const Span<float3> vert_normals,
1173 const Span<float3> face_normals,
1174 const Span<bool> sharp_edges,
1175 const Span<bool> sharp_faces,
1176 const short2 *clnors_data,
1177 CornerNormalSpaceArray *r_lnors_spacearr,
1178 MutableSpan<float3> r_corner_normals)
1179{
1194 Array<int2> edge_to_corners(edges.size(), int2(0));
1195
1196 CornerNormalSpaceArray _lnors_spacearr;
1197
1198#ifdef DEBUG_TIME
1199 SCOPED_TIMER_AVERAGED(__func__);
1200#endif
1201
1202 if (!r_lnors_spacearr && clnors_data) {
1203 /* We need to compute lnor spacearr if some custom lnor data are given to us! */
1204 r_lnors_spacearr = &_lnors_spacearr;
1205 }
1206
1207 /* Init data common to all tasks. */
1208 CornerSplitTaskDataCommon common_data;
1209 common_data.lnors_spacearr = r_lnors_spacearr;
1210 common_data.corner_normals = r_corner_normals;
1211 common_data.clnors_data = {clnors_data, clnors_data ? corner_verts.size() : 0};
1212 common_data.positions = vert_positions;
1213 common_data.edges = edges;
1214 common_data.faces = faces;
1215 common_data.corner_verts = corner_verts;
1216 common_data.corner_edges = corner_edges;
1217 common_data.edge_to_corners = edge_to_corners;
1218 common_data.corner_to_face = corner_to_face_map;
1219 common_data.face_normals = face_normals;
1220 common_data.vert_normals = vert_normals;
1221
1222 /* Pre-populate all corner normals as if their verts were all smooth.
1223 * This way we don't have to compute those later! */
1224 array_utils::gather(vert_normals, corner_verts, r_corner_normals, 1024);
1225
1226 /* This first corner check which edges are actually smooth, and compute edge vectors. */
1228 faces, corner_verts, corner_edges, sharp_faces, sharp_edges, edge_to_corners);
1229
1230 Vector<int, 32> single_corners;
1231 Vector<int, 32> fan_corners;
1232 corner_split_generator(&common_data, single_corners, fan_corners);
1233
1234 if (r_lnors_spacearr) {
1235 r_lnors_spacearr->spaces.reinitialize(single_corners.size() + fan_corners.size());
1236 r_lnors_spacearr->corner_space_indices = Array<int>(corner_verts.size(), -1);
1237 if (r_lnors_spacearr->create_corners_by_space) {
1238 r_lnors_spacearr->corners_by_space.reinitialize(r_lnors_spacearr->spaces.size());
1239 }
1240 }
1241
1242 threading::parallel_for(single_corners.index_range(), 1024, [&](const IndexRange range) {
1243 for (const int i : range) {
1244 const int corner = single_corners[i];
1245 lnor_space_for_single_fan(&common_data, corner, i);
1246 }
1247 });
1248
1249 threading::parallel_for(fan_corners.index_range(), 1024, [&](const IndexRange range) {
1250 Vector<float3, 16> edge_vectors;
1251 for (const int i : range) {
1252 const int corner = fan_corners[i];
1253 const int space_index = single_corners.size() + i;
1254 split_corner_normal_fan_do(&common_data, corner, space_index, &edge_vectors);
1255 }
1256 });
1257}
1258
1259#undef INDEX_UNSET
1260#undef INDEX_INVALID
1261#undef IS_EDGE_SHARP
1262
1274 const Span<int2> edges,
1275 const OffsetIndices<int> faces,
1276 const Span<int> corner_verts,
1277 const Span<int> corner_edges,
1278 const Span<float3> vert_normals,
1279 const Span<float3> face_normals,
1280 const Span<bool> sharp_faces,
1281 const bool use_vertices,
1282 MutableSpan<float3> r_custom_corner_normals,
1283 MutableSpan<bool> sharp_edges,
1284 MutableSpan<short2> r_clnors_data)
1285{
1286 /* We *may* make that poor #bke::mesh::normals_calc_corners() even more complex by making it
1287 * handling that feature too, would probably be more efficient in absolute. However, this
1288 * function *is not* performance-critical, since it is mostly expected to be called by IO add-ons
1289 * when importing custom normals, and modifier (and perhaps from some editing tools later?). So
1290 * better to keep some simplicity here, and just call #bke::mesh::normals_calc_corners() twice!
1291 */
1292 CornerNormalSpaceArray lnors_spacearr;
1293 lnors_spacearr.create_corners_by_space = true;
1294 BitVector<> done_corners(corner_verts.size(), false);
1295 Array<float3> corner_normals(corner_verts.size());
1296 const Array<int> corner_to_face = build_corner_to_face_map(faces);
1297
1298 /* Compute current lnor spacearr. */
1299 normals_calc_corners(positions,
1300 edges,
1301 faces,
1302 corner_verts,
1303 corner_edges,
1304 corner_to_face,
1305 vert_normals,
1306 face_normals,
1307 sharp_edges,
1308 sharp_faces,
1309 r_clnors_data.data(),
1310 &lnors_spacearr,
1311 corner_normals);
1312
1313 /* Set all given zero vectors to their default value. */
1314 if (use_vertices) {
1315 for (const int i : positions.index_range()) {
1316 if (is_zero_v3(r_custom_corner_normals[i])) {
1317 copy_v3_v3(r_custom_corner_normals[i], vert_normals[i]);
1318 }
1319 }
1320 }
1321 else {
1322 for (const int i : corner_verts.index_range()) {
1323 if (is_zero_v3(r_custom_corner_normals[i])) {
1324 copy_v3_v3(r_custom_corner_normals[i], corner_normals[i]);
1325 }
1326 }
1327 }
1328
1329 /* Now, check each current smooth fan (one lnor space per smooth fan!),
1330 * and if all its matching custom corner_normals are not (enough) equal, add sharp edges as
1331 * needed. This way, next time we run bke::mesh::normals_calc_corners(), we'll get lnor
1332 * spacearr/smooth fans matching given custom corner_normals. Note this code *will never* unsharp
1333 * edges! And quite obviously, when we set custom normals per vertices, running this is
1334 * absolutely useless. */
1335 if (use_vertices) {
1336 done_corners.fill(true);
1337 }
1338 else {
1339 for (const int i : corner_verts.index_range()) {
1340 if (lnors_spacearr.corner_space_indices[i] == -1) {
1341 /* This should not happen in theory, but in some rare case (probably ugly geometry)
1342 * we can get some missing loopspacearr at this point. :/
1343 * Maybe we should set those corners' edges as sharp? */
1344 done_corners[i].set();
1345 if (G.debug & G_DEBUG) {
1346 printf("WARNING! Getting invalid nullptr corner space for corner %d!\n", i);
1347 }
1348 continue;
1349 }
1350 if (done_corners[i]) {
1351 continue;
1352 }
1353
1354 const int space_index = lnors_spacearr.corner_space_indices[i];
1355 const Span<int> fan_corners = lnors_spacearr.corners_by_space[space_index];
1356
1357 /* Notes:
1358 * - In case of mono-corner smooth fan, we have nothing to do.
1359 * - Loops in this linklist are ordered (in reversed order compared to how they were
1360 * discovered by bke::mesh::normals_calc_corners(), but this is not a problem).
1361 * Which means if we find a mismatching clnor,
1362 * we know all remaining corners will have to be in a new, different smooth fan/lnor space.
1363 * - In smooth fan case, we compare each clnor against a ref one,
1364 * to avoid small differences adding up into a real big one in the end!
1365 */
1366 if (fan_corners.is_empty()) {
1367 done_corners[i].set();
1368 continue;
1369 }
1370
1371 int prev_corner = -1;
1372 const float *org_nor = nullptr;
1373
1374 for (int i = fan_corners.index_range().last(); i >= 0; i--) {
1375 const int corner = fan_corners[i];
1376 float *nor = r_custom_corner_normals[corner];
1377
1378 if (!org_nor) {
1379 org_nor = nor;
1380 }
1381 else if (dot_v3v3(org_nor, nor) < LNOR_SPACE_TRIGO_THRESHOLD) {
1382 /* Current normal differs too much from org one, we have to tag the edge between
1383 * previous corner's face and current's one as sharp.
1384 * We know those two corners do not point to the same edge,
1385 * since we do not allow reversed winding in a same smooth fan. */
1386 const IndexRange face = faces[corner_to_face[corner]];
1387 const int corner_prev = face_corner_prev(face, corner);
1388 const int edge = corner_edges[corner];
1389 const int edge_prev = corner_edges[corner_prev];
1390 const int prev_edge = corner_edges[prev_corner];
1391 sharp_edges[prev_edge == edge_prev ? prev_edge : edge] = true;
1392
1393 org_nor = nor;
1394 }
1395
1396 prev_corner = corner;
1397 done_corners[corner].set();
1398 }
1399
1400 /* We also have to check between last and first corners,
1401 * otherwise we may miss some sharp edges here!
1402 * This is just a simplified version of above while loop.
1403 * See #45984. */
1404 if (fan_corners.size() > 1 && org_nor) {
1405 const int corner = fan_corners.last();
1406 float *nor = r_custom_corner_normals[corner];
1407
1408 if (dot_v3v3(org_nor, nor) < LNOR_SPACE_TRIGO_THRESHOLD) {
1409 const IndexRange face = faces[corner_to_face[corner]];
1410 const int corner_prev = face_corner_prev(face, corner);
1411 const int edge = corner_edges[corner];
1412 const int edge_prev = corner_edges[corner_prev];
1413 const int prev_edge = corner_edges[prev_corner];
1414 sharp_edges[prev_edge == edge_prev ? prev_edge : edge] = true;
1415 }
1416 }
1417 }
1418
1419 /* And now, recompute our new auto `corner_normals` and lnor spacearr! */
1420 normals_calc_corners(positions,
1421 edges,
1422 faces,
1423 corner_verts,
1424 corner_edges,
1425 corner_to_face,
1426 vert_normals,
1427 face_normals,
1428 sharp_edges,
1429 sharp_faces,
1430 r_clnors_data.data(),
1431 &lnors_spacearr,
1432 corner_normals);
1433 }
1434
1435 /* And we just have to convert plain object-space custom normals to our
1436 * lnor space-encoded ones. */
1437 for (const int i : corner_verts.index_range()) {
1438 if (lnors_spacearr.corner_space_indices[i] == -1) {
1439 done_corners[i].reset();
1440 if (G.debug & G_DEBUG) {
1441 printf("WARNING! Still getting invalid nullptr corner space in second for loop %d!\n", i);
1442 }
1443 continue;
1444 }
1445 if (!done_corners[i]) {
1446 continue;
1447 }
1448
1449 const int space_index = lnors_spacearr.corner_space_indices[i];
1450 const Span<int> fan_corners = lnors_spacearr.corners_by_space[space_index];
1451
1452 /* Note we accumulate and average all custom normals in current smooth fan,
1453 * to avoid getting different clnors data (tiny differences in plain custom normals can
1454 * give rather huge differences in computed 2D factors). */
1455 if (fan_corners.size() < 2) {
1456 const int nidx = use_vertices ? corner_verts[i] : i;
1457 r_clnors_data[i] = corner_space_custom_normal_to_data(lnors_spacearr.spaces[space_index],
1458 r_custom_corner_normals[nidx]);
1459 done_corners[i].reset();
1460 }
1461 else {
1462 float3 avg_nor(0.0f);
1463 for (const int corner : fan_corners) {
1464 const int nidx = use_vertices ? corner_verts[corner] : corner;
1465 avg_nor += r_custom_corner_normals[nidx];
1466 done_corners[corner].reset();
1467 }
1468
1469 mul_v3_fl(avg_nor, 1.0f / float(fan_corners.size()));
1471 lnors_spacearr.spaces[space_index], avg_nor);
1472
1473 r_clnors_data.fill_indices(fan_corners, clnor_data_tmp);
1474 }
1475 }
1476}
1477
1478void normals_corner_custom_set(const Span<float3> vert_positions,
1479 const Span<int2> edges,
1480 const OffsetIndices<int> faces,
1481 const Span<int> corner_verts,
1482 const Span<int> corner_edges,
1483 const Span<float3> vert_normals,
1484 const Span<float3> face_normals,
1485 const Span<bool> sharp_faces,
1486 MutableSpan<bool> sharp_edges,
1487 MutableSpan<float3> r_custom_corner_normals,
1488 MutableSpan<short2> r_clnors_data)
1489{
1490 mesh_normals_corner_custom_set(vert_positions,
1491 edges,
1492 faces,
1493 corner_verts,
1494 corner_edges,
1495 vert_normals,
1496 face_normals,
1497 sharp_faces,
1498 false,
1499 r_custom_corner_normals,
1500 sharp_edges,
1501 r_clnors_data);
1502}
1503
1505 const Span<int2> edges,
1506 const OffsetIndices<int> faces,
1507 const Span<int> corner_verts,
1508 const Span<int> corner_edges,
1509 const Span<float3> vert_normals,
1510 const Span<float3> face_normals,
1511 const Span<bool> sharp_faces,
1512 MutableSpan<bool> sharp_edges,
1513 MutableSpan<float3> r_custom_vert_normals,
1514 MutableSpan<short2> r_clnors_data)
1515{
1516 mesh_normals_corner_custom_set(vert_positions,
1517 edges,
1518 faces,
1519 corner_verts,
1520 corner_edges,
1521 vert_normals,
1522 face_normals,
1523 sharp_faces,
1524 true,
1525 r_custom_vert_normals,
1526 sharp_edges,
1527 r_clnors_data);
1528}
1529
1530static void mesh_set_custom_normals(Mesh *mesh, float (*r_custom_nors)[3], const bool use_vertices)
1531{
1532 short2 *clnors = static_cast<short2 *>(
1533 CustomData_get_layer_for_write(&mesh->corner_data, CD_CUSTOMLOOPNORMAL, mesh->corners_num));
1534 if (clnors != nullptr) {
1535 memset(clnors, 0, sizeof(*clnors) * mesh->corners_num);
1536 }
1537 else {
1538 clnors = static_cast<short2 *>(CustomData_add_layer(
1539 &mesh->corner_data, CD_CUSTOMLOOPNORMAL, CD_SET_DEFAULT, mesh->corners_num));
1540 }
1541 MutableAttributeAccessor attributes = mesh->attributes_for_write();
1542 SpanAttributeWriter<bool> sharp_edges = attributes.lookup_or_add_for_write_span<bool>(
1543 "sharp_edge", AttrDomain::Edge);
1544 const VArraySpan sharp_faces = *attributes.lookup<bool>("sharp_face", AttrDomain::Face);
1545
1546 mesh_normals_corner_custom_set(mesh->vert_positions(),
1547 mesh->edges(),
1548 mesh->faces(),
1549 mesh->corner_verts(),
1550 mesh->corner_edges(),
1551 mesh->vert_normals(),
1552 mesh->face_normals(),
1553 sharp_faces,
1554 use_vertices,
1555 {reinterpret_cast<float3 *>(r_custom_nors),
1556 use_vertices ? mesh->verts_num : mesh->corners_num},
1557 sharp_edges.span,
1558 {clnors, mesh->corners_num});
1559
1560 sharp_edges.finish();
1561}
1562
1563} // namespace blender::bke::mesh
1564
1566{
1567 using namespace blender;
1568
1569 threading::parallel_for(normals.index_range(), 4096, [&](const IndexRange range) {
1570 for (const int i : range) {
1571 normals[i] = math::normalize(normals[i]);
1572 }
1573 });
1574}
1575
1576void BKE_mesh_set_custom_normals(Mesh *mesh, float (*r_custom_corner_normals)[3])
1577{
1579 {reinterpret_cast<blender::float3 *>(r_custom_corner_normals), mesh->corners_num});
1580
1581 blender::bke::mesh::mesh_set_custom_normals(mesh, r_custom_corner_normals, false);
1582}
1583
1584void BKE_mesh_set_custom_normals_normalized(Mesh *mesh, float (*r_custom_corner_normals)[3])
1585{
1586 blender::bke::mesh::mesh_set_custom_normals(mesh, r_custom_corner_normals, false);
1587}
1588
1589void BKE_mesh_set_custom_normals_from_verts(Mesh *mesh, float (*r_custom_vert_normals)[3])
1590{
1591 normalize_vecs({reinterpret_cast<blender::float3 *>(r_custom_vert_normals), mesh->verts_num});
1592
1593 blender::bke::mesh::mesh_set_custom_normals(mesh, r_custom_vert_normals, true);
1594}
1595
1597 float (*r_custom_vert_normals)[3])
1598{
1599 blender::bke::mesh::mesh_set_custom_normals(mesh, r_custom_vert_normals, true);
1600}
1601
1602void BKE_mesh_normals_loop_to_vertex(const int numVerts,
1603 const int *corner_verts,
1604 const int numLoops,
1605 const float (*clnors)[3],
1606 float (*r_vert_clnors)[3])
1607{
1608 int *vert_loops_count = (int *)MEM_calloc_arrayN(
1609 size_t(numVerts), sizeof(*vert_loops_count), __func__);
1610
1611 copy_vn_fl((float *)r_vert_clnors, 3 * numVerts, 0.0f);
1612
1613 int i;
1614 for (i = 0; i < numLoops; i++) {
1615 const int vert = corner_verts[i];
1616 add_v3_v3(r_vert_clnors[vert], clnors[i]);
1617 vert_loops_count[vert]++;
1618 }
1619
1620 for (i = 0; i < numVerts; i++) {
1621 mul_v3_fl(r_vert_clnors[i], 1.0f / float(vert_loops_count[i]));
1622 }
1623
1624 MEM_freeN(vert_loops_count);
1625}
1626
1627#undef LNOR_SPACE_TRIGO_THRESHOLD
1628
CustomData interface, see also DNA_customdata_types.h.
const void * CustomData_get_layer(const CustomData *data, eCustomDataType type)
@ CD_SET_DEFAULT
void * CustomData_get_layer_for_write(CustomData *data, eCustomDataType type, int totelem)
bool CustomData_has_layer(const CustomData *data, eCustomDataType type)
void * CustomData_add_layer(CustomData *data, eCustomDataType type, eCDAllocType alloctype, int totelem)
@ G_DEBUG
@ MLNOR_SPACE_IS_SINGLE
Definition BKE_mesh.h:258
@ MLNOR_SPACEARR_LOOP_INDEX
Definition BKE_mesh.h:276
@ MLNOR_SPACEARR_BMLOOP_PTR
Definition BKE_mesh.h:277
#define BLI_assert(a)
Definition BLI_assert.h:50
#define BLI_ASSERT_UNIT_V3(v)
#define M_PI
float normal_quad_v3(float n[3], const float v1[3], const float v2[3], const float v3[3], const float v4[3])
Definition math_geom.cc:56
#define MINLINE
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
MINLINE void add_newell_cross_v3_v3v3(float n[3], const float v_prev[3], const float v_curr[3])
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
void copy_vn_fl(float *array_tar, int size, float val)
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void copy_v2_v2_short(short r[2], const short a[2])
MINLINE bool compare_v3v3(const float v1[3], const float v2[3], float limit) ATTR_WARN_UNUSED_RESULT
MINLINE bool is_zero_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
MINLINE void add_v3_v3(float r[3], const float a[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_calloc(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
void BLI_memarena_merge(MemArena *ma_dst, MemArena *ma_src) ATTR_NONNULL(1
#define BLI_MEMARENA_STD_BUFSIZE
void void BLI_memarena_clear(MemArena *ma) ATTR_NONNULL(1)
#define SCOPED_TIMER_AVERAGED(name)
Definition BLI_timeit.hh:67
#define POINTER_FROM_INT(i)
#define UNLIKELY(x)
#define ELEM(...)
#define LIKELY(x)
@ CD_CUSTOMLOOPNORMAL
Read Guarded memory(de)allocation.
SIMD_FORCE_INLINE btScalar length() const
Return the length of the vector.
Definition btVector3.h:257
AttributeSet attributes
MutableSpan< T > as_mutable_span()
Definition BLI_array.hh:237
constexpr int64_t last(const int64_t n=0) const
constexpr int64_t size() const
Definition BLI_span.hh:494
constexpr T * data() const
Definition BLI_span.hh:540
constexpr void fill_indices(Span< IndexT > indices, const T &value) const
Definition BLI_span.hh:527
constexpr int64_t size() const
Definition BLI_span.hh:253
constexpr const T & last(const int64_t n=0) const
Definition BLI_span.hh:326
constexpr IndexRange index_range() const
Definition BLI_span.hh:402
constexpr bool is_empty() const
Definition BLI_span.hh:261
int64_t size() const
void append(const T &value)
IndexRange index_range() const
Span< T > as_span() const
void fill(const bool value)
#define printf
#define sinf(x)
#define cosf(x)
#define floorf(x)
#define fabsf(x)
draw_view in_light_buf[] float
void *(* MEM_calloc_arrayN)(size_t len, size_t size, const char *str)
Definition mallocn.cc:43
void MEM_freeN(void *vmemh)
Definition mallocn.cc:105
static char faces[256]
#define G(x, y, z)
void BKE_lnor_space_custom_data_to_normal(const MLoopNorSpace *lnor_space, const short clnor_data[2], float r_custom_lnor[3])
MLoopNorSpace * BKE_lnor_space_create(MLoopNorSpaceArray *lnors_spacearr)
#define INDEX_INVALID
void BKE_lnor_space_custom_normal_to_data(const MLoopNorSpace *lnor_space, const float custom_lnor[3], short r_clnor_data[2])
bool BKE_mesh_vert_normals_are_dirty(const Mesh *mesh)
MINLINE short unit_float_to_short(const float val)
void BKE_lnor_spacearr_init(MLoopNorSpaceArray *lnors_spacearr, const int numLoops, const char data_type)
static void normalize_vecs(blender::MutableSpan< blender::float3 > normals)
void BKE_lnor_spacearr_clear(MLoopNorSpaceArray *lnors_spacearr)
void BKE_mesh_normals_loop_to_vertex(const int numVerts, const int *corner_verts, const int numLoops, const float(*clnors)[3], float(*r_vert_clnors)[3])
#define INDEX_UNSET
bool BKE_mesh_face_normals_are_dirty(const Mesh *mesh)
#define LNOR_SPACE_TRIGO_THRESHOLD
void BKE_lnor_space_define(MLoopNorSpace *lnor_space, const float lnor[3], const float vec_ref[3], const float vec_other[3], const blender::Span< blender::float3 > edge_vectors)
void BKE_mesh_set_custom_normals(Mesh *mesh, float(*r_custom_corner_normals)[3])
void BKE_mesh_set_custom_normals_from_verts_normalized(Mesh *mesh, float(*r_custom_vert_normals)[3])
void BKE_lnor_space_add_loop(MLoopNorSpaceArray *lnors_spacearr, MLoopNorSpace *lnor_space, const int corner, void *bm_loop, const bool is_single)
void BKE_mesh_set_custom_normals_from_verts(Mesh *mesh, float(*r_custom_vert_normals)[3])
void BKE_lnor_spacearr_free(MLoopNorSpaceArray *lnors_spacearr)
void BKE_lnor_spacearr_tls_join(MLoopNorSpaceArray *lnors_spacearr, MLoopNorSpaceArray *lnors_spacearr_tls)
void BKE_mesh_set_custom_normals_normalized(Mesh *mesh, float(*r_custom_corner_normals)[3])
MINLINE float unit_short_to_float(const short val)
void BKE_lnor_spacearr_tls_init(MLoopNorSpaceArray *lnors_spacearr, MLoopNorSpaceArray *lnors_spacearr_tls)
#define IS_EDGE_SHARP(_e2l)
void gather(const GVArray &src, const IndexMask &indices, GMutableSpan dst, int64_t grain_size=4096)
void normals_corner_custom_set_from_verts(Span< float3 > vert_positions, Span< int2 > edges, OffsetIndices< int > faces, Span< int > corner_verts, Span< int > corner_edges, 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)
int edge_other_vert(const int2 edge, const int vert)
Definition BKE_mesh.hh:307
static void split_corner_normal_fan_do(CornerSplitTaskDataCommon *common_data, const int corner, const int space_index, Vector< float3, 16 > *edge_vectors)
static void mesh_normals_corner_custom_set(const Span< float3 > positions, const Span< int2 > edges, const OffsetIndices< int > faces, const Span< int > corner_verts, const Span< int > corner_edges, 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 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 corner_manifold_fan_around_vert_next(const Span< int > corner_verts, const OffsetIndices< int > faces, const Span< int > corner_to_face, const int2 e2lfan_curr, const int vert_pivot, int *r_fan_corner, int *r_vert_corner)
static void lnor_space_for_single_fan(CornerSplitTaskDataCommon *common_data, const int corner, const int space_index)
static float3 corner_space_custom_data_to_normal(const CornerNormalSpace &lnor_space, const short2 clnor_data)
float3 face_normal_calc(Span< float3 > vert_positions, Span< int > face_verts)
int face_corner_prev(const IndexRange face, const int corner)
Definition BKE_mesh.hh:243
Array< int > build_corner_to_face_map(OffsetIndices< int > faces)
void normals_calc_corners(Span< float3 > vert_positions, Span< int2 > edges, OffsetIndices< int > faces, Span< int > corner_verts, Span< int > corner_edges, Span< int > corner_to_face_map, Span< float3 > vert_normals, Span< float3 > face_normals, Span< bool > sharp_edges, Span< bool > sharp_faces, const short2 *clnors_data, CornerNormalSpaceArray *r_lnors_spacearr, MutableSpan< float3 > r_corner_normals)
void normals_corner_custom_set(Span< float3 > vert_positions, Span< int2 > edges, OffsetIndices< int > faces, Span< int > corner_verts, Span< int > corner_edges, 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)
static void mesh_set_custom_normals(Mesh *mesh, float(*r_custom_nors)[3], const bool use_vertices)
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)
Definition BKE_mesh.hh:252
static void corner_split_generator(CornerSplitTaskDataCommon *common_data, Vector< int, 32 > &r_single_corners, Vector< int, 32 > &r_fan_corners)
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)
void normals_calc_faces(Span< float3 > vert_positions, OffsetIndices< int > faces, Span< int > corner_verts, MutableSpan< float3 > face_normals)
static void build_edge_to_corner_map_with_flip_and_sharp(const OffsetIndices< int > faces, const Span< int > corner_verts, const Span< int > corner_edges, const Span< bool > sharp_faces, const Span< bool > sharp_edges, MutableSpan< int2 > edge_to_corners)
static bool corner_split_generator_check_cyclic_smooth_fan(const Span< int > corner_verts, const Span< int > corner_edges, const OffsetIndices< int > faces, const Span< int2 > edge_to_corners, const Span< int > corner_to_face, const int2 e2l_prev, MutableBitSpan skip_corners, const int corner, const int corner_prev)
void mesh_vert_normals_assign(Mesh &mesh, Span< float3 > vert_normals)
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)
QuaternionBase< T > normalize_and_get_length(const QuaternionBase< T > &q, T &out_length)
T dot(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
bool is_zero(const T &a)
AxisSigned cross(const AxisSigned a, const AxisSigned b)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
Definition BLI_task.hh:95
VecBase< int32_t, 2 > int2
blender::VecBase< int16_t, 2 > short2
Frequency::GEOMETRY nor[]
struct LinkNode * loops_pool
Definition BKE_mesh.h:266
struct MemArena * mem
Definition BKE_mesh.h:270
MLoopNorSpace ** lspacearr
Definition BKE_mesh.h:265
float ref_alpha
Definition BKE_mesh.h:244
float vec_ortho[3]
Definition BKE_mesh.h:242
float ref_beta
Definition BKE_mesh.h:246
float vec_ref[3]
Definition BKE_mesh.h:240
float vec_lnor[3]
Definition BKE_mesh.h:238
struct LinkNode * loops
Definition BKE_mesh.h:251
int corners_num
MeshRuntimeHandle * runtime
CustomData corner_data
int faces_num
Array< CornerNormalSpace > spaces
Definition BKE_mesh.hh:141
ccl_device_inline float beta(float x, float y)
Definition util/math.h:833