Changeset View
Standalone View
source/blender/blenkernel/intern/deform.c
| Show First 20 Lines • Show All 357 Lines • ▼ Show 20 Lines | else { | ||||
| for (i = dvert->totweight, dw = dvert->dw; i != 0; i--, dw++) { | for (i = dvert->totweight, dw = dvert->dw; i != 0; i--, dw++) { | ||||
| if ((dw->def_nr < vgroup_tot) && vgroup_subset[dw->def_nr]) { | if ((dw->def_nr < vgroup_tot) && vgroup_subset[dw->def_nr]) { | ||||
| if (dw->def_nr != def_nr_lock) { | if (dw->def_nr != def_nr_lock) { | ||||
| tot_weight += dw->weight; | tot_weight += dw->weight; | ||||
| } | } | ||||
| else { | else { | ||||
| dw_lock = dw; | dw_lock = dw; | ||||
| lock_iweight = (1.0f - dw_lock->weight); | lock_iweight = (dw_lock->weight > 0.990) ? 0 : (1.0f - dw_lock->weight); | ||||
| CLAMP(lock_iweight, 0.0f, 1.0f); | CLAMP(lock_iweight, 0.0f, 1.0f); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| if (tot_weight > 0.0f) { | if (tot_weight > 0.0f) { | ||||
| /* paranoid, should be 1.0 but in case of float error clamp anyway */ | /* paranoid, should be 1.0 but in case of float error clamp anyway */ | ||||
| ▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | if (tot_weight > 0.0f) { | ||||
| CLAMP(dw->weight, 0.0f, 1.0f); | CLAMP(dw->weight, 0.0f, 1.0f); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void BKE_defvert_flip(MDeformVert *dvert, const int *flip_map, const int flip_map_len) | void BKE_defvert_flip(MDeformVert *dvert, const int *flip_map, const int flip_map_len) | ||||
campbellbarton: Regarding naming `BKE_devert_normalize_gradient_paint` isn't very informative, as it doesn't… | |||||
| { | { | ||||
Done Inline ActionsNo reason to pass both dv and dw, as you can access both with dv. campbellbarton: No reason to pass both `dv` and `dw`, as you can access both with `dv`. | |||||
| MDeformWeight *dw; | MDeformWeight *dw; | ||||
Not Done Inline ActionsFollow the naming style same as other variables in this module. tot is generally a prefix. ankitm: Follow the naming style same as other variables in this module. `tot` is generally a prefix. | |||||
| int i; | int i; | ||||
Done Inline Actionsdef_nr_lock can be const too ankitm: def_nr_lock can be const too | |||||
| for (dw = dvert->dw, i = 0; i < dvert->totweight; dw++, i++) { | for (dw = dvert->dw, i = 0; i < dvert->totweight; dw++, i++) { | ||||
| if (dw->def_nr < flip_map_len) { | if (dw->def_nr < flip_map_len) { | ||||
Not Done Inline ActionsMight want to early return here ? ankitm: Might want to early return here ? | |||||
| if (flip_map[dw->def_nr] >= 0) { | if (flip_map[dw->def_nr] >= 0) { | ||||
| dw->def_nr = flip_map[dw->def_nr]; | dw->def_nr = flip_map[dw->def_nr]; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
Done Inline ActionsEarly return here, and then remove the else (and the scope & indent it created). ankitm: Early return here, and then remove the `else` (and the scope & indent it created). | |||||
| void BKE_defvert_flip_merged(MDeformVert *dvert, const int *flip_map, const int flip_map_len) | void BKE_defvert_flip_merged(MDeformVert *dvert, const int *flip_map, const int flip_map_len) | ||||
| { | { | ||||
| MDeformWeight *dw, *dw_cpy; | MDeformWeight *dw, *dw_cpy; | ||||
Done Inline ActionsKeep the scope of i and other variables to the minimum. ankitm: Keep the scope of `i` and other variables to the minimum.
https://isocpp.github. | |||||
| float weight; | float weight; | ||||
| int i, totweight = dvert->totweight; | int i, totweight = dvert->totweight; | ||||
Done Inline ActionsIs the first i in lock_iweight a typo? I'm not familiar with the code here, so ignore if I'm wrong here. ankitm: Is the first `i` in `lock_iweight` a typo? I'm not familiar with the code here, so ignore if… | |||||
Done Inline ActionsI keep code block related to calculation of vertex weight similar to other function (eg. see BKE_defvert_normalize_lock_single ,BKE_defvert_normalize_lock_map) . PratikPB2123: I keep code block related to calculation of vertex weight similar to other function (eg. see… | |||||
| /* copy weights */ | /* copy weights */ | ||||
| for (dw = dvert->dw, i = 0; i < totweight; dw++, i++) { | for (dw = dvert->dw, i = 0; i < totweight; dw++, i++) { | ||||
| if (dw->def_nr < flip_map_len) { | if (dw->def_nr < flip_map_len) { | ||||
| if (flip_map[dw->def_nr] >= 0) { | if (flip_map[dw->def_nr] >= 0) { | ||||
| /* error checkers complain of this but we'll never get NULL return */ | /* error checkers complain of this but we'll never get NULL return */ | ||||
| dw_cpy = BKE_defvert_ensure_index(dvert, flip_map[dw->def_nr]); | dw_cpy = BKE_defvert_ensure_index(dvert, flip_map[dw->def_nr]); | ||||
| dw = &dvert->dw[i]; /* in case array got realloced */ | dw = &dvert->dw[i]; /* in case array got realloced */ | ||||
| /* distribute weights: if only one of the vertex groups was | /* distribute weights: if only one of the vertex groups was | ||||
| * assigned this will halve the weights, otherwise it gets | * assigned this will halve the weights, otherwise it gets | ||||
| * evened out. this keeps it proportional to other groups */ | * evened out. this keeps it proportional to other groups */ | ||||
| weight = 0.5f * (dw_cpy->weight + dw->weight); | weight = 0.5f * (dw_cpy->weight + dw->weight); | ||||
| dw_cpy->weight = weight; | dw_cpy->weight = weight; | ||||
| dw->weight = weight; | dw->weight = weight; | ||||
| } | } | ||||
Done Inline ActionsComments should start with capital letter, and end with period. Same elsewhere. ankitm: Comments should start with capital letter, and end with period. Same elsewhere. | |||||
Done Inline Actionssee BKE_defvert_normalize_lock_single or BKE_defvert_normalize_lock_map PratikPB2123: see `BKE_defvert_normalize_lock_single` or `BKE_defvert_normalize_lock_map` | |||||
| } | } | ||||
| } | } | ||||
Done Inline Actionsankitm: `const float scalar`
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#con1-by… | |||||
| } | } | ||||
| bDeformGroup *BKE_object_defgroup_find_name(const Object *ob, const char *name) | bDeformGroup *BKE_object_defgroup_find_name(const Object *ob, const char *name) | ||||
| { | { | ||||
| return (name && name[0] != '\0') ? | return (name && name[0] != '\0') ? | ||||
| BLI_findstring(&ob->defbase, name, offsetof(bDeformGroup, name)) : | BLI_findstring(&ob->defbase, name, offsetof(bDeformGroup, name)) : | ||||
| NULL; | NULL; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 874 Lines • Show Last 20 Lines | |||||
Regarding naming BKE_devert_normalize_gradient_paint isn't very informative, as it doesn't let developers know whats different. Also, if this is used in other situations, the name is likely to become meaningless.