BsFBXImportData.h 4.0 KB

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