Merge pull request #11833 from super626/v3

getTriangleList to bundle and add terrain to 3d render queue
This commit is contained in:
minggo 2015-05-14 18:16:27 +08:00
commit 9f3284d62f
4 changed files with 34 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

@ -262,9 +262,9 @@ bool Terrain::initHeightMap(const char * heightMap)
Terrain::Terrain()
{
_alphaMap = nullptr;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
_customCommand.setTransparent(false);
_customCommand.set3D(true);
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
auto _backToForegroundListener = EventListenerCustom::create(EVENT_RENDERER_RECREATED,
[this](EventCustom*)
{

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,19 +694,9 @@ 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");
for (auto& it : trianglesList) {
it *= scale;
}
rbDes.mass = 0.0f;