BsFBXImportData.h 3.7 KB

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