Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c
| Show First 20 Lines • Show All 564 Lines • ▼ Show 20 Lines | |||||
| /* *** VGroups Gradient *** */ | /* *** VGroups Gradient *** */ | ||||
| typedef struct WPGradient_vertStore { | typedef struct WPGradient_vertStore { | ||||
| float sco[2]; | float sco[2]; | ||||
| float weight_orig; | float weight_orig; | ||||
| enum { | enum { | ||||
| VGRAD_STORE_NOP = 0, | VGRAD_STORE_NOP = 0, | ||||
| VGRAD_STORE_DW_EXIST = (1 << 0), | VGRAD_STORE_DW_EXIST = (1 << 0), | ||||
| VGRAD_STORE_IS_MODIFIED = (1 << 1) | |||||
| } flag; | } flag; | ||||
| } WPGradient_vertStore; | } WPGradient_vertStore; | ||||
| typedef struct WPGradient_vertStoreBase { | typedef struct WPGradient_vertStoreBase { | ||||
| struct WPaintPrev wpp; | struct WPaintPrev wpp; | ||||
| WPGradient_vertStore elem[0]; | WPGradient_vertStore elem[0]; | ||||
| } WPGradient_vertStoreBase; | } WPGradient_vertStoreBase; | ||||
| Show All 18 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]; | ||||
| vs->flag &= ~VGRAD_STORE_IS_MODIFIED; | |||||
campbellbarton: This can be moved under the `VGRAD_STORE_DW_EXIST` check below. Since that situation won't ever… | |||||
| /* Optionally restrict to assigned verices only. */ | /* Optionally restrict to assigned verices only. */ | ||||
| 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 14 Lines | if (alpha != 0.0f) { | ||||
| int tool = grad_data->brush->blend; | int tool = grad_data->brush->blend; | ||||
| float testw; | float testw; | ||||
| /* init if we just added */ | /* init if we just added */ | ||||
| testw = ED_wpaint_blend_tool( | testw = ED_wpaint_blend_tool( | ||||
| tool, vs->weight_orig, grad_data->weightpaint, alpha * grad_data->brush->alpha); | tool, vs->weight_orig, grad_data->weightpaint, alpha * grad_data->brush->alpha); | ||||
| CLAMP(testw, 0.0f, 1.0f); | CLAMP(testw, 0.0f, 1.0f); | ||||
| dw->weight = testw; | dw->weight = testw; | ||||
| vs->flag |= VGRAD_STORE_IS_MODIFIED; | |||||
| } | } | ||||
| else { | else { | ||||
| MDeformVert *dv = &me->dvert[index]; | MDeformVert *dv = &me->dvert[index]; | ||||
| if (vs->flag & VGRAD_STORE_DW_EXIST) { | if (vs->flag & VGRAD_STORE_DW_EXIST) { | ||||
| /* normally we NULL check, but in this case we know it exists */ | /* normally we NULL check, but in this case we know it exists */ | ||||
| MDeformWeight *dw = BKE_defvert_find_index(dv, grad_data->def_nr); | MDeformWeight *dw = BKE_defvert_find_index(dv, grad_data->def_nr); | ||||
| dw->weight = vs->weight_orig; | dw->weight = vs->weight_orig; | ||||
| } | } | ||||
| else { | 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 97 Lines • ▼ Show 20 Lines | static int paint_weight_gradient_exec(bContext *C, wmOperator *op) | ||||
| Object *ob = CTX_data_active_object(C); | Object *ob = CTX_data_active_object(C); | ||||
| Mesh *me = ob->data; | Mesh *me = ob->data; | ||||
| int x_start = RNA_int_get(op->ptr, "xstart"); | int x_start = RNA_int_get(op->ptr, "xstart"); | ||||
| int y_start = RNA_int_get(op->ptr, "ystart"); | int y_start = RNA_int_get(op->ptr, "ystart"); | ||||
| 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); | ||||
Done Inline ActionsProbably a mistake to add an empty line ankitm: Probably a mistake to add an empty line | |||||
| Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); | Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); | ||||
| WPGradient_userData data = {NULL}; | WPGradient_userData data = {NULL}; | ||||
| 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) + | ||||
| ▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | else { | ||||
| BKE_mesh_foreach_mapped_vert(me_eval, gradientVertUpdate__mapFunc, &data, MESH_FOREACH_NOP); | BKE_mesh_foreach_mapped_vert(me_eval, gradientVertUpdate__mapFunc, &data, MESH_FOREACH_NOP); | ||||
| } | } | ||||
| 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); | ||||
| } | } | ||||
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 is_normalize = scene->toolsettings->auto_normalize; | |||||
| if (is_normalize) { | |||||
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. | |||||
Done Inline ActionsDon't declare uninitialized variables. ankitm: Don't declare uninitialized variables. | |||||
Done Inline ActionsThis needs to be freed. campbellbarton: This needs to be freed. | |||||
| const int vgroup_tot = BLI_listbase_count(&ob->defbase); | |||||
| const int def_nr_lock = ob->actdef - 1; | |||||
| const bool *vgroup_validmap = BKE_object_defgroup_validmap_get(ob, vgroup_tot); | |||||
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`… | |||||
| MDeformVert *dvert = me->dvert; | |||||
Done Inline Actionsconst bool is_normalize ankitm: `const bool is_normalize` | |||||
| for (int i = 0; i < me->totvert; i++) { | |||||
| MDeformVert *dv = (dvert + i); | |||||
| if (data.vert_cache->elem[i].flag & VGRAD_STORE_IS_MODIFIED) { | |||||
| BKE_defvert_normalize_lock_single(dv, vgroup_validmap, vgroup_tot, def_nr_lock); | |||||
| } | |||||
| } | |||||
| MEM_freeN(vgroup_validmap); | |||||
| } | |||||
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. | |||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
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… | |||||
Done Inline Actions4 empty lines seem overdone here ankitm: 4 empty lines seem overdone here | |||||
| 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) | ||||
| { | { | ||||
| 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; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 47 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.