Cleanup: Use array and span in weighted normal modifier
This commit is contained in:
@@ -97,7 +97,7 @@ struct WeightedNormalData {
|
||||
/* Lower-level, internal processing data. */
|
||||
float cached_inverse_powers_of_weight[NUM_CACHED_INVERSE_POWERS_OF_WEIGHT];
|
||||
|
||||
WeightedNormalDataAggregateItem *items_data;
|
||||
blender::Span<WeightedNormalDataAggregateItem> items_data;
|
||||
|
||||
ModePair *mode_pair;
|
||||
};
|
||||
@@ -214,9 +214,8 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd,
|
||||
|
||||
blender::Array<blender::float3> loop_normals;
|
||||
|
||||
WeightedNormalDataAggregateItem *items_data = nullptr;
|
||||
Array<int> item_index_per_corner(corner_verts.size(), 0);
|
||||
int items_num = 0;
|
||||
Array<WeightedNormalDataAggregateItem> items_data;
|
||||
Array<int> item_index_per_corner;
|
||||
if (keep_sharp) {
|
||||
BLI_bitmap *done_loops = BLI_BITMAP_NEW(corner_verts.size(), __func__);
|
||||
|
||||
@@ -239,9 +238,9 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd,
|
||||
&lnors_spacearr,
|
||||
loop_normals);
|
||||
|
||||
items_num = lnors_spacearr.spaces_num;
|
||||
items_data = static_cast<WeightedNormalDataAggregateItem *>(
|
||||
MEM_calloc_arrayN(size_t(items_num), sizeof(*items_data), __func__));
|
||||
item_index_per_corner.reinitialize(corner_verts.size());
|
||||
items_data = Array<WeightedNormalDataAggregateItem>(lnors_spacearr.spaces_num,
|
||||
WeightedNormalDataAggregateItem{});
|
||||
|
||||
/* In this first loop, we assign each WeightedNormalDataAggregateItem
|
||||
* to its smooth fan of loops (aka lnor space). */
|
||||
@@ -277,11 +276,10 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd,
|
||||
MEM_freeN(done_loops);
|
||||
}
|
||||
else {
|
||||
items_num = verts_num;
|
||||
items_data = static_cast<WeightedNormalDataAggregateItem *>(
|
||||
MEM_calloc_arrayN(size_t(items_num), sizeof(*items_data), __func__));
|
||||
items_data = Array<WeightedNormalDataAggregateItem>(verts_num,
|
||||
WeightedNormalDataAggregateItem{});
|
||||
if (use_face_influence) {
|
||||
for (int item_index = 0; item_index < items_num; item_index++) {
|
||||
for (int item_index : items_data.index_range()) {
|
||||
items_data[item_index].curr_strength = FACE_STRENGTH_WEAK;
|
||||
}
|
||||
}
|
||||
@@ -324,7 +322,7 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd,
|
||||
}
|
||||
|
||||
/* Validate computed weighted normals. */
|
||||
for (int item_index = 0; item_index < items_num; item_index++) {
|
||||
for (int item_index : items_data.index_range()) {
|
||||
if (normalize_v3(items_data[item_index].normal) < CLNORS_VALID_VEC_LEN) {
|
||||
zero_v3(items_data[item_index].normal);
|
||||
}
|
||||
@@ -628,7 +626,6 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
|
||||
}
|
||||
|
||||
MEM_SAFE_FREE(wn_data.mode_pair);
|
||||
MEM_SAFE_FREE(wn_data.items_data);
|
||||
|
||||
result->runtime->is_original_bmesh = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user