2014-07-29 10:49:06 +08:00
|
|
|
/****************************************************************************
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2014-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2014-07-29 10:49:06 +08:00
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-08-22 13:52:03 +08:00
|
|
|
#ifndef __CCMESHVERTEXINDEXDATA_H__
|
|
|
|
#define __CCMESHVERTEXINDEXDATA_H__
|
2014-07-29 10:49:06 +08:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "3d/CCBundle3DData.h"
|
2014-08-18 17:02:13 +08:00
|
|
|
#include "3d/CCAABB.h"
|
2014-07-29 10:49:06 +08:00
|
|
|
|
|
|
|
#include "base/CCRef.h"
|
2014-08-29 15:39:52 +08:00
|
|
|
#include "base/CCVector.h"
|
2014-07-29 10:49:06 +08:00
|
|
|
#include "math/CCMath.h"
|
|
|
|
#include "renderer/CCGLProgram.h"
|
2014-08-22 13:25:26 +08:00
|
|
|
#include "renderer/CCVertexIndexData.h"
|
|
|
|
#include "renderer/CCVertexIndexBuffer.h"
|
2014-08-29 15:39:52 +08:00
|
|
|
|
2014-07-29 10:49:06 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2015-03-27 14:10:41 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup _3d
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2014-08-22 13:25:26 +08:00
|
|
|
class MeshVertexData;
|
2014-07-29 10:49:06 +08:00
|
|
|
|
2015-03-20 17:20:22 +08:00
|
|
|
/**
|
|
|
|
* the MeshIndexData class.
|
|
|
|
* @brief the MeshIndexData contain all of the indices data which mesh need.
|
2015-03-28 15:11:51 +08:00
|
|
|
* @js NA
|
2015-03-30 15:47:47 +08:00
|
|
|
* @lua NA
|
2015-03-20 17:20:22 +08:00
|
|
|
*/
|
2015-11-27 14:58:18 +08:00
|
|
|
class CC_DLL MeshIndexData : public Ref
|
2014-07-29 10:49:06 +08:00
|
|
|
{
|
2014-08-22 13:25:26 +08:00
|
|
|
public:
|
|
|
|
/** create */
|
|
|
|
static MeshIndexData* create(const std::string& id, MeshVertexData* vertexData, IndexBuffer* indexbuffer, const AABB& aabb);
|
|
|
|
|
|
|
|
/**get index buffer*/
|
|
|
|
const IndexBuffer* getIndexBuffer() const { return _indexBuffer; }
|
|
|
|
/**get vertex buffer*/
|
|
|
|
const VertexBuffer* getVertexBuffer() const;
|
|
|
|
|
|
|
|
/**get vertex data*/
|
|
|
|
const MeshVertexData* getMeshVertexData() const { return _vertexData; }
|
|
|
|
|
|
|
|
/** aabb getter and setter */
|
|
|
|
void setAABB(const AABB& aabb) { _aabb = aabb; }
|
|
|
|
const AABB& getAABB() const { return _aabb; }
|
|
|
|
|
|
|
|
/** id setter and getter */
|
|
|
|
void setId(const std::string& id) { _id = id; }
|
|
|
|
const std::string& getId() const { return _id; }
|
|
|
|
|
2014-08-22 14:02:51 +08:00
|
|
|
/**primitive type setter & getter*/
|
2014-08-22 13:25:26 +08:00
|
|
|
GLenum getPrimitiveType() const { return _primitiveType; }
|
|
|
|
void setPrimitiveType(GLenum primitive) { _primitiveType = primitive; }
|
|
|
|
|
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
|
|
|
MeshIndexData();
|
|
|
|
virtual ~MeshIndexData();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
IndexBuffer* _indexBuffer; //index buffer
|
2015-04-09 11:31:56 +08:00
|
|
|
MeshVertexData* _vertexData; //vertex buffer, weak ref
|
2014-08-22 13:25:26 +08:00
|
|
|
AABB _aabb; // original aabb of the submesh
|
|
|
|
std::string _id; //id
|
|
|
|
GLenum _primitiveType;
|
|
|
|
|
|
|
|
friend class MeshVertexData;
|
|
|
|
friend class Sprite3D;
|
2014-07-29 10:49:06 +08:00
|
|
|
};
|
|
|
|
|
2015-03-20 17:20:22 +08:00
|
|
|
/**
|
|
|
|
* the MeshVertexData class.
|
|
|
|
* @brief the MeshIndexData contain all of the vertices data which mesh need.
|
|
|
|
*/
|
2015-12-03 15:56:39 +08:00
|
|
|
class CC_DLL MeshVertexData : public Ref
|
2014-07-29 10:49:06 +08:00
|
|
|
{
|
2014-08-22 13:25:26 +08:00
|
|
|
friend class Sprite3D;
|
2014-07-29 10:49:06 +08:00
|
|
|
friend class Mesh;
|
|
|
|
public:
|
2014-08-22 13:25:26 +08:00
|
|
|
/**create*/
|
|
|
|
static MeshVertexData* create(const MeshData& meshdata);
|
2014-07-29 10:49:06 +08:00
|
|
|
|
2014-08-22 13:25:26 +08:00
|
|
|
/** get vertexbuffer */
|
|
|
|
const VertexBuffer* getVertexBuffer() const { return _vertexBuffer; }
|
2014-08-15 14:58:30 +08:00
|
|
|
|
2014-08-22 13:25:26 +08:00
|
|
|
/** get attributes count */
|
|
|
|
ssize_t getMeshVertexAttribCount() const { return _attribs.size(); }
|
2014-08-15 14:58:30 +08:00
|
|
|
|
2014-08-22 13:25:26 +08:00
|
|
|
/** get attribute by index */
|
|
|
|
const MeshVertexAttrib& getMeshVertexAttrib(ssize_t index) const { return _attribs[index]; }
|
|
|
|
|
|
|
|
/** get index data count */
|
|
|
|
ssize_t getMeshIndexDataCount() const { return _indexs.size(); }
|
|
|
|
/** get index data by index */
|
|
|
|
MeshIndexData* getMeshIndexDataByIndex(int index) const { return _indexs.at(index); }
|
|
|
|
/** get index data by id */
|
|
|
|
MeshIndexData* getMeshIndexDataById(const std::string& id) const;
|
|
|
|
|
|
|
|
/**has vertex attribute?*/
|
|
|
|
bool hasVertexAttrib(int attrib) const;
|
2014-08-15 18:21:58 +08:00
|
|
|
|
2014-07-29 10:49:06 +08:00
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
2014-08-22 13:25:26 +08:00
|
|
|
MeshVertexData();
|
|
|
|
virtual ~MeshVertexData();
|
2014-11-19 17:58:40 +08:00
|
|
|
|
2014-07-29 10:49:06 +08:00
|
|
|
protected:
|
2014-08-22 13:25:26 +08:00
|
|
|
VertexData* _vertexData; //mesh vertex data
|
|
|
|
VertexBuffer* _vertexBuffer; // vertex buffer
|
|
|
|
Vector<MeshIndexData*> _indexs; //index data
|
2014-08-22 14:02:51 +08:00
|
|
|
std::vector<MeshVertexAttrib> _attribs; //vertex attributes
|
2014-08-15 14:58:30 +08:00
|
|
|
|
2014-08-22 13:25:26 +08:00
|
|
|
int _vertexCount; //vertex count
|
2014-07-29 10:49:06 +08:00
|
|
|
};
|
|
|
|
|
2015-04-01 10:23:53 +08:00
|
|
|
// end of 3d group
|
2015-03-27 14:10:41 +08:00
|
|
|
/// @}
|
|
|
|
|
2014-07-29 10:49:06 +08:00
|
|
|
NS_CC_END
|
|
|
|
|
2014-08-22 13:52:03 +08:00
|
|
|
#endif // __CCMESHVERTEXINDEXDATA_H__
|