[Bf-blender-cvs] [22686b4ccf5] soc-2020-io-performance: Export transform was wrongly calculated.

Howard Trickey noreply at git.blender.org
Mon Jun 7 05:18:57 CEST 2021


Commit: 22686b4ccf5ff249a3323232690cd605b1a5f53d
Author: Howard Trickey
Date:   Sun Jun 6 20:16:28 2021 -0700
Branches: soc-2020-io-performance
https://developer.blender.org/rB22686b4ccf5ff249a3323232690cd605b1a5f53d

Export transform was wrongly calculated.

Several mistakes fixed: Blender's axes convention was wrongly stated;
the mat3_from_axis_conversion in C returns a transposed matrix,
probably because it was copied from Python; the axis transformation
wasn't properly applied to the location part of an object transform.

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

M	source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc
M	source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc
M	source/blender/io/wavefront_obj/importer/importer_mesh_utils.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 8815c0e30b9..d4b017bcece 100644
--- a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc
+++ b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc
@@ -129,12 +129,14 @@ void OBJMesh::set_world_axes_transform(const eTransformAxisForward forward,
 {
   float axes_transform[3][3];
   unit_m3(axes_transform);
-  /* -Y-forward and +Z-up are the default Blender axis settings. */
-  mat3_from_axis_conversion(
-      OBJ_AXIS_NEGATIVE_Y_FORWARD, OBJ_AXIS_Z_UP, forward, up, axes_transform);
+  /* +Y-forward and +Z-up are the default Blender axis settings. */
+  mat3_from_axis_conversion(OBJ_AXIS_Y_FORWARD, OBJ_AXIS_Z_UP, forward, up, axes_transform);
+  /* mat3_from_axis_conversion returns a transposed matrix! */
+  transpose_m3(axes_transform);
   mul_m4_m3m4(world_and_axes_transform_, axes_transform, export_object_eval_->obmat);
-  /* mul_m4_m3m4 does not copy last row of obmat, i.e. location data. */
-  copy_v4_v4(world_and_axes_transform_[3], export_object_eval_->obmat[3]);
+  /* mul_m4_m3m4 does not transform last row of obmat, i.e. location data. */
+  mul_v3_m3v3(world_and_axes_transform_[3], axes_transform, export_object_eval_->obmat[3]);
+  world_and_axes_transform_[3][3] = export_object_eval_->obmat[3][3];
 }
 
 int OBJMesh::tot_vertices() const
@@ -377,8 +379,8 @@ void OBJMesh::calc_loop_normals(const int poly_index, Vector<float3> &r_loop_nor
 {
   r_loop_normals.clear();
   const MPoly &mpoly = export_mesh_eval_->mpoly[poly_index];
-  const float(*lnors)[3] = (const float(*)[3])(
-      CustomData_get_layer(&export_mesh_eval_->ldata, CD_NORMAL));
+  const float(
+      *lnors)[3] = (const float(*)[3])(CustomData_get_layer(&export_mesh_eval_->ldata, CD_NORMAL));
   for (int loop_of_poly = 0; loop_of_poly < mpoly.totloop; loop_of_poly++) {
     float3 loop_normal;
     copy_v3_v3(loop_normal, lnors[mpoly.loopstart + loop_of_poly]);
diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc b/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc
index 6e368c307a2..d21665ba040 100644
--- a/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc
+++ b/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc
@@ -50,12 +50,14 @@ void OBJCurve::set_world_axes_transform(const eTransformAxisForward forward,
 {
   float axes_transform[3][3];
   unit_m3(axes_transform);
-  /* -Y-forward and +Z-up are the Blender's default axis settings. */
-  mat3_from_axis_conversion(
-      OBJ_AXIS_NEGATIVE_Y_FORWARD, OBJ_AXIS_Z_UP, forward, up, axes_transform);
+  /* +Y-forward and +Z-up are the Blender's default axis settings. */
+  mat3_from_axis_conversion(OBJ_AXIS_Y_FORWARD, OBJ_AXIS_Z_UP, forward, up, axes_transform);
+  /* mat3_from_axis_conversion returns a transposed matrix! */
+  transpose_m3(axes_transform);
   mul_m4_m3m4(world_axes_transform_, axes_transform, export_object_eval_->obmat);
-  /* #mul_m4_m3m4 does not copy last row of #Object.obmat, i.e. location data. */
-  copy_v4_v4(world_axes_transform_[3], export_object_eval_->obmat[3]);
+  /* #mul_m4_m3m4 does not transform last row of #Object.obmat, i.e. location data. */
+  mul_v3_m3v3(world_axes_transform_[3], axes_transform, export_object_eval_->obmat[3]);
+  world_axes_transform_[3][3] = export_object_eval_->obmat[3][3];
 }
 
 const char *OBJCurve::get_curve_name() const
diff --git a/source/blender/io/wavefront_obj/importer/importer_mesh_utils.cc b/source/blender/io/wavefront_obj/importer/importer_mesh_utils.cc
index 7b46b812551..eb86da836f7 100644
--- a/source/blender/io/wavefront_obj/importer/importer_mesh_utils.cc
+++ b/source/blender/io/wavefront_obj/importer/importer_mesh_utils.cc
@@ -336,19 +336,21 @@ void transform_object(Object *object, const OBJImportParams &import_params)
   unit_m4(object->obmat);
   /* Location shift should be 0. */
   copy_v3_fl(object->obmat[3], 0.0f);
-  /* -Y-forward and +Z-up are the default Blender axis settings. */
-  mat3_from_axis_conversion(OBJ_AXIS_NEGATIVE_Y_FORWARD,
+  /* +Y-forward and +Z-up are the default Blender axis settings. */
+  mat3_from_axis_conversion(OBJ_AXIS_Y_FORWARD,
                             OBJ_AXIS_Z_UP,
                             import_params.forward_axis,
                             import_params.up_axis,
                             axes_transform);
+  /* mat3_from_axis_conversion returns a transposed matrix! */
+  transpose_m3(axes_transform);
   mul_m4_m3m4(object->obmat, axes_transform, object->obmat);
 
   if (import_params.clamp_size != 0.0f) {
     float3 max_coord(-INT_MAX);
     float3 min_coord(INT_MAX);
     BoundBox *bb = BKE_mesh_boundbox_get(object);
-    for (const float (&vertex)[3] : bb->vec) {
+    for (const float(&vertex)[3] : bb->vec) {
       for (int axis = 0; axis < 3; axis++) {
         max_coord[axis] = max_ff(max_coord[axis], vertex[axis]);
         min_coord[axis] = min_ff(min_coord[axis], vertex[axis]);



More information about the Bf-blender-cvs mailing list