Blender  V2.93
TransformWriter.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include "BLI_math.h"
22 #include "BLI_sys_types.h"
23 
24 #include "BKE_object.h"
25 
26 #include "TransformWriter.h"
27 
29  float mat[4][4],
30  float parent_mat[4][4],
31  BCExportSettings &export_settings,
32  bool has_restmat)
33 {
34  float local[4][4];
35 
36  if (parent_mat) {
37  float invpar[4][4];
38  invert_m4_m4(invpar, parent_mat);
39  mul_m4_m4m4(local, invpar, mat);
40  }
41  else {
42  copy_m4_m4(local, mat);
43  }
44 
45  if (!has_restmat && export_settings.get_apply_global_orientation()) {
46  bc_apply_global_transform(local, export_settings.get_global_transform());
47  }
48 
49  double dmat[4][4];
51 
52  if (export_settings.get_object_transformation_type() == BC_TRANSFORMATION_TYPE_MATRIX) {
53  node.addMatrix("transform", dmat);
54  }
55  else {
56  float loc[3], rot[3], scale[3];
57  bc_decompose(local, loc, rot, nullptr, scale);
58  add_transform(node, loc, rot, scale);
59  }
60 }
61 
63  Object *ob,
64  BCExportSettings &export_settings)
65 {
66  bool limit_precision = export_settings.get_limit_precision();
67 
68  /* Export the local Matrix (relative to the object parent,
69  * be it an object, bone or vertices (one or more)). */
70  Matrix f_obmat;
71  BKE_object_matrix_local_get(ob, f_obmat);
72 
73  if (export_settings.get_apply_global_orientation()) {
74  bc_apply_global_transform(f_obmat, export_settings.get_global_transform());
75  }
76  else {
77  bc_add_global_transform(f_obmat, export_settings.get_global_transform());
78  }
79 
80  switch (export_settings.get_object_transformation_type()) {
82  double d_obmat[4][4];
83  UnitConverter::mat4_to_dae_double(d_obmat, f_obmat);
84 
85  if (limit_precision) {
87  }
88  node.addMatrix("transform", d_obmat);
89  break;
90  }
92  float loc[3], rot[3], scale[3];
93  bc_decompose(f_obmat, loc, rot, nullptr, scale);
94  if (limit_precision) {
98  }
99  add_transform(node, loc, rot, scale);
100  break;
101  }
102  }
103 }
104 
106  BCExportSettings &export_settings)
107 {
108  BC_export_transformation_type transformation_type =
109  export_settings.get_object_transformation_type();
110  switch (transformation_type) {
112  BCMatrix mat;
113  DMatrix d_obmat;
114  mat.get_matrix(d_obmat);
115  node.addMatrix("transform", d_obmat);
116  break;
117  }
118  default: {
119  float loc[3] = {0.0f, 0.0f, 0.0f};
120  float scale[3] = {1.0f, 1.0f, 1.0f};
121  float rot[3] = {0.0f, 0.0f, 0.0f};
122  add_transform(node, loc, rot, scale);
123  break;
124  }
125  }
126 }
127 
128 void TransformWriter::add_transform(COLLADASW::Node &node,
129  const float loc[3],
130  const float rot[3],
131  const float scale[3])
132 {
133  node.addScale("scale", scale[0], scale[1], scale[2]);
134  node.addRotateZ("rotationZ", RAD2DEGF(rot[2]));
135  node.addRotateY("rotationY", RAD2DEGF(rot[1]));
136  node.addRotateX("rotationX", RAD2DEGF(rot[0]));
137  node.addTranslate("location", loc[0], loc[1], loc[2]);
138 }
General operations, lookup, etc. for blender objects.
void BKE_object_matrix_local_get(struct Object *ob, float r_mat[4][4])
Definition: object.c:3245
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
Definition: math_matrix.c:262
bool invert_m4_m4(float R[4][4], const float A[4][4])
Definition: math_matrix.c:1278
void copy_m4_m4(float m1[4][4], const float m2[4][4])
Definition: math_matrix.c:95
#define RAD2DEGF(_rad)
BC_export_transformation_type
@ BC_TRANSFORMATION_TYPE_MATRIX
@ BC_TRANSFORMATION_TYPE_DECOMPOSED
void get_matrix(DMatrix &matrix, const bool transposed=false, const int precision=-1) const
Definition: BCMath.cpp:187
static void sanitize(Matrix &matrix, int precision)
Definition: BCMath.cpp:158
void add_node_transform_ob(COLLADASW::Node &node, Object *ob, BCExportSettings &export_settings)
void add_joint_transform(COLLADASW::Node &node, float mat[4][4], float parent_mat[4][4], BCExportSettings &export_settings, bool has_restmat)
void add_node_transform_identity(COLLADASW::Node &node, BCExportSettings &export_settings)
static void mat4_to_dae_double(double out[4][4], float in[4][4])
void bc_add_global_transform(Matrix &to_mat, const Matrix &from_mat, const BCMatrix &global_transform, const bool invert)
void bc_sanitize_v3(float v[3], int precision)
void bc_apply_global_transform(Matrix &to_mat, const BCMatrix &global_transform, const bool invert)
void bc_decompose(float mat[4][4], float *loc, float eul[3], float quat[4], float *size)
constexpr int LIMITTED_PRECISION
Definition: collada_utils.h:67
OperationNode * node
#define rot(x, k)