From 2c18db5b18de9fb1475a2f83dc24a0df4c5d9981 Mon Sep 17 00:00:00 2001 From: lvlong Date: Fri, 10 Oct 2014 17:44:45 +0800 Subject: [PATCH 1/3] create animate by frame section. --- cocos/3d/CCAnimate3D.cpp | 22 ++++++++++++++++++++++ cocos/3d/CCAnimate3D.h | 10 ++++++++++ 2 files changed, 32 insertions(+) diff --git a/cocos/3d/CCAnimate3D.cpp b/cocos/3d/CCAnimate3D.cpp index 7327822d20..33ba435658 100644 --- a/cocos/3d/CCAnimate3D.cpp +++ b/cocos/3d/CCAnimate3D.cpp @@ -62,6 +62,28 @@ Animate3D* Animate3D::create(Animation3D* animation, float fromTime, float durat return animate; } +Animate3D* Animate3D::create(Animation3D* animation, int startFrame, int endFrame, float frameRate) +{ + auto animate = Animate3D::create(animation); + + float fullDuration = animation->getDuration(); + float perFrameTime = 1.f / frameRate; + float fromTime = startFrame * perFrameTime; + float duration = (endFrame - startFrame) * perFrameTime; + + if (fromTime < 0) + fromTime = 0; + + if (duration > fullDuration - fromTime) + duration = fullDuration - fromTime; + + animate->_start = fromTime / fullDuration; + animate->_last = duration / fullDuration; + animate->setDuration(duration); + + return animate; +} + /** returns a clone of action */ Animate3D* Animate3D::clone() const { diff --git a/cocos/3d/CCAnimate3D.h b/cocos/3d/CCAnimate3D.h index 5591e96f4b..12aaed634d 100644 --- a/cocos/3d/CCAnimate3D.h +++ b/cocos/3d/CCAnimate3D.h @@ -56,6 +56,16 @@ public: * @return Animate3D created using animate */ static Animate3D* create(Animation3D* animation, float fromTime, float duration); + + /** + * create Animate3D by frame section + * @param animation used to generate animate3D + * @param startFrame + * @param endFrame + * @return Animate3D created using animate + */ + static Animate3D* create(Animation3D* animation, int startFrame, int endFrame, float frameRate = 30.f); + // // Overrides // From 4bba69d578bbb06dcfdd6ece5fa9c0f100361513 Mon Sep 17 00:00:00 2001 From: lvlong Date: Fri, 10 Oct 2014 17:48:54 +0800 Subject: [PATCH 2/3] add a param comment --- cocos/3d/CCAnimate3D.h | 1 + 1 file changed, 1 insertion(+) diff --git a/cocos/3d/CCAnimate3D.h b/cocos/3d/CCAnimate3D.h index 12aaed634d..f0e2fb02ea 100644 --- a/cocos/3d/CCAnimate3D.h +++ b/cocos/3d/CCAnimate3D.h @@ -62,6 +62,7 @@ public: * @param animation used to generate animate3D * @param startFrame * @param endFrame + * @param frameRate default is 30 per second * @return Animate3D created using animate */ static Animate3D* create(Animation3D* animation, int startFrame, int endFrame, float frameRate = 30.f); From 6be64fedd7694328334666af3fa638565b992638 Mon Sep 17 00:00:00 2001 From: lvlong Date: Sat, 11 Oct 2014 17:02:42 +0800 Subject: [PATCH 3/3] modify Animate3D::create --- cocos/3d/CCAnimate3D.cpp | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/cocos/3d/CCAnimate3D.cpp b/cocos/3d/CCAnimate3D.cpp index 33ba435658..f62e102d98 100644 --- a/cocos/3d/CCAnimate3D.cpp +++ b/cocos/3d/CCAnimate3D.cpp @@ -64,23 +64,11 @@ Animate3D* Animate3D::create(Animation3D* animation, float fromTime, float durat Animate3D* Animate3D::create(Animation3D* animation, int startFrame, int endFrame, float frameRate) { - auto animate = Animate3D::create(animation); - - float fullDuration = animation->getDuration(); float perFrameTime = 1.f / frameRate; float fromTime = startFrame * perFrameTime; float duration = (endFrame - startFrame) * perFrameTime; - if (fromTime < 0) - fromTime = 0; - - if (duration > fullDuration - fromTime) - duration = fullDuration - fromTime; - - animate->_start = fromTime / fullDuration; - animate->_last = duration / fullDuration; - animate->setDuration(duration); - + auto animate = create(animation, fromTime, duration); return animate; }