Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c
| Show First 20 Lines • Show All 598 Lines • ▼ Show 20 Lines | typedef struct WPGradient_userData { | ||||
| float weightpaint; | float weightpaint; | ||||
| } WPGradient_userData; | } WPGradient_userData; | ||||
| static void gradientVert_update(WPGradient_userData *grad_data, int index) | static void gradientVert_update(WPGradient_userData *grad_data, int index) | ||||
| { | { | ||||
| Mesh *me = grad_data->me; | Mesh *me = grad_data->me; | ||||
| WPGradient_vertStore *vs = &grad_data->vert_cache->elem[index]; | WPGradient_vertStore *vs = &grad_data->vert_cache->elem[index]; | ||||
| /* Optionally restrict to assigned verices only. */ | /* Optionally restrict to assigned verices only. */ | ||||
campbellbarton: This can be moved under the `VGRAD_STORE_DW_EXIST` check below. Since that situation won't ever… | |||||
| if (grad_data->use_vgroup_restrict && ((vs->flag & VGRAD_STORE_DW_EXIST) == 0)) { | if (grad_data->use_vgroup_restrict && ((vs->flag & VGRAD_STORE_DW_EXIST) == 0)) { | ||||
| return; | return; | ||||
| } | } | ||||
| float alpha; | float alpha; | ||||
| if (grad_data->type == WPAINT_GRADIENT_TYPE_LINEAR) { | if (grad_data->type == WPAINT_GRADIENT_TYPE_LINEAR) { | ||||
| alpha = line_point_factor_v2(vs->sco, grad_data->sco_start, grad_data->sco_end); | alpha = line_point_factor_v2(vs->sco, grad_data->sco_start, grad_data->sco_end); | ||||
| } | } | ||||
| Show All 30 Lines | else { | ||||
| /* wasn't originally existing, remove */ | /* wasn't originally existing, remove */ | ||||
| MDeformWeight *dw = BKE_defvert_find_index(dv, grad_data->def_nr); | MDeformWeight *dw = BKE_defvert_find_index(dv, grad_data->def_nr); | ||||
| if (dw) { | if (dw) { | ||||
| BKE_defvert_remove_group(dv, dw); | BKE_defvert_remove_group(dv, dw); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
Done Inline ActionsThis should be moved into the alpha != 0.0 block above. campbellbarton: This should be moved into the `alpha != 0.0` block above.
| |||||
| static void gradientVertUpdate__mapFunc(void *userData, | static void gradientVertUpdate__mapFunc(void *userData, | ||||
| int index, | int index, | ||||
| const float UNUSED(co[3]), | const float UNUSED(co[3]), | ||||
| const float UNUSED(no_f[3]), | const float UNUSED(no_f[3]), | ||||
| const short UNUSED(no_s[3])) | const short UNUSED(no_s[3])) | ||||
| { | { | ||||
| WPGradient_userData *grad_data = userData; | WPGradient_userData *grad_data = userData; | ||||
| WPGradient_vertStore *vs = &grad_data->vert_cache->elem[index]; | WPGradient_vertStore *vs = &grad_data->vert_cache->elem[index]; | ||||
| ▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | static int paint_weight_gradient_exec(bContext *C, wmOperator *op) | ||||
| int x_end = RNA_int_get(op->ptr, "xend"); | int x_end = RNA_int_get(op->ptr, "xend"); | ||||
| int y_end = RNA_int_get(op->ptr, "yend"); | int y_end = RNA_int_get(op->ptr, "yend"); | ||||
| const float sco_start[2] = {x_start, y_start}; | const float sco_start[2] = {x_start, y_start}; | ||||
| const float sco_end[2] = {x_end, y_end}; | const float sco_end[2] = {x_end, y_end}; | ||||
| const bool is_interactive = (gesture != NULL); | const bool is_interactive = (gesture != NULL); | ||||
| Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); | Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); | ||||
| WPGradient_userData data = {NULL}; | WPGradient_userData data = {NULL}; | ||||
Done Inline ActionsProbably a mistake to add an empty line ankitm: Probably a mistake to add an empty line | |||||
| if (is_interactive) { | if (is_interactive) { | ||||
| if (gesture->user_data.data == NULL) { | if (gesture->user_data.data == NULL) { | ||||
| gesture->user_data.data = MEM_mallocN(sizeof(WPGradient_vertStoreBase) + | gesture->user_data.data = MEM_mallocN(sizeof(WPGradient_vertStoreBase) + | ||||
| (sizeof(WPGradient_vertStore) * me->totvert), | (sizeof(WPGradient_vertStore) * me->totvert), | ||||
| __func__); | __func__); | ||||
| gesture->user_data.use_free = false; | gesture->user_data.use_free = false; | ||||
| data.is_init = true; | data.is_init = true; | ||||
| ▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | static int paint_weight_gradient_exec(bContext *C, wmOperator *op) | ||||
| } | } | ||||
| DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); | DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); | ||||
| WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob); | WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob); | ||||
| if (is_interactive == false) { | if (is_interactive == false) { | ||||
| MEM_freeN(vert_cache); | MEM_freeN(vert_cache); | ||||
| } | } | ||||
| const int vgroup_tot = BLI_listbase_count(&ob->defbase); | |||||
| const int def_nr_lock = ob->actdef - 1; | |||||
| const bool is_normalize = scene->toolsettings->auto_normalize; | |||||
Done Inline ActionsRemove "fix". Comment to concisely describe what the code below does is fine. ankitm: Remove "fix". Comment to concisely describe what the code below does is fine. | |||||
| const bool *vgroup_validmap = BKE_object_defgroup_validmap_get(ob, vgroup_tot); | |||||
Done Inline ActionsThis needs to be freed. campbellbarton: This needs to be freed. | |||||
| MDeformVert *dvert = me->dvert; | |||||
| data.vert_visit = BLI_BITMAP_NEW(me->totvert, __func__); | |||||
Done Inline ActionsThis should be initialized from BKE_object_defgroup_validmap_get. campbellbarton: This should be initialized from `BKE_object_defgroup_validmap_get`. | |||||
Not Done Inline ActionsMy mistake, that functions checks bones, this should be BKE_object_defgroup_lock_flags_get - to respect the groups lock icon. campbellbarton: My mistake, that functions checks bones, this should be `BKE_object_defgroup_lock_flags_get`… | |||||
| BKE_mesh_foreach_mapped_vert(me_eval, gradientVertInit__mapFunc, &data, MESH_FOREACH_NOP); | |||||
Done Inline ActionsDon't declare uninitialized variables. ankitm: Don't declare uninitialized variables. | |||||
| if (is_normalize) { | |||||
| for (int i = 0; i < me->totvert; i++) { | |||||
Done Inline Actionsconst bool is_normalize ankitm: `const bool is_normalize` | |||||
| MDeformVert *dv = (dvert + i); | |||||
| if (BLI_BITMAP_TEST(data.vert_visit , i)) { | |||||
| BKE_defvert_normalize_lock_single(dv, vgroup_validmap, vgroup_tot, def_nr_lock); | |||||
| } | |||||
| } | |||||
| } | |||||
Done Inline ActionsThis entire block can be in an if (is_normalized) {...} check. campbellbarton: This entire block can be in an `if (is_normalized) {...}` check. | |||||
| MEM_freeN(data.vert_visit); | |||||
campbellbartonUnsubmitted Done Inline ActionsThis is unnecessary data.vert_visit is already created and freed above (line 840 without this patch applied). campbellbarton: This is unnecessary `data.vert_visit` is already created and freed above (line 840 without this… | |||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
Done Inline Actionsvc is only used to access scene use: Scene *scene = CTX_data_scene(C); instead. campbellbarton: `vc` is only used to access `scene` use: `Scene *scene = CTX_data_scene(C);` instead. | |||||
| } | } | ||||
| static int paint_weight_gradient_invoke(bContext *C, wmOperator *op, const wmEvent *event) | static int paint_weight_gradient_invoke(bContext *C, wmOperator *op, const wmEvent *event) | ||||
Done Inline Actions4 empty lines seem overdone here ankitm: 4 empty lines seem overdone here | |||||
| { | { | ||||
| int ret; | int ret; | ||||
| if (ED_wpaint_ensure_data(C, op->reports, 0, NULL) == false) { | if (ED_wpaint_ensure_data(C, op->reports, 0, NULL) == false) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| ret = WM_gesture_straightline_invoke(C, op, event); | ret = WM_gesture_straightline_invoke(C, op, event); | ||||
| ▲ Show 20 Lines • Show All 46 Lines • Show Last 20 Lines | |||||
This can be moved under the VGRAD_STORE_DW_EXIST check below. Since that situation won't ever cause the vertices to be painted onto.