gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Test mesh normals

#175523 - Scribe - Mon Dec 13, 2010 1:11 am

Hi guys,

I've just written for the most part an FBX to DS friendly CallList file converter, however, my normals are all a mess, I'm using a simple cube for my first test with normals that line up with a plane (so one component is always 1), I've confirmed that they are being converted to the v10 format correctly but I'm getting about half a face out of my entire cube showing, there's no issue if I turn my normals off, any ideas?

call list code:
Code:

            // 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 ) );
//..................
   // 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);
      }
   }


I greatly appreciate any help.
Many thanks[/code]

#175531 - Rexhunter99 - Wed Dec 15, 2010 10:47 am

My first post! :D and the first reply to the topic!

Hi Scribe, now I'm still learning the libNDS library, but I think I can try and offer a hand of help here. I just made my own model testing application in Win32 and OpenGL so I can make sure my models are working and correct before I slap them into my game project for the DS and cry when it doesn't work for some seemingly random reason.

Okay as for your code, not sure what syntax it is but it looks like you are mistreating the NORMAL_PACK macro. NORMAL_PACK packs three v10 variables (normals, x,y,z) into a single 32-bit variable, off the top of my head it only uses 30 bits and ignores the last 2... don't quote me though.

So basically to use NORMAL_PACK, you have to convert your floating-point normal co-ords to the v10 format using the macro floattov10() and then pump the three resulting short integers into the NORMAL_PACK macro. This is how I did it in 3dsMax 2010's maxscript.

Also this sounds like it could be a DS-issue with the call-list, since I don't know ALL the details I won't assume anything yet.
This is also why I ignore the call-list feature, I prefer pumping the raw data in via glNormal,glTexCoord,glColor and glVertex :)
_________________
[Images not permitted - Click here to view it] - Move over Mario... Cruise by Crash... Croc Rocks!