mirror of https://github.com/axmolengine/axmol.git
Merge pull request #11833 from super626/v3
getTriangleList to bundle and add terrain to 3d render queue
This commit is contained in:
commit
9f3284d62f
|
@ -2111,6 +2111,29 @@ Reference* Bundle3D::seekToFirstType(unsigned int type, const std::string& id)
|
||||||
return nullptr;
|
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()
|
Bundle3D::Bundle3D()
|
||||||
: _modelPath(""),
|
: _modelPath(""),
|
||||||
_path(""),
|
_path(""),
|
||||||
|
|
|
@ -85,6 +85,12 @@ public:
|
||||||
//since 3.3, to support reskin
|
//since 3.3, to support reskin
|
||||||
virtual bool loadMaterials(MaterialDatas& materialdatas);
|
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
|
//load .obj file
|
||||||
static bool loadObj(MeshDatas& meshdatas, MaterialDatas& materialdatas, NodeDatas& nodedatas, const std::string& fullPath, const char* mtl_basepath = nullptr);
|
static bool loadObj(MeshDatas& meshdatas, MaterialDatas& materialdatas, NodeDatas& nodedatas, const std::string& fullPath, const char* mtl_basepath = nullptr);
|
||||||
|
|
||||||
|
|
|
@ -262,9 +262,9 @@ bool Terrain::initHeightMap(const char * heightMap)
|
||||||
Terrain::Terrain()
|
Terrain::Terrain()
|
||||||
{
|
{
|
||||||
_alphaMap = nullptr;
|
_alphaMap = nullptr;
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
|
||||||
_customCommand.setTransparent(false);
|
_customCommand.setTransparent(false);
|
||||||
_customCommand.set3D(true);
|
_customCommand.set3D(true);
|
||||||
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
||||||
auto _backToForegroundListener = EventListenerCustom::create(EVENT_RENDERER_RECREATED,
|
auto _backToForegroundListener = EventListenerCustom::create(EVENT_RENDERER_RECREATED,
|
||||||
[this](EventCustom*)
|
[this](EventCustom*)
|
||||||
{
|
{
|
||||||
|
|
|
@ -626,20 +626,7 @@ bool Physics3DTerrainDemo::init()
|
||||||
}
|
}
|
||||||
|
|
||||||
//create mesh
|
//create mesh
|
||||||
std::vector<Vec3> trianglesList;
|
std::vector<Vec3> trianglesList = Bundle3D::getTrianglesList("Sprite3DTest/boss.c3b");
|
||||||
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]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rbDes.mass = 0.0f;
|
rbDes.mass = 0.0f;
|
||||||
rbDes.shape = Physics3DShape::createMesh(&trianglesList[0], (int)trianglesList.size() / 3);
|
rbDes.shape = Physics3DShape::createMesh(&trianglesList[0], (int)trianglesList.size() / 3);
|
||||||
|
@ -707,19 +694,9 @@ bool Physics3DCollisionCallbackDemo::init()
|
||||||
Physics3DRigidBodyDes rbDes;
|
Physics3DRigidBodyDes rbDes;
|
||||||
|
|
||||||
float scale = 2.0f;
|
float scale = 2.0f;
|
||||||
std::vector<Vec3> trianglesList;
|
std::vector<Vec3> trianglesList = Bundle3D::getTrianglesList("Sprite3DTest/boss.c3b");
|
||||||
auto bundle = Bundle3D::createBundle();
|
for (auto& it : trianglesList) {
|
||||||
bundle->load("Sprite3DTest/boss.c3b");
|
it *= scale;
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rbDes.mass = 0.0f;
|
rbDes.mass = 0.0f;
|
||||||
|
|
Loading…
Reference in New Issue