[Bf-blender-cvs] [122b9478c66] master: refactor collada: replace bc_sanitize_mat() by static class method in BCMatrix

Gaia Clary noreply at git.blender.org
Sun Jun 2 23:01:48 CEST 2019


Commit: 122b9478c66e13fa3c14da606cfa92528acd0b87
Author: Gaia Clary
Date:   Tue May 28 09:23:05 2019 +0200
Branches: master
https://developer.blender.org/rB122b9478c66e13fa3c14da606cfa92528acd0b87

refactor collada: replace bc_sanitize_mat() by static class method in BCMatrix

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

M	source/blender/collada/ArmatureExporter.cpp
M	source/blender/collada/BCMath.cpp
M	source/blender/collada/BCMath.h
M	source/blender/collada/BCSampleData.cpp
M	source/blender/collada/BlenderContext.h
M	source/blender/collada/ControllerExporter.cpp
M	source/blender/collada/ExportSettings.h
M	source/blender/collada/TransformWriter.cpp
M	source/blender/collada/collada_utils.cpp
M	source/blender/collada/collada_utils.h

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

diff --git a/source/blender/collada/ArmatureExporter.cpp b/source/blender/collada/ArmatureExporter.cpp
index ed645ee5001..84979cc4ca4 100644
--- a/source/blender/collada/ArmatureExporter.cpp
+++ b/source/blender/collada/ArmatureExporter.cpp
@@ -315,7 +315,7 @@ void ArmatureExporter::add_bone_transform(Object *ob_arm, Bone *bone, COLLADASW:
   }
 
   if (this->export_settings.get_limit_precision()) {
-    bc_sanitize_mat(mat, LIMITTED_PRECISION);
+    BCMatrix::sanitize(mat, LIMITTED_PRECISION);
   }
 
   TransformWriter::add_joint_transform(node, mat, NULL, this->export_settings, has_restmat);
diff --git a/source/blender/collada/BCMath.cpp b/source/blender/collada/BCMath.cpp
index 8d4a0778cc1..a07d1e735ff 100644
--- a/source/blender/collada/BCMath.cpp
+++ b/source/blender/collada/BCMath.cpp
@@ -19,7 +19,6 @@
 
 #include "BCMath.h"
 #include "BlenderContext.h"
-#include "collada_utils.h"
 
 BCMatrix::BCMatrix(const BCMatrix &mat)
 {
@@ -134,7 +133,19 @@ void BCMatrix::transpose(Matrix &mat)
 
 void BCMatrix::sanitize(Matrix &mat, int precision)
 {
-  bc_sanitize_mat(mat, precision);
+  for (int i = 0; i < 4; i++)
+    for (int j = 0; j < 4; j++) {
+      double val = (double)mat[i][j];
+      val = double_round(val, precision);
+      mat[i][j] = (float)val;
+    }
+}
+
+void BCMatrix::sanitize(DMatrix &mat, int precision)
+{
+  for (int i = 0; i < 4; i++)
+    for (int j = 0; j < 4; j++)
+      mat[i][j] = double_round(mat[i][j], precision);
 }
 
 void BCMatrix::unit()
diff --git a/source/blender/collada/BCMath.h b/source/blender/collada/BCMath.h
index 2866e983689..00e8f24c970 100644
--- a/source/blender/collada/BCMath.h
+++ b/source/blender/collada/BCMath.h
@@ -32,9 +32,6 @@ class BCQuat {
  private:
   mutable Quat q;
 
-  void unit();
-  void copy(Quat &r, Quat &a);
-
  public:
   BCQuat(const BCQuat &other)
   {
@@ -102,7 +99,9 @@ class BCMatrix {
   void apply_transform(const BCMatrix &matrix, const bool inverted = false);
 
   const bool in_range(const BCMatrix &other, float distance) const;
+
   static void sanitize(Matrix &matrix, int precision);
+  static void sanitize(DMatrix &matrix, int precision);
   static void transpose(Matrix &matrix);
 };
 
diff --git a/source/blender/collada/BCSampleData.cpp b/source/blender/collada/BCSampleData.cpp
index 6258c9c9bdb..fff3c393a1d 100644
--- a/source/blender/collada/BCSampleData.cpp
+++ b/source/blender/collada/BCSampleData.cpp
@@ -75,193 +75,3 @@ const BCMatrix &BCSample::get_matrix() const
 {
   return obmat;
 }
-
-BCMatrix::BCMatrix(const BCMatrix &mat)
-{
-  set_transform(mat.matrix);
-}
-
-BCMatrix::BCMatrix(Matrix &mat)
-{
-  set_transform(mat);
-}
-
-BCMatrix::BCMatrix(Object *ob)
-{
-  set_transform(ob);
-}
-
-BCMatrix::BCMatrix()
-{
-  unit();
-}
-
-BCMatrix::BCMatrix(BC_global_forward_axis global_forward_axis, BC_global_up_axis global_up_axis)
-{
-  float mrot[3][3];
-  float mat[4][4];
-  mat3_from_axis_conversion(
-      BC_DEFAULT_FORWARD, BC_DEFAULT_UP, global_forward_axis, global_up_axis, mrot);
-
-  transpose_m3(mrot);  // TODO: Verify that mat3_from_axis_conversion() returns a transposed matrix
-  copy_m4_m3(mat, mrot);
-  set_transform(mat);
-}
-
-void BCMatrix::add_transform(const Matrix &mat, bool inverse)
-{
-  add_transform(this->matrix, mat, this->matrix, inverse);
-}
-
-void BCMatrix::add_transform(const BCMatrix &mat, bool inverse)
-{
-  add_transform(this->matrix, mat.matrix, this->matrix, inverse);
-}
-
-void BCMatrix::apply_transform(const BCMatrix &mat, bool inverse)
-{
-  apply_transform(this->matrix, mat.matrix, this->matrix, inverse);
-}
-
-void BCMatrix::add_transform(Matrix &to, const Matrix &transform, const Matrix &from, bool inverse)
-{
-  if (inverse) {
-    Matrix globinv;
-    invert_m4_m4(globinv, transform);
-    add_transform(to, globinv, from, /*inverse=*/false);
-  }
-  else {
-    mul_m4_m4m4(to, transform, from);
-  }
-}
-
-void BCMatrix::apply_transform(Matrix &to,
-                               const Matrix &transform,
-                               const Matrix &from,
-                               bool inverse)
-{
-  Matrix globinv;
-  invert_m4_m4(globinv, transform);
-  if (inverse) {
-    add_transform(to, globinv, from, /*inverse=*/false);
-  }
-  else {
-    mul_m4_m4m4(to, transform, from);
-    mul_m4_m4m4(to, to, globinv);
-  }
-}
-
-void BCMatrix::add_inverted_transform(Matrix &to, const Matrix &transform, const Matrix &from)
-{
-  Matrix workmat;
-  invert_m4_m4(workmat, transform);
-  mul_m4_m4m4(to, workmat, from);
-}
-
-void BCMatrix::set_transform(Object *ob)
-{
-  Matrix lmat;
-
-  BKE_object_matrix_local_get(ob, lmat);
-  copy_m4_m4(matrix, lmat);
-
-  mat4_decompose(this->loc, this->q, this->size, lmat);
-  quat_to_compatible_eul(this->rot, ob->rot, this->q);
-}
-
-void BCMatrix::set_transform(Matrix &mat)
-{
-  copy_m4_m4(matrix, mat);
-  mat4_decompose(this->loc, this->q, this->size, mat);
-  quat_to_eul(this->rot, this->q);
-}
-
-void BCMatrix::copy(Matrix &out, Matrix &in)
-{
-  /* destination comes first: */
-  memcpy(out, in, sizeof(Matrix));
-}
-
-void BCMatrix::transpose(Matrix &mat)
-{
-  transpose_m4(mat);
-}
-
-void BCMatrix::sanitize(Matrix &mat, int precision)
-{
-  bc_sanitize_mat(mat, precision);
-}
-
-void BCMatrix::unit()
-{
-  unit_m4(this->matrix);
-  mat4_decompose(this->loc, this->q, this->size, this->matrix);
-  quat_to_eul(this->rot, this->q);
-}
-
-/* We need double here because the OpenCollada API needs it.
- * precision = -1 indicates to not limit the precision. */
-void BCMatrix::get_matrix(DMatrix &mat, const bool transposed, const int precision) const
-{
-  for (int i = 0; i < 4; i++) {
-    for (int j = 0; j < 4; j++) {
-      float val = (transposed) ? matrix[j][i] : matrix[i][j];
-      if (precision >= 0) {
-        val = floor((val * pow(10, precision) + 0.5)) / pow(10, precision);
-      }
-      mat[i][j] = val;
-    }
-  }
-}
-
-void BCMatrix::get_matrix(Matrix &mat,
-                          const bool transposed,
-                          const int precision,
-                          const bool inverted) const
-{
-  for (int i = 0; i < 4; i++) {
-    for (int j = 0; j < 4; j++) {
-      float val = (transposed) ? matrix[j][i] : matrix[i][j];
-      if (precision >= 0) {
-        val = floor((val * pow(10, precision) + 0.5)) / pow(10, precision);
-      }
-      mat[i][j] = val;
-    }
-  }
-
-  if (inverted) {
-    invert_m4(mat);
-  }
-}
-
-const bool BCMatrix::in_range(const BCMatrix &other, float distance) const
-{
-  for (int i = 0; i < 4; i++) {
-    for (int j = 0; j < 4; j++) {
-      if (fabs(other.matrix[i][j] - matrix[i][j]) > distance) {
-        return false;
-      }
-    }
-  }
-  return true;
-}
-
-float (&BCMatrix::location() const)[3]
-{
-  return loc;
-}
-
-float (&BCMatrix::rotation() const)[3]
-{
-  return rot;
-}
-
-float (&BCMatrix::scale() const)[3]
-{
-  return size;
-}
-
-float (&BCMatrix::quat() const)[4]
-{
-  return q;
-}
diff --git a/source/blender/collada/BlenderContext.h b/source/blender/collada/BlenderContext.h
index bf5c0e85280..50781e8eede 100644
--- a/source/blender/collada/BlenderContext.h
+++ b/source/blender/collada/BlenderContext.h
@@ -50,55 +50,6 @@ void bc_set_mark(Object *ob);
 #ifdef __cplusplus
 }
 
-class BCMatrix {
-
- private:
-  mutable float matrix[4][4];
-  mutable float size[3];
-  mutable float rot[3];
-  mutable float loc[3];
-  mutable float q[4];
-
-  void unit();
-  void copy(Matrix &r, Matrix &a);
-
- public:
-  float (&location() const)[3];
-  float (&rotation() const)[3];
-  float (&scale() const)[3];
-  float (&quat() const)[4];
-
-  BCMatrix(BC_global_forward_axis global_forward_axis, BC_global_up_axis global_up_axis);
-  BCMatrix(const BCMatrix &mat);
-  BCMatrix(Matrix &mat);
-  BCMatrix(Object *ob);
-  BCMatrix();
-
-  void get_matrix(DMatrix &matrix, const bool transposed = false, const int precision = -1) const;
-  void get_matrix(Matrix &matrix,
-                  const bool transposed = false,
-                  const int precision = -1,
-                  const bool inverted = false) const;
-  void set_transform(Object *ob);
-  void set_transform(Matrix &mat);
-  void add_transform(Matrix &to,
-                     const Matrix &transform,
-                     const Matrix &from,
-                     const bool inverted = false);
-  void apply_transform(Matrix &to,
-                       const Matrix &transform,
-                       const Matrix &from,
-                       const bool inverted = false);
-  void add_inverted_transform(Matrix &to, const Matrix &transform, const Matrix &from);
-  void add_transform(const Matrix &matrix, const bool inverted = false);
-  void add_transform(const BCMatrix &matrix, const bool inverted = false);
-  void apply_transform(const BCMatrix &matrix, const bool inverted = false);
-
-  const bool in_range(const BCMatrix &other, float distance) const;
-  static void sanitize(Matrix &matrix, int precision);
-  static void transpose(Matrix &matrix);
-};
-
 class BlenderContext {
  private:
   bContext *context;
diff --git a/source/blender/collada/ControllerExporter.cpp b/source/blender/collada/ControllerExporter.cpp
index 1e1da13fc5f..b574635217c 100644
--- a/source/blender/collada/ControllerExporter.cpp
+++ b/source/blender/collada/ControllerExporter.cpp
@@ -444,7 +444,7 @@ void ControllerExporter::add_bind_shape_mat(Object *ob)
   // UnitConverter::mat4_to_dae_double(bind_mat, ob->obmat);
   UnitConverter::mat4_to_dae_double(bind_mat, f_obmat);
   if (this->export_settings.get_limit_precision()) {
-    bc_sanitize_mat(bind_mat, LIMITTED_PRECISION);
+	  BCMatrix::sanitize(bind_mat, LIMITTED_PRECISION);
   }
 
   addBindShapeTransform(bind_mat);
@@ -569,7 +569,7 @@ std::string ControllerExporter::add_inv_bind_mats_source(Object *ob_arm,
       invert_m4_m4(mat, world);
       UnitConverter::mat4_to_dae(inv_bind_mat, mat);
       if (this->export_settings.get_limit_precision()) {
-        bc_sanitize_mat(inv_bind_mat, LIMITTED_PRECISION);
+        BCMatrix::sanitize(inv_bind_mat, LIMITTED_PRECISION);
       }
       source.appendValues(inv_bind_mat);
     }
diff --git a/source/blender/collada/ExportSettings.h b/source/blender/collada/ExportSettings.h
index 36f3ea40da9..1e158418

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list