mirror of https://github.com/axmolengine/axmol.git
commit
9ece9cead4
|
@ -60,7 +60,7 @@ bool Bundle3D::loadMeshData(const std::string& id, MeshData* meshdata)
|
|||
{
|
||||
meshdata->resetData();
|
||||
meshdata->vertexSizeInFloat = 13 * 4;
|
||||
meshdata->vertex = new float[meshdata->vertexSizeInFloat];
|
||||
meshdata->vertex.resize(meshdata->vertexSizeInFloat);
|
||||
//dabing's data
|
||||
// float vert[] = {0.f,50.f,0.f, 0.f,0.f, 0.f,0.f,0.f,0.f, 1.f,0.f,0.f,0.f,
|
||||
// 0.f,0.f,50.f, 1.f,1.f, 0.f,0.f,0.f,0.f, 1.f,0.f,0.f,0.f,
|
||||
|
@ -73,18 +73,18 @@ bool Bundle3D::loadMeshData(const std::string& id, MeshData* meshdata)
|
|||
|
||||
|
||||
//float vert[] = {0.f,50.f,0.f, 0.f,0.f,50.f, 50.f,0.f,0.f, -50.f,0.f,0.f};
|
||||
memcpy(meshdata->vertex, vert, meshdata->vertexSizeInFloat * sizeof(float));
|
||||
memcpy(&meshdata->vertex[0], vert, meshdata->vertexSizeInFloat * sizeof(float));
|
||||
|
||||
meshdata->numIndex = 4 * 3;
|
||||
//meshdata->numIndex = 3;
|
||||
meshdata->indices = new unsigned short[meshdata->numIndex];
|
||||
meshdata->indices.resize(meshdata->numIndex);
|
||||
unsigned short index[] = {0,1,2, 0,3,1, 0,2,3, 3,2,1};
|
||||
//unsigned short index[] = {0,3,2};
|
||||
//unsigned short index[] = {0,1,2};
|
||||
memcpy(meshdata->indices, index, meshdata->numIndex * sizeof(unsigned short));
|
||||
memcpy(&meshdata->indices[0], index, meshdata->numIndex * sizeof(unsigned short));
|
||||
|
||||
meshdata->attribCount = 4;
|
||||
meshdata->attribs = new MeshVertexAttrib[meshdata->attribCount];
|
||||
meshdata->attribs.resize(meshdata->attribCount);
|
||||
meshdata->attribs[0].attribSizeBytes = 3 * sizeof(float);
|
||||
meshdata->attribs[0].size = 3;
|
||||
meshdata->attribs[0].type = GL_FLOAT;
|
||||
|
|
|
@ -49,29 +49,26 @@ struct MeshVertexAttrib
|
|||
|
||||
struct MeshData
|
||||
{
|
||||
float* vertex;
|
||||
std::vector<float> vertex;
|
||||
int vertexSizeInFloat;
|
||||
unsigned short* indices;
|
||||
std::vector<unsigned short> indices;
|
||||
int numIndex;
|
||||
MeshVertexAttrib* attribs;
|
||||
std::vector<MeshVertexAttrib> attribs;
|
||||
int attribCount;
|
||||
|
||||
public:
|
||||
void resetData()
|
||||
{
|
||||
CC_SAFE_DELETE_ARRAY(vertex);
|
||||
CC_SAFE_DELETE_ARRAY(indices);
|
||||
CC_SAFE_DELETE_ARRAY(attribs);
|
||||
vertex.clear();
|
||||
indices.clear();
|
||||
attribs.clear();
|
||||
vertexSizeInFloat = 0;
|
||||
numIndex = 0;
|
||||
attribCount = 0;
|
||||
}
|
||||
MeshData()
|
||||
: vertex(nullptr)
|
||||
, vertexSizeInFloat(0)
|
||||
, indices(nullptr)
|
||||
: vertexSizeInFloat(0)
|
||||
, numIndex(0)
|
||||
, attribs(nullptr)
|
||||
, attribCount(0)
|
||||
{
|
||||
}
|
||||
|
@ -106,6 +103,7 @@ struct MaterialData
|
|||
|
||||
struct Animation3DData
|
||||
{
|
||||
public:
|
||||
struct Vec3Key
|
||||
{
|
||||
Vec3Key()
|
||||
|
@ -142,12 +140,14 @@ struct Animation3DData
|
|||
Quaternion _key;
|
||||
};
|
||||
|
||||
public:
|
||||
std::map<std::string, std::vector<Vec3Key>> _translationKeys;
|
||||
std::map<std::string, std::vector<QuatKey>> _rotationKeys;
|
||||
std::map<std::string, std::vector<Vec3Key>> _scaleKeys;
|
||||
|
||||
float _totalTime;
|
||||
|
||||
public:
|
||||
Animation3DData()
|
||||
:_totalTime(0)
|
||||
{
|
||||
|
|
|
@ -118,15 +118,14 @@ bool RenderMeshData::initFrom(const std::vector<float>& positions,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool RenderMeshData::initFrom(const float* vertex, int vertexSizeInFloat, unsigned short* indices, int numIndex, const MeshVertexAttrib* attribs, int attribCount)
|
||||
bool RenderMeshData::initFrom(const std::vector<float>& vertices, int vertexSizeInFloat, const std::vector<unsigned short>& indices, int numIndex, const std::vector<MeshVertexAttrib>& attribs, int attribCount)
|
||||
{
|
||||
_vertexs.assign(vertex, vertex + vertexSizeInFloat);
|
||||
_indices.assign(indices, indices + numIndex);
|
||||
_vertexAttribs.assign(attribs, attribs + attribCount);
|
||||
_vertexs = vertices;
|
||||
_indices = indices;
|
||||
_vertexAttribs = attribs;
|
||||
|
||||
_vertexsizeBytes = calVertexSizeBytes();
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -168,10 +167,10 @@ Mesh* Mesh::create(const std::vector<float>& positions, const std::vector<float>
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
Mesh* Mesh::create(const float* vertex, int vertexSizeInFloat, unsigned short* indices, int numIndex, const MeshVertexAttrib* attribs, int attribCount)
|
||||
Mesh* Mesh::create(const std::vector<float> &vertices, int vertexSizeInFloat, const std::vector<unsigned short> &indices, int numIndex, const std::vector<MeshVertexAttrib> &attribs, int attribCount)
|
||||
{
|
||||
auto mesh = new Mesh();
|
||||
if (mesh && mesh->init(vertex, vertexSizeInFloat, indices, numIndex, attribs, attribCount))
|
||||
if (mesh && mesh->init(vertices, vertexSizeInFloat, indices, numIndex, attribs, attribCount))
|
||||
{
|
||||
mesh->autorelease();
|
||||
return mesh;
|
||||
|
@ -190,9 +189,9 @@ bool Mesh::init(const std::vector<float>& positions, const std::vector<float>& n
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Mesh::init(const float* vertex, int vertexSizeInFloat, unsigned short* indices, int numIndex, const MeshVertexAttrib* attribs, int attribCount)
|
||||
bool Mesh::init(const std::vector<float>& vertices, int vertexSizeInFloat, const std::vector<unsigned short>& indices, int numIndex, const std::vector<MeshVertexAttrib>& attribs, int attribCount)
|
||||
{
|
||||
bool bRet = _renderdata.initFrom(vertex, vertexSizeInFloat, indices, numIndex, attribs, attribCount);
|
||||
bool bRet = _renderdata.initFrom(vertices, vertexSizeInFloat, indices, numIndex, attribs, attribCount);
|
||||
if (!bRet)
|
||||
return false;
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ public:
|
|||
}
|
||||
bool hasVertexAttrib(int attrib);
|
||||
bool initFrom(const std::vector<float>& positions, const std::vector<float>& normals, const std::vector<float>& texs, const std::vector<unsigned short>& indices);
|
||||
bool initFrom(const float* vertex, int vertexSizeInFloat, unsigned short* indices, int numIndex, const MeshVertexAttrib* attribs, int attribCount);
|
||||
bool initFrom(const std::vector<float>& vertices, int vertexSizeInFloat, const std::vector<unsigned short>& indices, int numIndex, const std::vector<MeshVertexAttrib>& attribs, int attribCount);
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -83,7 +83,7 @@ public:
|
|||
//create
|
||||
static Mesh* create(const std::vector<float>& positions, const std::vector<float>& normals, const std::vector<float>& texs, const std::vector<unsigned short>& indices);
|
||||
|
||||
static Mesh* create(const float* vertex, int vertexSizeInFloat, unsigned short* indices, int numIndex, const MeshVertexAttrib* attribs, int attribCount);
|
||||
static Mesh* create(const std::vector<float>& vertices, int vertexSizeInFloat, const std::vector<unsigned short>& indices, int numIndex, const std::vector<MeshVertexAttrib>& attribs, int attribCount);
|
||||
|
||||
//get vertex buffer
|
||||
inline GLuint getVertexBuffer() const { return _vertexBuffer; }
|
||||
|
@ -110,7 +110,7 @@ protected:
|
|||
virtual ~Mesh();
|
||||
bool init(const std::vector<float>& positions, const std::vector<float>& normals, const std::vector<float>& texs, const std::vector<unsigned short>& indices);
|
||||
|
||||
bool init(const float* vertex, int vertexSizeInFloat, unsigned short* indices, int numIndex, const MeshVertexAttrib* attribs, int attribCount);
|
||||
bool init(const std::vector<float>& vertices, int vertexSizeInFloat, const std::vector<unsigned short>& indices, int numIndex, const std::vector<MeshVertexAttrib>& attribs, int attribCount);
|
||||
|
||||
//build buffer
|
||||
void buildBuffer();
|
||||
|
|
Loading…
Reference in New Issue