Fix #139675: Mesh analysis crashes in editmode with instances

Caused by a67b5f6f63

Since we dont necessarily act with `MeshExtractType::BMesh` (can be
`MeshExtractType::Mesh` as well -- and seems the specific mesh analysis
`statvis_calc` functions are well prepared for this), move access to
`BMesh` to the codepaths specific to `MeshExtractType::BMesh`.

Also remove (non-appropriate) assert in `extract_mesh_analysis`.

Pull Request: https://projects.blender.org/blender/blender/pulls/139717
This commit is contained in:
Philipp Oeser
2025-06-02 16:15:21 +02:00
committed by Philipp Oeser
parent 20ca13e4e4
commit 6e3b483c6d

View File

@@ -61,10 +61,6 @@ static void statvis_calc_overhang(const MeshRenderData &mr,
const float min = statvis->overhang_min / float(M_PI);
const float max = statvis->overhang_max / float(M_PI);
const char axis = statvis->overhang_axis;
BMEditMesh *em = mr.edit_bmesh;
BMIter iter;
BMesh *bm = em->bm;
BMFace *f;
float dir[3];
const float minmax_irange = 1.0f / (max - min);
@@ -77,6 +73,10 @@ static void statvis_calc_overhang(const MeshRenderData &mr,
normalize_v3(dir);
if (mr.extract_type == MeshExtractType::BMesh) {
BMEditMesh *em = mr.edit_bmesh;
BMIter iter;
BMesh *bm = em->bm;
BMFace *f;
int l_index = 0;
BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
float fac = angle_normalized_v3v3(bm_face_no_get(mr, f), dir) / float(M_PI);
@@ -133,7 +133,6 @@ static void statvis_calc_thickness(const MeshRenderData &mr,
const float eps_offset = 0.00002f; /* values <= 0.00001 give errors */
/* cheating to avoid another allocation */
float *face_dists = r_thickness.data() + (mr.corners_num - mr.faces_num);
BMEditMesh *em = mr.edit_bmesh;
const float scale = 1.0f / mat4_to_scale(object_to_world.ptr());
const MeshStatVis *statvis = &mr.toolsettings->statvis;
const float min = statvis->thickness_min * scale;
@@ -152,6 +151,7 @@ static void statvis_calc_thickness(const MeshRenderData &mr,
}
if (mr.extract_type == MeshExtractType::BMesh) {
BMEditMesh *em = mr.edit_bmesh;
BMesh *bm = em->bm;
BM_mesh_elem_index_ensure(bm, BM_FACE);
@@ -293,13 +293,12 @@ static bool bvh_overlap_cb(void *userdata, int index_a, int index_b, int /*threa
static void statvis_calc_intersect(const MeshRenderData &mr, MutableSpan<float> r_intersect)
{
BMEditMesh *em = mr.edit_bmesh;
for (int l_index = 0; l_index < mr.corners_num; l_index++) {
r_intersect[l_index] = -1.0f;
}
if (mr.extract_type == MeshExtractType::BMesh) {
BMEditMesh *em = mr.edit_bmesh;
uint overlap_len;
BMesh *bm = em->bm;
@@ -376,13 +375,13 @@ BLI_INLINE float distort_remap(float fac, float min, float /*max*/, float minmax
static void statvis_calc_distort(const MeshRenderData &mr, MutableSpan<float> r_distort)
{
BMEditMesh *em = mr.edit_bmesh;
const MeshStatVis *statvis = &mr.toolsettings->statvis;
const float min = statvis->distort_min;
const float max = statvis->distort_max;
const float minmax_irange = 1.0f / (max - min);
if (mr.extract_type == MeshExtractType::BMesh) {
BMEditMesh *em = mr.edit_bmesh;
BMIter iter;
BMesh *bm = em->bm;
BMFace *f;
@@ -479,7 +478,6 @@ BLI_INLINE float sharp_remap(float fac, float min, float /*max*/, float minmax_i
static void statvis_calc_sharp(const MeshRenderData &mr, MutableSpan<float> r_sharp)
{
BMEditMesh *em = mr.edit_bmesh;
const MeshStatVis *statvis = &mr.toolsettings->statvis;
const float min = statvis->sharp_min;
const float max = statvis->sharp_max;
@@ -490,6 +488,7 @@ static void statvis_calc_sharp(const MeshRenderData &mr, MutableSpan<float> r_sh
copy_vn_fl(vert_angles, mr.verts_num, -M_PI);
if (mr.extract_type == MeshExtractType::BMesh) {
BMEditMesh *em = mr.edit_bmesh;
BMIter iter;
BMesh *bm = em->bm;
BMFace *efa;
@@ -573,8 +572,6 @@ static void statvis_calc_sharp(const MeshRenderData &mr, MutableSpan<float> r_sh
gpu::VertBufPtr extract_mesh_analysis(const MeshRenderData &mr, const float4x4 &object_to_world)
{
BLI_assert(mr.edit_bmesh);
static const GPUVertFormat format = GPU_vertformat_from_attribute(
"weight", GPU_COMP_F32, 1, GPU_FETCH_FLOAT);