Cornell Box MDL Reading Example
Cornell University Program of Computer Graphics
Cornell Seal

The canonical outer loop for programs that read mdl files looks like this:

    mdlInput inp(fp);
    
    while (inp.NumRemain() > 0) {
    
       mdlKey k = inp.BeginChunk();
    
       // Do something that depends on k
          
       inp.EndChunk();
       }
    

This demonstrates the use of NumRemain at the file scope to test for end of file.

Here is some partial code for reading polygon meshes:

    void ReadMesh(mdlInput &inp, Mesh &mesh) {
    
       // We have already started a msh chunk
    
       mesh.name = strdup(inp.ReadString());
       ReadMaterial(inp, mesh.material);
    
       while (inp.NumRemain() > 0) {
          mdlKey k = inp.BeginChunk();
          if (k == mdlKey("vrtxPstn")) {
             mesh.numVertices = inp.NumRemain() / 3;
             int n = inp.ReadFloats(mesh.vp, mesh.numVertices * 3);
             assert(n == mesh.numVertices * 3);
             }
          inp.EndChunk();
          }
       }
    

This demonstrates using NumRemain and ReadFloats to quickly read in a large list of numbers.


Last updated 10/07/04 PCG www Home