#define MAX_POINTS		2048
#define MAX_SURFACES	32
#define MAX_POLYGONS	800
#define MAX_CURVES		200
#define MAX_TEXCHUNKS	6

#define TEXMODE_CTEX	0x1
#define TEXMODE_DTEX	0x2
#define TEXMODE_STEX	0x4
#define TEXMODE_RTEX	0x8
#define TEXMODE_TTEX	0x01
#define TEXMODE_BTEX	0x02

typedef struct 
{
	float	point[3];
} lwpoint_t;

// this structure keeps all the chunk info for a .lwo file
typedef struct
{
	char	name[16];	// surface name
	byte	colr[4];	// color componant of surface. rgb[3] should always be 0
	short	flag;		// surface flags
	short	lumi;		// luminosity value
	short	diff;		// diffuse light value
	short	spec;		// specular light value
	short	refl;		// reflection value
	short	tran;		// transparency value
	short	glos;		// glossiness value
	char	rimg[128];	// filename of reflection map
	float	rsan;		// heading angle of reflection map seam
	float	rind;		// refractive index
	float	edge;		// edge transparency
	float	sman;		// max angle between 2 adjacent polys than can be smooth shaded

	// the following chunks are specific to the texture mode. 
	// currently they can appear up to 6 times in a .lwo file (onr for each texture mode)
	short	texmode[MAX_TEXCHUNKS];		// CTEX, DTEX, STEX, RTEX, TTEX, or BTEX
	char	textype[MAX_TEXCHUNKS][32]; // texture mapping mode
	char	timg[MAX_TEXCHUNKS][128];	// filename of texture image
	short	tflg[MAX_TEXCHUNKS];		// texture options
	float	tsiz[MAX_TEXCHUNKS][3];		// texture size
	float	tctr[MAX_TEXCHUNKS][3];		// texture center
	float	tfal[MAX_TEXCHUNKS][3];		// texture falloff
	float	tvel[MAX_TEXCHUNKS][3];		// texture velocity
	int		tclr[4];					// texture color, requires CTEX subchunk
	short	tval[MAX_TEXCHUNKS];		// requires DTEX, STEX, RTEX, or TTEX subchunk
	float	tamp;						// requires BTEX subchunk
	short	tfrq[MAX_TEXCHUNKS];		// number of noise frequencies or wave sources
	float	tsp0[MAX_TEXCHUNKS];		// special texture type-specific parameter
	float	tsp1[MAX_TEXCHUNKS];		// special texture type-specific parameter
	float	tsp2[MAX_TEXCHUNKS];		// special texture type-specific parameter
} lwsurface_t;

typedef struct lwpoly_s
{
	short	num_xyz;
	short	index_surface;
	short	*index_xyz;
	short	num_detailpolys;
	struct lwpoly_s	*detailpolys;
} lwpoly_t;

typedef struct
{
	short	num_xyz;
	short	index_surface;
	short	flags;
	short	*index_xyz;
} lwcurve_t;

typedef struct
{
	int	num_polys;
	int	num_points;
	int	num_curves;
	int	num_surfaces;

	lwpoint_t	*lwpoint;
	lwpoly_t	*lwpoly;
	lwsurface_t	*lwsurface;
	lwcurve_t	*lwcurve;
} lwinfo_t;

extern lwinfo_t	lwinfo;		

int align (int len);
int LW_OpenFile (char *filename, byte **start, byte **end);
void LW_CloseFile (void);
void LW_ParseChunkPNTS (byte *in, int chunklength);
void LW_ParseChunkSRFS (byte *in, int chunklength);
void LW_ParseChunkPOLS (byte *in, int chunklength);
void LW_ParseChunkCRVS (byte *in, int chunklength);
void LW_ParseChunkSURF (byte *in, int chunklength);
byte *LW_ParseChunkUnknown (byte *in, int chunklength);
