export_idtf.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 * MeshLab                                                           o o     *
00003 * An extendible mesh processor                                    o     o   *
00004 *                                                                _   O  _   *
00005 * Copyright(C) 2005, 2009                                          \/)\/    *
00006 * Visual Computing Lab                                            /\/|      *
00007 * ISTI - Italian National Research Council                           |      *
00008 *                                                                    \      *
00009 * All rights reserved.                                                      *
00010 *                                                                           *
00011 * This program is free software; you can redistribute it and/or modify      *
00012 * it under the terms of the GNU General Public License as published by      *
00013 * the Free Software Foundation; either version 2 of the License, or         *
00014 * (at your option) any later version.                                       *
00015 *                                                                           *
00016 * This program is distributed in the hope that it will be useful,           *
00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
00019 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
00020 * for more details.                                                         *
00021 *                                                                           *
00022 ****************************************************************************/
00023 
00024 #ifndef __VCGLIB_EXPORTERIDTF
00025 #define __VCGLIB_EXPORTERIDTF
00026 
00027 
00028 #include <sstream>
00029 #include <fstream>
00030 #include <ostream>
00031 #include <string>
00032 #include <ios>
00033 #include <vcg/space/color4.h>
00034 #include <vcg/complex/algorithms/update/bounding.h>
00035 #include <wrap/io_trimesh/io_mask.h>
00036 #include <QString>
00037 #include <QFile>
00038 
00039 
00040 
00041 class TextUtility
00042 {
00043 public:
00044         template<typename NUMERICTYPE>
00045         static std::string nmbToStr(NUMERICTYPE n)
00046         {
00047                 std::stringstream ss;
00048                 ss.setf(std::ios::fixed);
00049                 ss << n;
00050                 ss.setf(std::ios::scientific);
00051                 return ss.str();
00052         }
00053 };
00054 
00055 class Output_File
00056 {
00057 public:
00058         Output_File(const std::string& file)
00059                 :_file()
00060         {
00061                 _file.open(file.c_str(),std::ios::out);
00062         }
00063 
00064         void write(unsigned int tabl,const std::string& st)
00065         {
00066                 std::string tmp;
00067                 for(unsigned int ii = 0;ii < tabl;++ii)
00068                         tmp += '\t';
00069                 _file << tmp << st << std::endl;
00070         }
00071 
00072         ~Output_File()
00073         {
00074                 _file.close();
00075         }
00076 
00077 private:
00078         std::ofstream _file;
00079         std::string _tab;
00080 };
00081 
00082 #include <QString>
00083 #include <QtGlobal>
00084 #include <fstream>
00085 #include <QImage>
00086 
00087 
00088 namespace vcg {
00089 namespace tri {
00090 namespace io {
00091 
00092 
00093 namespace QtUtilityFunctions
00094 {
00095         static void splitFilePath(const QString& filepath,QStringList& trim_path)
00096         {
00097                 QString file_uniformed = filepath;
00098                 file_uniformed.replace(QString("\\"),QString("/"));
00099                 trim_path = file_uniformed.split("/");
00100         }
00101 
00102         static QString fileNameFromTrimmedPath(const QStringList& file_path)
00103         {
00104 
00105                 if (file_path.size() > 0)
00106                         return file_path.at(file_path.size() - 1);
00107                 else 
00108                         return QString();
00109         }
00110 
00111         static QString fileNameFromPath(const QString& filepath)
00112         {
00113                 QStringList list;
00114                 splitFilePath(filepath,list);
00115                 return fileNameFromTrimmedPath(list);
00116         }
00117 
00118         static QString pathWithoutFileName(const QString& filepath)
00119         {
00120                 QString tmp(filepath);
00121                 tmp.remove(fileNameFromPath(filepath));
00122                 return tmp;
00123         }
00124 
00125         static QString fileExtension(const QString& filepath)
00126         {
00127                 QStringList trim_list;
00128                 splitFilePath(filepath,trim_list);
00129                 QString file = fileNameFromTrimmedPath(trim_list);
00130                 trim_list = file.split(".");
00131                 return trim_list.at(trim_list.size() - 1);
00132         }
00133 }
00134 
00135 class TGA_Exporter
00136 {
00137 public:
00138 
00139         struct TGAHeader
00140         {
00141                 unsigned char  identsize;          
00142                 unsigned char  colourmaptype;      
00143                 unsigned char  imagetype;          
00144 
00145                 unsigned char colormapspecs[5];
00146 
00147                 short xstart;             
00148                 short ystart;             
00149                 short width;              
00150                 short height;             
00151                 unsigned char  bits;               
00152                 unsigned char  descriptor;         
00153         };
00154 
00155         static void convert(const QString& outfile,const QImage& im)
00156         {
00157                 TGAHeader tga;
00158                 tga.identsize = 0;
00159                 tga.colourmaptype = 0;
00160                 tga.imagetype = 2;
00161 
00162                 memset(tga.colormapspecs,0,5);
00163                 tga.xstart = (short) im.offset().x();
00164                 tga.ystart = (short) im.offset().y();
00165                 tga.height = (short) im.height();
00166                 tga.width =  (short) im.width();
00167                 
00168 
00169                 //QString moutfile = QString("C:/Users/Guido/AppData/Local/Temp/duckCM.tga");
00170 
00171                 QFile file(qPrintable(outfile));
00172                 file.setPermissions(QFile::WriteOther);
00173                 file.open(QIODevice::WriteOnly);
00174                 QString err = file.errorString();
00175                 //bool val = file.failbit;
00176                 unsigned char* tmpchan;
00177                 int totbyte;
00178                 if (im.hasAlphaChannel())
00179                 {
00180                         //is a 8-digits binary number code  
00181                         // always 0 0  |  mirroring | bits 
00182                         //(future uses)|  image     | for alpha-channel
00183                         //--------------------------------------------                  
00184                         //     7 6     |      5 4   |      3 2 1 0
00185                         //--------------------------------------------
00186                         //     0 0     |      1 0   |      1 0 0 0
00187                         tga.descriptor = (char) 40;
00188                         tga.bits = (char) 32;
00189                 }
00190                 else
00191                 {
00192                         //is a 8-digits binary number code  
00193                         // always 0 0  |  mirroring | bits 
00194                         //(future uses)|  image     | for alpha-channel
00195                         //--------------------------------------------                  
00196                         //     7 6     |      5 4   |      3 2 1 0
00197                         //--------------------------------------------
00198                         //     0 0     |      1 0   |      0 0 0 0
00199                         tga.descriptor = (char) 32;
00200                         tga.bits = (char) 24;
00201                 }
00202 
00203                 totbyte = tga.height * tga.width * (tga.bits / 8);
00204 
00205                 if (im.hasAlphaChannel())
00206                         tmpchan = const_cast<unsigned char*>(im.bits());
00207                 else
00208                 {
00209                         tmpchan = new unsigned char[totbyte];
00210 
00211                         int ii = 0;
00212                         while(ii < totbyte)
00213                         {
00214                                 tmpchan[ii] = const_cast<unsigned char*>(im.bits())[ii + (ii/3)];
00215                                 ++ii;
00216                         }
00217                 }
00218 
00219                 file.write((char *) &tga,qint64(sizeof(tga)));
00220                 file.write(reinterpret_cast<const char*>(tmpchan),qint64(totbyte));
00221                 file.close();
00222         }
00223         
00224         template<typename SaveMeshType>
00225         static void convertTexturesFiles(SaveMeshType& m,const QString& file_path,QStringList& conv_file)
00226         {
00227                 for(unsigned int ii = 0; ii < m.textures.size(); ++ii)
00228                 {
00229                         QString qtmp(m.textures[ii].c_str());
00230                         QString ext = QtUtilityFunctions::fileExtension(qtmp);
00231                         QString filename = QtUtilityFunctions::fileNameFromPath(qtmp);
00232                         if (ext.toLower() != "tga")
00233                         {
00234                                 QImage img(qtmp);
00235                                 QString stmp;
00236                                 if ((file_path.at(file_path.length() - 1) != '/') || (file_path.at(file_path.length() - 1) != '\\'))
00237                                         stmp = file_path + QString("/");
00238                                 else
00239                                         stmp = file_path;
00240                                 filename = stmp + filename.remove(ext) + "tga";
00241                                 m.textures[ii] = filename.toStdString();
00242                                 TGA_Exporter::convert(filename,img);
00243                                 conv_file.push_back(filename);
00244                         }
00245                 }
00246         }
00247 
00248         static void removeConvertedTexturesFiles(const QStringList& conv_file)
00249         {
00250         for(QStringList::size_type ii = 0;ii < conv_file.size();++ii)
00251                 {
00252                         QDir dir(QtUtilityFunctions::pathWithoutFileName(conv_file[ii]));
00253                         dir.remove(QtUtilityFunctions::fileNameFromPath(conv_file[ii]));
00254                 }
00255         }
00256 };
00257 
00258 
00259 
00260 template<typename SaveMeshType>
00261 class ExporterIDTF
00262 {
00263 
00264 public:
00265 typedef typename SaveMeshType::VertexPointer VertexPointer;
00266 typedef typename SaveMeshType::ScalarType ScalarType;
00267 typedef typename SaveMeshType::VertexType VertexType;
00268 typedef typename SaveMeshType::FaceType FaceType;
00269 typedef typename SaveMeshType::ConstVertexIterator ConstVertexIterator;
00270 typedef typename SaveMeshType::VertexIterator VertexIterator;
00271 typedef typename SaveMeshType::FaceIterator FaceIterator;
00272 typedef typename SaveMeshType::ConstFaceIterator ConstFaceIterator;
00273 typedef typename SaveMeshType::CoordType CoordType;
00274 
00275         enum IDTFError 
00276         {
00277                 E_NOERROR                               // 0
00278         };
00279 
00280         static const char *ErrorMsg(int error)
00281         {
00282                 static const char * dae_error_msg[] =
00283                 {
00284                         "No errors"
00285                 };
00286 
00287                 if(error>0 || error<0) return "Unknown error";
00288                 else return dae_error_msg[error];
00289         };
00290         
00291         static QStringList convertInTGATextures(SaveMeshType& m,const QString& path,QStringList& textures_to_be_restored)
00292         {
00293                 //if there are textures file that aren't in tga format I have to convert them
00294                 //I maintain the converted file name (i.e. file_path + originalname without extension + tga) in mesh.textures but I have to revert to the original ones
00295                 //before the function return. 
00296                 for(unsigned int ii = 0; ii < m.textures.size();++ii)
00297                         textures_to_be_restored.push_back(m.textures[ii].c_str());
00298 
00299                 //tmp vector to save the tga created files that should be deleted.
00300                 QStringList convfile;
00301                 vcg::tri::io::TGA_Exporter::convertTexturesFiles(m,path,convfile);
00302                 return convfile;
00303         }
00304 
00305         static void removeConvertedTGATextures(const QStringList& convfile)
00306         {
00307                 //if some tga files have been created I have to delete them
00308                 vcg::tri::io::TGA_Exporter::removeConvertedTexturesFiles(convfile);
00309         }
00310 
00311         static void restoreConvertedTextures(SaveMeshType& mesh_with_textures_to_be_restored,const QStringList& textures_to_be_restored)
00312         {
00313                 mesh_with_textures_to_be_restored.textures.clear();
00314                 for(QStringList::ConstIterator it = textures_to_be_restored.begin();it != textures_to_be_restored.end();++it)
00315                         mesh_with_textures_to_be_restored.textures.push_back(it->toStdString());
00316         }
00317 
00318         static int Save(SaveMeshType& m,const char* file,const int mask)
00319         {
00320                 
00321                 Output_File idtf(file);
00322 
00323                 idtf.write(0,"FILE_FORMAT \"IDTF\"");
00324                 idtf.write(0,"FORMAT_VERSION 100\n");
00325 
00326                 idtf.write(0,"NODE \"MODEL\" {");
00327                 idtf.write(1,"NODE_NAME \"VcgMesh01\"");
00328                 idtf.write(1,"PARENT_LIST {");
00329                 idtf.write(2,"PARENT_COUNT 1");
00330                 idtf.write(2,"PARENT 0 {");
00331                 idtf.write(3,"PARENT_NAME \"<NULL>\"");
00332                 idtf.write(3,"PARENT_TM {");
00333                 idtf.write(4,"1.000000 0.000000 0.000000 0.000000");
00334                 idtf.write(4,"0.000000 1.000000 0.000000 0.000000");
00335                 idtf.write(4,"0.000000 0.000000 1.000000 0.000000");
00336                 idtf.write(4,"0.000000 0.000000 0.000000 1.000000");
00337                 idtf.write(3,"}");
00338                 idtf.write(2,"}");
00339                 idtf.write(1,"}");
00340                 idtf.write(1,"RESOURCE_NAME \"MyVcgMesh01\"");
00341                 idtf.write(0,"}");
00342 
00343 
00344                 if ((mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD) | (mask & vcg::tri::io::Mask::IOM_VERTCOLOR) | (mask & vcg::tri::io::Mask::IOM_FACECOLOR))
00345                 {
00346                         idtf.write(0,"");
00347                         idtf.write(0,"RESOURCE_LIST \"SHADER\" {");
00348                         idtf.write(1,"RESOURCE_COUNT " + TextUtility::nmbToStr(m.textures.size()));
00349                         for(unsigned int ii = 0; ii < m.textures.size(); ++ii)
00350                         {
00351                                 idtf.write(1,"RESOURCE " + TextUtility::nmbToStr(ii) + " {");
00352                                 idtf.write(2,"RESOURCE_NAME \"ModelShader" + TextUtility::nmbToStr(ii) +"\"");
00353                                 std::string vertcol;
00354                                 if (mask & vcg::tri::io::Mask::IOM_VERTCOLOR)
00355                                         vertcol = "TRUE";
00356                                 else
00357                                         vertcol = "FALSE";
00358 
00359                                 idtf.write(2,"ATTRIBUTE_USE_VERTEX_COLOR \"" + vertcol + "\"");
00360                                 idtf.write(2,"SHADER_MATERIAL_NAME \"Mat01\"");
00361 
00362 
00363                                 size_t texcount = 0;
00364                                 if (mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD)
00365                                         texcount = m.textures.size();
00366 
00367                                 
00368                                 idtf.write(2,"SHADER_ACTIVE_TEXTURE_COUNT " + TextUtility::nmbToStr(texcount));
00369                                 if (mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD)
00370                                 {
00371                                         idtf.write(2,"SHADER_TEXTURE_LAYER_LIST {");
00372                                         idtf.write(3,"TEXTURE_LAYER 0 {");
00373                                         idtf.write(4,"TEXTURE_NAME \"Texture" + TextUtility::nmbToStr(ii) +"\"");
00374                                         idtf.write(3,"}");
00375                                         idtf.write(2,"}");
00376                                 }
00377 
00378                 idtf.write(1,"}");
00379                         }
00380                         idtf.write(0,"}");
00381                         idtf.write(0,"");
00382                 }
00383 
00384                 if ((mask & Mask::IOM_WEDGTEXCOORD) | (mask & vcg::tri::io::Mask::IOM_VERTCOLOR) | (mask & vcg::tri::io::Mask::IOM_FACECOLOR))
00385                 {
00386                         idtf.write(0,"RESOURCE_LIST \"MATERIAL\" {");
00387                         idtf.write(1,"RESOURCE_COUNT 1");
00388                         idtf.write(1,"RESOURCE 0 {");
00389                         idtf.write(2,"RESOURCE_NAME \"Mat01\"");
00390                         idtf.write(2,"MATERIAL_AMBIENT 0.2 0.2 0.2");
00391                         idtf.write(2,"MATERIAL_DIFFUSE 0.8 0.8 0.8");
00392                         idtf.write(2,"MATERIAL_SPECULAR 0.0 0.0 0.0");
00393                         idtf.write(2,"MATERIAL_EMISSIVE 0.0 0.0 0.0");
00394                         idtf.write(2,"MATERIAL_REFLECTIVITY 0.000000");
00395                         idtf.write(2,"MATERIAL_OPACITY 1.000000");
00396                         idtf.write(1,"}");
00397                         idtf.write(0,"}");
00398                         idtf.write(0,"");
00399                         if ((mask & Mask::IOM_WEDGTEXCOORD))
00400                         {
00401                                 idtf.write(0,"RESOURCE_LIST \"TEXTURE\" {");
00402                                 idtf.write(1,"RESOURCE_COUNT " + TextUtility::nmbToStr(m.textures.size()));
00403                                 for(unsigned int ii = 0; ii < m.textures.size();++ii)
00404                                 {
00405                                         idtf.write(1,"RESOURCE " + TextUtility::nmbToStr(ii) + " {");
00406                                         idtf.write(2,"RESOURCE_NAME \"Texture" + TextUtility::nmbToStr(ii) + "\"");
00407                                         idtf.write(2,"TEXTURE_PATH \"" + m.textures[ii] + "\"");
00408                                         idtf.write(1,"}");
00409                                 }
00410                                 idtf.write(0,"}");
00411                         }
00412 
00413                 }
00414                 idtf.write(0,"");
00415                 idtf.write(0,"RESOURCE_LIST \"MODEL\" {");
00416                 idtf.write(1,"RESOURCE_COUNT 1");
00417                 idtf.write(1,"RESOURCE 0 {");
00418                 idtf.write(2,"RESOURCE_NAME \"MyVcgMesh01\"");
00419                 idtf.write(2,"MODEL_TYPE \"MESH\"");
00420                 idtf.write(2,"MESH {");
00421                 idtf.write(3,"FACE_COUNT " + TextUtility::nmbToStr(m.face.size()));
00422                 idtf.write(3,"MODEL_POSITION_COUNT " + TextUtility::nmbToStr(m.vert.size()));
00423                 idtf.write(3,"MODEL_NORMAL_COUNT " + TextUtility::nmbToStr(m.face.size() * 3));
00424                 if ((mask & vcg::tri::io::Mask::IOM_VERTCOLOR) | (mask & vcg::tri::io::Mask::IOM_FACECOLOR))
00425                         idtf.write(3,"MODEL_DIFFUSE_COLOR_COUNT " + TextUtility::nmbToStr(m.face.size() * 3));
00426                 else 
00427                         idtf.write(3,"MODEL_DIFFUSE_COLOR_COUNT 0");
00428                 idtf.write(3,"MODEL_SPECULAR_COLOR_COUNT 0");
00429                 if (mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD) idtf.write(3,"MODEL_TEXTURE_COORD_COUNT " + TextUtility::nmbToStr(m.face.size() * 3));
00430                 else idtf.write(3,"MODEL_TEXTURE_COORD_COUNT 0");
00431                 idtf.write(3,"MODEL_BONE_COUNT 0");
00432                 size_t mod_sha;
00433                 if (m.textures.size() == 0)
00434                         mod_sha = 1;
00435                 else
00436                         mod_sha = m.textures.size();
00437                 idtf.write(3,"MODEL_SHADING_COUNT " + TextUtility::nmbToStr(mod_sha));
00438                 idtf.write(3,"MODEL_SHADING_DESCRIPTION_LIST {");
00439                 unsigned int hh = 0;
00440                 do
00441                 {
00442                         idtf.write(4,"SHADING_DESCRIPTION " + TextUtility::nmbToStr(hh) + " {");
00443                         if (mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD)
00444                         {
00445                                 idtf.write(5,"TEXTURE_LAYER_COUNT 1");
00446                                 idtf.write(5,"TEXTURE_COORD_DIMENSION_LIST {");
00447                                 idtf.write(6,"TEXTURE_LAYER 0   DIMENSION: 2");
00448                                 idtf.write(5,"}");
00449                                 idtf.write(5,"SHADER_ID 0");
00450                         }
00451                         else 
00452                         {
00453                                 idtf.write(5,"TEXTURE_LAYER_COUNT 0");
00454                                 idtf.write(5,"SHADER_ID 0");
00455                         }
00456                         idtf.write(4,"}");
00457                         ++hh;
00458                 }
00459                 while(hh < m.textures.size());
00460                 idtf.write(3,"}");
00461                 idtf.write(3,"MESH_FACE_POSITION_LIST {");
00462                 for(ConstFaceIterator fit = m.face.begin();fit != m.face.end();++fit)  
00463                 {
00464                         idtf.write(4,TextUtility::nmbToStr(fit->cV(0) - &(*m.vert.begin())) + " " +
00465                                 TextUtility::nmbToStr(fit->cV(1) - &(*m.vert.begin())) + " " +
00466                                 TextUtility::nmbToStr(fit->cV(2) - &(*m.vert.begin())));
00467                 }
00468                 idtf.write(3,"}");
00469 
00470                 idtf.write(3,"MESH_FACE_NORMAL_LIST {");
00471                 unsigned int nn = 0;
00472                 for(ConstFaceIterator fit = m.face.begin();fit != m.face.end();++fit)  
00473                 {
00474                         idtf.write(4,TextUtility::nmbToStr(nn) + " " +
00475                                 TextUtility::nmbToStr(nn + 1) + " " + 
00476                                 TextUtility::nmbToStr(nn + 2));
00477                         nn += 3;
00478                 }
00479                 idtf.write(3,"}");
00480 
00481                 idtf.write(3,"MESH_FACE_SHADING_LIST {");
00482                 for(FaceIterator fit = m.face.begin();fit != m.face.end();++fit)  
00483                 {
00484                         unsigned int texind = 0;
00485                         if (mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD) 
00486                                 texind = fit->WT(0).N();
00487                         idtf.write(4,TextUtility::nmbToStr(texind));
00488                 }
00489                 idtf.write(3,"}");
00490 
00491                 if (mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD) 
00492                 {
00493                         idtf.write(3,"MESH_FACE_TEXTURE_COORD_LIST {"); 
00494                         for(unsigned int ii = 0; ii < m.face.size();++ii)
00495                         {
00496                                 idtf.write(4,"FACE " + TextUtility::nmbToStr(ii) + " {");
00497                                 idtf.write(5,"TEXTURE_LAYER 0 TEX_COORD: " + TextUtility::nmbToStr(ii * 3) + " " + TextUtility::nmbToStr(ii * 3 + 1) + " " + TextUtility::nmbToStr(ii * 3 + 2));
00498                                 idtf.write(4,"}");
00499                         }
00500                         idtf.write(3,"}");
00501                 }
00502 
00503                 if ((mask & vcg::tri::io::Mask::IOM_VERTCOLOR) | (mask & vcg::tri::io::Mask::IOM_FACECOLOR))
00504                 {
00505                         idtf.write(3,"MESH_FACE_DIFFUSE_COLOR_LIST {");
00506                         nn = 0;
00507                         for(FaceIterator fit = m.face.begin();fit != m.face.end();++fit)  
00508                         {
00509                                 idtf.write(4,TextUtility::nmbToStr(nn) + " " +
00510                                         TextUtility::nmbToStr(nn + 1) + " " + 
00511                                         TextUtility::nmbToStr(nn + 2));
00512                                 nn += 3;
00513                         }
00514                         idtf.write(3,"}");
00515                 }
00516 
00517                 idtf.write(3,"MODEL_POSITION_LIST {");
00518                 //vcg::tri::UpdateBounding<SaveMeshType>::Box(m);
00519                 //ScalarType diag = m.bbox.Diag();
00520                 //CoordType center = m.bbox.Center();
00521                 for(ConstVertexIterator vit = m.vert.begin();vit != m.vert.end();++vit)  
00522                 {
00523                         CoordType tmp = vit->P();// - center);// /diag;
00524                         idtf.write(4,TextUtility::nmbToStr(-tmp.X()) + " " +
00525                                 TextUtility::nmbToStr(tmp.Z()) + " " + 
00526                                 TextUtility::nmbToStr(tmp.Y()));
00527                 }
00528                 idtf.write(3,"}");
00529 
00530                 idtf.write(3,"MODEL_NORMAL_LIST {");
00531                 for(FaceIterator fitn = m.face.begin();fitn != m.face.end();++fitn)  
00532                 {
00533                         for(unsigned int ii = 0;ii < 3;++ii)
00534                         {
00535                                 fitn->N().Normalize();
00536                                 idtf.write(4,TextUtility::nmbToStr(-fitn->N().X()) + " " +
00537                                         TextUtility::nmbToStr(fitn->N().Z()) + " " + 
00538                                         TextUtility::nmbToStr(fitn->N().Y()));
00539                         }
00540                 }
00541                 idtf.write(3,"}");
00542 
00543                 if ((mask & vcg::tri::io::Mask::IOM_VERTCOLOR) | (mask & vcg::tri::io::Mask::IOM_FACECOLOR))
00544                 {
00545                         idtf.write(3,"MODEL_DIFFUSE_COLOR_LIST {");
00546                         //ScalarType diag = m.bbox.Diag();
00547                         //CoordType center = m.bbox.Center();
00548                         for(FaceIterator vit = m.face.begin();vit != m.face.end();++vit)  
00549                         {
00550                                 
00551                                 for (unsigned int ii =0; ii <3;++ii)
00552                                 {
00553                                         vcg::Color4b cc;
00554                                         if (mask & vcg::tri::io::Mask::IOM_VERTCOLOR)
00555                                                 cc = vit->V(ii)->C();
00556                                         else
00557                                                 cc = vit->C();
00558                                         idtf.write(4,TextUtility::nmbToStr(float(cc.X()) / 255.0f) + " " +
00559                                                 TextUtility::nmbToStr(float(cc.Y()) / 255.0f) + " " + 
00560                                                 TextUtility::nmbToStr(float(cc.Z()) / 255.0f) + " " + TextUtility::nmbToStr(float(cc.W()) / 255.0f));
00561                                 }
00562                         }
00563                         idtf.write(3,"}");
00564                 }
00565 
00566                 if (mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD)
00567                 {
00568                         idtf.write(3,"MODEL_TEXTURE_COORD_LIST {");
00569                         for(FaceIterator fitn = m.face.begin();fitn != m.face.end();++fitn)  
00570                         {
00571                                 for(unsigned int ii = 0;ii < 3;++ii)
00572                                 {
00573                                         idtf.write(4,TextUtility::nmbToStr(fitn->WT(ii).U()) + " " +
00574                                                 TextUtility::nmbToStr(-fitn->WT(ii).V()) + " " + TextUtility::nmbToStr(0.0f) + " " + TextUtility::nmbToStr(0.0f));
00575                                 }
00576                         }
00577                         idtf.write(3,"}");
00578                 }
00579 
00580                 idtf.write(2,"}");
00581                 idtf.write(1,"}");
00582                 idtf.write(0,"}");
00583 
00584                 //if (!(mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD) & (mask & vcg::tri::io::Mask::IOM_VERTCOLOR) | (mask & vcg::tri::io::Mask::IOM_FACECOLOR))
00585                 //{
00586                 //      idtf.write(0,"RESOURCE_LIST \"SHADER\" {");
00587                 //      idtf.write(1,"RESOURCE_COUNT 1");
00588                 //      idtf.write(1,"RESOURCE 0 {");
00589                 //      idtf.write(2,"RESOURCE_NAME \"VcgMesh010\"");
00590                 //      
00591 
00592                 //      //WARNING! IF VERTEX COLOR AND FACE COLOR ARE BOTH CHECKED THE FILTER SAVE ONLY VERTEX COLOR! THIS IS A DESIGN CHOICE A NOT A BUG!
00593 
00594                 //      std::string vertcol;
00595                 //      if (mask & vcg::tri::io::Mask::IOM_VERTCOLOR)
00596                 //              vertcol = "TRUE";
00597                 //      else
00598                 //              vertcol = "FALSE";
00599                 //      
00600                 //      idtf.write(2,"ATTRIBUTE_USE_VERTEX_COLOR \"" + vertcol + "\"");
00601                 //      idtf.write(2,"SHADER_MATERIAL_NAME \"Mat01\"");
00602                 //      idtf.write(2,"SHADER_ACTIVE_TEXTURE_COUNT 0");
00603                 //      idtf.write(1,"}");
00604                 //      idtf.write(0,"}");
00605                 //}
00606 
00607                 if ((mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD) | (mask & vcg::tri::io::Mask::IOM_VERTCOLOR) | (mask & vcg::tri::io::Mask::IOM_FACECOLOR))
00608                 {
00609                         idtf.write(0,"");
00610                         idtf.write(0,"MODIFIER \"SHADING\" {");
00611                         idtf.write(1,"MODIFIER_NAME \"VcgMesh01\"");
00612                         idtf.write(1,"PARAMETERS {");
00613 
00614                         idtf.write(2,"SHADER_LIST_COUNT " + TextUtility::nmbToStr(m.textures.size()));
00615                         idtf.write(2,"SHADING_GROUP {");
00616                         for(unsigned int ii = 0; ii < m.textures.size();++ii)
00617                         {
00618                                 idtf.write(3,"SHADER_LIST " +  TextUtility::nmbToStr(ii) + "{");
00619                                 idtf.write(4,"SHADER_COUNT 1");
00620                                 idtf.write(4,"SHADER_NAME_LIST {");
00621                                 idtf.write(5,"SHADER 0 NAME: \"ModelShader" + TextUtility::nmbToStr(ii) + "\"");
00622                                 idtf.write(4,"}");
00623                                 idtf.write(3,"}");
00624                         }
00625                         idtf.write(2,"}");
00626                         idtf.write(1,"}");
00627                         idtf.write(0,"}");
00628                 }
00629         
00630                 return E_NOERROR;
00631         }
00632 
00633         static int GetExportMaskCapability()
00634         {
00635                 int capability = 0;
00636 
00637                 //vert
00638                 capability |= vcg::tri::io::Mask::IOM_VERTNORMAL;
00639                 capability |= vcg::tri::io::Mask::IOM_VERTCOLOR;
00640 
00641                 //face
00642                 capability |= vcg::tri::io::Mask::IOM_FACECOLOR;
00643 
00645                 capability |= vcg::tri::io::Mask::IOM_WEDGTEXCOORD;
00646                 capability |= vcg::tri::io::Mask::IOM_WEDGNORMAL;
00647 
00648                 return capability;
00649         }
00650 };
00651 }
00652 }
00653 }
00654 
00655 #endif


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:30:52