From ceb834b8d40ac19832cd0ef1440a0d6e8f8f9b39 Mon Sep 17 00:00:00 2001 From: songchengjiang Date: Wed, 24 Dec 2014 10:12:31 +0800 Subject: [PATCH] read AABB from file(v0.6+) --- cocos/3d/CCBundle3D.cpp | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/cocos/3d/CCBundle3D.cpp b/cocos/3d/CCBundle3D.cpp index bd2d7df862..2369314274 100644 --- a/cocos/3d/CCBundle3D.cpp +++ b/cocos/3d/CCBundle3D.cpp @@ -87,6 +87,7 @@ static const char* TRANSLATION = "translation"; static const char* ROTATION = "rotation"; static const char* SCALE = "scale"; static const char* KEYTIME = "keytime"; +static const char* AABBS = "aabb"; NS_CC_BEGIN @@ -439,7 +440,22 @@ bool Bundle3D::loadMeshDatasBinary(MeshDatas& meshdatas) } meshData->subMeshIndices.push_back(indexArray); meshData->numIndex = (int)meshData->subMeshIndices.size(); - meshData->subMeshAABB.push_back(calculateAABB(meshData->vertex, meshData->getPerVertexSize(), indexArray)); + //meshData->subMeshAABB.push_back(calculateAABB(meshData->vertex, meshData->getPerVertexSize(), indexArray)); + if (_version != "0.3" && _version != "0.4" && _version != "0.5") + { + //read mesh aabb + float aabb[6]; + if (_binaryReader.read(aabb, 4, 6) != 6) + { + CCLOG("warning: Failed to read meshdata: aabb '%s'.", _path.c_str()); + return false; + } + meshData->subMeshAABB.push_back(AABB(Vec3(aabb[0], aabb[1], aabb[2]), Vec3(aabb[3], aabb[4], aabb[5]))); + } + else + { + meshData->subMeshAABB.push_back(calculateAABB(meshData->vertex, meshData->getPerVertexSize(), indexArray)); + } } meshdatas.meshDatas.push_back(meshData); } @@ -718,7 +734,19 @@ bool Bundle3D::loadMeshDatasJson(MeshDatas& meshdatas) meshData->subMeshIndices.push_back(indexArray); meshData->numIndex = (int)meshData->subMeshIndices.size(); - meshData->subMeshAABB.push_back(calculateAABB(meshData->vertex, meshData->getPerVertexSize(), indexArray)); + + //meshData->subMeshAABB.push_back(calculateAABB(meshData->vertex, meshData->getPerVertexSize(), indexArray)); + const rapidjson::Value& mesh_part_aabb = mesh_part[AABBS]; + if (mesh_part.HasMember(AABBS) && mesh_part_aabb.Size() == 6) + { + Vec3 min = Vec3(mesh_part_aabb[(rapidjson::SizeType)0].GetDouble(), mesh_part_aabb[(rapidjson::SizeType)1].GetDouble(), mesh_part_aabb[(rapidjson::SizeType)2].GetDouble()); + Vec3 max = Vec3(mesh_part_aabb[(rapidjson::SizeType)3].GetDouble(), mesh_part_aabb[(rapidjson::SizeType)4].GetDouble(), mesh_part_aabb[(rapidjson::SizeType)5].GetDouble()); + meshData->subMeshAABB.push_back(AABB(min, max)); + } + else + { + meshData->subMeshAABB.push_back(calculateAABB(meshData->vertex, meshData->getPerVertexSize(), indexArray)); + } } meshdatas.meshDatas.push_back(meshData); }