diff --git a/cocos/3d/CCBundle3D.cpp b/cocos/3d/CCBundle3D.cpp index 22b4346aee..247cf35e29 100644 --- a/cocos/3d/CCBundle3D.cpp +++ b/cocos/3d/CCBundle3D.cpp @@ -2111,6 +2111,29 @@ Reference* Bundle3D::seekToFirstType(unsigned int type, const std::string& id) return nullptr; } +std::vector Bundle3D::getTrianglesList(const std::string& path) +{ + std::vector 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(""), diff --git a/cocos/3d/CCBundle3D.h b/cocos/3d/CCBundle3D.h index f9927eeac3..60d681931a 100644 --- a/cocos/3d/CCBundle3D.h +++ b/cocos/3d/CCBundle3D.h @@ -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 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); diff --git a/cocos/3d/CCTerrain.cpp b/cocos/3d/CCTerrain.cpp index a0236d4d5f..d8c9b13a4f 100644 --- a/cocos/3d/CCTerrain.cpp +++ b/cocos/3d/CCTerrain.cpp @@ -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*) { diff --git a/tests/cpp-tests/Classes/Physics3DTest/Physics3DTest.cpp b/tests/cpp-tests/Classes/Physics3DTest/Physics3DTest.cpp index 9a44f80a64..cb2d1e9934 100644 --- a/tests/cpp-tests/Classes/Physics3DTest/Physics3DTest.cpp +++ b/tests/cpp-tests/Classes/Physics3DTest/Physics3DTest.cpp @@ -626,20 +626,7 @@ bool Physics3DTerrainDemo::init() } //create mesh - std::vector 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 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 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 trianglesList = Bundle3D::getTrianglesList("Sprite3DTest/boss.c3b"); + for (auto& it : trianglesList) { + it *= scale; } rbDes.mass = 0.0f;