BsFBXImportData.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. FbxNode* fbxNode;
  34. Vector<FBXImportNode*> children;
  35. };
  36. /** Contains geometry from one blend shape frame. */
  37. struct FBXBlendShapeFrame
  38. {
  39. Vector<Vector3> positions;
  40. Vector<Vector3> normals;
  41. Vector<Vector3> tangents;
  42. Vector<Vector3> bitangents;
  43. float weight;
  44. };
  45. /** Contains all geometry for a single blend shape. */
  46. struct FBXBlendShape
  47. {
  48. String name;
  49. Vector<FBXBlendShapeFrame> frames;
  50. };
  51. /** Contains data about a single bone in a skinned mesh. */
  52. struct FBXBone
  53. {
  54. FBXImportNode* node;
  55. Matrix4 bindPose;
  56. };
  57. /** Contains a set of bone weights and indices for a single vertex, used in a skinned mesh. */
  58. struct FBXBoneInfluence
  59. {
  60. FBXBoneInfluence()
  61. {
  62. for (UINT32 i = 0; i < FBX_IMPORT_MAX_BONE_INFLUENCES; i++)
  63. {
  64. weights[i] = 0.0f;
  65. indices[i] = -1;
  66. }
  67. }
  68. float weights[FBX_IMPORT_MAX_BONE_INFLUENCES];
  69. INT32 indices[FBX_IMPORT_MAX_BONE_INFLUENCES];
  70. };
  71. /**
  72. * Represents a single frame in an animation curve. Contains a value at a specific time as well as the in and out
  73. * tangents at that position.
  74. */
  75. struct FBXKeyFrame
  76. {
  77. float time;
  78. float value;
  79. float inTangent;
  80. float outTangent;
  81. };
  82. /** Curve with a set of key frames used for animation of a single value. */
  83. struct FBXAnimationCurve
  84. {
  85. Vector<FBXKeyFrame> keyframes;
  86. float evaluate(float time);
  87. };
  88. /** Animation curves required to animate a single bone. */
  89. struct FBXBoneAnimation
  90. {
  91. FBXImportNode* node;
  92. FBXAnimationCurve translation[3];
  93. FBXAnimationCurve rotation[4];
  94. FBXAnimationCurve scale[3];
  95. };
  96. /** Animation curve required to animate a blend shape. */
  97. struct FBXBlendShapeAnimation
  98. {
  99. String blendShape;
  100. FBXAnimationCurve curve;
  101. };
  102. /** Animation clip containing a set of bone or blend shape animations. */
  103. struct FBXAnimationClip
  104. {
  105. String name;
  106. float start;
  107. float end;
  108. Vector<FBXBoneAnimation> boneAnimations;
  109. Vector<FBXBlendShapeAnimation> blendShapeAnimations;
  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. };
  142. /** @} */
  143. }