Remove qt4-support for viewer.
parent
fe6be58b35
commit
0ff4640dcd
|
@ -3,47 +3,28 @@ project(assimp_qt_viewer)
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 2.6)
|
cmake_minimum_required(VERSION 2.6)
|
||||||
|
|
||||||
OPTION( ASSIMP_QT4_VIEWER
|
|
||||||
"Set to ON to enable Qt4 against Qt5 for assimp_qt_viewer"
|
|
||||||
OFF
|
|
||||||
)
|
|
||||||
|
|
||||||
FIND_PACKAGE(OpenGL QUIET)
|
FIND_PACKAGE(OpenGL QUIET)
|
||||||
|
|
||||||
IF(ASSIMP_QT4_VIEWER)
|
# Qt5 version
|
||||||
# Qt4 version
|
FIND_PACKAGE(Qt5 COMPONENTS Gui Widgets OpenGL QUIET)
|
||||||
FIND_PACKAGE(Qt4 QUIET)
|
|
||||||
ELSE(ASSIMP_QT4_VIEWER)
|
|
||||||
# Qt5 version
|
|
||||||
FIND_PACKAGE(Qt5 COMPONENTS Gui Widgets OpenGL QUIET)
|
|
||||||
ENDIF(ASSIMP_QT4_VIEWER)
|
|
||||||
|
|
||||||
SET(VIEWER_BUILD:BOOL FALSE)
|
SET(VIEWER_BUILD:BOOL FALSE)
|
||||||
|
|
||||||
IF((Qt4_FOUND OR Qt5Widgets_FOUND) AND OPENGL_FOUND)
|
IF( Qt5Widgets_FOUND AND OPENGL_FOUND)
|
||||||
SET(VIEWER_BUILD TRUE)
|
SET(VIEWER_BUILD TRUE)
|
||||||
|
ELSE( Qt5Widgets_FOUND AND OPENGL_FOUND)
|
||||||
ELSE((QT4_FOUND OR Qt5Widgets_FOUND) AND OPENGL_FOUND)
|
|
||||||
SET ( ASSIMP_QT_VIEWER_DEPENDENCIES "")
|
SET ( ASSIMP_QT_VIEWER_DEPENDENCIES "")
|
||||||
|
|
||||||
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)
|
IF (NOT Qt5_FOUND)
|
||||||
SET ( ASSIMP_QT_VIEWER_DEPENDENCIES "${ASSIMP_QT_VIEWER_DEPENDENCIES} Qt5")
|
SET ( ASSIMP_QT_VIEWER_DEPENDENCIES "${ASSIMP_QT_VIEWER_DEPENDENCIES} Qt5")
|
||||||
ENDIF (NOT Qt5_FOUND)
|
ENDIF (NOT Qt5_FOUND)
|
||||||
|
|
||||||
ENDIF(ASSIMP_QT4_VIEWER)
|
|
||||||
|
|
||||||
IF (NOT OPENGL_FOUND)
|
IF (NOT OPENGL_FOUND)
|
||||||
SET ( ASSIMP_QT_VIEWER_DEPENDENCIES "${ASSIMP_QT_VIEWER_DEPENDENCIES} OpengGL")
|
SET ( ASSIMP_QT_VIEWER_DEPENDENCIES "${ASSIMP_QT_VIEWER_DEPENDENCIES} OpengGL")
|
||||||
ENDIF (NOT OPENGL_FOUND)
|
ENDIF (NOT OPENGL_FOUND)
|
||||||
|
|
||||||
MESSAGE (WARNING "Build of assimp_qt_viewer is disabled. Unsatisfied dendencies: ${ASSIMP_QT_VIEWER_DEPENDENCIES}")
|
MESSAGE (WARNING "Build of assimp_qt_viewer is disabled. Unsatisfied dendencies: ${ASSIMP_QT_VIEWER_DEPENDENCIES}")
|
||||||
ENDIF((Qt4_FOUND OR Qt5Widgets_FOUND) AND OPENGL_FOUND)
|
ENDIF( Qt5Widgets_FOUND AND OPENGL_FOUND)
|
||||||
|
|
||||||
IF(VIEWER_BUILD)
|
IF(VIEWER_BUILD)
|
||||||
INCLUDE_DIRECTORIES(
|
INCLUDE_DIRECTORIES(
|
||||||
|
@ -68,26 +49,13 @@ IF(VIEWER_BUILD)
|
||||||
mainwindow.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")
|
MESSAGE("assimp_qt_viewer use Qt5")
|
||||||
INCLUDE_DIRECTORIES(${Qt5Widgets_INCLUDES})
|
INCLUDE_DIRECTORIES(${Qt5Widgets_INCLUDES})
|
||||||
qt5_wrap_ui(UISrcs mainwindow.ui)
|
qt5_wrap_ui(UISrcs mainwindow.ui)
|
||||||
qt5_wrap_cpp(MOCrcs mainwindow.hpp glview.hpp)
|
qt5_wrap_cpp(MOCrcs mainwindow.hpp glview.hpp)
|
||||||
ENDIF()
|
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME} ${assimp_qt_viewer_SRCS} ${UISrcs} ${MOCrcs})
|
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)
|
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(WIN32) # Check if we are on Windows
|
||||||
IF(MSVC) # Check if we are using the Visual Studio compiler
|
IF(MSVC) # Check if we are using the Visual Studio compiler
|
||||||
|
|
|
@ -59,14 +59,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
#include "stb_image.h"
|
#include "stb_image.h"
|
||||||
/*
|
|
||||||
#ifndef __unused
|
|
||||||
#define __unused __attribute__((unused))
|
|
||||||
#endif // __unused
|
|
||||||
*/
|
|
||||||
/**********************************/
|
|
||||||
/********** SHelper_Mesh **********/
|
|
||||||
/**********************************/
|
|
||||||
|
|
||||||
CGLView::SHelper_Mesh::SHelper_Mesh(const size_t pQuantity_Point, const size_t pQuantity_Line, const size_t pQuantity_Triangle, const SBBox& pBBox)
|
CGLView::SHelper_Mesh::SHelper_Mesh(const size_t pQuantity_Point, const size_t pQuantity_Line, const size_t pQuantity_Triangle, const SBBox& pBBox)
|
||||||
: Quantity_Point(pQuantity_Point)
|
: Quantity_Point(pQuantity_Point)
|
||||||
|
@ -84,12 +76,7 @@ CGLView::SHelper_Mesh::~SHelper_Mesh() {
|
||||||
delete [] Index_Triangle;
|
delete [] Index_Triangle;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**********************************/
|
void CGLView::SHelper_Camera::SetDefault() {
|
||||||
/********** SHelper_Mesh **********/
|
|
||||||
/**********************************/
|
|
||||||
|
|
||||||
void CGLView::SHelper_Camera::SetDefault()
|
|
||||||
{
|
|
||||||
Position.Set(0, 0, 0);
|
Position.Set(0, 0, 0);
|
||||||
Target.Set(0, 0, -1);
|
Target.Set(0, 0, -1);
|
||||||
Rotation_AroundCamera = aiMatrix4x4();
|
Rotation_AroundCamera = aiMatrix4x4();
|
||||||
|
@ -97,37 +84,6 @@ void CGLView::SHelper_Camera::SetDefault()
|
||||||
Translation_ToScene.Set(0, 0, 2);
|
Translation_ToScene.Set(0, 0, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**********************************/
|
|
||||||
/************ 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
|
|
||||||
|
|
||||||
static void set_float4(float f[4], float a, float b, float c, float d) {
|
static void set_float4(float f[4], float a, float b, float c, float d) {
|
||||||
f[0] = a;
|
f[0] = a;
|
||||||
f[1] = b;
|
f[1] = b;
|
||||||
|
@ -142,8 +98,7 @@ static void color4_to_float4(const aiColor4D *c, float f[4]) {
|
||||||
f[3] = c->a;
|
f[3] = c->a;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGLView::Material_Apply(const aiMaterial* pMaterial)
|
void CGLView::Material_Apply(const aiMaterial* pMaterial) {
|
||||||
{
|
|
||||||
GLfloat tcol[4];
|
GLfloat tcol[4];
|
||||||
aiColor4D taicol;
|
aiColor4D taicol;
|
||||||
unsigned int max;
|
unsigned int max;
|
||||||
|
@ -154,9 +109,9 @@ void CGLView::Material_Apply(const aiMaterial* pMaterial)
|
||||||
///TODO: cache materials
|
///TODO: cache materials
|
||||||
// Disable color material because glMaterial is used.
|
// Disable color material because glMaterial is used.
|
||||||
glDisable(GL_COLOR_MATERIAL);///TODO: cache
|
glDisable(GL_COLOR_MATERIAL);///TODO: cache
|
||||||
|
|
||||||
// Set texture. If assigned.
|
// Set texture. If assigned.
|
||||||
if(AI_SUCCESS == pMaterial->GetTexture(aiTextureType_DIFFUSE, texture_index, &texture_path))
|
if(AI_SUCCESS == pMaterial->GetTexture(aiTextureType_DIFFUSE, texture_index, &texture_path)) {
|
||||||
{
|
|
||||||
//bind texture
|
//bind texture
|
||||||
unsigned int texture_ID = mTexture_IDMap.value(texture_path.data, 0);
|
unsigned int texture_ID = mTexture_IDMap.value(texture_path.data, 0);
|
||||||
|
|
||||||
|
@ -167,19 +122,26 @@ void CGLView::Material_Apply(const aiMaterial* pMaterial)
|
||||||
//
|
//
|
||||||
// Diffuse
|
// Diffuse
|
||||||
set_float4(tcol, 0.8f, 0.8f, 0.8f, 1.0f);
|
set_float4(tcol, 0.8f, 0.8f, 0.8f, 1.0f);
|
||||||
if(AI_SUCCESS == aiGetMaterialColor(pMaterial, AI_MATKEY_COLOR_DIFFUSE, &taicol)) color4_to_float4(&taicol, tcol);
|
if ( AI_SUCCESS == aiGetMaterialColor( pMaterial, AI_MATKEY_COLOR_DIFFUSE, &taicol )) {
|
||||||
|
color4_to_float4( &taicol, tcol );
|
||||||
|
}
|
||||||
|
|
||||||
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, tcol);
|
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, tcol);
|
||||||
|
|
||||||
// Specular
|
// Specular
|
||||||
set_float4(tcol, 0.0f, 0.0f, 0.0f, 1.0f);
|
set_float4(tcol, 0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
if(AI_SUCCESS == aiGetMaterialColor(pMaterial, AI_MATKEY_COLOR_SPECULAR, &taicol)) color4_to_float4(&taicol, tcol);
|
if ( AI_SUCCESS == aiGetMaterialColor( pMaterial, AI_MATKEY_COLOR_SPECULAR, &taicol )) {
|
||||||
|
color4_to_float4( &taicol, tcol );
|
||||||
|
}
|
||||||
|
|
||||||
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, tcol);
|
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, tcol);
|
||||||
// Ambient
|
// Ambient
|
||||||
set_float4(tcol, 0.2f, 0.2f, 0.2f, 1.0f);
|
set_float4(tcol, 0.2f, 0.2f, 0.2f, 1.0f);
|
||||||
if(AI_SUCCESS == aiGetMaterialColor(pMaterial, AI_MATKEY_COLOR_AMBIENT, &taicol)) color4_to_float4(&taicol, tcol);
|
if ( AI_SUCCESS == aiGetMaterialColor( pMaterial, AI_MATKEY_COLOR_AMBIENT, &taicol )) {
|
||||||
|
color4_to_float4( &taicol, tcol );
|
||||||
|
}
|
||||||
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, tcol);
|
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, tcol);
|
||||||
|
|
||||||
// Emission
|
// Emission
|
||||||
set_float4(tcol, 0.0f, 0.0f, 0.0f, 1.0f);
|
set_float4(tcol, 0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
if(AI_SUCCESS == aiGetMaterialColor(pMaterial, AI_MATKEY_COLOR_EMISSIVE, &taicol)) color4_to_float4(&taicol, tcol);
|
if(AI_SUCCESS == aiGetMaterialColor(pMaterial, AI_MATKEY_COLOR_EMISSIVE, &taicol)) color4_to_float4(&taicol, tcol);
|
||||||
|
@ -193,12 +155,9 @@ void CGLView::Material_Apply(const aiMaterial* pMaterial)
|
||||||
// Shininess strength
|
// Shininess strength
|
||||||
max = 1;
|
max = 1;
|
||||||
ret2 = aiGetMaterialFloatArray(pMaterial, AI_MATKEY_SHININESS_STRENGTH, &strength, &max);
|
ret2 = aiGetMaterialFloatArray(pMaterial, AI_MATKEY_SHININESS_STRENGTH, &strength, &max);
|
||||||
if((ret1 == AI_SUCCESS) && (ret2 == AI_SUCCESS))
|
if((ret1 == AI_SUCCESS) && (ret2 == AI_SUCCESS)) {
|
||||||
{
|
|
||||||
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess * strength);///TODO: cache
|
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess * strength);///TODO: cache
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0.0f);///TODO: cache
|
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0.0f);///TODO: cache
|
||||||
set_float4(tcol, 0.0f, 0.0f, 0.0f, 0.0f);
|
set_float4(tcol, 0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, tcol);
|
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, tcol);
|
||||||
|
@ -476,26 +435,15 @@ void CGLView::BBox_GetFromVertices(const aiVector3D* pVertices, const size_t pVe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************/
|
void CGLView::LogInfo(const QString& pMessage) {
|
||||||
/************************ Logging functions *************************/
|
|
||||||
/********************************************************************/
|
|
||||||
|
|
||||||
void CGLView::LogInfo(const QString& pMessage)
|
|
||||||
{
|
|
||||||
Assimp::DefaultLogger::get()->info(pMessage.toStdString());
|
Assimp::DefaultLogger::get()->info(pMessage.toStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGLView::LogError(const QString& pMessage)
|
void CGLView::LogError(const QString& pMessage) {
|
||||||
{
|
|
||||||
Assimp::DefaultLogger::get()->error(pMessage.toStdString());
|
Assimp::DefaultLogger::get()->error(pMessage.toStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************/
|
void CGLView::Draw_Node(const aiNode* pNode) {
|
||||||
/************************** Draw functions **************************/
|
|
||||||
/********************************************************************/
|
|
||||||
|
|
||||||
void CGLView::Draw_Node(const aiNode* pNode)
|
|
||||||
{
|
|
||||||
aiMatrix4x4 mat_node = pNode->mTransformation;
|
aiMatrix4x4 mat_node = pNode->mTransformation;
|
||||||
|
|
||||||
// Apply node transformation matrix.
|
// Apply node transformation matrix.
|
||||||
|
@ -606,13 +554,9 @@ void CGLView::Draw_BBox(const SBBox& pBBox)
|
||||||
glBindTexture(GL_TEXTURE_1D, 0);
|
glBindTexture(GL_TEXTURE_1D, 0);
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
glBindTexture(GL_TEXTURE_3D, 0);
|
glBindTexture(GL_TEXTURE_3D, 0);
|
||||||
#if ASSIMP_QT4_VIEWER
|
|
||||||
qglColor(QColor(Qt::white));
|
|
||||||
#else
|
|
||||||
const QColor c_w(Qt::white);
|
const QColor c_w(Qt::white);
|
||||||
|
|
||||||
glColor3f(c_w.redF(), c_w.greenF(), c_w.blueF());
|
glColor3f(c_w.redF(), c_w.greenF(), c_w.blueF());
|
||||||
#endif // ASSIMP_QT4_VIEWER
|
|
||||||
|
|
||||||
glBegin(GL_LINE_STRIP);
|
glBegin(GL_LINE_STRIP);
|
||||||
# ifdef ASSIMP_DOUBLE_PRECISION
|
# ifdef ASSIMP_DOUBLE_PRECISION
|
||||||
|
@ -640,49 +584,28 @@ void CGLView::Draw_BBox(const SBBox& pBBox)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGLView::Enable_Textures(const bool pEnable)
|
void CGLView::Enable_Textures(const bool pEnable) {
|
||||||
{
|
if(pEnable) {
|
||||||
#if !ASSIMP_QT4_VIEWER
|
|
||||||
ConditionalContextControl_Begin;
|
|
||||||
#endif // ASSIMP_QT4_VIEWER
|
|
||||||
|
|
||||||
if(pEnable)
|
|
||||||
{
|
|
||||||
glEnable(GL_TEXTURE_1D);
|
glEnable(GL_TEXTURE_1D);
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
glEnable(GL_TEXTURE_3D);
|
glEnable(GL_TEXTURE_3D);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
glDisable(GL_TEXTURE_1D);
|
glDisable(GL_TEXTURE_1D);
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
glDisable(GL_TEXTURE_3D);
|
glDisable(GL_TEXTURE_3D);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !ASSIMP_QT4_VIEWER
|
|
||||||
ConditionalContextControl_End;
|
|
||||||
#endif // ASSIMP_QT4_VIEWER
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************/
|
void CGLView::initializeGL() {
|
||||||
/*********************** Override functions ************************/
|
|
||||||
/********************************************************************/
|
|
||||||
|
|
||||||
void CGLView::initializeGL()
|
|
||||||
{
|
|
||||||
#if ASSIMP_QT4_VIEWER
|
|
||||||
qglClearColor(Qt::gray);
|
|
||||||
#else
|
|
||||||
mGLContext_Current = true;
|
mGLContext_Current = true;
|
||||||
initializeOpenGLFunctions();
|
initializeOpenGLFunctions();
|
||||||
glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
|
glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
|
||||||
#endif // ASSIMP_QT4_VIEWER
|
|
||||||
glShadeModel(GL_SMOOTH);
|
glShadeModel(GL_SMOOTH);
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glEnable(GL_NORMALIZE);
|
glEnable(GL_NORMALIZE);
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
//glEnable( GL_MULTISAMPLE );
|
glEnable( GL_MULTISAMPLE );
|
||||||
|
|
||||||
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT);
|
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT);
|
||||||
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
|
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
|
||||||
|
@ -694,25 +617,14 @@ void CGLView::initializeGL()
|
||||||
glCullFace(GL_BACK);
|
glCullFace(GL_BACK);
|
||||||
|
|
||||||
glFrontFace(GL_CCW);
|
glFrontFace(GL_CCW);
|
||||||
|
|
||||||
#if !ASSIMP_QT4_VIEWER
|
|
||||||
mGLContext_Current = false;
|
|
||||||
#endif // ASSIMP_QT4_VIEWER
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGLView::resizeGL(int pWidth, int pHeight)
|
void CGLView::resizeGL(int width, int height) {
|
||||||
{
|
mCamera_Viewport_AspectRatio = (GLdouble)width / height;
|
||||||
#if !ASSIMP_QT4_VIEWER
|
glViewport(0, 0, width, height);
|
||||||
mGLContext_Current = true;
|
|
||||||
#endif // ASSIMP_QT4_VIEWER
|
|
||||||
mCamera_Viewport_AspectRatio = (GLdouble)pWidth / pHeight;
|
|
||||||
glViewport(0, 0, pWidth, pHeight);
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluPerspective(mCamera_FOVY, mCamera_Viewport_AspectRatio, 1.0, 100000.0);///TODO: znear/zfar depend on scene size.
|
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() {
|
void CGLView::drawCoordSystem() {
|
||||||
|
@ -725,18 +637,7 @@ void CGLView::drawCoordSystem() {
|
||||||
glBindTexture(GL_TEXTURE_3D, 0);
|
glBindTexture(GL_TEXTURE_3D, 0);
|
||||||
glEnable(GL_COLOR_MATERIAL);
|
glEnable(GL_COLOR_MATERIAL);
|
||||||
glBegin(GL_LINES);
|
glBegin(GL_LINES);
|
||||||
#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
|
|
||||||
qglColor(QColor(Qt::green)), glVertex3f(0.0, 0.0, 0.0), glVertex3f(0.0, 100000.0, 0.0);
|
|
||||||
qglColor(QColor(Qt::magenta)), glVertex3f(0.0, 0.0, 0.0), glVertex3f(0.0, -100000.0, 0.0);
|
|
||||||
// Z, -Z
|
|
||||||
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));
|
|
||||||
#else
|
|
||||||
// X, -X
|
// X, -X
|
||||||
glColor3f(1.0f, 0.0f, 0.0f), glVertex3f(0.0, 0.0, 0.0), glVertex3f(100000.0, 0.0, 0.0);
|
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);
|
glColor3f(0.5f, 0.5f, 1.0f), glVertex3f(0.0, 0.0, 0.0), glVertex3f(-100000.0, 0.0, 0.0);
|
||||||
|
@ -747,19 +648,15 @@ void CGLView::drawCoordSystem() {
|
||||||
glColor3f(0.0f, 0.0f, 1.0f), glVertex3f(0.0, 0.0, 0.0), glVertex3f(0.0, 0.0, 100000.0);
|
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, 0.0f), glVertex3f(0.0, 0.0, 0.0), glVertex3f(0.0, 0.0, -100000.0);
|
||||||
glColor3f(1.0f, 1.0f, 1.0f);
|
glColor3f(1.0f, 1.0f, 1.0f);
|
||||||
#endif // ASSIMP_QT4_VIEWER
|
|
||||||
glEnd();
|
glEnd();
|
||||||
// Restore previous state of lighting.
|
// Restore previous state of lighting.
|
||||||
if(mLightingEnabled) glEnable(GL_LIGHTING);
|
if (mLightingEnabled) {
|
||||||
|
glEnable( GL_LIGHTING );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGLView::paintGL()
|
void CGLView::paintGL() {
|
||||||
{
|
|
||||||
#if !ASSIMP_QT4_VIEWER
|
|
||||||
mGLContext_Current = true;
|
|
||||||
#endif // ASSIMP_QT4_VIEWER
|
|
||||||
|
|
||||||
QTime time_paintbegin;
|
QTime time_paintbegin;
|
||||||
|
|
||||||
time_paintbegin = QTime::currentTime();
|
time_paintbegin = QTime::currentTime();
|
||||||
|
@ -767,6 +664,7 @@ void CGLView::paintGL()
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
// Apply current camera transformations.
|
// Apply current camera transformations.
|
||||||
#if ASSIMP_DOUBLE_PRECISION
|
#if ASSIMP_DOUBLE_PRECISION
|
||||||
glMultMatrixd((GLdouble*)&mHelper_Camera.Rotation_AroundCamera);
|
glMultMatrixd((GLdouble*)&mHelper_Camera.Rotation_AroundCamera);
|
||||||
|
@ -779,58 +677,38 @@ void CGLView::paintGL()
|
||||||
#endif // ASSIMP_DOUBLE_PRECISION
|
#endif // ASSIMP_DOUBLE_PRECISION
|
||||||
|
|
||||||
// Coordinate system
|
// Coordinate system
|
||||||
if (mScene_AxesEnabled == true)
|
if ( mScene_AxesEnabled ) {
|
||||||
{
|
|
||||||
drawCoordSystem();
|
drawCoordSystem();
|
||||||
}
|
}
|
||||||
|
|
||||||
glDisable(GL_COLOR_MATERIAL);
|
glDisable(GL_COLOR_MATERIAL);
|
||||||
|
|
||||||
// Scene
|
// Scene
|
||||||
if(mScene != nullptr)
|
if(mScene != nullptr) {
|
||||||
{
|
|
||||||
Draw_Node(mScene->mRootNode);
|
Draw_Node(mScene->mRootNode);
|
||||||
// Scene BBox
|
// Scene BBox
|
||||||
if(mScene_DrawBBox) Draw_BBox(mScene_BBox);
|
if (mScene_DrawBBox) {
|
||||||
|
Draw_BBox( mScene_BBox );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emit Paint_Finished((size_t)time_paintbegin.msecsTo(QTime::currentTime()), mHelper_Camera.Translation_ToScene.Length());
|
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************/
|
|
||||||
/********************** Constructor/Destructor **********************/
|
|
||||||
/********************************************************************/
|
|
||||||
|
|
||||||
CGLView::CGLView(QWidget *pParent)
|
CGLView::CGLView( QWidget *pParent )
|
||||||
#if ASSIMP_QT4_VIEWER
|
: QOpenGLWidget( pParent )
|
||||||
: QGLWidget(QGLFormat(QGL::DoubleBuffer | QGL::DepthBuffer), pParent)
|
, mGLContext_Current( false ) {
|
||||||
#else
|
|
||||||
: QOpenGLWidget(pParent), mGLContext_Current(false)
|
|
||||||
#endif // ASSIMP_QT4_VIEWER
|
|
||||||
{
|
|
||||||
// set initial view
|
// set initial view
|
||||||
mHelper_CameraDefault.SetDefault();
|
mHelper_CameraDefault.SetDefault();
|
||||||
Camera_Set(0);
|
Camera_Set( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
CGLView::~CGLView()
|
CGLView::~CGLView() {
|
||||||
{
|
|
||||||
FreeScene();
|
FreeScene();
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************/
|
void CGLView::FreeScene() {
|
||||||
/********************* Scene control functions **********************/
|
|
||||||
/********************************************************************/
|
|
||||||
|
|
||||||
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.
|
// Set scene to null and after that \ref paintGL will not try to render it.
|
||||||
mScene = nullptr;
|
mScene = nullptr;
|
||||||
// Clean helper objects.
|
// Clean helper objects.
|
||||||
|
@ -860,21 +738,14 @@ void CGLView::FreeScene()
|
||||||
mTexture_IDMap.clear();
|
mTexture_IDMap.clear();
|
||||||
delete [] id_tex;
|
delete [] id_tex;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !ASSIMP_QT4_VIEWER
|
|
||||||
ConditionalContextControl_End;
|
|
||||||
#endif // ASSIMP_QT4_VIEWER
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGLView::SetScene(const aiScene *pScene, const QString& pScenePath)
|
void CGLView::SetScene(const aiScene *pScene, const QString& pScenePath) {
|
||||||
{
|
|
||||||
#if !ASSIMP_QT4_VIEWER
|
|
||||||
ConditionalContextControl_Begin;
|
|
||||||
#endif // ASSIMP_QT4_VIEWER
|
|
||||||
|
|
||||||
FreeScene();// Clear old data
|
FreeScene();// Clear old data
|
||||||
// Why checking here, not at begin of function. Because old scene may not exist at know. So, need cleanup.
|
// Why checking here, not at begin of function. Because old scene may not exist at know. So, need cleanup.
|
||||||
if(pScene == nullptr) return;
|
if (pScene == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
mScene = pScene;// Copy pointer of new scene.
|
mScene = pScene;// Copy pointer of new scene.
|
||||||
|
|
||||||
|
@ -900,7 +771,7 @@ void CGLView::SetScene(const aiScene *pScene, const QString& pScenePath)
|
||||||
|
|
||||||
BBox_GetFromVertices(mesh_cur.mVertices, mesh_cur.mNumVertices, mesh_bbox);
|
BBox_GetFromVertices(mesh_cur.mVertices, mesh_cur.mNumVertices, mesh_bbox);
|
||||||
//
|
//
|
||||||
// Create vertices indices arrays splited by primitive type.
|
// Create vertices indices arrays splitted by primitive type.
|
||||||
//
|
//
|
||||||
size_t indcnt_p = 0;// points quantity
|
size_t indcnt_p = 0;// points quantity
|
||||||
size_t indcnt_l = 0;// lines quantity
|
size_t indcnt_l = 0;// lines quantity
|
||||||
|
@ -1065,7 +936,10 @@ void CGLView::SetScene(const aiScene *pScene, const QString& pScenePath)
|
||||||
}// switch(light_cur.mType)
|
}// switch(light_cur.mType)
|
||||||
|
|
||||||
// Add light source
|
// Add light source
|
||||||
if(name.isEmpty()) name += QString("%1").arg(idx_light);// Use index if name is empty.
|
// Use index if name is empty.
|
||||||
|
if (name.isEmpty()) {
|
||||||
|
name += QString( "%1" ).arg( idx_light );
|
||||||
|
}
|
||||||
|
|
||||||
Lighting_EditSource(idx_light, lp);
|
Lighting_EditSource(idx_light, lp);
|
||||||
emit SceneObject_LightSource(name);// Light source will be enabled in signal handler.
|
emit SceneObject_LightSource(name);// Light source will be enabled in signal handler.
|
||||||
|
@ -1098,50 +972,20 @@ void CGLView::SetScene(const aiScene *pScene, const QString& pScenePath)
|
||||||
emit SceneObject_Camera(mScene->mCameras[idx_cam]->mName.C_Str());
|
emit SceneObject_Camera(mScene->mCameras[idx_cam]->mName.C_Str());
|
||||||
}
|
}
|
||||||
}// if(!mScene->HasCameras()) else
|
}// if(!mScene->HasCameras()) else
|
||||||
|
|
||||||
#if !ASSIMP_QT4_VIEWER
|
|
||||||
ConditionalContextControl_End;
|
|
||||||
#endif // ASSIMP_QT4_VIEWER
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************/
|
void CGLView::Lighting_Enable() {
|
||||||
/******************** Lighting control functions ********************/
|
|
||||||
/********************************************************************/
|
|
||||||
|
|
||||||
void CGLView::Lighting_Enable()
|
|
||||||
{
|
|
||||||
#if !ASSIMP_QT4_VIEWER
|
|
||||||
ConditionalContextControl_Begin;
|
|
||||||
#endif // ASSIMP_QT4_VIEWER
|
|
||||||
|
|
||||||
mLightingEnabled = true;
|
mLightingEnabled = true;
|
||||||
glEnable(GL_LIGHTING);
|
glEnable(GL_LIGHTING);
|
||||||
|
|
||||||
#if !ASSIMP_QT4_VIEWER
|
|
||||||
ConditionalContextControl_End;
|
|
||||||
#endif // ASSIMP_QT4_VIEWER
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGLView::Lighting_Disable()
|
void CGLView::Lighting_Disable() {
|
||||||
{
|
glDisable( GL_LIGHTING );
|
||||||
#if !ASSIMP_QT4_VIEWER
|
|
||||||
ConditionalContextControl_Begin;
|
|
||||||
#endif // ASSIMP_QT4_VIEWER
|
|
||||||
|
|
||||||
glDisable(GL_LIGHTING);
|
|
||||||
mLightingEnabled = false;
|
mLightingEnabled = false;
|
||||||
|
|
||||||
#if !ASSIMP_QT4_VIEWER
|
|
||||||
ConditionalContextControl_End;
|
|
||||||
#endif // ASSIMP_QT4_VIEWER
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGLView::Lighting_EditSource(const size_t pLightNumber, const SLightParameters& pLightParameters)
|
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;
|
const size_t light_num = GL_LIGHT0 + pLightNumber;
|
||||||
|
|
||||||
GLfloat farr[4];
|
GLfloat farr[4];
|
||||||
|
@ -1214,46 +1058,21 @@ void CGLView::Lighting_EditSource(const size_t pLightNumber, const SLightParamet
|
||||||
glLightf(light_num, GL_SPOT_CUTOFF, 180.0);
|
glLightf(light_num, GL_SPOT_CUTOFF, 180.0);
|
||||||
break;
|
break;
|
||||||
}// switch(pLightParameters.Type)
|
}// switch(pLightParameters.Type)
|
||||||
|
|
||||||
#if !ASSIMP_QT4_VIEWER
|
|
||||||
ConditionalContextControl_End;
|
|
||||||
#endif // ASSIMP_QT4_VIEWER
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGLView::Lighting_EnableSource(const size_t pLightNumber)
|
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;
|
if(pLightNumber >= GL_MAX_LIGHTS) return;///TODO: return value;
|
||||||
|
|
||||||
glEnable(GL_LIGHT0 + pLightNumber);
|
glEnable(GL_LIGHT0 + pLightNumber);
|
||||||
|
|
||||||
#if !ASSIMP_QT4_VIEWER
|
|
||||||
ConditionalContextControl_End;
|
|
||||||
#endif // ASSIMP_QT4_VIEWER
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGLView::Lighting_DisableSource(const size_t pLightNumber)
|
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;
|
if(pLightNumber >= GL_MAX_LIGHTS) return;///TODO: return value;
|
||||||
|
|
||||||
glDisable(GL_LIGHT0 + pLightNumber);
|
glDisable(GL_LIGHT0 + pLightNumber);
|
||||||
|
|
||||||
#if !ASSIMP_QT4_VIEWER
|
|
||||||
ConditionalContextControl_End;
|
|
||||||
#endif // ASSIMP_QT4_VIEWER
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************/
|
|
||||||
/******************** Cameras control functions *********************/
|
|
||||||
/********************************************************************/
|
|
||||||
|
|
||||||
void CGLView::Camera_Set(const size_t pCameraNumber)
|
void CGLView::Camera_Set(const size_t pCameraNumber)
|
||||||
{
|
{
|
||||||
SHelper_Camera& hcam = mHelper_Camera;// reference with short name for conveniance.
|
SHelper_Camera& hcam = mHelper_Camera;// reference with short name for conveniance.
|
||||||
|
|
|
@ -54,22 +54,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
using namespace Assimp;
|
using namespace Assimp;
|
||||||
|
|
||||||
/**********************************/
|
|
||||||
/************ Functions ***********/
|
|
||||||
/**********************************/
|
|
||||||
|
|
||||||
/********************************************************************/
|
void MainWindow::ImportFile(const QString &pFileName) {
|
||||||
/********************* Import/Export functions **********************/
|
QTime time_begin = QTime::currentTime();
|
||||||
/********************************************************************/
|
|
||||||
|
|
||||||
void MainWindow::ImportFile(const QString &pFileName)
|
if ( mScene != nullptr ) {
|
||||||
{
|
|
||||||
using namespace Assimp;
|
|
||||||
|
|
||||||
QTime time_begin = QTime::currentTime();
|
|
||||||
|
|
||||||
if(mScene != nullptr)
|
|
||||||
{
|
|
||||||
mImporter.FreeScene();
|
mImporter.FreeScene();
|
||||||
mGLView->FreeScene();
|
mGLView->FreeScene();
|
||||||
}
|
}
|
||||||
|
@ -77,8 +66,7 @@ QTime time_begin = QTime::currentTime();
|
||||||
// Try to import scene.
|
// Try to import scene.
|
||||||
mScene = mImporter.ReadFile(pFileName.toStdString(), aiProcess_Triangulate | aiProcess_GenNormals | aiProcess_ValidateDataStructure | \
|
mScene = mImporter.ReadFile(pFileName.toStdString(), aiProcess_Triangulate | aiProcess_GenNormals | aiProcess_ValidateDataStructure | \
|
||||||
aiProcess_GenUVCoords | aiProcess_TransformUVCoords | aiProcess_FlipUVs);
|
aiProcess_GenUVCoords | aiProcess_TransformUVCoords | aiProcess_FlipUVs);
|
||||||
if(mScene != nullptr)
|
if ( mScene != nullptr ) {
|
||||||
{
|
|
||||||
ui->lblLoadTime->setText(QString::number(time_begin.secsTo(QTime::currentTime())));
|
ui->lblLoadTime->setText(QString::number(time_begin.secsTo(QTime::currentTime())));
|
||||||
LogInfo("Import done: " + pFileName);
|
LogInfo("Import done: " + pFileName);
|
||||||
// Prepare widgets for new scene.
|
// Prepare widgets for new scene.
|
||||||
|
@ -100,8 +88,7 @@ QTime time_begin = QTime::currentTime();
|
||||||
size_t qty_face = 0;
|
size_t qty_face = 0;
|
||||||
size_t qty_vert = 0;
|
size_t qty_vert = 0;
|
||||||
|
|
||||||
for(size_t idx_mesh = 0; idx_mesh < mScene->mNumMeshes; idx_mesh++)
|
for(size_t idx_mesh = 0; idx_mesh < mScene->mNumMeshes; idx_mesh++) {
|
||||||
{
|
|
||||||
qty_face += mScene->mMeshes[idx_mesh]->mNumFaces;
|
qty_face += mScene->mMeshes[idx_mesh]->mNumFaces;
|
||||||
qty_vert += mScene->mMeshes[idx_mesh]->mNumVertices;
|
qty_vert += mScene->mMeshes[idx_mesh]->mNumVertices;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue