BsFBXImportData.h 3.8 KB

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