RavEngine
Loading...
Searching...
No Matches
fbx.h
1//----------------------------------------------------------------------------//
2// //
3// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
4// and distributed under the MIT License (MIT). //
5// //
6// Copyright (c) Guillaume Blanc //
7// //
8// Permission is hereby granted, free of charge, to any person obtaining a //
9// copy of this software and associated documentation files (the "Software"), //
10// to deal in the Software without restriction, including without limitation //
11// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
12// and/or sell copies of the Software, and to permit persons to whom the //
13// Software is furnished to do so, subject to the following conditions: //
14// //
15// The above copyright notice and this permission notice shall be included in //
16// all copies or substantial portions of the Software. //
17// //
18// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
19// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
20// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
21// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
22// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
23// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
24// DEALINGS IN THE SOFTWARE. //
25// //
26//----------------------------------------------------------------------------//
27
28#ifndef OZZ_OZZ_ANIMATION_OFFLINE_FBX_FBX_H_
29#define OZZ_OZZ_ANIMATION_OFFLINE_FBX_FBX_H_
30
31#include <fbxsdk.h>
32
33#include "ozz/animation/offline/fbx/export.h"
34#include "ozz/base/maths/simd_math.h"
35#include "ozz/base/maths/transform.h"
36
37namespace ozz {
38namespace math {
39struct Transform;
40} // namespace math
41namespace animation {
42namespace offline {
43namespace fbx {
44
45// Manages FbxManager instance.
46class OZZ_ANIMFBX_DLL FbxManagerInstance {
47 public:
48 // Instantiates FbxManager.
50
51 // Destroys FbxManager.
53
54 // Cast operator to get internal FbxManager instance.
55 operator FbxManager*() const { return fbx_manager_; }
56
57 private:
58 FbxManager* fbx_manager_;
59};
60
61// Default io settings used to import a scene.
62class OZZ_ANIMFBX_DLL FbxDefaultIOSettings {
63 public:
64 // Instantiates default settings.
65 explicit FbxDefaultIOSettings(const FbxManagerInstance& _manager);
66
67 // De-instantiates default settings.
68 virtual ~FbxDefaultIOSettings();
69
70 // Get FbxIOSettings instance.
71 FbxIOSettings* settings() const { return io_settings_; }
72
73 // Cast operator to get internal FbxIOSettings instance.
74 operator FbxIOSettings*() const { return io_settings_; }
75
76 private:
77 FbxIOSettings* io_settings_;
78};
79
80// Io settings used to import an animation from a scene.
81class OZZ_ANIMFBX_DLL FbxAnimationIOSettings : public FbxDefaultIOSettings {
82 public:
84};
85
86// Io settings used to import a skeleton from a scene.
87class OZZ_ANIMFBX_DLL FbxSkeletonIOSettings : public FbxDefaultIOSettings {
88 public:
90};
91
92// Implements axis system and unit system conversion helper, from any Fbx system
93// to ozz system (FbxAxisSystem::eYAxis, FbxAxisSystem::eParityOdd,
94// FbxAxisSystem::eRightHanded, meter).
95// While Fbx sdk FbxAxisSystem::ConvertScene and FbxSystem::ConvertScene only
96// affect scene root, this class functions can be used to bake nodes, vertices,
97// animations transformations...
98class OZZ_ANIMFBX_DLL FbxSystemConverter {
99 public:
100 // Initialize converter with fbx scene systems.
101 FbxSystemConverter(const FbxAxisSystem& _from_axis,
102 const FbxSystemUnit& _from_unit);
103
104 // Converts a fbx matrix to an ozz Float4x4 matrix, in ozz axis and unit
105 // systems, using _m' = C * _m * (C-1) operation.
106 math::Float4x4 ConvertMatrix(const FbxAMatrix& _m) const;
107
108 // Converts fbx matrix to an ozz transform, in ozz axis and unit systems,
109 // using _m' = C * _m * (C-1) operation.
110 // Can return false if matrix isn't affine.
111 bool ConvertTransform(const FbxAMatrix& _m,
112 math::Transform* _transform) const;
113
114 // Converts fbx FbxVector4 point to an ozz Float3, in ozz axis and unit
115 // systems, using _p' = C * _p operation.
116 math::Float3 ConvertPoint(const FbxVector4& _p) const;
117
118 // Converts fbx FbxVector4 vector to an ozz Float3, in ozz axis and unit
119 // systems, using _p' = ((C-1)-T) * _p operation. Normals are converted
120 // using the inverse transpose matrix to support non-uniform scale
121 // transformations.
122 math::Float3 ConvertVector(const FbxVector4& _p) const;
123
124 private:
125 // The matrix used to convert from "from" axis/unit to ozz coordinate system
126 // base.
127 math::Float4x4 convert_;
128
129 // The inverse of convert_ matrix.
130 math::Float4x4 inverse_convert_;
131
132 // The transpose inverse of convert_ matrix.
133 math::Float4x4 inverse_transpose_convert_;
134};
135
136// Loads a scene from a Fbx file.
137class OZZ_ANIMFBX_DLL FbxSceneLoader {
138 public:
139 // Loads the scene that can then be obtained with scene() function.
140 FbxSceneLoader(const char* _filename, const char* _password,
141 const FbxManagerInstance& _manager,
142 const FbxDefaultIOSettings& _io_settings);
143
144 FbxSceneLoader(FbxStream* _stream, const char* _password,
145 const FbxManagerInstance& _manager,
146 const FbxDefaultIOSettings& _io_settings);
147
149
150 // Returns a valid scene if fbx import was successful, nullptr otherwise.
151 FbxScene* scene() const { return scene_; }
152
153 // Returns a valid converter if fbx import was successful, nullptr otherwise.
154 FbxSystemConverter* converter() { return converter_; }
155
156 private:
157 void ImportScene(FbxImporter* _importer, const bool _initialized,
158 const char* _password, const FbxManagerInstance& _manager,
159 const FbxDefaultIOSettings& _io_settings);
160
161 // Scene instance that was loaded from the file.
162 FbxScene* scene_;
163
164 // Axis and unit conversion helper.
165 FbxSystemConverter* converter_;
166};
167} // namespace fbx
168} // namespace offline
169} // namespace animation
170} // namespace ozz
171#endif // OZZ_OZZ_ANIMATION_OFFLINE_FBX_FBX_H_
Definition vec_float.h:67
Definition simd_math.h:1066
Definition transform.h:40