#include "dkdata.h"

//==============================================================

// each element in the array corresponds directly 
// to each element in the triangles array
uvinfo_t	uvinfo;
uv_t		uvdata[MAX_TRIANGLES][3];

/*
============
LoadUVFromFile
============
*/
void LoadUVFromFile (char *filename)
{
	FILE	*f;
	int		i, j;
	int		polynum, num_xyz;
	int		junk;
	int		surfcount;

	surfcount = 0;

	StripExtension (filename);
	strcat (filename, ".uv");

	f = fopen (filename, "r");
	if (!f)
		Error ("LoadUVFile: Error opening file\n");

	// get version number
	fscanf (f, "%d\n", &uvinfo.version);

	// get number of images
	fscanf (f, "%d\n", &uvinfo.num_images);

	// images
	for (i = 0; i < uvinfo.num_images; i++)
	{
		fscanf (f, "%s\n", lwinfo.lwsurface[i].timg[0]);
		lwinfo.lwsurface[i].texmode[0] = TEXMODE_CTEX;
	}

	// get number of polys
	fscanf (f, "%d\n", &uvinfo.num_polys);

	for (i = 0; i < uvinfo.num_polys; i++)
	{
		fscanf (f, "%d %d\n", &polynum, &num_xyz);
		
		for (j = 0; j < 3; j++)
			fscanf (f, "%f %f %d\n", &uvdata[i][j][0], &uvdata[i][j][1], &junk);
	}

	fclose (f);
}


