BsFBXImportData.h 4.1 KB

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