www.pudn.com > 3dsloader.rar > README.BMF, change:2007-06-22,size:4515b


The Basic Model Format (BMF)
David Farrell

The BMF file is a binary file that I created out of a need to work with .3DS files. However, I
needed an easier way to get data into my graphics code than parsing the 3DS file every time I
loaded the program. I modified View3DS so that it will load in a .3DS file, manipulate it, and
then export it into the easier-to-use BMF format.

In the bmf/ directory you will find a sample program that will read in a .BMF file and then
render it with OpenGL. To use it, type bmf <filename>, where filename is the .BMF file you want
to see. If you want to use BMF files in your own code, examine MAIN.C to see how it calls LoadBMF() 
to load a BMF object and then uses DrawBMFObject() to render the object. I think it is pretty simple 
code; you should be able to easily modify it to read the BMF objects into your own data structures 
and call your own rendering routines.

BMF files are around twice as large as .3DS files because it contains the same information as
.3DS files plus the per-vertex normals.

The BMF format looks roughly like this:

Header Information
Material #1
 Texture Properties
 Color Properties
 Vertex Information
 Triangle Information 
Material #2
 Texture Properties
 Color Properties
 Vertex Information
 Triangle Information 
Material #3
 Texture Properties
 Color Properties
 Vertex Information
 Triangle Information 
 .
 .
 .

As you can see, a BMF file consists of a series of materials. Each of these materials has unique 
color and texture properties. For a given material, there is a set of vertex coordinates, as well as
a list of indexes into these coordinates for each triangle. All of the triangles listed in a
material use that material's properties. Note that there is not a single vertex pool for the 
whole model; instead, each material has its own set of vertices independent
of the other materials. This means there are some duplicated vertices across the materials,
but in general, not that many vertices are wasted. 

The idea behind splitting up the vertices is that I can transform a set of vertices, then feed 
them to my hardware accelerator. While it is drawing, I can then go transform the next set of 
vertices for the next material. I then send these to the accelerator and go on to the next set 
of vertices. This overlap means that the CPU and the accelerator work in parallel instead of 
sequentially so that overall performance is increased.

The texture coordinates are from 0 to 1. The texture filename is stored in the BMF file, but the
texture itself is stored separately. You will have to read the texture in yourself and store it
in whatever format you desire.

Please look at LOADBMF.C, BMF.H, and TYPES.H for more information.

The BMF file format starts with the following:

   (unsigned short int) # of materials
   (ushort int) mesh type

   If mesh type == 0, then it's a sparse (non-stripified) mesh. If it's a one, then it's a stripified mesh.

    Following the above two entries are each material. These materials are either a sparse mesh or
triangle strips. A BMF file never contains both; it is strictly one or the other.

   A sparse material looks like this:

   (ushort int) Texture Name Length (Always at least one; the terminating zero is counted)
   (char) Texture Name (Terminated by a zero)
   (3 floats)RGB ambient
   (3 floats)RGB diffuse
   (3 floats)RGB specular
   (ushort int)Number of Vertices (for this material only)
   (BMF_UNVERTEX) vertex[NumberOfVertices]
   (ushort int)Number of Triangles
   (BMF_SURFACE) triangle[NumberOfTriangles]


   If it's a stripified mesh, then it looks like:

   (ushort int) Texture Name Length (Always at least one; the terminating zero is counted)
   (char) Texture Name (Terminated by a zero)
   (3 floats)RGB ambient
   (3 floats)RGB diffuse
   (3 floats)RGB specular
   (ushort int)Number of Vertices (for this material only)
   (BMF_UNVERTEX) vertex[NumberOfVertices]
   (ushort int) NumberOfStrips
   (ushort int) LengthOfEachStrip[NumberOfStrips]
   (ushort int) NumberOfStripPoints
   (ushort int) NumberOfStripIndices[NumberOfStripPoints]
 

   In the BMF definition, these are also defined:

   // This is a GL_T2F_N3F_V3F struct
   // BMF_UNVERTEX means a BMF untransformed vertex with normals
   struct {
     GLfloat u,v;
     GLfloat i,j,k;
     GLfloat x,y,z;
   } BMF_UNVERTEX;

   // A surface (or triangle). These points are indices into the vertex list.
   struct {
     unsigned short int point0, point1, point2;
   } BMF_SURFACE;