BsFBXImportData.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #pragma once
  2. #include "BsFBXPrerequisites.h"
  3. #include "BsMatrix4.h"
  4. #include "BsColor.h"
  5. #include "BsVector2.h"
  6. #include "BsVector4.h"
  7. #include "BsSubMesh.h"
  8. namespace BansheeEngine
  9. {
  10. /**
  11. * @brief Options that control FBX import
  12. */
  13. struct FBXImportOptions
  14. {
  15. bool importAnimation = true;
  16. bool importSkin = true;
  17. bool importBlendShapes = true;
  18. bool importNormals = true;
  19. bool importTangents = true;
  20. float importScale = 0.01f;
  21. float animSampleRate = 1.0f / 60.0f;
  22. bool animResample = false;
  23. };
  24. /**
  25. * @brief Represents a single node in the FBX transform hierarchy.
  26. */
  27. struct FBXImportNode
  28. {
  29. ~FBXImportNode();
  30. Matrix4 localTransform;
  31. Matrix4 worldTransform;
  32. FbxNode* fbxNode;
  33. Vector<FBXImportNode*> children;
  34. };
  35. /**
  36. * @brief Contains geometry from one blend shape frame.
  37. */
  38. struct FBXBlendShapeFrame
  39. {
  40. Vector<Vector3> positions;
  41. Vector<Vector3> normals;
  42. Vector<Vector3> tangents;
  43. Vector<Vector3> bitangents;
  44. float weight;
  45. };
  46. /**
  47. * @brief Contains all geometry for a single blend shape.
  48. */
  49. struct FBXBlendShape
  50. {
  51. String name;
  52. Vector<FBXBlendShapeFrame> frames;
  53. };
  54. /**
  55. * @brief Contains data about a single bone in a skinned mesh.
  56. */
  57. struct FBXBone
  58. {
  59. FBXImportNode* node;
  60. Matrix4 bindPose;
  61. };
  62. /**
  63. * @brief Contains a set of bone weights and indices for a single
  64. * vertex, used in a skinned mesh.
  65. */
  66. struct FBXBoneInfluence
  67. {
  68. FBXBoneInfluence()
  69. {
  70. for (UINT32 i = 0; i < FBX_IMPORT_MAX_BONE_INFLUENCES; i++)
  71. {
  72. weights[i] = 0.0f;
  73. indices[i] = -1;
  74. }
  75. }
  76. float weights[FBX_IMPORT_MAX_BONE_INFLUENCES];
  77. INT32 indices[FBX_IMPORT_MAX_BONE_INFLUENCES];
  78. };
  79. /**
  80. * @brief Represents a single frame in an animation curve. Contains
  81. * a value at a specific time as well as the in and out tangents
  82. * at that position.
  83. */
  84. struct FBXKeyFrame
  85. {
  86. float time;
  87. float value;
  88. float inTangent;
  89. float outTangent;
  90. };
  91. /**
  92. * @brief Curve with a set of key frames used for animation
  93. * of a single value.
  94. */
  95. struct FBXAnimationCurve
  96. {
  97. Vector<FBXKeyFrame> keyframes;
  98. float evaluate(float time);
  99. };
  100. /**
  101. * @brief Animation curves required to animate a single bone.
  102. */
  103. struct FBXBoneAnimation
  104. {
  105. FBXImportNode* node;
  106. FBXAnimationCurve translation[3];
  107. FBXAnimationCurve rotation[4];
  108. FBXAnimationCurve scale[3];
  109. };
  110. /**
  111. * @brief Animation curve required to animate a blend shape.
  112. */
  113. struct FBXBlendShapeAnimation
  114. {
  115. String blendShape;
  116. FBXAnimationCurve curve;
  117. };
  118. /**
  119. * @brief Animation clip containing a set of bone or blend shape
  120. * animations.
  121. */
  122. struct FBXAnimationClip
  123. {
  124. String name;
  125. float start;
  126. float end;
  127. Vector<FBXBoneAnimation> boneAnimations;
  128. Vector<FBXBlendShapeAnimation> blendShapeAnimations;
  129. };
  130. /**
  131. * @brief Imported mesh data.
  132. */
  133. struct FBXImportMesh
  134. {
  135. FbxMesh* fbxMesh;
  136. Vector<int> indices;
  137. Vector<Vector3> positions;
  138. Vector<Vector3> normals;
  139. Vector<Vector3> tangents;
  140. Vector<Vector3> bitangents;
  141. Vector<RGBA> colors;
  142. Vector<Vector2> UV[FBX_IMPORT_MAX_UV_LAYERS];
  143. Vector<int> materials;
  144. Vector<int> smoothingGroups;
  145. Vector<FBXBlendShape> blendShapes;
  146. Vector<FBXBoneInfluence> boneInfluences;
  147. Vector<FBXBone> bones;
  148. MeshDataPtr meshData;
  149. Vector<SubMesh> subMeshes;
  150. Vector<FBXImportNode*> referencedBy;
  151. };
  152. /**
  153. * @brief Scene information used and modified during FBX import.
  154. */
  155. struct FBXImportScene
  156. {
  157. FBXImportScene();
  158. ~FBXImportScene();
  159. Vector<FBXImportMesh*> meshes;
  160. FBXImportNode* rootNode;
  161. UnorderedMap<FbxNode*, FBXImportNode*> nodeMap;
  162. UnorderedMap<FbxMesh*, UINT32> meshMap;
  163. Vector<FBXAnimationClip> clips;
  164. };
  165. }