XFileImporter.h 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /** @file Definition of the XFile importer class. */
  2. #ifndef AI_XFILEIMPORTER_H_INC
  3. #define AI_XFILEIMPORTER_H_INC
  4. #include <map>
  5. #include "XFileHelper.h"
  6. #include "BaseImporter.h"
  7. #include "../include/aiTypes.h"
  8. struct aiNode;
  9. namespace Assimp
  10. {
  11. struct XFile::Scene;
  12. struct XFile::Node;
  13. // ---------------------------------------------------------------------------
  14. /** The XFileImporter is a worker class capable of importing a scene from a
  15. * DirectX file .x
  16. */
  17. class XFileImporter : public BaseImporter
  18. {
  19. friend class Importer;
  20. protected:
  21. /** Constructor to be privately used by Importer */
  22. XFileImporter();
  23. /** Destructor, private as well */
  24. ~XFileImporter();
  25. public:
  26. // -------------------------------------------------------------------
  27. /** Returns whether the class can handle the format of the given file.
  28. * See BaseImporter::CanRead() for details. */
  29. bool CanRead( const std::string& pFile, IOSystem* pIOHandler) const;
  30. protected:
  31. // -------------------------------------------------------------------
  32. /** Imports the given file into the given scene structure.
  33. * See BaseImporter::InternReadFile() for details
  34. */
  35. void InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler);
  36. // -------------------------------------------------------------------
  37. /** Constructs the return data structure out of the imported data.
  38. * @param pScene The scene to construct the return data in.
  39. * @param pData The imported data in the internal temporary representation.
  40. */
  41. void CreateDataRepresentationFromImport( aiScene* pScene, const XFile::Scene* pData);
  42. // -------------------------------------------------------------------
  43. /** Recursively creates scene nodes from the imported hierarchy. The meshes and materials
  44. * of the nodes will be extracted on the way.
  45. * @param pScene The scene to construct the return data in.
  46. * @param pParent The parent node where to create new child nodes
  47. * @param pNode The temporary node to copy.
  48. * @return The created node
  49. */
  50. aiNode* CreateNodes( aiScene* pScene, aiNode* pParent, const XFile::Node* pNode);
  51. // -------------------------------------------------------------------
  52. /** Converts all meshes in the given mesh array. Each mesh is splitted up per material,
  53. * the indices of the generated meshes are stored in the node structure.
  54. * @param pScene The scene to construct the return data in.
  55. * @param pNode The target node structure that references the constructed meshes.
  56. * @param pMeshes The array of meshes to convert
  57. */
  58. void CreateMeshes( aiScene* pScene, aiNode* pNode, const std::vector<XFile::Mesh*>& pMeshes);
  59. // -------------------------------------------------------------------
  60. /** Converts the animations from the given imported data and creates them in the scene.
  61. * @param pScene The scene to hold to converted animations
  62. * @param pData The data to read the animations from
  63. */
  64. void CreateAnimations( aiScene* pScene, const XFile::Scene* pData);
  65. // -------------------------------------------------------------------
  66. /** Converts all materials in the given array and stores them in the scene's material list.
  67. * @param pScene The scene to hold the converted materials.
  68. * @param pMaterials The material array to convert.
  69. */
  70. void ConvertMaterials( aiScene* pScene, const std::vector<XFile::Material>& pMaterials);
  71. protected:
  72. /** Buffer to hold the loaded file */
  73. std::vector<char> mBuffer;
  74. /** Imported materials: index in the scene's material list by name */
  75. std::map<std::string, unsigned int> mImportedMats;
  76. };
  77. } // end of namespace Assimp
  78. #endif // AI_BASEIMPORTER_H_INC