From 16ab05a8cf3c0adccfeb37cde35b3fbe96fdbd14 Mon Sep 17 00:00:00 2001 From: yangxiao Date: Thu, 28 Aug 2014 13:47:17 +0800 Subject: [PATCH 01/20] sequence3d --- build/cocos2d_libs.xcodeproj/project.pbxproj | 12 + cocos/3d/CCSequence3D.cpp | 346 +++++++++++++++++++ cocos/3d/CCSequence3D.h | 107 ++++++ 3 files changed, 465 insertions(+) create mode 100644 cocos/3d/CCSequence3D.cpp create mode 100644 cocos/3d/CCSequence3D.h diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj b/build/cocos2d_libs.xcodeproj/project.pbxproj index 6178a6bb87..9db966c5d6 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj @@ -1858,6 +1858,10 @@ B37510841823ACA100B3BA6A /* CCPhysicsShapeInfo_chipmunk.h in Headers */ = {isa = PBXBuildFile; fileRef = B375104D1823AC7B00B3BA6A /* CCPhysicsShapeInfo_chipmunk.h */; }; B37510851823ACA100B3BA6A /* CCPhysicsWorldInfo_chipmunk.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B375104E1823AC7B00B3BA6A /* CCPhysicsWorldInfo_chipmunk.cpp */; }; B37510861823ACA100B3BA6A /* CCPhysicsWorldInfo_chipmunk.h in Headers */ = {isa = PBXBuildFile; fileRef = B375104F1823AC7B00B3BA6A /* CCPhysicsWorldInfo_chipmunk.h */; }; + B6F7149419AEF7C8009061BD /* CCSequence3D.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B6F7149219AEF7C8009061BD /* CCSequence3D.cpp */; }; + B6F7149519AEF7C8009061BD /* CCSequence3D.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B6F7149219AEF7C8009061BD /* CCSequence3D.cpp */; }; + B6F7149619AEF7C8009061BD /* CCSequence3D.h in Headers */ = {isa = PBXBuildFile; fileRef = B6F7149319AEF7C8009061BD /* CCSequence3D.h */; }; + B6F7149719AEF7C8009061BD /* CCSequence3D.h in Headers */ = {isa = PBXBuildFile; fileRef = B6F7149319AEF7C8009061BD /* CCSequence3D.h */; }; ED9C6A9418599AD8000A5232 /* CCNodeGrid.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ED9C6A9218599AD8000A5232 /* CCNodeGrid.cpp */; }; ED9C6A9518599AD8000A5232 /* CCNodeGrid.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ED9C6A9218599AD8000A5232 /* CCNodeGrid.cpp */; }; ED9C6A9618599AD8000A5232 /* CCNodeGrid.h in Headers */ = {isa = PBXBuildFile; fileRef = ED9C6A9318599AD8000A5232 /* CCNodeGrid.h */; }; @@ -2877,6 +2881,8 @@ B375104F1823AC7B00B3BA6A /* CCPhysicsWorldInfo_chipmunk.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCPhysicsWorldInfo_chipmunk.h; sourceTree = ""; }; B3AF019E1842FBA400A98B85 /* b2MotorJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2MotorJoint.cpp; sourceTree = ""; }; B3AF019F1842FBA400A98B85 /* b2MotorJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2MotorJoint.h; sourceTree = ""; }; + B6F7149219AEF7C8009061BD /* CCSequence3D.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCSequence3D.cpp; sourceTree = ""; }; + B6F7149319AEF7C8009061BD /* CCSequence3D.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCSequence3D.h; sourceTree = ""; }; ED9C6A9218599AD8000A5232 /* CCNodeGrid.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = CCNodeGrid.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; ED9C6A9318599AD8000A5232 /* CCNodeGrid.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCNodeGrid.h; sourceTree = ""; }; /* End PBXFileReference section */ @@ -4888,6 +4894,8 @@ B29594B81926D61F003EEF37 /* 3d */ = { isa = PBXGroup; children = ( + B6F7149219AEF7C8009061BD /* CCSequence3D.cpp */, + B6F7149319AEF7C8009061BD /* CCSequence3D.h */, 15AE17E319AAD2F700C27E9E /* 3dExport.h */, 15AE17E419AAD2F700C27E9E /* CCAABB.cpp */, 15AE17E519AAD2F700C27E9E /* CCAABB.h */, @@ -5374,6 +5382,7 @@ 50ABC0031926664800A911A9 /* CCLock.h in Headers */, B37510721823AC9F00B3BA6A /* CCPhysicsBodyInfo_chipmunk.h in Headers */, 50ABBE2D1925AB6F00A911A9 /* ccCArray.h in Headers */, + B6F7149619AEF7C8009061BD /* CCSequence3D.h in Headers */, 50ABBD5E1925AB0000A911A9 /* Vec3.h in Headers */, 15AE188919AAD33D00C27E9E /* CCControlButtonLoader.h in Headers */, 15AE19EE19AAD3A700C27E9E /* spine.h in Headers */, @@ -5708,6 +5717,7 @@ 15AE1AAB19AAD40300C27E9E /* b2World.h in Headers */, 15AE19FC19AAD3A700C27E9E /* AnimationStateData.h in Headers */, 15AE180F19AAD2F700C27E9E /* CCAnimate3D.h in Headers */, + B6F7149719AEF7C8009061BD /* CCSequence3D.h in Headers */, 50ABBE341925AB6F00A911A9 /* CCConfiguration.h in Headers */, 1A570299180BCCAB0088DEC7 /* CCAnimationCache.h in Headers */, 15AE1ABF19AAD40300C27E9E /* b2PolygonContact.h in Headers */, @@ -6174,6 +6184,7 @@ 1A5701E6180BCB8C0088DEC7 /* CCTransition.cpp in Sources */, 15AE19D819AAD3A700C27E9E /* CCSkeletonAnimation.cpp in Sources */, 15AE19E819AAD3A700C27E9E /* Slot.cpp in Sources */, + B6F7149419AEF7C8009061BD /* CCSequence3D.cpp in Sources */, B24AA985195A675C007B4522 /* CCFastTMXLayer.cpp in Sources */, 15AE1A6A19AAD40300C27E9E /* b2ChainAndCircleContact.cpp in Sources */, 15AE19BE19AAD3A700C27E9E /* Event.cpp in Sources */, @@ -6624,6 +6635,7 @@ 1A5701C8180BCB5A0088DEC7 /* CCLabelTextFormatter.cpp in Sources */, 1A5701CC180BCB5A0088DEC7 /* CCLabelTTF.cpp in Sources */, 15AE193419AAD35100C27E9E /* CCActionObject.cpp in Sources */, + B6F7149519AEF7C8009061BD /* CCSequence3D.cpp in Sources */, 15AE1AD619AAD40300C27E9E /* b2WheelJoint.cpp in Sources */, 299754F5193EC95400A54AC3 /* ObjectFactory.cpp in Sources */, 1A5701DF180BCB8C0088DEC7 /* CCLayer.cpp in Sources */, diff --git a/cocos/3d/CCSequence3D.cpp b/cocos/3d/CCSequence3D.cpp new file mode 100644 index 0000000000..e75d100ee5 --- /dev/null +++ b/cocos/3d/CCSequence3D.cpp @@ -0,0 +1,346 @@ +/**************************************************************************** + Copyright (c) 2014 Chukong Technologies Inc. + + http://www.cocos2d-x.org + + 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. + ****************************************************************************/ + +#include "3d/CCSequence3D.h" + +NS_CC_BEGIN + +class ExtraAnimate3D : public FiniteTimeAction +{ +public: + static ExtraAnimate3D* create(); + virtual ExtraAnimate3D* clone() const; + virtual ExtraAnimate3D* reverse(void) const; + virtual void update(float time); + virtual void step(float dt); +}; + +ExtraAnimate3D* ExtraAnimate3D::create() +{ + ExtraAnimate3D* ret = new ExtraAnimate3D(); + if (ret) + { + ret->autorelease(); + } + return ret; +} +ExtraAnimate3D* ExtraAnimate3D::clone() const +{ + // no copy constructor + auto a = new ExtraAnimate3D(); + a->autorelease(); + return a; +} + +ExtraAnimate3D* ExtraAnimate3D::reverse() const +{ + return ExtraAnimate3D::create(); +} + +void ExtraAnimate3D::update(float time) +{ + CC_UNUSED_PARAM(time); +} + +void ExtraAnimate3D::step(float dt) +{ + CC_UNUSED_PARAM(dt); +} + +Sequence3D* Sequence3D::createWithTwoActions(Animate3D *actionOne, Animate3D *actionTwo) +{ + Sequence3D *sequence3d = new Sequence3D(); + sequence3d->initWithTwoActions(actionOne, actionTwo); + sequence3d->autorelease(); + + return sequence3d; +} + +#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) +Sequence3D* Sequence3D::variadicCreate(Animate3D *action1, ...) +{ + va_list params; + va_start(params, action1); + + Sequence3D *ret = Sequence3D::createWithVariableList(action1, params); + + va_end(params); + + return ret; +} +#else +Sequence3D* Sequence3D::create(Animate3D *action1, ...) +{ + va_list params; + va_start(params, action1); + + Sequence3D *ret = Sequence3D::createWithVariableList(action1, params); + + va_end(params); + + return ret; +} +#endif + +Sequence3D* Sequence3D::createWithVariableList(Animate3D *action1, va_list args) +{ + Animate3D *now; + Animate3D *prev = action1; + bool bOneAction = true; + + while (action1) + { + now = va_arg(args, Animate3D*); + if (now) + { + prev = (Animate3D*)createWithTwoActions(prev, now); + bOneAction = false; + } + else + { + if (bOneAction) + { + prev = (Animate3D*)createWithTwoActions(prev, (Animate3D*)ExtraAnimate3D::create()); + } + break; + } + } + + return ((Sequence3D*)prev); +} + +Sequence3D* Sequence3D::create(const Vector& arrayOfActions) +{ + Sequence3D* ret = nullptr; + do + { + auto count = arrayOfActions.size(); + CC_BREAK_IF(count == 0); + + auto prev = arrayOfActions.at(0); + + if (count > 1) + { + for (int i = 1; i < count; ++i) + { + prev = (Animate3D*)createWithTwoActions(prev, arrayOfActions.at(i)); + } + } + else + { + prev = (Animate3D*)createWithTwoActions(prev, (Animate3D*)ExtraAnimate3D::create()); + } + ret = (Sequence3D*)prev; + }while (0); + return ret; +} + +bool Sequence3D::initWithTwoActions(Animate3D *actionOne, Animate3D *actionTwo) +{ + CCASSERT(actionOne != nullptr, ""); + CCASSERT(actionTwo != nullptr, ""); + + float d = actionOne->getDuration() + actionTwo->getDuration(); + ActionInterval::initWithDuration(d); + + _actions[0] = actionOne; + actionOne->retain(); + + _actions[1] = actionTwo; + actionTwo->retain(); + + return true; +} + +Sequence3D* Sequence3D::clone() const +{ + // no copy constructor + auto seq3d = new Sequence3D(); + seq3d->initWithTwoActions(_actions[0]->clone(), _actions[1]->clone() ); + seq3d->autorelease(); + return seq3d; +} + +Sequence3D::Sequence3D() +: _blendTime(0.1f) +,_blendRemain(0.1f) +,_cutAnim(false) +,cut_t(0.0f) +{ + +} + +Sequence3D::~Sequence3D(void) +{ + CC_SAFE_RELEASE(_actions[0]); + CC_SAFE_RELEASE(_actions[1]); +} + +void Sequence3D::startWithTarget(Node *target) +{ + ActionInterval::startWithTarget(target); + _split = _actions[0]->getDuration() / _duration; + _last = -1; +} + +void Sequence3D::stop(void) +{ + if( _last != - 1) + { + _actions[_last]->stop(); + } + + ActionInterval::stop(); +} + +Sequence3D* Sequence3D::reverse() const +{ + return Sequence3D::createWithTwoActions(_actions[1]->reverse(), _actions[0]->reverse()); +} + +void Sequence3D::update(float t) +{ + int found = 0; + float new_t = 0.0f; + float blend_t = 0.0f; + + if( t < _split ) { + // action[0] + found = 0; + if( _split != 0 ) + new_t = t / _split; + else + new_t = 1; + + if( found != _last && found <= 0 ) + _actions[0]->startWithTarget(_target); + + _actions[0]->update(new_t); + + } + if(t >= (_split - _blendTime) && _cutAnim == false) + { + // action[1] + + blend_t += 0.01f; + Blend(blend_t); + found = 1; + if ( _split == 1 ) + new_t = 1; + else + new_t = (t-(_split - _blendTime)) / (1 - (_split - _blendTime)); + + if( found != _last && found >= 1 ) + _actions[1]->startWithTarget(_target); + + _actions[1]->update(new_t); + } + if(_cutAnim == true) + { + blend_t += 0.01f; + Blend(blend_t); + found = 1; + if(found != _last && found >= 1) + { + cut_t = t; + } + if ( _split == 1 ) + new_t = 1; + else + new_t = (t - cut_t) / (1 - cut_t); + + if( found != _last && found >= 1 ) + _actions[1]->startWithTarget(_target); + + _actions[1]->update(new_t); + } + // if ( found==1 ) { + + // if( _last == -1 ) { + // // action[0] was skipped, execute it. + // _actions[0]->startWithTarget(_target); + // _actions[0]->update(1.0f); + // _actions[0]->stop(); + // } + // else if( _last == 0 ) + // { + // // switching to action 1. stop action 0. + // _actions[0]->update(1.0f); + // _actions[0]->stop(); + // } + // } + //else if(found==0 && _last==1 ) + //{ + // // Reverse mode ? + // // XXX: Bug. this case doesn't contemplate when _last==-1, found=0 and in "reverse mode" + // // since it will require a hack to know if an action is on reverse mode or not. + // // "step" should be overriden, and the "reverseMode" value propagated to inner Sequences. + // _actions[1]->update(0); + // _actions[1]->stop(); + //} + // // Last action found and it is done. + // if( found == _last && _actions[found]->isDone() ) + // { + // return; + // } + + // // Last action found and it is done + // if( found != _last ) + // { + // //_actions[found]->startWithTarget(_target); + // } + + //_actions[found]->update(new_t); + _last = found; +} + +void Sequence3D::Blend(float timeElapse) +{ + _blendRemain -= timeElapse; + bool bBlending = _blendRemain >= 0; + if (bBlending) + { + float fSrcWeight = _blendRemain / _blendTime; + _actions[0]->setWeight(fSrcWeight); + _actions[1]->setWeight(1 - fSrcWeight); + } +} + +void Sequence3D::addAnimate3D(Animate3D* animate) +{ + if(this->_duration > 0) + { + if(_actions[1]->getDuration() <= 0) + { + _actions[1] = animate; + _cutAnim = true; + _duration += _actions[1]->getDuration(); + _split = _actions[0]->getDuration() / _duration; + } + } + else + return; +} + +NS_CC_END diff --git a/cocos/3d/CCSequence3D.h b/cocos/3d/CCSequence3D.h new file mode 100644 index 0000000000..e580f6179e --- /dev/null +++ b/cocos/3d/CCSequence3D.h @@ -0,0 +1,107 @@ +/**************************************************************************** + Copyright (c) 2014 Chukong Technologies Inc. + + http://www.cocos2d-x.org + + 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 __CCSEQUECE3D_H__ +#define __CCSEQUECE3D_H__ + +#include "2d/CCActionInterval.h" +#include "3d/CCAnimate3D.h" + +NS_CC_BEGIN + + +class CC_3D_DLL Sequence3D : public ActionInterval +{ +public: + /** helper constructor to create an array of sequenceable actions */ +#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) + // WP8 in VS2012 does not support nullptr in variable args lists and variadic templates are also not supported + typedef Animate3D* M; + static Sequence3D* create(M m1, std::nullptr_t listEnd) { return variadicCreate(m1, NULL); } + static Sequence3D* create(M m1, M m2, std::nullptr_t listEnd) { return variadicCreate(m1, m2, NULL); } + static Sequence3D* create(M m1, M m2, M m3, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, NULL); } + static Sequence3D* create(M m1, M m2, M m3, M m4, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, NULL); } + static Sequence3D* create(M m1, M m2, M m3, M m4, M m5, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, NULL); } + static Sequence3D* create(M m1, M m2, M m3, M m4, M m5, M m6, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, m6, NULL); } + static Sequence3D* create(M m1, M m2, M m3, M m4, M m5, M m6, M m7, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, m6, m7, NULL); } + static Sequence3D* create(M m1, M m2, M m3, M m4, M m5, M m6, M m7, M m8, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, m6, m7, m8, NULL); } + static Sequence3D* create(M m1, M m2, M m3, M m4, M m5, M m6, M m7, M m8, M m9, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, m6, m7, m8, m9, NULL); } + static Sequence3D* create(M m1, M m2, M m3, M m4, M m5, M m6, M m7, M m8, M m9, M m10, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, NULL); } + + // On WP8 for variable argument lists longer than 10 items, use the other create functions or variadicCreate with NULL as the last argument + static Sequence3D* variadicCreate(Animate3D* item, ...); +#else + static Sequence3D* create(Animate3D *action1, ...) CC_REQUIRES_NULL_TERMINATION; +#endif + + /** helper constructor to create an array of sequenceable actions given an array + * @code + * When this funtion bound to the js or lua,the input params changed + * in js :var create(var object1,var object2, ...) + * in lua :local create(local object1,local object2, ...) + * @endcode + */ + static Sequence3D* create(const Vector& arrayOfActions); + /** helper constructor to create an array of sequence-able actions */ + static Sequence3D* createWithVariableList(Animate3D *action1, va_list args); + /** creates the action */ + static Sequence3D* createWithTwoActions(Animate3D *actionOne, Animate3D *actionTwo); + + // + // Overrides + // + virtual Sequence3D* clone() const override; + virtual Sequence3D* reverse() const override; + virtual void startWithTarget(Node *target) override; + virtual void stop(void) override; + virtual void update(float t) override; + + void addAnimate3D(Animate3D* animate); + +CC_CONSTRUCTOR_ACCESS: + Sequence3D(); + virtual ~Sequence3D(void); + + /** initializes the action */ + bool initWithTwoActions(Animate3D *pActionOne, Animate3D *pActionTwo); + +protected: + Animate3D* _actions[2]; + float _split; + int _last; + float _blendTime; + float _blendRemain; + bool _cutAnim; + float cut_t; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(Sequence3D); + + void Blend(float timeElapse); + +}; + +NS_CC_END + +#endif // __CCSEQUECE3D_H__ From a3dd4e101a5be527114cc26d9440ebbbe6688439 Mon Sep 17 00:00:00 2001 From: yangxiao Date: Thu, 28 Aug 2014 18:53:15 +0800 Subject: [PATCH 02/20] animation transition --- cocos/3d/CCAnimate3D.cpp | 126 +++++++++++++++++++++++++++++++-------- cocos/3d/CCAnimate3D.h | 20 ++++++- 2 files changed, 120 insertions(+), 26 deletions(-) diff --git a/cocos/3d/CCAnimate3D.cpp b/cocos/3d/CCAnimate3D.cpp index 0aff12f2d1..8ebada6608 100644 --- a/cocos/3d/CCAnimate3D.cpp +++ b/cocos/3d/CCAnimate3D.cpp @@ -33,6 +33,10 @@ NS_CC_BEGIN +std::unordered_map Animate3D::s_fadeInAnimates; +std::unordered_map Animate3D::s_fadeOutAnimates; +std::unordered_map Animate3D::s_runningAnimates; + //create Animate3D using Animation. Animate3D* Animate3D::create(Animation3D* animation) { @@ -110,6 +114,41 @@ void Animate3D::startWithTarget(Node *target) { CCLOG("warning: no animation finde for the skeleton"); } + + auto runningAction = s_runningAnimates.find(sprite); + if (runningAction != s_runningAnimates.end()) + { + //make the running action fade out + auto action = (*runningAction).second; + s_fadeOutAnimates[sprite] = action; + action->_state = Animate3D::Animate3DState::FadeOut; + action->_accTransTime = 0.0f; + + s_fadeInAnimates[sprite] = this; + _accTransTime = 0.0f; + _state = Animate3D::Animate3DState::FadeIn; + _weight = 0.f; + } + else + { + s_runningAnimates[sprite] = this; + _state = Animate3D::Animate3DState::Running; + _weight = 1.0f; + } +} + +void Animate3D::stop() +{ + //remove this action from map + Sprite3D* sprite = static_cast(_target); + if (_state == Animate3D::Animate3DState::FadeIn) + s_fadeInAnimates.erase(sprite); + else if (_state == Animate3D::Animate3DState::FadeOut) + s_fadeOutAnimates.erase(sprite); + else + s_runningAnimates.erase(sprite); + + ActionInterval::stop(); } //! called every frame with it's delta time. DON'T override unless you know what you are doing. @@ -120,36 +159,69 @@ void Animate3D::step(float dt) void Animate3D::update(float t) { - if (_target && _weight > 0.f) + if (_target) { - float transDst[3], rotDst[4], scaleDst[3]; - float* trans = nullptr, *rot = nullptr, *scale = nullptr; - if (_playReverse) - t = 1 - t; + if (_state == Animate3D::Animate3DState::FadeIn && _accTransTime > 0.f) + { + _accTransTime += (t - _lastTime) * getDuration(); + + _weight = _accTransTime / _transTime; + if (_weight >= 1.0f) + { + _accTransTime = _transTime; + _weight = 1.0f; + + Sprite3D* sprite = static_cast(_target); + s_fadeInAnimates.erase(sprite); + s_runningAnimates[sprite] = this; + } + } + else if (_state == Animate3D::Animate3DState::FadeOut && _accTransTime > 0.f) + { + _accTransTime += (t - _lastTime) * getDuration(); + + _weight = 1 - _accTransTime / _transTime; + if (_weight <= 0.0f) + { + _accTransTime = _transTime; + _weight = 0.0f; + + Sprite3D* sprite = static_cast(_target); + s_fadeOutAnimates.erase(sprite); + } + } + _lastTime = t; - t = _start + t * _last; - for (const auto& it : _boneCurves) { - auto bone = it.first; - auto curve = it.second; - if (curve->translateCurve) - { - curve->translateCurve->evaluate(t, transDst, EvaluateType::INT_LINEAR); - trans = &transDst[0]; + if (_weight > 0.0f) + { + float transDst[3], rotDst[4], scaleDst[3]; + float* trans = nullptr, *rot = nullptr, *scale = nullptr; + if (_playReverse) + t = 1 - t; + + t = _start + t * _last; + for (const auto& it : _boneCurves) { + auto bone = it.first; + auto curve = it.second; + if (curve->translateCurve) + { + curve->translateCurve->evaluate(t, transDst, EvaluateType::INT_LINEAR); + trans = &transDst[0]; + } + if (curve->rotCurve) + { + curve->rotCurve->evaluate(t, rotDst, EvaluateType::INT_QUAT_SLERP); + rot = &rotDst[0]; + } + if (curve->scaleCurve) + { + curve->scaleCurve->evaluate(t, scaleDst, EvaluateType::INT_LINEAR); + scale = &scaleDst[0]; + } + bone->setAnimationValue(trans, rot, scale, this, _weight); } - if (curve->rotCurve) - { - curve->rotCurve->evaluate(t, rotDst, EvaluateType::INT_QUAT_SLERP); - rot = &rotDst[0]; - } - if (curve->scaleCurve) - { - curve->scaleCurve->evaluate(t, scaleDst, EvaluateType::INT_LINEAR); - scale = &scaleDst[0]; - } - bone->setAnimationValue(trans, rot, scale, this, _weight); } } - } float Animate3D::getSpeed() const @@ -175,6 +247,10 @@ Animate3D::Animate3D() , _last(1.f) , _animation(nullptr) , _playReverse(false) +, _state(Animate3D::Animate3DState::Running) +, _transTime(0.1f) +, _accTransTime(0.0f) +, _lastTime(0.0f) { } diff --git a/cocos/3d/CCAnimate3D.h b/cocos/3d/CCAnimate3D.h index d6d8152bb2..5782e175b8 100644 --- a/cocos/3d/CCAnimate3D.h +++ b/cocos/3d/CCAnimate3D.h @@ -26,6 +26,7 @@ #define __CCANIMATE3D_H__ #include +#include #include "3d/CCAnimation3D.h" @@ -40,6 +41,7 @@ NS_CC_BEGIN class Animation3D; class Bone3D; +class Sprite3D; /** * Animate3D, Animates a Sprite3D given with an Animation3D */ @@ -61,6 +63,7 @@ public: // // Overrides // + virtual void stop() override; virtual void step(float dt) override; virtual void startWithTarget(Node *target) override; virtual Animate3D* reverse() const override; @@ -86,6 +89,13 @@ CC_CONSTRUCTOR_ACCESS: virtual ~Animate3D(); protected: + enum class Animate3DState + { + FadeIn, + FadeOut, + Running, + }; + Animate3DState _state; //animation state Animation3D* _animation; //animation data float _absSpeed; //playing speed @@ -93,7 +103,15 @@ protected: 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 - std::map _boneCurves; //weak ref + float _transTime; //transition time from one animate3d to another + float _accTransTime; // acculate transition time + float _lastTime; // last t (0 - 1) + std::unordered_map _boneCurves; //weak ref + + //sprite animates + static std::unordered_map s_fadeInAnimates; + static std::unordered_map s_fadeOutAnimates; + static std::unordered_map s_runningAnimates; }; NS_CC_END From a039d6b0fc3824025bcfce8025ad29934885cef7 Mon Sep 17 00:00:00 2001 From: yangxiao Date: Fri, 29 Aug 2014 18:25:42 +0800 Subject: [PATCH 03/20] animate3d transition --- cocos/3d/CCAnimate3D.cpp | 30 +++++++++++-------- cocos/3d/CCAnimate3D.h | 5 +++- .../Classes/Sprite3DTest/Sprite3DTest.cpp | 29 ++++++++---------- .../Classes/Sprite3DTest/Sprite3DTest.h | 4 +-- 4 files changed, 37 insertions(+), 31 deletions(-) diff --git a/cocos/3d/CCAnimate3D.cpp b/cocos/3d/CCAnimate3D.cpp index 8ebada6608..ae7afdc0b4 100644 --- a/cocos/3d/CCAnimate3D.cpp +++ b/cocos/3d/CCAnimate3D.cpp @@ -36,6 +36,7 @@ NS_CC_BEGIN std::unordered_map Animate3D::s_fadeInAnimates; std::unordered_map Animate3D::s_fadeOutAnimates; std::unordered_map Animate3D::s_runningAnimates; +float Animate3D::_transTime = 0.1f; //create Animate3D using Animation. Animate3D* Animate3D::create(Animation3D* animation) @@ -120,14 +121,20 @@ void Animate3D::startWithTarget(Node *target) { //make the running action fade out auto action = (*runningAction).second; - s_fadeOutAnimates[sprite] = action; - action->_state = Animate3D::Animate3DState::FadeOut; - action->_accTransTime = 0.0f; - - s_fadeInAnimates[sprite] = this; - _accTransTime = 0.0f; - _state = Animate3D::Animate3DState::FadeIn; - _weight = 0.f; + if (action != this) + { + s_fadeOutAnimates[sprite] = action; + action->_state = Animate3D::Animate3DState::FadeOut; + action->_accTransTime = 0.0f; + action->_weight = 1.0f; + action->_lastTime = 0.f; + + s_fadeInAnimates[sprite] = this; + _accTransTime = 0.0f; + _state = Animate3D::Animate3DState::FadeIn; + _weight = 0.f; + _lastTime = 0.f; + } } else { @@ -161,7 +168,7 @@ void Animate3D::update(float t) { if (_target) { - if (_state == Animate3D::Animate3DState::FadeIn && _accTransTime > 0.f) + if (_state == Animate3D::Animate3DState::FadeIn && _lastTime > 0.f) { _accTransTime += (t - _lastTime) * getDuration(); @@ -170,13 +177,13 @@ void Animate3D::update(float t) { _accTransTime = _transTime; _weight = 1.0f; - + _state = Animate3D::Animate3DState::Running; Sprite3D* sprite = static_cast(_target); s_fadeInAnimates.erase(sprite); s_runningAnimates[sprite] = this; } } - else if (_state == Animate3D::Animate3DState::FadeOut && _accTransTime > 0.f) + else if (_state == Animate3D::Animate3DState::FadeOut && _lastTime > 0.f) { _accTransTime += (t - _lastTime) * getDuration(); @@ -248,7 +255,6 @@ Animate3D::Animate3D() , _animation(nullptr) , _playReverse(false) , _state(Animate3D::Animate3DState::Running) -, _transTime(0.1f) , _accTransTime(0.0f) , _lastTime(0.0f) { diff --git a/cocos/3d/CCAnimate3D.h b/cocos/3d/CCAnimate3D.h index 5782e175b8..1ea5c96aa3 100644 --- a/cocos/3d/CCAnimate3D.h +++ b/cocos/3d/CCAnimate3D.h @@ -79,6 +79,9 @@ public: float getWeight() const { return _weight; } void setWeight(float weight); + /** animate transistion time */ + static float getTransitionTime() { return _transTime; } + /**get & set play reverse, these are deprecated, use set negative speed instead*/ CC_DEPRECATED_ATTRIBUTE bool getPlayBack() const { return _playReverse; } CC_DEPRECATED_ATTRIBUTE void setPlayBack(bool reverse) { _playReverse = reverse; } @@ -103,7 +106,7 @@ protected: 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 - float _transTime; //transition time from one animate3d to another + static float _transTime; //transition time from one animate3d to another float _accTransTime; // acculate transition time float _lastTime; // last t (0 - 1) std::unordered_map _boneCurves; //weak ref diff --git a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp index 1ec8d15e5d..72239dc621 100644 --- a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp +++ b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp @@ -808,7 +808,6 @@ Animate3DTest::Animate3DTest() , _swim(nullptr) , _sprite(nullptr) , _moveAction(nullptr) -, _transTime(0.1f) , _elapseTransTime(0.f) { addSprite3D(); @@ -842,28 +841,21 @@ void Animate3DTest::update(float dt) if (_state == State::HURT_TO_SWIMMING) { _elapseTransTime += dt; - float t = _elapseTransTime / _transTime; - if (t >= 1.f) + if (_elapseTransTime >= Animate3D::getTransitionTime()) { - t = 1.f; _sprite->stopAction(_hurt); _state = State::SWIMMING; } - _swim->setWeight(t); - _hurt->setWeight(1.f - t); } else if (_state == State::SWIMMING_TO_HURT) { _elapseTransTime += dt; - float t = _elapseTransTime / _transTime; - if (t >= 1.f) + if (_elapseTransTime >= Animate3D::getTransitionTime()) { - t = 1.f; + _sprite->stopAction(_swim); _state = State::HURT; } - _swim->setWeight(1.f - t); - _hurt->setWeight(t); } } @@ -880,8 +872,9 @@ void Animate3DTest::addSprite3D() if (animation) { auto animate = Animate3D::create(animation, 0.f, 1.933f); - sprite->runAction(RepeatForever::create(animate)); - _swim = animate; + _swim = RepeatForever::create(animate); + sprite->runAction(_swim); + _swim->retain(); _hurt = Animate3D::create(animation, 1.933f, 2.8f); _hurt->retain(); @@ -910,8 +903,10 @@ void Animate3DTest::reachEndCallBack() void Animate3DTest::renewCallBack() { - _sprite->stopActionByTag(101); + //rerun swim action + _sprite->runAction(_swim); _state = State::HURT_TO_SWIMMING; + _elapseTransTime = 0.0f; } void Animate3DTest::onTouchesEnded(const std::vector& touches, Event* event) @@ -928,12 +923,14 @@ void Animate3DTest::onTouchesEnded(const std::vector& touches, Event* ev //hurt the tortoise if (_state == State::SWIMMING) { + _elapseTransTime = 0.0f; + _state = State::SWIMMING_TO_HURT; + _sprite->stopAction(_hurt); _sprite->runAction(_hurt); - auto delay = DelayTime::create(_hurt->getDuration() - 0.1f); + auto delay = DelayTime::create(_hurt->getDuration() - Animate3D::getTransitionTime()); auto seq = Sequence::create(delay, CallFunc::create(CC_CALLBACK_0(Animate3DTest::renewCallBack, this)), nullptr); seq->setTag(101); _sprite->runAction(seq); - _state = State::SWIMMING_TO_HURT; } return; } diff --git a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h index b2ac350077..fcb5de6c0e 100644 --- a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h +++ b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h @@ -219,9 +219,9 @@ protected: cocos2d::Sprite3D* _sprite; - cocos2d::Animate3D* _swim; + cocos2d::Action* _swim; cocos2d::Animate3D* _hurt; - float _transTime; + float _elapseTransTime; State _state; From f3e017e139fef8f525f661a0bf77437dc7f90587 Mon Sep 17 00:00:00 2001 From: yangxiao Date: Mon, 1 Sep 2014 09:34:09 +0800 Subject: [PATCH 04/20] normalize quat --- cocos/3d/CCSkeleton3D.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/cocos/3d/CCSkeleton3D.cpp b/cocos/3d/CCSkeleton3D.cpp index 76a40eb7a0..e7b7ee4374 100644 --- a/cocos/3d/CCSkeleton3D.cpp +++ b/cocos/3d/CCSkeleton3D.cpp @@ -235,6 +235,7 @@ void Bone3D::updateLocalMat() } quat = Quaternion(it.localRot.x * weight + quat.x, it.localRot.y * weight + quat.y, it.localRot.z * weight + quat.z, it.localRot.w * weight + quat.w); } + quat.normalize(); } } From b5a3bb1c03c0474d6b60bee5ffe89df7f6529f08 Mon Sep 17 00:00:00 2001 From: yangxiao Date: Mon, 1 Sep 2014 15:07:06 +0800 Subject: [PATCH 05/20] sequence3d work --- cocos/3d/CCSequence3D.cpp | 299 ++++++++++---------------------------- cocos/3d/CCSequence3D.h | 27 ++-- 2 files changed, 88 insertions(+), 238 deletions(-) diff --git a/cocos/3d/CCSequence3D.cpp b/cocos/3d/CCSequence3D.cpp index e75d100ee5..620b76ee28 100644 --- a/cocos/3d/CCSequence3D.cpp +++ b/cocos/3d/CCSequence3D.cpp @@ -26,57 +26,6 @@ NS_CC_BEGIN -class ExtraAnimate3D : public FiniteTimeAction -{ -public: - static ExtraAnimate3D* create(); - virtual ExtraAnimate3D* clone() const; - virtual ExtraAnimate3D* reverse(void) const; - virtual void update(float time); - virtual void step(float dt); -}; - -ExtraAnimate3D* ExtraAnimate3D::create() -{ - ExtraAnimate3D* ret = new ExtraAnimate3D(); - if (ret) - { - ret->autorelease(); - } - return ret; -} -ExtraAnimate3D* ExtraAnimate3D::clone() const -{ - // no copy constructor - auto a = new ExtraAnimate3D(); - a->autorelease(); - return a; -} - -ExtraAnimate3D* ExtraAnimate3D::reverse() const -{ - return ExtraAnimate3D::create(); -} - -void ExtraAnimate3D::update(float time) -{ - CC_UNUSED_PARAM(time); -} - -void ExtraAnimate3D::step(float dt) -{ - CC_UNUSED_PARAM(dt); -} - -Sequence3D* Sequence3D::createWithTwoActions(Animate3D *actionOne, Animate3D *actionTwo) -{ - Sequence3D *sequence3d = new Sequence3D(); - sequence3d->initWithTwoActions(actionOne, actionTwo); - sequence3d->autorelease(); - - return sequence3d; -} - #if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) Sequence3D* Sequence3D::variadicCreate(Animate3D *action1, ...) { @@ -106,109 +55,106 @@ Sequence3D* Sequence3D::create(Animate3D *action1, ...) Sequence3D* Sequence3D::createWithVariableList(Animate3D *action1, va_list args) { Animate3D *now; - Animate3D *prev = action1; - bool bOneAction = true; + Vector actions; while (action1) { now = va_arg(args, Animate3D*); if (now) { - prev = (Animate3D*)createWithTwoActions(prev, now); - bOneAction = false; + actions.pushBack(now); } else - { - if (bOneAction) - { - prev = (Animate3D*)createWithTwoActions(prev, (Animate3D*)ExtraAnimate3D::create()); - } break; - } } - return ((Sequence3D*)prev); + return create(actions); } Sequence3D* Sequence3D::create(const Vector& arrayOfActions) { Sequence3D* ret = nullptr; - do + + ret = new (std::nothrow) Sequence3D(); + if (ret->initWithActions(arrayOfActions)) { - auto count = arrayOfActions.size(); - CC_BREAK_IF(count == 0); - - auto prev = arrayOfActions.at(0); - - if (count > 1) - { - for (int i = 1; i < count; ++i) - { - prev = (Animate3D*)createWithTwoActions(prev, arrayOfActions.at(i)); - } - } - else - { - prev = (Animate3D*)createWithTwoActions(prev, (Animate3D*)ExtraAnimate3D::create()); - } - ret = (Sequence3D*)prev; - }while (0); + ret->autorelease(); + return ret; + } + + CC_SAFE_RELEASE(ret); return ret; } -bool Sequence3D::initWithTwoActions(Animate3D *actionOne, Animate3D *actionTwo) +bool Sequence3D::initWithActions(const Vector& arrayOfActions) { - CCASSERT(actionOne != nullptr, ""); - CCASSERT(actionTwo != nullptr, ""); - - float d = actionOne->getDuration() + actionTwo->getDuration(); - ActionInterval::initWithDuration(d); - - _actions[0] = actionOne; - actionOne->retain(); - - _actions[1] = actionTwo; - actionTwo->retain(); - + if (arrayOfActions.size() == 0) + return false; + + _actions.clear(); + _startTime.clear(); + _endTime.clear(); + + Animate3D* preAction = nullptr; + float duration = 0.f, dur = 0.f; + _startTime.push_back(duration); + for (auto& it : arrayOfActions) { + float d1 = 0.f; + if (preAction) + d1 = preAction->getDuration(); + + float d2 = it->getDuration(); + if (d1 < Animate3D::getTransitionTime() || d2 < Animate3D::getTransitionTime()) + dur = d1 > d2 ? d1 : d2; + else + dur = d1 + d2 - Animate3D::getTransitionTime(); + + preAction = it; + _actions.pushBack(it); + _startTime.push_back(dur); + _endTime.push_back(dur); + duration += dur; + } + _startTime.erase(_startTime.end() - 1); + for (ssize_t i = 0; i < _startTime.size(); i++) { + _startTime[i] /= duration; + _endTime[i] /= duration; + } + setDuration(duration); + _curActionIdx = -1; return true; } Sequence3D* Sequence3D::clone() const { // no copy constructor - auto seq3d = new Sequence3D(); - seq3d->initWithTwoActions(_actions[0]->clone(), _actions[1]->clone() ); + auto seq3d = new (std::nothrow) Sequence3D(); + seq3d->initWithActions(_actions); seq3d->autorelease(); return seq3d; } Sequence3D::Sequence3D() -: _blendTime(0.1f) -,_blendRemain(0.1f) -,_cutAnim(false) -,cut_t(0.0f) +: _curActionIdx(-1) { } Sequence3D::~Sequence3D(void) { - CC_SAFE_RELEASE(_actions[0]); - CC_SAFE_RELEASE(_actions[1]); + _actions.clear(); } void Sequence3D::startWithTarget(Node *target) { ActionInterval::startWithTarget(target); - _split = _actions[0]->getDuration() / _duration; - _last = -1; + _curActionIdx = -1; } void Sequence3D::stop(void) { - if( _last != - 1) - { - _actions[_last]->stop(); + for (auto& action : _actions) { + action->stop(); } ActionInterval::stop(); @@ -216,131 +162,40 @@ void Sequence3D::stop(void) Sequence3D* Sequence3D::reverse() const { - return Sequence3D::createWithTwoActions(_actions[1]->reverse(), _actions[0]->reverse()); + Vector actions; + for (auto it = _actions.rbegin(); it != _actions.rend(); ++it) { + actions.pushBack(*it); + } + + return create(actions); } void Sequence3D::update(float t) { - int found = 0; - float new_t = 0.0f; - float blend_t = 0.0f; - - if( t < _split ) { - // action[0] - found = 0; - if( _split != 0 ) - new_t = t / _split; - else - new_t = 1; - - if( found != _last && found <= 0 ) - _actions[0]->startWithTarget(_target); - - _actions[0]->update(new_t); - - } - if(t >= (_split - _blendTime) && _cutAnim == false) + if (_target) { - // action[1] - - blend_t += 0.01f; - Blend(blend_t); - found = 1; - if ( _split == 1 ) - new_t = 1; - else - new_t = (t-(_split - _blendTime)) / (1 - (_split - _blendTime)); - - if( found != _last && found >= 1 ) - _actions[1]->startWithTarget(_target); - - _actions[1]->update(new_t); - } - if(_cutAnim == true) - { - blend_t += 0.01f; - Blend(blend_t); - found = 1; - if(found != _last && found >= 1) + int nextIdx = _curActionIdx + 1; + if (nextIdx < _actions.size()) { - cut_t = t; + if (t >= _startTime[nextIdx]) + { + _actions.at(nextIdx)->startWithTarget(_target); + _curActionIdx = nextIdx; + } } - if ( _split == 1 ) - new_t = 1; - else - new_t = (t - cut_t) / (1 - cut_t); - - if( found != _last && found >= 1 ) - _actions[1]->startWithTarget(_target); - - _actions[1]->update(new_t); - } - // if ( found==1 ) { - - // if( _last == -1 ) { - // // action[0] was skipped, execute it. - // _actions[0]->startWithTarget(_target); - // _actions[0]->update(1.0f); - // _actions[0]->stop(); - // } - // else if( _last == 0 ) - // { - // // switching to action 1. stop action 0. - // _actions[0]->update(1.0f); - // _actions[0]->stop(); - // } - // } - //else if(found==0 && _last==1 ) - //{ - // // Reverse mode ? - // // XXX: Bug. this case doesn't contemplate when _last==-1, found=0 and in "reverse mode" - // // since it will require a hack to know if an action is on reverse mode or not. - // // "step" should be overriden, and the "reverseMode" value propagated to inner Sequences. - // _actions[1]->update(0); - // _actions[1]->stop(); - //} - // // Last action found and it is done. - // if( found == _last && _actions[found]->isDone() ) - // { - // return; - // } - - // // Last action found and it is done - // if( found != _last ) - // { - // //_actions[found]->startWithTarget(_target); - // } - - //_actions[found]->update(new_t); - _last = found; -} - -void Sequence3D::Blend(float timeElapse) -{ - _blendRemain -= timeElapse; - bool bBlending = _blendRemain >= 0; - if (bBlending) - { - float fSrcWeight = _blendRemain / _blendTime; - _actions[0]->setWeight(fSrcWeight); - _actions[1]->setWeight(1 - fSrcWeight); - } -} - -void Sequence3D::addAnimate3D(Animate3D* animate) -{ - if(this->_duration > 0) - { - if(_actions[1]->getDuration() <= 0) + //update action + int preActionIdx = _curActionIdx - 1; + if (preActionIdx >= 0 && _endTime[preActionIdx] > t) { - _actions[1] = animate; - _cutAnim = true; - _duration += _actions[1]->getDuration(); - _split = _actions[0]->getDuration() / _duration; + float newt = (t - _startTime[preActionIdx]) / (_endTime[preActionIdx] - _startTime[preActionIdx]); + _actions.at(preActionIdx)->update(newt); + } + if (_curActionIdx >= 0 && _curActionIdx < _actions.size()) + { + float newt = (t - _startTime[_curActionIdx]) / (_endTime[_curActionIdx] - _startTime[_curActionIdx]); + _actions.at(_curActionIdx)->update(newt); } } - else - return; } NS_CC_END diff --git a/cocos/3d/CCSequence3D.h b/cocos/3d/CCSequence3D.h index e580f6179e..0e72d00391 100644 --- a/cocos/3d/CCSequence3D.h +++ b/cocos/3d/CCSequence3D.h @@ -30,7 +30,11 @@ NS_CC_BEGIN - +/** + * It is similar to Sequence in 2D action + * But it is only used to sequence Animate3D + * The difference between Sequence and Sequence3D is that Sequence3D play animation one by one and with some overlap time. We use the overlap time to make the transition between one action to another. The comming action fades in and the previous one fades out. + */ class CC_3D_DLL Sequence3D : public ActionInterval { public: @@ -65,8 +69,6 @@ public: static Sequence3D* create(const Vector& arrayOfActions); /** helper constructor to create an array of sequence-able actions */ static Sequence3D* createWithVariableList(Animate3D *action1, va_list args); - /** creates the action */ - static Sequence3D* createWithTwoActions(Animate3D *actionOne, Animate3D *actionTwo); // // Overrides @@ -76,30 +78,23 @@ public: virtual void startWithTarget(Node *target) override; virtual void stop(void) override; virtual void update(float t) override; - - void addAnimate3D(Animate3D* animate); CC_CONSTRUCTOR_ACCESS: Sequence3D(); virtual ~Sequence3D(void); - /** initializes the action */ - bool initWithTwoActions(Animate3D *pActionOne, Animate3D *pActionTwo); + /** initializes the action */ + bool initWithActions(const Vector& arrayOfActions); protected: - Animate3D* _actions[2]; - float _split; - int _last; - float _blendTime; - float _blendRemain; - bool _cutAnim; - float cut_t; + Vector _actions; + int _curActionIdx; + std::vector _startTime; + std::vector _endTime; private: CC_DISALLOW_COPY_AND_ASSIGN(Sequence3D); - void Blend(float timeElapse); - }; NS_CC_END From 97c8764ae728e1f1ee67347ddaa7858cb845804a Mon Sep 17 00:00:00 2001 From: yangxiao Date: Mon, 1 Sep 2014 15:21:47 +0800 Subject: [PATCH 06/20] remove unused header --- cocos/3d/CCAnimate3D.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/cocos/3d/CCAnimate3D.cpp b/cocos/3d/CCAnimate3D.cpp index b7d7c5dfd8..49508f005a 100644 --- a/cocos/3d/CCAnimate3D.cpp +++ b/cocos/3d/CCAnimate3D.cpp @@ -25,7 +25,6 @@ #include "3d/CCAnimate3D.h" #include "3d/CCSprite3D.h" #include "3d/CCSkeleton3D.h" -#include "3d/CCMeshSkin.h" #include "platform/CCFileUtils.h" NS_CC_BEGIN From 33005bedcbdb407979599e6bb1bbc8c7fdea5df1 Mon Sep 17 00:00:00 2001 From: yangxiao Date: Mon, 1 Sep 2014 15:32:06 +0800 Subject: [PATCH 07/20] add to cocos3d --- cocos/3d/cocos3d.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cocos/3d/cocos3d.h b/cocos/3d/cocos3d.h index fdbfef8fca..b97df23784 100755 --- a/cocos/3d/cocos3d.h +++ b/cocos/3d/cocos3d.h @@ -37,5 +37,7 @@ #include "3d/CCSprite3DMaterial.h" #include "3d/CCAttachNode.h" #include "3d/CCMeshVertexIndexData.h" +#include "3d/CCSequence3D.h" +#include "3d/CCSkeleton3D.h" #endif From 57a70b629fa628a905a4a0c2ac134e51da6f5c4b Mon Sep 17 00:00:00 2001 From: yangxiao Date: Mon, 1 Sep 2014 16:00:50 +0800 Subject: [PATCH 08/20] add sequence3d --- cocos/3d/Android.mk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cocos/3d/Android.mk b/cocos/3d/Android.mk index 0a9d859a27..ae72c67f4d 100644 --- a/cocos/3d/Android.mk +++ b/cocos/3d/Android.mk @@ -20,7 +20,8 @@ CCMeshVertexIndexData.cpp \ CCSprite3DMaterial.cpp \ CCObjLoader.cpp \ CCSkeleton3D.cpp \ -CCSprite3D.cpp +CCSprite3D.cpp \ +CCSequence3D.cpp LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/.. From c4242b4d0b637df2d297ec73315bf35ee8c5a2ad Mon Sep 17 00:00:00 2001 From: liuliang Date: Mon, 1 Sep 2014 17:45:45 +0800 Subject: [PATCH 09/20] Configure project file --- cocos/2d/libcocos2d.vcxproj | 2 ++ cocos/2d/libcocos2d.vcxproj.filters | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/cocos/2d/libcocos2d.vcxproj b/cocos/2d/libcocos2d.vcxproj index 9fdc34eb21..2e4bc274b9 100644 --- a/cocos/2d/libcocos2d.vcxproj +++ b/cocos/2d/libcocos2d.vcxproj @@ -220,6 +220,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\spine\prebuilt\release-l + @@ -557,6 +558,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\spine\prebuilt\release-l + diff --git a/cocos/2d/libcocos2d.vcxproj.filters b/cocos/2d/libcocos2d.vcxproj.filters index 1a5d9f9b25..2afb927148 100644 --- a/cocos/2d/libcocos2d.vcxproj.filters +++ b/cocos/2d/libcocos2d.vcxproj.filters @@ -1165,6 +1165,9 @@ cocosbuilder\Source Files + + 3d + @@ -2290,6 +2293,9 @@ cocosbuilder\Header Files + + 3d + From 9ce30bdabd1d896cdf76f5700ad7618a7cd27c2b Mon Sep 17 00:00:00 2001 From: yangxiao Date: Mon, 1 Sep 2014 17:52:13 +0800 Subject: [PATCH 10/20] add to linux --- cocos/3d/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/cocos/3d/CMakeLists.txt b/cocos/3d/CMakeLists.txt index 70e3560efd..5d56e92278 100644 --- a/cocos/3d/CMakeLists.txt +++ b/cocos/3d/CMakeLists.txt @@ -14,6 +14,7 @@ CCSprite3DMaterial.cpp CCObjLoader.cpp CCSkeleton3D.cpp CCSprite3D.cpp +CCSequence3D.cpp ) From d542624bfd426fce0a80ea2181043039bb07cf8b Mon Sep 17 00:00:00 2001 From: yangxiao Date: Tue, 2 Sep 2014 10:40:29 +0800 Subject: [PATCH 11/20] remove from map when release --- cocos/3d/CCAnimate3D.cpp | 26 ++++++++++++++++++-------- cocos/3d/CCAnimate3D.h | 2 ++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/cocos/3d/CCAnimate3D.cpp b/cocos/3d/CCAnimate3D.cpp index 49508f005a..7327822d20 100644 --- a/cocos/3d/CCAnimate3D.cpp +++ b/cocos/3d/CCAnimate3D.cpp @@ -142,14 +142,7 @@ void Animate3D::startWithTarget(Node *target) void Animate3D::stop() { - //remove this action from map - Sprite3D* sprite = static_cast(_target); - if (_state == Animate3D::Animate3DState::FadeIn) - s_fadeInAnimates.erase(sprite); - else if (_state == Animate3D::Animate3DState::FadeOut) - s_fadeOutAnimates.erase(sprite); - else - s_runningAnimates.erase(sprite); + removeFromMap(); ActionInterval::stop(); } @@ -258,7 +251,24 @@ Animate3D::Animate3D() } Animate3D::~Animate3D() { + removeFromMap(); + CC_SAFE_RELEASE(_animation); } +void Animate3D::removeFromMap() +{ + //remove this action from map + if (_target) + { + Sprite3D* sprite = static_cast(_target); + if (_state == Animate3D::Animate3DState::FadeIn) + s_fadeInAnimates.erase(sprite); + else if (_state == Animate3D::Animate3DState::FadeOut) + s_fadeOutAnimates.erase(sprite); + else + s_runningAnimates.erase(sprite); + } +} + NS_CC_END diff --git a/cocos/3d/CCAnimate3D.h b/cocos/3d/CCAnimate3D.h index 0e5357751e..5591e96f4b 100644 --- a/cocos/3d/CCAnimate3D.h +++ b/cocos/3d/CCAnimate3D.h @@ -87,6 +87,8 @@ CC_CONSTRUCTOR_ACCESS: Animate3D(); virtual ~Animate3D(); + void removeFromMap(); + protected: enum class Animate3DState { From 50a7a1703ac0891a28d5ab2380d5eff4155263d8 Mon Sep 17 00:00:00 2001 From: yangxiao Date: Tue, 2 Sep 2014 12:05:37 +0800 Subject: [PATCH 12/20] add sequence3d to template --- templates/cocos2dx_files.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templates/cocos2dx_files.json b/templates/cocos2dx_files.json index 25d6d414cb..872a82ea93 100644 --- a/templates/cocos2dx_files.json +++ b/templates/cocos2dx_files.json @@ -226,6 +226,8 @@ "cocos/3d/CCSprite3D.h", "cocos/3d/CCSprite3DMaterial.cpp", "cocos/3d/CCSprite3DMaterial.h", + "cocos/3d/CCSequence3D.cpp", + "cocos/3d/CCSequence3D.h", "cocos/3d/CMakeLists.txt", "cocos/3d/cocos3d.h", "cocos/Android.mk", From 49a2122e17c12c6e6229bf887be3d3535b385ede Mon Sep 17 00:00:00 2001 From: yangxiao Date: Tue, 2 Sep 2014 14:28:46 +0800 Subject: [PATCH 13/20] add sequence3d to template --- templates/cocos2dx_files.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/cocos2dx_files.json b/templates/cocos2dx_files.json index 872a82ea93..a9fc09ca33 100644 --- a/templates/cocos2dx_files.json +++ b/templates/cocos2dx_files.json @@ -220,14 +220,14 @@ "cocos/3d/CCObjLoader.h", "cocos/3d/CCRay.cpp", "cocos/3d/CCRay.h", + "cocos/3d/CCSequence3D.cpp", + "cocos/3d/CCSequence3D.h", "cocos/3d/CCSkeleton3D.cpp", "cocos/3d/CCSkeleton3D.h", "cocos/3d/CCSprite3D.cpp", "cocos/3d/CCSprite3D.h", "cocos/3d/CCSprite3DMaterial.cpp", "cocos/3d/CCSprite3DMaterial.h", - "cocos/3d/CCSequence3D.cpp", - "cocos/3d/CCSequence3D.h", "cocos/3d/CMakeLists.txt", "cocos/3d/cocos3d.h", "cocos/Android.mk", From f59f43251a6dbc8ed14b230ce5120f7fd32c99a4 Mon Sep 17 00:00:00 2001 From: yangxiao Date: Wed, 3 Sep 2014 10:38:21 +0800 Subject: [PATCH 14/20] failed to export Sequence3D::create --- tools/tolua/cocos2dx_3d.ini | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/tolua/cocos2dx_3d.ini b/tools/tolua/cocos2dx_3d.ini index a043f994f9..46bfd02ebb 100644 --- a/tools/tolua/cocos2dx_3d.ini +++ b/tools/tolua/cocos2dx_3d.ini @@ -44,7 +44,8 @@ skip = Mesh::[create getAABB], Bone3D::[*], Ray::[*], AABB::[*], - OBB::[*] + OBB::[*], + Sequence3D::[create] rename_functions = From cb96458878fd03f21fd01de9988173c63e1061f0 Mon Sep 17 00:00:00 2001 From: yangxiao Date: Wed, 3 Sep 2014 11:06:38 +0800 Subject: [PATCH 15/20] not export Sequence3D --- tools/tolua/cocos2dx_3d.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/tolua/cocos2dx_3d.ini b/tools/tolua/cocos2dx_3d.ini index 46bfd02ebb..84acecf4af 100644 --- a/tools/tolua/cocos2dx_3d.ini +++ b/tools/tolua/cocos2dx_3d.ini @@ -45,7 +45,7 @@ skip = Mesh::[create getAABB], Ray::[*], AABB::[*], OBB::[*], - Sequence3D::[create] + Sequence3D::[*] rename_functions = From 6e55a508de25e188ac807dd569451326144de9c8 Mon Sep 17 00:00:00 2001 From: yangxiao Date: Wed, 3 Sep 2014 12:08:58 +0800 Subject: [PATCH 16/20] not export Sequence3D::create --- tools/tolua/cocos2dx.ini | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/tolua/cocos2dx.ini b/tools/tolua/cocos2dx.ini index 2d59d96980..3bf763b0d6 100644 --- a/tools/tolua/cocos2dx.ini +++ b/tools/tolua/cocos2dx.ini @@ -136,7 +136,8 @@ skip = Node::[setGLServerState description getUserObject .*UserData getGLServerS Animation3DCache::[*], Sprite3DMaterialCache::[*], Sprite3DCache::[*], - Bone3D::[*] + Bone3D::[*], + Sequence3D::[create] rename_functions = SpriteFrameCache::[addSpriteFramesWithFile=addSpriteFrames getSpriteFrameByName=getSpriteFrame], ProgressTimer::[setReverseProgress=setReverseDirection], From 5fc57412859e01b20213c3c2d86e88d43658a39f Mon Sep 17 00:00:00 2001 From: yangxiao Date: Wed, 3 Sep 2014 12:44:54 +0800 Subject: [PATCH 17/20] not export Sequence3D --- tools/tolua/cocos2dx.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/tolua/cocos2dx.ini b/tools/tolua/cocos2dx.ini index 3bf763b0d6..f0a652fd88 100644 --- a/tools/tolua/cocos2dx.ini +++ b/tools/tolua/cocos2dx.ini @@ -137,7 +137,7 @@ skip = Node::[setGLServerState description getUserObject .*UserData getGLServerS Sprite3DMaterialCache::[*], Sprite3DCache::[*], Bone3D::[*], - Sequence3D::[create] + Sequence3D::[*] rename_functions = SpriteFrameCache::[addSpriteFramesWithFile=addSpriteFrames getSpriteFrameByName=getSpriteFrame], ProgressTimer::[setReverseProgress=setReverseDirection], From b88c462c8fdc4e0b9405efd462627802dabff944 Mon Sep 17 00:00:00 2001 From: yangxiao Date: Tue, 9 Sep 2014 11:34:17 +0800 Subject: [PATCH 18/20] remove Sequence3D --- build/cocos2d_libs.xcodeproj/project.pbxproj | 12 -- cocos/3d/Android.mk | 3 +- cocos/3d/CCSequence3D.cpp | 201 ------------------- cocos/3d/CCSequence3D.h | 102 ---------- cocos/3d/CMakeLists.txt | 1 - cocos/3d/cocos3d.h | 1 - tools/tolua/cocos2dx.ini | 3 +- tools/tolua/cocos2dx_3d.ini | 3 +- 8 files changed, 3 insertions(+), 323 deletions(-) delete mode 100644 cocos/3d/CCSequence3D.cpp delete mode 100644 cocos/3d/CCSequence3D.h diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj b/build/cocos2d_libs.xcodeproj/project.pbxproj index 2cd2d62c36..6f0291e781 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj @@ -1880,10 +1880,6 @@ B37510841823ACA100B3BA6A /* CCPhysicsShapeInfo_chipmunk.h in Headers */ = {isa = PBXBuildFile; fileRef = B375104D1823AC7B00B3BA6A /* CCPhysicsShapeInfo_chipmunk.h */; }; B37510851823ACA100B3BA6A /* CCPhysicsWorldInfo_chipmunk.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B375104E1823AC7B00B3BA6A /* CCPhysicsWorldInfo_chipmunk.cpp */; }; B37510861823ACA100B3BA6A /* CCPhysicsWorldInfo_chipmunk.h in Headers */ = {isa = PBXBuildFile; fileRef = B375104F1823AC7B00B3BA6A /* CCPhysicsWorldInfo_chipmunk.h */; }; - B6F7149419AEF7C8009061BD /* CCSequence3D.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B6F7149219AEF7C8009061BD /* CCSequence3D.cpp */; }; - B6F7149519AEF7C8009061BD /* CCSequence3D.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B6F7149219AEF7C8009061BD /* CCSequence3D.cpp */; }; - B6F7149619AEF7C8009061BD /* CCSequence3D.h in Headers */ = {isa = PBXBuildFile; fileRef = B6F7149319AEF7C8009061BD /* CCSequence3D.h */; }; - B6F7149719AEF7C8009061BD /* CCSequence3D.h in Headers */ = {isa = PBXBuildFile; fileRef = B6F7149319AEF7C8009061BD /* CCSequence3D.h */; }; ED9C6A9418599AD8000A5232 /* CCNodeGrid.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ED9C6A9218599AD8000A5232 /* CCNodeGrid.cpp */; }; ED9C6A9518599AD8000A5232 /* CCNodeGrid.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ED9C6A9218599AD8000A5232 /* CCNodeGrid.cpp */; }; ED9C6A9618599AD8000A5232 /* CCNodeGrid.h in Headers */ = {isa = PBXBuildFile; fileRef = ED9C6A9318599AD8000A5232 /* CCNodeGrid.h */; }; @@ -2905,8 +2901,6 @@ B375104F1823AC7B00B3BA6A /* CCPhysicsWorldInfo_chipmunk.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCPhysicsWorldInfo_chipmunk.h; sourceTree = ""; }; B3AF019E1842FBA400A98B85 /* b2MotorJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2MotorJoint.cpp; sourceTree = ""; }; B3AF019F1842FBA400A98B85 /* b2MotorJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2MotorJoint.h; sourceTree = ""; }; - B6F7149219AEF7C8009061BD /* CCSequence3D.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCSequence3D.cpp; sourceTree = ""; }; - B6F7149319AEF7C8009061BD /* CCSequence3D.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCSequence3D.h; sourceTree = ""; }; ED9C6A9218599AD8000A5232 /* CCNodeGrid.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = CCNodeGrid.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; ED9C6A9318599AD8000A5232 /* CCNodeGrid.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCNodeGrid.h; sourceTree = ""; }; /* End PBXFileReference section */ @@ -4912,8 +4906,6 @@ B29594B81926D61F003EEF37 /* 3d */ = { isa = PBXGroup; children = ( - B6F7149219AEF7C8009061BD /* CCSequence3D.cpp */, - B6F7149319AEF7C8009061BD /* CCSequence3D.h */, 15AE17E319AAD2F700C27E9E /* 3dExport.h */, 15AE17E419AAD2F700C27E9E /* CCAABB.cpp */, 15AE17E519AAD2F700C27E9E /* CCAABB.h */, @@ -5406,7 +5398,6 @@ 50ABC0031926664800A911A9 /* CCLock.h in Headers */, B37510721823AC9F00B3BA6A /* CCPhysicsBodyInfo_chipmunk.h in Headers */, 50ABBE2D1925AB6F00A911A9 /* ccCArray.h in Headers */, - B6F7149619AEF7C8009061BD /* CCSequence3D.h in Headers */, 50ABBD5E1925AB0000A911A9 /* Vec3.h in Headers */, 15AE188919AAD33D00C27E9E /* CCControlButtonLoader.h in Headers */, 15AE19EE19AAD3A700C27E9E /* spine.h in Headers */, @@ -5748,7 +5739,6 @@ 15AE1AAB19AAD40300C27E9E /* b2World.h in Headers */, 15AE19FC19AAD3A700C27E9E /* AnimationStateData.h in Headers */, 15AE180F19AAD2F700C27E9E /* CCAnimate3D.h in Headers */, - B6F7149719AEF7C8009061BD /* CCSequence3D.h in Headers */, 50ABBE341925AB6F00A911A9 /* CCConfiguration.h in Headers */, 1A570299180BCCAB0088DEC7 /* CCAnimationCache.h in Headers */, 15AE1ABF19AAD40300C27E9E /* b2PolygonContact.h in Headers */, @@ -6214,7 +6204,6 @@ 1A5701E6180BCB8C0088DEC7 /* CCTransition.cpp in Sources */, 15AE19D819AAD3A700C27E9E /* CCSkeletonAnimation.cpp in Sources */, 15AE19E819AAD3A700C27E9E /* Slot.cpp in Sources */, - B6F7149419AEF7C8009061BD /* CCSequence3D.cpp in Sources */, B24AA985195A675C007B4522 /* CCFastTMXLayer.cpp in Sources */, 15AE1A6A19AAD40300C27E9E /* b2ChainAndCircleContact.cpp in Sources */, 15AE19BE19AAD3A700C27E9E /* Event.cpp in Sources */, @@ -6674,7 +6663,6 @@ 1A5701C8180BCB5A0088DEC7 /* CCLabelTextFormatter.cpp in Sources */, 1A5701CC180BCB5A0088DEC7 /* CCLabelTTF.cpp in Sources */, 15AE193419AAD35100C27E9E /* CCActionObject.cpp in Sources */, - B6F7149519AEF7C8009061BD /* CCSequence3D.cpp in Sources */, 15AE1AD619AAD40300C27E9E /* b2WheelJoint.cpp in Sources */, 299754F5193EC95400A54AC3 /* ObjectFactory.cpp in Sources */, 1A5701DF180BCB8C0088DEC7 /* CCLayer.cpp in Sources */, diff --git a/cocos/3d/Android.mk b/cocos/3d/Android.mk index ae72c67f4d..0a9d859a27 100644 --- a/cocos/3d/Android.mk +++ b/cocos/3d/Android.mk @@ -20,8 +20,7 @@ CCMeshVertexIndexData.cpp \ CCSprite3DMaterial.cpp \ CCObjLoader.cpp \ CCSkeleton3D.cpp \ -CCSprite3D.cpp \ -CCSequence3D.cpp +CCSprite3D.cpp LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/.. diff --git a/cocos/3d/CCSequence3D.cpp b/cocos/3d/CCSequence3D.cpp deleted file mode 100644 index 620b76ee28..0000000000 --- a/cocos/3d/CCSequence3D.cpp +++ /dev/null @@ -1,201 +0,0 @@ -/**************************************************************************** - Copyright (c) 2014 Chukong Technologies Inc. - - http://www.cocos2d-x.org - - 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. - ****************************************************************************/ - -#include "3d/CCSequence3D.h" - -NS_CC_BEGIN - -#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) -Sequence3D* Sequence3D::variadicCreate(Animate3D *action1, ...) -{ - va_list params; - va_start(params, action1); - - Sequence3D *ret = Sequence3D::createWithVariableList(action1, params); - - va_end(params); - - return ret; -} -#else -Sequence3D* Sequence3D::create(Animate3D *action1, ...) -{ - va_list params; - va_start(params, action1); - - Sequence3D *ret = Sequence3D::createWithVariableList(action1, params); - - va_end(params); - - return ret; -} -#endif - -Sequence3D* Sequence3D::createWithVariableList(Animate3D *action1, va_list args) -{ - Animate3D *now; - - Vector actions; - while (action1) - { - now = va_arg(args, Animate3D*); - if (now) - { - actions.pushBack(now); - } - else - break; - } - - return create(actions); -} - -Sequence3D* Sequence3D::create(const Vector& arrayOfActions) -{ - Sequence3D* ret = nullptr; - - ret = new (std::nothrow) Sequence3D(); - if (ret->initWithActions(arrayOfActions)) - { - ret->autorelease(); - return ret; - } - - CC_SAFE_RELEASE(ret); - return ret; -} - -bool Sequence3D::initWithActions(const Vector& arrayOfActions) -{ - if (arrayOfActions.size() == 0) - return false; - - _actions.clear(); - _startTime.clear(); - _endTime.clear(); - - Animate3D* preAction = nullptr; - float duration = 0.f, dur = 0.f; - _startTime.push_back(duration); - for (auto& it : arrayOfActions) { - float d1 = 0.f; - if (preAction) - d1 = preAction->getDuration(); - - float d2 = it->getDuration(); - if (d1 < Animate3D::getTransitionTime() || d2 < Animate3D::getTransitionTime()) - dur = d1 > d2 ? d1 : d2; - else - dur = d1 + d2 - Animate3D::getTransitionTime(); - - preAction = it; - _actions.pushBack(it); - _startTime.push_back(dur); - _endTime.push_back(dur); - duration += dur; - } - _startTime.erase(_startTime.end() - 1); - for (ssize_t i = 0; i < _startTime.size(); i++) { - _startTime[i] /= duration; - _endTime[i] /= duration; - } - setDuration(duration); - _curActionIdx = -1; - return true; -} - -Sequence3D* Sequence3D::clone() const -{ - // no copy constructor - auto seq3d = new (std::nothrow) Sequence3D(); - seq3d->initWithActions(_actions); - seq3d->autorelease(); - return seq3d; -} - -Sequence3D::Sequence3D() -: _curActionIdx(-1) -{ - -} - -Sequence3D::~Sequence3D(void) -{ - _actions.clear(); -} - -void Sequence3D::startWithTarget(Node *target) -{ - ActionInterval::startWithTarget(target); - _curActionIdx = -1; -} - -void Sequence3D::stop(void) -{ - for (auto& action : _actions) { - action->stop(); - } - - ActionInterval::stop(); -} - -Sequence3D* Sequence3D::reverse() const -{ - Vector actions; - for (auto it = _actions.rbegin(); it != _actions.rend(); ++it) { - actions.pushBack(*it); - } - - return create(actions); -} - -void Sequence3D::update(float t) -{ - if (_target) - { - int nextIdx = _curActionIdx + 1; - if (nextIdx < _actions.size()) - { - if (t >= _startTime[nextIdx]) - { - _actions.at(nextIdx)->startWithTarget(_target); - _curActionIdx = nextIdx; - } - } - //update action - int preActionIdx = _curActionIdx - 1; - if (preActionIdx >= 0 && _endTime[preActionIdx] > t) - { - float newt = (t - _startTime[preActionIdx]) / (_endTime[preActionIdx] - _startTime[preActionIdx]); - _actions.at(preActionIdx)->update(newt); - } - if (_curActionIdx >= 0 && _curActionIdx < _actions.size()) - { - float newt = (t - _startTime[_curActionIdx]) / (_endTime[_curActionIdx] - _startTime[_curActionIdx]); - _actions.at(_curActionIdx)->update(newt); - } - } -} - -NS_CC_END diff --git a/cocos/3d/CCSequence3D.h b/cocos/3d/CCSequence3D.h deleted file mode 100644 index 0e72d00391..0000000000 --- a/cocos/3d/CCSequence3D.h +++ /dev/null @@ -1,102 +0,0 @@ -/**************************************************************************** - Copyright (c) 2014 Chukong Technologies Inc. - - http://www.cocos2d-x.org - - 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 __CCSEQUECE3D_H__ -#define __CCSEQUECE3D_H__ - -#include "2d/CCActionInterval.h" -#include "3d/CCAnimate3D.h" - -NS_CC_BEGIN - -/** - * It is similar to Sequence in 2D action - * But it is only used to sequence Animate3D - * The difference between Sequence and Sequence3D is that Sequence3D play animation one by one and with some overlap time. We use the overlap time to make the transition between one action to another. The comming action fades in and the previous one fades out. - */ -class CC_3D_DLL Sequence3D : public ActionInterval -{ -public: - /** helper constructor to create an array of sequenceable actions */ -#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) - // WP8 in VS2012 does not support nullptr in variable args lists and variadic templates are also not supported - typedef Animate3D* M; - static Sequence3D* create(M m1, std::nullptr_t listEnd) { return variadicCreate(m1, NULL); } - static Sequence3D* create(M m1, M m2, std::nullptr_t listEnd) { return variadicCreate(m1, m2, NULL); } - static Sequence3D* create(M m1, M m2, M m3, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, NULL); } - static Sequence3D* create(M m1, M m2, M m3, M m4, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, NULL); } - static Sequence3D* create(M m1, M m2, M m3, M m4, M m5, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, NULL); } - static Sequence3D* create(M m1, M m2, M m3, M m4, M m5, M m6, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, m6, NULL); } - static Sequence3D* create(M m1, M m2, M m3, M m4, M m5, M m6, M m7, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, m6, m7, NULL); } - static Sequence3D* create(M m1, M m2, M m3, M m4, M m5, M m6, M m7, M m8, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, m6, m7, m8, NULL); } - static Sequence3D* create(M m1, M m2, M m3, M m4, M m5, M m6, M m7, M m8, M m9, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, m6, m7, m8, m9, NULL); } - static Sequence3D* create(M m1, M m2, M m3, M m4, M m5, M m6, M m7, M m8, M m9, M m10, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, NULL); } - - // On WP8 for variable argument lists longer than 10 items, use the other create functions or variadicCreate with NULL as the last argument - static Sequence3D* variadicCreate(Animate3D* item, ...); -#else - static Sequence3D* create(Animate3D *action1, ...) CC_REQUIRES_NULL_TERMINATION; -#endif - - /** helper constructor to create an array of sequenceable actions given an array - * @code - * When this funtion bound to the js or lua,the input params changed - * in js :var create(var object1,var object2, ...) - * in lua :local create(local object1,local object2, ...) - * @endcode - */ - static Sequence3D* create(const Vector& arrayOfActions); - /** helper constructor to create an array of sequence-able actions */ - static Sequence3D* createWithVariableList(Animate3D *action1, va_list args); - - // - // Overrides - // - virtual Sequence3D* clone() const override; - virtual Sequence3D* reverse() const override; - virtual void startWithTarget(Node *target) override; - virtual void stop(void) override; - virtual void update(float t) override; - -CC_CONSTRUCTOR_ACCESS: - Sequence3D(); - virtual ~Sequence3D(void); - - /** initializes the action */ - bool initWithActions(const Vector& arrayOfActions); - -protected: - Vector _actions; - int _curActionIdx; - std::vector _startTime; - std::vector _endTime; - -private: - CC_DISALLOW_COPY_AND_ASSIGN(Sequence3D); - -}; - -NS_CC_END - -#endif // __CCSEQUECE3D_H__ diff --git a/cocos/3d/CMakeLists.txt b/cocos/3d/CMakeLists.txt index 5d56e92278..70e3560efd 100644 --- a/cocos/3d/CMakeLists.txt +++ b/cocos/3d/CMakeLists.txt @@ -14,7 +14,6 @@ CCSprite3DMaterial.cpp CCObjLoader.cpp CCSkeleton3D.cpp CCSprite3D.cpp -CCSequence3D.cpp ) diff --git a/cocos/3d/cocos3d.h b/cocos/3d/cocos3d.h index b97df23784..dbd2760feb 100755 --- a/cocos/3d/cocos3d.h +++ b/cocos/3d/cocos3d.h @@ -37,7 +37,6 @@ #include "3d/CCSprite3DMaterial.h" #include "3d/CCAttachNode.h" #include "3d/CCMeshVertexIndexData.h" -#include "3d/CCSequence3D.h" #include "3d/CCSkeleton3D.h" #endif diff --git a/tools/tolua/cocos2dx.ini b/tools/tolua/cocos2dx.ini index 832fe14fa1..d6894e123b 100644 --- a/tools/tolua/cocos2dx.ini +++ b/tools/tolua/cocos2dx.ini @@ -136,8 +136,7 @@ skip = Node::[setGLServerState description getUserObject .*UserData getGLServerS Animation3DCache::[*], Sprite3DMaterialCache::[*], Sprite3DCache::[*], - Bone3D::[*], - Sequence3D::[*] + Bone3D::[*] rename_functions = SpriteFrameCache::[addSpriteFramesWithFile=addSpriteFrames getSpriteFrameByName=getSpriteFrame], ProgressTimer::[setReverseProgress=setReverseDirection], diff --git a/tools/tolua/cocos2dx_3d.ini b/tools/tolua/cocos2dx_3d.ini index 84acecf4af..a043f994f9 100644 --- a/tools/tolua/cocos2dx_3d.ini +++ b/tools/tolua/cocos2dx_3d.ini @@ -44,8 +44,7 @@ skip = Mesh::[create getAABB], Bone3D::[*], Ray::[*], AABB::[*], - OBB::[*], - Sequence3D::[*] + OBB::[*] rename_functions = From a6337a3c56cde21f4fa070f287ab08b13d8548d4 Mon Sep 17 00:00:00 2001 From: yangxiao Date: Tue, 9 Sep 2014 13:20:33 +0800 Subject: [PATCH 19/20] remove sequence3d --- templates/cocos2dx_files.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/templates/cocos2dx_files.json b/templates/cocos2dx_files.json index cbadcebbae..8371a753c1 100644 --- a/templates/cocos2dx_files.json +++ b/templates/cocos2dx_files.json @@ -220,8 +220,6 @@ "cocos/3d/CCObjLoader.h", "cocos/3d/CCRay.cpp", "cocos/3d/CCRay.h", - "cocos/3d/CCSequence3D.cpp", - "cocos/3d/CCSequence3D.h", "cocos/3d/CCSkeleton3D.cpp", "cocos/3d/CCSkeleton3D.h", "cocos/3d/CCSprite3D.cpp", From be72d5730ce4fd2b4d82f492b06e7522f13be29b Mon Sep 17 00:00:00 2001 From: liuliang Date: Tue, 9 Sep 2014 14:03:27 +0800 Subject: [PATCH 20/20] Modify the environment configuration --- cocos/2d/libcocos2d.vcxproj | 2 -- cocos/2d/libcocos2d.vcxproj.filters | 6 ------ 2 files changed, 8 deletions(-) diff --git a/cocos/2d/libcocos2d.vcxproj b/cocos/2d/libcocos2d.vcxproj index 9a32708130..8c7eaf7504 100644 --- a/cocos/2d/libcocos2d.vcxproj +++ b/cocos/2d/libcocos2d.vcxproj @@ -213,7 +213,6 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\chipmunk\prebuilt\releas - @@ -550,7 +549,6 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\chipmunk\prebuilt\releas - diff --git a/cocos/2d/libcocos2d.vcxproj.filters b/cocos/2d/libcocos2d.vcxproj.filters index 7f9653ac6f..71ff22990a 100644 --- a/cocos/2d/libcocos2d.vcxproj.filters +++ b/cocos/2d/libcocos2d.vcxproj.filters @@ -1123,9 +1123,6 @@ cocosbuilder\Source Files - - 3d - ui\UIWidgets\EditBox @@ -2245,9 +2242,6 @@ cocosbuilder\Header Files - - 3d - ui\UIWidgets\EditBox