BsFBXImportData.h 4.0 KB

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