From a7a39d71f58e3d2fac92603841595776cf07893e Mon Sep 17 00:00:00 2001 From: yangxiao Date: Wed, 8 Apr 2015 16:40:04 +0800 Subject: [PATCH] modify getAABBRecursively --- cocos/3d/CCSprite3D.cpp | 35 +++++++++++++++++++++++++++-------- cocos/3d/CCSprite3D.h | 2 +- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/cocos/3d/CCSprite3D.cpp b/cocos/3d/CCSprite3D.cpp index 8f9ad8988b..08f12ec863 100644 --- a/cocos/3d/CCSprite3D.cpp +++ b/cocos/3d/CCSprite3D.cpp @@ -820,6 +820,22 @@ const BlendFunc& Sprite3D::getBlendFunc() const return _blend; } +AABB Sprite3D::getAABBRecursively() +{ + AABB aabb; + const Vector& children = getChildren(); + for (const auto& iter : children) + { + Sprite3D* child = dynamic_cast(iter); + if(child) + { + aabb.merge(child->getAABBRecursively()); + } + } + aabb.merge(getAABB()); + return aabb; +} + const AABB& Sprite3D::getAABB() const { Mat4 nodeToWorldTransform(getNodeToWorldTransform()); @@ -832,15 +848,18 @@ const AABB& Sprite3D::getAABB() const else { _aabb.reset(); - Mat4 transform(nodeToWorldTransform); - for (const auto& it : _meshes) { - if (it->isVisible()) - _aabb.merge(it->getAABB()); + if (_meshes.size()) + { + Mat4 transform(nodeToWorldTransform); + for (const auto& it : _meshes) { + if (it->isVisible()) + _aabb.merge(it->getAABB()); + } + + _aabb.transform(transform); + _nodeToWorldTransform = nodeToWorldTransform; + _aabbDirty = false; } - - _aabb.transform(transform); - _nodeToWorldTransform = nodeToWorldTransform; - _aabbDirty = false; } return _aabb; diff --git a/cocos/3d/CCSprite3D.h b/cocos/3d/CCSprite3D.h index 94ca0c698f..147b7c43f8 100644 --- a/cocos/3d/CCSprite3D.h +++ b/cocos/3d/CCSprite3D.h @@ -141,7 +141,7 @@ public: * the Sprite3D don't contain any meshes, so getAABB() * will return a wrong value at that time. */ - const AABB& getAABBRecursively(); + AABB getAABBRecursively(); /** * Executes an action, and returns the action that is executed. For Sprite3D special logic are needed to take care of Fading.