最高指挥官SCM模型格式简介(英语)

PART 1: the FA.scm file format
.scm files contain 6 or 7 (FA) or 8 or 9 (SC2) sections in this order:
-the header which contains the position (offsets) of the other section. The header has this format:
Code:
struct ScmHeader
{

   // The FOURCC 'MODL'
   unsigned long mMagic;

   // The .SCM version number
   unsigned long mVersion;

   // Offset to SCM_BoneData[0]
   unsigned long mBoneOffset;
   
   // Number of elements in SCM_BoneData that actually influence verts (no reference points)
   unsigned long mWeightedBoneCount;

   // Offset of basic vertex data section (SCM_VertData[0])
   unsigned long mVertexOffset;

   // Offset of extra vertex data section (SCM_VertExtraData[0]) 
   // Contains additional per-vertex information. *** Currently unused (and omitted) in SupCom 1.0 ***
   unsigned long mVertexExtraOffset;   

   // Number of elements in the SCM_VertData array
   // (and the SCM_VertExtraData array, if mVertexExtraOffset != 0)
   unsigned long mVertexCount;        

   // Offset of the triangle index section (SCM_TriangleData[0])
   unsigned long mIndexOffset;         

   // Number of elements in the SCM_TriangleData array = 3*number of triangles
   unsigned long mIndexCount;          

   // Offset of information section (SCM_InfoData[0])
   unsigned long mInfoOffset;
   
   // Number of elements in the SCM_InfoData list
   unsigned long mInfoCount;           

   // Number of elements in the SCM_BoneData array (including 'reference point' bones)
   unsigned long mTotalBoneCount;  

   // Offset of material section (SC2 only)
   unsigned long mMatsOffset;

   // Number of materials used
   unsigned long mMatsCount;   
};

-the name section (we don't care about its content here)
-the skeleton section (we don't care about its content here)
-the vertex section which contains the definition of each vertex of the 3d model. A vertex has the following format:
Code:
struct ScmVertData   //'3f3f3f3f2f2f4B'
{
   // Position of the vertex relative to the local origin of the mesh
   float mPosition[3];

   // 'Tangent Space' normal, tangent & binormal unit vectors
   float mNormal[3];
   float mTangent[3];
   float mBinormal[3];

   // Two sets of UV coordinates 
   float mUV0[2];
   float mUV1[2];

   // Up to 4-bone skinning can be supported using additional 
   // indices (in conjunction with bone weights in the optional VertexExtra array)
   // Skinned meshes are not used in SupCom 1.0 so only mBoneIndex[0] is expected
   // to contain a valid index.
   unsigned char mBoneIndex[4]; 
};

-the triangle section which is a bunch of short int (2 bytes) trios. Each of those shorts is the index of a vertex that makes one of the triangle's summit. So a triangle that links vertex 0,1 and 2 will be written 0000 0100 0200 in the file.
-the info section, totally useless
-the material names section (SC2 only) contains the names of the materials used by this model. AFAIK those names aren't used anywhere by the game, so you can pretty much put anything.
-The material section which tells which faces are painted with what material. This section contains up to 2 material entries AFAIK. Each entry has the following format:
Code:
struct ScmMatsData
{
   // absolute offset of the material name
   unsigned int mNameOffset;

   // 2 ranges of triangles to be painted with this material
   unsigned int mFirstTriangle1;
   unsigned int mRangeTrisCount1;
   unsigned int mFirstTriangle2;
   unsigned int mRangeTrisCount2;
};

So basically if you want to paint all triangles with a material, just put mFirstTriangle1=0 and mRangeTrisCount1 = number of triangles in this model. What texture is actually associated with this material is specified in the unit.bp file where you have a Materials = { {1st material definition}, {2nd material definition} }, section. BTW I'm not totally sure about the second range of triangles, those int _might_ be something else, I'm not sure.

PART 2: Converting FA.scm int SC2.scm
(algorithm optimized for comprehension, not performance)
-Open the FA.scm
-In the header, read the number of vertexes and the location of the vertex section.
-Sweep trough the vertexes and list all those that have their v coordinate > 0.9. I'll call this the scrolling vertex list.
-In the header, read the number of triangles and the location of the triangle section.
-Sweep trough the triangles and list all triangles that use vertexes on the scrolling vertex list (we'll call that the scrolling triangle list), and put the the other triangles in a non-scrolling triangle list.
-Rewrite the triangle section: first write all the non-scrolling triangles, and then all the scrolling ones. That way you get a contiguous range of scrolling (or non scrolling) triangles.
-Add a material name section at the end of the file, and write there 2 string with their null terminator. Note the offset where each section begins.
-Add a material section: absolute offset of the 1st name(int), 0 (int), number of non-scrolling vertexes (int),0 (int),0(int), absolute offset of the 2nd name(int), number of non-scrolling vertexes+1 (int), number of scrolling vertexes (int),0 (int),0(int).

PART 3: remarks/traps to keep in mind when adding sections
-Beware that all sections are 0x20 aligned which means that they MUST begin at an offset that is a multiple of 32 bytes. Add padding (useless) bytes if required. If you see a lot of 0xBB in the file, those are usually padding bytes.
-Each section has a fourcc code (MODL for the header, NAME for the names, SKEL for skeleton, VXTL for the vertexes, TRIS for the triangles, VEXT for extra vertex data, INFO for info, MNAM for material name, MATS for the material section). All those names are BEFORE the section offset written in the file. So if it is written that the name section starts at offset 64, the 'NAME' word will be at offset 60-63.

最高指挥官SCM模型格式简介(英语)原始网页地址:
http://pastebin.com/raw.php?i=UzfYgs29
最高指挥官SCM模型格式简介(英语)谷歌在线翻译地址:
http://translate.google.com.hk/translate?hl=en&ie=UTF8&prev=_t&sl=en&tl=zh-CN&u=http://bbs.taclub.net/thread-15226-1-1.html