axmol/core/3d/CCAnimate3D.h

189 lines
6.1 KiB
C
Raw Normal View History

2019-11-23 20:27:39 +08:00
/****************************************************************************
Copyright (c) 2014-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
2022-07-09 07:07:01 +08:00
https://adxeproject.github.io/
2019-11-23 20:27:39 +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 __CCANIMATE3D_H__
#define __CCANIMATE3D_H__
#include <map>
#include <unordered_map>
#include "3d/CCAnimation3D.h"
#include "base/ccMacros.h"
#include "base/CCRef.h"
#include "2d/CCActionInterval.h"
NS_CC_BEGIN
class Bone3D;
class MeshRenderer;
2019-11-23 20:27:39 +08:00
class EventCustom;
enum class Animate3DQuality
{
2021-12-25 10:04:45 +08:00
QUALITY_NONE =
0, // it'll be ignore the curve-evaluating(the animation looks like stop), just accumulate transition time.
QUALITY_LOW, // low animation quality, it'll be more efficient.
QUALITY_HIGH, // high animation quality.
2019-11-23 20:27:39 +08:00
};
/**
* @addtogroup _3d
* @{
*/
/**
* @brief Animate3D, Animates a MeshRenderer given with an Animation3D
2019-11-23 20:27:39 +08:00
*/
2021-12-25 10:04:45 +08:00
class CC_DLL Animate3D : public ActionInterval
2019-11-23 20:27:39 +08:00
{
public:
/**create Animate3D using Animation.*/
static Animate3D* create(Animation3D* animation);
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
/**
* create Animate3D
* @param animation used to generate animate3D
* @param fromTime
* @param duration Time the Animate3D lasts
* @return Animate3D created using animate
*/
static Animate3D* create(Animation3D* animation, float fromTime, float duration);
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
/**
* create Animate3D by frame section, [startFrame, endFrame)
* @param animation used to generate animate3D
* @param startFrame
* @param endFrame
* @param frameRate default is 30 per second
* @return Animate3D created using animate
*/
static Animate3D* createWithFrames(Animation3D* animation, int startFrame, int endFrame, float frameRate = 30.f);
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
//
// Overrides
//
virtual void stop() override;
virtual void step(float dt) override;
2021-12-25 10:04:45 +08:00
virtual void startWithTarget(Node* target) override;
2019-11-23 20:27:39 +08:00
virtual Animate3D* reverse() const override;
2021-12-25 10:04:45 +08:00
virtual Animate3D* clone() const override;
2019-11-23 20:27:39 +08:00
virtual void update(float t) override;
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
/**get & set speed, negative speed means playing reverse */
float getSpeed() const;
void setSpeed(float speed);
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
/**get & set blend weight, weight must positive*/
float getWeight() const { return _weight; }
void setWeight(float weight);
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
/**get & set origin interval*/
void setOriginInterval(float interval);
2021-12-25 10:04:45 +08:00
float getOriginInterval() const { return _originInterval; }
2019-11-23 20:27:39 +08:00
/** get animate transition time between 3d animations */
static float getTransitionTime() { return _transTime; }
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
/** set animate transition time between 3d animations */
2021-12-25 10:04:45 +08:00
static void setTransitionTime(float transTime)
{
if (transTime >= 0.f)
_transTime = transTime;
}
2019-11-23 20:27:39 +08:00
/**set animate quality*/
void setQuality(Animate3DQuality quality);
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
/**get animate quality*/
Animate3DQuality getQuality() const;
struct Animate3DDisplayedEventInfo
{
int frame;
Node* target;
const ValueMap* userInfo;
};
2021-12-25 10:04:45 +08:00
void setKeyFrameUserInfo(int keyFrame, const ValueMap& userInfo);
2019-11-23 20:27:39 +08:00
const ValueMap* getKeyFrameUserInfo(int keyFrame) const;
ValueMap* getKeyFrameUserInfo(int keyFrame);
Animate3D();
2019-11-23 20:27:39 +08:00
virtual ~Animate3D();
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
void removeFromMap();
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
/** init method */
bool init(Animation3D* animation);
bool init(Animation3D* animation, float fromTime, float duration);
bool initWithFrames(Animation3D* animation, int startFrame, int endFrame, float frameRate);
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
protected:
enum class Animate3DState
{
FadeIn,
FadeOut,
Running,
};
2021-12-25 10:04:45 +08:00
Animate3DState _state; // animation state
Animation3D* _animation; // animation data
float _absSpeed; // playing speed
float _weight; // blend weight
float _start; // start time 0 - 1, used to generate sub Animate3D
float _last; // last time 0 - 1, used to generate sub Animate3D
bool _playReverse; // is playing reverse
static float _transTime; // transition time from one animate3d to another
float _accTransTime; // accumulate transition time
float _lastTime; // last t (0 - 1)
float _originInterval; // save origin interval time
float _frameRate;
2019-11-23 20:27:39 +08:00
// animation quality
EvaluateType _translateEvaluate;
EvaluateType _roteEvaluate;
EvaluateType _scaleEvaluate;
Animate3DQuality _quality;
2021-12-25 10:04:45 +08:00
std::unordered_map<Bone3D*, Animation3D::Curve*> _boneCurves; // weak ref
2019-11-23 20:27:39 +08:00
std::unordered_map<Node*, Animation3D::Curve*> _nodeCurves;
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
std::unordered_map<int, ValueMap> _keyFrameUserInfos;
std::unordered_map<int, EventCustom*> _keyFrameEvent;
std::unordered_map<int, Animate3DDisplayedEventInfo> _displayedEventInfo;
// mesh animations
2019-11-23 20:27:39 +08:00
static std::unordered_map<Node*, Animate3D*> s_fadeInAnimates;
static std::unordered_map<Node*, Animate3D*> s_fadeOutAnimates;
static std::unordered_map<Node*, Animate3D*> s_runningAnimates;
};
// end of 3d group
/// @}
NS_CC_END
2021-12-25 10:04:45 +08:00
#endif // __CCANIMATE3D_H__