diff --git a/cocos/3d/CCAnimate3D.cpp b/cocos/3d/CCAnimate3D.cpp index 7327822d20..f62e102d98 100644 --- a/cocos/3d/CCAnimate3D.cpp +++ b/cocos/3d/CCAnimate3D.cpp @@ -62,6 +62,16 @@ Animate3D* Animate3D::create(Animation3D* animation, float fromTime, float durat return animate; } +Animate3D* Animate3D::create(Animation3D* animation, int startFrame, int endFrame, float frameRate) +{ + float perFrameTime = 1.f / frameRate; + float fromTime = startFrame * perFrameTime; + float duration = (endFrame - startFrame) * perFrameTime; + + auto animate = create(animation, fromTime, 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 cf46227697..686e8f014e 100644 --- a/cocos/3d/CCAnimate3D.h +++ b/cocos/3d/CCAnimate3D.h @@ -55,6 +55,17 @@ 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 + * @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); + // // Overrides //