Fix part of T70295: sculpt drawing not clipping PBVH nodes outside of viewport

As before in 2.7, this only works for optimized drawing in workbench mode.
This commit is contained in:
Brecht Van Lommel 2019-09-27 11:09:50 +02:00
parent 0901a72b6b
commit d3a98b2c3b
1 changed files with 26 additions and 1 deletions

View File

@ -888,6 +888,29 @@ static void sculpt_debug_cb(void *user_data,
}
#endif
static void drw_sculpt_get_frustum_planes(Object *ob, float planes[4][4])
{
/* TODO: take into account partial redraw for clipping planes. */
float frustum_planes[6][4];
DRW_view_frustum_planes_get(DRW_view_default_get(), frustum_planes);
/* PBVH only needs X/Y clipping planes, no Z depth.
* TODO: support Z depth clipping in PBVH. */
copy_v4_v4(planes[0], frustum_planes[0]);
copy_v4_v4(planes[1], frustum_planes[1]);
copy_v4_v4(planes[2], frustum_planes[3]);
copy_v4_v4(planes[3], frustum_planes[5]);
/* Transform clipping planes to object space. Transforming a plane with a
* 4x4 matrix is done by multiplying with the tranpose inverse. The inverse
* cancels out here since we transform by inverse(obmat). */
float tmat[4][4];
transpose_m4_m4(tmat, ob->obmat);
for (int i = 0; i < 4; i++) {
mul_m4_v4(tmat, planes[i]);
}
}
static void drw_sculpt_generate_calls(DRWSculptCallbackData *scd, bool use_vcol)
{
/* PBVH should always exist for non-empty meshes, created by depsgrah eval. */
@ -896,7 +919,9 @@ static void drw_sculpt_generate_calls(DRWSculptCallbackData *scd, bool use_vcol)
return;
}
float(*planes)[4] = NULL; /* TODO proper culling. */
float planes[4][4];
drw_sculpt_get_frustum_planes(scd->ob, planes);
scd->fast_mode = false;
const DRWContextState *drwctx = DRW_context_state_get();