axmol/cocos/editor-support/cocostudio/CCArmature.cpp

739 lines
18 KiB
C++
Raw Normal View History

2013-06-06 12:02:54 +08:00
/****************************************************************************
2016-08-05 09:42:15 +08:00
Copyright (c) 2013-2016 Chukong Technologies Inc.
2013-06-06 12:02:54 +08:00
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 "editor-support/cocostudio/CCArmature.h"
#include "editor-support/cocostudio/CCArmatureDataManager.h"
#include "editor-support/cocostudio/CCArmatureDefine.h"
#include "editor-support/cocostudio/CCDataReaderHelper.h"
#include "editor-support/cocostudio/CCDatas.h"
#include "editor-support/cocostudio/CCSkin.h"
2014-04-30 08:37:36 +08:00
#include "renderer/CCRenderer.h"
#include "renderer/CCGroupCommand.h"
2014-05-10 09:39:25 +08:00
#include "renderer/CCGLProgramState.h"
Squashed commit of the following: commit c16dcfaaea0922039aad05bce1f4efed18e04871 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 30 19:05:18 2014 -0700 more linux fixes commit 1553795976c9090a1b46deb53d12910fe0676008 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 30 19:04:04 2014 -0700 more linux fixes commit 1e43a8cabff33cbf25aa5eb5412f53a878222d83 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 30 19:02:07 2014 -0700 fixes linux isuses commit 723a445dd6411f91846da2b801248ad8298174f1 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 30 18:58:50 2014 -0700 more linux fixes commit 533c8025e794fc76cef02f396b3a93b3d7f4cfc8 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 30 18:57:33 2014 -0700 more linux fixes commit 4ba1e84959670bcbf044f18d1c0d4b3cb3be4090 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 30 18:53:43 2014 -0700 more linux fixes commit 1f8e011f306a47ed4134224e5e349929201f0539 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 30 18:49:28 2014 -0700 more linux fixes commit 3e2033100822ff6d532a1b4f012337491dc11920 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 30 18:47:43 2014 -0700 more linux fixes commit 2e708863c75fd032f1b2396dfdf1d31f7a62b713 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 30 18:46:00 2014 -0700 more linux fixes commit 861b5b92a6efd4de7b926c20d636ce9d749b293f Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 30 18:43:15 2014 -0700 more linux fixes commit 2a43365a0c1755e9b9cada53301be1a20adb31cf Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 30 18:36:06 2014 -0700 more fixes for linux commit 7d332bf911892f87c7824d2a5da7bf73ce7ec411 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 30 18:35:29 2014 -0700 more fixes for linux commit f1becc17d3316dfe3678c23c9dcedb7a447d9235 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 30 18:34:44 2014 -0700 more fixes for linux commit d2e5959bb0dde921dd5e73be1d8acc3b3f50e51d Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 30 18:33:45 2014 -0700 fixes for linux commit ad9b633c352107cf0e8b060a0e23d6e6a3f5e80f Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 30 18:16:48 2014 -0700 compiles on Windows commit 4425ee8e5de8f42a2d6050e4470109600dce8b5d Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 30 18:07:20 2014 -0700 fix builder
2014-05-01 10:09:13 +08:00
#include "2d/CCDrawingPrimitives.h"
2014-04-30 08:37:36 +08:00
#include "base/CCDirector.h"
2013-06-06 12:02:54 +08:00
2013-09-13 18:07:37 +08:00
#if ENABLE_PHYSICS_BOX2D_DETECT
#include "Box2D/Box2D.h"
#elif ENABLE_PHYSICS_CHIPMUNK_DETECT
Squashed commit of the following: commit 36c2807d07848448c1fed86f4b119205048691bf Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Feb 29 13:11:40 2016 -0800 binary file 82 commit 9b7cd003b12faefd0522d12f765c027efb001ab2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Feb 29 12:56:39 2016 -0800 fore multiple in windows phone 8.1 too commit daea8a3ef8d69915e7a9d962fd745a1103011bab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Feb 29 12:50:45 2016 -0800 force multiple commit 0fbabdbf99974e95de083d79c7d6ae7cf735e4b6 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Feb 29 10:44:40 2016 -0800 compiles commit f817766afcd0ffc4ca93f628d55fabc4b5a96ba5 Merge: 7b2cea3 8bf3d33 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Feb 29 09:37:24 2016 -0800 Merge branch 'v3' into chipmunk_v7_2 commit 7b2cea329a56ae2786428d39a499bc12ba3860e6 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sat Feb 27 01:11:13 2016 -0800 correct paths for win8.1 commit dcf1f046eb1e18474d6f94b2d7dc31fbf1b06cea Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 26 22:46:58 2016 -0800 projects works on win32 commit ab5b14c25ef0fdf224480302f9cb3cc01d5c360c Merge: 04377cc 9af2f4e Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 26 21:57:10 2016 -0800 Merge branch 'v3' into chipmunk_v7_2 commit 04377cce7f46b2c2016ccc3855fc479c4f6aa516 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 26 21:26:55 2016 -0800 trying to make it compile on win32 commit 7703946d99e1cdc6a57f2ccb2a868818c1367291 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Feb 24 10:28:12 2016 -0800 quick hack to make it compile... ...autogenerated files will fix it. commit ea35bf3a5894cb80b09ecd0a4a5408dcc19785f5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Feb 24 09:20:59 2016 -0800 Squashed commit of the following: commit 487e52a7af7cdb40135fd3bd83b2efba0dfe6265 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 23 20:10:13 2016 -0800 compiles.. sort of commit a7990e2888d5ef1e43b811148b23c0b899105ab3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 23 19:55:24 2016 -0800 more chipmunk fixes commit 1174f6ec8201324161d7946af0f493b136a56690 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 23 19:36:15 2016 -0800 more chipmunk fixes commit 00ac2449ca0c35bd9184310d58e74aaa05bd1323 Merge: f942c5a 0594d3c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 23 19:29:27 2016 -0800 Merge branch 'chipmunk_v7_squashed' of github.com:ricardoquesada/cocos2d-x into chipmunk_v7_squashed commit f942c5a3cc7b24f3ac211d781be1b9c9d4ec0fd7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 23 19:28:51 2016 -0800 correct path for chipmunk commit 0594d3c4141d390b2566ea76101e383f15ebcaaf Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 23 18:44:05 2016 -0800 compiles on ios commit 379503399c384ad77d25d68a2f83b71a829b1c04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 23 17:51:36 2016 -0800 chipmunk include fixes commit 95839fb7b406a32255853294b016d8c15aec1ed6 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 23 17:09:04 2016 -0800 fixes for cmake + mac commit 39449ea3b7efccae2946785c1c11433d964ee480 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 23 16:51:25 2016 -0800 correct includes commit 98e97d7d2f00e6a78d040dcaf17e5a077e9a88c3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 23 16:35:40 2016 -0800 fixes chipmunk with cmake commit 337f21f9466703722847635301d841ace9b757cb Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 23 14:42:01 2016 -0800 updates android and linux projects commit 7111a9993b97f78cf73206804b25665c21a59ca8 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 23 14:18:26 2016 -0800 cosmetic changes commit ce15038b8d2c0c7ebe31b4e1efe92646b7c70d1b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 23 06:53:41 2016 -0800 chipmunk autogenerated files commit 66c71bfa3aaab04abf25f284e2e76ce2a74a98de Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 23 06:47:41 2016 -0800 compatibility both in JS (to reduce space) and in C for (C++ users) commit 0f9ffa0a8ab23a19e1f10b04e6987c2288764b1f Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 23 06:10:02 2016 -0800 mooooore fixes commit 9ab23014093677e8eda69b105f50410b8c792aa3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 23 05:30:58 2016 -0800 doesn't crash with collision handler commit 69275a16817a038244bbaaff9e82a011b6729cb2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 23 05:16:29 2016 -0800 adds missing space functions commit a6b97bbc76cb9ab293356bb7451cfa858353f589 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Feb 22 22:22:27 2016 -0800 queries... better commit 3442bceca64f5a0ddbbbb1a288146a2a61d87632 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Feb 22 19:48:41 2016 -0800 adds more missing functions fixes other chipmunk JS issues commit 3797a033896d059da58a05ce0de832ed9c150eff Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Feb 22 18:30:21 2016 -0800 yep... poly works ok commit d1bb57776891605b9d3e4fb90736c6869d96b944 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Feb 22 17:28:29 2016 -0800 neede compat files commit 39ec518d4e089124d9a53fe3a8dce3aa0474c233 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Feb 22 17:28:04 2016 -0800 query working! commit 71a8001fd6bc03ac674621f5da38a3f8778430b4 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 19 21:57:03 2016 -0800 almost there commit 9272fdcd06ba188db2fe5701fb2ac21476d54883 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 19 21:18:46 2016 -0800 fixes return values commit 7218778da846e1e36a510c0a19a5ee76f91db032 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 19 20:36:14 2016 -0800 cpMomentForSegment is manual since parameter 4 is optional in chipmunk 6, but not in 7 commit 98d5d3e23c2cdb941cc0b1f3ce8275990356e88d Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 19 17:29:28 2016 -0800 yeah... process the arguments correctly works both for functions and auto_classes commit ce6a4fe3593b4f3b0fcdf11d12e297d789e0d96b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 19 16:49:00 2016 -0800 compiles and links fixes some issues with the queries. returns shapes instad of the queryInfo commit 3f879482dc6db86e45e4319bc802ccf19b52a46c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 19 15:03:18 2016 -0800 adds removeCollisionHandler and other fixes commit 32d825fc7bd323e144db6a1badc4a62420b6ea44 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 18 20:59:24 2016 -0800 compiles... doesn't work yet commit bd64de81713fb2d7652a538d667d73f05f5d9320 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Feb 17 18:17:39 2016 -0800 WIP: chipmunk bindings
2016-03-01 05:53:00 +08:00
#include "chipmunk/chipmunk.h"
2013-09-13 18:07:37 +08:00
#endif
2013-06-06 12:02:54 +08:00
using namespace cocos2d;
2013-06-07 10:52:32 +08:00
namespace cocostudio {
2013-06-07 10:52:32 +08:00
Armature *Armature::create()
2013-06-06 12:02:54 +08:00
{
Armature *armature = new (std::nothrow) Armature();
2013-06-06 12:02:54 +08:00
if (armature && armature->init())
{
armature->autorelease();
return armature;
}
CC_SAFE_DELETE(armature);
return nullptr;
2013-06-06 12:02:54 +08:00
}
2013-06-07 10:52:32 +08:00
Armature *Armature::create(const std::string& name)
2013-06-06 12:02:54 +08:00
{
Armature *armature = new (std::nothrow) Armature();
2013-09-13 18:07:37 +08:00
if (armature && armature->init(name))
2013-06-06 12:02:54 +08:00
{
armature->autorelease();
return armature;
}
CC_SAFE_DELETE(armature);
return nullptr;
2013-06-06 12:02:54 +08:00
}
Armature *Armature::create(const std::string& name, Bone *parentBone)
2013-06-06 12:02:54 +08:00
{
Armature *armature = new (std::nothrow) Armature();
2013-06-07 10:52:32 +08:00
if (armature && armature->init(name, parentBone))
{
armature->autorelease();
return armature;
}
CC_SAFE_DELETE(armature);
return nullptr;
2013-06-06 12:02:54 +08:00
}
Armature::Armature()
: _armatureData(nullptr)
, _batchNode(nullptr)
, _parentBone(nullptr)
2013-09-15 20:24:25 +08:00
, _armatureTransformDirty(true)
, _animation(nullptr)
2013-06-06 12:02:54 +08:00
{
}
Armature::~Armature(void)
2013-06-06 12:02:54 +08:00
{
_boneDic.clear();
_topBoneList.clear();
CC_SAFE_DELETE(_animation);
2013-06-06 12:02:54 +08:00
}
2013-06-07 10:52:32 +08:00
bool Armature::init()
2013-06-06 12:02:54 +08:00
{
2014-01-07 20:53:44 +08:00
return init("");
2013-06-06 12:02:54 +08:00
}
bool Armature::init(const std::string& name)
2013-06-06 12:02:54 +08:00
{
bool bRet = false;
do
{
2013-06-07 10:52:32 +08:00
removeAllChildren();
2013-06-06 12:02:54 +08:00
CC_SAFE_DELETE(_animation);
_animation = new (std::nothrow) ArmatureAnimation();
_animation->init(this);
2013-06-06 12:02:54 +08:00
_boneDic.clear();
_topBoneList.clear();
2013-06-06 12:02:54 +08:00
2014-07-23 20:07:33 +08:00
_blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
2013-06-07 10:52:32 +08:00
_name = name;
2013-06-06 12:02:54 +08:00
ArmatureDataManager *armatureDataManager = ArmatureDataManager::getInstance();
2013-06-07 10:52:32 +08:00
2013-12-24 11:05:53 +08:00
if(!_name.empty())
2013-06-06 12:02:54 +08:00
{
AnimationData *animationData = armatureDataManager->getAnimationData(name);
2013-09-16 12:02:57 +08:00
CCASSERT(animationData, "AnimationData not exist! ");
2013-06-07 10:52:32 +08:00
_animation->setAnimationData(animationData);
2013-06-07 10:52:32 +08:00
ArmatureData *armatureData = armatureDataManager->getArmatureData(name);
CCASSERT(armatureData, "armatureData doesn't exists!");
2013-06-07 10:52:32 +08:00
_armatureData = armatureData;
2013-06-07 10:52:32 +08:00
2013-12-18 22:07:33 +08:00
for (auto& element : armatureData->boneDataDic)
2013-06-06 12:02:54 +08:00
{
Bone *bone = createBone(element.first);
2013-06-07 10:52:32 +08:00
//! init bone's Tween to 1st movement's 1st frame
2013-06-07 10:52:32 +08:00
do
{
MovementData *movData = animationData->getMovement(animationData->movementNames.at(0));
2013-06-06 12:02:54 +08:00
CC_BREAK_IF(!movData);
2013-06-07 10:52:32 +08:00
MovementBoneData *movBoneData = movData->getMovementBoneData(bone->getName());
2013-12-13 19:40:38 +08:00
CC_BREAK_IF(!movBoneData || movBoneData->frameList.size() <= 0);
2013-06-07 10:52:32 +08:00
FrameData *frameData = movBoneData->getFrameData(0);
2013-06-06 12:02:54 +08:00
CC_BREAK_IF(!frameData);
2013-06-07 10:52:32 +08:00
2013-06-06 12:02:54 +08:00
bone->getTweenData()->copy(frameData);
2014-01-02 11:07:31 +08:00
bone->changeDisplayWithIndex(frameData->displayIndex, false);
2013-06-07 10:52:32 +08:00
}
while (0);
}
update(0);
updateOffsetPoint();
2013-06-06 12:02:54 +08:00
}
else
{
_name = "new_armature";
_armatureData = ArmatureData::create();
_armatureData->name = _name;
2013-06-07 10:52:32 +08:00
AnimationData *animationData = AnimationData::create();
animationData->name = _name;
2013-06-07 10:52:32 +08:00
armatureDataManager->addArmatureData(_name, _armatureData);
armatureDataManager->addAnimationData(_name, animationData);
2013-06-07 10:52:32 +08:00
_animation->setAnimationData(animationData);
2013-06-07 10:52:32 +08:00
2013-06-06 12:02:54 +08:00
}
setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR));
2013-06-06 12:02:54 +08:00
2013-06-07 10:52:32 +08:00
setCascadeOpacityEnabled(true);
setCascadeColorEnabled(true);
2013-06-06 12:02:54 +08:00
bRet = true;
}
while (0);
return bRet;
}
bool Armature::init(const std::string& name, Bone *parentBone)
2013-06-06 12:02:54 +08:00
{
_parentBone = parentBone;
2013-06-07 10:52:32 +08:00
return init(name);
2013-06-06 12:02:54 +08:00
}
Bone *Armature::createBone(const std::string& boneName)
2013-06-06 12:02:54 +08:00
{
Bone *existedBone = getBone(boneName);
if(existedBone != nullptr)
2013-06-07 10:52:32 +08:00
return existedBone;
BoneData *boneData = (BoneData *)_armatureData->getBoneData(boneName);
2013-06-07 10:52:32 +08:00
std::string parentName = boneData->parentName;
2013-06-06 12:02:54 +08:00
Bone *bone = nullptr;
2013-06-07 10:52:32 +08:00
if( !parentName.empty())
2013-06-06 12:02:54 +08:00
{
createBone(parentName);
bone = Bone::create(boneName);
addBone(bone, parentName);
2013-06-07 10:52:32 +08:00
}
else
{
bone = Bone::create(boneName);
2013-06-06 12:02:54 +08:00
addBone(bone, "");
}
2013-06-07 10:52:32 +08:00
2013-06-06 12:02:54 +08:00
bone->setBoneData(boneData);
2014-01-02 11:07:31 +08:00
bone->getDisplayManager()->changeDisplayWithIndex(-1, false);
2013-06-07 10:52:32 +08:00
2013-06-06 12:02:54 +08:00
return bone;
}
void Armature::addBone(Bone *bone, const std::string& parentName)
2013-06-06 12:02:54 +08:00
{
CCASSERT( bone != nullptr, "Argument must be non-nil");
CCASSERT(_boneDic.at(bone->getName()) == nullptr, "bone already added. It can't be added again");
2013-06-06 12:02:54 +08:00
2013-12-24 11:05:53 +08:00
if (!parentName.empty())
2013-06-06 12:02:54 +08:00
{
Bone *boneParent = _boneDic.at(parentName);
2013-06-06 12:02:54 +08:00
if (boneParent)
2013-06-07 10:52:32 +08:00
{
boneParent->addChildBone(bone);
}
else
{
_topBoneList.pushBack(bone);
2013-06-07 10:52:32 +08:00
}
2013-06-06 12:02:54 +08:00
}
2013-06-07 10:52:32 +08:00
else
{
_topBoneList.pushBack(bone);
2013-06-07 10:52:32 +08:00
}
2013-06-06 12:02:54 +08:00
bone->setArmature(this);
2013-06-07 10:52:32 +08:00
_boneDic.insert(bone->getName(), bone);
2013-06-06 12:02:54 +08:00
addChild(bone);
}
void Armature::removeBone(Bone *bone, bool recursion)
2013-06-06 12:02:54 +08:00
{
CCASSERT(bone != nullptr, "bone must be added to the bone dictionary!");
2013-06-07 10:52:32 +08:00
bone->setArmature(nullptr);
2013-06-06 12:02:54 +08:00
bone->removeFromParent(recursion);
2013-06-07 10:52:32 +08:00
if (_topBoneList.contains(bone))
2013-06-07 10:52:32 +08:00
{
_topBoneList.eraseObject(bone);
2013-06-07 10:52:32 +08:00
}
_boneDic.erase(bone->getName());
removeChild(bone, true);
2013-06-06 12:02:54 +08:00
}
Bone *Armature::getBone(const std::string& name) const
2013-06-06 12:02:54 +08:00
{
return _boneDic.at(name);
2013-06-06 12:02:54 +08:00
}
void Armature::changeBoneParent(Bone *bone, const std::string& parentName)
2013-06-06 12:02:54 +08:00
{
CCASSERT(bone != nullptr, "bone must be added to the bone dictionary!");
2013-06-06 12:02:54 +08:00
2013-09-13 18:07:37 +08:00
if(bone->getParentBone())
{
bone->getParentBone()->getChildren().eraseObject(bone);
bone->setParentBone(nullptr);
2013-09-13 18:07:37 +08:00
}
2013-06-06 12:02:54 +08:00
2013-12-24 11:05:53 +08:00
if (!parentName.empty())
2013-06-07 10:52:32 +08:00
{
Bone *boneParent = _boneDic.at(parentName);
2013-06-06 12:02:54 +08:00
2013-06-07 10:52:32 +08:00
if (boneParent)
{
boneParent->addChildBone(bone);
if (_topBoneList.contains(bone))
2013-09-13 18:07:37 +08:00
{
_topBoneList.eraseObject(bone);
2013-09-13 18:07:37 +08:00
}
}
else
{
_topBoneList.pushBack(bone);
2013-06-07 10:52:32 +08:00
}
}
2013-06-06 12:02:54 +08:00
}
const cocos2d::Map<std::string, Bone*>& Armature::getBoneDic() const
2013-06-06 12:02:54 +08:00
{
return _boneDic;
2013-06-06 12:02:54 +08:00
}
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
const Mat4& Armature::getNodeToParentTransform() const
2013-06-06 12:02:54 +08:00
{
if (_transformDirty)
2013-09-15 20:24:25 +08:00
_armatureTransformDirty = true;
2013-09-13 18:07:37 +08:00
return Node::getNodeToParentTransform();
2013-06-06 12:02:54 +08:00
}
2013-06-07 10:52:32 +08:00
void Armature::updateOffsetPoint()
2013-06-06 12:02:54 +08:00
{
2013-06-07 10:52:32 +08:00
// Set contentsize and Calculate anchor point.
Rect rect = getBoundingBox();
2013-06-07 10:52:32 +08:00
setContentSize(rect.size);
_offsetPoint.set(-rect.origin.x, -rect.origin.y);
2013-09-13 18:07:37 +08:00
if (rect.size.width != 0 && rect.size.height != 0)
{
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
setAnchorPoint(Vec2(_offsetPoint.x / rect.size.width, _offsetPoint.y / rect.size.height));
2013-09-13 18:07:37 +08:00
}
2013-06-06 12:02:54 +08:00
}
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
void Armature::setAnchorPoint(const Vec2& point)
2013-12-19 15:43:32 +08:00
{
if( ! point.equals(_anchorPoint))
{
_anchorPoint = point;
_anchorPointInPoints.set(_contentSize.width * _anchorPoint.x - _offsetPoint.x, _contentSize.height * _anchorPoint.y - _offsetPoint.y);
_realAnchorPointInPoints.set(_contentSize.width * _anchorPoint.x, _contentSize.height * _anchorPoint.y);
2013-12-19 15:43:32 +08:00
_transformDirty = _inverseDirty = true;
}
}
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
const Vec2& Armature::getAnchorPointInPoints() const
2013-12-19 15:43:32 +08:00
{
return _realAnchorPointInPoints;
}
const Vec2& Armature::getOffsetPoints() const
{
2014-09-24 15:14:47 +08:00
return _offsetPoint;
}
void Armature::setAnimation(ArmatureAnimation *animation)
2013-09-13 18:07:37 +08:00
{
2013-09-15 20:24:25 +08:00
_animation = animation;
2013-06-06 12:02:54 +08:00
}
2013-11-05 19:53:38 +08:00
ArmatureAnimation *Armature::getAnimation() const
2013-06-06 12:02:54 +08:00
{
2013-09-15 20:24:25 +08:00
return _animation;
2013-09-13 18:07:37 +08:00
}
2013-06-06 12:02:54 +08:00
2013-11-05 19:53:38 +08:00
bool Armature::getArmatureTransformDirty() const
2013-06-06 12:02:54 +08:00
{
2013-09-15 20:24:25 +08:00
return _armatureTransformDirty;
}
2013-06-06 12:02:54 +08:00
void Armature::update(float dt)
2013-06-06 12:02:54 +08:00
{
_animation->update(dt);
2013-06-06 12:02:54 +08:00
for(const auto &bone : _topBoneList) {
2013-12-18 22:07:33 +08:00
bone->update(dt);
}
2013-09-13 18:07:37 +08:00
2013-09-15 20:24:25 +08:00
_armatureTransformDirty = false;
2013-06-06 12:02:54 +08:00
}
void Armature::draw(cocos2d::Renderer *renderer, const Mat4 &transform, uint32_t flags)
2013-06-06 12:02:54 +08:00
{
if (_parentBone == nullptr && _batchNode == nullptr)
2013-06-07 10:52:32 +08:00
{
// CC_NODE_DRAW_SETUP();
2013-06-07 10:52:32 +08:00
}
2013-12-17 17:00:01 +08:00
2013-12-18 22:07:33 +08:00
for (auto& object : _children)
2013-06-07 10:52:32 +08:00
{
if (Bone *bone = dynamic_cast<Bone *>(object))
2013-09-13 18:07:37 +08:00
{
2013-10-30 09:41:40 +08:00
Node *node = bone->getDisplayRenderNode();
2013-06-07 10:52:32 +08:00
if (nullptr == node)
2013-09-13 18:07:37 +08:00
continue;
2013-06-07 10:52:32 +08:00
2013-10-30 09:41:40 +08:00
switch (bone->getDisplayRenderNodeType())
2013-06-07 10:52:32 +08:00
{
2013-09-13 18:07:37 +08:00
case CS_DISPLAY_SPRITE:
2013-06-07 10:52:32 +08:00
{
2013-09-16 12:21:18 +08:00
Skin *skin = static_cast<Skin *>(node);
2013-09-13 18:07:37 +08:00
skin->updateTransform();
2013-12-17 17:00:01 +08:00
2014-07-09 14:25:51 +08:00
BlendFunc func = bone->getBlendFunc();
2013-12-17 17:00:01 +08:00
2014-07-23 20:07:33 +08:00
if (func.src != BlendFunc::ALPHA_PREMULTIPLIED.src || func.dst != BlendFunc::ALPHA_PREMULTIPLIED.dst)
2013-06-07 10:52:32 +08:00
{
skin->setBlendFunc(bone->getBlendFunc());
2013-06-07 10:52:32 +08:00
}
else
{
2014-07-23 21:35:08 +08:00
if (_blendFunc == BlendFunc::ALPHA_PREMULTIPLIED && !skin->getTexture()->hasPremultipliedAlpha())
2014-07-23 20:07:33 +08:00
{
2014-07-23 21:35:08 +08:00
skin->setBlendFunc(_blendFunc.ALPHA_NON_PREMULTIPLIED);
}
else
{
skin->setBlendFunc(_blendFunc);
2014-07-23 20:07:33 +08:00
}
}
skin->draw(renderer, transform, flags);
2013-06-07 10:52:32 +08:00
}
2013-09-13 18:07:37 +08:00
break;
case CS_DISPLAY_ARMATURE:
2013-06-07 10:52:32 +08:00
{
node->draw(renderer, transform, flags);
2013-09-13 18:07:37 +08:00
}
break;
default:
2013-06-07 10:52:32 +08:00
{
node->visit(renderer, transform, flags);
// CC_NODE_DRAW_SETUP();
2013-09-13 18:07:37 +08:00
}
break;
2013-06-07 10:52:32 +08:00
}
}
2013-09-13 18:07:37 +08:00
else if(Node *node = dynamic_cast<Node *>(object))
2013-06-07 10:52:32 +08:00
{
node->visit(renderer, transform, flags);
// CC_NODE_DRAW_SETUP();
2013-06-07 10:52:32 +08:00
}
}
2013-06-06 12:02:54 +08:00
}
2013-12-26 15:49:20 +08:00
void Armature::onEnter()
{
#if CC_ENABLE_SCRIPT_BINDING
if (_scriptType == kScriptTypeJavascript)
{
if (ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnEnter))
return;
}
#endif
2013-12-26 15:49:20 +08:00
Node::onEnter();
scheduleUpdate();
}
void Armature::onExit()
{
#if CC_ENABLE_SCRIPT_BINDING
if (_scriptType == kScriptTypeJavascript)
{
if (ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnExit))
return;
}
#endif
2013-12-26 15:49:20 +08:00
Node::onExit();
unscheduleUpdate();
}
2013-09-13 18:07:37 +08:00
void Armature::visit(cocos2d::Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags)
2013-06-06 12:02:54 +08:00
{
2013-06-07 10:52:32 +08:00
// quick return if not visible. children won't be drawn.
if (!_visible)
2013-06-07 10:52:32 +08:00
{
return;
}
uint32_t flags = processParentFlags(parentTransform, parentFlags);
if (isVisitableByVisitingCamera())
{
// IMPORTANT:
// To ease the migration to v3.0, we still support the Mat4 stack,
// but it is deprecated and your code should not rely on it
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when setting matrix stack");
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform);
sortAllChildren();
draw(renderer, _modelViewTransform, flags);
// FIX ME: Why need to set _orderOfArrival to 0??
// Please refer to https://github.com/cocos2d/cocos2d-x/pull/6920
// setOrderOfArrival(0);
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
}
2013-06-06 12:02:54 +08:00
}
Rect Armature::getBoundingBox() const
2013-06-06 12:02:54 +08:00
{
2013-06-07 10:52:32 +08:00
float minx, miny, maxx, maxy = 0;
bool first = true;
Rect boundingBox = Rect(0, 0, 0, 0);
2013-06-07 10:52:32 +08:00
for (const auto& object : _children)
2013-06-07 10:52:32 +08:00
{
if (Bone *bone = dynamic_cast<Bone *>(object))
2013-06-07 10:52:32 +08:00
{
2013-09-13 18:07:37 +08:00
Rect r = bone->getDisplayManager()->getBoundingBox();
if (r.equals(Rect::ZERO))
continue;
2013-06-07 10:52:32 +08:00
2013-09-13 18:07:37 +08:00
if(first)
{
minx = r.getMinX();
miny = r.getMinY();
maxx = r.getMaxX();
maxy = r.getMaxY();
2013-06-07 10:52:32 +08:00
2013-09-13 18:07:37 +08:00
first = false;
}
else
{
minx = r.getMinX() < boundingBox.getMinX() ? r.getMinX() : boundingBox.getMinX();
miny = r.getMinY() < boundingBox.getMinY() ? r.getMinY() : boundingBox.getMinY();
maxx = r.getMaxX() > boundingBox.getMaxX() ? r.getMaxX() : boundingBox.getMaxX();
maxy = r.getMaxY() > boundingBox.getMaxY() ? r.getMaxY() : boundingBox.getMaxY();
}
boundingBox.setRect(minx, miny, maxx - minx, maxy - miny);
}
2013-12-18 22:07:33 +08:00
}
2013-06-07 10:52:32 +08:00
2013-12-11 03:07:15 +08:00
return RectApplyTransform(boundingBox, getNodeToParentTransform());
2013-06-06 12:02:54 +08:00
}
2013-11-05 19:53:38 +08:00
Bone *Armature::getBoneAtPoint(float x, float y) const
2013-06-06 12:02:54 +08:00
{
long length = _children.size();
Bone *bs;
2013-06-07 10:52:32 +08:00
for(long i = length - 1; i >= 0; i--)
2013-06-06 12:02:54 +08:00
{
bs = static_cast<Bone*>( _children.at(i) );
if(bs->getDisplayManager()->containPoint(x, y))
2013-06-06 12:02:54 +08:00
{
return bs;
2013-06-06 12:02:54 +08:00
}
2013-06-07 10:52:32 +08:00
}
return nullptr;
2013-06-06 12:02:54 +08:00
}
2013-10-30 09:41:40 +08:00
void Armature::setParentBone(Bone *parentBone)
{
_parentBone = parentBone;
2013-12-18 22:07:33 +08:00
for (auto& element : _boneDic)
2013-10-30 09:41:40 +08:00
{
element.second->setArmature(this);
2013-10-30 09:41:40 +08:00
}
}
2013-11-05 19:53:38 +08:00
Bone *Armature::getParentBone() const
2013-10-30 09:41:40 +08:00
{
return _parentBone;
}
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT
void Armature::setColliderFilter(ColliderFilter *filter)
2013-11-01 14:36:44 +08:00
{
2013-12-18 22:07:33 +08:00
for (auto& element : _boneDic)
2013-11-01 14:36:44 +08:00
{
element.second->setColliderFilter(filter);
2013-11-01 14:36:44 +08:00
}
}
#elif ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
void Armature::drawContour()
{
2013-12-18 22:07:33 +08:00
for(auto& element : _boneDic)
{
Bone *bone = element.second;
ColliderDetector *detector = bone->getColliderDetector();
if (!detector)
continue;
const cocos2d::Vector<ColliderBody*>& bodyList = detector->getColliderBodyList();
2013-12-18 22:07:33 +08:00
for (auto& object : bodyList)
{
ColliderBody *body = static_cast<ColliderBody*>(object);
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
const std::vector<Vec2> &vertexList = body->getCalculatedVertexList();
2013-12-17 19:32:16 +08:00
unsigned long length = vertexList.size();
Vec2 *points = new (std::nothrow) Vec2[length];
2013-12-17 19:32:16 +08:00
for (unsigned long i = 0; i<length; i++)
{
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
Vec2 p = vertexList.at(i);
2013-12-13 19:40:38 +08:00
points[i].x = p.x;
points[i].y = p.y;
}
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#elif _MSC_VER >= 1400 //vs 2005 or higher
#pragma warning (push)
#pragma warning (disable: 4996)
#endif
2013-12-17 19:32:16 +08:00
DrawPrimitives::drawPoly( points, (unsigned int)length, true );
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
#elif _MSC_VER >= 1400 //vs 2005 or higher
#pragma warning (pop)
#endif
delete []points;
}
}
}
#endif
2013-11-01 14:36:44 +08:00
2013-09-13 18:07:37 +08:00
#if ENABLE_PHYSICS_BOX2D_DETECT
2013-11-05 19:53:38 +08:00
b2Body *Armature::getBody() const
2013-09-13 18:07:37 +08:00
{
2013-09-15 20:24:25 +08:00
return _body;
2013-09-13 18:07:37 +08:00
}
void Armature::setBody(b2Body *body)
2013-09-13 18:07:37 +08:00
{
2013-09-15 20:24:25 +08:00
if (_body == body)
2013-09-13 18:07:37 +08:00
{
return;
}
2013-09-15 20:24:25 +08:00
_body = body;
_body->SetUserData(this);
2013-09-13 18:07:37 +08:00
2013-12-18 22:36:10 +08:00
for(auto& object : _children)
2013-09-13 18:07:37 +08:00
{
if (Bone *bone = dynamic_cast<Bone *>(object))
2013-09-13 18:07:37 +08:00
{
2013-12-18 22:36:10 +08:00
auto displayList = bone->getDisplayManager()->getDecorativeDisplayList();
2013-09-13 18:07:37 +08:00
for(auto displayObject : displayList)
2013-09-13 18:07:37 +08:00
{
ColliderDetector *detector = static_cast<DecorativeDisplay *>(displayObject)->getColliderDetector();
if (detector != nullptr)
2013-09-13 18:07:37 +08:00
{
2013-09-15 20:24:25 +08:00
detector->setBody(_body);
2013-09-13 18:07:37 +08:00
}
}
}
}
}
b2Fixture *Armature::getShapeList()
2013-09-13 18:07:37 +08:00
{
2013-09-15 20:24:25 +08:00
if (_body)
2013-09-13 18:07:37 +08:00
{
2013-09-15 20:24:25 +08:00
return _body->GetFixtureList();
2013-09-13 18:07:37 +08:00
}
else
{
return nullptr;
2013-09-13 18:07:37 +08:00
}
}
#elif ENABLE_PHYSICS_CHIPMUNK_DETECT
2013-11-05 19:53:38 +08:00
cpBody *Armature::getBody() const
2013-09-13 18:07:37 +08:00
{
2013-09-15 20:24:25 +08:00
return _body;
2013-09-13 18:07:37 +08:00
}
void Armature::setBody(cpBody *body)
2013-09-13 18:07:37 +08:00
{
2013-09-15 20:24:25 +08:00
if (_body == body)
2013-09-13 18:07:37 +08:00
{
return;
}
2013-09-15 20:24:25 +08:00
_body = body;
_body->data = this;
2013-09-13 18:07:37 +08:00
for (const auto& object : _children)
2013-09-13 18:07:37 +08:00
{
if (Bone *bone = dynamic_cast<Bone *>(object))
2013-09-13 18:07:37 +08:00
{
2013-12-18 22:36:10 +08:00
auto displayList = bone->getDisplayManager()->getDecorativeDisplayList();
2013-09-13 18:07:37 +08:00
for (const auto& displayObject : displayList)
2013-09-13 18:07:37 +08:00
{
auto detector = displayObject->getColliderDetector();
if (detector != nullptr)
2013-09-13 18:07:37 +08:00
{
2013-12-18 22:36:10 +08:00
detector->setBody(body);
2013-09-13 18:07:37 +08:00
}
2013-12-18 22:07:33 +08:00
});
2013-09-13 18:07:37 +08:00
}
}
}
cpShape *Armature::getShapeList()
2013-09-13 18:07:37 +08:00
{
2013-09-15 20:24:25 +08:00
if (_body)
2013-09-13 18:07:37 +08:00
{
2013-09-15 20:24:25 +08:00
return _body->shapeList_private;
2013-09-13 18:07:37 +08:00
}
else
{
return nullptr;
2013-09-13 18:07:37 +08:00
}
}
#endif
}