diff --git a/cocos/3d/CCSprite3D.cpp b/cocos/3d/CCSprite3D.cpp index a498d9b03e..66a0f0d216 100644 --- a/cocos/3d/CCSprite3D.cpp +++ b/cocos/3d/CCSprite3D.cpp @@ -684,7 +684,7 @@ Mesh* Sprite3D::getMeshByIndex(int index) const return _meshes.at(index); } -/**get SubMeshState by Name */ +/**get Mesh by Name */ Mesh* Sprite3D::getMeshByName(const std::string& name) const { for (const auto& it : _meshes) { @@ -694,6 +694,16 @@ Mesh* Sprite3D::getMeshByName(const std::string& name) const return nullptr; } +std::vector Sprite3D::getMeshArrayByName(const std::string& name) const +{ + std::vector meshes; + for (const auto& it : _meshes) { + if (it->getName() == name) + meshes.push_back(it); + } + return meshes; +} + MeshSkin* Sprite3D::getSkin() const { for (const auto& it : _meshes) { diff --git a/cocos/3d/CCSprite3D.h b/cocos/3d/CCSprite3D.h index 3b08d9bf9e..daeb83c688 100644 --- a/cocos/3d/CCSprite3D.h +++ b/cocos/3d/CCSprite3D.h @@ -60,11 +60,14 @@ public: void setTexture(const std::string& texFile); void setTexture(Texture2D* texture); - /**get SubMeshState by index*/ + /**get Mesh by index*/ Mesh* getMeshByIndex(int index) const; - /**get SubMeshState by Name */ + /**get Mesh by Name, it returns the first one if there are more than one mesh with the same name */ Mesh* getMeshByName(const std::string& name) const; + + /** get mesh array by name, returns all meshes with the given name */ + std::vector getMeshArrayByName(const std::string& name) const; /**get mesh*/ Mesh* getMesh() const { return _meshes.at(0); }