submeshid

This commit is contained in:
yangxiao 2014-08-15 18:21:58 +08:00
parent d09695b118
commit a740841f5e
4 changed files with 20 additions and 4 deletions

View File

@ -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
*/

View File

@ -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(); }

View File

@ -58,7 +58,6 @@ SubMesh::SubMesh()
SubMesh::~SubMesh()
{
cleanAndFreeBuffers();
CC_SAFE_RELEASE(_mesh);
}
SubMesh* SubMesh::create(PrimitiveType primitivetype, IndexFormat indexformat, const std::vector<unsigned short>& 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<unsigned short>& indices)
SubMesh* SubMesh::create(const std::string& submeshId, Mesh* mesh, PrimitiveType primitivetype, IndexFormat indexformat, const std::vector<unsigned short>& indices)
{
auto submesh = new SubMesh();
submesh->_primitiveType = primitivetype;
submesh->_indexFormat = indexformat;
submesh->_mesh = mesh;
submesh->_id = submeshId;
submesh->autorelease();
return submesh;

View File

@ -67,7 +67,7 @@ public:
/**create submesh from primitivetype indexformat and indices*/
static SubMesh* create(PrimitiveType primitivetype, IndexFormat indexformat, const std::vector<unsigned short>& indices);
static SubMesh* create(Mesh* mesh, PrimitiveType primitivetype, IndexFormat indexformat, const std::vector<unsigned short>& indices);
static SubMesh* create(const std::string& submeshId, Mesh* mesh, PrimitiveType primitivetype, IndexFormat indexformat, const std::vector<unsigned short>& 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