I have a problem with the FBX SDK. I read in the data for the vertex position and the UV coordinates. It works fine, but now I want to read for each polygon to which texture it belongs, so that I can have models with multiple textures. Can anyone tell me how I can get the texture file name for my polygon? My code to read in vertex position and uv coordinates is the following:
int i, j, lPolygonCount = pMesh->GetPolygonCount();
FbxVector4* lControlPoints = pMesh->GetControlPoints();
int vertexId = 0;
for (i = 0; i < lPolygonCount; i++)
{
int lPolygonSize = pMesh->GetPolygonSize(i);
for (j = 0; j < lPolygonSize; j++)
{
int lControlPointIndex = pMesh->GetPolygonVertex(i, j);
FbxVector4 pos = lControlPoints[lControlPointIndex];
current_model[vertex_index].x = pos.mData[0] - pivot_offset[0];
current_model[vertex_index].y = pos.mData[1] - pivot_offset[1];
current_model[vertex_index].z = pos.mData[2]- pivot_offset[2];
FbxVector4 vertex_normal;
pMesh->GetPolygonVertexNormal(i,j, vertex_normal);
current_model[vertex_index].nx = vertex_normal.mData[0];
current_model[vertex_index].ny = vertex_normal.mData[1];
current_model[vertex_index].nz = vertex_normal.mData[2];
//read in UV data
FbxStringList lUVSetNameList;
pMesh->GetUVSetNames(lUVSetNameList);
//get lUVSetIndex-th uv set
const char* lUVSetName = lUVSetNameList.GetStringAt(0);
const FbxGeometryElementUV* lUVElement = pMesh->GetElementUV(lUVSetName);
if(!lUVElement)
continue;
// only support mapping mode eByPolygonVertex and eByControlPoint
if( lUVElement->GetMappingMode() != FbxGeometryElement::eByPolygonVertex &&
lUVElement->GetMappingMode() != FbxGeometryElement::eByControlPoint )
return;
//index array, where holds the index referenced to the uv data
const bool lUseIndex
= lUVElement->GetReferenceMode() != FbxGeometryElement::eDirect;
const int lIndexCount= (lUseIndex) ? lUVElement->GetIndexArray().GetCount() : 0;
FbxVector2 lUVValue;
//get the index of the current vertex in control points array
int lPolyVertIndex = pMesh->GetPolygonVertex(i,j);
//the UV index depends on the reference mode
int lUVIndex = pMesh->GetTextureUVIndex(i, j);
lUVValue = lUVElement->GetDirectArray().GetAt(lUVIndex);
current_model[vertex_index].tu = (float)lUVValue.mData[0];
current_model[vertex_index].tv = (float)lUVValue.mData[1];
vertex_index ++;
}
}
float v1[3], v2[3], v3[3];
v1[0] = current_model[vertex_index - 3].x;
v1[1] = current_model[vertex_index - 3].y;
v1[2] = current_model[vertex_index - 3].z;
v2[0] = current_model[vertex_index - 2].x;
v2[1] = current_model[vertex_index - 2].y;
v2[2] = current_model[vertex_index - 2].z;
v3[0] = current_model[vertex_index - 1].x;
v3[1] = current_model[vertex_index - 1].y;
v3[2] = current_model[vertex_index - 1].z;
collision_model->addTriangle(v1,v2,v3);
No comments:
Post a Comment