Sculpt: Store explicit value for multires sculpt level

Allows to know what level sculpting has been done after the value has
been changed in the MultiresModifierData.

No functional changes, just preparing code to have everything needed
for propagation undo.

Differential Revision: https://developer.blender.org/D7307
This commit is contained in:
Sergey Sharybin 2020-04-02 10:10:13 +02:00
parent f868d51bdd
commit 3dad6294da
6 changed files with 22 additions and 11 deletions

View File

@ -283,7 +283,11 @@ typedef struct SculptClothSimulation {
typedef struct SculptSession {
/* Mesh data (not copied) can come either directly from a Mesh, or from a MultiresDM */
struct MultiresModifierData *multires; /* Special handling for multires meshes */
struct { /* Special handling for multires meshes */
bool active;
struct MultiresModifierData *modifier;
int level;
} multires;
struct MVert *mvert;
struct MPoly *mpoly;
struct MLoop *mloop;

View File

@ -473,7 +473,8 @@ void multires_flush_sculpt_updates(Object *object)
}
SculptSession *sculpt_session = object->sculpt;
if (BKE_pbvh_type(sculpt_session->pbvh) != PBVH_GRIDS || sculpt_session->multires == NULL) {
if (BKE_pbvh_type(sculpt_session->pbvh) != PBVH_GRIDS || !sculpt_session->multires.active ||
sculpt_session->multires.modifier == NULL) {
return;
}
@ -488,7 +489,7 @@ void multires_flush_sculpt_updates(Object *object)
Mesh *mesh = object->data;
multiresModifier_reshapeFromCCG(
sculpt_session->multires->totlvl, mesh, sculpt_session->subdiv_ccg);
sculpt_session->multires.modifier->totlvl, mesh, sculpt_session->subdiv_ccg);
subdiv_ccg->dirty.coords = false;
subdiv_ccg->dirty.hidden = false;

View File

@ -400,7 +400,7 @@ static char get_effective_edge_crease_char(
const MultiresReshapeSmoothContext *reshape_smooth_context, const MEdge *base_edge)
{
const MultiresReshapeContext *reshape_context = reshape_smooth_context->reshape_context;
if (reshape_context->mmd->simple) {
if (reshape_context->subdiv->settings.is_simple) {
return 255;
}
return base_edge->crease;

View File

@ -1522,7 +1522,9 @@ static void sculpt_update_object(
/* NOTE: Weight pPaint require mesh info for loop lookup, but it never uses multires code path,
* so no extra checks is needed here. */
if (mmd) {
ss->multires = mmd;
ss->multires.active = true;
ss->multires.modifier = mmd;
ss->multires.level = mmd->sculptlvl;
ss->totvert = me_eval->totvert;
ss->totpoly = me_eval->totpoly;
ss->totfaces = me->totpoly;
@ -1537,7 +1539,9 @@ static void sculpt_update_object(
ss->mvert = me->mvert;
ss->mpoly = me->mpoly;
ss->mloop = me->mloop;
ss->multires = NULL;
ss->multires.active = false;
ss->multires.modifier = NULL;
ss->multires.level = 0;
ss->vmask = CustomData_get_layer(&me->vdata, CD_PAINT_MASK);
}

View File

@ -5083,7 +5083,7 @@ static void do_layer_brush_task_cb_ex(void *__restrict userdata,
mul_v3_v3fl(val, offset, *disp);
if (!ss->multires && !ss->bm && ss->layer_co && (brush->flag & BRUSH_PERSISTENT)) {
if (!ss->multires.active && !ss->bm && ss->layer_co && (brush->flag & BRUSH_PERSISTENT)) {
int index = vd.vert_indices[vd.i];
/* Persistent base. */
@ -6758,7 +6758,7 @@ static void sculpt_fix_noise_tear(Sculpt *sd, Object *ob)
Brush *brush = BKE_paint_brush(&sd->paint);
MTex *mtex = &brush->mtex;
if (ss->multires && mtex->tex && mtex->tex->type == TEX_NOISE) {
if (ss->multires.active && mtex->tex && mtex->tex->type == TEX_NOISE) {
multires_stitch_grids(ob);
}
}
@ -7096,7 +7096,7 @@ static void sculpt_update_cache_invariants(
/* Initialize layer brush displacements and persistent coords. */
if (brush->sculpt_tool == SCULPT_TOOL_LAYER) {
/* Not supported yet for multires or dynamic topology. */
if (!ss->multires && !ss->bm && !ss->layer_co && (brush->flag & BRUSH_PERSISTENT)) {
if (!ss->multires.active && !ss->bm && !ss->layer_co && (brush->flag & BRUSH_PERSISTENT)) {
if (!ss->layer_co) {
ss->layer_co = MEM_mallocN(sizeof(float) * 3 * ss->totvert, "sculpt mesh vertices copy");
}
@ -7862,7 +7862,7 @@ static void sculpt_flush_update_step(bContext *C, SculptUpdateType update_flags)
Object *ob = CTX_data_active_object(C);
SculptSession *ss = ob->sculpt;
ARegion *region = CTX_wm_region(C);
MultiresModifierData *mmd = ss->multires;
MultiresModifierData *mmd = ss->multires.modifier;
View3D *v3d = CTX_wm_view3d(C);
RegionView3D *rv3d = CTX_wm_region_view3d(C);

View File

@ -211,7 +211,9 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
if (ctx->object->sculpt != NULL) {
SculptSession *sculpt_session = ctx->object->sculpt;
sculpt_session->subdiv_ccg = result->runtime.subdiv_ccg;
sculpt_session->multires = mmd;
sculpt_session->multires.active = true;
sculpt_session->multires.modifier = mmd;
sculpt_session->multires.level = mmd->sculptlvl;
sculpt_session->totvert = mesh->totvert;
sculpt_session->totpoly = mesh->totpoly;
sculpt_session->mvert = NULL;