Commit 45e5d461 authored by Jan's avatar Jan
Browse files

Moved Plugin Assimp to a separate repo

parent f40cc6f2
/*===========================================================================*\
* *
* 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 $ *
* $Date: 2012-01-12 16:33:16 +0100 (Thu, 12 Jan 2012) $ *
* *
\*===========================================================================*/
#ifndef ASSIMPPLUGIN_HH
#define ASSIMPPLUGIN_HH
#include <QObject>
#include <OpenFlipper/common/Types.hh>
#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/FileInterface.hh>
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <OpenFlipper/BasePlugin/ScriptInterface.hh>
#include <OpenFlipper/BasePlugin/TypeInterface.hh>
#include <OpenFlipper/BasePlugin/RPCInterface.hh>
#include <OpenFlipper/BasePlugin/AboutInfoInterface.hh>
#include <OpenFlipper/BasePlugin/ProcessInterface.hh>
#include <OpenFlipper/BasePlugin/TextureInterface.hh>
#include <ObjectTypes/PolyMesh/PolyMesh.hh>
#include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
#include <assimp/Importer.hpp>
#include <assimp/Exporter.hpp>
#include <assimp/postprocess.h>
#include <assimp/scene.h>
#include<unordered_map>
#include "AssimpPluginCommon.hh"
#include <QComboBox>
#include <QCheckBox>
class AssimpOptionsWidget;
class AssimpPlugin : public QObject, BaseInterface, FileInterface, LoadSaveInterface,
LoggingInterface, ScriptInterface, RPCInterface, AboutInfoInterface, ProcessInterface, TextureInterface
{
Q_OBJECT
Q_INTERFACES(FileInterface)
Q_INTERFACES(LoadSaveInterface)
Q_INTERFACES(LoggingInterface)
Q_INTERFACES(BaseInterface)
Q_INTERFACES(ScriptInterface)
Q_INTERFACES(RPCInterface)
Q_INTERFACES(AboutInfoInterface)
Q_INTERFACES(ProcessInterface)
Q_INTERFACES(TextureInterface)
#if QT_VERSION >= 0x050000
Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-Assimp")
#endif
signals:
void openedFile( int _id );
void addEmptyObject( DataType _type, int& _id);
void load(QString _filename, DataType _type, int& _id);
void save(int _id , QString _filename );
void log(Logtype _type, QString _message);
void log(QString _message);
void updateView();
void updatedObject(int _identifier, const UpdateType& _type);
void deleteObject( int _id );
//RPCInterface
void pluginExists( QString _pluginName , bool& _exists );
//AboutInfoInterface
void addAboutInfo(QString _text, QString _tabName );
//texture interface
void addTexture( QString _name , QImage _image , uint _dimension , int _id );
void switchTexture( QString _textureName , int _id );
void setTextureMode(QString _textureName, QString _mode, int _id );
public:
AssimpPlugin();
QString name() { return (QString("AssimpPlugin")); }
QString description( ) { return (QString(tr("Load/Save Files with the assimp library"))); }
DataType supportedType();
QString getSaveFilters();
QString getLoadFilters();
QWidget* saveOptionsWidget(QString /*_currentFilter*/);
QWidget* loadOptionsWidget(QString /*_currentFilter*/);
public slots:
/// Loads Object and converts it to a triangle mesh if possible
int loadObject(QString _filename);
/// Loads Object with given datatype
int loadObject(QString _filename, DataType _type);
bool saveObject(int _id, QString _filename);
QString version() { return QString("1.0"); }
private slots:
void fileOpened( int /*_id*/ ){}
void noguiSupported( ) {}
void initializePlugin();
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);
// void addTexture(TextureNode* _node, const QImage& img);
private:
/// converts an aiScene to a polymesh or trimesh
int convertAiSceneToOpenMesh(const aiScene* _scene, QString _objectName);
/// converts a polymesh or trimesh to an aiScene
bool convertOpenMeshToAiScene(aiScene* _scene, BaseObjectData* _object);
/// converts _mesh into _polyMesh
void convertAiMeshToPolyMesh(PolyMesh* _polyMesh, aiMesh* _mesh);
/// converts _mesh into _triMesh
void convertAiMeshToTriMesh(TriMesh* _triMesh, aiMesh* _mesh);
/// converts a polymesh to an aiMesh
bool convertPolyMeshToAiMesh(PolyMesh* _polyMesh, aiMesh* _mesh);
/// converts a trimesh to an aiMesh
bool convertTriMeshToAiMesh(TriMesh* _triMesh, aiMesh* _mesh);
/// add a vertex from _mesh to _polyMesh and stores the index to handle mapping
//void mapVertices(PolyMesh* _polyMesh, aiMesh* _mesh);
/// add a vertex from _mesh to _trimesh and stores the index to handle mapping
//void mapVertices(TriMesh* _triMesh, aiMesh* _mesh);
template<typename Mesh>
void mapVertices(Mesh* _triMesh, aiMesh* _mesh);
/// returns which postprocessing steps are enabled for the loader
//unsigned int processSteps(const std::unordered_map<QCheckBox*, unsigned int>& _options);
/// loads a material from the given aiScene to a given MaterialNode
void loadMaterial(const aiScene* _scene, MaterialNode* _matNode, unsigned int _materialIndex);
/// loads all embedded textures from a scene
void loadTexturesFromScene(const aiScene* _scene);
/// load all textures of a specific type from a material
/// this also loads textures which are not embedded, but specified by a file path
std::vector<std::pair<std::string,QImage>> loadTexturesFromMaterial(const aiMaterial* _mat, aiTextureType _textureType);
/// loads all lights from a scene
void loadLightsFromScene(const aiScene* _scene);
/// loads all cameras from a scene
void loadCamerasFromScene(const aiScene* _scene);
/// loads all animations from a scene
void loadAnimationsFromScene(const aiScene* _scene);
/// loads all meshes from a scene
void loadMeshesFromScene(const aiScene* _scene, std::vector<int> & _outIds, QString& _objectName);
private:
//Option Widgets
//QWidget *loadOptions_, *saveOptions_;
AssimpOptionsWidget *loadOptions_, *saveOptions_;
QComboBox *triMeshHandling_;
QCheckBox * loadVertexColor_ , * loadNormals_ , * loadTexCoords_ , * loadTextures_ ,
* loadLights_ , * loadCameras_ , * loadAnimations_ ;
QPushButton* loadDefaultButton_;
LoaderOptions options_;
QCheckBox* load_assimp_process_calcTangentSpace ;
QCheckBox* load_assimp_process_joinIdenticalVertices ;
QCheckBox* load_assimp_process_makeLeftHanded ;
QCheckBox* load_assimp_process_triangulate ;
QCheckBox* load_assimp_process_removeComponent ;
QCheckBox* load_assimp_process_genNormals ;
QCheckBox* load_assimp_process_genSmoothNormals ;
QCheckBox* load_assimp_process_splitLargeMeshes ;
QCheckBox* load_assimp_process_preTransformVertices ;
QCheckBox* load_assimp_process_limitBoneWeights ;
QCheckBox* load_assimp_process_validateDataStructure ;
QCheckBox* load_assimp_process_improveCacheLocality ;
QCheckBox* load_assimp_process_removeRedundantMaterials;
QCheckBox* load_assimp_process_fixInfacingNormals ;
QCheckBox* load_assimp_process_sortByPType ;
QCheckBox* load_assimp_process_findDegenerates ;
QCheckBox* load_assimp_process_findInvalidData ;
QCheckBox* load_assimp_process_genUVCoords ;
QCheckBox* load_assimp_process_transformUVCoords ;
QCheckBox* load_assimp_process_findInstances ;
QCheckBox* load_assimp_process_optimizeMeshes ;
QCheckBox* load_assimp_process_optimizeGraph ;
QCheckBox* load_assimp_process_flipUVs ;
QCheckBox* load_assimp_process_flipWindingOrder ;
QCheckBox* load_assimp_process_splitByBoneCount ;
QCheckBox* load_assimp_process_debone ;
std::unordered_map<QCheckBox*, unsigned int> loadOptions;
unsigned int processSteps;
QCheckBox* saveVertexColor_;
QCheckBox* saveFaceColor_;
QCheckBox* saveAlpha_;
QCheckBox* saveNormals_;
QCheckBox* saveTexCoords_;
QCheckBox* saveTextures_;
QPushButton* saveDefaultButton_;
QCheckBox* save_assimp_process_calcTangentSpace ;
QCheckBox* save_assimp_process_joinIdenticalVertices ;
QCheckBox* save_assimp_process_makeLeftHanded ;
QCheckBox* save_assimp_process_triangulate ;
QCheckBox* save_assimp_process_removeComponent ;
QCheckBox* save_assimp_process_genNormals ;
QCheckBox* save_assimp_process_genSmoothNormals ;
QCheckBox* save_assimp_process_splitLargeMeshes ;
QCheckBox* save_assimp_process_preTransformVertices ;
QCheckBox* save_assimp_process_limitBoneWeights ;
QCheckBox* save_assimp_process_validateDataStructure ;
QCheckBox* save_assimp_process_improveCacheLocality ;
QCheckBox* save_assimp_process_removeRedundantMaterials;
QCheckBox* save_assimp_process_fixInfacingNormals ;
QCheckBox* save_assimp_process_sortByPType ;
QCheckBox* save_assimp_process_findDegenerates ;
QCheckBox* save_assimp_process_findInvalidData ;
QCheckBox* save_assimp_process_genUVCoords ;
QCheckBox* save_assimp_process_transformUVCoords ;
QCheckBox* save_assimp_process_findInstances ;
QCheckBox* save_assimp_process_optimizeMeshes ;
QCheckBox* save_assimp_process_optimizeGraph ;
QCheckBox* save_assimp_process_flipUVs ;
QCheckBox* save_assimp_process_flipWindingOrder ;
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
std::map<unsigned int, OpenMesh::VertexHandle> vertexHandles_;
/// cancels loading
bool cancel_;
/// a list of images, that was loaded by material type
std::unordered_map<unsigned int, std::vector<std::pair<std::string, QImage>>> loadedImages_;
std::vector<std::pair<std::string, QImage>> embeddedTextures_;
};
#include "AssimpPluginT.cc"
#endif // ASSIMPPLUGIN_HH
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (c) 2001-2015, RWTH-Aachen University *
* Department of Computer Graphics and Multimedia *
* All rights reserved. *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
*---------------------------------------------------------------------------*
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* *
* 2. 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. *
* *
* 3. Neither the name of the copyright holder nor the names of its *
* contributors may be used to endorse or promote products derived from *
* this software without specific prior written permission. *
* *
* 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 HOLDER *
* 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 THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* *
\*===========================================================================*/
#pragma once
// Defines for the type handling drop down box
#define TYPEAUTODETECT 0
#define TYPEASK 1
#define TYPEPOLY 2
#define TYPETRIANGLE 3
struct LoaderOptions
{
unsigned int triMeshHandling_;
bool loadVertexColorOption_ , loadNormalsOption_ , loadTexCoordsOption_ , loadTexturesOption_,
loadLightsOption_ , loadCamerasOption_ , loadAnimationsOption_;
LoaderOptions() : triMeshHandling_ (TYPEAUTODETECT) , loadVertexColorOption_(false) , loadNormalsOption_(false) ,
loadTexCoordsOption_(false) , loadTexturesOption_ (false) , loadLightsOption_ (false) ,
loadCamerasOption_ (false) , loadAnimationsOption_ (false)
{}
};
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (c) 2001-2015, RWTH-Aachen University *
* Department of Computer Graphics and Multimedia *
* All rights reserved. *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
*---------------------------------------------------------------------------*
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* *
* 2. 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. *
* *
* 3. Neither the name of the copyright holder nor the names of its *
* contributors may be used to endorse or promote products derived from *
* this software without specific prior written permission. *
* *
* 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 HOLDER *
* 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 THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* *
\*===========================================================================*/
#pragma once
template <typename Mesh>
void AssimpPlugin::mapVertices(Mesh *_polyMesh, aiMesh *_mesh) {
vertexHandles_.clear();
std::cout<<"mesh has "<<_mesh->GetNumColorChannels()<<" color channels"<<std::endl;
bool tc1requested = false;
bool tc2requested = false;
bool tc3requested = false;
//
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));
//load vertexColors
for(unsigned int j = 0 ; j < _mesh->GetNumColorChannels(); ++j)
{
if(options_.loadVertexColorOption_ && _mesh->HasVertexColors(j))
_polyMesh->set_color(vertexHandles_[i], PolyMesh::Color(_mesh->mColors[j][i].r, _mesh->mColors[j][i].g, _mesh->mColors[j][i].b, _mesh->mColors[j][i].a));
}
//load texCoords
for(unsigned int j = 0 ; j < _mesh->GetNumUVChannels(); ++j)
{
if(options_.loadTexCoordsOption_ && _mesh->HasTextureCoords(j))
{
if(_mesh->mNumUVComponents[j] == 1)
{
if(!tc1requested)
{
_polyMesh->request_vertex_texcoords1D();
tc1requested = true;
}
_polyMesh->set_texcoord1D(vertexHandles_[i], PolyMesh::TexCoord1D(_mesh->mTextureCoords[j][i].x));
}
if(_mesh->mNumUVComponents[j] == 2)
{
if(!tc2requested)
{
_polyMesh->request_vertex_texcoords2D();
tc2requested = true;
}
_polyMesh->set_texcoord2D(vertexHandles_[i], PolyMesh::TexCoord2D(_mesh->mTextureCoords[j][i].x, _mesh->mTextureCoords[j][i].y));
}
if(_mesh->mNumUVComponents[j] == 3)
{
if(!tc3requested)
{
_polyMesh->request_vertex_texcoords3D();
tc3requested = true;
}
_polyMesh->set_texcoord3D(vertexHandles_[i], PolyMesh::TexCoord3D(_mesh->mTextureCoords[j][i].x, _mesh->mTextureCoords[j][i].y, _mesh->mTextureCoords[j][i].z));
}
}
}
}
}
include(plugin)
openflipper_plugin(DIRS widgets
DEPS ASSIMP
TYPES POLYMESH TRIANGLEMESH
OPT_TYPES LIGHT CAMERA SKELETON)
if(NOT ${ASSIMP_LIBRARY} STREQUAL "ASSIMP_LIBRARY-NOTFOUND")
# Include Testing package
if(BUILD_TESTING)
include( ${CMAKE_SOURCE_DIR}/OpenFlipper/tests/testGenerators.cmake )
# ========================================================================
# ========================================================================
# Tests
# ========================================================================
# ========================================================================
run_single_object_file_mesh_test("assimpplugin" "Plugin-Assimp/cube.xgl" "fileMeshTest.ofs")
run_single_object_file_mesh_test("assimpplugin" "Plugin-Assimp/cube.dae" "fileMeshTest.ofs")
endif()
endif()
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (c) 2001-2015, RWTH-Aachen University *
* Department of Computer Graphics and Multimedia *
* All rights reserved. *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
*---------------------------------------------------------------------------*
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* *
* 2. 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. *
* *
* 3. Neither the name of the copyright holder nor the names of its *
* contributors may be used to endorse or promote products derived from *
* this software without specific prior written permission. *
* *
* 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 HOLDER *
* 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 THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* *
\*===========================================================================*/
#include "AssimpLoadOptionsWidget.hh"
#include <assimp/postprocess.h>
#include <OpenFlipper/common/GlobalOptions.hh>
#include "../AssimpPluginCommon.hh"
AssimpLoadOptionsWidget::AssimpLoadOptionsWidget(LoaderOptions & loader, QWidget * parent )
: AssimpOptionsWidget ("Load", loader, parent)
{
// 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") );
loadVertexColor_ = new QCheckBox("Load Vertex Colors");
loadNormals_ = new QCheckBox("Load Vertex Normals");
loadTexCoords_ = new QCheckBox("Load Vertex Texture Coordinates");
loadTextures_ = new QCheckBox("Load Textures");
loadLights_ = new QCheckBox("Load Lights");
loadCameras_ = new QCheckBox("Load Cameras");
loadAnimations_ = new QCheckBox("Load Animations");
#ifndef ENABLE_LIGHT_SUPPORT
loadLights_->setEnabled(false);
#endif
#ifndef ENABLE_CAMERA_SUPPORT
loadCameras_->setEnabled(false);
#endif
#ifndef ENABLE_SKELETON_SUPPORT
loadAnimations_->setEnabled(false);
#endif