diff --git a/cocos/3d/CCSprite3D.h b/cocos/3d/CCSprite3D.h index 9e79ba37ab..7c587c0b8b 100644 --- a/cocos/3d/CCSprite3D.h +++ b/cocos/3d/CCSprite3D.h @@ -124,6 +124,9 @@ protected: std::unordered_map _attachments; BlendFunc _blend; + + //since 3.3 + std::vector _meshes; }; extern std::string CC_DLL s_attributeNames[];//attribute names array diff --git a/cocos/3d/CCSubMesh.cpp b/cocos/3d/CCSubMesh.cpp index 330e6e3f2a..9625e10073 100644 --- a/cocos/3d/CCSubMesh.cpp +++ b/cocos/3d/CCSubMesh.cpp @@ -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& 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& indices) +{ + auto submesh = new SubMesh(); + submesh->_primitiveType = primitivetype; + submesh->_indexFormat = indexformat; + submesh->_mesh = mesh; + submesh->autorelease(); + + return submesh; +} + void SubMesh::cleanAndFreeBuffers() { if(glIsBuffer(_indexBuffer)) diff --git a/cocos/3d/CCSubMesh.h b/cocos/3d/CCSubMesh.h index ff8dc0e026..4e3b307e67 100644 --- a/cocos/3d/CCSubMesh.h +++ b/cocos/3d/CCSubMesh.h @@ -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& indices); + static SubMesh* create(Mesh* mesh, PrimitiveType primitivetype, IndexFormat indexformat, const std::vector& 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_ diff --git a/cocos/3d/CCSubMeshState.cpp b/cocos/3d/CCSubMeshState.cpp index 639c1e87cd..9f97a941bd 100644 --- a/cocos/3d/CCSubMeshState.cpp +++ b/cocos/3d/CCSubMeshState.cpp @@ -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 diff --git a/cocos/3d/CCSubMeshState.h b/cocos/3d/CCSubMeshState.h index 26bca6cb17..129a45a67b 100644 --- a/cocos/3d/CCSubMeshState.h +++ b/cocos/3d/CCSubMeshState.h @@ -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