gKitGL
MeshMaterialIO.h
00001 
00002 #ifndef _IOMESH_MATERIAL_H
00003 #define _IOMESH_MATERIAL_H
00004 
00005 #include <cstdio>
00006 
00007 #include "IOManager.h"
00008 #include "MeshMaterial.h"
00009 #include "MeshOBJ.h"
00010 
00011 namespace gk {
00012 
00013 //! manager pour importer des matieres.
00014 class MeshMaterialIO : public IOManager<MeshMaterial>
00015 {
00016     // non copyable
00017     MeshMaterialIO( const MeshMaterialIO& );
00018     MeshMaterialIO& operator=( const MeshMaterialIO& );
00019     
00020     // private default constructor, singleton
00021     MeshMaterialIO( )
00022         :
00023         IOManager<MeshMaterial>()
00024     {}
00025     
00026     ~MeshMaterialIO( ) {}
00027     
00028 public:
00029     //! importe la matiere 'name' du fichier 'filename'
00030     static
00031     MeshMaterial *read( const std::string& filename, const std::string& name= "" ) 
00032     {
00033         // importer le fichier, si necessaire
00034         MeshMaterial *material= manager().find(filename, name);
00035         if(material != NULL)
00036             return material;
00037         
00038         // importer le fichier et referencer toutes les matieres dans le manager
00039         if(MaterialLoadFromMTL(filename) < 0)
00040         {
00041             printf("'%s' failed.\n", filename.c_str());
00042             return NULL;
00043         }
00044         
00045         // rechercher et renvoyer la matiere 'name'
00046         return manager().find(filename, name);
00047     }
00048 
00049     static
00050     MeshMaterialIO &manager( )  // singleton
00051     {
00052         static MeshMaterialIO manager;
00053         return manager;
00054     }
00055 };
00056 
00057 }       // namespace
00058 
00059 #endif
 All Classes Namespaces Functions Variables Typedefs Enumerator Friends