mirror of https://github.com/axmolengine/axmol.git
calculate aabb if not exist
This commit is contained in:
parent
a76e2e430d
commit
a1ec27d0b1
|
@ -79,6 +79,9 @@ public:
|
|||
|
||||
//load .obj file
|
||||
static bool loadObj(MeshDatas& meshdatas, MaterialDatas& materialdatas, NodeDatas& nodedatas, const std::string& fullPath, const char* mtl_basepath = nullptr);
|
||||
|
||||
//calculate aabb
|
||||
static AABB calculateAABB(const std::vector<float>& vertex, int stride, const std::vector<unsigned short>& index);
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -154,8 +157,6 @@ CC_CONSTRUCTOR_ACCESS:
|
|||
Bundle3D();
|
||||
virtual ~Bundle3D();
|
||||
|
||||
static AABB calculateAABB(const std::vector<float>& vertex, int stride, const std::vector<unsigned short>& index);
|
||||
|
||||
protected:
|
||||
static Bundle3D* _instance;
|
||||
std::string _modelPath;
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "3d/CCObjLoader.h"
|
||||
#include "3d/CCSprite3DMaterial.h"
|
||||
#include "3d/CCMesh.h"
|
||||
#include "3d/CCBundle3D.h"
|
||||
|
||||
#include "base/ccMacros.h"
|
||||
#include "base/CCEventCustom.h"
|
||||
|
@ -102,14 +103,22 @@ MeshVertexData* MeshVertexData::create(const MeshData& meshdata)
|
|||
vertexdata->_vertexBuffer->updateVertices((void*)&meshdata.vertex[0], (int)meshdata.vertex.size() * 4 / vertexdata->_vertexBuffer->getSizePerVertex(), 0);
|
||||
}
|
||||
|
||||
|
||||
bool needCalcAABB = (meshdata.subMeshAABB.size() != meshdata.subMeshIndices.size());
|
||||
for (size_t i = 0; i < meshdata.subMeshIndices.size(); i++) {
|
||||
|
||||
auto& index = meshdata.subMeshIndices[i];
|
||||
auto indexBuffer = IndexBuffer::create(IndexBuffer::IndexType::INDEX_TYPE_SHORT_16, (int)(index.size()));
|
||||
indexBuffer->updateIndices(&index[0], (int)index.size(), 0);
|
||||
std::string id = (i < meshdata.subMeshIds.size() ? meshdata.subMeshIds[i] : "");
|
||||
MeshIndexData* indexdata = MeshIndexData::create(id, vertexdata, indexBuffer, meshdata.subMeshAABB[i]);
|
||||
MeshIndexData* indexdata = nullptr;
|
||||
if (needCalcAABB)
|
||||
{
|
||||
auto aabb = Bundle3D::calculateAABB(meshdata.vertex, meshdata.getPerVertexSize(), index);
|
||||
indexdata = MeshIndexData::create(id, vertexdata, indexBuffer, aabb);
|
||||
}
|
||||
else
|
||||
indexdata = MeshIndexData::create(id, vertexdata, indexBuffer, meshdata.subMeshAABB[i]);
|
||||
|
||||
vertexdata->_indexs.pushBack(indexdata);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue