From a740841f5e8717a24c331ae985e46c654235c0a4 Mon Sep 17 00:00:00 2001 From: yangxiao Date: Fri, 15 Aug 2014 18:21:58 +0800 Subject: [PATCH] submeshid --- cocos/3d/CCMesh.cpp | 9 +++++++++ cocos/3d/CCMesh.h | 3 +++ cocos/3d/CCSubMesh.cpp | 4 ++-- cocos/3d/CCSubMesh.h | 8 ++++++-- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/cocos/3d/CCMesh.cpp b/cocos/3d/CCMesh.cpp index 16007b1588..d2e6cd5b7d 100644 --- a/cocos/3d/CCMesh.cpp +++ b/cocos/3d/CCMesh.cpp @@ -295,6 +295,15 @@ const AABB& Mesh::getOriginAABB() const return _originAABB; } +SubMesh* Mesh::getSubMeshById(const std::string& subMeshId) const +{ + for (auto it : _subMeshes) { + if (it->getSubMeshId() == subMeshId) + return it; + } + return nullptr; +} + /** * MeshCache */ diff --git a/cocos/3d/CCMesh.h b/cocos/3d/CCMesh.h index 304a09f207..ed0c78c145 100644 --- a/cocos/3d/CCMesh.h +++ b/cocos/3d/CCMesh.h @@ -127,6 +127,9 @@ public: /** get origin aabb that calculate from vertices*/ const AABB& getOriginAABB() const; + /** get submesh by id */ + SubMesh* getSubMeshById(const std::string& subMeshId) const; + /**to be deprecated, those functions have been moved to SubMesh*/ /** get primitive type*/ CC_DEPRECATED_ATTRIBUTE PrimitiveType getPrimitiveType() const { return _subMeshes.at(0)->getPrimitiveType(); } diff --git a/cocos/3d/CCSubMesh.cpp b/cocos/3d/CCSubMesh.cpp index 9625e10073..693d8d37d3 100644 --- a/cocos/3d/CCSubMesh.cpp +++ b/cocos/3d/CCSubMesh.cpp @@ -58,7 +58,6 @@ SubMesh::SubMesh() SubMesh::~SubMesh() { cleanAndFreeBuffers(); - CC_SAFE_RELEASE(_mesh); } SubMesh* SubMesh::create(PrimitiveType primitivetype, IndexFormat indexformat, const std::vector& indices) @@ -71,12 +70,13 @@ SubMesh* SubMesh::create(PrimitiveType primitivetype, IndexFormat indexformat, c return submesh; } -SubMesh* SubMesh::create(Mesh* mesh, PrimitiveType primitivetype, IndexFormat indexformat, const std::vector& indices) +SubMesh* SubMesh::create(const std::string& submeshId, Mesh* mesh, PrimitiveType primitivetype, IndexFormat indexformat, const std::vector& indices) { auto submesh = new SubMesh(); submesh->_primitiveType = primitivetype; submesh->_indexFormat = indexformat; submesh->_mesh = mesh; + submesh->_id = submeshId; submesh->autorelease(); return submesh; diff --git a/cocos/3d/CCSubMesh.h b/cocos/3d/CCSubMesh.h index 4e3b307e67..1e792473f7 100644 --- a/cocos/3d/CCSubMesh.h +++ b/cocos/3d/CCSubMesh.h @@ -67,7 +67,7 @@ public: /**create submesh from primitivetype indexformat and indices*/ static SubMesh* create(PrimitiveType primitivetype, IndexFormat indexformat, const std::vector& indices); - static SubMesh* create(Mesh* mesh, PrimitiveType primitivetype, IndexFormat indexformat, const std::vector& indices); + static SubMesh* create(const std::string& submeshId, Mesh* mesh, PrimitiveType primitivetype, IndexFormat indexformat, const std::vector& indices); /** get primitive type*/ PrimitiveType getPrimitiveType() const { return _primitiveType; } @@ -80,6 +80,9 @@ public: /** get mesh */ Mesh* getMesh() const { return _mesh; } + + /** get submesh id */ + const std::string& getSubMeshId() const { return _id; } CC_CONSTRUCTOR_ACCESS: @@ -98,7 +101,8 @@ protected: GLuint _indexBuffer; ssize_t _indexCount; - Mesh* _mesh; //parent mesh, weak ref + Mesh* _mesh; //parent mesh, weak ref + std::string _id; //submeshid }; NS_CC_END