From 8abcc454ada68ff96f4c373cf1bd64403470021a Mon Sep 17 00:00:00 2001 From: smalcom Date: Mon, 21 May 2018 17:38:01 +0300 Subject: [PATCH 01/14] [F] Uninitialized variables. --- code/D3MFExporter.cpp | 2 +- test/unit/utMetadata.cpp | 2 +- test/unit/utSharedPPData.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/code/D3MFExporter.cpp b/code/D3MFExporter.cpp index 204e6f77b..99e2ff3f5 100644 --- a/code/D3MFExporter.cpp +++ b/code/D3MFExporter.cpp @@ -222,7 +222,7 @@ void D3MFExporter::writeMetaData() { return; } - const aiString *key; + const aiString *key = nullptr; const aiMetadataEntry *entry(nullptr); for ( size_t i = 0; i < numMetaEntries; ++i ) { mScene->mMetaData->Get( i, key, entry ); diff --git a/test/unit/utMetadata.cpp b/test/unit/utMetadata.cpp index 0801ffd3f..c2cd6e1ef 100644 --- a/test/unit/utMetadata.cpp +++ b/test/unit/utMetadata.cpp @@ -210,7 +210,7 @@ TEST_F( utMetadata, copy_test ) { // int32_t test { - int32_t v; + int32_t v = 0; bool ok = copy.Get( "int32", v ); EXPECT_TRUE( ok ); EXPECT_EQ( i32v, v ); diff --git a/test/unit/utSharedPPData.cpp b/test/unit/utSharedPPData.cpp index a7c3043a5..94f2a5678 100644 --- a/test/unit/utSharedPPData.cpp +++ b/test/unit/utSharedPPData.cpp @@ -78,7 +78,7 @@ TEST_F(SharedPPDataTest, testPODProperty) { int i = 5; shared->AddProperty("test",i); - int o; + int o = 0; EXPECT_TRUE(shared->GetProperty("test",o)); EXPECT_EQ(5, o); EXPECT_FALSE(shared->GetProperty("test2",o)); From 348b34a2de53e14be058f2beadf5d2c506c02104 Mon Sep 17 00:00:00 2001 From: smalcom Date: Mon, 21 May 2018 17:38:43 +0300 Subject: [PATCH 02/14] [F] Wrong type in equation. --- tools/assimp_qt_viewer/mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/assimp_qt_viewer/mainwindow.cpp b/tools/assimp_qt_viewer/mainwindow.cpp index d7d809086..ae68a2234 100644 --- a/tools/assimp_qt_viewer/mainwindow.cpp +++ b/tools/assimp_qt_viewer/mainwindow.cpp @@ -301,7 +301,7 @@ QMap exportersMap; return; } - for (int i = 0; i < exporter.GetExportFormatCount(); ++i) + for (size_t i = 0; i < exporter.GetExportFormatCount(); ++i) { const aiExportFormatDesc* desc = exporter.GetExportFormatDescription(i); exportersList.push_back(desc->id + QString(": ") + desc->description); From 0c07397720bc722cba1af6bf379e72a62b1fb77c Mon Sep 17 00:00:00 2001 From: gstanlo Date: Tue, 22 May 2018 17:32:12 -0700 Subject: [PATCH 03/14] glTF/2.0: Pick scene zero as scene to recursively load if no "scene" property is specified. --- code/glTF2Asset.inl | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/code/glTF2Asset.inl b/code/glTF2Asset.inl index acf8cb331..5aa658f61 100644 --- a/code/glTF2Asset.inl +++ b/code/glTF2Asset.inl @@ -1216,12 +1216,15 @@ inline void Asset::Load(const std::string& pFile, bool isBinary) // Read the "scene" property, which specifies which scene to load // and recursively load everything referenced by it + unsigned int sceneIndex = 0; if (Value* scene = FindUInt(doc, "scene")) { - unsigned int sceneIndex = scene->GetUint(); + sceneIndex = scene->GetUint(); + } - Ref s = scenes.Retrieve(sceneIndex); - - this->scene = s; + if (Value* scenesArray = FindArray(doc, "scenes")) { + if (sceneIndex < scenesArray->Size()) { + this->scene = scenes.Retrieve(sceneIndex); + } } // Clean up From e201fcf4f43e0fe929aaddb10dce907fed59d839 Mon Sep 17 00:00:00 2001 From: smalcom Date: Thu, 24 May 2018 12:25:27 +0300 Subject: [PATCH 04/14] [-] Function "GetExtension" always return lowercase string. Using uppercase extension in desc is not needed. --- code/3DSLoader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/3DSLoader.cpp b/code/3DSLoader.cpp index 3c95d8193..cd79b0a6d 100644 --- a/code/3DSLoader.cpp +++ b/code/3DSLoader.cpp @@ -71,7 +71,7 @@ static const aiImporterDesc desc = { 0, 0, 0, - "3ds prj 3DS PRJ" + "3ds prj" }; @@ -127,7 +127,7 @@ Discreet3DSImporter::~Discreet3DSImporter() { // Returns whether the class can handle the format of the given file. bool Discreet3DSImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const { std::string extension = GetExtension(pFile); - if(extension == "3ds" || extension == "3DS" || extension == "prj"|| extension == "PRJ" ) { + if(extension == "3ds" || extension == "prj") { return true; } From 6093769da1d62fe115b633d6b5ce9f1eacf954a0 Mon Sep 17 00:00:00 2001 From: smalcom Date: Thu, 24 May 2018 12:31:49 +0300 Subject: [PATCH 05/14] [*] Refactoring of "draw axes" procedure. [-] Removed not working part of code for reloading textures. That do nothing, just show checkbox. As Yoda said: "Do. Or do not. There is no try." --- tools/assimp_qt_viewer/glview.cpp | 39 ++++++--------------------- tools/assimp_qt_viewer/glview.hpp | 16 +++++------ tools/assimp_qt_viewer/mainwindow.cpp | 15 +---------- tools/assimp_qt_viewer/mainwindow.hpp | 2 -- 4 files changed, 17 insertions(+), 55 deletions(-) diff --git a/tools/assimp_qt_viewer/glview.cpp b/tools/assimp_qt_viewer/glview.cpp index a9a60a6fc..c52ac34e3 100644 --- a/tools/assimp_qt_viewer/glview.cpp +++ b/tools/assimp_qt_viewer/glview.cpp @@ -560,30 +560,6 @@ void CGLView::Enable_Textures(const bool pEnable) } } -void CGLView::Enable_Axes(const bool pEnable){ - if(pEnable) - { - this->mAxesEnabled = true; - } - else - { - this->mAxesEnabled = false; - } -} - -void CGLView::Enable_Reload_Textures(const bool pEnable) -{ - if(pEnable) - { - this->mReloadTexturesEnabled = true; -// this->mScene->ImportTextures(this->mScene->pScenePath); - } - else - { - this->mReloadTexturesEnabled = false; - } -} - /********************************************************************/ /*********************** Override functions ************************/ /********************************************************************/ @@ -619,7 +595,11 @@ void CGLView::resizeGL(int pWidth, int pHeight) } void CGLView::drawCoordSystem() { - glBindTexture(GL_TEXTURE_1D, 0); + // Disable lighting. Colors must be bright and colorful) + if ( mLightingEnabled ) glDisable( GL_LIGHTING );///TODO: display list + + // For same reason - disable textures. + glBindTexture(GL_TEXTURE_1D, 0); glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_3D, 0); glEnable(GL_COLOR_MATERIAL); @@ -635,6 +615,8 @@ void CGLView::drawCoordSystem() { qglColor(QColor(Qt::yellow)), glVertex3f(0.0, 0.0, 0.0), glVertex3f(0.0, 0.0, -100000.0); qglColor(QColor(Qt::white)); glEnd(); + // Restore previous state of lighting. + if(mLightingEnabled) glEnable(GL_LIGHTING); } void CGLView::paintGL() @@ -651,17 +633,12 @@ void CGLView::paintGL() glTranslatef(-mHelper_Camera.Translation_ToScene.x, -mHelper_Camera.Translation_ToScene.y, -mHelper_Camera.Translation_ToScene.z); glMultMatrixf((GLfloat*)&mHelper_Camera.Rotation_Scene); // Coordinate system - if ( mLightingEnabled ) { - glDisable( GL_LIGHTING );///TODO: display list - } - if (this->mAxesEnabled == true) + if (mScene_AxesEnabled == true) { drawCoordSystem(); } glDisable(GL_COLOR_MATERIAL); - if(mLightingEnabled) glEnable(GL_LIGHTING); - // Scene if(mScene != nullptr) { diff --git a/tools/assimp_qt_viewer/glview.hpp b/tools/assimp_qt_viewer/glview.hpp index 1c397f13f..3bfb8fa08 100644 --- a/tools/assimp_qt_viewer/glview.hpp +++ b/tools/assimp_qt_viewer/glview.hpp @@ -75,9 +75,7 @@ private: }; public: - bool mAxesEnabled = true; - // Textures - bool mReloadTexturesEnabled = false; // If true then textures will reload when the window is activated. + /// \enum ELightType /// Type of light source. enum class ELightType { Directional, Point, Spot }; @@ -146,6 +144,7 @@ private: SBBox mScene_BBox;///< Bounding box of scene. aiVector3D mScene_Center;///< Coordinates of center of the scene. bool mScene_DrawBBox = false;///< Flag which control drawing scene BBox. + bool mScene_AxesEnabled = true;///< Flag which control drawing axes of the coordinate system. // Meshes size_t mHelper_Mesh_Quantity = 0;///< Quantity of meshes in scene. SHelper_Mesh** mHelper_Mesh = nullptr;///< Array of pointers to helper objects for drawing mesh. Sequence of meshes are equivalent to \ref aiScene::mMeshes. @@ -254,7 +253,11 @@ private: /********************************************************************/ protected: + + /// \fn void drawCoordSystem() + /// Draw axes of the coordinate system. void drawCoordSystem(); + /// \fn void initializeGL() override /// Override function to initialise OpenGL. void initializeGL() override; @@ -307,11 +310,8 @@ public: /// \param [in] pEnable - if true then enable textures, false - disable textures. void Enable_Textures(const bool pEnable); - void Enable_Axes(const bool pEnable); - /// \fn void Enable_Textures(const bool pEnable) - /// Control textures drawing. - /// \param [in] pEnable - if true then enable textures, false - disable textures. - void Enable_Reload_Textures(const bool pEnable); + ///TODO: doc + void Enable_Axes(const bool pEnable) { this->mScene_AxesEnabled = pEnable; } /********************************************************************/ /******************** Lighting control functions ********************/ diff --git a/tools/assimp_qt_viewer/mainwindow.cpp b/tools/assimp_qt_viewer/mainwindow.cpp index ae68a2234..cd52230f3 100644 --- a/tools/assimp_qt_viewer/mainwindow.cpp +++ b/tools/assimp_qt_viewer/mainwindow.cpp @@ -48,7 +48,7 @@ QTime time_begin = QTime::currentTime(); ui->cbxLighting->setChecked(true); mGLView->Lighting_Enable(); ui->cbxBBox->setChecked(false); mGLView->Enable_SceneBBox(false); ui->cbxTextures->setChecked(true); mGLView->Enable_Textures(true); - ui->cbxReloadTextures->setChecked(true); mGLView->Enable_Reload_Textures(false); + // // Fill info labels // @@ -195,13 +195,6 @@ GLfloat step; /********************************************************************/ /********************** Constructor/Destructor **********************/ /********************************************************************/ -bool MainWindow::event(QEvent *e) -{ - if (e->type() == QEvent::WindowActivate && this->mGLView->mReloadTexturesEnabled == true) { - qInfo() << "Window Activated"; - } - return QWidget::event(e); -} MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), @@ -378,12 +371,6 @@ void MainWindow::on_cbxDrawAxes_clicked(bool checked) mGLView->updateGL(); } -void MainWindow::on_cbxReloadTextures_clicked(bool checked) -{ - mGLView->Enable_Reload_Textures(checked); - mGLView->updateGL(); -} - void MainWindow::on_cbxTextures_clicked(bool checked) { mGLView->Enable_Textures(checked); diff --git a/tools/assimp_qt_viewer/mainwindow.hpp b/tools/assimp_qt_viewer/mainwindow.hpp index da8a852ac..14e870f51 100644 --- a/tools/assimp_qt_viewer/mainwindow.hpp +++ b/tools/assimp_qt_viewer/mainwindow.hpp @@ -90,7 +90,6 @@ protected: /// \param [in] pEvent - pointer to event data. void keyPressEvent(QKeyEvent* pEvent) override; - bool event(QEvent*); public: /********************************************************************/ @@ -134,5 +133,4 @@ private slots: void on_cbxBBox_clicked(bool checked); void on_cbxTextures_clicked(bool checked); void on_cbxDrawAxes_clicked(bool checked); - void on_cbxReloadTextures_clicked(bool checked); }; From c23f99919673331bb578846c25068568ae86bc86 Mon Sep 17 00:00:00 2001 From: smalcom Date: Thu, 24 May 2018 12:34:18 +0300 Subject: [PATCH 06/14] [+] QtCreator temporary file. --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index f8dda3e8b..60884061d 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,8 @@ build bin/ lib/ +# QtCreator +CMakeLists.txt.user # Generated assimp.pc From f56432f713f9cfa99210db2f050ea850b51be74e Mon Sep 17 00:00:00 2001 From: smalcom Date: Thu, 24 May 2018 13:04:39 +0300 Subject: [PATCH 07/14] [F] One alignment for labels. [-] Unused checkbox. --- tools/assimp_qt_viewer/mainwindow.ui | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/tools/assimp_qt_viewer/mainwindow.ui b/tools/assimp_qt_viewer/mainwindow.ui index 9b139bafd..04208f585 100644 --- a/tools/assimp_qt_viewer/mainwindow.ui +++ b/tools/assimp_qt_viewer/mainwindow.ui @@ -302,6 +302,9 @@ + + Qt::AlignCenter + @@ -312,6 +315,9 @@ + + Qt::AlignCenter + @@ -325,6 +331,9 @@ + + Qt::AlignCenter + @@ -335,6 +344,9 @@ + + Qt::AlignCenter + @@ -349,6 +361,9 @@ + + Qt::AlignCenter + @@ -511,13 +526,6 @@ - - - - Live Reload Textures - - - From fd7f07068c2f173037e2f606f7308421ff6dc5fe Mon Sep 17 00:00:00 2001 From: smalcom Date: Thu, 24 May 2018 13:05:50 +0300 Subject: [PATCH 08/14] [F] React on mouse pressing ig view only. --- tools/assimp_qt_viewer/mainwindow.cpp | 64 ++++++++++++++++----------- tools/assimp_qt_viewer/mainwindow.hpp | 1 + 2 files changed, 40 insertions(+), 25 deletions(-) diff --git a/tools/assimp_qt_viewer/mainwindow.cpp b/tools/assimp_qt_viewer/mainwindow.cpp index cd52230f3..2d87005a0 100644 --- a/tools/assimp_qt_viewer/mainwindow.cpp +++ b/tools/assimp_qt_viewer/mainwindow.cpp @@ -128,40 +128,54 @@ void MainWindow::LogError(const QString& pMessage) void MainWindow::mousePressEvent(QMouseEvent* pEvent) { - if(pEvent->button() & Qt::LeftButton) - mPosition_Pressed_LMB = pEvent->pos(); - else if(pEvent->button() & Qt::RightButton) - mPosition_Pressed_RMB = pEvent->pos(); +const QPoint ms_pt = pEvent->pos(); + + // Check if GLView is pointed. + if(childAt(ms_pt) == mGLView) + { + mPosition_Pressed_Valid = true; + if(pEvent->button() & Qt::LeftButton) + mPosition_Pressed_LMB = ms_pt; + else if(pEvent->button() & Qt::RightButton) + mPosition_Pressed_RMB = ms_pt; + } + else + { + mPosition_Pressed_Valid = false; + } } void MainWindow::mouseMoveEvent(QMouseEvent* pEvent) { - if(pEvent->buttons() & Qt::LeftButton) + if(mPosition_Pressed_Valid) { - GLfloat dx = 180 * GLfloat(pEvent->x() - mPosition_Pressed_LMB.x()) / mGLView->width(); - GLfloat dy = 180 * GLfloat(pEvent->y() - mPosition_Pressed_LMB.y()) / mGLView->height(); + if(pEvent->buttons() & Qt::LeftButton) + { + GLfloat dx = 180 * GLfloat(pEvent->x() - mPosition_Pressed_LMB.x()) / mGLView->width(); + GLfloat dy = 180 * GLfloat(pEvent->y() - mPosition_Pressed_LMB.y()) / mGLView->height(); - if(pEvent->modifiers() & Qt::ShiftModifier) - mGLView->Camera_RotateScene(dy, 0, dx);// Rotate around oX and oZ axises. - else - mGLView->Camera_RotateScene(dy, dx, 0);// Rotate around oX and oY axises. + if(pEvent->modifiers() & Qt::ShiftModifier) + mGLView->Camera_RotateScene(dy, 0, dx);// Rotate around oX and oZ axises. + else + mGLView->Camera_RotateScene(dy, dx, 0);// Rotate around oX and oY axises. - mGLView->updateGL(); - mPosition_Pressed_LMB = pEvent->pos(); - } + mGLView->updateGL(); + mPosition_Pressed_LMB = pEvent->pos(); + } - if(pEvent->buttons() & Qt::RightButton) - { - GLfloat dx = 180 * GLfloat(pEvent->x() - mPosition_Pressed_RMB.x()) / mGLView->width(); - GLfloat dy = 180 * GLfloat(pEvent->y() - mPosition_Pressed_RMB.y()) / mGLView->height(); + if(pEvent->buttons() & Qt::RightButton) + { + GLfloat dx = 180 * GLfloat(pEvent->x() - mPosition_Pressed_RMB.x()) / mGLView->width(); + GLfloat dy = 180 * GLfloat(pEvent->y() - mPosition_Pressed_RMB.y()) / mGLView->height(); - if(pEvent->modifiers() & Qt::ShiftModifier) - mGLView->Camera_Rotate(dy, 0, dx);// Rotate around oX and oZ axises. - else - mGLView->Camera_Rotate(dy, dx, 0);// Rotate around oX and oY axises. + if(pEvent->modifiers() & Qt::ShiftModifier) + mGLView->Camera_Rotate(dy, 0, dx);// Rotate around oX and oZ axises. + else + mGLView->Camera_Rotate(dy, dx, 0);// Rotate around oX and oY axises. - mGLView->updateGL(); - mPosition_Pressed_RMB = pEvent->pos(); + mGLView->updateGL(); + mPosition_Pressed_RMB = pEvent->pos(); + } } } @@ -198,7 +212,7 @@ GLfloat step; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), - mScene(nullptr) + mScene(nullptr), mPosition_Pressed_Valid(false) { using namespace Assimp; diff --git a/tools/assimp_qt_viewer/mainwindow.hpp b/tools/assimp_qt_viewer/mainwindow.hpp index 14e870f51..fc31599b7 100644 --- a/tools/assimp_qt_viewer/mainwindow.hpp +++ b/tools/assimp_qt_viewer/mainwindow.hpp @@ -36,6 +36,7 @@ private: CLoggerView* mLoggerView;///< Pointer to logging object. Assimp::Importer mImporter;///< Assimp importer. const aiScene* mScene;///< Pointer to loaded scene (\ref aiScene). + bool mPosition_Pressed_Valid;///< Mouse button pressed on GLView. QPoint mPosition_Pressed_LMB;///< Position where was pressed left mouse button. QPoint mPosition_Pressed_RMB;///< Position where was pressed right mouse button. From f59ab5c34f2e464ac247b5185f705959a6e20d42 Mon Sep 17 00:00:00 2001 From: smalcom Date: Thu, 24 May 2018 17:11:21 +0300 Subject: [PATCH 09/14] [F] More correct control by a mouse --- tools/assimp_qt_viewer/glview.cpp | 21 +++++++++--- tools/assimp_qt_viewer/glview.hpp | 23 ++++++++++--- tools/assimp_qt_viewer/mainwindow.cpp | 47 ++++++++++++++++++--------- tools/assimp_qt_viewer/mainwindow.hpp | 19 +++++++++-- 4 files changed, 82 insertions(+), 28 deletions(-) diff --git a/tools/assimp_qt_viewer/glview.cpp b/tools/assimp_qt_viewer/glview.cpp index c52ac34e3..833400c46 100644 --- a/tools/assimp_qt_viewer/glview.cpp +++ b/tools/assimp_qt_viewer/glview.cpp @@ -1073,24 +1073,30 @@ void CGLView::Camera_Set(const size_t pCameraNumber) gluLookAt(hcam.Position.x, hcam.Position.y, hcam.Position.z, hcam.Target.x, hcam.Target.y, hcam.Target.z, up.x, up.y, up.z); } -void CGLView::Camera_RotateScene(const GLfloat pAngle_X, const GLfloat pAngle_Y, const GLfloat pAngle_Z) +void CGLView::Camera_RotateScene(const GLfloat pAngle_X, const GLfloat pAngle_Y, const GLfloat pAngle_Z, const aiMatrix4x4* pMatrix_Rotation_Initial) { auto deg2rad = [](const GLfloat pDegree) -> GLfloat { return pDegree * M_PI / 180.0; }; aiMatrix4x4 mat_rot; mat_rot.FromEulerAnglesXYZ(deg2rad(pAngle_X), deg2rad(pAngle_Y), deg2rad(pAngle_Z)); - mHelper_Camera.Rotation_Scene *= mat_rot; + if(pMatrix_Rotation_Initial != nullptr) + mHelper_Camera.Rotation_Scene = *pMatrix_Rotation_Initial * mat_rot; + else + mHelper_Camera.Rotation_Scene *= mat_rot; } -void CGLView::Camera_Rotate(const GLfloat pAngle_X, const GLfloat pAngle_Y, const GLfloat pAngle_Z) +void CGLView::Camera_Rotate(const GLfloat pAngle_X, const GLfloat pAngle_Y, const GLfloat pAngle_Z, const aiMatrix4x4* pMatrix_Rotation_Initial) { auto deg2rad = [](const GLfloat pDegree) -> GLfloat { return pDegree * M_PI / 180.0; }; aiMatrix4x4 mat_rot; mat_rot.FromEulerAnglesXYZ(deg2rad(pAngle_X), deg2rad(pAngle_Y), deg2rad(pAngle_Z)); - mHelper_Camera.Rotation_AroundCamera *= mat_rot; + if(pMatrix_Rotation_Initial != nullptr) + mHelper_Camera.Rotation_AroundCamera = *pMatrix_Rotation_Initial * mat_rot; + else + mHelper_Camera.Rotation_AroundCamera *= mat_rot; } void CGLView::Camera_Translate(const GLfloat pTranslate_X, const GLfloat pTranslate_Y, const GLfloat pTranslate_Z) @@ -1100,3 +1106,10 @@ aiVector3D vect_tr(pTranslate_X, pTranslate_Y, pTranslate_Z); vect_tr *= mHelper_Camera.Rotation_AroundCamera; mHelper_Camera.Translation_ToScene += vect_tr; } + +void CGLView::Camera_Matrix(aiMatrix4x4& pRotation_Camera, aiMatrix4x4& pRotation_Scene, aiVector3D& pTranslation_Camera) +{ + pRotation_Camera = mHelper_Camera.Rotation_AroundCamera; + pRotation_Scene = mHelper_Camera.Rotation_Scene; + pTranslation_Camera = mHelper_Camera.Translation_ToScene; +} diff --git a/tools/assimp_qt_viewer/glview.hpp b/tools/assimp_qt_viewer/glview.hpp index 3bfb8fa08..2d8614e21 100644 --- a/tools/assimp_qt_viewer/glview.hpp +++ b/tools/assimp_qt_viewer/glview.hpp @@ -310,7 +310,9 @@ public: /// \param [in] pEnable - if true then enable textures, false - disable textures. void Enable_Textures(const bool pEnable); - ///TODO: doc + /// \fn void Enable_Axes(const bool pEnable) + /// Control axes drawing. + /// \param [in] pEnable - if true then enable axes, false - disable axes. void Enable_Axes(const bool pEnable) { this->mScene_AxesEnabled = pEnable; } /********************************************************************/ @@ -350,19 +352,23 @@ public: /// \param [in] pCamera_Index - index of the camera (\ref aiScene::mCameras). void Camera_Set(const size_t pCameraNumber); - /// \fn void Camera_RotateScene(const GLfloat pAngle_X, const GLfloat pAngle_Y, const GLfloat pAngle_Z) + /// \fn void Camera_RotateScene(const GLfloat pAngle_X, const GLfloat pAngle_Y, const GLfloat pAngle_Z, const aiMatrix4x4* pMatrix_Rotation_Initial) /// Rotate scene around axisees. /// \param [in] pAngle_X - specifies the angle of rotation around axis oX, in degrees. /// \param [in] pAngle_Y - specifies the angle of rotation around axis oY, in degrees. /// \param [in] pAngle_Z - specifies the angle of rotation around axis oZ, in degrees. - void Camera_RotateScene(const GLfloat pAngle_X, const GLfloat pAngle_Y, const GLfloat pAngle_Z); + /// \param [in] pMatrix_Rotation_Initial - matrix from which calculates new transformation matrix. If not set (equal to nullptr) then current transformation matrix + /// will be used. + void Camera_RotateScene(const GLfloat pAngle_X, const GLfloat pAngle_Y, const GLfloat pAngle_Z, const aiMatrix4x4* pMatrix_Rotation_Initial = nullptr); - /// \fn void Camera_Rotate(const GLfloat pAngle_X, const GLfloat pAngle_Y, const GLfloat pAngle_Z) + /// \fn void Camera_Rotate(const GLfloat pAngle_X, const GLfloat pAngle_Y, const GLfloat pAngle_Z, const aiMatrix4x4* pMatrix_Rotation_Initial = nullptr) /// Rotate camera around axisees. /// \param [in] pAngle_X - specifies the angle of rotation around axis oX, in degrees. /// \param [in] pAngle_Y - specifies the angle of rotation around axis oY, in degrees. /// \param [in] pAngle_Z - specifies the angle of rotation around axis oZ, in degrees. - void Camera_Rotate(const GLfloat pAngle_X, const GLfloat pAngle_Y, const GLfloat pAngle_Z); + /// \param [in] pMatrix_Rotation_Initial - matrix from which calculates new transformation matrix. If not set (equal to nullptr) then current transformation matrix + /// will be used. + void Camera_Rotate(const GLfloat pAngle_X, const GLfloat pAngle_Y, const GLfloat pAngle_Z, const aiMatrix4x4* pMatrix_Rotation_Initial = nullptr); /// \fn void Camera_Translate(const size_t pTranslate_X, const size_t pTranslate_Y, const size_t pTranslate_Z) /// Translate camera along axises. In local coordinates. @@ -371,6 +377,13 @@ public: /// \param [in] pTranslate_Z - specifies the Z coordinate of translation vector. void Camera_Translate(const GLfloat pTranslate_X, const GLfloat pTranslate_Y, const GLfloat pTranslate_Z); + /// \fn void Camera_Matrix(aiMatrix4x4& pRotation_Camera, aiMatrix4x4& pRotation_Scene, aiVector3D& pTranslation_Camera) + /// Return data about camera position in world. + /// \param [out] pRotation_Camera - rotation matrix which set rotation angles of the scene around camera. + /// \param [out] pRotation_Scene - rotation matrix which set rotation angles of the scene around own center. + /// \param [out] pTranslation_Camera - translation vector from camera to the scene. + void Camera_Matrix(aiMatrix4x4& pRotation_Camera, aiMatrix4x4& pRotation_Scene, aiVector3D& pTranslation_Camera); + signals: /// \fn void Paint_Finished(const size_t pPaintTime, const GLfloat pDistance) diff --git a/tools/assimp_qt_viewer/mainwindow.cpp b/tools/assimp_qt_viewer/mainwindow.cpp index 2d87005a0..c17188472 100644 --- a/tools/assimp_qt_viewer/mainwindow.cpp +++ b/tools/assimp_qt_viewer/mainwindow.cpp @@ -130,51 +130,63 @@ void MainWindow::mousePressEvent(QMouseEvent* pEvent) { const QPoint ms_pt = pEvent->pos(); +__unused aiVector3D temp_v3; + // Check if GLView is pointed. if(childAt(ms_pt) == mGLView) { - mPosition_Pressed_Valid = true; + if(!mMouse_Transformation.Position_Pressed_Valid) + { + mMouse_Transformation.Position_Pressed_Valid = true;// set flag + // Store current transformation matrices. + mGLView->Camera_Matrix(mMouse_Transformation.Rotation_AroundCamera, mMouse_Transformation.Rotation_Scene, temp_v3); + } + if(pEvent->button() & Qt::LeftButton) - mPosition_Pressed_LMB = ms_pt; + mMouse_Transformation.Position_Pressed_LMB = ms_pt; else if(pEvent->button() & Qt::RightButton) - mPosition_Pressed_RMB = ms_pt; + mMouse_Transformation.Position_Pressed_RMB = ms_pt; } else { - mPosition_Pressed_Valid = false; + mMouse_Transformation.Position_Pressed_Valid = false; } } +void MainWindow::mouseReleaseEvent(QMouseEvent *pEvent) +{ + if(pEvent->buttons() == 0) mMouse_Transformation.Position_Pressed_Valid = false; + +} + void MainWindow::mouseMoveEvent(QMouseEvent* pEvent) { - if(mPosition_Pressed_Valid) + if(mMouse_Transformation.Position_Pressed_Valid) { if(pEvent->buttons() & Qt::LeftButton) { - GLfloat dx = 180 * GLfloat(pEvent->x() - mPosition_Pressed_LMB.x()) / mGLView->width(); - GLfloat dy = 180 * GLfloat(pEvent->y() - mPosition_Pressed_LMB.y()) / mGLView->height(); + GLfloat dx = 180 * GLfloat(pEvent->x() - mMouse_Transformation.Position_Pressed_LMB.x()) / mGLView->width(); + GLfloat dy = 180 * GLfloat(pEvent->y() - mMouse_Transformation.Position_Pressed_LMB.y()) / mGLView->height(); if(pEvent->modifiers() & Qt::ShiftModifier) - mGLView->Camera_RotateScene(dy, 0, dx);// Rotate around oX and oZ axises. + mGLView->Camera_RotateScene(dy, 0, dx, &mMouse_Transformation.Rotation_Scene);// Rotate around oX and oZ axises. else - mGLView->Camera_RotateScene(dy, dx, 0);// Rotate around oX and oY axises. + mGLView->Camera_RotateScene(dy, dx, 0, &mMouse_Transformation.Rotation_Scene);// Rotate around oX and oY axises. mGLView->updateGL(); - mPosition_Pressed_LMB = pEvent->pos(); } if(pEvent->buttons() & Qt::RightButton) { - GLfloat dx = 180 * GLfloat(pEvent->x() - mPosition_Pressed_RMB.x()) / mGLView->width(); - GLfloat dy = 180 * GLfloat(pEvent->y() - mPosition_Pressed_RMB.y()) / mGLView->height(); + GLfloat dx = 180 * GLfloat(pEvent->x() - mMouse_Transformation.Position_Pressed_RMB.x()) / mGLView->width(); + GLfloat dy = 180 * GLfloat(pEvent->y() - mMouse_Transformation.Position_Pressed_RMB.y()) / mGLView->height(); if(pEvent->modifiers() & Qt::ShiftModifier) - mGLView->Camera_Rotate(dy, 0, dx);// Rotate around oX and oZ axises. + mGLView->Camera_Rotate(dy, 0, dx, &mMouse_Transformation.Rotation_AroundCamera);// Rotate around oX and oZ axises. else - mGLView->Camera_Rotate(dy, dx, 0);// Rotate around oX and oY axises. + mGLView->Camera_Rotate(dy, dx, 0, &mMouse_Transformation.Rotation_AroundCamera);// Rotate around oX and oY axises. mGLView->updateGL(); - mPosition_Pressed_RMB = pEvent->pos(); } } } @@ -212,10 +224,13 @@ GLfloat step; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), - mScene(nullptr), mPosition_Pressed_Valid(false) + mScene(nullptr) { using namespace Assimp; + // other variables + mMouse_Transformation.Position_Pressed_Valid = false; + ui->setupUi(this); // Create OpenGL widget mGLView = new CGLView(this); diff --git a/tools/assimp_qt_viewer/mainwindow.hpp b/tools/assimp_qt_viewer/mainwindow.hpp index fc31599b7..2eedf18f2 100644 --- a/tools/assimp_qt_viewer/mainwindow.hpp +++ b/tools/assimp_qt_viewer/mainwindow.hpp @@ -36,9 +36,17 @@ private: CLoggerView* mLoggerView;///< Pointer to logging object. Assimp::Importer mImporter;///< Assimp importer. const aiScene* mScene;///< Pointer to loaded scene (\ref aiScene). - bool mPosition_Pressed_Valid;///< Mouse button pressed on GLView. - QPoint mPosition_Pressed_LMB;///< Position where was pressed left mouse button. - QPoint mPosition_Pressed_RMB;///< Position where was pressed right mouse button. + + /// \struct SMouse_Transformation + /// Holds data about transformation of the scene/camera when mouse us used. + struct SMouse_Transformation + { + bool Position_Pressed_Valid;///< Mouse button pressed on GLView. + QPoint Position_Pressed_LMB;///< Position where was pressed left mouse button. + QPoint Position_Pressed_RMB;///< Position where was pressed right mouse button. + aiMatrix4x4 Rotation_AroundCamera;///< Rotation matrix which set rotation angles of the scene around camera. + aiMatrix4x4 Rotation_Scene;///< Rotation matrix which set rotation angles of the scene around own center. + } mMouse_Transformation; /**********************************/ /************ Functions ***********/ @@ -81,6 +89,11 @@ protected: /// \param [in] pEvent - pointer to event data. void mousePressEvent(QMouseEvent* pEvent) override; + /// \fn void mouseReleaseEvent(QMouseEvent *pEvent) override + /// Override function which handles mouse event "button released". + /// \param [in] pEvent - pointer to event data. + void mouseReleaseEvent(QMouseEvent *pEvent) override; + /// \fn void mouseMoveEvent(QMouseEvent* pEvent) override /// Override function which handles mouse event "move". /// \param [in] pEvent - pointer to event data. From d72ff712cb70f8345a3eb02a633c790d719da348 Mon Sep 17 00:00:00 2001 From: smalcom Date: Fri, 25 May 2018 21:16:08 +0300 Subject: [PATCH 10/14] [F] List of importers can be empty. --- code/Importer.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/code/Importer.cpp b/code/Importer.cpp index 139dc6c51..347ce12d2 100644 --- a/code/Importer.cpp +++ b/code/Importer.cpp @@ -970,15 +970,19 @@ void Importer::GetExtensionList(aiString& szOut) const (*i)->GetExtensionList(str); } - for (std::set::const_iterator it = str.begin();; ) { - szOut.Append("*."); - szOut.Append((*it).c_str()); + // List can be empty + if(str.size() > 0) + { + for (std::set::const_iterator it = str.begin();; ) { + szOut.Append("*."); + szOut.Append((*it).c_str()); - if (++it == str.end()) { - break; - } - szOut.Append(";"); - } + if (++it == str.end()) { + break; + } + szOut.Append(";"); + } + } ASSIMP_END_EXCEPTION_REGION(void); } From 67eff10d8f3197dea997039cdeb63de59825861b Mon Sep 17 00:00:00 2001 From: smalcom Date: Fri, 25 May 2018 21:19:06 +0300 Subject: [PATCH 11/14] [*] qt_assimp_viewer can be built with Qt4 or Qt5. [F] Working in doule precision. --- CMakeLists.txt | 27 +-- tools/assimp_qt_viewer/CMakeLists.txt | 127 ++++++++++---- tools/assimp_qt_viewer/glview.cpp | 233 ++++++++++++++++++++++++-- tools/assimp_qt_viewer/glview.hpp | 16 +- tools/assimp_qt_viewer/mainwindow.cpp | 41 ++++- tools/assimp_qt_viewer/mainwindow.hpp | 6 +- 6 files changed, 370 insertions(+), 80 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cb407c4b1..d5a7bc278 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -412,32 +412,7 @@ IF ( ASSIMP_BUILD_ASSIMP_TOOLS ) ENDIF ( WIN32 AND DirectX_D3DX9_LIBRARY ) ADD_SUBDIRECTORY( tools/assimp_cmd/ ) - - # Check dependencies for assimp_qt_viewer. - # Why here? Maybe user do not want Qt viewer and have no Qt. - # Why assimp_qt_viewer/CMakeLists.txt still contain similar check? - # Because viewer can be build independently of Assimp. - FIND_PACKAGE(Qt5Widgets QUIET) - FIND_PACKAGE(DevIL QUIET) - FIND_PACKAGE(OpenGL QUIET) - IF ( Qt5Widgets_FOUND AND IL_FOUND AND OPENGL_FOUND) - ADD_SUBDIRECTORY( tools/assimp_qt_viewer/ ) - ELSE() - SET ( ASSIMP_QT_VIEWER_DEPENDENCIES "") - IF (NOT Qt5_FOUND) - SET ( ASSIMP_QT_VIEWER_DEPENDENCIES "${ASSIMP_QT_VIEWER_DEPENDENCIES} Qt5") - ENDIF (NOT Qt5_FOUND) - - IF (NOT IL_FOUND) - SET ( ASSIMP_QT_VIEWER_DEPENDENCIES "${ASSIMP_QT_VIEWER_DEPENDENCIES} DevIL") - ENDIF (NOT IL_FOUND) - - IF (NOT OPENGL_FOUND) - SET ( ASSIMP_QT_VIEWER_DEPENDENCIES "${ASSIMP_QT_VIEWER_DEPENDENCIES} OpengGL") - ENDIF (NOT OPENGL_FOUND) - - MESSAGE (WARNING "Build of assimp_qt_viewer is disabled. Unsatisfied dendencies: ${ASSIMP_QT_VIEWER_DEPENDENCIES}") - ENDIF ( Qt5Widgets_FOUND AND IL_FOUND AND OPENGL_FOUND) + ADD_SUBDIRECTORY( tools/assimp_qt_viewer/ ) ENDIF ( ASSIMP_BUILD_ASSIMP_TOOLS ) IF ( ASSIMP_BUILD_SAMPLES) diff --git a/tools/assimp_qt_viewer/CMakeLists.txt b/tools/assimp_qt_viewer/CMakeLists.txt index b41291e3d..51a4efad8 100644 --- a/tools/assimp_qt_viewer/CMakeLists.txt +++ b/tools/assimp_qt_viewer/CMakeLists.txt @@ -3,44 +3,103 @@ project(assimp_qt_viewer) cmake_minimum_required(VERSION 2.6) -find_package(Qt5 COMPONENTS Gui Widgets OpenGL REQUIRED) -find_package(DevIL REQUIRED) -find_package(OpenGL REQUIRED) - -include_directories( - ${Qt5Widgets_INCLUDES} - ${Assimp_SOURCE_DIR}/include - ${Assimp_SOURCE_DIR}/code - ${CMAKE_CURRENT_BINARY_DIR} - ${CMAKE_SOURCE_DIR} - ${OPENGL_INCLUDE_DIR} - ${IL_INCLUDE_DIR} +OPTION( ASSIMP_QT4_VIEWER + "Set to ON to enable Qt4 against Qt5 for assimp_qt_viewer" + OFF ) -link_directories(${Assimp_BINARY_DIR}) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pedantic -Wall") +FIND_PACKAGE(DevIL QUIET) +FIND_PACKAGE(OpenGL QUIET) -set(assimp_qt_viewer_SRCS main.cpp loggerview.cpp glview.cpp mainwindow.cpp) -qt5_wrap_ui(UISrcs mainwindow.ui) -qt5_wrap_cpp(MOCrcs mainwindow.hpp glview.hpp) +IF(ASSIMP_QT4_VIEWER) + # Qt4 version + FIND_PACKAGE(Qt4 QUIET) +ELSE(ASSIMP_QT4_VIEWER) + # Qt5 version + FIND_PACKAGE(Qt5 COMPONENTS Gui Widgets OpenGL QUIET) +ENDIF(ASSIMP_QT4_VIEWER) -add_executable(${PROJECT_NAME} ${assimp_qt_viewer_SRCS} ${UISrcs} ${MOCrcs}) -target_link_libraries(${PROJECT_NAME} Qt5::Gui Qt5::Widgets Qt5::OpenGL ${IL_LIBRARIES} ${OPENGL_LIBRARIES} assimp) +SET(VIEWER_BUILD:BOOL FALSE) -if(WIN32) # Check if we are on Windows - if(MSVC) # Check if we are using the Visual Studio compiler - #set_target_properties(TestProject PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS") - elseif(CMAKE_COMPILER_IS_GNUCXX) - # SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mwindows") # Not tested - else() - message(SEND_ERROR "You are using an unsupported Windows compiler! (Not MSVC or GCC)") - endif() -elseif(UNIX) - # Nothing special required -else() - message(SEND_ERROR "You are on an unsupported platform! (Not Win32 or Unix)") -endif() +IF((Qt4_FOUND OR Qt5Widgets_FOUND) AND IL_FOUND AND OPENGL_FOUND) + SET(VIEWER_BUILD TRUE) -set_property(TARGET ${PROJECT_NAME} PROPERTY DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) +ELSE((Qt4_FOUND OR Qt5Widgets_FOUND) AND IL_FOUND AND OPENGL_FOUND) + SET ( ASSIMP_QT_VIEWER_DEPENDENCIES "") -install(TARGETS assimp_qt_viewer DESTINATION "${ASSIMP_BIN_INSTALL_DIR}") + IF(ASSIMP_QT4_VIEWER) + IF (NOT Qt4_FOUND) + SET ( ASSIMP_QT_VIEWER_DEPENDENCIES "${ASSIMP_QT_VIEWER_DEPENDENCIES} Qt4") + ENDIF (NOT Qt4_FOUND) + + ELSE(ASSIMP_QT4_VIEWER) + IF (NOT Qt5_FOUND) + SET ( ASSIMP_QT_VIEWER_DEPENDENCIES "${ASSIMP_QT_VIEWER_DEPENDENCIES} Qt5") + ENDIF (NOT Qt5_FOUND) + + ENDIF(ASSIMP_QT4_VIEWER) + + IF (NOT IL_FOUND) + SET ( ASSIMP_QT_VIEWER_DEPENDENCIES "${ASSIMP_QT_VIEWER_DEPENDENCIES} DevIL") + ENDIF (NOT IL_FOUND) + + IF (NOT OPENGL_FOUND) + SET ( ASSIMP_QT_VIEWER_DEPENDENCIES "${ASSIMP_QT_VIEWER_DEPENDENCIES} OpengGL") + ENDIF (NOT OPENGL_FOUND) + + MESSAGE (WARNING "Build of assimp_qt_viewer is disabled. Unsatisfied dendencies: ${ASSIMP_QT_VIEWER_DEPENDENCIES}") +ENDIF((Qt4_FOUND OR Qt5Widgets_FOUND) AND IL_FOUND AND OPENGL_FOUND) + +IF(VIEWER_BUILD) + INCLUDE_DIRECTORIES( + ${Assimp_SOURCE_DIR}/include + ${Assimp_SOURCE_DIR}/code + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_SOURCE_DIR} + ${OPENGL_INCLUDE_DIR} + ${IL_INCLUDE_DIR} + ) + + LINK_DIRECTORIES(${Assimp_BINARY_DIR}) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pedantic -Wall") + + SET(assimp_qt_viewer_SRCS main.cpp loggerview.cpp glview.cpp mainwindow.cpp) + + IF(ASSIMP_QT4_VIEWER) + MESSAGE("assimp_qt_viewer use Qt4") + ADD_DEFINITIONS( -DASSIMP_QT4_VIEWER ) + INCLUDE_DIRECTORIES(${QT_INCLUDES}) + qt4_wrap_ui(UISrcs mainwindow.ui) + qt4_wrap_cpp(MOCrcs mainwindow.hpp glview.hpp) + ELSE() + MESSAGE("assimp_qt_viewer use Qt5") + INCLUDE_DIRECTORIES(${Qt5Widgets_INCLUDES}) + qt5_wrap_ui(UISrcs mainwindow.ui) + qt5_wrap_cpp(MOCrcs mainwindow.hpp glview.hpp) + ENDIF() + + add_executable(${PROJECT_NAME} ${assimp_qt_viewer_SRCS} ${UISrcs} ${MOCrcs}) + + IF(ASSIMP_QT4_VIEWER) + target_link_libraries(${PROJECT_NAME} ${QT_LIBRARIES} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTOPENGL_LIBRARY} ${IL_LIBRARIES} ${OPENGL_LIBRARIES} assimp) + ELSE() + target_link_libraries(${PROJECT_NAME} Qt5::Gui Qt5::Widgets Qt5::OpenGL ${IL_LIBRARIES} ${OPENGL_LIBRARIES} assimp) + ENDIF() + + IF(WIN32) # Check if we are on Windows + IF(MSVC) # Check if we are using the Visual Studio compiler + #set_target_properties(TestProject PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS") + ELSEIF(CMAKE_COMPILER_IS_GNUCXX) + # SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mwindows") # Not tested + ELSE() + MESSAGE(SEND_ERROR "You are using an unsupported Windows compiler! (Not MSVC or GCC)") + ENDIF() + ELSEIF(UNIX) + # Nothing special required + ELSE() + MESSAGE(SEND_ERROR "You are on an unsupported platform! (Not Win32 or Unix)") + ENDIF() + + SET_PROPERTY(TARGET ${PROJECT_NAME} PROPERTY DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) + INSTALL(TARGETS assimp_qt_viewer DESTINATION "${ASSIMP_BIN_INSTALL_DIR}") +ENDIF(VIEWER_BUILD) diff --git a/tools/assimp_qt_viewer/glview.cpp b/tools/assimp_qt_viewer/glview.cpp index 833400c46..c67420c06 100644 --- a/tools/assimp_qt_viewer/glview.cpp +++ b/tools/assimp_qt_viewer/glview.cpp @@ -5,6 +5,9 @@ #include "glview.hpp" +// Header files, Qt. +#include + // Header files, OpenGL. #if defined(__APPLE__) # include @@ -58,6 +61,33 @@ void CGLView::SHelper_Camera::SetDefault() /************ CGLView *************/ /**********************************/ +#if !ASSIMP_QT4_VIEWER +# define ConditionalContextControl_Begin \ + bool ContextEnabledHere; \ + \ + if(mGLContext_Current) \ + { \ + ContextEnabledHere = false; \ + } \ + else \ + { \ + makeCurrent(); \ + mGLContext_Current = true; \ + ContextEnabledHere = true; \ + } \ + \ + do {} while(false) + +# define ConditionalContextControl_End \ + if(ContextEnabledHere) \ + { \ + doneCurrent(); \ + mGLContext_Current = false; \ + } \ + \ + do {} while(false) +#endif // ASSIMP_QT4_VIEWER + void CGLView::Material_Apply(const aiMaterial* pMaterial) { GLfloat tcol[4]; @@ -105,7 +135,7 @@ void CGLView::Material_Apply(const aiMaterial* pMaterial) glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, tcol); // Shininess - float shininess, strength; + ai_real shininess, strength; max = 1; ret1 = aiGetMaterialFloatArray(pMaterial, AI_MATKEY_SHININESS, &shininess, &max); @@ -406,10 +436,11 @@ void CGLView::BBox_GetFromVertices(const aiVector3D* pVertices, const size_t pVe for(size_t idx_vert = 1; idx_vert < pVerticesQuantity; idx_vert++) { - const GLfloat x = pVertices[idx_vert].x; - const GLfloat y = pVertices[idx_vert].y; - const GLfloat z = pVertices[idx_vert].z; + const ai_real x = pVertices[idx_vert].x; + const ai_real y = pVertices[idx_vert].y; + const ai_real z = pVertices[idx_vert].z; + printf("vert[%lu]=%g,%g,%g\r\n", idx_vert, x, y, z);///TODO: dbg // search minimal... AssignIfLesser(&pBBox.Minimum.x, x); AssignIfLesser(&pBBox.Minimum.y, y); @@ -439,14 +470,29 @@ void CGLView::LogError(const QString& pMessage) /************************** Draw functions **************************/ /********************************************************************/ +static void print_matrix(const aiMatrix4x4 pMatrix)///TODO: dbg +{ + printf("Matrix:\r\n"); + printf("\t%g,%g,%g%g\r\n", pMatrix.a1, pMatrix.a2, pMatrix.a3, pMatrix.a4); + printf("\t%g,%g,%g%g\r\n", pMatrix.b1, pMatrix.b2, pMatrix.b3, pMatrix.b4); + printf("\t%g,%g,%g%g\r\n", pMatrix.c1, pMatrix.c2, pMatrix.c3, pMatrix.c4); + printf("\t%g,%g,%g%g\r\n", pMatrix.d1, pMatrix.d2, pMatrix.d3, pMatrix.d4); +} + void CGLView::Draw_Node(const aiNode* pNode) { aiMatrix4x4 mat_node = pNode->mTransformation; // Apply node transformation matrix. mat_node.Transpose(); + print_matrix(mat_node); glPushMatrix(); +#if ASSIMP_DOUBLE_PRECISION + glMultMatrixd((GLdouble*)mat_node[0]); +#else glMultMatrixf((GLfloat*)&mat_node); +#endif // ASSIMP_DOUBLE_PRECISION + // Draw all meshes assigned to this node for(size_t idx_mesh_arr = 0; idx_mesh_arr < pNode->mNumMeshes; idx_mesh_arr++) Draw_Mesh(pNode->mMeshes[idx_mesh_arr]); @@ -473,13 +519,21 @@ void CGLView::Draw_Mesh(const size_t pMesh_Index) // Vertices array // glEnableClientState(GL_VERTEX_ARRAY); +#if ASSIMP_DOUBLE_PRECISION + glVertexPointer(3, GL_DOUBLE, 0, mesh_cur.mVertices); +#else glVertexPointer(3, GL_FLOAT, 0, mesh_cur.mVertices); +#endif // ASSIMP_DOUBLE_PRECISION if(mesh_cur.HasVertexColors(0)) { glEnable(GL_COLOR_MATERIAL);///TODO: cache glEnableClientState(GL_COLOR_ARRAY); +#if ASSIMP_DOUBLE_PRECISION + glColorPointer(4, GL_DOUBLE, 0, mesh_cur.mColors[0]); +#else glColorPointer(4, GL_FLOAT, 0, mesh_cur.mColors[0]); +#endif // ASSIMP_DOUBLE_PRECISION } // @@ -488,7 +542,11 @@ void CGLView::Draw_Mesh(const size_t pMesh_Index) if(mesh_cur.HasTextureCoords(0)) { glEnableClientState(GL_TEXTURE_COORD_ARRAY); +#if ASSIMP_DOUBLE_PRECISION + glTexCoordPointer(2, GL_DOUBLE, sizeof(aiVector3D), mesh_cur.mTextureCoords[0]); +#else glTexCoordPointer(2, GL_FLOAT, sizeof(aiVector3D), mesh_cur.mTextureCoords[0]); +#endif // ASSIMP_DOUBLE_PRECISION } // @@ -497,7 +555,11 @@ void CGLView::Draw_Mesh(const size_t pMesh_Index) if(mesh_cur.HasNormals()) { glEnableClientState(GL_NORMAL_ARRAY); +#if ASSIMP_DOUBLE_PRECISION + glNormalPointer(GL_DOUBLE, 0, mesh_cur.mNormals); +#else glNormalPointer(GL_FLOAT, 0, mesh_cur.mNormals); +#endif // ASSIMP_DOUBLE_PRECISION } // @@ -530,22 +592,46 @@ void CGLView::Draw_BBox(const SBBox& pBBox) glBindTexture(GL_TEXTURE_1D, 0); glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_3D, 0); +#if ASSIMP_QT4_VIEWER qglColor(QColor(Qt::white)); +#else + const QColor c_w(Qt::white); + + glColor3f(c_w.redF(), c_w.greenF(), c_w.blueF()); +#endif // ASSIMP_QT4_VIEWER + glBegin(GL_LINE_STRIP); +# if ASSIMP_DOUBLE_PRECISION + glVertex3dv(&vertex[0][0]), glVertex3dv(&vertex[1][0]), glVertex3dv(&vertex[2][0]), glVertex3dv(&vertex[3][0]), glVertex3dv(&vertex[0][0]);// "Minimum" side. + glVertex3dv(&vertex[4][0]), glVertex3dv(&vertex[5][0]), glVertex3dv(&vertex[6][0]), glVertex3dv(&vertex[7][0]), glVertex3dv(&vertex[4][0]);// Edge and "maximum" side. +# else glVertex3fv(&vertex[0][0]), glVertex3fv(&vertex[1][0]), glVertex3fv(&vertex[2][0]), glVertex3fv(&vertex[3][0]), glVertex3fv(&vertex[0][0]);// "Minimum" side. glVertex3fv(&vertex[4][0]), glVertex3fv(&vertex[5][0]), glVertex3fv(&vertex[6][0]), glVertex3fv(&vertex[7][0]), glVertex3fv(&vertex[4][0]);// Edge and "maximum" side. +# endif // ASSIMP_DOUBLE_PRECISION glEnd(); + glBegin(GL_LINES); +# if ASSIMP_DOUBLE_PRECISION + glVertex3dv(&vertex[1][0]), glVertex3dv(&vertex[5][0]); + glVertex3dv(&vertex[2][0]), glVertex3dv(&vertex[6][0]); + glVertex3dv(&vertex[3][0]), glVertex3dv(&vertex[7][0]); +# else glVertex3fv(&vertex[1][0]), glVertex3fv(&vertex[5][0]); glVertex3fv(&vertex[2][0]), glVertex3fv(&vertex[6][0]); glVertex3fv(&vertex[3][0]), glVertex3fv(&vertex[7][0]); +# endif // ASSIMP_DOUBLE_PRECISION glEnd(); glDisable(GL_COLOR_MATERIAL); if(mLightingEnabled) glEnable(GL_LIGHTING); + } void CGLView::Enable_Textures(const bool pEnable) { +#if !ASSIMP_QT4_VIEWER + ConditionalContextControl_Begin; +#endif // ASSIMP_QT4_VIEWER + if(pEnable) { glEnable(GL_TEXTURE_1D); @@ -558,6 +644,10 @@ void CGLView::Enable_Textures(const bool pEnable) glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_3D); } + +#if !ASSIMP_QT4_VIEWER + ConditionalContextControl_End; +#endif // ASSIMP_QT4_VIEWER } /********************************************************************/ @@ -566,7 +656,13 @@ void CGLView::Enable_Textures(const bool pEnable) void CGLView::initializeGL() { +#if ASSIMP_QT4_VIEWER qglClearColor(Qt::gray); +#else + mGLContext_Current = true; + initializeOpenGLFunctions(); + glClearColor(0.5f, 0.5f, 0.5f, 1.0f); +#endif // ASSIMP_QT4_VIEWER glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); @@ -583,15 +679,25 @@ void CGLView::initializeGL() glCullFace(GL_BACK); glFrontFace(GL_CCW); + +#if !ASSIMP_QT4_VIEWER + mGLContext_Current = false; +#endif // ASSIMP_QT4_VIEWER } void CGLView::resizeGL(int pWidth, int pHeight) { +#if !ASSIMP_QT4_VIEWER + mGLContext_Current = true; +#endif // ASSIMP_QT4_VIEWER mCamera_Viewport_AspectRatio = (GLdouble)pWidth / pHeight; glViewport(0, 0, pWidth, pHeight); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(mCamera_FOVY, mCamera_Viewport_AspectRatio, 1.0, 100000.0);///TODO: znear/zfar depend on scene size. +#if !ASSIMP_QT4_VIEWER + mGLContext_Current = false; +#endif // ASSIMP_QT4_VIEWER } void CGLView::drawCoordSystem() { @@ -604,7 +710,8 @@ void CGLView::drawCoordSystem() { glBindTexture(GL_TEXTURE_3D, 0); glEnable(GL_COLOR_MATERIAL); glBegin(GL_LINES); - // X, -X +#if ASSIMP_QT4_VIEWER + // X, -X qglColor(QColor(Qt::red)), glVertex3f(0.0, 0.0, 0.0), glVertex3f(100000.0, 0.0, 0.0); qglColor(QColor(Qt::cyan)), glVertex3f(0.0, 0.0, 0.0), glVertex3f(-100000.0, 0.0, 0.0); // Y, -Y @@ -614,14 +721,31 @@ void CGLView::drawCoordSystem() { qglColor(QColor(Qt::blue)), glVertex3f(0.0, 0.0, 0.0), glVertex3f(0.0, 0.0, 100000.0); qglColor(QColor(Qt::yellow)), glVertex3f(0.0, 0.0, 0.0), glVertex3f(0.0, 0.0, -100000.0); qglColor(QColor(Qt::white)); - glEnd(); +#else + // X, -X + glColor3f(1.0f, 0.0f, 0.0f), glVertex3f(0.0, 0.0, 0.0), glVertex3f(100000.0, 0.0, 0.0); + glColor3f(0.5f, 0.5f, 1.0f), glVertex3f(0.0, 0.0, 0.0), glVertex3f(-100000.0, 0.0, 0.0); + // Y, -Y + glColor3f(0.0f, 1.0f, 0.0f), glVertex3f(0.0, 0.0, 0.0), glVertex3f(0.0, 100000.0, 0.0); + glColor3f(1.0f, 0.0f, 1.0f), glVertex3f(0.0, 0.0, 0.0), glVertex3f(0.0, -100000.0, 0.0); + // Z, -Z + glColor3f(0.0f, 0.0f, 1.0f), glVertex3f(0.0, 0.0, 0.0), glVertex3f(0.0, 0.0, 100000.0); + glColor3f(1.0f, 1.0f, 0.0f), glVertex3f(0.0, 0.0, 0.0), glVertex3f(0.0, 0.0, -100000.0); + glColor3f(1.0f, 1.0f, 1.0f); +#endif // ASSIMP_QT4_VIEWER + glEnd(); // Restore previous state of lighting. if(mLightingEnabled) glEnable(GL_LIGHTING); + } void CGLView::paintGL() { - QTime time_paintbegin; +#if !ASSIMP_QT4_VIEWER + mGLContext_Current = true; +#endif // ASSIMP_QT4_VIEWER + + QTime time_paintbegin; time_paintbegin = QTime::currentTime(); @@ -629,9 +753,16 @@ void CGLView::paintGL() glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // Apply current camera transformations. +#if ASSIMP_DOUBLE_PRECISION + glMultMatrixd((GLdouble*)&mHelper_Camera.Rotation_AroundCamera); + glTranslated(-mHelper_Camera.Translation_ToScene.x, -mHelper_Camera.Translation_ToScene.y, -mHelper_Camera.Translation_ToScene.z); + glMultMatrixd((GLdouble*)&mHelper_Camera.Rotation_Scene); +#else glMultMatrixf((GLfloat*)&mHelper_Camera.Rotation_AroundCamera); glTranslatef(-mHelper_Camera.Translation_ToScene.x, -mHelper_Camera.Translation_ToScene.y, -mHelper_Camera.Translation_ToScene.z); glMultMatrixf((GLfloat*)&mHelper_Camera.Rotation_Scene); +#endif // ASSIMP_DOUBLE_PRECISION + // Coordinate system if (mScene_AxesEnabled == true) { @@ -645,9 +776,13 @@ void CGLView::paintGL() Draw_Node(mScene->mRootNode); // Scene BBox if(mScene_DrawBBox) Draw_BBox(mScene_BBox); + } emit Paint_Finished((size_t)time_paintbegin.msecsTo(QTime::currentTime()), mHelper_Camera.Translation_ToScene.Length()); +#if !ASSIMP_QT4_VIEWER + mGLContext_Current = false; +#endif // ASSIMP_QT4_VIEWER } /********************************************************************/ @@ -655,10 +790,12 @@ void CGLView::paintGL() /********************************************************************/ CGLView::CGLView(QWidget *pParent) +#if ASSIMP_QT4_VIEWER : QGLWidget(QGLFormat(QGL::DoubleBuffer | QGL::DepthBuffer), pParent) +#else + : QOpenGLWidget(pParent), mGLContext_Current(false) +#endif // ASSIMP_QT4_VIEWER { - static_assert(sizeof(GLfloat) == sizeof(ai_real), "ai_real in Assimp must be equal to GLfloat/float.");///TODO: may be templates can be used. - // set initial view mHelper_CameraDefault.SetDefault(); Camera_Set(0); @@ -675,6 +812,10 @@ CGLView::~CGLView() void CGLView::FreeScene() { +#if !ASSIMP_QT4_VIEWER + ConditionalContextControl_Begin; +#endif // ASSIMP_QT4_VIEWER + // Set scene to null and after that \ref paintGL will not try to render it. mScene = nullptr; // Clean helper objects. @@ -704,10 +845,18 @@ void CGLView::FreeScene() mTexture_IDMap.clear(); delete [] id_tex; } + +#if !ASSIMP_QT4_VIEWER + ConditionalContextControl_End; +#endif // ASSIMP_QT4_VIEWER } void CGLView::SetScene(const aiScene *pScene, const QString& pScenePath) { +#if !ASSIMP_QT4_VIEWER + ConditionalContextControl_Begin; +#endif // ASSIMP_QT4_VIEWER + FreeScene();// Clear old data // Why checking here, not at begin of function. Because old scene may not exist at know. So, need cleanup. if(pScene == nullptr) return; @@ -934,6 +1083,10 @@ void CGLView::SetScene(const aiScene *pScene, const QString& pScenePath) emit SceneObject_Camera(mScene->mCameras[idx_cam]->mName.C_Str()); } }// if(!mScene->HasCameras()) else + +#if !ASSIMP_QT4_VIEWER + ConditionalContextControl_End; +#endif // ASSIMP_QT4_VIEWER } /********************************************************************/ @@ -942,39 +1095,65 @@ void CGLView::SetScene(const aiScene *pScene, const QString& pScenePath) void CGLView::Lighting_Enable() { +#if !ASSIMP_QT4_VIEWER + ConditionalContextControl_Begin; +#endif // ASSIMP_QT4_VIEWER + mLightingEnabled = true; glEnable(GL_LIGHTING); + +#if !ASSIMP_QT4_VIEWER + ConditionalContextControl_End; +#endif // ASSIMP_QT4_VIEWER } void CGLView::Lighting_Disable() { +#if !ASSIMP_QT4_VIEWER + ConditionalContextControl_Begin; +#endif // ASSIMP_QT4_VIEWER + glDisable(GL_LIGHTING); mLightingEnabled = false; + +#if !ASSIMP_QT4_VIEWER + ConditionalContextControl_End; +#endif // ASSIMP_QT4_VIEWER } void CGLView::Lighting_EditSource(const size_t pLightNumber, const SLightParameters& pLightParameters) { +#if !ASSIMP_QT4_VIEWER + ConditionalContextControl_Begin; +#endif // ASSIMP_QT4_VIEWER + const size_t light_num = GL_LIGHT0 + pLightNumber; GLfloat farr[4]; if(pLightNumber >= GL_MAX_LIGHTS) return;///TODO: return value; - glLightfv(light_num, GL_AMBIENT, &pLightParameters.Ambient.r);// Ambient color - glLightfv(light_num, GL_DIFFUSE, &pLightParameters.Diffuse.r);// Diffuse color - glLightfv(light_num, GL_SPECULAR, &pLightParameters.Specular.r);// Specular color + // Ambient color + farr[0] = pLightParameters.Ambient.r, farr[1] = pLightParameters.Ambient.g; farr[2] = pLightParameters.Ambient.b; farr[3] = pLightParameters.Ambient.a; + glLightfv(light_num, GL_AMBIENT, farr); + // Diffuse color + farr[0] = pLightParameters.Diffuse.r, farr[1] = pLightParameters.Diffuse.g; farr[2] = pLightParameters.Diffuse.b; farr[3] = pLightParameters.Diffuse.a; + glLightfv(light_num, GL_DIFFUSE, farr); + // Specular color + farr[0] = pLightParameters.Specular.r, farr[1] = pLightParameters.Specular.g; farr[2] = pLightParameters.Specular.b; farr[3] = pLightParameters.Specular.a; + glLightfv(light_num, GL_SPECULAR, farr); // Other parameters switch(pLightParameters.Type) { case aiLightSource_DIRECTIONAL: // Direction - farr[0] = pLightParameters.For.Directional.Direction.x, farr[2] = pLightParameters.For.Directional.Direction.y; + farr[0] = pLightParameters.For.Directional.Direction.x, farr[1] = pLightParameters.For.Directional.Direction.y; farr[2] = pLightParameters.For.Directional.Direction.z; farr[3] = 0; glLightfv(light_num, GL_POSITION, farr); break; case aiLightSource_POINT: // Position - farr[0] = pLightParameters.For.Point.Position.x, farr[2] = pLightParameters.For.Point.Position.y; + farr[0] = pLightParameters.For.Point.Position.x, farr[1] = pLightParameters.For.Point.Position.y; farr[2] = pLightParameters.For.Point.Position.z; farr[3] = 1; glLightfv(light_num, GL_POSITION, farr); // Attenuation @@ -985,20 +1164,20 @@ GLfloat farr[4]; break; case aiLightSource_SPOT: // Position - farr[0] = pLightParameters.For.Spot.Position.x, farr[2] = pLightParameters.For.Spot.Position.y, farr[2] = pLightParameters.For.Spot.Position.z; farr[3] = 1; + farr[0] = pLightParameters.For.Spot.Position.x, farr[1] = pLightParameters.For.Spot.Position.y, farr[2] = pLightParameters.For.Spot.Position.z; farr[3] = 1; glLightfv(light_num, GL_POSITION, farr); // Attenuation glLightf(light_num, GL_CONSTANT_ATTENUATION, pLightParameters.For.Spot.Attenuation_Constant); glLightf(light_num, GL_LINEAR_ATTENUATION, pLightParameters.For.Spot.Attenuation_Linear); glLightf(light_num, GL_QUADRATIC_ATTENUATION, pLightParameters.For.Spot.Attenuation_Quadratic); // Spot specific - farr[0] = pLightParameters.For.Spot.Direction.x, farr[2] = pLightParameters.For.Spot.Direction.y, farr[2] = pLightParameters.For.Spot.Direction.z; farr[3] = 0; + farr[0] = pLightParameters.For.Spot.Direction.x, farr[1] = pLightParameters.For.Spot.Direction.y, farr[2] = pLightParameters.For.Spot.Direction.z; farr[3] = 0; glLightfv(light_num, GL_SPOT_DIRECTION, farr); glLightf(light_num, GL_SPOT_CUTOFF, pLightParameters.For.Spot.CutOff); break; default:// For unknown light source types use point source. // Position - farr[0] = pLightParameters.For.Point.Position.x, farr[2] = pLightParameters.For.Point.Position.y; + farr[0] = pLightParameters.For.Point.Position.x, farr[1] = pLightParameters.For.Point.Position.y; farr[2] = pLightParameters.For.Point.Position.z; farr[3] = 1; glLightfv(light_num, GL_POSITION, farr); // Attenuation @@ -1008,20 +1187,40 @@ GLfloat farr[4]; glLightf(light_num, GL_SPOT_CUTOFF, 180.0); break; }// switch(pLightParameters.Type) + +#if !ASSIMP_QT4_VIEWER + ConditionalContextControl_End; +#endif // ASSIMP_QT4_VIEWER } void CGLView::Lighting_EnableSource(const size_t pLightNumber) { +#if !ASSIMP_QT4_VIEWER + ConditionalContextControl_Begin; +#endif // ASSIMP_QT4_VIEWER + if(pLightNumber >= GL_MAX_LIGHTS) return;///TODO: return value; glEnable(GL_LIGHT0 + pLightNumber); + +#if !ASSIMP_QT4_VIEWER + ConditionalContextControl_End; +#endif // ASSIMP_QT4_VIEWER } void CGLView::Lighting_DisableSource(const size_t pLightNumber) { +#if !ASSIMP_QT4_VIEWER + ConditionalContextControl_Begin; +#endif // ASSIMP_QT4_VIEWER + if(pLightNumber >= GL_MAX_LIGHTS) return;///TODO: return value; glDisable(GL_LIGHT0 + pLightNumber); + +#if !ASSIMP_QT4_VIEWER + ConditionalContextControl_End; +#endif // ASSIMP_QT4_VIEWER } /********************************************************************/ diff --git a/tools/assimp_qt_viewer/glview.hpp b/tools/assimp_qt_viewer/glview.hpp index 2d8614e21..6068e1448 100644 --- a/tools/assimp_qt_viewer/glview.hpp +++ b/tools/assimp_qt_viewer/glview.hpp @@ -6,14 +6,24 @@ #pragma once // Header files, Qt. -#include +#include +#if ASSIMP_QT4_VIEWER +# include +#else +# include +# include +#endif // ASSIMP_QT4_VIEWER // Header files Assimp #include /// \class CGLView /// Class which hold and render scene. +#if ASSIMP_QT4_VIEWER class CGLView : public QGLWidget +#else +class CGLView : public QOpenGLWidget, protected QOpenGLFunctions +#endif // ASSIMP_QT4_VIEWER { Q_OBJECT @@ -139,6 +149,10 @@ public: private: +#if !ASSIMP_QT4_VIEWER + // Qt5 widget has another behavior, so you must to know that you already made context are current. Yes, its a dirty hack. Better decision are welcome. + bool mGLContext_Current;///< Widget's GL-context made current. +#endif // ASSIMP_QT4_VIEWER // Scene const aiScene* mScene = nullptr;///< Copy of pointer to scene (\ref aiScene). SBBox mScene_BBox;///< Bounding box of scene. diff --git a/tools/assimp_qt_viewer/mainwindow.cpp b/tools/assimp_qt_viewer/mainwindow.cpp index c17188472..85a70ba6b 100644 --- a/tools/assimp_qt_viewer/mainwindow.cpp +++ b/tools/assimp_qt_viewer/mainwindow.cpp @@ -84,7 +84,11 @@ QTime time_begin = QTime::currentTime(); mGLView->Camera_Set(0); // Scene is loaded, do first rendering. LogInfo("Scene is ready for rendering."); +#if ASSIMP_QT4_VIEWER mGLView->updateGL(); +#else + mGLView->update(); +#endif // ASSIMP_QT4_VIEWER } else { @@ -173,7 +177,11 @@ void MainWindow::mouseMoveEvent(QMouseEvent* pEvent) else mGLView->Camera_RotateScene(dy, dx, 0, &mMouse_Transformation.Rotation_Scene);// Rotate around oX and oY axises. + #if ASSIMP_QT4_VIEWER mGLView->updateGL(); + #else + mGLView->update(); + #endif // ASSIMP_QT4_VIEWER } if(pEvent->buttons() & Qt::RightButton) @@ -186,7 +194,11 @@ void MainWindow::mouseMoveEvent(QMouseEvent* pEvent) else mGLView->Camera_Rotate(dy, dx, 0, &mMouse_Transformation.Rotation_AroundCamera);// Rotate around oX and oY axises. + #if ASSIMP_QT4_VIEWER mGLView->updateGL(); + #else + mGLView->update(); + #endif // ASSIMP_QT4_VIEWER } } } @@ -215,7 +227,11 @@ GLfloat step; else if(pEvent->key() == Qt::Key_Down) mGLView->Camera_Translate(0, 0, step); +#if ASSIMP_QT4_VIEWER mGLView->updateGL(); +#else + mGLView->update(); +#endif // ASSIMP_QT4_VIEWER } /********************************************************************/ @@ -303,7 +319,6 @@ QString filename, filter; if(!filename.isEmpty()) ImportFile(filename); } - void MainWindow::on_butExport_clicked() { using namespace Assimp; @@ -367,7 +382,11 @@ void MainWindow::on_cbxLighting_clicked(bool pChecked) else mGLView->Lighting_Disable(); +#if ASSIMP_QT4_VIEWER mGLView->updateGL(); +#else + mGLView->update(); +#endif // ASSIMP_QT4_VIEWER } void MainWindow::on_lstLight_itemSelectionChanged() @@ -379,29 +398,49 @@ bool selected = ui->lstLight->isItemSelected(ui->lstLight->currentItem()); else mGLView->Lighting_DisableSource(ui->lstLight->currentRow()); +#if ASSIMP_QT4_VIEWER mGLView->updateGL(); +#else + mGLView->update(); +#endif // ASSIMP_QT4_VIEWER } void MainWindow::on_lstCamera_clicked( const QModelIndex &) { mGLView->Camera_Set(ui->lstLight->currentRow()); +#if ASSIMP_QT4_VIEWER mGLView->updateGL(); +#else + mGLView->update(); +#endif // ASSIMP_QT4_VIEWER } void MainWindow::on_cbxBBox_clicked(bool checked) { mGLView->Enable_SceneBBox(checked); +#if ASSIMP_QT4_VIEWER mGLView->updateGL(); +#else + mGLView->update(); +#endif // ASSIMP_QT4_VIEWER } void MainWindow::on_cbxDrawAxes_clicked(bool checked) { mGLView->Enable_Axes(checked); +#if ASSIMP_QT4_VIEWER mGLView->updateGL(); +#else + mGLView->update(); +#endif // ASSIMP_QT4_VIEWER } void MainWindow::on_cbxTextures_clicked(bool checked) { mGLView->Enable_Textures(checked); +#if ASSIMP_QT4_VIEWER mGLView->updateGL(); +#else + mGLView->update(); +#endif // ASSIMP_QT4_VIEWER } diff --git a/tools/assimp_qt_viewer/mainwindow.hpp b/tools/assimp_qt_viewer/mainwindow.hpp index 2eedf18f2..e0d17181d 100644 --- a/tools/assimp_qt_viewer/mainwindow.hpp +++ b/tools/assimp_qt_viewer/mainwindow.hpp @@ -6,7 +6,11 @@ #pragma once // Header files, Qt. -#include +#if ASSIMP_QT4_VIEWER +# include +#else +# include +#endif // Header files, project. #include "glview.hpp" From 02d2b6e0d8e5dfd43e310fe1774eff4e6a522c0f Mon Sep 17 00:00:00 2001 From: smalcom Date: Fri, 25 May 2018 21:30:59 +0300 Subject: [PATCH 12/14] [F] Get return "like true" when error occured. --- code/glTF2Exporter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/glTF2Exporter.cpp b/code/glTF2Exporter.cpp index 9e8dfc822..1001a2d94 100644 --- a/code/glTF2Exporter.cpp +++ b/code/glTF2Exporter.cpp @@ -514,9 +514,9 @@ void glTF2Exporter::ExportMaterials() GetMatColor(mat, pbrSG.specularFactor, AI_MATKEY_COLOR_SPECULAR); if (mat->Get(AI_MATKEY_GLTF_PBRSPECULARGLOSSINESS_GLOSSINESS_FACTOR, pbrSG.glossinessFactor) != AI_SUCCESS) { - float shininess; + float shininess; - if (mat->Get(AI_MATKEY_SHININESS, shininess)) { + if (mat->Get(AI_MATKEY_SHININESS, shininess) == AI_SUCCESS) { pbrSG.glossinessFactor = shininess / 1000; } } From f29af1abc08b2e3d08efa3808f6458bed39e4150 Mon Sep 17 00:00:00 2001 From: smalcom Date: Fri, 25 May 2018 21:31:22 +0300 Subject: [PATCH 13/14] [-] Trace print removed. --- tools/assimp_qt_viewer/glview.cpp | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/tools/assimp_qt_viewer/glview.cpp b/tools/assimp_qt_viewer/glview.cpp index c67420c06..85dbbbae1 100644 --- a/tools/assimp_qt_viewer/glview.cpp +++ b/tools/assimp_qt_viewer/glview.cpp @@ -440,7 +440,6 @@ void CGLView::BBox_GetFromVertices(const aiVector3D* pVertices, const size_t pVe const ai_real y = pVertices[idx_vert].y; const ai_real z = pVertices[idx_vert].z; - printf("vert[%lu]=%g,%g,%g\r\n", idx_vert, x, y, z);///TODO: dbg // search minimal... AssignIfLesser(&pBBox.Minimum.x, x); AssignIfLesser(&pBBox.Minimum.y, y); @@ -470,22 +469,12 @@ void CGLView::LogError(const QString& pMessage) /************************** Draw functions **************************/ /********************************************************************/ -static void print_matrix(const aiMatrix4x4 pMatrix)///TODO: dbg -{ - printf("Matrix:\r\n"); - printf("\t%g,%g,%g%g\r\n", pMatrix.a1, pMatrix.a2, pMatrix.a3, pMatrix.a4); - printf("\t%g,%g,%g%g\r\n", pMatrix.b1, pMatrix.b2, pMatrix.b3, pMatrix.b4); - printf("\t%g,%g,%g%g\r\n", pMatrix.c1, pMatrix.c2, pMatrix.c3, pMatrix.c4); - printf("\t%g,%g,%g%g\r\n", pMatrix.d1, pMatrix.d2, pMatrix.d3, pMatrix.d4); -} - void CGLView::Draw_Node(const aiNode* pNode) { aiMatrix4x4 mat_node = pNode->mTransformation; // Apply node transformation matrix. mat_node.Transpose(); - print_matrix(mat_node); glPushMatrix(); #if ASSIMP_DOUBLE_PRECISION glMultMatrixd((GLdouble*)mat_node[0]); From aa18e8a2a5bb85597814084978b8293e651de83d Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Fri, 25 May 2018 21:43:39 +0200 Subject: [PATCH 14/14] Update Importer.cpp Make check more expressive. --- code/Importer.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/code/Importer.cpp b/code/Importer.cpp index 347ce12d2..c258f0519 100644 --- a/code/Importer.cpp +++ b/code/Importer.cpp @@ -971,8 +971,7 @@ void Importer::GetExtensionList(aiString& szOut) const } // List can be empty - if(str.size() > 0) - { + if( !str.empty() ) { for (std::set::const_iterator it = str.begin();; ) { szOut.Append("*."); szOut.Append((*it).c_str());