Assimp.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /** @file Implementation of the Plain-C API */
  2. #include <map>
  3. #include "../include/assimp.h"
  4. #include "../include/assimp.hpp"
  5. /** Stores the importer objects for all active import processes */
  6. typedef std::map< const aiScene*, Assimp::Importer* > ImporterMap;
  7. /** Local storage of all active import processes */
  8. static ImporterMap gActiveImports;
  9. /** Error message of the last failed import process */
  10. static std::string gLastErrorString;
  11. // ------------------------------------------------------------------------------------------------
  12. // Reads the given file and returns its content.
  13. const aiScene* aiImportFile( const char* pFile, unsigned int pFlags)
  14. {
  15. // create an Importer for this file
  16. Assimp::Importer* imp = new Assimp::Importer;
  17. // and have it read the file
  18. const aiScene* scene = imp->ReadFile( pFile, pFlags);
  19. // if succeeded, place it in the collection of active processes
  20. if( scene)
  21. {
  22. gActiveImports[scene] = imp;
  23. }
  24. else
  25. {
  26. // if failed, extract error code and destroy the import
  27. gLastErrorString = imp->GetErrorString();
  28. delete imp;
  29. }
  30. // return imported data. If the import failed the pointer is NULL anyways
  31. return scene;
  32. }
  33. // ------------------------------------------------------------------------------------------------
  34. // Releases all resources associated with the given import process.
  35. void aiReleaseImport( const aiScene* pScene)
  36. {
  37. // find the importer associated with this data
  38. ImporterMap::iterator it = gActiveImports.find( pScene);
  39. // it should be there... else the user is playing fools with us
  40. if( it == gActiveImports.end())
  41. return;
  42. // kill the importer, the data dies with it
  43. delete it->second;
  44. gActiveImports.erase( it);
  45. }
  46. // ------------------------------------------------------------------------------------------------
  47. // Returns the error text of the last failed import process.
  48. const char* aiGetErrorString()
  49. {
  50. return gLastErrorString.c_str();
  51. }