ModelImporter.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //
  2. // Copyright (c) 2014-2016 THUNDERBEAST GAMES 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 deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // 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 FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "AssetImporter.h"
  24. namespace Atomic
  25. {
  26. class Node;
  27. class Animation;
  28. }
  29. using namespace Atomic;
  30. namespace ToolCore
  31. {
  32. class AnimationImportInfo : public Object
  33. {
  34. friend class ModelImporter;
  35. ATOMIC_OBJECT(AnimationImportInfo, Object);
  36. public:
  37. AnimationImportInfo(Context* context) : Object(context), startTime_(-1.0f), endTime_(-1.0f)
  38. {
  39. }
  40. const String& GetName() const { return name_; }
  41. float GetStartTime() const { return startTime_; }
  42. float GetEndTime() const { return endTime_; }
  43. void SetName(const String& name) { name_ = name; }
  44. void SetStartTime(float time) { startTime_ = time; }
  45. void SetEndTime(float time) { endTime_ = time; }
  46. private:
  47. String name_;
  48. float startTime_;
  49. float endTime_;
  50. };
  51. class ModelImporter : public AssetImporter
  52. {
  53. ATOMIC_OBJECT(ModelImporter, AssetImporter)
  54. public:
  55. /// Construct.
  56. ModelImporter(Context* context, Asset* asset);
  57. virtual ~ModelImporter();
  58. virtual void SetDefaults();
  59. double GetScale() { return scale_; }
  60. void SetScale(double scale) {scale_ = scale; }
  61. bool GetImportAnimations() { return importAnimations_; }
  62. void SetImportAnimations(bool importAnimations) { importAnimations_ = importAnimations; }
  63. bool GetImportMaterials() { return importMaterials_; }
  64. void SetImportMaterials(bool importMat) { importMaterials_ = importMat; }
  65. unsigned GetAnimationCount();
  66. void SetAnimationCount(unsigned count);
  67. // Lightmap UV
  68. bool GetGenerateLightmapUV() const { return genLightmapUV_; }
  69. void SetGenerateLightmapUV(bool value) { genLightmapUV_ = value; }
  70. Resource* GetResource(const String& typeName = String::EMPTY);
  71. void GetAnimations(PODVector<Atomic::Animation *>& animations);
  72. AnimationImportInfo* GetAnimationInfo(unsigned index) { return animationInfo_[index]; }
  73. /// Instantiate a node from the asset
  74. Node* InstantiateNode(Node* parent, const String& name);
  75. protected:
  76. bool Import();
  77. bool ImportModel();
  78. bool ImportAnimations();
  79. bool ImportAnimation(const String &filename, const String& name, float startTime=-1.0f, float endTime=-1.0f);
  80. virtual bool LoadSettingsInternal(JSONValue& jsonRoot);
  81. virtual bool SaveSettingsInternal(JSONValue& jsonRoot);
  82. void GetAssetCacheMap(HashMap<String, String>& assetMap);
  83. double scale_;
  84. bool importAnimations_;
  85. bool importMaterials_;
  86. bool includeNonSkinningBones_;
  87. Vector<SharedPtr<AnimationImportInfo>> animationInfo_;
  88. SharedPtr<Node> importNode_;
  89. bool genLightmapUV_;
  90. };
  91. }