...
 
Commits (2)
......@@ -44,7 +44,6 @@
#include "AssimpPlugin.hh"
#include <ACG/QtWidgets/QtFlapBox.hh>
// Defines for the type handling drop down box
#define TYPEAUTODETECT 0
......@@ -56,7 +55,8 @@ AssimpPlugin::AssimpPlugin()
:
loadOptions_(nullptr),
saveOptions_(nullptr),
type_(DATA_TRIANGLE_MESH)
type_(DATA_TRIANGLE_MESH),
cancel_(false)
{
}
......@@ -91,6 +91,8 @@ void AssimpPlugin::initializePlugin() {
" <br> ";
emit addAboutInfo(info,"File-Assimp Plugin");
connect(this, SIGNAL(showConfirmationDialog(const QString&, const QString&)), this, SLOT(slotShowConfirmationDialog(const QString&, const QString&)), Qt::BlockingQueuedConnection);
}
int AssimpPlugin::convertAiSceneToOpenMesh(const aiScene *_scene, QString _objectName) {
......@@ -100,7 +102,16 @@ int AssimpPlugin::convertAiSceneToOpenMesh(const aiScene *_scene, QString _objec
if (_scene->mNumMeshes == 0)
emit log(LOGWARN, tr("aiScene contains no meshes"));
for (unsigned int i = 0; i < _scene->mNumMeshes; ++i) {
if(_scene->mNumMaterials > 1)
{
if(!emit showConfirmationDialog(tr("Multiple MAterials in file"),
tr("The File you are trying to load contains %1 materials. "
"Assimp creates a separate Mesh for each material, which may cause performance issues.\n\n "
"Do you want to continue loading the file?").arg(_scene->mNumMaterials)))
return returnId;
}
for (unsigned int i = 0; i < _scene->mNumMeshes && !cancel_; ++i) {
int objectId = -1;
if(type_ == DATA_UNKNOWN)
{
......@@ -479,11 +490,14 @@ QWidget *AssimpPlugin::loadOptionsWidget(QString) {
triMeshHandling_->addItem( tr("Open as PolyMesh") );
triMeshHandling_->addItem( tr("Open as TriangleMesh") );
loadFaceColor_ = new QCheckBox("Load Face Colors");
loadNormals_ = new QCheckBox("Load Normals");
loadTexCoords_ = new QCheckBox("Load Texture Coordinates");
loadFaceColor_ = new QCheckBox("Load Vertex Colors");
loadNormals_ = new QCheckBox("Load Vertex Normals");
loadTexCoords_ = new QCheckBox("Load Vertex Texture Coordinates");
loadTextures_ = new QCheckBox("Load Textures");
//loading textures is not yet supported
loadTextures_->setDisabled(true);
QList<QWidget*> generalOptions = {triMeshHandling_, loadFaceColor_, loadNormals_, loadTexCoords_, loadTextures_};
QTreeWidget* tree = new QTreeWidget();
......@@ -612,6 +626,7 @@ QWidget *AssimpPlugin::loadOptionsWidget(QString) {
int AssimpPlugin::loadObject(QString _filename) {
Assimp::Importer importer;
cancel_ = false;
const aiScene* scene = NULL;
scene = importer.ReadFile(_filename.toStdString(), processSteps(loadOptions));
......@@ -766,11 +781,32 @@ unsigned int AssimpPlugin::processSteps( const std::unordered_map<QCheckBox*, un
unsigned int result = 0;
for(auto entry : _options)
{
if(entry.first != nullptr)
result |= entry.first->isChecked()? entry.second : 0;
}
return result;
}
bool AssimpPlugin::slotShowConfirmationDialog(const QString& _title, const QString& _message)
{
QMessageBox msgBox;
QPushButton *cancelButton = msgBox.addButton(tr("Cancel"), QMessageBox::ActionRole);
/*QPushButton *confirmButton =*/ msgBox.addButton(tr("Continue"), QMessageBox::ActionRole);
msgBox.setWindowTitle( _title );
msgBox.setText( _message );
msgBox.setDefaultButton( cancelButton );
msgBox.exec();
if (msgBox.clickedButton() == cancelButton)
return false;
return true;
}
void AssimpPlugin::canceledJob(QString _jobId)
{
if(_jobId == "Loading File" || _jobId == "Loading Files")
cancel_ = true;
}
#if QT_VERSION < 0x050000
Q_EXPORT_PLUGIN2( assimpplugin , AssimpPlugin )
#endif
......@@ -57,6 +57,7 @@
#include <OpenFlipper/BasePlugin/TypeInterface.hh>
#include <OpenFlipper/BasePlugin/RPCInterface.hh>
#include <OpenFlipper/BasePlugin/AboutInfoInterface.hh>
#include <OpenFlipper/BasePlugin/ProcessInterface.hh>
#include <ObjectTypes/PolyMesh/PolyMesh.hh>
#include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
......@@ -69,7 +70,7 @@
#include<unordered_map>
class AssimpPlugin : public QObject, BaseInterface, FileInterface, LoadSaveInterface,
LoggingInterface, ScriptInterface, RPCInterface, AboutInfoInterface
LoggingInterface, ScriptInterface, RPCInterface, AboutInfoInterface, ProcessInterface
{
Q_OBJECT
Q_INTERFACES(FileInterface)
......@@ -79,6 +80,7 @@ class AssimpPlugin : public QObject, BaseInterface, FileInterface, LoadSaveInter
Q_INTERFACES(ScriptInterface)
Q_INTERFACES(RPCInterface)
Q_INTERFACES(AboutInfoInterface)
Q_INTERFACES(ProcessInterface)
#if QT_VERSION >= 0x050000
Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-Assimp")
......@@ -138,6 +140,17 @@ private slots:
void slotLoadDefault();
void slotSaveDefault();
/// displays a message dialog with the given message,
/// and returns whether confirm or cancel was clicked
/// returns true if confirm was clicked
bool slotShowConfirmationDialog(const QString& _title, const QString & _message);
/// slot gets called when a user clicks on the cancel button.
void canceledJob(QString _jobId);
signals:
bool showConfirmationDialog(const QString& _title, const QString & _message);
private:
/// converts an aiScene to a polymesh or trimesh
......@@ -252,6 +265,8 @@ private:
/// maps indices of vertices in an aiMesh to OpenMesh VertexHandles
std::map<unsigned int, OpenMesh::VertexHandle> vertexHandles_;
bool cancel_;
};
#endif // ASSIMPPLUGIN_HH