BsFBXImportData.h 3.9 KB

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