Merge pull request #36 from dabingnn/v3Animation

V3 animation
This commit is contained in:
Huabing.Xu 2014-06-13 12:03:06 +08:00
commit 9ece9cead4
4 changed files with 28 additions and 29 deletions

View File

@ -60,7 +60,7 @@ bool Bundle3D::loadMeshData(const std::string& id, MeshData* meshdata)
{ {
meshdata->resetData(); meshdata->resetData();
meshdata->vertexSizeInFloat = 13 * 4; meshdata->vertexSizeInFloat = 13 * 4;
meshdata->vertex = new float[meshdata->vertexSizeInFloat]; meshdata->vertex.resize(meshdata->vertexSizeInFloat);
//dabing's data //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, // 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, // 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}; //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 = 4 * 3;
//meshdata->numIndex = 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,1,2, 0,3,1, 0,2,3, 3,2,1};
//unsigned short index[] = {0,3,2}; //unsigned short index[] = {0,3,2};
//unsigned short index[] = {0,1,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->attribCount = 4;
meshdata->attribs = new MeshVertexAttrib[meshdata->attribCount]; meshdata->attribs.resize(meshdata->attribCount);
meshdata->attribs[0].attribSizeBytes = 3 * sizeof(float); meshdata->attribs[0].attribSizeBytes = 3 * sizeof(float);
meshdata->attribs[0].size = 3; meshdata->attribs[0].size = 3;
meshdata->attribs[0].type = GL_FLOAT; meshdata->attribs[0].type = GL_FLOAT;

View File

@ -49,29 +49,26 @@ struct MeshVertexAttrib
struct MeshData struct MeshData
{ {
float* vertex; std::vector<float> vertex;
int vertexSizeInFloat; int vertexSizeInFloat;
unsigned short* indices; std::vector<unsigned short> indices;
int numIndex; int numIndex;
MeshVertexAttrib* attribs; std::vector<MeshVertexAttrib> attribs;
int attribCount; int attribCount;
public: public:
void resetData() void resetData()
{ {
CC_SAFE_DELETE_ARRAY(vertex); vertex.clear();
CC_SAFE_DELETE_ARRAY(indices); indices.clear();
CC_SAFE_DELETE_ARRAY(attribs); attribs.clear();
vertexSizeInFloat = 0; vertexSizeInFloat = 0;
numIndex = 0; numIndex = 0;
attribCount = 0; attribCount = 0;
} }
MeshData() MeshData()
: vertex(nullptr) : vertexSizeInFloat(0)
, vertexSizeInFloat(0)
, indices(nullptr)
, numIndex(0) , numIndex(0)
, attribs(nullptr)
, attribCount(0) , attribCount(0)
{ {
} }
@ -106,6 +103,7 @@ struct MaterialData
struct Animation3DData struct Animation3DData
{ {
public:
struct Vec3Key struct Vec3Key
{ {
Vec3Key() Vec3Key()
@ -142,12 +140,14 @@ struct Animation3DData
Quaternion _key; Quaternion _key;
}; };
public:
std::map<std::string, std::vector<Vec3Key>> _translationKeys; std::map<std::string, std::vector<Vec3Key>> _translationKeys;
std::map<std::string, std::vector<QuatKey>> _rotationKeys; std::map<std::string, std::vector<QuatKey>> _rotationKeys;
std::map<std::string, std::vector<Vec3Key>> _scaleKeys; std::map<std::string, std::vector<Vec3Key>> _scaleKeys;
float _totalTime; float _totalTime;
public:
Animation3DData() Animation3DData()
:_totalTime(0) :_totalTime(0)
{ {

View File

@ -118,15 +118,14 @@ bool RenderMeshData::initFrom(const std::vector<float>& positions,
return true; 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); _vertexs = vertices;
_indices.assign(indices, indices + numIndex); _indices = indices;
_vertexAttribs.assign(attribs, attribs + attribCount); _vertexAttribs = attribs;
_vertexsizeBytes = calVertexSizeBytes(); _vertexsizeBytes = calVertexSizeBytes();
return true; return true;
} }
@ -168,10 +167,10 @@ Mesh* Mesh::create(const std::vector<float>& positions, const std::vector<float>
return nullptr; 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(); 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(); mesh->autorelease();
return mesh; return mesh;
@ -190,9 +189,9 @@ bool Mesh::init(const std::vector<float>& positions, const std::vector<float>& n
return true; 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) if (!bRet)
return false; return false;

View File

@ -46,7 +46,7 @@ public:
} }
bool hasVertexAttrib(int attrib); 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 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: protected:
@ -83,7 +83,7 @@ public:
//create //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 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 //get vertex buffer
inline GLuint getVertexBuffer() const { return _vertexBuffer; } inline GLuint getVertexBuffer() const { return _vertexBuffer; }
@ -110,7 +110,7 @@ protected:
virtual ~Mesh(); 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 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 //build buffer
void buildBuffer(); void buildBuffer();