| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | #include <osgAnimation/ActionStripAnimation> |
|---|
| 17 | |
|---|
| 18 | using namespace osgAnimation; |
|---|
| 19 | |
|---|
| 20 | ActionAnimation* ActionStripAnimation::getAnimation() { return _animation.get(); } |
|---|
| 21 | ActionBlendIn* ActionStripAnimation::getBlendIn() { return _blendIn.get(); } |
|---|
| 22 | ActionBlendOut* ActionStripAnimation::getBlendOut() { return _blendOut.second.get(); } |
|---|
| 23 | const ActionAnimation* ActionStripAnimation::getAnimation() const { return _animation.get(); } |
|---|
| 24 | const ActionBlendIn* ActionStripAnimation::getBlendIn() const { return _blendIn.get(); } |
|---|
| 25 | const ActionBlendOut* ActionStripAnimation::getBlendOut() const { return _blendOut.second.get(); } |
|---|
| 26 | unsigned int ActionStripAnimation::getBlendOutStartFrame() const { return _blendOut.first; } |
|---|
| 27 | |
|---|
| 28 | unsigned int ActionStripAnimation::getLoop() const { return _animation->getLoop(); } |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | ActionStripAnimation::ActionStripAnimation(const ActionStripAnimation& a, const osg::CopyOp& c) : Action(a,c) |
|---|
| 32 | { |
|---|
| 33 | _animation = a._animation; |
|---|
| 34 | _blendIn = a._blendIn; |
|---|
| 35 | _blendOut = a._blendOut; |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | ActionStripAnimation::ActionStripAnimation(Animation* animation, double blendInDuration, double blendOutDuration, double blendInWeightTarget) |
|---|
| 39 | { |
|---|
| 40 | _blendIn = new ActionBlendIn(animation, blendInDuration, blendInWeightTarget); |
|---|
| 41 | _animation = new ActionAnimation(animation); |
|---|
| 42 | unsigned int start = static_cast<unsigned int>(floor((_animation->getDuration() - blendOutDuration) * _fps)); |
|---|
| 43 | _blendOut = FrameBlendOut(start, new ActionBlendOut(animation, blendOutDuration)); |
|---|
| 44 | setName(animation->getName() + "_Strip"); |
|---|
| 45 | _blendIn->setName(_animation->getName() + "_" + _blendIn->getName()); |
|---|
| 46 | _blendOut.second->setName(_animation->getName() + "_" + _blendOut.second->getName()); |
|---|
| 47 | setDuration(animation->getDuration()); |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | void ActionStripAnimation::setLoop(unsigned int loop) |
|---|
| 52 | { |
|---|
| 53 | _animation->setLoop(loop); |
|---|
| 54 | if (!loop) |
|---|
| 55 | setDuration(-1); |
|---|
| 56 | else |
|---|
| 57 | setDuration(loop * _animation->getDuration()); |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | unsigned int start = static_cast<unsigned int>(floor((getDuration() - _blendOut.second->getDuration()) * _fps)); |
|---|
| 61 | _blendOut = FrameBlendOut(start, _blendOut.second); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | void ActionStripAnimation::traverse(ActionVisitor& visitor) |
|---|
| 65 | { |
|---|
| 66 | if (_blendIn.valid()) |
|---|
| 67 | { |
|---|
| 68 | unsigned int f = visitor.getStackedFrameAction().back().first; |
|---|
| 69 | visitor.pushFrameActionOnStack(FrameAction(f,_blendIn.get())); |
|---|
| 70 | _blendIn->accept(visitor); |
|---|
| 71 | visitor.popFrameAction(); |
|---|
| 72 | } |
|---|
| 73 | if (_blendOut.second.valid()) |
|---|
| 74 | { |
|---|
| 75 | unsigned int f = visitor.getStackedFrameAction().back().first; |
|---|
| 76 | visitor.pushFrameActionOnStack(FrameAction(f + _blendOut.first,_blendOut.second.get())); |
|---|
| 77 | _blendOut.second.get()->accept(visitor); |
|---|
| 78 | visitor.popFrameAction(); |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | if (_animation.valid()) |
|---|
| 82 | { |
|---|
| 83 | unsigned int f = visitor.getStackedFrameAction().back().first; |
|---|
| 84 | visitor.pushFrameActionOnStack(FrameAction(f,_animation.get())); |
|---|
| 85 | _animation->accept(visitor); |
|---|
| 86 | visitor.popFrameAction(); |
|---|
| 87 | } |
|---|
| 88 | } |
|---|