diff --git a/source/blender/blenkernel/intern/cloth.cc b/source/blender/blenkernel/intern/cloth.cc index e300c4d5084..8924c4f3cd8 100644 --- a/source/blender/blenkernel/intern/cloth.cc +++ b/source/blender/blenkernel/intern/cloth.cc @@ -835,7 +835,7 @@ static bool cloth_from_object( static void cloth_from_mesh(ClothModifierData *clmd, const Object *ob, Mesh *mesh) { - const MLoop *mloop = BKE_mesh_loops(mesh); + const blender::Span loops = mesh->loops(); const MLoopTri *looptri = BKE_mesh_runtime_looptri_ensure(mesh); const uint mvert_num = mesh->totvert; const uint looptri_num = BKE_mesh_runtime_looptri_len(mesh); @@ -868,9 +868,10 @@ static void cloth_from_mesh(ClothModifierData *clmd, const Object *ob, Mesh *mes printf("cloth_free_modifier clmd->clothObject->looptri\n"); return; } - BKE_mesh_runtime_verttri_from_looptri(clmd->clothObject->tri, mloop, looptri, looptri_num); + BKE_mesh_runtime_verttri_from_looptri( + clmd->clothObject->tri, loops.data(), looptri, looptri_num); - clmd->clothObject->edges = BKE_mesh_edges(mesh); + clmd->clothObject->edges = mesh->edges().data(); /* Free the springs since they can't be correct if the vertices * changed. @@ -1288,8 +1289,8 @@ void cloth_parallel_transport_hair_frame(float mat[3][3], /* Add a shear and a bend spring between two verts within a poly. */ static bool cloth_add_shear_bend_spring(ClothModifierData *clmd, LinkNodePair *edgelist, - const MLoop *mloop, - const MPoly *mpoly, + const blender::Span loops, + const blender::Span polys, int i, int j, int k) @@ -1308,7 +1309,7 @@ static bool cloth_add_shear_bend_spring(ClothModifierData *clmd, } spring_verts_ordered_set( - spring, mloop[mpoly[i].loopstart + j].v, mloop[mpoly[i].loopstart + k].v); + spring, loops[polys[i].loopstart + j].v, loops[polys[i].loopstart + k].v); shrink_factor = cloth_shrink_factor(clmd, cloth->verts, spring->ij, spring->kl); spring->restlen = len_v3v3(cloth->verts[spring->kl].xrest, cloth->verts[spring->ij].xrest) * @@ -1328,7 +1329,7 @@ static bool cloth_add_shear_bend_spring(ClothModifierData *clmd, spring->type |= CLOTH_SPRING_TYPE_BENDING; spring->la = k - j + 1; - spring->lb = mpoly[i].totloop - k + j + 1; + spring->lb = polys[i].totloop - k + j + 1; spring->pa = static_cast(MEM_mallocN(sizeof(*spring->pa) * spring->la, "spring poly")); if (!spring->pa) { @@ -1340,7 +1341,7 @@ static bool cloth_add_shear_bend_spring(ClothModifierData *clmd, return false; } - tmp_loop = mloop + mpoly[i].loopstart; + tmp_loop = &loops[polys[i].loopstart]; for (x = 0; x < spring->la; x++) { spring->pa[x] = tmp_loop[j + x].v; @@ -1350,7 +1351,7 @@ static bool cloth_add_shear_bend_spring(ClothModifierData *clmd, spring->pb[x] = tmp_loop[x].v; } - for (y = k; y < mpoly[i].totloop; x++, y++) { + for (y = k; y < polys[i].totloop; x++, y++) { spring->pb[x] = tmp_loop[y].v; } @@ -1474,9 +1475,9 @@ static bool cloth_build_springs(ClothModifierData *clmd, Mesh *mesh) uint numedges = uint(mesh->totedge); uint numpolys = uint(mesh->totpoly); float shrink_factor; - const MEdge *medge = BKE_mesh_edges(mesh); - const MPoly *mpoly = BKE_mesh_polys(mesh); - const MLoop *mloop = BKE_mesh_loops(mesh); + const blender::Span edges = mesh->edges(); + const blender::Span polys = mesh->polys(); + const blender::Span loops = mesh->loops(); int index2 = 0; /* our second vertex index */ LinkNodePair *edgelist = nullptr; EdgeSet *edgeset = nullptr; @@ -1607,7 +1608,7 @@ static bool cloth_build_springs(ClothModifierData *clmd, Mesh *mesh) spring = (ClothSpring *)MEM_callocN(sizeof(ClothSpring), "cloth spring"); if (spring) { - spring_verts_ordered_set(spring, medge[i].v1, medge[i].v2); + spring_verts_ordered_set(spring, edges[i].v1, edges[i].v2); if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_SEW && loose_edges.count > 0 && loose_edges.is_loose_bits[i]) { /* handle sewing (loose edges will be pulled together) */ @@ -1615,7 +1616,7 @@ static bool cloth_build_springs(ClothModifierData *clmd, Mesh *mesh) spring->lin_stiffness = 1.0f; spring->type = CLOTH_SPRING_TYPE_SEWING; - BLI_edgeset_insert(cloth->sew_edge_graph, medge[i].v1, medge[i].v2); + BLI_edgeset_insert(cloth->sew_edge_graph, edges[i].v1, edges[i].v2); } else { shrink_factor = cloth_shrink_factor(clmd, cloth->verts, spring->ij, spring->kl); @@ -1668,10 +1669,10 @@ static bool cloth_build_springs(ClothModifierData *clmd, Mesh *mesh) for (int i = 0; i < numpolys; i++) { /* Shear springs. */ /* Triangle faces already have shear springs due to structural geometry. */ - if (mpoly[i].totloop > 3) { - for (int j = 1; j < mpoly[i].totloop - 1; j++) { + if (polys[i].totloop > 3) { + for (int j = 1; j < polys[i].totloop - 1; j++) { if (j > 1) { - if (cloth_add_shear_bend_spring(clmd, edgelist, mloop, mpoly, i, 0, j)) { + if (cloth_add_shear_bend_spring(clmd, edgelist, loops, polys, i, 0, j)) { shear_springs++; if (clmd->sim_parms->bending_model == CLOTH_BENDING_ANGULAR) { @@ -1684,8 +1685,8 @@ static bool cloth_build_springs(ClothModifierData *clmd, Mesh *mesh) } } - for (int k = j + 2; k < mpoly[i].totloop; k++) { - if (cloth_add_shear_bend_spring(clmd, edgelist, mloop, mpoly, i, j, k)) { + for (int k = j + 2; k < polys[i].totloop; k++) { + if (cloth_add_shear_bend_spring(clmd, edgelist, loops, polys, i, j, k)) { shear_springs++; if (clmd->sim_parms->bending_model == CLOTH_BENDING_ANGULAR) { @@ -1702,9 +1703,9 @@ static bool cloth_build_springs(ClothModifierData *clmd, Mesh *mesh) /* Angular bending springs along struct springs. */ if (clmd->sim_parms->bending_model == CLOTH_BENDING_ANGULAR) { - const MLoop *ml = mloop + mpoly[i].loopstart; + const MLoop *ml = &loops[polys[i].loopstart]; - for (int j = 0; j < mpoly[i].totloop; j++, ml++) { + for (int j = 0; j < polys[i].totloop; j++, ml++) { BendSpringRef *curr_ref = &spring_ref[ml->e]; curr_ref->polys++; @@ -1718,13 +1719,13 @@ static bool cloth_build_springs(ClothModifierData *clmd, Mesh *mesh) spring->type |= CLOTH_SPRING_TYPE_BENDING; - spring->la = mpoly[curr_ref->index].totloop; - spring->lb = mpoly[i].totloop; + spring->la = polys[curr_ref->index].totloop; + spring->lb = polys[i].totloop; if (!cloth_bend_set_poly_vert_array( - &spring->pa, spring->la, &mloop[mpoly[curr_ref->index].loopstart]) || + &spring->pa, spring->la, &loops[polys[curr_ref->index].loopstart]) || !cloth_bend_set_poly_vert_array( - &spring->pb, spring->lb, &mloop[mpoly[i].loopstart])) { + &spring->pb, spring->lb, &loops[polys[i].loopstart])) { cloth_free_errorsprings(cloth, edgelist, spring_ref); return false; } @@ -1890,13 +1891,13 @@ static bool cloth_build_springs(ClothModifierData *clmd, Mesh *mesh) /* insert other near springs in edgeset AFTER bending springs are calculated (for selfcolls) */ for (int i = 0; i < numedges; i++) { /* struct springs */ - BLI_edgeset_add(edgeset, medge[i].v1, medge[i].v2); + BLI_edgeset_add(edgeset, edges[i].v1, edges[i].v2); } for (int i = 0; i < numpolys; i++) { /* edge springs */ - if (mpoly[i].totloop == 4) { - BLI_edgeset_add(edgeset, mloop[mpoly[i].loopstart + 0].v, mloop[mpoly[i].loopstart + 2].v); - BLI_edgeset_add(edgeset, mloop[mpoly[i].loopstart + 1].v, mloop[mpoly[i].loopstart + 3].v); + if (polys[i].totloop == 4) { + BLI_edgeset_add(edgeset, loops[polys[i].loopstart + 0].v, loops[polys[i].loopstart + 2].v); + BLI_edgeset_add(edgeset, loops[polys[i].loopstart + 1].v, loops[polys[i].loopstart + 3].v); } } diff --git a/source/blender/blenkernel/intern/data_transfer.cc b/source/blender/blenkernel/intern/data_transfer.cc index 225011f1556..abb081e34d7 100644 --- a/source/blender/blenkernel/intern/data_transfer.cc +++ b/source/blender/blenkernel/intern/data_transfer.cc @@ -265,20 +265,24 @@ static void data_transfer_mesh_attributes_transfer_active_color_string( const char *active_color_src = BKE_id_attributes_active_color_name(&mesh_src->id); if ((data_type == CD_PROP_COLOR) && - !BKE_id_attribute_search(&mesh_src->id, active_color_src, CD_MASK_PROP_COLOR, ATTR_DOMAIN_MASK_COLOR)) { + !BKE_id_attribute_search( + &mesh_src->id, active_color_src, CD_MASK_PROP_COLOR, ATTR_DOMAIN_MASK_COLOR)) { return; } else if ((data_type == CD_PROP_BYTE_COLOR) && - !BKE_id_attribute_search(&mesh_src->id, active_color_src, CD_MASK_PROP_BYTE_COLOR, ATTR_DOMAIN_MASK_COLOR)) { + !BKE_id_attribute_search( + &mesh_src->id, active_color_src, CD_MASK_PROP_BYTE_COLOR, ATTR_DOMAIN_MASK_COLOR)) { return; } if ((data_type == CD_PROP_COLOR) && - BKE_id_attribute_search(&mesh_dst->id, active_color_src, CD_MASK_PROP_COLOR, ATTR_DOMAIN_MASK_COLOR)) { + BKE_id_attribute_search( + &mesh_dst->id, active_color_src, CD_MASK_PROP_COLOR, ATTR_DOMAIN_MASK_COLOR)) { mesh_dst->active_color_attribute = BLI_strdup(active_color_src); } else if ((data_type == CD_PROP_BYTE_COLOR) && - BKE_id_attribute_search(&mesh_dst->id, active_color_src, CD_MASK_PROP_BYTE_COLOR, ATTR_DOMAIN_MASK_COLOR)) { + BKE_id_attribute_search( + &mesh_dst->id, active_color_src, CD_MASK_PROP_BYTE_COLOR, ATTR_DOMAIN_MASK_COLOR)) { mesh_dst->active_color_attribute = BLI_strdup(active_color_src); } else { @@ -305,20 +309,26 @@ static void data_transfer_mesh_attributes_transfer_default_color_string( const char *default_color_src = BKE_id_attributes_default_color_name(&mesh_src->id); if ((data_type == CD_PROP_COLOR) && - !BKE_id_attribute_search(&mesh_src->id, default_color_src, CD_MASK_PROP_COLOR, ATTR_DOMAIN_MASK_COLOR)) { + !BKE_id_attribute_search( + &mesh_src->id, default_color_src, CD_MASK_PROP_COLOR, ATTR_DOMAIN_MASK_COLOR)) { return; } - else if ((data_type == CD_PROP_BYTE_COLOR) && - !BKE_id_attribute_search(&mesh_src->id, default_color_src, CD_MASK_PROP_BYTE_COLOR, ATTR_DOMAIN_MASK_COLOR)) { + else if ((data_type == CD_PROP_BYTE_COLOR) && !BKE_id_attribute_search(&mesh_src->id, + default_color_src, + CD_MASK_PROP_BYTE_COLOR, + ATTR_DOMAIN_MASK_COLOR)) { return; } if ((data_type == CD_PROP_COLOR) && - BKE_id_attribute_search(&mesh_dst->id, default_color_src, CD_MASK_PROP_COLOR, ATTR_DOMAIN_MASK_COLOR)) { + BKE_id_attribute_search( + &mesh_dst->id, default_color_src, CD_MASK_PROP_COLOR, ATTR_DOMAIN_MASK_COLOR)) { mesh_dst->default_color_attribute = BLI_strdup(default_color_src); } - else if ((data_type == CD_PROP_BYTE_COLOR) && - BKE_id_attribute_search(&mesh_dst->id, default_color_src, CD_MASK_PROP_BYTE_COLOR, ATTR_DOMAIN_MASK_COLOR)) { + else if ((data_type == CD_PROP_BYTE_COLOR) && BKE_id_attribute_search(&mesh_dst->id, + default_color_src, + CD_MASK_PROP_BYTE_COLOR, + ATTR_DOMAIN_MASK_COLOR)) { mesh_dst->default_color_attribute = BLI_strdup(default_color_src); } else { @@ -344,12 +354,9 @@ static void data_transfer_dtdata_type_preprocess(Mesh *me_src, const float(*positions_dst)[3] = BKE_mesh_vert_positions(me_dst); const int num_verts_dst = me_dst->totvert; - const MEdge *edges_dst = BKE_mesh_edges(me_dst); - const int num_edges_dst = me_dst->totedge; - const MPoly *polys_dst = BKE_mesh_polys(me_dst); - const int num_polys_dst = me_dst->totpoly; - const MLoop *loops_dst = BKE_mesh_loops(me_dst); - const int num_loops_dst = me_dst->totloop; + const blender::Span edges_dst = me_dst->edges(); + const blender::Span polys_dst = me_dst->polys(); + const blender::Span loops_dst = me_dst->loops(); CustomData *ldata_dst = &me_dst->ldata; const bool use_split_nors_dst = (me_dst->flag & ME_AUTOSMOOTH) != 0; @@ -369,7 +376,7 @@ static void data_transfer_dtdata_type_preprocess(Mesh *me_src, const bool do_loop_nors_dst = (loop_nors_dst == nullptr); if (do_loop_nors_dst) { loop_nors_dst = static_cast( - CustomData_add_layer(ldata_dst, CD_NORMAL, CD_SET_DEFAULT, nullptr, num_loops_dst)); + CustomData_add_layer(ldata_dst, CD_NORMAL, CD_SET_DEFAULT, nullptr, loops_dst.size())); CustomData_set_layer_flag(ldata_dst, CD_NORMAL, CD_FLAG_TEMPORARY); } if (dirty_nors_dst || do_loop_nors_dst) { @@ -378,14 +385,14 @@ static void data_transfer_dtdata_type_preprocess(Mesh *me_src, BKE_mesh_normals_loop_split(positions_dst, BKE_mesh_vertex_normals_ensure(me_dst), num_verts_dst, - edges_dst, - num_edges_dst, - loops_dst, + edges_dst.data(), + edges_dst.size(), + loops_dst.data(), loop_nors_dst, - num_loops_dst, - polys_dst, + loops_dst.size(), + polys_dst.data(), BKE_mesh_poly_normals_ensure(me_dst), - num_polys_dst, + polys_dst.size(), use_split_nors_dst, split_angle_dst, sharp_edges, @@ -412,10 +419,8 @@ static void data_transfer_dtdata_type_postprocess(Object * /*ob_src*/, /* Bake edited destination loop normals into custom normals again. */ const float(*positions_dst)[3] = BKE_mesh_vert_positions(me_dst); const int num_verts_dst = me_dst->totvert; - MEdge *edges_dst = BKE_mesh_edges_for_write(me_dst); - const int num_edges_dst = me_dst->totedge; - MPoly *polys_dst = BKE_mesh_polys_for_write(me_dst); - const int num_polys_dst = me_dst->totpoly; + const blender::Span edges_dst = me_dst->edges(); + blender::MutableSpan polys_dst = me_dst->polys_for_write(); MLoop *loops_dst = BKE_mesh_loops_for_write(me_dst); const int num_loops_dst = me_dst->totloop; CustomData *ldata_dst = &me_dst->ldata; @@ -439,14 +444,14 @@ static void data_transfer_dtdata_type_postprocess(Object * /*ob_src*/, BKE_mesh_normals_loop_custom_set(positions_dst, BKE_mesh_vertex_normals_ensure(me_dst), num_verts_dst, - edges_dst, - num_edges_dst, + edges_dst.data(), + edges_dst.size(), loops_dst, loop_nors_dst, num_loops_dst, - polys_dst, + polys_dst.data(), poly_nors_dst, - num_polys_dst, + polys_dst.size(), sharp_edges.span.data(), custom_nors_dst); sharp_edges.finish(); @@ -1119,8 +1124,8 @@ static bool data_transfer_layersmapping_generate(ListBase *r_map, mix_mode, mix_factor, mix_weights, - BKE_mesh_polys(me_src), - BKE_mesh_polys_for_write(me_dst), + me_src->polys().data(), + me_dst->polys_for_write().data(), me_src->totpoly, me_dst->totpoly, elem_size, @@ -1497,13 +1502,12 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph, if (DT_DATATYPE_IS_EDGE(dtdata_type)) { const float(*positions_dst)[3] = BKE_mesh_vert_positions_for_write(me_dst); const int num_verts_dst = me_dst->totvert; - const MEdge *edges_dst = BKE_mesh_edges(me_dst); - const int num_edges_dst = me_dst->totedge; + const blender::Span edges_dst = me_dst->edges(); if (!geom_map_init[EDATA]) { const int num_edges_src = me_src->totedge; - if ((map_edge_mode == MREMAP_MODE_TOPOLOGY) && (num_edges_dst != num_edges_src)) { + if ((map_edge_mode == MREMAP_MODE_TOPOLOGY) && (edges_dst.size() != num_edges_src)) { BKE_report(reports, RPT_ERROR, "Source and destination meshes do not have the same amount of edges, " @@ -1517,7 +1521,7 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph, "None of the 'Face' mappings can be used in this case"); continue; } - if (ELEM(0, num_edges_dst, num_edges_src)) { + if (ELEM(0, edges_dst.size(), num_edges_src)) { BKE_report( reports, RPT_ERROR, @@ -1531,8 +1535,8 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph, ray_radius, positions_dst, num_verts_dst, - edges_dst, - num_edges_dst, + edges_dst.data(), + edges_dst.size(), dirty_nors_dst, me_src, me_dst, @@ -1542,9 +1546,14 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph, if (mdef && vg_idx != -1 && !weights[EDATA]) { weights[EDATA] = static_cast( - MEM_mallocN(sizeof(*weights[EDATA]) * size_t(num_edges_dst), __func__)); - BKE_defvert_extract_vgroup_to_edgeweights( - mdef, vg_idx, num_verts_dst, edges_dst, num_edges_dst, invert_vgroup, weights[EDATA]); + MEM_mallocN(sizeof(*weights[EDATA]) * size_t(edges_dst.size()), __func__)); + BKE_defvert_extract_vgroup_to_edgeweights(mdef, + vg_idx, + num_verts_dst, + edges_dst.data(), + edges_dst.size(), + invert_vgroup, + weights[EDATA]); } if (data_transfer_layersmapping_generate(&lay_map, @@ -1557,7 +1566,7 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph, mix_mode, mix_factor, weights[EDATA], - num_edges_dst, + edges_dst.size(), use_create, use_delete, fromlayers, @@ -1578,12 +1587,9 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph, if (DT_DATATYPE_IS_LOOP(dtdata_type)) { const float(*positions_dst)[3] = BKE_mesh_vert_positions(me_dst); const int num_verts_dst = me_dst->totvert; - const MEdge *edges_dst = BKE_mesh_edges(me_dst); - const int num_edges_dst = me_dst->totedge; - const MPoly *polys_dst = BKE_mesh_polys(me_dst); - const int num_polys_dst = me_dst->totpoly; - const MLoop *loops_dst = BKE_mesh_loops(me_dst); - const int num_loops_dst = me_dst->totloop; + const blender::Span edges_dst = me_dst->edges(); + const blender::Span polys_dst = me_dst->polys(); + const blender::Span loops_dst = me_dst->loops(); CustomData *ldata_dst = &me_dst->ldata; MeshRemapIslandsCalc island_callback = data_transfer_get_loop_islands_generator(cddata_type); @@ -1591,7 +1597,7 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph, if (!geom_map_init[LDATA]) { const int num_loops_src = me_src->totloop; - if ((map_loop_mode == MREMAP_MODE_TOPOLOGY) && (num_loops_dst != num_loops_src)) { + if ((map_loop_mode == MREMAP_MODE_TOPOLOGY) && (loops_dst.size() != num_loops_src)) { BKE_report(reports, RPT_ERROR, "Source and destination meshes do not have the same amount of face corners, " @@ -1605,7 +1611,7 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph, "None of the 'Edge' mappings can be used in this case"); continue; } - if (ELEM(0, num_loops_dst, num_loops_src)) { + if (ELEM(0, loops_dst.size(), num_loops_src)) { BKE_report( reports, RPT_ERROR, @@ -1620,12 +1626,12 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph, me_dst, positions_dst, num_verts_dst, - edges_dst, - num_edges_dst, - loops_dst, - num_loops_dst, - polys_dst, - num_polys_dst, + edges_dst.data(), + edges_dst.size(), + loops_dst.data(), + loops_dst.size(), + polys_dst.data(), + polys_dst.size(), ldata_dst, (me_dst->flag & ME_AUTOSMOOTH) != 0, me_dst->smoothresh, @@ -1639,9 +1645,14 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph, if (mdef && vg_idx != -1 && !weights[LDATA]) { weights[LDATA] = static_cast( - MEM_mallocN(sizeof(*weights[LDATA]) * size_t(num_loops_dst), __func__)); - BKE_defvert_extract_vgroup_to_loopweights( - mdef, vg_idx, num_verts_dst, loops_dst, num_loops_dst, invert_vgroup, weights[LDATA]); + MEM_mallocN(sizeof(*weights[LDATA]) * size_t(loops_dst.size()), __func__)); + BKE_defvert_extract_vgroup_to_loopweights(mdef, + vg_idx, + num_verts_dst, + loops_dst.data(), + loops_dst.size(), + invert_vgroup, + weights[LDATA]); } if (data_transfer_layersmapping_generate(&lay_map, @@ -1654,7 +1665,7 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph, mix_mode, mix_factor, weights[LDATA], - num_loops_dst, + loops_dst.size(), use_create, use_delete, fromlayers, @@ -1675,15 +1686,13 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph, if (DT_DATATYPE_IS_POLY(dtdata_type)) { const float(*positions_dst)[3] = BKE_mesh_vert_positions(me_dst); const int num_verts_dst = me_dst->totvert; - const MPoly *polys_dst = BKE_mesh_polys(me_dst); - const int num_polys_dst = me_dst->totpoly; - const MLoop *loops_dst = BKE_mesh_loops(me_dst); - const int num_loops_dst = me_dst->totloop; + const blender::Span polys_dst = me_dst->polys(); + const blender::Span loops_dst = me_dst->loops(); if (!geom_map_init[PDATA]) { const int num_polys_src = me_src->totpoly; - if ((map_poly_mode == MREMAP_MODE_TOPOLOGY) && (num_polys_dst != num_polys_src)) { + if ((map_poly_mode == MREMAP_MODE_TOPOLOGY) && (polys_dst.size() != num_polys_src)) { BKE_report(reports, RPT_ERROR, "Source and destination meshes do not have the same amount of faces, " @@ -1697,7 +1706,7 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph, "None of the 'Edge' mappings can be used in this case"); continue; } - if (ELEM(0, num_polys_dst, num_polys_src)) { + if (ELEM(0, polys_dst.size(), num_polys_src)) { BKE_report( reports, RPT_ERROR, @@ -1711,9 +1720,9 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph, ray_radius, me_dst, positions_dst, - loops_dst, - polys_dst, - num_polys_dst, + loops_dst.data(), + polys_dst.data(), + polys_dst.size(), me_src, &geom_map[PDATA]); geom_map_init[PDATA] = true; @@ -1721,14 +1730,14 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph, if (mdef && vg_idx != -1 && !weights[PDATA]) { weights[PDATA] = static_cast( - MEM_mallocN(sizeof(*weights[PDATA]) * size_t(num_polys_dst), __func__)); + MEM_mallocN(sizeof(*weights[PDATA]) * size_t(polys_dst.size()), __func__)); BKE_defvert_extract_vgroup_to_polyweights(mdef, vg_idx, num_verts_dst, - loops_dst, - num_loops_dst, - polys_dst, - num_polys_dst, + loops_dst.data(), + loops_dst.size(), + polys_dst.data(), + polys_dst.size(), invert_vgroup, weights[PDATA]); } @@ -1743,7 +1752,7 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph, mix_mode, mix_factor, weights[PDATA], - num_polys_dst, + polys_dst.size(), use_create, use_delete, fromlayers, diff --git a/source/blender/blenkernel/intern/dynamicpaint.cc b/source/blender/blenkernel/intern/dynamicpaint.cc index bfd391c4cc9..4ef9f018dc2 100644 --- a/source/blender/blenkernel/intern/dynamicpaint.cc +++ b/source/blender/blenkernel/intern/dynamicpaint.cc @@ -1414,9 +1414,9 @@ static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, const b /* For vertex format, count every vertex that is connected by an edge */ int numOfEdges = mesh->totedge; int numOfPolys = mesh->totpoly; - const MEdge *edges = BKE_mesh_edges(mesh); - const MPoly *polys = BKE_mesh_polys(mesh); - const MLoop *loops = BKE_mesh_loops(mesh); + const blender::Span edges = mesh->edges(); + const blender::Span polys = mesh->polys(); + const blender::Span loops = mesh->loops(); /* count number of edges per vertex */ for (int i = 0; i < numOfEdges; i++) { @@ -1479,7 +1479,7 @@ static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, const b struct DynamicPaintSetInitColorData { const DynamicPaintSurface *surface; - const MLoop *mloop; + blender::Span loops; const float (*mloopuv)[2]; const MLoopTri *mlooptri; const MLoopCol *mloopcol; @@ -1497,7 +1497,7 @@ static void dynamic_paint_set_init_color_tex_to_vcol_cb(void *__restrict userdat const PaintSurfaceData *sData = data->surface->data; PaintPoint *pPoint = (PaintPoint *)sData->type_data; - const MLoop *mloop = data->mloop; + const blender::Span loops = data->loops; const MLoopTri *mlooptri = data->mlooptri; const float(*mloopuv)[2] = data->mloopuv; ImagePool *pool = data->pool; @@ -1509,7 +1509,7 @@ static void dynamic_paint_set_init_color_tex_to_vcol_cb(void *__restrict userdat for (int j = 3; j--;) { TexResult texres = {0}; - const uint vert = mloop[mlooptri[i].tri[j]].v; + const uint vert = loops[mlooptri[i].tri[j]].v; /* remap to [-1.0, 1.0] */ uv[0] = mloopuv[mlooptri[i].tri[j]][0] * 2.0f - 1.0f; @@ -1618,7 +1618,7 @@ static void dynamicPaint_setInitialColor(const Scene *scene, DynamicPaintSurface else if (surface->init_color_type == MOD_DPAINT_INITIAL_TEXTURE) { Tex *tex = surface->init_texture; - const MLoop *mloop = BKE_mesh_loops(mesh); + const blender::Span loops = mesh->loops(); const MLoopTri *mlooptri = BKE_mesh_runtime_looptri_ensure(mesh); const int tottri = BKE_mesh_runtime_looptri_len(mesh); @@ -1644,7 +1644,7 @@ static void dynamicPaint_setInitialColor(const Scene *scene, DynamicPaintSurface DynamicPaintSetInitColorData data{}; data.surface = surface; - data.mloop = mloop; + data.loops = loops; data.mlooptri = mlooptri; data.mloopuv = mloopuv; data.pool = pool; @@ -1676,16 +1676,15 @@ static void dynamicPaint_setInitialColor(const Scene *scene, DynamicPaintSurface /* For vertex surface, just copy colors from #MLoopCol. */ if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) { - const MLoop *mloop = BKE_mesh_loops(mesh); - const int totloop = mesh->totloop; + const blender::Span loops = mesh->loops(); const MLoopCol *col = static_cast( CustomData_get_layer_named(&mesh->ldata, CD_PROP_BYTE_COLOR, surface->init_layername)); if (!col) { return; } - for (int i = 0; i < totloop; i++) { - rgba_uchar_to_float(pPoint[mloop[i].v].color, (const uchar *)&col[i].r); + for (const int i : loops.index_range()) { + rgba_uchar_to_float(pPoint[loops[i].v].color, (const uchar *)&col[i].r); } } else if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) { @@ -1792,8 +1791,8 @@ struct DynamicPaintModifierApplyData { float (*vert_positions)[3]; const float (*vert_normals)[3]; - const MLoop *mloop; - const MPoly *mpoly; + blender::Span polys; + blender::Span loops; float (*fcolor)[4]; MLoopCol *mloopcol; @@ -1861,8 +1860,8 @@ static void dynamic_paint_apply_surface_vpaint_cb(void *__restrict userdata, const DynamicPaintModifierApplyData *data = static_cast( userdata); - const MLoop *mloop = data->mloop; - const MPoly *mpoly = data->mpoly; + const blender::Span polys = data->polys; + const blender::Span loops = data->loops; const DynamicPaintSurface *surface = data->surface; PaintPoint *pPoint = (PaintPoint *)surface->data->type_data; @@ -1871,9 +1870,9 @@ static void dynamic_paint_apply_surface_vpaint_cb(void *__restrict userdata, MLoopCol *mloopcol = data->mloopcol; MLoopCol *mloopcol_wet = data->mloopcol_wet; - for (int j = 0; j < mpoly[p_index].totloop; j++) { - const int l_index = mpoly[p_index].loopstart + j; - const int v_index = mloop[l_index].v; + for (int j = 0; j < polys[p_index].totloop; j++) { + const int l_index = polys[p_index].loopstart + j; + const int v_index = loops[l_index].v; /* save layer data to output layer */ /* apply color */ @@ -1930,10 +1929,8 @@ static Mesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData *pmd, Object * /* vertex color paint */ if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) { - const MLoop *mloop = BKE_mesh_loops(result); - const int totloop = result->totloop; - const MPoly *mpoly = BKE_mesh_polys(result); - const int totpoly = result->totpoly; + const blender::Span polys = result->polys(); + const blender::Span loops = result->loops(); /* paint is stored on dry and wet layers, so mix final color first */ float(*fcolor)[4] = static_cast( @@ -1963,7 +1960,7 @@ static Mesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData *pmd, Object * CD_PROP_BYTE_COLOR, CD_SET_DEFAULT, nullptr, - totloop, + loops.size(), surface->output_name)); } @@ -1977,22 +1974,22 @@ static Mesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData *pmd, Object * CD_PROP_BYTE_COLOR, CD_SET_DEFAULT, nullptr, - totloop, + loops.size(), surface->output_name2)); } data.ob = ob; - data.mloop = mloop; - data.mpoly = mpoly; + data.loops = loops; + data.polys = polys; data.mloopcol = mloopcol; data.mloopcol_wet = mloopcol_wet; { TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); - settings.use_threading = (totpoly > 1000); + settings.use_threading = (polys.size() > 1000); BLI_task_parallel_range( - 0, totpoly, &data, dynamic_paint_apply_surface_vpaint_cb, &settings); + 0, polys.size(), &data, dynamic_paint_apply_surface_vpaint_cb, &settings); } MEM_freeN(fcolor); @@ -2197,7 +2194,7 @@ struct DynamicPaintCreateUVSurfaceData { const MLoopTri *mlooptri; const float (*mloopuv)[2]; - const MLoop *mloop; + blender::Span loops; int tottri; const Bounds2D *faceBB; @@ -2217,7 +2214,7 @@ static void dynamic_paint_create_uv_surface_direct_cb(void *__restrict userdata, const MLoopTri *mlooptri = data->mlooptri; const float(*mloopuv)[2] = data->mloopuv; - const MLoop *mloop = data->mloop; + const blender::Span loops = data->loops; const int tottri = data->tottri; const Bounds2D *faceBB = data->faceBB; @@ -2289,9 +2286,9 @@ static void dynamic_paint_create_uv_surface_direct_cb(void *__restrict userdata, tPoint->tri_index = i; /* save vertex indexes */ - tPoint->v1 = mloop[mlooptri[i].tri[0]].v; - tPoint->v2 = mloop[mlooptri[i].tri[1]].v; - tPoint->v3 = mloop[mlooptri[i].tri[2]].v; + tPoint->v1 = loops[mlooptri[i].tri[0]].v; + tPoint->v2 = loops[mlooptri[i].tri[1]].v; + tPoint->v3 = loops[mlooptri[i].tri[2]].v; sample = 5; /* make sure we exit sample loop as well */ break; @@ -2314,7 +2311,7 @@ static void dynamic_paint_create_uv_surface_neighbor_cb(void *__restrict userdat const MLoopTri *mlooptri = data->mlooptri; const float(*mloopuv)[2] = data->mloopuv; - const MLoop *mloop = data->mloop; + const blender::Span loops = data->loops; uint32_t *active_points = data->active_points; @@ -2379,9 +2376,9 @@ static void dynamic_paint_create_uv_surface_neighbor_cb(void *__restrict userdat } /* save vertex indexes */ - tPoint->v1 = mloop[mlooptri[i].tri[0]].v; - tPoint->v2 = mloop[mlooptri[i].tri[1]].v; - tPoint->v3 = mloop[mlooptri[i].tri[2]].v; + tPoint->v1 = loops[mlooptri[i].tri[0]].v; + tPoint->v2 = loops[mlooptri[i].tri[1]].v; + tPoint->v3 = loops[mlooptri[i].tri[2]].v; break; } @@ -2522,7 +2519,7 @@ static void dynamic_paint_find_island_border(const DynamicPaintCreateUVSurfaceDa int in_edge, int depth) { - const MLoop *mloop = data->mloop; + const blender::Span loops = data->loops; const MLoopTri *mlooptri = data->mlooptri; const float(*mloopuv)[2] = data->mloopuv; @@ -2560,8 +2557,8 @@ static void dynamic_paint_find_island_border(const DynamicPaintCreateUVSurfaceDa } /* Now find another face that is linked to that edge. */ - const int vert0 = mloop[loop_idx[(edge_idx + 0)]].v; - const int vert1 = mloop[loop_idx[(edge_idx + 1) % 3]].v; + const int vert0 = loops[loop_idx[(edge_idx + 0)]].v; + const int vert1 = loops[loop_idx[(edge_idx + 1) % 3]].v; /* Use a pre-computed vert-to-looptri mapping, * speeds up things a lot compared to looping over all looptri. */ @@ -2584,8 +2581,8 @@ static void dynamic_paint_find_island_border(const DynamicPaintCreateUVSurfaceDa /* Check edges for match, looping in the same order as the outer loop. */ for (int j = 0; j < 3; j++) { - const int overt0 = mloop[other_loop_idx[(j + 0)]].v; - const int overt1 = mloop[other_loop_idx[(j + 1) % 3]].v; + const int overt0 = loops[other_loop_idx[(j + 0)]].v; + const int overt1 = loops[other_loop_idx[(j + 1) % 3]].v; /* Allow for swapped vertex order */ if (overt0 == vert0 && overt1 == vert1) { @@ -2823,7 +2820,6 @@ int dynamicPaint_createUVSurface(Scene *scene, Vec3f *tempWeights = nullptr; const MLoopTri *mlooptri = nullptr; const float(*mloopuv)[2] = nullptr; - const MLoop *mloop = nullptr; Bounds2D *faceBB = nullptr; int *final_index; @@ -2838,7 +2834,7 @@ int dynamicPaint_createUVSurface(Scene *scene, return setError(canvas, N_("Cannot bake non-'image sequence' formats")); } - mloop = BKE_mesh_loops(mesh); + const blender::Span loops = mesh->loops(); mlooptri = BKE_mesh_runtime_looptri_ensure(mesh); const int tottri = BKE_mesh_runtime_looptri_len(mesh); @@ -2926,7 +2922,7 @@ int dynamicPaint_createUVSurface(Scene *scene, data.tempWeights = tempWeights; data.mlooptri = mlooptri; data.mloopuv = mloopuv; - data.mloop = mloop; + data.loops = loops; data.tottri = tottri; data.faceBB = faceBB; @@ -2985,7 +2981,7 @@ int dynamicPaint_createUVSurface(Scene *scene, mesh->totvert, mlooptri, tottri, - mloop, + loops.data(), mesh->totloop); int total_border = 0; @@ -3444,14 +3440,14 @@ static void mesh_tris_spherecast_dp(void *userdata, const BVHTreeFromMesh *data = (BVHTreeFromMesh *)userdata; const float(*positions)[3] = data->vert_positions; const MLoopTri *mlooptri = data->looptri; - const MLoop *mloop = data->loop; + const MLoop *loops = data->loop; const float *t0, *t1, *t2; float dist; - t0 = positions[mloop[mlooptri[index].tri[0]].v]; - t1 = positions[mloop[mlooptri[index].tri[1]].v]; - t2 = positions[mloop[mlooptri[index].tri[2]].v]; + t0 = positions[loops[mlooptri[index].tri[0]].v]; + t1 = positions[loops[mlooptri[index].tri[1]].v]; + t2 = positions[loops[mlooptri[index].tri[2]].v]; dist = bvhtree_ray_tri_intersection(ray, hit->dist, t0, t1, t2); @@ -3476,13 +3472,13 @@ static void mesh_tris_nearest_point_dp(void *userdata, const BVHTreeFromMesh *data = (BVHTreeFromMesh *)userdata; const float(*positions)[3] = data->vert_positions; const MLoopTri *mlooptri = data->looptri; - const MLoop *mloop = data->loop; + const MLoop *loops = data->loop; float nearest_tmp[3], dist_sq; const float *t0, *t1, *t2; - t0 = positions[mloop[mlooptri[index].tri[0]].v]; - t1 = positions[mloop[mlooptri[index].tri[1]].v]; - t2 = positions[mloop[mlooptri[index].tri[2]].v]; + t0 = positions[loops[mlooptri[index].tri[0]].v]; + t1 = positions[loops[mlooptri[index].tri[1]].v]; + t2 = positions[loops[mlooptri[index].tri[2]].v]; closest_on_tri_to_point_v3(nearest_tmp, co, t0, t1, t2); dist_sq = len_squared_v3v3(co, nearest_tmp); @@ -3915,7 +3911,7 @@ struct DynamicPaintPaintData { Mesh *mesh; const float (*positions)[3]; - const MLoop *mloop; + blender::Span loops; const MLoopTri *mlooptri; float brush_radius; const float *avg_brushNor; @@ -3949,7 +3945,7 @@ static void dynamic_paint_paint_mesh_cell_point_cb_ex(void *__restrict userdata, const int c_index = data->c_index; const float(*positions)[3] = data->positions; - const MLoop *mloop = data->mloop; + const blender::Span loops = data->loops; const MLoopTri *mlooptri = data->mlooptri; const float brush_radius = data->brush_radius; const float *avg_brushNor = data->avg_brushNor; @@ -4023,9 +4019,9 @@ static void dynamic_paint_paint_mesh_cell_point_cb_ex(void *__restrict userdata, /* For optimization sake, hit point normal isn't calculated in ray cast loop */ const int vtri[3] = { - int(mloop[mlooptri[hit.index].tri[0]].v), - int(mloop[mlooptri[hit.index].tri[1]].v), - int(mloop[mlooptri[hit.index].tri[2]].v), + int(loops[mlooptri[hit.index].tri[0]].v), + int(loops[mlooptri[hit.index].tri[1]].v), + int(loops[mlooptri[hit.index].tri[2]].v), }; float dot; @@ -4173,9 +4169,9 @@ static void dynamic_paint_paint_mesh_cell_point_cb_ex(void *__restrict userdata, float brushPointVelocity[3]; float velocity[3]; - const int v1 = mloop[mlooptri[hitTri].tri[0]].v; - const int v2 = mloop[mlooptri[hitTri].tri[1]].v; - const int v3 = mloop[mlooptri[hitTri].tri[2]].v; + const int v1 = loops[mlooptri[hitTri].tri[0]].v; + const int v2 = loops[mlooptri[hitTri].tri[1]].v; + const int v3 = loops[mlooptri[hitTri].tri[2]].v; /* calculate barycentric weights for hit point */ interp_weights_tri_v3(weights, positions[v1], positions[v2], positions[v3], hitCoord); @@ -4275,7 +4271,6 @@ static bool dynamicPaint_paintMesh(Depsgraph *depsgraph, Mesh *mesh = nullptr; Vec3f *brushVelocity = nullptr; const MLoopTri *mlooptri = nullptr; - const MLoop *mloop = nullptr; if (brush->flags & MOD_DPAINT_USES_VELOCITY) { dynamicPaint_brushMeshCalculateVelocity( @@ -4300,7 +4295,7 @@ static bool dynamicPaint_paintMesh(Depsgraph *depsgraph, float(*positions)[3] = BKE_mesh_vert_positions_for_write(mesh); const float(*vert_normals)[3] = BKE_mesh_vertex_normals_ensure(mesh); mlooptri = BKE_mesh_runtime_looptri_ensure(mesh); - mloop = BKE_mesh_loops(mesh); + const blender::Span loops = mesh->loops(); numOfVerts = mesh->totvert; /* Transform collider vertices to global space @@ -4354,7 +4349,7 @@ static bool dynamicPaint_paintMesh(Depsgraph *depsgraph, data.c_index = c_index; data.mesh = mesh; data.positions = positions; - data.mloop = mloop; + data.loops = loops; data.mlooptri = mlooptri; data.brush_radius = brush_radius; data.avg_brushNor = avg_brushNor; diff --git a/source/blender/blenkernel/intern/key.cc b/source/blender/blenkernel/intern/key.cc index 2c25ec0bdeb..a4f3fbf2de3 100644 --- a/source/blender/blenkernel/intern/key.cc +++ b/source/blender/blenkernel/intern/key.cc @@ -2233,9 +2233,9 @@ void BKE_keyblock_mesh_calc_normals(const KeyBlock *kb, float(*positions)[3] = static_cast(MEM_dupallocN(BKE_mesh_vert_positions(mesh))); BKE_keyblock_convert_to_mesh(kb, positions, mesh->totvert); - const MEdge *edges = BKE_mesh_edges(mesh); - const MPoly *polys = BKE_mesh_polys(mesh); - const MLoop *loops = BKE_mesh_loops(mesh); + const blender::Span edges = mesh->edges(); + const blender::Span polys = mesh->polys(); + const blender::Span loops = mesh->loops(); const bool loop_normals_needed = r_loop_normals != nullptr; const bool vert_normals_needed = r_vert_normals != nullptr || loop_normals_needed; @@ -2258,35 +2258,40 @@ void BKE_keyblock_mesh_calc_normals(const KeyBlock *kb, } if (poly_normals_needed) { - BKE_mesh_calc_normals_poly( - positions, mesh->totvert, loops, mesh->totloop, polys, mesh->totpoly, poly_normals); + BKE_mesh_calc_normals_poly(positions, + mesh->totvert, + loops.data(), + loops.size(), + polys.data(), + polys.size(), + poly_normals); } if (vert_normals_needed) { BKE_mesh_calc_normals_poly_and_vertex(positions, mesh->totvert, - loops, - mesh->totloop, - polys, - mesh->totpoly, + loops.data(), + loops.size(), + polys.data(), + polys.size(), poly_normals, vert_normals); } if (loop_normals_needed) { short(*clnors)[2] = static_cast(CustomData_get_layer_for_write( - &mesh->ldata, CD_CUSTOMLOOPNORMAL, mesh->totloop)); /* May be nullptr. */ + &mesh->ldata, CD_CUSTOMLOOPNORMAL, loops.size())); /* May be nullptr. */ const bool *sharp_edges = static_cast( CustomData_get_layer_named(&mesh->edata, CD_PROP_BOOL, "sharp_edge")); BKE_mesh_normals_loop_split(positions, vert_normals, mesh->totvert, - edges, + edges.data(), mesh->totedge, - loops, + loops.data(), r_loop_normals, - mesh->totloop, - polys, + loops.size(), + polys.data(), poly_normals, - mesh->totpoly, + polys.size(), (mesh->flag & ME_AUTOSMOOTH) != 0, mesh->smoothresh, sharp_edges, diff --git a/source/blender/blenkernel/intern/mesh_evaluate.cc b/source/blender/blenkernel/intern/mesh_evaluate.cc index d6f40a472de..8cab5a4dd9a 100644 --- a/source/blender/blenkernel/intern/mesh_evaluate.cc +++ b/source/blender/blenkernel/intern/mesh_evaluate.cc @@ -329,21 +329,19 @@ bool BKE_mesh_center_bounds(const Mesh *me, float r_cent[3]) bool BKE_mesh_center_of_surface(const Mesh *me, float r_cent[3]) { - int i = me->totpoly; - const MPoly *mpoly; float poly_area; float total_area = 0.0f; float poly_cent[3]; const float(*positions)[3] = BKE_mesh_vert_positions(me); - const MPoly *polys = BKE_mesh_polys(me); - const MLoop *loops = BKE_mesh_loops(me); + const blender::Span polys = me->polys(); + const blender::Span loops = me->loops(); zero_v3(r_cent); /* calculate a weighted average of polygon centroids */ - for (mpoly = polys; i--; mpoly++) { + for (const int i : polys.index_range()) { poly_area = mesh_calc_poly_area_centroid( - mpoly, loops + mpoly->loopstart, positions, poly_cent); + &polys[i], &loops[polys[i].loopstart], positions, poly_cent); madd_v3_v3fl(r_cent, poly_cent, poly_area); total_area += poly_area; @@ -363,14 +361,12 @@ bool BKE_mesh_center_of_surface(const Mesh *me, float r_cent[3]) bool BKE_mesh_center_of_volume(const Mesh *me, float r_cent[3]) { - int i = me->totpoly; - const MPoly *mpoly; float poly_volume; float total_volume = 0.0f; float poly_cent[3]; const Span positions = me->vert_positions(); - const MPoly *polys = BKE_mesh_polys(me); - const MLoop *loops = BKE_mesh_loops(me); + const blender::Span polys = me->polys(); + const blender::Span loops = me->loops(); /* Use an initial center to avoid numeric instability of geometry far away from the center. */ float init_cent[3]; @@ -379,9 +375,9 @@ bool BKE_mesh_center_of_volume(const Mesh *me, float r_cent[3]) zero_v3(r_cent); /* calculate a weighted average of polyhedron centroids */ - for (mpoly = polys; i--; mpoly++) { + for (const int i : polys.index_range()) { poly_volume = mesh_calc_poly_volume_centroid_with_reference_center( - mpoly, loops + mpoly->loopstart, positions, init_cent, poly_cent); + &polys[i], &loops[polys[i].loopstart], positions, init_cent, poly_cent); /* poly_cent is already volume-weighted, so no need to multiply by the volume */ add_v3_v3(r_cent, poly_cent); diff --git a/source/blender/blenkernel/intern/mesh_iterators.cc b/source/blender/blenkernel/intern/mesh_iterators.cc index 159ff94d24d..7d6a9d58a79 100644 --- a/source/blender/blenkernel/intern/mesh_iterators.cc +++ b/source/blender/blenkernel/intern/mesh_iterators.cc @@ -121,21 +121,22 @@ void BKE_mesh_foreach_mapped_edge( } else { const float(*positions)[3] = BKE_mesh_vert_positions(mesh); - const MEdge *med = BKE_mesh_edges(mesh); + const blender::Span edges = mesh->edges(); const int *index = static_cast(CustomData_get_layer(&mesh->edata, CD_ORIGINDEX)); if (index) { - for (int i = 0; i < mesh->totedge; i++, med++) { + for (const int i : edges.index_range()) { + const int orig = *index++; if (orig == ORIGINDEX_NONE) { continue; } - func(userData, orig, positions[med->v1], positions[med->v2]); + func(userData, orig, positions[edges[i].v1], positions[edges[i].v2]); } } else if (mesh->totedge == tot_edges) { - for (int i = 0; i < mesh->totedge; i++, med++) { - func(userData, i, positions[med->v1], positions[med->v2]); + for (const int i : edges.index_range()) { + func(userData, i, positions[edges[i].v1], positions[edges[i].v2]); } } } @@ -191,34 +192,35 @@ void BKE_mesh_foreach_mapped_loop(Mesh *mesh, nullptr; const float(*positions)[3] = BKE_mesh_vert_positions(mesh); - const MLoop *ml = BKE_mesh_loops(mesh); - const MPoly *mp = BKE_mesh_polys(mesh); + const blender::Span polys = mesh->polys(); + const blender::Span loops = mesh->loops(); const int *v_index = static_cast( CustomData_get_layer(&mesh->vdata, CD_ORIGINDEX)); const int *f_index = static_cast( CustomData_get_layer(&mesh->pdata, CD_ORIGINDEX)); - int p_idx, i; if (v_index || f_index) { - for (p_idx = 0; p_idx < mesh->totpoly; p_idx++, mp++) { - for (i = 0; i < mp->totloop; i++, ml++) { - const int v_idx = v_index ? v_index[ml->v] : ml->v; - const int f_idx = f_index ? f_index[p_idx] : p_idx; + for (const int poly_i : polys.index_range()) { + for (const int loop_i : + blender::IndexRange(polys[poly_i].loopstart, polys[poly_i].totloop)) { + const int v_idx = v_index ? v_index[loops[loop_i].v] : loops[loop_i].v; + const int f_idx = f_index ? f_index[poly_i] : poly_i; const float *no = loop_normals ? *loop_normals++ : nullptr; if (ELEM(ORIGINDEX_NONE, v_idx, f_idx)) { continue; } - func(userData, v_idx, f_idx, positions[ml->v], no); + func(userData, v_idx, f_idx, positions[loops[loop_i].v], no); } } } else { - for (p_idx = 0; p_idx < mesh->totpoly; p_idx++, mp++) { - for (i = 0; i < mp->totloop; i++, ml++) { - const int v_idx = ml->v; - const int f_idx = p_idx; + for (const int poly_i : polys.index_range()) { + for (const int loop_i : + blender::IndexRange(polys[poly_i].loopstart, polys[poly_i].totloop)) { + const int v_idx = loops[loop_i].v; + const int f_idx = poly_i; const float *no = loop_normals ? *loop_normals++ : nullptr; - func(userData, v_idx, f_idx, positions[ml->v], no); + func(userData, v_idx, f_idx, positions[loops[loop_i].v], no); } } } @@ -266,35 +268,32 @@ void BKE_mesh_foreach_mapped_face_center( } else { const float(*positions)[3] = BKE_mesh_vert_positions(mesh); - const MPoly *mp = BKE_mesh_polys(mesh); - const MLoop *loops = BKE_mesh_loops(mesh); - const MLoop *ml; + const blender::Span polys = mesh->polys(); + const blender::Span loops = mesh->loops(); float _no_buf[3]; float *no = (flag & MESH_FOREACH_USE_NORMAL) ? _no_buf : nullptr; const int *index = static_cast(CustomData_get_layer(&mesh->pdata, CD_ORIGINDEX)); if (index) { - for (int i = 0; i < mesh->totpoly; i++, mp++) { + for (const int i : polys.index_range()) { const int orig = *index++; if (orig == ORIGINDEX_NONE) { continue; } float cent[3]; - ml = &loops[mp->loopstart]; - BKE_mesh_calc_poly_center(mp, ml, positions, cent); + BKE_mesh_calc_poly_center(&polys[i], &loops[polys[i].loopstart], positions, cent); if (flag & MESH_FOREACH_USE_NORMAL) { - BKE_mesh_calc_poly_normal(mp, ml, positions, no); + BKE_mesh_calc_poly_normal(&polys[i], &loops[polys[i].loopstart], positions, no); } func(userData, orig, cent, no); } } else { - for (int i = 0; i < mesh->totpoly; i++, mp++) { + for (const int i : polys.index_range()) { float cent[3]; - ml = &loops[mp->loopstart]; - BKE_mesh_calc_poly_center(mp, ml, positions, cent); + BKE_mesh_calc_poly_center(&polys[i], &loops[polys[i].loopstart], positions, cent); if (flag & MESH_FOREACH_USE_NORMAL) { - BKE_mesh_calc_poly_normal(mp, ml, positions, no); + BKE_mesh_calc_poly_normal(&polys[i], &loops[polys[i].loopstart], positions, no); } func(userData, i, cent, no); } @@ -309,9 +308,8 @@ void BKE_mesh_foreach_mapped_subdiv_face_center( MeshForeachFlag flag) { const float(*positions)[3] = BKE_mesh_vert_positions(mesh); - const MPoly *mp = BKE_mesh_polys(mesh); - const MLoop *loops = BKE_mesh_loops(mesh); - const MLoop *ml; + const blender::Span polys = mesh->polys(); + const blender::Span loops = mesh->loops(); const float(*vert_normals)[3] = (flag & MESH_FOREACH_USE_NORMAL) ? BKE_mesh_vertex_normals_ensure(mesh) : nullptr; @@ -319,31 +317,29 @@ void BKE_mesh_foreach_mapped_subdiv_face_center( const blender::BitSpan facedot_tags = mesh->runtime->subsurf_face_dot_tags; if (index) { - for (int i = 0; i < mesh->totpoly; i++, mp++) { + for (const int i : polys.index_range()) { const int orig = *index++; if (orig == ORIGINDEX_NONE) { continue; } - ml = &loops[mp->loopstart]; - for (int j = 0; j < mp->totloop; j++, ml++) { - if (facedot_tags[ml->v]) { + for (const MLoop &loop : loops.slice(polys[i].loopstart, polys[i].totloop)) { + if (facedot_tags[loop.v]) { func(userData, orig, - positions[ml->v], - (flag & MESH_FOREACH_USE_NORMAL) ? vert_normals[ml->v] : nullptr); + positions[loop.v], + (flag & MESH_FOREACH_USE_NORMAL) ? vert_normals[loop.v] : nullptr); } } } } else { - for (int i = 0; i < mesh->totpoly; i++, mp++) { - ml = &loops[mp->loopstart]; - for (int j = 0; j < mp->totloop; j++, ml++) { - if (facedot_tags[ml->v]) { + for (const int i : polys.index_range()) { + for (const MLoop &loop : loops.slice(polys[i].loopstart, polys[i].totloop)) { + if (facedot_tags[loop.v]) { func(userData, i, - positions[ml->v], - (flag & MESH_FOREACH_USE_NORMAL) ? vert_normals[ml->v] : nullptr); + positions[loop.v], + (flag & MESH_FOREACH_USE_NORMAL) ? vert_normals[loop.v] : nullptr); } } } diff --git a/source/blender/blenkernel/intern/mesh_merge_customdata.cc b/source/blender/blenkernel/intern/mesh_merge_customdata.cc index c10c9d851b9..6ceedc66082 100644 --- a/source/blender/blenkernel/intern/mesh_merge_customdata.cc +++ b/source/blender/blenkernel/intern/mesh_merge_customdata.cc @@ -116,8 +116,8 @@ void BKE_mesh_merge_customdata_for_apply_modifier(Mesh *me) struct MeshElemMap *vert_to_loop; BKE_mesh_vert_loop_map_create(&vert_to_loop, &vert_map_mem, - BKE_mesh_polys(me), - BKE_mesh_loops(me), + me->polys().data(), + me->loops().data(), me->totvert, me->totpoly, me->totloop); diff --git a/source/blender/blenkernel/intern/mesh_mirror.cc b/source/blender/blenkernel/intern/mesh_mirror.cc index e435f056301..b1b4f011b7c 100644 --- a/source/blender/blenkernel/intern/mesh_mirror.cc +++ b/source/blender/blenkernel/intern/mesh_mirror.cc @@ -290,14 +290,14 @@ Mesh *BKE_mesh_mirror_apply_mirror_on_axis_for_modifier(MirrorModifierData *mmd, } /* adjust mirrored edge vertex indices */ - me = BKE_mesh_edges_for_write(result) + maxEdges; + me = result->edges_for_write().data() + maxEdges; for (i = 0; i < maxEdges; i++, me++) { me->v1 += maxVerts; me->v2 += maxVerts; } /* adjust mirrored poly loopstart indices, and reverse loop order (normals) */ - mp = BKE_mesh_polys_for_write(result) + maxPolys; + mp = result->polys_for_write().data() + maxPolys; ml = BKE_mesh_loops_for_write(result); for (i = 0; i < maxPolys; i++, mp++) { MLoop *ml2; @@ -399,12 +399,12 @@ Mesh *BKE_mesh_mirror_apply_mirror_on_axis_for_modifier(MirrorModifierData *mmd, BKE_mesh_normals_loop_split(BKE_mesh_vert_positions(result), BKE_mesh_vertex_normals_ensure(result), result->totvert, - BKE_mesh_edges(result), + result->edges().data(), result->totedge, - BKE_mesh_loops(result), + result->loops().data(), loop_normals, totloop, - BKE_mesh_polys(result), + result->polys().data(), BKE_mesh_poly_normals_ensure(result), totpoly, true, @@ -415,16 +415,15 @@ Mesh *BKE_mesh_mirror_apply_mirror_on_axis_for_modifier(MirrorModifierData *mmd, clnors); /* mirroring has to account for loops being reversed in polys in second half */ - MPoly *result_polys = BKE_mesh_polys_for_write(result); - mp = result_polys; - for (i = 0; i < maxPolys; i++, mp++) { - MPoly *mpmirror = result_polys + maxPolys + i; + blender::MutableSpan result_polys = result->polys_for_write(); + for (i = 0; i < maxPolys; i++) { + const int mirror_i = maxPolys + i; int j; for (j = mp->loopstart; j < mp->loopstart + mp->totloop; j++) { - int mirrorj = mpmirror->loopstart; + int mirrorj = result_polys[mirror_i].loopstart; if (j > mp->loopstart) { - mirrorj += mpmirror->totloop - (j - mp->loopstart); + mirrorj += result_polys[mirror_i].totloop - (j - mp->loopstart); } copy_v3_v3(loop_normals[mirrorj], loop_normals[j]); mul_m4_v3(mtx_nor, loop_normals[mirrorj]); diff --git a/source/blender/blenkernel/intern/mesh_remap.cc b/source/blender/blenkernel/intern/mesh_remap.cc index 8c25315ab19..73e869a9ce1 100644 --- a/source/blender/blenkernel/intern/mesh_remap.cc +++ b/source/blender/blenkernel/intern/mesh_remap.cc @@ -371,8 +371,8 @@ void BKE_mesh_remap_item_define_invalid(MeshPairRemap *map, const int index) mesh_remap_item_define(map, index, FLT_MAX, 0, 0, nullptr, nullptr); } -static int mesh_remap_interp_poly_data_get(const MPoly *mp, - const MLoop *mloops, +static int mesh_remap_interp_poly_data_get(const MPoly &poly, + const blender::Span loops, const float (*vcos_src)[3], const float point[3], size_t *buff_size, @@ -387,7 +387,7 @@ static int mesh_remap_interp_poly_data_get(const MPoly *mp, float(*vco)[3]; float ref_dist_sq = FLT_MAX; int *index; - const int sources_num = mp->totloop; + const int sources_num = poly.totloop; int i; if (size_t(sources_num) > *buff_size) { @@ -399,9 +399,9 @@ static int mesh_remap_interp_poly_data_get(const MPoly *mp, } } - for (i = 0, ml = &mloops[mp->loopstart], vco = *vcos, index = *indices; i < sources_num; + for (i = 0, ml = &loops[poly.loopstart], vco = *vcos, index = *indices; i < sources_num; i++, ml++, vco++, index++) { - *index = use_loops ? int(mp->loopstart) + i : int(ml->v); + *index = use_loops ? int(poly.loopstart) + i : int(ml->v); copy_v3_v3(*vco, vcos_src[ml->v]); if (r_closest_index) { /* Find closest vert/loop in this case. */ @@ -515,7 +515,7 @@ void BKE_mesh_remap_calc_verts_from_mesh(const int mode, } } else if (ELEM(mode, MREMAP_MODE_VERT_EDGE_NEAREST, MREMAP_MODE_VERT_EDGEINTERP_NEAREST)) { - const MEdge *edges_src = BKE_mesh_edges(me_src); + const blender::Span edges_src = me_src->edges(); float(*vcos_src)[3] = BKE_mesh_vert_coords_alloc(me_src, nullptr); BKE_bvhtree_from_mesh_get(&treedata, me_src, BVHTREE_FROM_EDGES, 2); @@ -568,8 +568,8 @@ void BKE_mesh_remap_calc_verts_from_mesh(const int mode, MREMAP_MODE_VERT_POLY_NEAREST, MREMAP_MODE_VERT_POLYINTERP_NEAREST, MREMAP_MODE_VERT_POLYINTERP_VNORPROJ)) { - const MPoly *polys_src = BKE_mesh_polys(me_src); - const MLoop *loops_src = BKE_mesh_loops(me_src); + const blender::Span polys_src = me_src->polys(); + const blender::Span loops_src = me_src->loops(); float(*vcos_src)[3] = BKE_mesh_vert_coords_alloc(me_src, nullptr); const float(*vert_normals_dst)[3] = BKE_mesh_vertex_normals_ensure(me_dst); @@ -596,8 +596,7 @@ void BKE_mesh_remap_calc_verts_from_mesh(const int mode, if (mesh_remap_bvhtree_query_raycast( &treedata, &rayhit, tmp_co, tmp_no, ray_radius, max_dist, &hit_dist)) { const MLoopTri *lt = &treedata.looptri[rayhit.index]; - const MPoly *mp_src = &polys_src[lt->poly]; - const int sources_num = mesh_remap_interp_poly_data_get(mp_src, + const int sources_num = mesh_remap_interp_poly_data_get(polys_src[lt->poly], loops_src, (const float(*)[3])vcos_src, rayhit.co, @@ -631,11 +630,10 @@ void BKE_mesh_remap_calc_verts_from_mesh(const int mode, if (mesh_remap_bvhtree_query_nearest( &treedata, &nearest, tmp_co, max_dist_sq, &hit_dist)) { const MLoopTri *lt = &treedata.looptri[nearest.index]; - const MPoly *mp = &polys_src[lt->poly]; if (mode == MREMAP_MODE_VERT_POLY_NEAREST) { int index; - mesh_remap_interp_poly_data_get(mp, + mesh_remap_interp_poly_data_get(polys_src[lt->poly], loops_src, (const float(*)[3])vcos_src, nearest.co, @@ -650,7 +648,7 @@ void BKE_mesh_remap_calc_verts_from_mesh(const int mode, mesh_remap_item_define(r_map, i, hit_dist, 0, 1, &index, &full_weight); } else if (mode == MREMAP_MODE_VERT_POLYINTERP_NEAREST) { - const int sources_num = mesh_remap_interp_poly_data_get(mp, + const int sources_num = mesh_remap_interp_poly_data_get(polys_src[lt->poly], loops_src, (const float(*)[3])vcos_src, nearest.co, @@ -722,8 +720,7 @@ void BKE_mesh_remap_calc_edges_from_mesh(const int mode, if (mode == MREMAP_MODE_EDGE_VERT_NEAREST) { const int num_verts_src = me_src->totvert; - const int num_edges_src = me_src->totedge; - const MEdge *edges_src = BKE_mesh_edges(me_src); + const blender::Span edges_src = me_src->edges(); float(*vcos_src)[3] = BKE_mesh_vert_coords_alloc(me_src, nullptr); MeshElemMap *vert_to_edge_src_map; @@ -742,9 +739,9 @@ void BKE_mesh_remap_calc_edges_from_mesh(const int mode, BKE_mesh_vert_edge_map_create(&vert_to_edge_src_map, &vert_to_edge_src_map_mem, - edges_src, + edges_src.data(), num_verts_src, - num_edges_src); + int(edges_src.size())); BKE_bvhtree_from_mesh_get(&treedata, me_src, BVHTREE_FROM_VERTS, 2); nearest.index = -1; @@ -874,9 +871,9 @@ void BKE_mesh_remap_calc_edges_from_mesh(const int mode, } } else if (mode == MREMAP_MODE_EDGE_POLY_NEAREST) { - const MEdge *edges_src = BKE_mesh_edges(me_src); - const MPoly *polys_src = BKE_mesh_polys(me_src); - const MLoop *loops_src = BKE_mesh_loops(me_src); + const blender::Span edges_src = me_src->edges(); + const blender::Span polys_src = me_src->polys(); + const blender::Span loops_src = me_src->loops(); float(*vcos_src)[3] = BKE_mesh_vert_coords_alloc(me_src, nullptr); BKE_bvhtree_from_mesh_get(&treedata, me_src, BVHTREE_FROM_LOOPTRI, 2); @@ -1311,12 +1308,9 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode, const float(*positions_src)[3] = BKE_mesh_vert_positions(me_src); const int num_verts_src = me_src->totvert; float(*vcos_src)[3] = nullptr; - const MEdge *edges_src = BKE_mesh_edges(me_src); - const int num_edges_src = me_src->totedge; - const MLoop *loops_src = BKE_mesh_loops(me_src); - const int num_loops_src = me_src->totloop; - const MPoly *polys_src = BKE_mesh_polys(me_src); - const int num_polys_src = me_src->totpoly; + const blender::Span edges_src = me_src->edges(); + const blender::Span polys_src = me_src->polys(); + const blender::Span loops_src = me_src->loops(); const MLoopTri *looptri_src = nullptr; int num_looptri_src = 0; @@ -1327,7 +1321,6 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode, const MLoop *ml_src; const MLoop *ml_dst; - const MPoly *mp_src; const MPoly *mp_dst; int tindex, pidx_dst, lidx_dst, plidx_dst, pidx_src, lidx_src, plidx_src; @@ -1405,42 +1398,43 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode, if (use_from_vert) { BKE_mesh_vert_loop_map_create(&vert_to_loop_map_src, &vert_to_loop_map_src_buff, - polys_src, - loops_src, + polys_src.data(), + loops_src.data(), num_verts_src, - num_polys_src, - num_loops_src); + int(polys_src.size()), + int(loops_src.size())); if (mode & MREMAP_USE_POLY) { BKE_mesh_vert_poly_map_create(&vert_to_poly_map_src, &vert_to_poly_map_src_buff, - polys_src, - loops_src, + polys_src.data(), + loops_src.data(), num_verts_src, - num_polys_src, - num_loops_src); + int(polys_src.size()), + int(loops_src.size())); } } /* Needed for islands (or plain mesh) to AStar graph conversion. */ BKE_mesh_edge_poly_map_create(&edge_to_poly_map_src, &edge_to_poly_map_src_buff, - num_edges_src, - polys_src, - num_polys_src, - loops_src, - num_loops_src); + int(edges_src.size()), + polys_src.data(), + int(polys_src.size()), + loops_src.data(), + int(loops_src.size())); if (use_from_vert) { loop_to_poly_map_src = static_cast( - MEM_mallocN(sizeof(*loop_to_poly_map_src) * size_t(num_loops_src), __func__)); + MEM_mallocN(sizeof(*loop_to_poly_map_src) * size_t(loops_src.size()), __func__)); poly_cents_src = static_cast( - MEM_mallocN(sizeof(*poly_cents_src) * size_t(num_polys_src), __func__)); - for (pidx_src = 0, mp_src = polys_src; pidx_src < num_polys_src; pidx_src++, mp_src++) { - ml_src = &loops_src[mp_src->loopstart]; - for (plidx_src = 0, lidx_src = mp_src->loopstart; plidx_src < mp_src->totloop; + MEM_mallocN(sizeof(*poly_cents_src) * size_t(polys_src.size()), __func__)); + for (pidx_src = 0; pidx_src < polys_src.size(); pidx_src++) { + const MPoly &poly = polys_src[pidx_src]; + ml_src = &loops_src[poly.loopstart]; + for (plidx_src = 0, lidx_src = poly.loopstart; plidx_src < poly.totloop; plidx_src++, lidx_src++) { loop_to_poly_map_src[lidx_src] = pidx_src; } - BKE_mesh_calc_poly_center(mp_src, ml_src, positions_src, poly_cents_src[pidx_src]); + BKE_mesh_calc_poly_center(&poly, ml_src, positions_src, poly_cents_src[pidx_src]); } } @@ -1455,12 +1449,12 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode, if (gen_islands_src) { use_islands = gen_islands_src(positions_src, num_verts_src, - edges_src, - num_edges_src, - polys_src, - num_polys_src, - loops_src, - num_loops_src, + edges_src.data(), + int(edges_src.size()), + polys_src.data(), + int(polys_src.size()), + loops_src.data(), + int(loops_src.size()), &island_store); num_trees = use_islands ? island_store.islands_num : 1; @@ -1495,10 +1489,10 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode, tindex, positions_src, edge_to_poly_map_src, - num_edges_src, - loops_src, - polys_src, - num_polys_src, + int(edges_src.size()), + loops_src.data(), + polys_src.data(), + int(polys_src.size()), &as_graphdata[tindex]); } } @@ -1513,9 +1507,8 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode, int num_verts_active = 0; verts_active.fill(false); for (i = 0; i < isld->count; i++) { - mp_src = &polys_src[isld->indices[i]]; - for (lidx_src = mp_src->loopstart; lidx_src < mp_src->loopstart + mp_src->totloop; - lidx_src++) { + const MPoly &poly = polys_src[isld->indices[i]]; + for (lidx_src = poly.loopstart; lidx_src < poly.loopstart + poly.totloop; lidx_src++) { const uint vidx_src = loops_src[lidx_src].v; if (!verts_active[vidx_src]) { verts_active[vidx_src].set(); @@ -1549,15 +1542,15 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode, int num_looptri_active = 0; looptri_active.fill(false); for (i = 0; i < num_looptri_src; i++) { - mp_src = &polys_src[looptri_src[i].poly]; - if (island_store.items_to_islands[mp_src->loopstart] == tindex) { + const MPoly &poly = polys_src[looptri_src[i].poly]; + if (island_store.items_to_islands[poly.loopstart] == tindex) { looptri_active[i].set(); num_looptri_active++; } } bvhtree_from_mesh_looptri_ex(&treedata[tindex], positions_src, - loops_src, + loops_src.data(), looptri_src, num_looptri_src, looptri_active, @@ -1670,8 +1663,8 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode, float *pcent_src; float sqdist; - mp_src = &polys_src[pidx_src]; - ml_src = &loops_src[mp_src->loopstart]; + const MPoly &poly = polys_src[pidx_src]; + ml_src = &loops_src[poly.loopstart]; if (!pcent_dst_valid) { BKE_mesh_calc_poly_center( @@ -1696,11 +1689,11 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode, else if (mode == MREMAP_MODE_LOOP_NEAREST_POLYNOR) { /* Our best_index_src is a poly one for now! * Have to find its loop matching our closest vertex. */ - mp_src = &polys_src[best_index_src]; - ml_src = &loops_src[mp_src->loopstart]; - for (plidx_src = 0; plidx_src < mp_src->totloop; plidx_src++, ml_src++) { + const MPoly &poly = polys_src[best_index_src]; + ml_src = &loops_src[poly.loopstart]; + for (plidx_src = 0; plidx_src < poly.totloop; plidx_src++, ml_src++) { if (int(ml_src->v) == nearest.index) { - best_index_src = plidx_src + mp_src->loopstart; + best_index_src = plidx_src + poly.loopstart; break; } } @@ -1915,13 +1908,13 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode, pidx_src = (use_islands ? best_island->indices[last_valid_pidx_isld_src] : last_valid_pidx_isld_src); - mp_src = &polys_src[pidx_src]; - ml_src = &loops_src[mp_src->loopstart]; - for (j = 0; j < mp_src->totloop; j++, ml_src++) { + const MPoly &poly = polys_src[pidx_src]; + ml_src = &loops_src[poly.loopstart]; + for (j = 0; j < poly.totloop; j++, ml_src++) { const float dist_sq = len_squared_v3v3(positions_src[ml_src->v], tmp_co); if (dist_sq < best_dist_sq) { best_dist_sq = dist_sq; - lidx_src = mp_src->loopstart + j; + lidx_src = poly.loopstart + j; } } } @@ -1951,7 +1944,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode, float *hit_co = isld_res->hit_point; int best_loop_index_src; - mp_src = &polys_src[pidx_src]; + const MPoly &poly = polys_src[pidx_src]; /* If prev and curr poly are the same, no need to do anything more!!! */ if (!ELEM(pidx_src_prev, -1, pidx_src) && isld_steps_src) { int pidx_isld_src, pidx_isld_src_prev; @@ -2008,14 +2001,13 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode, pidx_src = (use_islands ? best_island->indices[last_valid_pidx_isld_src] : last_valid_pidx_isld_src); - mp_src = &polys_src[pidx_src]; /* Create that one on demand. */ if (poly_to_looptri_map_src == nullptr) { BKE_mesh_origindex_map_create_looptri(&poly_to_looptri_map_src, &poly_to_looptri_map_src_buff, - polys_src, - num_polys_src, + polys_src.data(), + int(polys_src.size()), looptri_src, num_looptri_src); } @@ -2042,7 +2034,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode, } if (mode == MREMAP_MODE_LOOP_POLY_NEAREST) { - mesh_remap_interp_poly_data_get(mp_src, + mesh_remap_interp_poly_data_get(poly, loops_src, (const float(*)[3])vcos_src, hit_co, @@ -2064,7 +2056,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode, } else { const int sources_num = mesh_remap_interp_poly_data_get( - mp_src, + poly, loops_src, (const float(*)[3])vcos_src, hit_co, diff --git a/source/blender/blenkernel/intern/mesh_tangent.cc b/source/blender/blenkernel/intern/mesh_tangent.cc index b0bc16b2732..d40c9a458db 100644 --- a/source/blender/blenkernel/intern/mesh_tangent.cc +++ b/source/blender/blenkernel/intern/mesh_tangent.cc @@ -146,12 +146,12 @@ void BKE_mesh_calc_loop_tangent_single(Mesh *mesh, BKE_mesh_calc_loop_tangent_single_ex(BKE_mesh_vert_positions(mesh), mesh->totvert, - BKE_mesh_loops(mesh), + mesh->loops().data(), r_looptangents, loop_normals, reinterpret_cast(uv_map.data()), mesh->totloop, - BKE_mesh_polys(mesh), + mesh->polys().data(), mesh->totpoly, reports); } @@ -577,9 +577,9 @@ void BKE_mesh_calc_loop_tangents(Mesh *me_eval, short tangent_mask = 0; BKE_mesh_calc_loop_tangent_ex( BKE_mesh_vert_positions(me_eval), - BKE_mesh_polys(me_eval), + me_eval->polys().data(), uint(me_eval->totpoly), - BKE_mesh_loops(me_eval), + me_eval->loops().data(), BKE_mesh_runtime_looptri_ensure(me_eval), uint(BKE_mesh_runtime_looptri_len(me_eval)), &me_eval->ldata, diff --git a/source/blender/blenkernel/intern/multires.cc b/source/blender/blenkernel/intern/multires.cc index aaa35e02747..49084ca12cb 100644 --- a/source/blender/blenkernel/intern/multires.cc +++ b/source/blender/blenkernel/intern/multires.cc @@ -183,15 +183,15 @@ static BLI_bitmap *multires_mdisps_downsample_hidden(const BLI_bitmap *old_hidde static void multires_output_hidden_to_ccgdm(CCGDerivedMesh *ccgdm, Mesh *me, int level) { - const MPoly *polys = BKE_mesh_polys(me); + const blender::Span polys = me->polys(); const MDisps *mdisps = static_cast(CustomData_get_layer(&me->ldata, CD_MDISPS)); BLI_bitmap **grid_hidden = ccgdm->gridHidden; int *gridOffset; - int i, j; + int j; gridOffset = ccgdm->dm.getGridOffset(&ccgdm->dm); - for (i = 0; i < me->totpoly; i++) { + for (const int i : polys.index_range()) { for (j = 0; j < polys[i].totloop; j++) { int g = gridOffset[i] + j; const MDisps *md = &mdisps[g]; @@ -487,12 +487,12 @@ void multires_force_external_reload(Object *object) static int get_levels_from_disps(Object *ob) { Mesh *me = static_cast(ob->data); - const MPoly *polys = BKE_mesh_polys(me); - int i, j, totlvl = 0; + const blender::Span polys = me->polys(); + int j, totlvl = 0; const MDisps *mdisp = static_cast(CustomData_get_layer(&me->ldata, CD_MDISPS)); - for (i = 0; i < me->totpoly; i++) { + for (const int i : polys.index_range()) { const MDisps *md = mdisp + polys[i].loopstart; for (j = 0; j < polys[i].totloop; j++, md++) { @@ -657,7 +657,7 @@ static void multires_grid_paint_mask_downsample(GridPaintMask *gpm, int level) static void multires_del_higher(MultiresModifierData *mmd, Object *ob, int lvl) { Mesh *me = (Mesh *)ob->data; - const MPoly *polys = BKE_mesh_polys(me); + const blender::Span polys = me->polys(); int levels = mmd->totlvl - lvl; MDisps *mdisps; GridPaintMask *gpm; @@ -676,9 +676,9 @@ static void multires_del_higher(MultiresModifierData *mmd, Object *ob, int lvl) // MLoop *ml = me->mloop; /*UNUSED*/ int nsize = multires_side_tot[lvl]; int hsize = multires_side_tot[mmd->totlvl]; - int i, j; + int j; - for (i = 0; i < me->totpoly; i++) { + for (const int i : polys.index_range()) { for (j = 0; j < polys[i].totloop; j++) { int g = polys[i].loopstart + j; MDisps *mdisp = &mdisps[g]; @@ -968,7 +968,7 @@ static void multiresModifier_disp_run( CCGDerivedMesh *ccgdm = (CCGDerivedMesh *)dm; CCGElem **gridData, **subGridData; CCGKey key; - const MPoly *mpoly = BKE_mesh_polys(me); + const MPoly *mpoly = me->polys().data(); MDisps *mdisps = static_cast( CustomData_get_layer_for_write(&me->ldata, CD_MDISPS, me->totloop)); GridPaintMask *grid_paint_mask = nullptr; diff --git a/source/blender/blenkernel/intern/multires_reshape.hh b/source/blender/blenkernel/intern/multires_reshape.hh index 8e112f18d7b..d709afca86f 100644 --- a/source/blender/blenkernel/intern/multires_reshape.hh +++ b/source/blender/blenkernel/intern/multires_reshape.hh @@ -7,6 +7,7 @@ #pragma once +#include "BLI_span.hh" #include "BLI_sys_types.h" #include "BKE_multires.h" @@ -34,9 +35,9 @@ struct MultiresReshapeContext { * NOTE: Does NOT include any leading modifiers in it. */ Mesh *base_mesh; const float (*base_positions)[3]; - const MEdge *base_edges; - const MPoly *base_polys; - const MLoop *base_loops; + blender::Span base_edges; + blender::Span base_polys; + blender::Span base_loops; /* Subdivision surface created for multires modifier. * diff --git a/source/blender/blenkernel/intern/multires_reshape_apply_base.cc b/source/blender/blenkernel/intern/multires_reshape_apply_base.cc index f2c2df9d7ce..50083ada4a1 100644 --- a/source/blender/blenkernel/intern/multires_reshape_apply_base.cc +++ b/source/blender/blenkernel/intern/multires_reshape_apply_base.cc @@ -34,9 +34,9 @@ void multires_reshape_apply_base_update_mesh_coords(MultiresReshapeContext *resh /* Update the context in case the vertices were duplicated. */ reshape_context->base_positions = base_positions; - const MLoop *mloop = reshape_context->base_loops; - for (int loop_index = 0; loop_index < base_mesh->totloop; ++loop_index) { - const MLoop *loop = &mloop[loop_index]; + const blender::Span loops = reshape_context->base_loops; + for (const int loop_index : loops.index_range()) { + const MLoop *loop = &loops[loop_index]; GridCoord grid_coord; grid_coord.grid_index = loop_index; @@ -75,8 +75,8 @@ void multires_reshape_apply_base_refit_base_mesh(MultiresReshapeContext *reshape int *pmap_mem; BKE_mesh_vert_poly_map_create(&pmap, &pmap_mem, - reshape_context->base_polys, - reshape_context->base_loops, + reshape_context->base_polys.data(), + reshape_context->base_loops.data(), base_mesh->totvert, base_mesh->totpoly, base_mesh->totloop); diff --git a/source/blender/blenkernel/intern/multires_reshape_smooth.cc b/source/blender/blenkernel/intern/multires_reshape_smooth.cc index 19cad4e8e71..ce8df750f8a 100644 --- a/source/blender/blenkernel/intern/multires_reshape_smooth.cc +++ b/source/blender/blenkernel/intern/multires_reshape_smooth.cc @@ -849,17 +849,17 @@ static void geometry_init_loose_information(MultiresReshapeSmoothContext *reshap { const MultiresReshapeContext *reshape_context = reshape_smooth_context->reshape_context; const Mesh *base_mesh = reshape_context->base_mesh; - const MPoly *base_mpoly = reshape_context->base_polys; - const MLoop *base_mloop = reshape_context->base_loops; + const blender::Span base_polys = reshape_context->base_polys; + const blender::Span base_loops = reshape_context->base_loops; reshape_smooth_context->non_loose_base_edge_map = BLI_BITMAP_NEW(base_mesh->totedge, "non_loose_base_edge_map"); int num_used_edges = 0; - for (int poly_index = 0; poly_index < base_mesh->totpoly; ++poly_index) { - const MPoly *base_poly = &base_mpoly[poly_index]; + for (const int poly_index : base_polys.index_range()) { + const MPoly *base_poly = &base_polys[poly_index]; for (int corner = 0; corner < base_poly->totloop; corner++) { - const MLoop *loop = &base_mloop[base_poly->loopstart + corner]; + const MLoop *loop = &base_loops[base_poly->loopstart + corner]; if (!BLI_BITMAP_TEST_BOOL(reshape_smooth_context->non_loose_base_edge_map, loop->e)) { BLI_BITMAP_ENABLE(reshape_smooth_context->non_loose_base_edge_map, loop->e); diff --git a/source/blender/blenkernel/intern/multires_reshape_subdivide.cc b/source/blender/blenkernel/intern/multires_reshape_subdivide.cc index 724e07a7d44..4bef8b6ee0f 100644 --- a/source/blender/blenkernel/intern/multires_reshape_subdivide.cc +++ b/source/blender/blenkernel/intern/multires_reshape_subdivide.cc @@ -29,13 +29,12 @@ static void multires_subdivide_create_object_space_linear_grids(Mesh *mesh) { const float(*positions)[3] = BKE_mesh_vert_positions(mesh); - const MPoly *polys = BKE_mesh_polys(mesh); - const MLoop *loops = BKE_mesh_loops(mesh); + const blender::Span polys = mesh->polys(); + const blender::Span loops = mesh->loops(); MDisps *mdisps = static_cast( CustomData_get_layer_for_write(&mesh->ldata, CD_MDISPS, mesh->totloop)); - const int totpoly = mesh->totpoly; - for (int p = 0; p < totpoly; p++) { + for (const int p : polys.index_range()) { const MPoly *poly = &polys[p]; float poly_center[3]; BKE_mesh_calc_poly_center(poly, &loops[poly->loopstart], positions, poly_center); diff --git a/source/blender/blenkernel/intern/multires_reshape_util.cc b/source/blender/blenkernel/intern/multires_reshape_util.cc index 93d1662de14..d0dbfd0a144 100644 --- a/source/blender/blenkernel/intern/multires_reshape_util.cc +++ b/source/blender/blenkernel/intern/multires_reshape_util.cc @@ -61,13 +61,13 @@ Subdiv *multires_reshape_create_subdiv(Depsgraph *depsgraph, static void context_zero(MultiresReshapeContext *reshape_context) { - memset(reshape_context, 0, sizeof(*reshape_context)); + *reshape_context = {}; } static void context_init_lookup(MultiresReshapeContext *reshape_context) { const Mesh *base_mesh = reshape_context->base_mesh; - const MPoly *mpoly = reshape_context->base_polys; + const blender::Span polys = reshape_context->base_polys; const int num_faces = base_mesh->totpoly; reshape_context->face_start_grid_index = static_cast( @@ -75,7 +75,7 @@ static void context_init_lookup(MultiresReshapeContext *reshape_context) int num_grids = 0; int num_ptex_faces = 0; for (int face_index = 0; face_index < num_faces; ++face_index) { - const int num_corners = mpoly[face_index].totloop; + const int num_corners = polys[face_index].totloop; reshape_context->face_start_grid_index[face_index] = num_grids; num_grids += num_corners; num_ptex_faces += (num_corners == 4) ? 1 : num_corners; @@ -86,7 +86,7 @@ static void context_init_lookup(MultiresReshapeContext *reshape_context) reshape_context->ptex_start_grid_index = static_cast( MEM_malloc_arrayN(num_ptex_faces, sizeof(int), "ptex_start_grid_index")); for (int face_index = 0, grid_index = 0, ptex_index = 0; face_index < num_faces; ++face_index) { - const int num_corners = mpoly[face_index].totloop; + const int num_corners = polys[face_index].totloop; const int num_face_ptex_faces = (num_corners == 4) ? 1 : num_corners; for (int i = 0; i < num_face_ptex_faces; ++i) { reshape_context->ptex_start_grid_index[ptex_index + i] = grid_index + i; @@ -156,9 +156,9 @@ bool multires_reshape_context_create_from_base_mesh(MultiresReshapeContext *resh reshape_context->base_mesh = base_mesh; reshape_context->base_positions = BKE_mesh_vert_positions(base_mesh); - reshape_context->base_edges = BKE_mesh_edges(base_mesh); - reshape_context->base_polys = BKE_mesh_polys(base_mesh); - reshape_context->base_loops = BKE_mesh_loops(base_mesh); + reshape_context->base_edges = base_mesh->edges(); + reshape_context->base_polys = base_mesh->polys(); + reshape_context->base_loops = base_mesh->loops(); reshape_context->subdiv = multires_reshape_create_subdiv(nullptr, object, mmd); reshape_context->need_free_subdiv = true; @@ -193,9 +193,9 @@ bool multires_reshape_context_create_from_object(MultiresReshapeContext *reshape reshape_context->base_mesh = base_mesh; reshape_context->base_positions = BKE_mesh_vert_positions(base_mesh); - reshape_context->base_edges = BKE_mesh_edges(base_mesh); - reshape_context->base_polys = BKE_mesh_polys(base_mesh); - reshape_context->base_loops = BKE_mesh_loops(base_mesh); + reshape_context->base_edges = base_mesh->edges(); + reshape_context->base_polys = base_mesh->polys(); + reshape_context->base_loops = base_mesh->loops(); reshape_context->subdiv = multires_reshape_create_subdiv(depsgraph, object, mmd); reshape_context->need_free_subdiv = true; @@ -227,9 +227,9 @@ bool multires_reshape_context_create_from_ccg(MultiresReshapeContext *reshape_co reshape_context->base_mesh = base_mesh; reshape_context->base_positions = BKE_mesh_vert_positions(base_mesh); - reshape_context->base_edges = BKE_mesh_edges(base_mesh); - reshape_context->base_polys = BKE_mesh_polys(base_mesh); - reshape_context->base_loops = BKE_mesh_loops(base_mesh); + reshape_context->base_edges = base_mesh->edges(); + reshape_context->base_polys = base_mesh->polys(); + reshape_context->base_loops = base_mesh->loops(); reshape_context->subdiv = subdiv_ccg->subdiv; reshape_context->need_free_subdiv = false; @@ -274,9 +274,9 @@ bool multires_reshape_context_create_from_subdiv(MultiresReshapeContext *reshape reshape_context->mmd = mmd; reshape_context->base_mesh = base_mesh; reshape_context->base_positions = BKE_mesh_vert_positions(base_mesh); - reshape_context->base_edges = BKE_mesh_edges(base_mesh); - reshape_context->base_polys = BKE_mesh_polys(base_mesh); - reshape_context->base_loops = BKE_mesh_loops(base_mesh); + reshape_context->base_edges = base_mesh->edges(); + reshape_context->base_polys = base_mesh->polys(); + reshape_context->base_loops = base_mesh->loops(); reshape_context->cd_vertex_crease = (const float *)CustomData_get_layer(&base_mesh->edata, CD_CREASE); @@ -665,11 +665,11 @@ static void foreach_grid_face_coordinate_task(void *__restrict userdata_v, const MultiresReshapeContext *reshape_context = data->reshape_context; - const MPoly *mpoly = reshape_context->base_polys; + const blender::Span polys = reshape_context->base_polys; const int grid_size = data->grid_size; const float grid_size_1_inv = 1.0f / (float(grid_size) - 1.0f); - const int num_corners = mpoly[face_index].totloop; + const int num_corners = polys[face_index].totloop; int grid_index = reshape_context->face_start_grid_index[face_index]; for (int corner = 0; corner < num_corners; ++corner, ++grid_index) { for (int y = 0; y < grid_size; ++y) { diff --git a/source/blender/blenkernel/intern/multires_unsubdivide.cc b/source/blender/blenkernel/intern/multires_unsubdivide.cc index d6c2e8fd80e..cfcfc25b72f 100644 --- a/source/blender/blenkernel/intern/multires_unsubdivide.cc +++ b/source/blender/blenkernel/intern/multires_unsubdivide.cc @@ -642,8 +642,8 @@ static void store_grid_data(MultiresUnsubdivideContext *context, int grid_y) { Mesh *original_mesh = context->original_mesh; - const MPoly *polys = BKE_mesh_polys(original_mesh); - const MLoop *loops = BKE_mesh_loops(original_mesh); + const blender::Span polys = original_mesh->polys(); + const blender::Span loops = original_mesh->loops(); const MPoly *poly = &polys[BM_elem_index_get(f)]; const int corner_vertex_index = BM_elem_index_get(v); @@ -921,7 +921,7 @@ static void multires_unsubdivide_prepare_original_bmesh_for_extract( MultiresUnsubdivideContext *context) { Mesh *original_mesh = context->original_mesh; - const MPoly *original_polys = BKE_mesh_polys(original_mesh); + const blender::Span original_polys = original_mesh->polys(); Mesh *base_mesh = context->base_mesh; @@ -966,8 +966,11 @@ static void multires_unsubdivide_prepare_original_bmesh_for_extract( * Checks the orientation of the loops to flip the x and y axis when extracting the grid if * necessary. */ -static bool multires_unsubdivide_flip_grid_x_axis( - const MPoly *polys, const MLoop *loops, int poly, int loop, int v_x) +static bool multires_unsubdivide_flip_grid_x_axis(const blender::Span polys, + const blender::Span loops, + int poly, + int loop, + int v_x) { const MPoly *p = &polys[poly]; @@ -1041,8 +1044,8 @@ static void multires_unsubdivide_extract_grids(MultiresUnsubdivideContext *conte const int base_l_offset = CustomData_get_n_offset( &bm_base_mesh->ldata, CD_PROP_INT32, base_l_layer_index); - const MPoly *polys = BKE_mesh_polys(base_mesh); - const MLoop *loops = BKE_mesh_loops(base_mesh); + const blender::Span polys = base_mesh->polys(); + const blender::Span loops = base_mesh->loops(); /* Main loop for extracting the grids. Iterates over the base mesh vertices. */ BM_ITER_MESH (v, &iter, bm_base_mesh, BM_VERTS_OF_MESH) { diff --git a/source/blender/blenkernel/intern/paint.cc b/source/blender/blenkernel/intern/paint.cc index c8d93c3039d..5c5c670deeb 100644 --- a/source/blender/blenkernel/intern/paint.cc +++ b/source/blender/blenkernel/intern/paint.cc @@ -1696,16 +1696,16 @@ static void sculpt_update_object( /* These are assigned to the base mesh in Multires. This is needed because Face Sets operators * and tools use the Face Sets data from the base mesh when Multires is active. */ ss->vert_positions = BKE_mesh_vert_positions_for_write(me); - ss->mpoly = BKE_mesh_polys(me); - ss->mloop = BKE_mesh_loops(me); + ss->mpoly = me->polys().data(); + ss->mloop = me->loops().data(); } else { ss->totvert = me->totvert; ss->totpoly = me->totpoly; ss->totfaces = me->totpoly; ss->vert_positions = BKE_mesh_vert_positions_for_write(me); - ss->mpoly = BKE_mesh_polys(me); - ss->mloop = BKE_mesh_loops(me); + ss->mpoly = me->polys().data(); + ss->mloop = me->loops().data(); ss->multires.active = false; ss->multires.modifier = nullptr; ss->multires.level = 0; @@ -1765,8 +1765,8 @@ static void sculpt_update_object( if (need_pmap && ob->type == OB_MESH && !ss->pmap) { BKE_mesh_vert_poly_map_create(&ss->pmap, &ss->pmap_mem, - BKE_mesh_polys(me), - BKE_mesh_loops(me), + me->polys().data(), + me->loops().data(), me->totvert, me->totpoly, me->totloop); diff --git a/source/blender/blenkernel/intern/pbvh.cc b/source/blender/blenkernel/intern/pbvh.cc index 7d4769c6e25..ecae54dba94 100644 --- a/source/blender/blenkernel/intern/pbvh.cc +++ b/source/blender/blenkernel/intern/pbvh.cc @@ -924,10 +924,9 @@ void BKE_pbvh_build_grids(PBVH *pbvh, /* Find maximum number of grids per face. */ int max_grids = 1; - const MPoly *mpoly = BKE_mesh_polys(me); - - for (int i = 0; i < me->totpoly; i++) { - max_grids = max_ii(max_grids, mpoly[i].totloop); + const blender::Span polys = me->polys(); + for (const int i : polys.index_range()) { + max_grids = max_ii(max_grids, polys[i].totloop); } /* Ensure leaf limit is at least 4 so there's room @@ -941,8 +940,8 @@ void BKE_pbvh_build_grids(PBVH *pbvh, pbvh->ldata = &me->ldata; pbvh->pdata = &me->pdata; - pbvh->mpoly = BKE_mesh_polys(me); - pbvh->mloop = BKE_mesh_loops(me); + pbvh->mpoly = me->polys().data(); + pbvh->mloop = me->loops().data(); /* We also need the base mesh for PBVH draw. */ pbvh->mesh = me; @@ -3846,18 +3845,18 @@ void BKE_pbvh_sync_visibility_from_verts(PBVH *pbvh, Mesh *mesh) break; } case PBVH_GRIDS: { - const MPoly *mp = BKE_mesh_polys(mesh); + const blender::Span polys = mesh->polys(); CCGKey key = pbvh->gridkey; bool *hide_poly = static_cast(CustomData_get_layer_named_for_write( &mesh->pdata, CD_PROP_BOOL, ".hide_poly", mesh->totpoly)); bool delete_hide_poly = true; - for (int face_index = 0; face_index < mesh->totpoly; face_index++, mp++) { + for (const int face_index : polys.index_range()) { bool hidden = false; - for (int loop_index = 0; !hidden && loop_index < mp->totloop; loop_index++) { - int grid_index = mp->loopstart + loop_index; + for (int loop_index = 0; !hidden && loop_index < polys[face_index].totloop; loop_index++) { + int grid_index = polys[face_index].loopstart + loop_index; if (pbvh->grid_hidden[grid_index] && BLI_BITMAP_TEST(pbvh->grid_hidden[grid_index], key.grid_area - 1)) { diff --git a/source/blender/blenkernel/intern/shrinkwrap.cc b/source/blender/blenkernel/intern/shrinkwrap.cc index 1a0b33ca2b1..0756d04ffc4 100644 --- a/source/blender/blenkernel/intern/shrinkwrap.cc +++ b/source/blender/blenkernel/intern/shrinkwrap.cc @@ -114,7 +114,7 @@ bool BKE_shrinkwrap_init_tree( } data->mesh = mesh; - data->polys = BKE_mesh_polys(mesh); + data->polys = mesh->polys().data(); data->vert_normals = BKE_mesh_vertex_normals_ensure(mesh); if (shrinkType == MOD_SHRINKWRAP_NEAREST_VERTEX) { @@ -189,15 +189,15 @@ static void merge_vert_dir(ShrinkwrapBoundaryVertData *vdata, static ShrinkwrapBoundaryData *shrinkwrap_build_boundary_data(Mesh *mesh) { const float(*positions)[3] = BKE_mesh_vert_positions(mesh); - const MEdge *medge = BKE_mesh_edges(mesh); - const MLoop *mloop = BKE_mesh_loops(mesh); + const blender::Span edges = mesh->edges(); + const blender::Span loops = mesh->loops(); /* Count faces per edge (up to 2). */ char *edge_mode = static_cast( MEM_calloc_arrayN(size_t(mesh->totedge), sizeof(char), __func__)); for (int i = 0; i < mesh->totloop; i++) { - uint eidx = mloop[i].e; + uint eidx = loops[i].e; if (edge_mode[eidx] < 2) { edge_mode[eidx]++; @@ -238,11 +238,11 @@ static ShrinkwrapBoundaryData *shrinkwrap_build_boundary_data(Mesh *mesh) "ShrinkwrapBoundaryData::looptri_is_boundary"); for (int i = 0; i < totlooptri; i++) { - int edges[3]; - BKE_mesh_looptri_get_real_edges(medge, mloop, &mlooptri[i], edges); + int real_edges[3]; + BKE_mesh_looptri_get_real_edges(edges.data(), loops.data(), &mlooptri[i], real_edges); for (int j = 0; j < 3; j++) { - if (edges[j] >= 0 && edge_mode[edges[j]]) { + if (real_edges[j] >= 0 && edge_mode[real_edges[j]]) { BLI_BITMAP_ENABLE(looptri_has_boundary, i); break; } @@ -257,7 +257,7 @@ static ShrinkwrapBoundaryData *shrinkwrap_build_boundary_data(Mesh *mesh) for (int i = 0; i < mesh->totedge; i++) { if (edge_mode[i]) { - const MEdge *edge = &medge[i]; + const MEdge *edge = &edges[i]; vert_boundary_id[edge->v1] = 1; vert_boundary_id[edge->v2] = 1; @@ -282,7 +282,7 @@ static ShrinkwrapBoundaryData *shrinkwrap_build_boundary_data(Mesh *mesh) for (int i = 0; i < mesh->totedge; i++) { if (edge_mode[i]) { - const MEdge *edge = &medge[i]; + const MEdge *edge = &edges[i]; float dir[3]; sub_v3_v3v3(dir, positions[edge->v2], positions[edge->v1]); diff --git a/source/blender/blenkernel/intern/subdiv_ccg_mask.cc b/source/blender/blenkernel/intern/subdiv_ccg_mask.cc index 538c4c5eaf4..b76b63c3f5d 100644 --- a/source/blender/blenkernel/intern/subdiv_ccg_mask.cc +++ b/source/blender/blenkernel/intern/subdiv_ccg_mask.cc @@ -29,7 +29,7 @@ struct PolyCornerIndex { struct GridPaintMaskData { // int grid_size; - const MPoly *mpoly; + blender::Span polys; const GridPaintMask *grid_paint_mask; /* Indexed by ptex face index, contains polygon/corner which corresponds * to it. @@ -50,7 +50,7 @@ static int mask_get_grid_and_coord(SubdivCCGMaskEvaluator *mask_evaluator, { GridPaintMaskData *data = static_cast(mask_evaluator->user_data); const PolyCornerIndex *poly_corner = &data->ptex_poly_corner[ptex_face_index]; - const MPoly *poly = &data->mpoly[poly_corner->poly_index]; + const MPoly *poly = &data->polys[poly_corner->poly_index]; const int start_grid_index = poly->loopstart + poly_corner->corner; int corner = 0; if (poly->totloop == 4) { @@ -103,9 +103,9 @@ static void free_mask_data(SubdivCCGMaskEvaluator *mask_evaluator) static int count_num_ptex_faces(const Mesh *mesh) { int num_ptex_faces = 0; - const MPoly *mpoly = BKE_mesh_polys(mesh); + const blender::Span polys = mesh->polys(); for (int poly_index = 0; poly_index < mesh->totpoly; poly_index++) { - const MPoly *poly = &mpoly[poly_index]; + const MPoly *poly = &polys[poly_index]; num_ptex_faces += (poly->totloop == 4) ? 1 : poly->totloop; } return num_ptex_faces; @@ -114,7 +114,7 @@ static int count_num_ptex_faces(const Mesh *mesh) static void mask_data_init_mapping(SubdivCCGMaskEvaluator *mask_evaluator, const Mesh *mesh) { GridPaintMaskData *data = static_cast(mask_evaluator->user_data); - const MPoly *mpoly = BKE_mesh_polys(mesh); + const blender::Span polys = mesh->polys(); const int num_ptex_faces = count_num_ptex_faces(mesh); /* Allocate memory. */ data->ptex_poly_corner = static_cast( @@ -123,7 +123,7 @@ static void mask_data_init_mapping(SubdivCCGMaskEvaluator *mask_evaluator, const int ptex_face_index = 0; PolyCornerIndex *ptex_poly_corner = data->ptex_poly_corner; for (int poly_index = 0; poly_index < mesh->totpoly; poly_index++) { - const MPoly *poly = &mpoly[poly_index]; + const MPoly *poly = &polys[poly_index]; if (poly->totloop == 4) { ptex_poly_corner[ptex_face_index].poly_index = poly_index; ptex_poly_corner[ptex_face_index].corner = 0; @@ -142,7 +142,7 @@ static void mask_data_init_mapping(SubdivCCGMaskEvaluator *mask_evaluator, const static void mask_init_data(SubdivCCGMaskEvaluator *mask_evaluator, const Mesh *mesh) { GridPaintMaskData *data = static_cast(mask_evaluator->user_data); - data->mpoly = BKE_mesh_polys(mesh); + data->polys = mesh->polys(); data->grid_paint_mask = static_cast( CustomData_get_layer(&mesh->ldata, CD_GRID_PAINT_MASK)); mask_data_init_mapping(mask_evaluator, mesh); diff --git a/source/blender/blenkernel/intern/subdiv_ccg_material.cc b/source/blender/blenkernel/intern/subdiv_ccg_material.cc index 23f5371b504..b1fe12ce8fe 100644 --- a/source/blender/blenkernel/intern/subdiv_ccg_material.cc +++ b/source/blender/blenkernel/intern/subdiv_ccg_material.cc @@ -15,7 +15,7 @@ struct CCGMaterialFromMeshData { const Mesh *mesh; - const MPoly *polys; + blender::Span polys; const int *material_indices; }; @@ -45,7 +45,7 @@ void BKE_subdiv_ccg_material_flags_init_from_mesh( data->mesh = mesh; data->material_indices = (const int *)CustomData_get_layer_named( &mesh->pdata, CD_PROP_INT32, "material_index"); - data->polys = BKE_mesh_polys(mesh); + data->polys = mesh->polys(); material_flags_evaluator->eval_material_flags = subdiv_ccg_material_flags_eval; material_flags_evaluator->free = subdiv_ccg_material_flags_free; material_flags_evaluator->user_data = data; diff --git a/source/blender/blenkernel/intern/subdiv_converter_mesh.cc b/source/blender/blenkernel/intern/subdiv_converter_mesh.cc index 8be3f128e10..85cac62660d 100644 --- a/source/blender/blenkernel/intern/subdiv_converter_mesh.cc +++ b/source/blender/blenkernel/intern/subdiv_converter_mesh.cc @@ -35,9 +35,9 @@ struct ConverterStorage { SubdivSettings settings; const Mesh *mesh; const float (*vert_positions)[3]; - const MEdge *edges; - const MPoly *polys; - const MLoop *loops; + blender::Span edges; + blender::Span polys; + blender::Span loops; /* CustomData layer for vertex sharpnesses. */ const float *cd_vertex_crease; @@ -135,10 +135,10 @@ static void get_face_vertices(const OpenSubdiv_Converter *converter, { ConverterStorage *storage = static_cast(converter->user_data); const MPoly *poly = &storage->polys[manifold_face_index]; - const MLoop *mloop = storage->loops; + const blender::Span loops = storage->loops; for (int corner = 0; corner < poly->totloop; corner++) { manifold_face_vertices[corner] = - storage->manifold_vertex_index[mloop[poly->loopstart + corner].v]; + storage->manifold_vertex_index[loops[poly->loopstart + corner].v]; } } @@ -213,10 +213,10 @@ static void precalc_uv_layer(const OpenSubdiv_Converter *converter, const int la MEM_malloc_arrayN(mesh->totloop, sizeof(int), "loop uv vertex index")); } UvVertMap *uv_vert_map = BKE_mesh_uv_vert_map_create( - storage->polys, + storage->polys.data(), (const bool *)CustomData_get_layer_named(&mesh->pdata, CD_PROP_BOOL, ".hide_poly"), (const bool *)CustomData_get_layer_named(&mesh->pdata, CD_PROP_BOOL, ".select_poly"), - storage->loops, + storage->loops.data(), mloopuv, num_poly, num_vert, @@ -354,16 +354,16 @@ static void initialize_manifold_index_array(const BLI_bitmap *used_map, static void initialize_manifold_indices(ConverterStorage *storage) { const Mesh *mesh = storage->mesh; - const MEdge *medge = storage->edges; - const MLoop *mloop = storage->loops; - const MPoly *mpoly = storage->polys; + const blender::Span edges = storage->edges; + const blender::Span loops = storage->loops; + const blender::Span polys = storage->polys; /* Set bits of elements which are not loose. */ BLI_bitmap *vert_used_map = BLI_BITMAP_NEW(mesh->totvert, "vert used map"); BLI_bitmap *edge_used_map = BLI_BITMAP_NEW(mesh->totedge, "edge used map"); for (int poly_index = 0; poly_index < mesh->totpoly; poly_index++) { - const MPoly *poly = &mpoly[poly_index]; + const MPoly *poly = &polys[poly_index]; for (int corner = 0; corner < poly->totloop; corner++) { - const MLoop *loop = &mloop[poly->loopstart + corner]; + const MLoop *loop = &loops[poly->loopstart + corner]; BLI_BITMAP_ENABLE(vert_used_map, loop->v); BLI_BITMAP_ENABLE(edge_used_map, loop->e); } @@ -382,7 +382,7 @@ static void initialize_manifold_indices(ConverterStorage *storage) storage->infinite_sharp_vertices_map = BLI_BITMAP_NEW(mesh->totvert, "vert used map"); for (int edge_index = 0; edge_index < mesh->totedge; edge_index++) { if (!BLI_BITMAP_TEST_BOOL(edge_used_map, edge_index)) { - const MEdge *edge = &medge[edge_index]; + const MEdge *edge = &edges[edge_index]; BLI_BITMAP_ENABLE(storage->infinite_sharp_vertices_map, edge->v1); BLI_BITMAP_ENABLE(storage->infinite_sharp_vertices_map, edge->v2); } @@ -401,9 +401,9 @@ static void init_user_data(OpenSubdiv_Converter *converter, user_data->settings = *settings; user_data->mesh = mesh; user_data->vert_positions = BKE_mesh_vert_positions(mesh); - user_data->edges = BKE_mesh_edges(mesh); - user_data->polys = BKE_mesh_polys(mesh); - user_data->loops = BKE_mesh_loops(mesh); + user_data->edges = mesh->edges(); + user_data->polys = mesh->polys(); + user_data->loops = mesh->loops(); user_data->cd_vertex_crease = static_cast( CustomData_get_layer(&mesh->vdata, CD_CREASE)); user_data->cd_edge_crease = static_cast( diff --git a/source/blender/blenkernel/intern/subdiv_displacement_multires.cc b/source/blender/blenkernel/intern/subdiv_displacement_multires.cc index b076a4b7ad5..f4fe80276d4 100644 --- a/source/blender/blenkernel/intern/subdiv_displacement_multires.cc +++ b/source/blender/blenkernel/intern/subdiv_displacement_multires.cc @@ -35,7 +35,7 @@ struct MultiresDisplacementData { /* Mesh is used to read external displacement. */ Mesh *mesh; const MultiresModifierData *mmd; - const MPoly *mpoly; + blender::Span polys; const MDisps *mdisps; /* Indexed by ptex face index, contains polygon/corner which corresponds * to it. @@ -71,7 +71,7 @@ static int displacement_get_grid_and_coord(SubdivDisplacement *displacement, MultiresDisplacementData *data = static_cast( displacement->user_data); const PolyCornerIndex *poly_corner = &data->ptex_poly_corner[ptex_face_index]; - const MPoly *poly = &data->mpoly[poly_corner->poly_index]; + const MPoly *poly = &data->polys[poly_corner->poly_index]; const int start_grid_index = poly->loopstart + poly_corner->corner; int corner = 0; if (poly->totloop == 4) { @@ -95,7 +95,7 @@ static const MDisps *displacement_get_other_grid(SubdivDisplacement *displacemen MultiresDisplacementData *data = static_cast( displacement->user_data); const PolyCornerIndex *poly_corner = &data->ptex_poly_corner[ptex_face_index]; - const MPoly *poly = &data->mpoly[poly_corner->poly_index]; + const MPoly *poly = &data->polys[poly_corner->poly_index]; const int effective_corner = (poly->totloop == 4) ? corner : poly_corner->corner; const int next_corner = (effective_corner + corner_delta + poly->totloop) % poly->totloop; return &data->mdisps[poly->loopstart + next_corner]; @@ -174,7 +174,7 @@ static void average_read_displacement_object(MultiresDisplacementData *data, float r_D[3]) { const PolyCornerIndex *poly_corner = &data->ptex_poly_corner[ptex_face_index]; - const MPoly *poly = &data->mpoly[poly_corner->poly_index]; + const MPoly *poly = &data->polys[poly_corner->poly_index]; /* Get (u, v) coordinate within the other ptex face which corresponds to * the grid coordinates. */ float u, v; @@ -199,10 +199,10 @@ static void average_get_other_ptex_and_corner(MultiresDisplacementData *data, int *r_other_corner_index) { const PolyCornerIndex *poly_corner = &data->ptex_poly_corner[ptex_face_index]; - const MPoly *poly = &data->mpoly[poly_corner->poly_index]; + const MPoly *poly = &data->polys[poly_corner->poly_index]; const int num_corners = poly->totloop; const bool is_quad = (num_corners == 4); - const int poly_index = poly - data->mpoly; + const int poly_index = poly - data->polys.data(); const int start_ptex_face_index = data->face_ptex_offset[poly_index]; *r_other_corner_index = (corner + corner_delta + num_corners) % num_corners; *r_other_ptex_face_index = is_quad ? start_ptex_face_index : @@ -249,7 +249,7 @@ static void average_with_all(SubdivDisplacement *displacement, MultiresDisplacementData *data = static_cast( displacement->user_data); const PolyCornerIndex *poly_corner = &data->ptex_poly_corner[ptex_face_index]; - const MPoly *poly = &data->mpoly[poly_corner->poly_index]; + const MPoly *poly = &data->polys[poly_corner->poly_index]; const int num_corners = poly->totloop; for (int corner_delta = 1; corner_delta < num_corners; corner_delta++) { average_with_other(displacement, ptex_face_index, corner, 0.0f, 0.0f, corner_delta, r_D); @@ -305,7 +305,7 @@ static int displacement_get_face_corner(MultiresDisplacementData *data, const float v) { const PolyCornerIndex *poly_corner = &data->ptex_poly_corner[ptex_face_index]; - const MPoly *poly = &data->mpoly[poly_corner->poly_index]; + const MPoly *poly = &data->polys[poly_corner->poly_index]; const int num_corners = poly->totloop; const bool is_quad = (num_corners == 4); if (is_quad) { @@ -368,9 +368,9 @@ static void free_displacement(SubdivDisplacement *displacement) static int count_num_ptex_faces(const Mesh *mesh) { int num_ptex_faces = 0; - const MPoly *mpoly = BKE_mesh_polys(mesh); + const blender::Span polys = mesh->polys(); for (int poly_index = 0; poly_index < mesh->totpoly; poly_index++) { - const MPoly *poly = &mpoly[poly_index]; + const MPoly *poly = &polys[poly_index]; num_ptex_faces += (poly->totloop == 4) ? 1 : poly->totloop; } return num_ptex_faces; @@ -380,7 +380,7 @@ static void displacement_data_init_mapping(SubdivDisplacement *displacement, con { MultiresDisplacementData *data = static_cast( displacement->user_data); - const MPoly *mpoly = BKE_mesh_polys(mesh); + const blender::Span polys = mesh->polys(); const int num_ptex_faces = count_num_ptex_faces(mesh); /* Allocate memory. */ data->ptex_poly_corner = static_cast( @@ -389,7 +389,7 @@ static void displacement_data_init_mapping(SubdivDisplacement *displacement, con int ptex_face_index = 0; PolyCornerIndex *ptex_poly_corner = data->ptex_poly_corner; for (int poly_index = 0; poly_index < mesh->totpoly; poly_index++) { - const MPoly *poly = &mpoly[poly_index]; + const MPoly *poly = &polys[poly_index]; if (poly->totloop == 4) { ptex_poly_corner[ptex_face_index].poly_index = poly_index; ptex_poly_corner[ptex_face_index].corner = 0; @@ -416,7 +416,7 @@ static void displacement_init_data(SubdivDisplacement *displacement, data->grid_size = BKE_subdiv_grid_size_from_level(mmd->totlvl); data->mesh = mesh; data->mmd = mmd; - data->mpoly = BKE_mesh_polys(mesh); + data->polys = mesh->polys(); data->mdisps = static_cast(CustomData_get_layer(&mesh->ldata, CD_MDISPS)); data->face_ptex_offset = BKE_subdiv_face_ptex_offset_get(subdiv); data->is_initialized = false; diff --git a/source/blender/blenkernel/intern/subdiv_eval.cc b/source/blender/blenkernel/intern/subdiv_eval.cc index b8cda67f642..b7d79e88c26 100644 --- a/source/blender/blenkernel/intern/subdiv_eval.cc +++ b/source/blender/blenkernel/intern/subdiv_eval.cc @@ -82,17 +82,17 @@ static void set_coarse_positions(Subdiv *subdiv, const float (*coarse_vertex_cos)[3]) { const float(*positions)[3] = BKE_mesh_vert_positions(mesh); - const MPoly *mpoly = BKE_mesh_polys(mesh); - const MLoop *mloop = BKE_mesh_loops(mesh); + const blender::Span polys = mesh->polys(); + const blender::Span loops = mesh->loops(); /* Mark vertices which needs new coordinates. */ /* TODO(sergey): This is annoying to calculate this on every update, * maybe it's better to cache this mapping. Or make it possible to have * OpenSubdiv's vertices match mesh ones? */ BLI_bitmap *vertex_used_map = BLI_BITMAP_NEW(mesh->totvert, "vert used map"); for (int poly_index = 0; poly_index < mesh->totpoly; poly_index++) { - const MPoly *poly = &mpoly[poly_index]; + const MPoly *poly = &polys[poly_index]; for (int corner = 0; corner < poly->totloop; corner++) { - const MLoop *loop = &mloop[poly->loopstart + corner]; + const MLoop *loop = &loops[poly->loopstart + corner]; BLI_BITMAP_ENABLE(vertex_used_map, loop->v); } } @@ -126,7 +126,7 @@ static void set_coarse_positions(Subdiv *subdiv, struct FaceVaryingDataFromUVContext { OpenSubdiv_TopologyRefiner *topology_refiner; const Mesh *mesh; - const MPoly *polys; + blender::Span polys; const float (*mloopuv)[2]; float (*buffer)[2]; int layer_index; @@ -173,7 +173,7 @@ static void set_face_varying_data_from_uv(Subdiv *subdiv, ctx.layer_index = layer_index; ctx.mloopuv = mluv; ctx.mesh = mesh; - ctx.polys = BKE_mesh_polys(mesh); + ctx.polys = mesh->polys(); ctx.buffer = buffer; TaskParallelSettings parallel_range_settings; diff --git a/source/blender/blenkernel/intern/subdiv_foreach.cc b/source/blender/blenkernel/intern/subdiv_foreach.cc index 86a1c18c416..414781f137a 100644 --- a/source/blender/blenkernel/intern/subdiv_foreach.cc +++ b/source/blender/blenkernel/intern/subdiv_foreach.cc @@ -67,9 +67,9 @@ BLI_INLINE int ptex_face_resolution_get(const MPoly *poly, int resolution) struct SubdivForeachTaskContext { const Mesh *coarse_mesh; - const MEdge *coarse_edges; - const MPoly *coarse_polys; - const MLoop *coarse_loops; + blender::Span coarse_edges; + blender::Span coarse_polys; + blender::Span coarse_loops; const SubdivToMeshSettings *settings; /* Callbacks. */ const SubdivForeachContext *foreach_context; @@ -300,7 +300,7 @@ static void subdiv_foreach_corner_vertices_regular_do( bool check_usage) { const float weights[4][2] = {{0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}}; - const int coarse_poly_index = coarse_poly - ctx->coarse_polys; + const int coarse_poly_index = coarse_poly - ctx->coarse_polys.data(); const int ptex_face_index = ctx->face_ptex_offset[coarse_poly_index]; for (int corner = 0; corner < coarse_poly->totloop; corner++) { const MLoop *coarse_loop = &ctx->coarse_loops[coarse_poly->loopstart + corner]; @@ -339,7 +339,7 @@ static void subdiv_foreach_corner_vertices_special_do( SubdivForeachVertexFromCornerCb vertex_corner, bool check_usage) { - const int coarse_poly_index = coarse_poly - ctx->coarse_polys; + const int coarse_poly_index = coarse_poly - ctx->coarse_polys.data(); int ptex_face_index = ctx->face_ptex_offset[coarse_poly_index]; for (int corner = 0; corner < coarse_poly->totloop; corner++, ptex_face_index++) { const MLoop *coarse_loop = &ctx->coarse_loops[coarse_poly->loopstart + corner]; @@ -426,7 +426,7 @@ static void subdiv_foreach_edge_vertices_regular_do(SubdivForeachTaskContext *ct const int resolution_1 = resolution - 1; const float inv_resolution_1 = 1.0f / float(resolution_1); const int num_subdiv_vertices_per_coarse_edge = resolution - 2; - const int coarse_poly_index = coarse_poly - ctx->coarse_polys; + const int coarse_poly_index = coarse_poly - ctx->coarse_polys.data(); const int ptex_face_index = ctx->face_ptex_offset[coarse_poly_index]; for (int corner = 0; corner < coarse_poly->totloop; corner++) { const MLoop *coarse_loop = &ctx->coarse_loops[coarse_poly->loopstart + corner]; @@ -488,7 +488,7 @@ static void subdiv_foreach_edge_vertices_special_do(SubdivForeachTaskContext *ct const int num_subdiv_vertices_per_coarse_edge = resolution - 2; const int num_vertices_per_ptex_edge = ((resolution >> 1) + 1); const float inv_ptex_resolution_1 = 1.0f / float(num_vertices_per_ptex_edge - 1); - const int coarse_poly_index = coarse_poly - ctx->coarse_polys; + const int coarse_poly_index = coarse_poly - ctx->coarse_polys.data(); const int ptex_face_start_index = ctx->face_ptex_offset[coarse_poly_index]; int ptex_face_index = ptex_face_start_index; for (int corner = 0; corner < coarse_poly->totloop; corner++, ptex_face_index++) { @@ -599,7 +599,7 @@ static void subdiv_foreach_inner_vertices_regular(SubdivForeachTaskContext *ctx, { const int resolution = ctx->settings->resolution; const float inv_resolution_1 = 1.0f / float(resolution - 1); - const int coarse_poly_index = coarse_poly - ctx->coarse_polys; + const int coarse_poly_index = coarse_poly - ctx->coarse_polys.data(); const int ptex_face_index = ctx->face_ptex_offset[coarse_poly_index]; const int start_vertex_index = ctx->subdiv_vertex_offset[coarse_poly_index]; int subdiv_vertex_index = ctx->vertices_inner_offset + start_vertex_index; @@ -626,7 +626,7 @@ static void subdiv_foreach_inner_vertices_special(SubdivForeachTaskContext *ctx, const int resolution = ctx->settings->resolution; const int ptex_face_resolution = ptex_face_resolution_get(coarse_poly, resolution); const float inv_ptex_face_resolution_1 = 1.0f / float(ptex_face_resolution - 1); - const int coarse_poly_index = coarse_poly - ctx->coarse_polys; + const int coarse_poly_index = coarse_poly - ctx->coarse_polys.data(); int ptex_face_index = ctx->face_ptex_offset[coarse_poly_index]; const int start_vertex_index = ctx->subdiv_vertex_offset[coarse_poly_index]; int subdiv_vertex_index = ctx->vertices_inner_offset + start_vertex_index; @@ -753,7 +753,7 @@ static void subdiv_foreach_edges_all_patches_regular(SubdivForeachTaskContext *c void *tls, const MPoly *coarse_poly) { - const int poly_index = coarse_poly - ctx->coarse_polys; + const int poly_index = coarse_poly - ctx->coarse_polys.data(); const int resolution = ctx->settings->resolution; const int start_vertex_index = ctx->vertices_inner_offset + ctx->subdiv_vertex_offset[poly_index]; @@ -830,7 +830,7 @@ static void subdiv_foreach_edges_all_patches_special(SubdivForeachTaskContext *c void *tls, const MPoly *coarse_poly) { - const int poly_index = coarse_poly - ctx->coarse_polys; + const int poly_index = coarse_poly - ctx->coarse_polys.data(); const int resolution = ctx->settings->resolution; const int ptex_face_resolution = ptex_face_resolution_get(coarse_poly, resolution); const int ptex_face_inner_resolution = ptex_face_resolution - 2; @@ -1091,7 +1091,7 @@ static void subdiv_foreach_loops_regular(SubdivForeachTaskContext *ctx, { const int resolution = ctx->settings->resolution; /* Base/coarse mesh information. */ - const int coarse_poly_index = coarse_poly - ctx->coarse_polys; + const int coarse_poly_index = coarse_poly - ctx->coarse_polys.data(); const int ptex_resolution = ptex_face_resolution_get(coarse_poly, resolution); const int ptex_inner_resolution = ptex_resolution - 2; const int num_subdiv_edges_per_coarse_edge = resolution - 1; @@ -1282,7 +1282,7 @@ static void subdiv_foreach_loops_special(SubdivForeachTaskContext *ctx, { const int resolution = ctx->settings->resolution; /* Base/coarse mesh information. */ - const int coarse_poly_index = coarse_poly - ctx->coarse_polys; + const int coarse_poly_index = coarse_poly - ctx->coarse_polys.data(); const int ptex_face_resolution = ptex_face_resolution_get(coarse_poly, resolution); const int ptex_face_inner_resolution = ptex_face_resolution - 2; const float inv_ptex_resolution_1 = 1.0f / float(ptex_face_resolution - 1); @@ -1808,9 +1808,9 @@ bool BKE_subdiv_foreach_subdiv_geometry(Subdiv *subdiv, { SubdivForeachTaskContext ctx = {0}; ctx.coarse_mesh = coarse_mesh; - ctx.coarse_edges = BKE_mesh_edges(coarse_mesh); - ctx.coarse_polys = BKE_mesh_polys(coarse_mesh); - ctx.coarse_loops = BKE_mesh_loops(coarse_mesh); + ctx.coarse_edges = coarse_mesh->edges(); + ctx.coarse_polys = coarse_mesh->polys(); + ctx.coarse_loops = coarse_mesh->loops(); ctx.settings = mesh_settings; ctx.foreach_context = context; subdiv_foreach_ctx_init(subdiv, &ctx); diff --git a/source/blender/blenkernel/intern/subdiv_mesh.cc b/source/blender/blenkernel/intern/subdiv_mesh.cc index ee9e02883c6..727772a20f0 100644 --- a/source/blender/blenkernel/intern/subdiv_mesh.cc +++ b/source/blender/blenkernel/intern/subdiv_mesh.cc @@ -41,16 +41,16 @@ struct SubdivMeshContext { const SubdivToMeshSettings *settings; const Mesh *coarse_mesh; const float (*coarse_positions)[3]; - const MEdge *coarse_edges; - const MPoly *coarse_polys; - const MLoop *coarse_loops; + blender::Span coarse_edges; + blender::Span coarse_polys; + blender::Span coarse_loops; Subdiv *subdiv; Mesh *subdiv_mesh; - float3 *subdiv_positions; - MEdge *subdiv_edges; - MPoly *subdiv_polys; - MLoop *subdiv_loops; + blender::MutableSpan subdiv_positions; + blender::MutableSpan subdiv_edges; + blender::MutableSpan subdiv_polys; + blender::MutableSpan subdiv_loops; /* Cached custom data arrays for faster access. */ int *vert_origindex; @@ -87,10 +87,10 @@ static void subdiv_mesh_ctx_cache_uv_layers(SubdivMeshContext *ctx) static void subdiv_mesh_ctx_cache_custom_data_layers(SubdivMeshContext *ctx) { Mesh *subdiv_mesh = ctx->subdiv_mesh; - ctx->subdiv_positions = subdiv_mesh->vert_positions_for_write().data(); - ctx->subdiv_edges = BKE_mesh_edges_for_write(subdiv_mesh); - ctx->subdiv_polys = BKE_mesh_polys_for_write(subdiv_mesh); - ctx->subdiv_loops = BKE_mesh_loops_for_write(subdiv_mesh); + ctx->subdiv_positions = subdiv_mesh->vert_positions_for_write(); + ctx->subdiv_edges = subdiv_mesh->edges_for_write(); + ctx->subdiv_polys = subdiv_mesh->polys_for_write(); + ctx->subdiv_loops = subdiv_mesh->loops_for_write(); /* Pointers to original indices layers. */ ctx->vert_origindex = static_cast( CustomData_get_layer_for_write(&subdiv_mesh->vdata, CD_ORIGINDEX, subdiv_mesh->totvert)); @@ -146,7 +146,6 @@ static void loops_of_ptex_get(const SubdivMeshContext *ctx, const MPoly *coarse_poly, const int ptex_of_poly_index) { - const MLoop *coarse_mloop = ctx->coarse_loops; const int first_ptex_loop_index = coarse_poly->loopstart + ptex_of_poly_index; /* Loop which look in the (opposite) V direction of the current * ptex face. @@ -155,8 +154,8 @@ static void loops_of_ptex_get(const SubdivMeshContext *ctx, const int last_ptex_loop_index = coarse_poly->loopstart + (ptex_of_poly_index + coarse_poly->totloop - 1) % coarse_poly->totloop; - loops_of_ptex->first_loop = &coarse_mloop[first_ptex_loop_index]; - loops_of_ptex->last_loop = &coarse_mloop[last_ptex_loop_index]; + loops_of_ptex->first_loop = &ctx->coarse_loops[first_ptex_loop_index]; + loops_of_ptex->last_loop = &ctx->coarse_loops[last_ptex_loop_index]; if (coarse_poly->totloop == 4) { loops_of_ptex->second_loop = loops_of_ptex->first_loop + 1; loops_of_ptex->third_loop = loops_of_ptex->first_loop + 2; @@ -202,13 +201,13 @@ static void vertex_interpolation_init(const SubdivMeshContext *ctx, const MPoly *coarse_poly) { const Mesh *coarse_mesh = ctx->coarse_mesh; - const MLoop *coarse_mloop = ctx->coarse_loops; + const blender::Span coarse_loops = ctx->coarse_loops; if (coarse_poly->totloop == 4) { vertex_interpolation->vertex_data = &coarse_mesh->vdata; - vertex_interpolation->vertex_indices[0] = coarse_mloop[coarse_poly->loopstart + 0].v; - vertex_interpolation->vertex_indices[1] = coarse_mloop[coarse_poly->loopstart + 1].v; - vertex_interpolation->vertex_indices[2] = coarse_mloop[coarse_poly->loopstart + 2].v; - vertex_interpolation->vertex_indices[3] = coarse_mloop[coarse_poly->loopstart + 3].v; + vertex_interpolation->vertex_indices[0] = coarse_loops[coarse_poly->loopstart + 0].v; + vertex_interpolation->vertex_indices[1] = coarse_loops[coarse_poly->loopstart + 1].v; + vertex_interpolation->vertex_indices[2] = coarse_loops[coarse_poly->loopstart + 2].v; + vertex_interpolation->vertex_indices[3] = coarse_loops[coarse_poly->loopstart + 3].v; vertex_interpolation->vertex_data_storage_allocated = false; } else { @@ -232,7 +231,7 @@ static void vertex_interpolation_init(const SubdivMeshContext *ctx, blender::Array indices(coarse_poly->totloop); for (int i = 0; i < coarse_poly->totloop; i++) { weights[i] = weight; - indices[i] = coarse_mloop[coarse_poly->loopstart + i].v; + indices[i] = coarse_loops[coarse_poly->loopstart + i].v; } CustomData_interp(&coarse_mesh->vdata, &vertex_interpolation->vertex_data_storage, @@ -254,13 +253,13 @@ static void vertex_interpolation_from_corner(const SubdivMeshContext *ctx, } else { const CustomData *vertex_data = &ctx->coarse_mesh->vdata; - const MLoop *coarse_mloop = ctx->coarse_loops; + const blender::Span coarse_loops = ctx->coarse_loops; LoopsOfPtex loops_of_ptex; loops_of_ptex_get(ctx, &loops_of_ptex, coarse_poly, corner); /* Ptex face corner corresponds to a poly loop with same index. */ CustomData_copy_data(vertex_data, &vertex_interpolation->vertex_data_storage, - coarse_mloop[coarse_poly->loopstart + corner].v, + coarse_loops[coarse_poly->loopstart + corner].v, 0, 1); /* Interpolate remaining ptex face corners, which hits loops @@ -269,16 +268,16 @@ static void vertex_interpolation_from_corner(const SubdivMeshContext *ctx, * TODO(sergey): Re-use one of interpolation results from previous * iteration. */ const float weights[2] = {0.5f, 0.5f}; - const int first_loop_index = loops_of_ptex.first_loop - coarse_mloop; - const int last_loop_index = loops_of_ptex.last_loop - coarse_mloop; + const int first_loop_index = loops_of_ptex.first_loop - coarse_loops.data(); + const int last_loop_index = loops_of_ptex.last_loop - coarse_loops.data(); const int first_indices[2] = { - int(coarse_mloop[first_loop_index].v), - int(coarse_mloop[coarse_poly->loopstart + + int(coarse_loops[first_loop_index].v), + int(coarse_loops[coarse_poly->loopstart + (first_loop_index - coarse_poly->loopstart + 1) % coarse_poly->totloop] .v)}; const int last_indices[2] = { - int(coarse_mloop[first_loop_index].v), - int(coarse_mloop[last_loop_index].v), + int(coarse_loops[first_loop_index].v), + int(coarse_loops[last_loop_index].v), }; CustomData_interp(vertex_data, &vertex_interpolation->vertex_data_storage, @@ -387,7 +386,7 @@ static void loop_interpolation_from_corner(const SubdivMeshContext *ctx, } else { const CustomData *loop_data = &ctx->coarse_mesh->ldata; - const MLoop *coarse_mloop = ctx->coarse_loops; + const blender::Span coarse_loops = ctx->coarse_loops; LoopsOfPtex loops_of_ptex; loops_of_ptex_get(ctx, &loops_of_ptex, coarse_poly, corner); /* Ptex face corner corresponds to a poly loop with same index. */ @@ -401,13 +400,13 @@ static void loop_interpolation_from_corner(const SubdivMeshContext *ctx, * iteration. */ const float weights[2] = {0.5f, 0.5f}; const int base_loop_index = coarse_poly->loopstart; - const int first_loop_index = loops_of_ptex.first_loop - coarse_mloop; + const int first_loop_index = loops_of_ptex.first_loop - coarse_loops.data(); const int second_loop_index = base_loop_index + (first_loop_index - base_loop_index + 1) % coarse_poly->totloop; const int first_indices[2] = {first_loop_index, second_loop_index}; const int last_indices[2] = { - int(loops_of_ptex.last_loop - coarse_mloop), - int(loops_of_ptex.first_loop - coarse_mloop), + int(loops_of_ptex.last_loop - coarse_loops.data()), + int(loops_of_ptex.first_loop - coarse_loops.data()), }; CustomData_interp( loop_data, &loop_interpolation->loop_data_storage, first_indices, weights, nullptr, 2, 1); @@ -813,11 +812,9 @@ static void subdiv_mesh_edge(const SubdivForeachContext *foreach_context, const int subdiv_v2) { SubdivMeshContext *ctx = static_cast(foreach_context->user_data); - MEdge *subdiv_medge = ctx->subdiv_edges; - MEdge *subdiv_edge = &subdiv_medge[subdiv_edge_index]; subdiv_copy_edge_data(ctx, subdiv_edge_index, coarse_edge_index); - subdiv_edge->v1 = subdiv_v1; - subdiv_edge->v2 = subdiv_v2; + ctx->subdiv_edges[subdiv_edge_index].v1 = subdiv_v1; + ctx->subdiv_edges[subdiv_edge_index].v2 = subdiv_v2; } /** \} */ @@ -832,7 +829,7 @@ static void subdiv_interpolate_loop_data(const SubdivMeshContext *ctx, const float u, const float v) { - const int subdiv_loop_index = subdiv_loop - ctx->subdiv_loops; + const int subdiv_loop_index = subdiv_loop - ctx->subdiv_loops.data(); const float weights[4] = {(1.0f - u) * (1.0f - v), u * (1.0f - v), u * v, (1.0f - u) * v}; CustomData_interp(loop_interpolation->loop_data, &ctx->subdiv_mesh->ldata, @@ -854,7 +851,7 @@ static void subdiv_eval_uv_layer(SubdivMeshContext *ctx, return; } Subdiv *subdiv = ctx->subdiv; - const int mloop_index = subdiv_loop - ctx->subdiv_loops; + const int mloop_index = subdiv_loop - ctx->subdiv_loops.data(); for (int layer_index = 0; layer_index < ctx->num_uv_layers; layer_index++) { BKE_subdiv_eval_face_varying( subdiv, layer_index, ptex_face_index, u, v, ctx->uv_layers[layer_index][mloop_index]); @@ -903,8 +900,7 @@ static void subdiv_mesh_loop(const SubdivForeachContext *foreach_context, { SubdivMeshContext *ctx = static_cast(foreach_context->user_data); SubdivMeshTLS *tls = static_cast(tls_v); - const MPoly *coarse_mpoly = ctx->coarse_polys; - const MPoly *coarse_poly = &coarse_mpoly[coarse_poly_index]; + const MPoly *coarse_poly = &ctx->coarse_polys[coarse_poly_index]; MLoop *subdiv_loop = &ctx->subdiv_loops[subdiv_loop_index]; subdiv_mesh_ensure_loop_interpolation(ctx, tls, coarse_poly, coarse_corner); subdiv_interpolate_loop_data(ctx, subdiv_loop, &tls->loop_interpolation, u, v); @@ -923,8 +919,8 @@ static void subdiv_copy_poly_data(const SubdivMeshContext *ctx, MPoly *subdiv_poly, const MPoly *coarse_poly) { - const int coarse_poly_index = coarse_poly - ctx->coarse_polys; - const int subdiv_poly_index = subdiv_poly - ctx->subdiv_polys; + const int coarse_poly_index = coarse_poly - ctx->coarse_polys.data(); + const int subdiv_poly_index = subdiv_poly - ctx->subdiv_polys.data(); CustomData_copy_data( &ctx->coarse_mesh->pdata, &ctx->subdiv_mesh->pdata, coarse_poly_index, subdiv_poly_index, 1); } @@ -1103,7 +1099,7 @@ static void subdiv_mesh_vertex_of_loose_edge(const SubdivForeachContext *foreach if (ctx->vert_to_edge_map == nullptr) { BKE_mesh_vert_edge_map_create(&ctx->vert_to_edge_map, &ctx->vert_to_edge_buffer, - ctx->coarse_edges, + ctx->coarse_edges.data(), coarse_mesh->totvert, ctx->coarse_mesh->totedge); } @@ -1116,7 +1112,7 @@ static void subdiv_mesh_vertex_of_loose_edge(const SubdivForeachContext *foreach } /* Interpolate coordinate. */ BKE_subdiv_mesh_interpolate_position_on_edge(ctx->coarse_positions, - ctx->coarse_edges, + ctx->coarse_edges.data(), ctx->vert_to_edge_map, coarse_edge_index, is_simple, @@ -1183,9 +1179,9 @@ Mesh *BKE_subdiv_to_mesh(Subdiv *subdiv, subdiv_context.coarse_mesh = coarse_mesh; subdiv_context.coarse_positions = BKE_mesh_vert_positions(coarse_mesh); - subdiv_context.coarse_edges = BKE_mesh_edges(coarse_mesh); - subdiv_context.coarse_polys = BKE_mesh_polys(coarse_mesh); - subdiv_context.coarse_loops = BKE_mesh_loops(coarse_mesh); + subdiv_context.coarse_edges = coarse_mesh->edges(); + subdiv_context.coarse_polys = coarse_mesh->polys(); + subdiv_context.coarse_loops = coarse_mesh->loops(); subdiv_context.subdiv = subdiv; subdiv_context.have_displacement = (subdiv->displacement_evaluator != nullptr); diff --git a/source/blender/blenloader/intern/versioning_290.cc b/source/blender/blenloader/intern/versioning_290.cc index b90e7529bbc..580a1437c16 100644 --- a/source/blender/blenloader/intern/versioning_290.cc +++ b/source/blender/blenloader/intern/versioning_290.cc @@ -816,20 +816,21 @@ void blo_do_versions_290(FileData *fd, Library * /*lib*/, Main *bmain) if (MAIN_VERSION_ATLEAST(bmain, 290, 2) && MAIN_VERSION_OLDER(bmain, 291, 1)) { /* In this range, the extrude manifold could generate meshes with degenerated face. */ LISTBASE_FOREACH (Mesh *, me, &bmain->meshes) { - for (const MPoly *mp = BKE_mesh_polys(me), *mp_end = mp + me->totpoly; mp < mp_end; mp++) { - if (mp->totloop == 2) { + blender::MutableSpan polys = me->polys_for_write(); + for (const int i : polys.index_range()) { + if (polys[i].totloop == 2) { bool changed; BKE_mesh_validate_arrays( me, BKE_mesh_vert_positions_for_write(me), me->totvert, - BKE_mesh_edges_for_write(me), + me->edges_for_write().data(), me->totedge, (MFace *)CustomData_get_layer_for_write(&me->fdata, CD_MFACE, me->totface), me->totface, BKE_mesh_loops_for_write(me), - me->totloop, - BKE_mesh_polys_for_write(me), + polys.size(), + polys.data(), me->totpoly, BKE_mesh_deform_verts_for_write(me), false, diff --git a/source/blender/draw/intern/draw_cache_extract_mesh_render_data.cc b/source/blender/draw/intern/draw_cache_extract_mesh_render_data.cc index 0937e9feb54..b83297307ae 100644 --- a/source/blender/draw/intern/draw_cache_extract_mesh_render_data.cc +++ b/source/blender/draw/intern/draw_cache_extract_mesh_render_data.cc @@ -546,9 +546,9 @@ MeshRenderData *mesh_render_data_create(Object *object, mr->tri_len = poly_to_tri_count(mr->poly_len, mr->loop_len); mr->vert_positions = mr->me->vert_positions().data(); - mr->medge = BKE_mesh_edges(mr->me); - mr->mpoly = BKE_mesh_polys(mr->me); - mr->mloop = BKE_mesh_loops(mr->me); + mr->medge = mr->me->edges().data(); + mr->mpoly = mr->me->polys().data(); + mr->mloop = mr->me->loops().data(); mr->v_origindex = static_cast(CustomData_get_layer(&mr->me->vdata, CD_ORIGINDEX)); mr->e_origindex = static_cast(CustomData_get_layer(&mr->me->edata, CD_ORIGINDEX)); diff --git a/source/blender/editors/armature/meshlaplacian.cc b/source/blender/editors/armature/meshlaplacian.cc index 7cd25577ad2..25af4ea10ee 100644 --- a/source/blender/editors/armature/meshlaplacian.cc +++ b/source/blender/editors/armature/meshlaplacian.cc @@ -74,7 +74,7 @@ struct LaplacianSystem { struct HeatWeighting { const MLoopTri *mlooptri; - const MLoop *mloop; /* needed to find vertices by index */ + blender::Span loops; /* needed to find vertices by index */ int verts_num; int tris_num; float (*verts)[3]; /* vertex coordinates */ @@ -205,7 +205,7 @@ static LaplacianSystem *laplacian_system_construct_begin(int verts_num, int face { LaplacianSystem *sys; - sys = MEM_cnew(__func__); + sys = MEM_new(__func__); sys->verts = static_cast( MEM_callocN(sizeof(float *) * verts_num, "LaplacianSystemVerts")); @@ -323,7 +323,7 @@ static void laplacian_system_delete(LaplacianSystem *sys) } EIG_linear_solver_delete(sys->context); - MEM_freeN(sys); + MEM_delete(sys); } void laplacian_begin_solve(LaplacianSystem *sys, int index) @@ -382,14 +382,14 @@ static void bvh_callback(void *userdata, int index, const BVHTreeRay *ray, BVHTr { BVHCallbackUserData *data = (struct BVHCallbackUserData *)userdata; const MLoopTri *lt = &data->sys->heat.mlooptri[index]; - const MLoop *mloop = data->sys->heat.mloop; + const blender::Span loops = data->sys->heat.loops; float(*verts)[3] = data->sys->heat.verts; const float *vtri_co[3]; float dist_test; - vtri_co[0] = verts[mloop[lt->tri[0]].v]; - vtri_co[1] = verts[mloop[lt->tri[1]].v]; - vtri_co[2] = verts[mloop[lt->tri[2]].v]; + vtri_co[0] = verts[loops[lt->tri[0]].v]; + vtri_co[1] = verts[loops[lt->tri[1]].v]; + vtri_co[2] = verts[loops[lt->tri[2]].v]; #ifdef USE_KDOPBVH_WATERTIGHT if (isect_ray_tri_watertight_v3( @@ -414,7 +414,7 @@ static void bvh_callback(void *userdata, int index, const BVHTreeRay *ray, BVHTr static void heat_ray_tree_create(LaplacianSystem *sys) { const MLoopTri *looptri = sys->heat.mlooptri; - const MLoop *mloop = sys->heat.mloop; + const blender::Span loops = sys->heat.loops; float(*verts)[3] = sys->heat.verts; int tris_num = sys->heat.tris_num; int verts_num = sys->heat.verts_num; @@ -429,9 +429,9 @@ static void heat_ray_tree_create(LaplacianSystem *sys) float bb[6]; int vtri[3]; - vtri[0] = mloop[lt->tri[0]].v; - vtri[1] = mloop[lt->tri[1]].v; - vtri[2] = mloop[lt->tri[2]].v; + vtri[0] = loops[lt->tri[0]].v; + vtri[1] = loops[lt->tri[1]].v; + vtri[2] = loops[lt->tri[2]].v; INIT_MINMAX(bb, bb + 3); minmax_v3v3_v3(bb, bb + 3, verts[vtri[0]]); @@ -581,7 +581,7 @@ static void heat_calc_vnormals(LaplacianSystem *sys) static void heat_laplacian_create(LaplacianSystem *sys) { const MLoopTri *mlooptri = sys->heat.mlooptri, *lt; - const MLoop *mloop = sys->heat.mloop; + const blender::Span loops = sys->heat.loops; int tris_num = sys->heat.tris_num; int verts_num = sys->heat.verts_num; int a; @@ -598,9 +598,9 @@ static void heat_laplacian_create(LaplacianSystem *sys) for (a = 0, lt = mlooptri; a < tris_num; a++, lt++) { int vtri[3]; - vtri[0] = mloop[lt->tri[0]].v; - vtri[1] = mloop[lt->tri[1]].v; - vtri[2] = mloop[lt->tri[2]].v; + vtri[0] = loops[lt->tri[0]].v; + vtri[1] = loops[lt->tri[1]].v; + vtri[2] = loops[lt->tri[2]].v; laplacian_add_triangle(sys, UNPACK3(vtri)); } @@ -651,16 +651,14 @@ void heat_bone_weighting(Object *ob, { LaplacianSystem *sys; MLoopTri *mlooptri; - const MPoly *mp; - const MLoop *ml; float solution, weight; int *vertsflipped = nullptr, *mask = nullptr; int a, tris_num, j, bbone, firstsegment, lastsegment; bool use_topology = (me->editflag & ME_EDIT_MIRROR_TOPO) != 0; const float(*vert_positions)[3] = BKE_mesh_vert_positions(me); - const MPoly *polys = BKE_mesh_polys(me); - const MLoop *loops = BKE_mesh_loops(me); + const blender::Span polys = me->polys(); + const blender::Span loops = me->loops(); bool use_vert_sel = (me->editflag & ME_EDIT_PAINT_VERT_SEL) != 0; bool use_face_sel = (me->editflag & ME_EDIT_PAINT_FACE_SEL) != 0; @@ -678,9 +676,9 @@ void heat_bone_weighting(Object *ob, const bool *select_vert = (const bool *)CustomData_get_layer_named( &me->vdata, CD_PROP_BOOL, ".select_vert"); if (select_vert) { - for (a = 0, mp = polys; a < me->totpoly; mp++, a++) { - for (j = 0, ml = loops + mp->loopstart; j < mp->totloop; j++, ml++) { - mask[ml->v] = select_vert[ml->v]; + for (const int i : polys.index_range()) { + for (const MLoop &loop : loops.slice(polys[i].loopstart, polys[i].totloop)) { + mask[loop.v] = select_vert[loop.v]; } } } @@ -689,10 +687,10 @@ void heat_bone_weighting(Object *ob, const bool *select_poly = (const bool *)CustomData_get_layer_named( &me->pdata, CD_PROP_BOOL, ".select_poly"); if (select_poly) { - for (a = 0, mp = polys; a < me->totpoly; mp++, a++) { - if (select_poly[a]) { - for (j = 0, ml = loops + mp->loopstart; j < mp->totloop; j++, ml++) { - mask[ml->v] = 1; + for (const int i : polys.index_range()) { + if (select_poly[i]) { + for (const MLoop &loop : loops.slice(polys[i].loopstart, polys[i].totloop)) { + mask[loop.v] = 1; } } } @@ -707,10 +705,11 @@ void heat_bone_weighting(Object *ob, mlooptri = static_cast( MEM_mallocN(sizeof(*sys->heat.mlooptri) * sys->heat.tris_num, __func__)); - BKE_mesh_recalc_looptri(loops, polys, vert_positions, me->totloop, me->totpoly, mlooptri); + BKE_mesh_recalc_looptri( + loops.data(), polys.data(), vert_positions, me->totloop, me->totpoly, mlooptri); sys->heat.mlooptri = mlooptri; - sys->heat.mloop = loops; + sys->heat.loops = loops; sys->heat.verts_num = me->totvert; sys->heat.verts = verts; sys->heat.root = root; @@ -927,8 +926,8 @@ typedef struct MeshDeformBind { /* avoid DM function calls during intersections */ struct { - const MPoly *mpoly; - const MLoop *mloop; + blender::Span polys; + blender::Span loops; const MLoopTri *looptri; const float (*poly_nors)[3]; } cagemesh_cache; @@ -959,7 +958,7 @@ static void harmonic_ray_callback(void *userdata, { MeshRayCallbackData *data = static_cast(userdata); MeshDeformBind *mdb = data->mdb; - const MLoop *mloop = mdb->cagemesh_cache.mloop; + const blender::Span loops = mdb->cagemesh_cache.loops; const MLoopTri *looptri = mdb->cagemesh_cache.looptri, *lt; const float(*poly_nors)[3] = mdb->cagemesh_cache.poly_nors; MeshDeformIsect *isec = data->isec; @@ -968,9 +967,9 @@ static void harmonic_ray_callback(void *userdata, lt = &looptri[index]; - face[0] = mdb->cagecos[mloop[lt->tri[0]].v]; - face[1] = mdb->cagecos[mloop[lt->tri[1]].v]; - face[2] = mdb->cagecos[mloop[lt->tri[2]].v]; + face[0] = mdb->cagecos[loops[lt->tri[0]].v]; + face[1] = mdb->cagecos[loops[lt->tri[1]].v]; + face[2] = mdb->cagecos[loops[lt->tri[2]].v]; bool isect_ray_tri = isect_ray_tri_watertight_v3( ray->origin, ray->isect_precalc, UNPACK3(face), &dist, nullptr); @@ -1034,9 +1033,9 @@ static MDefBoundIsect *meshdeform_ray_tree_intersect(MeshDeformBind *mdb, harmonic_ray_callback, &data, BVH_RAYCAST_WATERTIGHT) != -1) { - const MLoop *mloop = mdb->cagemesh_cache.mloop; + const blender::Span loops = mdb->cagemesh_cache.loops; const MLoopTri *lt = &mdb->cagemesh_cache.looptri[hit.index]; - const MPoly *mp = &mdb->cagemesh_cache.mpoly[lt->poly]; + const MPoly *mp = &mdb->cagemesh_cache.polys[lt->poly]; const float(*cagecos)[3] = mdb->cagecos; const float len = isect_mdef.lambda; MDefBoundIsect *isect; @@ -1058,7 +1057,7 @@ static MDefBoundIsect *meshdeform_ray_tree_intersect(MeshDeformBind *mdb, /* compute mean value coordinates for interpolation */ for (int i = 0; i < mp->totloop; i++) { - copy_v3_v3(mp_cagecos[i], cagecos[mloop[mp->loopstart + i].v]); + copy_v3_v3(mp_cagecos[i], cagecos[loops[mp->loopstart + i].v]); } interp_weights_poly_v3(isect->poly_weights, @@ -1227,11 +1226,11 @@ static float meshdeform_boundary_phi(const MeshDeformBind *mdb, const MDefBoundIsect *isect, int cagevert) { - const MLoop *mloop = mdb->cagemesh_cache.mloop; - const MPoly *mp = &mdb->cagemesh_cache.mpoly[isect->poly_index]; + const blender::Span loops = mdb->cagemesh_cache.loops; + const MPoly *mp = &mdb->cagemesh_cache.polys[isect->poly_index]; for (int i = 0; i < mp->totloop; i++) { - if (mloop[mp->loopstart + i].v == cagevert) { + if (loops[mp->loopstart + i].v == cagevert) { return isect->poly_weights[i]; } } @@ -1631,8 +1630,8 @@ static void harmonic_coordinates_bind(MeshDeformModifierData *mmd, MeshDeformBin /* initialize data from 'cagedm' for reuse */ { Mesh *me = mdb->cagemesh; - mdb->cagemesh_cache.mpoly = BKE_mesh_polys(me); - mdb->cagemesh_cache.mloop = BKE_mesh_loops(me); + mdb->cagemesh_cache.polys = me->polys(); + mdb->cagemesh_cache.loops = me->loops(); mdb->cagemesh_cache.looptri = BKE_mesh_runtime_looptri_ensure(me); mdb->cagemesh_cache.poly_nors = BKE_mesh_poly_normals_ensure(me); } @@ -1769,14 +1768,12 @@ void ED_mesh_deform_bind_callback(Object *object, { MeshDeformModifierData *mmd_orig = (MeshDeformModifierData *)BKE_modifier_get_original( object, &mmd->modifier); - MeshDeformBind mdb; + MeshDeformBind mdb{}; int a; waitcursor(1); start_progress_bar(); - memset(&mdb, 0, sizeof(MeshDeformBind)); - /* No need to support other kinds of mesh data as binding is a one-off action. */ BKE_mesh_wrapper_ensure_mdata(cagemesh); diff --git a/source/blender/editors/mesh/mesh_data.cc b/source/blender/editors/mesh/mesh_data.cc index 113848e5cce..245fd151772 100644 --- a/source/blender/editors/mesh/mesh_data.cc +++ b/source/blender/editors/mesh/mesh_data.cc @@ -208,8 +208,8 @@ void ED_mesh_uv_loop_reset_ex(Mesh *me, const int layernum) float2 *mloopuv = static_cast( CustomData_get_layer_n_for_write(&me->ldata, CD_PROP_FLOAT2, layernum, me->totloop)); - const MPoly *polys = BKE_mesh_polys(me); - for (int i = 0; i < me->totpoly; i++) { + const blender::Span polys = me->polys(); + for (const int i : polys.index_range()) { mesh_uv_reset_mface(&polys[i], mloopuv); } } diff --git a/source/blender/editors/object/object_bake_api.cc b/source/blender/editors/object/object_bake_api.cc index d3b8e0e0eed..2a3b64ccd0a 100644 --- a/source/blender/editors/object/object_bake_api.cc +++ b/source/blender/editors/object/object_bake_api.cc @@ -978,8 +978,8 @@ static bool bake_targets_init_vertex_colors(Main *bmain, return true; } -static int find_original_loop(const MPoly *orig_polys, - const MLoop *orig_loops, +static int find_original_loop(const blender::Span orig_polys, + const blender::Span orig_loops, const int *vert_origindex, const int *poly_origindex, const int poly_eval, @@ -995,8 +995,8 @@ static int find_original_loop(const MPoly *orig_polys, } /* Find matching loop with original vertex in original polygon. */ - const MPoly *mpoly_orig = orig_polys + poly_orig; - const MLoop *mloop_orig = orig_loops + mpoly_orig->loopstart; + const MPoly *mpoly_orig = &orig_polys[poly_orig]; + const MLoop *mloop_orig = &orig_loops[mpoly_orig->loopstart]; for (int j = 0; j < mpoly_orig->totloop; ++j, ++mloop_orig) { if (mloop_orig->v == vert_orig) { return mpoly_orig->loopstart + j; @@ -1033,9 +1033,9 @@ static void bake_targets_populate_pixels_color_attributes(BakeTargets *targets, const int tottri = poly_to_tri_count(me_eval->totpoly, me_eval->totloop); MLoopTri *looptri = static_cast(MEM_mallocN(sizeof(*looptri) * tottri, __func__)); - const MLoop *loops = BKE_mesh_loops(me_eval); - BKE_mesh_recalc_looptri(loops, - BKE_mesh_polys(me_eval), + const blender::Span loops = me_eval->loops(); + BKE_mesh_recalc_looptri(loops.data(), + me_eval->polys().data(), BKE_mesh_vert_positions(me_eval), me_eval->totloop, me_eval->totpoly, @@ -1046,8 +1046,8 @@ static void bake_targets_populate_pixels_color_attributes(BakeTargets *targets, CustomData_get_layer(&me_eval->vdata, CD_ORIGINDEX)); const int *poly_origindex = static_cast( CustomData_get_layer(&me_eval->pdata, CD_ORIGINDEX)); - const MPoly *orig_polys = BKE_mesh_polys(me); - const MLoop *orig_loops = BKE_mesh_loops(me); + const blender::Span orig_polys = me->polys(); + const blender::Span orig_loops = me->loops(); for (int i = 0; i < tottri; i++) { const MLoopTri *lt = &looptri[i]; @@ -1156,9 +1156,9 @@ static bool bake_targets_output_vertex_colors(BakeTargets *targets, Object *ob) MEM_callocN(sizeof(int) * me->totvert, "num_loops_for_vertex")); memset(mcol, 0, sizeof(MPropCol) * me->totvert); - const MLoop *mloop = BKE_mesh_loops(me); - for (int i = 0; i < totloop; i++, mloop++) { - const int v = mloop->v; + const blender::Span loops = me->loops(); + for (int i = 0; i < totloop; i++) { + const int v = loops[i].v; bake_result_add_to_rgba(mcol[v].color, &result[i * channels_num], channels_num); num_loops_for_vertex[v]++; } diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.cc b/source/blender/editors/sculpt_paint/paint_image_proj.cc index 1800f8f862b..04ea1d3f91f 100644 --- a/source/blender/editors/sculpt_paint/paint_image_proj.cc +++ b/source/blender/editors/sculpt_paint/paint_image_proj.cc @@ -414,17 +414,17 @@ struct ProjPaintState { const float (*vert_positions_eval)[3]; const float (*vert_normals)[3]; - const MEdge *medge_eval; - const MPoly *mpoly_eval; + blender::Span edges_eval; + blender::Span polys_eval; + blender::Span loops_eval; const bool *select_poly_eval; const int *material_indices; - const MLoop *mloop_eval; const MLoopTri *mlooptri_eval; const float (*mloopuv_stencil_eval)[2]; /** - * \note These UV layers are aligned to \a mpoly_eval + * \note These UV layers are aligned to \a polys_eval * but each pointer references the start of the layer, * so a loop indirection is needed as well. */ @@ -509,8 +509,8 @@ struct VertSeam { * \{ */ #define PS_LOOPTRI_AS_VERT_INDEX_3(ps, lt) \ - int(ps->mloop_eval[lt->tri[0]].v), int(ps->mloop_eval[lt->tri[1]].v), \ - int(ps->mloop_eval[lt->tri[2]].v), + int(ps->loops_eval[lt->tri[0]].v), int(ps->loops_eval[lt->tri[1]].v), \ + int(ps->loops_eval[lt->tri[2]].v), #define PS_LOOPTRI_AS_UV_3(uvlayer, lt) \ uvlayer[lt->poly][lt->tri[0]], uvlayer[lt->poly][lt->tri[1]], uvlayer[lt->poly][lt->tri[2]], @@ -675,9 +675,9 @@ static int project_paint_PickFace(const ProjPaintState *ps, const float pt[2], f const int tri_index = POINTER_AS_INT(node->link); const MLoopTri *lt = &ps->mlooptri_eval[tri_index]; const float *vtri_ss[3] = { - ps->screenCoords[ps->mloop_eval[lt->tri[0]].v], - ps->screenCoords[ps->mloop_eval[lt->tri[1]].v], - ps->screenCoords[ps->mloop_eval[lt->tri[2]].v], + ps->screenCoords[ps->loops_eval[lt->tri[0]].v], + ps->screenCoords[ps->loops_eval[lt->tri[1]].v], + ps->screenCoords[ps->loops_eval[lt->tri[2]].v], }; if (isect_point_tri_v2(pt, UNPACK3(vtri_ss))) { @@ -917,17 +917,17 @@ static bool project_bucket_point_occluded(const ProjPaintState *ps, if (orig_face != tri_index) { const MLoopTri *lt = &ps->mlooptri_eval[tri_index]; const float *vtri_ss[3] = { - ps->screenCoords[ps->mloop_eval[lt->tri[0]].v], - ps->screenCoords[ps->mloop_eval[lt->tri[1]].v], - ps->screenCoords[ps->mloop_eval[lt->tri[2]].v], + ps->screenCoords[ps->loops_eval[lt->tri[0]].v], + ps->screenCoords[ps->loops_eval[lt->tri[1]].v], + ps->screenCoords[ps->loops_eval[lt->tri[2]].v], }; float w[3]; if (do_clip) { const float *vtri_co[3] = { - ps->vert_positions_eval[ps->mloop_eval[lt->tri[0]].v], - ps->vert_positions_eval[ps->mloop_eval[lt->tri[1]].v], - ps->vert_positions_eval[ps->mloop_eval[lt->tri[2]].v], + ps->vert_positions_eval[ps->loops_eval[lt->tri[0]].v], + ps->vert_positions_eval[ps->loops_eval[lt->tri[1]].v], + ps->vert_positions_eval[ps->loops_eval[lt->tri[2]].v], }; isect_ret = project_paint_occlude_ptv_clip( pixelScreenCo, UNPACK3(vtri_ss), UNPACK3(vtri_co), w, ps->is_ortho, ps->rv3d); @@ -1144,8 +1144,8 @@ static bool check_seam(const ProjPaintState *ps, const MLoopTri *orig_lt = &ps->mlooptri_eval[orig_face]; const float *orig_lt_tri_uv[3] = {PS_LOOPTRI_AS_UV_3(ps->poly_to_loop_uv, orig_lt)}; /* vert indices from face vert order indices */ - const uint i1 = ps->mloop_eval[orig_lt->tri[orig_i1_fidx]].v; - const uint i2 = ps->mloop_eval[orig_lt->tri[orig_i2_fidx]].v; + const uint i1 = ps->loops_eval[orig_lt->tri[orig_i1_fidx]].v; + const uint i2 = ps->loops_eval[orig_lt->tri[orig_i2_fidx]].v; LinkNode *node; /* index in face */ int i1_fidx = -1, i2_fidx = -1; @@ -1330,8 +1330,8 @@ static void uv_image_outset(const ProjPaintState *ps, fidx[1] = (fidx[0] == 2) ? 0 : fidx[0] + 1; - vert[0] = ps->mloop_eval[loop_index].v; - vert[1] = ps->mloop_eval[ltri->tri[fidx[1]]].v; + vert[0] = ps->loops_eval[loop_index].v; + vert[1] = ps->loops_eval[ltri->tri[fidx[1]]].v; for (uint i = 0; i < 2; i++) { VertSeam *seam; @@ -1416,7 +1416,7 @@ static void insert_seam_vert_array(const ProjPaintState *ps, copy_v2_v2(vseam[1].uv, lt_tri_uv[fidx[1]]); for (uint i = 0; i < 2; i++) { - uint vert = ps->mloop_eval[lt->tri[fidx[i]]].v; + uint vert = ps->loops_eval[lt->tri[fidx[i]]].v; ListBase *list = &ps->vertSeams[vert]; VertSeam *item = static_cast(list->first); @@ -1455,8 +1455,8 @@ static void project_face_seams_init(const ProjPaintState *ps, } do { - if (init_all || (ps->mloop_eval[lt->tri[fidx[0]]].v == vert_index) || - (ps->mloop_eval[lt->tri[fidx[1]]].v == vert_index)) { + if (init_all || (ps->loops_eval[lt->tri[fidx[0]]].v == vert_index) || + (ps->loops_eval[lt->tri[fidx[1]]].v == vert_index)) { if ((ps->faceSeamFlags[tri_index] & (PROJ_FACE_SEAM0 << fidx[0] | PROJ_FACE_NOSEAM0 << fidx[0])) == 0) { if (check_seam(ps, tri_index, fidx[0], fidx[1], &other_face, &other_fidx)) { @@ -1503,7 +1503,7 @@ static void project_face_seams_init(const ProjPaintState *ps, continue; } - vert = ps->mloop_eval[lt->tri[fidx[i]]].v; + vert = ps->loops_eval[lt->tri[fidx[i]]].v; for (node = ps->vertFaces[vert]; node; node = node->next) { const int tri = POINTER_AS_INT(node->link); @@ -1721,7 +1721,7 @@ static float project_paint_uvpixel_mask(const ProjPaintState *ps, if (ps->do_mask_normal) { const MLoopTri *lt = &ps->mlooptri_eval[tri_index]; const int lt_vtri[3] = {PS_LOOPTRI_AS_VERT_INDEX_3(ps, lt)}; - const MPoly *mp = &ps->mpoly_eval[lt->poly]; + const MPoly *mp = &ps->polys_eval[lt->poly]; float no[3], angle_cos; if (mp->flag & ME_SMOOTH) { @@ -3878,7 +3878,6 @@ static void proj_paint_state_screen_coords_init(ProjPaintState *ps, const int di static void proj_paint_state_cavity_init(ProjPaintState *ps) { - const MEdge *me; float *cavities; int a; @@ -3890,14 +3889,15 @@ static void proj_paint_state_cavity_init(ProjPaintState *ps) MEM_mallocN(sizeof(float) * ps->totvert_eval, "ProjectPaint Cavities")); cavities = ps->cavities; - for (a = 0, me = ps->medge_eval; a < ps->totedge_eval; a++, me++) { + for (const int64_t i : ps->edges_eval.index_range()) { + const MEdge &edge = ps->edges_eval[i]; float e[3]; - sub_v3_v3v3(e, ps->vert_positions_eval[me->v1], ps->vert_positions_eval[me->v2]); + sub_v3_v3v3(e, ps->vert_positions_eval[edge.v1], ps->vert_positions_eval[edge.v2]); normalize_v3(e); - add_v3_v3(edges[me->v2], e); - counter[me->v2]++; - sub_v3_v3(edges[me->v1], e); - counter[me->v1]++; + add_v3_v3(edges[edge.v2], e); + counter[edge.v2]++; + sub_v3_v3(edges[edge.v1], e); + counter[edge.v1]++; } for (a = 0; a < ps->totvert_eval; a++) { if (counter[a] > 0) { @@ -4072,11 +4072,9 @@ static bool proj_paint_state_mesh_eval_init(const bContext *C, ProjPaintState *p ps->vert_positions_eval = BKE_mesh_vert_positions(ps->me_eval); ps->vert_normals = BKE_mesh_vertex_normals_ensure(ps->me_eval); - if (ps->do_mask_cavity) { - ps->medge_eval = BKE_mesh_edges(ps->me_eval); - } - ps->mloop_eval = BKE_mesh_loops(ps->me_eval); - ps->mpoly_eval = BKE_mesh_polys(ps->me_eval); + ps->edges_eval = ps->me_eval->edges(); + ps->polys_eval = ps->me_eval->polys(); + ps->loops_eval = ps->me_eval->loops(); ps->select_poly_eval = (const bool *)CustomData_get_layer_named( &ps->me_eval->pdata, CD_PROP_BOOL, ".select_poly"); ps->material_indices = (const int *)CustomData_get_layer_named( @@ -4391,11 +4389,11 @@ static void project_paint_prepare_all_faces(ProjPaintState *ps, if (prev_poly != lt->poly) { int iloop; bool culled = true; - const MPoly *poly = ps->mpoly_eval + lt->poly; + const MPoly *poly = &ps->polys_eval[lt->poly]; int poly_loops = poly->totloop; prev_poly = lt->poly; for (iloop = 0; iloop < poly_loops; iloop++) { - if (!(ps->vertFlags[ps->mloop_eval[poly->loopstart + iloop].v] & PROJ_VERT_CULL)) { + if (!(ps->vertFlags[ps->loops_eval[poly->loopstart + iloop].v] & PROJ_VERT_CULL)) { culled = false; break; } @@ -5954,7 +5952,7 @@ void *paint_proj_new_stroke(bContext *C, Object *ob, const float mouse[2], int m bool is_multi_view = (ps_handle->ps_views_tot != 1); for (int i = 0; i < ps_handle->ps_views_tot; i++) { - ProjPaintState *ps = MEM_cnew("ProjectionPaintState"); + ProjPaintState *ps = MEM_new("ProjectionPaintState"); ps_handle->ps_views[i] = ps; } @@ -6020,8 +6018,7 @@ void *paint_proj_new_stroke(bContext *C, Object *ob, const float mouse[2], int m fail: for (int i = 0; i < ps_handle->ps_views_tot; i++) { - ProjPaintState *ps = ps_handle->ps_views[i]; - MEM_freeN(ps); + MEM_delete(ps_handle->ps_views[i]); } MEM_freeN(ps_handle); return nullptr; diff --git a/source/blender/editors/sculpt_paint/paint_mask.cc b/source/blender/editors/sculpt_paint/paint_mask.cc index bde6e25dec2..ba2f734a490 100644 --- a/source/blender/editors/sculpt_paint/paint_mask.cc +++ b/source/blender/editors/sculpt_paint/paint_mask.cc @@ -1225,54 +1225,62 @@ static void sculpt_gesture_trim_geometry_generate(SculptGestureContext *sgcontex BLI_polyfill_calc(screen_points, tot_screen_points, 0, r_tris); /* Write the front face triangle indices. */ - MPoly *polys = BKE_mesh_polys_for_write(trim_operation->mesh); - MLoop *loops = BKE_mesh_loops_for_write(trim_operation->mesh); - MPoly *mp = polys; - MLoop *ml = loops; - for (int i = 0; i < tot_tris_face; i++, mp++, ml += 3) { - mp->loopstart = int(ml - loops); - mp->totloop = 3; - ml[0].v = r_tris[i][0]; - ml[1].v = r_tris[i][1]; - ml[2].v = r_tris[i][2]; + blender::MutableSpan polys = trim_operation->mesh->polys_for_write(); + blender::MutableSpan loops = trim_operation->mesh->loops_for_write(); + int poly_index = 0; + int loop_index = 0; + for (int i = 0; i < tot_tris_face; i++) { + polys[poly_index].loopstart = loop_index; + polys[poly_index].totloop = 3; + loops[loop_index + 0].v = r_tris[i][0]; + loops[loop_index + 1].v = r_tris[i][1]; + loops[loop_index + 2].v = r_tris[i][2]; + poly_index++; + loop_index += 3; } /* Write the back face triangle indices. */ - for (int i = 0; i < tot_tris_face; i++, mp++, ml += 3) { - mp->loopstart = int(ml - loops); - mp->totloop = 3; - ml[0].v = r_tris[i][0] + tot_screen_points; - ml[1].v = r_tris[i][1] + tot_screen_points; - ml[2].v = r_tris[i][2] + tot_screen_points; + for (int i = 0; i < tot_tris_face; i++) { + polys[poly_index].loopstart = loop_index; + polys[poly_index].totloop = 3; + loops[loop_index + 0].v = r_tris[i][0] + tot_screen_points; + loops[loop_index + 1].v = r_tris[i][1] + tot_screen_points; + loops[loop_index + 2].v = r_tris[i][2] + tot_screen_points; + poly_index++; + loop_index += 3; } MEM_freeN(r_tris); /* Write the indices for the lateral triangles. */ - for (int i = 0; i < tot_screen_points; i++, mp++, ml += 3) { - mp->loopstart = int(ml - loops); - mp->totloop = 3; + for (int i = 0; i < tot_screen_points; i++) { + polys[poly_index].loopstart = loop_index; + polys[poly_index].totloop = 3; int current_index = i; int next_index = current_index + 1; if (next_index >= tot_screen_points) { next_index = 0; } - ml[0].v = next_index + tot_screen_points; - ml[1].v = next_index; - ml[2].v = current_index; + loops[loop_index + 0].v = next_index + tot_screen_points; + loops[loop_index + 1].v = next_index; + loops[loop_index + 2].v = current_index; + poly_index++; + loop_index += 3; } - for (int i = 0; i < tot_screen_points; i++, mp++, ml += 3) { - mp->loopstart = int(ml - loops); - mp->totloop = 3; + for (int i = 0; i < tot_screen_points; i++) { + polys[poly_index].loopstart = loop_index; + polys[poly_index].totloop = 3; int current_index = i; int next_index = current_index + 1; if (next_index >= tot_screen_points) { next_index = 0; } - ml[0].v = current_index; - ml[1].v = current_index + tot_screen_points; - ml[2].v = next_index + tot_screen_points; + loops[loop_index + 0].v = current_index; + loops[loop_index + 1].v = current_index + tot_screen_points; + loops[loop_index + 2].v = next_index + tot_screen_points; + poly_index++; + loop_index += 3; } BKE_mesh_calc_edges(trim_operation->mesh, false, false); diff --git a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.cc b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.cc index 1e6a70c8bb2..22e04982bca 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.cc +++ b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.cc @@ -317,8 +317,8 @@ static const EnumPropertyItem *weight_paint_sample_enum_itemf(bContext *C, ED_view3d_viewcontext_init(C, &vc, depsgraph); me = BKE_mesh_from_object(vc.obact); - const MPoly *polys = BKE_mesh_polys(me); - const MLoop *loops = BKE_mesh_loops(me); + const blender::Span polys = me->polys(); + const blender::Span loops = me->loops(); const MDeformVert *dverts = BKE_mesh_deform_verts(me); if (me && dverts && vc.v3d && vc.rv3d && me->vertex_group_names.first) { @@ -438,7 +438,6 @@ void PAINT_OT_weight_sample_group(wmOperatorType *ot) static bool weight_paint_set(Object *ob, float paintweight) { Mesh *me = static_cast(ob->data); - const MPoly *mp; MDeformWeight *dw, *dw_prev; int vgroup_active, vgroup_mirror = -1; uint index; @@ -447,8 +446,8 @@ static bool weight_paint_set(Object *ob, float paintweight) /* mutually exclusive, could be made into a */ const short paint_selmode = ME_EDIT_PAINT_SEL_MODE(me); - const MPoly *polys = BKE_mesh_polys(me); - const MLoop *loops = BKE_mesh_loops(me); + const blender::Span polys = me->polys(); + const blender::Span loops = me->loops(); MDeformVert *dvert = BKE_mesh_deform_verts_for_write(me); if (me->totpoly == 0 || dvert == nullptr) { @@ -470,15 +469,16 @@ static bool weight_paint_set(Object *ob, float paintweight) const bool *select_poly = (const bool *)CustomData_get_layer_named( &me->pdata, CD_PROP_BOOL, ".select_poly"); - for (index = 0, mp = polys; index < me->totpoly; index++, mp++) { - uint fidx = mp->totloop - 1; + for (const int i : polys.index_range()) { + const MPoly &poly = polys[i]; + uint fidx = poly.totloop - 1; if ((paint_selmode == SCE_SELECT_FACE) && !(select_poly && select_poly[index])) { continue; } do { - uint vidx = loops[mp->loopstart + fidx].v; + uint vidx = loops[poly.loopstart + fidx].v; if (!dvert[vidx].flag) { if ((paint_selmode == SCE_SELECT_VERTEX) && !(select_vert && select_vert[vidx])) { diff --git a/source/blender/editors/sculpt_paint/sculpt.cc b/source/blender/editors/sculpt_paint/sculpt.cc index d1751625937..ebe483cbd25 100644 --- a/source/blender/editors/sculpt_paint/sculpt.cc +++ b/source/blender/editors/sculpt_paint/sculpt.cc @@ -6201,15 +6201,15 @@ void SCULPT_boundary_info_ensure(Object *object) } Mesh *base_mesh = BKE_mesh_from_object(object); - const MEdge *edges = BKE_mesh_edges(base_mesh); - const MPoly *polys = BKE_mesh_polys(base_mesh); - const MLoop *loops = BKE_mesh_loops(base_mesh); + const blender::Span edges = base_mesh->edges(); + const blender::Span polys = base_mesh->polys(); + const blender::Span loops = base_mesh->loops(); ss->vertex_info.boundary = BLI_BITMAP_NEW(base_mesh->totvert, "Boundary info"); int *adjacent_faces_edge_count = static_cast( MEM_calloc_arrayN(base_mesh->totedge, sizeof(int), "Adjacent face edge count")); - for (int p = 0; p < base_mesh->totpoly; p++) { + for (const int p : polys.index_range()) { const MPoly *poly = &polys[p]; for (int l = 0; l < poly->totloop; l++) { const MLoop *loop = &loops[l + poly->loopstart]; @@ -6217,7 +6217,7 @@ void SCULPT_boundary_info_ensure(Object *object) } } - for (int e = 0; e < base_mesh->totedge; e++) { + for (const int e : edges.index_range()) { if (adjacent_faces_edge_count[e] < 2) { const MEdge *edge = &edges[e]; BLI_BITMAP_SET(ss->vertex_info.boundary, edge->v1, true); diff --git a/source/blender/editors/sculpt_paint/sculpt_expand.cc b/source/blender/editors/sculpt_paint/sculpt_expand.cc index e6a69501ac5..e38ad0fcd2d 100644 --- a/source/blender/editors/sculpt_paint/sculpt_expand.cc +++ b/source/blender/editors/sculpt_paint/sculpt_expand.cc @@ -791,10 +791,10 @@ static void sculpt_expand_grids_to_faces_falloff(SculptSession *ss, Mesh *mesh, ExpandCache *expand_cache) { - const MPoly *polys = BKE_mesh_polys(mesh); + const blender::Span polys = mesh->polys(); const CCGKey *key = BKE_pbvh_get_grid_key(ss->pbvh); - for (int p = 0; p < mesh->totpoly; p++) { + for (const int p : polys.index_range()) { const MPoly *poly = &polys[p]; float accum = 0.0f; for (int l = 0; l < poly->totloop; l++) { @@ -809,10 +809,10 @@ static void sculpt_expand_grids_to_faces_falloff(SculptSession *ss, static void sculpt_expand_vertex_to_faces_falloff(Mesh *mesh, ExpandCache *expand_cache) { - const MPoly *polys = BKE_mesh_polys(mesh); - const MLoop *loops = BKE_mesh_loops(mesh); + const blender::Span polys = mesh->polys(); + const blender::Span loops = mesh->loops(); - for (int p = 0; p < mesh->totpoly; p++) { + for (const int p : polys.index_range()) { const MPoly *poly = &polys[p]; float accum = 0.0f; for (int l = 0; l < poly->totloop; l++) { @@ -1987,8 +1987,8 @@ static void sculpt_expand_delete_face_set_id(int *r_face_sets, { const int totface = ss->totfaces; MeshElemMap *pmap = ss->pmap; - const MPoly *polys = BKE_mesh_polys(mesh); - const MLoop *loops = BKE_mesh_loops(mesh); + const blender::Span polys = mesh->polys(); + const blender::Span loops = mesh->loops(); /* Check that all the face sets IDs in the mesh are not equal to `delete_id` * before attempting to delete it. */ diff --git a/source/blender/editors/sculpt_paint/sculpt_face_set.cc b/source/blender/editors/sculpt_paint/sculpt_face_set.cc index de06fa3541a..46f247aeccf 100644 --- a/source/blender/editors/sculpt_paint/sculpt_face_set.cc +++ b/source/blender/editors/sculpt_paint/sculpt_face_set.cc @@ -1102,10 +1102,10 @@ static void sculpt_face_set_grow(Object *ob, const bool modify_hidden) { Mesh *mesh = BKE_mesh_from_object(ob); - const MPoly *polys = BKE_mesh_polys(mesh); - const MLoop *loops = BKE_mesh_loops(mesh); + const blender::Span polys = mesh->polys(); + const blender::Span loops = mesh->loops(); - for (int p = 0; p < mesh->totpoly; p++) { + for (const int p : polys.index_range()) { if (!modify_hidden && prev_face_sets[p] <= 0) { continue; } @@ -1133,9 +1133,9 @@ static void sculpt_face_set_shrink(Object *ob, const bool modify_hidden) { Mesh *mesh = BKE_mesh_from_object(ob); - const MPoly *polys = BKE_mesh_polys(mesh); - const MLoop *loops = BKE_mesh_loops(mesh); - for (int p = 0; p < mesh->totpoly; p++) { + const blender::Span polys = mesh->polys(); + const blender::Span loops = mesh->loops(); + for (const int p : polys.index_range()) { if (!modify_hidden && prev_face_sets[p] <= 0) { continue; } diff --git a/source/blender/editors/sculpt_paint/sculpt_geodesic.cc b/source/blender/editors/sculpt_paint/sculpt_geodesic.cc index 84232a295dd..2b85e09581e 100644 --- a/source/blender/editors/sculpt_paint/sculpt_geodesic.cc +++ b/source/blender/editors/sculpt_paint/sculpt_geodesic.cc @@ -87,19 +87,25 @@ static float *SCULPT_geodesic_mesh_create(Object *ob, const float limit_radius_sq = limit_radius * limit_radius; float(*vert_positions)[3] = SCULPT_mesh_deformed_positions_get(ss); - const MEdge *edges = BKE_mesh_edges(mesh); - const MPoly *polys = BKE_mesh_polys(mesh); - const MLoop *loops = BKE_mesh_loops(mesh); + const blender::Span edges = mesh->edges(); + const blender::Span polys = mesh->polys(); + const blender::Span loops = mesh->loops(); float *dists = static_cast(MEM_malloc_arrayN(totvert, sizeof(float), __func__)); BLI_bitmap *edge_tag = BLI_BITMAP_NEW(totedge, "edge tag"); if (!ss->epmap) { - BKE_mesh_edge_poly_map_create( - &ss->epmap, &ss->epmap_mem, mesh->totedge, polys, mesh->totpoly, loops, mesh->totloop); + BKE_mesh_edge_poly_map_create(&ss->epmap, + &ss->epmap_mem, + edges.size(), + polys.data(), + polys.size(), + loops.data(), + loops.size()); } if (!ss->vemap) { - BKE_mesh_vert_edge_map_create(&ss->vemap, &ss->vemap_mem, edges, mesh->totvert, mesh->totedge); + BKE_mesh_vert_edge_map_create( + &ss->vemap, &ss->vemap_mem, edges.data(), mesh->totvert, edges.size()); } /* Both contain edge indices encoded as *void. */ diff --git a/source/blender/editors/space_view3d/drawobject.cc b/source/blender/editors/space_view3d/drawobject.cc index 94e2c94227b..9dc1aaa876b 100644 --- a/source/blender/editors/space_view3d/drawobject.cc +++ b/source/blender/editors/space_view3d/drawobject.cc @@ -70,16 +70,13 @@ void ED_draw_object_facemap(Depsgraph *depsgraph, GPU_blend(GPU_BLEND_ALPHA); const float(*positions)[3] = BKE_mesh_vert_positions(me); - const MPoly *polys = BKE_mesh_polys(me); - const MLoop *loops = BKE_mesh_loops(me); - - int mpoly_len = me->totpoly; - int mloop_len = me->totloop; + const blender::Span polys = me->polys(); + const blender::Span loops = me->loops(); facemap_data = static_cast(CustomData_get_layer(&me->pdata, CD_FACEMAP)); /* Make a batch and free it each time for now. */ - const int looptris_len = poly_to_tri_count(mpoly_len, mloop_len); + const int looptris_len = poly_to_tri_count(polys.size(), loops.size()); const int vbo_len_capacity = looptris_len * 3; int vbo_len_used = 0; @@ -93,13 +90,12 @@ void ED_draw_object_facemap(Depsgraph *depsgraph, GPUVertBufRaw pos_step; GPU_vertbuf_attr_get_raw_data(vbo_pos, pos_id, &pos_step); - const MPoly *mp; - int i; if (BKE_mesh_runtime_looptri_ensure(me)) { const MLoopTri *mlt = BKE_mesh_runtime_looptri_ensure(me); - for (mp = polys, i = 0; i < mpoly_len; i++, mp++) { + for (const int i : polys.index_range()) { + const MPoly &poly = polys[i]; if (facemap_data[i] == facemap) { - for (int j = 2; j < mp->totloop; j++) { + for (int j = 2; j < poly.totloop; j++) { copy_v3_v3(static_cast(GPU_vertbuf_raw_step(&pos_step)), positions[loops[mlt->tri[0]].v]); copy_v3_v3(static_cast(GPU_vertbuf_raw_step(&pos_step)), @@ -111,18 +107,19 @@ void ED_draw_object_facemap(Depsgraph *depsgraph, } } else { - mlt += mp->totloop - 2; + mlt += poly.totloop - 2; } } } else { /* No tessellation data, fan-fill. */ - for (mp = polys, i = 0; i < mpoly_len; i++, mp++) { + for (const int i : polys.index_range()) { + const MPoly &poly = polys[i]; if (facemap_data[i] == facemap) { - const MLoop *ml_start = &loops[mp->loopstart]; + const MLoop *ml_start = &loops[poly.loopstart]; const MLoop *ml_a = ml_start + 1; const MLoop *ml_b = ml_start + 2; - for (int j = 2; j < mp->totloop; j++) { + for (int j = 2; j < poly.totloop; j++) { copy_v3_v3(static_cast(GPU_vertbuf_raw_step(&pos_step)), positions[ml_start->v]); copy_v3_v3(static_cast(GPU_vertbuf_raw_step(&pos_step)), positions[ml_a->v]); diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.cc b/source/blender/editors/uvedit/uvedit_unwrap_ops.cc index 050362d0c7f..1cd5b2e6ce1 100644 --- a/source/blender/editors/uvedit/uvedit_unwrap_ops.cc +++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.cc @@ -630,9 +630,9 @@ static ParamHandle *construct_param_handle_subsurfed(const Scene *scene, Mesh *subdiv_mesh = subdivide_edit_mesh(ob, em, &smd); const float(*subsurfedPositions)[3] = BKE_mesh_vert_positions(subdiv_mesh); - const MEdge *subsurfedEdges = BKE_mesh_edges(subdiv_mesh); - const MPoly *subsurfedPolys = BKE_mesh_polys(subdiv_mesh); - const MLoop *subsurfedLoops = BKE_mesh_loops(subdiv_mesh); + const blender::Span subsurf_edges = subdiv_mesh->edges(); + const blender::Span subsurf_polys = subdiv_mesh->polys(); + const blender::Span subsurf_loops = subdiv_mesh->loops(); const int *origVertIndices = static_cast( CustomData_get_layer(&subdiv_mesh->vdata, CD_ORIGINDEX)); @@ -664,8 +664,8 @@ static ParamHandle *construct_param_handle_subsurfed(const Scene *scene, } /* Prepare and feed faces to the solver */ - for (int i = 0; i < subdiv_mesh->totpoly; i++) { - const MPoly *mpoly = &subsurfedPolys[i]; + for (const int i : subsurf_polys.index_range()) { + const MPoly *mpoly = &subsurf_polys[i]; ParamKey key, vkeys[4]; bool pin[4], select[4]; const float *co[4]; @@ -684,7 +684,7 @@ static ParamHandle *construct_param_handle_subsurfed(const Scene *scene, } } - const MLoop *mloop = &subsurfedLoops[mpoly->loopstart]; + const MLoop *mloop = &subsurf_loops[mpoly->loopstart]; /* We will not check for v4 here. Sub-surface faces always have 4 vertices. */ BLI_assert(mpoly->totloop == 4); @@ -715,9 +715,9 @@ static ParamHandle *construct_param_handle_subsurfed(const Scene *scene, } /* these are calculated from original mesh too */ - for (int i = 0; i < subdiv_mesh->totedge; i++) { + for (const int i : subsurf_edges.index_range()) { if ((edgeMap[i] != nullptr) && BM_elem_flag_test(edgeMap[i], BM_ELEM_SEAM)) { - const MEdge *edge = &subsurfedEdges[i]; + const MEdge *edge = &subsurf_edges[i]; ParamKey vkeys[2]; vkeys[0] = (ParamKey)edge->v1; vkeys[1] = (ParamKey)edge->v2; diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.cc b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.cc index 4cd2ae880ef..f7de35a99fa 100644 --- a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.cc +++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.cc @@ -1863,7 +1863,7 @@ struct EdgeNeighborData { LineartEdgeNeighbor *edge_nabr; LineartAdjacentEdge *adj_e; const MLoopTri *mlooptri; - const MLoop *mloop; + blender::Span loops; }; static void lineart_edge_neighbor_init_task(void *__restrict userdata, @@ -1874,11 +1874,11 @@ static void lineart_edge_neighbor_init_task(void *__restrict userdata, LineartAdjacentEdge *adj_e = &en_data->adj_e[i]; const MLoopTri *looptri = &en_data->mlooptri[i / 3]; LineartEdgeNeighbor *edge_nabr = &en_data->edge_nabr[i]; - const MLoop *mloop = en_data->mloop; + const blender::Span loops = en_data->loops; adj_e->e = i; - adj_e->v1 = mloop[looptri->tri[i % 3]].v; - adj_e->v2 = mloop[looptri->tri[(i + 1) % 3]].v; + adj_e->v1 = loops[looptri->tri[i % 3]].v; + adj_e->v2 = loops[looptri->tri[(i + 1) % 3]].v; if (adj_e->v1 > adj_e->v2) { std::swap(adj_e->v1, adj_e->v2); } @@ -1925,7 +1925,7 @@ static LineartEdgeNeighbor *lineart_build_edge_neighbor(Mesh *me, int total_edge en_data.adj_e = adj_e; en_data.edge_nabr = edge_nabr; en_data.mlooptri = BKE_mesh_runtime_looptri_ensure(me); - en_data.mloop = BKE_mesh_loops(me); + en_data.loops = me->loops(); BLI_task_parallel_range(0, total_edges, &en_data, lineart_edge_neighbor_init_task, &en_settings); diff --git a/source/blender/modifiers/intern/MOD_array.cc b/source/blender/modifiers/intern/MOD_array.cc index ce9edafe525..beba3ce7de2 100644 --- a/source/blender/modifiers/intern/MOD_array.cc +++ b/source/blender/modifiers/intern/MOD_array.cc @@ -280,9 +280,9 @@ static void mesh_merge_transform(Mesh *result, MLoop *ml; MPoly *mp; float(*result_positions)[3] = BKE_mesh_vert_positions_for_write(result); - MEdge *result_edges = BKE_mesh_edges_for_write(result); - MPoly *result_polys = BKE_mesh_polys_for_write(result); - MLoop *result_loops = BKE_mesh_loops_for_write(result); + blender::MutableSpan result_edges = result->edges_for_write(); + blender::MutableSpan result_polys = result->polys_for_write(); + blender::MutableSpan result_loops = result->loops_for_write(); CustomData_copy_data(&cap_mesh->vdata, &result->vdata, 0, cap_verts_index, cap_nverts); CustomData_copy_data(&cap_mesh->edata, &result->edata, 0, cap_edges_index, cap_nedges); @@ -309,20 +309,20 @@ static void mesh_merge_transform(Mesh *result, } /* adjust cap edge vertex indices */ - me = result_edges + cap_edges_index; + me = &result_edges[cap_edges_index]; for (i = 0; i < cap_nedges; i++, me++) { me->v1 += cap_verts_index; me->v2 += cap_verts_index; } /* adjust cap poly loopstart indices */ - mp = result_polys + cap_polys_index; + mp = &result_polys[cap_polys_index]; for (i = 0; i < cap_npolys; i++, mp++) { mp->loopstart += cap_loops_index; } /* adjust cap loop vertex and edge indices */ - ml = result_loops + cap_loops_index; + ml = &result_loops[cap_loops_index]; for (i = 0; i < cap_nloops; i++, ml++) { ml->v += cap_verts_index; ml->e += cap_edges_index; @@ -430,9 +430,6 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd, /* Build up offset array, accumulating all settings options. */ unit_m4(offset); - const MEdge *src_edges = BKE_mesh_edges(mesh); - const MPoly *src_polys = BKE_mesh_polys(mesh); - const MLoop *src_loops = BKE_mesh_loops(mesh); if (amd->offset_type & MOD_ARR_OFF_CONST) { add_v3_v3(offset[3], amd->offset); @@ -539,9 +536,9 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd, result = BKE_mesh_new_nomain_from_template( mesh, result_nverts, result_nedges, 0, result_nloops, result_npolys); float(*result_positions)[3] = BKE_mesh_vert_positions_for_write(result); - MEdge *result_edges = BKE_mesh_edges_for_write(result); - MPoly *result_polys = BKE_mesh_polys_for_write(result); - MLoop *result_loops = BKE_mesh_loops_for_write(result); + blender::MutableSpan result_edges = result->edges_for_write(); + blender::MutableSpan result_polys = result->polys_for_write(); + blender::MutableSpan result_loops = result->loops_for_write(); if (use_merge) { /* Will need full_doubles_map for handling merge */ @@ -594,19 +591,19 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd, } /* adjust edge vertex indices */ - me = result_edges + c * chunk_nedges; + me = &result_edges[c * chunk_nedges]; for (i = 0; i < chunk_nedges; i++, me++) { me->v1 += c * chunk_nverts; me->v2 += c * chunk_nverts; } - mp = result_polys + c * chunk_npolys; + mp = &result_polys[c * chunk_npolys]; for (i = 0; i < chunk_npolys; i++, mp++) { mp->loopstart += c * chunk_nloops; } /* adjust loop vertex and edge indices */ - ml = result_loops + c * chunk_nloops; + ml = &result_loops[c * chunk_nloops]; for (i = 0; i < chunk_nloops; i++, ml++) { ml->v += c * chunk_nverts; ml->e += c * chunk_nedges; diff --git a/source/blender/modifiers/intern/MOD_build.cc b/source/blender/modifiers/intern/MOD_build.cc index ae69677a2d6..3c717ea4a9e 100644 --- a/source/blender/modifiers/intern/MOD_build.cc +++ b/source/blender/modifiers/intern/MOD_build.cc @@ -72,19 +72,17 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * GHash *edgeHash2 = BLI_ghash_int_new("build ed apply gh"); const int vert_src_num = mesh->totvert; - const int edge_src_num = mesh->totedge; - const int poly_src_num = mesh->totpoly; - const MEdge *medge_src = BKE_mesh_edges(mesh); - const MPoly *mpoly_src = BKE_mesh_polys(mesh); - const MLoop *mloop_src = BKE_mesh_loops(mesh); + const blender::Span edges_src = mesh->edges(); + const blender::Span polys_src = mesh->polys(); + const blender::Span loops_src = mesh->loops(); int *vertMap = static_cast(MEM_malloc_arrayN(vert_src_num, sizeof(int), __func__)); - int *edgeMap = static_cast(MEM_malloc_arrayN(edge_src_num, sizeof(int), __func__)); - int *faceMap = static_cast(MEM_malloc_arrayN(poly_src_num, sizeof(int), __func__)); + int *edgeMap = static_cast(MEM_malloc_arrayN(edges_src.size(), sizeof(int), __func__)); + int *faceMap = static_cast(MEM_malloc_arrayN(polys_src.size(), sizeof(int), __func__)); range_vn_i(vertMap, vert_src_num, 0); - range_vn_i(edgeMap, edge_src_num, 0); - range_vn_i(faceMap, poly_src_num, 0); + range_vn_i(edgeMap, edges_src.size(), 0); + range_vn_i(faceMap, polys_src.size(), 0); Scene *scene = DEG_get_input_scene(ctx->depsgraph); frac = (BKE_scene_ctime_get(scene) - bmd->start) / bmd->length; @@ -93,8 +91,8 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * frac = 1.0f - frac; } - faces_dst_num = poly_src_num * frac; - edges_dst_num = edge_src_num * frac; + faces_dst_num = polys_src.size() * frac; + edges_dst_num = edges_src.size() * frac; /* if there's at least one face, build based on faces */ if (faces_dst_num) { @@ -103,14 +101,14 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * uintptr_t hash_num, hash_num_alt; if (bmd->flag & MOD_BUILD_FLAG_RANDOMIZE) { - BLI_array_randomize(faceMap, sizeof(*faceMap), poly_src_num, bmd->seed); + BLI_array_randomize(faceMap, sizeof(*faceMap), polys_src.size(), bmd->seed); } /* get the set of all vert indices that will be in the final mesh, * mapped to the new indices */ - mpoly = mpoly_src; - mloop = mloop_src; + mpoly = polys_src.data(); + mloop = loops_src.data(); hash_num = 0; for (i = 0; i < faces_dst_num; i++) { mp = mpoly + faceMap[i]; @@ -133,8 +131,8 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * */ hash_num = 0; hash_num_alt = 0; - for (i = 0; i < edge_src_num; i++, hash_num_alt++) { - const MEdge *me = medge_src + i; + for (i = 0; i < edges_src.size(); i++, hash_num_alt++) { + const MEdge *me = edges_src.data() + i; if (BLI_ghash_haskey(vertHash, POINTER_FROM_INT(me->v1)) && BLI_ghash_haskey(vertHash, POINTER_FROM_INT(me->v2))) { @@ -150,13 +148,13 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * uintptr_t hash_num; if (bmd->flag & MOD_BUILD_FLAG_RANDOMIZE) { - BLI_array_randomize(edgeMap, sizeof(*edgeMap), edge_src_num, bmd->seed); + BLI_array_randomize(edgeMap, sizeof(*edgeMap), edges_src.size(), bmd->seed); } /* get the set of all vert indices that will be in the final mesh, * mapped to the new indices */ - medge = medge_src; + medge = edges_src.data(); hash_num = 0; BLI_assert(hash_num == BLI_ghash_len(vertHash)); for (i = 0; i < edges_dst_num; i++) { @@ -200,9 +198,9 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * /* now we know the number of verts, edges and faces, we can create the mesh. */ result = BKE_mesh_new_nomain_from_template( mesh, BLI_ghash_len(vertHash), BLI_ghash_len(edgeHash), 0, loops_dst_num, faces_dst_num); - MEdge *result_edges = BKE_mesh_edges_for_write(result); - MPoly *result_polys = BKE_mesh_polys_for_write(result); - MLoop *result_loops = BKE_mesh_loops_for_write(result); + blender::MutableSpan result_edges = result->edges_for_write(); + blender::MutableSpan result_polys = result->polys_for_write(); + blender::MutableSpan result_loops = result->loops_for_write(); /* copy the vertices across */ GHASH_ITER (gh_iter, vertHash) { @@ -217,7 +215,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * MEdge *dest; int oldIndex = POINTER_AS_INT(BLI_ghash_lookup(edgeHash, POINTER_FROM_INT(i))); - source = medge_src[oldIndex]; + source = edges_src[oldIndex]; dest = &result_edges[i]; source.v1 = POINTER_AS_INT(BLI_ghash_lookup(vertHash, POINTER_FROM_INT(source.v1))); @@ -227,8 +225,8 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * *dest = source; } - mpoly_dst = result_polys; - ml_dst = result_loops; + mpoly_dst = result_polys.data(); + ml_dst = result_loops.data(); /* copy the faces across, remapping indices */ k = 0; @@ -236,7 +234,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * const MPoly *source; MPoly *dest; - source = mpoly_src + faceMap[i]; + source = &polys_src[faceMap[i]]; dest = mpoly_dst + i; CustomData_copy_data(&mesh->pdata, &result->pdata, faceMap[i], i, 1); @@ -245,7 +243,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * CustomData_copy_data( &mesh->ldata, &result->ldata, source->loopstart, dest->loopstart, dest->totloop); - ml_src = mloop_src + source->loopstart; + ml_src = &loops_src[source->loopstart]; for (j = 0; j < source->totloop; j++, k++, ml_src++, ml_dst++) { ml_dst->v = POINTER_AS_INT(BLI_ghash_lookup(vertHash, POINTER_FROM_INT(ml_src->v))); ml_dst->e = POINTER_AS_INT(BLI_ghash_lookup(edgeHash2, POINTER_FROM_INT(ml_src->e))); diff --git a/source/blender/modifiers/intern/MOD_correctivesmooth.cc b/source/blender/modifiers/intern/MOD_correctivesmooth.cc index 5a1d4dc637a..d906c628097 100644 --- a/source/blender/modifiers/intern/MOD_correctivesmooth.cc +++ b/source/blender/modifiers/intern/MOD_correctivesmooth.cc @@ -127,31 +127,27 @@ static void mesh_get_weights(const MDeformVert *dvert, static void mesh_get_boundaries(Mesh *mesh, float *smooth_weights) { - const MEdge *medge = BKE_mesh_edges(mesh); - const MPoly *mpoly = BKE_mesh_polys(mesh); - const MLoop *mloop = BKE_mesh_loops(mesh); - - const uint mpoly_num = uint(mesh->totpoly); - const uint medge_num = uint(mesh->totedge); + const blender::Span edges = mesh->edges(); + const blender::Span polys = mesh->polys(); + const blender::Span loops = mesh->loops(); /* Flag boundary edges so only boundaries are set to 1. */ uint8_t *boundaries = static_cast( - MEM_calloc_arrayN(medge_num, sizeof(*boundaries), __func__)); + MEM_calloc_arrayN(size_t(edges.size()), sizeof(*boundaries), __func__)); - for (uint i = 0; i < mpoly_num; i++) { - const MPoly *p = &mpoly[i]; - const int totloop = p->totloop; + for (const int64_t i : polys.index_range()) { + const int totloop = polys[i].totloop; int j; for (j = 0; j < totloop; j++) { - uint8_t *e_value = &boundaries[mloop[p->loopstart + j].e]; + uint8_t *e_value = &boundaries[loops[polys[i].loopstart + j].e]; *e_value |= uint8_t((*e_value) + 1); } } - for (uint i = 0; i < medge_num; i++) { + for (const int64_t i : edges.index_range()) { if (boundaries[i] == 1) { - smooth_weights[medge[i].v1] = 0.0f; - smooth_weights[medge[i].v2] = 0.0f; + smooth_weights[edges[i].v1] = 0.0f; + smooth_weights[edges[i].v2] = 0.0f; } } @@ -174,7 +170,7 @@ static void smooth_iter__simple(CorrectiveSmoothModifierData *csmd, uint i; const uint edges_num = uint(mesh->totedge); - const MEdge *edges = BKE_mesh_edges(mesh); + const blender::Span edges = mesh->edges(); struct SmoothingData_Simple { float delta[3]; @@ -252,7 +248,7 @@ static void smooth_iter__length_weight(CorrectiveSmoothModifierData *csmd, /* NOTE: the way this smoothing method works, its approx half as strong as the simple-smooth, * and 2.0 rarely spikes, double the value for consistent behavior. */ const float lambda = csmd->lambda * 2.0f; - const MEdge *edges = BKE_mesh_edges(mesh); + const blender::Span edges = mesh->edges(); uint i; struct SmoothingData_Weighted { @@ -437,19 +433,17 @@ static void calc_tangent_spaces(const Mesh *mesh, float *r_tangent_weights, float *r_tangent_weights_per_vertex) { - const uint mpoly_num = uint(mesh->totpoly); const uint mvert_num = uint(mesh->totvert); - const MPoly *mpoly = BKE_mesh_polys(mesh); - const MLoop *mloop = BKE_mesh_loops(mesh); - uint i; + const blender::Span polys = mesh->polys(); + const blender::Span loops = mesh->loops(); if (r_tangent_weights_per_vertex != nullptr) { copy_vn_fl(r_tangent_weights_per_vertex, int(mvert_num), 0.0f); } - for (i = 0; i < mpoly_num; i++) { - const MPoly *mp = &mpoly[i]; - const MLoop *l_next = &mloop[mp->loopstart]; + for (const int64_t i : polys.index_range()) { + const MPoly *mp = &polys[i]; + const MLoop *l_next = &loops[mp->loopstart]; const MLoop *l_term = l_next + mp->totloop; const MLoop *l_prev = l_term - 2; const MLoop *l_curr = l_term - 1; @@ -462,7 +456,7 @@ static void calc_tangent_spaces(const Mesh *mesh, normalize_v3(v_dir_prev); for (; l_next != l_term; l_prev = l_curr, l_curr = l_next, l_next++) { - uint l_index = uint(l_curr - mloop); + uint l_index = uint(l_curr - loops.data()); float(*ts)[3] = r_tangent_spaces[l_index]; /* re-use the previous value */ @@ -519,35 +513,34 @@ static void calc_deltas(CorrectiveSmoothModifierData *csmd, const float (*rest_coords)[3], uint verts_num) { - const MLoop *mloop = BKE_mesh_loops(mesh); - const uint loops_num = uint(mesh->totloop); + const blender::Span loops = mesh->loops(); float(*smooth_vertex_coords)[3] = static_cast(MEM_dupallocN(rest_coords)); uint l_index; float(*tangent_spaces)[3][3] = static_cast( - MEM_malloc_arrayN(loops_num, sizeof(float[3][3]), __func__)); + MEM_malloc_arrayN(size_t(loops.size()), sizeof(float[3][3]), __func__)); - if (csmd->delta_cache.deltas_num != loops_num) { + if (csmd->delta_cache.deltas_num != uint(loops.size())) { MEM_SAFE_FREE(csmd->delta_cache.deltas); } /* allocate deltas if they have not yet been allocated, otherwise we will just write over them */ if (!csmd->delta_cache.deltas) { - csmd->delta_cache.deltas_num = loops_num; + csmd->delta_cache.deltas_num = uint(loops.size()); csmd->delta_cache.deltas = static_cast( - MEM_malloc_arrayN(loops_num, sizeof(float[3]), __func__)); + MEM_malloc_arrayN(size_t(loops.size()), sizeof(float[3]), __func__)); } smooth_verts(csmd, mesh, dvert, defgrp_index, smooth_vertex_coords, verts_num); calc_tangent_spaces(mesh, smooth_vertex_coords, tangent_spaces, nullptr, nullptr); - copy_vn_fl(&csmd->delta_cache.deltas[0][0], int(loops_num) * 3, 0.0f); + copy_vn_fl(&csmd->delta_cache.deltas[0][0], int(loops.size()) * 3, 0.0f); - for (l_index = 0; l_index < loops_num; l_index++) { - const int v_index = int(mloop[l_index].v); + for (l_index = 0; l_index < loops.size(); l_index++) { + const int v_index = int(loops[l_index].v); float delta[3]; sub_v3_v3v3(delta, rest_coords[v_index], smooth_vertex_coords[v_index]); @@ -578,8 +571,7 @@ static void correctivesmooth_modifier_do(ModifierData *md, ((csmd->rest_source == MOD_CORRECTIVESMOOTH_RESTSOURCE_ORCO) && (((ID *)ob->data)->recalc & ID_RECALC_ALL)); - const MLoop *mloop = BKE_mesh_loops(mesh); - const uint loops_num = uint(mesh->totloop); + const blender::Span loops = mesh->loops(); bool use_only_smooth = (csmd->flag & MOD_CORRECTIVESMOOTH_ONLY_SMOOTH) != 0; const MDeformVert *dvert = nullptr; @@ -644,7 +636,7 @@ static void correctivesmooth_modifier_do(ModifierData *md, } /* check to see if our deltas are still valid */ - if (!csmd->delta_cache.deltas || (csmd->delta_cache.deltas_num != loops_num) || + if (!csmd->delta_cache.deltas || (csmd->delta_cache.deltas_num != loops.size()) || force_delta_cache_update) { const float(*rest_coords)[3]; bool is_rest_coords_alloc = false; @@ -693,22 +685,21 @@ static void correctivesmooth_modifier_do(ModifierData *md, smooth_verts(csmd, mesh, dvert, defgrp_index, vertexCos, verts_num); { - uint l_index; const float scale = csmd->scale; float(*tangent_spaces)[3][3] = static_cast( - MEM_malloc_arrayN(loops_num, sizeof(float[3][3]), __func__)); + MEM_malloc_arrayN(size_t(loops.size()), sizeof(float[3][3]), __func__)); float *tangent_weights = static_cast( - MEM_malloc_arrayN(loops_num, sizeof(float), __func__)); + MEM_malloc_arrayN(size_t(loops.size()), sizeof(float), __func__)); float *tangent_weights_per_vertex = static_cast( MEM_malloc_arrayN(verts_num, sizeof(float), __func__)); calc_tangent_spaces( mesh, vertexCos, tangent_spaces, tangent_weights, tangent_weights_per_vertex); - for (l_index = 0; l_index < loops_num; l_index++) { - const uint v_index = mloop[l_index].v; + for (const int64_t l_index : loops.index_range()) { + const uint v_index = loops[l_index].v; const float weight = tangent_weights[l_index] / tangent_weights_per_vertex[v_index]; if (UNLIKELY(!(weight > 0.0f))) { /* Catches zero & divide by zero. */ diff --git a/source/blender/modifiers/intern/MOD_datatransfer.cc b/source/blender/modifiers/intern/MOD_datatransfer.cc index 80c78955d14..4bb36d9a791 100644 --- a/source/blender/modifiers/intern/MOD_datatransfer.cc +++ b/source/blender/modifiers/intern/MOD_datatransfer.cc @@ -176,11 +176,12 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * } const float(*me_positions)[3] = BKE_mesh_vert_positions(me); - const MEdge *me_edges = BKE_mesh_edges(me); + const blender::Span me_edges = me->edges(); const float(*result_positions)[3] = BKE_mesh_vert_positions(result); - const MEdge *result_edges = BKE_mesh_edges(result); + const blender::Span result_edges = result->edges(); - if (((result == me) || (me_positions == result_positions) || (me_edges == result_edges)) && + if (((result == me) || (me_positions == result_positions) || + (me_edges.data() == result_edges.data())) && (dtmd->data_types & DT_TYPES_AFFECT_MESH)) { /* We need to duplicate data here, otherwise setting custom normals, edges' sharpness, etc., * could modify org mesh, see #43671. */ diff --git a/source/blender/modifiers/intern/MOD_displace.cc b/source/blender/modifiers/intern/MOD_displace.cc index 1b3b10b3873..fcdb9625613 100644 --- a/source/blender/modifiers/intern/MOD_displace.cc +++ b/source/blender/modifiers/intern/MOD_displace.cc @@ -312,7 +312,7 @@ static void displaceModifier_do(DisplaceModifierData *dmd, vert_clnors = static_cast( MEM_malloc_arrayN(verts_num, sizeof(*vert_clnors), __func__)); BKE_mesh_normals_loop_to_vertex( - verts_num, BKE_mesh_loops(mesh), mesh->totloop, (const float(*)[3])clnors, vert_clnors); + verts_num, mesh->loops().data(), mesh->totloop, (const float(*)[3])clnors, vert_clnors); } else { direction = MOD_DISP_DIR_NOR; diff --git a/source/blender/modifiers/intern/MOD_laplaciansmooth.cc b/source/blender/modifiers/intern/MOD_laplaciansmooth.cc index ae74de3e5a6..2f696e52eb7 100644 --- a/source/blender/modifiers/intern/MOD_laplaciansmooth.cc +++ b/source/blender/modifiers/intern/MOD_laplaciansmooth.cc @@ -45,9 +45,6 @@ struct LaplacianSystem { float *ring_areas; /* Total area per ring. */ float *vlengths; /* Total sum of lengths(edges) per vertex. */ float *vweights; /* Total sum of weights per vertex. */ - int edges_num; /* Number of edges. */ - int loops_num; /* Number of edges. */ - int polys_num; /* Number of faces. */ int verts_num; /* Number of verts. */ short *ne_fa_num; /* Number of neighbors faces around vertex. */ short *ne_ed_num; /* Number of neighbors Edges around vertex. */ @@ -55,9 +52,9 @@ struct LaplacianSystem { /* Pointers to data. */ float (*vertexCos)[3]; - const MPoly *mpoly; - const MLoop *mloop; - const MEdge *medges; + blender::Span polys; + blender::Span loops; + blender::Span edges; LinearSolver *context; /* Data. */ @@ -65,15 +62,6 @@ struct LaplacianSystem { float vert_centroid[3]; }; -static float compute_volume(const float center[3], - float (*vertexCos)[3], - const MPoly *mpoly, - int polys_num, - const MLoop *mloop); -static LaplacianSystem *init_laplacian_system(int a_numEdges, - int a_numPolys, - int a_numLoops, - int a_numVerts); static void delete_laplacian_system(LaplacianSystem *sys); static void fill_laplacian_matrix(LaplacianSystem *sys); static void init_data(ModifierData *md); @@ -97,16 +85,13 @@ static void delete_laplacian_system(LaplacianSystem *sys) EIG_linear_solver_delete(sys->context); } sys->vertexCos = nullptr; - sys->mpoly = nullptr; - sys->mloop = nullptr; - sys->medges = nullptr; MEM_freeN(sys); } static void memset_laplacian_system(LaplacianSystem *sys, int val) { - memset(sys->eweights, val, sizeof(float) * sys->edges_num); - memset(sys->fweights, val, sizeof(float[3]) * sys->loops_num); + memset(sys->eweights, val, sizeof(float) * sys->edges.size()); + memset(sys->fweights, val, sizeof(float[3]) * sys->loops.size()); memset(sys->ne_ed_num, val, sizeof(short) * sys->verts_num); memset(sys->ne_fa_num, val, sizeof(short) * sys->verts_num); memset(sys->ring_areas, val, sizeof(float) * sys->verts_num); @@ -115,20 +100,14 @@ static void memset_laplacian_system(LaplacianSystem *sys, int val) memset(sys->zerola, val, sizeof(bool) * sys->verts_num); } -static LaplacianSystem *init_laplacian_system(int a_numEdges, - int a_numPolys, - int a_numLoops, - int a_numVerts) +static LaplacianSystem *init_laplacian_system(int a_numEdges, int a_numLoops, int a_numVerts) { LaplacianSystem *sys; sys = static_cast(MEM_callocN(sizeof(LaplacianSystem), __func__)); - sys->edges_num = a_numEdges; - sys->polys_num = a_numPolys; - sys->loops_num = a_numLoops; sys->verts_num = a_numVerts; - sys->eweights = MEM_cnew_array(sys->edges_num, __func__); - sys->fweights = MEM_cnew_array(sys->loops_num, __func__); + sys->eweights = MEM_cnew_array(a_numEdges, __func__); + sys->fweights = MEM_cnew_array(a_numLoops, __func__); sys->ne_ed_num = MEM_cnew_array(sys->verts_num, __func__); sys->ne_fa_num = MEM_cnew_array(sys->verts_num, __func__); sys->ring_areas = MEM_cnew_array(sys->verts_num, __func__); @@ -141,16 +120,14 @@ static LaplacianSystem *init_laplacian_system(int a_numEdges, static float compute_volume(const float center[3], float (*vertexCos)[3], - const MPoly *mpoly, - int polys_num, - const MLoop *mloop) + const blender::Span polys, + const blender::Span loops) { - int i; float vol = 0.0f; - for (i = 0; i < polys_num; i++) { - const MPoly *mp = &mpoly[i]; - const MLoop *l_first = &mloop[mp->loopstart]; + for (const int i : polys.index_range()) { + const MPoly *mp = &polys[i]; + const MLoop *l_first = &loops[mp->loopstart]; const MLoop *l_prev = l_first + 1; const MLoop *l_curr = l_first + 2; const MLoop *l_term = l_first + mp->totloop; @@ -196,9 +173,9 @@ static void init_laplacian_matrix(LaplacianSystem *sys) int i; uint idv1, idv2; - for (i = 0; i < sys->edges_num; i++) { - idv1 = sys->medges[i].v1; - idv2 = sys->medges[i].v2; + for (i = 0; i < sys->edges.size(); i++) { + idv1 = sys->edges[i].v1; + idv2 = sys->edges[i].v2; v1 = sys->vertexCos[idv1]; v2 = sys->vertexCos[idv2]; @@ -217,9 +194,9 @@ static void init_laplacian_matrix(LaplacianSystem *sys) sys->eweights[i] = w1; } - for (i = 0; i < sys->polys_num; i++) { - const MPoly *mp = &sys->mpoly[i]; - const MLoop *l_next = &sys->mloop[mp->loopstart]; + for (i = 0; i < sys->polys.size(); i++) { + const MPoly *mp = &sys->polys[i]; + const MLoop *l_next = &sys->loops[mp->loopstart]; const MLoop *l_term = l_next + mp->totloop; const MLoop *l_prev = l_term - 2; const MLoop *l_curr = l_term - 1; @@ -228,7 +205,7 @@ static void init_laplacian_matrix(LaplacianSystem *sys) const float *v_prev = sys->vertexCos[l_prev->v]; const float *v_curr = sys->vertexCos[l_curr->v]; const float *v_next = sys->vertexCos[l_next->v]; - const uint l_curr_index = l_curr - sys->mloop; + const uint l_curr_index = l_curr - sys->loops.data(); sys->ne_fa_num[l_curr->v] += 1; @@ -255,9 +232,9 @@ static void init_laplacian_matrix(LaplacianSystem *sys) sys->vweights[l_prev->v] += w1 + w2; } } - for (i = 0; i < sys->edges_num; i++) { - idv1 = sys->medges[i].v1; - idv2 = sys->medges[i].v2; + for (i = 0; i < sys->edges.size(); i++) { + idv1 = sys->edges[i].v1; + idv2 = sys->edges[i].v2; /* if is boundary, apply scale-dependent umbrella operator only with neighbors in boundary */ if (sys->ne_ed_num[idv1] != sys->ne_fa_num[idv1] && sys->ne_ed_num[idv2] != sys->ne_fa_num[idv2]) { @@ -272,15 +249,15 @@ static void fill_laplacian_matrix(LaplacianSystem *sys) int i; uint idv1, idv2; - for (i = 0; i < sys->polys_num; i++) { - const MPoly *mp = &sys->mpoly[i]; - const MLoop *l_next = &sys->mloop[mp->loopstart]; + for (i = 0; i < sys->polys.size(); i++) { + const MPoly *mp = &sys->polys[i]; + const MLoop *l_next = &sys->loops[mp->loopstart]; const MLoop *l_term = l_next + mp->totloop; const MLoop *l_prev = l_term - 2; const MLoop *l_curr = l_term - 1; for (; l_next != l_term; l_prev = l_curr, l_curr = l_next, l_next++) { - const uint l_curr_index = l_curr - sys->mloop; + const uint l_curr_index = l_curr - sys->loops.data(); /* Is ring if number of faces == number of edges around vertex. */ if (sys->ne_ed_num[l_curr->v] == sys->ne_fa_num[l_curr->v] && @@ -319,9 +296,9 @@ static void fill_laplacian_matrix(LaplacianSystem *sys) } } - for (i = 0; i < sys->edges_num; i++) { - idv1 = sys->medges[i].v1; - idv2 = sys->medges[i].v2; + for (i = 0; i < sys->edges.size(); i++) { + idv1 = sys->edges[i].v1; + idv2 = sys->edges[i].v2; /* Is boundary */ if (sys->ne_ed_num[idv1] != sys->ne_fa_num[idv1] && sys->ne_ed_num[idv2] != sys->ne_fa_num[idv2] && sys->zerola[idv1] == false && @@ -341,8 +318,7 @@ static void validate_solution(LaplacianSystem *sys, short flag, float lambda, fl float vini = 0.0f, vend = 0.0f; if (flag & MOD_LAPLACIANSMOOTH_PRESERVE_VOLUME) { - vini = compute_volume( - sys->vert_centroid, sys->vertexCos, sys->mpoly, sys->polys_num, sys->mloop); + vini = compute_volume(sys->vert_centroid, sys->vertexCos, sys->polys, sys->loops); } for (i = 0; i < sys->verts_num; i++) { if (sys->zerola[i] == false) { @@ -363,8 +339,7 @@ static void validate_solution(LaplacianSystem *sys, short flag, float lambda, fl } } if (flag & MOD_LAPLACIANSMOOTH_PRESERVE_VOLUME) { - vend = compute_volume( - sys->vert_centroid, sys->vertexCos, sys->mpoly, sys->polys_num, sys->mloop); + vend = compute_volume(sys->vert_centroid, sys->vertexCos, sys->polys, sys->loops); volume_preservation(sys, vini, vend, flag); } } @@ -380,14 +355,14 @@ static void laplaciansmoothModifier_do( int defgrp_index; const bool invert_vgroup = (smd->flag & MOD_LAPLACIANSMOOTH_INVERT_VGROUP) != 0; - sys = init_laplacian_system(mesh->totedge, mesh->totpoly, mesh->totloop, verts_num); + sys = init_laplacian_system(mesh->totedge, mesh->totloop, verts_num); if (!sys) { return; } - sys->mpoly = BKE_mesh_polys(mesh); - sys->mloop = BKE_mesh_loops(mesh); - sys->medges = BKE_mesh_edges(mesh); + sys->polys = mesh->polys(); + sys->loops = mesh->loops(); + sys->edges = mesh->edges(); sys->vertexCos = vertexCos; sys->min_area = 0.00001f; MOD_get_vgroup(ob, mesh, smd->defgrp_name, &dvert, &defgrp_index); diff --git a/source/blender/modifiers/intern/MOD_normal_edit.cc b/source/blender/modifiers/intern/MOD_normal_edit.cc index aecbff5c7be..a111f60f25a 100644 --- a/source/blender/modifiers/intern/MOD_normal_edit.cc +++ b/source/blender/modifiers/intern/MOD_normal_edit.cc @@ -529,7 +529,7 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd, } Mesh *result; - if (BKE_mesh_edges(mesh) == BKE_mesh_edges((Mesh *)ob->data)) { + if (mesh->edges().data() == ((Mesh *)ob->data)->edges().data()) { /* We need to duplicate data here, otherwise setting custom normals * (which may also affect sharp edges) could * modify original mesh, see #43671. */ @@ -540,13 +540,10 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd, } const int verts_num = result->totvert; - const int edges_num = result->totedge; - const int loops_num = result->totloop; - const int polys_num = result->totpoly; const float(*positions)[3] = BKE_mesh_vert_positions(result); - const MEdge *edges = BKE_mesh_edges(result); - const MPoly *polys = BKE_mesh_polys(result); - MLoop *loops = BKE_mesh_loops_for_write(result); + const blender::Span edges = result->edges(); + const blender::Span polys = result->polys(); + blender::MutableSpan loops = result->loops_for_write(); int defgrp_index; const MDeformVert *dvert; @@ -563,24 +560,24 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd, "sharp_edge", ATTR_DOMAIN_EDGE); short(*clnors)[2] = static_cast( - CustomData_get_layer_for_write(ldata, CD_CUSTOMLOOPNORMAL, loops_num)); + CustomData_get_layer_for_write(ldata, CD_CUSTOMLOOPNORMAL, loops.size())); if (use_current_clnors) { clnors = static_cast( - CustomData_get_layer_for_write(ldata, CD_CUSTOMLOOPNORMAL, loops_num)); + CustomData_get_layer_for_write(ldata, CD_CUSTOMLOOPNORMAL, loops.size())); loop_normals = static_cast( - MEM_malloc_arrayN(size_t(loops_num), sizeof(*loop_normals), __func__)); + MEM_malloc_arrayN(loops.size(), sizeof(*loop_normals), __func__)); BKE_mesh_normals_loop_split(positions, vert_normals, verts_num, - edges, - edges_num, - loops, + edges.data(), + edges.size(), + loops.data(), loop_normals, - loops_num, - polys, + loops.size(), + polys.data(), poly_normals, - polys_num, + polys.size(), true, result->smoothresh, sharp_edges.span.data(), @@ -591,7 +588,7 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd, if (clnors == nullptr) { clnors = static_cast( - CustomData_add_layer(ldata, CD_CUSTOMLOOPNORMAL, CD_SET_DEFAULT, nullptr, loops_num)); + CustomData_add_layer(ldata, CD_CUSTOMLOOPNORMAL, CD_SET_DEFAULT, nullptr, loops.size())); } MOD_get_vgroup(ob, result, enmd->defgrp_name, &dvert, &defgrp_index); @@ -612,13 +609,13 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd, use_invert_vgroup, positions, verts_num, - edges, - edges_num, + edges.data(), + edges.size(), sharp_edges.span.data(), - loops, - loops_num, - polys, - polys_num); + loops.data(), + loops.size(), + polys.data(), + polys.size()); } else if (enmd->mode == MOD_NORMALEDIT_MODE_DIRECTIONAL) { normalEditModifier_do_directional(enmd, @@ -636,13 +633,13 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd, use_invert_vgroup, positions, verts_num, - edges, - edges_num, + edges.data(), + edges.size(), sharp_edges.span.data(), - loops, - loops_num, - polys, - polys_num); + loops.data(), + loops.size(), + polys.data(), + polys.size()); } MEM_SAFE_FREE(loop_normals); diff --git a/source/blender/modifiers/intern/MOD_ocean.cc b/source/blender/modifiers/intern/MOD_ocean.cc index 6ca8c25ef28..ac818e7841a 100644 --- a/source/blender/modifiers/intern/MOD_ocean.cc +++ b/source/blender/modifiers/intern/MOD_ocean.cc @@ -154,8 +154,8 @@ static bool dependsOnNormals(ModifierData *md) struct GenerateOceanGeometryData { float (*vert_positions)[3]; - MPoly *mpolys; - MLoop *mloops; + blender::MutableSpan polys; + blender::MutableSpan loops; float (*mloopuvs)[2]; int res_x, res_y; @@ -191,8 +191,8 @@ static void generate_ocean_geometry_polys(void *__restrict userdata, for (x = 0; x < gogd->res_x; x++) { const int fi = y * gogd->res_x + x; const int vi = y * (gogd->res_x + 1) + x; - MPoly *mp = &gogd->mpolys[fi]; - MLoop *ml = &gogd->mloops[fi * 4]; + MPoly *mp = &gogd->polys[fi]; + MLoop *ml = &gogd->loops[fi * 4]; ml->v = vi; ml++; @@ -270,8 +270,8 @@ static Mesh *generate_ocean_geometry(OceanModifierData *omd, Mesh *mesh_orig, co BKE_mesh_copy_parameters_for_eval(result, mesh_orig); gogd.vert_positions = BKE_mesh_vert_positions_for_write(result); - gogd.mpolys = BKE_mesh_polys_for_write(result); - gogd.mloops = BKE_mesh_loops_for_write(result); + gogd.polys = result->polys_for_write(); + gogd.loops = result->loops_for_write(); TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); @@ -363,19 +363,17 @@ static Mesh *doOcean(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mes cfra_for_cache -= omd->bakestart; /* shift to 0 based */ float(*positions)[3] = BKE_mesh_vert_positions_for_write(result); - const MPoly *polys = BKE_mesh_polys(result); + const blender::Span polys = mesh->polys(); /* Add vertex-colors before displacement: allows lookup based on position. */ if (omd->flag & MOD_OCEAN_GENERATE_FOAM) { - const int polys_num = result->totpoly; - const int loops_num = result->totloop; - const MLoop *mloops = BKE_mesh_loops(result); + const blender::Span loops = result->loops(); MLoopCol *mloopcols = static_cast(CustomData_add_layer_named(&result->ldata, CD_PROP_BYTE_COLOR, CD_SET_DEFAULT, nullptr, - loops_num, + loops.size(), omd->foamlayername)); MLoopCol *mloopcols_spray = nullptr; @@ -384,23 +382,22 @@ static Mesh *doOcean(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mes CD_PROP_BYTE_COLOR, CD_SET_DEFAULT, nullptr, - loops_num, + loops.size(), omd->spraylayername)); } if (mloopcols) { /* unlikely to fail */ - const MPoly *mp; - for (i = 0, mp = polys; i < polys_num; i++, mp++) { - const MLoop *ml = &mloops[mp->loopstart]; - MLoopCol *mlcol = &mloopcols[mp->loopstart]; + for (const int i : polys.index_range()) { + const MLoop *ml = &loops[polys[i].loopstart]; + MLoopCol *mlcol = &mloopcols[polys[i].loopstart]; MLoopCol *mlcolspray = nullptr; if (omd->flag & MOD_OCEAN_GENERATE_SPRAY) { - mlcolspray = &mloopcols_spray[mp->loopstart]; + mlcolspray = &mloopcols_spray[polys[i].loopstart]; } - for (j = mp->totloop; j--; ml++, mlcol++) { + for (j = polys[i].totloop; j--; ml++, mlcol++) { const float *vco = positions[ml->v]; const float u = OCEAN_CO(size_co_inv, vco[0]); const float v = OCEAN_CO(size_co_inv, vco[1]); diff --git a/source/blender/modifiers/intern/MOD_particleinstance.cc b/source/blender/modifiers/intern/MOD_particleinstance.cc index 751ec2916b5..76bebddb4d7 100644 --- a/source/blender/modifiers/intern/MOD_particleinstance.cc +++ b/source/blender/modifiers/intern/MOD_particleinstance.cc @@ -314,12 +314,12 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * result = BKE_mesh_new_nomain_from_template(mesh, maxvert, maxedge, 0, maxloop, maxpoly); - const MPoly *orig_mpoly = BKE_mesh_polys(mesh); - const MLoop *orig_mloop = BKE_mesh_loops(mesh); + const blender::Span orig_polys = mesh->polys(); + const blender::Span orig_loops = mesh->loops(); float(*positions)[3] = BKE_mesh_vert_positions_for_write(result); - MEdge *edges = BKE_mesh_edges_for_write(result); - MPoly *mpoly = BKE_mesh_polys_for_write(result); - MLoop *mloop = BKE_mesh_loops_for_write(result); + blender::MutableSpan edges = result->edges_for_write(); + blender::MutableSpan polys = result->polys_for_write(); + blender::MutableSpan loops = result->loops_for_write(); MLoopCol *mloopcols_index = static_cast(CustomData_get_layer_named_for_write( &result->ldata, CD_PROP_BYTE_COLOR, pimd->index_layer_name, result->totloop)); @@ -477,23 +477,23 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * /* create polys and loops */ for (k = 0; k < totpoly; k++) { - const MPoly *inMP = orig_mpoly + k; - MPoly *mp = mpoly + p_skip * totpoly + k; + const MPoly *inMP = &orig_polys[k]; + MPoly *mp = &polys[p_skip * totpoly + k]; CustomData_copy_data(&mesh->pdata, &result->pdata, k, p_skip * totpoly + k, 1); *mp = *inMP; mp->loopstart += p_skip * totloop; { - const MLoop *inML = orig_mloop + inMP->loopstart; - MLoop *ml = mloop + mp->loopstart; + const MLoop *inML = &orig_loops[inMP->loopstart]; + MLoop *ml = &loops[mp->loopstart]; int j = mp->totloop; CustomData_copy_data(&mesh->ldata, &result->ldata, inMP->loopstart, mp->loopstart, j); for (; j; j--, ml++, inML++) { ml->v = inML->v + (p_skip * totvert); ml->e = inML->e + (p_skip * totedge); - const int ml_index = (ml - mloop); + const int ml_index = (ml - loops.data()); if (mloopcols_index != nullptr) { const int part_index = vert_part_index[ml->v]; store_float_in_vcol(&mloopcols_index[ml_index], diff --git a/source/blender/modifiers/intern/MOD_remesh.cc b/source/blender/modifiers/intern/MOD_remesh.cc index e57778841e2..f124acd132e 100644 --- a/source/blender/modifiers/intern/MOD_remesh.cc +++ b/source/blender/modifiers/intern/MOD_remesh.cc @@ -63,7 +63,7 @@ static void init_dualcon_mesh(DualConInput *input, Mesh *mesh) input->co_stride = sizeof(float[3]); input->totco = mesh->totvert; - input->mloop = (DualConLoop)BKE_mesh_loops(mesh); + input->mloop = (DualConLoop)mesh->loops().data(); input->loop_stride = sizeof(MLoop); input->looptri = (DualConTri)BKE_mesh_runtime_looptri_ensure(mesh); @@ -95,8 +95,8 @@ static void *dualcon_alloc_output(int totvert, int totquad) output->mesh = BKE_mesh_new_nomain(totvert, 0, 0, 4 * totquad, totquad); output->vert_positions = BKE_mesh_vert_positions_for_write(output->mesh); - output->polys = BKE_mesh_polys_for_write(output->mesh); - output->loops = BKE_mesh_loops_for_write(output->mesh); + output->polys = output->mesh->polys_for_write().data(); + output->loops = output->mesh->loops_for_write().data(); return output; } @@ -197,15 +197,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext * /*ctx*/, M MEM_freeN(output); } - if (rmd->flag & MOD_REMESH_SMOOTH_SHADING) { - MPoly *mpoly = BKE_mesh_polys_for_write(result); - int i, totpoly = result->totpoly; - - /* Apply smooth shading to output faces */ - for (i = 0; i < totpoly; i++) { - mpoly[i].flag |= ME_SMOOTH; - } - } + BKE_mesh_smooth_flag_set(result, rmd->flag & MOD_REMESH_SMOOTH_SHADING); BKE_mesh_copy_parameters_for_eval(result, mesh); BKE_mesh_calc_edges(result, true, false); diff --git a/source/blender/modifiers/intern/MOD_screw.cc b/source/blender/modifiers/intern/MOD_screw.cc index e7eed1c4dd3..bcf43748bee 100644 --- a/source/blender/modifiers/intern/MOD_screw.cc +++ b/source/blender/modifiers/intern/MOD_screw.cc @@ -186,7 +186,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * int mpoly_index = 0; uint step; - uint i, j; + uint j; uint i1, i2; uint step_tot = use_render_params ? ltmd->render_steps : ltmd->steps; const bool do_flip = (ltmd->flag & MOD_SCREW_NORMAL_FLIP) != 0; @@ -385,14 +385,14 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * CustomData_free_layers(&result->pdata, CD_ORIGINDEX, result->totedge); const float(*vert_positions_orig)[3] = BKE_mesh_vert_positions(mesh); - const MEdge *medge_orig = BKE_mesh_edges(mesh); - const MPoly *mpoly_orig = BKE_mesh_polys(mesh); - const MLoop *mloop_orig = BKE_mesh_loops(mesh); + const blender::Span edges_orig = mesh->edges(); + const blender::Span polys_orig = mesh->polys(); + const blender::Span loops_orig = mesh->loops(); float(*vert_positions_new)[3] = BKE_mesh_vert_positions_for_write(result); - MEdge *medge_new = BKE_mesh_edges_for_write(result); - MPoly *mpoly_new = BKE_mesh_polys_for_write(result); - MLoop *mloop_new = BKE_mesh_loops_for_write(result); + blender::MutableSpan edges_new = result->edges_for_write(); + blender::MutableSpan polys_new = result->polys_for_write(); + blender::MutableSpan loops_new = result->loops_for_write(); if (!CustomData_has_layer(&result->pdata, CD_ORIGINDEX)) { CustomData_add_layer(&result->pdata, CD_ORIGINDEX, CD_SET_DEFAULT, nullptr, int(maxPolys)); @@ -416,7 +416,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * } if (ltmd->flag & MOD_SCREW_UV_STRETCH_V) { - for (i = 0; i < totvert; i++) { + for (uint i = 0; i < totvert; i++) { const float v = dist_signed_squared_to_plane_v3(vert_positions_orig[i], uv_axis_plane); uv_v_minmax[0] = min_ff(v, uv_v_minmax[0]); uv_v_minmax[1] = max_ff(v, uv_v_minmax[1]); @@ -432,9 +432,9 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * /* Set the locations of the first set of verts */ /* Copy the first set of edges */ - const MEdge *med_orig = medge_orig; - med_new = medge_new; - for (i = 0; i < totedge; i++, med_orig++, med_new++) { + const MEdge *med_orig = edges_orig.data(); + med_new = edges_new.data(); + for (uint i = 0; i < totedge; i++, med_orig++, med_new++) { med_new->v1 = med_orig->v1; med_new->v2 = med_orig->v2; med_new->flag = med_orig->flag; @@ -442,7 +442,6 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * /* build polygon -> edge map */ if (totpoly) { - const MPoly *mp_orig; edge_poly_map = static_cast( MEM_malloc_arrayN(totedge, sizeof(*edge_poly_map), __func__)); @@ -452,19 +451,19 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * MEM_malloc_arrayN(totvert, sizeof(*vert_loop_map), __func__)); memset(vert_loop_map, 0xff, sizeof(*vert_loop_map) * totvert); - for (i = 0, mp_orig = mpoly_orig; i < totpoly; i++, mp_orig++) { - uint loopstart = uint(mp_orig->loopstart); - uint loopend = loopstart + uint(mp_orig->totloop); + for (const int64_t i : polys_orig.index_range()) { + uint loopstart = uint(polys_orig[i].loopstart); + uint loopend = loopstart + uint(polys_orig[i].totloop); - const MLoop *ml_orig = &mloop_orig[loopstart]; + const MLoop *ml_orig = &loops_orig[loopstart]; uint k; for (k = loopstart; k < loopend; k++, ml_orig++) { - edge_poly_map[ml_orig->e] = i; + edge_poly_map[ml_orig->e] = uint(i); vert_loop_map[ml_orig->v] = k; /* also order edges based on faces */ - if (medge_new[ml_orig->e].v1 != ml_orig->v) { - std::swap(medge_new[ml_orig->e].v1, medge_new[ml_orig->e].v2); + if (edges_new[ml_orig->e].v1 != ml_orig->v) { + std::swap(edges_new[ml_orig->e].v1, edges_new[ml_orig->e].v2); } } } @@ -486,11 +485,11 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * if (totedge != 0) { // printf("\n\n\n\n\nStarting Modifier\n"); /* set edge users */ - med_new = medge_new; + med_new = edges_new.data(); if (ob_axis != nullptr) { /* `mtx_tx` is initialized early on. */ - for (i = 0; i < totvert; i++, vc++) { + for (uint i = 0; i < totvert; i++, vc++) { vc->co[0] = vert_positions_new[i][0] = vert_positions_orig[i][0]; vc->co[1] = vert_positions_new[i][1] = vert_positions_orig[i][1]; vc->co[2] = vert_positions_new[i][2] = vert_positions_orig[i][2]; @@ -508,7 +507,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * } } else { - for (i = 0; i < totvert; i++, vc++) { + for (uint i = 0; i < totvert; i++, vc++) { vc->co[0] = vert_positions_new[i][0] = vert_positions_orig[i][0]; vc->co[1] = vert_positions_new[i][1] = vert_positions_orig[i][1]; vc->co[2] = vert_positions_new[i][2] = vert_positions_orig[i][2]; @@ -526,7 +525,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * } /* this loop builds connectivity info for verts */ - for (i = 0; i < totedge; i++, med_new++) { + for (uint i = 0; i < totedge; i++, med_new++) { vc = &vert_connect[med_new->v1]; if (vc->v[0] == SV_UNUSED) { /* unused */ @@ -559,7 +558,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * /* find the first vert */ vc = vert_connect; - for (i = 0; i < totvert; i++, vc++) { + for (uint i = 0; i < totvert; i++, vc++) { /* Now do search for connected verts, order all edges and flip them * so resulting faces are flipped the right way */ vc_tot_linked = 0; /* count the number of linked verts for this loop */ @@ -738,7 +737,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * } } else { - for (i = 0; i < totvert; i++) { + for (uint i = 0; i < totvert; i++) { copy_v3_v3(vert_positions_new[i], vert_positions_orig[i]); } } @@ -805,7 +804,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * /* last loop of edges, previous loop doesn't account for the last set of edges */ const uint varray_stride = (step_tot - 1) * totvert; - for (i = 0; i < totvert; i++) { + for (uint i = 0; i < totvert; i++) { med_new->v1 = i; med_new->v2 = varray_stride + i; med_new->flag = 0; @@ -813,9 +812,9 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * } } - mp_new = mpoly_new; - ml_new = mloop_new; - med_new_firstloop = medge_new; + mp_new = polys_new.data(); + ml_new = loops_new.data(); + med_new_firstloop = edges_new.data(); /* more of an offset in this case */ edge_offset = totedge + (totvert * (step_tot - (close ? 0 : 1))); @@ -823,15 +822,15 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * const int *src_material_index = BKE_mesh_material_indices(mesh); int *dst_material_index = BKE_mesh_material_indices_for_write(result); - for (i = 0; i < totedge; i++, med_new_firstloop++) { + for (uint i = 0; i < totedge; i++, med_new_firstloop++) { const uint step_last = step_tot - (close ? 1 : 2); const uint mpoly_index_orig = totpoly ? edge_poly_map[i] : UINT_MAX; const bool has_mpoly_orig = (mpoly_index_orig != UINT_MAX); float uv_v_offset_a, uv_v_offset_b; const uint mloop_index_orig[2] = { - vert_loop_map ? vert_loop_map[medge_new[i].v1] : UINT_MAX, - vert_loop_map ? vert_loop_map[medge_new[i].v2] : UINT_MAX, + vert_loop_map ? vert_loop_map[edges_new[i].v1] : UINT_MAX, + vert_loop_map ? vert_loop_map[edges_new[i].v2] : UINT_MAX, }; const bool has_mloop_orig = mloop_index_orig[0] != UINT_MAX; @@ -849,8 +848,8 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * } if (has_mloop_orig == false && mloopuv_layers_tot) { - uv_v_offset_a = dist_signed_to_plane_v3(vert_positions_new[medge_new[i].v1], uv_axis_plane); - uv_v_offset_b = dist_signed_to_plane_v3(vert_positions_new[medge_new[i].v2], uv_axis_plane); + uv_v_offset_a = dist_signed_to_plane_v3(vert_positions_new[edges_new[i].v1], uv_axis_plane); + uv_v_offset_b = dist_signed_to_plane_v3(vert_positions_new[edges_new[i].v2], uv_axis_plane); if (ltmd->flag & MOD_SCREW_UV_STRETCH_V) { uv_v_offset_a = (uv_v_offset_a - uv_v_minmax[0]) * uv_v_range_inv; @@ -876,7 +875,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * /* Loop-Custom-Data */ if (has_mloop_orig) { - int l_index = int(ml_new - mloop_new); + int l_index = int(ml_new - loops_new.data()); CustomData_copy_data( &mesh->ldata, &result->ldata, int(mloop_index_orig[0]), l_index + 0, 1); @@ -903,7 +902,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * } else { if (mloopuv_layers_tot) { - int l_index = int(ml_new - mloop_new); + int l_index = int(ml_new - loops_new.data()); uint uv_lay; const float uv_u_offset_a = float(step) * uv_u_scale; diff --git a/source/blender/modifiers/intern/MOD_solidify_extrude.cc b/source/blender/modifiers/intern/MOD_solidify_extrude.cc index 9375a3eb59f..01f1c0e0af5 100644 --- a/source/blender/modifiers/intern/MOD_solidify_extrude.cc +++ b/source/blender/modifiers/intern/MOD_solidify_extrude.cc @@ -61,29 +61,23 @@ static void mesh_calc_hq_normal(Mesh *mesh, #endif ) { - int i; - const int verts_num = mesh->totvert; - const int edges_num = mesh->totedge; - const int polys_num = mesh->totpoly; - const MPoly *mpoly = BKE_mesh_polys(mesh); - const MLoop *mloop = BKE_mesh_loops(mesh); - const MEdge *medge = BKE_mesh_edges(mesh); - - const MPoly *mp = mpoly; + const blender::Span edges = mesh->edges(); + const blender::Span polys = mesh->polys(); + const blender::Span loops = mesh->loops(); { - EdgeFaceRef *edge_ref_array = MEM_cnew_array(size_t(edges_num), __func__); + EdgeFaceRef *edge_ref_array = MEM_cnew_array(size_t(edges.size()), __func__); EdgeFaceRef *edge_ref; float edge_normal[3]; /* Add an edge reference if it's not there, pointing back to the face index. */ - for (i = 0; i < polys_num; i++, mp++) { + for (const int i : polys.index_range()) { int j; - const MLoop *ml = mloop + mp->loopstart; + const MLoop *ml = &loops[polys[i].loopstart]; - for (j = 0; j < mp->totloop; j++, ml++) { + for (j = 0; j < polys[i].totloop; j++, ml++) { /* --- add edge ref to face --- */ edge_ref = &edge_ref_array[ml->e]; if (!edgeref_is_init(edge_ref)) { @@ -104,8 +98,10 @@ static void mesh_calc_hq_normal(Mesh *mesh, } } + int i; const MEdge *ed; - for (i = 0, ed = medge, edge_ref = edge_ref_array; i < edges_num; i++, ed++, edge_ref++) { + for (i = 0, ed = edges.data(), edge_ref = edge_ref_array; i < edges.size(); + i++, ed++, edge_ref++) { /* Get the edge vert indices, and edge value (the face indices that use it) */ if (edgeref_is_init(edge_ref) && (edge_ref->p1 != -1)) { @@ -136,7 +132,7 @@ static void mesh_calc_hq_normal(Mesh *mesh, /* normalize vertex normals and assign */ const float(*vert_normals)[3] = BKE_mesh_vertex_normals_ensure(mesh); - for (i = 0; i < verts_num; i++) { + for (int i = 0; i < verts_num; i++) { if (normalize_v3(r_vert_nors[i]) == 0.0f) { copy_v3_v3(r_vert_nors[i], vert_normals[i]); } @@ -214,9 +210,9 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex MOD_get_vgroup(ctx->object, mesh, smd->defgrp_name, &dvert, &defgrp_index); const float(*orig_vert_positions)[3] = BKE_mesh_vert_positions(mesh); - const MEdge *orig_medge = BKE_mesh_edges(mesh); - const MPoly *orig_mpoly = BKE_mesh_polys(mesh); - const MLoop *orig_mloop = BKE_mesh_loops(mesh); + const blender::Span orig_edges = mesh->edges(); + const blender::Span orig_polys = mesh->polys(); + const blender::Span orig_loops = mesh->loops(); if (need_poly_normals) { /* calculate only face normals */ @@ -248,24 +244,25 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex #endif const MEdge *ed; - for (eidx = 0, ed = orig_medge; eidx < edges_num; eidx++, ed++) { + for (eidx = 0, ed = orig_edges.data(); eidx < edges_num; eidx++, ed++) { edge_users[eidx] = INVALID_UNUSED; } - const MPoly *mp; - for (i = 0, mp = orig_mpoly; i < polys_num; i++, mp++) { + for (const int64_t i : orig_polys.index_range()) { + const MPoly &poly = orig_polys[i]; int j; - const MLoop *ml = orig_mloop + mp->loopstart; - const MLoop *ml_prev = ml + (mp->totloop - 1); + const MLoop *ml = &orig_loops[poly.loopstart]; + const MLoop *ml_prev = ml + (poly.totloop - 1); - for (j = 0; j < mp->totloop; j++, ml++) { + for (j = 0; j < poly.totloop; j++, ml++) { /* add edge user */ eidx = ml_prev->e; if (edge_users[eidx] == INVALID_UNUSED) { - ed = orig_medge + eidx; + ed = &orig_edges[eidx]; BLI_assert(ELEM(ml_prev->v, ed->v1, ed->v2) && ELEM(ml->v, ed->v1, ed->v2)); - edge_users[eidx] = (ml_prev->v > ml->v) == (ed->v1 < ed->v2) ? i : (i + polys_num); + edge_users[eidx] = (ml_prev->v > ml->v) == (ed->v1 < ed->v2) ? uint(i) : + (uint(i) + polys_num); edge_order[eidx] = j; } else { @@ -275,7 +272,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex } } - for (eidx = 0, ed = orig_medge; eidx < edges_num; eidx++, ed++) { + for (eidx = 0, ed = orig_edges.data(); eidx < edges_num; eidx++, ed++) { if (!ELEM(edge_users[eidx], INVALID_UNUSED, INVALID_PAIR)) { BLI_BITMAP_ENABLE(orig_mvert_tag, ed->v1); BLI_BITMAP_ENABLE(orig_mvert_tag, ed->v2); @@ -335,9 +332,9 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex int((polys_num * stride) + newPolys)); float(*vert_positions)[3] = BKE_mesh_vert_positions_for_write(result); - MEdge *medge = BKE_mesh_edges_for_write(result); - MPoly *mpoly = BKE_mesh_polys_for_write(result); - MLoop *mloop = BKE_mesh_loops_for_write(result); + blender::MutableSpan edges = result->edges_for_write(); + blender::MutableSpan polys = result->polys_for_write(); + blender::MutableSpan loops = result->loops_for_write(); if (do_shell) { CustomData_copy_data(&mesh->vdata, &result->vdata, 0, 0, int(verts_num)); @@ -373,8 +370,8 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex MEdge *ed_src, *ed_dst; CustomData_copy_data(&mesh->edata, &result->edata, i, j, 1); - ed_src = &medge[i]; - ed_dst = &medge[j]; + ed_src = &edges[i]; + ed_dst = &edges[j]; ed_dst->v1 = old_vert_arr[ed_src->v1] + verts_num; ed_dst->v2 = old_vert_arr[ed_src->v2] + verts_num; j++; @@ -419,7 +416,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex if (do_shell) { uint i; - MPoly *mp = mpoly + polys_num; + MPoly *mp = &polys[polys_num]; for (i = 0; i < mesh->totpoly; i++, mp++) { const int loop_end = mp->totloop - 1; MLoop *ml2; @@ -428,7 +425,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex /* reverses the loop direction (MLoop.v as well as custom-data) * MLoop.e also needs to be corrected too, done in a separate loop below. */ - ml2 = mloop + mp->loopstart + mesh->totloop; + ml2 = &loops[mp->loopstart + mesh->totloop]; #if 0 for (j = 0; j < mp->totloop; j++) { CustomData_copy_data(&mesh->ldata, @@ -451,8 +448,8 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex #endif if (mat_ofs) { - dst_material_index[mp - mpoly] += mat_ofs; - CLAMP(dst_material_index[mp - mpoly], 0, mat_nr_max); + dst_material_index[mp - polys.data()] += mat_ofs; + CLAMP(dst_material_index[mp - polys.data()], 0, mat_nr_max); } e = ml2[0].e; @@ -470,7 +467,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex } MEdge *ed; - for (i = 0, ed = medge + edges_num; i < edges_num; i++, ed++) { + for (i = 0, ed = &edges[edges_num]; i < edges_num; i++, ed++) { ed->v1 += verts_num; ed->v2 += verts_num; } @@ -494,10 +491,10 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex vert_lens = static_cast(MEM_malloc_arrayN(verts_num, sizeof(float), "vert_lens")); copy_vn_fl(vert_lens, int(verts_num), FLT_MAX); for (uint i = 0; i < edges_num; i++) { - const float ed_len_sq = len_squared_v3v3(vert_positions[medge[i].v1], - vert_positions[medge[i].v2]); - vert_lens[medge[i].v1] = min_ff(vert_lens[medge[i].v1], ed_len_sq); - vert_lens[medge[i].v2] = min_ff(vert_lens[medge[i].v2], ed_len_sq); + const float ed_len_sq = len_squared_v3v3(vert_positions[edges[i].v1], + vert_positions[edges[i].v2]); + vert_lens[edges[i].v1] = min_ff(vert_lens[edges[i].v1], ed_len_sq); + vert_lens[edges[i].v2] = min_ff(vert_lens[edges[i].v2], ed_len_sq); } } @@ -520,19 +517,19 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex edge_user_pairs[eidx][0] = INVALID_UNUSED; edge_user_pairs[eidx][1] = INVALID_UNUSED; } - const MPoly *mp = orig_mpoly; - for (uint i = 0; i < polys_num; i++, mp++) { - const MLoop *ml = orig_mloop + mp->loopstart; - const MLoop *ml_prev = ml + (mp->totloop - 1); + for (const int64_t i : orig_polys.index_range()) { + const MPoly &poly = orig_polys[i]; + const MLoop *ml = &orig_loops[poly.loopstart]; + const MLoop *ml_prev = ml + (poly.totloop - 1); - for (uint j = 0; j < mp->totloop; j++, ml++) { + for (uint j = 0; j < poly.totloop; j++, ml++) { /* add edge user */ eidx = ml_prev->e; - const MEdge *ed = orig_medge + eidx; + const MEdge *ed = &orig_edges[eidx]; BLI_assert(ELEM(ml_prev->v, ed->v1, ed->v2) && ELEM(ml->v, ed->v1, ed->v2)); char flip = char((ml_prev->v > ml->v) == (ed->v1 < ed->v2)); if (edge_user_pairs[eidx][flip] == INVALID_UNUSED) { - edge_user_pairs[eidx][flip] = i; + edge_user_pairs[eidx][flip] = uint(i); } else { edge_user_pairs[eidx][0] = INVALID_PAIR; @@ -541,7 +538,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex ml_prev = ml; } } - const MEdge *ed = orig_medge; + const MEdge *ed = orig_edges.data(); float e[3]; for (uint i = 0; i < edges_num; i++, ed++) { if (!ELEM(edge_user_pairs[i][0], INVALID_UNUSED, INVALID_PAIR) && @@ -721,7 +718,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex } const MPoly *mp; - for (i = 0, mp = mpoly; i < polys_num; i++, mp++) { + for (i = 0, mp = polys.data(); i < polys_num; i++, mp++) { /* #BKE_mesh_calc_poly_angles logic is inlined here */ float nor_prev[3]; float nor_next[3]; @@ -729,7 +726,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex int i_curr = mp->totloop - 1; int i_next = 0; - const MLoop *ml = &mloop[mp->loopstart]; + const MLoop *ml = &loops[mp->loopstart]; sub_v3_v3v3(nor_prev, vert_positions[ml[i_curr - 1].v], vert_positions[ml[i_curr].v]); normalize_v3(nor_prev); @@ -818,18 +815,19 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex edge_user_pairs[eidx][0] = INVALID_UNUSED; edge_user_pairs[eidx][1] = INVALID_UNUSED; } - for (i = 0, mp = orig_mpoly; i < polys_num; i++, mp++) { - const MLoop *ml = orig_mloop + mp->loopstart; - const MLoop *ml_prev = ml + (mp->totloop - 1); + for (const int i : orig_polys.index_range()) { + const MPoly &poly = orig_polys[i]; + const MLoop *ml = &orig_loops[poly.loopstart]; + const MLoop *ml_prev = ml + (poly.totloop - 1); - for (int j = 0; j < mp->totloop; j++, ml++) { + for (int j = 0; j < poly.totloop; j++, ml++) { /* add edge user */ eidx = ml_prev->e; - const MEdge *ed = orig_medge + eidx; + const MEdge *ed = &orig_edges[eidx]; BLI_assert(ELEM(ml_prev->v, ed->v1, ed->v2) && ELEM(ml->v, ed->v1, ed->v2)); char flip = char((ml_prev->v > ml->v) == (ed->v1 < ed->v2)); if (edge_user_pairs[eidx][flip] == INVALID_UNUSED) { - edge_user_pairs[eidx][flip] = i; + edge_user_pairs[eidx][flip] = uint(i); } else { edge_user_pairs[eidx][0] = INVALID_PAIR; @@ -838,7 +836,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex ml_prev = ml; } } - const MEdge *ed = orig_medge; + const MEdge *ed = orig_edges.data(); float e[3]; for (i = 0; i < edges_num; i++, ed++) { if (!ELEM(edge_user_pairs[i][0], INVALID_UNUSED, INVALID_PAIR) && @@ -872,10 +870,10 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex const float offset_sq = offset * offset; copy_vn_fl(vert_lens_sq, int(verts_num), FLT_MAX); for (i = 0; i < edges_num; i++) { - const float ed_len = len_squared_v3v3(vert_positions[medge[i].v1], - vert_positions[medge[i].v2]); - vert_lens_sq[medge[i].v1] = min_ff(vert_lens_sq[medge[i].v1], ed_len); - vert_lens_sq[medge[i].v2] = min_ff(vert_lens_sq[medge[i].v2], ed_len); + const float ed_len = len_squared_v3v3(vert_positions[edges[i].v1], + vert_positions[edges[i].v2]); + vert_lens_sq[edges[i].v1] = min_ff(vert_lens_sq[edges[i].v1], ed_len); + vert_lens_sq[edges[i].v2] = min_ff(vert_lens_sq[edges[i].v2], ed_len); } if (do_angle_clamp) { for (i = 0; i < verts_num; i++) { @@ -1050,7 +1048,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex origindex_edge = static_cast( CustomData_get_layer_for_write(&result->edata, CD_ORIGINDEX, result->totedge)); orig_ed = (origindex_edge) ? &origindex_edge[(edges_num * stride) + newEdges] : nullptr; - MEdge *ed = &medge[(edges_num * stride) + newEdges]; /* start after copied edges */ + MEdge *ed = &edges[(edges_num * stride) + newEdges]; /* start after copied edges */ for (i = 0; i < rimVerts; i++, ed++) { ed->v1 = new_vert_arr[i]; ed->v2 = (do_shell ? new_vert_arr[i] : i) + verts_num; @@ -1061,13 +1059,13 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex } if (crease_rim) { - result_edge_crease[ed - medge] = crease_rim; + result_edge_crease[ed - edges.data()] = crease_rim; } } /* faces */ - MPoly *mp = mpoly + (polys_num * stride); - MLoop *ml = mloop + (loops_num * stride); + MPoly *mp = &polys[polys_num * stride]; + MLoop *ml = &loops[loops_num * stride]; j = 0; for (i = 0; i < newPolys; i++, mp++) { uint eidx = new_edge_arr[i]; @@ -1083,22 +1081,22 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex flip = false; } - ed = medge + eidx; + ed = &edges[eidx]; /* copy most of the face settings */ CustomData_copy_data( &mesh->pdata, &result->pdata, int(pidx), int((polys_num * stride) + i), 1); mp->loopstart = int(j + (loops_num * stride)); - mp->flag = mpoly[pidx].flag; + mp->flag = polys[pidx].flag; /* notice we use 'mp->totloop' which is later overwritten, * we could lookup the original face but there's no point since this is a copy * and will have the same value, just take care when changing order of assignment */ /* prev loop */ - k1 = mpoly[pidx].loopstart + (((edge_order[eidx] - 1) + mp->totloop) % mp->totloop); + k1 = polys[pidx].loopstart + (((edge_order[eidx] - 1) + mp->totloop) % mp->totloop); - k2 = mpoly[pidx].loopstart + (edge_order[eidx]); + k2 = polys[pidx].loopstart + (edge_order[eidx]); mp->totloop = 4; @@ -1141,12 +1139,12 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex /* use the next material index if option enabled */ if (mat_ofs_rim) { - dst_material_index[mp - mpoly] += mat_ofs_rim; - CLAMP(dst_material_index[mp - mpoly], 0, mat_nr_max); + dst_material_index[mp - polys.data()] += mat_ofs_rim; + CLAMP(dst_material_index[mp - polys.data()], 0, mat_nr_max); } if (crease_outer) { /* crease += crease_outer; without wrapping */ - float *cr = &(result_edge_crease[ed - medge]); + float *cr = &(result_edge_crease[ed - edges.data()]); float tcr = *cr + crease_outer; *cr = tcr > 1.0f ? 1.0f : tcr; } @@ -1174,8 +1172,8 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex #ifdef SOLIDIFY_SIDE_NORMALS if (do_side_normals) { - const MEdge *ed_orig = medge; - ed = medge + (edges_num * stride); + const MEdge *ed_orig = edges.data(); + ed = &edges[edges_num * stride]; for (i = 0; i < rimVerts; i++, ed++, ed_orig++) { float nor_cpy[3]; int k; diff --git a/source/blender/modifiers/intern/MOD_solidify_nonmanifold.cc b/source/blender/modifiers/intern/MOD_solidify_nonmanifold.cc index 74a020d8a89..80bf41c4a68 100644 --- a/source/blender/modifiers/intern/MOD_solidify_nonmanifold.cc +++ b/source/blender/modifiers/intern/MOD_solidify_nonmanifold.cc @@ -187,9 +187,9 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, const bool do_flat_faces = dvert && (smd->flag & MOD_SOLIDIFY_NONMANIFOLD_FLAT_FACES); const float(*orig_vert_positions)[3] = BKE_mesh_vert_positions(mesh); - const MEdge *orig_medge = BKE_mesh_edges(mesh); - const MPoly *orig_mpoly = BKE_mesh_polys(mesh); - const MLoop *orig_mloop = BKE_mesh_loops(mesh); + const blender::Span orig_edges = mesh->edges(); + const blender::Span orig_polys = mesh->polys(); + const blender::Span orig_loops = mesh->loops(); /* These might be null. */ const float *orig_vert_bweight = static_cast( @@ -220,11 +220,11 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, uint largest_ngon = 3; /* Calculate face to #NewFaceRef map. */ { - const MPoly *mp = orig_mpoly; - for (uint i = 0; i < polys_num; i++, mp++) { + for (const int i : orig_polys.index_range()) { + const MPoly &poly = orig_polys[i]; /* Make normals for faces without area (should really be avoided though). */ if (len_squared_v3(poly_nors[i]) < 0.5f) { - const MEdge *e = orig_medge + orig_mloop[mp->loopstart].e; + const MEdge *e = &orig_edges[orig_loops[poly.loopstart].e]; float edgedir[3]; sub_v3_v3v3(edgedir, orig_vert_positions[e->v2], orig_vert_positions[e->v1]); if (fabsf(edgedir[2]) < fabsf(edgedir[1])) { @@ -239,32 +239,32 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, } NewEdgeRef **link_edges = static_cast( - MEM_calloc_arrayN(uint(mp->totloop), sizeof(*link_edges), __func__)); + MEM_calloc_arrayN(uint(poly.totloop), sizeof(*link_edges), __func__)); NewFaceRef new_face_ref_a{}; - new_face_ref_a.face = mp; - new_face_ref_a.index = i; + new_face_ref_a.face = &poly; + new_face_ref_a.index = uint(i); new_face_ref_a.reversed = false; new_face_ref_a.link_edges = link_edges; face_sides_arr[i * 2] = new_face_ref_a; link_edges = static_cast( - MEM_calloc_arrayN(uint(mp->totloop), sizeof(*link_edges), __func__)); + MEM_calloc_arrayN(uint(poly.totloop), sizeof(*link_edges), __func__)); NewFaceRef new_face_ref_b{}; - new_face_ref_b.face = mp; - new_face_ref_b.index = i; + new_face_ref_b.face = &poly; + new_face_ref_b.index = uint(i); new_face_ref_b.reversed = true; new_face_ref_b.link_edges = link_edges; face_sides_arr[i * 2 + 1] = new_face_ref_b; - if (mp->totloop > largest_ngon) { - largest_ngon = uint(mp->totloop); + if (poly.totloop > largest_ngon) { + largest_ngon = uint(poly.totloop); } /* add to final mesh face count */ if (do_shell) { new_polys_num += 2; - new_loops_num += uint(mp->totloop * 2); + new_loops_num += uint(poly.totloop * 2); } } } @@ -273,10 +273,10 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, MEM_calloc_arrayN(edges_num, sizeof(*edge_adj_faces_len), __func__)); /* Count for each edge how many faces it has adjacent. */ { - const MPoly *mp = orig_mpoly; - for (uint i = 0; i < polys_num; i++, mp++) { - const MLoop *ml = orig_mloop + mp->loopstart; - for (uint j = 0; j < mp->totloop; j++, ml++) { + for (const int64_t i : orig_polys.index_range()) { + const MPoly &poly = orig_polys[i]; + const MLoop *ml = &orig_loops[poly.loopstart]; + for (uint j = 0; j < poly.totloop; j++, ml++) { edge_adj_faces_len[ml->e]++; } } @@ -323,12 +323,12 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, /* Create link_faces for edges. */ { - const MPoly *mp = orig_mpoly; - for (uint i = 0; i < polys_num; i++, mp++) { - const MLoop *ml = orig_mloop + mp->loopstart; - for (uint j = 0; j < mp->totloop; j++, ml++) { + for (const int64_t i : orig_polys.index_range()) { + const MPoly &poly = orig_polys[i]; + const MLoop *ml = &orig_loops[poly.loopstart]; + for (uint j = 0; j < poly.totloop; j++, ml++) { const uint edge = ml->e; - const bool reversed = orig_medge[edge].v2 != ml->v; + const bool reversed = orig_edges[edge].v2 != ml->v; OldEdgeFaceRef *old_face_edge_ref = edge_adj_faces[edge]; if (old_face_edge_ref == nullptr) { const uint len = edge_adj_faces_len[edge]; @@ -337,7 +337,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, MEM_malloc_arrayN(len, sizeof(*adj_faces), __func__)); bool *adj_faces_reversed = static_cast( MEM_malloc_arrayN(len, sizeof(*adj_faces_reversed), __func__)); - adj_faces[0] = i; + adj_faces[0] = uint(i); for (uint k = 1; k < len; k++) { adj_faces[k] = MOD_SOLIDIFY_EMPTY_TAG; } @@ -350,7 +350,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, else { for (uint k = 1; k < old_face_edge_ref->faces_len; k++) { if (old_face_edge_ref->faces[k] == MOD_SOLIDIFY_EMPTY_TAG) { - old_face_edge_ref->faces[k] = i; + old_face_edge_ref->faces[k] = uint(i); old_face_edge_ref->faces_reversed[k] = reversed; break; } @@ -373,7 +373,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, uint *combined_verts = static_cast( MEM_calloc_arrayN(verts_num, sizeof(*combined_verts), __func__)); - const MEdge *ed = orig_medge; + const MEdge *ed = orig_edges.data(); for (uint i = 0; i < edges_num; i++, ed++) { if (edge_adj_faces_len[i] > 0) { uint v1 = vm[ed->v1]; @@ -395,14 +395,14 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, bool can_merge = true; for (uint k = 0; k < edges_num && can_merge; k++) { if (k != i && edge_adj_faces_len[k] > 0 && - (ELEM(vm[orig_medge[k].v1], v1, v2) != ELEM(vm[orig_medge[k].v2], v1, v2))) { + (ELEM(vm[orig_edges[k].v1], v1, v2) != ELEM(vm[orig_edges[k].v2], v1, v2))) { for (uint j = 0; j < edge_adj_faces[k]->faces_len && can_merge; j++) { - const MPoly *mp = orig_mpoly + edge_adj_faces[k]->faces[j]; + const MPoly *mp = &orig_polys[edge_adj_faces[k]->faces[j]]; uint changes = 0; int cur = mp->totloop - 1; for (int next = 0; next < mp->totloop && changes <= 2; next++) { - uint cur_v = vm[orig_mloop[mp->loopstart + cur].v]; - uint next_v = vm[orig_mloop[mp->loopstart + next].v]; + uint cur_v = vm[orig_loops[mp->loopstart + cur].v]; + uint next_v = vm[orig_loops[mp->loopstart + next].v]; changes += (ELEM(cur_v, v1, v2) != ELEM(next_v, v1, v2)); cur = next; } @@ -449,7 +449,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, } } /* remove zero faces in a second pass */ - ed = orig_medge; + ed = orig_edges.data(); for (uint i = 0; i < edges_num; i++, ed++) { const uint v1 = vm[ed->v1]; const uint v2 = vm[ed->v2]; @@ -459,8 +459,8 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, const uint face = edge_adj_faces[i]->faces[j]; if (!face_singularity[face]) { bool is_singularity = true; - for (uint k = 0; k < orig_mpoly[face].totloop; k++) { - if (vm[orig_mloop[uint(orig_mpoly[face].loopstart) + k].v] != v1) { + for (uint k = 0; k < orig_polys[face].totloop; k++) { + if (vm[orig_loops[uint(orig_polys[face].loopstart) + k].v] != v1) { is_singularity = false; break; } @@ -493,7 +493,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, /* Create vert_adj_edges for verts. */ { - const MEdge *ed = orig_medge; + const MEdge *ed = orig_edges.data(); for (uint i = 0; i < edges_num; i++, ed++) { if (edge_adj_faces_len[i] > 0) { const uint vs[2] = {vm[ed->v1], vm[ed->v2]}; @@ -525,12 +525,12 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, old_edge_vert_ref->edges_len++; break; } - if (vm[orig_medge[edge].v1] == vs[1 - j]) { + if (vm[orig_edges[edge].v1] == vs[1 - j]) { invalid_edge_index = edge + 1; invalid_edge_reversed = (j == 0); break; } - if (vm[orig_medge[edge].v2] == vs[1 - j]) { + if (vm[orig_edges[edge].v2] == vs[1 - j]) { invalid_edge_index = edge + 1; invalid_edge_reversed = (j == 1); break; @@ -613,7 +613,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, /* Filter duplicate polys. */ { - const MEdge *ed = orig_medge; + const MEdge *ed = orig_edges.data(); /* Iterate over edges and only check the faces around an edge for duplicates * (performance optimization). */ for (uint i = 0; i < edges_num; i++, ed++) { @@ -626,17 +626,17 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, /* For each face pair check if they have equal verts. */ for (uint j = 0; j < adj_len; j++) { const uint face = adj_faces->faces[j]; - const int j_loopstart = orig_mpoly[face].loopstart; - const int totloop = orig_mpoly[face].totloop; - const uint j_first_v = vm[orig_mloop[j_loopstart].v]; + const int j_loopstart = orig_polys[face].loopstart; + const int totloop = orig_polys[face].totloop; + const uint j_first_v = vm[orig_loops[j_loopstart].v]; for (uint k = j + 1; k < adj_len; k++) { - if (orig_mpoly[adj_faces->faces[k]].totloop != totloop) { + if (orig_polys[adj_faces->faces[k]].totloop != totloop) { continue; } /* Find first face first loop vert in second face loops. */ - const int k_loopstart = orig_mpoly[adj_faces->faces[k]].loopstart; + const int k_loopstart = orig_polys[adj_faces->faces[k]].loopstart; int l; - const MLoop *ml = orig_mloop + k_loopstart; + const MLoop *ml = &orig_loops[k_loopstart]; for (l = 0; l < totloop && vm[ml->v] != j_first_v; l++, ml++) { /* Pass. */ } @@ -647,14 +647,14 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, const bool reversed = adj_faces->faces_reversed[j] != adj_faces->faces_reversed[k]; const int count_dir = reversed ? -1 : 1; bool has_diff = false; - ml = orig_mloop + j_loopstart; + ml = &orig_loops[j_loopstart]; for (int m = 0, n = l + totloop; m < totloop && !has_diff; m++, n += count_dir, ml++) { - has_diff = has_diff || vm[ml->v] != vm[orig_mloop[k_loopstart + n % totloop].v]; + has_diff = has_diff || vm[ml->v] != vm[orig_loops[k_loopstart + n % totloop].v]; } /* If the faces are equal, discard one (j). */ if (!has_diff) { - ml = orig_mloop + j_loopstart; + ml = &orig_loops[j_loopstart]; uint del_loops = 0; for (uint m = 0; m < totloop; m++, ml++) { const uint e = ml->e; @@ -724,7 +724,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, /* Create #NewEdgeRef array. */ { - const MEdge *ed = orig_medge; + const MEdge *ed = orig_edges.data(); for (uint i = 0; i < edges_num; i++, ed++) { const uint v1 = vm[ed->v1]; const uint v2 = vm[ed->v2]; @@ -747,7 +747,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, uint e = link1->edges[j]; if (edge_adj_faces_len[e] > 0 && e != i) { uint other_v = - vm[vm[orig_medge[e].v1] == v1 ? orig_medge[e].v2 : orig_medge[e].v1]; + vm[vm[orig_edges[e].v1] == v1 ? orig_edges[e].v2 : orig_edges[e].v1]; sub_v3_v3v3(edgedir, orig_mvert_co[other_v], pos); add_v3_v3(v1_dir, edgedir); } @@ -759,7 +759,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, uint e = link2->edges[j]; if (edge_adj_faces_len[e] > 0 && e != i) { uint other_v = - vm[vm[orig_medge[e].v1] == v2 ? orig_medge[e].v2 : orig_medge[e].v1]; + vm[vm[orig_edges[e].v1] == v2 ? orig_edges[e].v2 : orig_edges[e].v1]; sub_v3_v3v3(edgedir, orig_mvert_co[other_v], pos); add_v3_v3(v2_dir, edgedir); } @@ -795,7 +795,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, copy_v3_v3(nor, poly_nors[face_i]); } float d = 1; - if (orig_mpoly[face_i].totloop > 3) { + if (orig_polys[face_i].totloop > 3) { d = project_v3_v3(nor, edgedir); if (LIKELY(d != 0)) { d = normalize_v3(nor); @@ -876,7 +876,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, new_edges[j] = edge_data; for (uint k = 0; k < 2; k++) { if (faces[k] != nullptr) { - const MLoop *ml = orig_mloop + faces[k]->face->loopstart; + const MLoop *ml = &orig_loops[faces[k]->face->loopstart]; for (int l = 0; l < faces[k]->face->totloop; l++, ml++) { if (edge_adj_faces[ml->e] == edge_adj_faces[i]) { if (ml->e != i && orig_edge_data_arr[ml->e] == nullptr) { @@ -1000,7 +1000,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, BLI_assert(edge != nullptr); found_edge_index = j - 1; found_edge = edge; - if (!last_open_edge_track && vm[orig_medge[edge->old_edge].v1] == i) { + if (!last_open_edge_track && vm[orig_edges[edge->old_edge].v1] == i) { eg_track_faces[0] = edge->faces[0]; eg_track_faces[1] = edge->faces[1]; if (edge->faces[1] == nullptr) { @@ -1332,8 +1332,8 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, for (EdgeGroup *g = edge_groups; g->valid; g++) { NewEdgeRef **e = g->edges; for (uint j = 0; j < g->edges_len; j++, e++) { - const uint flip = uint(vm[orig_medge[(*e)->old_edge].v2] == i); - BLI_assert(flip || vm[orig_medge[(*e)->old_edge].v1] == i); + const uint flip = uint(vm[orig_edges[(*e)->old_edge].v2] == i); + BLI_assert(flip || vm[orig_edges[(*e)->old_edge].v1] == i); (*e)->link_edge_groups[flip] = g; } uint added = 0; @@ -1412,12 +1412,12 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, face_weight = static_cast( MEM_malloc_arrayN(polys_num, sizeof(*face_weight), __func__)); - const MPoly *mp = orig_mpoly; - for (uint i = 0; i < polys_num; i++, mp++) { + for (const int i : orig_polys.index_range()) { + const MPoly &poly = orig_polys[i]; float scalar_vgroup = 1.0f; - int loopend = mp->loopstart + mp->totloop; - const MLoop *ml = orig_mloop + mp->loopstart; - for (int j = mp->loopstart; j < loopend; j++, ml++) { + int loopend = poly.loopstart + poly.totloop; + const MLoop *ml = &orig_loops[poly.loopstart]; + for (int j = poly.loopstart; j < loopend; j++, ml++) { const MDeformVert *dv = &dvert[ml->v]; if (defgrp_invert) { scalar_vgroup = min_ff(1.0f - BKE_defvert_find_weight(dv, defgrp_index), @@ -1688,7 +1688,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, if (smd->nonmanifold_offset_mode == MOD_SOLIDIFY_NONMANIFOLD_OFFSET_MODE_EVEN) { - const MLoop *ml_next = orig_mloop + face->face->loopstart; + const MLoop *ml_next = &orig_loops[face->face->loopstart]; const MLoop *ml = ml_next + (face->face->totloop - 1); const MLoop *ml_prev = ml - 1; for (int m = 0; m < face->face->totloop && vm[ml->v] != i; @@ -1799,7 +1799,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, float tmp[3]; int k; for (k = 1; k + 1 < g->edges_len; k++, edge_ptr++) { - const MEdge *e = orig_medge + (*edge_ptr)->old_edge; + const MEdge *e = &orig_edges[(*edge_ptr)->old_edge]; sub_v3_v3v3(tmp, orig_mvert_co[vm[e->v1] == i ? e->v2 : e->v1], orig_mvert_co[i]); add_v3_v3(move_nor, tmp); } @@ -1814,8 +1814,8 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, if (!disable_boundary_fix) { /* Constraint normal, nor * constr_nor == 0 after this fix. */ float constr_nor[3]; - const MEdge *e0_edge = orig_medge + g->edges[0]->old_edge; - const MEdge *e1_edge = orig_medge + g->edges[g->edges_len - 1]->old_edge; + const MEdge *e0_edge = &orig_edges[g->edges[0]->old_edge]; + const MEdge *e1_edge = &orig_edges[g->edges[g->edges_len - 1]->old_edge]; float e0[3]; float e1[3]; sub_v3_v3v3(e0, @@ -1991,9 +1991,9 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, mesh, int(new_verts_num), int(new_edges_num), 0, int(new_loops_num), int(new_polys_num)); float(*vert_positions)[3] = BKE_mesh_vert_positions_for_write(result); - MEdge *medge = BKE_mesh_edges_for_write(result); - MPoly *mpoly = BKE_mesh_polys_for_write(result); - MLoop *mloop = BKE_mesh_loops_for_write(result); + blender::MutableSpan edges = result->edges_for_write(); + blender::MutableSpan polys = result->polys_for_write(); + blender::MutableSpan loops = result->loops_for_write(); int *origindex_edge = static_cast( CustomData_get_layer_for_write(&result->edata, CD_ORIGINDEX, result->totedge)); @@ -2071,9 +2071,9 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, CustomData_copy_data(&mesh->edata, &result->edata, int(i), int(insert), 1); BLI_assert(v1 != MOD_SOLIDIFY_EMPTY_TAG); BLI_assert(v2 != MOD_SOLIDIFY_EMPTY_TAG); - medge[insert].v1 = v1; - medge[insert].v2 = v2; - medge[insert].flag = orig_medge[(*l)->old_edge].flag; + edges[insert].v1 = v1; + edges[insert].v2 = v2; + edges[insert].flag = orig_edges[(*l)->old_edge].flag; if (result_edge_crease) { result_edge_crease[insert] = orig_edge_crease ? orig_edge_crease[(*l)->old_edge] : 0.0f; @@ -2187,7 +2187,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, else { for (uint k = 1; k < g->edges_len - 1; k++) { const uint orig_edge_index = g->edges[k]->old_edge; - const MEdge *ed = &orig_medge[orig_edge_index]; + const MEdge *ed = &orig_edges[orig_edge_index]; if (result_edge_crease) { if (orig_edge_crease && orig_edge_crease[orig_edge_index] > max_crease) { max_crease = orig_edge_crease[orig_edge_index]; @@ -2234,9 +2234,9 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, if (origindex_edge) { origindex_edge[edge_index] = ORIGINDEX_NONE; } - medge[edge_index].v1 = last_g->new_vert; - medge[edge_index].v2 = g->new_vert; - medge[edge_index].flag = ((last_flag | flag) & ME_SEAM); + edges[edge_index].v1 = last_g->new_vert; + edges[edge_index].v2 = g->new_vert; + edges[edge_index].flag = ((last_flag | flag) & ME_SEAM); if (result_edge_crease) { result_edge_crease[edge_index] = max_ff(mv_crease, min_ff(last_max_crease, max_crease)); @@ -2267,9 +2267,9 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, origindex_edge[edge_index] = ORIGINDEX_NONE; } last_g->open_face_edge = edge_index; - medge[edge_index].v1 = last_g->new_vert; - medge[edge_index].v2 = first_g->new_vert; - medge[edge_index].flag = ((last_flag | first_flag) & ME_SEAM); + edges[edge_index].v1 = last_g->new_vert; + edges[edge_index].v2 = first_g->new_vert; + edges[edge_index].flag = ((last_flag | first_flag) & ME_SEAM); if (result_edge_crease) { result_edge_crease[edge_index] = max_ff(mv_crease, min_ff(last_max_crease, first_max_crease)); @@ -2281,7 +2281,8 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, edge_index++; /* Loop data. */ - int *loops = static_cast(MEM_malloc_arrayN(j, sizeof(*loops), __func__)); + int *loops_data = static_cast( + MEM_malloc_arrayN(j, sizeof(*loops_data), __func__)); /* The result material index is from consensus. */ short most_mat_nr = 0; uint most_mat_nr_face = 0; @@ -2324,21 +2325,21 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, if (origindex_poly) { origindex_poly[poly_index] = ORIGINDEX_NONE; } - mpoly[poly_index].loopstart = int(loop_index); - mpoly[poly_index].totloop = int(j); + polys[poly_index].loopstart = int(loop_index); + polys[poly_index].totloop = int(j); dst_material_index[poly_index] = most_mat_nr + (g->is_orig_closed || !do_rim ? 0 : mat_ofs_rim); CLAMP(dst_material_index[poly_index], 0, mat_nr_max); - mpoly[poly_index].flag = orig_mpoly[most_mat_nr_face].flag; + polys[poly_index].flag = orig_polys[most_mat_nr_face].flag; poly_index++; for (uint k = 0; g2->valid && k < j; g2++) { if ((do_rim && !g2->is_orig_closed) || (do_shell && g2->split)) { const MPoly *face = g2->edges[0]->faces[0]->face; - const MLoop *ml = orig_mloop + face->loopstart; + const MLoop *ml = &orig_loops[face->loopstart]; for (int l = 0; l < face->totloop; l++, ml++) { if (vm[ml->v] == i) { - loops[k] = face->loopstart + l; + loops_data[k] = face->loopstart + l; break; } } @@ -2348,20 +2349,21 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, if (!do_flip) { for (uint k = 0; k < j; k++) { - CustomData_copy_data(&mesh->ldata, &result->ldata, loops[k], int(loop_index), 1); - mloop[loop_index].v = medge[edge_index - j + k].v1; - mloop[loop_index++].e = edge_index - j + k; + CustomData_copy_data( + &mesh->ldata, &result->ldata, loops_data[k], int(loop_index), 1); + loops[loop_index].v = edges[edge_index - j + k].v1; + loops[loop_index++].e = edge_index - j + k; } } else { for (uint k = 1; k <= j; k++) { CustomData_copy_data( - &mesh->ldata, &result->ldata, loops[j - k], int(loop_index), 1); - mloop[loop_index].v = medge[edge_index - k].v2; - mloop[loop_index++].e = edge_index - k; + &mesh->ldata, &result->ldata, loops_data[j - k], int(loop_index), 1); + loops[loop_index].v = edges[edge_index - k].v2; + loops[loop_index++].e = edge_index - k; } } - MEM_freeN(loops); + MEM_freeN(loops_data); } /* Reset everything for the next poly. */ j = 0; @@ -2400,19 +2402,19 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, const MPoly *face = (*new_edges)->faces[0]->face; CustomData_copy_data( &mesh->pdata, &result->pdata, int((*new_edges)->faces[0]->index), int(poly_index), 1); - mpoly[poly_index].loopstart = int(loop_index); - mpoly[poly_index].totloop = 4 - int(v1_singularity || v2_singularity); + polys[poly_index].loopstart = int(loop_index); + polys[poly_index].totloop = 4 - int(v1_singularity || v2_singularity); dst_material_index[poly_index] = (src_material_index ? src_material_index[orig_face_index] : 0) + mat_ofs_rim; CLAMP(dst_material_index[poly_index], 0, mat_nr_max); - mpoly[poly_index].flag = face->flag; + polys[poly_index].flag = face->flag; poly_index++; int loop1 = -1; int loop2 = -1; - const MLoop *ml = orig_mloop + face->loopstart; - const uint old_v1 = vm[orig_medge[edge1->old_edge].v1]; - const uint old_v2 = vm[orig_medge[edge1->old_edge].v2]; + const MLoop *ml = &orig_loops[face->loopstart]; + const uint old_v1 = vm[orig_edges[edge1->old_edge].v1]; + const uint old_v2 = vm[orig_edges[edge1->old_edge].v2]; for (uint j = 0; j < face->totloop; j++, ml++) { if (vm[ml->v] == old_v1) { loop1 = face->loopstart + int(j); @@ -2426,52 +2428,52 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, uint open_face_edge_index; if (!do_flip) { if (rim_defgrp_index != -1) { - BKE_defvert_ensure_index(&dst_dvert[medge[edge1->new_edge].v1], rim_defgrp_index) + BKE_defvert_ensure_index(&dst_dvert[edges[edge1->new_edge].v1], rim_defgrp_index) ->weight = 1.0f; } CustomData_copy_data(&mesh->ldata, &result->ldata, loop1, int(loop_index), 1); - mloop[loop_index].v = medge[edge1->new_edge].v1; - mloop[loop_index++].e = edge1->new_edge; + loops[loop_index].v = edges[edge1->new_edge].v1; + loops[loop_index++].e = edge1->new_edge; if (!v2_singularity) { open_face_edge_index = edge1->link_edge_groups[1]->open_face_edge; if (rim_defgrp_index != -1) { - BKE_defvert_ensure_index(&dst_dvert[medge[edge1->new_edge].v2], rim_defgrp_index) + BKE_defvert_ensure_index(&dst_dvert[edges[edge1->new_edge].v2], rim_defgrp_index) ->weight = 1.0f; } CustomData_copy_data(&mesh->ldata, &result->ldata, loop2, int(loop_index), 1); - mloop[loop_index].v = medge[edge1->new_edge].v2; - open_face_edge = medge + open_face_edge_index; - if (ELEM(medge[edge2->new_edge].v2, open_face_edge->v1, open_face_edge->v2)) { - mloop[loop_index++].e = open_face_edge_index; + loops[loop_index].v = edges[edge1->new_edge].v2; + open_face_edge = &edges[open_face_edge_index]; + if (ELEM(edges[edge2->new_edge].v2, open_face_edge->v1, open_face_edge->v2)) { + loops[loop_index++].e = open_face_edge_index; } else { - mloop[loop_index++].e = edge2->link_edge_groups[1]->open_face_edge; + loops[loop_index++].e = edge2->link_edge_groups[1]->open_face_edge; } } if (rim_defgrp_index != -1) { - BKE_defvert_ensure_index(&dst_dvert[medge[edge2->new_edge].v2], rim_defgrp_index) + BKE_defvert_ensure_index(&dst_dvert[edges[edge2->new_edge].v2], rim_defgrp_index) ->weight = 1.0f; } CustomData_copy_data(&mesh->ldata, &result->ldata, loop2, int(loop_index), 1); - mloop[loop_index].v = medge[edge2->new_edge].v2; - mloop[loop_index++].e = edge2->new_edge; + loops[loop_index].v = edges[edge2->new_edge].v2; + loops[loop_index++].e = edge2->new_edge; if (!v1_singularity) { open_face_edge_index = edge2->link_edge_groups[0]->open_face_edge; if (rim_defgrp_index != -1) { - BKE_defvert_ensure_index(&dst_dvert[medge[edge2->new_edge].v1], rim_defgrp_index) + BKE_defvert_ensure_index(&dst_dvert[edges[edge2->new_edge].v1], rim_defgrp_index) ->weight = 1.0f; } CustomData_copy_data(&mesh->ldata, &result->ldata, loop1, int(loop_index), 1); - mloop[loop_index].v = medge[edge2->new_edge].v1; - open_face_edge = medge + open_face_edge_index; - if (ELEM(medge[edge1->new_edge].v1, open_face_edge->v1, open_face_edge->v2)) { - mloop[loop_index++].e = open_face_edge_index; + loops[loop_index].v = edges[edge2->new_edge].v1; + open_face_edge = &edges[open_face_edge_index]; + if (ELEM(edges[edge1->new_edge].v1, open_face_edge->v1, open_face_edge->v2)) { + loops[loop_index++].e = open_face_edge_index; } else { - mloop[loop_index++].e = edge1->link_edge_groups[0]->open_face_edge; + loops[loop_index++].e = edge1->link_edge_groups[0]->open_face_edge; } } } @@ -2479,52 +2481,52 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, if (!v1_singularity) { open_face_edge_index = edge1->link_edge_groups[0]->open_face_edge; if (rim_defgrp_index != -1) { - BKE_defvert_ensure_index(&dst_dvert[medge[edge1->new_edge].v1], rim_defgrp_index) + BKE_defvert_ensure_index(&dst_dvert[edges[edge1->new_edge].v1], rim_defgrp_index) ->weight = 1.0f; } CustomData_copy_data(&mesh->ldata, &result->ldata, loop1, int(loop_index), 1); - mloop[loop_index].v = medge[edge1->new_edge].v1; - open_face_edge = medge + open_face_edge_index; - if (ELEM(medge[edge2->new_edge].v1, open_face_edge->v1, open_face_edge->v2)) { - mloop[loop_index++].e = open_face_edge_index; + loops[loop_index].v = edges[edge1->new_edge].v1; + open_face_edge = &edges[open_face_edge_index]; + if (ELEM(edges[edge2->new_edge].v1, open_face_edge->v1, open_face_edge->v2)) { + loops[loop_index++].e = open_face_edge_index; } else { - mloop[loop_index++].e = edge2->link_edge_groups[0]->open_face_edge; + loops[loop_index++].e = edge2->link_edge_groups[0]->open_face_edge; } } if (rim_defgrp_index != -1) { - BKE_defvert_ensure_index(&dst_dvert[medge[edge2->new_edge].v1], rim_defgrp_index) + BKE_defvert_ensure_index(&dst_dvert[edges[edge2->new_edge].v1], rim_defgrp_index) ->weight = 1.0f; } CustomData_copy_data(&mesh->ldata, &result->ldata, loop1, int(loop_index), 1); - mloop[loop_index].v = medge[edge2->new_edge].v1; - mloop[loop_index++].e = edge2->new_edge; + loops[loop_index].v = edges[edge2->new_edge].v1; + loops[loop_index++].e = edge2->new_edge; if (!v2_singularity) { open_face_edge_index = edge2->link_edge_groups[1]->open_face_edge; if (rim_defgrp_index != -1) { - BKE_defvert_ensure_index(&dst_dvert[medge[edge2->new_edge].v2], rim_defgrp_index) + BKE_defvert_ensure_index(&dst_dvert[edges[edge2->new_edge].v2], rim_defgrp_index) ->weight = 1.0f; } CustomData_copy_data(&mesh->ldata, &result->ldata, loop2, int(loop_index), 1); - mloop[loop_index].v = medge[edge2->new_edge].v2; - open_face_edge = medge + open_face_edge_index; - if (ELEM(medge[edge1->new_edge].v2, open_face_edge->v1, open_face_edge->v2)) { - mloop[loop_index++].e = open_face_edge_index; + loops[loop_index].v = edges[edge2->new_edge].v2; + open_face_edge = &edges[open_face_edge_index]; + if (ELEM(edges[edge1->new_edge].v2, open_face_edge->v1, open_face_edge->v2)) { + loops[loop_index++].e = open_face_edge_index; } else { - mloop[loop_index++].e = edge1->link_edge_groups[1]->open_face_edge; + loops[loop_index++].e = edge1->link_edge_groups[1]->open_face_edge; } } if (rim_defgrp_index != -1) { - BKE_defvert_ensure_index(&dst_dvert[medge[edge1->new_edge].v2], rim_defgrp_index) + BKE_defvert_ensure_index(&dst_dvert[edges[edge1->new_edge].v2], rim_defgrp_index) ->weight = 1.0f; } CustomData_copy_data(&mesh->ldata, &result->ldata, loop2, int(loop_index), 1); - mloop[loop_index].v = medge[edge1->new_edge].v2; - mloop[loop_index++].e = edge1->new_edge; + loops[loop_index].v = edges[edge1->new_edge].v2; + loops[loop_index++].e = edge1->new_edge; } } } @@ -2550,16 +2552,16 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, } if (totloop > 0) { NewEdgeRef *prior_edge = fr->link_edges[totloop - 1]; - uint prior_flip = uint(vm[orig_medge[prior_edge->old_edge].v1] == - vm[orig_mloop[loopstart + (totloop - 1)].v]); + uint prior_flip = uint(vm[orig_edges[prior_edge->old_edge].v1] == + vm[orig_loops[loopstart + (totloop - 1)].v]); for (uint j = 0; j < totloop; j++) { NewEdgeRef *new_edge = fr->link_edges[j]; if (new_edge && new_edge->new_edge != MOD_SOLIDIFY_EMPTY_TAG) { valid_edges++; - const uint flip = uint(vm[orig_medge[new_edge->old_edge].v2] == - vm[orig_mloop[loopstart + j].v]); + const uint flip = uint(vm[orig_edges[new_edge->old_edge].v2] == + vm[orig_loops[loopstart + j].v]); BLI_assert(flip || - vm[orig_medge[new_edge->old_edge].v1] == vm[orig_mloop[loopstart + j].v]); + vm[orig_edges[new_edge->old_edge].v1] == vm[orig_loops[loopstart + j].v]); /* The vert that's in the current loop. */ const uint new_v1 = new_edge->link_edge_groups[flip]->new_vert; /* The vert that's in the next loop. */ @@ -2592,13 +2594,13 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, } if (k > 2 && valid_edges > 2) { CustomData_copy_data(&mesh->pdata, &result->pdata, int(i / 2), int(poly_index), 1); - mpoly[poly_index].loopstart = int(loop_index); - mpoly[poly_index].totloop = int(k); + polys[poly_index].loopstart = int(loop_index); + polys[poly_index].totloop = int(k); dst_material_index[poly_index] = (src_material_index ? src_material_index[fr->index] : 0) + (fr->reversed != do_flip ? mat_ofs : 0); CLAMP(dst_material_index[poly_index], 0, mat_nr_max); - mpoly[poly_index].flag = fr->face->flag; + polys[poly_index].flag = fr->face->flag; if (fr->reversed != do_flip) { for (int l = int(k) - 1; l >= 0; l--) { if (shell_defgrp_index != -1) { @@ -2607,8 +2609,8 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, } CustomData_copy_data( &mesh->ldata, &result->ldata, int(face_loops[l]), int(loop_index), 1); - mloop[loop_index].v = face_verts[l]; - mloop[loop_index++].e = face_edges[l]; + loops[loop_index].v = face_verts[l]; + loops[loop_index++].e = face_edges[l]; } } else { @@ -2616,8 +2618,8 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, for (uint next_l = 0; next_l < k; next_l++) { CustomData_copy_data( &mesh->ldata, &result->ldata, int(face_loops[l]), int(loop_index), 1); - mloop[loop_index].v = face_verts[l]; - mloop[loop_index++].e = face_edges[next_l]; + loops[loop_index].v = face_verts[l]; + loops[loop_index++].e = face_edges[next_l]; l = next_l; } } diff --git a/source/blender/modifiers/intern/MOD_surfacedeform.cc b/source/blender/modifiers/intern/MOD_surfacedeform.cc index bbcbb80a771..bf8eb5acaf2 100644 --- a/source/blender/modifiers/intern/MOD_surfacedeform.cc +++ b/source/blender/modifiers/intern/MOD_surfacedeform.cc @@ -69,9 +69,10 @@ struct SDefBindCalcData { const SDefEdgePolys *edge_polys; SDefVert *bind_verts; const MLoopTri *looptri; - const MPoly *mpoly; - const MEdge *medge; - const MLoop *mloop; + blender::Span edges; + blender::Span polys; + blender::Span loops; + /** Coordinates to bind to, transformed into local space (compatible with `vertexCos`). */ float (*targetCos)[3]; /** Coordinates to bind (reference to the modifiers input argument). */ @@ -279,7 +280,7 @@ static void freeAdjacencyMap(SDefAdjacencyArray *const vert_edges, static int buildAdjacencyMap(const MPoly *poly, const MEdge *edge, - const MLoop *const mloop, + const MLoop *const loops, const uint polys_num, const uint edges_num, SDefAdjacencyArray *const vert_edges, @@ -290,7 +291,7 @@ static int buildAdjacencyMap(const MPoly *poly, /* Find polygons adjacent to edges. */ for (int i = 0; i < polys_num; i++, poly++) { - loop = &mloop[poly->loopstart]; + loop = &loops[poly->loopstart]; for (int j = 0; j < poly->totloop; j++, loop++) { if (edge_polys[loop->e].num == 0) { @@ -327,41 +328,41 @@ static int buildAdjacencyMap(const MPoly *poly, } BLI_INLINE void sortPolyVertsEdge(uint *indices, - const MLoop *const mloop, + const MLoop *const loops, const uint edge, const uint num) { bool found = false; for (int i = 0; i < num; i++) { - if (mloop[i].e == edge) { + if (loops[i].e == edge) { found = true; } if (found) { - *indices = mloop[i].v; + *indices = loops[i].v; indices++; } } /* Fill in remaining vertex indices that occur before the edge */ - for (int i = 0; mloop[i].e != edge; i++) { - *indices = mloop[i].v; + for (int i = 0; loops[i].e != edge; i++) { + *indices = loops[i].v; indices++; } } BLI_INLINE void sortPolyVertsTri(uint *indices, - const MLoop *const mloop, + const MLoop *const loops, const uint loopstart, const uint num) { for (int i = loopstart; i < num; i++) { - *indices = mloop[i].v; + *indices = loops[i].v; indices++; } for (int i = 0; i < loopstart; i++) { - *indices = mloop[i].v; + *indices = loops[i].v; indices++; } } @@ -385,11 +386,11 @@ BLI_INLINE uint nearestVert(SDefBindCalcData *const data, const float point_co[3 BLI_bvhtree_find_nearest( data->treeData->tree, t_point, &nearest, data->treeData->nearest_callback, data->treeData); - poly = &data->mpoly[data->looptri[nearest.index].poly]; - loop = &data->mloop[poly->loopstart]; + poly = &data->polys[data->looptri[nearest.index].poly]; + loop = &data->loops[poly->loopstart]; for (int i = 0; i < poly->totloop; i++, loop++) { - edge = &data->medge[loop->e]; + edge = &data->edges[loop->e]; dist = dist_squared_to_line_segment_v3( point_co, data->targetCos[edge->v1], data->targetCos[edge->v2]); @@ -399,7 +400,7 @@ BLI_INLINE uint nearestVert(SDefBindCalcData *const data, const float point_co[3 } } - edge = &data->medge[index]; + edge = &data->edges[index]; if (len_squared_v3v3(point_co, data->targetCos[edge->v1]) < len_squared_v3v3(point_co, data->targetCos[edge->v2])) { return edge->v1; @@ -536,8 +537,8 @@ BLI_INLINE SDefBindWeightData *computeBindWeights(SDefBindCalcData *const data, bpoly->coords_v2 = nullptr; /* Copy poly data */ - poly = &data->mpoly[bpoly->index]; - loop = &data->mloop[poly->loopstart]; + poly = &data->polys[bpoly->index]; + loop = &data->loops[poly->loopstart]; bpoly->verts_num = poly->totloop; bpoly->loopstart = poly->loopstart; @@ -567,7 +568,7 @@ BLI_INLINE SDefBindWeightData *computeBindWeights(SDefBindCalcData *const data, bpoly->edge_vert_inds[0] = (j == 0) ? (poly->totloop - 1) : (j - 1); bpoly->edge_vert_inds[1] = (j == poly->totloop - 1) ? (0) : (j + 1); - bpoly->edge_inds[0] = data->mloop[poly->loopstart + bpoly->edge_vert_inds[0]].e; + bpoly->edge_inds[0] = data->loops[poly->loopstart + bpoly->edge_vert_inds[0]].e; bpoly->edge_inds[1] = loop->e; } } @@ -1004,7 +1005,7 @@ static void bindVert(void *__restrict userdata, for (int i = 0; i < bwdata->binds_num; bpoly++) { if (bpoly->weight >= FLT_EPSILON) { if (bpoly->inside) { - const MLoop *loop = &data->mloop[bpoly->loopstart]; + const MLoop *loop = &data->loops[bpoly->loopstart]; sdbind->influence = bpoly->weight; sdbind->verts_num = bpoly->verts_num; @@ -1065,7 +1066,7 @@ static void bindVert(void *__restrict userdata, } sortPolyVertsEdge(sdbind->vert_inds, - &data->mloop[bpoly->loopstart], + &data->loops[bpoly->loopstart], bpoly->edge_inds[bpoly->dominant_edge], bpoly->verts_num); @@ -1112,7 +1113,7 @@ static void bindVert(void *__restrict userdata, } sortPolyVertsTri(sdbind->vert_inds, - &data->mloop[bpoly->loopstart], + &data->loops[bpoly->loopstart], bpoly->edge_vert_inds[0], bpoly->verts_num); @@ -1172,9 +1173,9 @@ static bool surfacedeformBind(Object *ob, { BVHTreeFromMesh treeData = {nullptr}; const float(*positions)[3] = BKE_mesh_vert_positions(target); - const MPoly *mpoly = BKE_mesh_polys(target); - const MEdge *medge = BKE_mesh_edges(target); - const MLoop *mloop = BKE_mesh_loops(target); + const blender::Span edges = target->edges(); + const blender::Span polys = target->polys(); + const blender::Span loops = target->loops(); uint tedges_num = target->totedge; int adj_result; @@ -1219,8 +1220,14 @@ static bool surfacedeformBind(Object *ob, return false; } - adj_result = buildAdjacencyMap( - mpoly, medge, mloop, target_polys_num, tedges_num, vert_edges, adj_array, edge_polys); + adj_result = buildAdjacencyMap(polys.data(), + edges.data(), + loops.data(), + target_polys_num, + tedges_num, + vert_edges, + adj_array, + edge_polys); if (adj_result == MOD_SDEF_BIND_RESULT_NONMANY_ERR) { BKE_modifier_set_error( @@ -1246,9 +1253,9 @@ static bool surfacedeformBind(Object *ob, data.treeData = &treeData; data.vert_edges = vert_edges; data.edge_polys = edge_polys; - data.mpoly = mpoly; - data.medge = medge; - data.mloop = mloop; + data.polys = polys; + data.edges = edges; + data.loops = loops; data.looptri = BKE_mesh_runtime_looptri_ensure(target); data.targetCos = static_cast( MEM_malloc_arrayN(target_verts_num, sizeof(float[3]), "SDefTargetBindVertArray")); diff --git a/source/blender/modifiers/intern/MOD_util.cc b/source/blender/modifiers/intern/MOD_util.cc index 9826987a15d..4c8663277ab 100644 --- a/source/blender/modifiers/intern/MOD_util.cc +++ b/source/blender/modifiers/intern/MOD_util.cc @@ -92,23 +92,22 @@ void MOD_get_texture_coords(MappingInfoModifierData *dmd, /* UVs need special handling, since they come from faces */ if (texmapping == MOD_DISP_MAP_UV) { if (CustomData_has_layer(&mesh->ldata, CD_PROP_FLOAT2)) { - const MPoly *mpoly = BKE_mesh_polys(mesh); - const MPoly *mp; - const MLoop *mloop = BKE_mesh_loops(mesh); + const blender::Span polys = mesh->polys(); + const blender::Span loops = mesh->loops(); BLI_bitmap *done = BLI_BITMAP_NEW(verts_num, __func__); - const int polys_num = mesh->totpoly; char uvname[MAX_CUSTOMDATA_LAYER_NAME]; CustomData_validate_layer_name(&mesh->ldata, CD_PROP_FLOAT2, dmd->uvlayer_name, uvname); const float(*mloop_uv)[2] = static_cast( CustomData_get_layer_named(&mesh->ldata, CD_PROP_FLOAT2, uvname)); /* verts are given the UV from the first face that uses them */ - for (i = 0, mp = mpoly; i < polys_num; i++, mp++) { - uint fidx = mp->totloop - 1; + for (const int i : polys.index_range()) { + const MPoly &poly = polys[i]; + uint fidx = poly.totloop - 1; do { - uint lidx = mp->loopstart + fidx; - uint vidx = mloop[lidx].v; + uint lidx = poly.loopstart + fidx; + uint vidx = loops[lidx].v; if (!BLI_BITMAP_TEST(done, vidx)) { /* remap UVs from [0, 1] to [-1, 1] */ diff --git a/source/blender/modifiers/intern/MOD_uvproject.cc b/source/blender/modifiers/intern/MOD_uvproject.cc index 9491a6bfb6e..92bd0bd77e6 100644 --- a/source/blender/modifiers/intern/MOD_uvproject.cc +++ b/source/blender/modifiers/intern/MOD_uvproject.cc @@ -95,8 +95,7 @@ static Mesh *uvprojectModifier_do(UVProjectModifierData *umd, Mesh *mesh) { float(*coords)[3], (*co)[3]; - int i, verts_num, polys_num, loops_num; - const MPoly *mp; + int i, verts_num; Projector projectors[MOD_UVPROJECT_MAXPROJECTORS]; int projectors_num = 0; char uvname[MAX_CUSTOMDATA_LAYER_NAME]; @@ -181,11 +180,11 @@ static Mesh *uvprojectModifier_do(UVProjectModifierData *umd, mul_mat3_m4_v3(projectors[i].ob->object_to_world, projectors[i].normal); } - polys_num = mesh->totpoly; - loops_num = mesh->totloop; + const blender::Span polys = mesh->polys(); + const blender::Span loops = mesh->loops(); float(*mloop_uv)[2] = static_cast( - CustomData_get_layer_named_for_write(&mesh->ldata, CD_PROP_FLOAT2, uvname, loops_num)); + CustomData_get_layer_named_for_write(&mesh->ldata, CD_PROP_FLOAT2, uvname, loops.size())); coords = BKE_mesh_vert_coords_alloc(mesh, &verts_num); @@ -201,16 +200,14 @@ static Mesh *uvprojectModifier_do(UVProjectModifierData *umd, } } - const MPoly *polys = BKE_mesh_polys(mesh); - const MLoop *loops = BKE_mesh_loops(mesh); - /* apply coords as UVs */ - for (i = 0, mp = polys; i < polys_num; i++, mp++) { + for (const int i : polys.index_range()) { + const MPoly &poly = polys[i]; if (projectors_num == 1) { if (projectors[0].uci) { - uint fidx = mp->totloop - 1; + uint fidx = poly.totloop - 1; do { - uint lidx = mp->loopstart + fidx; + uint lidx = poly.loopstart + fidx; uint vidx = loops[lidx].v; BLI_uvproject_from_camera( mloop_uv[lidx], coords[vidx], static_cast(projectors[0].uci)); @@ -218,9 +215,9 @@ static Mesh *uvprojectModifier_do(UVProjectModifierData *umd, } else { /* apply transformed coords as UVs */ - uint fidx = mp->totloop - 1; + uint fidx = poly.totloop - 1; do { - uint lidx = mp->loopstart + fidx; + uint lidx = poly.loopstart + fidx; uint vidx = loops[lidx].v; copy_v2_v2(mloop_uv[lidx], coords[vidx]); } while (fidx--); @@ -234,7 +231,7 @@ static Mesh *uvprojectModifier_do(UVProjectModifierData *umd, float best_dot; /* get the untransformed face normal */ - BKE_mesh_calc_poly_normal(mp, loops + mp->loopstart, (const float(*)[3])coords, face_no); + BKE_mesh_calc_poly_normal(&poly, &loops[poly.loopstart], (const float(*)[3])coords, face_no); /* find the projector which the face points at most directly * (projector normal with largest dot product is best) @@ -251,18 +248,18 @@ static Mesh *uvprojectModifier_do(UVProjectModifierData *umd, } if (best_projector->uci) { - uint fidx = mp->totloop - 1; + uint fidx = poly.totloop - 1; do { - uint lidx = mp->loopstart + fidx; + uint lidx = poly.loopstart + fidx; uint vidx = loops[lidx].v; BLI_uvproject_from_camera( mloop_uv[lidx], coords[vidx], static_cast(best_projector->uci)); } while (fidx--); } else { - uint fidx = mp->totloop - 1; + uint fidx = poly.totloop - 1; do { - uint lidx = mp->loopstart + fidx; + uint lidx = poly.loopstart + fidx; uint vidx = loops[lidx].v; mul_v2_project_m4_v3(mloop_uv[lidx], best_projector->projmat, coords[vidx]); } while (fidx--); diff --git a/source/blender/modifiers/intern/MOD_uvwarp.cc b/source/blender/modifiers/intern/MOD_uvwarp.cc index 5b4f3275d58..052df92b6d8 100644 --- a/source/blender/modifiers/intern/MOD_uvwarp.cc +++ b/source/blender/modifiers/intern/MOD_uvwarp.cc @@ -80,8 +80,8 @@ static void matrix_from_obj_pchan(float mat[4][4], Object *ob, const char *bonen } struct UVWarpData { - const MPoly *mpoly; - const MLoop *mloop; + blender::Span polys; + blender::Span loops; float (*mloopuv)[2]; const MDeformVert *dvert; @@ -97,8 +97,8 @@ static void uv_warp_compute(void *__restrict userdata, { const UVWarpData *data = static_cast(userdata); - const MPoly *mp = &data->mpoly[i]; - const MLoop *ml = &data->mloop[mp->loopstart]; + const MPoly *mp = &data->polys[i]; + const MLoop *ml = &data->loops[mp->loopstart]; float(*mluv)[2] = &data->mloopuv[mp->loopstart]; const MDeformVert *dvert = data->dvert; @@ -192,18 +192,16 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * /* make sure we're using an existing layer */ CustomData_validate_layer_name(&mesh->ldata, CD_PROP_FLOAT2, umd->uvlayer_name, uvname); - const MPoly *polys = BKE_mesh_polys(mesh); - const MLoop *loops = BKE_mesh_loops(mesh); - polys_num = mesh->totpoly; - loops_num = mesh->totloop; + const blender::Span polys = mesh->polys(); + const blender::Span loops = mesh->loops(); float(*mloopuv)[2] = static_cast( CustomData_get_layer_named_for_write(&mesh->ldata, CD_PROP_FLOAT2, uvname, loops_num)); MOD_get_vgroup(ctx->object, mesh, umd->vgroup_name, &dvert, &defgrp_index); UVWarpData data{}; - data.mpoly = polys; - data.mloop = loops; + data.polys = polys; + data.loops = loops; data.mloopuv = mloopuv; data.dvert = dvert; data.defgrp_index = defgrp_index; diff --git a/source/blender/modifiers/intern/MOD_weighted_normal.cc b/source/blender/modifiers/intern/MOD_weighted_normal.cc index cbf385d20a7..a350154c409 100644 --- a/source/blender/modifiers/intern/MOD_weighted_normal.cc +++ b/source/blender/modifiers/intern/MOD_weighted_normal.cc @@ -69,22 +69,19 @@ struct WeightedNormalDataAggregateItem { struct WeightedNormalData { int verts_num; - int edges_num; - int loops_num; - int polys_num; const float (*vert_positions)[3]; const float (*vert_normals)[3]; - const MEdge *medge; + blender::Span edges; bool *sharp_edges; - const MLoop *mloop; + blender::Span loops; blender::Span loop_to_poly; short (*clnors)[2]; bool has_clnors; /* True if clnors already existed, false if we had to create them. */ float split_angle; - const MPoly *mpoly; + blender::Span polys; const float (*poly_normals)[3]; const int *poly_strength; @@ -185,18 +182,15 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd, { using namespace blender; const int verts_num = wn_data->verts_num; - const int edges_num = wn_data->edges_num; - const int loops_num = wn_data->loops_num; - const int polys_num = wn_data->polys_num; const float(*positions)[3] = wn_data->vert_positions; - const MEdge *medge = wn_data->medge; + const blender::Span edges = wn_data->edges; + const blender::Span polys = wn_data->polys; + const blender::Span loops = wn_data->loops; - const MLoop *mloop = wn_data->mloop; short(*clnors)[2] = wn_data->clnors; const Span loop_to_poly = wn_data->loop_to_poly; - const MPoly *mpoly = wn_data->mpoly; const float(*poly_normals)[3] = wn_data->poly_normals; const int *poly_strength = wn_data->poly_strength; @@ -219,23 +213,23 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd, WeightedNormalDataAggregateItem *items_data = nullptr; int items_num = 0; if (keep_sharp) { - BLI_bitmap *done_loops = BLI_BITMAP_NEW(loops_num, __func__); + BLI_bitmap *done_loops = BLI_BITMAP_NEW(loops.size(), __func__); /* This will give us loop normal spaces, * we do not actually care about computed loop_normals for now... */ loop_normals = static_cast( - MEM_calloc_arrayN(size_t(loops_num), sizeof(*loop_normals), __func__)); + MEM_calloc_arrayN(size_t(loops.size()), sizeof(*loop_normals), __func__)); BKE_mesh_normals_loop_split(positions, wn_data->vert_normals, verts_num, - medge, - edges_num, - mloop, + edges.data(), + edges.size(), + loops.data(), loop_normals, - loops_num, - mpoly, + loops.size(), + polys.data(), poly_normals, - polys_num, + polys.size(), true, split_angle, wn_data->sharp_edges, @@ -249,12 +243,11 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd, /* In this first loop, we assign each WeightedNormalDataAggregateItem * to its smooth fan of loops (aka lnor space). */ - const MPoly *mp; int mp_index; int item_index; - for (mp = mpoly, mp_index = 0, item_index = 0; mp_index < polys_num; mp++, mp_index++) { - int ml_index = mp->loopstart; - const int ml_end_index = ml_index + mp->totloop; + for (mp_index = 0, item_index = 0; mp_index < polys.size(); mp_index++) { + int ml_index = polys[mp_index].loopstart; + const int ml_end_index = ml_index + polys[mp_index].totloop; for (; ml_index < ml_end_index; ml_index++) { if (BLI_BITMAP_TEST(done_loops, ml_index)) { @@ -299,14 +292,14 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd, switch (mode) { case MOD_WEIGHTEDNORMAL_MODE_FACE: - for (int i = 0; i < polys_num; i++) { + for (int i = 0; i < polys.size(); i++) { const int mp_index = mode_pair[i].index; const float mp_val = mode_pair[i].val; - int ml_index = mpoly[mp_index].loopstart; - const int ml_index_end = ml_index + mpoly[mp_index].totloop; + int ml_index = polys[mp_index].loopstart; + const int ml_index_end = ml_index + polys[mp_index].totloop; for (; ml_index < ml_index_end; ml_index++) { - const int mv_index = mloop[ml_index].v; + const int mv_index = loops[ml_index].v; WeightedNormalDataAggregateItem *item_data = keep_sharp ? static_cast( lnors_spacearr.lspacearr[ml_index]->user_data) : @@ -319,12 +312,12 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd, break; case MOD_WEIGHTEDNORMAL_MODE_ANGLE: case MOD_WEIGHTEDNORMAL_MODE_FACE_ANGLE: - for (int i = 0; i < loops_num; i++) { + for (int i = 0; i < loops.size(); i++) { const int ml_index = mode_pair[i].index; const float ml_val = mode_pair[i].val; const int mp_index = loop_to_poly[ml_index]; - const int mv_index = mloop[ml_index].v; + const int mv_index = loops[ml_index].v; WeightedNormalDataAggregateItem *item_data = keep_sharp ? static_cast( lnors_spacearr.lspacearr[ml_index]->user_data) : @@ -350,7 +343,7 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd, * Note that loop_normals is already populated with clnors * (before this modifier is applied, at start of this function), * so no need to recompute them here. */ - for (int ml_index = 0; ml_index < loops_num; ml_index++) { + for (int ml_index = 0; ml_index < loops.size(); ml_index++) { WeightedNormalDataAggregateItem *item_data = static_cast( lnors_spacearr.lspacearr[ml_index]->user_data); if (!is_zero_v3(item_data->normal)) { @@ -361,14 +354,14 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd, BKE_mesh_normals_loop_custom_set(positions, wn_data->vert_normals, verts_num, - medge, - edges_num, - mloop, + edges.data(), + edges.size(), + loops.data(), loop_normals, - loops_num, - mpoly, + loops.size(), + polys.data(), poly_normals, - polys_num, + polys.size(), wn_data->sharp_edges, clnors); } @@ -385,8 +378,8 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd, float(*vert_normals)[3] = static_cast( MEM_calloc_arrayN(size_t(verts_num), sizeof(*loop_normals), __func__)); - for (int ml_index = 0; ml_index < loops_num; ml_index++) { - const int mv_index = mloop[ml_index].v; + for (int ml_index = 0; ml_index < loops.size(); ml_index++) { + const int mv_index = loops[ml_index].v; copy_v3_v3(vert_normals[mv_index], items_data[mv_index].normal); } @@ -394,13 +387,13 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd, wn_data->vert_normals, vert_normals, verts_num, - medge, - edges_num, - mloop, - loops_num, - mpoly, + edges.data(), + edges.size(), + loops.data(), + loops.size(), + polys.data(), poly_normals, - polys_num, + polys.size(), wn_data->sharp_edges, clnors); @@ -408,19 +401,19 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd, } else { loop_normals = static_cast( - MEM_calloc_arrayN(size_t(loops_num), sizeof(*loop_normals), __func__)); + MEM_calloc_arrayN(size_t(loops.size()), sizeof(*loop_normals), __func__)); BKE_mesh_normals_loop_split(positions, wn_data->vert_normals, verts_num, - medge, - edges_num, - mloop, + edges.data(), + edges.size(), + loops.data(), loop_normals, - loops_num, - mpoly, + loops.size(), + polys.data(), poly_normals, - polys_num, + polys.size(), true, split_angle, wn_data->sharp_edges, @@ -428,8 +421,8 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd, nullptr, has_clnors ? clnors : nullptr); - for (int ml_index = 0; ml_index < loops_num; ml_index++) { - const int item_index = mloop[ml_index].v; + for (int ml_index = 0; ml_index < loops.size(); ml_index++) { + const int item_index = loops[ml_index].v; if (!is_zero_v3(items_data[item_index].normal)) { copy_v3_v3(loop_normals[ml_index], items_data[item_index].normal); } @@ -438,14 +431,14 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd, BKE_mesh_normals_loop_custom_set(positions, wn_data->vert_normals, verts_num, - medge, - edges_num, - mloop, + edges.data(), + edges.size(), + loops.data(), loop_normals, - loops_num, - mpoly, + loops.size(), + polys.data(), poly_normals, - polys_num, + polys.size(), wn_data->sharp_edges, clnors); } @@ -459,25 +452,22 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd, static void wn_face_area(WeightedNormalModifierData *wnmd, WeightedNormalData *wn_data) { - const int polys_num = wn_data->polys_num; - const float(*positions)[3] = wn_data->vert_positions; - const MLoop *mloop = wn_data->mloop; - const MPoly *mpoly = wn_data->mpoly; + const blender::Span polys = wn_data->polys; + const blender::Span loops = wn_data->loops; - const MPoly *mp; int mp_index; ModePair *face_area = static_cast( - MEM_malloc_arrayN(size_t(polys_num), sizeof(*face_area), __func__)); + MEM_malloc_arrayN(size_t(polys.size()), sizeof(*face_area), __func__)); ModePair *f_area = face_area; - for (mp_index = 0, mp = mpoly; mp_index < polys_num; mp_index++, mp++, f_area++) { - f_area->val = BKE_mesh_calc_poly_area(mp, &mloop[mp->loopstart], positions); + for (const int i : polys.index_range()) { + f_area->val = BKE_mesh_calc_poly_area(&polys[i], &loops[polys[i].loopstart], positions); f_area->index = mp_index; } - qsort(face_area, polys_num, sizeof(*face_area), modepair_cmp_by_val_inverse); + qsort(face_area, polys.size(), sizeof(*face_area), modepair_cmp_by_val_inverse); wn_data->mode_pair = face_area; apply_weights_vertex_normal(wnmd, wn_data); @@ -485,29 +475,22 @@ static void wn_face_area(WeightedNormalModifierData *wnmd, WeightedNormalData *w static void wn_corner_angle(WeightedNormalModifierData *wnmd, WeightedNormalData *wn_data) { - const int loops_num = wn_data->loops_num; - const int polys_num = wn_data->polys_num; - const float(*positions)[3] = wn_data->vert_positions; - const MLoop *mloop = wn_data->mloop; - const MPoly *mpoly = wn_data->mpoly; - - const MPoly *mp; - int mp_index; + const blender::Span polys = wn_data->polys; + const blender::Span loops = wn_data->loops; ModePair *corner_angle = static_cast( - MEM_malloc_arrayN(size_t(loops_num), sizeof(*corner_angle), __func__)); - - for (mp_index = 0, mp = mpoly; mp_index < polys_num; mp_index++, mp++) { - const MLoop *ml_start = &mloop[mp->loopstart]; + MEM_malloc_arrayN(loops.size(), sizeof(*corner_angle), __func__)); + for (const int i : polys.index_range()) { + const MPoly &poly = polys[i]; float *index_angle = static_cast( - MEM_malloc_arrayN(size_t(mp->totloop), sizeof(*index_angle), __func__)); - BKE_mesh_calc_poly_angles(mp, ml_start, positions, index_angle); + MEM_malloc_arrayN(poly.totloop, sizeof(*index_angle), __func__)); + BKE_mesh_calc_poly_angles(&poly, &loops[poly.loopstart], positions, index_angle); - ModePair *c_angl = &corner_angle[mp->loopstart]; + ModePair *c_angl = &corner_angle[poly.loopstart]; float *angl = index_angle; - for (int ml_index = mp->loopstart; ml_index < mp->loopstart + mp->totloop; + for (int ml_index = poly.loopstart; ml_index < poly.loopstart + poly.totloop; ml_index++, c_angl++, angl++) { c_angl->val = float(M_PI) - *angl; c_angl->index = ml_index; @@ -515,7 +498,7 @@ static void wn_corner_angle(WeightedNormalModifierData *wnmd, WeightedNormalData MEM_freeN(index_angle); } - qsort(corner_angle, loops_num, sizeof(*corner_angle), modepair_cmp_by_val_inverse); + qsort(corner_angle, loops.size(), sizeof(*corner_angle), modepair_cmp_by_val_inverse); wn_data->mode_pair = corner_angle; apply_weights_vertex_normal(wnmd, wn_data); @@ -523,30 +506,23 @@ static void wn_corner_angle(WeightedNormalModifierData *wnmd, WeightedNormalData static void wn_face_with_angle(WeightedNormalModifierData *wnmd, WeightedNormalData *wn_data) { - const int loops_num = wn_data->loops_num; - const int polys_num = wn_data->polys_num; - const float(*positions)[3] = wn_data->vert_positions; - const MLoop *mloop = wn_data->mloop; - const MPoly *mpoly = wn_data->mpoly; - - const MPoly *mp; - int mp_index; + const blender::Span polys = wn_data->polys; + const blender::Span loops = wn_data->loops; ModePair *combined = static_cast( - MEM_malloc_arrayN(size_t(loops_num), sizeof(*combined), __func__)); + MEM_malloc_arrayN(loops.size(), sizeof(*combined), __func__)); - for (mp_index = 0, mp = mpoly; mp_index < polys_num; mp_index++, mp++) { - const MLoop *ml_start = &mloop[mp->loopstart]; - - float face_area = BKE_mesh_calc_poly_area(mp, ml_start, positions); + for (const int i : polys.index_range()) { + const MPoly &poly = polys[i]; + float face_area = BKE_mesh_calc_poly_area(&poly, &loops[poly.loopstart], positions); float *index_angle = static_cast( - MEM_malloc_arrayN(size_t(mp->totloop), sizeof(*index_angle), __func__)); - BKE_mesh_calc_poly_angles(mp, ml_start, positions, index_angle); + MEM_malloc_arrayN(size_t(poly.totloop), sizeof(*index_angle), __func__)); + BKE_mesh_calc_poly_angles(&poly, &loops[poly.loopstart], positions, index_angle); - ModePair *cmbnd = &combined[mp->loopstart]; + ModePair *cmbnd = &combined[poly.loopstart]; float *angl = index_angle; - for (int ml_index = mp->loopstart; ml_index < mp->loopstart + mp->totloop; + for (int ml_index = poly.loopstart; ml_index < poly.loopstart + poly.totloop; ml_index++, cmbnd++, angl++) { /* In this case val is product of corner angle and face area. */ cmbnd->val = (float(M_PI) - *angl) * face_area; @@ -555,7 +531,7 @@ static void wn_face_with_angle(WeightedNormalModifierData *wnmd, WeightedNormalD MEM_freeN(index_angle); } - qsort(combined, loops_num, sizeof(*combined), modepair_cmp_by_val_inverse); + qsort(combined, loops.size(), sizeof(*combined), modepair_cmp_by_val_inverse); wn_data->mode_pair = combined; apply_weights_vertex_normal(wnmd, wn_data); @@ -587,13 +563,10 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * result = (Mesh *)BKE_id_copy_ex(nullptr, &mesh->id, nullptr, LIB_ID_COPY_LOCALIZE); const int verts_num = result->totvert; - const int edges_num = result->totedge; - const int loops_num = result->totloop; - const int polys_num = result->totpoly; const float(*positions)[3] = BKE_mesh_vert_positions(result); - const MEdge *medge = BKE_mesh_edges(result); - const MPoly *mpoly = BKE_mesh_polys(result); - const MLoop *mloop = BKE_mesh_loops(result); + const blender::Span edges = mesh->edges(); + const blender::Span polys = mesh->polys(); + const blender::Span loops = mesh->loops(); /* Right now: * If weight = 50 then all faces are given equal weight. @@ -621,7 +594,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * const bool has_clnors = clnors != nullptr; if (!clnors) { clnors = static_cast(CustomData_add_layer( - &result->ldata, CD_CUSTOMLOOPNORMAL, CD_SET_DEFAULT, nullptr, loops_num)); + &result->ldata, CD_CUSTOMLOOPNORMAL, CD_SET_DEFAULT, nullptr, loops.size())); } const MDeformVert *dvert; @@ -637,22 +610,19 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * WeightedNormalData wn_data{}; wn_data.verts_num = verts_num; - wn_data.edges_num = edges_num; - wn_data.loops_num = loops_num; - wn_data.polys_num = polys_num; wn_data.vert_positions = positions; wn_data.vert_normals = BKE_mesh_vertex_normals_ensure(result); - wn_data.medge = medge; + wn_data.edges = edges; wn_data.sharp_edges = sharp_edges.span.data(); - wn_data.mloop = mloop; + wn_data.loops = loops; wn_data.loop_to_poly = loop_to_poly_map; wn_data.clnors = clnors; wn_data.has_clnors = has_clnors; wn_data.split_angle = split_angle; - wn_data.mpoly = mpoly; + wn_data.polys = polys; wn_data.poly_normals = BKE_mesh_poly_normals_ensure(mesh); wn_data.poly_strength = static_cast(CustomData_get_layer_named( &result->pdata, CD_PROP_INT32, MOD_WEIGHTEDNORMALS_FACEWEIGHT_CDLAYER_ID)); diff --git a/source/blender/render/intern/bake.cc b/source/blender/render/intern/bake.cc index c8ecb827c6d..2712e5ab96b 100644 --- a/source/blender/render/intern/bake.cc +++ b/source/blender/render/intern/bake.cc @@ -461,8 +461,8 @@ static TriTessFace *mesh_calc_tri_tessface(Mesh *me, bool tangent, Mesh *me_eval float no[3]; const float(*positions)[3] = BKE_mesh_vert_positions(me); - const MPoly *polys = BKE_mesh_polys(me); - const MLoop *loops = BKE_mesh_loops(me); + const blender::Span polys = me->polys(); + const blender::Span loops = me->loops(); looptri = static_cast(MEM_mallocN(sizeof(*looptri) * tottri, __func__)); triangles = static_cast(MEM_callocN(sizeof(TriTessFace) * tottri, __func__)); @@ -473,11 +473,17 @@ static TriTessFace *mesh_calc_tri_tessface(Mesh *me, bool tangent, Mesh *me_eval const bool calculate_normal = precomputed_normals ? false : true; if (precomputed_normals != nullptr) { - BKE_mesh_recalc_looptri_with_normals( - loops, polys, positions, me->totloop, me->totpoly, looptri, precomputed_normals); + BKE_mesh_recalc_looptri_with_normals(loops.data(), + polys.data(), + positions, + me->totloop, + me->totpoly, + looptri, + precomputed_normals); } else { - BKE_mesh_recalc_looptri(loops, polys, positions, me->totloop, me->totpoly, looptri); + BKE_mesh_recalc_looptri( + loops.data(), polys.data(), positions, me->totloop, me->totpoly, looptri); } const TSpace *tspace = nullptr; @@ -746,9 +752,10 @@ void RE_bake_pixels_populate(Mesh *me, MLoopTri *looptri = static_cast(MEM_mallocN(sizeof(*looptri) * tottri, __func__)); const float(*positions)[3] = BKE_mesh_vert_positions(me); - const MPoly *polys = BKE_mesh_polys(me); - const MLoop *loops = BKE_mesh_loops(me); - BKE_mesh_recalc_looptri(loops, polys, positions, me->totloop, me->totpoly, looptri); + const blender::Span polys = me->polys(); + const blender::Span loops = me->loops(); + BKE_mesh_recalc_looptri( + loops.data(), polys.data(), positions, me->totloop, me->totpoly, looptri); const int *material_indices = BKE_mesh_material_indices(me); const int materials_num = targets->materials_num; diff --git a/source/blender/render/intern/multires_bake.cc b/source/blender/render/intern/multires_bake.cc index 8a7d8090da4..22b091b52c6 100644 --- a/source/blender/render/intern/multires_bake.cc +++ b/source/blender/render/intern/multires_bake.cc @@ -488,15 +488,9 @@ static void do_multires_bake(MultiresBakeRender *bkr, memcpy(temp_mesh->vert_positions_for_write().data(), positions, temp_mesh->totvert * sizeof(float[3])); - memcpy(BKE_mesh_edges_for_write(temp_mesh), - dm->getEdgeArray(dm), - temp_mesh->totedge * sizeof(MEdge)); - memcpy(BKE_mesh_polys_for_write(temp_mesh), - dm->getPolyArray(dm), - temp_mesh->totpoly * sizeof(MPoly)); - memcpy(BKE_mesh_loops_for_write(temp_mesh), - dm->getLoopArray(dm), - temp_mesh->totloop * sizeof(MLoop)); + temp_mesh->edges_for_write().copy_from({dm->getEdgeArray(dm), temp_mesh->totedge}); + temp_mesh->polys_for_write().copy_from({dm->getPolyArray(dm), temp_mesh->totpoly}); + temp_mesh->loops_for_write().copy_from({dm->getLoopArray(dm), temp_mesh->totloop}); const float(*vert_normals)[3] = BKE_mesh_vertex_normals_ensure(temp_mesh); const float(*poly_normals)[3] = BKE_mesh_poly_normals_ensure(temp_mesh);