1//************************************ bs::framework - Copyright 2018 Marko Pintera **************************************//
2//*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********//
3#pragma once
4
5#include "BsFBXPrerequisites.h"
6#include "Math/BsMatrix4.h"
7#include "Image/BsColor.h"
8#include "Math/BsVector2.h"
9#include "Math/BsVector4.h"
10#include "Math/BsQuaternion.h"
11#include "Animation/BsAnimationCurve.h"
12#include "RenderAPI/BsSubMesh.h"
13#include "Scene/BsTransform.h"
14
15namespace bs
16{
17 struct RootMotion;
18
19 /** @addtogroup FBX
20 * @{
21 */
22
23 /** Options that control FBX import */
24 struct FBXImportOptions
25 {
26 bool importAnimation = true;
27 bool importSkin = true;
28 bool importBlendShapes = true;
29 bool importNormals = true;
30 bool importTangents = true;
31 float importScale = 0.01f;
32 float animSampleRate = 1.0f / 60.0f;
33 bool animResample = false;
34 bool reduceKeyframes = true;
35 };
36
37 /** Represents a single node in the FBX transform hierarchy. */
38 struct FBXImportNode
39 {
40 ~FBXImportNode();
41
42 Matrix4 geomTransform;
43 Transform localTransform;
44 Matrix4 worldTransform;
45 String name;
46 FbxNode* fbxNode;
47 bool flipWinding;
48
49 Vector<FBXImportNode*> children;
50 };
51
52 /** Contains geometry from one blend shape frame. */
53 struct FBXBlendShapeFrame
54 {
55 Vector<Vector3> positions;
56 Vector<Vector3> normals;
57 Vector<Vector3> tangents;
58 Vector<Vector3> bitangents;
59
60 float weight;
61 String name;
62 };
63
64 /** Contains all geometry for a single blend shape. */
65 struct FBXBlendShape
66 {
67 String name;
68 Vector<FBXBlendShapeFrame> frames;
69 };
70
71 /** Contains data about a single bone in a skinned mesh. */
72 struct FBXBone
73 {
74 FBXImportNode* node;
75 Transform localTfrm;
76 Matrix4 bindPose;
77 };
78
79 /** Contains a set of bone weights and indices for a single vertex, used in a skinned mesh. */
80 struct FBXBoneInfluence
81 {
82 FBXBoneInfluence()
83 {
84 for (UINT32 i = 0; i < FBX_IMPORT_MAX_BONE_INFLUENCES; i++)
85 {
86 weights[i] = 0.0f;
87 indices[i] = -1;
88 }
89 }
90
91 float weights[FBX_IMPORT_MAX_BONE_INFLUENCES];
92 INT32 indices[FBX_IMPORT_MAX_BONE_INFLUENCES];
93 };
94
95 /** Animation curves required to animate a single bone. */
96 struct FBXBoneAnimation
97 {
98 FBXImportNode* node;
99
100 TAnimationCurve<Vector3> translation;
101 TAnimationCurve<Quaternion> rotation;
102 TAnimationCurve<Vector3> scale;
103 };
104
105 /** Animation curve required to animate a blend shape. */
106 struct FBXBlendShapeAnimation
107 {
108 String blendShape;
109 TAnimationCurve<float> curve;
110 };
111
112 /** Animation clip containing a set of bone or blend shape animations. */
113 struct FBXAnimationClip
114 {
115 String name;
116 float start;
117 float end;
118 UINT32 sampleRate;
119
120 Vector<FBXBoneAnimation> boneAnimations;
121 Vector<FBXBlendShapeAnimation> blendShapeAnimations;
122 };
123
124 /** All information required for creating an animation clip. */
125 struct FBXAnimationClipData
126 {
127 FBXAnimationClipData(const String& name, bool isAdditive, UINT32 sampleRate, const SPtr<AnimationCurves>& curves,
128 const SPtr<RootMotion>& rootMotion)
129 :name(name), isAdditive(isAdditive), sampleRate(sampleRate), curves(curves), rootMotion(rootMotion)
130 { }
131
132 String name;
133 bool isAdditive;
134 UINT32 sampleRate;
135 SPtr<AnimationCurves> curves;
136 SPtr<RootMotion> rootMotion;
137 };
138
139 /** Imported mesh data. */
140 struct FBXImportMesh
141 {
142 FbxMesh* fbxMesh;
143
144 Vector<int> indices;
145 Vector<Vector3> positions;
146 Vector<Vector3> normals;
147 Vector<Vector3> tangents;
148 Vector<Vector3> bitangents;
149 Vector<RGBA> colors;
150 Vector<Vector2> UV[FBX_IMPORT_MAX_UV_LAYERS];
151 Vector<int> materials;
152
153 Vector<int> smoothingGroups;
154 Vector<FBXBlendShape> blendShapes;
155
156 Vector<FBXBoneInfluence> boneInfluences;
157 Vector<FBXBone> bones;
158
159 SPtr<MeshData> meshData;
160 Vector<SubMesh> subMeshes;
161
162 Vector<FBXImportNode*> referencedBy;
163 };
164
165 /** Scene information used and modified during FBX import. */
166 struct FBXImportScene
167 {
168 FBXImportScene() = default;
169 ~FBXImportScene();
170
171 Vector<FBXImportMesh*> meshes;
172 FBXImportNode* rootNode = nullptr;
173
174 UnorderedMap<FbxNode*, FBXImportNode*> nodeMap;
175 UnorderedMap<FbxMesh*, UINT32> meshMap;
176
177 Vector<FBXAnimationClip> clips;
178 };
179
180 /** @} */
181}