assimpShapeLoader.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _ASSIMP_SHAPELOADER_H_
  23. #define _ASSIMP_SHAPELOADER_H_
  24. #ifndef _TSSHAPELOADER_H_
  25. #include "ts/loader/tsShapeLoader.h"
  26. #endif
  27. #ifndef _ASSIMP_APPNODE_H_
  28. #include "ts/assimp/assimpAppNode.h"
  29. #endif
  30. #include <assimp/Importer.hpp>
  31. #include <assimp/texture.h>
  32. class GuiTreeViewCtrl;
  33. struct aiNode;
  34. struct aiMetadata;
  35. //-----------------------------------------------------------------------------
  36. class AssimpShapeLoader : public TSShapeLoader
  37. {
  38. friend TSShape* assimpLoadShape(const Torque::Path &path);
  39. protected:
  40. Assimp::Importer mImporter;
  41. const aiScene* mScene;
  42. //bool processNode(AppNode* node) override;
  43. bool ignoreNode(const String& name) override;
  44. bool ignoreMesh(const String& name) override;
  45. void detectDetails();
  46. void extractTexture(U32 index, aiTexture* pTex);
  47. private:
  48. void processAssimpNode(const aiNode* node, const aiScene* scene, AssimpAppNode* parentNode = nullptr);
  49. void addNodeToTree(S32 parentItem, aiNode* node, GuiTreeViewCtrl* tree, U32& nodeCount);
  50. void addMetaDataToTree(const aiMetadata* metaData, GuiTreeViewCtrl* tree);
  51. bool getMetabool(const char* key, bool& boolVal);
  52. bool getMetaInt(const char* key, S32& intVal);
  53. bool getMetaFloat(const char* key, F32& floatVal);
  54. bool getMetaDouble(const char* key, F64& doubleVal);
  55. bool getMetaString(const char* key, String& stringVal);
  56. public:
  57. AssimpShapeLoader();
  58. ~AssimpShapeLoader();
  59. void releaseImport();
  60. void enumerateScene() override;
  61. void configureImportUnits();
  62. void updateMaterialsScript(const Torque::Path &path);
  63. void processAnimations();
  64. void computeBounds(Box3F& bounds) override;
  65. bool fillGuiTreeView(const char* shapePath, GuiTreeViewCtrl* tree);
  66. static bool canLoadCachedDTS(const Torque::Path& path);
  67. static void assimpLogCallback(const char* message, char* user);
  68. };
  69. #endif // _ASSIMP_SHAPELOADER_H_