45 fac = (fac -
min) * minmax_irange;
47 CLAMP(fac, 0.0f, 1.0f);
63 const float minmax_irange = 1.0f / (max -
min);
78 for (
int i = 0; i < f->
len; i++, l_index++) {
79 r_overhang[l_index] = fac;
84 for (
const int face_i : mr.
faces.index_range()) {
87 for (
const int loop_i : mr.
faces[face_i]) {
88 r_overhang[loop_i] = fac;
101 if (uv[0] + uv[1] > 1.0f) {
102 uv[0] = 1.0f - uv[0];
103 uv[1] = 1.0f - uv[1];
113 fac = (fac -
min) * minmax_irange;
115 CLAMP(fac, 0.0f, 1.0f);
125 const float eps_offset = 0.00002f;
133 const float minmax_irange = 1.0f / (max -
min);
135 float jit_ofs[32][2];
142 for (
int j = 0; j < samples; j++) {
153 const BMLoop *
const *ltri = looptris[i].
data();
155 const float *
cos[3] = {
165 for (
int j = 0; j < samples; j++) {
166 float dist = face_dists[index];
171 if (f_hit && dist < face_dists[index]) {
172 float angle_fac =
fabsf(
174 angle_fac = 1.0f - angle_fac;
175 angle_fac = angle_fac * angle_fac * angle_fac;
176 angle_fac = 1.0f - angle_fac;
178 if (dist < face_dists[index]) {
179 face_dists[index] = dist;
192 for (
int i = 0; i < f->
len; i++, l_index++) {
193 r_thickness[l_index] = fac;
201 if (
tree ==
nullptr) {
208 const int index = tri_faces[i];
217 for (
int j = 0; j < samples; j++) {
223 hit.dist = face_dists[index];
226 hit.dist < face_dists[index])
229 angle_fac = 1.0f - angle_fac;
230 angle_fac = angle_fac * angle_fac * angle_fac;
231 angle_fac = 1.0f - angle_fac;
232 hit.dist /= angle_fac;
233 if (hit.dist < face_dists[index]) {
234 face_dists[index] = hit.dist;
240 for (
const int face_i : mr.
faces.index_range()) {
241 float fac = face_dists[face_i];
243 for (
const int loop_i : mr.
faces[face_i]) {
244 r_thickness[loop_i] = fac;
262 if (
UNLIKELY(data->tri_faces[index_a] == data->tri_faces[index_b])) {
266 const int3 tri_a = data->corner_tris[index_a];
267 const int3 tri_b = data->corner_tris[index_b];
269 const float *tri_a_co[3] = {data->positions[data->corner_verts[tri_a[0]]],
270 data->positions[data->corner_verts[tri_a[1]]],
271 data->positions[data->corner_verts[tri_a[2]]]};
272 const float *tri_b_co[3] = {data->positions[data->corner_verts[tri_b[0]]],
273 data->positions[data->corner_verts[tri_b[1]]],
274 data->positions[data->corner_verts[tri_b[2]]]};
276 int verts_shared = 0;
282 if (verts_shared >= 2) {
288 ((verts_shared == 0) || (
len_squared_v3v3(ix_pair[0], ix_pair[1]) > data->epsilon)));
295 for (
int l_index = 0; l_index < mr.
corners_num; l_index++) {
296 r_intersect[l_index] = -1.0f;
309 for (
int i = 0; i < overlap_len; i++) {
314 for (
int j = 0; j < 2; j++) {
315 BMFace *f_hit = f_hit_pair[j];
318 for (
int k = 0; k < f_hit->
len; k++, l_index++) {
319 r_intersect[l_index] = 1.0f;
333 if (
tree ==
nullptr) {
340 data.corner_tris = mr.
mesh->corner_tris();
341 data.tri_faces = mr.
mesh->corner_tri_faces();
346 for (
int i = 0; i < overlap_len; i++) {
351 int l_index = f_hit.start();
352 for (
int k = 0; k < f_hit.size(); k++, l_index++) {
353 r_intersect[l_index] = 1.0f;
365 fac = (fac -
min) * minmax_irange;
366 CLAMP(fac, 0.0f, 1.0f);
381 const float minmax_irange = 1.0f / (max -
min);
399 const float *no_face;
415 if (
dot_v3v3(no_face, no_corner) < 0.0f) {
420 }
while ((l_iter = l_iter->
next) != l_first);
425 for (
int i = 0; i < f->
len; i++, l_index++) {
426 r_distort[l_index] = fac;
431 for (
const int face_index : mr.
faces.index_range()) {
435 if (face.size() > 3) {
439 for (
const int corner : face.drop_front(1)) {
448 if (
dot_v3v3(f_no, no_corner) < 0.0f) {
457 for (
const int corner : face) {
458 r_distort[corner] = fac;
468 fac = (fac -
min) * minmax_irange;
469 CLAMP(fac, 0.0f, 1.0f);
484 const float minmax_irange = 1.0f / (max -
min);
500 *col1 =
max_ff(*col1, angle);
501 *col2 =
max_ff(*col2, angle);
510 r_sharp[l_index] =
sharp_remap(vert_angles[v_index],
min, max, minmax_irange);
511 }
while ((l_iter = l_iter->
next) != l_first);
520 for (
int face_index = 0; face_index < mr.
faces_num; face_index++) {
522 for (
const int corner : face) {
527 {vert_curr, vert_next},
528 [&](
int *value) { *value = face_index; },
530 const int other_face_index = *value;
531 if (other_face_index == -1) {
548 float *col1 = &vert_angles[vert_curr];
549 float *col2 = &vert_angles[vert_next];
550 *col1 =
max_ff(*col1, angle);
551 *col2 =
max_ff(*col2, angle);
556 const float angle =
DEG2RADF(90.0f);
557 float *col1 = &vert_angles[edge.v_low];
558 float *col2 = &vert_angles[edge.v_high];
559 *col1 =
max_ff(*col1, angle);
560 *col2 =
max_ff(*col2, angle);
563 for (
int l_index = 0; l_index < mr.
corners_num; l_index++) {
565 r_sharp[l_index] =
sharp_remap(vert_angles[vert],
min, max, minmax_irange);
577 if (
format.attr_len == 0) {
BVHTree * BKE_bvhtree_from_mesh_get(BVHTreeFromMesh *data, const Mesh *mesh, BVHCacheType bvh_cache_type, int tree_type)
@ BVHTREE_FROM_CORNER_TRIS
BMBVHTree * BKE_bmbvh_new_from_editmesh(struct BMEditMesh *em, int flag, const blender::float3 *cos_cage, bool cos_cage_free)
struct BMFace * BKE_bmbvh_ray_cast(const BMBVHTree *tree, const float co[3], const float dir[3], float radius, float *r_dist, float r_hitout[3], float r_cagehit[3])
struct BVHTreeOverlap * BKE_bmbvh_overlap_self(const BMBVHTree *bmtree, unsigned int *r_overlap_tot)
void BKE_bmbvh_free(BMBVHTree *tree)
void BLI_jitter_init(float(*jitarr)[2], int num)
BVHTreeOverlap * BLI_bvhtree_overlap_self(const BVHTree *tree, unsigned int *r_overlap_num, BVHTree_OverlapCallback callback, void *userdata)
float BLI_bvhtree_get_epsilon(const BVHTree *tree)
int BLI_bvhtree_ray_cast(const BVHTree *tree, const float co[3], const float dir[3], float radius, BVHTreeRayHit *hit, BVHTree_RayCastCallback callback, void *userdata)
MINLINE float max_ff(float a, float b)
bool isect_tri_tri_v3(const float t_a0[3], const float t_a1[3], const float t_a2[3], const float t_b0[3], const float t_b1[3], const float t_b2[3], float r_i1[3], float r_i2[3])
bool is_edge_convex_v3(const float v1[3], const float v2[3], const float f1_no[3], const float f2_no[3])
float normal_tri_v3(float n[3], const float v1[3], const float v2[3], const float v3[3])
float mat4_to_scale(const float mat[4][4])
void mul_transposed_mat3_m4_v3(const float M[4][4], float r[3])
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
MINLINE float len_squared_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
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 negate_v3(float r[3])
MINLINE void clamp_v2(float vec[2], float min, float max)
MINLINE void zero_v3(float r[3])
float angle_normalized_v3v3(const float v1[3], const float v2[3]) ATTR_WARN_UNUSED_RESULT
void interp_v3_v3v3v3_uv(float p[3], const float v1[3], const float v2[3], const float v3[3], const float uv[2])
MINLINE float normalize_v3(float n[3])
#define GPU_vertbuf_init_with_format(verts, format)
void GPU_vertbuf_data_alloc(blender::gpu::VertBuf &verts, uint v_len)
static double angle(const Eigen::Vector3d &v1, const Eigen::Vector3d &v2)
Read Guarded memory(de)allocation.
#define BM_FACE_FIRST_LOOP(p)
#define BM_elem_index_get(ele)
#define BM_ITER_MESH(ele, iter, bm, itype)
#define BM_ITER_MESH_INDEX(ele, iter, bm, itype, indexvar)
ATTR_WARN_UNUSED_RESULT BMesh * bm
void BM_mesh_elem_index_ensure(BMesh *bm, const char htype)
float BM_loop_calc_face_normal_safe(const BMLoop *l, float r_normal[3])
float BM_loop_calc_face_normal_safe_vcos(const BMLoop *l, const float normal_fallback[3], float const (*vertexCos)[3], float r_normal[3])
float BM_edge_calc_face_angle_signed(const BMEdge *e)
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
ATTR_WARN_UNUSED_RESULT const BMVert * v
auto add_or_modify(const Key &key, const CreateValueF &create_value, const ModifyValueF &modify_value) -> decltype(create_value(nullptr))
constexpr T * data() const
constexpr const T * data() const
constexpr IndexRange index_range() const
constexpr bool is_empty() const
draw_view in_light_buf[] float
void *(* MEM_mallocN)(size_t len, const char *str)
void MEM_freeN(void *vmemh)
int face_corner_prev(const IndexRange face, const int corner)
int face_corner_next(const IndexRange face, const int corner)
static void statvis_calc_distort(const MeshRenderData &mr, MutableSpan< float > r_distort)
BLI_INLINE float distort_remap(float fac, float min, float, float minmax_irange)
static bool bvh_overlap_cb(void *userdata, int index_a, int index_b, int)
static void axis_from_enum_v3(float v[3], const char axis)
BLI_INLINE float sharp_remap(float fac, float min, float, float minmax_irange)
BLI_INLINE const float * bm_face_no_get(const MeshRenderData &mr, const BMFace *efa)
static void uv_from_jitter_v2(float uv[2])
static void statvis_calc_sharp(const MeshRenderData &mr, MutableSpan< float > r_sharp)
void extract_mesh_analysis(const MeshRenderData &mr, gpu::VertBuf &vbo)
static void statvis_calc_intersect(const MeshRenderData &mr, MutableSpan< float > r_intersect)
BLI_INLINE float overhang_remap(float fac, float min, float max, float minmax_irange)
static void statvis_calc_overhang(const MeshRenderData &mr, MutableSpan< float > r_overhang)
BLI_INLINE const float * bm_vert_co_get(const MeshRenderData &mr, const BMVert *eve)
static void statvis_calc_thickness(const MeshRenderData &mr, MutableSpan< float > r_thickness)
BLI_INLINE float thickness_remap(float fac, float min, float max, float minmax_irange)
T cos(const AngleRadianBase< T > &a)
MatBase< T, NumCol, NumRow > scale(const MatBase< T, NumCol, NumRow > &mat, const VectorT &scale)
blender::Array< std::array< BMLoop *, 3 > > looptris
BVHTree_RayCastCallback raycast_callback
const c_style_mat & ptr() const
Span< float3 > bm_vert_coords
const ToolSettings * toolsettings
Span< float3 > vert_positions
eMRExtractType extract_type
Span< float3 > bm_face_normals
Span< float3 > face_normals
OffsetIndices< int > faces