I'm poosting this here a separate topic because I marked the other one as solved.
I've got the UV layer but now I'm having a different problem.
Doing...
FbxLayer* lUVLayer = pMesh->GetLayer(0, FbxLayerElement::eUV ) ; FbxLayerElementUV* leUV = lUVLayer->GetUVs();
I can see that the UVs are in there (just looking at the direct array), but I can't figure out how to index into it, having a polygon index and vertex index (within the polygon).
Mapping mode is FbxGeometryElement::eByPolygonVertex
and Reference mode is FbxGeometryElement::eIndexToDirect
The code that I had before did:
int uvidx = pMesh->GetTextureUVIndex(i,j);
int idx = aUV->GetIndexArray().GetAt(uvidx);
FbxVector2 rUV = aUV->GetDirectArray().GetAt(idx);
which works perfectly fine, but only for UVs in Layer 0.
That's because GetTextureUVIndex(i,j) only works for Layer 0.
I need the equivalent for this particular layer.
The following:
int ubidx = pMesh->GetPolygonVertex(i, j);
doesn't work.
So, how do I index into the uv vertex from a polygon index and a vertex position index ?
Thanks
Solved! Go to Solution.
Got it...
I've found the following in the UVSample:
else if (lUVElement->GetMappingMode() == FbxGeometryElement::eByPolygonVertex)
{
int lPolyIndexCounter = 0;
for( int lPolyIndex = 0; lPolyIndex < lPolyCount; ++lPolyIndex )
{
// build the max index array that we need to pass into MakePoly
const int lPolySize = pMesh->GetPolygonSize(lPolyIndex);
for( int lVertIndex = 0; lVertIndex < lPolySize; ++lVertIndex )
{
if (lPolyIndexCounter < lIndexCount)
{
FbxVector2 lUVValue;
//the UV index depends on the reference mode
int lUVIndex = lUseIndex ? lUVElement->GetIndexArray().GetAt(lPolyIndexCounter) : lPolyIndexCounter;
lUVValue = lUVElement->GetDirectArray().GetAt(lUVIndex);
//User TODO:
//Print out the value of UV(lUVValue) or log it to a file
lPolyIndexCounter++;
}
}
}
}
Which shows that the equivalent for GetTextureUVIndex(i,j) reduces to
(i * 3 ) + j
in my triangular mesh example.
And in more general case it would be vertexcount[0] + vertexcount[1] ... + vertexcount[i-1] + j
where vertexcount is the number of vertices in each polygon.
Best
Can't find what you're looking for? Ask the community or share your knowledge.