1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
void getModel()
{
FILE* dataFile = fopen(fileName, "r");
FILE* fileOut = fopen("cubey.txt", "w");
if (dataFile == NULL)
{
cout << "Input file failed to open or is missing.\n";
exit(1);
}
string type;
float x, y, z;
int v1, vt1, vn1, v2, vt2, vn2, v3, vt3, vn3;
fscanf(dataFile, "%d %d %d %d", &numVertices, &numTex, &numNormals, &numFaces);
vertices = new CUSTOMVERTEX[numVertices];
indices = new short[numFaces];
D3DXVECTOR3* v = new D3DXVECTOR3[numVertices];
D3DXVECTOR2* vt = new D3DXVECTOR2[numTex];
D3DXVECTOR3* vn = new D3DXVECTOR3[numNormals];
for(int i = 0; i < numVertices; i++)
{
fscanf(dataFile, "%s %f %f %f", &type, &x, &y, &z);
v[i].x = x;
v[i].y = y;
v[i].z = z;
fprintf(fileOut, "%f %f %f\n", x, y, z);
}
for(int i = 0; i < numTex; i++)
{
fscanf(dataFile, "%s %f %f", &type, &x, &y);
vt[i].x = x;
vt[i].y = y;
fprintf(fileOut, "%f %f\n", x, y);
}
for(int i = 0; i < numNormals; i++)
{
fscanf(dataFile, "%s %f %f %f", &type, &x, &y, &z);
vn[i].x = x;
vn[i].y = y;
vn[i].z = z;
fprintf(fileOut, "%f %f %f\n", x, y, z);
}
for(int i = 0; i < numFaces; i++)
{
fscanf(dataFile, "%s %d/%d/%d %d/%d/%d %d/%d/%d", &type, &v1, &vt1, &vn1, &v2, &vt2, &vn2, &v3, &vt3, &vn3);
fprintf(fileOut, "%d,%d,%d %d,%d,%d %d,%d,%d\n", v1, vt1, vn1, v2, vt2, vn2, v3, vt3, vn3);
}
delete [] v;
delete [] vt;
delete [] vn;
fclose(dataFile);
fclose(fileOut);
}
|