I'm half way through writing an all in one image/FBX to xBGR16/NDS DisplayList converter tool, I have reached the point of testing a basic model so have create a simple cube in Maya and exported as an fbx and converted with my tool. I am able to then display the converted DisplayList on screen and see the cube, however, I'm unable to get it displaying correctly once I feed in the normal information. All I see is half a face.
I've confirmed that all of my normals are normalised and are are axially aligned (as the cube faces are straight) as so contain the value 1 on one of the axis and 0 on the others so this should be a fairly simple situation.
Here's my conversion code, and below I'll attach two screen shots, with and without normal data:
Code: Select all
meshFile->Write( (UInt32)FIFO_COMMAND_PACK( FIFO_BEGIN,FIFO_TEX_COORD, FIFO_VERTEX16, FIFO_NORMAL ) );
meshFile->Write( (UInt32)GL_TRIANGLES );
for( int i = 0; i < mesh->GetPolygonCount()*3; ++i )
{
// Fetch vertex from polygon
KFbxVector4 vertex = controlPoints[mesh->GetPolygonVertex( i/3, i%3 )];
KFbxVector4 normal;
mesh->GetPolygonVertexNormal( i/3, i%3, normal );
//normal.Normalize();
KFbxVector4 texture = controlPoints[mesh->GetTextureUVIndex( i/3, i%3 )];
// Write Tex-Coord
meshFile->Write( (UInt32)TEXTURE_PACK(floatToFixed164( vertex.GetAt( 0 ) ), floatToFixed164( vertex.GetAt( 1 ) )) );
// Write vertex
meshFile->Write( (UInt32)VERTEX_PACK(floatToFixed3212( vertex.GetAt( 0 ) ), floatToFixed3212( vertex.GetAt( 1 ) )) );
meshFile->Write( (UInt32)VERTEX_PACK(floatToFixed3212( vertex.GetAt( 2 ) ), 0) );
// Write Normal
meshFile->Write( (UInt32)NORMAL_PACK(floatToFixed1010( normal.GetAt( 0 ) ), floatToFixed1010( normal.GetAt( 1 ) ),
floatToFixed1010( normal.GetAt( 2 ) )) );
// Write next command pack
if( mesh->GetPolygonCount()*3 - i > 1 )
{
meshFile->Write( (UInt32)FIFO_COMMAND_PACK(FIFO_TEX_COORD, FIFO_VERTEX16, FIFO_NORMAL, FIFO_NOP ) );
}
}
//.......................Normal float to fixed function
// Floating-point to fixed point 10-bit (10-bit fractional) convertion
private: fbxShort1 floatToFixed1010( fbxDouble1 floatingPoint )
{
const static fbxInteger1 factor = 1 << 9;
if( floatingPoint > 0.998 )
{
return (fbxShort1)0x1FF;
}
else
{
return static_cast<fbxShort1>(floatingPoint*factor);
}
}