CS123MeshObjLoader.h

Go to the documentation of this file.
00001 /*
00002  *
00003  * This class will load meshes in standard obj format and 
00004  * provides an interface to get at the polygons in the file.
00005  *
00006  * @author nli
00007  */
00008 
00009 #ifndef __CS123_MESH_OBJ_LOADER__
00010 #define __CS123_MESH_OBJ_LOADER__
00011 
00012 /** Includes */
00013 #include <vector>
00014 
00015 //! Simple Struct to store uv's
00016 struct CS123MeshUV
00017 {
00018     float u, v;
00019     CS123MeshUV(float u, float v);
00020 };
00021 
00022 //! Struct to contain 3 floats
00023 struct float3
00024 {
00025     float x, y, z;
00026 };
00027 
00028 //! Generic Polygon Struct.
00029 /*!- Polygon will be stored in counter clockwise order
00030  * There will be in normal and uv for each vertex. */
00031 struct CS123Polygon
00032 {
00033     float* vertices;
00034     float* normals;
00035     CS123MeshUV* uvs;
00036     unsigned int num_vertices;
00037 };
00038 
00039 //! Utility class that will parse and load mesh files in standard obj format
00040 class CS123MeshObjLoader
00041 {
00042     public:
00043    //! Constructor for the mesh loader.  Initializes values.
00044    CS123MeshObjLoader();
00045    //! Clean up memory resources
00046    ~CS123MeshObjLoader();
00047 
00048    //! Returns true if mesh loaded successfully and false otherwise */
00049    bool loadMesh(const char* filename);
00050 
00051    //! Returns a list of polygons.
00052    /*! On return, numPolygons will store the 
00053     *  number of polygons in the list.  You are responsible for cleaning
00054     *  up the memory associated with the array of polygons.  (you must
00055     *  clean up the array and each of the arrays within the struct) */
00056    CS123Polygon* getPolygons(unsigned int& numPolygons);
00057 
00058     private:
00059    CS123Polygon* m_polygons;
00060    unsigned int m_numPolygons;
00061    unsigned int m_size;
00062    bool m_cleanMemory;
00063 
00064    std::vector<float3> m_vertexList;
00065    std::vector<CS123MeshUV> m_uvList;
00066    std::vector<float3> m_normalList;
00067 };
00068 
00069 #endif

Generated on Sat Sep 20 04:06:11 2008 for CS123Support by  doxygen 1.5.6