Go to the documentation of this file.00001 #ifndef OPENTISSUE_KINEMATICS_SKINNING_IO_SKINNING_MATERIAL_CAL3D_XML_READ_H
00002 #define OPENTISSUE_KINEMATICS_SKINNING_IO_SKINNING_MATERIAL_CAL3D_XML_READ_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <TinyXML/tinyxml.h>
00013
00014 #include <cassert>
00015 #include <string>
00016 #include <sstream>
00017 #include <iostream>
00018
00019 namespace OpenTissue
00020 {
00021 namespace skinning
00022 {
00023
00024 template<typename material_type>
00025 bool material_cal3d_xml_read(std::string const & filename, material_type & mat)
00026 {
00027
00028 #ifdef TIXML_USE_STL
00029 TiXmlDocument xml_document(filename);
00030 #else
00031 TiXmlDocument xml_document(filename.c_str());
00032 #endif
00033
00034 if(!xml_document.LoadFile())
00035 {
00036 std::cerr << "file: " << filename << " not found" << std::endl;
00037 return false;
00038 }
00039
00040 std::stringstream str;
00041 TiXmlNode* node;
00042 TiXmlElement * xml_material = xml_document.FirstChildElement( "MATERIAL" );
00043 if(xml_material)
00044 {
00045 TiXmlElement * ambient = xml_material->FirstChildElement("AMBIENT");
00046 if(ambient)
00047 {
00048 float r,g,b,a;
00049
00050 node = ambient->FirstChild();
00051 TiXmlText* ambientdata = node->ToText();
00052 str.clear();
00053 str << ambientdata->Value();
00054 str >> r >> g >> b >> a;
00055
00056 if(r>1.0) r /= 255.0;
00057 if(g>1.0) g /= 255.0;
00058 if(b>1.0) b /= 255.0;
00059 if(a>1.0) a /= 255.0;
00060 mat.ambient(r,g,b,a);
00061 }
00062
00063 TiXmlElement * diffuse = xml_material->FirstChildElement("DIFFUSE");
00064
00065 if(diffuse)
00066 {
00067 float r,g,b,a;
00068
00069 node = diffuse->FirstChild();
00070 TiXmlText* diffusedata = node->ToText();
00071 str.clear();
00072 str << diffusedata->Value();
00073 str >> r >> g >> b >> a;
00074
00075 if(r>1.0) r /= 255.0;
00076 if(g>1.0) g /= 255.0;
00077 if(b>1.0) b /= 255.0;
00078 if(a>1.0) a /= 255.0;
00079 mat.diffuse(r,g,b,a);
00080 }
00081
00082 TiXmlElement * specular = xml_material->FirstChildElement("SPECULAR");
00083
00084 if(specular)
00085 {
00086 float r,g,b,a;
00087
00088 node = specular->FirstChild();
00089 TiXmlText* speculardata = node->ToText();
00090 str.clear();
00091 str << speculardata->Value();
00092 str >> r >> g >> b >> a;
00093
00094 if(r>1.0) r /= 255.0;
00095 if(g>1.0) g /= 255.0;
00096 if(b>1.0) b /= 255.0;
00097 if(a>1.0) a /= 255.0;
00098
00099 mat.specular(r,g,b,a);
00100 }
00101
00102 TiXmlElement * shininess = xml_material->FirstChildElement("SHININESS");
00103
00104 if(shininess)
00105 {
00106 float s;
00107
00108 node = shininess->FirstChild();
00109 TiXmlText* shininessdata = node->ToText();
00110 str.clear();
00111 str << shininessdata->Value();
00112 str >> s;
00113
00114 mat.shininess(s);
00115 }
00116 }
00117
00118 xml_document.Clear();
00119 return true;
00120 };
00121
00122 }
00123 }
00124
00125
00126 #endif