0
\$\begingroup\$

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:

360 image: https://i.gyazo.com/5a2e5f6e127521915508c9c300eb03e5.mp4

https://i.gyazo.com/6b37c0525f8fe42b9b54a5e79ec354fa.png

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

My UV reading method:

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;
        _readUV(pFbxMesh, vertexIndex, pFbxMesh->GetTextureUVIndex(j, k), 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
\$\endgroup\$
5
  • \$\begingroup\$ 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? \$\endgroup\$
    – Syntac_
    Commented Feb 17, 2017 at 9:53
  • \$\begingroup\$ Ignore that, misread which mapping mode it was using. Try passing uvIndex as j * 3 + k. \$\endgroup\$
    – Syntac_
    Commented Feb 17, 2017 at 10:00
  • \$\begingroup\$ Thanks for your reply. I tried it, but the model turns mostly gray with that. \$\endgroup\$ Commented Feb 17, 2017 at 10:26
  • \$\begingroup\$ For the eIndexToDirect case you still need to access via the index array first. \$\endgroup\$
    – Syntac_
    Commented Feb 17, 2017 at 10:35
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Feb 17, 2017 at 17:44

1 Answer 1

1
\$\begingroup\$

The solution was to split the vertices.

enter image description here

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Could you elaborate? (and mark your answer as accepted :) ) \$\endgroup\$
    – Casey
    Commented Oct 24, 2018 at 22:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .