AssimpPlugin.cc 50 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
/*===========================================================================*\
*                                                                            *
*                              OpenFlipper                                   *
*      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen       *
*                           www.openflipper.org                              *
*                                                                            *
*--------------------------------------------------------------------------- *
*  This file is part of OpenFlipper.                                         *
*                                                                            *
*  OpenFlipper is free software: you can redistribute it and/or modify       *
*  it under the terms of the GNU Lesser General Public License as            *
*  published by the Free Software Foundation, either version 3 of            *
*  the License, or (at your option) any later version with the               *
*  following exceptions:                                                     *
*                                                                            *
*  If other files instantiate templates or use macros                        *
*  or inline functions from this file, or you compile this file and          *
*  link it with other files to produce an executable, this file does         *
*  not by itself cause the resulting executable to be covered by the         *
*  GNU Lesser General Public License. This exception does not however        *
*  invalidate any other reasons why the executable file might be             *
*  covered by the GNU Lesser General Public License.                         *
*                                                                            *
*  OpenFlipper is distributed in the hope that it will be useful,            *
*  but WITHOUT ANY WARRANTY; without even the implied warranty of            *
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
*  GNU Lesser General Public License for more details.                       *
*                                                                            *
*  You should have received a copy of the GNU LesserGeneral Public           *
*  License along with OpenFlipper. If not,                                   *
*  see <http://www.gnu.org/licenses/>.                                       *
*                                                                            *
\*===========================================================================*/

/*===========================================================================*\
*                                                                            *
*   $Revision: 13361 $                                                       *
*   $LastChangedBy: moebius $                                                *
39
*   $Date: 2012-01-12 16:33:16 +0100 (Thu, 12 Jan 2012) $                    *
40 41 42 43 44 45 46
*                                                                            *
\*===========================================================================*/




#include "AssimpPlugin.hh"
47 48 49 50 51 52

// Defines for the type handling drop down box
#define TYPEAUTODETECT 0
#define TYPEASK        1
#define TYPEPOLY       2
#define TYPETRIANGLE   3
53 54 55

AssimpPlugin::AssimpPlugin()
  :
56 57
  loadOptions_(nullptr),
  saveOptions_(nullptr),
58 59
  type_(DATA_TRIANGLE_MESH),
  cancel_(false)
60 61 62 63
{
}

void AssimpPlugin::initializePlugin() {
64 65

  QString info =
66 67
    " Copyright (c) 2006-2012 assimp team<br>                                                "
    " All rights reserved.<br>                                                               "
68 69
    " Redistribution and use in source and binary forms, with or without modification, are   "
    " permitted provided that the following conditions are met: <br>                         "
70
    " <br>                                                                                   "
71 72 73 74 75 76 77 78 79 80
    " Redistributions of source code must retain the above copyright notice, this list of    "
    " conditions and the following disclaimer.<br>                                           "
    " <br>                                                                                   "
    " Redistributions in binary form must reproduce the above copyright notice, this list    "
    " of conditions and the following disclaimer in the documentation and/or other           "
    " materials provided with the distribution.<br>                                          "
    " <br>                                                                                   "
    " Neither the name of the assimp team nor the names of its contributors may be used to   "
    " endorse or promote products derived from this software without specific prior written  "
    " permission.<br>                                                                        "
81
    " <br>                                                                                   "
82 83 84 85 86 87 88 89
    " THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY  "
    " EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF"
    " MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL "
    " THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,    "
    " SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,           "
    " PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS"
    " INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,      "
    " STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF"
90
    " THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.           "
91 92 93
    " <br>                                                                                   ";

    emit addAboutInfo(info,"File-Assimp Plugin");
94 95
  
  connect(this, SIGNAL(showConfirmationDialog(const QString&, const QString&)), this, SLOT(slotShowConfirmationDialog(const QString&, const QString&)), Qt::BlockingQueuedConnection);
96 97
}

Isaak Lim's avatar
Isaak Lim committed
98
int AssimpPlugin::convertAiSceneToOpenMesh(const aiScene *_scene, QString _objectName) {
99 100
  int returnId = -1;
  std::vector<int> ids;
101

102 103
  if (_scene->mNumMeshes == 0)
    emit log(LOGWARN, tr("aiScene contains no meshes"));
104 105 106 107 108 109 110 111 112
  
  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;
  }
113

114
  for (unsigned int i = 0; i < _scene->mNumMeshes && !cancel_; ++i) {
115
    int objectId = -1;
116 117 118 119 120 121 122 123 124
    if(type_ == DATA_UNKNOWN)
    {
      if(_scene->mMeshes[i]->mPrimitiveTypes & aiPrimitiveType_POLYGON)
        emit addEmptyObject(DATA_POLY_MESH, objectId);
      else
        emit addEmptyObject(DATA_TRIANGLE_MESH, objectId);
    }
    else
      emit addEmptyObject(type_, objectId);
125 126 127

    BaseObject* object(0);
    if(!PluginFunctions::getObject( objectId, object )) {
128 129
      emit log(LOGERR, tr("Could not create new object!"));
      return -1;
130 131
    }

132 133 134
    if (i == 0)
      returnId = objectId;

Isaak Lim's avatar
Isaak Lim committed
135 136
    object->setName(_objectName);

137 138 139 140
    PolyMeshObject* polyMeshObj = dynamic_cast< PolyMeshObject* > (object);
    TriMeshObject*  triMeshObj  = dynamic_cast< TriMeshObject*  > (object);

    if (polyMeshObj) {
Martin Schultz's avatar
Martin Schultz committed
141
      convertAiMeshToPolyMesh(polyMeshObj->mesh(), _scene->mMeshes[i]);
142

143
      emit updatedObject(polyMeshObj->id(), UPDATE_ALL);
144

145
      ids.push_back(object->id());
146
    } else if (triMeshObj) {
147
      convertAiMeshToTriMesh(triMeshObj->mesh(), _scene->mMeshes[i]);
148

149
      emit updatedObject(triMeshObj->id(), UPDATE_ALL);
150 151

      ids.push_back(object->id());
152 153 154
    }

    emit openedFile( object->id() );
155 156 157 158 159 160 161 162 163 164
  }

  if (_scene->mNumMeshes > 1) {
    bool dataControlExists = false;
    pluginExists( "datacontrol", dataControlExists );

    if ( dataControlExists ){
      returnId = RPC::callFunctionValue<int>("datacontrol","groupObjects", ids, _objectName);
    }
  }
165

166
  return returnId;
167 168
}

Isaak Lim's avatar
Isaak Lim committed
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
bool AssimpPlugin::convertOpenMeshToAiScene(aiScene *_scene, BaseObjectData *_object) {
  _scene->mMeshes = new aiMesh*[1];
  _scene->mMeshes[0] = new aiMesh();
  _scene->mNumMeshes = 1;
  _scene->mRootNode = new aiNode();
  _scene->mRootNode->mNumChildren = 0;
  _scene->mRootNode->mNumMeshes = 1;
  _scene->mRootNode->mMeshes = new unsigned int[1];
  _scene->mRootNode->mMeshes[0] = 0;

  // assimp requires at least one material
  _scene->mMaterials = new aiMaterial*[1];
  _scene->mMaterials[0] = new aiMaterial();
  _scene->mNumMaterials = 1;

  if ( _object->dataType( DATA_POLY_MESH ) ) {
    return convertPolyMeshToAiMesh(dynamic_cast<PolyMeshObject*>(_object)->mesh(), _scene->mMeshes[0]);
  }
  else if ( _object->dataType( DATA_TRIANGLE_MESH ) ) {
    return convertTriMeshToAiMesh(dynamic_cast<TriMeshObject*>(_object)->mesh(), _scene->mMeshes[0]);
  }
  else {
    emit log(LOGERR, tr("Unable to save (object is not a compatible mesh type)"));
    return false;
  }
}

void AssimpPlugin::convertAiMeshToPolyMesh(PolyMesh *_polyMesh, aiMesh *_mesh) {
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
  mapVertices(_polyMesh, _mesh);

  std::vector<OpenMesh::VertexHandle> vhandles;
  for (unsigned int i = 0; i < _mesh->mNumFaces; ++i) {
    aiFace& face = _mesh->mFaces[i];
    for (unsigned int j = 0; j < face.mNumIndices; ++j) {
      vhandles.push_back(vertexHandles_[face.mIndices[j]]);
      if (_mesh->HasNormals()) {
        aiVector3D& aiNormal = _mesh->mNormals[face.mIndices[j]];
        _polyMesh->set_normal(vhandles.back(), ACG::Vec3d(aiNormal.x, aiNormal.y, aiNormal.z));
      }
    }

    _polyMesh->add_face(vhandles);
    vhandles.clear();
  }

214
  if (!_mesh->HasNormals())
215 216 217 218 219
    _polyMesh->update_normals();
  else
    _polyMesh->update_face_normals();
}

Isaak Lim's avatar
Isaak Lim committed
220
void AssimpPlugin::convertAiMeshToTriMesh(TriMesh *_triMesh, aiMesh *_mesh) {
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
  mapVertices(_triMesh, _mesh);

  std::vector<OpenMesh::VertexHandle> vhandles;
  for (unsigned int i = 0; i < _mesh->mNumFaces; ++i) {
    aiFace& face = _mesh->mFaces[i];
    for (unsigned int j = 0; j < face.mNumIndices; ++j) {
      vhandles.push_back(vertexHandles_[face.mIndices[j]]);
      if (_mesh->HasNormals()) {
        aiVector3D& aiNormal = _mesh->mNormals[face.mIndices[j]];
        _triMesh->set_normal(vhandles.back(), ACG::Vec3d(aiNormal.x, aiNormal.y, aiNormal.z));
      }
    }

    _triMesh->add_face(vhandles);
    vhandles.clear();
  }

238
  if (!_mesh->HasNormals())
239 240 241 242 243
    _triMesh->update_normals();
  else
    _triMesh->update_face_normals();
}

Isaak Lim's avatar
Isaak Lim committed
244 245 246 247 248 249 250 251 252 253 254 255
bool AssimpPlugin::convertPolyMeshToAiMesh(PolyMesh *_polyMesh, aiMesh *_mesh) {
  _mesh->mPrimitiveTypes = aiPrimitiveType_POLYGON;
  _mesh->mNumVertices = _polyMesh->n_vertices();
  _mesh->mNumFaces = _polyMesh->n_faces();

  _mesh->mVertices = new aiVector3D[_mesh->mNumVertices];
  _mesh->mNormals = new aiVector3D[_mesh->mNumVertices];
  _mesh->mFaces = new aiFace[_mesh->mNumFaces];

  std::map<OpenMesh::VertexHandle, int> vertexHandles;
  int i = 0;
  for (PolyMesh::ConstVertexIter v_it = _polyMesh->vertices_begin(); v_it != _polyMesh->vertices_end(); ++v_it, ++i) {
256 257
      ACG::Vec3d pos = _polyMesh->point(*v_it);
      ACG::Vec3d normal = _polyMesh->normal(*v_it);
Isaak Lim's avatar
Isaak Lim committed
258 259 260 261 262 263 264 265
      _mesh->mVertices[i] = aiVector3D(pos[0], pos[1], pos[2]);
      _mesh->mNormals[i] = aiVector3D(normal[0], normal[1], normal[2]);
      vertexHandles[*v_it] = i;
  }

  i = 0;
  for (PolyMesh::ConstFaceIter f_it = _polyMesh->faces_begin(); f_it != _polyMesh->faces_end(); ++f_it, ++i) {
    int nVertices = 0;
266
    for (PolyMesh::ConstFaceVertexIter fv_it = _polyMesh->fv_iter(*f_it); fv_it.is_valid(); ++fv_it) {
Isaak Lim's avatar
Isaak Lim committed
267 268 269 270 271 272
      ++nVertices;
    }

    _mesh->mFaces[i].mNumIndices = nVertices;
    _mesh->mFaces[i].mIndices = new unsigned int[nVertices];
    int j = 0;
273 274
    for (PolyMesh::ConstFaceVertexIter fv_it = _polyMesh->fv_iter(*f_it); fv_it.is_valid(); ++fv_it, ++j) {
      _mesh->mFaces[i].mIndices[j] = vertexHandles[*fv_it];
Isaak Lim's avatar
Isaak Lim committed
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
    }
  }

  return true;
}

bool AssimpPlugin::convertTriMeshToAiMesh(TriMesh *_triMesh, aiMesh *_mesh) {
  _mesh->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
  _mesh->mNumVertices = _triMesh->n_vertices();
  _mesh->mNumFaces = _triMesh->n_faces();

  _mesh->mVertices = new aiVector3D[_mesh->mNumVertices];
  _mesh->mNormals = new aiVector3D[_mesh->mNumVertices];
  _mesh->mFaces = new aiFace[_mesh->mNumFaces];

  std::map<OpenMesh::VertexHandle, int> vertexHandles;
  int i = 0;
  for (TriMesh::ConstVertexIter v_it = _triMesh->vertices_begin(); v_it != _triMesh->vertices_end(); ++v_it, ++i) {
293 294
      ACG::Vec3d pos = _triMesh->point(*v_it);
      ACG::Vec3d normal = _triMesh->normal(*v_it);
Isaak Lim's avatar
Isaak Lim committed
295 296 297 298 299 300 301 302 303 304
      _mesh->mVertices[i] = aiVector3D(pos[0], pos[1], pos[2]);
      _mesh->mNormals[i] = aiVector3D(normal[0], normal[1], normal[2]);
      vertexHandles[*v_it] = i;
  }

  i = 0;
  for (TriMesh::ConstFaceIter f_it = _triMesh->faces_begin(); f_it != _triMesh->faces_end(); ++f_it, ++i) {
    _mesh->mFaces[i].mNumIndices = 3;
    _mesh->mFaces[i].mIndices = new unsigned int[3];
    int j = 0;
305 306
    for (PolyMesh::ConstFaceVertexIter fv_it = _triMesh->fv_iter(*f_it); fv_it.is_valid(); ++fv_it, ++j) {
      _mesh->mFaces[i].mIndices[j] = vertexHandles[*fv_it];
Isaak Lim's avatar
Isaak Lim committed
307 308 309 310 311 312
    }
  }

  return true;
}

313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
void AssimpPlugin::mapVertices(PolyMesh *_polyMesh, aiMesh *_mesh) {
  vertexHandles_.clear();

  for (unsigned int i = 0; i < _mesh->mNumVertices; ++i) {
    vertexHandles_[i] = _polyMesh->add_vertex(ACG::Vec3d(_mesh->mVertices[i].x, _mesh->mVertices[i].y, _mesh->mVertices[i].z));
  }
}

void AssimpPlugin::mapVertices(TriMesh *_triMesh, aiMesh *_mesh) {
  vertexHandles_.clear();

  for (unsigned int i = 0; i < _mesh->mNumVertices; ++i) {
    vertexHandles_[i] = _triMesh->add_vertex(ACG::Vec3d(_mesh->mVertices[i].x, _mesh->mVertices[i].y, _mesh->mVertices[i].z));
  }
}

DataType AssimpPlugin::supportedType() {
330
  DataType type = DATA_POLY_MESH | DATA_TRIANGLE_MESH | DATA_GROUP;
331 332 333 334 335
  return type;
}


QString AssimpPlugin::getSaveFilters() {
Isaak Lim's avatar
Isaak Lim committed
336
  return QString( tr("Alias/Wavefront ( *.obj );;Collada ( *.dae );;Stereolithography files ( *.stl );;Polygon File Format files ( *.ply )" ) );
337 338 339
}

QString AssimpPlugin::getLoadFilters() {
340
  return QString( tr("Alias/Wavefront ( *.obj );;AutoCAD DXF ( *.dxf );;Collada ( *.dae );;Stereolithography files ( *.stl );;Polygon File Format files ( *.ply );;Blender 3D( *.blend );;3ds Max 3DS ( *.3ds );;3ds Max ASE( *.ase );;Industry Foundation Classes ( *.ifc );;XGL ( *.xgl *.zgl );;Lightwave ( *.lwo );;Lightwave Scene ( *.lws );;Modo ( *.lxo );;DirectX X ( *.x );;AC3D ( *.ac );;Milkshape 3D ( *.ms3d );;TrueSpace ( *.cob *.scn )") );
341 342 343
}

QWidget *AssimpPlugin::saveOptionsWidget(QString) {
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473
  if (saveOptions_ == nullptr){
      //generate widget
      saveOptions_ = new QWidget();
      QVBoxLayout* layout = new QVBoxLayout();
      layout->setAlignment(Qt::AlignTop);

      saveFaceColor_ = new QCheckBox("Save Face Colors");      
      saveNormals_   = new QCheckBox("Save Normals");      
      saveTexCoords_ = new QCheckBox("Save Texture Coordinates");      
      saveTextures_  = new QCheckBox("Save Textures");      
      
      QList<QWidget*> generalOptions = { saveFaceColor_, saveNormals_, saveTexCoords_, saveTextures_};
      
      QTreeWidget* tree = new QTreeWidget();
      tree->setHeaderLabel("Configuration:");
      QTreeWidgetItem* advanced = new QTreeWidgetItem();
      advanced->setText(0,"Advanced");
      QTreeWidgetItem* general = new QTreeWidgetItem();
      general->setText(0,"General");
      tree->invisibleRootItem()->addChild(general);
      tree->invisibleRootItem()->addChild(advanced);
      
      save_assimp_process_calcTangentSpace         = new QCheckBox("assimp_process_calcTangentSpace        ");
      save_assimp_process_joinIdenticalVertices    = new QCheckBox("assimp_process_joinIdenticalVertices   ");
      save_assimp_process_makeLeftHanded           = new QCheckBox("assimp_process_makeLeftHanded          ");
      save_assimp_process_triangulate              = new QCheckBox("assimp_process_triangulate             ");
      save_assimp_process_removeComponent          = new QCheckBox("assimp_process_removeComponent         ");
      save_assimp_process_genNormals               = new QCheckBox("assimp_process_genNormals              ");
      save_assimp_process_genSmoothNormals         = new QCheckBox("assimp_process_genSmoothNormals        ");
      save_assimp_process_splitLargeMeshes         = new QCheckBox("assimp_process_splitLargeMeshes        ");
      save_assimp_process_preTransformVertices     = new QCheckBox("assimp_process_preTransformVertices    ");
      save_assimp_process_limitBoneWeights         = new QCheckBox("assimp_process_limitBoneWeights        ");
      save_assimp_process_validateDataStructure    = new QCheckBox("assimp_process_validateDataStructure   ");
      save_assimp_process_improveCacheLocality     = new QCheckBox("assimp_process_improveCacheLocality    ");
      save_assimp_process_removeRedundantMaterials = new QCheckBox("assimp_process_removeRedundantMaterials");
      save_assimp_process_fixInfacingNormals       = new QCheckBox("assimp_process_fixInfacingNormals      ");
      save_assimp_process_sortByPType              = new QCheckBox("assimp_process_sortByPType             ");
      save_assimp_process_findDegenerates          = new QCheckBox("assimp_process_findDegenerates         ");
      save_assimp_process_findInvalidData          = new QCheckBox("assimp_process_findInvalidData         ");
      save_assimp_process_genUVCoords              = new QCheckBox("assimp_process_genUVCoords             ");
      save_assimp_process_transformUVCoords        = new QCheckBox("assimp_process_transformUVCoords       ");
      save_assimp_process_findInstances            = new QCheckBox("assimp_process_findInstances           ");
      save_assimp_process_optimizeMeshes           = new QCheckBox("assimp_process_optimizeMeshes          ");
      save_assimp_process_optimizeGraph            = new QCheckBox("assimp_process_optimizeGraph           ");
      save_assimp_process_flipUVs                  = new QCheckBox("assimp_process_flipUVs                 ");
      save_assimp_process_flipWindingOrder         = new QCheckBox("assimp_process_flipWindingOrder        ");
      save_assimp_process_splitByBoneCount         = new QCheckBox("assimp_process_splitByBoneCount        ");
      save_assimp_process_debone                   = new QCheckBox("assimp_process_debone                  ");

      QList<QWidget*> advancedOptions= {save_assimp_process_calcTangentSpace        ,
                                        save_assimp_process_joinIdenticalVertices   ,
                                        save_assimp_process_makeLeftHanded          ,
                                        save_assimp_process_triangulate             ,
                                        save_assimp_process_removeComponent         ,
                                        save_assimp_process_genNormals              ,
                                        save_assimp_process_genSmoothNormals        ,
                                        save_assimp_process_splitLargeMeshes        ,
                                        save_assimp_process_preTransformVertices    ,
                                        save_assimp_process_limitBoneWeights        ,
                                        save_assimp_process_validateDataStructure   ,
                                        save_assimp_process_improveCacheLocality    ,
                                        save_assimp_process_removeRedundantMaterials,
                                        save_assimp_process_fixInfacingNormals      ,
                                        save_assimp_process_sortByPType             ,
                                        save_assimp_process_findDegenerates         ,
                                        save_assimp_process_findInvalidData         ,
                                        save_assimp_process_genUVCoords             ,
                                        save_assimp_process_transformUVCoords       ,
                                        save_assimp_process_findInstances           ,
                                        save_assimp_process_optimizeMeshes          ,
                                        save_assimp_process_optimizeGraph           ,
                                        save_assimp_process_flipUVs                 ,
                                        save_assimp_process_flipWindingOrder        ,
                                        save_assimp_process_splitByBoneCount        ,
                                        save_assimp_process_debone                  };
      
      for(QList<QWidget*>::iterator it = advancedOptions.begin() ; it != advancedOptions.end(); ++it)
      {
        QTreeWidgetItem* treeWidget = new QTreeWidgetItem();
        advanced->addChild(treeWidget);
        tree->setItemWidget(treeWidget,0,*it);
      }
      
      for(QList<QWidget*>::iterator it = generalOptions.begin() ; it != generalOptions.end(); ++it)
      {
        QTreeWidgetItem* treeWidget = new QTreeWidgetItem();
        general->addChild(treeWidget);
        tree->setItemWidget(treeWidget,0,*it);
      }
      
      saveDefaultButton_ = new QPushButton("Make Default");
      
      layout->addWidget(tree);
      layout->addWidget(saveDefaultButton_);
      
      saveOptions_->setLayout(layout);

      connect(saveDefaultButton_, SIGNAL(clicked()), this, SLOT(slotSaveDefault()));

      saveFaceColor_->setChecked( OpenFlipperSettings().value("Assimp/Save/FaceColor",true).toBool()  );
      saveNormals_->setChecked  ( OpenFlipperSettings().value("Assimp/Save/Normals"  ,true).toBool()  );
      saveTexCoords_->setChecked( OpenFlipperSettings().value("Assimp/Save/TexCoords",true).toBool()  );
      saveTextures_->setChecked ( OpenFlipperSettings().value("Assimp/Save/Textures" ,true).toBool()  );
      
      save_assimp_process_calcTangentSpace         ->setChecked(OpenFlipperSettings().value( "Assimp/Save/process/calcTangentSpace"        , false).toBool());
      save_assimp_process_joinIdenticalVertices    ->setChecked(OpenFlipperSettings().value( "Assimp/Save/process/joinIdenticalVertices"   , true ).toBool());
      save_assimp_process_makeLeftHanded           ->setChecked(OpenFlipperSettings().value( "Assimp/Save/process/makeLeftHanded"          , false).toBool());
      save_assimp_process_triangulate              ->setChecked(OpenFlipperSettings().value( "Assimp/Save/process/triangulate"             , false).toBool());
      save_assimp_process_removeComponent          ->setChecked(OpenFlipperSettings().value( "Assimp/Save/process/removeComponent"         , false).toBool());
      save_assimp_process_genNormals               ->setChecked(OpenFlipperSettings().value( "Assimp/Save/process/genNormals"              , false).toBool());
      save_assimp_process_genSmoothNormals         ->setChecked(OpenFlipperSettings().value( "Assimp/Save/process/genSmoothNormals"        , false).toBool());
      save_assimp_process_splitLargeMeshes         ->setChecked(OpenFlipperSettings().value( "Assimp/Save/process/splitLargeMeshes"        , false).toBool());
      save_assimp_process_preTransformVertices     ->setChecked(OpenFlipperSettings().value( "Assimp/Save/process/preTransformVertices"    , false).toBool());
      save_assimp_process_limitBoneWeights         ->setChecked(OpenFlipperSettings().value( "Assimp/Save/process/limitBoneWeights"        , false).toBool());
      save_assimp_process_validateDataStructure    ->setChecked(OpenFlipperSettings().value( "Assimp/Save/process/validateDataStructure"   , false).toBool());
      save_assimp_process_improveCacheLocality     ->setChecked(OpenFlipperSettings().value( "Assimp/Save/process/improveCacheLocality"    , false).toBool());
      save_assimp_process_removeRedundantMaterials ->setChecked(OpenFlipperSettings().value( "Assimp/Save/process/removeRedundantMaterials", false).toBool());
      save_assimp_process_fixInfacingNormals       ->setChecked(OpenFlipperSettings().value( "Assimp/Save/process/fixInfacingNormals"      , false).toBool());
      save_assimp_process_sortByPType              ->setChecked(OpenFlipperSettings().value( "Assimp/Save/process/sortByPType"             , false).toBool());
      save_assimp_process_findDegenerates          ->setChecked(OpenFlipperSettings().value( "Assimp/Save/process/findDegenerates"         , true ).toBool());
      save_assimp_process_findInvalidData          ->setChecked(OpenFlipperSettings().value( "Assimp/Save/process/findInvalidData"         , false).toBool());
      save_assimp_process_genUVCoords              ->setChecked(OpenFlipperSettings().value( "Assimp/Save/process/genUVCoords"             , false).toBool());
      save_assimp_process_transformUVCoords        ->setChecked(OpenFlipperSettings().value( "Assimp/Save/process/transformUVCoords"       , false).toBool());
      save_assimp_process_findInstances            ->setChecked(OpenFlipperSettings().value( "Assimp/Save/process/findInstances"           , false).toBool());
      save_assimp_process_optimizeMeshes           ->setChecked(OpenFlipperSettings().value( "Assimp/Save/process/optimizeMeshes"          , false).toBool());
      save_assimp_process_optimizeGraph            ->setChecked(OpenFlipperSettings().value( "Assimp/Save/process/optimizeGraph"           , false).toBool());
      save_assimp_process_flipUVs                  ->setChecked(OpenFlipperSettings().value( "Assimp/Save/process/flipUVs"                 , false).toBool());
      save_assimp_process_flipWindingOrder         ->setChecked(OpenFlipperSettings().value( "Assimp/Save/process/flipWindingOrder"        , false).toBool());
      save_assimp_process_splitByBoneCount         ->setChecked(OpenFlipperSettings().value( "Assimp/Save/process/splitByBoneCount"        , false).toBool());
      save_assimp_process_debone                   ->setChecked(OpenFlipperSettings().value( "Assimp/Save/process/debone"                  , false).toBool());
474 475 476 477 478 479
  }

  return saveOptions_;
}

QWidget *AssimpPlugin::loadOptionsWidget(QString) {
480 481 482 483 484 485 486 487 488 489 490 491 492
  if (loadOptions_ == 0){
      //generate widget
      loadOptions_ = new QWidget();
      QVBoxLayout* layout = new QVBoxLayout();
      layout->setAlignment(Qt::AlignTop);

      // generic configuration
      triMeshHandling_ = new QComboBox();
      triMeshHandling_->addItem( tr("Detect correct mesh type") );
      triMeshHandling_->addItem( tr("Ask") );
      triMeshHandling_->addItem( tr("Open as PolyMesh") );
      triMeshHandling_->addItem( tr("Open as TriangleMesh") );      

493 494 495 496 497 498 499
      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);
500 501 502 503 504 505 506 507 508 509 510 511
      
      QList<QWidget*> generalOptions = {triMeshHandling_, loadFaceColor_, loadNormals_, loadTexCoords_, loadTextures_};
      
      QTreeWidget* tree = new QTreeWidget();
      tree->setHeaderLabel("Configuration:");
      QTreeWidgetItem* advanced = new QTreeWidgetItem();
      advanced->setText(0,"Advanced");
      QTreeWidgetItem* general = new QTreeWidgetItem();
      general->setText(0,"General");
      tree->invisibleRootItem()->addChild(general);
      tree->invisibleRootItem()->addChild(advanced);
      
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
      load_assimp_process_calcTangentSpace         = new QCheckBox("assimp_process_calcTangentSpace        ");
      load_assimp_process_joinIdenticalVertices    = new QCheckBox("assimp_process_joinIdenticalVertices   ");
      load_assimp_process_makeLeftHanded           = new QCheckBox("assimp_process_makeLeftHanded          ");
      load_assimp_process_triangulate              = new QCheckBox("assimp_process_triangulate             ");
      load_assimp_process_removeComponent          = new QCheckBox("assimp_process_removeComponent         ");
      load_assimp_process_genNormals               = new QCheckBox("assimp_process_genNormals              ");
      load_assimp_process_genSmoothNormals         = new QCheckBox("assimp_process_genSmoothNormals        ");
      load_assimp_process_splitLargeMeshes         = new QCheckBox("assimp_process_splitLargeMeshes        ");
      load_assimp_process_preTransformVertices     = new QCheckBox("assimp_process_preTransformVertices    ");
      load_assimp_process_limitBoneWeights         = new QCheckBox("assimp_process_limitBoneWeights        ");
      load_assimp_process_validateDataStructure    = new QCheckBox("assimp_process_validateDataStructure   ");
      load_assimp_process_improveCacheLocality     = new QCheckBox("assimp_process_improveCacheLocality    ");
      load_assimp_process_removeRedundantMaterials = new QCheckBox("assimp_process_removeRedundantMaterials");
      load_assimp_process_fixInfacingNormals       = new QCheckBox("assimp_process_fixInfacingNormals      ");
      load_assimp_process_sortByPType              = new QCheckBox("assimp_process_sortByPType             ");
      load_assimp_process_findDegenerates          = new QCheckBox("assimp_process_findDegenerates         ");
      load_assimp_process_findInvalidData          = new QCheckBox("assimp_process_findInvalidData         ");
      load_assimp_process_genUVCoords              = new QCheckBox("assimp_process_genUVCoords             ");
      load_assimp_process_transformUVCoords        = new QCheckBox("assimp_process_transformUVCoords       ");
      load_assimp_process_findInstances            = new QCheckBox("assimp_process_findInstances           ");
      load_assimp_process_optimizeMeshes           = new QCheckBox("assimp_process_optimizeMeshes          ");
      load_assimp_process_optimizeGraph            = new QCheckBox("assimp_process_optimizeGraph           ");
      load_assimp_process_flipUVs                  = new QCheckBox("assimp_process_flipUVs                 ");
      load_assimp_process_flipWindingOrder         = new QCheckBox("assimp_process_flipWindingOrder        ");
      load_assimp_process_splitByBoneCount         = new QCheckBox("assimp_process_splitByBoneCount        ");
      load_assimp_process_debone                   = new QCheckBox("assimp_process_debone                  ");

Martin Schultz's avatar
Martin Schultz committed
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564
      loadOptions= {{load_assimp_process_calcTangentSpace        , aiProcess_CalcTangentSpace        },
                    {load_assimp_process_joinIdenticalVertices   , aiProcess_JoinIdenticalVertices   },
                    {load_assimp_process_makeLeftHanded          , aiProcess_MakeLeftHanded          },
                    {load_assimp_process_triangulate             , aiProcess_Triangulate             },
                    {load_assimp_process_removeComponent         , aiProcess_RemoveComponent         },
                    {load_assimp_process_genNormals              , aiProcess_GenNormals              },
                    {load_assimp_process_genSmoothNormals        , aiProcess_GenSmoothNormals        },
                    {load_assimp_process_splitLargeMeshes        , aiProcess_SplitLargeMeshes        },
                    {load_assimp_process_preTransformVertices    , aiProcess_PreTransformVertices    },
                    {load_assimp_process_limitBoneWeights        , aiProcess_LimitBoneWeights        },
                    {load_assimp_process_validateDataStructure   , aiProcess_ValidateDataStructure   },
                    {load_assimp_process_improveCacheLocality    , aiProcess_ImproveCacheLocality    },
                    {load_assimp_process_removeRedundantMaterials, aiProcess_RemoveRedundantMaterials},
                    {load_assimp_process_fixInfacingNormals      , aiProcess_FixInfacingNormals      },
                    {load_assimp_process_sortByPType             , aiProcess_SortByPType             },
                    {load_assimp_process_findDegenerates         , aiProcess_FindDegenerates         },
                    {load_assimp_process_findInvalidData         , aiProcess_FindInvalidData         },
                    {load_assimp_process_genUVCoords             , aiProcess_GenUVCoords             },
                    {load_assimp_process_transformUVCoords       , aiProcess_TransformUVCoords       },
                    {load_assimp_process_findInstances           , aiProcess_FindInstances           },
                    {load_assimp_process_optimizeMeshes          , aiProcess_OptimizeMeshes          },
                    {load_assimp_process_optimizeGraph           , aiProcess_OptimizeGraph           },
                    {load_assimp_process_flipUVs                 , aiProcess_FlipUVs                 },
                    {load_assimp_process_flipWindingOrder        , aiProcess_FlipWindingOrder        },
                    {load_assimp_process_splitByBoneCount        , aiProcess_SplitByBoneCount        },
                    {load_assimp_process_debone                  , aiProcess_Debone                  }};
565
      
Martin Schultz's avatar
Martin Schultz committed
566
      for(auto it = loadOptions.begin() ; it != loadOptions.end(); ++it)
567 568 569
      {
        QTreeWidgetItem* treeWidget = new QTreeWidgetItem();
        advanced->addChild(treeWidget);
Martin Schultz's avatar
Martin Schultz committed
570
        tree->setItemWidget(treeWidget,0,it->first);
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595
      }
      
      for(QList<QWidget*>::iterator it = generalOptions.begin() ; it != generalOptions.end(); ++it)
      {
        QTreeWidgetItem* treeWidget = new QTreeWidgetItem();
        general->addChild(treeWidget);
        tree->setItemWidget(treeWidget,0,*it);
      }
      
      loadDefaultButton_ = new QPushButton("Make Default");
      
      layout->addWidget(tree);
      layout->addWidget(loadDefaultButton_);
      
      loadOptions_->setLayout(layout);

      connect(loadDefaultButton_, SIGNAL(clicked()), this, SLOT(slotLoadDefault()));

      triMeshHandling_->setCurrentIndex(OpenFlipperSettings().value("Assimp/Load/TriMeshHandling",TYPEAUTODETECT).toInt() );

      loadFaceColor_->setChecked( OpenFlipperSettings().value("Assimp/Load/FaceColor",true).toBool()  );
      loadNormals_->setChecked  ( OpenFlipperSettings().value("Assimp/Load/Normals"  ,true).toBool()  );
      loadTexCoords_->setChecked( OpenFlipperSettings().value("Assimp/Load/TexCoords",true).toBool()  );
      loadTextures_->setChecked ( OpenFlipperSettings().value("Assimp/Load/Textures" ,true).toBool()  );
      
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621
      load_assimp_process_calcTangentSpace         ->setChecked(OpenFlipperSettings().value( "Assimp/Load/process/calcTangentSpace"        , false).toBool());
      load_assimp_process_joinIdenticalVertices    ->setChecked(OpenFlipperSettings().value( "Assimp/Load/process/joinIdenticalVertices"   , true ).toBool());
      load_assimp_process_makeLeftHanded           ->setChecked(OpenFlipperSettings().value( "Assimp/Load/process/makeLeftHanded"          , false).toBool());
      load_assimp_process_triangulate              ->setChecked(OpenFlipperSettings().value( "Assimp/Load/process/triangulate"             , false).toBool());
      load_assimp_process_removeComponent          ->setChecked(OpenFlipperSettings().value( "Assimp/Load/process/removeComponent"         , false).toBool());
      load_assimp_process_genNormals               ->setChecked(OpenFlipperSettings().value( "Assimp/Load/process/genNormals"              , false).toBool());
      load_assimp_process_genSmoothNormals         ->setChecked(OpenFlipperSettings().value( "Assimp/Load/process/genSmoothNormals"        , false).toBool());
      load_assimp_process_splitLargeMeshes         ->setChecked(OpenFlipperSettings().value( "Assimp/Load/process/splitLargeMeshes"        , false).toBool());
      load_assimp_process_preTransformVertices     ->setChecked(OpenFlipperSettings().value( "Assimp/Load/process/preTransformVertices"    , false).toBool());
      load_assimp_process_limitBoneWeights         ->setChecked(OpenFlipperSettings().value( "Assimp/Load/process/limitBoneWeights"        , false).toBool());
      load_assimp_process_validateDataStructure    ->setChecked(OpenFlipperSettings().value( "Assimp/Load/process/validateDataStructure"   , false).toBool());
      load_assimp_process_improveCacheLocality     ->setChecked(OpenFlipperSettings().value( "Assimp/Load/process/improveCacheLocality"    , false).toBool());
      load_assimp_process_removeRedundantMaterials ->setChecked(OpenFlipperSettings().value( "Assimp/Load/process/removeRedundantMaterials", false).toBool());
      load_assimp_process_fixInfacingNormals       ->setChecked(OpenFlipperSettings().value( "Assimp/Load/process/fixInfacingNormals"      , false).toBool());
      load_assimp_process_sortByPType              ->setChecked(OpenFlipperSettings().value( "Assimp/Load/process/sortByPType"             , false).toBool());
      load_assimp_process_findDegenerates          ->setChecked(OpenFlipperSettings().value( "Assimp/Load/process/findDegenerates"         , true ).toBool());
      load_assimp_process_findInvalidData          ->setChecked(OpenFlipperSettings().value( "Assimp/Load/process/findInvalidData"         , false).toBool());
      load_assimp_process_genUVCoords              ->setChecked(OpenFlipperSettings().value( "Assimp/Load/process/genUVCoords"             , false).toBool());
      load_assimp_process_transformUVCoords        ->setChecked(OpenFlipperSettings().value( "Assimp/Load/process/transformUVCoords"       , false).toBool());
      load_assimp_process_findInstances            ->setChecked(OpenFlipperSettings().value( "Assimp/Load/process/findInstances"           , false).toBool());
      load_assimp_process_optimizeMeshes           ->setChecked(OpenFlipperSettings().value( "Assimp/Load/process/optimizeMeshes"          , false).toBool());
      load_assimp_process_optimizeGraph            ->setChecked(OpenFlipperSettings().value( "Assimp/Load/process/optimizeGraph"           , false).toBool());
      load_assimp_process_flipUVs                  ->setChecked(OpenFlipperSettings().value( "Assimp/Load/process/flipUVs"                 , false).toBool());
      load_assimp_process_flipWindingOrder         ->setChecked(OpenFlipperSettings().value( "Assimp/Load/process/flipWindingOrder"        , false).toBool());
      load_assimp_process_splitByBoneCount         ->setChecked(OpenFlipperSettings().value( "Assimp/Load/process/splitByBoneCount"        , false).toBool());
      load_assimp_process_debone                   ->setChecked(OpenFlipperSettings().value( "Assimp/Load/process/debone"                  , false).toBool());
622 623 624 625 626 627 628
  }

  return loadOptions_;
}

int AssimpPlugin::loadObject(QString _filename) {
  Assimp::Importer importer;
629
  cancel_ = false;
630 631 632 633 634 635 636 637 638
  
  const aiScene* scene = NULL;
  scene = importer.ReadFile(_filename.toStdString(), processSteps(loadOptions));

  if (!scene) {
    emit log(LOGERR, tr(importer.GetErrorString()));
    return -1;
  }
  
Martin Schultz's avatar
Martin Schultz committed
639 640 641 642 643
  if(OpenFlipper::Options::gui() && loadOptions_ != nullptr)
  {
    switch(triMeshHandling_->currentIndex())
    {
      case TYPEAUTODETECT :
644
          type_ = DATA_UNKNOWN;
Martin Schultz's avatar
Martin Schultz committed
645 646 647 648 649 650
          break;
      case TYPEPOLY :
          type_ = DATA_POLY_MESH;
         break;
      case TYPETRIANGLE :
          type_ = DATA_TRIANGLE_MESH;
651
         break;
Martin Schultz's avatar
Martin Schultz committed
652
      case TYPEASK :
653 654 655 656 657 658 659 660 661 662 663 664
          QMessageBox msgBox;
          QPushButton *detectButton = msgBox.addButton(tr("Auto-Detect"), QMessageBox::ActionRole);
          QPushButton *triButton    = msgBox.addButton(tr("Open as triangle mesh"), QMessageBox::ActionRole);
          QPushButton *polyButton   = msgBox.addButton(tr("Open as poly mesh"), QMessageBox::ActionRole);
          msgBox.setWindowTitle( tr("Mesh types in file") );
          msgBox.setText( tr("You are about to open a file containing one or more mesh types. \n\n Which mesh type should be used?") );
          msgBox.setDefaultButton( detectButton );
          msgBox.exec();
          if (msgBox.clickedButton() == triButton)
            type_ = DATA_TRIANGLE_MESH;
          else if (msgBox.clickedButton() == polyButton)
            type_ = DATA_POLY_MESH;
Martin Schultz's avatar
Martin Schultz committed
665 666 667
         break;
    }
  }
668

Isaak Lim's avatar
Isaak Lim committed
669 670
  QFileInfo f(_filename);
  return convertAiSceneToOpenMesh(scene, f.fileName());
671 672 673
}

int AssimpPlugin::loadObject(QString _filename, DataType _type) {
674 675
  if (_type != DATA_GROUP) //if equal => autodetect data
    type_ = _type;
676 677 678 679
  return loadObject(_filename);
}

bool AssimpPlugin::saveObject(int _id, QString _filename) {
Isaak Lim's avatar
Isaak Lim committed
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705
  BaseObjectData* object;
  PluginFunctions::getObject(_id,object);

  if (!object) {
    emit log(LOGERR, tr("Could not get the object with the given id"));
    return false;
  }

  object->setFromFileName(_filename);
  object->setName(object->filename());

  aiScene scene;

  if (!convertOpenMeshToAiScene(&scene, object))
    return false;

  Assimp::Exporter exporter;

  QFileInfo f(_filename);

  std::string formatId = (f.suffix() == "dae") ? "collada" : f.suffix().toStdString();
  bool ok = exporter.Export(&scene, formatId, _filename.toStdString()) == AI_SUCCESS;
  if (!ok)
    emit log(LOGERR, exporter.GetErrorString());

  return ok;
706 707
}

708 709 710 711 712 713 714
void AssimpPlugin::slotLoadDefault() {
  OpenFlipperSettings().setValue( "Assimp/Load/FaceColor",   loadFaceColor_->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Load/Normals",     loadNormals_->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Load/TexCoords",   loadTexCoords_->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Load/Textures",    loadTextures_->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Load/TriMeshHandling", triMeshHandling_->currentIndex() );

715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740
  OpenFlipperSettings().setValue( "Assimp/Load/process/calcTangentSpace"        ,   load_assimp_process_calcTangentSpace        ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Load/process/joinIdenticalVertices"   ,   load_assimp_process_joinIdenticalVertices   ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Load/process/makeLeftHanded"          ,   load_assimp_process_makeLeftHanded          ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Load/process/triangulate"             ,   load_assimp_process_triangulate             ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Load/process/removeComponent"         ,   load_assimp_process_removeComponent         ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Load/process/genNormals"              ,   load_assimp_process_genNormals              ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Load/process/genSmoothNormals"        ,   load_assimp_process_genSmoothNormals        ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Load/process/splitLargeMeshes"        ,   load_assimp_process_splitLargeMeshes        ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Load/process/preTransformVertices"    ,   load_assimp_process_preTransformVertices    ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Load/process/limitBoneWeights"        ,   load_assimp_process_limitBoneWeights        ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Load/process/validateDataStructure"   ,   load_assimp_process_validateDataStructure   ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Load/process/improveCacheLocality"    ,   load_assimp_process_improveCacheLocality    ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Load/process/removeRedundantMaterials",   load_assimp_process_removeRedundantMaterials->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Load/process/fixInfacingNormals"      ,   load_assimp_process_fixInfacingNormals      ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Load/process/sortByPType"             ,   load_assimp_process_sortByPType             ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Load/process/findDegenerates"         ,   load_assimp_process_findDegenerates         ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Load/process/findInvalidData"         ,   load_assimp_process_findInvalidData         ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Load/process/genUVCoords"             ,   load_assimp_process_genUVCoords             ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Load/process/transformUVCoords"       ,   load_assimp_process_transformUVCoords       ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Load/process/findInstances"           ,   load_assimp_process_findInstances           ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Load/process/optimizeMeshes"          ,   load_assimp_process_optimizeMeshes          ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Load/process/optimizeGraph"           ,   load_assimp_process_optimizeGraph           ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Load/process/flipUVs"                 ,   load_assimp_process_flipUVs                 ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Load/process/flipWindingOrder"        ,   load_assimp_process_flipWindingOrder        ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Load/process/splitByBoneCount"        ,   load_assimp_process_splitByBoneCount        ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Load/process/debone"                  ,   load_assimp_process_debone                  ->isChecked()  );
741 742 743 744
  
  OpenFlipperSettings().setValue( "Core/File/UseLoadDefaults", true );
}

745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777
void AssimpPlugin::slotSaveDefault() {
  OpenFlipperSettings().setValue( "Assimp/Save/FaceColor",   saveFaceColor_->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Save/Normals",     saveNormals_  ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Save/TexCoords",   saveTexCoords_->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Save/Textures",    saveTextures_ ->isChecked()  );

  OpenFlipperSettings().setValue( "Assimp/Save/process/calcTangentSpace"        ,   save_assimp_process_calcTangentSpace        ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Save/process/joinIdenticalVertices"   ,   save_assimp_process_joinIdenticalVertices   ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Save/process/makeLeftHanded"          ,   save_assimp_process_makeLeftHanded          ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Save/process/triangulate"             ,   save_assimp_process_triangulate             ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Save/process/removeComponent"         ,   save_assimp_process_removeComponent         ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Save/process/genNormals"              ,   save_assimp_process_genNormals              ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Save/process/genSmoothNormals"        ,   save_assimp_process_genSmoothNormals        ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Save/process/splitLargeMeshes"        ,   save_assimp_process_splitLargeMeshes        ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Save/process/preTransformVertices"    ,   save_assimp_process_preTransformVertices    ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Save/process/limitBoneWeights"        ,   save_assimp_process_limitBoneWeights        ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Save/process/validateDataStructure"   ,   save_assimp_process_validateDataStructure   ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Save/process/improveCacheLocality"    ,   save_assimp_process_improveCacheLocality    ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Save/process/removeRedundantMaterials",   save_assimp_process_removeRedundantMaterials->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Save/process/fixInfacingNormals"      ,   save_assimp_process_fixInfacingNormals      ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Save/process/sortByPType"             ,   save_assimp_process_sortByPType             ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Save/process/findDegenerates"         ,   save_assimp_process_findDegenerates         ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Save/process/findInvalidData"         ,   save_assimp_process_findInvalidData         ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Save/process/genUVCoords"             ,   save_assimp_process_genUVCoords             ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Save/process/transformUVCoords"       ,   save_assimp_process_transformUVCoords       ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Save/process/findInstances"           ,   save_assimp_process_findInstances           ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Save/process/optimizeMeshes"          ,   save_assimp_process_optimizeMeshes          ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Save/process/optimizeGraph"           ,   save_assimp_process_optimizeGraph           ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Save/process/flipUVs"                 ,   save_assimp_process_flipUVs                 ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Save/process/flipWindingOrder"        ,   save_assimp_process_flipWindingOrder        ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Save/process/splitByBoneCount"        ,   save_assimp_process_splitByBoneCount        ->isChecked()  );
  OpenFlipperSettings().setValue( "Assimp/Save/process/debone"                  ,   save_assimp_process_debone                  ->isChecked()  );
}
778

Martin Schultz's avatar
Martin Schultz committed
779 780 781 782 783
unsigned int AssimpPlugin::processSteps( const std::unordered_map<QCheckBox*, unsigned int>& _options)
{
  unsigned int result = 0;
  for(auto entry : _options)
  {
784 785
    if(entry.first != nullptr)
      result |= entry.first->isChecked()? entry.second : 0;
Martin Schultz's avatar
Martin Schultz committed
786 787 788 789
  }
  return result;
}

790 791 792 793 794 795 796 797 798 799 800 801 802 803
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;
}

804 805 806 807 808 809
void AssimpPlugin::canceledJob(QString _jobId)
{
  if(_jobId ==  "Loading File" || _jobId == "Loading Files")
    cancel_ = true;
}

810 811 812
#if QT_VERSION < 0x050000
  Q_EXPORT_PLUGIN2( assimpplugin , AssimpPlugin )
#endif