Skip to content

Commit 460bc2b

Browse files
committed
move aabb calculation to bundle
1 parent 17e4598 commit 460bc2b

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

cocos/3d/CCBundle3D.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ bool Bundle3D::loadObj(MeshDatas& meshdatas, MaterialDatas& materialdatas, NodeD
291291
materialdatas.materials.push_back(materialdata);
292292

293293
meshdata->subMeshIndices.push_back(it.mesh.indices);
294+
meshdata->subMeshAABB.push_back(calculateAABB(meshdata->vertex, meshdata->getPerVertexSize(), it.mesh.indices));
294295
meshdata->subMeshIds.push_back(str);
295296
auto node = new (std::nothrow) NodeData();
296297
auto modelnode = new (std::nothrow) ModelData();
@@ -438,6 +439,7 @@ bool Bundle3D::loadMeshDatasBinary(MeshDatas& meshdatas)
438439
}
439440
meshData->subMeshIndices.push_back(indexArray);
440441
meshData->numIndex = (int)meshData->subMeshIndices.size();
442+
meshData->subMeshAABB.push_back(calculateAABB(meshData->vertex, meshData->getPerVertexSize(), indexArray));
441443
}
442444
meshdatas.meshDatas.push_back(meshData);
443445
}
@@ -545,6 +547,7 @@ bool Bundle3D::loadMeshDatasBinary_0_1(MeshDatas& meshdatas)
545547
}
546548

547549
meshdata->subMeshIndices.push_back(indices);
550+
meshdata->subMeshAABB.push_back(calculateAABB(meshdata->vertex, meshdata->getPerVertexSize(), indices));
548551
}
549552

550553
meshdatas.meshDatas.push_back(meshdata);
@@ -659,6 +662,7 @@ bool Bundle3D::loadMeshDatasBinary_0_2(MeshDatas& meshdatas)
659662
}
660663

661664
meshdata->subMeshIndices.push_back(indices);
665+
meshdata->subMeshAABB.push_back(calculateAABB(meshdata->vertex, meshdata->getPerVertexSize(), indices));
662666
}
663667

664668
meshdatas.meshDatas.push_back(meshdata);
@@ -714,6 +718,7 @@ bool Bundle3D::loadMeshDatasJson(MeshDatas& meshdatas)
714718

715719
meshData->subMeshIndices.push_back(indexArray);
716720
meshData->numIndex = (int)meshData->subMeshIndices.size();
721+
meshData->subMeshAABB.push_back(calculateAABB(meshData->vertex, meshData->getPerVertexSize(), indexArray));
717722
}
718723
meshdatas.meshDatas.push_back(meshData);
719724
}
@@ -1080,6 +1085,7 @@ bool Bundle3D::loadMeshDataJson_0_1(MeshDatas& meshdatas)
10801085
indices[i] = (unsigned short)indices_val_array[i].GetUint();
10811086

10821087
meshdata->subMeshIndices.push_back(indices);
1088+
meshdata->subMeshAABB.push_back(calculateAABB(meshdata->vertex, meshdata->getPerVertexSize(), indices));
10831089
meshdatas.meshDatas.push_back(meshdata);
10841090
return true;
10851091
}
@@ -1134,6 +1140,7 @@ bool Bundle3D::loadMeshDataJson_0_2(MeshDatas& meshdatas)
11341140
indices[j] = (unsigned short)indices_val_array[j].GetUint();
11351141

11361142
meshdata->subMeshIndices.push_back(indices);
1143+
meshdata->subMeshAABB.push_back(calculateAABB(meshdata->vertex, meshdata->getPerVertexSize(), indices));
11371144
}
11381145
meshdatas.meshDatas.push_back(meshdata);
11391146
return true;
@@ -1996,4 +2003,16 @@ Bundle3D::~Bundle3D()
19962003

19972004
}
19982005

2006+
cocos2d::AABB Bundle3D::calculateAABB( const std::vector<float>& vertex, int stride, const std::vector<unsigned short>& index )
2007+
{
2008+
AABB aabb;
2009+
stride /= 4;
2010+
for(const auto& it : index)
2011+
{
2012+
Vec3 point = Vec3(vertex[it * stride ], vertex[ it * stride + 1], vertex[it * stride + 2 ]);
2013+
aabb.updateMinMax(&point, 1);
2014+
}
2015+
return aabb;
2016+
}
2017+
19992018
NS_CC_END

cocos/3d/CCBundle3D.h

+2
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ class CC_DLL Bundle3D
154154
Bundle3D();
155155
virtual ~Bundle3D();
156156

157+
static AABB calculateAABB(const std::vector<float>& vertex, int stride, const std::vector<unsigned short>& index);
158+
157159
protected:
158160
static Bundle3D* _instance;
159161
std::string _modelPath;

cocos/3d/CCMeshVertexIndexData.cpp

-12
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,6 @@ MeshVertexData* MeshVertexData::create(const MeshData& meshdata)
117117
return vertexdata;
118118
}
119119

120-
AABB MeshVertexData::calculateAABB(const std::vector<float>& vertex, int stride, const std::vector<unsigned short>& index)
121-
{
122-
AABB aabb;
123-
stride /= 4;
124-
for(const auto& it : index)
125-
{
126-
Vec3 point = Vec3(vertex[it * stride ], vertex[ it * stride + 1], vertex[it * stride + 2 ]);
127-
aabb.updateMinMax(&point, 1);
128-
}
129-
return aabb;
130-
}
131-
132120
MeshIndexData* MeshVertexData::getMeshIndexDataById(const std::string& id) const
133121
{
134122
for (auto it : _indexs) {

cocos/3d/CCMeshVertexIndexData.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ class MeshVertexData : public Ref
114114
CC_CONSTRUCTOR_ACCESS:
115115
MeshVertexData();
116116
virtual ~MeshVertexData();
117-
118-
static AABB calculateAABB(const std::vector<float>& vertex, int stride, const std::vector<unsigned short>& index);
117+
119118
protected:
120119
VertexData* _vertexData; //mesh vertex data
121120
VertexBuffer* _vertexBuffer; // vertex buffer

0 commit comments

Comments
 (0)