Commit 20e99fa7 authored by Jan Möbius's avatar Jan Möbius

Add option to ststop writing bad collors and to override it.

parent c42cd9f4
......@@ -49,7 +49,7 @@
#include <OpenFlipper/Utils/Memory/RAMInfo.hh>
#include <QtWidgets>
#include <QtWidgets>
#include "FileOBJ.hh"
......@@ -80,11 +80,13 @@ void remove_duplicated_vertices(VHandles& _indices)
/// Constructor
FileOBJPlugin::FileOBJPlugin()
: loadOptions_(0),
: materialErrors_(0),
loadOptions_(0),
saveOptions_(0),
saveBinary_(0),
saveVertexColor_(0),
saveFaceColor_(0),
saveFaceColorOverride_(0),
saveAlpha_(0),
saveNormals_(0),
saveTexCoords_(0),
......@@ -2267,6 +2269,10 @@ QWidget* FileOBJPlugin::saveOptionsWidget(QString /*_currentFilter*/) {
saveFaceColor_ = new QCheckBox("Save Face Colors");
layout->addWidget(saveFaceColor_);
saveFaceColorOverride_ = new QCheckBox("Save Face Colors Error Override (Save, even if colors contain errors!)");
saveFaceColorOverride_->setToolTip("If color values of a mesh are not initialized, OpenFlipper will detect that and stop writing materials. This option will force it to write them anyway.");
layout->addWidget(saveFaceColorOverride_);
saveAlpha_ = new QCheckBox("Save Color Alpha");
layout->addWidget(saveAlpha_);
......@@ -2303,6 +2309,7 @@ QWidget* FileOBJPlugin::saveOptionsWidget(QString /*_currentFilter*/) {
connect(saveCopyTextures_, SIGNAL(toggled(bool)), this, SLOT(slotHandleCheckBoxes(bool)));
saveFaceColor_->setChecked( OpenFlipperSettings().value("FileObj/Save/FaceColor",true).toBool() );
saveFaceColorOverride_->setChecked( OpenFlipperSettings().value("FileObj/Save/FaceColorOverrise",false).toBool() );
saveAlpha_->setChecked( OpenFlipperSettings().value("FileObj/Save/Alpha",true).toBool() );
saveNormals_->setChecked( OpenFlipperSettings().value("FileObj/Save/Normals",true).toBool() );
saveTexCoords_->setChecked( OpenFlipperSettings().value("FileObj/Save/TexCoords",true).toBool() );
......@@ -2382,6 +2389,7 @@ void FileOBJPlugin::slotLoadDefault() {
void FileOBJPlugin::slotSaveDefault() {
OpenFlipperSettings().setValue( "FileObj/Save/FaceColor", saveFaceColor_->isChecked() );
OpenFlipperSettings().setValue( "FileObj/Save/FaceColorOverride", saveFaceColorOverride_->isChecked() );
OpenFlipperSettings().setValue( "FileObj/Save/Normals", saveNormals_->isChecked() );
OpenFlipperSettings().setValue( "FileObj/Save/TexCoords", saveTexCoords_->isChecked() );
OpenFlipperSettings().setValue( "FileObj/Save/Textures", saveTextures_->isChecked() );
......
......@@ -199,6 +199,9 @@ class FileOBJPlugin : public QObject, BaseInterface, FileInterface, LoadSaveInte
/// List that contains the material properties
MaterialList materials_;
/// number of defect materials encountered during writing
unsigned int materialErrors_;
template< class MeshT >
Material& getMaterial(MeshT& _mesh, const OpenMesh::FaceHandle& _fh, int _objId);
......@@ -227,6 +230,7 @@ class FileOBJPlugin : public QObject, BaseInterface, FileInterface, LoadSaveInte
QCheckBox* saveBinary_;
QCheckBox* saveVertexColor_;
QCheckBox* saveFaceColor_;
QCheckBox* saveFaceColorOverride_;
QCheckBox* saveAlpha_;
QCheckBox* saveNormals_;
QCheckBox* saveTexCoords_;
......
......@@ -55,17 +55,20 @@
template< class MeshT >
bool FileOBJPlugin::writeMaterial(QString _filename, MeshT& _mesh, int _objId )
{
bool optionColorAlpha = false;
bool optionTextures = false;
bool optionCopyTextures = false;
bool optionCreateTexFolder = false;
bool optionFaceColors = false;
bool optionFaceColorsOverride = false;
bool optionColorAlpha = false;
bool optionTextures = false;
bool optionCopyTextures = false;
bool optionCreateTexFolder = false;
// check options
if ( !OpenFlipper::Options::savingSettings() && saveOptions_ != 0) {
optionColorAlpha = saveAlpha_->isChecked();
optionTextures = saveTextures_->isChecked();
optionCopyTextures = saveCopyTextures_->isChecked();
optionCreateTexFolder = saveCreateTexFolder_->isChecked();
optionColorAlpha = saveAlpha_->isChecked();
optionTextures = saveTextures_->isChecked();
optionCopyTextures = saveCopyTextures_->isChecked();
optionCreateTexFolder = saveCreateTexFolder_->isChecked();
}
// \TODO Fetch options from ini states if dialog box is not available
......@@ -136,24 +139,41 @@ bool FileOBJPlugin::writeMaterial(QString _filename, MeshT& _mesh, int _objId )
template< class MeshT >
Material& FileOBJPlugin::getMaterial(MeshT& _mesh, const OpenMesh::FaceHandle& _fh, int _objId)
{
// check options
bool optionColorAlpha = false;
if ( !OpenFlipper::Options::savingSettings() && saveOptions_ != 0)
optionColorAlpha = saveAlpha_->isChecked();
// \TODO Fetch options from ini states if dialog box is not available
bool optionFaceColors = false;
bool optionFaceColorsOverride = false;
bool optionColorAlpha = false;
if ( !OpenFlipper::Options::savingSettings() && saveOptions_ != 0) {
optionFaceColors = saveFaceColor_->isChecked();
optionFaceColorsOverride = saveFaceColorOverride_->isChecked();
optionColorAlpha = saveAlpha_->isChecked();
}
// \TODO Fetch options from ini states if dialog box is not available
OpenMesh::Vec4f c = _mesh.color( _fh );
OpenMesh::Vec4f c = _mesh.color( _fh );
if ( optionFaceColors && !optionFaceColorsOverride ) {
// If one of the entries is out of range, assume uninitialized color and set to default
// Ugly hack to ensure that materials will only be generated if initialized
if ( c[0] > 255.0 || c[1] > 255.0 || c[2] > 255.0 || c[0] < 0.0 || c[1] < 0.0 || c[2] < 0.0) {
if ( c[0] > 255.0 || c[1] > 255.0 || c[2] > 255.0 || c[0] < 0.0 || c[1] < 0.0 || c[2] < 0.0 || std::isnan(c[0]) || std::isnan(c[1]) || std::isnan(c[2]) ) {
c[0] = 155.0;
c[1] = 155.0;
c[2] = 155.0;
c[3] = 1.0;
++materialErrors_;
// If we have too many errors, we always return the first material
// Except, if the override option is set.
if (materialErrors_ > 10)
return (*materials_.begin()).second;
}
// First off, try to fetch texture index of current face/object...
}
// First off, try to fetch texture index of current face/object...
if(!textureIndexPropFetched_) {
emit textureIndexPropertyName(_objId, textureIndexPropertyName_);
textureIndexPropFetched_ = true;
......@@ -250,23 +270,23 @@ bool FileOBJPlugin::writeMesh(std::ostream& _out, QString _filename, MeshT& _mes
bool useMaterial = false;
OpenMesh::Vec4f c;
bool optionFaceColors = false;
bool optionVertexNormals = false;
bool optionVertexTexCoords = true;
bool optionTextures = false;
bool optionCopyTextures = false;
bool optionCreateTexFolder = false;
bool optionFaceColors = false;
bool optionVertexNormals = false;
bool optionVertexTexCoords = true;
bool optionTextures = false;
bool optionCopyTextures = false;
bool optionCreateTexFolder = false;
QFileInfo fi(_filename);
// check options
if ( !OpenFlipper::Options::savingSettings() && saveOptions_ != 0) {
optionFaceColors = saveFaceColor_->isChecked();
optionVertexNormals = saveNormals_->isChecked();
optionVertexTexCoords = saveTexCoords_->isChecked();
optionTextures = saveTextures_->isChecked();
optionCopyTextures = saveCopyTextures_->isChecked();
optionCreateTexFolder = saveCreateTexFolder_->isChecked();
optionFaceColors = saveFaceColor_->isChecked();
optionVertexNormals = saveNormals_->isChecked();
optionVertexTexCoords = saveTexCoords_->isChecked();
optionTextures = saveTextures_->isChecked();
optionCopyTextures = saveCopyTextures_->isChecked();
optionCreateTexFolder = saveCreateTexFolder_->isChecked();
_out.precision(savePrecision_->value());
};
// \TODO Fetch options from ini states if dialog box is not available
......@@ -440,6 +460,7 @@ bool FileOBJPlugin::writeMesh(std::ostream& _out, QString _filename, MeshT& _mes
}
materials_.clear();
materialErrors_ = 0;
texIndexFileMap_.clear();
textureIndexPropFetched_ = false;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment