Blender V4.5
TransformReader.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
8
9#include "COLLADAFWMatrix.h"
10#include "COLLADAFWRotate.h"
11#include "COLLADAFWScale.h"
12#include "COLLADAFWTranslate.h"
13
14#include "TransformReader.h"
15
16#include "BLI_math_matrix.h"
17#include "BLI_math_rotation.h"
18
23
24void TransformReader::get_node_mat(float mat[4][4],
25 COLLADAFW::Node *node,
26 std::map<COLLADAFW::UniqueId, Animation> *animation_map,
27 Object *ob)
28{
29 get_node_mat(mat, node, animation_map, ob, nullptr);
30}
31
32void TransformReader::get_node_mat(float mat[4][4],
33 COLLADAFW::Node *node,
34 std::map<COLLADAFW::UniqueId, Animation> *animation_map,
35 Object *ob,
36 float parent_mat[4][4])
37{
38 float cur[4][4];
39 float copy[4][4];
40
41 unit_m4(mat);
42
43 for (uint i = 0; i < node->getTransformations().getCount(); i++) {
44
45 COLLADAFW::Transformation *tm = node->getTransformations()[i];
46 COLLADAFW::Transformation::TransformationType type = tm->getTransformationType();
47
48 switch (type) {
49 case COLLADAFW::Transformation::MATRIX:
50 /* When matrix AND Trans/Rot/Scale are defined for a node,
51 * then this is considered as redundant information.
52 * So if we find a Matrix we use that and return. */
53 dae_matrix_to_mat4(tm, mat);
54 if (parent_mat) {
55 mul_m4_m4m4(mat, parent_mat, mat);
56 }
57 return;
58 case COLLADAFW::Transformation::TRANSLATE:
59 dae_translate_to_mat4(tm, cur);
60 break;
61 case COLLADAFW::Transformation::ROTATE:
62 dae_rotate_to_mat4(tm, cur);
63 break;
64 case COLLADAFW::Transformation::SCALE:
65 dae_scale_to_mat4(tm, cur);
66 break;
67 case COLLADAFW::Transformation::LOOKAT:
68 fprintf(stderr, "|! LOOKAT transformations are not supported yet.\n");
69 break;
70 case COLLADAFW::Transformation::SKEW:
71 fprintf(stderr, "|! SKEW transformations are not supported yet.\n");
72 break;
73 }
74
75 copy_m4_m4(copy, mat);
76 mul_m4_m4m4(mat, copy, cur);
77
78 if (animation_map) {
79 /* AnimationList that drives this Transformation */
80 const COLLADAFW::UniqueId &anim_list_id = tm->getAnimationList();
81
82 /* store this so later we can link animation data with ob */
83 Animation anim = {ob, node, tm};
84 (*animation_map)[anim_list_id] = anim;
85 }
86 }
87
88 if (parent_mat) {
89 mul_m4_m4m4(mat, parent_mat, mat);
90 }
91}
92
93void TransformReader::dae_rotate_to_mat4(COLLADAFW::Transformation *tm, float m[4][4])
94{
95 COLLADAFW::Rotate *ro = (COLLADAFW::Rotate *)tm;
96 COLLADABU::Math::Vector3 &axis = ro->getRotationAxis();
97 const float angle = float(DEG2RAD(ro->getRotationAngle()));
98 const float ax[] = {float(axis[0]), float(axis[1]), float(axis[2])};
99#if 0
100 float quat[4];
101 axis_angle_to_quat(quat, axis, angle);
102 quat_to_mat4(m, quat);
103#endif
105}
106
107void TransformReader::dae_translate_to_mat4(COLLADAFW::Transformation *tm, float m[4][4])
108{
109 COLLADAFW::Translate *tra = (COLLADAFW::Translate *)tm;
110 COLLADABU::Math::Vector3 &t = tra->getTranslation();
111
112 unit_m4(m);
113
114 m[3][0] = float(t[0]);
115 m[3][1] = float(t[1]);
116 m[3][2] = float(t[2]);
117}
118
119void TransformReader::dae_scale_to_mat4(COLLADAFW::Transformation *tm, float m[4][4])
120{
121 COLLADABU::Math::Vector3 &s = ((COLLADAFW::Scale *)tm)->getScale();
122 float size[3] = {float(s[0]), float(s[1]), float(s[2])};
123 size_to_mat4(m, size);
124}
125
126void TransformReader::dae_matrix_to_mat4(COLLADAFW::Transformation *tm, float m[4][4])
127{
128 UnitConverter::dae_matrix_to_mat4_(m, ((COLLADAFW::Matrix *)tm)->getMatrix());
129}
130
131void TransformReader::dae_translate_to_v3(COLLADAFW::Transformation *tm, float v[3])
132{
133 dae_vector3_to_v3(((COLLADAFW::Translate *)tm)->getTranslation(), v);
134}
135
136void TransformReader::dae_scale_to_v3(COLLADAFW::Transformation *tm, float v[3])
137{
138 dae_vector3_to_v3(((COLLADAFW::Scale *)tm)->getScale(), v);
139}
140
141void TransformReader::dae_vector3_to_v3(const COLLADABU::Math::Vector3 &v3, float v[3])
142{
143 v[0] = v3.x;
144 v[1] = v3.y;
145 v[2] = v3.z;
146}
#define DEG2RAD(_deg)
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
void size_to_mat4(float R[4][4], const float size[3])
void copy_m4_m4(float m1[4][4], const float m2[4][4])
void unit_m4(float m[4][4])
void axis_angle_to_quat(float r[4], const float axis[3], float angle)
void quat_to_mat4(float m[4][4], const float q[4])
void axis_angle_to_mat4(float R[4][4], const float axis[3], float angle)
unsigned int uint
static double angle(const Eigen::Vector3d &v1, const Eigen::Vector3d &v2)
Definition IK_Math.h:117
ATTR_WARN_UNUSED_RESULT const BMVert * v
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
void dae_matrix_to_mat4(COLLADAFW::Transformation *tm, float m[4][4])
void dae_translate_to_v3(COLLADAFW::Transformation *tm, float v[3])
void get_node_mat(float mat[4][4], COLLADAFW::Node *node, std::map< COLLADAFW::UniqueId, Animation > *animation_map, Object *ob)
void dae_scale_to_v3(COLLADAFW::Transformation *tm, float v[3])
void dae_vector3_to_v3(const COLLADABU::Math::Vector3 &v3, float v[3])
void dae_translate_to_mat4(COLLADAFW::Transformation *tm, float m[4][4])
void dae_scale_to_mat4(COLLADAFW::Transformation *tm, float m[4][4])
TransformReader(UnitConverter *conv)
void dae_rotate_to_mat4(COLLADAFW::Transformation *tm, float m[4][4])
UnitConverter * unit_converter
static void dae_matrix_to_mat4_(float out[4][4], const COLLADABU::Math::Matrix4 &in)
static void copy(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node)
i
Definition text_draw.cc:230