[Bf-blender-cvs] [07514def194] blender-v3.1-release: Fix T95328, new obj exporter not exporting custom normals.

Aras Pranckevicius noreply at git.blender.org
Sun Jan 30 19:51:59 CET 2022


Commit: 07514def194a78fbb70931d5fbd002248e8f3c34
Author: Aras Pranckevicius
Date:   Sun Jan 30 13:48:03 2022 -0500
Branches: blender-v3.1-release
https://developer.blender.org/rB07514def194a78fbb70931d5fbd002248e8f3c34

Fix T95328, new obj exporter not exporting custom normals.

Previously, the new obj exporter was only exporting per-vertex normals for faces
marked as "smooth". But a face can have custom normals, as soon as the normals
data layer exists. This change makes it follow the behavior of USD & Collada
exporters and the old Python one, which also export per-vertex normals as soon
as the layer is there. (From Patch D13957.)

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

M	source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc
M	source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc

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

diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc
index c1b12ddd217..14e50d726c0 100644
--- a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc
+++ b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc
@@ -358,7 +358,7 @@ void OBJMesh::store_normal_coords_and_indices(Vector<float3> &r_normal_coords)
       *lnors)[3] = (const float(*)[3])(CustomData_get_layer(&export_mesh_eval_->ldata, CD_NORMAL));
   for (int poly_index = 0; poly_index < export_mesh_eval_->totpoly; ++poly_index) {
     const MPoly &mpoly = export_mesh_eval_->mpoly[poly_index];
-    bool need_per_loop_normals = is_ith_poly_smooth(poly_index);
+    bool need_per_loop_normals = lnors != nullptr || (mpoly.flag & ME_SMOOTH);
     if (need_per_loop_normals) {
       for (int loop_of_poly = 0; loop_of_poly < mpoly.totloop; ++loop_of_poly) {
         float3 loop_normal;
diff --git a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc
index 89e1de49511..1e2d509ef29 100644
--- a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc
+++ b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc
@@ -402,6 +402,18 @@ TEST_F(obj_exporter_regression_test, cube_all_data_triangulated)
                                _export.params);
 }
 
+TEST_F(obj_exporter_regression_test, cube_normal_edit)
+{
+  OBJExportParamsDefault _export;
+  _export.params.forward_axis = OBJ_AXIS_Y_FORWARD;
+  _export.params.up_axis = OBJ_AXIS_Z_UP;
+  _export.params.export_materials = false;
+  compare_obj_export_to_golden("io_tests/blend_geometry/cube_normal_edit.blend",
+                               "io_tests/obj/cube_normal_edit.obj",
+                               "",
+                               _export.params);
+}
+
 TEST_F(obj_exporter_regression_test, suzanne_all_data)
 {
   OBJExportParamsDefault _export;



More information about the Bf-blender-cvs mailing list