Edge/Vert slide: improve multires interpolation

Need to re-interpolate the entire face, not just the connected loop.

Also add BM_face_interp_multires()
This commit is contained in:
Campbell Barton 2015-11-03 20:30:54 +11:00
parent f29f4c92f2
commit bed91b623f
4 changed files with 42 additions and 23 deletions

@ -527,6 +527,31 @@ void BM_loop_interp_multires(BMesh *bm, BMLoop *l_dst, const BMFace *f_src)
BM_loop_interp_multires_ex(bm, l_dst, f_src, f_dst_center, f_src_center, cd_loop_mdisp_offset);
}
void BM_face_interp_multires_ex(
BMesh *bm, BMFace *f_dst, const BMFace *f_src,
const float f_dst_center[3], const float f_src_center[3], const int cd_loop_mdisp_offset)
{
BMLoop *l_iter, *l_first;
l_iter = l_first = BM_FACE_FIRST_LOOP(f_dst);
do {
BM_loop_interp_multires_ex(
bm, l_iter, f_src,
f_dst_center, f_src_center, cd_loop_mdisp_offset);
} while ((l_iter = l_iter->next) != l_first);
}
void BM_face_interp_multires(BMesh *bm, BMFace *f_dst, const BMFace *f_src)
{
const int cd_loop_mdisp_offset = CustomData_get_offset(&bm->ldata, CD_MDISPS);
float f_dst_center[3];
float f_src_center[3];
BM_face_calc_center_mean(f_dst, f_dst_center);
BM_face_calc_center_mean(f_src, f_src_center);
BM_face_interp_multires_ex(bm, f_dst, f_src, f_dst_center, f_src_center, cd_loop_mdisp_offset);
}
/**
* smooths boundaries between multires grids,
* including some borders in adjacent faces

@ -35,6 +35,12 @@ void BM_loop_interp_multires_ex(
const float f_dst_center[3], const float f_src_center[3], const int cd_loop_mdisp_offset);
void BM_loop_interp_multires(
BMesh *bm, BMLoop *l_dst, const BMFace *f_src);
void BM_face_interp_multires_ex(
BMesh *UNUSED(bm), BMFace *f_dst, const BMFace *f_src,
const float f_dst_center[3], const float f_src_center[3], const int cd_loop_mdisp_offset);
void BM_face_interp_multires(BMesh *bm, BMFace *f_dst, const BMFace *f_src);
void BM_vert_interp_from_face(BMesh *bm, BMVert *v_dst, const BMFace *f_src);
void BM_data_interp_from_verts(BMesh *bm, const BMVert *v_src_1, const BMVert *v_src_2, BMVert *v_dst, const float fac);

@ -313,24 +313,16 @@ BMFace *BM_face_split(
if (f_new) {
/* handle multires update */
if (cd_loop_mdisp_offset != -1) {
BMLoop *l_iter;
BMLoop *l_first;
float f_dst_center[3];
float f_src_center[3];
BM_face_calc_center_mean(f_tmp, f_src_center);
BM_face_calc_center_mean(f, f_dst_center);
l_iter = l_first = BM_FACE_FIRST_LOOP(f);
do {
BM_loop_interp_multires_ex(bm, l_iter, f_tmp, f_dst_center, f_src_center, cd_loop_mdisp_offset);
} while ((l_iter = l_iter->next) != l_first);
BM_face_interp_multires_ex(bm, f, f_tmp, f_dst_center, f_src_center, cd_loop_mdisp_offset);
BM_face_calc_center_mean(f_new, f_dst_center);
l_iter = l_first = BM_FACE_FIRST_LOOP(f_new);
do {
BM_loop_interp_multires_ex(bm, l_iter, f_tmp, f_dst_center, f_src_center, cd_loop_mdisp_offset);
} while ((l_iter = l_iter->next) != l_first);
BM_face_interp_multires_ex(bm, f_new, f_tmp, f_dst_center, f_src_center, cd_loop_mdisp_offset);
#if 0
/* BM_face_multires_bounds_smooth doesn't flip displacement correct */
@ -1229,7 +1221,7 @@ BMVert *BM_edge_split(BMesh *bm, BMEdge *e, BMVert *v, BMEdge **r_e, float fac)
for (j = 0; j < 2; j++) {
BMEdge *e1 = j ? *r_e : e;
BMLoop *l, *l2;
BMLoop *l;
l = e1->l;
@ -1241,17 +1233,12 @@ BMVert *BM_edge_split(BMesh *bm, BMEdge *e, BMVert *v, BMEdge **r_e, float fac)
do {
/* check this is an old face */
if (BM_ELEM_API_FLAG_TEST(l->f, _FLAG_OVERLAP)) {
BMLoop *l2_first;
float f_center[3];
BM_face_calc_center_mean(l->f, f_center);
l2 = l2_first = BM_FACE_FIRST_LOOP(l->f);
do {
BM_loop_interp_multires_ex(
bm, l2, oldfaces[i],
f_center, f_center_old, cd_loop_mdisp_offset);
} while ((l2 = l2->next) != l2_first);
BM_face_interp_multires_ex(
bm, l->f, oldfaces[i],
f_center, f_center_old, cd_loop_mdisp_offset);
}
l = l->radial_next;
} while (l != e1->l);

@ -5483,11 +5483,12 @@ static void slide_origdata_interp_data_vert(
float *loop_weights;
const bool is_moved = (len_squared_v3v3(sv->v->co, sv->co_orig_3d) > FLT_EPSILON);
const bool do_loop_weight = sod->layer_math_map_num && is_moved;
const bool do_loop_mdisps = is_final && is_moved && (sod->cd_loop_mdisp_offset != -1);
const float *v_proj_axis = sv->v->no;
/* original (l->prev, l, l->next) projections for each loop ('l' remains unchanged) */
float v_proj[3][3];
if (do_loop_weight) {
if (do_loop_weight || do_loop_mdisps) {
project_plane_v3_v3v3(v_proj[1], sv->co_orig_3d, v_proj_axis);
}
@ -5569,7 +5570,7 @@ static void slide_origdata_interp_data_vert(
* Interpolate from every other loop (not ideal)
* However values will only be taken from loops which overlap other mdisps.
* */
if (is_final && is_moved && (sod->cd_loop_mdisp_offset != -1)) {
if (do_loop_mdisps) {
float (*faces_center)[3] = BLI_array_alloca(faces_center, l_num);
BMLoop *l;
@ -5587,8 +5588,8 @@ static void slide_origdata_interp_data_vert(
BM_face_calc_center_mean(f_copy, f_copy_center);
BM_ITER_ELEM_INDEX (l_other, &liter_other, sv->v, BM_LOOPS_OF_VERT, j_other) {
BM_loop_interp_multires_ex(
bm, l_other, f_copy,
BM_face_interp_multires_ex(
bm, l_other->f, f_copy,
faces_center[j_other], f_copy_center, sod->cd_loop_mdisp_offset);
}
}