diff --git a/qglview/CMakeLists.txt b/qglview/CMakeLists.txt index 29d6010..15c4080 100644 --- a/qglview/CMakeLists.txt +++ b/qglview/CMakeLists.txt @@ -7,7 +7,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -Wall") #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3") set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS}") -set(LIBS ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTOPENGL_LIBRARY} ${QT_QTXML_LIBRARY} qad_widgets) +set(LIBS ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTOPENGL_LIBRARY} ${QT_QTXML_LIBRARY} qad_widgets qad_utils) find_package(OpenGL REQUIRED) list(APPEND LIBS ${OPENGL_LIBRARIES}) @@ -41,5 +41,5 @@ endif () qt4_wrap_cpp(CMOCS_TEST "mainwindow.h" OPTIONS -nw) qt4_wrap_ui(CUIS_TEST "mainwindow.ui") -add_executable(qglview_test "main.cpp" "mainwindow.cpp" ${CMOCS_TEST} ${CUIS_TEST}) -target_link_libraries(qglview_test ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTOPENGL_LIBRARY} ${QT_QTXML_LIBRARY} qglview qad_widgets) +add_executable(qglview_test "main.cpp" "mainwindow.cpp" ${CMOCS_TEST} ${CUIS_TEST} ${CRES}) +target_link_libraries(qglview_test ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTOPENGL_LIBRARY} ${QT_QTXML_LIBRARY} qglview qad_widgets qad_utils) diff --git a/qglview/glcamera.cpp b/qglview/glcamera.cpp index 284c330..90055d2 100644 --- a/qglview/glcamera.cpp +++ b/qglview/glcamera.cpp @@ -24,6 +24,7 @@ QMatrix4x4 globCameraMatrix; Camera::Camera() { + type_ = glCamera; fov_ = 60.; angle_limit_lower_xy = 0.; angle_limit_upper_xy = 360.; diff --git a/qglview/glcamera.h b/qglview/glcamera.h index b1a8d09..7842b12 100644 --- a/qglview/glcamera.h +++ b/qglview/glcamera.h @@ -30,6 +30,8 @@ class Camera: public GLObjectBase { friend class QGLView; friend class GLParticlesSystem; + friend QDataStream & operator <<(QDataStream & s, const GLObjectBase * p); + friend QDataStream & operator >>(QDataStream & s, GLObjectBase *& p); public: Camera(); diff --git a/qglview/glmaterial.h b/qglview/glmaterial.h index 2c8ca03..4041d3b 100644 --- a/qglview/glmaterial.h +++ b/qglview/glmaterial.h @@ -20,6 +20,7 @@ #define GLMATERIAL_H #include "gltypes.h" +#include "chunkstream.h" class GLTexture { public: @@ -126,9 +127,53 @@ struct Material { GLCubeTexture map_reflection; }; -inline QDataStream & operator <<(QDataStream & s, const Map & m) {s << m.bitmap_path << m.color_amount << m.color_offset << m.animation << m.animation_frame_rate; return s;} -inline QDataStream & operator >>(QDataStream & s, Map & m) {s >> m.bitmap_path >> m.color_amount >> m.color_offset >> m.animation >> m.animation_frame_rate; return s;} -inline QDataStream & operator <<(QDataStream & s, const Material & m) {s << m.name << m.color_diffuse << m.color_specular << m.color_self_illumination << m.transparency << m.reflectivity << m.glass << m.map_diffuse << m.map_normal << m.map_relief << m.map_specular << m.map_specularity << m.map_self_illumination; return s;} -inline QDataStream & operator >>(QDataStream & s, Material & m) {s >> m.name >> m.color_diffuse >> m.color_specular >> m.color_self_illumination >> m.transparency >> m.reflectivity >> m.glass >> m.map_diffuse >> m.map_normal >> m.map_relief >> m.map_specular >> m.map_specularity >> m.map_self_illumination; return s;} + +inline QDataStream & operator <<(QDataStream & s, const Map & m) { + ChunkStream cs; + cs << cs.chunk(1, m.bitmap_path) << cs.chunk(2, m.color_amount) << cs.chunk(3, m.color_offset) << cs.chunk(4, m.animation) << cs.chunk(5, m.animation_frame_rate); + s << cs.data(); return s; +} +inline QDataStream & operator >>(QDataStream & s, Map & m) { + ChunkStream cs(s); + while (!cs.atEnd()) { + switch (cs.read()) { + case 1: m.bitmap_path = cs.getData(); break; + case 2: m.color_amount = cs.getData(); break; + case 3: m.color_offset = cs.getData(); break; + case 4: m.animation = cs.getData(); break; + case 5: m.animation_frame_rate = cs.getData(); break; + } + } + return s; +} + +inline QDataStream & operator <<(QDataStream & s, const Material & m) { + ChunkStream cs; + cs << cs.chunk(1, m.name) << cs.chunk(2, m.color_diffuse) << cs.chunk(3, m.color_specular) << cs.chunk(4, m.color_self_illumination) + << cs.chunk(5, m.transparency) << cs.chunk(6, m.reflectivity) << cs.chunk(7, m.glass) << cs.chunk(8, m.map_diffuse) << cs.chunk(9, m.map_normal) + << cs.chunk(10, m.map_relief) << cs.chunk(11, m.map_specular) << cs.chunk(12, m.map_specularity) << cs.chunk(13, m.map_self_illumination); + s << cs.data(); return s; +} +inline QDataStream & operator >>(QDataStream & s, Material & m) { + ChunkStream cs(s); + while (!cs.atEnd()) { + switch (cs.read()) { + case 1: m.name = cs.getData(); break; + case 2: m.color_diffuse = cs.getData(); break; + case 3: m.color_specular = cs.getData(); break; + case 4: m.color_self_illumination = cs.getData(); break; + case 5: m.transparency = cs.getData(); break; + case 6: m.reflectivity = cs.getData(); break; + case 7: m.glass = cs.getData(); break; + case 8: m.map_diffuse = cs.getData(); break; + case 9: m.map_normal = cs.getData(); break; + case 10: m.map_relief = cs.getData(); break; + case 11: m.map_specular = cs.getData(); break; + case 12: m.map_specularity = cs.getData(); break; + case 13: m.map_self_illumination = cs.getData(); break; + } + } + return s; +} #endif // GLMATERIAL_H diff --git a/qglview/globject.cpp b/qglview/globject.cpp index d30c951..4849027 100644 --- a/qglview/globject.cpp +++ b/qglview/globject.cpp @@ -18,10 +18,11 @@ #include "globject.h" #include "glcamera.h" +#include "qglview.h" GLObjectBase::GLObjectBase() { - type_ = Mesh; + type_ = glMesh; render_mode = View; pass_ = Solid; geom_prim = Triangles; @@ -32,7 +33,7 @@ GLObjectBase::GLObjectBase() { line_width = -1.; blend_src = GL_SRC_ALPHA; blend_dest = GL_ONE_MINUS_SRC_ALPHA; - type_ = Mesh; + type_ = glMesh; raw_matrix = false; mat_.setToIdentity(); view_ = 0; @@ -96,6 +97,13 @@ void GLObjectBase::draw(QGLShaderProgram * prog, bool simplest) { } +void GLObjectBase::setView(QGLView * v) { + view_ = v; + foreach (GLObjectBase * c, children_) + c->setView(v); +} + + QList GLObjectBase::children(bool all_) { if (!all_) return children_; QList cl; @@ -144,6 +152,14 @@ void GLObjectBase::setTransform(const QMatrix4x4 & t) { } +void GLObjectBase::select() { + //qDebug() << "select" << name() << view_; + selected_ = true; + if (view_) + ((QGLView*)view_)->selectObject(this); +} + + void GLObjectBase::buildTransform() { itransform_.setToIdentity(); GLObjectBase * p = parent_; @@ -212,7 +228,7 @@ void GLObjectBase::render(int * id, QMap * ids, int sh_id_ Light::Light(): GLObjectBase(), shadow_map(0, true, GL_R16F) { - type_ = GLObjectBase::Light; + type_ = glLight; light_type = Omni; intensity = 1.; angle_start = angle_end = 180.; @@ -223,7 +239,7 @@ Light::Light(): GLObjectBase(), shadow_map(0, true, GL_R16F) { Light::Light(const QVector3D & p, const QColor & c, GLdouble i): GLObjectBase(), shadow_map(0, true, GL_R16F) { - type_ = GLObjectBase::Light; + type_ = glLight; light_type = Omni; pos_ = p; intensity = i; @@ -279,3 +295,87 @@ void Light::draw(QGLShaderProgram * prog, bool simplest) { if (l) glEnable(GL_LIGHTING); } + +QDataStream & operator <<(QDataStream & s, const GLObjectBase * p) { + ChunkStream cs; + cs << cs.chunk(1, int(p->type_)) << cs.chunk(2, p->accept_light) << cs.chunk(3, p->accept_fog) << cs.chunk(4, p->visible_) + << cs.chunk(5, p->cast_shadow) << cs.chunk(6, p->rec_shadow) << cs.chunk(7, p->raw_matrix) << cs.chunk(8, p->line_width) + << cs.chunk(9, int(p->render_mode)) << cs.chunk(10, p->material_) << cs.chunk(11, p->pos_) << cs.chunk(12, p->angles_) + << cs.chunk(13, p->scale_) << cs.chunk(14, p->mat_) << cs.chunk(15, p->vbo) << cs.chunk(16, p->children_) + << cs.chunk(17, p->name_); + if (p->type_ == GLObjectBase::glLight) { + Light * l = (Light*)p; + cs << cs.chunk(100, l->direction) << cs.chunk(101, l->angle_start) << cs.chunk(102, l->angle_end) << cs.chunk(103, l->intensity) + << cs.chunk(104, l->decay_const) << cs.chunk(105, l->decay_linear) << cs.chunk(106, l->decay_quadratic) + << cs.chunk(107, l->decay_start) << cs.chunk(108, l->decay_end) << cs.chunk(109, int(l->light_type)); + } + if (p->type_ == GLObjectBase::glCamera) { + Camera * c = (Camera*)p; + cs << cs.chunk(200, c->aim_) << cs.chunk(201, c->fov_) << cs.chunk(202, c->depth_start) << cs.chunk(203, c->depth_end) + << cs.chunk(204, c->angle_limit_lower_xy) << cs.chunk(205, c->angle_limit_upper_xy) + << cs.chunk(206, c->mirror_x) << cs.chunk(207, c->mirror_y); + } + s << cs.data(); return s; +} +QDataStream & operator >>(QDataStream & s, GLObjectBase *& p) { + ChunkStream cs(s); + p = 0; + Light * l = 0; + Camera * c = 0; + while (!cs.atEnd()) { + switch (cs.read()) { + case 1: + { + GLObjectBase::Type type = (GLObjectBase::Type)cs.getData(); + switch (type) { + case GLObjectBase::glMesh: p = new GLObjectBase(); break; + case GLObjectBase::glLight: p = new Light(); l = (Light*)p; break; + case GLObjectBase::glCamera: p = new Camera(); c = (Camera*)p; break; + default : break; + } + if (p) p->type_ = type; + } + break; + case 2: if (p) p->accept_light = cs.getData(); break; + case 3: if (p) p->accept_fog = cs.getData(); break; + case 4: if (p) p->visible_ = cs.getData(); break; + case 5: if (p) p->cast_shadow = cs.getData(); break; + case 6: if (p) p->rec_shadow = cs.getData(); break; + case 7: if (p) p->raw_matrix = cs.getData(); break; + case 8: if (p) p->line_width = cs.getData(); break; + case 9: if (p) p->render_mode = (GLObjectBase::RenderMode)cs.getData(); break; + case 10: if (p) p->material_ = cs.getData(); break; + case 11: if (p) p->pos_ = cs.getData(); break; + case 12: if (p) p->angles_ = cs.getData(); break; + case 13: if (p) p->scale_ = cs.getData(); break; + case 14: if (p) p->mat_ = cs.getData(); break; + case 15: if (p) p->vbo = cs.getData(); break; + case 16: if (p) { + p->children_ = cs.getData >(); + foreach (GLObjectBase * c_, p->children_) + c_->parent_ = p; + } + break; + case 17: if (p) p->name_ = cs.getData(); break; + case 100: if (l) l->direction = cs.getData(); break; + case 101: if (l) l->angle_start = cs.getData(); break; + case 102: if (l) l->angle_end = cs.getData(); break; + case 103: if (l) l->intensity = cs.getData(); break; + case 104: if (l) l->decay_const = cs.getData(); break; + case 105: if (l) l->decay_linear = cs.getData(); break; + case 106: if (l) l->decay_quadratic = cs.getData(); break; + case 107: if (l) l->decay_start = cs.getData(); break; + case 108: if (l) l->decay_end = cs.getData(); break; + case 109: if (l) l->light_type = (Light::Type)cs.getData(); break; + case 200: if (c) c->setAim(cs.getData()); break; + case 201: if (c) c->setFOV(cs.getData()); break; + case 202: if (c) c->setDepthStart(cs.getData()); break; + case 203: if (c) c->setDepthEnd(cs.getData()); break; + case 204: if (c) c->setAngleLowerLimitXY(cs.getData()); break; + case 205: if (c) c->setAngleUpperLimitXY(cs.getData()); break; + case 206: if (c) c->mirror_x = cs.getData(); break; + case 207: if (c) c->mirror_y = cs.getData(); break; + } + } + return s; +} diff --git a/qglview/globject.h b/qglview/globject.h index 03175f9..9fa130e 100644 --- a/qglview/globject.h +++ b/qglview/globject.h @@ -24,13 +24,17 @@ #include "glmaterial.h" class Camera; +class QGLView; class GLObjectBase { friend class QGLView; friend class GLRendererBase; + friend QDataStream & operator <<(QDataStream & s, const GLObjectBase * p); + friend QDataStream & operator >>(QDataStream & s, GLObjectBase *& p); + friend GLObjectBase * loadFromQGLFile(const QString & filepath); public: - enum Type {Mesh, Light, ParticlesSystem}; + enum Type {glMesh, glLight, glCamera, glParticlesSystem}; enum Pass {Solid, Transparent, Reflection, User}; enum GeomPrimitives {Triangles = GL_TRIANGLES, Quads = GL_QUADS}; enum RenderMode {View = 0, Point = GL_POINT, Line = GL_LINE, Fill = GL_FILL}; @@ -60,6 +64,7 @@ public: void setParent(GLObjectBase * o) {parent_ = o;} bool hasParent() const {return parent_ != 0;} bool hasChildren() const {return children_.size() != 0;} + void setView(QGLView * v); void addChild(GLObjectBase * o) {if (o == this) return; if (o->parent_ != 0) o->parent_->children_.removeAll(o); children_ << o; o->parent_ = this; o->buildTransform(); if (view_ != 0) view_->collectLights();} void removeChild(GLObjectBase * o) {if (o == this) return; children_.removeAll(o); o->parent_ = 0; o->buildTransform(); if (view_ != 0) view_->collectLights();} @@ -68,6 +73,8 @@ public: int childCount() const {return children_.size();} GLObjectBase * child(int index) {if (index < 0 || index >= children_.size()) return 0; return children_[index];} GLObjectBase * child(const QString & name) {foreach (GLObjectBase * i, children_) if (i->name_ == name) return i; return 0;} + const GLObjectBase * child(int index) const {if (index < 0 || index >= children_.size()) return 0; return children_[index];} + const GLObjectBase * child(const QString & name) const {foreach (GLObjectBase * i, children_) if (i->name_ == name) return i; return 0;} QList children(bool all_ = false); bool isVisible() const {return visible_;} @@ -145,7 +152,7 @@ public: bool isSelected() const {return selected_;} void setSelected(bool yes) {selected_ = yes;} - void select() {selected_ = true;} + void select(); void deselect() {selected_ = false;} bool isSelectable() const {return select_;} @@ -246,4 +253,8 @@ inline T globject_cast(GLObjectBase * object) {return reinterpret_cast(object template inline T globject_cast(const GLObjectBase * object) {return reinterpret_cast(object);} + +QDataStream & operator <<(QDataStream & s, const GLObjectBase * p); +QDataStream & operator >>(QDataStream & s, GLObjectBase *& p); + #endif // GLOBJECT_H diff --git a/qglview/globject_editor.cpp b/qglview/globject_editor.cpp index 689fc6b..b4e3bb2 100644 --- a/qglview/globject_editor.cpp +++ b/qglview/globject_editor.cpp @@ -64,8 +64,8 @@ void GLObjectEditor::setObject(GLObjectBase * o) { checkCastShadows->setChecked(object->isCastShadows()); checkReceiveShadows->setChecked(object->isReceiveShadows()); comboRenderMode->setCurrentIndex(rmodes.indexOf(object->renderMode())); - groupLight->setEnabled(object->type() == GLObjectBase::Light); - if (object->type() == GLObjectBase::Light) { + groupLight->setEnabled(object->type() == GLObjectBase::glLight); + if (object->type() == GLObjectBase::glLight) { Light * l = globject_cast(object); //bool is_dir = l->light_type == Light::Directional, is_cone = l->light_type == Light::Cone; buttonLightColor->setColor(l->color()); @@ -102,7 +102,7 @@ void GLObjectEditor::objectChanged() { object->setCastShadows(checkCastShadows->isChecked()); object->setReceiveShadows(checkReceiveShadows->isChecked()); object->setRenderMode((GLObjectBase::RenderMode)rmodes[comboRenderMode->currentIndex()]); - if (object->type() == GLObjectBase::Light) { + if (object->type() == GLObjectBase::glLight) { Light * l = globject_cast(object); //bool is_dir = l->light_type == Light::Directional, is_cone = l->light_type == Light::Cone; l->setColor(buttonLightColor->color()); diff --git a/qglview/globject_editor.ui b/qglview/globject_editor.ui index 146e0a7..62c2aed 100644 --- a/qglview/globject_editor.ui +++ b/qglview/globject_editor.ui @@ -151,6 +151,9 @@ + + 4 + -99999.000000000000000 @@ -167,6 +170,9 @@ + + 4 + -99999.000000000000000 @@ -183,6 +189,9 @@ + + 4 + -99999.000000000000000 diff --git a/qglview/glvbo.h b/qglview/glvbo.h index 8b10800..d6347e0 100644 --- a/qglview/glvbo.h +++ b/qglview/glvbo.h @@ -20,10 +20,13 @@ #define GLVBO_H #include "gltypes.h" +#include "chunkstream.h" class GLVBO { friend class GLObjectBase; + friend QDataStream & operator <<(QDataStream & s, const GLVBO & m); + friend QDataStream & operator >>(QDataStream & s, GLVBO & m); public: GLVBO(GLenum usage = GL_DYNAMIC_DRAW); ~GLVBO(); @@ -64,4 +67,25 @@ private: }; + +inline QDataStream & operator <<(QDataStream & s, const GLVBO & m) { + ChunkStream cs; + cs << cs.chunk(1, m.vertices_) << cs.chunk(2, m.normals_) << cs.chunk(3, m.texcoords_) << cs.chunk(4, m.colors_) << cs.chunk(5, m.usage); + s << cs.data(); return s; +} +inline QDataStream & operator >>(QDataStream & s, GLVBO & m) { + ChunkStream cs(s); + while (!cs.atEnd()) { + switch (cs.read()) { + case 1: m.vertices_ = cs.getData >(); break; + case 2: m.normals_ = cs.getData >(); break; + case 3: m.texcoords_ = cs.getData >(); break; + case 4: m.colors_ = cs.getData >(); break; + case 5: m.usage = cs.getData(); break; + } + } + m.changed = true; + return s; +} + #endif // GLVBO_H diff --git a/qglview/icons/application-exit.png b/qglview/icons/application-exit.png new file mode 100644 index 0000000..ed5f8b2 Binary files /dev/null and b/qglview/icons/application-exit.png differ diff --git a/qglview/icons/document-import.png b/qglview/icons/document-import.png new file mode 100644 index 0000000..293b5a0 Binary files /dev/null and b/qglview/icons/document-import.png differ diff --git a/qglview/icons/document-new.png b/qglview/icons/document-new.png new file mode 100644 index 0000000..61db97a Binary files /dev/null and b/qglview/icons/document-new.png differ diff --git a/qglview/icons/document-open.png b/qglview/icons/document-open.png new file mode 100644 index 0000000..3432ed2 Binary files /dev/null and b/qglview/icons/document-open.png differ diff --git a/qglview/icons/document-save-.png b/qglview/icons/document-save-.png new file mode 100644 index 0000000..cc380a0 Binary files /dev/null and b/qglview/icons/document-save-.png differ diff --git a/qglview/icons/type-camera.png b/qglview/icons/type-camera.png new file mode 100644 index 0000000..c28aa2d Binary files /dev/null and b/qglview/icons/type-camera.png differ diff --git a/qglview/icons/type-geo.png b/qglview/icons/type-geo.png new file mode 100644 index 0000000..9204153 Binary files /dev/null and b/qglview/icons/type-geo.png differ diff --git a/qglview/icons/type-light.png b/qglview/icons/type-light.png new file mode 100644 index 0000000..687c8fe Binary files /dev/null and b/qglview/icons/type-light.png differ diff --git a/qglview/loader_dae.cpp b/qglview/loader_dae.cpp index 233901b..54ed66f 100644 --- a/qglview/loader_dae.cpp +++ b/qglview/loader_dae.cpp @@ -400,7 +400,7 @@ GLObjectBase * loadFromDAEFile(const QString & filepath, double scale) { for (int i = 0; i < root->childCount(); ++i) { GLObjectBase * o = root->child(i); - if (o->type() == GLObjectBase::Light) { + if (o->type() == GLObjectBase::glLight) { Light * l = (Light*)o; if (l->light_type == Light::Directional || l->light_type == Light::Cone) { QString tn = l->name() + ".Target"; @@ -423,6 +423,7 @@ GLObjectBase * loadFromDAEFile(const QString & filepath, double scale) { for (int j = 0; j < dol[i].size(); ++j) delete dol[i][j]; + root->setScale(0.001); qDebug() << "[Loader DAE] Loaded" << root->childCount() << "objects from" << filepath; return root; } diff --git a/qglview/loader_qgl.cpp b/qglview/loader_qgl.cpp new file mode 100644 index 0000000..57fed22 --- /dev/null +++ b/qglview/loader_qgl.cpp @@ -0,0 +1,64 @@ +/* + QGLView + Copyright (C) 2012 Ivan Pelipenko peri4ko@gmail.com + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "loader_qgl.h" +#include "chunkstream.h" + + +GLObjectBase * loadFromQGLFile(const QString & filepath) { + QFile f(filepath); + if (!f.exists()) { + qDebug() << "[Loader QGL] Error: can`t open \"" + filepath + "\""; + return 0; + } + f.open(QIODevice::ReadOnly); + QDataStream s(&f); + char sign[4]; + s.readRawData(sign, 4); + if ((sign[0] != 'Q') || (sign[1] != 'G') || (sign[2] != 'L') || (sign[3] != 'F')) { + qDebug() << "[Loader QGL] Error: \"" + filepath + "\" is not valid QGL file!"; + return 0; + } + QByteArray fc_; s >> fc_; + QByteArray fc = qUncompress(fc_); + if (fc.isEmpty()) return 0; + QDataStream os(fc); + GLObjectBase * root = 0; + os >> root; + root->buildTransform(); + if (root->name().isEmpty()) + root->setName(QFileInfo(f).baseName()); + qDebug() << "[Loader QGL] Loaded" << root->childCount() << "objects from" << filepath; + return root; +} + + +bool saveToQGLFile(const QString & filepath, const GLObjectBase * o) { + QFile f(filepath); + if (!f.open(QIODevice::ReadWrite)) + return false; + f.resize(0); + QDataStream s(&f); + char sign[4] = {'Q', 'G', 'L', 'F'}; + s.writeRawData(sign, 4); + QByteArray fc; + QDataStream os(&fc, QIODevice::ReadWrite); + os << o; + s << qCompress(fc); + return true; +} diff --git a/qglview/loader_qgl.h b/qglview/loader_qgl.h new file mode 100644 index 0000000..8b795a3 --- /dev/null +++ b/qglview/loader_qgl.h @@ -0,0 +1,31 @@ +/* + QGLView + Copyright (C) 2012 Ivan Pelipenko peri4ko@gmail.com + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef LOADER_QGL_H +#define LOADER_QGL_H + +#include "globject.h" +#include + +namespace LoaderQGL { +} + +GLObjectBase * loadFromQGLFile(const QString & filepath); +bool saveToQGLFile(const QString & filepath, const GLObjectBase * o); + +#endif // LOADER_QGL_H diff --git a/qglview/mainwindow.cpp b/qglview/mainwindow.cpp index 6cdf851..93debad 100644 --- a/qglview/mainwindow.cpp +++ b/qglview/mainwindow.cpp @@ -17,23 +17,27 @@ */ #include "mainwindow.h" +#include "loader_qgl.h" +#include "loader_ase.h" +#include "loader_3ds.h" #include "loader_obj.h" #include "loader_dae.h" #include #include +#include -#define EARTH_H 6356863.019 // m -#define EARTH_WL 6378245.000 // m MainWindow::MainWindow(QWidget * parent): QMainWindow(parent), Ui::MainWindow() { setupUi(this); - colorHalo->setColor(view->selectionHaloColor()); + icon_geo = QIcon(":/icons/type-geo.png"); + icon_camera = QIcon(":/icons/type-camera.png"); + icon_light = QIcon(":/icons/type-light.png"); sel_obj = 0; - //spinSliderShine->setDecimals(2); + view->camera().setAim(QVector3D()); + view->camera().setPos(QVector3D(2, 2, 2)); view->setFrameShape(QFrame::NoFrame); view->setRenderer(new RendererDeferredShading(view)); - //view->setRenderer(new RendererSimple(view)); view->setMouseRotateEnabled(true); view->setMouseSelectionEnabled(true); view->setSelectionHaloEnabled(true); @@ -43,130 +47,61 @@ MainWindow::MainWindow(QWidget * parent): QMainWindow(parent), Ui::MainWindow() view->setBackColor(Qt::lightGray); view->setDepthStart(1.); view->setDepthEnd(10000.); - //view->setLightingMode(QGLView::PerPixel); - /*MaterialEditor * o = new MaterialEditor(); - o->setWindowOpacity(.666); - view->addObject(o, Qt::Window);*/ - /**obj = loadFrom3DSFile("data/test.3DS", 0.15); - m.reflectivity = 1; - m.reflection.loadPathesFromDirectory("data/e"); - obj->child("sphere001")->setMaterial(m);*/ + spinFOV->setValue(view->FOV()); + spinDepthStart->setValue(view->depthStart()); + spinDepthEnd->setValue(view->depthEnd()); + groupHoverHalo->setChecked(view->isHoverHaloEnabled()); + groupSelectionHalo->setChecked(view->isSelectionHaloEnabled()); + spinHoverHaloFill->setValue(view->hoverHaloFillAlpha()); + spinSelectionHaloFill->setValue(view->selectionHaloFillAlpha()); + colorHoverHalo->setColor(view->hoverHaloColor()); + colorSelectionHalo->setColor(view->selectionHaloColor()); + checkFXAA->setChecked(view->isFeatureEnabled(QGLView::qglFXAA)); + checkMSAA->setChecked(view->isFeatureEnabled(QGLView::qglMSAA)); + colorBack->setColor(view->backColor()); + colorAmbient->setColor(view->ambientColor()); + checkCameraOrbit->setChecked(view->isCameraOrbit()); - //m.shine = 40; - //m.shine_strength = 1; - //m.diffuse.bitmap_path = "celtic_010.jpg"; - //m.bump.bitmap_path = "celtic_010n.jpg"; - /*obj->child("cone")->setMaterial(m); - m.diffuse.bitmap_path = "proj_plane_d.tga"; - m.bump.bitmap_path = "proj_plane_n.tga"; - obj->child("tor")->setMaterial(m); - m.reflectivity = 1.; - obj->child("sphere")->setMaterial(m);*/ - //obj->child("teapot")->setRenderMode(GLObjectBase::Point); - //obj->child("teapot")->setLineWidth(2.); - //obj->child("cone")->setRenderMode(GLObjectBase::Line); - //view->camera().setAim(obj->child("sphere001")->pos()); - GLTextureManager::addSearchPath("data"); - GLTextureManager::addSearchPath("data/images"); - GLTextureManager::addSearchPath("data/SU-33_maps"); - obj = loadFromDAEFile("data/shadows.dae");//new GLPrimitiveEllipsoid(EARTH_WL / 1E+6, EARTH_WL / 1E+6, EARTH_H / 1E+6, 500, 500);//GLPrimitiveCube(); - //obj->setScale(0.1); - //obj->child("Plane001")->material().map_specularity.color_amount = 0.95; - //obj = new GLPrimitiveEllipsoid(100, 100, 100, 100, 100);//GLPrimitiveCube(); - for (int i = 0; i < obj->childCount(); ++i) - if (obj->child(i)->type() == GLObjectBase::Light) { - //((Light*)obj->child(i))->intensity = 1.5; - //((Light*)obj->child(i))->decay_linear = .5; - } - view->addObject(obj); + groupShadows->setChecked(view->isFeatureEnabled(QGLView::qglShadowsEnabled)); + groupEyeAccomodation->setChecked(view->isFeatureEnabled(QGLView::qglEyeAccomodationEnabled)); + groupBloom->setChecked(view->isFeatureEnabled(QGLView::qglBloomEnabled)); + groupMotionBlur->setChecked(view->isFeatureEnabled(QGLView::qglMotionBlurEnabled)); + groupReflections->setChecked(view->isFeatureEnabled(QGLView::qglDynamicReflectionsEnabled)); + checkSoftShadows->setChecked(view->isFeatureEnabled(QGLView::qglShadowsSoftEnabled)); + spinAccom->setValue(view->isFeatureEnabled(QGLView::qglEyeAccomodationTime)); + spinAccomMS->setValue(view->isFeatureEnabled(QGLView::qglEyeAccomodationMaxSpeed)); + spinCubemapSize->setValue(view->isFeatureEnabled(QGLView::qglDynamicReflectionsMapSize)); + spinShadowmapSize->setValue(view->isFeatureEnabled(QGLView::qglShadowsMapSize)); + spinMotionBlurFactor->setValue(view->isFeatureEnabled(QGLView::qglMotionBlurFactor)); + spinMotionBlurSteps->setValue(view->isFeatureEnabled(QGLView::qglMotionBlurSteps)); + spinBloomFactor->setValue(view->isFeatureEnabled(QGLView::qglBloomFactor)); + spinBloomRadius->setValue(view->isFeatureEnabled(QGLView::qglBloomRadius)); + spinBloomThreshold->setValue(view->isFeatureEnabled(QGLView::qglBloomThreshold)); - //obj->setPos(1000000, -1000000, -10000000); - //obj->child("Box001")->addChild(&(view->camera())); - //obj->child("Box001")->VBO().translatePoints(QVector3D(20,30,40)); - view->camera().setPos(QVector3D(10, -20, 20)); - view->camera().setAim(obj->pos()); - view->camera().flyToDistance(500); - - double al = 7.; + axis = new GLObjectBase(); + GLObjectBase * obj; + double al = 1.; obj = new GLPrimitiveLine(QVector3D(0, 0, -al), QVector3D(0, 0, al)); obj->material().color_diffuse = Qt::darkBlue; obj->setAcceptLight(false); - view->addObject(obj); + axis->addChild(obj); obj = new GLPrimitiveLine(QVector3D(-al, 0, 0), QVector3D(al, 0, 0)); obj->material().color_diffuse = Qt::darkRed; obj->setAcceptLight(false); - view->addObject(obj); + axis->addChild(obj); obj = new GLPrimitiveLine(QVector3D(0, -al, 0), QVector3D(0, al, 0)); obj->material().color_diffuse = Qt::darkGreen; obj->setAcceptLight(false); - view->addObject(obj); - - double lat = deg2rad*(-85.), lng = deg2rad*(15.); - obj = new GLPrimitiveLine(QVector3D(), QVector3D(cos(lng)*cos(lat), sin(lng)*cos(lat), sin(lat)/*(EARTH_H/EARTH_WL)*/)*5); - view->addObject(obj); - - //view->camera().setMode(Camera::AimMatrix); - Light * l = new Light(view->camera().pos()); - /*l->light_type = Light::Cone; - l->direction = QVector3D(1., 0.2, -0.2); - l->angle_start = 0.; - l->angle_end = 120.;*/ - l->intensity = 0.5; - //l->decay_linear = 0.2; - l->setName("camera"); - view->addObject(l); + axis->addChild(obj); + view->addObject(axis); + + cam_light = new Light(view->camera().pos()); + cam_light->intensity = 0.5; + cam_light->setName("camera"); + view->camera().addChild(cam_light); view->start(-1); - //view->light(0)->light_type = Light::Omni; - //obj = loadFrom3DSFile("34.3DS", 0.03); - //view->addObject(obj); - //view->camera().moveUp(5, true); - - /**ps = new GLParticlesSystem(QVector3D(0,0,5)); - ps->setEmitterType(GLParticlesSystem::Box); - ps->setBirthRate(5); - ps->setSize(1.); - ps->setLifeDuration(5.); - ps->setInitialSpeed(.5); - ps->setFadeTime(1.); - ps->setSpeedDirectionJitter(1); - //ps->setTextureScale(2, 2); - ps->setAddVerticalFaceEnabled(true); - ps->addForce(QVector3D(0,0,-0.98/20));*/ - //ps->material().diffuse.bitmap_path = "expl_07.png"; - //view->addObject(ps); - - /**box = new GLPrimitiveCube(); - box->setSelectable(false); - box->setRenderMode(GLObjectBase::Line); - box->setLineWidth(2.); - view->addObject(box); - box->hide();*/ - //while (view->lightsCount() >= 5) view->removeLight(view->lightsCount() - 1); - //view->addObject(box); - - //obj = obj->clone(true); - //obj->move(QVector3D(10,10,0)); - //view->addObject(obj); - - //view->addObject(obj); - //obj = obj->clone(true); - //obj->move(QVector3D(10,10,0)); - //view->addObject(obj); - /*int h = 0, dh = 360 / view->lights().size(); - foreach (Light * i, view->lights()) { - i->setColor(QColor::fromHsv(h, 255, 255)); - i->intensity *= 2; - h += dh; - }*/ startTimer(1000/60); - //connect(view, SIGNAL(hoverChanged(GLObjectBase*,GLObjectBase*)), this, SLOT(hoverChanged(GLObjectBase*,GLObjectBase*))); - treeProperties->assignObject(view); connect(view, SIGNAL(selectionChanged(GLObjectBase*,GLObjectBase*)), this, SLOT(selectionChanged(GLObjectBase*,GLObjectBase*))); - connect(view, SIGNAL(glInitializeDone()), this, SLOT(glInit())); connect(matEditor, SIGNAL(changed()), this, SLOT(materialChanged())); - //view->addObject(new Light(view->camera().pos())); - - //show(); - //comboBox->setCurrentIndex(2); } @@ -177,29 +112,18 @@ MainWindow::~MainWindow() { void MainWindow::changeEvent(QEvent * e) { QMainWindow::changeEvent(e); - /*if (e->type() == QEvent::LanguageChange) { + if (e->type() == QEvent::LanguageChange) { retranslateUi(this); return; - }*/ + } } void MainWindow::timerEvent(QTimerEvent * ) { - static double t = 0.; - if (checkCameraLight->isChecked()) - view->light(view->lightsCount() - 1)->setPos(view->camera().worldPos()); + //static double t = 0.; + cam_light->setVisible(checkCameraLight->isChecked()); //((RendererSimple*)(view->renderer()))->mpos = view->mapFromGlobal(QCursor::pos()); -//qDebug() << view->camera().angles(); - //cam_mat.rotate(e->y(), 0., 1., 0.); - //view->camera().setTransform(cam_mat); - - /*obj->child("tor")->rotateX(0.5); - obj->child("tor")->rotateZ(0.1); - obj->child("cone")->rotateZ(1); - obj->child("teapot")->rotateY(sin(t)); - obj->child("sphere")->setPosZ(fabs(sin(t)*5)-0.75);*/ - t += 0.1; - setWindowTitle(QString::number(view->currentFPS(), 'f', 2)); + statusBar()->showMessage(QString("FPS: %1").arg(QString::number(view->currentFPS(), 'f', 2))); } @@ -214,34 +138,47 @@ void MainWindow::on_view_glKeyPressEvent(QKeyEvent * e) { } -void MainWindow::on_view_glMouseMoveEvent(QMouseEvent * e) { - cam_mat.rotate(e->x(), 0., 0., 1.); - cam_mat.rotate(e->y(), 0., 1., 0.); - view->camera().setTransform(cam_mat); -} - - -void MainWindow::glInit() { - //view->bindTexture(QImage("e/bottom.jpg")); - -} - - -void MainWindow::on_pushButton_clicked() { - //view->removeLight(view->lightsCount() - 1); - //setWindowTitle(QString::number(view->lightsCount())); - QVector3D wp = view->light(0)->worldPos(); - view->camera().setPos(wp); - view->camera().setAim(wp + (view->light(0)->worldTransform() * QVector4D(view->light(0)->direction)).toVector3D()*100); -} - - void MainWindow::loadFile(const QString & path) { prev_path = path; - QCursor pcur = cursor(); - setCursor(Qt::WaitCursor); + importFile(path); +} - setCursor(pcur); + +void MainWindow::importFile(const QString & path) { + QApplication::setOverrideCursor(Qt::WaitCursor); + QFileInfo fi(path); + GLObjectBase * o = 0; + if (fi.completeSuffix().toLower() == "qgl") o = loadFromQGLFile(path); + if (fi.completeSuffix().toLower() == "ase") o = loadFromASEFile(path); + if (fi.completeSuffix().toLower() == "3ds") o = loadFrom3DSFile(path); + if (fi.completeSuffix().toLower() == "obj") o = loadFromOBJFile(path); + if (fi.completeSuffix().toLower() == "dae") o = loadFromDAEFile(path); + QApplication::restoreOverrideCursor(); + if (!o) { + QMessageBox::critical(this, "Import", "Can`t load " + path + "!"); + return; + } + o->setName(fi.baseName()); + view->addObject(o); + objectsTreeChanged(); +} + + +void MainWindow::makeObjetTree(const GLObjectBase * o, QTreeWidgetItem * ti) { + if (o == axis) return; + for (int i = 0; i < o->childCount(); ++i) { + const GLObjectBase * co = o->child(i); + QTreeWidgetItem * ci = new QTreeWidgetItem(ti); + ci->setText(0, co->name()); + ci->setData(0, Qt::UserRole, quintptr(co)); + switch (co->type()) { + case GLObjectBase::glMesh: ci->setIcon(0, icon_geo); break; + case GLObjectBase::glLight: ci->setIcon(0, icon_light); break; + case GLObjectBase::glCamera: ci->setIcon(0, icon_camera); break; + default: break; + } + makeObjetTree(co, ci); + } } @@ -271,25 +208,62 @@ void MainWindow::materialChanged() { } -void MainWindow::on_pushButton_3_clicked() { - QList ol = view->objects(true); - qDebug() << ol.size(); - foreach (GLObjectBase * i, ol) { - i->VBO().rebuffer(); - } -} - - -void MainWindow::on_comboBox_currentIndexChanged(int val) { +void MainWindow::on_comboRenderer_currentIndexChanged(int val) { GLRendererBase * pr = 0; switch (val) { case 0: view->setRenderer(new RendererSimple(view), &pr); break; - case 2: view->setRenderer(new RendererDeferredShading(view), &pr); break; + case 1: view->setRenderer(new RendererDeferredShading(view), &pr); break; } if (pr != 0) delete pr; } +void MainWindow::on_actionReset_triggered() { + view->removeObject(axis, false); + view->clearObjects(true); + view->addObject(axis); +} + + +void MainWindow::on_actionImport_triggered() { + QStringList fl = QFileDialog::getOpenFileNames(this, "Select files", prev_path, "Supported types(*.qgl *.ase *.3ds *.obj *.dae);;" + "QGLView(*.qgl);;" + "Ascii Scene Export(*.ase);;" + "3D Studio(*.3ds);;" + "Wavefront OBJ(*.obj);;" + "Collada(*.dae)"); + if (fl.isEmpty()) return; + prev_path = fl.back(); + foreach (QString f, fl) + importFile(f); +} + + +void MainWindow::on_actionSave_triggered() { + QString f = QFileDialog::getSaveFileName(this, "Select file", prev_path, "QGLView(*.qgl)"); + if (f.isEmpty()) return; + if (f.right(4).toLower() != ".qgl") + f += ".qgl"; + prev_path = f; + view->removeObject(axis); + saveToQGLFile(f, &(view->rootObject())); + view->addObject(axis); +} + + +void MainWindow::on_actionOpen_triggered() { + QString f = QFileDialog::getOpenFileName(this, "Select file", prev_path, "Supported types(*.qgl *.ase *.3ds *.obj *.dae);;" + "QGLView(*.qgl);;" + "Ascii Scene Export(*.ase);;" + "3D Studio(*.3ds);;" + "Wavefront OBJ(*.obj);;" + "Collada(*.dae)"); + if (f.isEmpty()) return; + prev_path = f; + importFile(f); +} + + void MainWindow::on_view_keyEvent(Qt::Key k, Qt::KeyboardModifiers m) { //qDebug() << k; double spd = 0.2; @@ -303,3 +277,33 @@ void MainWindow::on_view_keyEvent(Qt::Key k, Qt::KeyboardModifiers m) { default: break; } } + + +void MainWindow::on_treeObjects_itemClicked(QTreeWidgetItem * ti, int col) { + ((GLObjectBase*)(ti->data(0, Qt::UserRole).toULongLong()))->select(); +} + + +void MainWindow::objectsTreeChanged() { + treeObjects->clear(); + makeObjetTree(&(view->rootObject()), treeObjects->invisibleRootItem()); +} + + +void MainWindow::on_pushButton_clicked() { + //view->removeLight(view->lightsCount() - 1); + //setWindowTitle(QString::number(view->lightsCount())); + QVector3D wp = view->light(0)->worldPos(); + view->camera().setPos(wp); + view->camera().setAim(wp + (view->light(0)->worldTransform() * QVector4D(view->light(0)->direction)).toVector3D()*100); +} + + +void MainWindow::on_pushButton_3_clicked() { + QList ol = view->objects(true); + qDebug() << ol.size(); + foreach (GLObjectBase * i, ol) { + i->VBO().rebuffer(); + } +} + diff --git a/qglview/mainwindow.h b/qglview/mainwindow.h index c420d15..51263de 100644 --- a/qglview/mainwindow.h +++ b/qglview/mainwindow.h @@ -52,61 +52,70 @@ private: void timerEvent(QTimerEvent * ); void loadFile(const QString & path); + void importFile(const QString & path); + void makeObjetTree(const GLObjectBase * o, QTreeWidgetItem * ti); QTranslator translator; - QString prev_path, dstyle; + QIcon icon_geo, icon_camera, icon_light; + QString prev_path; + GLObjectBase * sel_obj, * axis; + Light * cam_light; + GLPrimitiveCube * box; + Material m; bool isChanged; - GLObjectBase * obj, * sel_obj; - GLPrimitiveCube * box; - GLParticlesSystem * ps; - WaterSystem * ws; - RopeSystem * rs; - Material m; - private slots: - void glInit(); - void on_actionExit_triggered() {close();} - void on_spinFOV_valueChanged(double val) {view->setFOV(val);} + void on_spinDepthStart_valueChanged(double val) {view->setDepthStart(val);} + void on_spinDepthEnd_valueChanged(double val) {view->setDepthEnd(val);} + void on_comboRenderer_currentIndexChanged(int val); + void on_comboViewRenderMode_currentIndexChanged(int val) {static int modes[] = {GL_POINT, GL_LINE, GL_FILL}; view->setRenderMode((GLObjectBase::RenderMode)modes[val]);} + void on_groupHoverHalo_clicked(bool val) {view->setHoverHaloEnabled(val);} + void on_groupSelectionHalo_clicked(bool val) {view->setSelectionHaloEnabled(val);} + void on_spinHoverHaloFill_valueChanged(double val) {view->setHoverHaloFillAlpha(val);} + void on_spinSelectionHaloFill_valueChanged(double val) {view->setSelectionHaloFillAlpha(val);} + void on_colorHoverHalo_colorChanged(QColor color) {view->setHoverHaloColor(color);} + void on_colorSelectionHalo_colorChanged(QColor color) {view->setSelectionHaloColor(color);} + void on_checkFXAA_clicked(bool val) {view->setFeature(QGLView::qglFXAA, val);} + void on_checkMSAA_clicked(bool val) {view->setFeature(QGLView::qglMSAA, val);} + void on_colorBack_colorChanged(QColor color) {view->setBackColor(color);} + void on_colorAmbient_colorChanged(QColor color) {view->setAmbientColor(color);} + void on_checkCameraOrbit_clicked(bool val) {view->setCameraOrbit(val);} + + void on_groupShadows_clicked(bool val) {view->setFeature(QGLView::qglShadowsEnabled, val);} + void on_groupEyeAccomodation_clicked(bool val) {view->setFeature(QGLView::qglEyeAccomodationEnabled, val);} + void on_groupBloom_clicked(bool val) {view->setFeature(QGLView::qglBloomEnabled, val);} + void on_groupMotionBlur_clicked(bool val) {view->setFeature(QGLView::qglMotionBlurEnabled, val);} + void on_groupReflections_clicked(bool val) {view->setFeature(QGLView::qglDynamicReflectionsEnabled, val);} + void on_checkSoftShadows_clicked(bool val) {view->setFeature(QGLView::qglShadowsSoftEnabled, val);} void on_spinAccom_valueChanged(double val) {view->setFeature(QGLView::qglEyeAccomodationTime, val);} void on_spinAccomMS_valueChanged(double val) {view->setFeature(QGLView::qglEyeAccomodationMaxSpeed, val);} void on_spinCubemapSize_valueChanged(double val) {view->setFeature(QGLView::qglDynamicReflectionsMapSize, val);} void on_spinShadowmapSize_valueChanged(double val) {view->setFeature(QGLView::qglShadowsMapSize, val);} - void on_spinHaloFillAlpha_valueChanged(double val) {view->setSelectionHaloFillAlpha(val);} void on_spinMotionBlurFactor_valueChanged(double val) {view->setFeature(QGLView::qglMotionBlurFactor, val);} void on_spinMotionBlurSteps_valueChanged(int val) {view->setFeature(QGLView::qglMotionBlurSteps, val);} void on_spinBloomFactor_valueChanged(double val) {view->setFeature(QGLView::qglBloomFactor, val);} void on_spinBloomRadius_valueChanged(int val) {view->setFeature(QGLView::qglBloomRadius, val);} void on_spinBloomThreshold_valueChanged(double val) {view->setFeature(QGLView::qglBloomThreshold, val);} - //void on_spinSliderShine_valueChanged(double val) {obj->material().shine_strength = val; obj->setMaterial(obj->material(), true);} - //void on_spinSliderRough_valueChanged(double val) {obj->material().shine = val; obj->setMaterial(obj->material(), true);} + + void on_actionExit_triggered() {close();} + void on_actionReset_triggered(); + void on_actionImport_triggered(); + void on_actionSave_triggered(); + void on_actionOpen_triggered(); + + void on_view_glKeyPressEvent(QKeyEvent * e); + void on_view_keyEvent(Qt::Key k, Qt::KeyboardModifiers m); + + void on_treeObjects_itemClicked(QTreeWidgetItem * ti, int col); + + void objectsTreeChanged(); + void materialChanged(); + void selectionChanged(GLObjectBase * cur, GLObjectBase * prev); + void on_pushButton_clicked(); void on_pushButton_2_clicked() {view->reloadShaders();} void on_pushButton_3_clicked(); - void on_comboBox_currentIndexChanged(int val); - void on_comboViewRenderMode_currentIndexChanged(int val) {static int modes[] = {GL_POINT, GL_LINE, GL_FILL}; view->setRenderMode((GLObjectBase::RenderMode)modes[val]);} - //void on_comboLight_currentIndexChanged(int val) {obj->material().light_model = (Material::LightModel)val; obj->setMaterial(obj->material(), true);} - void on_checkSelectionHalo_toggled(bool val) {view->setSelectionHaloEnabled(val);} - void on_checkDynamicReflections_toggled(bool val) {view->setFeature(QGLView::qglDynamicReflectionsEnabled, val);} - void on_checkHDR_toggled(bool val) {view->setFeature(QGLView::qglHDR, val);} - void on_checkAccomodation_toggled(bool val) {view->setFeature(QGLView::qglEyeAccomodationEnabled, val);} - void on_checkBloom_toggled(bool val) {view->setFeature(QGLView::qglBloomEnabled, val);} - void on_checkFXAA_toggled(bool val) {view->setFeature(QGLView::qglFXAA, val);} - void on_checkMSAA_toggled(bool val) {view->setFeature(QGLView::qglMSAA, val);} - void on_checkShadows_toggled(bool val) {view->setFeature(QGLView::qglShadowsEnabled, val);} - void on_checkSoftShadows_toggled(bool val) {view->setFeature(QGLView::qglShadowsSoftEnabled, val);} - void on_checkCameraOrbit_toggled(bool val) {view->setCameraOrbit(val);} - void on_checkMotionBlur_toggled(bool val) {view->setFeature(QGLView::qglMotionBlurEnabled, val);} - void on_colorAmbient_colorChanged(QColor color) {view->setAmbientColor(color);} - void on_colorHalo_colorChanged(QColor color) {view->setSelectionHaloColor(color);} - void on_view_glKeyPressEvent(QKeyEvent * e); - void on_view_glMouseMoveEvent(QMouseEvent * e); - void on_view_keyEvent(Qt::Key k, Qt::KeyboardModifiers m); - - void hoverChanged(GLObjectBase * cur, GLObjectBase * prev) {/*qDebug() << "hovered" << (cur != 0 ? cur->name() : "0") << ", previous" << (prev != 0 ? prev->name() : "0");*/} - void selectionChanged(GLObjectBase * cur, GLObjectBase * prev); /*{qDebug() << "selected" << (cur != 0 ? cur->name() : "0") << ", previous" << (prev != 0 ? prev->name() : "0");}*/ - void materialChanged(); public slots: diff --git a/qglview/mainwindow.ui b/qglview/mainwindow.ui index b234152..25ec30e 100644 --- a/qglview/mainwindow.ui +++ b/qglview/mainwindow.ui @@ -6,25 +6,24 @@ 0 0 - 1131 - 781 + 1125 + 808 - Stanley designer - - - - :/icons/stanley_128.png:/icons/stanley_128.png + QGLView converter - + 2 + + 0 + @@ -53,313 +52,713 @@ - - - QFormLayout::AllNonFixedFieldsGrow + + + 0 - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - FOV - - - - - - - 0.100000000000000 - - - 179.900000000000006 - - - 60.000000000000000 - - - - - - - accomodation time - - - - - - - accomodation max speed - - - - - - - dynamic cubemap size - - - - - - - shadowmap size - - - - - - - motion blur factor - - - - - - - motion blur steps - - - - - - - 0.000000000000000 - - - 256.000000000000000 - - - 32.000000000000000 - - - true - - - - - - - 0.010000000000000 - - - 1.000000000000000 - - - 0.100000000000000 - - - 3 - - - 0.100000000000000 - - - 1.000000000000000 - - - true - - - - - - - 16.000000000000000 - - - 2048.000000000000000 - - - 512.000000000000000 - - - 0 - - - 16.000000000000000 - - - 512.000000000000000 - - - false - - - - - - - 16.000000000000000 - - - 2048.000000000000000 - - - 512.000000000000000 - - - 0 - - - 16.000000000000000 - - - 512.000000000000000 - - - true - - - - - - - 0.000000000000000 - - - 10000.000000000000000 - - - 1.000000000000000 - - - 1 - - - 0.100000000000000 - - - 1.000000000000000 - - - false - - - - - - - 1.000000000000000 - - - 128.000000000000000 - - - 8.000000000000000 - - - 0 - - - 1.000000000000000 - - - 4.000000000000000 - - - false - - - - - - - bloom factor - - - - - - - bloom radius - - - - - - - 0.000000000000000 - - - 100.000000000000000 - - - 1.000000000000000 - - - 1 - - - 0.100000000000000 - - - 1.000000000000000 - - - false - - - - - - - 1.000000000000000 - - - 128.000000000000000 - - - 8.000000000000000 - - - 0 - - - 1.000000000000000 - - - 4.000000000000000 - - - false - - - - - - - bloom threshold - - - - - - - 0.000000000000000 - - - 1.000000000000000 - - - 0.900000000000000 - - - 1 - - - 0.100000000000000 - - - 1.000000000000000 - - - false - - - - + + + Common + + + + QFormLayout::AllNonFixedFieldsGrow + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + FOV + + + + + + + 0.100000000000000 + + + 179.900000000000006 + + + 60.000000000000000 + + + + + + + Renderer + + + + + + + 1 + + + + Simple + + + + + Deferred shading + + + + + + + + Draw mode + + + + + + + 2 + + + + Point + + + + + Wireframe + + + + + Solid + + + + + + + + Ambient + + + + + + + + 10 + 10 + 10 + + + + + + + + MSAA + + + + + + + FXAA + + + + + + + Hover halo + + + true + + + + + + + 10 + 10 + 10 + + + + true + + + + + + + Fill + + + + + + + 0.000000000000000 + + + 1.000000000000000 + + + 0.300000000000000 + + + 2 + + + 0.050000000000000 + + + 0.100000000000000 + + + + + + + + + + Selection halo + + + true + + + + + + + 10 + 10 + 10 + + + + true + + + + + + + Fill + + + + + + + 0.000000000000000 + + + 1.000000000000000 + + + 0.300000000000000 + + + 2 + + + 0.050000000000000 + + + 0.100000000000000 + + + + + + + + + + Camera + + + + + + Orbit + + + true + + + + + + + Camera Light + + + + + + + + + + Depth + + + + + + + 0 + + + + + 9999999.000000000000000 + + + 1.000000000000000 + + + + + + + + 0 + 0 + + + + - + + + + + + + 9999999.000000000000000 + + + + + + + + + Back color + + + + + + + + 10 + 10 + 10 + + + + + + + + + Features + + + + + + Shadows + + + true + + + + QFormLayout::AllNonFixedFieldsGrow + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + Shadowmap size + + + + + + + 16.000000000000000 + + + 2048.000000000000000 + + + 512.000000000000000 + + + 0 + + + 16.000000000000000 + + + 512.000000000000000 + + + true + + + + + + + Soft + + + true + + + + + + + + + + Bloom + + + true + + + + QFormLayout::AllNonFixedFieldsGrow + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + Factror + + + + + + + 0.000000000000000 + + + 100.000000000000000 + + + 1.000000000000000 + + + 1 + + + 0.100000000000000 + + + 1.000000000000000 + + + false + + + + + + + 1.000000000000000 + + + 128.000000000000000 + + + 8.000000000000000 + + + 0 + + + 1.000000000000000 + + + 4.000000000000000 + + + false + + + + + + + Radius + + + + + + + Threshold + + + + + + + 0.000000000000000 + + + 1.000000000000000 + + + 0.900000000000000 + + + 2 + + + 0.050000000000000 + + + 0.100000000000000 + + + false + + + + + + + + + + Motion blur + + + true + + + + QFormLayout::AllNonFixedFieldsGrow + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + Factror + + + + + + + Steps + + + + + + + 0.000000000000000 + + + 10000.000000000000000 + + + 1.000000000000000 + + + 1 + + + 0.100000000000000 + + + 1.000000000000000 + + + false + + + + + + + 1.000000000000000 + + + 128.000000000000000 + + + 8.000000000000000 + + + 0 + + + 1.000000000000000 + + + 4.000000000000000 + + + false + + + + + + + + + + Eye accomodation + + + true + + + + QFormLayout::AllNonFixedFieldsGrow + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + Time + + + + + + + Max speed + + + + + + + 0.000000000000000 + + + 256.000000000000000 + + + 32.000000000000000 + + + true + + + + + + + 0.010000000000000 + + + 1.000000000000000 + + + 0.100000000000000 + + + 3 + + + 0.100000000000000 + + + 1.000000000000000 + + + true + + + + + + + + + + Reflections + + + true + + + + QFormLayout::AllNonFixedFieldsGrow + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + Cubemap size + + + + + + + 16.000000000000000 + + + 2048.000000000000000 + + + 512.000000000000000 + + + 0 + + + 16.000000000000000 + + + 512.000000000000000 + + + true + + + + + + + + + @@ -382,214 +781,6 @@ - - - - 2 - - - - point - - - - - wireframe - - - - - solid - - - - - - - - 0 - - - - simple - - - - - per-pixel - - - - - deferred shading - - - - - - - - - 10 - 10 - 10 - - - - true - - - - - - - halo fill alpha - - - - - - - 0.000000000000000 - - - 1.000000000000000 - - - 0.300000000000000 - - - 3 - - - 0.010000000000000 - - - 0.100000000000000 - - - - - - - 20 - - - - - dynamic reflections - - - - - - - bad accumulation - - - - - - - selection halo - - - true - - - - - - - shadows - - - - - - - false - - - soft shadows - - - true - - - - - - - orbit camera - - - true - - - - - - - accomodation - - - - - - - bloom - - - - - - - motion blur - - - - - - - FXAA - - - - - - - MSAA - - - - - - - Follow camera light - - - - - - - - - ambient - - - - - - - - 10 - 10 - 10 - - - - @@ -651,22 +842,6 @@ - - - Страница - - - - - - - 1 - - - - - - @@ -682,17 +857,115 @@ + + + + Objects + + + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::ScrollPerPixel + + + true + + + + Name + + + + + + + + + + toolBar + + + TopToolBarArea + + + false + + + + + + 0 + 0 + 1125 + 26 + + + + + File + + + + + + + + + + + + - + :/icons/application-exit.png:/icons/application-exit.png Exit + + + + :/icons/document-import.png:/icons/document-import.png + + + Import ... + + + + + + :/icons/document-open.png:/icons/document-open.png + + + Open ... + + + + + + :/icons/document-save-.png:/icons/document-save-.png + + + Save ... + + + + + + :/icons/document-new.png:/icons/document-new.png + + + Reset + + @@ -723,29 +996,9 @@
globject_editor.h
1
- - PropertyEditor - QTreeWidget -
propertyeditor.h
-
- - - - checkShadows - toggled(bool) - checkSoftShadows - setEnabled(bool) - - - 126 - 708 - - - 128 - 731 - - - - + + + + diff --git a/qglview/material_map_editor.cpp b/qglview/material_map_editor.cpp index c1e9478..f090c2f 100644 --- a/qglview/material_map_editor.cpp +++ b/qglview/material_map_editor.cpp @@ -40,11 +40,23 @@ void MaterialMapEditor::changeEvent(QEvent * e) { } +void MaterialMapEditor::resizeEvent(QResizeEvent * e) { + ui->iconedLabel->setFixedWidth(ui->iconedLabel->height()); + ui->iconedLabel->setIconSize(ui->iconedLabel->size()); +} + + +void MaterialMapEditor::updateIcon() { + ui->iconedLabel->setIcon(QIcon(ui->linePath->property("GLpath").toString())); +} + + void MaterialMapEditor::setMap(const Map & m) { active = false; ui->sliderAmount->setValue(m.color_amount); ui->sliderOffset->setValue(m.color_offset); ui->linePath->setProperty("GLpath", m.bitmap_path); ui->linePath->setText(QFileInfo(m.bitmap_path).fileName()); + updateIcon(); active = true; } @@ -63,6 +75,7 @@ void MaterialMapEditor::on_buttonSelect_clicked() { if (str.isEmpty()) return; ui->linePath->setProperty("GLpath", str); ui->linePath->setText(QFileInfo(str).fileName()); + updateIcon(); mapChanged(); } @@ -70,5 +83,6 @@ void MaterialMapEditor::on_buttonSelect_clicked() { void MaterialMapEditor::on_buttonClear_clicked() { ui->linePath->setText(""); ui->linePath->setProperty("GLpath", ""); + updateIcon(); mapChanged(); } diff --git a/qglview/material_map_editor.h b/qglview/material_map_editor.h index c537e3f..0ec0142 100644 --- a/qglview/material_map_editor.h +++ b/qglview/material_map_editor.h @@ -37,6 +37,8 @@ public: protected: void changeEvent(QEvent * e); + void resizeEvent(QResizeEvent * e); + void updateIcon(); bool active; Ui::MaterialMapEditor * ui; diff --git a/qglview/material_map_editor.ui b/qglview/material_map_editor.ui index 3f4ba26..f97cf3d 100644 --- a/qglview/material_map_editor.ui +++ b/qglview/material_map_editor.ui @@ -10,95 +10,103 @@ 74 - - - QFormLayout::AllNonFixedFieldsGrow - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + 0 0 - - - - 2 + + + + IconedLabel::RightToLeft - - + + + + + + + + 2 + + + + + + + + X + + + + + + + ^ + + + + - - + + - X + Amount: - - + + + + -10.000000000000000 + + + 10.000000000000000 + + + 1.000000000000000 + + + 2 + + + 0.050000000000000 + + + 0.200000000000000 + + + + + - ^ + Offset: + + + + + + + -10.000000000000000 + + + 10.000000000000000 + + + 2 + + + 0.050000000000000 + + + 0.200000000000000 - - - - Amount: - - - - - - - -10.000000000000000 - - - 10.000000000000000 - - - 1.000000000000000 - - - 2 - - - 0.050000000000000 - - - 0.200000000000000 - - - - - - - Offset: - - - - - - - -10.000000000000000 - - - 10.000000000000000 - - - 2 - - - 0.050000000000000 - - - 0.200000000000000 - - - @@ -107,6 +115,11 @@ QWidget
spinslider.h
+ + IconedLabel + QFrame +
iconedlabel.h
+
diff --git a/qglview/qglview.cpp b/qglview/qglview.cpp index 2c2a47b..cd585b1 100644 --- a/qglview/qglview.cpp +++ b/qglview/qglview.cpp @@ -108,7 +108,7 @@ void QGLView::addObject(QWidget * o, Qt::WindowFlags f) { void QGLView::addObject(GLObjectBase * o) { - o->view_ = this; + o->setView(this); objects_.addChild(o); collectLights(); if (is_init) { @@ -119,6 +119,12 @@ void QGLView::addObject(GLObjectBase * o) { } +void QGLView::selectObject(GLObjectBase * o) { + emit selectionChanged(o, sel_obj); + sel_obj = o; +} + + void QGLView::drawBackground(QPainter * painter, const QRectF & rect) { static bool f = true; painter_ = painter; @@ -472,7 +478,7 @@ void QGLView::collectGraphicItems(QList & list, QGraphicsItem void QGLView::collectObjectLights(GLObjectBase * o) { - if (o->type_ == GLObjectBase::Light) lights_ << globject_cast(o); + if (o->type_ == GLObjectBase::glLight) lights_ << globject_cast(o); foreach (GLObjectBase * i, o->children()) collectObjectLights(i); } @@ -530,10 +536,8 @@ void QGLView::mouseReleaseEvent(QMouseEvent * e) { selecting_ = false; if (mouseThis_ && mouseSelect_ && e->button() == Qt::LeftButton) { if ((lastPos - downPos).manhattanLength() < 8) { - if (sel_obj != hov_obj) { - emit selectionChanged(hov_obj, sel_obj); - sel_obj = hov_obj; - } + if (sel_obj != hov_obj) + selectObject(hov_obj); } } emit glMouseReleaseEvent(e); diff --git a/qglview/qglview.h b/qglview/qglview.h index 01f86d9..e538d46 100644 --- a/qglview/qglview.h +++ b/qglview/qglview.h @@ -157,7 +157,7 @@ public: int objectsCount(bool all = false) {if (!all) return objects_.childCount(); int cnt = 0; objectsCountInternal(&cnt, &objects_); return cnt;} void removeObject(GLObjectBase * o, bool inChildren = true) {if (inChildren) removeObjectInternal(o, &objects_); else objects_.removeChild(o);} void removeObject(GLObjectBase & o, bool inChildren = true) {removeObject(&o, inChildren);} - void clearObjects(bool deleteAll = false) {objects_.clearChildren(deleteAll);} + void clearObjects(bool deleteAll = false) {objects_.clearChildren(deleteAll); sel_obj = hov_obj = 0;} QList objects(bool all = false) {return objects_.children(all);} int lightsCount() const {return lights_.size();} @@ -187,6 +187,7 @@ public: void setSelectionModifier(Qt::KeyboardModifier v) {sel_mod = v;} void setSelectionRectPen(const QPen & v) {sel_pen = v;} void setSelectionRectBrush(const QBrush & v) {sel_brush = v;} + void selectObject(GLObjectBase * o); GLdouble aspect, iaspect; //QGLShaderProgram * shader_rope; diff --git a/qglview/qglview.qrc b/qglview/qglview.qrc new file mode 100644 index 0000000..169e46e --- /dev/null +++ b/qglview/qglview.qrc @@ -0,0 +1,28 @@ + + + icons/document-new.png + icons/document-import.png + icons/dialog-close.png + icons/edit-clear.png + icons/edit-guides.png + icons/type-camera.png + icons/type-geo.png + icons/type-light.png + icons/view-grid.png + icons/zoom-fit-best.png + icons/configure.png + icons/document-save.png + icons/edit-clear-locationbar-rtl.png + icons/edit-find.png + icons/list-add.png + icons/edit-delete.png + icons/item.png + icons/node-add.png + icons/application-exit.png + icons/document-open.png + icons/document-save-.png + icons/node.png + icons/edit-copy.png + icons/edit-paste.png + + diff --git a/qglview/shaders/dsl_pass_0.frag b/qglview/shaders/dsl_pass_0.frag index 9b2ec41..d9a5701 100644 --- a/qglview/shaders/dsl_pass_0.frag +++ b/qglview/shaders/dsl_pass_0.frag @@ -5,7 +5,7 @@ in vec3 src_normal, normal, binormal;//, et; in vec4 pos, ppos; -in float fogCoord, logz; +in float fogCoord, FC, C; in mat3 TBN; uniform bool acc_fog; @@ -16,6 +16,7 @@ const vec3 luma = vec3(0.299, 0.587, 0.114); void main(void) { //float z = pos.w;//((z_near / (z_near-z_far)) * z_far) / (pos.w - (z_far / (z_far-z_near))); + float logz = log(pos.w * C + 1.) * FC; vec4 dc = qgl_FragColor; vec2 tc = qgl_FragTexture.xy; float hei = dot(texture(qgl_Material.map_relief.map, tc).rgb, luma) * qgl_Material.map_relief.amount + qgl_Material.map_relief.offset; diff --git a/qglview/shaders/dsl_pass_0.vert b/qglview/shaders/dsl_pass_0.vert index 39c2f68..ab3f806 100644 --- a/qglview/shaders/dsl_pass_0.vert +++ b/qglview/shaders/dsl_pass_0.vert @@ -2,7 +2,7 @@ out vec3 src_normal, normal, binormal;//, et; out vec4 pos, ppos; -out float fogCoord, logz; +out float fogCoord, FC, C; out mat3 TBN; uniform bool acc_fog; @@ -11,9 +11,6 @@ uniform vec3 eye; uniform mat4 prev_ModelViewProjectioMatrix; uniform float z_near, z_far; -const float C = 0.0001; -float FC = 1. / log(z_far * C + 1.); - void main(void) { normal = qgl_Normal;//(qgl_NormalMatrix * qgl_Normal); binormal = qgl_Bitangent;//(qgl_NormalMatrix * qgl_Normal); @@ -39,7 +36,9 @@ void main(void) { //pos *= pos.w; //logz = gl_Position.w*C + 1; //version with fragment code - logz = log(pos.w * C + 1.) * FC; + C = 0.01; + FC = 1. / log(z_far * C + 1.); + //pos.z = (logz + logz - 1) * pos.w; gl_Position = pos;