Commit 17be8d95 authored by Martin Schultz's avatar Martin Schultz

Added saveOptions

Added selection between Poly and TriMesh
fixed polymesh loading
parent 0e379552
......@@ -96,7 +96,7 @@ void AssimpPlugin::initializePlugin() {
int AssimpPlugin::convertAiSceneToOpenMesh(const aiScene *_scene, QString _objectName) {
int returnId = -1;
std::vector<int> ids;
std::cout<<"found " << _scene->mNumMeshes << " meshes "<<std::endl;
if (_scene->mNumMeshes == 0)
emit log(LOGWARN, tr("aiScene contains no meshes"));
......@@ -119,7 +119,7 @@ int AssimpPlugin::convertAiSceneToOpenMesh(const aiScene *_scene, QString _objec
TriMeshObject* triMeshObj = dynamic_cast< TriMeshObject* > (object);
if (polyMeshObj) {
convertPolyMeshToAiMesh(polyMeshObj->mesh(), _scene->mMeshes[i]);
convertAiMeshToPolyMesh(polyMeshObj->mesh(), _scene->mMeshes[i]);
emit updatedObject(polyMeshObj->id(), UPDATE_ALL);
......@@ -514,38 +514,38 @@ QWidget *AssimpPlugin::loadOptionsWidget(QString) {
load_assimp_process_splitByBoneCount = new QCheckBox("assimp_process_splitByBoneCount ");
load_assimp_process_debone = new QCheckBox("assimp_process_debone ");
QList<QWidget*> advancedOptions= {load_assimp_process_calcTangentSpace ,
load_assimp_process_joinIdenticalVertices ,
load_assimp_process_makeLeftHanded ,
load_assimp_process_triangulate ,
load_assimp_process_removeComponent ,
load_assimp_process_genNormals ,
load_assimp_process_genSmoothNormals ,
load_assimp_process_splitLargeMeshes ,
load_assimp_process_preTransformVertices ,
load_assimp_process_limitBoneWeights ,
load_assimp_process_validateDataStructure ,
load_assimp_process_improveCacheLocality ,
load_assimp_process_removeRedundantMaterials,
load_assimp_process_fixInfacingNormals ,
load_assimp_process_sortByPType ,
load_assimp_process_findDegenerates ,
load_assimp_process_findInvalidData ,
load_assimp_process_genUVCoords ,
load_assimp_process_transformUVCoords ,
load_assimp_process_findInstances ,
load_assimp_process_optimizeMeshes ,
load_assimp_process_optimizeGraph ,
load_assimp_process_flipUVs ,
load_assimp_process_flipWindingOrder ,
load_assimp_process_splitByBoneCount ,
load_assimp_process_debone };
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 }};
for(QList<QWidget*>::iterator it = advancedOptions.begin() ; it != advancedOptions.end(); ++it)
for(auto it = loadOptions.begin() ; it != loadOptions.end(); ++it)
{
QTreeWidgetItem* treeWidget = new QTreeWidgetItem();
advanced->addChild(treeWidget);
tree->setItemWidget(treeWidget,0,*it);
tree->setItemWidget(treeWidget,0,it->first);
}
for(QList<QWidget*>::iterator it = generalOptions.begin() ; it != generalOptions.end(); ++it)
......@@ -604,13 +604,28 @@ QWidget *AssimpPlugin::loadOptionsWidget(QString) {
int AssimpPlugin::loadObject(QString _filename) {
Assimp::Importer importer;
if(OpenFlipper::Options::gui() && loadOptions_ != nullptr)
{
switch(triMeshHandling_->currentIndex())
{
case TYPEAUTODETECT :
break;
case TYPEPOLY :
type_ = DATA_POLY_MESH;
break;
case TYPETRIANGLE :
type_ = DATA_TRIANGLE_MESH;
case TYPEASK :
break;
}
}
const aiScene* scene = NULL;
if (type_ == DATA_TRIANGLE_MESH)
scene = importer.ReadFile(_filename.toStdString(), aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_FindDegenerates);
scene = importer.ReadFile(_filename.toStdString(), processSteps(loadOptions));// aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_FindDegenerates);
else
scene = importer.ReadFile(_filename.toStdString(), aiProcess_JoinIdenticalVertices | aiProcess_FindDegenerates);
scene = importer.ReadFile(_filename.toStdString(), processSteps(loadOptions));// aiProcess_JoinIdenticalVertices | aiProcess_FindDegenerates);
std::cout<<"processSteps: "<< processSteps(loadOptions)<<std::endl;
if (!scene) {
emit log(LOGERR, tr(importer.GetErrorString()));
return -1;
......@@ -726,6 +741,16 @@ void AssimpPlugin::slotSaveDefault() {
OpenFlipperSettings().setValue( "Assimp/Save/process/debone" , save_assimp_process_debone ->isChecked() );
}
unsigned int AssimpPlugin::processSteps( const std::unordered_map<QCheckBox*, unsigned int>& _options)
{
unsigned int result = 0;
for(auto entry : _options)
{
result |= entry.first->isChecked()? entry.second : 0;
}
return result;
}
#if QT_VERSION < 0x050000
Q_EXPORT_PLUGIN2( assimpplugin , AssimpPlugin )
#endif
......@@ -66,6 +66,7 @@
#include <assimp/postprocess.h>
#include <assimp/scene.h>
#include<unordered_map>
class AssimpPlugin : public QObject, BaseInterface, FileInterface, LoadSaveInterface,
LoggingInterface, ScriptInterface, RPCInterface, AboutInfoInterface
......@@ -162,6 +163,10 @@ private:
/// add a vertex from _mesh to _trimesh and stores the index to handle mapping
void mapVertices(TriMesh* _triMesh, aiMesh* _mesh);
/// returns which postprocessing steps are enabled for the loader
unsigned int processSteps(const std::unordered_map<QCheckBox*, unsigned int>& _options);
private:
//Option Widgets
......@@ -203,6 +208,8 @@ private:
QCheckBox* load_assimp_process_flipWindingOrder ;
QCheckBox* load_assimp_process_splitByBoneCount ;
QCheckBox* load_assimp_process_debone ;
std::unordered_map<QCheckBox*, unsigned int> loadOptions;
QCheckBox* saveVertexColor_;
QCheckBox* saveFaceColor_;
......@@ -239,6 +246,8 @@ private:
QCheckBox* save_assimp_process_splitByBoneCount ;
QCheckBox* save_assimp_process_debone ;
std::unordered_map<QCheckBox*, unsigned int> saveOptions;
DataType type_;
/// maps indices of vertices in an aiMesh to OpenMesh VertexHandles
......
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