# Fbx SDK Importer issue (texture / uv related)

I am using the latest autodesk FBX Importer SDK, but whatever I do, I am unable to get the uvs right. Some parts are textured properly while others are not.

I am using Direct3D9 and Direct3D11 (same result in both).

Image:

The model uses a single texture and a single material shared among 4 meshes.

Is there someone who sees immediately what the problem could be? Or is there someone who can replicate the issue for me and figure out what I am missing?

FBX Test File: http://www.4shared.com/rar/o_WG0Crpce/Peach64FBX.html

int vertexCounter = 0;
for (int j = 0; j < nbPolygons; j++) {

for (int k = 0; k < 3; k++) {

int vertexIndex = pFbxMesh->GetPolygonVertex(j, k);

Vector2 uv;

pVertices[vertexIndex].uv.x = uv.x;
pVertices[vertexIndex].uv.y = 1.0 - uv.y;
vertexCounter++;
}
}

void _readUV(fbxsdk::FbxMesh* pFbxMesh, int vertexIndex, int uvIndex, Vector2& uv) {

fbxsdk::FbxLayerElementUV *pFbxLayerElementUV = pFbxMesh->GetLayer(0)->GetUVs();

if (pFbxLayerElementUV == nullptr) {
return;
}

switch (pFbxLayerElementUV->GetMappingMode()) {

case FbxLayerElementUV::eByControlPoint:
{
switch (pFbxLayerElementUV->GetReferenceMode()) {

case FbxLayerElementUV::eDirect:
{
fbxsdk::FbxVector2 fbxUv = pFbxLayerElementUV->GetDirectArray().GetAt(vertexIndex);

uv.x = fbxUv.mData[0];
uv.y = fbxUv.mData[1];

break;
}

case FbxLayerElementUV::eIndexToDirect:
{
int id = pFbxLayerElementUV->GetIndexArray().GetAt(vertexIndex);
fbxsdk::FbxVector2 fbxUv = pFbxLayerElementUV->GetDirectArray().GetAt(id);

uv.x = fbxUv.mData[0];
uv.y = fbxUv.mData[1];

break;
}
}

break;
}

case FbxLayerElementUV::eByPolygonVertex:
{

switch (pFbxLayerElementUV->GetReferenceMode()) {

// Always enters this part for the example model
case FbxLayerElementUV::eDirect:
case FbxLayerElementUV::eIndexToDirect:
{

uv.x = pFbxLayerElementUV->GetDirectArray().GetAt(uvIndex).mData[0];
uv.y = pFbxLayerElementUV->GetDirectArray().GetAt(uvIndex).mData[1];

break;
}
}

break;
}
}
}


I am doing V = 1.0 - uv.y because I am using Direct3D11.

NOTE: the MappingMode is always eByPolygonVertex and ReferenceMode is always eIndexToDirect

• Rendering Info:
• Rendered as a Triangle List
• Uv wrapping mode: Wrap (Repeat)
• Culling: None
• I'm no fbx sdk expert but shouldn't you be looping over pFbxLayerElementUV->GetIndexArray() and seeing which index matches vertexIndex, then use the matching loop counter to index into the direct array? – Syntac_ Feb 17 '17 at 9:53
• Ignore that, misread which mapping mode it was using. Try passing uvIndex as j * 3 + k. – Syntac_ Feb 17 '17 at 10:00
• Thanks for your reply. I tried it, but the model turns mostly gray with that. – Joey Muiser Feb 17 '17 at 10:26
• For the eIndexToDirect case you still need to access via the index array first. – Syntac_ Feb 17 '17 at 10:35
• I found that some vertices shared among different faces use different uvs in different faces. For example the vertex in face one has UV coordinates (0.5, 0.5) and the same vertex in face two uses UV coordinates (0.25, 0.25). I think I should be splitting the vertex.. I wonder if the FBX SDK has a function for this. – Joey Muiser Feb 17 '17 at 17:44