mirror of
https://github.com/glest/glest-source.git
synced 2025-09-01 04:01:47 +02:00
Fixed the god-awful indentation
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* File: g2xml.c
|
||||
* Written: Jonathan Merritt <jmerritt@warpax.com>
|
||||
*
|
||||
*
|
||||
* Description:
|
||||
* Converts G3D format files into an XML representation.
|
||||
*
|
||||
@@ -25,9 +25,9 @@
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Forward function declarations.
|
||||
*/
|
||||
/**
|
||||
* Forward function declarations.
|
||||
*/
|
||||
int g3d2xml(FILE *infile, FILE *outfile);
|
||||
void usage(char *execname);
|
||||
|
||||
@@ -42,21 +42,17 @@ void usage(char *execname);
|
||||
* @returns: EXIT_SUCCESS or EXIT_FAILURE depending upon success or failure
|
||||
* of the conversion to XML.
|
||||
*/
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
char *infilename, *outfilename;
|
||||
FILE *infile, *outfile;
|
||||
int successFlag;
|
||||
|
||||
|
||||
/* parse command line arguments */
|
||||
if (argc != 3)
|
||||
{
|
||||
if (argc != 3) {
|
||||
usage(argv[0]);
|
||||
return (EXIT_FAILURE);
|
||||
}
|
||||
else
|
||||
{
|
||||
infilename = argv[1];
|
||||
} else {
|
||||
infilename = argv[1];
|
||||
outfilename = argv[2];
|
||||
}
|
||||
|
||||
@@ -64,20 +60,19 @@ int main(int argc, char **argv)
|
||||
//#ifdef WIN32
|
||||
// infile = _wfopen(utf8_decode(infilename).c_str(), L"rb");
|
||||
//#else
|
||||
infile = fopen(infilename, "rb");
|
||||
//#endif
|
||||
infile = fopen(infilename, "rb");
|
||||
//#endif
|
||||
if (infile == NULL) {
|
||||
printf("Could not open file \"%s\" for binary reading.\n",
|
||||
infilename);
|
||||
return (EXIT_FAILURE);
|
||||
}
|
||||
//#ifdef WIN32
|
||||
// outfile = _wfopen(utf8_decode(outfilename).c_str(), L"w");
|
||||
//#else
|
||||
//#ifdef WIN32
|
||||
// outfile = _wfopen(utf8_decode(outfilename).c_str(), L"w");
|
||||
//#else
|
||||
outfile = fopen(outfilename, "w");
|
||||
//#endif
|
||||
if (outfile == NULL)
|
||||
{
|
||||
//#endif
|
||||
if (outfile == NULL) {
|
||||
printf("Could not open file \"%s\" for writing.\n",
|
||||
outfilename);
|
||||
fclose(infile);
|
||||
@@ -86,7 +81,7 @@ int main(int argc, char **argv)
|
||||
|
||||
/* perform the XML conversion */
|
||||
successFlag = g3d2xml(infile, outfile);
|
||||
|
||||
|
||||
/* close the two files */
|
||||
fclose(infile);
|
||||
fclose(outfile);
|
||||
@@ -106,8 +101,7 @@ int main(int argc, char **argv)
|
||||
*
|
||||
* @param execname: Executable name of the program.
|
||||
*/
|
||||
void usage(char *execname)
|
||||
{
|
||||
void usage(char *execname) {
|
||||
printf("Usage:\n");
|
||||
printf(" %s infile.g3d outfile.xml\n", execname);
|
||||
|
||||
@@ -124,31 +118,27 @@ void usage(char *execname)
|
||||
*
|
||||
* @returns: TRUE if conversion to XML was successful, and FALSE otherwise.
|
||||
*/
|
||||
int g3d2xml(FILE *infile, FILE *outfile)
|
||||
{
|
||||
int g3d2xml(FILE *infile, FILE *outfile) {
|
||||
struct FileHeader fileHeader;
|
||||
struct ModelHeader modelHeader;
|
||||
struct MeshHeader meshHeader;
|
||||
size_t nBytes;
|
||||
uint8 textureName[NAMESIZE+1];
|
||||
uint8 textureName[NAMESIZE + 1];
|
||||
float32 *fdata;
|
||||
uint32 *idata;
|
||||
unsigned int ii, jj, kk;
|
||||
|
||||
/* read in the FileHeader */
|
||||
nBytes = sizeof(struct FileHeader);
|
||||
if (fread(&fileHeader, nBytes, 1, infile) != 1)
|
||||
{
|
||||
if (fread(&fileHeader, nBytes, 1, infile) != 1) {
|
||||
printf("Could not read file header!\n");
|
||||
return FALSE;
|
||||
}
|
||||
if (strncmp((char*)fileHeader.id, "G3D", 3) != 0)
|
||||
{
|
||||
if (strncmp((char*) fileHeader.id, "G3D", 3) != 0) {
|
||||
printf("Expected \"G3D\" id was not found!\n");
|
||||
return FALSE;
|
||||
}
|
||||
if (fileHeader.version != 4)
|
||||
{
|
||||
if (fileHeader.version != 4) {
|
||||
printf("Version 4 expected, but version %d found!\n",
|
||||
fileHeader.version);
|
||||
return FALSE;
|
||||
@@ -161,31 +151,27 @@ int g3d2xml(FILE *infile, FILE *outfile)
|
||||
fprintf(outfile, "\t(not yet accepted as part of Glest!).\n");
|
||||
fprintf(outfile, "-->\n");
|
||||
fprintf(outfile, "<G3D version=\"%d\">\n", fileHeader.version);
|
||||
|
||||
|
||||
/* read in the ModelHeader */
|
||||
nBytes = sizeof(struct ModelHeader);
|
||||
if (fread(&modelHeader, nBytes, 1, infile) != 1)
|
||||
{
|
||||
if (fread(&modelHeader, nBytes, 1, infile) != 1) {
|
||||
printf("Could not read model header!\n");
|
||||
return FALSE;
|
||||
}
|
||||
if (modelHeader.type != mtMorphMesh)
|
||||
{
|
||||
if (modelHeader.type != mtMorphMesh) {
|
||||
printf("Unrecognized mesh type!\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* read in the meshes */
|
||||
for (ii = 0; ii < modelHeader.meshCount; ii++)
|
||||
{
|
||||
for (ii = 0; ii < modelHeader.meshCount; ii++) {
|
||||
/* read in the MeshHeader */
|
||||
nBytes = sizeof(struct MeshHeader);
|
||||
if (fread(&meshHeader, nBytes, 1, infile) != 1)
|
||||
{
|
||||
if (fread(&meshHeader, nBytes, 1, infile) != 1) {
|
||||
printf("Could not read mesh header!\n");
|
||||
return FALSE;
|
||||
}
|
||||
meshHeader.name[NAMESIZE-1] = 0;
|
||||
meshHeader.name[NAMESIZE - 1] = 0;
|
||||
/* write out XML mesh header */
|
||||
fprintf(outfile, "\t<Mesh name=\"%s\" ", meshHeader.name);
|
||||
fprintf(outfile, "frameCount=\"%u\" ", meshHeader.frameCount);
|
||||
@@ -224,9 +210,8 @@ int g3d2xml(FILE *infile, FILE *outfile)
|
||||
fprintf(outfile, "\t\t</Specular>\n");
|
||||
|
||||
/* read / write the texture name if present */
|
||||
if (meshHeader.textures)
|
||||
{
|
||||
memset(&textureName[0],0,NAMESIZE+1);
|
||||
if (meshHeader.textures) {
|
||||
memset(&textureName[0], 0, NAMESIZE + 1);
|
||||
nBytes = NAMESIZE;
|
||||
if (fread(&textureName, nBytes, 1, infile) != 1) {
|
||||
printf("Could not read texture name!\n");
|
||||
@@ -238,99 +223,87 @@ int g3d2xml(FILE *infile, FILE *outfile)
|
||||
}
|
||||
|
||||
/* read / write each set of vertex data */
|
||||
for (jj=0; jj < meshHeader.frameCount; jj++)
|
||||
{
|
||||
nBytes = sizeof(float32)*meshHeader.vertexCount*3;
|
||||
for (jj = 0; jj < meshHeader.frameCount; jj++) {
|
||||
nBytes = sizeof(float32)*meshHeader.vertexCount * 3;
|
||||
fdata = malloc(nBytes);
|
||||
if (fdata == NULL)
|
||||
{
|
||||
if (fdata == NULL) {
|
||||
printf("Could not allocate buffer!\n");
|
||||
return FALSE;
|
||||
}
|
||||
if (fread(fdata, nBytes, 1, infile) != 1)
|
||||
{
|
||||
if (fread(fdata, nBytes, 1, infile) != 1) {
|
||||
printf("Could not read vertex data!\n");
|
||||
free(fdata);
|
||||
return FALSE;
|
||||
}
|
||||
fprintf(outfile, "\t\t<Vertices frame=\"%u\">\n",
|
||||
jj);
|
||||
for (kk=0; kk < meshHeader.vertexCount; kk++)
|
||||
{
|
||||
for (kk = 0; kk < meshHeader.vertexCount; kk++) {
|
||||
fprintf(outfile, "\t\t\t<Vertex ");
|
||||
/*fprintf(outfile, "i=\"%d\" ",
|
||||
kk);*/
|
||||
fprintf(outfile, "x=\"%f\" ",
|
||||
fdata[3*kk]);
|
||||
fdata[3 * kk]);
|
||||
fprintf(outfile, "y=\"%f\" ",
|
||||
fdata[3*kk+1]);
|
||||
fdata[3 * kk + 1]);
|
||||
fprintf(outfile, "z=\"%f\"/>\n",
|
||||
fdata[3*kk+2]);
|
||||
fdata[3 * kk + 2]);
|
||||
}
|
||||
fprintf(outfile, "\t\t</Vertices>\n");
|
||||
free(fdata);
|
||||
}
|
||||
|
||||
/* read / write each set of normal data */
|
||||
for (jj=0; jj < meshHeader.frameCount; jj++)
|
||||
{
|
||||
nBytes = sizeof(float32)*meshHeader.vertexCount*3;
|
||||
for (jj = 0; jj < meshHeader.frameCount; jj++) {
|
||||
nBytes = sizeof(float32)*meshHeader.vertexCount * 3;
|
||||
fdata = malloc(nBytes);
|
||||
if (fdata == NULL)
|
||||
{
|
||||
if (fdata == NULL) {
|
||||
printf("Could not allocate buffer!\n");
|
||||
return FALSE;
|
||||
}
|
||||
if (fread(fdata, nBytes, 1, infile) != 1)
|
||||
{
|
||||
if (fread(fdata, nBytes, 1, infile) != 1) {
|
||||
printf("Could not read normal data!\n");
|
||||
free(fdata);
|
||||
return FALSE;
|
||||
}
|
||||
fprintf(outfile, "\t\t<Normals frame=\"%u\">\n",
|
||||
jj);
|
||||
for (kk=0; kk < meshHeader.vertexCount; kk++)
|
||||
{
|
||||
for (kk = 0; kk < meshHeader.vertexCount; kk++) {
|
||||
fprintf(outfile, "\t\t\t<Normal ");
|
||||
/*fprintf(outfile, "i=\"%d\" ",
|
||||
kk);*/
|
||||
fprintf(outfile, "x=\"%f\" ",
|
||||
fdata[3*kk]);
|
||||
fdata[3 * kk]);
|
||||
fprintf(outfile, "y=\"%f\" ",
|
||||
fdata[3*kk+1]);
|
||||
fdata[3 * kk + 1]);
|
||||
fprintf(outfile, "z=\"%f\"/>\n",
|
||||
fdata[3*kk+2]);
|
||||
fdata[3 * kk + 2]);
|
||||
}
|
||||
fprintf(outfile, "\t\t</Normals>\n");
|
||||
free(fdata);
|
||||
}
|
||||
|
||||
/* read / write texture coordinates */
|
||||
if (meshHeader.textures)
|
||||
{
|
||||
nBytes = sizeof(float32)*meshHeader.vertexCount*2;
|
||||
if (meshHeader.textures) {
|
||||
nBytes = sizeof(float32)*meshHeader.vertexCount * 2;
|
||||
fdata = malloc(nBytes);
|
||||
if (fdata == NULL)
|
||||
{
|
||||
if (fdata == NULL) {
|
||||
printf("Could not allocate buffer!\n");
|
||||
return FALSE;
|
||||
}
|
||||
if (fread(fdata, nBytes, 1, infile) != 1)
|
||||
{
|
||||
if (fread(fdata, nBytes, 1, infile) != 1) {
|
||||
printf("Could not read texture coords!\n");
|
||||
free(fdata);
|
||||
return FALSE;
|
||||
}
|
||||
fprintf(outfile, "\t\t<TexCoords>\n");
|
||||
for (kk=0; kk < meshHeader.vertexCount; kk++)
|
||||
{
|
||||
for (kk = 0; kk < meshHeader.vertexCount; kk++) {
|
||||
fprintf(outfile, "\t\t\t<ST ");
|
||||
/*fprintf(outfile, "i=\"%d\" ",
|
||||
kk);*/
|
||||
fprintf(outfile, "s=\"%f\" ",
|
||||
fdata[2*kk]);
|
||||
fdata[2 * kk]);
|
||||
fprintf(outfile, "t=\"%f\"/>\n",
|
||||
fdata[2*kk+1]);
|
||||
fdata[2 * kk + 1]);
|
||||
}
|
||||
fprintf(outfile, "\t\t</TexCoords>\n");
|
||||
free(fdata);
|
||||
@@ -339,31 +312,28 @@ int g3d2xml(FILE *infile, FILE *outfile)
|
||||
/* read / write face indices */
|
||||
nBytes = sizeof(uint32)*meshHeader.indexCount;
|
||||
idata = malloc(nBytes);
|
||||
if (idata == NULL)
|
||||
{
|
||||
if (idata == NULL) {
|
||||
printf("Could not allocate buffer!\n");
|
||||
return FALSE;
|
||||
}
|
||||
if (fread(idata, nBytes, 1, infile) != 1)
|
||||
{
|
||||
if (fread(idata, nBytes, 1, infile) != 1) {
|
||||
printf("Could not read indexes!\n");
|
||||
free(idata);
|
||||
return FALSE;
|
||||
}
|
||||
fprintf(outfile, "\t\t<Indices>\n");
|
||||
for (kk=0; kk < meshHeader.indexCount; kk++)
|
||||
{
|
||||
for (kk = 0; kk < meshHeader.indexCount; kk++) {
|
||||
fprintf(outfile, "\t\t\t<Ix i=\"%u\"/>\n",
|
||||
idata[kk]);
|
||||
}
|
||||
fprintf(outfile, "\t\t</Indices>\n");
|
||||
free(idata);
|
||||
|
||||
|
||||
fprintf(outfile, "\t</Mesh>\n");
|
||||
}
|
||||
|
||||
fprintf(outfile, "</G3D>\n");
|
||||
|
||||
|
||||
return TRUE;
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user