Radium Engine  1.5.20
Loading...
Searching...
No Matches
AssimpWrapper.hpp
1#pragma once
2
3#include <assimp/color4.h>
4#include <assimp/matrix4x4.h>
5#include <assimp/quaternion.h>
6#include <assimp/types.h>
7#include <assimp/vector3.h>
8
9#include <Core/Types.hpp>
10#include <Core/Utils/Color.hpp>
11
12namespace Ra {
13namespace IO {
14
15template <typename T>
16struct AssimpTypeWrapper {};
17
18template <>
19struct AssimpTypeWrapper<aiVector3D> {
20 using Type = Core::Vector3;
21};
22
23template <>
24struct AssimpTypeWrapper<aiQuaternion> {
25 using Type = Core::Quaternion;
26};
27
28template <>
29struct AssimpTypeWrapper<aiMatrix4x4> {
30 using Type = Core::Transform;
31};
32
33template <>
34struct AssimpTypeWrapper<aiColor3D> {
35 using Type = Core::Utils::Color;
36};
37
38template <>
39struct AssimpTypeWrapper<aiColor4D> {
40 using Type = Core::Utils::Color;
41};
42
43template <>
44struct AssimpTypeWrapper<aiString> {
45 using Type = std::string;
46};
47
48inline Core::Vector3 assimpToCore( const aiVector3D& v ) {
49 return Core::Vector3( v.x, v.y, v.z );
50}
51
52inline aiVector3D coreToAssimp( const Core::Vector3& v ) {
53 return aiVector3D( v.x(), v.y(), v.z() );
54}
55
56inline Core::Quaternion assimpToCore( const aiQuaternion& q ) {
57 return Core::Quaternion( q.w, q.x, q.y, q.z );
58}
59
60inline Core::Transform assimpToCore( const aiMatrix4x4& M ) {
61 Core::Matrix4 m( Core::Matrix4::Identity() );
62 for ( uint i = 0; i < 4; ++i ) {
63 for ( uint j = 0; j < 4; ++j ) {
64 m( i, j ) = M[i][j];
65 }
66 }
67 return Core::Transform( m );
68}
69
70inline Core::Transform
71assimpToCore( const aiVector3D& T, const aiQuaternion& R, const aiVector3D& S ) {
72 Core::Vector3 t = assimpToCore( T );
73 Core::Quaternion r = assimpToCore( R );
74 Core::Vector3 s = assimpToCore( S );
75 Core::Transform M;
76 M.fromPositionOrientationScale( t, r, s );
77 return M;
78}
79
80inline Core::Utils::Color assimpToCore( const aiColor3D& c ) {
81 return Core::Utils::Color( c.r, c.g, c.b );
82}
83
84inline Core::Utils::Color assimpToCore( const aiColor4D& c ) {
85 return Core::Utils::Color( c.r, c.g, c.b, c.a );
86}
87
88inline std::string assimpToCore( const aiString& string ) {
89 std::string result( string.C_Str() );
90 std::transform( result.begin(), result.end(), result.begin(), []( char in ) {
91 if ( in == '\\' ) return '/';
92 return in;
93 } );
94 return result.empty() ? "default" : result;
95}
96
97inline Core::VectorNui assimpToCore( const uint* index, const uint size ) {
98 Core::VectorNui v( size );
99 for ( uint i = 0; i < size; ++i ) {
100 v[i] = index[i];
101 }
102
103 return v;
104}
105
106template <typename T>
107inline T assimpToCore( const uint* index, const uint size ) {
108 T v;
109 for ( uint i = 0; i < size; ++i ) {
110 v[i] = index[i];
111 }
112 return v;
113}
114
115} // namespace IO
116} // namespace Ra
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:3
T transform(T... args)