Blender  V2.93
TransformReader.cpp
Go to the documentation of this file.
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 
21 /* COLLADABU_ASSERT, may be able to remove later */
22 #include "COLLADABUPlatform.h"
23 
24 #include "TransformReader.h"
25 
26 TransformReader::TransformReader(UnitConverter *conv) : unit_converter(conv)
27 {
28  /* pass */
29 }
30 
31 void TransformReader::get_node_mat(float mat[4][4],
32  COLLADAFW::Node *node,
33  std::map<COLLADAFW::UniqueId, Animation> *animation_map,
34  Object *ob)
35 {
36  get_node_mat(mat, node, animation_map, ob, nullptr);
37 }
38 
39 void TransformReader::get_node_mat(float mat[4][4],
40  COLLADAFW::Node *node,
41  std::map<COLLADAFW::UniqueId, Animation> *animation_map,
42  Object *ob,
43  float parent_mat[4][4])
44 {
45  float cur[4][4];
46  float copy[4][4];
47 
48  unit_m4(mat);
49 
50  for (unsigned int i = 0; i < node->getTransformations().getCount(); i++) {
51 
52  COLLADAFW::Transformation *tm = node->getTransformations()[i];
53  COLLADAFW::Transformation::TransformationType type = tm->getTransformationType();
54 
55  switch (type) {
56  case COLLADAFW::Transformation::MATRIX:
57  /* When matrix AND Trans/Rot/Scale are defined for a node,
58  * then this is considered as redundant information.
59  * So if we find a Matrix we use that and return. */
60  dae_matrix_to_mat4(tm, mat);
61  if (parent_mat) {
62  mul_m4_m4m4(mat, parent_mat, mat);
63  }
64  return;
66  dae_translate_to_mat4(tm, cur);
67  break;
69  dae_rotate_to_mat4(tm, cur);
70  break;
72  dae_scale_to_mat4(tm, cur);
73  break;
74  case COLLADAFW::Transformation::LOOKAT:
75  fprintf(stderr, "|! LOOKAT transformations are not supported yet.\n");
76  break;
77  case COLLADAFW::Transformation::SKEW:
78  fprintf(stderr, "|! SKEW transformations are not supported yet.\n");
79  break;
80  }
81 
82  copy_m4_m4(copy, mat);
83  mul_m4_m4m4(mat, copy, cur);
84 
85  if (animation_map) {
86  /* AnimationList that drives this Transformation */
87  const COLLADAFW::UniqueId &anim_list_id = tm->getAnimationList();
88 
89  /* store this so later we can link animation data with ob */
90  Animation anim = {ob, node, tm};
91  (*animation_map)[anim_list_id] = anim;
92  }
93  }
94 
95  if (parent_mat) {
96  mul_m4_m4m4(mat, parent_mat, mat);
97  }
98 }
99 
100 void TransformReader::dae_rotate_to_mat4(COLLADAFW::Transformation *tm, float m[4][4])
101 {
103  COLLADABU::Math::Vector3 &axis = ro->getRotationAxis();
104  const float angle = (float)DEG2RAD(ro->getRotationAngle());
105  const float ax[] = {(float)axis[0], (float)axis[1], (float)axis[2]};
106  // float quat[4];
107  // axis_angle_to_quat(quat, axis, angle);
108  // quat_to_mat4(m, quat);
109  axis_angle_to_mat4(m, ax, angle);
110 }
111 
112 void TransformReader::dae_translate_to_mat4(COLLADAFW::Transformation *tm, float m[4][4])
113 {
115  COLLADABU::Math::Vector3 &t = tra->getTranslation();
116 
117  unit_m4(m);
118 
119  m[3][0] = (float)t[0];
120  m[3][1] = (float)t[1];
121  m[3][2] = (float)t[2];
122 }
123 
124 void TransformReader::dae_scale_to_mat4(COLLADAFW::Transformation *tm, float m[4][4])
125 {
126  COLLADABU::Math::Vector3 &s = ((COLLADAFW::Scale *)tm)->getScale();
127  float size[3] = {(float)s[0], (float)s[1], (float)s[2]};
128  size_to_mat4(m, size);
129 }
130 
131 void TransformReader::dae_matrix_to_mat4(COLLADAFW::Transformation *tm, float m[4][4])
132 {
133  UnitConverter::dae_matrix_to_mat4_(m, ((COLLADAFW::Matrix *)tm)->getMatrix());
134 }
135 
136 void TransformReader::dae_translate_to_v3(COLLADAFW::Transformation *tm, float v[3])
137 {
138  dae_vector3_to_v3(((COLLADAFW::Translate *)tm)->getTranslation(), v);
139 }
140 
141 void TransformReader::dae_scale_to_v3(COLLADAFW::Transformation *tm, float v[3])
142 {
143  dae_vector3_to_v3(((COLLADAFW::Scale *)tm)->getScale(), v);
144 }
145 
147 {
148  v[0] = v3.x;
149  v[1] = v3.y;
150  v[2] = v3.z;
151 }
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:262
void unit_m4(float m[4][4])
Definition: rct.c:1140
void size_to_mat4(float R[4][4], const float size[3])
Definition: math_matrix.c:2118
void copy_m4_m4(float m1[4][4], const float m2[4][4])
Definition: math_matrix.c:95
#define DEG2RAD(_deg)
void axis_angle_to_mat4(float R[4][4], const float axis[3], const float angle)
_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
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White RGB Map Separate Set Z Dilate Combine Combine Color Channel Split ID Combine Luminance Directional Alpha Distance Hue Movie Ellipse Bokeh View Corner Anti Mix RGB Hue Translate
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White RGB Map Separate Set Z Dilate Combine Combine Color Channel Split ID Combine Luminance Directional Alpha Distance Hue Movie Ellipse Bokeh View Corner Anti Mix RGB Hue TRANSLATE
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White RGB Map Separate Set Z Dilate Combine Combine Color Channel Split ID Combine Luminance Directional Alpha Distance Hue Movie Ellipse Bokeh View Corner Anti Mix RGB Hue Rotate
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White RGB Map Separate Set Z Dilate SCALE
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White RGB Map Separate Set Z Dilate Combine Combine Color Channel Split ID Combine Luminance Directional Alpha Distance Hue Movie Ellipse Bokeh View Corner Anti Mix RGB Hue ROTATE
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White RGB Map Separate Set Z Dilate Scale
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:87