   Exporting to Milkshape3D File
  Hi, Im writing a 3d modeller and im giving the option of exporting to MS3D file format. The problem im just wondering here is, in the ms3d file, does each of the structs have to be aligned in a specific manner?I have code for loading a ms3d file and theres all this:   // byte-align structures#ifdef _MSC_VER#pragma pack(push, packing)#pragma pack(1)#define PACK_STRUCT#elif defined( __GNUC__ )#define PACK_STRUCT__attribute__((packed))#else#error you must byte-align these structures with the appropriate compiler directives#endiftypedef unsigned char byte;typedef unsigned short word;// File headerstruct MS3DHeader{char m_ID[10];int m_version;} PACK_STRUCT;// Vertex informationstruct MS3DVertex{byte m_flags;float m_vertex[3];char m_boneID;byte m_refCount;} PACK_STRUCT;// Triangle informationstruct MS3DTriangle{word m_flags;word m_vertexIndices[3];float m_vertexNormals[3][3];float m_u[3], m_v[3];byte m_smoothingGroup;byte m_groupIndex;} PACK_STRUCT;// Material informationstruct MS3DMaterial{    char m_name[32];    float m_ambient[4];    float m_diffuse[4];    float m_specular[4];    float m_emissive[4];    float m_shininess;// 0.0f - 128.0f    float m_transparency;// 0.0f - 1.0f    byte m_mode;// 0, 1, 2 is unused now    char m_texture[128];    char m_alphamap[128];} PACK_STRUCT;// Default alignment#ifdef _MSC_VER#pragma pack(pop, packing)#endif#undef PACK_STRUCTCan anyone explain all this stuff to me please, and do you think that its even remotely needed by me to export.Thanks in advance,Keith 
  seeing as no-one else replied, here my somewhat shakey view of whats going on:ms3d expects the structs to be the exact sizes they are defined as , without padding.when you create a struct it is padded to the nearest number of mem allocation units. the size of these varies from os to os, compiler to compiler (not sure what they are though, sorry. it''s a number of bytes i think). It''s done because it''s faster to operate on a certain size than to fiddle around the smaller uneven denominations.obviously if a binary file is saved with the padding it will be bigger than needed, and will require you to take the padding into account.MS3d''s way of dealing with this is just to use packed structs for the fileformat data. As these are defined in the fileformat header, as long as you use the same structs you should be fine. ;  Aahm, I''m not completely sure, but I''m _quite_ sure that milkshape doesn''t assume you''re doing whole dumps/reads of structs to file. What you should be doing (I''ve done it before, but it was a while ago) is reading in each element at a time, the structs just define the size and order of the data.Most of the time, reading/writing the structs themselves would work, but you could come across a compiler that likes to bump a couple of the structure members over a byte or something, and then you''re in hot water..Also, if you''re trying to understand the layout of the file, try going into milkshape and exporting a simple model in the Milkshape3D ASCII format, that way you can read it and make a little more sense of it.IIRC, the MS3D ASCII format has the exact same data layout as the binary format, the only difference is that it''s stored in ASCII instead of binary representations.Hope that''s helpful.Klowner--http://dugnet.com/klown ;  So what your saying is that I can call each of the struct just as its declared (eg. MS3DMaterial) in code, but all the #pragma pack(...)stuff just tells the compiler how to store the struct properly, for byte alignments.If I get problems with the binary file, ill definitely look into the ASCII version of the file.Thanks guys, you were a great help,Keith 