// 3 / 22/ 04 Forrest Briggs
// Loads a milkshape 3d ascii file with texturemaps and calls interface commands in cStaticTriangle mesh to build
// the mesh in the engine. Updated file handling to C++ style and stripped some junk away from milkshape sdk importer code.
#ifndef cms3dfileloader_h
#define cms3dfileloader_h

#include <vector>

#include <stdio.h>
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <cctype>

#include "cStaticTriangleMesh.h"

using namespace std;

class cMS3DFileLoader
{
private:
    class MS3DVertex
    {
    public:
        float x_, y_, z_, u_, v_;
        int index_;
    };
    
    class MS3DTriangle
    {
    public:
        int v0_, v1_, v2_;	// indices of the vertices
    };
    
    class MS3DMaterial
    {
    public:
        char textureFilename_[256];
        int index_;
    };
    
    class MS3DMesh
    {
    public:
        int numTriangles_, numVertices_;
        int materialIndex_;
        
        MS3DVertex* vertices_;
        MS3DTriangle* triangles_;
        
        ~MS3DMesh() { delete[] vertices_; delete[] triangles_; }
    };
    
    class MS3DModel
    {	
    public:
        int numMeshes_, numMaterials_;
        MS3DMesh* meshes_;
        MS3DMaterial* materials_;
        
        ~MS3DModel() { delete[] meshes_; delete[] materials_; }
    };
    
    MS3DModel model_;

public:
    // load a milkshape 3d ascii text file into model_
    void load(const string& filename);
    
    // build a cStaticTriangleMesh from the milkshape model
    void buildStaticTriangleMesh(cStaticTriangleMesh& mesh);
};

#endif