Blender  V3.3
TransformReader.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 /* COLLADABU_ASSERT, may be able to remove later */
8 #include "COLLADABUPlatform.h"
9 
10 #include "TransformReader.h"
11 
12 TransformReader::TransformReader(UnitConverter *conv) : unit_converter(conv)
13 {
14  /* pass */
15 }
16 
17 void TransformReader::get_node_mat(float mat[4][4],
18  COLLADAFW::Node *node,
19  std::map<COLLADAFW::UniqueId, Animation> *animation_map,
20  Object *ob)
21 {
22  get_node_mat(mat, node, animation_map, ob, nullptr);
23 }
24 
25 void TransformReader::get_node_mat(float mat[4][4],
26  COLLADAFW::Node *node,
27  std::map<COLLADAFW::UniqueId, Animation> *animation_map,
28  Object *ob,
29  float parent_mat[4][4])
30 {
31  float cur[4][4];
32  float copy[4][4];
33 
34  unit_m4(mat);
35 
36  for (unsigned int i = 0; i < node->getTransformations().getCount(); i++) {
37 
38  COLLADAFW::Transformation *tm = node->getTransformations()[i];
39  COLLADAFW::Transformation::TransformationType type = tm->getTransformationType();
40 
41  switch (type) {
42  case COLLADAFW::Transformation::MATRIX:
43  /* When matrix AND Trans/Rot/Scale are defined for a node,
44  * then this is considered as redundant information.
45  * So if we find a Matrix we use that and return. */
46  dae_matrix_to_mat4(tm, mat);
47  if (parent_mat) {
48  mul_m4_m4m4(mat, parent_mat, mat);
49  }
50  return;
51  case COLLADAFW::Transformation::TRANSLATE:
52  dae_translate_to_mat4(tm, cur);
53  break;
54  case COLLADAFW::Transformation::ROTATE:
55  dae_rotate_to_mat4(tm, cur);
56  break;
57  case COLLADAFW::Transformation::SCALE:
58  dae_scale_to_mat4(tm, cur);
59  break;
60  case COLLADAFW::Transformation::LOOKAT:
61  fprintf(stderr, "|! LOOKAT transformations are not supported yet.\n");
62  break;
63  case COLLADAFW::Transformation::SKEW:
64  fprintf(stderr, "|! SKEW transformations are not supported yet.\n");
65  break;
66  }
67 
68  copy_m4_m4(copy, mat);
69  mul_m4_m4m4(mat, copy, cur);
70 
71  if (animation_map) {
72  /* AnimationList that drives this Transformation */
73  const COLLADAFW::UniqueId &anim_list_id = tm->getAnimationList();
74 
75  /* store this so later we can link animation data with ob */
76  Animation anim = {ob, node, tm};
77  (*animation_map)[anim_list_id] = anim;
78  }
79  }
80 
81  if (parent_mat) {
82  mul_m4_m4m4(mat, parent_mat, mat);
83  }
84 }
85 
86 void TransformReader::dae_rotate_to_mat4(COLLADAFW::Transformation *tm, float m[4][4])
87 {
88  COLLADAFW::Rotate *ro = (COLLADAFW::Rotate *)tm;
89  COLLADABU::Math::Vector3 &axis = ro->getRotationAxis();
90  const float angle = (float)DEG2RAD(ro->getRotationAngle());
91  const float ax[] = {(float)axis[0], (float)axis[1], (float)axis[2]};
92 #if 0
93  float quat[4];
94  axis_angle_to_quat(quat, axis, angle);
95  quat_to_mat4(m, quat);
96 #endif
97  axis_angle_to_mat4(m, ax, angle);
98 }
99 
100 void TransformReader::dae_translate_to_mat4(COLLADAFW::Transformation *tm, float m[4][4])
101 {
102  COLLADAFW::Translate *tra = (COLLADAFW::Translate *)tm;
103  COLLADABU::Math::Vector3 &t = tra->getTranslation();
104 
105  unit_m4(m);
106 
107  m[3][0] = (float)t[0];
108  m[3][1] = (float)t[1];
109  m[3][2] = (float)t[2];
110 }
111 
112 void TransformReader::dae_scale_to_mat4(COLLADAFW::Transformation *tm, float m[4][4])
113 {
114  COLLADABU::Math::Vector3 &s = ((COLLADAFW::Scale *)tm)->getScale();
115  float size[3] = {(float)s[0], (float)s[1], (float)s[2]};
116  size_to_mat4(m, size);
117 }
118 
119 void TransformReader::dae_matrix_to_mat4(COLLADAFW::Transformation *tm, float m[4][4])
120 {
121  UnitConverter::dae_matrix_to_mat4_(m, ((COLLADAFW::Matrix *)tm)->getMatrix());
122 }
123 
124 void TransformReader::dae_translate_to_v3(COLLADAFW::Transformation *tm, float v[3])
125 {
126  dae_vector3_to_v3(((COLLADAFW::Translate *)tm)->getTranslation(), v);
127 }
128 
129 void TransformReader::dae_scale_to_v3(COLLADAFW::Transformation *tm, float v[3])
130 {
131  dae_vector3_to_v3(((COLLADAFW::Scale *)tm)->getScale(), v);
132 }
133 
135 {
136  v[0] = v3.x;
137  v[1] = v3.y;
138  v[2] = v3.z;
139 }
typedef float(TangentPoint)[2]
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
Definition: math_matrix.c:259
void unit_m4(float m[4][4])
Definition: rct.c:1090
void size_to_mat4(float R[4][4], const float size[3])
Definition: math_matrix.c:2111
void copy_m4_m4(float m1[4][4], const float m2[4][4])
Definition: math_matrix.c:77
void axis_angle_to_quat(float r[4], const float axis[3], float angle)
#define DEG2RAD(_deg)
void axis_angle_to_mat4(float R[4][4], const float axis[3], float angle)
void quat_to_mat4(float mat[4][4], const float q[4])
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
ATTR_WARN_UNUSED_RESULT const BMVert * v
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition: btVector3.h:356
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
float[3] Vector3
static void copy(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node)
Definition: IMB_anim.h:71