BsFBXImportData.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 "BsQuaternion.h"
  10. #include "BsAnimationCurve.h"
  11. #include "BsSubMesh.h"
  12. namespace BansheeEngine
  13. {
  14. struct RootMotion;
  15. /** @addtogroup FBX
  16. * @{
  17. */
  18. /** Options that control FBX import */
  19. struct FBXImportOptions
  20. {
  21. bool importAnimation = true;
  22. bool importSkin = true;
  23. bool importBlendShapes = true;
  24. bool importNormals = true;
  25. bool importTangents = true;
  26. float importScale = 0.01f;
  27. float animSampleRate = 1.0f / 60.0f;
  28. bool animResample = false;
  29. bool reduceKeyframes = true;
  30. };
  31. /** Represents a single node in the FBX transform hierarchy. */
  32. struct FBXImportNode
  33. {
  34. ~FBXImportNode();
  35. Matrix4 localTransform;
  36. Matrix4 worldTransform;
  37. String name;
  38. FbxNode* fbxNode;
  39. Vector<FBXImportNode*> children;
  40. };
  41. /** Contains geometry from one blend shape frame. */
  42. struct FBXBlendShapeFrame
  43. {
  44. Vector<Vector3> positions;
  45. Vector<Vector3> normals;
  46. Vector<Vector3> tangents;
  47. Vector<Vector3> bitangents;
  48. float weight;
  49. String name;
  50. };
  51. /** Contains all geometry for a single blend shape. */
  52. struct FBXBlendShape
  53. {
  54. String name;
  55. Vector<FBXBlendShapeFrame> frames;
  56. };
  57. /** Contains data about a single bone in a skinned mesh. */
  58. struct FBXBone
  59. {
  60. FBXImportNode* node;
  61. Matrix4 bindPose;
  62. };
  63. /** Contains a set of bone weights and indices for a single vertex, used in a skinned mesh. */
  64. struct FBXBoneInfluence
  65. {
  66. FBXBoneInfluence()
  67. {
  68. for (UINT32 i = 0; i < FBX_IMPORT_MAX_BONE_INFLUENCES; i++)
  69. {
  70. weights[i] = 0.0f;
  71. indices[i] = -1;
  72. }
  73. }
  74. float weights[FBX_IMPORT_MAX_BONE_INFLUENCES];
  75. INT32 indices[FBX_IMPORT_MAX_BONE_INFLUENCES];
  76. };
  77. /** Animation curves required to animate a single bone. */
  78. struct FBXBoneAnimation
  79. {
  80. FBXImportNode* node;
  81. TAnimationCurve<Vector3> translation;
  82. TAnimationCurve<Quaternion> rotation;
  83. TAnimationCurve<Vector3> scale;
  84. };
  85. /** Animation curve required to animate a blend shape. */
  86. struct FBXBlendShapeAnimation
  87. {
  88. String blendShape;
  89. TAnimationCurve<float> curve;
  90. };
  91. /** Animation clip containing a set of bone or blend shape animations. */
  92. struct FBXAnimationClip
  93. {
  94. String name;
  95. float start;
  96. float end;
  97. UINT32 sampleRate;
  98. Vector<FBXBoneAnimation> boneAnimations;
  99. Vector<FBXBlendShapeAnimation> blendShapeAnimations;
  100. };
  101. /** All information required for creating an animation clip. */
  102. struct FBXAnimationClipData
  103. {
  104. FBXAnimationClipData(const String& name, bool isAdditive, UINT32 sampleRate, const SPtr<AnimationCurves>& curves,
  105. const SPtr<RootMotion>& rootMotion)
  106. :name(name), isAdditive(isAdditive), sampleRate(sampleRate), curves(curves), rootMotion(rootMotion)
  107. { }
  108. String name;
  109. bool isAdditive;
  110. UINT32 sampleRate;
  111. SPtr<AnimationCurves> curves;
  112. SPtr<RootMotion> rootMotion;
  113. };
  114. /** Imported mesh data. */
  115. struct FBXImportMesh
  116. {
  117. FbxMesh* fbxMesh;
  118. Vector<int> indices;
  119. Vector<Vector3> positions;
  120. Vector<Vector3> normals;
  121. Vector<Vector3> tangents;
  122. Vector<Vector3> bitangents;
  123. Vector<RGBA> colors;
  124. Vector<Vector2> UV[FBX_IMPORT_MAX_UV_LAYERS];
  125. Vector<int> materials;
  126. Vector<int> smoothingGroups;
  127. Vector<FBXBlendShape> blendShapes;
  128. Vector<FBXBoneInfluence> boneInfluences;
  129. Vector<FBXBone> bones;
  130. SPtr<MeshData> meshData;
  131. Vector<SubMesh> subMeshes;
  132. Vector<FBXImportNode*> referencedBy;
  133. };
  134. /** Scene information used and modified during FBX import. */
  135. struct FBXImportScene
  136. {
  137. FBXImportScene();
  138. ~FBXImportScene();
  139. Vector<FBXImportMesh*> meshes;
  140. FBXImportNode* rootNode;
  141. UnorderedMap<FbxNode*, FBXImportNode*> nodeMap;
  142. UnorderedMap<FbxMesh*, UINT32> meshMap;
  143. Vector<FBXAnimationClip> clips;
  144. float scaleFactor;
  145. Matrix4 globalScale;
  146. };
  147. /** @} */
  148. }