Merge branch 'master' into lyonm/custom-property-writing

This commit is contained in:
Max Lyon
2023-02-06 16:50:37 +01:00
46 changed files with 617 additions and 675 deletions

View File

@@ -51,6 +51,7 @@
// OpenMesh
#include <OpenMesh/Core/System/config.h>
#include <string>
//== NAMESPACES ==============================================================
@@ -115,31 +116,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 +148,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.

View File

@@ -330,7 +330,7 @@ struct binary< std::vector< T >, typename std::enable_if<std::is_default_constru
typedef typename value_type::value_type elem_type;
static const bool is_streamable = binary<T>::is_streamable;
static size_t size_of(bool _store_size = true)
static size_t size_of(bool /*_store_size*/ = true)
{ return IO::UnknownSize; }
static size_t size_of(const value_type& _v, bool _store_size = true)
@@ -424,7 +424,7 @@ struct binary< std::vector< T >, typename std::enable_if<std::is_default_constru
}
};
#include <OpenMesh/Core/IO/SR_binary_vector_of_bool.inl>
#include <OpenMesh/Core/IO/SR_binary_vector_of_bool.hh>
// ----------------------------------------------------------------------------

View File

@@ -6,7 +6,7 @@ template <> struct binary< std::vector<bool> >
static const bool is_streamable = true;
static size_t size_of(bool _store_size = true) { return UnknownSize; }
static size_t size_of(bool /*_store_size*/ = true) { return UnknownSize; }
static size_t size_of(const value_type& _v, bool _store_size = true)
{
size_t size = _v.size() / 8 + ((_v.size() % 8)!=0);

View File

@@ -130,26 +130,31 @@ write(const std::string& _filename, BaseExporter& _be, Options _opt, std::stream
size_t _OBJWriter_::getMaterial(OpenMesh::Vec3f _color) const
{
for (size_t i=0; i < material_.size(); i++)
if(material_[i] == _color)
return i;
auto idx_it = material_idx_.find(_color);
if (idx_it != material_idx_.end()) {
return idx_it->second;
} else {
size_t idx = material_.size();
material_.push_back(_color);
material_idx_[_color] = idx;
//not found add new material
material_.push_back( _color );
return material_.size()-1;
return idx;
}
}
//-----------------------------------------------------------------------------
size_t _OBJWriter_::getMaterial(OpenMesh::Vec4f _color) const
{
for (size_t i=0; i < materialA_.size(); i++)
if(materialA_[i] == _color)
return i;
//not found add new material
materialA_.push_back( _color );
return materialA_.size()-1;
auto idx_it = materialA_idx_.find(_color);
if (idx_it != materialA_idx_.end()) {
return idx_it->second;
} else {
size_t idx = materialA_.size();
materialA_.push_back(_color);
materialA_idx_[_color] = idx;
return idx;
}
}
//-----------------------------------------------------------------------------
@@ -162,7 +167,9 @@ writeMaterial(std::ostream& _out, BaseExporter& _be, Options _opt) const
OpenMesh::Vec4f cA;
material_.clear();
material_idx_.clear();
materialA_.clear();
materialA_idx_.clear();
//iterate over faces
for (size_t i=0, nF=_be.n_faces(); i<nF; ++i)
@@ -195,6 +202,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 +229,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 +252,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 +274,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<Vec2f,int> texMap;
//collect Texturevertices from halfedges
@@ -387,7 +399,9 @@ write(std::ostream& _out, BaseExporter& _be, Options _opt, std::streamsize _prec
}
material_.clear();
material_idx_.clear();
materialA_.clear();
materialA_idx_.clear();
return true;
}

View File

@@ -103,7 +103,9 @@ private:
mutable std::string objName_;
mutable std::vector< OpenMesh::Vec3f > material_;
mutable std::map< OpenMesh::Vec3f, size_t> material_idx_;
mutable std::vector< OpenMesh::Vec4f > materialA_;
mutable std::map< OpenMesh::Vec4f, size_t> materialA_idx_;
size_t getMaterial(OpenMesh::Vec3f _color) const;

View File

@@ -135,7 +135,7 @@ private:
writeValue(_type, _out, _value);
}
template<typename T>
void writeProxy(ValueType _type, std::ostream& _out, T _value, OpenMesh::GenProg::FalseType /*_binary*/) const
void writeProxy(ValueType /*_type*/, std::ostream& _out, T _value, OpenMesh::GenProg::FalseType /*_binary*/) const
{
_out << " " << _value;
}