Cleanup: rename some sculpt variables for clarity

This commit is contained in:
Brecht Van Lommel 2019-10-07 17:27:56 +02:00
parent ad84f22628
commit e00a00db52
6 changed files with 48 additions and 46 deletions

View File

@ -220,7 +220,7 @@ typedef struct SculptSession {
struct MPoly *mpoly;
struct MLoop *mloop;
int totvert, totpoly;
struct KeyBlock *kb;
struct KeyBlock *shapekey_active;
float *vmask;
/* Mesh connectivity */
@ -243,10 +243,10 @@ typedef struct SculptSession {
bool show_mask;
/* Painting on deformed mesh */
bool modifiers_active; /* object is deformed with some modifiers */
float (*orig_cos)[3]; /* coords of undeformed mesh */
float (*deform_cos)[3]; /* coords of deformed mesh but without stroke displacement */
float (*deform_imats)[3][3]; /* crazyspace deformation matrices */
bool deform_modifiers_active; /* object is deformed with some modifiers */
float (*orig_cos)[3]; /* coords of undeformed mesh */
float (*deform_cos)[3]; /* coords of deformed mesh but without stroke displacement */
float (*deform_imats)[3][3]; /* crazyspace deformation matrices */
/* Used to cache the render of the active texture */
unsigned int texcache_side, *texcache, texcache_actual;

View File

@ -1184,7 +1184,7 @@ static void sculpt_update_object(
Mesh *me = BKE_object_get_original_mesh(ob);
MultiresModifierData *mmd = BKE_sculpt_multires_active(scene, ob);
ss->modifiers_active = sculpt_modifiers_active(scene, sd, ob);
ss->deform_modifiers_active = sculpt_modifiers_active(scene, sd, ob);
ss->show_mask = (sd->flags & SCULPT_HIDE_MASK) == 0;
ss->building_vp_handle = false;
@ -1205,7 +1205,7 @@ static void sculpt_update_object(
/* tessfaces aren't used and will become invalid */
BKE_mesh_tessface_clear(me);
ss->kb = (mmd == NULL) ? BKE_keyblock_from_object(ob) : NULL;
ss->shapekey_active = (mmd == NULL) ? BKE_keyblock_from_object(ob) : NULL;
/* NOTE: Weight pPaint require mesh info for loop lookup, but it never uses multires code path,
* so no extra checks is needed here. */
@ -1240,14 +1240,15 @@ static void sculpt_update_object(
pbvh_show_mask_set(ss->pbvh, ss->show_mask);
if (ss->modifiers_active) {
if (ss->deform_modifiers_active) {
if (!ss->orig_cos) {
int a;
BKE_sculptsession_free_deformMats(ss);
ss->orig_cos = (ss->kb) ? BKE_keyblock_convert_to_vertcos(ob, ss->kb) :
BKE_mesh_vert_coords_alloc(me, NULL);
ss->orig_cos = (ss->shapekey_active) ?
BKE_keyblock_convert_to_vertcos(ob, ss->shapekey_active) :
BKE_mesh_vert_coords_alloc(me, NULL);
BKE_crazyspace_build_sculpt(depsgraph, scene, ob, &ss->deform_imats, &ss->deform_cos);
BKE_pbvh_vert_coords_apply(ss->pbvh, ss->deform_cos, me->totvert);
@ -1261,15 +1262,15 @@ static void sculpt_update_object(
BKE_sculptsession_free_deformMats(ss);
}
if (ss->kb != NULL && ss->deform_cos == NULL) {
ss->deform_cos = BKE_keyblock_convert_to_vertcos(ob, ss->kb);
if (ss->shapekey_active != NULL && ss->deform_cos == NULL) {
ss->deform_cos = BKE_keyblock_convert_to_vertcos(ob, ss->shapekey_active);
}
/* if pbvh is deformed, key block is already applied to it */
if (ss->kb) {
if (ss->shapekey_active) {
bool pbvh_deformed = BKE_pbvh_is_deformed(ss->pbvh);
if (!pbvh_deformed || ss->deform_cos == NULL) {
float(*vertCos)[3] = BKE_keyblock_convert_to_vertcos(ob, ss->kb);
float(*vertCos)[3] = BKE_keyblock_convert_to_vertcos(ob, ss->shapekey_active);
if (vertCos) {
if (!pbvh_deformed) {
@ -1448,17 +1449,17 @@ static bool check_sculpt_object_deformed(Object *object, const bool for_construc
* on birth of PBVH and sculpt "layer" levels, so use PBVH only for internal brush
* stuff and show final evaluated mesh so user would see actual object shape.
*/
deformed |= object->sculpt->modifiers_active;
deformed |= object->sculpt->deform_modifiers_active;
if (for_construction) {
deformed |= object->sculpt->kb != NULL;
deformed |= object->sculpt->shapekey_active != NULL;
}
else {
/* As in case with modifiers, we can't synchronize deformation made against
* PBVH and non-locked keyblock, so also use PBVH only for brushes and
* final DM to give final result to user.
*/
deformed |= object->sculpt->kb && (object->shapeflag & OB_SHAPE_LOCK) == 0;
deformed |= object->sculpt->shapekey_active && (object->shapeflag & OB_SHAPE_LOCK) == 0;
}
return deformed;
@ -1587,7 +1588,7 @@ bool BKE_sculptsession_use_pbvh_draw(const Object *ob, const View3D *v3d)
if (BKE_pbvh_type(ss->pbvh) == PBVH_FACES) {
/* Regular mesh only draws from PBVH without modifiers and shape keys. */
const bool full_shading = (v3d && (v3d->shading.type > OB_SOLID));
return !(ss->kb || ss->modifiers_active || full_shading);
return !(ss->shapekey_active || ss->deform_modifiers_active || full_shading);
}
else {
/* Multires and dyntopo always draw directly from the PBVH. */

View File

@ -155,8 +155,8 @@ static void SCULPT_cache_populate(void *vedata, Object *ob)
if (ob->sculpt) {
const DRWContextState *draw_ctx = DRW_context_state_get();
if ((ob == draw_ctx->obact) &&
(BKE_sculptsession_use_pbvh_draw(ob, draw_ctx->v3d) || !ob->sculpt->modifiers_active)) {
if ((ob == draw_ctx->obact) && (BKE_sculptsession_use_pbvh_draw(ob, draw_ctx->v3d) ||
!ob->sculpt->deform_modifiers_active)) {
PBVH *pbvh = ob->sculpt->pbvh;
if (pbvh && pbvh_has_mask(pbvh)) {
DRW_shgroup_call_sculpt(stl->g_data->mask_overlay_grp, ob, false, true, false);

View File

@ -1439,7 +1439,7 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused))
GPU_matrix_mul(vc.obact->obmat);
if (brush->sculpt_tool == SCULPT_TOOL_GRAB && (brush->flag & BRUSH_GRAB_ACTIVE_VERTEX) &&
!is_multires) {
if (BKE_pbvh_type(ss->pbvh) == PBVH_FACES && ss->modifiers_active) {
if (BKE_pbvh_type(ss->pbvh) == PBVH_FACES && ss->deform_modifiers_active) {
sculpt_geometry_preview_lines_update(C, ss, rds);
sculpt_geometry_preview_lines_draw(pos, ss);
}
@ -1492,7 +1492,7 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused))
/* Draw cached dynamic mesh preview lines */
if (brush->sculpt_tool == SCULPT_TOOL_GRAB && (brush->flag & BRUSH_GRAB_ACTIVE_VERTEX) &&
!is_multires) {
if (BKE_pbvh_type(ss->pbvh) == PBVH_FACES && ss->modifiers_active) {
if (BKE_pbvh_type(ss->pbvh) == PBVH_FACES && ss->deform_modifiers_active) {
GPU_matrix_push_projection();
ED_view3d_draw_setup_view(CTX_wm_window(C),
CTX_data_depsgraph_pointer(C),

View File

@ -5459,7 +5459,7 @@ static void sculpt_flush_pbvhvert_deform(Object *ob, PBVHVertexIter *vd)
copy_v3_v3(ss->deform_cos[index], vd->co);
copy_v3_v3(ss->orig_cos[index], newco);
if (!ss->kb) {
if (!ss->shapekey_active) {
copy_v3_v3(me->mvert[index].co, newco);
}
}
@ -5515,7 +5515,7 @@ static void sculpt_combine_proxies_task_cb(void *__restrict userdata,
sculpt_clip(sd, ss, vd.co, val);
if (ss->modifiers_active) {
if (ss->deform_modifiers_active) {
sculpt_flush_pbvhvert_deform(ob, &vd);
}
}
@ -5566,7 +5566,7 @@ static void sculpt_update_keyblock(Object *ob)
}
if (vertCos) {
sculpt_vertcos_to_key(ob, ss->kb, vertCos);
sculpt_vertcos_to_key(ob, ss->shapekey_active, vertCos);
if (vertCos != ss->orig_cos) {
MEM_freeN(vertCos);
@ -5612,7 +5612,7 @@ static void sculpt_flush_stroke_deform(Sculpt *sd, Object *ob, bool is_proxy_use
PBVHNode **nodes;
float(*vertCos)[3] = NULL;
if (ss->kb) {
if (ss->shapekey_active) {
vertCos = MEM_mallocN(sizeof(*vertCos) * me->totvert, "flushStrokeDeofrm keyVerts");
/* mesh could have isolated verts which wouldn't be in BVH,
@ -5637,7 +5637,7 @@ static void sculpt_flush_stroke_deform(Sculpt *sd, Object *ob, bool is_proxy_use
BLI_task_parallel_range(0, totnode, &data, sculpt_flush_stroke_deform_task_cb, &settings);
if (vertCos) {
sculpt_vertcos_to_key(ob, ss->kb, vertCos);
sculpt_vertcos_to_key(ob, ss->shapekey_active, vertCos);
MEM_freeN(vertCos);
}
@ -5648,7 +5648,7 @@ static void sculpt_flush_stroke_deform(Sculpt *sd, Object *ob, bool is_proxy_use
* after applying coords from keyblock on base mesh */
BKE_mesh_calc_normals(me);
}
else if (ss->kb) {
else if (ss->shapekey_active) {
sculpt_update_keyblock(ob);
}
}
@ -6412,7 +6412,8 @@ static void sculpt_stroke_modifiers_check(const bContext *C, Object *ob, const B
View3D *v3d = CTX_wm_view3d(C);
bool need_pmap = sculpt_needs_conectivity_info(brush, ss, 0);
if (ss->kb || ss->modifiers_active || (!BKE_sculptsession_use_pbvh_draw(ob, v3d) && need_pmap)) {
if (ss->shapekey_active || ss->deform_modifiers_active ||
(!BKE_sculptsession_use_pbvh_draw(ob, v3d) && need_pmap)) {
Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
BKE_sculpt_update_object_for_edit(depsgraph, ob, need_pmap, false);
}
@ -6911,7 +6912,7 @@ static void sculpt_flush_update_done(const bContext *C, Object *ob, SculptUpdate
/* optimization: if there is locked key and active modifiers present in */
/* the stack, keyblock is updating at each step. otherwise we could update */
/* keyblock only when stroke is finished */
if (ss->kb && !ss->modifiers_active) {
if (ss->shapekey_active && !ss->deform_modifiers_active) {
sculpt_update_keyblock(ob);
}
@ -7004,10 +7005,10 @@ static void sculpt_stroke_update_step(bContext *C,
* Same applies to the DEG_id_tag_update() invoked from
* sculpt_flush_update_step().
*/
if (ss->modifiers_active) {
if (ss->deform_modifiers_active) {
sculpt_flush_stroke_deform(sd, ob, sculpt_tool_is_proxy_used(brush->sculpt_tool));
}
else if (ss->kb) {
else if (ss->shapekey_active) {
sculpt_update_keyblock(ob);
}
@ -8428,7 +8429,7 @@ static int sculpt_mesh_filter_modal(bContext *C, wmOperator *op, const wmEvent *
&settings, (sd->flags & SCULPT_USE_OPENMP), ss->filter_cache->totnode);
BLI_task_parallel_range(0, ss->filter_cache->totnode, &data, mesh_filter_task_cb, &settings);
if (ss->modifiers_active || ss->kb) {
if (ss->deform_modifiers_active || ss->shapekey_active) {
sculpt_flush_stroke_deform(sd, ob, true);
}
@ -9594,7 +9595,7 @@ void ED_sculpt_update_modal_transform(struct bContext *C)
BLI_task_parallel_range(
0, ss->filter_cache->totnode, &data, sculpt_transform_task_cb, &settings);
if (ss->modifiers_active || ss->kb) {
if (ss->deform_modifiers_active || ss->shapekey_active) {
sculpt_flush_stroke_deform(sd, ob, true);
}

View File

@ -152,7 +152,7 @@ static bool sculpt_undo_restore_coords(bContext *C, Depsgraph *depsgraph, Sculpt
if (unode->maxvert) {
/* regular mesh restore */
if (ss->kb && !STREQ(ss->kb->name, unode->shapeName)) {
if (ss->shapekey_active && !STREQ(ss->shapekey_active->name, unode->shapeName)) {
/* shape key has been changed before calling undo operator */
Key *key = BKE_key_from_object(ob);
@ -174,12 +174,12 @@ static bool sculpt_undo_restore_coords(bContext *C, Depsgraph *depsgraph, Sculpt
index = unode->index;
mvert = ss->mvert;
if (ss->kb) {
if (ss->shapekey_active) {
float(*vertCos)[3];
vertCos = BKE_keyblock_convert_to_vertcos(ob, ss->kb);
vertCos = BKE_keyblock_convert_to_vertcos(ob, ss->shapekey_active);
if (unode->orig_co) {
if (ss->modifiers_active) {
if (ss->deform_modifiers_active) {
for (int i = 0; i < unode->totvert; i++) {
sculpt_undo_restore_deformed(ss, unode, i, index[i], vertCos[index[i]]);
}
@ -197,17 +197,17 @@ static bool sculpt_undo_restore_coords(bContext *C, Depsgraph *depsgraph, Sculpt
}
/* propagate new coords to keyblock */
sculpt_vertcos_to_key(ob, ss->kb, vertCos);
sculpt_vertcos_to_key(ob, ss->shapekey_active, vertCos);
/* pbvh uses it's own mvert array, so coords should be */
/* propagated to pbvh here */
BKE_pbvh_vert_coords_apply(ss->pbvh, vertCos, ss->kb->totelem);
BKE_pbvh_vert_coords_apply(ss->pbvh, vertCos, ss->shapekey_active->totelem);
MEM_freeN(vertCos);
}
else {
if (unode->orig_co) {
if (ss->modifiers_active) {
if (ss->deform_modifiers_active) {
for (int i = 0; i < unode->totvert; i++) {
sculpt_undo_restore_deformed(ss, unode, i, index[i], mvert[index[i]].co);
mvert[index[i]].flag |= ME_VERT_PBVH_UPDATE;
@ -628,7 +628,7 @@ static void sculpt_undo_restore_list(bContext *C, Depsgraph *depsgraph, ListBase
tag_update |= ((Mesh *)ob->data)->id.us > 1 || !BKE_sculptsession_use_pbvh_draw(ob, v3d);
if (ss->kb || ss->modifiers_active) {
if (ss->shapekey_active || ss->deform_modifiers_active) {
Mesh *mesh = ob->data;
BKE_mesh_calc_normals(mesh);
@ -831,7 +831,7 @@ static SculptUndoNode *sculpt_undo_alloc_node(Object *ob, PBVHNode *node, Sculpt
unode->index = MEM_mapallocN(sizeof(int) * allvert, "SculptUndoNode.index");
}
if (ss->modifiers_active) {
if (ss->deform_modifiers_active) {
unode->orig_co = MEM_callocN(allvert * sizeof(*unode->orig_co), "undoSculpt orig_cos");
}
@ -853,7 +853,7 @@ static void sculpt_undo_store_coords(Object *ob, SculptUndoNode *unode)
normal_float_to_short_v3(unode->no[vd.i], vd.fno);
}
if (ss->modifiers_active) {
if (ss->deform_modifiers_active) {
copy_v3_v3(unode->orig_co[vd.i], ss->orig_cos[unode->index[vd.i]]);
}
}
@ -1082,8 +1082,8 @@ SculptUndoNode *sculpt_undo_push_node(Object *ob, PBVHNode *node, SculptUndoType
copy_v3_v3(unode->pivot_rot, ss->pivot_rot);
/* store active shape key */
if (ss->kb) {
BLI_strncpy(unode->shapeName, ss->kb->name, sizeof(ss->kb->name));
if (ss->shapekey_active) {
BLI_strncpy(unode->shapeName, ss->shapekey_active->name, sizeof(ss->shapekey_active->name));
}
else {
unode->shapeName[0] = '\0';