[Bf-blender-cvs] [bf5c103d834] refactor-mesh-remove-pointers: Fix errors in Alembic export, remove changes in that area

Hans Goudey noreply at git.blender.org
Thu Sep 1 05:55:56 CEST 2022


Commit: bf5c103d83472b5a5ff63cd8310d9122afaf55ce
Author: Hans Goudey
Date:   Wed Aug 31 22:55:49 2022 -0500
Branches: refactor-mesh-remove-pointers
https://developer.blender.org/rBbf5c103d83472b5a5ff63cd8310d9122afaf55ce

Fix errors in Alembic export, remove changes in that area

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

M	source/blender/io/alembic/exporter/abc_writer_mesh.cc
M	source/blender/io/alembic/intern/abc_customdata.cc
M	source/blender/io/alembic/intern/abc_customdata.h
M	source/blender/io/alembic/intern/abc_reader_mesh.cc

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

diff --git a/source/blender/io/alembic/exporter/abc_writer_mesh.cc b/source/blender/io/alembic/exporter/abc_writer_mesh.cc
index 3805f1bc0b2..acfa4c1ea08 100644
--- a/source/blender/io/alembic/exporter/abc_writer_mesh.cc
+++ b/source/blender/io/alembic/exporter/abc_writer_mesh.cc
@@ -176,6 +176,11 @@ void ABCGenericMeshWriter::do_write(HierarchyContext &context)
 
   m_custom_data_config.pack_uvs = args_.export_params->packuv;
   m_custom_data_config.mesh = mesh;
+  m_custom_data_config.mpoly = mesh->polygons_for_write().data();
+  m_custom_data_config.mloop = mesh->loops_for_write().data();
+  m_custom_data_config.totpoly = mesh->totpoly;
+  m_custom_data_config.totloop = mesh->totloop;
+  m_custom_data_config.totvert = mesh->totvert;
   m_custom_data_config.timesample_index = timesample_index_;
 
   try {
@@ -431,9 +436,9 @@ static void get_vertices(struct Mesh *mesh, std::vector<Imath::V3f> &points)
   points.clear();
   points.resize(mesh->totvert);
 
-  const Span<MVert> vertices = mesh->vertices();
+  const Span<MVert> verts = mesh->vertices();
   for (int i = 0, e = mesh->totvert; i < e; i++) {
-    copy_yup_from_zup(points[i].getValue(), vertices[i].co);
+    copy_yup_from_zup(points[i].getValue(), verts[i].co);
   }
 }
 
diff --git a/source/blender/io/alembic/intern/abc_customdata.cc b/source/blender/io/alembic/intern/abc_customdata.cc
index 211ce9a45ff..64f1087a5de 100644
--- a/source/blender/io/alembic/intern/abc_customdata.cc
+++ b/source/blender/io/alembic/intern/abc_customdata.cc
@@ -56,17 +56,18 @@ static void get_uvs(const CDStreamConfig &config,
     return;
   }
 
-  const Span<MPoly> polys = config.polys;
-  const Span<MLoop> loops = config.loops;
+  const int num_poly = config.totpoly;
+  MPoly *polygons = config.mpoly;
+  MLoop *mloop = config.mloop;
 
   if (!config.pack_uvs) {
     int count = 0;
-    uvidx.resize(loops.size());
-    uvs.resize(loops.size());
+    uvidx.resize(config.totloop);
+    uvs.resize(config.totloop);
 
     /* Iterate in reverse order to match exported polygons. */
-    for (const int i : polys.index_range()) {
-      const MPoly &current_poly = polys[i];
+    for (int i = 0; i < num_poly; i++) {
+      MPoly &current_poly = polygons[i];
       const MLoopUV *loopuv = mloopuv_array + current_poly.loopstart + current_poly.totloop;
 
       for (int j = 0; j < current_poly.totloop; j++, count++) {
@@ -80,12 +81,12 @@ static void get_uvs(const CDStreamConfig &config,
   }
   else {
     /* Mapping for indexed UVs, deduplicating UV coordinates at vertices. */
-    std::vector<std::vector<uint32_t>> idx_map(config.verts.size());
+    std::vector<std::vector<uint32_t>> idx_map(config.totvert);
     int idx_count = 0;
 
-    for (const int i : polys.index_range()) {
-      const MPoly &current_poly = polys[i];
-      const MLoop *looppoly = &loops[current_poly.loopstart + current_poly.totloop];
+    for (int i = 0; i < num_poly; i++) {
+      MPoly &current_poly = polygons[i];
+      MLoop *looppoly = mloop + current_poly.loopstart + current_poly.totloop;
       const MLoopUV *loopuv = mloopuv_array + current_poly.loopstart + current_poly.totloop;
 
       for (int j = 0; j < current_poly.totloop; j++) {
@@ -171,19 +172,19 @@ static void get_cols(const CDStreamConfig &config,
                      const void *cd_data)
 {
   const float cscale = 1.0f / 255.0f;
-  const Span<MPoly> polys = config.polys;
-  const Span<MLoop> loops = config.loops;
+  const MPoly *polys = config.mpoly;
+  const MLoop *mloops = config.mloop;
   const MCol *cfaces = static_cast<const MCol *>(cd_data);
 
-  buffer.reserve(config.verts.size());
-  uvidx.reserve(config.verts.size());
+  buffer.reserve(config.totvert);
+  uvidx.reserve(config.totvert);
 
   Imath::C4f col;
 
-  for (const int i : polys.index_range()) {
+  for (int i = 0; i < config.totpoly; i++) {
     const MPoly *p = &polys[i];
     const MCol *cface = &cfaces[p->loopstart + p->totloop];
-    const MLoop *mloop = &loops[p->loopstart + p->totloop];
+    const MLoop *mloop = &mloops[p->loopstart + p->totloop];
 
     for (int j = 0; j < p->totloop; j++) {
       cface--;
@@ -246,9 +247,9 @@ void write_generated_coordinates(const OCompoundProperty &prop, CDStreamConfig &
   const float(*orcodata)[3] = static_cast<const float(*)[3]>(customdata);
 
   /* Convert 3D vertices from float[3] z=up to V3f y=up. */
-  std::vector<Imath::V3f> coords(mesh->totvert);
+  std::vector<Imath::V3f> coords(config.totvert);
   float orco_yup[3];
-  for (int vertex_idx = 0; vertex_idx < mesh->totvert; vertex_idx++) {
+  for (int vertex_idx = 0; vertex_idx < config.totvert; vertex_idx++) {
     copy_yup_from_zup(orco_yup, orcodata[vertex_idx]);
     coords[vertex_idx].setValue(orco_yup[0], orco_yup[1], orco_yup[2]);
   }
@@ -317,8 +318,8 @@ static void read_uvs(const CDStreamConfig &config,
                      const Alembic::AbcGeom::V2fArraySamplePtr &uvs,
                      const UInt32ArraySamplePtr &indices)
 {
-  const Span<MPoly> polys = config.polys;
-  const Span<MLoop> loops = config.loops;
+  MPoly *mpolys = config.mpoly;
+  MLoop *mloops = config.mloop;
   MLoopUV *mloopuvs = static_cast<MLoopUV *>(data);
 
   unsigned int uv_index, loop_index, rev_loop_index;
@@ -326,13 +327,13 @@ static void read_uvs(const CDStreamConfig &config,
   BLI_assert(uv_scope != ABC_UV_SCOPE_NONE);
   const bool do_uvs_per_loop = (uv_scope == ABC_UV_SCOPE_LOOP);
 
-  for (const int i : polys.index_range()) {
-    const MPoly &poly = polys[i];
+  for (int i = 0; i < config.totpoly; i++) {
+    MPoly &poly = mpolys[i];
     unsigned int rev_loop_offset = poly.loopstart + poly.totloop - 1;
 
     for (int f = 0; f < poly.totloop; f++) {
       rev_loop_index = rev_loop_offset - f;
-      loop_index = do_uvs_per_loop ? poly.loopstart + f : loops[rev_loop_index].v;
+      loop_index = do_uvs_per_loop ? poly.loopstart + f : mloops[rev_loop_index].v;
       uv_index = (*indices)[loop_index];
       const Imath::V2f &uv = (*uvs)[uv_index];
 
@@ -384,7 +385,7 @@ static void read_custom_data_mcols(const std::string &iobject_full_name,
 
     color_param.getIndexed(sample, iss);
     is_facevarying = sample.getScope() == kFacevaryingScope &&
-                     config.loops.size() == sample.getIndices()->size();
+                     config.totloop == sample.getIndices()->size();
 
     c3f_ptr = sample.getVals();
     indices = sample.getIndices();
@@ -397,7 +398,7 @@ static void read_custom_data_mcols(const std::string &iobject_full_name,
 
     color_param.getIndexed(sample, iss);
     is_facevarying = sample.getScope() == kFacevaryingScope &&
-                     config.loops.size() == sample.getIndices()->size();
+                     config.totloop == sample.getIndices()->size();
 
     c4f_ptr = sample.getVals();
     indices = sample.getIndices();
@@ -413,8 +414,8 @@ static void read_custom_data_mcols(const std::string &iobject_full_name,
   void *cd_data = config.add_customdata_cb(
       config.mesh, prop_header.getName().c_str(), CD_PROP_BYTE_COLOR);
   MCol *cfaces = static_cast<MCol *>(cd_data);
-  const Span<MPoly> polys = config.polys;
-  const Span<MLoop> loops = config.loops;
+  MPoly *mpolys = config.mpoly;
+  MLoop *mloops = config.mloop;
 
   size_t face_index = 0;
   size_t color_index;
@@ -426,10 +427,10 @@ static void read_custom_data_mcols(const std::string &iobject_full_name,
    * is why we have to check for indices->size() > 0 */
   bool use_dual_indexing = is_facevarying && indices->size() > 0;
 
-  for (const int i : polys.index_range()) {
-    const MPoly *poly = &polys[i];
+  for (int i = 0; i < config.totpoly; i++) {
+    MPoly *poly = &mpolys[i];
     MCol *cface = &cfaces[poly->loopstart + poly->totloop];
-    const MLoop *mloop = &loops[poly->loopstart + poly->totloop];
+    MLoop *mloop = &mloops[poly->loopstart + poly->totloop];
 
     for (int j = 0; j < poly->totloop; j++, face_index++) {
       cface--;
@@ -591,14 +592,14 @@ AbcUvScope get_uv_scope(const Alembic::AbcGeom::GeometryScope scope,
                         const CDStreamConfig &config,
                         const Alembic::AbcGeom::UInt32ArraySamplePtr &indices)
 {
-  if (scope == kFacevaryingScope && indices->size() == config.loops.size()) {
+  if (scope == kFacevaryingScope && indices->size() == config.totloop) {
     return ABC_UV_SCOPE_LOOP;
   }
 
   /* kVaryingScope is sometimes used for vertex scopes as the values vary across the vertices. To
    * be sure, one has to check the size of the data against the number of vertices, as it could
    * also be a varying attribute across the faces (i.e. one value per face). */
-  if ((ELEM(scope, kVaryingScope, kVertexScope)) && indices->size() == config.verts.size()) {
+  if ((ELEM(scope, kVaryingScope, kVertexScope)) && indices->size() == config.totvert) {
     return ABC_UV_SCOPE_VERTEX;
   }
 
diff --git a/source/blender/io/alembic/intern/abc_customdata.h b/source/blender/io/alembic/intern/abc_customdata.h
index d4b4fa8c33f..0ddba866016 100644
--- a/source/blender/io/alembic/intern/abc_customdata.h
+++ b/source/blender/io/alembic/intern/abc_customdata.h
@@ -6,8 +6,6 @@
  * \ingroup balembic
  */
 
-#include "BLI_span.hh"
-
 #include <Alembic/Abc/All.h>
 #include <Alembic/AbcGeom/All.h>
 
@@ -30,11 +28,14 @@ struct UVSample {
 };
 
 struct CDStreamConfig {
+  MLoop *mloop;
+  int totloop;
+
+  MPoly *mpoly;
+  int totpoly;
 
-  /* Only set for import. */
-  MutableSpan<MVert> verts;
-  MutableSpan<MPoly> polys;
-  MutableSpan<MLoop> loops;
+  MVert *mvert;
+  int totvert;
 
   MLoopUV *mloopuv;
 
@@ -70,7 +71,12 @@ struct CDStreamConfig {
   std::map<std::string, Alembic::AbcGeom::OC4fGeomParam> abc_vertex_colors;
 
   CDStreamConfig()
-      : pack_uvs(false),
+      : mloop(NULL),
+        totloop(0),
+        mpoly(NULL),
+        totpoly(0),
+        totvert(0),
+        pack_uvs(false),
         mesh(NULL),
         add_customdata_cb(NULL),
         weight(0.0),
diff --git a/source/blender/io/alembic/intern/abc_reader_mesh.cc b/source/blender/io/alembic/intern/abc_reader_mesh.cc
index dadfa93a6fb..2066ceebec6 100644
--- a/source/blender/io/alembic/intern/abc_reader_mesh.cc
+++ b/source/blender/io/alembic/intern/abc_reader_mesh.cc
@@ -117,14 +

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list