Blender  V3.3
TransformWriter.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include "BLI_math.h"
8 #include "BLI_sys_types.h"
9 
10 #include "BKE_object.h"
11 
12 #include "TransformWriter.h"
13 
15  float mat[4][4],
16  float parent_mat[4][4],
17  BCExportSettings &export_settings,
18  bool has_restmat)
19 {
20  float local[4][4];
21 
22  if (parent_mat) {
23  float invpar[4][4];
24  invert_m4_m4(invpar, parent_mat);
25  mul_m4_m4m4(local, invpar, mat);
26  }
27  else {
28  copy_m4_m4(local, mat);
29  }
30 
31  if (!has_restmat && export_settings.get_apply_global_orientation()) {
32  bc_apply_global_transform(local, export_settings.get_global_transform());
33  }
34 
35  double dmat[4][4];
37 
38  if (export_settings.get_object_transformation_type() == BC_TRANSFORMATION_TYPE_MATRIX) {
39  node.addMatrix("transform", dmat);
40  }
41  else {
42  float loc[3], rot[3], scale[3];
43  bc_decompose(local, loc, rot, nullptr, scale);
44  add_transform(node, loc, rot, scale);
45  }
46 }
47 
49  Object *ob,
50  BCExportSettings &export_settings)
51 {
52  bool limit_precision = export_settings.get_limit_precision();
53 
54  /* Export the local Matrix (relative to the object parent,
55  * be it an object, bone or vertices (one or more)). */
56  Matrix f_obmat;
57  BKE_object_matrix_local_get(ob, f_obmat);
58 
59  if (export_settings.get_apply_global_orientation()) {
60  bc_apply_global_transform(f_obmat, export_settings.get_global_transform());
61  }
62  else {
63  bc_add_global_transform(f_obmat, export_settings.get_global_transform());
64  }
65 
66  switch (export_settings.get_object_transformation_type()) {
68  double d_obmat[4][4];
69  UnitConverter::mat4_to_dae_double(d_obmat, f_obmat);
70 
71  if (limit_precision) {
73  }
74  node.addMatrix("transform", d_obmat);
75  break;
76  }
78  float loc[3], rot[3], scale[3];
79  bc_decompose(f_obmat, loc, rot, nullptr, scale);
80  if (limit_precision) {
84  }
85  add_transform(node, loc, rot, scale);
86  break;
87  }
88  }
89 }
90 
92  BCExportSettings &export_settings)
93 {
94  BC_export_transformation_type transformation_type =
95  export_settings.get_object_transformation_type();
96  switch (transformation_type) {
98  BCMatrix mat;
99  DMatrix d_obmat;
100  mat.get_matrix(d_obmat);
101  node.addMatrix("transform", d_obmat);
102  break;
103  }
104  default: {
105  float loc[3] = {0.0f, 0.0f, 0.0f};
106  float scale[3] = {1.0f, 1.0f, 1.0f};
107  float rot[3] = {0.0f, 0.0f, 0.0f};
108  add_transform(node, loc, rot, scale);
109  break;
110  }
111  }
112 }
113 
114 void TransformWriter::add_transform(COLLADASW::Node &node,
115  const float loc[3],
116  const float rot[3],
117  const float scale[3])
118 {
119  node.addScale("scale", scale[0], scale[1], scale[2]);
120  node.addRotateZ("rotationZ", RAD2DEGF(rot[2]));
121  node.addRotateY("rotationY", RAD2DEGF(rot[1]));
122  node.addRotateX("rotationX", RAD2DEGF(rot[0]));
123  node.addTranslate("location", loc[0], loc[1], loc[2]);
124 }
General operations, lookup, etc. for blender objects.
void BKE_object_matrix_local_get(struct Object *ob, float r_mat[4][4])
Definition: object.cc:3093
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
Definition: math_matrix.c:259
bool invert_m4_m4(float R[4][4], const float A[4][4])
Definition: math_matrix.c:1287
void copy_m4_m4(float m1[4][4], const float m2[4][4])
Definition: math_matrix.c:77
#define RAD2DEGF(_rad)
BC_export_transformation_type
@ BC_TRANSFORMATION_TYPE_MATRIX
@ BC_TRANSFORMATION_TYPE_DECOMPOSED
void get_matrix(DMatrix &matrix, bool transposed=false, int precision=-1) const
Definition: BCMath.cpp:166
static void sanitize(Matrix &matrix, int precision)
Definition: BCMath.cpp:139
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:53
OperationNode * node
#define rot(x, k)