Fix assertion snapping to selected in mesh edit-mode

ED_transverts_create_from_obedit expected an evaluated object.

Add flag to request TX_VERT_USE_MAPLOC to be set, which avoids having to
calculate this data when it's not used as well as the requirement
that the input object be evaluated from the depsgraph.
This commit is contained in:
Campbell Barton 2022-02-04 11:05:31 +11:00
parent a0c1306e8c
commit ef2685afea
3 changed files with 23 additions and 11 deletions

View File

@ -28,6 +28,7 @@ extern "C" {
#endif
struct Object;
struct bContext;
typedef struct TransVert {
float *loc;
@ -42,10 +43,14 @@ typedef struct TransVertStore {
int mode;
} TransVertStore;
void ED_transverts_create_from_obedit(TransVertStore *tvs, struct Object *obedit, int mode);
/**
* \param obedit: When `mode` has the #TM_CALC_MAPLOC flag set, `obedit` must be evaluated,
* to access evaluated vertices.
*/
void ED_transverts_create_from_obedit(TransVertStore *tvs, const struct Object *obedit, int mode);
void ED_transverts_update_obedit(TransVertStore *tvs, struct Object *obedit);
void ED_transverts_free(TransVertStore *tvs);
bool ED_transverts_check_obedit(Object *obedit);
bool ED_transverts_check_obedit(const struct Object *obedit);
bool ED_transverts_poll(struct bContext *C);
/* currently only used for bmesh index values */
@ -66,12 +71,16 @@ enum {
TM_SKIP_HANDLES = (1 << 1),
/** fill in normals when available */
TM_CALC_NORMALS = (1 << 2),
/** Calculates #TransVert.maploc where possible. */
TM_CALC_MAPLOC = (1 << 2),
};
enum {
/* SELECT == (1 << 0) */
/** Calculated when #TM_CALC_MAPLOC is set. */
TX_VERT_USE_MAPLOC = (1 << 1),
TX_VERT_USE_NORMAL = (1 << 2), /* avoid nonzero check */
/** Calculated when #TM_CALC_NORMALS is set, avoid nonzero check. */
TX_VERT_USE_NORMAL = (1 << 2),
};
#ifdef __cplusplus

View File

@ -1033,7 +1033,7 @@ bool ED_view3d_minmax_verts(Object *obedit, float r_min[3], float r_max[3])
}
if (ED_transverts_check_obedit(obedit)) {
ED_transverts_create_from_obedit(&tvs, obedit, TM_ALL_JOINTS);
ED_transverts_create_from_obedit(&tvs, obedit, TM_ALL_JOINTS | TM_CALC_MAPLOC);
}
if (tvs.transverts_tot == 0) {

View File

@ -195,12 +195,12 @@ static void set_mapped_co(void *vuserdata, int index, const float co[3], const f
}
}
bool ED_transverts_check_obedit(Object *obedit)
bool ED_transverts_check_obedit(const Object *obedit)
{
return (ELEM(obedit->type, OB_ARMATURE, OB_LATTICE, OB_MESH, OB_SURF, OB_CURVE, OB_MBALL));
}
void ED_transverts_create_from_obedit(TransVertStore *tvs, Object *obedit, const int mode)
void ED_transverts_create_from_obedit(TransVertStore *tvs, const Object *obedit, const int mode)
{
Nurb *nu;
BezTriple *bezt;
@ -214,7 +214,7 @@ void ED_transverts_create_from_obedit(TransVertStore *tvs, Object *obedit, const
tvs->transverts_tot = 0;
if (obedit->type == OB_MESH) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMEditMesh *em = BKE_editmesh_from_object((Object *)obedit);
BMesh *bm = em->bm;
BMIter iter;
void *userdata[2] = {em, NULL};
@ -312,10 +312,13 @@ void ED_transverts_create_from_obedit(TransVertStore *tvs, Object *obedit, const
userdata[1] = tvs->transverts;
}
struct Mesh *editmesh_eval_cage = BKE_object_get_editmesh_eval_cage(obedit);
if (tvs->transverts && editmesh_eval_cage) {
BM_mesh_elem_table_ensure(bm, BM_VERT);
BKE_mesh_foreach_mapped_vert(editmesh_eval_cage, set_mapped_co, userdata, MESH_FOREACH_NOP);
if (mode & TM_CALC_MAPLOC) {
struct Mesh *editmesh_eval_cage = BKE_object_get_editmesh_eval_cage(obedit);
if (tvs->transverts && editmesh_eval_cage) {
BM_mesh_elem_table_ensure(bm, BM_VERT);
BKE_mesh_foreach_mapped_vert(
editmesh_eval_cage, set_mapped_co, userdata, MESH_FOREACH_NOP);
}
}
}
else if (obedit->type == OB_ARMATURE) {