51 fac = (fac -
min) * minmax_irange;
53 CLAMP(fac, 0.0f, 1.0f);
67 const float minmax_irange = 1.0f / (
max -
min);
85 for (
int i = 0; i < f->
len; i++, l_index++) {
86 r_overhang[l_index] = fac;
91 for (
const int face_i : mr.
faces.index_range()) {
94 for (
const int loop_i : mr.
faces[face_i]) {
95 r_overhang[loop_i] = fac;
108 if (uv[0] + uv[1] > 1.0f) {
109 uv[0] = 1.0f - uv[0];
110 uv[1] = 1.0f - uv[1];
120 fac = (fac -
min) * minmax_irange;
122 CLAMP(fac, 0.0f, 1.0f);
134 const float eps_offset = 0.00002f;
141 const float minmax_irange = 1.0f / (
max -
min);
143 float jit_ofs[32][2];
150 for (
int j = 0; j < samples; j++) {
162 const BMLoop *
const *ltri = looptris[i].
data();
164 const float *
cos[3] = {
174 for (
int j = 0; j < samples; j++) {
175 float dist = face_dists[
index];
180 if (f_hit && dist < face_dists[
index]) {
181 float angle_fac =
fabsf(
183 angle_fac = 1.0f - angle_fac;
184 angle_fac = angle_fac * angle_fac * angle_fac;
185 angle_fac = 1.0f - angle_fac;
187 face_dists[
index] = std::min(dist, face_dists[
index]);
199 for (
int i = 0; i < f->
len; i++, l_index++) {
200 r_thickness[l_index] = fac;
212 const int index = tri_faces[i];
221 for (
int j = 0; j < samples; j++) {
226 const std::optional<bke::bvh::RayHit> hit = tree.
ray_intersect(ray);
227 if (hit && hit->distance < 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 face_dists[
index] = std::min(hit->distance / angle_fac, face_dists[
index]);
237 for (
const int face_i : mr.
faces.index_range()) {
238 float fac = face_dists[face_i];
240 for (
const int loop_i : mr.
faces[face_i]) {
241 r_thickness[loop_i] = fac;
259 if (
data->tri_faces[index_a] ==
data->tri_faces[index_b]) [[unlikely]] {
263 const int3 tri_a =
data->corner_tris[index_a];
264 const int3 tri_b =
data->corner_tris[index_b];
266 const float *tri_a_co[3] = {
data->positions[
data->corner_verts[tri_a[0]]],
267 data->positions[
data->corner_verts[tri_a[1]]],
268 data->positions[
data->corner_verts[tri_a[2]]]};
269 const float *tri_b_co[3] = {
data->positions[
data->corner_verts[tri_b[0]]],
270 data->positions[
data->corner_verts[tri_b[1]]],
271 data->positions[
data->corner_verts[tri_b[2]]]};
273 int verts_shared = 0;
279 if (verts_shared >= 2) {
290 for (
int l_index = 0; l_index < mr.
corners_num; l_index++) {
291 r_intersect[l_index] = -1.0f;
305 for (
int i = 0; i < overlap_len; i++) {
310 for (
int j = 0; j < 2; j++) {
311 BMFace *f_hit = f_hit_pair[j];
314 for (
int k = 0; k < f_hit->
len; k++, l_index++) {
315 r_intersect[l_index] = 1.0f;
328 if (tree ==
nullptr) {
335 data.corner_tris = mr.
mesh->corner_tris();
336 data.tri_faces = mr.
mesh->corner_tri_faces();
341 for (
int i = 0; i < overlap_len; i++) {
346 int l_index = f_hit.start();
347 for (
int k = 0; k < f_hit.size(); k++, l_index++) {
348 r_intersect[l_index] = 1.0f;
360 fac = (fac -
min) * minmax_irange;
361 CLAMP(fac, 0.0f, 1.0f);
375 const float minmax_irange = 1.0f / (
max -
min);
393 const float *no_face;
409 if (
dot_v3v3(no_face, no_corner) < 0.0f) {
414 }
while ((l_iter = l_iter->
next) != l_first);
419 for (
int i = 0; i < f->
len; i++, l_index++) {
420 r_distort[l_index] = fac;
425 for (
const int face_index : mr.
faces.index_range()) {
429 if (face.
size() > 3) {
442 if (
dot_v3v3(f_no, no_corner) < 0.0f) {
451 for (
const int corner : face) {
452 r_distort[corner] = fac;
462 fac = (fac -
min) * minmax_irange;
463 CLAMP(fac, 0.0f, 1.0f);
477 const float minmax_irange = 1.0f / (
max -
min);
504 }
while ((l_iter = l_iter->
next) != l_first);
513 for (
int face_index = 0; face_index < mr.
faces_num; face_index++) {
515 for (
const int corner : face) {
520 {vert_curr, vert_next},
521 [&](
int *value) { *value = face_index; },
523 const int other_face_index = *value;
524 if (other_face_index == -1) {
541 float *col1 = &vert_angles[vert_curr];
542 float *col2 = &vert_angles[vert_next];
550 float *col1 = &vert_angles[edge.v_low];
551 float *col2 = &vert_angles[edge.v_high];
556 for (
int l_index = 0; l_index < mr.
corners_num; l_index++) {
562 MEM_delete(vert_angles);
568 gpu::VertAttrType::SFLOAT_32);
Read Blender memory allocation and freeing.
#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)
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
constexpr int64_t size() const
constexpr IndexRange drop_front(int64_t n) const
KeyIterator keys() const &
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
std::optional< RayHit > ray_intersect(const Ray &ray) const
float3x3 scale(float3x3 mat, float2 scale)
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)
static void statvis_calc_thickness(const MeshRenderData &mr, const float4x4 &object_to_world, MutableSpan< float > r_thickness)
BLI_INLINE float sharp_remap(float fac, float min, float, float minmax_irange)
static void statvis_calc_overhang(const MeshRenderData &mr, const float4x4 &object_to_world, MutableSpan< float > r_overhang)
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)
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)
BLI_INLINE const float * bm_vert_co_get(const MeshRenderData &mr, const BMVert *eve)
gpu::VertBufPtr extract_mesh_analysis(const MeshRenderData &mr, const float4x4 &object_to_world)
BLI_INLINE float thickness_remap(float fac, float min, float max, float minmax_irange)
std::unique_ptr< gpu::VertBuf, gpu::VertBufDeleter > VertBufPtr
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
float BM_loop_calc_face_normal_safe_vcos(const BMLoop *l, const float normal_fallback[3], float const (*vertexCos)[3], float r_normal[3])
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
MINLINE float len_squared_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
float angle_normalized_v3v3(const float v1[3], const float v2[3]) ATTR_WARN_UNUSED_RESULT
void BKE_bmbvh_free(BMBVHTree *tree)
void BM_mesh_elem_index_ensure(BMesh *bm, const char htype)
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])
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
float BLI_bvhtree_get_epsilon(const BVHTree *tree)
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])
float mat4_to_scale(const float mat[4][4])
GPUVertFormat GPU_vertformat_from_attribute(StringRef name, gpu::VertAttrType type)
ATTR_WARN_UNUSED_RESULT const BMVert * v
float normal_tri_v3(float n[3], const float v1[3], const float v2[3], const float v3[3])
MatBase< float, 4, 4 > float4x4
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
void interp_v3_v3v3v3_uv(float p[3], const float v1[3], const float v2[3], const float v3[3], const float uv[2])
VecBase< int32_t, 3 > int3
BMesh const char void * data
BMBVHTree * BKE_bmbvh_new_from_editmesh(struct BMEditMesh *em, struct BMesh *bm, int flag, const float3 *cos_cage, bool cos_cage_free)
MINLINE void negate_v3(float r[3])
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)
MINLINE void zero_v3(float r[3])
float BM_loop_calc_face_normal_safe(const BMLoop *l, float r_normal[3])
MINLINE float normalize_v3(float n[3])
MINLINE void clamp_v2(float vec[2], float min, float max)
MINLINE float max_ff(float a, float b)
void GPU_vertbuf_data_alloc(gpu::VertBuf &verts, uint v_len)
bool is_edge_convex_v3(const float v1[3], const float v2[3], const float f1_no[3], const float f2_no[3])
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
struct BVHTreeOverlap * BKE_bmbvh_overlap_self(const BMBVHTree *bmtree, unsigned int *r_overlap_tot)
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
float BM_edge_calc_face_angle_signed(const BMEdge *e)
void mul_transposed_mat3_m4_v3(const float M[4][4], float r[3])
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
Array< std::array< BMLoop *, 3 > > looptris
Span< float3 > bm_vert_coords
const ToolSettings * toolsettings
Span< float3 > vert_positions
MeshExtractType extract_type
Span< float3 > bm_face_normals
Span< float3 > face_normals
OffsetIndices< int > faces