add getTriangleList to bundle

This commit is contained in:
yangxiao 2015-05-14 10:30:20 +08:00
parent 0f0f85b33c
commit e659373648
3 changed files with 31 additions and 28 deletions

View File

@ -2111,6 +2111,29 @@ Reference* Bundle3D::seekToFirstType(unsigned int type, const std::string& id)
return nullptr;
}
std::vector<Vec3> Bundle3D::getTrianglesList(const std::string& path)
{
std::vector<Vec3> trianglesList;
auto bundle = Bundle3D::createBundle();
if (!bundle->load(path))
{
Bundle3D::destroyBundle(bundle);
return trianglesList;
}
MeshDatas meshs;
bundle->loadMeshDatas(meshs);
Bundle3D::destroyBundle(bundle);
for (auto iter : meshs.meshDatas){
int preVertexSize = iter->getPerVertexSize() / sizeof(float);
for (auto indexArray : iter->subMeshIndices){
for (auto i : indexArray){
trianglesList.push_back(Vec3(iter->vertex[i * preVertexSize], iter->vertex[i * preVertexSize + 1], iter->vertex[i * preVertexSize + 2]));
}
}
}
return trianglesList;
}
Bundle3D::Bundle3D()
: _modelPath(""),
_path(""),

View File

@ -85,6 +85,12 @@ public:
//since 3.3, to support reskin
virtual bool loadMaterials(MaterialDatas& materialdatas);
/**
* load triangle list
* @param path the file path to load
*/
static std::vector<Vec3> getTrianglesList(const std::string& path);
//load .obj file
static bool loadObj(MeshDatas& meshdatas, MaterialDatas& materialdatas, NodeDatas& nodedatas, const std::string& fullPath, const char* mtl_basepath = nullptr);

View File

@ -626,20 +626,7 @@ bool Physics3DTerrainDemo::init()
}
//create mesh
std::vector<Vec3> trianglesList;
auto bundle = Bundle3D::createBundle();
bundle->load("Sprite3DTest/boss.c3b");
MeshDatas meshs;
bundle->loadMeshDatas(meshs);
Bundle3D::destroyBundle(bundle);
for (auto iter : meshs.meshDatas){
int preVertexSize = iter->getPerVertexSize() / sizeof(float);
for (auto indexArray : iter->subMeshIndices){
for (auto i : indexArray){
trianglesList.push_back(Vec3(iter->vertex[i * preVertexSize], iter->vertex[i * preVertexSize + 1], iter->vertex[i * preVertexSize + 2]));
}
}
}
std::vector<Vec3> trianglesList = Bundle3D::getTrianglesList("Sprite3DTest/boss.c3b");
rbDes.mass = 0.0f;
rbDes.shape = Physics3DShape::createMesh(&trianglesList[0], (int)trianglesList.size() / 3);
@ -707,20 +694,7 @@ bool Physics3DCollisionCallbackDemo::init()
Physics3DRigidBodyDes rbDes;
float scale = 2.0f;
std::vector<Vec3> trianglesList;
auto bundle = Bundle3D::createBundle();
bundle->load("Sprite3DTest/boss.c3b");
MeshDatas meshs;
bundle->loadMeshDatas(meshs);
Bundle3D::destroyBundle(bundle);
for (auto iter : meshs.meshDatas){
int preVertexSize = iter->getPerVertexSize() / sizeof(float);
for (auto indexArray : iter->subMeshIndices){
for (auto i : indexArray){
trianglesList.push_back(Vec3(iter->vertex[i * preVertexSize], iter->vertex[i * preVertexSize + 1], iter->vertex[i * preVertexSize + 2]) * scale);
}
}
}
std::vector<Vec3> trianglesList = Bundle3D::getTrianglesList("Sprite3DTest/boss.c3b");
rbDes.mass = 0.0f;
rbDes.shape = Physics3DShape::createMesh(&trianglesList[0], (int)trianglesList.size() / 3);