Community
FBX Forum
Welcome to Autodesk’s FBX Forums. Share your knowledge, ask questions, and explore popular FBX topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Split UV per Control Point

8 REPLIES 8
Reply
Message 1 of 9
Anonymous
1613 Views, 8 Replies

Split UV per Control Point

Hello Everyone,
I export a scene with multiple mesh from maya.
I’m faced a problem when import this scene with FBX SDK because my game engine supports only UV coord per CP(not by polygon vertex).


Can someone tell me how can I split the UVs per CP?
Since now I have one material per mesh and I don't need anymore UV mapping per face.

Any help will be appreciated
Thanks in advance
8 REPLIES 8
Message 2 of 9
Anonymous
in reply to: Anonymous

Hello nasboy3d,

If I undersand your question correctly, you can try and use the "SplitMeshesPerMaterial" function. This function will look through your scene and for each material, it will split the meshes and in turn split the uv's.

If this doesn't help you, can you please write back and give more detail in your question? Your scene has mulitple meshes, does that mean each mesh has it's own unique uv? Or, do all the meshes share one uv map? What is the end goal you would like to see in your game engine? Have you tried a test with only 1 mesh to see what can happen?

Regards,
Carlos
Message 3 of 9
Anonymous
in reply to: Anonymous

Thanks CarlosC for your reply
I have found a solution.
- First use function SplitMeshesPerMaterial on a mesh which have material mapping per face :
This yield multiple sub-meshes. But this is not enought. You still get UV coord per plygone vertex

- After use function Mesh::SplitPoints on each sub-mesh (only sub-mesh) to have UV coord per vertex

And you're done.
Message 4 of 9
Anonymous
in reply to: Anonymous

Excellent, I am happy to hear you found a solution.

If you have anymore questions please let us know.

Regards,
Carlos
Message 5 of 9
Anonymous
in reply to: Anonymous

HI everyone
I'm here again beacuse the solution I've found is not efficient at all.
The function KFbxMesh::SplitPoints only duplicate the control points (CP) and then the indices array become useless.

-Before applyng SplitPoints
CP array size = 1900
Indices array size = 10992
UV array size = 10992

-After applyng SplitPoints
CP array size = 10992
Indices array size = 10992
UV array size = 10992

Can someone give me a more efficient solution ?
Since I have one material per mesh I think I can get UV coord per CP without problemm but I don't know how to do that
Message 6 of 9
Anonymous
in reply to: Anonymous

Hi again nasboy3d,

Just wanted to give you an update, our main dev is looking into your problem, I will get back to you soon with an update.

Regards,
Carlos
Message 7 of 9
Anonymous
in reply to: Anonymous

That's good news
Thanks Carlos
Message 8 of 9
Anonymous
in reply to: Anonymous

Hi nasboy3d,

I heard back from the dev, here is his answer:

The FBX SDK does not provide a re-mapping function for this particular purpose. You will need to write one yourself (most likely after you loaded the file and before sending the data to your device). The code below is a possible example. Note that it simply shows how to access and modify the data but the algorithm may not work as you expect. No testing has been performed and the code is provided simply as a guide line.

for (int i = 0; i < lScene->GetSrcObjectCount(FbxMesh::ClassId); i++)
{
FbxMesh* lMesh = (FbxMesh*)lScene->GetSrcObject(FbxMesh::ClassId, i);
FbxLayerElementUV* lUVs = lMesh->GetLayer(0)->GetUVs();
ConvertMapping(lUVs, lMesh);
}

void ConvertMapping(FbxLayerElementUV* pUVs, FbxMesh* pMesh)
{
if (pUVs->GetMappingMode() == FbxLayerElement::eByPolygonVertex)
{
if (pUVs->GetReferenceMode() == FbxLayerElement::eIndexToDirect)
{
FbxArray<int> lNewIndexToDirect;
FbxArray<FbxVector2> lNewUVs;

// keep track of the processed control points
FbxSet lProcessedCP(pMesh->GetControlPointsCount());
for (int i = 0; i < pMesh->GetControlPointsCount(); i++)
lProcessedCP.Add((FbxHandle)i, (FbxHandle)false);

// visit each polygon and polygon vertex
for (int p = 0; p < pMesh->GetPolygonCount(); p++)
{
for (int pv = 0; pv < pMesh->GetPolygonSize(p); pv++)
{
int lCP = pMesh->GetPolygonVertex(p, pv);

// check if we already processed this control point
if (lProcessedCP.Get((FbxHandle)lCP) == 0)
{
FbxVector2 uv = pUVs->GetDirectArray().GetAt(lCP);
lNewUVs.Add(uv);
lNewIndexToDirect.Add(lCP);
lProcessedCP.SetItem((FbxHandle)lCP, (FbxHandle)true);
}
}
}

// change the content of the index array and its mapping
pUVs->SetMappingMode(FbxLayerElement::eByControlPoint);
pUVs->GetIndexArray().Clear();
pUVs->GetIndexArray().Resize(lNewIndexToDirect.GetCount());
int* lIndexArray = (int*)pUVs->GetIndexArray().GetLocked();
for (int i = 0; i < lNewIndexToDirect.GetCount(); i++)
lIndexArray = lNewIndexToDirect.GetAt(i);
pUVs->GetIndexArray().Release((void**)&lIndexArray);

// and the content of the direct array
pUVs->GetDirectArray().Clear();
pUVs->GetDirectArray().Resize(lNewUVs.GetCount());
FbxVector2* lDirectArray = (FbxVector2*)pUVs->GetDirectArray().GetLocked();
for (int j = 0; j < lNewUVs.GetCount(); j++)
lDirectArray = lNewUVs.GetAt(j);
pUVs->GetDirectArray().Release((void**)&lDirectArray);
}
}
}


Regards,
Carlos
Message 9 of 9
Anonymous
in reply to: Anonymous

Very helpful piece of code
Thanks Carlos

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report