This commit is contained in:
yangxiao 2014-08-15 14:58:30 +08:00
parent fdcec51cf4
commit 88bb1482e3
5 changed files with 52 additions and 2 deletions

View File

@ -124,6 +124,9 @@ protected:
std::unordered_map<std::string, AttachNode*> _attachments;
BlendFunc _blend;
//since 3.3
std::vector<Mesh*> _meshes;
};
extern std::string CC_DLL s_attributeNames[];//attribute names array

View File

@ -31,6 +31,7 @@
#include "3d/CCObjLoader.h"
#include "3d/CCSprite3DMaterial.h"
#include "3d/CCMesh.h"
#include "base/ccMacros.h"
#include "base/CCEventCustom.h"
@ -50,12 +51,14 @@ SubMesh::SubMesh()
, _primitiveType(PrimitiveType::TRIANGLES)
, _indexFormat(IndexFormat::INDEX16)
, _indexCount(0)
, _mesh(nullptr)
{
}
SubMesh::~SubMesh()
{
cleanAndFreeBuffers();
CC_SAFE_RELEASE(_mesh);
}
SubMesh* SubMesh::create(PrimitiveType primitivetype, IndexFormat indexformat, const std::vector<unsigned short>& indices)
@ -68,6 +71,17 @@ 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)
{
auto submesh = new SubMesh();
submesh->_primitiveType = primitivetype;
submesh->_indexFormat = indexformat;
submesh->_mesh = mesh;
submesh->autorelease();
return submesh;
}
void SubMesh::cleanAndFreeBuffers()
{
if(glIsBuffer(_indexBuffer))

View File

@ -54,6 +54,8 @@ enum class PrimitiveType
POINTS = GL_POINTS
};
class Mesh;
/**
* SubMesh: Defines the way the mesh's vertices how to be connected together.
*/
@ -65,6 +67,8 @@ 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);
/** get primitive type*/
PrimitiveType getPrimitiveType() const { return _primitiveType; }
/**get index count*/
@ -73,7 +77,9 @@ public:
IndexFormat getIndexFormat() const { return _indexFormat; }
/**get index buffer*/
GLuint getIndexBuffer() const {return _indexBuffer; }
/** get mesh */
Mesh* getMesh() const { return _mesh; }
CC_CONSTRUCTOR_ACCESS:
@ -91,8 +97,10 @@ protected:
GLuint _indexBuffer;
ssize_t _indexCount;
Mesh* _mesh; //parent mesh, weak ref
};
NS_CC_END
#endif // __CCMESH_H_
#endif // __CCSUBMESH_H_

View File

@ -49,6 +49,7 @@ SubMeshState::SubMeshState()
: _visible(true)
, _texture(nullptr)
, _skin(nullptr)
, _subMesh(nullptr)
{
}
@ -56,6 +57,7 @@ SubMeshState::~SubMeshState()
{
CC_SAFE_RELEASE(_texture);
CC_SAFE_RELEASE(_skin);
CC_SAFE_RELEASE(_subMesh);
}
SubMeshState* SubMeshState::create()
@ -86,4 +88,14 @@ void SubMeshState::setSkin(MeshSkin* skin)
}
}
void SubMeshState::setSubMesh(SubMesh* subMesh)
{
if (_subMesh != subMesh)
{
CC_SAFE_RETAIN(subMesh);
CC_SAFE_RELEASE(_subMesh);
_subMesh = subMesh;
}
}
NS_CC_END

View File

@ -39,6 +39,7 @@ NS_CC_BEGIN
class Texture2D;
class MeshSkin;
class SubMesh;
/**
* SubMeshState: visibility and apperence of submesh
*/
@ -60,6 +61,14 @@ public:
/**skin getter and setter*/
void setSkin(MeshSkin* skin);
MeshSkin* getSkin() const { return _skin; }
/**sub mesh getter and setter*/
void setSubMesh(SubMesh* subMesh);
SubMesh* getSubMesh() const { return _subMesh; }
/**name getter and setter*/
void setName(const std::string& name) { _name = name; }
const std::string& getName() const { return _name; }
CC_CONSTRUCTOR_ACCESS:
@ -70,6 +79,10 @@ protected:
Texture2D* _texture; //texture that submesh is using
MeshSkin* _skin; //skin
bool _visible; // is the submesh visible
//since 3.3
std::string _name;
SubMesh* _subMesh;
};
NS_CC_END