/* wavefront.cpp
*/
#include headers.h
#include gpuProgram.h
#include linalg.h
#include
#include
#include
#ifdef HAVE_PNG
#include
#include wavefront.h
boolwfModel::newGroupWithNewMaterial = false;
boolwfModel::verticesAreCW = false;
unsigned char wfMaterial::defaultTexmap[] = { 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255 };
/* Read a Wavefront model into this structure.See ObjectFile.html
* for a description of the Wavefront file format.This code is from
* the Nate Robins GLM library.
*/
void wfModel::read( char *filename )
{
FILE* file;
charbuf[1000];
float x, y, z;
wfGroup*currentGroup;
wfMaterial *currentMaterial;
int nextGroupNum = 0;
// Counts of different vertex formats
int numVTN = 0;
int numVT = 0;
int numVN = 0;
int numV = 0;
/* init */
vertices.clear();
normals.clear();
texcoords.clear();
facetnorms.clear();
materials.clear();
groups.clear();
pathname = strdup(filename);
groups.add( new wfGroup( default ) );
currentGroup = groups[0];
materials.add( new wfMaterial( default ) );
currentMaterial = materials[0];
currentGroup->material = currentMaterial;
/* open the file */
file = fopen(filename, r);
if (!file) {
cerr << “wfModel::read() failed: can’t open data file ‘” << filename << “‘.” << endl;exit(-1);}/* process each line */lineNum = 0;while(fscanf(file, “%s”, buf) != EOF) {lineNum++;if (strncmp( buf, “transform”, 9 ) == 0) {for (int r=0; r<4; r++)for (int c=0; c<4; c++) {float val;fscanf( file, “%f”, &val );objToWorldTransform[r][c] = val;}} else {int v = 0, n = 0, t = 0;wfTriangle *tri, *prevTri;switch(buf[0]) {case ‘#’:/* comment *//* eat up rest of line */fgets(buf, sizeof(buf), file);break;case ‘s’:/* smoothing group … ignore *//* eat up rest of line */fgets(buf, sizeof(buf), file);break;case ‘v’:/* v, vn, vt */switch(buf[1]) {case ‘