FBX File import now re-orders vertices and batches all materials together to reduce draw calls
--HG-- extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%4020
This commit is contained in:
@@ -279,7 +279,8 @@ void LoadMesh(std::vector<KRResource *> &resources, KFbxGeometryConverter *pGeom
|
||||
int uv_count = pMesh->GetElementUVCount();
|
||||
int normal_count = pMesh->GetElementNormalCount();
|
||||
int tangent_count = pMesh->GetElementTangentCount();
|
||||
int material_count = pMesh->GetElementMaterialCount();
|
||||
int elementmaterial_count = pMesh->GetElementMaterialCount();
|
||||
int material_count = pNode->GetMaterialCount();
|
||||
|
||||
|
||||
printf(" Polygon Count: %i (before triangulation: %i)\n", polygon_count, pSourceMesh->GetPolygonCount());
|
||||
@@ -293,14 +294,12 @@ void LoadMesh(std::vector<KRResource *> &resources, KFbxGeometryConverter *pGeom
|
||||
std::vector<int> submesh_starts;
|
||||
std::vector<std::string> material_names;
|
||||
|
||||
|
||||
int source_vertex_id = 0;
|
||||
int dest_vertex_id = 0;
|
||||
KFbxGeometryElementMaterial* pMaterial = NULL;
|
||||
int iMaterial = -1;
|
||||
int mat_vertex_count = 0;
|
||||
int mat_vertex_start = 0;
|
||||
|
||||
for(int iMaterial=0; iMaterial < material_count; iMaterial++) {
|
||||
int source_vertex_id = 0;
|
||||
int mat_vertex_count = 0;
|
||||
int mat_vertex_start = dest_vertex_id;
|
||||
for(int iPolygon = 0; iPolygon < polygon_count; iPolygon++) {
|
||||
int lPolygonSize = pMesh->GetPolygonSize(iPolygon);
|
||||
if(lPolygonSize != 3) {
|
||||
@@ -308,38 +307,21 @@ void LoadMesh(std::vector<KRResource *> &resources, KFbxGeometryConverter *pGeom
|
||||
printf(" Warning - Poly with %i vertices found. Expecting only triangles.", lPolygonSize);
|
||||
} else {
|
||||
// ----====---- Read SubMesh / Material Mapping ----====----
|
||||
int iPrevMat = iMaterial;
|
||||
KFbxGeometryElementMaterial *pPrevMat = pMaterial;
|
||||
iMaterial = -1;
|
||||
pMaterial = NULL;
|
||||
for (int l = 0; l < material_count; l++)
|
||||
int iNewMaterial = -1;
|
||||
for (int l = 0; l < elementmaterial_count; l++)
|
||||
{
|
||||
KFbxGeometryElementMaterial* leMat = pMesh->GetElementMaterial(l);
|
||||
if(leMat) {
|
||||
if (leMat->GetReferenceMode() == KFbxGeometryElement::eINDEX || leMat->GetReferenceMode() == KFbxGeometryElement::eINDEX_TO_DIRECT) {
|
||||
int new_id = leMat->GetIndexArray().GetAt(iPolygon);
|
||||
if(new_id >= 0) {
|
||||
iMaterial = new_id;
|
||||
pMaterial = leMat;
|
||||
iNewMaterial = new_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(iMaterial != iPrevMat) {
|
||||
if(pPrevMat && mat_vertex_count) {
|
||||
submesh_starts.push_back(mat_vertex_start);
|
||||
submesh_lengths.push_back(mat_vertex_count);
|
||||
material_names.push_back(pNode->GetMaterial(iMaterial)->GetName());
|
||||
printf(" Material \"%s\" from %i to %i\n", pNode->GetMaterial(iMaterial)->GetName(), mat_vertex_start, mat_vertex_count + mat_vertex_start - 1);
|
||||
}
|
||||
|
||||
mat_vertex_count = 0;
|
||||
mat_vertex_start = dest_vertex_id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(iMaterial == iNewMaterial) {
|
||||
// ----====---- Read Vertex-level Attributes ----====----
|
||||
for(int iVertex=0; iVertex<3; iVertex++) {
|
||||
// ----====---- Read Vertex Position ----====----
|
||||
@@ -464,14 +446,18 @@ void LoadMesh(std::vector<KRResource *> &resources, KFbxGeometryConverter *pGeom
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ----====---- Complete last material / submesh ----====----
|
||||
if(iMaterial >= 0 && mat_vertex_count) {
|
||||
// ----====---- Output last material / submesh details ----====----
|
||||
if(mat_vertex_count) {
|
||||
submesh_starts.push_back(mat_vertex_start);
|
||||
submesh_lengths.push_back(mat_vertex_count);
|
||||
material_names.push_back(pNode->GetMaterial(iMaterial)->GetName());
|
||||
printf(" Material \"%s\" from %i to %i\n", pNode->GetMaterial(iMaterial)->GetName(), mat_vertex_start, mat_vertex_count + mat_vertex_start - 1);
|
||||
printf(" %s: %i - %i\n", pNode->GetMaterial(iMaterial)->GetName(), mat_vertex_start, mat_vertex_count + mat_vertex_start - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ----====---- Generate Output Mesh Object ----====----
|
||||
|
||||
Reference in New Issue
Block a user