Archived

This topic is now archived and is closed to further replies.

adam17

good ol ASE file parser...

Recommended Posts

adam17    227
all of a sudden my file importer stopped working on me and started giving an access violation. i didn''t change a thing. here is my import function (i know its messy):
void Import_Obj()
{
	fseek(infile, 0L, SEEK_SET);

	outfile << "Import_Obj()" << endl;

	while(!feof(infile))
	{
		fscanf(infile, "%s", &stream);
		S_stream = stream;
		outfile << stream << endl;

		if(S_stream == "*GEOMOBJECT")
		{
			num_obj++;
			Mesh_array.reserve(256);

			Mesh_array.resize(num_obj);

			//outfile << "*GEOMOBJECT" << endl;

		}
		
		if(S_stream == "*MESH_NUMTVERTEX")
		{
			fscanf(infile, "%i", &Mesh_array[num_obj-1].num_t_vertex);

			//outfile << "NUM tVERTEX" << endl;

		}
				
		if(S_stream == "*MESH_NUMVERTEX")
		{
			fscanf(infile, "%i", &Mesh_array[num_obj-1].num_vertex);

			Mesh_array[num_obj-1].vertex.resize(Mesh_array[num_obj-1].num_vertex);
			Mesh_array[num_obj-1].vnormal.resize(Mesh_array[num_obj-1].num_vertex);

			//outfile << "NUM mVERTEX" << endl;

		}

		if(S_stream == "*MESH_NUMFACES")
		{
			fscanf(infile, "%i", &Mesh_array[num_obj-1].num_faces);

			Mesh_array[num_obj-1].face.resize(Mesh_array[num_obj-1].num_faces);
			Mesh_array[num_obj-1].fnormal.resize(Mesh_array[num_obj-1].num_faces);

			//outfile << "NUM FACES" << endl;

		}

		if(S_stream == "*MESH_VERTEX_LIST")
		{
			fscanf(infile, "%s", &stream);									//inputs bracket

			//outfile << "VERTEX LIST:" << endl;


			for(int i=0; i<Mesh_array[num_obj-1].num_vertex; i++)
			{
				fscanf(infile, "%s", &stream);								//inputs "*MESH_VERTEX"

				fscanf(infile, "%s", &stream);								//inputs vertex index


				//Y and Z values are swapped for 3D Studio files

				fscanf(infile, "%f", &Mesh_array[num_obj-1].vertex[i].x);	//converts x value & stores it

				fscanf(infile, "%f", &Mesh_array[num_obj-1].vertex[i].z);	//converts z value & stores it

				fscanf(infile, "%f", &Mesh_array[num_obj-1].vertex[i].y);	//converts y value & stores it


				//outfile << Mesh_array[num_obj-1].vertex[i].x << " ";

				//outfile << Mesh_array[num_obj-1].vertex[i].y << " ";

				//outfile << Mesh_array[num_obj-1].vertex[i].z << endl;

			}
			//outfile << endl;

		}
		
		if(S_stream == "*MESH_FACE_LIST")
		{
			fscanf(infile, "%s", &stream);
			//outfile << "FACE LIST:" << endl;


			for(int i=0; i<Mesh_array[num_obj-1].num_faces; i++)
			{
				fscanf(infile, "%s", &stream);
				fscanf(infile, "%s", &stream);

				fscanf(infile, "%s", &stream);
				fscanf(infile, "%i", &Mesh_array[num_obj-1].face[i].x);
				fscanf(infile, "%s", &stream);
				fscanf(infile, "%i", &Mesh_array[num_obj-1].face[i].y);
				fscanf(infile, "%s", &stream);
				fscanf(infile, "%i", &Mesh_array[num_obj-1].face[i].z);

				for(int loop=0; loop<10; loop++)
					fscanf(infile, "%s", &stream);
			}
		}

		if(S_stream == "*MESH_NORMALS")
		{
			fscanf(infile, "%s", &stream);
			//outfile << "MESH NORMALS" << endl;


			for(int i=0; i<Mesh_array[num_obj-1].num_vertex; i++)
			{
				fscanf(infile, "%s", &stream);
				fscanf(infile, "%s", &stream);

				fscanf(infile, "%f", &Mesh_array[num_obj-1].fnormal[i].x);
				fscanf(infile, "%f", &Mesh_array[num_obj-1].fnormal[i].z);
				fscanf(infile, "%f", &Mesh_array[num_obj-1].fnormal[i].y);

				for(int loop=0; loop<3; loop++)
				{
					fscanf(infile, "%s", &stream);
					fscanf(infile, "%s", &stream);

					fscanf(infile, "%f", &Mesh_array[num_obj-1].vnormal[loop].x);
					fscanf(infile, "%f", &Mesh_array[num_obj-1].vnormal[loop].z);
					fscanf(infile, "%f", &Mesh_array[num_obj-1].vnormal[loop].y);
				}
			}
		}
	}
}
...and here is my output:
File exists
Import_Obj()
*3DSMAX_ASCIIEXPORT
200
*COMMENT
"AsciiExport
Version
2.00
-
Thu
Dec
11
17:41:39
2003"
*SCENE
{
*SCENE_FILENAME
""
*SCENE_FIRSTFRAME
0
*SCENE_LASTFRAME
100
*SCENE_FRAMESPEED
30
*SCENE_TICKSPERFRAME
160
this is not the only ASE file it does this on. the parser always stops at the same spot. any ideas what could be going wrong? thanks ahead of time -adam

Share this post


Link to post
Share on other sites
orbano    130
ive just wrote one today!
i can send it to you if you want. it loads vertex, normal, texture coord arrays and indicies (the texcoord loads incorrectly i think)

"Knowledge is no more expensive than ignorance, and at least as satisfying." -Barrin

Share this post


Link to post
Share on other sites
adam17    227
ooooo man that would be nice!! could u email it to me? adam17@houston.rr.com
how is it compiled? .cpp and .h files, dll''s?
anyway that would be so cool thanks alot orbano!
-adam

Share this post


Link to post
Share on other sites