Merge branch 'master' into fix-vector-out-of-bound-access
commit
bf7ec7d130
|
@ -12,6 +12,8 @@ build
|
|||
bin/
|
||||
lib/
|
||||
|
||||
# QtCreator
|
||||
CMakeLists.txt.user
|
||||
|
||||
# Generated
|
||||
assimp.pc
|
||||
|
|
|
@ -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)
|
||||
ENDIF ( ASSIMP_BUILD_ASSIMP_TOOLS )
|
||||
|
||||
IF ( ASSIMP_BUILD_SAMPLES)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -970,6 +970,8 @@ void Importer::GetExtensionList(aiString& szOut) const
|
|||
(*i)->GetExtensionList(str);
|
||||
}
|
||||
|
||||
// List can be empty
|
||||
if( !str.empty() ) {
|
||||
for (std::set<std::string>::const_iterator it = str.begin();; ) {
|
||||
szOut.Append("*.");
|
||||
szOut.Append((*it).c_str());
|
||||
|
@ -979,6 +981,7 @@ void Importer::GetExtensionList(aiString& szOut) const
|
|||
}
|
||||
szOut.Append(";");
|
||||
}
|
||||
}
|
||||
ASSIMP_END_EXCEPTION_REGION(void);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Scene> s = scenes.Retrieve(sceneIndex);
|
||||
|
||||
this->scene = s;
|
||||
if (Value* scenesArray = FindArray(doc, "scenes")) {
|
||||
if (sceneIndex < scenesArray->Size()) {
|
||||
this->scene = scenes.Retrieve(sceneIndex);
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up
|
||||
|
|
|
@ -516,7 +516,7 @@ void glTF2Exporter::ExportMaterials()
|
|||
if (mat->Get(AI_MATKEY_GLTF_PBRSPECULARGLOSSINESS_GLOSSINESS_FACTOR, pbrSG.glossinessFactor) != AI_SUCCESS) {
|
||||
float shininess;
|
||||
|
||||
if (mat->Get(AI_MATKEY_SHININESS, shininess)) {
|
||||
if (mat->Get(AI_MATKEY_SHININESS, shininess) == AI_SUCCESS) {
|
||||
pbrSG.glossinessFactor = shininess / 1000;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -3,12 +3,55 @@ 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)
|
||||
OPTION( ASSIMP_QT4_VIEWER
|
||||
"Set to ON to enable Qt4 against Qt5 for assimp_qt_viewer"
|
||||
OFF
|
||||
)
|
||||
|
||||
include_directories(
|
||||
${Qt5Widgets_INCLUDES}
|
||||
FIND_PACKAGE(DevIL QUIET)
|
||||
FIND_PACKAGE(OpenGL QUIET)
|
||||
|
||||
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)
|
||||
|
||||
SET(VIEWER_BUILD:BOOL FALSE)
|
||||
|
||||
IF((Qt4_FOUND OR Qt5Widgets_FOUND) AND IL_FOUND AND OPENGL_FOUND)
|
||||
SET(VIEWER_BUILD TRUE)
|
||||
|
||||
ELSE((Qt4_FOUND OR Qt5Widgets_FOUND) AND IL_FOUND AND OPENGL_FOUND)
|
||||
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)
|
||||
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}
|
||||
|
@ -17,30 +60,46 @@ include_directories(
|
|||
${IL_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
link_directories(${Assimp_BINARY_DIR})
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pedantic -Wall")
|
||||
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)
|
||||
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
|
||||
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)
|
||||
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)
|
||||
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()
|
||||
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}")
|
||||
SET_PROPERTY(TARGET ${PROJECT_NAME} PROPERTY DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
|
||||
INSTALL(TARGETS assimp_qt_viewer DESTINATION "${ASSIMP_BIN_INSTALL_DIR}")
|
||||
ENDIF(VIEWER_BUILD)
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
|
||||
#include "glview.hpp"
|
||||
|
||||
// Header files, Qt.
|
||||
#include <QTime>
|
||||
|
||||
// Header files, OpenGL.
|
||||
#if defined(__APPLE__)
|
||||
# include <OpenGL/glu.h>
|
||||
|
@ -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,9 +436,9 @@ 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;
|
||||
|
||||
// search minimal...
|
||||
AssignIfLesser(&pBBox.Minimum.x, x);
|
||||
|
@ -446,7 +476,12 @@ void CGLView::Draw_Node(const aiNode* pNode)
|
|||
// Apply node transformation matrix.
|
||||
mat_node.Transpose();
|
||||
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 +508,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 +531,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 +544,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 +581,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,30 +633,10 @@ void CGLView::Enable_Textures(const bool pEnable)
|
|||
glDisable(GL_TEXTURE_2D);
|
||||
glDisable(GL_TEXTURE_3D);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
#if !ASSIMP_QT4_VIEWER
|
||||
ConditionalContextControl_End;
|
||||
#endif // ASSIMP_QT4_VIEWER
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
|
@ -590,7 +645,13 @@ void CGLView::Enable_Reload_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);
|
||||
|
@ -607,23 +668,38 @@ 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() {
|
||||
// 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);
|
||||
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);
|
||||
|
@ -634,11 +710,30 @@ 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));
|
||||
#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()
|
||||
{
|
||||
#if !ASSIMP_QT4_VIEWER
|
||||
mGLContext_Current = true;
|
||||
#endif // ASSIMP_QT4_VIEWER
|
||||
|
||||
QTime time_paintbegin;
|
||||
|
||||
time_paintbegin = QTime::currentTime();
|
||||
|
@ -647,30 +742,36 @@ 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 ( 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)
|
||||
{
|
||||
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
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
|
@ -678,10 +779,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);
|
||||
|
@ -698,6 +801,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.
|
||||
|
@ -727,10 +834,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;
|
||||
|
@ -957,6 +1072,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
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
|
@ -965,39 +1084,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
|
||||
|
@ -1008,20 +1153,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
|
||||
|
@ -1031,20 +1176,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
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
|
@ -1096,23 +1261,29 @@ 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));
|
||||
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));
|
||||
if(pMatrix_Rotation_Initial != nullptr)
|
||||
mHelper_Camera.Rotation_AroundCamera = *pMatrix_Rotation_Initial * mat_rot;
|
||||
else
|
||||
mHelper_Camera.Rotation_AroundCamera *= mat_rot;
|
||||
}
|
||||
|
||||
|
@ -1123,3 +1294,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;
|
||||
}
|
||||
|
|
|
@ -6,14 +6,24 @@
|
|||
#pragma once
|
||||
|
||||
// Header files, Qt.
|
||||
#include <QMap>
|
||||
#if ASSIMP_QT4_VIEWER
|
||||
# include <QtOpenGL>
|
||||
#else
|
||||
# include <QOpenGLWidget>
|
||||
# include <QOpenGLFunctions>
|
||||
#endif // ASSIMP_QT4_VIEWER
|
||||
|
||||
// Header files Assimp
|
||||
#include <assimp/scene.h>
|
||||
|
||||
/// \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
|
||||
|
||||
|
@ -75,9 +85,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 };
|
||||
|
@ -141,11 +149,16 @@ 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.
|
||||
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 +267,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 +324,10 @@ 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);
|
||||
/// \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; }
|
||||
|
||||
/********************************************************************/
|
||||
/******************** Lighting control functions ********************/
|
||||
|
@ -350,19 +366,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 +391,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)
|
||||
|
|
|
@ -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
|
||||
//
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -128,40 +132,74 @@ void MainWindow::LogError(const QString& pMessage)
|
|||
|
||||
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)
|
||||
{
|
||||
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 = pEvent->pos();
|
||||
mMouse_Transformation.Position_Pressed_LMB = ms_pt;
|
||||
else if(pEvent->button() & Qt::RightButton)
|
||||
mPosition_Pressed_RMB = pEvent->pos();
|
||||
mMouse_Transformation.Position_Pressed_RMB = ms_pt;
|
||||
}
|
||||
else
|
||||
{
|
||||
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(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.
|
||||
|
||||
#if ASSIMP_QT4_VIEWER
|
||||
mGLView->updateGL();
|
||||
mPosition_Pressed_LMB = pEvent->pos();
|
||||
#else
|
||||
mGLView->update();
|
||||
#endif // ASSIMP_QT4_VIEWER
|
||||
}
|
||||
|
||||
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.
|
||||
|
||||
#if ASSIMP_QT4_VIEWER
|
||||
mGLView->updateGL();
|
||||
mPosition_Pressed_RMB = pEvent->pos();
|
||||
#else
|
||||
mGLView->update();
|
||||
#endif // ASSIMP_QT4_VIEWER
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -189,19 +227,16 @@ 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
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
/********************** 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),
|
||||
|
@ -209,6 +244,9 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
{
|
||||
using namespace Assimp;
|
||||
|
||||
// other variables
|
||||
mMouse_Transformation.Position_Pressed_Valid = false;
|
||||
|
||||
ui->setupUi(this);
|
||||
// Create OpenGL widget
|
||||
mGLView = new CGLView(this);
|
||||
|
@ -281,7 +319,6 @@ QString filename, filter;
|
|||
if(!filename.isEmpty()) ImportFile(filename);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_butExport_clicked()
|
||||
{
|
||||
using namespace Assimp;
|
||||
|
@ -301,7 +338,7 @@ QMap<QString, const aiExportFormatDesc*> 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);
|
||||
|
@ -345,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()
|
||||
|
@ -357,35 +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();
|
||||
}
|
||||
|
||||
void MainWindow::on_cbxReloadTextures_clicked(bool checked)
|
||||
{
|
||||
mGLView->Enable_Reload_Textures(checked);
|
||||
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
|
||||
}
|
||||
|
|
|
@ -6,7 +6,11 @@
|
|||
#pragma once
|
||||
|
||||
// Header files, Qt.
|
||||
#if ASSIMP_QT4_VIEWER
|
||||
# include <QMainWindow>
|
||||
#else
|
||||
# include <QtWidgets>
|
||||
#endif
|
||||
|
||||
// Header files, project.
|
||||
#include "glview.hpp"
|
||||
|
@ -36,8 +40,17 @@ private:
|
|||
CLoggerView* mLoggerView;///< Pointer to logging object.
|
||||
Assimp::Importer mImporter;///< Assimp importer.
|
||||
const aiScene* mScene;///< Pointer to loaded scene (\ref aiScene).
|
||||
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 ***********/
|
||||
|
@ -80,6 +93,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.
|
||||
|
@ -90,7 +108,6 @@ protected:
|
|||
/// \param [in] pEvent - pointer to event data.
|
||||
void keyPressEvent(QKeyEvent* pEvent) override;
|
||||
|
||||
bool event(QEvent*);
|
||||
public:
|
||||
|
||||
/********************************************************************/
|
||||
|
@ -134,5 +151,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);
|
||||
};
|
||||
|
|
|
@ -302,6 +302,9 @@
|
|||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
|
@ -312,6 +315,9 @@
|
|||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
|
@ -325,6 +331,9 @@
|
|||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
|
@ -335,6 +344,9 @@
|
|||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
|
@ -349,6 +361,9 @@
|
|||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
@ -511,13 +526,6 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QCheckBox" name="cbxReloadTextures">
|
||||
<property name="text">
|
||||
<string>Live Reload Textures</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
|
|
Loading…
Reference in New Issue