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