00001 /****************************************************************************** 00002 * SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3 * 00003 * (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS * 00004 * * 00005 * This library is free software; you can redistribute it and/or modify it * 00006 * under the terms of the GNU Lesser General Public License as published by * 00007 * the Free Software Foundation; either version 2.1 of the License, or (at * 00008 * your option) any later version. * 00009 * * 00010 * This library is distributed in the hope that it will be useful, but WITHOUT * 00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * 00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * 00013 * for more details. * 00014 * * 00015 * You should have received a copy of the GNU Lesser General Public License * 00016 * along with this library; if not, write to the Free Software Foundation, * 00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 00018 ******************************************************************************* 00019 * SOFA :: Framework * 00020 * * 00021 * Authors: M. Adam, J. Allard, B. Andre, P-J. Bensoussan, S. Cotin, C. Duriez,* 00022 * H. Delingette, F. Falipou, F. Faure, S. Fonteneau, L. Heigeas, C. Mendoza, * 00023 * M. Nesme, P. Neumann, J-P. de la Plata Alcade, F. Poyer and F. Roy * 00024 * * 00025 * Contact information: contact@sofa-framework.org * 00026 ******************************************************************************/ 00027 #ifndef SOFA_HELPER_IO_MESH_H 00028 #define SOFA_HELPER_IO_MESH_H 00029 00030 #include <sofa/helper/vector.h> 00031 #include <sofa/defaulttype/Vec.h> 00032 #include <sofa/helper/Factory.h> 00033 //#include <sofa/core/objectmodel/Data.h> 00034 namespace sofa 00035 { 00036 00037 namespace helper 00038 { 00039 00040 namespace io 00041 { 00042 00043 using sofa::helper::vector; 00044 using sofa::defaulttype::Vector3; 00045 00046 using sofa::defaulttype::Vec4f; 00047 00048 class Mesh 00049 { 00050 public: 00051 00052 class Material 00053 { 00054 public: 00055 std::string name; /* name of material */ 00056 Vec4f diffuse ; /* diffuse component */ 00057 Vec4f ambient ; /* ambient component */ 00058 Vec4f specular; /* specular component */ 00059 Vec4f emissive; /* emmissive component */ 00060 float shininess; /* specular exponent */ 00061 bool useDiffuse; 00062 bool useSpecular; 00063 bool useAmbient; 00064 bool useEmissive; 00065 bool useShininess; 00066 bool activated; 00067 00068 void setColor(float r, float g, float b, float a); 00069 00070 inline friend std::ostream& operator << (std::ostream& out, const Material& m ) 00071 { 00072 out << m.name << " "; 00073 out << "Diffuse" << " " << m.useDiffuse << " " << m.diffuse << " "; 00074 out << "Ambient" << " " << m.useAmbient << " " << m.ambient << " "; 00075 out << "Specular" << " " << m.useSpecular << " " << m.specular << " "; 00076 out << "Emissive" << " " << m.useEmissive << " " << m.emissive << " "; 00077 out << "Shininess" << " " << m.useShininess << " " << m.shininess ; 00078 return out; 00079 } 00080 inline friend std::istream& operator >> (std::istream& in, Material &m ) 00081 { 00082 00083 std::string element; 00084 in >> m.name ; 00085 for (unsigned int i=0;i<5;++i) 00086 { 00087 in >> element; 00088 if (element == std::string("Diffuse") || element == std::string("diffuse") ) { in >> m.useDiffuse ;in >> m.diffuse; } 00089 else if (element == std::string("Ambient") || element == std::string("ambient") ) { in >> m.useAmbient ;in >> m.ambient; } 00090 else if (element == std::string("Specular") || element == std::string("specular") ) { in >> m.useSpecular ;in >> m.specular; } 00091 else if (element == std::string("Emissive") || element == std::string("emissive") ) { in >> m.useEmissive ;in >> m.emissive; } 00092 else if (element == std::string("Shininess") || element == std::string("shininess") ) { in >> m.useShininess ;in >> m.shininess; } 00093 } 00094 return in; 00095 } 00096 00097 Material(); 00098 }; 00099 00100 protected: 00101 vector<Vector3> vertices; 00102 vector<Vector3> texCoords; // for the moment, we suppose that texCoords is order 2 (2 texCoords for a vertex) 00103 vector<Vector3> normals; 00104 vector< vector < vector <int> > > facets; 00105 //sofa::core::objectmodel::Data< Material > material; 00106 Material material; 00107 00108 std::string textureName; 00109 public: 00110 00111 vector<Vector3> & getVertices() 00112 { 00113 //std::cout << "vertices size : " << vertices.size() << std::endl; 00114 return vertices; 00115 }; 00116 vector<Vector3> & getTexCoords() { return texCoords; } 00117 vector<Vector3> & getNormals() { return normals; } 00118 vector< vector < vector <int> > > & getFacets() 00119 { 00120 //std::cout << "facets size : " << facets.size() << std::endl; 00121 return facets; 00122 }; 00123 const Material& getMaterial() {return material; } 00124 00125 std::string& getTextureName() 00126 { 00127 return textureName; 00128 }; 00129 00130 typedef Factory<std::string, Mesh, std::string> FactoryMesh; 00131 00132 static Mesh* Create(std::string filename); 00133 00134 template<class Object> 00135 static void create(Object*& obj, std::string arg) 00136 { 00137 obj = new Object(arg); 00138 } 00139 00140 }; 00141 00142 } // namespace io 00143 00144 } // namespace helper 00145 00146 } // namespace sofa 00147 00148 #endif
1.5.7.1