|
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<VertexPosNorTex> tempVertices;
KFbxVector4* pMeshVertices = new KFbxVector4[m_pFbxMesh->GetControlPointsCount()];
memcpy(pMeshVertices, m_pFbxMesh->GetControlPoints(), m_pFbxMesh->GetControlPointsCount()*sizeof(KFbxVector4))
for( int i =0; i< m_pFbxMesh->GetPolygonCount() i++ )
{
for( int j =0; j< m_pFbxMesh->GetPolygonSize(i) j++ )
{
int vertInd = m_pFbxMesh->GetPolygonVertex( i, j)
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 = 0; tempCounter< tempVertices.size() ++tempCounter)
{
bool contains = false; //check for duplicate vertices
for(int vertexCounter = 0; vertexCounter < 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
|
|
|