diff --git a/cocos/3d/CCBundle3D.cpp b/cocos/3d/CCBundle3D.cpp index cb6ae9562e..2af3a8307e 100644 --- a/cocos/3d/CCBundle3D.cpp +++ b/cocos/3d/CCBundle3D.cpp @@ -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; diff --git a/cocos/3d/CCBundle3DData.h b/cocos/3d/CCBundle3DData.h index 8a907d3c20..ae2dbe1a1b 100644 --- a/cocos/3d/CCBundle3DData.h +++ b/cocos/3d/CCBundle3DData.h @@ -49,29 +49,26 @@ struct MeshVertexAttrib struct MeshData { - float* vertex; + std::vector vertex; int vertexSizeInFloat; - unsigned short* indices; + std::vector indices; int numIndex; - MeshVertexAttrib* attribs; + std::vector 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() @@ -141,13 +139,15 @@ struct Animation3DData float _time; Quaternion _key; }; - + +public: std::map> _translationKeys; std::map> _rotationKeys; std::map> _scaleKeys; float _totalTime; - + +public: Animation3DData() :_totalTime(0) { diff --git a/cocos/3d/CCMesh.cpp b/cocos/3d/CCMesh.cpp index 467f2c88ef..433476a3eb 100644 --- a/cocos/3d/CCMesh.cpp +++ b/cocos/3d/CCMesh.cpp @@ -118,15 +118,14 @@ bool RenderMeshData::initFrom(const std::vector& 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& vertices, int vertexSizeInFloat, const std::vector& indices, int numIndex, const std::vector& 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& positions, const std::vector 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 &vertices, int vertexSizeInFloat, const std::vector &indices, int numIndex, const std::vector &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& positions, const std::vector& 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& vertices, int vertexSizeInFloat, const std::vector& indices, int numIndex, const std::vector& 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; diff --git a/cocos/3d/CCMesh.h b/cocos/3d/CCMesh.h index 775f1c9118..ca4f5a310f 100644 --- a/cocos/3d/CCMesh.h +++ b/cocos/3d/CCMesh.h @@ -46,7 +46,7 @@ public: } bool hasVertexAttrib(int attrib); bool initFrom(const std::vector& positions, const std::vector& normals, const std::vector& texs, const std::vector& indices); - bool initFrom(const float* vertex, int vertexSizeInFloat, unsigned short* indices, int numIndex, const MeshVertexAttrib* attribs, int attribCount); + bool initFrom(const std::vector& vertices, int vertexSizeInFloat, const std::vector& indices, int numIndex, const std::vector& attribs, int attribCount); protected: @@ -83,7 +83,7 @@ public: //create static Mesh* create(const std::vector& positions, const std::vector& normals, const std::vector& texs, const std::vector& 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& vertices, int vertexSizeInFloat, const std::vector& indices, int numIndex, const std::vector& attribs, int attribCount); //get vertex buffer inline GLuint getVertexBuffer() const { return _vertexBuffer; } @@ -110,7 +110,7 @@ protected: virtual ~Mesh(); bool init(const std::vector& positions, const std::vector& normals, const std::vector& texs, const std::vector& indices); - bool init(const float* vertex, int vertexSizeInFloat, unsigned short* indices, int numIndex, const MeshVertexAttrib* attribs, int attribCount); + bool init(const std::vector& vertices, int vertexSizeInFloat, const std::vector& indices, int numIndex, const std::vector& attribs, int attribCount); //build buffer void buildBuffer();