diff --git a/Doc/changelog.docu b/Doc/changelog.docu
index ec0f2ac3..5011ac96 100644
--- a/Doc/changelog.docu
+++ b/Doc/changelog.docu
@@ -8,6 +8,12 @@
| 9.1 (?/?/?) |
+IO
+
+- OBJ writer: Added param 'texture_file' to the Options class, it specifies the path to the texture file (Thanks to Philipp Auersperg-Castell for the patch)
+- OBJ writer: added param 'material_file_extension' to the Options class, it specifies the material file suffix, default is ".mat" as it was before. (Thanks to Philipp Auersperg-Castell for the patch)
+
+
Build System
- Removed globbing for Core and Tools library include and source files
diff --git a/src/OpenMesh/Core/IO/Options.hh b/src/OpenMesh/Core/IO/Options.hh
index 3b5967a2..a459e3e0 100644
--- a/src/OpenMesh/Core/IO/Options.hh
+++ b/src/OpenMesh/Core/IO/Options.hh
@@ -115,31 +115,24 @@ public:
TexCoordST = 0x8000 ///< Write texture coordinates as ST instead of UV
};
+ /// Texture filename. This will be written as
+ /// map_Kd in the OBJ writer into the material file.
+ std::string texture_file ;
+
+ /// Filename extension for material files when writing OBJs
+ /// default is currently .mat
+ std::string material_file_extension;
+
public:
/// Default constructor
- Options() : flags_( Default )
+ Options() : texture_file(""), material_file_extension(".mat"), flags_( Default )
{ }
-
- /// Copy constructor
- Options(const Options& _opt) : flags_(_opt.flags_)
- { }
-
-
- /// Initializing constructor setting a single option
- Options(Flag _flg) : flags_( _flg)
- { }
-
-
- /// Initializing constructor setting multiple options
+ /// Initializing constructor setting multiple options
Options(const value_type _flgs) : flags_( _flgs)
{ }
-
- ~Options()
- { }
-
/// Restore state after default constructor.
void cleanup(void)
{ flags_ = Default; }
@@ -154,17 +147,9 @@ public:
public:
- //@{
- /// Copy options defined in _rhs.
-
- Options& operator = ( const Options& _rhs )
- { flags_ = _rhs.flags_; return *this; }
-
Options& operator = ( const value_type _rhs )
{ flags_ = _rhs; return *this; }
- //@}
-
//@{
/// Unset options defined in _rhs.
diff --git a/src/OpenMesh/Core/IO/writer/OBJWriter.cc b/src/OpenMesh/Core/IO/writer/OBJWriter.cc
index da706f99..145df5dc 100644
--- a/src/OpenMesh/Core/IO/writer/OBJWriter.cc
+++ b/src/OpenMesh/Core/IO/writer/OBJWriter.cc
@@ -195,6 +195,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;
}
@@ -219,8 +222,10 @@ write(std::ostream& _out, BaseExporter& _be, Options _opt, std::streamsize _prec
_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) ) {
@@ -240,9 +245,9 @@ write(std::ostream& _out, BaseExporter& _be, Options _opt, std::streamsize _prec
}
//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 );
@@ -262,8 +267,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)) || _opt.texture_file != "")
+ _out << "mtllib " << objName_ << _opt.material_file_extension << '\n';
std::map texMap;
//collect Texturevertices from halfedges
|