CCAnimation3D.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /****************************************************************************
  2. Copyright (c) 2014-2016 Chukong Technologies Inc.
  3. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  4. http://www.cocos2d-x.org
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. #ifndef __CCANIMATION3D_H__
  22. #define __CCANIMATION3D_H__
  23. #include <unordered_map>
  24. #include "3d/CCAnimationCurve.h"
  25. #include "base/ccMacros.h"
  26. #include "base/CCRef.h"
  27. #include "3d/CCBundle3DData.h"
  28. NS_CC_BEGIN
  29. /**
  30. * @addtogroup _3d
  31. * @{
  32. */
  33. /**
  34. * @brief static animation data, shared
  35. */
  36. class CC_DLL Animation3D: public Ref
  37. {
  38. friend class Bundle3D;
  39. public:
  40. /**
  41. * animation curve, translation, rotation, and scale
  42. */
  43. class Curve
  44. {
  45. public:
  46. typedef AnimationCurve<3> AnimationCurveVec3;
  47. typedef AnimationCurve<4> AnimationCurveQuat;
  48. /**translation curve*/
  49. AnimationCurveVec3* translateCurve;
  50. /**rotation curve*/
  51. AnimationCurveQuat* rotCurve;
  52. /**scaling curve*/
  53. AnimationCurveVec3* scaleCurve;
  54. /**constructor */
  55. Curve();
  56. /**constructor */
  57. ~Curve();
  58. };
  59. /**read all animation or only the animation with given animationName? animationName == "" read the first.*/
  60. static Animation3D* create(const std::string& filename, const std::string& animationName = "");
  61. /**the cache method to create or get an Animation3D object*/
  62. CC_DEPRECATED_ATTRIBUTE static Animation3D* getOrCreate(const std::string& filename, const std::string& animationName = ""){ return create(filename, animationName); }
  63. /**get duration*/
  64. float getDuration() const { return _duration; }
  65. /**
  66. * get bone curve
  67. *
  68. * @lua NA
  69. */
  70. Curve* getBoneCurveByName(const std::string& name) const;
  71. /**get the bone Curves set*/
  72. const std::unordered_map<std::string, Curve*>& getBoneCurves() const {return _boneCurves;}
  73. CC_CONSTRUCTOR_ACCESS:
  74. Animation3D();
  75. virtual ~Animation3D();
  76. /**init Animation3D from bundle data*/
  77. bool init(const Animation3DData& data);
  78. /**init Animation3D with file name and animation name*/
  79. bool initWithFile(const std::string& filename, const std::string& animationName);
  80. protected:
  81. std::unordered_map<std::string, Curve*> _boneCurves;//bone curves map, key bone name, value AnimationCurve
  82. float _duration; //animation duration
  83. };
  84. /**
  85. * Animation3D Cache
  86. */
  87. class Animation3DCache
  88. {
  89. public:
  90. /**get and destroy instance*/
  91. static Animation3DCache* getInstance();
  92. static void destroyInstance();
  93. /**get animation by key*/
  94. Animation3D* getAnimation(const std::string& key);
  95. /**add animation to cache*/
  96. void addAnimation(const std::string& key, Animation3D* animation);
  97. /**remove all animation*/
  98. void removeAllAnimations();
  99. /**remove unused animation*/
  100. void removeUnusedAnimation();
  101. protected:
  102. Animation3DCache();
  103. ~Animation3DCache();
  104. static Animation3DCache* _cacheInstance; //cache instance
  105. std::unordered_map<std::string, Animation3D*> _animations; //cached animations
  106. };
  107. // end of 3d group
  108. /// @}
  109. NS_CC_END
  110. #endif // __CCANIMATION3D_H__