[Bf-blender-cvs] [f69e57a53fa] master: Alembic export: fix exporting of loop normals

Sybren A. Stüvel noreply at git.blender.org
Tue Jul 30 17:07:15 CEST 2019


Commit: f69e57a53fab92d549a90a0198b86ff766ba0da2
Author: Sybren A. Stüvel
Date:   Tue Jul 30 17:05:37 2019 +0200
Branches: master
https://developer.blender.org/rBf69e57a53fab92d549a90a0198b86ff766ba0da2

Alembic export: fix exporting of loop normals

When the mesh is using custom normals, those should always be exported,
regardless of the `ME_SMOOTH` flag on the invidivual polys.

Also replaced the loop normal writing with the same logic as we use for
reading (less pointer arithmetic, more normal counting).

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

M	source/blender/alembic/intern/abc_mesh.cc

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

diff --git a/source/blender/alembic/intern/abc_mesh.cc b/source/blender/alembic/intern/abc_mesh.cc
index 1b5ae0b7adc..9e6f2dd6b52 100644
--- a/source/blender/alembic/intern/abc_mesh.cc
+++ b/source/blender/alembic/intern/abc_mesh.cc
@@ -205,17 +205,14 @@ static void get_loop_normals(struct Mesh *mesh, std::vector<Imath::V3f> &normals
   normals.clear();
   normals.resize(mesh->totloop);
 
-  unsigned loop_index = 0;
-
   /* NOTE: data needs to be written in the reverse order. */
+  int abc_index = 0;
 
   if (lnors) {
     for (int i = 0, e = mesh->totpoly; i < e; ++i, ++mp) {
-      ml = mloop + mp->loopstart + (mp->totloop - 1);
-
-      for (int j = 0; j < mp->totloop; --ml, ++j, ++loop_index) {
-        const int index = ml->v;
-        copy_yup_from_zup(normals[loop_index].getValue(), lnors[index]);
+      for (int j = mp->totloop - 1; j >= 0; --j, ++abc_index) {
+        int blender_index = mp->loopstart + j;
+        copy_yup_from_zup(normals[abc_index].getValue(), lnors[blender_index]);
       }
     }
   }
@@ -229,15 +226,15 @@ static void get_loop_normals(struct Mesh *mesh, std::vector<Imath::V3f> &normals
       if ((mp->flag & ME_SMOOTH) == 0) {
         BKE_mesh_calc_poly_normal(mp, ml - (mp->totloop - 1), verts, no);
 
-        for (int j = 0; j < mp->totloop; --ml, ++j, ++loop_index) {
-          copy_yup_from_zup(normals[loop_index].getValue(), no);
+        for (int j = 0; j < mp->totloop; --ml, ++j, ++abc_index) {
+          copy_yup_from_zup(normals[abc_index].getValue(), no);
         }
       }
       else {
         /* Smooth shaded, use individual vert normals. */
-        for (int j = 0; j < mp->totloop; --ml, ++j, ++loop_index) {
+        for (int j = 0; j < mp->totloop; --ml, ++j, ++abc_index) {
           normal_short_to_float_v3(no, verts[ml->v].no);
-          copy_yup_from_zup(normals[loop_index].getValue(), no);
+          copy_yup_from_zup(normals[abc_index].getValue(), no);
         }
       }
     }
@@ -413,7 +410,7 @@ void AbcGenericMeshWriter::writeMesh(struct Mesh *mesh)
   std::vector<int32_t> poly_verts, loop_counts;
   std::vector<Imath::V3f> velocities;
 
-  bool export_loop_normals = false;
+  bool export_loop_normals = (mesh->flag & ME_AUTOSMOOTH) != 0;
 
   get_vertices(mesh, points);
   get_topology(mesh, poly_verts, loop_counts, export_loop_normals);



More information about the Bf-blender-cvs mailing list