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