#ifndef loadobj_h
#define loadobj_h

#include "svk_vector_utils.hpp"
#include <stdint.h>


// How many error messages do you want before it stops?
#define NUM_DRAWMODEL_ERROR 8

typedef struct Mtl
{
	char newmtl[255];
	
	vec3 Ka, Kd, Ks, Ke;
	// I have also seen vec3's named Tf and a float called Ni in one file. What is that?
	// Tf = transmission filter
	// Ni = optical_density
	float Ns, Tr, d; // Tr = 1-d
	int illum;	// illumination model 0..10
	char map_Ka[255], map_Kd[255], map_Ks[255], map_Ke[255], map_Ns[255], map_d[255], map_bump[255];
	
	// NEW for texture support
	int texidKa, texidKd, texidKs, texidKe, texidNs, texid_d, texid_bump; // References to loaded textures!
	// refl -type not supported -o for options? A whole bunch.
	// Extensions for physically based rendering not supported
} Mtl, *MtlPtr, **MtlHandle;

typedef struct
{
  vec3* vertexArray;
  vec3* normalArray;
  vec2* texCoordArray;
  vec3* colorArray; // Rarely used
//  unsigned int* indexArray;
  uint32_t* indexArray;
  int numVertices;
  int numIndices;
  char externalData;
  
  // Space for saving VBO and VAO IDs
  unsigned int vao; // VAO
  unsigned int vb, ib, nb, tb; // VBOs
  
  Mtl *material;
} ModelData;

// Basic model loading
ModelData* LoadModelData(const char* name); // Load OBJ as single Model
ModelData** LoadModelDataSet(const char* name);  // Multi-part OBJ!


// Utility functions that you may need if you want to modify the model.

ModelData* LoadDataToModelData(
			vec3 *vertices,
			vec3 *normals,
			vec2 *texCoords,
			vec3 *colors,
			unsigned int *indices,
			int numVert,
			int numInd);

void CenterModelData(ModelData *m);
void ScaleModelData(ModelData *m, float sx, float sy, float sz);
void DisposeModelData(ModelData *m);

//#ifdef __cplusplus
//}
///#endif

#endif
