Fix T46389: Shrinkwrap fails in editmode

Own regression caused by fix for T46067,
edit-mode bvh only contained unselected faces.

This commit adds support for an edit-mode bvh containing all faces.
This commit is contained in:
Campbell Barton 2015-10-06 17:55:15 +11:00
parent 51f00499cd
commit 65bd2a6e6a
Notes: blender-bot 2023-02-14 08:38:11 +01:00
Referenced by issue #46389, Shrinkwrap fails when target mesh is in edit mode
3 changed files with 23 additions and 7 deletions

View File

@ -68,7 +68,8 @@ typedef struct BVHTreeFromMesh {
float sphere_radius;
/* Private data */
void *em_evil; /* var only for snapping */
void *em_evil;
bool em_evil_all; /* ignore selection/hidden state, adding all loops to the tree */
bool cached;
} BVHTreeFromMesh;
@ -141,8 +142,11 @@ enum {
BVHTREE_FROM_VERTS = 0,
BVHTREE_FROM_EDGES = 1,
BVHTREE_FROM_FACES = 2,
BVHTREE_FROM_FACES_EDITMESH = 3,
BVHTREE_FROM_LOOPTRI = 4,
BVHTREE_FROM_LOOPTRI = 3,
/* all faces */
BVHTREE_FROM_FACES_EDITMESH_ALL = 4,
/* visible unselected, only used for transform snapping */
BVHTREE_FROM_FACES_EDITMESH_SNAP = 5,
};
typedef struct LinkNode *BVHCache;

View File

@ -646,7 +646,10 @@ static BVHTree *bvhtree_from_mesh_faces_create_tree(
insert = insert_prev;
}
else if (insert) {
if (BM_elem_flag_test(f, BM_ELEM_SELECT) || BM_elem_flag_test(f, BM_ELEM_HIDDEN)) {
if (tree_type == BVHTREE_FROM_FACES_EDITMESH_ALL) {
/* pass */
}
else if (BM_elem_flag_test(f, BM_ELEM_SELECT) || BM_elem_flag_test(f, BM_ELEM_HIDDEN)) {
/* Don't insert triangles tessellated from faces that are hidden or selected */
insert = false;
}
@ -746,7 +749,9 @@ static void bvhtree_from_mesh_faces_setup_data(
BVHTree *bvhtree_from_mesh_faces(BVHTreeFromMesh *data, DerivedMesh *dm, float epsilon, int tree_type, int axis)
{
BMEditMesh *em = data->em_evil;
const int bvhcache_type = em ? BVHTREE_FROM_FACES_EDITMESH : BVHTREE_FROM_FACES;
const int bvhcache_type = em ?
(data->em_evil_all ? BVHTREE_FROM_FACES_EDITMESH_ALL : BVHTREE_FROM_FACES_EDITMESH_SNAP) :
BVHTREE_FROM_FACES;
BVHTree *tree;
MVert *vert = NULL;
MFace *face = NULL;
@ -881,7 +886,10 @@ static BVHTree *bvhtree_from_mesh_looptri_create_tree(
insert = insert_prev;
}
else if (insert) {
if (BM_elem_flag_test(f, BM_ELEM_SELECT) || BM_elem_flag_test(f, BM_ELEM_HIDDEN)) {
if (tree_type == BVHTREE_FROM_FACES_EDITMESH_ALL) {
/* pass */
}
else if (BM_elem_flag_test(f, BM_ELEM_SELECT) || BM_elem_flag_test(f, BM_ELEM_HIDDEN)) {
/* Don't insert triangles tessellated from faces that are hidden or selected */
insert = false;
}
@ -986,7 +994,9 @@ static void bvhtree_from_mesh_looptri_setup_data(
BVHTree *bvhtree_from_mesh_looptri(BVHTreeFromMesh *data, DerivedMesh *dm, float epsilon, int tree_type, int axis)
{
BMEditMesh *em = data->em_evil;
const int bvhcache_type = em ? BVHTREE_FROM_FACES_EDITMESH : BVHTREE_FROM_LOOPTRI;
const int bvhcache_type = em ?
(data->em_evil_all ? BVHTREE_FROM_FACES_EDITMESH_ALL : BVHTREE_FROM_FACES_EDITMESH_SNAP) :
BVHTREE_FROM_LOOPTRI;
BVHTree *tree;
MVert *mvert = NULL;
MLoop *mloop = NULL;

View File

@ -282,9 +282,11 @@ static void shrinkwrap_calc_normal_projection(ShrinkwrapCalcData *calc, bool for
/* use editmesh to avoid array allocation */
if (calc->smd->target && calc->target->type == DM_TYPE_EDITBMESH) {
treeData.em_evil = BKE_editmesh_from_object(calc->smd->target);
treeData.em_evil_all = true;
}
if (calc->smd->auxTarget && auxMesh->type == DM_TYPE_EDITBMESH) {
auxData.em_evil = BKE_editmesh_from_object(calc->smd->auxTarget);
auxData.em_evil_all = true;
}
/* After sucessufuly build the trees, start projection vertexs */