Example #1
0
TexturePack::TexturePack(Application* application,
                         const char* texturelistfile, const char* imagefile, Filter filter, Wrap wrap, Format format,
						 bool maketransparent/* = false*/, unsigned int transparentcolor/* = 0x00000000*/) :
    TextureBase(application, imagefile, filter, wrap, format, maketransparent, transparentcolor)
{
    float scale;
    const char *suffix = application->getImageSuffix(imagefile, &scale);

    const char *ext = strrchr(texturelistfile, '.');
    if (ext == NULL)
        ext = texturelistfile + strlen(texturelistfile);

    std::string texturelistfilex = std::string(texturelistfile, ext - texturelistfile) + (suffix ? suffix : "") + ext;

    G_FILE *f = g_fopen(texturelistfilex.c_str(), "r");
    if (f)
        g_fclose(f);

    if (f)
    {
        readTextureList(texturelistfilex.c_str(), textures_, filenameMap_);
        sizescalex = 1 / scale;
        sizescaley = 1 / scale;
        uvscalex = 1;
        uvscaley = 1;
    }
    else
    {
        readTextureList(texturelistfile, textures_, filenameMap_);
        // sizescalex, sizescaley, uvscalex, uvscaley are set at TextureBase's constructor
    }
}
int readMaterial()
{
	printInt(8);
	printInt(2);

	//Placeholder for length
	printBytes("\xFF\xFF\xFF\xFF", 4);

	int beginningOffset = ftell(output);

	readNothing("*MATERIAL");

	openBracket();

	int matRefNo = readInt("*MATERIAL_REF_NO");
	char* matName = readString("*MATERIAL_NAME");
	char* matClass = readString("*MATERIAL_CLASS");
	char* matAmbient = readRGB("*MATERIAL_AMBIENT");
	char* matDiffuse = readRGB("*MATERIAL_DIFFUSE");
	char* matSpecular = readRGB("*MATERIAL_SPECULAR");
	float matShine = readFloat("*MATERIAL_SHINE");
	float matShineStrength = readFloat("*MATERIAL_SHINESTRENGTH");
	float matTransparency = readFloat("*MATERIAL_TRANSPARENCY");
	/*float matTransparency;
	bracketize();
	char* buffer = (char*) malloc(sizeof(char)* 24);
	int offset = ftell(input);*/
	float matWireSize = readFloat("*MATERIAL_WIRESIZE");
	char* matShading = readString("*MATERIAL_SHADING");
	float matXPFallof = readFloat("*MATERIAL_XP_FALLOF");
	float matSelfIllum = readFloat("*MATERIAL_SELFILLUM");
	char* matFallof = readString("*MATERIAL_FALLOF");
	char* matXPType = readString("*MATERIAL_XP_TYPE");

	printInt(matRefNo);
	printString(matName);
	printString(matClass);
	printBytes(matAmbient, 4);
	printBytes(matDiffuse, 4);
	printBytes(matSpecular, 4);
	printFloat(matShine);
	printFloat(matShineStrength);
	printFloat(matTransparency);
	printFloat(matWireSize);

	if(!strncmp(matShading, "Blinn", 5))
		printInt(12);
	else
		printInt(0);

	printFloat(matXPFallof);
	printFloat(matSelfIllum);

	if(!strncmp(matFallof, "In", 2))
		printInt(1);
	else
		printInt(0);

	if(!strncmp(matXPType, "Filter", 6))
		printInt(1);
	else
		printInt(0);

	char* nextType = (char*)malloc(sizeof(char)*32);

	int numMaterials = 0;
	int numTextures = 0;

	int tParsed = 0;
	int mParsed = 0;

	while(1)
	{
		int currentOffset = ftell(input);
		fscanf(input, "%s\n", nextType);
		if(!strncmp(nextType, "*TEXTURE_LIST", 14) && tParsed == 0)
		{
			//Placeholder for number of textures
			int numTexturesOffset = ftell(output);
			printBytes("\xDE\xAD\xBE\xEF", 4);

			numTextures += readTextureList();

			int afterTextureList = ftell(output);
			fseek(output, numTexturesOffset, 0);
			printInt(numTextures);
			fseek(output, afterTextureList, 0);
			mParsed = 1;
		}
		else if(tParsed == 0)
		{
			tParsed = 1;
			printInt(0);
		}

		if(!strncmp(nextType, "*MATERIAL_LIST", 14) && mParsed == 0)
		{
			//Placeholder for number of textures
			int numMaterialsOffset = ftell(output);
			printBytes("\xDE\xAD\xBE\xEF", 4);

			numMaterials += readMaterialList();

			int afterMaterialList = ftell(output);
			fseek(output, numMaterialsOffset, 0);
			printInt(numMaterials);
			fseek(output, afterMaterialList, 0);
			mParsed = 1;
		}
		else if (mParsed == 0)
		{
			mParsed = 1;
			printInt(0);
		}		
		
		if(!strncmp(nextType, "}", 1))
		{
			fseek(input, currentOffset, 0);
			break;
		}
	}

	closeBracket();

	int endOffset = ftell(output);
	int size = endOffset - beginningOffset;

	fseek(output, beginningOffset - 4, 0);
	
	printInt(size);

	fseek(output, endOffset, 0);

	return 0;
}
void ASELoader::readMesh(vector<Vertex3> &vertices, vector<int> &triangles, vector<Vertex3> &textures, vector<int> &texturedTriangles)
{
	char line[255];
	string currentLine = line;

	// read the file until we come to a close bracket
	m_modelFile.getline(line,255);
	currentLine = line;
	do
	{
		if (currentLine.find("*MESH_NUMVERTEX")!= string::npos)
		{
			// read number of vertices...
			int displacement = (int)currentLine.find("*MESH_NUMVERTEX") + 15;
			m_numberOfVertices = atoi(currentLine.substr(displacement).c_str());
		}
		else if (currentLine.find("*MESH_NUMFACES")!= string::npos)
		{
			// read number of faces...
			int displacement = (int)currentLine.find("*MESH_NUMFACES") + 14;
			m_numberOfFaces = atoi(currentLine.substr(displacement).c_str());
		}
		else if (currentLine.find("*MESH_VERTEX_LIST")!= string::npos)
		{
			// read the actual vertices...
			readVertexList(vertices);
		}
		else if (currentLine.find("*MESH_FACE_LIST")!= string::npos)
		{
			// read the actual faces...
			readMeshFaceList(triangles);
		}
		// New - for loading textures
		else if (currentLine.find("*MESH_TVERTLIST")!= string::npos)
		{
			// read the actual faces...
			readTextureList(textures);
		}
		else if (currentLine.find("*MESH_TFACELIST")!= string::npos)
		{
			// read the actual faces...
			readTextureFaceList(texturedTriangles);
		}
		// end New - for loading textures
		else
		{
			// read some unknown data

			// read an unknown object...
			// if the line of the unknown line contains an open curly
			// bracket, skip to after the next close curly bracket.
			if (currentLine.find("{")!= string::npos)
			{
				do
				{
					m_modelFile.getline(line,255);
					currentLine = line;
				} while (currentLine.find("}") == string::npos);
			}
		}
		m_modelFile.getline(line,255);
		currentLine = line;
	} while (currentLine.find("}") == string::npos);
}