loaderFileTypeAssimp.cxx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /**
  2. * PANDA 3D SOFTWARE
  3. * Copyright (c) Carnegie Mellon University. All rights reserved.
  4. *
  5. * All use of this software is subject to the terms of the revised BSD
  6. * license. You should have received a copy of this license along
  7. * with this source code in a file named "LICENSE."
  8. *
  9. * @file loaderFileTypeAssimp.cxx
  10. * @author rdb
  11. * @date 2011-03-29
  12. */
  13. #include "loaderFileTypeAssimp.h"
  14. #include "config_assimp.h"
  15. #include "assimpLoader.h"
  16. #include <assimp/cimport.h>
  17. using std::string;
  18. TypeHandle LoaderFileTypeAssimp::_type_handle;
  19. /**
  20. *
  21. */
  22. LoaderFileTypeAssimp::
  23. LoaderFileTypeAssimp() : _loader(nullptr) {
  24. }
  25. /**
  26. *
  27. */
  28. LoaderFileTypeAssimp::
  29. ~LoaderFileTypeAssimp() {
  30. }
  31. /**
  32. *
  33. */
  34. string LoaderFileTypeAssimp::
  35. get_name() const {
  36. return "Assimp Importer";
  37. }
  38. /**
  39. *
  40. */
  41. string LoaderFileTypeAssimp::
  42. get_extension() const {
  43. return "";
  44. }
  45. /**
  46. * Returns a space-separated list of extension, in addition to the one
  47. * returned by get_extension(), that are recognized by this converter.
  48. */
  49. string LoaderFileTypeAssimp::
  50. get_additional_extensions() const {
  51. aiString aexts;
  52. aiGetExtensionList(&aexts);
  53. // The format is like: *.mdc;*.mdl;*.mesh.xml;*.mot
  54. std::string ext;
  55. char *sub = strtok(aexts.data, ";");
  56. while (sub != nullptr) {
  57. ext += sub + 2;
  58. sub = strtok(nullptr, ";");
  59. if (sub != nullptr) {
  60. ext += ' ';
  61. }
  62. }
  63. return ext;
  64. }
  65. /**
  66. * Returns true if this file type can transparently load compressed files
  67. * (with a .pz or .gz extension), false otherwise.
  68. */
  69. bool LoaderFileTypeAssimp::
  70. supports_compressed() const {
  71. return true;
  72. }
  73. /**
  74. *
  75. */
  76. PT(PandaNode) LoaderFileTypeAssimp::
  77. load_file(const Filename &path, const LoaderOptions &options,
  78. BamCacheRecord *record) const {
  79. assimp_cat.info()
  80. << "Reading " << path << "\n";
  81. AssimpLoader loader;
  82. loader.local_object();
  83. if (!loader.read(path)) {
  84. return nullptr;
  85. }
  86. loader.build_graph();
  87. return DCAST(PandaNode, loader._root);
  88. }