2014-06-04 18:17:09 +08:00
|
|
|
/****************************************************************************
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2014-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2014-06-04 18:17:09 +08:00
|
|
|
|
2022-07-09 01:23:11 +08:00
|
|
|
https://axis-project.github.io/
|
2014-06-04 18:17:09 +08:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __CCANIMATION3D_H__
|
|
|
|
#define __CCANIMATION3D_H__
|
|
|
|
|
|
|
|
#include <unordered_map>
|
|
|
|
|
2014-06-17 10:49:52 +08:00
|
|
|
#include "3d/CCAnimationCurve.h"
|
2014-06-04 18:17:09 +08:00
|
|
|
|
|
|
|
#include "base/ccMacros.h"
|
|
|
|
#include "base/CCRef.h"
|
2014-08-28 17:03:29 +08:00
|
|
|
#include "3d/CCBundle3DData.h"
|
2014-06-04 18:17:09 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2015-03-27 14:10:41 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup _3d
|
|
|
|
* @{
|
|
|
|
*/
|
2014-06-04 18:17:09 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-27 14:10:41 +08:00
|
|
|
* @brief static animation data, shared
|
2014-06-04 18:17:09 +08:00
|
|
|
*/
|
2022-07-15 19:17:01 +08:00
|
|
|
class AX_DLL Animation3D : public Ref
|
2014-06-04 18:17:09 +08:00
|
|
|
{
|
2014-06-09 18:37:58 +08:00
|
|
|
friend class Bundle3D;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-04 18:17:09 +08:00
|
|
|
public:
|
2014-06-19 14:11:14 +08:00
|
|
|
/**
|
|
|
|
* animation curve, translation, rotation, and scale
|
|
|
|
*/
|
2014-06-04 18:17:09 +08:00
|
|
|
class Curve
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef AnimationCurve<3> AnimationCurveVec3;
|
|
|
|
typedef AnimationCurve<4> AnimationCurveQuat;
|
2015-04-01 09:47:09 +08:00
|
|
|
/**translation curve*/
|
|
|
|
AnimationCurveVec3* translateCurve;
|
|
|
|
/**rotation curve*/
|
|
|
|
AnimationCurveQuat* rotCurve;
|
|
|
|
/**scaling curve*/
|
|
|
|
AnimationCurveVec3* scaleCurve;
|
|
|
|
/**constructor */
|
2014-06-04 18:17:09 +08:00
|
|
|
Curve();
|
2015-04-01 09:47:09 +08:00
|
|
|
/**constructor */
|
2014-06-04 18:17:09 +08:00
|
|
|
~Curve();
|
|
|
|
};
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-07-09 09:53:15 +08:00
|
|
|
/**read all animation or only the animation with given animationName? animationName == "" read the first.*/
|
2021-12-26 23:26:34 +08:00
|
|
|
static Animation3D* create(std::string_view filename, std::string_view animationName = "");
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-19 14:11:14 +08:00
|
|
|
/**get duration*/
|
2014-06-04 18:17:09 +08:00
|
|
|
float getDuration() const { return _duration; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-03-30 15:47:47 +08:00
|
|
|
/**
|
|
|
|
* get bone curve
|
2021-12-25 10:04:45 +08:00
|
|
|
*
|
2015-03-30 15:47:47 +08:00
|
|
|
* @lua NA
|
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
Curve* getBoneCurveByName(std::string_view name) const;
|
2015-04-01 09:47:09 +08:00
|
|
|
|
|
|
|
/**get the bone Curves set*/
|
2021-12-26 23:26:34 +08:00
|
|
|
const hlookup::string_map<Curve*>& getBoneCurves() const { return _boneCurves; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-03-18 21:46:07 +08:00
|
|
|
Animation3D();
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual ~Animation3D();
|
2014-06-19 14:11:14 +08:00
|
|
|
/**init Animation3D from bundle data*/
|
2014-06-12 14:03:33 +08:00
|
|
|
bool init(const Animation3DData& data);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-03-09 16:29:57 +08:00
|
|
|
/**init Animation3D with file name and animation name*/
|
2021-12-26 23:26:34 +08:00
|
|
|
bool initWithFile(std::string_view filename, std::string_view animationName);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-17 19:18:56 +08:00
|
|
|
protected:
|
2021-12-26 23:26:34 +08:00
|
|
|
hlookup::string_map<Curve*> _boneCurves; // bone curves map, key bone name, value AnimationCurve
|
2014-11-26 09:53:52 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
float _duration; // animation duration
|
2014-06-04 18:17:09 +08:00
|
|
|
};
|
|
|
|
|
2014-06-19 14:11:14 +08:00
|
|
|
/**
|
|
|
|
* Animation3D Cache
|
|
|
|
*/
|
2014-06-04 18:17:09 +08:00
|
|
|
class Animation3DCache
|
|
|
|
{
|
|
|
|
public:
|
2014-06-19 14:11:14 +08:00
|
|
|
/**get and destroy instance*/
|
2014-06-04 18:17:09 +08:00
|
|
|
static Animation3DCache* getInstance();
|
2014-06-17 19:18:56 +08:00
|
|
|
static void destroyInstance();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-19 14:11:14 +08:00
|
|
|
/**get animation by key*/
|
2021-12-26 23:26:34 +08:00
|
|
|
Animation3D* getAnimation(std::string_view key);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-19 14:11:14 +08:00
|
|
|
/**add animation to cache*/
|
2021-12-26 23:26:34 +08:00
|
|
|
void addAnimation(std::string_view key, Animation3D* animation);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-19 14:11:14 +08:00
|
|
|
/**remove all animation*/
|
2014-06-17 19:18:56 +08:00
|
|
|
void removeAllAnimations();
|
2014-06-19 14:11:14 +08:00
|
|
|
/**remove unused animation*/
|
2014-06-04 18:17:09 +08:00
|
|
|
void removeUnusedAnimation();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Animation3DCache();
|
|
|
|
~Animation3DCache();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
static Animation3DCache* _cacheInstance; // cache instance
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
hlookup::string_map<Animation3D*> _animations; // cached animations
|
2014-06-04 18:17:09 +08:00
|
|
|
};
|
|
|
|
|
2015-04-01 10:23:53 +08:00
|
|
|
// end of 3d group
|
2015-03-27 14:10:41 +08:00
|
|
|
/// @}
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|
2014-06-04 18:17:09 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
#endif // __CCANIMATION3D_H__
|