[ create a new paste ] login | about

Link: http://codepad.org/jaa1LuRx    [ raw code | fork ]

C++, pasted on Feb 27:
	Model(const char* name)
	{
		std::fstream file(name, std::ios::in | std::ios::binary);
		assert(file.is_open());

		std::string path(name);
		path = path.substr(0,path.find_last_of("/\\"));
		path += "/../TEXTURE/";

		file.read((char*)&header, sizeof(header));
		size_t count1 = file.tellg();
		
		for(long counter = 0; counter < header.numPoint; counter++)
		{
			SF_MOD_POINT point;
			file.read((char*)&point, sizeof(point));
			points.insert(std::make_pair(point.id, vector3df(point.x, point.y, point.z)));
		}

		for(long counter = 0; counter < header.numFace; counter++)
		{
			faces.push_back(Face());
			Face	&face = faces.back();

			long	id;
			short	kind;
			char	skip1[4];
			int		alternativenumPoints;
			char	skip2[16];
			long	buf0;
			char	skip3[4];
			long	buf1;
			long	buf2;
			long	numPoints;
			char	skip4[4];

			
			file.read((char*)&id, sizeof(id));
			file.read((char*)&kind, sizeof(kind));
			file.read(skip1, sizeof(skip1));
			file.read((char*)&alternativenumPoints, sizeof(alternativenumPoints));
			file.read(skip2, sizeof(skip2));
			file.read((char*)&buf0, sizeof(buf0));
			file.read(skip3, sizeof(skip3));

			if(kind == 1)//empty face?
			{

				file.read((char*)&buf1, sizeof(buf1));
				file.read((char*)&buf2, sizeof(buf2));
				file.read((char*)&numPoints, sizeof(numPoints));
				file.read(skip4, sizeof(skip4));

				//texturecoords
				for(long counter = 0; counter < numPoints; counter++)
				{
					char	skip4[2];
					short	texture_x;
					char	skip5[2];
					short	texture_y;
					
					file.read(skip4, sizeof(skip4));
					file.read((char*)&texture_x, sizeof(texture_x));
					file.read(skip5, sizeof(skip5));
					file.read((char*)&texture_y, sizeof(texture_y));

					face.texturecoords.push_back(vector2di(texture_x, texture_y));
				}

				long	str_len;
				char	skip6[4];
				char	texture_name[9];//mind the str_len!

				memset(texture_name, 0, sizeof(texture_name));

				file.read((char*)&str_len, sizeof(str_len));
				file.read(skip6, sizeof(skip6));
				file.read(texture_name, str_len);
				
				face.texture = path;
				face.texture += texture_name;

				//indices
				for(long counter = 0; counter < numPoints; counter++)
				{
					vector3di index;
					file.read((char*)&index, sizeof(vector3di));
					face.indices.push_back(index);
				}
			}
			else
			{
				faces.pop_back();
				for(long i = 0; i < alternativenumPoints - 1; i++)
				{
					vector3di index;
					file.read((char*)&index, sizeof(vector3di));
				}
			}
		}

	//	PrintContent(file, "output.txt");
	}


Create a new paste based on this one


Comments: