diff --git a/src/OpenMesh/Core/IO/Options.hh b/src/OpenMesh/Core/IO/Options.hh index 347098af..96388e84 100644 --- a/src/OpenMesh/Core/IO/Options.hh +++ b/src/OpenMesh/Core/IO/Options.hh @@ -114,32 +114,38 @@ public: Status = 0x4000, ///< Has (r) / store (w) status properties TexCoordST = 0x8000 ///< Write texture coordinates as ST instead of UV }; + std::string texture_file ; + std::string material_file_extension; public: /// Default constructor - Options() : flags_( Default ) + Options() : flags_( Default ), texture_file(""), material_file_extension(".mat") { } - - /// Copy constructor - Options(const Options& _opt) : flags_(_opt.flags_) - { } - - - /// Initializing constructor setting a single option - Options(Flag _flg) : flags_( _flg) - { } + // these are not necessary, because the default implementation does the right thing + // see https://en.cppreference.com/w/cpp/language/rule_of_three + +// /// Copy constructor +// Options(const Options& _opt) : flags_(_opt.flags_) +// { } +// +// +// /// Initializing constructor setting a single option +// Options(Flag _flg) : flags_( _flg) +// { } +// +// +// +// +// ~Options() +// { } /// Initializing constructor setting multiple options Options(const value_type _flgs) : flags_( _flgs) { } - - ~Options() - { } - /// Restore state after default constructor. void cleanup(void) { flags_ = Default; } @@ -157,8 +163,8 @@ public: //@{ /// Copy options defined in _rhs. - Options& operator = ( const Options& _rhs ) - { flags_ = _rhs.flags_; return *this; } +// Options& operator = ( const Options& _rhs ) +// { flags_ = _rhs.flags_; return *this; } Options& operator = ( const value_type _rhs ) { flags_ = _rhs; return *this; } diff --git a/src/OpenMesh/Core/IO/writer/OBJWriter.cc b/src/OpenMesh/Core/IO/writer/OBJWriter.cc index b83dde24..21cffcb4 100644 --- a/src/OpenMesh/Core/IO/writer/OBJWriter.cc +++ b/src/OpenMesh/Core/IO/writer/OBJWriter.cc @@ -54,6 +54,7 @@ #include #include #include +#include //=== NAMESPACES ============================================================== @@ -195,6 +196,9 @@ writeMaterial(std::ostream& _out, BaseExporter& _be, Options _opt) const _out << "illum 1" << '\n'; } + if (_opt.texture_file != "") { + _out << "map_Kd " << _opt.texture_file << std::endl; + } return true; } @@ -210,39 +214,43 @@ write(std::ostream& _out, BaseExporter& _be, Options _opt, std::streamsize _prec Vec2f t; VertexHandle vh; std::vector vhandles; - bool useMatrial = false; + bool useMatrial = true; OpenMesh::Vec3f c; OpenMesh::Vec4f cA; - omlog() << "[OBJWriter] : write file\n"; + omlog() << "[OBJWriter] : write file!!\n"; _out.precision(_precision); // check exporter features - if (!check( _be, _opt)) - return false; + if (!check( _be, _opt)) { + return false; + } + // No binary mode for OBJ if ( _opt.check(Options::Binary) ) { omout() << "[OBJWriter] : Warning, Binary mode requested for OBJ Writer (No support for Binary mode), falling back to standard." << std::endl; } - // check for unsupported writer features + + // check for unsupported writer features if (_opt.check(Options::FaceNormal) ) { omerr() << "[OBJWriter] : FaceNormal not supported by OBJ Writer" << std::endl; return false; } - // check for unsupported writer features + + // check for unsupported writer features if (_opt.check(Options::VertexColor) ) { omerr() << "[OBJWriter] : VertexColor not supported by OBJ Writer" << std::endl; return false; } //create material file if needed - if ( _opt.check(Options::FaceColor) ){ + if ( _opt.check(Options::FaceColor) || _opt.texture_file != ""){ - std::string matFile = path_ + objName_ + ".mat"; + std::string matFile = path_ + objName_ + _opt.material_file_extension; std::fstream matStream(matFile.c_str(), std::ios_base::out ); @@ -251,6 +259,8 @@ write(std::ostream& _out, BaseExporter& _be, Options _opt, std::streamsize _prec omerr() << "[OBJWriter] : cannot write material file " << matFile << std::endl; }else{ + omlog() << "writing material\n"; + useMatrial = writeMaterial(matStream, _be, _opt); matStream.close(); @@ -262,8 +272,8 @@ write(std::ostream& _out, BaseExporter& _be, Options _opt, std::streamsize _prec _out << _be.n_faces() << " faces" << '\n'; // material file - if (useMatrial && _opt.check(Options::FaceColor) ) - _out << "mtllib " << objName_ << ".mat" << '\n'; + if (useMatrial && _opt.check(Options::FaceColor) or _opt.texture_file != "") + _out << "mtllib " << objName_ << _opt.material_file_extension << '\n'; std::map texMap; //collect Texturevertices from halfedges