[Bf-blender-cvs] [106947c564b] refactor-mesh-material-index-generic: Cleanup: Use attribute API

Hans Goudey noreply at git.blender.org
Sat Aug 27 07:31:11 CEST 2022


Commit: 106947c564bddd4a051f7ddc6ebe308e58ac5dae
Author: Hans Goudey
Date:   Sat Aug 27 00:30:46 2022 -0500
Branches: refactor-mesh-material-index-generic
https://developer.blender.org/rB106947c564bddd4a051f7ddc6ebe308e58ac5dae

Cleanup: Use attribute API

===================================================================

M	source/blender/blenkernel/intern/mesh_convert.cc

===================================================================

diff --git a/source/blender/blenkernel/intern/mesh_convert.cc b/source/blender/blenkernel/intern/mesh_convert.cc
index 0f24d8df8d5..0f05a3635c4 100644
--- a/source/blender/blenkernel/intern/mesh_convert.cc
+++ b/source/blender/blenkernel/intern/mesh_convert.cc
@@ -140,6 +140,7 @@ static void make_edges_mdata_extend(Mesh &mesh)
 
 static Mesh *mesh_nurbs_displist_to_mesh(const Curve *cu, const ListBase *dispbase)
 {
+  using namespace blender::bke;
   const float *data;
   int a, b, ofs, vertcount, startvert, totvert = 0, totedge = 0, totloop = 0, totpoly = 0;
   int p1, p2, p3, p4, *index;
@@ -194,7 +195,9 @@ static Mesh *mesh_nurbs_displist_to_mesh(const Curve *cu, const ListBase *dispba
   MEdge *medge = edges.data();
   MPoly *mpoly = polys.data();
   MLoop *mloop = loops.data();
-  int *material_indices = BKE_mesh_material_indices_for_write(mesh);
+  MutableAttributeAccessor attributes = mesh_attributes_for_write(*mesh);
+  SpanAttributeWriter<int> material_indices = attributes.lookup_or_add_for_write_only_span<int>(
+      "material_index", ATTR_DOMAIN_FACE);
   MLoopUV *mloopuv = static_cast<MLoopUV *>(CustomData_add_layer_named(
       &mesh->ldata, CD_MLOOPUV, CD_CALLOC, nullptr, mesh->totloop, "UVMap"));
 
@@ -273,7 +276,7 @@ static Mesh *mesh_nurbs_displist_to_mesh(const Curve *cu, const ListBase *dispba
         mloop[2].v = startvert + index[1];
         mpoly->loopstart = (int)(mloop - loops.data());
         mpoly->totloop = 3;
-        material_indices[mpoly - polys.data()] = dl->col;
+        material_indices.span[mpoly - polys.data()] = dl->col;
 
         if (mloopuv) {
           for (int i = 0; i < 3; i++, mloopuv++) {
@@ -333,7 +336,7 @@ static Mesh *mesh_nurbs_displist_to_mesh(const Curve *cu, const ListBase *dispba
           mloop[3].v = p2;
           mpoly->loopstart = (int)(mloop - loops.data());
           mpoly->totloop = 4;
-          material_indices[mpoly - polys.data()] = dl->col;
+          material_indices.span[mpoly - polys.data()] = dl->col;
 
           if (mloopuv) {
             int orco_sizeu = dl->nr - 1;
@@ -386,6 +389,8 @@ static Mesh *mesh_nurbs_displist_to_mesh(const Curve *cu, const ListBase *dispba
     make_edges_mdata_extend(*mesh);
   }
 
+  material_indices.finish();
+
   return mesh;
 }



More information about the Bf-blender-cvs mailing list