Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/paint.c
| Show First 20 Lines • Show All 1,478 Lines • ▼ Show 20 Lines | |||||
| /** | /** | ||||
| * \param need_mask: So that the evaluated mesh that is returned has mask data. | * \param need_mask: So that the evaluated mesh that is returned has mask data. | ||||
| */ | */ | ||||
| static void sculpt_update_object(Depsgraph *depsgraph, | static void sculpt_update_object(Depsgraph *depsgraph, | ||||
| Object *ob, | Object *ob, | ||||
| Mesh *me_eval, | Mesh *me_eval, | ||||
| bool need_pmap, | bool need_pmap, | ||||
| bool need_mask, | bool need_mask, | ||||
| bool need_colors) | bool UNUSED(need_colors)) | ||||
| { | { | ||||
| Scene *scene = DEG_get_input_scene(depsgraph); | Scene *scene = DEG_get_input_scene(depsgraph); | ||||
| Sculpt *sd = scene->toolsettings->sculpt; | Sculpt *sd = scene->toolsettings->sculpt; | ||||
| SculptSession *ss = ob->sculpt; | SculptSession *ss = ob->sculpt; | ||||
| Mesh *me = BKE_object_get_original_mesh(ob); | Mesh *me = BKE_object_get_original_mesh(ob); | ||||
| MultiresModifierData *mmd = BKE_sculpt_multires_active(scene, ob); | MultiresModifierData *mmd = BKE_sculpt_multires_active(scene, ob); | ||||
| const bool use_face_sets = (ob->mode & OB_MODE_SCULPT) != 0; | const bool use_face_sets = (ob->mode & OB_MODE_SCULPT) != 0; | ||||
| Show All 13 Lines | if (need_mask) { | ||||
| } | } | ||||
| else { | else { | ||||
| if (!CustomData_has_layer(&me->ldata, CD_GRID_PAINT_MASK)) { | if (!CustomData_has_layer(&me->ldata, CD_GRID_PAINT_MASK)) { | ||||
| BKE_sculpt_mask_layers_ensure(ob, mmd); | BKE_sculpt_mask_layers_ensure(ob, mmd); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* Add a color layer if a color tool is used. */ | |||||
| Mesh *orig_me = BKE_object_get_original_mesh(ob); | |||||
| if (need_colors && U.experimental.use_sculpt_vertex_colors) { | |||||
| if (!CustomData_has_layer(&orig_me->vdata, CD_PROP_COLOR)) { | |||||
| CustomData_add_layer(&orig_me->vdata, CD_PROP_COLOR, CD_DEFAULT, NULL, orig_me->totvert); | |||||
| BKE_mesh_update_customdata_pointers(orig_me, true); | |||||
| DEG_id_tag_update(&orig_me->id, ID_RECALC_GEOMETRY); | |||||
| } | |||||
| } | |||||
| /* tessfaces aren't used and will become invalid */ | /* tessfaces aren't used and will become invalid */ | ||||
| BKE_mesh_tessface_clear(me); | BKE_mesh_tessface_clear(me); | ||||
| ss->shapekey_active = (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, | /* NOTE: Weight pPaint require mesh info for loop lookup, but it never uses multires code path, | ||||
| * so no extra checks is needed here. */ | * so no extra checks is needed here. */ | ||||
| if (mmd) { | if (mmd) { | ||||
| ▲ Show 20 Lines • Show All 144 Lines • ▼ Show 20 Lines | |||||
| void BKE_sculpt_update_object_after_eval(Depsgraph *depsgraph, Object *ob_eval) | void BKE_sculpt_update_object_after_eval(Depsgraph *depsgraph, Object *ob_eval) | ||||
| { | { | ||||
| /* Update after mesh evaluation in the dependency graph, to rebuild PBVH or | /* Update after mesh evaluation in the dependency graph, to rebuild PBVH or | ||||
| * other data when modifiers change the mesh. */ | * other data when modifiers change the mesh. */ | ||||
| Object *ob_orig = DEG_get_original_object(ob_eval); | Object *ob_orig = DEG_get_original_object(ob_eval); | ||||
| Mesh *me_eval = BKE_object_get_evaluated_mesh(ob_eval); | Mesh *me_eval = BKE_object_get_evaluated_mesh(ob_eval); | ||||
| BLI_assert(me_eval != NULL); | BLI_assert(me_eval != NULL); | ||||
| sculpt_update_object(depsgraph, ob_orig, me_eval, false, false, false); | sculpt_update_object(depsgraph, ob_orig, me_eval, false, false, false); | ||||
| } | } | ||||
| bool BKE_sculpt_color_layers_ensure(struct Object *object) | |||||
sergey: This is a weird semantic. Ensure is "make sure", "guarantee". Conditional behavior based on… | |||||
| { | |||||
| Mesh *orig_me = BKE_object_get_original_mesh(object); | |||||
| if (!U.experimental.use_sculpt_vertex_colors) { | |||||
| return false; | |||||
| } | |||||
| if (CustomData_has_layer(&orig_me->vdata, CD_PROP_COLOR)) { | |||||
| return false; | |||||
| } | |||||
| CustomData_add_layer(&orig_me->vdata, CD_PROP_COLOR, CD_DEFAULT, NULL, orig_me->totvert); | |||||
| BKE_mesh_update_customdata_pointers(orig_me, true); | |||||
| DEG_id_tag_update(&orig_me->id, ID_RECALC_GEOMETRY); | |||||
| return true; | |||||
| } | |||||
| void BKE_sculpt_update_object_for_edit( | void BKE_sculpt_update_object_for_edit( | ||||
| Depsgraph *depsgraph, Object *ob_orig, bool need_pmap, bool need_mask, bool need_colors) | Depsgraph *depsgraph, Object *ob_orig, bool need_pmap, bool need_mask, bool need_colors) | ||||
| { | { | ||||
| /* Update from sculpt operators and undo, to update sculpt session | /* Update from sculpt operators and undo, to update sculpt session | ||||
| * and PBVH after edits. */ | * and PBVH after edits. */ | ||||
| Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); | Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); | ||||
| Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob_orig); | Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob_orig); | ||||
| Mesh *me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_eval, &CD_MASK_BAREMESH); | Mesh *me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_eval, &CD_MASK_BAREMESH); | ||||
| ▲ Show 20 Lines • Show All 268 Lines • Show Last 20 Lines | |||||
This is a weird semantic. Ensure is "make sure", "guarantee". Conditional behavior based on experimental feature set enabled does not fit this definition.
Consider something like this instead:
/* Create new color layer on object if it doesn't have one and if experimental feature set has sculpt vertex color enabled. * Returns truth if new layer has been added, false otherwise. */ bool BKE_sculpt_color_layer_create_if_needed(Object *object) { }P.S. After reading the rest of the patch, I don't see where the return value is used. Is still fine to have it, but can as well replace with void.