|
|
MDL Reading Example
Cornell University Program of Computer Graphics |
|
||||
|
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 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
| ||||||
| ||||||