/**
 *\file		TriangleMesh.h
 *
 *\brief	For reading from an obj 3D model file. The model is translated so the center of the BBox is (0,0,0).
 *
 *\author	Xianming Chen
 *
 *\date		11 Jul 2004
 */


#ifndef _TRIANGLEMESH_H
#define _TRIANGLEMESH_H

#include "Canvas.h"
#include <vector>

/**
 * A triangle has 3 vertexes, and additionaly it may have normals and/or texture coordinates at these three vertexes.
 * All these values are of Point(Vector) type, and are specified only by the index value into some container which
 * is maintained in TriangleMesh class.
 *
 */
struct TriangleFace
{
    TriangleFace(int I, int J, int K, int Ti=-1, int Tj=-1, int Tk=-1, int Ni=-1, int Nj=-1, int Nk=-1) : 
      i(I), j(J), k(K), ti(Ti), tj(Tj), tk(Tk), ni(Ni), nj(Nj), nk(Nk) { }

    int i, j, k;                                               // indices of 3 vertices.
    int ni, nj, nk;                                            // indices of 3 normals.
    int ti, tj, tk;                                            // indices of 3 tex coords.
};
  

/**
 * Read in OBJ 3D model file, and provide access to its triangle data.
 */
struct TriangleMesh
{
    TriangleMesh(const string obj_fname);
    TriangleMesh()       { }

    void Draw(Canvas& canvas) const { }
      
    void init();

    std :: vector<Point> V;            // container of vertexes (x, y, z)
    std :: vector<Vector> N;           // container of normals (nx, ny, nz)
    std :: vector<RGB> T;              // container of textures (s, t, w)
    std :: vector<TriangleFace> F;     // container of triangles (i, j, k,  ni, nj, nk,  ti, tj, tk). 
    int total_triangles;

    bool has_normal;                            
    bool has_texture;
    Canvas* texture;                  // apply texture mapping only if this is non-zero and the trianglemesh has texture.
};


#endif
