Cleanup: remove redundant doxygen \file argument
[blender.git] / source / blender / collada / TransformWriter.cpp
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
17 /** \file \ingroup collada
18  */
19
20
21 #include "BLI_math.h"
22 #include "BLI_sys_types.h"
23
24 #include "BKE_object.h"
25
26 #include "TransformWriter.h"
27
28 void TransformWriter::add_node_transform(COLLADASW::Node& node, float mat[4][4], float parent_mat[4][4], bool limit_precision)
29 {
30         float loc[3], rot[3], scale[3];
31         float local[4][4];
32
33         if (parent_mat) {
34                 float invpar[4][4];
35                 invert_m4_m4(invpar, parent_mat);
36                 mul_m4_m4m4(local, invpar, mat);
37         }
38         else {
39                 copy_m4_m4(local, mat);
40         }
41
42         double dmat[4][4];
43         UnitConverter *converter = new UnitConverter();
44         converter->mat4_to_dae_double(dmat, local);
45         delete converter;
46
47         bc_decompose(local, loc, rot, NULL, scale);
48
49         if (node.getType() == COLLADASW::Node::JOINT) {
50                 // XXX Why are joints handled differently ?
51                 node.addMatrix("transform", dmat);
52         }
53         else {
54                 add_transform(node, loc, rot, scale);
55         }
56 }
57
58 void TransformWriter::add_node_transform_ob(
59         COLLADASW::Node& node,
60         Object *ob,
61         BC_export_transformation_type transformation_type,
62         bool limit_precision)
63 {
64 #if 0
65         float rot[3], loc[3], scale[3];
66
67         if (ob->parent) {
68                 float C[4][4], tmat[4][4], imat[4][4], mat[4][4];
69
70                 // factor out scale from obmat
71
72                 copy_v3_v3(scale, ob->size);
73
74                 ob->size[0] = ob->size[1] = ob->size[2] = 1.0f;
75                 BKE_object_to_mat4(ob, C);
76                 copy_v3_v3(ob->size, scale);
77
78                 mul_m4_series(tmat, ob->parent->obmat, ob->parentinv, C);
79
80                 // calculate local mat
81
82                 invert_m4_m4(imat, ob->parent->obmat);
83                 mul_m4_m4m4(mat, imat, tmat);
84
85                 // done
86
87                 mat4_to_eul(rot, mat);
88                 copy_v3_v3(loc, mat[3]);
89         }
90         else {
91                 copy_v3_v3(loc, ob->loc);
92                 copy_v3_v3(rot, ob->rot);
93                 copy_v3_v3(scale, ob->size);
94         }
95
96         add_transform(node, loc, rot, scale);
97 #endif
98
99         /* Export the local Matrix (relative to the object parent, be it an object, bone or vertex(-tices)) */
100         float  f_obmat[4][4];
101         BKE_object_matrix_local_get(ob, f_obmat);
102
103         switch (transformation_type) {
104                 case BC_TRANSFORMATION_TYPE_MATRIX:
105                 {
106                         UnitConverter converter;
107                         double d_obmat[4][4];
108                         converter.mat4_to_dae_double(d_obmat, f_obmat);
109                         if (limit_precision)
110                                 bc_sanitize_mat(d_obmat, LIMITTED_PRECISION);
111                         node.addMatrix("transform",d_obmat);
112                         break;
113                 }
114                 case BC_TRANSFORMATION_TYPE_TRANSROTLOC:
115                 {
116                         float loc[3], rot[3], scale[3];
117                         bc_decompose(f_obmat, loc, rot, NULL, scale);
118                         if (limit_precision) {
119                                 bc_sanitize_v3(loc, LIMITTED_PRECISION);
120                                 bc_sanitize_v3(rot, LIMITTED_PRECISION);
121                                 bc_sanitize_v3(scale, LIMITTED_PRECISION);
122                         }
123                         add_transform(node, loc, rot, scale);
124                         break;
125                 }
126         }
127
128 }
129
130 void TransformWriter::add_node_transform_identity(COLLADASW::Node& node)
131 {
132         float loc[3] = {0.0f, 0.0f, 0.0f}, scale[3] = {1.0f, 1.0f, 1.0f}, rot[3] = {0.0f, 0.0f, 0.0f};
133         add_transform(node, loc, rot, scale);
134 }
135
136 void TransformWriter::add_transform(COLLADASW::Node& node, float loc[3], float rot[3], float scale[3])
137 {
138 #if 0
139         node.addRotateZ("rotationZ", COLLADABU::Math::Utils::radToDegF(rot[2]));
140         node.addRotateY("rotationY", COLLADABU::Math::Utils::radToDegF(rot[1]));
141         node.addRotateX("rotationX", COLLADABU::Math::Utils::radToDegF(rot[0]));
142 #endif
143         node.addTranslate("location", loc[0], loc[1], loc[2]);
144         node.addRotateZ("rotationZ", RAD2DEGF(rot[2]));
145         node.addRotateY("rotationY", RAD2DEGF(rot[1]));
146         node.addRotateX("rotationX", RAD2DEGF(rot[0]));
147         node.addScale("scale", scale[0], scale[1], scale[2]);
148
149 }