Remember 3December
Find out where to celebrate your 3D CG art...
  • 1/3
You are here:Forum Home / Autodesk® FBX® / FBX SDK / UV's mapping out of order
  RSS 2.0 ATOM  

UV's mapping out of order
Rate this thread
 
36421
 
Subscribe to this thread
avatar
  • ksr
  • Posted: 06 November 2009 09:23 PM
  • Total Posts: 2
  • Joined: 2009-10-16 21:34:07

Hello,
I’m trying to map a simple texture on a cube in directX.  I used the FBX SDK to extract the vertex, normal and UV information ofthe cube.  However the cube displayed in my program has the wrong UV mapping.  It seems like they are a mirror image of each other and the wrong faces have the wrong part of the texture mapped on it. I have attached a screenshot of the cube in maya and the application I am making.
Here is the code I am using:

KFbxVector4 normal;
 
KFbxVector2 tex;
 
m_pFbxMesh->ComputeVertexNormals()
 KFbxLayerElementNormal
pNormals m_pFbxMesh->GetLayer(0,KFbxLayerElement::eNORMAL)->GetNormals()
 KFbxLayerElementUV
pUV m_pFbxMesh->GetLayer( 0 )->GetUVs()
 vector
<VertexPosNorTextempVertices;
 
KFbxVector4pMeshVertices = new KFbxVector4[m_pFbxMesh->GetControlPointsCount()];
 
memcpy(pMeshVerticesm_pFbxMesh->GetControlPoints()m_pFbxMesh->GetControlPointsCount()*sizeof(KFbxVector4))

 for( int  i 
=0im_pFbxMesh->GetPolygonCount() i++ )
 {
 for( int j 
=0jm_pFbxMesh->GetPolygonSize(i) j++ )
 {
 int vertInd 
m_pFbxMesh->GetPolygonVertex(  ij)
 VertexPosNorTex v
;
 
v.pos D3DXVECTOR3( pMeshVertices[ vertInd ].GetAt( 0 ),
   
pMeshVertices[ vertInd ].GetAt( 1 ),
   
pMeshVertices[ vertInd ].GetAt( 2 ))
 normal  
pNormals->GetDirectArray()[vertInd];
 
v.normal D3DXVECTOR3( normal.GetAt( 0 ),
 
normal.GetAt( 1 ),
 
normal.GetAt( 2 ))
 
 int meshInd 
=  m_pFbxMesh->GetTextureUVIndex(i,  j) 
 
 tex 
pUV->GetDirectArray().GetAt(meshInd) 
 v
.texC D3DXVECTOR2(tex.GetAt(0),1.0f -tex.GetAt(1))

 tempVertices
.push_back(v)
 }
 }
 SAFE_DELETE_ARRAY(pMeshVertices)

//creating the real index and vertex buffer here
 
int indexBufferCounter 0;
 
for(int tempCounter 0tempCountertempVertices.size() ++tempCounter)
 {
 bool contains  
false;
//check for duplicate vertices
 
for(int vertexCounter 0vertexCounter m_Vertices.size() ++vertexCounter)
 {
 if(
 m_Vertices[vertexCounter]
.pos == tempVertices[tempCounter].pos
 
&& m_Vertices[vertexCounter].normal== tempVertices[tempCounter].normal
 
&& m_Vertices[vertexCounter].texC == tempVertices[tempCounter].texC
 )
 {
 contains 
true;
 
m_Indices.push_back(vertexCounter)
 
break;
 
}

 }
 if(
!contains)
 {
 m_Vertices
.push_back(tempVertices[tempCounter])
 m_Indices
.push_back(indexBufferCounter)

 
++indexBufferCounter;
 
}
 
 }

I am doing v.texC = D3DXVECTOR2(tex.GetAt(0),1.0f -tex.GetAt(1)), because the texture mapping is totally wrong if I don’t (could be a difference in the mapping coordinate system of Maya and DX10). 

I have tried several combinations to fix this issue, but this is the closest I have got to the result.

Any help would be greatly appreciated.
Thanks in advance



Attachment Attachment
Replies: 0
avatar
  • Location: Montréal
  • Total Posts: 165
  • Joined: 2007-07-11 12:47:14

It is because Direct3D uses left-handed axis system, and FBX uses right-handed axis system like OpenGL and Maya. So in Direct3D, your scene appears like a mirror image of what you see in Maya.

Try KFbxAxisSystem::ConvertScene() to modify your scene.

Viviane, Autodesk FBX Team



Replies: 0




   
  Settings Choose Theme color: