code format

This commit is contained in:
2022-12-14 14:14:44 +03:00
parent 1dfca0aeab
commit cb944b62e4
85 changed files with 4451 additions and 3744 deletions

View File

@@ -17,9 +17,10 @@
*/ */
#define GL_GLEXT_PROTOTYPES #define GL_GLEXT_PROTOTYPES
#include <QOpenGLExtraFunctions>
#include "glbuffer.h" #include "glbuffer.h"
#include <QOpenGLExtraFunctions>
Buffer::Buffer(GLenum target, GLenum _usage) { Buffer::Buffer(GLenum target, GLenum _usage) {
target_ = target; target_ = target;
@@ -29,8 +30,7 @@ Buffer::Buffer(GLenum target, GLenum _usage) {
} }
Buffer::~Buffer() { Buffer::~Buffer() {}
}
void Buffer::init(QOpenGLExtraFunctions * f) { void Buffer::init(QOpenGLExtraFunctions * f) {

View File

@@ -22,9 +22,9 @@
#include "gltypes.h" #include "gltypes.h"
class Buffer class Buffer {
{
friend class ObjectBase; friend class ObjectBase;
public: public:
Buffer(GLenum target, GLenum usage = GL_DYNAMIC_DRAW); Buffer(GLenum target, GLenum usage = GL_DYNAMIC_DRAW);
~Buffer(); ~Buffer();
@@ -52,7 +52,6 @@ private:
GLenum target_, usage_; GLenum target_, usage_;
GLuint buffer_; GLuint buffer_;
int prev_size; int prev_size;
}; };

View File

@@ -16,8 +16,9 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "gltypes.h"
#include "glcubemap.h" #include "glcubemap.h"
#include "gltypes.h"
#include "hdr_p.h" #include "hdr_p.h"
using namespace QGLEngineShaders; using namespace QGLEngineShaders;
@@ -62,8 +63,7 @@ QVector<QVector3D> loadFileHDR(const QString & path, QSize * size) {
QDataStream ds(&f); QDataStream ds(&f);
int count = sz.width() * sz.height(); int count = sz.width() * sz.height();
QVector<float> data(count * 3); QVector<float> data(count * 3);
if (!RGBE_ReadPixels_RLE(&ds, data.data(), sz.width(), sz.height())) if (!RGBE_ReadPixels_RLE(&ds, data.data(), sz.width(), sz.height())) return ret;
return ret;
if (size) *size = sz; if (size) *size = sz;
ret.resize(count); ret.resize(count);
@@ -71,9 +71,7 @@ QVector<QVector3D> loadFileHDR(const QString & path, QSize * size) {
// QImage im(sz, QImage::Format_ARGB32); // QImage im(sz, QImage::Format_ARGB32);
// QRgb * imdata = (QRgb*)im.bits(); // QRgb * imdata = (QRgb*)im.bits();
for (int i = 0; i < count; ++i) { for (int i = 0; i < count; ++i) {
QVector3D p(pow(data[i*3 + 2], 1. / 2.2), QVector3D p(pow(data[i * 3 + 2], 1. / 2.2), pow(data[i * 3 + 1], 1. / 2.2), pow(data[i * 3 + 0], 1. / 2.2));
pow(data[i*3 + 1], 1. / 2.2),
pow(data[i*3 + 0], 1. / 2.2));
ret[i] = p; ret[i] = p;
// col = QColor::fromRgbF(piClamp(p[0], 0.f, 1.f), // col = QColor::fromRgbF(piClamp(p[0], 0.f, 1.f),
// piClamp(p[1], 0.f, 1.f), // piClamp(p[1], 0.f, 1.f),
@@ -151,7 +149,6 @@ QVector<QVector3D> faceHDR(const QVector<QVector3D> & data, QSize sz, QSize & fs
} }
CubeTexture::CubeTexture(QOpenGLExtraFunctions * f_, int _size, const GLenum & _format): f(f_) { CubeTexture::CubeTexture(QOpenGLExtraFunctions * f_, int _size, const GLenum & _format): f(f_) {
size = _size; size = _size;
format_ = _format; format_ = _format;
@@ -200,7 +197,15 @@ void CubeTexture::loadHDR(const QVector<QVector3D> & data, QSize sz) {
for (int i = 0; i < 6; ++i) { for (int i = 0; i < 6; ++i) {
fd = faceHDR(data, sz, fsz, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i); fd = faceHDR(data, sz, fsz, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i);
// qDebug() << "load cube" << fd[0]; // qDebug() << "load cube" << fd[0];
f->glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, format_, fsz.width(), fsz.height(), 0, GL_RGB, GL_FLOAT, fd.isEmpty() ? 0 : fd.constData()); f->glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
0,
format_,
fsz.width(),
fsz.height(),
0,
GL_RGB,
GL_FLOAT,
fd.isEmpty() ? 0 : fd.constData());
// qDebug() << QString::number(GetLastError(), 16); // qDebug() << QString::number(GetLastError(), 16);
} }
f->glGenerateMipmap(GL_TEXTURE_CUBE_MAP); f->glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
@@ -230,4 +235,3 @@ void CubeTexture::load() {
} }
changed_ = false; changed_ = false;
} }

View File

@@ -19,8 +19,8 @@
#ifndef GLCUBEMAP_H #ifndef GLCUBEMAP_H
#define GLCUBEMAP_H #define GLCUBEMAP_H
#include "glshaders_types.h"
#include "chunkstream.h" #include "chunkstream.h"
#include "glshaders_types.h"
QVector<QVector3D> loadFileHDR(const QString & path, QSize * size = 0); QVector<QVector3D> loadFileHDR(const QString & path, QSize * size = 0);
@@ -31,17 +31,23 @@ public:
void destroy(); void destroy();
void bind(int channel = 0); void bind(int channel = 0);
void release(); void release();
void resize(int _size) {size = _size; changed_ = true;} void resize(int _size) {
size = _size;
changed_ = true;
}
void loadHDR(const QVector<QVector3D> & data, QSize sz); void loadHDR(const QVector<QVector3D> & data, QSize sz);
void setFileHDR(const QString & path); void setFileHDR(const QString & path);
QString fileHDR() const { return hdr_path; } QString fileHDR() const { return hdr_path; }
GLenum format() const { return format_; } GLenum format() const { return format_; }
void setFormat(GLenum f) {format_ = f; changed_ = true;} void setFormat(GLenum f) {
format_ = f;
changed_ = true;
}
GLuint id() const { return id_; } GLuint id() const { return id_; }
bool isInit() const { return id_ != 0; } bool isInit() const { return id_ != 0; }
void load(); void load();
private:
private:
QOpenGLExtraFunctions * f; QOpenGLExtraFunctions * f;
bool changed_; bool changed_;
int size; int size;

View File

@@ -16,13 +16,15 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <QOpenGLExtraFunctions>
#include "glframebuffer.h" #include "glframebuffer.h"
#include <QOpenGLExtraFunctions>
#include <QTime> #include <QTime>
Framebuffer::Framebuffer(QOpenGLExtraFunctions * f_, int colorAttachments_, bool withDepth, GLenum colorFormat_, GLenum _target) Framebuffer::Framebuffer(QOpenGLExtraFunctions * f_, int colorAttachments_, bool withDepth, GLenum colorFormat_, GLenum _target)
: f(f_), pbo(GL_PIXEL_PACK_BUFFER, GL_STREAM_DRAW) { : f(f_)
, pbo(GL_PIXEL_PACK_BUFFER, GL_STREAM_DRAW) {
is_depth = withDepth; is_depth = withDepth;
target_ = _target; target_ = _target;
color_formats.fill(colorFormat_, colorAttachments_); color_formats.fill(colorFormat_, colorAttachments_);
@@ -36,7 +38,8 @@ Framebuffer::Framebuffer(QOpenGLExtraFunctions * f_, int colorAttachments_, bool
Framebuffer::Framebuffer(QOpenGLExtraFunctions * f_, QVector<GLenum> colors_, bool withDepth, GLenum _target) Framebuffer::Framebuffer(QOpenGLExtraFunctions * f_, QVector<GLenum> colors_, bool withDepth, GLenum _target)
: f(f_), pbo(GL_PIXEL_PACK_BUFFER, GL_STREAM_DRAW) { : f(f_)
, pbo(GL_PIXEL_PACK_BUFFER, GL_STREAM_DRAW) {
is_depth = withDepth; is_depth = withDepth;
target_ = _target; target_ = _target;
color_formats = colors_; color_formats = colors_;
@@ -152,8 +155,7 @@ uint Framebuffer::getPoint() const {
uint ret = 0; uint ret = 0;
pbo.bind(f); pbo.bind(f);
void * map = pbo.map(f, GL_MAP_READ_BIT, sizeof(uint)); void * map = pbo.map(f, GL_MAP_READ_BIT, sizeof(uint));
if (map) if (map) memcpy(&ret, map, sizeof(uint));
memcpy(&ret, map, sizeof(uint));
pbo.unmap(f); pbo.unmap(f);
pbo.release(f); pbo.release(f);
return ret; return ret;
@@ -166,8 +168,7 @@ QVector<uint> Framebuffer::getPointsByte() const {
ret.resize(pbo_queried); ret.resize(pbo_queried);
pbo.bind(f); pbo.bind(f);
void * map = pbo.map(f, GL_MAP_READ_BIT, pbo_queried * sizeof(uint)); void * map = pbo.map(f, GL_MAP_READ_BIT, pbo_queried * sizeof(uint));
if (map) if (map) memcpy(ret.data(), map, pbo_queried * sizeof(uint));
memcpy(ret.data(), map, pbo_queried * sizeof(uint));
pbo.unmap(f); pbo.unmap(f);
pbo.release(f); pbo.release(f);
return ret; return ret;
@@ -180,8 +181,7 @@ QVector<QVector4D> Framebuffer::getPointsFloat() const {
ret.resize(pbo_queried); ret.resize(pbo_queried);
pbo.bind(f); pbo.bind(f);
void * map = pbo.map(f, GL_MAP_READ_BIT, pbo_queried * sizeof(QVector4D)); void * map = pbo.map(f, GL_MAP_READ_BIT, pbo_queried * sizeof(QVector4D));
if (map) if (map) memcpy(ret.data(), map, pbo_queried * sizeof(QVector4D));
memcpy(ret.data(), map, pbo_queried * sizeof(QVector4D));
pbo.unmap(f); pbo.unmap(f);
pbo.release(f); pbo.release(f);
return ret; return ret;
@@ -195,8 +195,7 @@ QImage Framebuffer::getImage() const {
int bytes = width() * height() * 4; int bytes = width() * height() * 4;
pbo.bind(f); pbo.bind(f);
void * map = pbo.map(f, GL_MAP_READ_BIT, bytes); void * map = pbo.map(f, GL_MAP_READ_BIT, bytes);
if (map) if (map) memcpy(ret.bits(), map, bytes);
memcpy(ret.bits(), map, bytes);
pbo.unmap(f); pbo.unmap(f);
pbo.release(f); pbo.release(f);
return ret; return ret;
@@ -311,14 +310,12 @@ void Framebuffer::bindDepthTexture(int channel) {
void Framebuffer::deleteGLRenderbuffer(GLuint & drbo) { void Framebuffer::deleteGLRenderbuffer(GLuint & drbo) {
if (drbo != 0) if (drbo != 0) f->glDeleteRenderbuffers(1, &drbo);
f->glDeleteRenderbuffers(1, &drbo);
drbo = 0; drbo = 0;
} }
void Framebuffer::deleteGLFramebuffer(GLuint & fbo) { void Framebuffer::deleteGLFramebuffer(GLuint & fbo) {
if (fbo != 0) if (fbo != 0) f->glDeleteFramebuffers(1, &fbo);
f->glDeleteFramebuffers(1, &fbo);
fbo = 0; fbo = 0;
} }

View File

@@ -22,11 +22,15 @@
#include "glbuffer.h" #include "glbuffer.h"
class Framebuffer class Framebuffer {
{
friend class FramebufferMipmap; friend class FramebufferMipmap;
public: public:
Framebuffer(QOpenGLExtraFunctions * f_, int colorAttachments = 1, bool withDepth = true, GLenum colorFormat = GL_RGBA8, GLenum _target = GL_TEXTURE_2D); Framebuffer(QOpenGLExtraFunctions * f_,
int colorAttachments = 1,
bool withDepth = true,
GLenum colorFormat = GL_RGBA8,
GLenum _target = GL_TEXTURE_2D);
Framebuffer(QOpenGLExtraFunctions * f_, QVector<GLenum> colors_, bool withDepth = true, GLenum _target = GL_TEXTURE_2D); Framebuffer(QOpenGLExtraFunctions * f_, QVector<GLenum> colors_, bool withDepth = true, GLenum _target = GL_TEXTURE_2D);
virtual ~Framebuffer(); virtual ~Framebuffer();
@@ -49,7 +53,13 @@ public:
QVector<QVector4D> getPointsFloat() const; QVector<QVector4D> getPointsFloat() const;
QImage getImage() const; QImage getImage() const;
int queriedPoints() const { return pbo_queried; } int queriedPoints() const { return pbo_queried; }
void blit(int index_from, GLuint fb_to, int index_to, QRect from, QRect to, GLbitfield mask = GL_COLOR_BUFFER_BIT, GLenum filter = GL_NEAREST) const; void blit(int index_from,
GLuint fb_to,
int index_to,
QRect from,
QRect to,
GLbitfield mask = GL_COLOR_BUFFER_BIT,
GLenum filter = GL_NEAREST) const;
void resize(int width, int height, bool force = false); void resize(int width, int height, bool force = false);
void reinit(); void reinit();

View File

@@ -16,8 +16,9 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <QOpenGLExtraFunctions>
#include "glframebuffer_mipmap.h" #include "glframebuffer_mipmap.h"
#include <QOpenGLExtraFunctions>
#include <QTime> #include <QTime>
@@ -28,9 +29,7 @@ FramebufferMipmap::FramebufferMipmap(const Framebuffer & fb, int index_from_, in
} }
FramebufferMipmap::~FramebufferMipmap() { FramebufferMipmap::~FramebufferMipmap() {}
}
void FramebufferMipmap::resize() { void FramebufferMipmap::resize() {

View File

@@ -22,8 +22,7 @@
#include "glframebuffer.h" #include "glframebuffer.h"
class FramebufferMipmap class FramebufferMipmap {
{
public: public:
FramebufferMipmap(const Framebuffer & fb, int index_from_, int levels = 2); FramebufferMipmap(const Framebuffer & fb, int index_from_, int levels = 2);
virtual ~FramebufferMipmap(); virtual ~FramebufferMipmap();
@@ -45,7 +44,6 @@ private:
int index_from; int index_from;
const Framebuffer & src_fb; const Framebuffer & src_fb;
QVector<Framebuffer *> fbo; QVector<Framebuffer *> fbo;
}; };
#endif // GLFRAMEBUFFER_MIPMAP_H #endif // GLFRAMEBUFFER_MIPMAP_H

View File

@@ -16,8 +16,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "gltypes.h"
#include "gltexture_manager.h" #include "gltexture_manager.h"
#include "gltypes.h"
#include "qglview.h" #include "qglview.h"
using namespace QGLEngineShaders; using namespace QGLEngineShaders;
@@ -41,8 +41,7 @@ void Map::setBitmapPath(const QString & p) {
void Map::load(TextureManager * tm) { void Map::load(TextureManager * tm) {
if (bitmap_id == 0) if (bitmap_id == 0) bitmap_id = tm->loadTexture(bitmap_path, true, _type == mtNormal);
bitmap_id = tm->loadTexture(bitmap_path, true, _type == mtNormal);
} }
@@ -60,8 +59,6 @@ void Map::copyToQGLMap(QGLMap & m) const {
} }
Material::Material(const QString _name) { Material::Material(const QString _name) {
setTypes(); setTypes();
name = _name; name = _name;
@@ -89,11 +86,7 @@ bool Material::hasTransparency() const {
bool Material::isMapsChanged() const { bool Material::isMapsChanged() const {
return map_diffuse ._changed || return map_diffuse._changed || map_normal._changed || map_metalness._changed || map_roughness._changed || map_emission._changed ||
map_normal ._changed ||
map_metalness._changed ||
map_roughness._changed ||
map_emission ._changed ||
map_relief._changed; map_relief._changed;
} }

View File

@@ -19,8 +19,8 @@
#ifndef GLMATERIAL_H #ifndef GLMATERIAL_H
#define GLMATERIAL_H #define GLMATERIAL_H
#include "glshaders_types.h"
#include "chunkstream.h" #include "chunkstream.h"
#include "glshaders_types.h"
class Map { class Map {
@@ -75,24 +75,33 @@ public:
inline QDataStream & operator<<(QDataStream & s, const Map & m) { inline QDataStream & operator<<(QDataStream & s, const Map & m) {
ChunkStream cs; ChunkStream cs;
cs.add(1, m.bitmap_path).add(2, m.color_amount).add(3, m.color_offset).add(6, m.bitmap_scale) cs.add(1, m.bitmap_path).add(2, m.color_amount).add(3, m.color_offset).add(6, m.bitmap_scale).add(7, m.use_bitmap);
.add(7, m.use_bitmap); s << cs.data();
s << cs.data(); return s; return s;
} }
inline QDataStream & operator>>(QDataStream & s, Map & m) { inline QDataStream & operator>>(QDataStream & s, Map & m) {
ChunkStream cs(s); ChunkStream cs(s);
cs.readAll(); cs.readAll();
cs.get(1, m.bitmap_path).get(2, m.color_amount).get(3, m.color_offset).get(6, m.bitmap_scale) cs.get(1, m.bitmap_path).get(2, m.color_amount).get(3, m.color_offset).get(6, m.bitmap_scale).get(7, m.use_bitmap);
.get(7, m.use_bitmap);
return s; return s;
} }
inline QDataStream & operator<<(QDataStream & s, const Material * m) { inline QDataStream & operator<<(QDataStream & s, const Material * m) {
ChunkStream cs; ChunkStream cs;
cs.add(1, m->name).add(2, m->color_diffuse).add(4, m->color_emission) cs.add(1, m->name)
.add(5, m->transparency).add(6, m->reflectivity).add(7, m->glass).add(8, m->map_diffuse).add(9, m->map_normal) .add(2, m->color_diffuse)
.add(10, m->map_relief).add(11, m->map_metalness).add(12, m->map_roughness).add(13, m->map_emission); .add(4, m->color_emission)
s << (cs.data()); return s; .add(5, m->transparency)
.add(6, m->reflectivity)
.add(7, m->glass)
.add(8, m->map_diffuse)
.add(9, m->map_normal)
.add(10, m->map_relief)
.add(11, m->map_metalness)
.add(12, m->map_roughness)
.add(13, m->map_emission);
s << (cs.data());
return s;
} }
inline QDataStream & operator>>(QDataStream & s, Material *& m) { inline QDataStream & operator>>(QDataStream & s, Material *& m) {
m = new Material(); m = new Material();

View File

@@ -17,18 +17,21 @@
*/ */
#define GL_GLEXT_PROTOTYPES #define GL_GLEXT_PROTOTYPES
#include <QOpenGLExtraFunctions>
#include "glmesh.h" #include "glmesh.h"
#include "globject.h" #include "globject.h"
#include <QOpenGLExtraFunctions>
#include <QTime> #include <QTime>
using namespace QGLEngineShaders; using namespace QGLEngineShaders;
// static int _count = 0; // static int _count = 0;
Mesh::Mesh(GLenum geom_type_): geom_type(geom_type_), Mesh::Mesh(GLenum geom_type_)
buffer_geom(GL_ARRAY_BUFFER, GL_STATIC_DRAW), : geom_type(geom_type_)
buffer_ind (GL_ELEMENT_ARRAY_BUFFER, GL_STATIC_DRAW) { , buffer_geom(GL_ARRAY_BUFFER, GL_STATIC_DRAW)
, buffer_ind(GL_ELEMENT_ARRAY_BUFFER, GL_STATIC_DRAW) {
hash_ = 0; hash_ = 0;
changed = hash_changed = true; changed = hash_changed = true;
// qDebug() << "Mesh, now" << ++_count; // qDebug() << "Mesh, now" << ++_count;
@@ -145,8 +148,7 @@ VertexObject * Mesh::vaoByType(int type) {
bool Mesh::rebuffer(QOpenGLExtraFunctions * f) { bool Mesh::rebuffer(QOpenGLExtraFunctions * f) {
changed = false; changed = false;
if (vertices_.isEmpty()) return true; if (vertices_.isEmpty()) return true;
if (normals_.isEmpty()) if (normals_.isEmpty()) calculateNormals();
calculateNormals();
calculateTangents(); calculateTangents();
vert_count = qMin(vertices_.size(), normals_.size()); vert_count = qMin(vertices_.size(), normals_.size());
vert_count = qMin(vert_count, tangents_.size()); vert_count = qMin(vert_count, tangents_.size());
@@ -301,8 +303,7 @@ void Mesh::transformPoints(const QMatrix4x4 & mat) {
int vcnt = vertices_.size(), ncnt = normals_.size(); int vcnt = vertices_.size(), ncnt = normals_.size();
for (int i = 0; i < vcnt; ++i) { for (int i = 0; i < vcnt; ++i) {
vertices_[i] = (mat * QVector4D(vertices_[i], 1)).toVector3D(); vertices_[i] = (mat * QVector4D(vertices_[i], 1)).toVector3D();
if (i < ncnt) if (i < ncnt) normals_[i] = (mat * QVector4D(normals_[i], 0)).toVector3D();
normals_[i] = (mat * QVector4D(normals_[i], 0)).toVector3D();
} }
changed = hash_changed = true; changed = hash_changed = true;
} }
@@ -407,10 +408,10 @@ Box3D Mesh::boundingBox() const {
QDataStream & operator<<(QDataStream & s, const Mesh * m) { QDataStream & operator<<(QDataStream & s, const Mesh * m) {
ChunkStream cs; ChunkStream cs;
// qDebug() << "place VBO" << m.vertices_.size() << m.normals_.size() << m.texcoords_.size() << m.colors_.size() << "..."; // qDebug() << "place VBO" << m.vertices_.size() << m.normals_.size() << m.texcoords_.size() << m.colors_.size() << "...";
cs.add(1, m->vertices_).add(2, m->normals_).add(3, m->texcoords_) cs.add(1, m->vertices_).add(2, m->normals_).add(3, m->texcoords_).add(6, m->triangles_).add(7, m->lines_).add(10, int(m->geom_type));
.add(6, m->triangles_).add(7, m->lines_).add(10, int(m->geom_type));
// qDebug() << "place VBO done" << cs.data().size() << "..."; // qDebug() << "place VBO done" << cs.data().size() << "...";
s << cs.data(); return s; s << cs.data();
return s;
} }

View File

@@ -19,14 +19,15 @@
#ifndef GLMESH_H #ifndef GLMESH_H
#define GLMESH_H #define GLMESH_H
#include <chunkstream.h>
#include "glvertexobject.h" #include "glvertexobject.h"
#include <chunkstream.h>
class Mesh
{ class Mesh {
friend QDataStream & operator<<(QDataStream & s, const Mesh * m); friend QDataStream & operator<<(QDataStream & s, const Mesh * m);
friend QDataStream & operator>>(QDataStream & s, Mesh *& m); friend QDataStream & operator>>(QDataStream & s, Mesh *& m);
public: public:
Mesh(GLenum geom_type_ = GL_TRIANGLES); Mesh(GLenum geom_type_ = GL_TRIANGLES);
~Mesh(); ~Mesh();
@@ -57,18 +58,35 @@ public:
void setAllObjectsChanged(bool yes = true); void setAllObjectsChanged(bool yes = true);
void setAllSelectionChanged(bool yes = true); void setAllSelectionChanged(bool yes = true);
QVector<QVector3D> & vertices () {changed = hash_changed = true; return vertices_;} QVector<QVector3D> & vertices() {
QVector<QVector3D> & normals () {changed = hash_changed = true; return normals_;} changed = hash_changed = true;
QVector<QVector2D> & texcoords() {changed = hash_changed = true; return texcoords_;} return vertices_;
QVector< Vector3i> & indicesTriangles() {changed = hash_changed = true; return triangles_;} }
QVector< Vector2i> & indicesLines () {changed = hash_changed = true; return lines_;} QVector<QVector3D> & normals() {
changed = hash_changed = true;
return normals_;
}
QVector<QVector2D> & texcoords() {
changed = hash_changed = true;
return texcoords_;
}
QVector<Vector3i> & indicesTriangles() {
changed = hash_changed = true;
return triangles_;
}
QVector<Vector2i> & indicesLines() {
changed = hash_changed = true;
return lines_;
}
void translatePoints(const QVector3D & dp); void translatePoints(const QVector3D & dp);
void translatePoints(const double & x, const double & y, const double & z) { translatePoints(QVector3D(x, y, z)); } void translatePoints(const double & x, const double & y, const double & z) { translatePoints(QVector3D(x, y, z)); }
void scalePoints(const QVector3D & dp); void scalePoints(const QVector3D & dp);
void scalePoints(const double & s) { scalePoints(QVector3D(s, s, s)); } void scalePoints(const double & s) { scalePoints(QVector3D(s, s, s)); }
void rotatePoints(const double & angle, const QVector3D & a); void rotatePoints(const double & angle, const QVector3D & a);
void rotatePoints (const double & angle, const double & x, const double & y, const double & z) {rotatePoints(angle, QVector3D(x, y, z));} void rotatePoints(const double & angle, const double & x, const double & y, const double & z) {
rotatePoints(angle, QVector3D(x, y, z));
}
void transformPoints(const QMatrix4x4 & mat); void transformPoints(const QMatrix4x4 & mat);
void flipNormals(); void flipNormals();
void append(const Mesh * m); void append(const Mesh * m);

View File

@@ -17,6 +17,7 @@
*/ */
#include "glprimitives.h" #include "glprimitives.h"
#include "glmesh.h" #include "glmesh.h"
@@ -27,7 +28,8 @@ Mesh * Primitive::plane(float width, float length) {
QVector<QVector2D> & t(ret->texcoords()); QVector<QVector2D> & t(ret->texcoords());
QVector<Vector3i> & i(ret->indicesTriangles()); QVector<Vector3i> & i(ret->indicesTriangles());
float hw = width / 2.f, hl = length / 2.f; float hw = width / 2.f, hl = length / 2.f;
for (int j = 0; j < 4; ++j) n << QVector3D(0., 0., 1.); for (int j = 0; j < 4; ++j)
n << QVector3D(0., 0., 1.);
t << QVector2D(0., 0.) << QVector2D(0., 1.) << QVector2D(1., 1.) << QVector2D(1., 0.); t << QVector2D(0., 0.) << QVector2D(0., 1.) << QVector2D(1., 1.) << QVector2D(1., 0.);
v << QVector3D(-hw, -hl, 0.) << QVector3D(-hw, hl, 0.) << QVector3D(hw, hl, 0.) << QVector3D(hw, -hl, 0.); v << QVector3D(-hw, -hl, 0.) << QVector3D(-hw, hl, 0.) << QVector3D(hw, hl, 0.) << QVector3D(hw, -hl, 0.);
i << Vector3i(0, 2, 1) << Vector3i(0, 3, 2); i << Vector3i(0, 2, 1) << Vector3i(0, 3, 2);
@@ -47,7 +49,8 @@ Mesh * Primitive::cube(float width, float length, float height) {
QMatrix4x4 mat; QMatrix4x4 mat;
si = v.size(); si = v.size();
for (int j = 0; j < 4; ++j) n << QVector3D(0., -1., 0.); for (int j = 0; j < 4; ++j)
n << QVector3D(0., -1., 0.);
t << QVector2D(0., 0.) << QVector2D(1., 0.) << QVector2D(1., 1.) << QVector2D(0., 1.); t << QVector2D(0., 0.) << QVector2D(1., 0.) << QVector2D(1., 1.) << QVector2D(0., 1.);
v << QVector3D(-hs, -hs, -hs) << QVector3D(hs, -hs, -hs) << QVector3D(hs, -hs, hs) << QVector3D(-hs, -hs, hs); v << QVector3D(-hs, -hs, -hs) << QVector3D(hs, -hs, -hs) << QVector3D(hs, -hs, hs) << QVector3D(-hs, -hs, hs);
i << Vector3i(si + 0, si + 1, si + 2) << Vector3i(si + 0, si + 2, si + 3); i << Vector3i(si + 0, si + 1, si + 2) << Vector3i(si + 0, si + 2, si + 3);
@@ -194,8 +197,7 @@ Mesh * Primitive::cone(int segments, float radius, float height) {
t << QVector2D((double)i / (seg - 1), 0.f); t << QVector2D((double)i / (seg - 1), 0.f);
n << coneNormal(radius, height, a); n << coneNormal(radius, height, a);
int si = v.size() - 1; int si = v.size() - 1;
if (i > 0) if (i > 0) ind << Vector3i(si - 1, si - 2, si);
ind << Vector3i(si - 1, si - 2, si);
} }
Mesh * cap = Primitive::disc(segments, radius); Mesh * cap = Primitive::disc(segments, radius);
@@ -229,7 +231,8 @@ Mesh * Primitive::cylinder(int segments, float radius, float height, float end_a
v << cp; v << cp;
t << QVector2D((double)i / (seg - 1), 0.f); t << QVector2D((double)i / (seg - 1), 0.f);
t << QVector2D((double)i / (seg - 1), 1.f); t << QVector2D((double)i / (seg - 1), 1.f);
n << norm; n << norm; n << norm;
n << norm;
int si = v.size() - 1; int si = v.size() - 1;
if (i > 0) { if (i > 0) {
ind << Vector3i(si - 2, si - 1, si); ind << Vector3i(si - 2, si - 1, si);
@@ -328,8 +331,6 @@ Mesh * Primitive::torus(int segments_main, int segments_second, float radius_mai
} }
Mesh * Primitive::cubeFrame(float width, float length, float height) { Mesh * Primitive::cubeFrame(float width, float length, float height) {
Mesh * ret = new Mesh(GL_LINES); Mesh * ret = new Mesh(GL_LINES);
QVector3D scale(width, length, height); QVector3D scale(width, length, height);

View File

@@ -50,6 +50,6 @@ Mesh * ellipsoidFrame(int segments_wl, int segments_h, float radius = 1.);
Mesh * coneFrame(int segments, float radius = 1., float height = 1.); Mesh * coneFrame(int segments, float radius = 1., float height = 1.);
} } // namespace Primitive
#endif // GLPRIMITIVE_CUBE_H #endif // GLPRIMITIVE_CUBE_H

View File

@@ -16,15 +16,21 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "glshaders.h"
#include "glshaders_headers.h"
#include "gltypes.h" #include "gltypes.h"
#include "qglview.h" #include "qglview.h"
#include "glshaders.h"
#include "glshaders_headers.h"
using namespace QGLEngineShaders; using namespace QGLEngineShaders;
bool addShader(QOpenGLShaderProgram * prog, QOpenGLShader::ShaderType type, QString & content, const QString & file, bool add_qgl, const QString & defs) { bool addShader(QOpenGLShaderProgram * prog,
QOpenGLShader::ShaderType type,
QString & content,
const QString & file,
bool add_qgl,
const QString & defs) {
if (type == 0 || content.isEmpty()) { if (type == 0 || content.isEmpty()) {
content.clear(); content.clear();
return true; return true;
@@ -37,12 +43,8 @@ bool addShader(QOpenGLShaderProgram * prog, QOpenGLShader::ShaderType type, QStr
content.prepend(qgl_uniform); content.prepend(qgl_uniform);
content.prepend(qgl_structs); content.prepend(qgl_structs);
break; break;
case QOpenGLShader::Vertex : case QOpenGLShader::Vertex: content.prepend(qgl_vertex_head); break;
content.prepend(qgl_vertex_head ); case QOpenGLShader::Geometry: content.prepend(qgl_geometry_head); break;
break;
case QOpenGLShader::Geometry:
content.prepend(qgl_geometry_head);
break;
} }
} }
content.prepend(defs); content.prepend(defs);
@@ -64,8 +66,7 @@ QString prepareDefines(const QStringList & defines) {
bool QGLEngineShaders::loadShadersMulti(QOpenGLShaderProgram *& prog, const QString & file, bool add_qgl, const QStringList & defines) { bool QGLEngineShaders::loadShadersMulti(QOpenGLShaderProgram *& prog, const QString & file, bool add_qgl, const QStringList & defines) {
if (!prog) if (!prog) prog = new QOpenGLShaderProgram();
prog = new QOpenGLShaderProgram();
QFile f(file); QFile f(file);
if (!f.open(QIODevice::ReadOnly)) { if (!f.open(QIODevice::ReadOnly)) {
qDebug() << "[QGLEngine] Shader" << file << "Error: can`t open file!"; qDebug() << "[QGLEngine] Shader" << file << "Error: can`t open file!";
@@ -117,8 +118,7 @@ bool QGLEngineShaders::loadShadersMulti(QOpenGLShaderProgram *& prog, const QStr
bool QGLEngineShaders::loadShaders(QOpenGLShaderProgram *& prog, const QStringList & files, bool add_qgl, const QStringList & defines) { bool QGLEngineShaders::loadShaders(QOpenGLShaderProgram *& prog, const QStringList & files, bool add_qgl, const QStringList & defines) {
if (!prog) if (!prog) prog = new QOpenGLShaderProgram();
prog = new QOpenGLShaderProgram();
prog->removeAllShaders(); prog->removeAllShaders();
QString cur_shader, defs = prepareDefines(defines); QString cur_shader, defs = prepareDefines(defines);
foreach(QString f, files) { foreach(QString f, files) {

View File

@@ -26,6 +26,6 @@ namespace QGLEngineShaders {
bool loadShadersMulti(QOpenGLShaderProgram *& prog, const QString & file, bool add_qgl = true, const QStringList & defines = QStringList()); bool loadShadersMulti(QOpenGLShaderProgram *& prog, const QString & file, bool add_qgl = true, const QStringList & defines = QStringList());
bool loadShaders(QOpenGLShaderProgram *& prog, const QStringList & files, bool add_qgl = true, const QStringList & defines = QStringList()); bool loadShaders(QOpenGLShaderProgram *& prog, const QStringList & files, bool add_qgl = true, const QStringList & defines = QStringList());
} } // namespace QGLEngineShaders
#endif // GLSHADERS_H #endif // GLSHADERS_H

View File

@@ -24,12 +24,10 @@ namespace QGLEngineShaders {
const int max_materials = 128; const int max_materials = 128;
const int max_lights = 256; const int max_lights = 256;
const char qgl_common_head[] = const char qgl_common_head[] = "#version 400 core\n"
"#version 400 core\n"
""; "";
const char qgl_vertex_head[] = const char qgl_vertex_head[] = "layout(location = 1 ) in vec3 qgl_Vertex ;\n"
"layout(location = 1 ) in vec3 qgl_Vertex ;\n"
"layout(location = 2 ) in vec3 qgl_Normal ;\n" "layout(location = 2 ) in vec3 qgl_Normal ;\n"
"layout(location = 3 ) in vec3 qgl_Tangent ;\n" "layout(location = 3 ) in vec3 qgl_Tangent ;\n"
"layout(location = 4 ) in vec3 qgl_Bitangent ;\n" "layout(location = 4 ) in vec3 qgl_Bitangent ;\n"
@@ -63,11 +61,9 @@ const char qgl_fragment_head[] =
"#define qgl_FragColor qgl_FragData[0]\n" "#define qgl_FragColor qgl_FragData[0]\n"
""; "";
const char qgl_geometry_head[] = const char qgl_geometry_head[] = "";
"";
const char qgl_structs[] = const char qgl_structs[] = "#define QGL_MAPS_COUNT 6\n"
"#define QGL_MAPS_COUNT 6\n"
"#define QGL_MAP_DIFFUSE 0\n" "#define QGL_MAP_DIFFUSE 0\n"
"#define QGL_MAP_NORMAL 1\n" "#define QGL_MAP_NORMAL 1\n"
"#define QGL_MAP_METALNESS 2\n" "#define QGL_MAP_METALNESS 2\n"
@@ -103,8 +99,7 @@ const char qgl_structs[] =
"};\n" "};\n"
""; "";
const char qgl_uniform[] = const char qgl_uniform[] = "layout (std140) uniform QGLMaterialData {\n"
"layout (std140) uniform QGLMaterialData {\n"
" QGLMaterial qgl_material[128];\n" " QGLMaterial qgl_material[128];\n"
"};\n" "};\n"
"layout (std140) uniform QGLLightParameterData {\n" "layout (std140) uniform QGLLightParameterData {\n"
@@ -116,6 +111,6 @@ const char qgl_uniform[] =
"uniform sampler2DArray qgl_texture_array[2];\n" "uniform sampler2DArray qgl_texture_array[2];\n"
""; "";
} } // namespace QGLEngineShaders
#endif // GLSHADERS_HEADERS_H #endif // GLSHADERS_HEADERS_H

View File

@@ -73,7 +73,12 @@ void QGLEngineShaders::prepareDrawObj(QOpenGLExtraFunctions * f) {
f->glVertexAttribIPointer(object_id_loc, 1, GL_UNSIGNED_INT, size, (const void *)object_id_offset); f->glVertexAttribIPointer(object_id_loc, 1, GL_UNSIGNED_INT, size, (const void *)object_id_offset);
f->glVertexAttribPointer(color_loc, 4, GL_FLOAT, GL_FALSE, size, (const void *)color_offset); f->glVertexAttribPointer(color_loc, 4, GL_FLOAT, GL_FALSE, size, (const void *)color_offset);
for (int i = 0; i < 4; ++i) { for (int i = 0; i < 4; ++i) {
f->glVertexAttribPointer(modelmatrix_loc + i, 4, GL_FLOAT, GL_FALSE, size, (const void *)(modelmatrix_offset + sizeof(QVector4D)*i)); f->glVertexAttribPointer(modelmatrix_loc + i,
4,
GL_FLOAT,
GL_FALSE,
size,
(const void *)(modelmatrix_offset + sizeof(QVector4D) * i));
} }
f->glVertexAttribDivisor(material_loc, 1); f->glVertexAttribDivisor(material_loc, 1);
@@ -82,7 +87,6 @@ void QGLEngineShaders::prepareDrawObj(QOpenGLExtraFunctions * f) {
for (int i = 0; i < 4; ++i) { for (int i = 0; i < 4; ++i) {
f->glVertexAttribDivisor(modelmatrix_loc + i, 1); f->glVertexAttribDivisor(modelmatrix_loc + i, 1);
} }
} }
@@ -93,5 +97,4 @@ void QGLEngineShaders::prepareDrawSel(QOpenGLExtraFunctions * f) {
GLsizei size = 1; GLsizei size = 1;
f->glVertexAttribIPointer(is_selected_loc, 1, GL_UNSIGNED_BYTE, size, (const void *)is_selected_offset); f->glVertexAttribIPointer(is_selected_loc, 1, GL_UNSIGNED_BYTE, size, (const void *)is_selected_offset);
f->glVertexAttribDivisor(is_selected_loc, 1); f->glVertexAttribDivisor(is_selected_loc, 1);
} }

View File

@@ -137,6 +137,6 @@ void prepareDrawObj (QOpenGLExtraFunctions * f);
void prepareDrawSel(QOpenGLExtraFunctions * f); void prepareDrawSel(QOpenGLExtraFunctions * f);
} } // namespace QGLEngineShaders
#endif // GLSHADERS_TYPES_H #endif // GLSHADERS_TYPES_H

View File

@@ -17,9 +17,10 @@
*/ */
#define GL_GLEXT_PROTOTYPES #define GL_GLEXT_PROTOTYPES
#include <QOpenGLExtraFunctions>
#include "gltexturearray.h" #include "gltexturearray.h"
#include <QOpenGLExtraFunctions>
Texture2DArray::Texture2DArray(bool filter) { Texture2DArray::Texture2DArray(bool filter) {
target_ = GL_TEXTURE_2D_ARRAY; target_ = GL_TEXTURE_2D_ARRAY;
@@ -29,8 +30,7 @@ Texture2DArray::Texture2DArray(bool filter) {
} }
Texture2DArray::~Texture2DArray() { Texture2DArray::~Texture2DArray() {}
}
void Texture2DArray::init(QOpenGLExtraFunctions * f) { void Texture2DArray::init(QOpenGLExtraFunctions * f) {
@@ -88,9 +88,8 @@ bool Texture2DArray::resize(QOpenGLExtraFunctions * f, QSize new_size, int layer
void Texture2DArray::load(QOpenGLExtraFunctions * f, const QImage & image, int layer) { void Texture2DArray::load(QOpenGLExtraFunctions * f, const QImage & image, int layer) {
if (image.isNull() || size_.isNull() || layer < 0 || layer >= layers_) return; if (image.isNull() || size_.isNull() || layer < 0 || layer >= layers_) return;
QImage im = image.mirrored(false, true) QImage im =
.scaled(size_, Qt::IgnoreAspectRatio, Qt::SmoothTransformation) image.mirrored(false, true).scaled(size_, Qt::IgnoreAspectRatio, Qt::SmoothTransformation).convertToFormat(QImage::Format_RGBA8888);
.convertToFormat(QImage::Format_RGBA8888);
// qDebug() << "Texture2DArray::load image" << image.size() << "to layer" << layer; // qDebug() << "Texture2DArray::load image" << image.size() << "to layer" << layer;
f->glTexSubImage3D(target_, 0, 0, 0, layer, size_.width(), size_.height(), 1, GL_RGBA, GL_UNSIGNED_BYTE, im.constBits()); f->glTexSubImage3D(target_, 0, 0, 0, layer, size_.width(), size_.height(), 1, GL_RGBA, GL_UNSIGNED_BYTE, im.constBits());
} }

View File

@@ -22,8 +22,7 @@
#include "gltypes.h" #include "gltypes.h"
class Texture2DArray class Texture2DArray {
{
public: public:
Texture2DArray(bool filter); Texture2DArray(bool filter);
~Texture2DArray(); ~Texture2DArray();

View File

@@ -18,7 +18,9 @@
#include "gltransform.h" #include "gltransform.h"
#include "gltypes.h" #include "gltypes.h"
#include <cmath> #include <cmath>
@@ -26,11 +28,23 @@ inline void composeQMatrix4x4(const QVector3D & position, const QVector3D & orie
const QMatrix3x3 rot3x3(Transform::toRotationMatrix(orientation)); const QMatrix3x3 rot3x3(Transform::toRotationMatrix(orientation));
// set up final matrix with scale, rotation and translation // set up final matrix with scale, rotation and translation
m(0, 0) = scale.x() * rot3x3(0, 0); m(0, 1) = scale.y() * rot3x3(0, 1); m(0, 2) = scale.z() * rot3x3(0, 2); m(0, 3) = position.x(); m(0, 0) = scale.x() * rot3x3(0, 0);
m(1, 0) = scale.x() * rot3x3(1, 0); m(1, 1) = scale.y() * rot3x3(1, 1); m(1, 2) = scale.z() * rot3x3(1, 2); m(1, 3) = position.y(); m(0, 1) = scale.y() * rot3x3(0, 1);
m(2, 0) = scale.x() * rot3x3(2, 0); m(2, 1) = scale.y() * rot3x3(2, 1); m(2, 2) = scale.z() * rot3x3(2, 2); m(2, 3) = position.z(); m(0, 2) = scale.z() * rot3x3(0, 2);
m(0, 3) = position.x();
m(1, 0) = scale.x() * rot3x3(1, 0);
m(1, 1) = scale.y() * rot3x3(1, 1);
m(1, 2) = scale.z() * rot3x3(1, 2);
m(1, 3) = position.y();
m(2, 0) = scale.x() * rot3x3(2, 0);
m(2, 1) = scale.y() * rot3x3(2, 1);
m(2, 2) = scale.z() * rot3x3(2, 2);
m(2, 3) = position.z();
// no projection term // no projection term
m(3, 0) = 0.0f; m(3, 1) = 0.0f; m(3, 2) = 0.0f; m(3, 3) = 1.0f; m(3, 0) = 0.0f;
m(3, 1) = 0.0f;
m(3, 2) = 0.0f;
m(3, 3) = 1.0f;
} }
inline void decomposeQMatrix3x3(const QMatrix3x3 & m, QMatrix3x3 & Q, QVector3D & D, QVector3D & U) { inline void decomposeQMatrix3x3(const QMatrix3x3 & m, QMatrix3x3 & Q, QVector3D & D, QVector3D & U) {
@@ -89,11 +103,9 @@ inline void decomposeQMatrix3x3(const QMatrix3x3 & m, QMatrix3x3 & Q, QVector3D
Q(2, 2) *= invLen; Q(2, 2) *= invLen;
// guarantee that orthogonal matrix has determinant 1 (no reflections) // guarantee that orthogonal matrix has determinant 1 (no reflections)
const float det = Q(0, 0) * Q(1, 1) * Q(2, 2) + Q(0, 1) * Q(1, 2) * Q(2, 0) + const float det = Q(0, 0) * Q(1, 1) * Q(2, 2) + Q(0, 1) * Q(1, 2) * Q(2, 0) + Q(0, 2) * Q(1, 0) * Q(2, 1) -
Q(0, 2) * Q(1, 0) * Q(2, 1) - Q(0, 2) * Q(1, 1) * Q(2, 0) - Q(0, 2) * Q(1, 1) * Q(2, 0) - Q(0, 1) * Q(1, 0) * Q(2, 2) - Q(0, 0) * Q(1, 2) * Q(2, 1);
Q(0, 1) * Q(1, 0) * Q(2, 2) - Q(0, 0) * Q(1, 2) * Q(2, 1); if (det < 0.0f) Q *= -1.0f;
if (det < 0.0f)
Q *= -1.0f;
// build "right" matrix R // build "right" matrix R
QMatrix3x3 R(Qt::Uninitialized); QMatrix3x3 R(Qt::Uninitialized);
@@ -118,17 +130,13 @@ inline void decomposeQMatrix3x3(const QMatrix3x3 & m, QMatrix3x3 & Q, QVector3D
inline bool hasScale(const QMatrix4x4 & m) { inline bool hasScale(const QMatrix4x4 & m) {
// If the columns are orthonormal and form a right-handed system, then there is no scale // If the columns are orthonormal and form a right-handed system, then there is no scale
float t(m.determinant()); float t(m.determinant());
if (!qFuzzyIsNull(t - 1.0f)) if (!qFuzzyIsNull(t - 1.0f)) return true;
return true;
t = m(0, 0) * m(0, 0) + m(1, 0) * m(1, 0) + m(2, 0) * m(2, 0); t = m(0, 0) * m(0, 0) + m(1, 0) * m(1, 0) + m(2, 0) * m(2, 0);
if (!qFuzzyIsNull(t - 1.0f)) if (!qFuzzyIsNull(t - 1.0f)) return true;
return true;
t = m(0, 1) * m(0, 1) + m(1, 1) * m(1, 1) + m(2, 1) * m(2, 1); t = m(0, 1) * m(0, 1) + m(1, 1) * m(1, 1) + m(2, 1) * m(2, 1);
if (!qFuzzyIsNull(t - 1.0f)) if (!qFuzzyIsNull(t - 1.0f)) return true;
return true;
t = m(0, 2) * m(0, 2) + m(1, 2) * m(1, 2) + m(2, 2) * m(2, 2); t = m(0, 2) * m(0, 2) + m(1, 2) * m(1, 2) + m(2, 2) * m(2, 2);
if (!qFuzzyIsNull(t - 1.0f)) if (!qFuzzyIsNull(t - 1.0f)) return true;
return true;
return false; return false;
} }
@@ -150,11 +158,7 @@ inline void decomposeQMatrix4x4(const QMatrix4x4 & m, QVector3D & position, QVec
} }
Transform::Transform(): m_scale(1.0f, 1.0f, 1.0f), m_translation(), m_eulerRotationAngles(), m_matrixDirty(false) {}
Transform::Transform(): m_scale(1.0f, 1.0f, 1.0f),
m_translation(), m_eulerRotationAngles(), m_matrixDirty(false) {
}
Transform & Transform::operator=(const Transform & t) { Transform & Transform::operator=(const Transform & t) {
@@ -182,24 +186,21 @@ void Transform::setMatrix(const QMatrix4x4 & m) {
void Transform::setRotationX(float r) { void Transform::setRotationX(float r) {
if (m_eulerRotationAngles.x() == r) if (m_eulerRotationAngles.x() == r) return;
return;
m_eulerRotationAngles.setX(r); m_eulerRotationAngles.setX(r);
m_matrixDirty = true; m_matrixDirty = true;
} }
void Transform::setRotationY(float r) { void Transform::setRotationY(float r) {
if (m_eulerRotationAngles.y() == r) if (m_eulerRotationAngles.y() == r) return;
return;
m_eulerRotationAngles.setY(r); m_eulerRotationAngles.setY(r);
m_matrixDirty = true; m_matrixDirty = true;
} }
void Transform::setRotationZ(float r) { void Transform::setRotationZ(float r) {
if (m_eulerRotationAngles.z() == r) if (m_eulerRotationAngles.z() == r) return;
return;
m_eulerRotationAngles.setZ(r); m_eulerRotationAngles.setZ(r);
m_matrixDirty = true; m_matrixDirty = true;
} }
@@ -362,17 +363,19 @@ QQuaternion Transform::fromAxisAndAngle(float x, float y, float z, float angle)
} }
QQuaternion Transform::fromAxesAndAngles(const QVector3D & axis1, float angle1, QQuaternion Transform::fromAxesAndAngles(const QVector3D & axis1, float angle1, const QVector3D & axis2, float angle2) {
const QVector3D & axis2, float angle2) {
const QQuaternion q1 = QQuaternion::fromAxisAndAngle(axis1, angle1); const QQuaternion q1 = QQuaternion::fromAxisAndAngle(axis1, angle1);
const QQuaternion q2 = QQuaternion::fromAxisAndAngle(axis2, angle2); const QQuaternion q2 = QQuaternion::fromAxisAndAngle(axis2, angle2);
return q2 * q1; return q2 * q1;
} }
QQuaternion Transform::fromAxesAndAngles(const QVector3D & axis1, float angle1, QQuaternion Transform::fromAxesAndAngles(const QVector3D & axis1,
const QVector3D & axis2, float angle2, float angle1,
const QVector3D & axis3, float angle3) { const QVector3D & axis2,
float angle2,
const QVector3D & axis3,
float angle3) {
const QQuaternion q1 = QQuaternion::fromAxisAndAngle(axis1, angle1); const QQuaternion q1 = QQuaternion::fromAxisAndAngle(axis1, angle1);
const QQuaternion q2 = QQuaternion::fromAxisAndAngle(axis2, angle2); const QQuaternion q2 = QQuaternion::fromAxisAndAngle(axis2, angle2);
const QQuaternion q3 = QQuaternion::fromAxisAndAngle(axis3, angle3); const QQuaternion q3 = QQuaternion::fromAxisAndAngle(axis3, angle3);
@@ -433,8 +436,20 @@ QMatrix4x4 Transform::rotateAround(const QVector3D & point, float angle, const Q
QMatrix4x4 Transform::rotateFromAxes(const QVector3D & xAxis, const QVector3D & yAxis, const QVector3D & zAxis) { QMatrix4x4 Transform::rotateFromAxes(const QVector3D & xAxis, const QVector3D & yAxis, const QVector3D & zAxis) {
return QMatrix4x4(xAxis.x(), yAxis.x(), zAxis.x(), 0.0f, return QMatrix4x4(xAxis.x(),
xAxis.y(), yAxis.y(), zAxis.y(), 0.0f, yAxis.x(),
xAxis.z(), yAxis.z(), zAxis.z(), 0.0f, zAxis.x(),
0.0f, 0.0f, 0.0f, 1.0f); 0.0f,
xAxis.y(),
yAxis.y(),
zAxis.y(),
0.0f,
xAxis.z(),
yAxis.z(),
zAxis.z(),
0.0f,
0.0f,
0.0f,
0.0f,
1.0f);
} }

View File

@@ -27,6 +27,7 @@
class Transform { class Transform {
friend QDataStream & operator>>(QDataStream & s, Transform & v); friend QDataStream & operator>>(QDataStream & s, Transform & v);
public: public:
Transform(); Transform();
Transform & operator=(const Transform & t); Transform & operator=(const Transform & t);
@@ -68,11 +69,9 @@ public:
static QQuaternion fromAxisAndAngle(const QVector3D & axis, float angle); static QQuaternion fromAxisAndAngle(const QVector3D & axis, float angle);
static QQuaternion fromAxisAndAngle(float x, float y, float z, float angle); static QQuaternion fromAxisAndAngle(float x, float y, float z, float angle);
static QQuaternion fromAxesAndAngles(const QVector3D & axis1, float angle1, static QQuaternion fromAxesAndAngles(const QVector3D & axis1, float angle1, const QVector3D & axis2, float angle2);
const QVector3D & axis2, float angle2); static QQuaternion
static QQuaternion fromAxesAndAngles(const QVector3D & axis1, float angle1, fromAxesAndAngles(const QVector3D & axis1, float angle1, const QVector3D & axis2, float angle2, const QVector3D & axis3, float angle3);
const QVector3D & axis2, float angle2,
const QVector3D & axis3, float angle3);
static QQuaternion fromAxes(const QVector3D & xAxis, const QVector3D & yAxis, const QVector3D & zAxis); static QQuaternion fromAxes(const QVector3D & xAxis, const QVector3D & yAxis, const QVector3D & zAxis);
static QVector3D fromDirection(QVector3D d, float pitch = 0.f); static QVector3D fromDirection(QVector3D d, float pitch = 0.f);
@@ -91,12 +90,12 @@ protected:
mutable QMatrix4x4 m_matrix, m_matrixWT, m_matrixR, m_matrixS; mutable QMatrix4x4 m_matrix, m_matrixWT, m_matrixR, m_matrixS;
mutable bool m_matrixDirty; mutable bool m_matrixDirty;
}; };
inline QDataStream & operator<<(QDataStream & s, const Transform & v) { inline QDataStream & operator<<(QDataStream & s, const Transform & v) {
s << v.matrix(); return s; s << v.matrix();
return s;
} }
inline QDataStream & operator>>(QDataStream & s, Transform & v) { inline QDataStream & operator>>(QDataStream & s, Transform & v) {
QMatrix4x4 m; QMatrix4x4 m;

View File

@@ -17,8 +17,8 @@
*/ */
#include "glcamera.h" #include "glcamera.h"
#include "qglview.h"
#include "gltexture_manager.h" #include "gltexture_manager.h"
#include "qglview.h"
#include <QPainter> #include <QPainter>
@@ -44,8 +44,7 @@ QString findFile(const QString & file, const QStringList & pathes) {
foreach(QString p, pathes) { foreach(QString p, pathes) {
QFileInfoList fil = QDir(p).entryInfoList(QStringList(fn), QDir::Files | QDir::NoDotAndDotDot); QFileInfoList fil = QDir(p).entryInfoList(QStringList(fn), QDir::Files | QDir::NoDotAndDotDot);
// qDebug() << "findFile" << fn << "in" << p << "->" << fil.size(); // qDebug() << "findFile" << fn << "in" << p << "->" << fil.size();
if (!fil.isEmpty()) if (!fil.isEmpty()) return fil[0].absoluteFilePath();
return fil[0].absoluteFilePath();
} }
return QString(); return QString();
} }
@@ -55,10 +54,8 @@ void glDrawQuad(QOpenGLShaderProgram * prog, QVector4D * corner_dirs, GLfloat x,
glSetPolygonMode(GL_FILL); glSetPolygonMode(GL_FILL);
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
int loc = prog ? prog->attributeLocation("qgl_Color") : -1, int loc = prog ? prog->attributeLocation("qgl_Color") : -1, locv = prog ? prog->attributeLocation("qgl_Vertex") : -1,
locv = prog ? prog->attributeLocation("qgl_Vertex") : -1, loct = prog ? prog->attributeLocation("qgl_Texture") : -1, locc = prog ? prog->attributeLocation("view_corner") : -1;
loct = prog ? prog->attributeLocation("qgl_Texture") : -1,
locc = prog ? prog->attributeLocation("view_corner") : -1;
QOpenGLFunctions * glFuncs = QOpenGLContext::currentContext()->functions(); QOpenGLFunctions * glFuncs = QOpenGLContext::currentContext()->functions();
if (prog) { if (prog) {
static const GLfloat cols[] = {1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f}; static const GLfloat cols[] = {1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f};
@@ -66,10 +63,18 @@ void glDrawQuad(QOpenGLShaderProgram * prog, QVector4D * corner_dirs, GLfloat x,
static const GLfloat texs[] = {0.f, 0.f, 1.f, 0.f, 0.f, 1.f, 1.f, 1.f}; static const GLfloat texs[] = {0.f, 0.f, 1.f, 0.f, 0.f, 1.f, 1.f, 1.f};
GLfloat vcs[] = {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f}; GLfloat vcs[] = {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f};
if (corner_dirs) { if (corner_dirs) {
vcs[0] = corner_dirs[0].x(); vcs[1] = corner_dirs[0].y(); vcs[2] = corner_dirs[0].z(); vcs[0] = corner_dirs[0].x();
vcs[3] = corner_dirs[1].x(); vcs[4] = corner_dirs[1].y(); vcs[5] = corner_dirs[1].z(); vcs[1] = corner_dirs[0].y();
vcs[6] = corner_dirs[2].x(); vcs[7] = corner_dirs[2].y(); vcs[8] = corner_dirs[2].z(); vcs[2] = corner_dirs[0].z();
vcs[9] = corner_dirs[3].x(); vcs[10] = corner_dirs[3].y(); vcs[11] = corner_dirs[3].z(); vcs[3] = corner_dirs[1].x();
vcs[4] = corner_dirs[1].y();
vcs[5] = corner_dirs[1].z();
vcs[6] = corner_dirs[2].x();
vcs[7] = corner_dirs[2].y();
vcs[8] = corner_dirs[2].z();
vcs[9] = corner_dirs[3].x();
vcs[10] = corner_dirs[3].y();
vcs[11] = corner_dirs[3].z();
} }
glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_NORMAL_ARRAY);
@@ -92,10 +97,14 @@ void glDrawQuad(QOpenGLShaderProgram * prog, QVector4D * corner_dirs, GLfloat x,
} else { } else {
glBegin(GL_TRIANGLE_STRIP); glBegin(GL_TRIANGLE_STRIP);
glColor4f(1.f, 1.f, 1.f, 1.f); glColor4f(1.f, 1.f, 1.f, 1.f);
glTexCoord2f(0.f, 0.f); glVertex2f(x, y); glTexCoord2f(0.f, 0.f);
glTexCoord2f(1.f, 0.f); glVertex2f(x+w, y); glVertex2f(x, y);
glTexCoord2f(0.f, 1.f); glVertex2f(x, y+h); glTexCoord2f(1.f, 0.f);
glTexCoord2f(1.f, 1.f); glVertex2f(x+w, y+h); glVertex2f(x + w, y);
glTexCoord2f(0.f, 1.f);
glVertex2f(x, y + h);
glTexCoord2f(1.f, 1.f);
glVertex2f(x + w, y + h);
glEnd(); glEnd();
} }
} }
@@ -141,10 +150,8 @@ void createGLTexture(QOpenGLExtraFunctions * f, GLuint & tex, int width, int hei
else { else {
int type = GL_UNSIGNED_BYTE; int type = GL_UNSIGNED_BYTE;
int fmt = GL_RGBA; int fmt = GL_RGBA;
if (format == GL_RGB32F || format == GL_RGB16F || format == GL_RGBA32F || format == GL_RGBA16F) if (format == GL_RGB32F || format == GL_RGB16F || format == GL_RGBA32F || format == GL_RGBA16F) type = GL_FLOAT;
type = GL_FLOAT; if (format == GL_RGB32F || format == GL_RGB16F || format == GL_RGB8 || format == GL_RGB) fmt = GL_RGB;
if (format == GL_RGB32F || format == GL_RGB16F || format == GL_RGB8 || format == GL_RGB)
fmt = GL_RGB;
f->glTexImage2D(target, 0, format, width, height, 0, fmt, type, nullptr); f->glTexImage2D(target, 0, format, width, height, 0, fmt, type, nullptr);
// qDebug() << "glTexImage2D" << width << height << QString::number(t, 16); // qDebug() << "glTexImage2D" << width << height << QString::number(t, 16);
} }
@@ -216,14 +223,15 @@ QImage rotateQImageRight(const QImage & im) {
} }
QColor colorFromString(const QString & str) { QColor colorFromString(const QString & str) {
QString s = str.trimmed(); QString s = str.trimmed();
int i = s.indexOf("\t"); int i = s.indexOf("\t");
float r, g, b; float r, g, b;
r = s.left(i).toFloat(); s = s.right(s.length() - i - 1); i = s.indexOf("\t"); r = s.left(i).toFloat();
g = s.left(i).toFloat(); s = s.right(s.length() - i - 1); s = s.right(s.length() - i - 1);
i = s.indexOf("\t");
g = s.left(i).toFloat();
s = s.right(s.length() - i - 1);
b = s.toFloat(); b = s.toFloat();
return QColor(r * 255.f, g * 255.f, b * 255.f); return QColor(r * 255.f, g * 255.f, b * 255.f);
} }
@@ -232,9 +240,12 @@ QColor colorFromString(const QString & str) {
QVector3D orthToVector(const QVector3D & v, const float & scale) { QVector3D orthToVector(const QVector3D & v, const float & scale) {
if (v.isNull()) return QVector3D(); if (v.isNull()) return QVector3D();
QVector3D rv, fn, sn; QVector3D rv, fn, sn;
if (v.x() != 0.f) rv.setZ(1.); if (v.x() != 0.f)
else if (v.y() != 0.f) rv.setX(1.); rv.setZ(1.);
else rv.setY(1.); else if (v.y() != 0.f)
rv.setX(1.);
else
rv.setY(1.);
fn = QVector3D::crossProduct(v, rv).normalized(); fn = QVector3D::crossProduct(v, rv).normalized();
sn = QVector3D::crossProduct(v, fn).normalized(); sn = QVector3D::crossProduct(v, fn).normalized();
return fn * urand(scale) + sn * urand(scale); return fn * urand(scale) + sn * urand(scale);
@@ -269,7 +280,8 @@ void lengthenVector(QVector3D & v, const float & l) {
Vector2i::Vector2i(const QString & str) { Vector2i::Vector2i(const QString & str) {
QString s = str.trimmed(); QString s = str.trimmed();
int i = s.indexOf("\t"); int i = s.indexOf("\t");
p0 = s.left(i).toInt(); s = s.right(s.length() - i - 1); p0 = s.left(i).toInt();
s = s.right(s.length() - i - 1);
p1 = s.toInt(); p1 = s.toInt();
} }
@@ -277,8 +289,11 @@ Vector2i::Vector2i(const QString & str) {
Vector3i::Vector3i(const QString & str) { Vector3i::Vector3i(const QString & str) {
QString s = str.trimmed(); QString s = str.trimmed();
int i = s.indexOf("\t"); int i = s.indexOf("\t");
p0 = s.left(i).toInt(); s = s.right(s.length() - i - 1); i = s.indexOf("\t"); p0 = s.left(i).toInt();
p1 = s.left(i).toInt(); s = s.right(s.length() - i - 1); s = s.right(s.length() - i - 1);
i = s.indexOf("\t");
p1 = s.left(i).toInt();
s = s.right(s.length() - i - 1);
p2 = s.toInt(); p2 = s.toInt();
} }
@@ -305,8 +320,6 @@ void glClearFramebuffer(const QColor & color, bool depth) {
} }
Box3D::Box3D(const QVector<QVector3D> & points) { Box3D::Box3D(const QVector<QVector3D> & points) {
x = y = z = width = length = height = angle_z = angle_xy = angle_roll = 0.f; x = y = z = width = length = height = angle_z = angle_xy = angle_roll = 0.f;
if (points.isEmpty()) return; if (points.isEmpty()) return;
@@ -315,9 +328,12 @@ Box3D::Box3D(const QVector<QVector3D> & points) {
iy = ay = points[0].y(); iy = ay = points[0].y();
iz = az = points[0].z(); iz = az = points[0].z();
for (int i = 1; i < points.size(); ++i) { for (int i = 1; i < points.size(); ++i) {
ix = qMin<float>(ix, points[i].x()); ax = qMax<float>(ax, points[i].x()); ix = qMin<float>(ix, points[i].x());
iy = qMin<float>(iy, points[i].y()); ay = qMax<float>(ay, points[i].y()); ax = qMax<float>(ax, points[i].x());
iz = qMin<float>(iz, points[i].z()); az = qMax<float>(az, points[i].z()); iy = qMin<float>(iy, points[i].y());
ay = qMax<float>(ay, points[i].y());
iz = qMin<float>(iz, points[i].z());
az = qMax<float>(az, points[i].z());
} }
x = ix; x = ix;
y = iy; y = iy;
@@ -331,21 +347,28 @@ Box3D::Box3D(const QVector<QVector3D> & points) {
QVector<QVector3D> Box3D::corners() const { QVector<QVector3D> Box3D::corners() const {
QVector<QVector3D> ret; QVector<QVector3D> ret;
ret << QVector3D(x, y, z) << QVector3D(x, y + width, z) << QVector3D(x, y, z + height) << QVector3D(x, y + width, z + height) ret << QVector3D(x, y, z) << QVector3D(x, y + width, z) << QVector3D(x, y, z + height) << QVector3D(x, y + width, z + height)
<< QVector3D(x + length, y, z) << QVector3D(x + length, y + width, z) << QVector3D(x + length, y, z) << QVector3D(x + length, y + width, z) << QVector3D(x + length, y, z + height)
<< QVector3D(x + length, y, z + height) << QVector3D(x + length, y + width, z + height); << QVector3D(x + length, y + width, z + height);
return ret; return ret;
} }
Box3D & Box3D::operator|=(const Box3D & o) { Box3D & Box3D::operator|=(const Box3D & o) {
if (o.isEmpty()) return *this; if (o.isEmpty()) return *this;
if (isEmpty()) *this = o; if (isEmpty())
*this = o;
else { else {
GLfloat mx = x + length, my = y + width, mz = z + height; GLfloat mx = x + length, my = y + width, mz = z + height;
GLfloat omx = o.x + o.length, omy = o.y + o.width, omz = o.z + o.height; GLfloat omx = o.x + o.length, omy = o.y + o.width, omz = o.z + o.height;
x = qMin(x, o.x); y = qMin(y, o.y); z = qMin(z, o.z); x = qMin(x, o.x);
mx = qMax(mx, omx); my = qMax(my, omy); mz = qMax(mz, omz); y = qMin(y, o.y);
length = mx - x; width = my - y; height = mz - z; z = qMin(z, o.z);
mx = qMax(mx, omx);
my = qMax(my, omy);
mz = qMax(mz, omz);
length = mx - x;
width = my - y;
height = mz - z;
} }
return *this; return *this;
} }
@@ -355,8 +378,11 @@ QVector3D vectorFromString(const QString & str) {
QTextStream s(const_cast<QString *>(&str), QIODevice::ReadOnly); QTextStream s(const_cast<QString *>(&str), QIODevice::ReadOnly);
QVector3D ret; QVector3D ret;
float f(0.f); float f(0.f);
s >> f; ret.setX(f); s >> f;
s >> f; ret.setY(f); ret.setX(f);
s >> f; ret.setZ(f); s >> f;
ret.setY(f);
s >> f;
ret.setZ(f);
return ret; return ret;
} }

View File

@@ -54,32 +54,33 @@
// # include <GL/glu.h> // # include <GL/glu.h>
// # endif // # endif
// #endif // #endif
#include <QColor>
#include <QDataStream>
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QImage>
#include <QMatrix4x4>
#include <QMutex>
#include <QOpenGLExtraFunctions> #include <QOpenGLExtraFunctions>
#include <QOpenGLShader> #include <QOpenGLShader>
#include <QOpenGLShaderProgram> #include <QOpenGLShaderProgram>
#include <qopenglext.h>
#include <cmath>
#include <float.h>
#include <QMatrix4x4>
#include <QDebug>
#include <QDataStream>
#include <QColor>
#include <QVector2D> #include <QVector2D>
#include <QVector3D> #include <QVector3D>
#include <QImage> #include <cmath>
#include <QMutex> #include <float.h>
#include <QFile> #include <qopenglext.h>
#include <QDir>
#ifndef QNX #ifndef QNX
# include <cmath> # include <cmath>
# include <complex> # include <complex>
#else #else
# include <math.h>
# include <complex.h> # include <complex.h>
# include <math.h>
#endif #endif
#include <iostream>
#include "qglengine_version.h"
#include "qglengine_core_export.h" #include "qglengine_core_export.h"
#include "qglengine_version.h"
#include <iostream>
// #ifdef WINDOWS // #ifdef WINDOWS
@@ -116,53 +117,131 @@ const float deg2rad = atanf(1.f) / 45.f;
const float rad2deg = 45.f / atanf(1.f); const float rad2deg = 45.f / atanf(1.f);
# ifdef WINDOWS # ifdef WINDOWS
inline int random() {return rand();} inline int random() {
return rand();
}
# endif # endif
#else #else
# define random randomi # define random randomi
#endif #endif
#ifdef CC_VC #ifdef CC_VC
inline float round(const float & v) {return floor(v + 0.5);} inline float round(const float & v) {
return floor(v + 0.5);
}
#endif #endif
inline float randomu() {return float(random()) / RAND_MAX;} inline float randomu() {
return float(random()) / RAND_MAX;
}
inline const QSizeF operator *(const QSizeF & f, const QSizeF & s) {return QSizeF(f.width() * s.width(), f.height() * s.height());} inline const QSizeF operator*(const QSizeF & f, const QSizeF & s) {
return QSizeF(f.width() * s.width(), f.height() * s.height());
}
#ifndef PIP_VERSION #ifndef PIP_VERSION
template<typename T> inline void piSwap(T & f, T & s) {T t(f); f = s; s = t;} template<typename T>
template<typename Type> inline Type piMin(const Type & f, const Type & s) {return (f > s) ? s : f;} inline void piSwap(T & f, T & s) {
template<typename Type> inline Type piMin(const Type & f, const Type & s, const Type & t) {return (f < s && f < t) ? f : ((s < t) ? s : t);} T t(f);
template<typename Type> inline Type piMax(const Type & f, const Type & s) {return (f < s) ? s : f;} f = s;
template<typename Type> inline Type piMax(const Type & f, const Type & s, const Type & t) {return (f > s && f > t) ? f : ((s > t) ? s : t);} s = t;
template<typename Type> inline Type piClamp(const Type & v, const Type & min, const Type & max) {return (v > max ? max : (v < min ? min : v));} }
inline ushort letobe_s(ushort v) {return (v << 8) | (v >> 8);} template<typename Type>
inline uint letobe_i(const uint & v) {return (v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | ((v << 24) & 0xFF000000);} inline Type piMin(const Type & f, const Type & s) {
return (f > s) ? s : f;
}
template<typename Type>
inline Type piMin(const Type & f, const Type & s, const Type & t) {
return (f < s && f < t) ? f : ((s < t) ? s : t);
}
template<typename Type>
inline Type piMax(const Type & f, const Type & s) {
return (f < s) ? s : f;
}
template<typename Type>
inline Type piMax(const Type & f, const Type & s, const Type & t) {
return (f > s && f > t) ? f : ((s > t) ? s : t);
}
template<typename Type>
inline Type piClamp(const Type & v, const Type & min, const Type & max) {
return (v > max ? max : (v < min ? min : v));
}
inline ushort letobe_s(ushort v) {
return (v << 8) | (v >> 8);
}
inline uint letobe_i(const uint & v) {
return (v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | ((v << 24) & 0xFF000000);
}
#endif #endif
// return [-1, 1] // return [-1, 1]
inline float urand(const float & scale = 1.) {return ((float)rand() / RAND_MAX - .5f) * (scale + scale);} inline float urand(const float & scale = 1.) {
return ((float)rand() / RAND_MAX - .5f) * (scale + scale);
}
// return [0, 1] // return [0, 1]
inline float uprand(const float & scale = 1.) {return ((float)rand() / RAND_MAX) * scale;} inline float uprand(const float & scale = 1.) {
return ((float)rand() / RAND_MAX) * scale;
}
QString readCharsUntilNull(QDataStream & s); QString readCharsUntilNull(QDataStream & s);
QString findFile(const QString & file, const QStringList & pathes); QString findFile(const QString & file, const QStringList & pathes);
inline QColor operator *(const QColor & c, float v) {return QColor(piClamp<int>(c.red() * v, 0, 255), piClamp<int>(c.green() * v, 0, 255), piClamp<int>(c.blue() * v, 0, 255), piClamp<int>(c.alpha() * v, 0, 255));} inline QColor operator*(const QColor & c, float v) {
inline QColor operator /(const QColor & c, float v) {return QColor(piClamp<int>(c.red() / v, 0, 255), piClamp<int>(c.green() / v, 0, 255), piClamp<int>(c.blue() / v, 0, 255), piClamp<int>(c.alpha() / v, 0, 255));} return QColor(piClamp<int>(c.red() * v, 0, 255),
piClamp<int>(c.green() * v, 0, 255),
piClamp<int>(c.blue() * v, 0, 255),
piClamp<int>(c.alpha() * v, 0, 255));
}
inline QColor operator/(const QColor & c, float v) {
return QColor(piClamp<int>(c.red() / v, 0, 255),
piClamp<int>(c.green() / v, 0, 255),
piClamp<int>(c.blue() / v, 0, 255),
piClamp<int>(c.alpha() / v, 0, 255));
}
inline void qglColor(const QColor & c) {glColor4f(c.redF(), c.greenF(), c.blueF(), c.alphaF());} inline void qglColor(const QColor & c) {
inline void glClearError() {int c = 100; while (glGetError() != GL_NO_ERROR && --c > 0) glGetError();} glColor4f(c.redF(), c.greenF(), c.blueF(), c.alphaF());
inline void glSetCapEnabled(GLenum cap, bool on = true) {if (on) glEnable(cap); else glDisable(cap);} }
inline void glSetPolygonMode(GLenum mode) {glPolygonMode(GL_FRONT_AND_BACK, mode);} inline void glClearError() {
inline void deleteGLTexture(QOpenGLExtraFunctions * f, GLuint & tex) {if (tex != 0) f->glDeleteTextures(1, &tex); tex = 0;} int c = 100;
while (glGetError() != GL_NO_ERROR && --c > 0)
glGetError();
}
inline void glSetCapEnabled(GLenum cap, bool on = true) {
if (on)
glEnable(cap);
else
glDisable(cap);
}
inline void glSetPolygonMode(GLenum mode) {
glPolygonMode(GL_FRONT_AND_BACK, mode);
}
inline void deleteGLTexture(QOpenGLExtraFunctions * f, GLuint & tex) {
if (tex != 0) f->glDeleteTextures(1, &tex);
tex = 0;
}
void glEnableDepth(); void glEnableDepth();
void glDisableDepth(); void glDisableDepth();
void glClearFramebuffer(const QColor & color = Qt::black, bool depth = true); void glClearFramebuffer(const QColor & color = Qt::black, bool depth = true);
void glDrawQuad(QOpenGLShaderProgram * prog = nullptr, QVector4D * corner_dirs = nullptr, GLfloat x = -1.f, GLfloat y = -1.f, GLfloat w = 2.f, GLfloat h = 2.f); void glDrawQuad(QOpenGLShaderProgram * prog = nullptr,
void createGLTexture(QOpenGLExtraFunctions * f, GLuint & tex, int width, int height, const GLenum & format = GL_RGBA, const GLenum & target = GL_TEXTURE_2D); QVector4D * corner_dirs = nullptr,
void createGLTexture(QOpenGLExtraFunctions * f, GLuint & tex, const QImage & image, const GLenum & format = GL_RGBA, const GLenum & target = GL_TEXTURE_2D); GLfloat x = -1.f,
GLfloat y = -1.f,
GLfloat w = 2.f,
GLfloat h = 2.f);
void createGLTexture(QOpenGLExtraFunctions * f,
GLuint & tex,
int width,
int height,
const GLenum & format = GL_RGBA,
const GLenum & target = GL_TEXTURE_2D);
void createGLTexture(QOpenGLExtraFunctions * f,
GLuint & tex,
const QImage & image,
const GLenum & format = GL_RGBA,
const GLenum & target = GL_TEXTURE_2D);
QMatrix4x4 glMatrixPerspective(float angle, float aspect, float near_); QMatrix4x4 glMatrixPerspective(float angle, float aspect, float near_);
QImage rotateQImageLeft(const QImage & im); QImage rotateQImageLeft(const QImage & im);
QImage rotateQImageRight(const QImage & im); QImage rotateQImageRight(const QImage & im);
inline QImage rotateQImage180(const QImage & im) {return im.mirrored(true, true);} inline QImage rotateQImage180(const QImage & im) {
return im.mirrored(true, true);
}
class QGLView; class QGLView;
class MouseController; class MouseController;
@@ -205,7 +284,15 @@ struct Box3D {
GLfloat angle_xy; GLfloat angle_xy;
GLfloat angle_roll; GLfloat angle_roll;
Box3D() { x = y = z = width = length = height = angle_z = angle_xy = angle_roll = 0.f; } Box3D() { x = y = z = width = length = height = angle_z = angle_xy = angle_roll = 0.f; }
Box3D(const QVector3D & center, GLfloat hwid, GLfloat hlen, GLfloat hhei) {x = center.x() - hwid; y = center.y() - hlen; z = center.z() - hhei; width = 2 * hwid; length = 2 * hlen; height = 2 * hhei; angle_z = angle_xy = angle_roll = 0.f;} Box3D(const QVector3D & center, GLfloat hwid, GLfloat hlen, GLfloat hhei) {
x = center.x() - hwid;
y = center.y() - hlen;
z = center.z() - hhei;
width = 2 * hwid;
length = 2 * hlen;
height = 2 * hhei;
angle_z = angle_xy = angle_roll = 0.f;
}
Box3D(const QVector<QVector3D> & points); Box3D(const QVector<QVector3D> & points);
bool isEmpty() const { return (qAbs(width) < 1E-6f) && (qAbs(length) < 1E-6f) && (qAbs(height) < 1E-6f); } bool isEmpty() const { return (qAbs(width) < 1E-6f) && (qAbs(length) < 1E-6f) && (qAbs(height) < 1E-6f); }
QVector3D randomPoint() const { return QVector3D(uprand(length) + x, uprand(width) + y, uprand(height) + z); } QVector3D randomPoint() const { return QVector3D(uprand(length) + x, uprand(width) + y, uprand(height) + z); }
@@ -214,22 +301,62 @@ struct Box3D {
QVector3D center() const { return QVector3D(length / 2.f + x, width / 2.f + y, height / 2.f + z); } QVector3D center() const { return QVector3D(length / 2.f + x, width / 2.f + y, height / 2.f + z); }
QVector3D angles() const { return QVector3D(angle_xy, angle_roll, angle_z); } QVector3D angles() const { return QVector3D(angle_xy, angle_roll, angle_z); }
QVector<QVector3D> corners() const; QVector<QVector3D> corners() const;
void setPos(const QVector3D & p) {x = p.x(); y = p.y(); z = p.z();} void setPos(const QVector3D & p) {
void setAngles(const QVector3D & a) {angle_xy = a.x(); angle_roll = a.y(); angle_z = a.z();} x = p.x();
void setSize(const QVector3D & s) {length = s.x(); width = s.y(); height = s.z();} y = p.y();
Box3D & moveTo(const QVector3D & v) {x = v.x(); y = v.y(); z = v.z(); return *this;} z = p.z();
Box3D & move(const QVector3D & v) {x += v.x(); y += v.y(); z += v.z(); return *this;} }
Box3D movedTo(const QVector3D & v) const {Box3D t(*this); t.x = v.x(); t.y = v.y(); t.z = v.z(); return t;} void setAngles(const QVector3D & a) {
Box3D moved(const QVector3D & v) const {Box3D t(*this); t.x += v.x(); t.y += v.y(); t.z += v.z(); return t;} angle_xy = a.x();
angle_roll = a.y();
angle_z = a.z();
}
void setSize(const QVector3D & s) {
length = s.x();
width = s.y();
height = s.z();
}
Box3D & moveTo(const QVector3D & v) {
x = v.x();
y = v.y();
z = v.z();
return *this;
}
Box3D & move(const QVector3D & v) {
x += v.x();
y += v.y();
z += v.z();
return *this;
}
Box3D movedTo(const QVector3D & v) const {
Box3D t(*this);
t.x = v.x();
t.y = v.y();
t.z = v.z();
return t;
}
Box3D moved(const QVector3D & v) const {
Box3D t(*this);
t.x += v.x();
t.y += v.y();
t.z += v.z();
return t;
}
Box3D & operator|=(const Box3D & o); Box3D & operator|=(const Box3D & o);
}; };
inline QDebug operator <<(QDebug d, const Box3D & v) {d << "Box3D {start (" << v.x << "," << v.y << "," << v.z << "), size (" << v.length << "," << v.width << "," << v.height << ")}"; return d;} inline QDebug operator<<(QDebug d, const Box3D & v) {
d << "Box3D {start (" << v.x << "," << v.y << "," << v.z << "), size (" << v.length << "," << v.width << "," << v.height << ")}";
return d;
}
#pragma pack(push, 1) #pragma pack(push, 1)
struct Vector2i { struct Vector2i {
Vector2i(int p0_ = 0, int p1_ = 0) {p0 = p0_; p1 = p1_;} Vector2i(int p0_ = 0, int p1_ = 0) {
p0 = p0_;
p1 = p1_;
}
Vector2i(const QString & str); Vector2i(const QString & str);
Vector2i movedX(const int & o) { return Vector2i(p0 + o, p1); } Vector2i movedX(const int & o) { return Vector2i(p0 + o, p1); }
Vector2i movedY(const int & o) { return Vector2i(p0, p1 + o); } Vector2i movedY(const int & o) { return Vector2i(p0, p1 + o); }
@@ -238,24 +365,48 @@ struct Vector2i {
GLint p1; GLint p1;
bool operator==(const Vector2i & o) const { return p0 == o.p0 && p1 == o.p1; } bool operator==(const Vector2i & o) const { return p0 == o.p0 && p1 == o.p1; }
bool operator!=(const Vector2i & o) const { return p0 != o.p0 || p1 != o.p1; } bool operator!=(const Vector2i & o) const { return p0 != o.p0 || p1 != o.p1; }
void operator +=(int v) {p0 += v; p1 += v;} void operator+=(int v) {
p0 += v;
p1 += v;
}
QVector2D toQVector2D() const { return QVector2D(p0, p1); } QVector2D toQVector2D() const { return QVector2D(p0, p1); }
}; };
#pragma pack(pop) #pragma pack(pop)
inline Vector2i operator +(const Vector2i & f, const Vector2i & s) {return Vector2i(f.p0 + s.p0, f.p1 + s.p1);} inline Vector2i operator+(const Vector2i & f, const Vector2i & s) {
inline Vector2i operator -(const Vector2i & f, const Vector2i & s) {return Vector2i(f.p0 - s.p0, f.p1 - s.p1);} return Vector2i(f.p0 + s.p0, f.p1 + s.p1);
inline Vector2i operator /(const Vector2i & f, const int & s) {return Vector2i(f.p0 / s, f.p1 / s);} }
inline uint qHash(const Vector2i & v) {return v.p0 ^ ((v.p1 << 8) | (v.p1 >> 24));} inline Vector2i operator-(const Vector2i & f, const Vector2i & s) {
inline QDebug operator <<(QDebug d, const Vector2i & v) {d.nospace() << "{" << v.p0 << ", " << v.p1 << "}"; return d.space();} return Vector2i(f.p0 - s.p0, f.p1 - s.p1);
}
inline Vector2i operator/(const Vector2i & f, const int & s) {
return Vector2i(f.p0 / s, f.p1 / s);
}
inline uint qHash(const Vector2i & v) {
return v.p0 ^ ((v.p1 << 8) | (v.p1 >> 24));
}
inline QDebug operator<<(QDebug d, const Vector2i & v) {
d.nospace() << "{" << v.p0 << ", " << v.p1 << "}";
return d.space();
}
inline QDataStream & operator <<(QDataStream & s, const Vector2i & v) {s << v.p0 << v.p1; return s;} inline QDataStream & operator<<(QDataStream & s, const Vector2i & v) {
inline QDataStream & operator >>(QDataStream & s, Vector2i & v) {s >> v.p0 >> v.p1; return s;} s << v.p0 << v.p1;
return s;
}
inline QDataStream & operator>>(QDataStream & s, Vector2i & v) {
s >> v.p0 >> v.p1;
return s;
}
#pragma pack(push, 1) #pragma pack(push, 1)
struct Vector3i { struct Vector3i {
Vector3i(int p0_ = 0, int p1_ = 0, int p2_ = 0) {p0 = p0_; p1 = p1_; p2 = p2_;} Vector3i(int p0_ = 0, int p1_ = 0, int p2_ = 0) {
p0 = p0_;
p1 = p1_;
p2 = p2_;
}
Vector3i(const QString & str); Vector3i(const QString & str);
Vector3i movedX(const int & o) { return Vector3i(p0 + o, p1, p2); } Vector3i movedX(const int & o) { return Vector3i(p0 + o, p1, p2); }
Vector3i movedY(const int & o) { return Vector3i(p0, p1 + o, p2); } Vector3i movedY(const int & o) { return Vector3i(p0, p1 + o, p2); }
@@ -266,39 +417,81 @@ struct Vector3i {
GLint p2; GLint p2;
bool operator==(const Vector3i & o) const { return p0 == o.p0 && p1 == o.p1 && p2 == o.p2; } bool operator==(const Vector3i & o) const { return p0 == o.p0 && p1 == o.p1 && p2 == o.p2; }
bool operator!=(const Vector3i & o) const { return p0 != o.p0 || p1 != o.p1 || p2 != o.p2; } bool operator!=(const Vector3i & o) const { return p0 != o.p0 || p1 != o.p1 || p2 != o.p2; }
void operator +=(int v) {p0 += v; p1 += v; p2 += v;} void operator+=(int v) {
p0 += v;
p1 += v;
p2 += v;
}
QVector3D toQVector3D() const { return QVector3D(p0, p1, p2); } QVector3D toQVector3D() const { return QVector3D(p0, p1, p2); }
}; };
#pragma pack(pop) #pragma pack(pop)
inline Vector3i operator +(const Vector3i & f, const Vector3i & s) {return Vector3i(f.p0 + s.p0, f.p1 + s.p1, f.p2 + s.p2);} inline Vector3i operator+(const Vector3i & f, const Vector3i & s) {
inline Vector3i operator -(const Vector3i & f, const Vector3i & s) {return Vector3i(f.p0 - s.p0, f.p1 - s.p1, f.p2 - s.p2);} return Vector3i(f.p0 + s.p0, f.p1 + s.p1, f.p2 + s.p2);
inline Vector3i operator /(const Vector3i & f, const int & s) {return Vector3i(f.p0 / s, f.p1 / s, f.p2 / s);} }
inline uint qHash(const Vector3i & v) {return v.p0 ^ ((v.p1 << 8) | (v.p1 >> 24)) ^ ((v.p2 << 16) | (v.p2 >> 16));} inline Vector3i operator-(const Vector3i & f, const Vector3i & s) {
inline QDebug operator <<(QDebug d, const Vector3i & v) {d.nospace() << "{" << v.p0 << ", " << v.p1 << ", " << v.p2 << "}"; return d.space();} return Vector3i(f.p0 - s.p0, f.p1 - s.p1, f.p2 - s.p2);
}
inline Vector3i operator/(const Vector3i & f, const int & s) {
return Vector3i(f.p0 / s, f.p1 / s, f.p2 / s);
}
inline uint qHash(const Vector3i & v) {
return v.p0 ^ ((v.p1 << 8) | (v.p1 >> 24)) ^ ((v.p2 << 16) | (v.p2 >> 16));
}
inline QDebug operator<<(QDebug d, const Vector3i & v) {
d.nospace() << "{" << v.p0 << ", " << v.p1 << ", " << v.p2 << "}";
return d.space();
}
inline QDataStream & operator <<(QDataStream & s, const Vector3i & v) {s << v.p0 << v.p1 << v.p2; return s;} inline QDataStream & operator<<(QDataStream & s, const Vector3i & v) {
inline QDataStream & operator >>(QDataStream & s, Vector3i & v) {s >> v.p0 >> v.p1 >> v.p2; return s;} s << v.p0 << v.p1 << v.p2;
return s;
}
inline QDataStream & operator>>(QDataStream & s, Vector3i & v) {
s >> v.p0 >> v.p1 >> v.p2;
return s;
}
QVector3D vectorFromString(const QString & str); QVector3D vectorFromString(const QString & str);
QColor colorFromString(const QString & str); QColor colorFromString(const QString & str);
inline QVector4D QColor2QVector(const QColor & c) {return QVector4D(c.redF(), c.greenF(), c.blueF(), c.alphaF());} inline QVector4D QColor2QVector(const QColor & c) {
return QVector4D(c.redF(), c.greenF(), c.blueF(), c.alphaF());
}
inline float cosABV(const QVector3D & v0, const QVector3D & v1) { inline float cosABV(const QVector3D & v0, const QVector3D & v1) {
float l = v0.length() * v1.length(); float l = v0.length() * v1.length();
if (l == 0.f) return 0.; if (l == 0.f) return 0.;
return (QVector3D::dotProduct(v0, v1)) / l; return (QVector3D::dotProduct(v0, v1)) / l;
} }
inline void normalizeAngleRad(float & a) {while (a < 0.) a += M_2PI; while (a >= M_2PI) a -= M_2PI;} inline void normalizeAngleRad(float & a) {
inline void normalizeAngleDeg360(float & a) {while (a < 0.) a += 360. ; while (a >= 360. ) a -= 360. ;} while (a < 0.)
inline QVector3D projection(const QVector3D & v, const QVector3D & to) {return to.normalized() * v.length() * cosABV(v, to);} a += M_2PI;
while (a >= M_2PI)
a -= M_2PI;
}
inline void normalizeAngleDeg360(float & a) {
while (a < 0.)
a += 360.;
while (a >= 360.)
a -= 360.;
}
inline QVector3D projection(const QVector3D & v, const QVector3D & to) {
return to.normalized() * v.length() * cosABV(v, to);
}
QVector3D orthToVector(const QVector3D & v, const float & scale = 1.); QVector3D orthToVector(const QVector3D & v, const float & scale = 1.);
QVector3D rotateVector(const QVector3D & v, const QVector3D & a); QVector3D rotateVector(const QVector3D & v, const QVector3D & a);
void setVectorLength(QVector3D & v, const float & l); void setVectorLength(QVector3D & v, const float & l);
void lengthenVector(QVector3D & v, const float & l); void lengthenVector(QVector3D & v, const float & l);
inline float squareLength(const QVector3D & from, const QVector3D & to) {return (to.x() - from.x())*(to.x() - from.x()) + (to.y() - from.y())*(to.y() - from.y()) + (to.z() - from.z())*(to.z() - from.z());} inline float squareLength(const QVector3D & from, const QVector3D & to) {
inline QVector3D directionFromAngles(const QVector3D & a) {return rotateVector(QVector3D(1., 0., 0.), a);} return (to.x() - from.x()) * (to.x() - from.x()) + (to.y() - from.y()) * (to.y() - from.y()) +
inline float frac(const float & x, const float & b) {return x - int(x / b) * b;} (to.z() - from.z()) * (to.z() - from.z());
}
inline QVector3D directionFromAngles(const QVector3D & a) {
return rotateVector(QVector3D(1., 0., 0.), a);
}
inline float frac(const float & x, const float & b) {
return x - int(x / b) * b;
}
#endif // GLTYPES_H #endif // GLTYPES_H

View File

@@ -17,23 +17,21 @@
*/ */
#define GL_GLEXT_PROTOTYPES #define GL_GLEXT_PROTOTYPES
#include <QOpenGLExtraFunctions>
#include "glvertexobject.h" #include "glvertexobject.h"
#include <QOpenGLExtraFunctions>
using namespace QGLEngineShaders; using namespace QGLEngineShaders;
VertexObject::VertexObject(): VertexObject::VertexObject(): buffer_obj(GL_ARRAY_BUFFER, GL_STREAM_DRAW), buffer_sel(GL_ARRAY_BUFFER, GL_STREAM_DRAW) {
buffer_obj (GL_ARRAY_BUFFER, GL_STREAM_DRAW),
buffer_sel (GL_ARRAY_BUFFER, GL_STREAM_DRAW) {
vao_ = 0; vao_ = 0;
buffers_binded = false; buffers_binded = false;
objects_changed = selected_changed = true; objects_changed = selected_changed = true;
} }
VertexObject::~VertexObject() { VertexObject::~VertexObject() {}
}
void VertexObject::init(QOpenGLExtraFunctions * f) { void VertexObject::init(QOpenGLExtraFunctions * f) {

View File

@@ -23,8 +23,7 @@
#include "glshaders_types.h" #include "glshaders_types.h"
class VertexObject class VertexObject {
{
public: public:
VertexObject(); VertexObject();
~VertexObject(); ~VertexObject();

View File

@@ -17,8 +17,9 @@
*/ */
#include "hdr_p.h" #include "hdr_p.h"
#include <qmath.h>
#include <QByteArray> #include <QByteArray>
#include <qmath.h>
#define RGBE_DATA_RED 2 #define RGBE_DATA_RED 2
#define RGBE_DATA_GREEN 1 #define RGBE_DATA_GREEN 1
@@ -34,8 +35,7 @@ void rgbe2float(float *red, float *green, float *blue, uchar rgbe[4]) {
*red = rgbe[0] * f; *red = rgbe[0] * f;
*green = rgbe[1] * f; *green = rgbe[1] * f;
*blue = rgbe[2] * f; *blue = rgbe[2] * f;
} } else
else
*red = *green = *blue = 0.0; *red = *green = *blue = 0.0;
} }
@@ -44,8 +44,7 @@ void rgbe2float(float *red, float *green, float *blue, uchar rgbe[4]) {
bool RGBE_ReadPixels(QDataStream * fp, float * data, int numpixels) { bool RGBE_ReadPixels(QDataStream * fp, float * data, int numpixels) {
uchar rgbe[4]; uchar rgbe[4];
while (numpixels-- > 0) { while (numpixels-- > 0) {
if (fp->readRawData((char*)rgbe, sizeof(rgbe)) < 1) if (fp->readRawData((char *)rgbe, sizeof(rgbe)) < 1) return false;
return false;
rgbe2float(&data[RGBE_DATA_RED], &data[RGBE_DATA_GREEN], &data[RGBE_DATA_BLUE], rgbe); rgbe2float(&data[RGBE_DATA_RED], &data[RGBE_DATA_GREEN], &data[RGBE_DATA_BLUE], rgbe);
data += RGBE_DATA_SIZE; data += RGBE_DATA_SIZE;
} }
@@ -59,8 +58,7 @@ bool RGBE_ReadPixels_RLE(QDataStream * fp, float * data, int scanline_width, int
uchar buf[2]; uchar buf[2];
QByteArray scanline_buffer; QByteArray scanline_buffer;
if ((scanline_width < 8)||(scanline_width > 0x7fff)) if ((scanline_width < 8) || (scanline_width > 0x7fff)) /* run length encoding is not allowed so read flat*/
/* run length encoding is not allowed so read flat*/
return RGBE_ReadPixels(fp, data, scanline_width * num_scanlines); return RGBE_ReadPixels(fp, data, scanline_width * num_scanlines);
scanline_buffer.resize(4 * scanline_width); scanline_buffer.resize(4 * scanline_width);
/* read in each successive scanline */ /* read in each successive scanline */
@@ -93,8 +91,7 @@ bool RGBE_ReadPixels_RLE(QDataStream * fp, float * data, int scanline_width, int
} }
while (count-- > 0) while (count-- > 0)
*ptr++ = buf[1]; *ptr++ = buf[1];
} } else {
else {
/* a non-run */ /* a non-run */
count = buf[0]; count = buf[0];
if ((count == 0) || (count > ptr_end - ptr)) { if ((count == 0) || (count > ptr_end - ptr)) {
@@ -116,8 +113,7 @@ bool RGBE_ReadPixels_RLE(QDataStream * fp, float * data, int scanline_width, int
rgbe[1] = scanline_buffer[i + scanline_width]; rgbe[1] = scanline_buffer[i + scanline_width];
rgbe[2] = scanline_buffer[i + 2 * scanline_width]; rgbe[2] = scanline_buffer[i + 2 * scanline_width];
rgbe[3] = scanline_buffer[i + 3 * scanline_width]; rgbe[3] = scanline_buffer[i + 3 * scanline_width];
rgbe2float(&data[RGBE_DATA_RED],&data[RGBE_DATA_GREEN], rgbe2float(&data[RGBE_DATA_RED], &data[RGBE_DATA_GREEN], &data[RGBE_DATA_BLUE], rgbe);
&data[RGBE_DATA_BLUE],rgbe);
data += RGBE_DATA_SIZE; data += RGBE_DATA_SIZE;
} }
num_scanlines--; num_scanlines--;

View File

@@ -17,25 +17,36 @@
*/ */
#include "loader_assimp.h" #include "loader_assimp.h"
#include "glscene.h"
#include "glmesh.h"
#include "glmaterial.h" #include "glmaterial.h"
#include "glmesh.h"
#include "globject.h" #include "globject.h"
#include "glscene.h"
#include <assimp/Importer.hpp> #include <assimp/Importer.hpp>
#include <assimp/material.h>
#include <assimp/mesh.h>
#include <assimp/postprocess.h> #include <assimp/postprocess.h>
#include <assimp/scene.h> #include <assimp/scene.h>
#include <assimp/mesh.h>
#include <assimp/material.h>
QString fromAiString (const aiString & s) {return QString::fromLocal8Bit(s.C_Str());} QString fromAiString(const aiString & s) {
QColor fromAiColor (const aiColor4D & c) {return QColor::fromRgbF(piClamp(c.r, 0.f, 1.f), piClamp(c.g, 0.f, 1.f), piClamp(c.b, 0.f, 1.f));} return QString::fromLocal8Bit(s.C_Str());
QVector3D fromAiVector3D(const aiVector3D & v) {return QVector3D(v.x, v.y, v.z);} }
Vector3i fromAiFace (const aiFace & v) {return Vector3i(v.mIndices[0], v.mIndices[1], v.mIndices[2]);} QColor fromAiColor(const aiColor4D & c) {
QMatrix4x4 fromAiMatrix4D(const aiMatrix4x4 & v) {return QMatrix4x4(v.a1, v.a2, v.a3, v.a4, return QColor::fromRgbF(piClamp(c.r, 0.f, 1.f), piClamp(c.g, 0.f, 1.f), piClamp(c.b, 0.f, 1.f));
v.b1, v.b2, v.b3, v.b4, }
v.c1, v.c2, v.c3, v.c4, QVector3D fromAiVector3D(const aiVector3D & v) {
v.d1, v.d2, v.d3, v.d4);} return QVector3D(v.x, v.y, v.z);
bool isAiMeshTriangles(const aiMesh * m) {return (m->mPrimitiveTypes & aiPrimitiveType_TRIANGLE) == aiPrimitiveType_TRIANGLE;} }
Vector3i fromAiFace(const aiFace & v) {
return Vector3i(v.mIndices[0], v.mIndices[1], v.mIndices[2]);
}
QMatrix4x4 fromAiMatrix4D(const aiMatrix4x4 & v) {
return QMatrix4x4(v.a1, v.a2, v.a3, v.a4, v.b1, v.b2, v.b3, v.b4, v.c1, v.c2, v.c3, v.c4, v.d1, v.d2, v.d3, v.d4);
}
bool isAiMeshTriangles(const aiMesh * m) {
return (m->mPrimitiveTypes & aiPrimitiveType_TRIANGLE) == aiPrimitiveType_TRIANGLE;
}
Mesh * assimpMesh(const aiMesh * m) { Mesh * assimpMesh(const aiMesh * m) {
@@ -44,8 +55,10 @@ Mesh * assimpMesh(const aiMesh * m) {
Mesh * ret = new Mesh(); Mesh * ret = new Mesh();
int vcnt = m->mNumVertices, tcnt = m->mNumFaces; int vcnt = m->mNumVertices, tcnt = m->mNumFaces;
QVector<QVector3D> & v(ret->vertices()); v.resize(vcnt); QVector<QVector3D> & v(ret->vertices());
QVector<QVector2D> & t(ret->texcoords()); t.resize(vcnt); v.resize(vcnt);
QVector<QVector2D> & t(ret->texcoords());
t.resize(vcnt);
QVector<Vector3i> & ind(ret->indicesTriangles()); QVector<Vector3i> & ind(ret->indicesTriangles());
for (int i = 0; i < vcnt; ++i) for (int i = 0; i < vcnt; ++i)
@@ -136,8 +149,7 @@ Material * assimpMaterial(const aiMaterial * m) {
Light * assimpLight(const aiLight * l) { Light * assimpLight(const aiLight * l) {
if (!l) return 0; if (!l) return 0;
if (l->mType != aiLightSource_POINT && l->mType != aiLightSource_SPOT) if (l->mType != aiLightSource_POINT && l->mType != aiLightSource_SPOT) return 0;
return 0;
Light * ret = new Light(); Light * ret = new Light();
ret->setName(fromAiString(l->mName)); ret->setName(fromAiString(l->mName));
ret->setPos(fromAiVector3D(l->mPosition)); ret->setPos(fromAiVector3D(l->mPosition));
@@ -147,8 +159,7 @@ Light * assimpLight(const aiLight * l) {
ret->decay_quadratic = l->mAttenuationQuadratic; ret->decay_quadratic = l->mAttenuationQuadratic;
ret->angle_start = l->mAngleInnerCone * rad2deg; ret->angle_start = l->mAngleInnerCone * rad2deg;
ret->angle_end = l->mAngleOuterCone * rad2deg; ret->angle_end = l->mAngleOuterCone * rad2deg;
if (l->mType == aiLightSource_SPOT) if (l->mType == aiLightSource_SPOT) ret->light_type = Light::Cone;
ret->light_type = Light::Cone;
QVector3D col(l->mColorDiffuse.r, l->mColorDiffuse.g, l->mColorDiffuse.b); QVector3D col(l->mColorDiffuse.r, l->mColorDiffuse.g, l->mColorDiffuse.b);
ret->intensity = col.length(); ret->intensity = col.length();
col /= ret->intensity; col /= ret->intensity;
@@ -157,9 +168,12 @@ Light * assimpLight(const aiLight * l) {
} }
ObjectBaseList assimpObject(const aiNode * n, const QVector<Mesh * > & meshes, aiMesh ** ai_meshes, ObjectBaseList assimpObject(const aiNode * n,
const QVector<Mesh *> & meshes,
aiMesh ** ai_meshes,
const QVector<Material *> & materials, const QVector<Material *> & materials,
const QMap<QString, Light * > & light_by_name, QVector<Light*> & out_lights) { const QMap<QString, Light *> & light_by_name,
QVector<Light *> & out_lights) {
if (!n) return ObjectBaseList(); if (!n) return ObjectBaseList();
ObjectBaseList ret; ObjectBaseList ret;
ObjectBase * obj = 0; ObjectBase * obj = 0;
@@ -185,8 +199,7 @@ ObjectBaseList assimpObject(const aiNode * n, const QVector<Mesh * > & meshes, a
} }
obj->setMesh(meshes[mi]); obj->setMesh(meshes[mi]);
int mati = ai_meshes[mi]->mMaterialIndex; int mati = ai_meshes[mi]->mMaterialIndex;
if (mati >= 0 || mati < materials.size()) if (mati >= 0 || mati < materials.size()) obj->setMaterial(materials[mati]);
obj->setMaterial(materials[mati]);
// ret->setMesh(meshes[mi]); // ret->setMesh(meshes[mi]);
// qDebug() << "set mesh" << mi << ret->mesh(); // qDebug() << "set mesh" << mi << ret->mesh();
// break; // break;
@@ -207,10 +220,9 @@ Scene * loadScene(const QString & filepath) {
if (filepath.isEmpty()) return 0; if (filepath.isEmpty()) return 0;
qDebug() << "[Loader Assimp] Import" << filepath << "..."; qDebug() << "[Loader Assimp] Import" << filepath << "...";
Assimp::Importer importer; Assimp::Importer importer;
const aiScene * ais = importer.ReadFile(filepath.toUtf8(), aiProcess_Triangulate | const aiScene * ais =
aiProcess_SortByPType | importer.ReadFile(filepath.toUtf8(),
aiProcess_GenUVCoords | aiProcess_Triangulate | aiProcess_SortByPType | aiProcess_GenUVCoords | aiProcess_TransformUVCoords);
aiProcess_TransformUVCoords);
if (!ais) { if (!ais) {
qDebug() << "[Loader Assimp] Error: \"" + QString(importer.GetErrorString()) + "\""; qDebug() << "[Loader Assimp] Error: \"" + QString(importer.GetErrorString()) + "\"";
return 0; return 0;
@@ -227,8 +239,7 @@ Scene * loadScene(const QString & filepath) {
lights << assimpLight(ais->mLights[i]); lights << assimpLight(ais->mLights[i]);
QMap<QString, Light *> light_by_name; QMap<QString, Light *> light_by_name;
foreach(Light * l, lights) foreach(Light * l, lights)
if (l) if (l) light_by_name[l->name()] = l;
light_by_name[l->name()] = l;
QVector<Light *> out_lights; QVector<Light *> out_lights;
ObjectBaseList rootl = assimpObject(ais->mRootNode, meshes, ais->mMeshes, materials, light_by_name, out_lights); ObjectBaseList rootl = assimpObject(ais->mRootNode, meshes, ais->mMeshes, materials, light_by_name, out_lights);

View File

@@ -17,7 +17,9 @@
*/ */
#include "loader_qgl.h" #include "loader_qgl.h"
#include "glscene.h" #include "glscene.h"
#include <chunkstream.h> #include <chunkstream.h>
@@ -53,8 +55,7 @@ Scene * loadFromQGLFile(const QString & filepath) {
bool saveToQGLFile(const QString & filepath, const Scene * scene) { bool saveToQGLFile(const QString & filepath, const Scene * scene) {
QFile f(filepath); QFile f(filepath);
if (!f.open(QIODevice::ReadWrite)) if (!f.open(QIODevice::ReadWrite)) return false;
return false;
f.resize(0); f.resize(0);
QDataStream s(&f); QDataStream s(&f);
s.setVersion(QDataStream::Qt_5_0); s.setVersion(QDataStream::Qt_5_0);

View File

@@ -20,6 +20,7 @@
#define LOADER_QGL_H #define LOADER_QGL_H
#include "gltypes.h" #include "gltypes.h"
#include <QFileInfo> #include <QFileInfo>
Scene * loadFromQGLFile(const QString & filepath); Scene * loadFromQGLFile(const QString & filepath);

View File

@@ -22,10 +22,10 @@
#include "globject.h" #include "globject.h"
class Camera: public AimedObject class Camera: public AimedObject {
{
friend QDataStream & operator<<(QDataStream & s, const ObjectBase * p); friend QDataStream & operator<<(QDataStream & s, const ObjectBase * p);
friend QDataStream & operator>>(QDataStream & s, ObjectBase *& p); friend QDataStream & operator>>(QDataStream & s, ObjectBase *& p);
public: public:
Camera(); Camera();

View File

@@ -17,9 +17,11 @@
*/ */
#include "globject.h" #include "globject.h"
#include "glcamera.h" #include "glcamera.h"
#include "glscene.h"
#include "glmesh.h" #include "glmesh.h"
#include "glscene.h"
#include <chunkstream.h> #include <chunkstream.h>
// static int _count = 0; // static int _count = 0;
@@ -106,8 +108,7 @@ void ObjectBase::init() {
RenderPass ObjectBase::pass() const { RenderPass ObjectBase::pass() const {
RenderPass ret = rpSolid; RenderPass ret = rpSolid;
if (material_) if (material_)
if (material_->hasTransparency()) if (material_->hasTransparency()) ret = rpTransparent;
ret = rpTransparent;
return ret; return ret;
} }
@@ -121,8 +122,7 @@ void ObjectBase::setScene(Scene * v) {
void ObjectBase::addChild(ObjectBase * o) { void ObjectBase::addChild(ObjectBase * o) {
if (o == this) return; if (o == this) return;
if (o->parent_) if (o->parent_) o->parent_->children_.removeAll(o);
o->parent_->children_.removeAll(o);
children_ << o; children_ << o;
o->parent_ = this; o->parent_ = this;
o->setScene(scene_); o->setScene(scene_);
@@ -326,8 +326,10 @@ void ObjectBase::transferTransformToChildren(bool only_scale) {
if (only_scale) m = trans.matrixScale(); if (only_scale) m = trans.matrixScale();
foreach(ObjectBase * i, children_) foreach(ObjectBase * i, children_)
i->trans.setMatrix(m * i->trans.matrix()); i->trans.setMatrix(m * i->trans.matrix());
if (only_scale) resetScale(); if (only_scale)
else setMatrix(QMatrix4x4()); resetScale();
else
setMatrix(QMatrix4x4());
} }
@@ -357,10 +359,8 @@ bool ObjectBase::isSelected(bool check_parents) const {
void ObjectBase::setSelected(bool yes) { void ObjectBase::setSelected(bool yes) {
// qDebug() << "select" << name() << view_; // qDebug() << "select" << name() << view_;
if (select_) if (select_) selected_ = yes;
selected_ = yes; if (!selected_) selected_aim = false;
if (!selected_)
selected_aim = false;
} }
@@ -377,7 +377,8 @@ ObjectBase * ObjectBase::selectedParent() const {
void ObjectBase::setMaterial(Material * m, bool with_children) { void ObjectBase::setMaterial(Material * m, bool with_children) {
material_ = m; material_ = m;
if (with_children) if (with_children)
foreach (ObjectBase * i, children_) i->setMaterial(m, true); foreach(ObjectBase * i, children_)
i->setMaterial(m, true);
setObjectsChanged(); setObjectsChanged();
if (scene_) scene_->mat_changed = scene_->tree_changed = true; if (scene_) scene_->mat_changed = scene_->tree_changed = true;
} }
@@ -386,14 +387,14 @@ void ObjectBase::setMaterial(Material * m, bool with_children) {
void ObjectBase::setColor(QColor c, bool with_children) { void ObjectBase::setColor(QColor c, bool with_children) {
color_ = c; color_ = c;
if (with_children) if (with_children)
foreach (ObjectBase * i, children_) i->setColor(c, true); foreach(ObjectBase * i, children_)
i->setColor(c, true);
setObjectsChanged(); setObjectsChanged();
} }
void ObjectBase::setMesh(Mesh * v) { void ObjectBase::setMesh(Mesh * v) {
if (scene_) if (scene_) v = scene_->attachMesh(v);
v = scene_->attachMesh(v);
mesh_ = v; mesh_ = v;
setSceneTreeChanged(); setSceneTreeChanged();
setObjectsChanged(); setObjectsChanged();
@@ -404,8 +405,7 @@ void ObjectBase::buildTransform(bool force) {
if (force) trans.setDirty(); if (force) trans.setDirty();
itransform_.setToIdentity(); itransform_.setToIdentity();
ObjectBase * p = parent_; ObjectBase * p = parent_;
if (p) if (p) itransform_ = p->itransform_;
itransform_ = p->itransform_;
// if (raw_matrix) { // if (raw_matrix) {
// itransform_.translate(pos_); // itransform_.translate(pos_);
// itransform_ *= mat_; // itransform_ *= mat_;
@@ -421,7 +421,8 @@ void ObjectBase::buildTransform(bool force) {
void ObjectBase::initInternal() { void ObjectBase::initInternal() {
init(); init();
foreach (ObjectBase * i, children_) i->initInternal(); foreach(ObjectBase * i, children_)
i->initInternal();
} }
@@ -469,8 +470,6 @@ QMatrix4x4 ObjectBase::worldMatrix(QMatrix4x4 parent) const {
} }
AimedObject::AimedObject() { AimedObject::AimedObject() {
aim_dist = 1.; aim_dist = 1.;
} }
@@ -560,11 +559,7 @@ void AimedObject::orbitXY(const float & a) {
} }
void AimedObject::transformChanged() { void AimedObject::transformChanged() {}
}
Light::Light(): AimedObject(), shadow_map(0, true, GL_R16F) { Light::Light(): AimedObject(), shadow_map(0, true, GL_R16F) {
@@ -625,24 +620,45 @@ void Light::apply() {
QDataStream & operator<<(QDataStream & s, const ObjectBase * p) { QDataStream & operator<<(QDataStream & s, const ObjectBase * p) {
ChunkStream cs; ChunkStream cs;
// qDebug() << "place" << p->name() << "..."; // qDebug() << "place" << p->name() << "...";
cs.add(1, int(p->type_)).add(2, p->accept_light).add(3, p->accept_fog).add(4, p->visible_) cs.add(1, int(p->type_))
.add(5, p->cast_shadow).add(6, p->rec_shadow).add(7, p->raw_matrix).add(8, p->line_width) .add(2, p->accept_light)
.add(9, int(p->render_mode)).add(14, p->mat_).add(16, p->children_.size()) .add(3, p->accept_fog)
.add(17, p->name_).add(18, p->meta).add(19, p->color_).add(20, p->trans); .add(4, p->visible_)
.add(5, p->cast_shadow)
.add(6, p->rec_shadow)
.add(7, p->raw_matrix)
.add(8, p->line_width)
.add(9, int(p->render_mode))
.add(14, p->mat_)
.add(16, p->children_.size())
.add(17, p->name_)
.add(18, p->meta)
.add(19, p->color_)
.add(20, p->trans);
// qDebug() << "place self done"; // qDebug() << "place self done";
if (p->type_ == ObjectBase::glLight) { if (p->type_ == ObjectBase::glLight) {
// qDebug() << "place light ..."; // qDebug() << "place light ...";
const Light * l = (const Light *)p; const Light * l = (const Light *)p;
cs.add(101, l->angle_start).add(102, l->angle_end).add(103, l->intensity) cs.add(101, l->angle_start)
.add(104, l->decay_const).add(105, l->decay_linear).add(106, l->decay_quadratic) .add(102, l->angle_end)
.add(107, l->decay_start).add(108, l->decay_end).add(109, int(l->light_type)) .add(103, l->intensity)
.add(104, l->decay_const)
.add(105, l->decay_linear)
.add(106, l->decay_quadratic)
.add(107, l->decay_start)
.add(108, l->decay_end)
.add(109, int(l->light_type))
.add(111, l->distance()); .add(111, l->distance());
} }
if (p->type_ == ObjectBase::glCamera) { if (p->type_ == ObjectBase::glCamera) {
// qDebug() << "place camera ..."; // qDebug() << "place camera ...";
const Camera * c = (const Camera *)p; const Camera * c = (const Camera *)p;
cs.add(200, c->aim()).add(201, c->fov_).add(202, c->depth_start) cs.add(200, c->aim())
.add(206, c->mirror_x).add(207, c->mirror_y).add(208, c->distance()) .add(201, c->fov_)
.add(202, c->depth_start)
.add(206, c->mirror_x)
.add(207, c->mirror_y)
.add(208, c->distance())
.add(209, c->roll_); .add(209, c->roll_);
} }
// qDebug() << "place" << p->name() << cs.data().size() << s.device()->size(); // qDebug() << "place" << p->name() << cs.data().size() << s.device()->size();
@@ -664,44 +680,114 @@ QDataStream & operator >>(QDataStream & s, ObjectBase *& p) {
ObjectBase::Type type = (ObjectBase::Type)cs.getData<int>(); ObjectBase::Type type = (ObjectBase::Type)cs.getData<int>();
switch (type) { switch (type) {
case ObjectBase::glMesh: p = new ObjectBase(); break; case ObjectBase::glMesh: p = new ObjectBase(); break;
case ObjectBase::glLight: p = new Light(); l = (Light*)p; break; case ObjectBase::glLight:
case ObjectBase::glCamera: p = new Camera(); c = (Camera*)p; break; p = new Light();
l = (Light *)p;
break;
case ObjectBase::glCamera:
p = new Camera();
c = (Camera *)p;
break;
default: break; default: break;
} }
if (p) p->type_ = type; if (p) p->type_ = type;
} break; } break;
case 2: if (p) p->accept_light = cs.getData<bool>(); break; case 2:
case 3: if (p) p->accept_fog = cs.getData<bool>(); break; if (p) p->accept_light = cs.getData<bool>();
case 4: if (p) p->visible_ = cs.getData<bool>(); break; break;
case 5: if (p) p->cast_shadow = cs.getData<bool>(); break; case 3:
case 6: if (p) p->rec_shadow = cs.getData<bool>(); break; if (p) p->accept_fog = cs.getData<bool>();
case 7: if (p) p->raw_matrix = cs.getData<bool>(); break; break;
case 8: if (p) p->line_width = cs.getData<float>(); break; case 4:
case 9: if (p) p->render_mode = (ObjectBase::RenderMode)cs.getData<int>(); break; if (p) p->visible_ = cs.getData<bool>();
case 14: if (p) p->mat_ = cs.getData<QMatrix4x4>(); break; break;
case 16: if (p) ccnt = cs.getData<int>(); break; case 5:
case 17: if (p) p->name_ = cs.getData<QString>(); break; if (p) p->cast_shadow = cs.getData<bool>();
case 18: if (p) p->meta = cs.getData<QVariantMap>(); break; break;
case 19: if (p) p->color_ = cs.getData<QColor>(); break; case 6:
case 20: if (p) p->trans = cs.getData<Transform>(); break; if (p) p->rec_shadow = cs.getData<bool>();
case 100: if (l) l->setAim(cs.getData<QVector3D>()); break; break;
case 101: if (l) l->angle_start = cs.getData<GLfloat>(); break; case 7:
case 102: if (l) l->angle_end = cs.getData<GLfloat>(); break; if (p) p->raw_matrix = cs.getData<bool>();
case 103: if (l) l->intensity = cs.getData<GLfloat>(); break; break;
case 104: if (l) l->decay_const = cs.getData<GLfloat>(); break; case 8:
case 105: if (l) l->decay_linear = cs.getData<GLfloat>(); break; if (p) p->line_width = cs.getData<float>();
case 106: if (l) l->decay_quadratic = cs.getData<GLfloat>(); break; break;
case 107: if (l) l->decay_start = cs.getData<GLfloat>(); break; case 9:
case 108: if (l) l->decay_end = cs.getData<GLfloat>(); break; if (p) p->render_mode = (ObjectBase::RenderMode)cs.getData<int>();
case 109: if (l) l->light_type = (Light::Type)cs.getData<int>(); break; break;
case 111: if (l) l->setDistance(cs.getData<double>()); break; case 14:
case 200: if (c) c->setAim(cs.getData<QVector3D>()); break; if (p) p->mat_ = cs.getData<QMatrix4x4>();
case 201: if (c) c->setFOV(cs.getData<GLfloat>()); break; break;
case 202: if (c) c->setDepthStart(cs.getData<GLfloat>()); break; case 16:
case 206: if (c) c->mirror_x = cs.getData<bool>(); break; if (p) ccnt = cs.getData<int>();
case 207: if (c) c->mirror_y = cs.getData<bool>(); break; break;
case 208: if (c) c->setDistance(cs.getData<double>()); break; case 17:
case 209: if (c) c->roll_ = cs.getData<GLfloat>(); break; if (p) p->name_ = cs.getData<QString>();
break;
case 18:
if (p) p->meta = cs.getData<QVariantMap>();
break;
case 19:
if (p) p->color_ = cs.getData<QColor>();
break;
case 20:
if (p) p->trans = cs.getData<Transform>();
break;
case 100:
if (l) l->setAim(cs.getData<QVector3D>());
break;
case 101:
if (l) l->angle_start = cs.getData<GLfloat>();
break;
case 102:
if (l) l->angle_end = cs.getData<GLfloat>();
break;
case 103:
if (l) l->intensity = cs.getData<GLfloat>();
break;
case 104:
if (l) l->decay_const = cs.getData<GLfloat>();
break;
case 105:
if (l) l->decay_linear = cs.getData<GLfloat>();
break;
case 106:
if (l) l->decay_quadratic = cs.getData<GLfloat>();
break;
case 107:
if (l) l->decay_start = cs.getData<GLfloat>();
break;
case 108:
if (l) l->decay_end = cs.getData<GLfloat>();
break;
case 109:
if (l) l->light_type = (Light::Type)cs.getData<int>();
break;
case 111:
if (l) l->setDistance(cs.getData<double>());
break;
case 200:
if (c) c->setAim(cs.getData<QVector3D>());
break;
case 201:
if (c) c->setFOV(cs.getData<GLfloat>());
break;
case 202:
if (c) c->setDepthStart(cs.getData<GLfloat>());
break;
case 206:
if (c) c->mirror_x = cs.getData<bool>();
break;
case 207:
if (c) c->mirror_y = cs.getData<bool>();
break;
case 208:
if (c) c->setDistance(cs.getData<double>());
break;
case 209:
if (c) c->roll_ = cs.getData<GLfloat>();
break;
} }
} }
// qDebug() << p->name() << ccnt; // qDebug() << p->name() << ccnt;

View File

@@ -21,20 +21,30 @@
#include "glframebuffer.h" #include "glframebuffer.h"
#include "glmaterial.h" #include "glmaterial.h"
#include "gltypes.h"
#include "gltransform.h" #include "gltransform.h"
#include "gltypes.h"
class ObjectBase class ObjectBase {
{
friend class Scene; friend class Scene;
friend class RendererSelection; friend class RendererSelection;
friend QDataStream & operator<<(QDataStream & s, const ObjectBase * p); friend QDataStream & operator<<(QDataStream & s, const ObjectBase * p);
friend QDataStream & operator>>(QDataStream & s, ObjectBase *& p); friend QDataStream & operator>>(QDataStream & s, ObjectBase *& p);
friend QDataStream & operator>>(QDataStream & s, Scene *& p); friend QDataStream & operator>>(QDataStream & s, Scene *& p);
public: public:
enum Type {glMesh, glLight, glCamera, glParticlesSystem}; enum Type {
enum RenderMode {View = 0, Point = GL_POINT, Line = GL_LINE, Fill = GL_FILL}; glMesh,
glLight,
glCamera,
glParticlesSystem
};
enum RenderMode {
View = 0,
Point = GL_POINT,
Line = GL_LINE,
Fill = GL_FILL
};
explicit ObjectBase(Mesh * geom = 0, Material * mat = 0); explicit ObjectBase(Mesh * geom = 0, Material * mat = 0);
virtual ~ObjectBase(); virtual ~ObjectBase();
@@ -86,19 +96,58 @@ public:
void setReceiveShadows(bool on) { rec_shadow = on; } void setReceiveShadows(bool on) { rec_shadow = on; }
void setCastShadows(bool on) { cast_shadow = on; } void setCastShadows(bool on) { cast_shadow = on; }
void move(const QVector3D & dv) {trans.setTranslation(pos() + dv); buildTransform();} void move(const QVector3D & dv) {
void moveTo(const QVector3D & dv) {trans.setTranslation(dv); buildTransform();} trans.setTranslation(pos() + dv);
void move(GLfloat dx, GLfloat dy, GLfloat dz = 0.) {move(QVector3D(dx, dy, dz)); buildTransform();} buildTransform();
void moveTo(GLfloat dx, GLfloat dy, GLfloat dz = 0.) {moveTo(QVector3D(dx, dy, dz)); buildTransform();} }
void moveX(GLfloat o) {trans.setTranslationX(posX() + o); buildTransform();} void moveTo(const QVector3D & dv) {
void moveY(GLfloat o) {trans.setTranslationY(posY() + o); buildTransform();} trans.setTranslation(dv);
void moveZ(GLfloat o) {trans.setTranslationZ(posZ() + o); buildTransform();} buildTransform();
void setPosX(GLfloat o) {trans.setTranslationX(o); buildTransform();} }
void setPosY(GLfloat o) {trans.setTranslationY(o); buildTransform();} void move(GLfloat dx, GLfloat dy, GLfloat dz = 0.) {
void setPosZ(GLfloat o) {trans.setTranslationZ(o); buildTransform();} move(QVector3D(dx, dy, dz));
void setPos(GLfloat x, GLfloat y, GLfloat z) {trans.setTranslation(QVector3D(x, y, z)); buildTransform();} buildTransform();
void setPos(const QVector3D & p) {trans.setTranslation(p); buildTransform();} }
void resetPos() {trans.setTranslation(QVector3D()); buildTransform();} void moveTo(GLfloat dx, GLfloat dy, GLfloat dz = 0.) {
moveTo(QVector3D(dx, dy, dz));
buildTransform();
}
void moveX(GLfloat o) {
trans.setTranslationX(posX() + o);
buildTransform();
}
void moveY(GLfloat o) {
trans.setTranslationY(posY() + o);
buildTransform();
}
void moveZ(GLfloat o) {
trans.setTranslationZ(posZ() + o);
buildTransform();
}
void setPosX(GLfloat o) {
trans.setTranslationX(o);
buildTransform();
}
void setPosY(GLfloat o) {
trans.setTranslationY(o);
buildTransform();
}
void setPosZ(GLfloat o) {
trans.setTranslationZ(o);
buildTransform();
}
void setPos(GLfloat x, GLfloat y, GLfloat z) {
trans.setTranslation(QVector3D(x, y, z));
buildTransform();
}
void setPos(const QVector3D & p) {
trans.setTranslation(p);
buildTransform();
}
void resetPos() {
trans.setTranslation(QVector3D());
buildTransform();
}
QVector3D pos() const { return trans.translation(); } QVector3D pos() const { return trans.translation(); }
float posX() const { return trans.translation().x(); } float posX() const { return trans.translation().x(); }
@@ -111,32 +160,108 @@ public:
float rotationX() const { return rotation().x(); } float rotationX() const { return rotation().x(); }
float rotationY() const { return rotation().y(); } float rotationY() const { return rotation().y(); }
float rotationZ() const { return rotation().z(); } float rotationZ() const { return rotation().z(); }
void rotateX(GLfloat a) {raw_matrix = false; trans.setRotationX(trans.rotationX() + a); buildTransform();} void rotateX(GLfloat a) {
void rotateY(GLfloat a) {raw_matrix = false; trans.setRotationY(trans.rotationY() + a); buildTransform();} raw_matrix = false;
trans.setRotationX(trans.rotationX() + a);
buildTransform();
}
void rotateY(GLfloat a) {
raw_matrix = false;
trans.setRotationY(trans.rotationY() + a);
buildTransform();
}
void rotateZ(GLfloat a); void rotateZ(GLfloat a);
void setRotationX(GLfloat a) {raw_matrix = false; trans.setRotationX(a); buildTransform();} void setRotationX(GLfloat a) {
void setRotationY(GLfloat a) {raw_matrix = false; trans.setRotationY(a); buildTransform();} raw_matrix = false;
trans.setRotationX(a);
buildTransform();
}
void setRotationY(GLfloat a) {
raw_matrix = false;
trans.setRotationY(a);
buildTransform();
}
void setRotationZ(GLfloat a); void setRotationZ(GLfloat a);
void setRotation(const QVector3D & a) {raw_matrix = false; trans.setRotation(a); buildTransform();} void setRotation(const QVector3D & a) {
void resetRotation() {raw_matrix = false; trans.setRotation(QVector3D()); buildTransform();} raw_matrix = false;
trans.setRotation(a);
buildTransform();
}
void resetRotation() {
raw_matrix = false;
trans.setRotation(QVector3D());
buildTransform();
}
QVector3D scale() { return trans.scale3D(); } QVector3D scale() { return trans.scale3D(); }
float scaleX() { return trans.scale3D().x(); } float scaleX() { return trans.scale3D().x(); }
float scaleY() { return trans.scale3D().y(); } float scaleY() { return trans.scale3D().y(); }
float scaleZ() { return trans.scale3D().z(); } float scaleZ() { return trans.scale3D().z(); }
void scale(const QVector3D & sv) {raw_matrix = false; trans.setScale(trans.scale3D() * sv); buildTransform();} void scale(const QVector3D & sv) {
void scale(GLfloat sx, GLfloat sy, GLfloat sz) {raw_matrix = false; scale(QVector3D(sx, sy, sz)); buildTransform();} raw_matrix = false;
void scale(GLfloat sx, GLfloat sy) {raw_matrix = false; scale(QVector3D(sx, sy, sy)); buildTransform();} trans.setScale(trans.scale3D() * sv);
void scale(GLfloat sx) {raw_matrix = false; scale(QVector3D(sx, sx, sx)); buildTransform();} buildTransform();
void scaleX(GLfloat a) {raw_matrix = false; trans.setScaleX(trans.scale3D().x() + a); buildTransform();} }
void scaleY(GLfloat a) {raw_matrix = false; trans.setScaleY(trans.scale3D().y() + a); buildTransform();} void scale(GLfloat sx, GLfloat sy, GLfloat sz) {
void scaleZ(GLfloat a) {raw_matrix = false; trans.setScaleZ(trans.scale3D().z() + a); buildTransform();} raw_matrix = false;
void setScale(const QVector3D & a) {raw_matrix = false; trans.setScale(a); buildTransform();} scale(QVector3D(sx, sy, sz));
void setScale(GLfloat a) {raw_matrix = false; trans.setScale(a); buildTransform();} buildTransform();
void setScaleX(GLfloat a) {raw_matrix = false; trans.setScaleX(a); buildTransform();} }
void setScaleY(GLfloat a) {raw_matrix = false; trans.setScaleY(a); buildTransform();} void scale(GLfloat sx, GLfloat sy) {
void setScaleZ(GLfloat a) {raw_matrix = false; trans.setScaleZ(a); buildTransform();} raw_matrix = false;
void resetScale() {raw_matrix = false; trans.setScale(1.f); buildTransform();} scale(QVector3D(sx, sy, sy));
buildTransform();
}
void scale(GLfloat sx) {
raw_matrix = false;
scale(QVector3D(sx, sx, sx));
buildTransform();
}
void scaleX(GLfloat a) {
raw_matrix = false;
trans.setScaleX(trans.scale3D().x() + a);
buildTransform();
}
void scaleY(GLfloat a) {
raw_matrix = false;
trans.setScaleY(trans.scale3D().y() + a);
buildTransform();
}
void scaleZ(GLfloat a) {
raw_matrix = false;
trans.setScaleZ(trans.scale3D().z() + a);
buildTransform();
}
void setScale(const QVector3D & a) {
raw_matrix = false;
trans.setScale(a);
buildTransform();
}
void setScale(GLfloat a) {
raw_matrix = false;
trans.setScale(a);
buildTransform();
}
void setScaleX(GLfloat a) {
raw_matrix = false;
trans.setScaleX(a);
buildTransform();
}
void setScaleY(GLfloat a) {
raw_matrix = false;
trans.setScaleY(a);
buildTransform();
}
void setScaleZ(GLfloat a) {
raw_matrix = false;
trans.setScaleZ(a);
buildTransform();
}
void resetScale() {
raw_matrix = false;
trans.setScale(1.f);
buildTransform();
}
Transform transform() { return trans; } Transform transform() { return trans; }
void setTransform(const Transform & t); void setTransform(const Transform & t);
@@ -220,7 +345,9 @@ protected:
QVariantMap meta; QVariantMap meta;
}; };
inline bool operator <(const ObjectBase & f, const ObjectBase & s) {return f.pos_h.z() < s.pos_h.z();} inline bool operator<(const ObjectBase & f, const ObjectBase & s) {
return f.pos_h.z() < s.pos_h.z();
}
class AimedObject: public ObjectBase { class AimedObject: public ObjectBase {
@@ -228,6 +355,7 @@ class AimedObject: public ObjectBase {
friend class GLRendererBase; friend class GLRendererBase;
friend class Light; friend class Light;
friend class Camera; friend class Camera;
public: public:
AimedObject(); AimedObject();
~AimedObject() {} ~AimedObject() {}
@@ -265,13 +393,21 @@ protected:
class Light: public AimedObject { class Light: public AimedObject {
friend class QGLView; friend class QGLView;
friend class RendererBase; friend class RendererBase;
public: public:
enum Type {Omni, Cone, Directional}; enum Type {
Omni,
Cone,
Directional
};
Light(); Light();
Light(const QVector3D & p, const QColor & c = Qt::white, float i = 1.); Light(const QVector3D & p, const QColor & c = Qt::white, float i = 1.);
virtual ObjectBase * clone(bool withChildren = true); virtual ObjectBase * clone(bool withChildren = true);
virtual void init() {shadow_map.resize(512, 512); is_init = true;} virtual void init() {
shadow_map.resize(512, 512);
is_init = true;
}
void apply(); void apply();
float angle_start; float angle_start;
@@ -288,16 +424,30 @@ public:
}; };
template<class T> template<class T>
inline T globject_cast(ObjectBase * object) {return reinterpret_cast<T>(object);} inline T globject_cast(ObjectBase * object) {
return reinterpret_cast<T>(object);
}
template<class T> template<class T>
inline T globject_cast(const ObjectBase * object) {return reinterpret_cast<T>(object);} inline T globject_cast(const ObjectBase * object) {
return reinterpret_cast<T>(object);
}
QDataStream & operator<<(QDataStream & s, const ObjectBase * p); QDataStream & operator<<(QDataStream & s, const ObjectBase * p);
QDataStream & operator>>(QDataStream & s, ObjectBase *& p); QDataStream & operator>>(QDataStream & s, ObjectBase *& p);
inline ObjectBaseList lights2objectList(const QList<Light*> & v) {ObjectBaseList ret; foreach (Light*i, v) ret << (ObjectBase*)i; return ret;} inline ObjectBaseList lights2objectList(const QList<Light *> & v) {
inline ObjectBaseList cameras2objectList(const QList<Camera*> & v) {ObjectBaseList ret; foreach (Camera*i, v) ret << (ObjectBase*)i; return ret;} ObjectBaseList ret;
foreach(Light * i, v)
ret << (ObjectBase *)i;
return ret;
}
inline ObjectBaseList cameras2objectList(const QList<Camera *> & v) {
ObjectBaseList ret;
foreach(Camera * i, v)
ret << (ObjectBase *)i;
return ret;
}
#endif // GLOBJECT_H #endif // GLOBJECT_H

View File

@@ -17,9 +17,11 @@
*/ */
#include "glscene.h" #include "glscene.h"
#include "glcamera.h" #include "glcamera.h"
#include "glmesh.h" #include "glmesh.h"
#include "qglview.h" #include "qglview.h"
#include <chunkstream.h> #include <chunkstream.h>
@@ -148,8 +150,7 @@ void Scene::emitSelectionChanged() {
foreach(ObjectBase * o, selected_) { foreach(ObjectBase * o, selected_) {
ObjectBase * po = o->selectedParent(); ObjectBase * po = o->selectedParent();
if (!po) po = o; if (!po) po = o;
if (!selected_top.contains(po)) if (!selected_top.contains(po)) selected_top << po;
selected_top << po;
} }
foreach(Mesh * m, geometries) foreach(Mesh * m, geometries)
m->setAllSelectionChanged(true); m->setAllSelectionChanged(true);
@@ -158,14 +159,14 @@ void Scene::emitSelectionChanged() {
QString Scene::uniqueName(QString n, const QSet<QString> & names) { QString Scene::uniqueName(QString n, const QSet<QString> & names) {
if (!names.contains(n)) if (!names.contains(n)) return n;
return n;
QString num; QString num;
while (!n.isEmpty()) { while (!n.isEmpty()) {
if (n.right(1)[0].isDigit()) { if (n.right(1)[0].isDigit()) {
num.push_front(n.right(1)); num.push_front(n.right(1));
n.chop(1); n.chop(1);
} else break; } else
break;
} }
if (!n.endsWith('_')) n += '_'; if (!n.endsWith('_')) n += '_';
int in = num.toInt() + 1; int in = num.toInt() + 1;
@@ -176,7 +177,6 @@ QString Scene::uniqueName(QString n, const QSet<QString> & names) {
} }
void Scene::removeObject(ObjectBase * o, bool inChildren) { void Scene::removeObject(ObjectBase * o, bool inChildren) {
if (destroying) return; if (destroying) return;
o->setScene(nullptr); o->setScene(nullptr);
@@ -208,8 +208,10 @@ void Scene::selectObject(ObjectBase * o, bool add_to_selection) {
// qDebug() << "selectObject" << o << add_to_selection; // qDebug() << "selectObject" << o << add_to_selection;
if (!add_to_selection || (sel_mode_ == smSingleSelection)) clearSelection(); if (!add_to_selection || (sel_mode_ == smSingleSelection)) clearSelection();
if (o) { if (o) {
if (!add_to_selection) o->setSelected(true); if (!add_to_selection)
else o->setSelected(!o->isSelected()); o->setSelected(true);
else
o->setSelected(!o->isSelected());
gatherSelection(); gatherSelection();
} }
emitSelectionChanged(); emitSelectionChanged();
@@ -231,12 +233,10 @@ void Scene::selectObjectsByMesh() {
ObjectBaseList csl = selected_; ObjectBaseList csl = selected_;
QSet<Mesh *> sml; QSet<Mesh *> sml;
foreach(ObjectBase * o, csl) foreach(ObjectBase * o, csl)
if (o->mesh()) if (o->mesh()) sml << o->mesh();
sml << o->mesh();
ObjectBaseList ol = root_->children(true); ObjectBaseList ol = root_->children(true);
foreach(ObjectBase * o, ol) { foreach(ObjectBase * o, ol) {
if (sml.contains(o->mesh())) if (sml.contains(o->mesh())) o->setSelected(true);
o->setSelected(true);
} }
gatherSelection(); gatherSelection();
emitSelectionChanged(); emitSelectionChanged();
@@ -247,12 +247,10 @@ void Scene::selectObjectsByMaterial() {
ObjectBaseList csl = selected_; ObjectBaseList csl = selected_;
QSet<Material *> sml; QSet<Material *> sml;
foreach(ObjectBase * o, csl) foreach(ObjectBase * o, csl)
if (o->material()) if (o->material()) sml << o->material();
sml << o->material();
ObjectBaseList ol = root_->children(true); ObjectBaseList ol = root_->children(true);
foreach(ObjectBase * o, ol) { foreach(ObjectBase * o, ol) {
if (sml.contains(o->material())) if (sml.contains(o->material())) o->setSelected(true);
o->setSelected(true);
} }
gatherSelection(); gatherSelection();
emitSelectionChanged(); emitSelectionChanged();
@@ -317,8 +315,7 @@ void Scene::removeMaterial(Material * m) {
if (!m || !materials.contains(m)) return; if (!m || !materials.contains(m)) return;
ObjectBaseList ol = root_->children(true); ObjectBaseList ol = root_->children(true);
foreach(ObjectBase * o, ol) foreach(ObjectBase * o, ol)
if (o->material_ == m) if (o->material_ == m) o->setMaterial(0);
o->setMaterial(0);
materials.removeAll(m); materials.removeAll(m);
changed_materials.removeAll(m); changed_materials.removeAll(m);
mat_changed = true; mat_changed = true;
@@ -356,8 +353,7 @@ void Scene::gatherSelection() {
selected_.clear(); selected_.clear();
ObjectBaseList ol = root_->children(true); ObjectBaseList ol = root_->children(true);
foreach(ObjectBase * o, ol) foreach(ObjectBase * o, ol)
if (o->isSelected()) if (o->isSelected()) selected_ << o;
selected_ << o;
} }
@@ -447,9 +443,7 @@ void Scene::prepareTree(ObjectBase * o) {
co->setObjectsChanged(); co->setObjectsChanged();
} }
break; break;
case ObjectBase::glCamera: case ObjectBase::glCamera: cameras_used << globject_cast<Camera *>(co); break;
cameras_used << globject_cast<Camera * >(co);
break;
default: break; default: break;
} }
prepareTree(co); prepareTree(co);
@@ -513,8 +507,7 @@ QDataStream & operator <<(QDataStream & s, const Scene * p) {
geom_ind << p->geometries.indexOf(c->mesh()); geom_ind << p->geometries.indexOf(c->mesh());
mat_ind << p->materials.indexOf(c->material()); mat_ind << p->materials.indexOf(c->material());
} }
cs.add(1, p->name_).add(10, p->geometries).add(11, p->materials) cs.add(1, p->name_).add(10, p->geometries).add(11, p->materials).add(20, p->root_).add(21, geom_ind).add(22, mat_ind);
.add(20, p->root_).add(21, geom_ind).add(22, mat_ind);
s << qCompress(cs.data()); s << qCompress(cs.data());
return s; return s;
} }
@@ -530,7 +523,10 @@ QDataStream & operator >>(QDataStream & s, Scene *& p) {
case 1: cs.get(p->name_); break; case 1: cs.get(p->name_); break;
case 10: cs.get(p->geometries); break; case 10: cs.get(p->geometries); break;
case 11: cs.get(p->materials); break; case 11: cs.get(p->materials); break;
case 20: cs.get(p->root_); p->root_->setScene(p); break; case 20:
cs.get(p->root_);
p->root_->setScene(p);
break;
case 21: cs.get(geom_ind); break; case 21: cs.get(geom_ind); break;
case 22: cs.get(mat_ind); break; case 22: cs.get(mat_ind); break;
} }

View File

@@ -33,6 +33,7 @@ class Scene: public QObject {
friend class Light; friend class Light;
friend QDataStream & operator<<(QDataStream & s, const Scene * p); friend QDataStream & operator<<(QDataStream & s, const Scene * p);
friend QDataStream & operator>>(QDataStream & s, Scene *& p); friend QDataStream & operator>>(QDataStream & s, Scene *& p);
public: public:
explicit Scene(); explicit Scene();
virtual ~Scene(); virtual ~Scene();

View File

@@ -17,6 +17,7 @@
*/ */
#include "gltexture_manager.h" #include "gltexture_manager.h"
#include "gltypes.h" #include "gltypes.h"
QStringList TextureManager::search_pathes("."); QStringList TextureManager::search_pathes(".");
@@ -115,9 +116,12 @@ void TextureManager::convertToNormal(QImage & im) {
const uchar * sd = sim.constBits(); const uchar * sd = sim.constBits();
for (int i = 0; i < sim.height(); i++) { for (int i = 0; i < sim.height(); i++) {
for (int j = 0; j < sim.width(); j++) { for (int j = 0; j < sim.width(); j++) {
sum[2] += sd[a] / 255.f - 0.5f; ++a; sum[2] += sd[a] / 255.f - 0.5f;
sum[1] += sd[a] / 255.f - 0.5f; ++a; ++a;
sum[0] += sd[a] / 255.f - 0.5f; ++a; sum[1] += sd[a] / 255.f - 0.5f;
++a;
sum[0] += sd[a] / 255.f - 0.5f;
++a;
++a; ++a;
} }
} }
@@ -152,10 +156,14 @@ void TextureManager::convertToNormal(QImage & im) {
res.setY(piClamp(0.5f + (p[0].length() - p[1].length()) / 2.f, 0.f, 1.f)); res.setY(piClamp(0.5f + (p[0].length() - p[1].length()) / 2.f, 0.f, 1.f));
res.setX(piClamp(0.5f - (p[0].length() - p[2].length()) / 2.f, 0.f, 1.f)); res.setX(piClamp(0.5f - (p[0].length() - p[2].length()) / 2.f, 0.f, 1.f));
res.setZ(1.f); res.setZ(1.f);
dd[a] = res.z() * 255; ++a; dd[a] = res.z() * 255;
dd[a] = res.y() * 255; ++a; ++a;
dd[a] = res.x() * 255; ++a; dd[a] = res.y() * 255;
dd[a] = 255; ++a; ++a;
dd[a] = res.x() * 255;
++a;
dd[a] = 255;
++a;
} }
} }
im = dim; im = dim;

View File

@@ -19,11 +19,11 @@
#ifndef GLTEXTUREMANAGER_H #ifndef GLTEXTUREMANAGER_H
#define GLTEXTUREMANAGER_H #define GLTEXTUREMANAGER_H
#include <QOpenGLExtraFunctions>
#include <QDir> #include <QDir>
#include <QMap>
#include <QFileInfo> #include <QFileInfo>
#include <QImage> #include <QImage>
#include <QMap>
#include <QOpenGLExtraFunctions>
class TextureManager { class TextureManager {
@@ -31,7 +31,9 @@ public:
TextureManager(QOpenGLExtraFunctions * f_): f(f_) {} TextureManager(QOpenGLExtraFunctions * f_): f(f_) {}
virtual ~TextureManager() {} virtual ~TextureManager() {}
static void addSearchPath(const QString & path) {if (!search_pathes.contains(path)) search_pathes << path;} static void addSearchPath(const QString & path) {
if (!search_pathes.contains(path)) search_pathes << path;
}
static void clearSearchPathes() { search_pathes.clear(); } static void clearSearchPathes() { search_pathes.clear(); }
static QStringList searchPathes() { return search_pathes; } static QStringList searchPathes() { return search_pathes; }
static QString findFile(const QString & path); static QString findFile(const QString & path);

View File

@@ -17,7 +17,9 @@
*/ */
#include "glwidget.h" #include "glwidget.h"
#include "qglview.h" #include "qglview.h"
#include <QVBoxLayout> #include <QVBoxLayout>
@@ -70,8 +72,7 @@ bool GLWidget::isMouseSelectionEnabled() const {
} }
bool GLWidget::isCameraOrbit() const bool GLWidget::isCameraOrbit() const {
{
return view_->isCameraOrbit(); return view_->isCameraOrbit();
} }

View File

@@ -26,8 +26,7 @@ class QGLView;
class ObjectBase; class ObjectBase;
class Scene; class Scene;
class GLWidget : public QWidget class GLWidget: public QWidget {
{
Q_OBJECT Q_OBJECT
Q_PROPERTY(qreal lineWidth READ lineWidth WRITE setLineWidth) Q_PROPERTY(qreal lineWidth READ lineWidth WRITE setLineWidth)
Q_PROPERTY(qreal FOV READ FOV WRITE setFOV) Q_PROPERTY(qreal FOV READ FOV WRITE setFOV)
@@ -42,6 +41,7 @@ class GLWidget : public QWidget
Q_PROPERTY(bool selectionHalo READ isSelectionHaloEnabled WRITE setSelectionHaloEnabled) Q_PROPERTY(bool selectionHalo READ isSelectionHaloEnabled WRITE setSelectionHaloEnabled)
Q_PROPERTY(QColor selectionHaloColor READ selectionHaloColor WRITE setSelectionHaloColor) Q_PROPERTY(QColor selectionHaloColor READ selectionHaloColor WRITE setSelectionHaloColor)
Q_PROPERTY(qreal selectionHaloFillAlpha READ selectionHaloFillAlpha WRITE setSelectionHaloFillAlpha) Q_PROPERTY(qreal selectionHaloFillAlpha READ selectionHaloFillAlpha WRITE setSelectionHaloFillAlpha)
public: public:
explicit GLWidget(QWidget * parent = nullptr); explicit GLWidget(QWidget * parent = nullptr);
QGLView * view() { return view_; } QGLView * view() { return view_; }

View File

@@ -17,11 +17,13 @@
*/ */
#include "mouse_controller.h" #include "mouse_controller.h"
#include "glmesh.h" #include "glmesh.h"
#include "qglview.h" #include "qglview.h"
#include <qad_types.h>
#include <QApplication> #include <QApplication>
#include <QKeyEvent> #include <QKeyEvent>
#include <qad_types.h>
using namespace QGLEngineShaders; using namespace QGLEngineShaders;
@@ -37,8 +39,7 @@ MouseController::MouseController(QGLView * view_): view(view_) {
} }
MouseController::~MouseController() { MouseController::~MouseController() {}
}
void MouseController::resize() { void MouseController::resize() {
@@ -67,8 +68,7 @@ void MouseController::mouseReleaseEvent(QMouseEvent * e) {
if (hov_objects.isEmpty() && hov_aims.isEmpty()) { if (hov_objects.isEmpty() && hov_aims.isEmpty()) {
view->scene()->clearSelection(); view->scene()->clearSelection();
} else { } else {
if (!hov_objects.isEmpty()) if (!hov_objects.isEmpty()) view->scene()->selectObject(hov_objects[0], add_ts);
view->scene()->selectObject(hov_objects[0], add_ts);
if (!hov_aims.isEmpty()) { if (!hov_aims.isEmpty()) {
view->scene()->selectObject(hov_aims[0], add_ts); view->scene()->selectObject(hov_aims[0], add_ts);
hov_aims[0]->setAimSelected(true); hov_aims[0]->setAimSelected(true);
@@ -135,7 +135,8 @@ void MouseController::mouseMoveEvent(QMouseEvent * e) {
} }
QVector<QVector3D> scales; QVector<QVector3D> scales;
foreach(int a, axis) { foreach(int a, axis) {
QVector3D axe_vector; axe_vector[a] = 1.; QVector3D axe_vector;
axe_vector[a] = 1.;
QMatrix4x4 axis_mat = view->camera()->fullViewMatrix() * rs.axis_mat; QMatrix4x4 axis_mat = view->camera()->fullViewMatrix() * rs.axis_mat;
QVector3D center_screen = axis_mat.map(rs.selection_center); QVector3D center_screen = axis_mat.map(rs.selection_center);
QVector3D axe_screen = (axis_mat.map(rs.selection_center + axe_vector) - center_screen).normalized(); QVector3D axe_screen = (axis_mat.map(rs.selection_center + axe_vector) - center_screen).normalized();
@@ -149,8 +150,7 @@ void MouseController::mouseMoveEvent(QMouseEvent * e) {
QMatrix4x4 pmat; QMatrix4x4 pmat;
foreach(ObjectBase * o, objects) { foreach(ObjectBase * o, objects) {
pmat.setToIdentity(); pmat.setToIdentity();
if (o->parent()) if (o->parent()) pmat = o->parent()->worldTransform().inverted();
pmat = o->parent()->worldTransform().inverted();
QVector3D dv = pmat.mapVector(axe_vector); QVector3D dv = pmat.mapVector(axe_vector);
if (o->isAimSelected()) { if (o->isAimSelected()) {
AimedObject * ao = (AimedObject *)o; AimedObject * ao = (AimedObject *)o;
@@ -251,8 +251,7 @@ void MouseController::mouseMoveEvent(QMouseEvent * e) {
cs = Qt::SplitHCursor; cs = Qt::SplitHCursor;
} }
} }
if (cur_action == RendererService::haNoAction) if (cur_action == RendererService::haNoAction) cur_handle = QFlags<RendererService::HandleMesh>();
cur_handle = QFlags<RendererService::HandleMesh>();
view->setCursor(cs); view->setCursor(cs);
view->renderer_.rend_service.current_handle = cur_handle; view->renderer_.rend_service.current_handle = cur_handle;
} }
@@ -305,6 +304,5 @@ void MouseController::leaveEvent(QEvent * ) {
void MouseController::mouseDoubleClickEvent(QMouseEvent * e) { void MouseController::mouseDoubleClickEvent(QMouseEvent * e) {
if (e->buttons().testFlag(QT_MID_BUTTON)) if (e->buttons().testFlag(QT_MID_BUTTON)) emit view->doubleClick();
emit view->doubleClick();
} }

View File

@@ -19,18 +19,19 @@
#ifndef MOUSE_CONTROLLER_H #ifndef MOUSE_CONTROLLER_H
#define MOUSE_CONTROLLER_H #define MOUSE_CONTROLLER_H
#include "glprimitives.h"
#include "glcamera.h" #include "glcamera.h"
#include "glprimitives.h"
#include "renderer_service.h" #include "renderer_service.h"
#include <QMouseEvent> #include <QMouseEvent>
#include <QTime> #include <QTime>
class MouseController: public QObject class MouseController: public QObject {
{
friend class QGLView; friend class QGLView;
friend class RendererSelection; friend class RendererSelection;
Q_OBJECT Q_OBJECT
public: public:
MouseController(QGLView * view_); MouseController(QGLView * view_);
virtual ~MouseController(); virtual ~MouseController();
@@ -71,14 +72,16 @@ private:
private slots: private slots:
public slots: public slots:
void setGrabMouseEnabled(const bool & arg) {grabMouse_ = arg; mouse_first = true;} void setGrabMouseEnabled(const bool & arg) {
grabMouse_ = arg;
mouse_first = true;
}
void setMouseRotateEnabled(const bool & arg) { mouseRotate_ = arg; } void setMouseRotateEnabled(const bool & arg) { mouseRotate_ = arg; }
void setMouseSelectionEnabled(const bool & arg) { mouseSelect_ = arg; } void setMouseSelectionEnabled(const bool & arg) { mouseSelect_ = arg; }
void setCustomMouseMove(const bool & arg) { customMouseMove_ = arg; } void setCustomMouseMove(const bool & arg) { customMouseMove_ = arg; }
void setCameraOrbit(const bool & arg) { cameraOrbit_ = arg; } void setCameraOrbit(const bool & arg) { cameraOrbit_ = arg; }
signals: signals:
}; };
#endif // QGLVIEW_H #endif // QGLVIEW_H

View File

@@ -1,4 +1,5 @@
#include "openglwindow.h" #include "openglwindow.h"
#include <QCoreApplication> #include <QCoreApplication>
#include <QOpenGLContext> #include <QOpenGLContext>
#include <QOpenGLPaintDevice> #include <QOpenGLPaintDevice>
@@ -31,11 +32,8 @@ void OpenGLWindow::renderLater() {
bool OpenGLWindow::event(QEvent * event) { bool OpenGLWindow::event(QEvent * event) {
switch (event->type()) { switch (event->type()) {
case QEvent::UpdateRequest: case QEvent::UpdateRequest: renderNow(); return true;
renderNow(); default: return QWindow::event(event);
return true;
default:
return QWindow::event(event);
} }
} }
@@ -103,4 +101,3 @@ void OpenGLWindow::renderNow() {
m_context->swapBuffers(this); m_context->swapBuffers(this);
frame_cnt++; frame_cnt++;
} }

View File

@@ -1,13 +1,16 @@
#include <QWindow>
#include <QOpenGLExtraFunctions> #include <QOpenGLExtraFunctions>
#include <QWindow>
class QPainter; class QPainter;
class QOpenGLContext; class QOpenGLContext;
class QOpenGLPaintDevice; class QOpenGLPaintDevice;
class OpenGLWindow : public QWindow, public QOpenGLExtraFunctions { class OpenGLWindow
: public QWindow
, public QOpenGLExtraFunctions {
Q_OBJECT Q_OBJECT
public: public:
explicit OpenGLWindow(QWindow * parent = nullptr); explicit OpenGLWindow(QWindow * parent = nullptr);
virtual ~OpenGLWindow() {} virtual ~OpenGLWindow() {}
@@ -35,4 +38,3 @@ private:
bool format_change = false; bool format_change = false;
int frame_cnt = 0; int frame_cnt = 0;
}; };

View File

@@ -1,9 +1,9 @@
#include "qglview_designerplugin.h" #include "qglview_designerplugin.h"
#include "qglviewplugin.h" #include "qglviewplugin.h"
QGLViewDesignerPlugin::QGLViewDesignerPlugin(QObject * parent): QObject(parent) QGLViewDesignerPlugin::QGLViewDesignerPlugin(QObject * parent): QObject(parent) {
{
m_widgets.append(new QGLViewPlugin(this)); m_widgets.append(new QGLViewPlugin(this));
} }
@@ -11,4 +11,3 @@ QGLViewDesignerPlugin::QGLViewDesignerPlugin(QObject * parent): QObject(parent)
QList<QDesignerCustomWidgetInterface *> QGLViewDesignerPlugin::customWidgets() const { QList<QDesignerCustomWidgetInterface *> QGLViewDesignerPlugin::customWidgets() const {
return m_widgets; return m_widgets;
} }

View File

@@ -1,22 +1,23 @@
#ifndef QGLVIEW_DESIGNERPLUGIN_H #ifndef QGLVIEW_DESIGNERPLUGIN_H
#define QGLVIEW_DESIGNERPLUGIN_H #define QGLVIEW_DESIGNERPLUGIN_H
#include <QtDesigner/QtDesigner>
#include <QtCore/qplugin.h> #include <QtCore/qplugin.h>
#include <QtDesigner/QtDesigner>
class QGLViewDesignerPlugin: public QObject, public QDesignerCustomWidgetCollectionInterface class QGLViewDesignerPlugin
{ : public QObject
, public QDesignerCustomWidgetCollectionInterface {
Q_OBJECT Q_OBJECT
Q_PLUGIN_METADATA(IID "qad.qglview") Q_PLUGIN_METADATA(IID "qad.qglview")
Q_INTERFACES(QDesignerCustomWidgetCollectionInterface) Q_INTERFACES(QDesignerCustomWidgetCollectionInterface)
public: public:
QGLViewDesignerPlugin(QObject * parent = 0); QGLViewDesignerPlugin(QObject * parent = 0);
virtual QList<QDesignerCustomWidgetInterface *> customWidgets() const; virtual QList<QDesignerCustomWidgetInterface *> customWidgets() const;
private: private:
QList<QDesignerCustomWidgetInterface *> m_widgets; QList<QDesignerCustomWidgetInterface *> m_widgets;
}; };
#endif // QGLVIEW_DESIGNERPLUGIN_H #endif // QGLVIEW_DESIGNERPLUGIN_H

View File

@@ -1,9 +1,11 @@
#include "../glwidget.h"
#include "qglviewplugin.h" #include "qglviewplugin.h"
#include <QtCore/QtPlugin>
#include "../glwidget.h"
#include "glprimitives.h" #include "glprimitives.h"
#include "qglview.h" #include "qglview.h"
#include <QtCore/QtPlugin>
QGLViewPlugin::QGLViewPlugin(QObject * parent): QObject(parent) { QGLViewPlugin::QGLViewPlugin(QObject * parent): QObject(parent) {
m_initialized = false; m_initialized = false;
@@ -11,8 +13,7 @@ QGLViewPlugin::QGLViewPlugin(QObject * parent): QObject(parent) {
void QGLViewPlugin::initialize(QDesignerFormEditorInterface * /* core */) { void QGLViewPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
if (m_initialized) if (m_initialized) return;
return;
// Add extension registrations, etc. here // Add extension registrations, etc. here
@@ -32,15 +33,18 @@ QWidget * QGLViewPlugin::createWidget(QWidget * parent) {
GLObjectBase * obj; GLObjectBase * obj;
float al = 1.; float al = 1.;
obj = new GLPrimitiveLine(QVector3D(0, 0, -al), QVector3D(0, 0, al)); obj = new GLPrimitiveLine(QVector3D(0, 0, -al), QVector3D(0, 0, al));
obj->material().color_diffuse = Qt::darkBlue; obj->setAcceptLight(false); obj->material().color_diffuse = Qt::darkBlue;
obj->setAcceptLight(false);
obj->setSelectable(false); obj->setSelectable(false);
axis->addChild(obj); axis->addChild(obj);
obj = new GLPrimitiveLine(QVector3D(-al, 0, 0), QVector3D(al, 0, 0)); obj = new GLPrimitiveLine(QVector3D(-al, 0, 0), QVector3D(al, 0, 0));
obj->material().color_diffuse = Qt::darkRed; obj->setAcceptLight(false); obj->material().color_diffuse = Qt::darkRed;
obj->setAcceptLight(false);
obj->setSelectable(false); obj->setSelectable(false);
axis->addChild(obj); axis->addChild(obj);
obj = new GLPrimitiveLine(QVector3D(0, -al, 0), QVector3D(0, al, 0)); obj = new GLPrimitiveLine(QVector3D(0, -al, 0), QVector3D(0, al, 0));
obj->material().color_diffuse = Qt::darkGreen; obj->setAcceptLight(false); obj->material().color_diffuse = Qt::darkGreen;
obj->setAcceptLight(false);
obj->setSelectable(false); obj->setSelectable(false);
axis->addChild(obj); axis->addChild(obj);
w->view()->addObject(axis); w->view()->addObject(axis);
@@ -92,4 +96,3 @@ QString QGLViewPlugin::domXml() const {
QString QGLViewPlugin::includeFile() const { QString QGLViewPlugin::includeFile() const {
return QLatin1String("glwidget.h"); return QLatin1String("glwidget.h");
} }

View File

@@ -5,8 +5,9 @@
#include <QtUiPlugin/QDesignerCustomWidgetInterface> #include <QtUiPlugin/QDesignerCustomWidgetInterface>
class QGLViewPlugin: public QObject, public QDesignerCustomWidgetInterface class QGLViewPlugin
{ : public QObject
, public QDesignerCustomWidgetInterface {
Q_OBJECT Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface) Q_INTERFACES(QDesignerCustomWidgetInterface)
@@ -27,7 +28,6 @@ public:
private: private:
bool m_initialized; bool m_initialized;
}; };
#endif // QGLVIEWPLUGIN_H #endif // QGLVIEWPLUGIN_H

View File

@@ -17,13 +17,15 @@
*/ */
#include "qglview.h" #include "qglview.h"
#include "glmesh.h" #include "glmesh.h"
#include "gltexture_manager.h" #include "gltexture_manager.h"
#include <QApplication>
#include <QKeyEvent>
#include <QOpenGLTexture>
#include <chunkstream.h> #include <chunkstream.h>
#include <qad_types.h> #include <qad_types.h>
#include <QApplication>
#include <QOpenGLTexture>
#include <QKeyEvent>
using namespace QGLEngineShaders; using namespace QGLEngineShaders;
@@ -116,8 +118,7 @@ QList<Light * > QGLView::selectedLights() const {
QList<Light *> ret; QList<Light *> ret;
ObjectBaseList sol = scene_->selectedObjects(); ObjectBaseList sol = scene_->selectedObjects();
foreach(ObjectBase * o, sol) foreach(ObjectBase * o, sol)
if (o->type() == ObjectBase::glLight) if (o->type() == ObjectBase::glLight) ret << (Light *)o;
ret << (Light*)o;
return ret; return ret;
} }
@@ -132,7 +133,6 @@ QList<Camera * > QGLView::selectedCameras() const {
} }
void QGLView::resizeEvent(QResizeEvent * e) { void QGLView::resizeEvent(QResizeEvent * e) {
renderLater(); renderLater();
mouse.resize(); mouse.resize();

View File

@@ -19,19 +19,19 @@
#ifndef QGLVIEW_H #ifndef QGLVIEW_H
#define QGLVIEW_H #define QGLVIEW_H
#include "openglwindow.h" #include "glcamera.h"
#include "glframebuffer.h" #include "glframebuffer.h"
#include "glprimitives.h" #include "glprimitives.h"
#include "glcamera.h"
#include "glscene.h" #include "glscene.h"
#include "renderer.h"
#include "mouse_controller.h" #include "mouse_controller.h"
#include "openglwindow.h"
#include "renderer.h"
#include <QElapsedTimer> #include <QElapsedTimer>
#include <QMenu> #include <QMenu>
class QGLView: public OpenGLWindow class QGLView: public OpenGLWindow {
{
friend class RendererSelection; friend class RendererSelection;
Q_OBJECT Q_OBJECT
Q_PROPERTY(float lineWidth READ lineWidth WRITE setLineWidth) Q_PROPERTY(float lineWidth READ lineWidth WRITE setLineWidth)
@@ -126,7 +126,11 @@ public:
float selectionHaloFillAlpha() const { return selectionHaloFill_; } float selectionHaloFillAlpha() const { return selectionHaloFill_; }
QVariant feature(Feature f) const { return features_.value(int(f)); } QVariant feature(Feature f) const { return features_.value(int(f)); }
QVariant setFeature(Feature f, const QVariant & value) {QVariant ret = features_.value(int(f)); features_[int(f)] = value; return ret;} QVariant setFeature(Feature f, const QVariant & value) {
QVariant ret = features_.value(int(f));
features_[int(f)] = value;
return ret;
}
bool isFeatureEnabled(Feature f) const { return features_[int(f)].toBool(); } bool isFeatureEnabled(Feature f) const { return features_[int(f)].toBool(); }
int renderMode() const { return (int)rmode; } int renderMode() const { return (int)rmode; }
@@ -171,7 +175,10 @@ public:
QImage materialThumbnail(Material * m) { return renderer_.materialThumbnail(m); } QImage materialThumbnail(Material * m) { return renderer_.materialThumbnail(m); }
void setCurrentAction(RendererService::HandleAction ha) { renderer_.rend_service.setCurrentAction(ha); } void setCurrentAction(RendererService::HandleAction ha) { renderer_.rend_service.setCurrentAction(ha); }
void setContextActions(QList<QAction*> al) {context_menu.clear(); context_menu.addActions(al);} void setContextActions(QList<QAction *> al) {
context_menu.clear();
context_menu.addActions(al);
}
void popupMenu(const QPoint & pos, QAction * at = nullptr) { context_menu.popup(pos, at); } void popupMenu(const QPoint & pos, QAction * at = nullptr) { context_menu.popup(pos, at); }
void setGrabImage(bool on) { renderer_.setGrabImage(on); } void setGrabImage(bool on) { renderer_.setGrabImage(on); }
bool isGrabImage() const { return renderer_.isGrabImage(); } bool isGrabImage() const { return renderer_.isGrabImage(); }
@@ -234,7 +241,10 @@ public slots:
void setDepthStart(const float & arg) { camera()->setDepthStart(arg); } void setDepthStart(const float & arg) { camera()->setDepthStart(arg); }
void setGamma(const float & arg) { renderer_.gamma_ = arg; } void setGamma(const float & arg) { renderer_.gamma_ = arg; }
void setAutoExposure(bool arg) { renderer_.tone_proc.enabled = arg; } void setAutoExposure(bool arg) { renderer_.tone_proc.enabled = arg; }
void setEnvironmentMapFile(QString file) {renderer_.tex_env.setFileHDR(file); renderer_.recreateMaterialThumbnails(true);} void setEnvironmentMapFile(QString file) {
renderer_.tex_env.setFileHDR(file);
renderer_.recreateMaterialThumbnails(true);
}
void setFogColor(const QColor & arg) { fogColor_ = arg; } void setFogColor(const QColor & arg) { fogColor_ = arg; }
void setFogDensity(const float & arg) { fogDensity_ = arg; } void setFogDensity(const float & arg) { fogDensity_ = arg; }
void setFogDecay(const float & arg) { fogDecay_ = arg; } void setFogDecay(const float & arg) { fogDecay_ = arg; }

View File

@@ -16,10 +16,11 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "qglview_window.h"
#include <QApplication> #include <QApplication>
#include <QDebug> #include <QDebug>
#include <QDir> #include <QDir>
#include "qglview_window.h"
int main(int argc, char ** argv) { int main(int argc, char ** argv) {
QApplication a(argc, argv); QApplication a(argc, argv);

View File

@@ -17,13 +17,15 @@
*/ */
#include "qglview_window.h" #include "qglview_window.h"
#include "renderer.h"
#include "glwidget.h"
#include "gltexture_manager.h" #include "gltexture_manager.h"
#include "glwidget.h"
#include "qad_types.h"
#include "renderer.h"
#include <QGraphicsRectItem> #include <QGraphicsRectItem>
#include <QImageReader> #include <QImageReader>
#include <QMessageBox> #include <QMessageBox>
#include "qad_types.h"
QGLViewWindow::QGLViewWindow(QWidget * parent): QMainWindow(parent), Ui::QGLViewWindow() { QGLViewWindow::QGLViewWindow(QWidget * parent): QMainWindow(parent), Ui::QGLViewWindow() {
@@ -123,15 +125,18 @@ void QGLViewWindow::loadFile(const QString & path, bool import) {
QApplication::setOverrideCursor(Qt::WaitCursor); QApplication::setOverrideCursor(Qt::WaitCursor);
QFileInfo fi(path); QFileInfo fi(path);
Scene * s = nullptr; Scene * s = nullptr;
if (fi.suffix().toLower() == "qgl") s = loadFromQGLFile(path); if (fi.suffix().toLower() == "qgl")
else s = loadScene(path); s = loadFromQGLFile(path);
else
s = loadScene(path);
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
if (!s) { if (!s) {
QMessageBox::critical(this, "Import", "Can`t load " + path + "!"); QMessageBox::critical(this, "Import", "Can`t load " + path + "!");
return; return;
} }
s->setName(fi.baseName()); s->setName(fi.baseName());
if (import) view->scene()->addScene(s); if (import)
view->scene()->addScene(s);
else { else {
TextureManager::clearSearchPathes(); TextureManager::clearSearchPathes();
view->scene()->assignFrom(s); view->scene()->assignFrom(s);
@@ -161,8 +166,7 @@ void QGLViewWindow::on_actionImport_triggered() {
void QGLViewWindow::on_actionSave_triggered() { void QGLViewWindow::on_actionSave_triggered() {
QString f = QFileDialog::getSaveFileName(this, "Select file", prev_path, "QGLView(*.qgl)"); QString f = QFileDialog::getSaveFileName(this, "Select file", prev_path, "QGLView(*.qgl)");
if (f.isEmpty()) return; if (f.isEmpty()) return;
if (f.right(4).toLower() != ".qgl") if (f.right(4).toLower() != ".qgl") f += ".qgl";
f += ".qgl";
prev_path = f; prev_path = f;
QApplication::setOverrideCursor(Qt::WaitCursor); QApplication::setOverrideCursor(Qt::WaitCursor);
saveToQGLFile(f, view->scene()); saveToQGLFile(f, view->scene());
@@ -175,8 +179,7 @@ void QGLViewWindow::on_actionSaveSelected_triggered() {
if (!sel_obj) return; if (!sel_obj) return;
QString f = QFileDialog::getSaveFileName(this, "Select file", prev_path, "QGLView(*.qgl)"); QString f = QFileDialog::getSaveFileName(this, "Select file", prev_path, "QGLView(*.qgl)");
if (f.isEmpty()) return; if (f.isEmpty()) return;
if (f.right(4).toLower() != ".qgl") if (f.right(4).toLower() != ".qgl") f += ".qgl";
f += ".qgl";
prev_path = f; prev_path = f;
QApplication::setOverrideCursor(Qt::WaitCursor); QApplication::setOverrideCursor(Qt::WaitCursor);
/// saveToQGLFile(f, sel_obj); /// saveToQGLFile(f, sel_obj);
@@ -195,8 +198,7 @@ void QGLViewWindow::on_actionOpen_triggered() {
void QGLViewWindow::view_keyEvent(Qt::Key k, Qt::KeyboardModifiers m) { void QGLViewWindow::view_keyEvent(Qt::Key k, Qt::KeyboardModifiers m) {
// qDebug() << k; // qDebug() << k;
double spd = 0.2; double spd = 0.2;
if (m.testFlag(Qt::ShiftModifier)) if (m.testFlag(Qt::ShiftModifier)) spd = 0.5;
spd = 0.5;
switch (k) { switch (k) {
case Qt::Key_W: view->view()->camera()->moveForward(spd); break; case Qt::Key_W: view->view()->camera()->moveForward(spd); break;
case Qt::Key_S: view->view()->camera()->moveBackward(spd); break; case Qt::Key_S: view->view()->camera()->moveBackward(spd); break;

View File

@@ -19,29 +19,32 @@
#ifndef QGLVIEWWINDOW_H #ifndef QGLVIEWWINDOW_H
#define QGLVIEWWINDOW_H #define QGLVIEWWINDOW_H
#include <QTranslator> #include "formats/loader_assimp.h"
#include <QInputDialog> #include "formats/loader_qgl.h"
#include <QFileDialog> #include "session_manager.h"
#include <QColorDialog> #include "ui_qglview_window.h"
#include <QCloseEvent>
#include <QClipboard> #include <QClipboard>
#include <QCloseEvent>
#include <QColorDialog>
#include <QFileDialog>
#include <QInputDialog>
#include <QRadioButton> #include <QRadioButton>
#include <QUrl> #include <QSplitter>
#include <QThread> #include <QThread>
#include <QTime> #include <QTime>
#include <QSplitter> #include <QTranslator>
#include "ui_qglview_window.h" #include <QUrl>
#include "formats/loader_qgl.h"
#include "formats/loader_assimp.h"
#include "session_manager.h"
// #include "renderer_rt.h" // #include "renderer_rt.h"
#include "qglview.h" #include "qglview.h"
#include "ui_qglview_window.h" #include "ui_qglview_window.h"
class QGLViewWindow: public QMainWindow, public Ui::QGLViewWindow class QGLViewWindow
{ : public QMainWindow
, public Ui::QGLViewWindow {
Q_OBJECT Q_OBJECT
public: public:
QGLViewWindow(QWidget * parent = 0); QGLViewWindow(QWidget * parent = 0);
~QGLViewWindow(); ~QGLViewWindow();
@@ -113,7 +116,6 @@ signals:
private: private:
QMatrix4x4 cam_mat; QMatrix4x4 cam_mat;
}; };
#endif // QGLVIEWWINDOW_H #endif // QGLVIEWWINDOW_H

View File

@@ -17,22 +17,29 @@
*/ */
#define GL_GLEXT_PROTOTYPES #define GL_GLEXT_PROTOTYPES
#include "renderer.h"
#include "glmesh.h"
#include "glshaders.h"
#include "gltexture_manager.h"
#include "qglview.h"
#include <QOpenGLExtraFunctions> #include <QOpenGLExtraFunctions>
#include <qad_types.h> #include <qad_types.h>
#include "renderer.h"
#include "qglview.h"
#include "glmesh.h"
#include "gltexture_manager.h"
#include "glshaders.h"
using namespace QGLEngineShaders; using namespace QGLEngineShaders;
Renderer::Renderer(QGLView * view_): RendererBase(view_), Renderer::Renderer(QGLView * view_)
fbo_ds (view_, QVector<GLenum>() << GL_RGBA16F << GL_RGBA32F << GL_RGBA16F << GL_RGBA16F << GL_RGBA16F), : RendererBase(view_)
fbo_out (view_, obrBuffersCount, false, GL_RGBA16F), , fbo_ds(view_, QVector<GLenum>() << GL_RGBA16F << GL_RGBA32F << GL_RGBA16F << GL_RGBA16F << GL_RGBA16F)
rend_mat(this), rend_service(this), rend_selection(this), tone_proc(this), tex_env(view_, 512) { , fbo_out(view_, obrBuffersCount, false, GL_RGBA16F)
, rend_mat(this)
, rend_service(this)
, rend_selection(this)
, tone_proc(this)
, tex_env(view_, 512) {
quad = Primitive::plane(2., 2.); quad = Primitive::plane(2., 2.);
cam_light = new Light(); cam_light = new Light();
cam_light->intensity = 0.75; cam_light->intensity = 0.75;
@@ -49,7 +56,8 @@ Renderer::Renderer(QGLView * view_): RendererBase(view_),
shader_files[srGeometryPass] = "ds_geom.glsl"; shader_files[srGeometryPass] = "ds_geom.glsl";
shader_files[srLightOmniPass] = "ds_light.glsl"; shader_files[srLightOmniPass] = "ds_light.glsl";
shader_files[srLightSpotPass] = "ds_light.glsl"; shader_defines[srLightSpotPass] << "SPOT"; shader_files[srLightSpotPass] = "ds_light.glsl";
shader_defines[srLightSpotPass] << "SPOT";
shader_files[srFinalPass] = "ds_final.glsl"; shader_files[srFinalPass] = "ds_final.glsl";
shader_files[srTonemapPass] = "ds_tonemap.glsl"; shader_files[srTonemapPass] = "ds_tonemap.glsl";
@@ -115,7 +123,9 @@ void Renderer::reloadShaders() {
} }
loadShadersMulti(tone_proc.shader_sum, dir + "sum.glsl", false); loadShadersMulti(tone_proc.shader_sum, dir + "sum.glsl", false);
QStringList fxaa_defs; QStringList fxaa_defs;
fxaa_defs << "FXAA_PC 1" << "FXAA_GLSL_130 1" << "FXAA_QUALITY__PRESET 15"; fxaa_defs << "FXAA_PC 1"
<< "FXAA_GLSL_130 1"
<< "FXAA_QUALITY__PRESET 15";
loadShaders(shader_fxaa, QStringList() << (dir + "fxaa.vert") << (dir + "fxaa.frag"), true, fxaa_defs); loadShaders(shader_fxaa, QStringList() << (dir + "fxaa.vert") << (dir + "fxaa.frag"), true, fxaa_defs);
need_init_shaders = true; need_init_shaders = true;
view->scene()->setLightsChanged(); view->scene()->setLightsChanged();
@@ -200,7 +210,6 @@ void Renderer::fillObjectsBuffer(const ObjectBaseList & ol, RenderPass pass) {
// qDebug() << "load obj" << o->name() << o->worldTransform(); // qDebug() << "load obj" << o->name() << o->worldTransform();
} }
// qDebug() << "fillObjectsBuffer" << ol.size(); // qDebug() << "fillObjectsBuffer" << ol.size();
} }
@@ -279,8 +288,7 @@ void Renderer::renderScene() {
if (scene_changed || scene.need_reload_materials) { if (scene_changed || scene.need_reload_materials) {
rend_selection.generateObjectsID(scene); rend_selection.generateObjectsID(scene);
reloadMaterials(scene); reloadMaterials(scene);
if (edit_mode) if (edit_mode) recreateMaterialThumbnails();
recreateMaterialThumbnails();
emit view->materialsChanged(); emit view->materialsChanged();
} }

View File

@@ -19,12 +19,13 @@
#ifndef RENDERER_H #ifndef RENDERER_H
#define RENDERER_H #define RENDERER_H
#include "glcubemap.h"
#include "renderer_base.h" #include "renderer_base.h"
#include "renderer_material.h" #include "renderer_material.h"
#include "renderer_service.h"
#include "renderer_selection.h" #include "renderer_selection.h"
#include "renderer_service.h"
#include "tonemapping_proc.h" #include "tonemapping_proc.h"
#include "glcubemap.h"
#include <QQueue> #include <QQueue>

View File

@@ -17,30 +17,30 @@
*/ */
#define GL_GLEXT_PROTOTYPES #define GL_GLEXT_PROTOTYPES
#include <QOpenGLExtraFunctions>
#include "renderer_base.h" #include "renderer_base.h"
#include "renderer.h"
#include "qglview.h"
#include "glmesh.h" #include "glmesh.h"
#include "gltexture_manager.h"
#include "glshaders_headers.h" #include "glshaders_headers.h"
#include "gltexture_manager.h"
#include "qglview.h"
#include "renderer.h"
#include <QOpenGLExtraFunctions>
using namespace QGLEngineShaders; using namespace QGLEngineShaders;
RendererBase::RendererBase(QGLView * view_): RendererBase::RendererBase(QGLView * view_)
view(view_), : view(view_)
buffer_materials (GL_UNIFORM_BUFFER, GL_STREAM_DRAW), , buffer_materials(GL_UNIFORM_BUFFER, GL_STREAM_DRAW)
buffer_lights (GL_UNIFORM_BUFFER, GL_STREAM_DRAW), , buffer_lights(GL_UNIFORM_BUFFER, GL_STREAM_DRAW)
buffer_lights_pos(GL_UNIFORM_BUFFER, GL_STREAM_DRAW), , buffer_lights_pos(GL_UNIFORM_BUFFER, GL_STREAM_DRAW)
textures_empty(false), , textures_empty(false)
textures_maps(true) , textures_maps(true) {
{
textures_manager = new TextureManager(view); textures_manager = new TextureManager(view);
maps_size = QSize(512, 512); maps_size = QSize(512, 512);
maps_hash = 0; maps_hash = 0;
tex_coeff[0] = tex_coeff[1] = 0; tex_coeff[0] = tex_coeff[1] = 0;
} }
@@ -212,7 +212,6 @@ void RendererBase::reloadMaterials(Scene & scene) {
buffer_materials.resize(view, cur_materials_.size() * sizeof(QGLMaterial)); buffer_materials.resize(view, cur_materials_.size() * sizeof(QGLMaterial));
buffer_materials.load(view, cur_materials_.constData(), cur_materials_.size() * sizeof(QGLMaterial)); buffer_materials.load(view, cur_materials_.constData(), cur_materials_.size() * sizeof(QGLMaterial));
scene.need_reload_materials = false; scene.need_reload_materials = false;
} }
@@ -232,8 +231,7 @@ void RendererBase::reloadLightsParameters(const QMap<int, QList<Light*>> & light
QGLLightParameter & so(cur_lights_params_[i]); QGLLightParameter & so(cur_lights_params_[i]);
Light * l = current_lights[i]; Light * l = current_lights[i];
double ang_start = l->angle_start / 2.f, ang_end = l->angle_end / 2.f; double ang_start = l->angle_start / 2.f, ang_end = l->angle_end / 2.f;
if (l->light_type == Light::Omni) if (l->light_type == Light::Omni) ang_start = ang_end = 180.;
ang_start = ang_end = 180.;
// qDebug() << "light" << light->name() << ulightn << pos; // qDebug() << "light" << light->name() << ulightn << pos;
so.color = QColor2QVector(l->color_); so.color = QColor2QVector(l->color_);
so.angles[0] = ang_start; so.angles[0] = ang_start;
@@ -293,8 +291,7 @@ void RendererBase::initQuad(Mesh * mesh, QMatrix4x4 mat) {
void RendererBase::renderQuad(QOpenGLShaderProgram * prog, Mesh * mesh, Camera * cam, bool uniforms) { void RendererBase::renderQuad(QOpenGLShaderProgram * prog, Mesh * mesh, Camera * cam, bool uniforms) {
glDisableDepth(); glDisableDepth();
if (uniforms) if (uniforms) setUniformCamera(prog, cam, false);
setUniformCamera(prog, cam, false);
mesh->draw(view, 1); mesh->draw(view, 1);
} }
@@ -408,8 +405,17 @@ void RendererBase::createCoeffTexture(GLuint & id, const void * data, int size,
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
GLenum iformat = GL_R16F, format = GL_RED; GLenum iformat = GL_R16F, format = GL_RED;
if (channels == 2) {iformat = GL_RG16F; format = GL_RG;} if (channels == 2) {
if (channels == 3) {iformat = GL_RGB16F; format = GL_RGB;} iformat = GL_RG16F;
if (channels == 4) {iformat = GL_RGBA16F; format = GL_RGBA;} format = GL_RG;
}
if (channels == 3) {
iformat = GL_RGB16F;
format = GL_RGB;
}
if (channels == 4) {
iformat = GL_RGBA16F;
format = GL_RGBA;
}
f->glTexImage2D(GL_TEXTURE_2D, 0, iformat, size, size, 0, format, GL_FLOAT, data); f->glTexImage2D(GL_TEXTURE_2D, 0, iformat, size, size, 0, format, GL_FLOAT, data);
} }

View File

@@ -19,9 +19,9 @@
#ifndef RENDERER_BASE_H #ifndef RENDERER_BASE_H
#define RENDERER_BASE_H #define RENDERER_BASE_H
#include "glbuffer.h"
#include "glshaders_types.h" #include "glshaders_types.h"
#include "gltexturearray.h" #include "gltexturearray.h"
#include "glbuffer.h"
class RendererBase { class RendererBase {

View File

@@ -17,19 +17,20 @@
*/ */
#define GL_GLEXT_PROTOTYPES #define GL_GLEXT_PROTOTYPES
#include <QOpenGLExtraFunctions>
#include "renderer_material.h" #include "renderer_material.h"
#include "renderer.h"
#include "qglview.h"
#include "glmesh.h" #include "glmesh.h"
#include "gltexture_manager.h" #include "gltexture_manager.h"
#include "qglview.h"
#include "renderer.h"
#include <QOpenGLExtraFunctions>
#include <qad_types.h> #include <qad_types.h>
using namespace QGLEngineShaders; using namespace QGLEngineShaders;
RendererMaterial::RendererMaterial(Renderer * r_) RendererMaterial::RendererMaterial(Renderer * r_): r(r_), fbo_mat_thumb(r->view, 6, true, GL_RGBA16F) {
: r(r_), fbo_mat_thumb(r->view, 6, true , GL_RGBA16F) {
mat_sphere = Primitive::ellipsoid(16, 16); mat_sphere = Primitive::ellipsoid(16, 16);
mat_camera = new Camera(); mat_camera = new Camera();
mat_camera->setPos(QVector3D(2, 2, 2)); mat_camera->setPos(QVector3D(2, 2, 2));
@@ -110,8 +111,7 @@ void RendererMaterial::procQueue() {
emit r->view->materialThumbnailCreated(last_thumb_material); emit r->view->materialThumbnailCreated(last_thumb_material);
last_thumb_material = 0; last_thumb_material = 0;
} }
if (!mat_thumb_queue.isEmpty()) if (!mat_thumb_queue.isEmpty()) renderMaterial(mat_thumb_queue.dequeue());
renderMaterial(mat_thumb_queue.dequeue());
} }
@@ -128,7 +128,6 @@ void RendererMaterial::recreateMaterialThumbnails(bool force_all) {
mat_thumb_queue.enqueue(m); mat_thumb_queue.enqueue(m);
} else { } else {
foreach(Material * m, r->view->scene()->changed_materials) foreach(Material * m, r->view->scene()->changed_materials)
if (!mat_thumb_queue.contains(m)) if (!mat_thumb_queue.contains(m)) mat_thumb_queue.enqueue(m);
mat_thumb_queue.enqueue(m);
} }
} }

View File

@@ -20,11 +20,13 @@
#define RENDERER_MATERIAL_H #define RENDERER_MATERIAL_H
#include "glframebuffer.h" #include "glframebuffer.h"
#include <QQueue> #include <QQueue>
class RendererMaterial { class RendererMaterial {
friend class QGLView; friend class QGLView;
public: public:
RendererMaterial(Renderer * r_); RendererMaterial(Renderer * r_);
virtual ~RendererMaterial(); virtual ~RendererMaterial();

View File

@@ -17,17 +17,18 @@
*/ */
#define GL_GLEXT_PROTOTYPES #define GL_GLEXT_PROTOTYPES
#include <QOpenGLExtraFunctions>
#include "renderer_selection.h" #include "renderer_selection.h"
#include "qglview.h"
#include "glmesh.h" #include "glmesh.h"
#include "qglview.h"
#include <QOpenGLExtraFunctions>
#include <qad_types.h> #include <qad_types.h>
using namespace QGLEngineShaders; using namespace QGLEngineShaders;
RendererSelection::RendererSelection(Renderer * r_) RendererSelection::RendererSelection(Renderer * r_): r(r_), fbo_selection(r->view, 6) {
: r(r_), fbo_selection(r->view, 6) {
sel_frame = Primitive::plane(2., 2.); sel_frame = Primitive::plane(2., 2.);
id_hover = 0; id_hover = 0;
line_thick_ = 2.; line_thick_ = 2.;
@@ -105,8 +106,7 @@ void RendererSelection::renderSelection(Scene & scene) {
mc.hov_objects << o; mc.hov_objects << o;
else { else {
o = aim_ids.value(id_hover); o = aim_ids.value(id_hover);
if (o) if (o) mc.hov_aims << o;
mc.hov_aims << o;
} }
// qDebug() << id_hover; // qDebug() << id_hover;
} else { } else {
@@ -141,8 +141,7 @@ void RendererSelection::renderSelection(Scene & scene) {
if (r->mouse_rect.isNull()) if (r->mouse_rect.isNull())
fbo_selection.queryPoint(0, r->mouse_pos * scale_); fbo_selection.queryPoint(0, r->mouse_pos * scale_);
else else
fbo_selection.queryPoints(0, QRect(r->mouse_rect.topLeft() * scale_, fbo_selection.queryPoints(0, QRect(r->mouse_rect.topLeft() * scale_, r->mouse_rect.size() * scale_));
r->mouse_rect.size() * scale_));
// qDebug() << id_hover; // qDebug() << id_hover;
fbo_selection.bindColorTexture(sbrSrcHover, sbrSrcHover); fbo_selection.bindColorTexture(sbrSrcHover, sbrSrcHover);
@@ -158,7 +157,8 @@ void RendererSelection::renderSelection(Scene & scene) {
prog->setUniformValue("has_selection", view->isSelectionHaloEnabled() ? 1.f : 0.f); prog->setUniformValue("has_selection", view->isSelectionHaloEnabled() ? 1.f : 0.f);
prog->setUniformValue("fb_hover", (int)sbrSrcHover); prog->setUniformValue("fb_hover", (int)sbrSrcHover);
prog->setUniformValue("fb_selection", (int)sbrSrcSelect); prog->setUniformValue("fb_selection", (int)sbrSrcSelect);
prog->setUniformValue("hover_id", QVector4D(float( id_hover & 0xFF) / 255.f, prog->setUniformValue("hover_id",
QVector4D(float(id_hover & 0xFF) / 255.f,
float((id_hover >> 8) & 0xFF) / 255.f, float((id_hover >> 8) & 0xFF) / 255.f,
float((id_hover >> 16) & 0xFF) / 255.f, float((id_hover >> 16) & 0xFF) / 255.f,
float((id_hover >> 24) & 0xFF) / 255.f)); float((id_hover >> 24) & 0xFF) / 255.f));

View File

@@ -20,6 +20,7 @@
#define RENDERER_SELECTION_H #define RENDERER_SELECTION_H
#include "renderer_service.h" #include "renderer_service.h"
#include <QHash> #include <QHash>

View File

@@ -17,11 +17,13 @@
*/ */
#define GL_GLEXT_PROTOTYPES #define GL_GLEXT_PROTOTYPES
#include <QOpenGLExtraFunctions>
#include "renderer_service.h" #include "renderer_service.h"
#include "renderer.h"
#include "qglview.h"
#include "glmesh.h" #include "glmesh.h"
#include "qglview.h"
#include "renderer.h"
#include <QOpenGLExtraFunctions>
#include <qad_types.h> #include <qad_types.h>
using namespace QGLEngineShaders; using namespace QGLEngineShaders;
@@ -31,8 +33,10 @@ RendererService::RendererService(Renderer * r_): r(r_) {
line_width = 1; line_width = 1;
current_action = haNoAction; current_action = haNoAction;
current_handle = QFlags<HandleMesh>(); current_handle = QFlags<HandleMesh>();
mat_xyz.resize(3); mat_ms2.resize(3); mat_xyz.resize(3);
color_xyz.resize(3); color_ms2.resize(3); mat_ms2.resize(3);
color_xyz.resize(3);
color_ms2.resize(3);
const QVector3D _rot[3] = {QVector3D(0, 1, 0), QVector3D(-1, 0, 0), QVector3D(0, 0, 1)}; const QVector3D _rot[3] = {QVector3D(0, 1, 0), QVector3D(-1, 0, 0), QVector3D(0, 0, 1)};
const QVector3D _rot2[3] = {QVector3D(0, 0, 0), QVector3D(1, 0, 0), QVector3D(0, -1, 0)}; const QVector3D _rot2[3] = {QVector3D(0, 0, 0), QVector3D(1, 0, 0), QVector3D(0, -1, 0)};
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
@@ -40,8 +44,7 @@ RendererService::RendererService(Renderer * r_): r(r_) {
m.rotate(90., _rot[i]); m.rotate(90., _rot[i]);
mat_xyz[i] = m; mat_xyz[i] = m;
m.setToIdentity(); m.setToIdentity();
if (!_rot2[i].isNull()) if (!_rot2[i].isNull()) m.rotate(90., _rot2[i]);
m.rotate(90., _rot2[i]);
mat_ms2[i] = m; mat_ms2[i] = m;
color_xyz[i] = color_ms2[i] = QVector4D(0, 0, 0, 0.8); color_xyz[i] = color_ms2[i] = QVector4D(0, 0, 0, 0.8);
color_xyz[i][i] = 1.; color_xyz[i][i] = 1.;
@@ -254,7 +257,12 @@ void RendererService::fillAimedObjects(const ObjectBaseList & objects, Mesh * li
} }
void RendererService::fillHandleObjects(QVector3D center, HandleMesh ids[], const QVector<QMatrix4x4> & mats, const QVector<QVector4D> & colors, QMatrix4x4 add_mat, int count) { void RendererService::fillHandleObjects(QVector3D center,
HandleMesh ids[],
const QVector<QMatrix4x4> & mats,
const QVector<QVector4D> & colors,
QMatrix4x4 add_mat,
int count) {
QMatrix4x4 m = invariantSizeMatrix(center) * add_mat; QMatrix4x4 m = invariantSizeMatrix(center) * add_mat;
cur_objects.resize(count); cur_objects.resize(count);
for (int i = 0; i < count; ++i) { for (int i = 0; i < count; ++i) {
@@ -286,8 +294,7 @@ bool RendererService::calculateCenter() {
axis_mat = QMatrix4x4(); axis_mat = QMatrix4x4();
if ((sol.size() == 1)) { if ((sol.size() == 1)) {
if (current_action == haMove) { if (current_action == haMove) {
if (sol[0]->isAimSelected()) if (sol[0]->isAimSelected()) selection_center = ((AimedObject *)sol[0])->worldAim();
selection_center = ((AimedObject*)sol[0])->worldAim();
} else { } else {
axis_mat = parentRotationMatrix(sol[0]); axis_mat = parentRotationMatrix(sol[0]);
} }
@@ -301,9 +308,21 @@ void RendererService::drawCurrentHandleObjects() {
if (calculateCenter()) { if (calculateCenter()) {
HandleMesh ids[3]; HandleMesh ids[3];
switch (current_action) { switch (current_action) {
case haMove : ids[0] = hmMoveX ; ids[1] = hmMoveY ; ids[2] = hmMoveZ ; break; case haMove:
case haRotate: ids[0] = hmRotateX; ids[1] = hmRotateY; ids[2] = hmRotateZ; break; ids[0] = hmMoveX;
case haScale : ids[0] = hmScaleX ; ids[1] = hmScaleY ; ids[2] = hmScaleZ ; break; ids[1] = hmMoveY;
ids[2] = hmMoveZ;
break;
case haRotate:
ids[0] = hmRotateX;
ids[1] = hmRotateY;
ids[2] = hmRotateZ;
break;
case haScale:
ids[0] = hmScaleX;
ids[1] = hmScaleY;
ids[2] = hmScaleZ;
break;
default: break; default: break;
} }
fillHandleObjects(selection_center, ids, mat_xyz, color_xyz, axis_mat); fillHandleObjects(selection_center, ids, mat_xyz, color_xyz, axis_mat);
@@ -317,8 +336,16 @@ void RendererService::drawCurrentHandleObjects() {
} }
if (current_action == haMove || current_action == haScale) { if (current_action == haMove || current_action == haScale) {
switch (current_action) { switch (current_action) {
case haMove : ids[0] = hmMoveXY ; ids[1] = hmMoveXZ ; ids[2] = hmMoveYZ ; break; case haMove:
case haScale : ids[0] = hmScaleXY ; ids[1] = hmScaleXZ ; ids[2] = hmScaleYZ ; break; ids[0] = hmMoveXY;
ids[1] = hmMoveXZ;
ids[2] = hmMoveYZ;
break;
case haScale:
ids[0] = hmScaleXY;
ids[1] = hmScaleXZ;
ids[2] = hmScaleYZ;
break;
default: break; default: break;
} }
hm = handle_ms_2_mesh; hm = handle_ms_2_mesh;
@@ -328,8 +355,10 @@ void RendererService::drawCurrentHandleObjects() {
hm->draw(r->view, 3); hm->draw(r->view, 3);
if (current_action == haScale) { if (current_action == haScale) {
hm = handle_scale_3_mesh; hm = handle_scale_3_mesh;
QVector<QMatrix4x4> mv; mv.resize(1); QVector<QMatrix4x4> mv;
QVector<QVector4D> cv; cv.fill(QVector4D(1, 1, 0.5, 1), 1); mv.resize(1);
QVector<QVector4D> cv;
cv.fill(QVector4D(1, 1, 0.5, 1), 1);
ids[0] = hmMaxScale; ids[0] = hmMaxScale;
fillHandleObjects(selection_center, ids, mv, cv, axis_mat, 1); fillHandleObjects(selection_center, ids, mv, cv, axis_mat, 1);
hm->loadObjects(r->view, cur_objects); hm->loadObjects(r->view, cur_objects);
@@ -360,7 +389,6 @@ void RendererService::drawLights() {
box_mesh->loadObjects(v, cur_aims); box_mesh->loadObjects(v, cur_aims);
box_mesh->loadSelections(v, rs.cur_selections_); box_mesh->loadSelections(v, rs.cur_selections_);
box_mesh->draw(v, cur_aims.size()); box_mesh->draw(v, cur_aims.size());
} }
@@ -387,7 +415,6 @@ void RendererService::drawLightsFrame(QColor color) {
box_mesh_f->loadObjects(v, cur_aims); box_mesh_f->loadObjects(v, cur_aims);
box_mesh_f->loadSelections(v, rs.cur_selections_); box_mesh_f->loadSelections(v, rs.cur_selections_);
box_mesh_f->draw(v, cur_aims.size()); box_mesh_f->draw(v, cur_aims.size());
} }
@@ -405,7 +432,6 @@ void RendererService::drawCameras() {
box_mesh->loadObjects(v, cur_aims); box_mesh->loadObjects(v, cur_aims);
box_mesh->loadSelections(v, rs.cur_selections_); box_mesh->loadSelections(v, rs.cur_selections_);
box_mesh->draw(v, cur_aims.size()); box_mesh->draw(v, cur_aims.size());
} }
@@ -426,7 +452,6 @@ void RendererService::drawCamerasFrame(QColor color) {
box_mesh_f->loadObjects(v, cur_aims); box_mesh_f->loadObjects(v, cur_aims);
box_mesh_f->loadSelections(v, rs.cur_selections_); box_mesh_f->loadSelections(v, rs.cur_selections_);
box_mesh_f->draw(v, cur_aims.size()); box_mesh_f->draw(v, cur_aims.size());
} }
@@ -460,7 +485,6 @@ void RendererService::renderService() {
prog->setUniformValue("z_offset", -1.E-2f); prog->setUniformValue("z_offset", -1.E-2f);
drawLightsFrame(Qt::black); drawLightsFrame(Qt::black);
drawCamerasFrame(Qt::black); drawCamerasFrame(Qt::black);
} }
if (r->bindShader(Renderer::srServiceLine, &prog)) { if (r->bindShader(Renderer::srServiceLine, &prog)) {
r->setUniformCamera(prog, r->view->camera()); r->setUniformCamera(prog, r->view->camera());
@@ -488,7 +512,6 @@ void RendererService::renderService() {
r->setUniformCamera(prog, axis_camera, true, axis_viewport); r->setUniformCamera(prog, axis_camera, true, axis_viewport);
axis_mesh->draw(f, 3); axis_mesh->draw(f, 3);
f->glViewport(0, 0, r->view->width(), r->view->height()); f->glViewport(0, 0, r->view->width(), r->view->height());
} }
f->glDisable(GL_MULTISAMPLE); f->glDisable(GL_MULTISAMPLE);
} }

View File

@@ -21,6 +21,7 @@
#include "glframebuffer.h" #include "glframebuffer.h"
#include "glshaders_types.h" #include "glshaders_types.h"
#include <QQueue> #include <QQueue>
@@ -70,7 +71,12 @@ public:
void fillXYZObjects(); void fillXYZObjects();
void fillOmniObjects(); void fillOmniObjects();
void fillAimedObjects(const ObjectBaseList & objects, Mesh * line_mesh); void fillAimedObjects(const ObjectBaseList & objects, Mesh * line_mesh);
void fillHandleObjects(QVector3D center, HandleMesh ids[], const QVector<QMatrix4x4> & mats, const QVector<QVector4D> & colors, QMatrix4x4 add_mat, int count = 3); void fillHandleObjects(QVector3D center,
HandleMesh ids[],
const QVector<QMatrix4x4> & mats,
const QVector<QVector4D> & colors,
QMatrix4x4 add_mat,
int count = 3);
bool calculateCenter(); bool calculateCenter();
void drawCurrentHandleObjects(); void drawCurrentHandleObjects();
void drawLights(); void drawLights();

View File

@@ -17,18 +17,22 @@
*/ */
#define GL_GLEXT_PROTOTYPES #define GL_GLEXT_PROTOTYPES
#include <QOpenGLExtraFunctions>
#include "tonemapping_proc.h" #include "tonemapping_proc.h"
#include "qglview.h" #include "qglview.h"
#include <QOpenGLExtraFunctions>
#include <qad_types.h> #include <qad_types.h>
using namespace QGLEngineShaders; using namespace QGLEngineShaders;
TonemappingProc::TonemappingProc(Renderer * rend): QThread(), r(rend), TonemappingProc::TonemappingProc(Renderer * rend)
fbo_1x1(r->view, 1, false, GL_RGB32F), : QThread()
fbomm(r->fbo_out, Renderer::obrSum, 3), , r(rend)
buffer_vbo(GL_ARRAY_BUFFER, GL_DYNAMIC_DRAW) { , fbo_1x1(r->view, 1, false, GL_RGB32F)
, fbomm(r->fbo_out, Renderer::obrSum, 3)
, buffer_vbo(GL_ARRAY_BUFFER, GL_DYNAMIC_DRAW) {
shader_sum = 0; shader_sum = 0;
timer_delim = 0; timer_delim = 0;
frame_max = cur_max = 1.; frame_max = cur_max = 1.;
@@ -40,8 +44,7 @@ TonemappingProc::TonemappingProc(Renderer * rend): QThread(), r(rend),
TonemappingProc::~TonemappingProc() { TonemappingProc::~TonemappingProc() {
exit_ = true; exit_ = true;
if (!wait(1000)) if (!wait(1000)) terminate();
terminate();
killTimer(timer_tone); killTimer(timer_tone);
if (shader_sum) delete shader_sum; if (shader_sum) delete shader_sum;
} }
@@ -85,8 +88,7 @@ void TonemappingProc::resize() {
void TonemappingProc::timerEvent(QTimerEvent * e) { void TonemappingProc::timerEvent(QTimerEvent * e) {
if (!fbo_1x1.isInit() || !enabled) return; if (!fbo_1x1.isInit() || !enabled) return;
if (timer_delim == 0) if (timer_delim == 0) need_render_sum = true;
need_render_sum = true;
timer_delim = (timer_delim + 1) % 10; timer_delim = (timer_delim + 1) % 10;
mutex.lock(); mutex.lock();
float fmax = frame_max; float fmax = frame_max;
@@ -139,8 +141,7 @@ void TonemappingProc::run() {
mutex.unlock(); mutex.unlock();
float max = calcHistogram(data); float max = calcHistogram(data);
last_max << max; last_max << max;
if (last_max.size() > 5) if (last_max.size() > 5) last_max.removeAt(0);
last_max.removeAt(0);
float cm = last_max[0]; float cm = last_max[0];
for (int i = 1; i < last_max.size(); ++i) for (int i = 1; i < last_max.size(); ++i)
cm += last_max[i]; cm += last_max[i];

View File

@@ -20,13 +20,14 @@
#define TONEMAPPING_PROC_H #define TONEMAPPING_PROC_H
#include "glframebuffer_mipmap.h" #include "glframebuffer_mipmap.h"
#include <QThread> #include <QThread>
class TonemappingProc: public QThread class TonemappingProc: public QThread {
{
friend class Renderer; friend class Renderer;
friend class QGLView; friend class QGLView;
public: public:
TonemappingProc(Renderer * rend); TonemappingProc(Renderer * rend);
virtual ~TonemappingProc(); virtual ~TonemappingProc();

View File

@@ -17,8 +17,9 @@
*/ */
#include "material_editor.h" #include "material_editor.h"
#include "ui_material_editor.h"
#include "glmaterial.h" #include "glmaterial.h"
#include "ui_material_editor.h"
MaterialEditor::MaterialEditor(QWidget * parent): QWidget(parent) { MaterialEditor::MaterialEditor(QWidget * parent): QWidget(parent) {
@@ -42,11 +43,8 @@ MaterialEditor::MaterialEditor(QWidget * parent): QWidget(parent) {
void MaterialEditor::changeEvent(QEvent * e) { void MaterialEditor::changeEvent(QEvent * e) {
QWidget::changeEvent(e); QWidget::changeEvent(e);
switch (e->type()) { switch (e->type()) {
case QEvent::LanguageChange: case QEvent::LanguageChange: ui->retranslateUi(this); break;
ui->retranslateUi(this); default: break;
break;
default:
break;
} }
} }
@@ -88,13 +86,17 @@ void MaterialEditor::setMaterial(Material * m) {
ui->mapRoughness->setMap(&(mat->map_roughness)); ui->mapRoughness->setMap(&(mat->map_roughness));
ui->mapEmission->setMap(&(mat->map_emission)); ui->mapEmission->setMap(&(mat->map_emission));
ui->mapRelief->setMap(&(mat->map_relief)); ui->mapRelief->setMap(&(mat->map_relief));
/*ui->lineReflFront->setProperty("GLpath", mat->map_reflection.path(0)); ui->lineReflFront->setText(QFileInfo(mat->map_reflection.path(0)).fileName()); /*ui->lineReflFront->setProperty("GLpath", mat->map_reflection.path(0));
ui->lineReflBack->setProperty("GLpath", mat->map_reflection.path(1)); ui->lineReflBack->setText(QFileInfo(mat->map_reflection.path(1)).fileName()); ui->lineReflFront->setText(QFileInfo(mat->map_reflection.path(0)).fileName()); ui->lineReflBack->setProperty("GLpath",
ui->lineReflLeft->setProperty("GLpath", mat->map_reflection.path(2)); ui->lineReflLeft->setText(QFileInfo(mat->map_reflection.path(2)).fileName()); mat->map_reflection.path(1)); ui->lineReflBack->setText(QFileInfo(mat->map_reflection.path(1)).fileName());
ui->lineReflRight->setProperty("GLpath", mat->map_reflection.path(3)); ui->lineReflRight->setText(QFileInfo(mat->map_reflection.path(3)).fileName()); ui->lineReflLeft->setProperty("GLpath", mat->map_reflection.path(2));
ui->lineReflTop->setProperty("GLpath", mat->map_reflection.path(4)); ui->lineReflTop->setText(QFileInfo(mat->map_reflection.path(4)).fileName()); ui->lineReflLeft->setText(QFileInfo(mat->map_reflection.path(2)).fileName()); ui->lineReflRight->setProperty("GLpath",
ui->lineReflBottom->setProperty("GLpath", mat->map_reflection.path(5)); ui->lineReflBottom->setText(QFileInfo(mat->map_reflection.path(5)).fileName()); mat->map_reflection.path(3)); ui->lineReflRight->setText(QFileInfo(mat->map_reflection.path(3)).fileName());
*/active = true; ui->lineReflTop->setProperty("GLpath", mat->map_reflection.path(4));
ui->lineReflTop->setText(QFileInfo(mat->map_reflection.path(4)).fileName()); ui->lineReflBottom->setProperty("GLpath",
mat->map_reflection.path(5)); ui->lineReflBottom->setText(QFileInfo(mat->map_reflection.path(5)).fileName());
*/
active = true;
} }
/* /*
@@ -125,7 +127,10 @@ Material MaterialEditor::material() {
*/ */
void MaterialEditor::on_buttonReflFrontSelect_clicked() { void MaterialEditor::on_buttonReflFrontSelect_clicked() {
QString str = QFileDialog::getOpenFileName(this, "Select image", ui->lineReflFront->property("GLpath").toString(), "Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)"); QString str = QFileDialog::getOpenFileName(this,
"Select image",
ui->lineReflFront->property("GLpath").toString(),
"Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)");
if (str.isEmpty()) return; if (str.isEmpty()) return;
ui->lineReflFront->setProperty("GLpath", str); ui->lineReflFront->setProperty("GLpath", str);
ui->lineReflFront->setText(QFileInfo(str).fileName()); ui->lineReflFront->setText(QFileInfo(str).fileName());
@@ -134,7 +139,10 @@ void MaterialEditor::on_buttonReflFrontSelect_clicked() {
void MaterialEditor::on_buttonReflBackSelect_clicked() { void MaterialEditor::on_buttonReflBackSelect_clicked() {
QString str = QFileDialog::getOpenFileName(this, "Select image", ui->lineReflBack->property("GLpath").toString(), "Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)"); QString str = QFileDialog::getOpenFileName(this,
"Select image",
ui->lineReflBack->property("GLpath").toString(),
"Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)");
if (str.isEmpty()) return; if (str.isEmpty()) return;
ui->lineReflBack->setProperty("GLpath", str); ui->lineReflBack->setProperty("GLpath", str);
ui->lineReflBack->setText(QFileInfo(str).fileName()); ui->lineReflBack->setText(QFileInfo(str).fileName());
@@ -143,7 +151,10 @@ void MaterialEditor::on_buttonReflBackSelect_clicked() {
void MaterialEditor::on_buttonReflLeftSelect_clicked() { void MaterialEditor::on_buttonReflLeftSelect_clicked() {
QString str = QFileDialog::getOpenFileName(this, "Select image", ui->lineReflLeft->property("GLpath").toString(), "Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)"); QString str = QFileDialog::getOpenFileName(this,
"Select image",
ui->lineReflLeft->property("GLpath").toString(),
"Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)");
if (str.isEmpty()) return; if (str.isEmpty()) return;
ui->lineReflLeft->setProperty("GLpath", str); ui->lineReflLeft->setProperty("GLpath", str);
ui->lineReflLeft->setText(QFileInfo(str).fileName()); ui->lineReflLeft->setText(QFileInfo(str).fileName());
@@ -152,7 +163,10 @@ void MaterialEditor::on_buttonReflLeftSelect_clicked() {
void MaterialEditor::on_buttonReflRightSelect_clicked() { void MaterialEditor::on_buttonReflRightSelect_clicked() {
QString str = QFileDialog::getOpenFileName(this, "Select image", ui->lineReflRight->property("GLpath").toString(), "Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)"); QString str = QFileDialog::getOpenFileName(this,
"Select image",
ui->lineReflRight->property("GLpath").toString(),
"Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)");
if (str.isEmpty()) return; if (str.isEmpty()) return;
ui->lineReflRight->setProperty("GLpath", str); ui->lineReflRight->setProperty("GLpath", str);
ui->lineReflRight->setText(QFileInfo(str).fileName()); ui->lineReflRight->setText(QFileInfo(str).fileName());
@@ -161,7 +175,10 @@ void MaterialEditor::on_buttonReflRightSelect_clicked() {
void MaterialEditor::on_buttonReflTopSelect_clicked() { void MaterialEditor::on_buttonReflTopSelect_clicked() {
QString str = QFileDialog::getOpenFileName(this, "Select image", ui->lineReflTop->property("GLpath").toString(), "Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)"); QString str = QFileDialog::getOpenFileName(this,
"Select image",
ui->lineReflTop->property("GLpath").toString(),
"Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)");
if (str.isEmpty()) return; if (str.isEmpty()) return;
ui->lineReflTop->setProperty("GLpath", str); ui->lineReflTop->setProperty("GLpath", str);
ui->lineReflTop->setText(QFileInfo(str).fileName()); ui->lineReflTop->setText(QFileInfo(str).fileName());
@@ -170,7 +187,10 @@ void MaterialEditor::on_buttonReflTopSelect_clicked() {
void MaterialEditor::on_buttonReflBottomSelect_clicked() { void MaterialEditor::on_buttonReflBottomSelect_clicked() {
QString str = QFileDialog::getOpenFileName(this, "Select image", ui->lineReflBottom->property("GLpath").toString(), "Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)"); QString str = QFileDialog::getOpenFileName(this,
"Select image",
ui->lineReflBottom->property("GLpath").toString(),
"Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)");
if (str.isEmpty()) return; if (str.isEmpty()) return;
ui->lineReflBottom->setProperty("GLpath", str); ui->lineReflBottom->setProperty("GLpath", str);
ui->lineReflBottom->setText(QFileInfo(str).fileName()); ui->lineReflBottom->setText(QFileInfo(str).fileName());

View File

@@ -19,17 +19,18 @@
#ifndef MATERIAL_EDITOR_H #ifndef MATERIAL_EDITOR_H
#define MATERIAL_EDITOR_H #define MATERIAL_EDITOR_H
#include <QFileDialog>
#include "gltypes.h" #include "gltypes.h"
#include <QFileDialog>
namespace Ui { namespace Ui {
class MaterialEditor; class MaterialEditor;
} }
class MaterialEditor: public QWidget class MaterialEditor: public QWidget {
{
friend class MaterialsEditor; friend class MaterialsEditor;
Q_OBJECT Q_OBJECT
public: public:
explicit MaterialEditor(QWidget * parent = 0); explicit MaterialEditor(QWidget * parent = 0);
@@ -61,7 +62,6 @@ private slots:
signals: signals:
void changed(); void changed();
}; };
#endif // MATERIAL_EDITOR_H #endif // MATERIAL_EDITOR_H

View File

@@ -17,9 +17,11 @@
*/ */
#include "material_map_editor.h" #include "material_map_editor.h"
#include "ui_material_map_editor.h"
#include "gltexture_manager.h"
#include "glmaterial.h" #include "glmaterial.h"
#include "gltexture_manager.h"
#include "ui_material_map_editor.h"
#include <qad_types.h> #include <qad_types.h>
@@ -34,11 +36,8 @@ MaterialMapEditor::MaterialMapEditor(QWidget * parent): QWidget(parent) {
void MaterialMapEditor::changeEvent(QEvent * e) { void MaterialMapEditor::changeEvent(QEvent * e) {
QWidget::changeEvent(e); QWidget::changeEvent(e);
switch (e->type()) { switch (e->type()) {
case QEvent::LanguageChange: case QEvent::LanguageChange: ui->retranslateUi(this); break;
ui->retranslateUi(this); default: break;
break;
default:
break;
} }
} }
@@ -85,7 +84,8 @@ void MaterialMapEditor::setMap(Map * m) {
ui->sliderOffset->setValue(map->color_offset); ui->sliderOffset->setValue(map->color_offset);
ui->spinScaleX->setValue(map->bitmap_scale.x()); ui->spinScaleX->setValue(map->bitmap_scale.x());
ui->spinScaleY->setValue(map->bitmap_scale.y()); ui->spinScaleY->setValue(map->bitmap_scale.y());
ui->linePath->setProperty("GLpath", map->bitmap_path); ui->linePath->setText(QFileInfo(map->bitmap_path).fileName()); ui->linePath->setProperty("GLpath", map->bitmap_path);
ui->linePath->setText(QFileInfo(map->bitmap_path).fileName());
updateIcon(); updateIcon();
active = true; active = true;
} }
@@ -121,7 +121,10 @@ Map MaterialMapEditor::map() {
*/ */
void MaterialMapEditor::on_buttonSelect_clicked() { void MaterialMapEditor::on_buttonSelect_clicked() {
QString str = QFileDialog::getOpenFileName(this, "Select image", ui->linePath->property("GLpath").toString(), "Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)"); QString str = QFileDialog::getOpenFileName(this,
"Select image",
ui->linePath->property("GLpath").toString(),
"Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)");
if (str.isEmpty()) return; if (str.isEmpty()) return;
ui->linePath->setProperty("GLpath", str); ui->linePath->setProperty("GLpath", str);
ui->linePath->setText(QFileInfo(str).fileName()); ui->linePath->setText(QFileInfo(str).fileName());

View File

@@ -19,16 +19,17 @@
#ifndef MATERIAL_MAP_EDITOR_H #ifndef MATERIAL_MAP_EDITOR_H
#define MATERIAL_MAP_EDITOR_H #define MATERIAL_MAP_EDITOR_H
#include <QFileDialog>
#include "gltypes.h" #include "gltypes.h"
#include <QFileDialog>
namespace Ui { namespace Ui {
class MaterialMapEditor; class MaterialMapEditor;
} }
class MaterialMapEditor: public QWidget class MaterialMapEditor: public QWidget {
{
Q_OBJECT Q_OBJECT
public: public:
explicit MaterialMapEditor(QWidget * parent = 0); explicit MaterialMapEditor(QWidget * parent = 0);
@@ -54,7 +55,6 @@ private slots:
signals: signals:
void changed(); void changed();
}; };
#endif // MATERIAL_MAP_EDITOR_H #endif // MATERIAL_MAP_EDITOR_H

View File

@@ -17,13 +17,15 @@
*/ */
#include "materials_editor.h" #include "materials_editor.h"
#include "ui_materials_editor.h"
#include "glmaterial.h"
#include "material_editor.h" #include "material_editor.h"
#include "qglview.h" #include "qglview.h"
#include "glmaterial.h" #include "ui_materials_editor.h"
#include <qad_types.h>
#include <ecombobox.h>
#include <QInputDialog> #include <QInputDialog>
#include <ecombobox.h>
#include <qad_types.h>
MaterialsEditor::MaterialsEditor(QWidget * parent): QWidget(parent) { MaterialsEditor::MaterialsEditor(QWidget * parent): QWidget(parent) {
@@ -63,11 +65,8 @@ bool MaterialsEditor::event(QEvent * e) {
void MaterialsEditor::changeEvent(QEvent * e) { void MaterialsEditor::changeEvent(QEvent * e) {
QWidget::changeEvent(e); QWidget::changeEvent(e);
switch (e->type()) { switch (e->type()) {
case QEvent::LanguageChange: case QEvent::LanguageChange: ui->retranslateUi(this); break;
ui->retranslateUi(this); default: break;
break;
default:
break;
} }
} }
@@ -98,8 +97,7 @@ void MaterialsEditor::selectMaterial(Material * m) {
int MaterialsEditor::indexByMaterial(Material * m) { int MaterialsEditor::indexByMaterial(Material * m) {
if (!m) return -1; if (!m) return -1;
for (int i = 0; i < ui->comboMaterial->count(); ++i) { for (int i = 0; i < ui->comboMaterial->count(); ++i) {
if ((Material*)(ui->comboMaterial->itemData(i, Qt::UserRole + 1).value<quintptr>()) == m) if ((Material *)(ui->comboMaterial->itemData(i, Qt::UserRole + 1).value<quintptr>()) == m) return i;
return i;
} }
return -1; return -1;
} }
@@ -129,7 +127,6 @@ void MaterialsEditor::materialsChanged() {
ui->comboMaterial->setItemIcon(i, QIcon(QPixmap::fromImage(view->materialThumbnail(m)))); ui->comboMaterial->setItemIcon(i, QIcon(QPixmap::fromImage(view->materialThumbnail(m))));
if (cm == m) ui->comboMaterial->setCurrentIndex(i); if (cm == m) ui->comboMaterial->setCurrentIndex(i);
} }
} }

View File

@@ -19,16 +19,17 @@
#ifndef MATERIALS_EDITOR_H #ifndef MATERIALS_EDITOR_H
#define MATERIALS_EDITOR_H #define MATERIALS_EDITOR_H
#include <QFileDialog>
#include "gltypes.h" #include "gltypes.h"
#include <QFileDialog>
namespace Ui { namespace Ui {
class MaterialsEditor; class MaterialsEditor;
} }
class MaterialsEditor: public QWidget class MaterialsEditor: public QWidget {
{
Q_OBJECT Q_OBJECT
public: public:
explicit MaterialsEditor(QWidget * parent = 0); explicit MaterialsEditor(QWidget * parent = 0);
@@ -60,7 +61,6 @@ private slots:
signals: signals:
void changed(); void changed();
}; };
#endif // MATERIALS_EDITOR_H #endif // MATERIALS_EDITOR_H

View File

@@ -17,10 +17,12 @@
*/ */
#include "object_editor.h" #include "object_editor.h"
#include "ui_object_editor.h"
#include "qglview.h" #include "qglview.h"
#include <spinslider.h> #include "ui_object_editor.h"
#include <scroll_spin_box.h> #include <scroll_spin_box.h>
#include <spinslider.h>
ObjectEditor::ObjectEditor(QWidget * parent): QWidget(parent) { ObjectEditor::ObjectEditor(QWidget * parent): QWidget(parent) {
@@ -35,16 +37,14 @@ ObjectEditor::ObjectEditor(QWidget * parent): QWidget(parent) {
ui->spinAimDist->hide(); ui->spinAimDist->hide();
QObjectList ol; QObjectList ol;
ol << ui->spinPosX << ui->spinPosY << ui->spinPosZ << ol << ui->spinPosX << ui->spinPosY << ui->spinPosZ << ui->spinRotationX << ui->spinRotationY << ui->spinRotationZ << ui->spinScaleX
ui->spinRotationX << ui->spinRotationY << ui->spinRotationZ << << ui->spinScaleY << ui->spinScaleZ;
ui->spinScaleX << ui->spinScaleY << ui->spinScaleZ;
foreach(QObject * o, ol) foreach(QObject * o, ol)
connect(o, SIGNAL(valueChanged(double)), this, SLOT(spinChanged(double))); connect(o, SIGNAL(valueChanged(double)), this, SLOT(spinChanged(double)));
ol.clear(); ol.clear();
ol << ui->spinLightIntensity << ui->spinLightDecayConst << ui->spinLightDecayLinear << ol << ui->spinLightIntensity << ui->spinLightDecayConst << ui->spinLightDecayLinear << ui->spinLightDecayQuadratic
ui->spinLightDecayQuadratic << ui->spinLightAngleStart << ui->spinLightAngleEnd << << ui->spinLightAngleStart << ui->spinLightAngleEnd << ui->spinAimDist;
ui->spinAimDist;
foreach(QObject * o, ol) foreach(QObject * o, ol)
connect(o, SIGNAL(valueChanged(double)), this, SLOT(spinLightChanged(double))); connect(o, SIGNAL(valueChanged(double)), this, SLOT(spinLightChanged(double)));
@@ -54,12 +54,10 @@ ObjectEditor::ObjectEditor(QWidget * parent): QWidget(parent) {
connect(o, SIGNAL(valueChanged(double)), this, SLOT(spinCameraChanged(double))); connect(o, SIGNAL(valueChanged(double)), this, SLOT(spinCameraChanged(double)));
ol.clear(); ol.clear();
ol << ui->checkVisible << ui->checkCastShadows << ui->checkReceiveShadows << ol << ui->checkVisible << ui->checkCastShadows << ui->checkReceiveShadows << ui->checkAcceptLight << ui->checkAcceptFog
ui->checkAcceptLight << ui->checkAcceptFog << << ui->checkCameraMirrorX << ui->checkCameraMirrorY;
ui->checkCameraMirrorX << ui->checkCameraMirrorY;
foreach(QObject * o, ol) foreach(QObject * o, ol)
connect(o, SIGNAL(toggled(bool)), this, SLOT(checkChanged(bool))); connect(o, SIGNAL(toggled(bool)), this, SLOT(checkChanged(bool)));
} }
@@ -75,11 +73,8 @@ void ObjectEditor::assignQGLView(QGLView * v) {
void ObjectEditor::changeEvent(QEvent * e) { void ObjectEditor::changeEvent(QEvent * e) {
QWidget::changeEvent(e); QWidget::changeEvent(e);
switch (e->type()) { switch (e->type()) {
case QEvent::LanguageChange: case QEvent::LanguageChange: ui->retranslateUi(this); break;
ui->retranslateUi(this); default: break;
break;
default:
break;
} }
} }
@@ -161,14 +156,12 @@ void ObjectEditor::setObject(ObjectBase * o) {
void ObjectEditor::on_spinLightAngleStart_valueChanged(double v) { void ObjectEditor::on_spinLightAngleStart_valueChanged(double v) {
if (ui->spinLightAngleEnd->value() < v) if (ui->spinLightAngleEnd->value() < v) ui->spinLightAngleEnd->setValue(v);
ui->spinLightAngleEnd->setValue(v);
} }
void ObjectEditor::on_spinLightAngleEnd_valueChanged(double v) { void ObjectEditor::on_spinLightAngleEnd_valueChanged(double v) {
if (ui->spinLightAngleStart->value() > v) if (ui->spinLightAngleStart->value() > v) ui->spinLightAngleStart->setValue(v);
ui->spinLightAngleStart->setValue(v);
} }

View File

@@ -19,16 +19,17 @@
#ifndef OBJECT_EDITOR_H #ifndef OBJECT_EDITOR_H
#define OBJECT_EDITOR_H #define OBJECT_EDITOR_H
#include <QWidget>
#include "globject.h" #include "globject.h"
#include <QWidget>
namespace Ui { namespace Ui {
class ObjectEditor; class ObjectEditor;
} }
class ObjectEditor: public QWidget class ObjectEditor: public QWidget {
{
Q_OBJECT Q_OBJECT
public: public:
explicit ObjectEditor(QWidget * parent = 0); explicit ObjectEditor(QWidget * parent = 0);
@@ -56,7 +57,6 @@ private slots:
signals: signals:
void changed(); void changed();
}; };
#endif // OBJECT_EDITOR_H #endif // OBJECT_EDITOR_H

View File

@@ -17,11 +17,13 @@
*/ */
#include "primitiveeditor.h" #include "primitiveeditor.h"
#include "glmesh.h"
#include "glprimitives.h"
#include "ui_primitiveeditor.h" #include "ui_primitiveeditor.h"
#include <QMetaEnum> #include <QMetaEnum>
#include <qad_types.h> #include <qad_types.h>
#include "glprimitives.h"
#include "glmesh.h"
PrimitiveEditor::PrimitiveEditor(QWidget * parent): QWidget(parent), ui(new Ui::PrimitiveEditor) { PrimitiveEditor::PrimitiveEditor(QWidget * parent): QWidget(parent), ui(new Ui::PrimitiveEditor) {
@@ -90,54 +92,28 @@ Mesh * PrimitiveEditor::createMesh(QVariantList & params) {
params << pt; params << pt;
switch (pt) { switch (pt) {
case Plane: case Plane:
m = Primitive::plane(ui->spinWidth->value(), m = Primitive::plane(ui->spinWidth->value(), ui->spinLength->value());
ui->spinLength->value()); params << ui->spinWidth->value() << ui->spinLength->value();
params << ui->spinWidth->value()
<< ui->spinLength->value();
break; break;
case Cube: case Cube:
m = Primitive::cube(ui->spinWidth->value(), m = Primitive::cube(ui->spinWidth->value(), ui->spinLength->value(), ui->spinHeight->value());
ui->spinLength->value(), params << ui->spinWidth->value() << ui->spinLength->value() << ui->spinHeight->value();
ui->spinHeight->value());
params << ui->spinWidth->value()
<< ui->spinLength->value()
<< ui->spinHeight->value();
break; break;
case Ellipsoid: case Ellipsoid:
m = Primitive::ellipsoid(ui->spinSegments->value(), m = Primitive::ellipsoid(ui->spinSegments->value(), ui->spinSegments2->value(), ui->spinRadius->value(), ui->spinAngle->value());
ui->spinSegments2->value(), params << ui->spinSegments->value() << ui->spinSegments2->value() << ui->spinRadius->value() << ui->spinAngle->value();
ui->spinRadius->value(),
ui->spinAngle->value());
params << ui->spinSegments->value()
<< ui->spinSegments2->value()
<< ui->spinRadius->value()
<< ui->spinAngle->value();
break; break;
case Disc: case Disc:
m = Primitive::disc(ui->spinSegments->value(), m = Primitive::disc(ui->spinSegments->value(), ui->spinRadius->value(), ui->spinAngle->value());
ui->spinRadius->value(), params << ui->spinSegments->value() << ui->spinRadius->value() << ui->spinAngle->value();
ui->spinAngle->value());
params << ui->spinSegments->value()
<< ui->spinRadius->value()
<< ui->spinAngle->value();
break; break;
case Cone: case Cone:
m = Primitive::cone(ui->spinSegments->value(), m = Primitive::cone(ui->spinSegments->value(), ui->spinRadius->value(), ui->spinHeight->value());
ui->spinRadius->value(), params << ui->spinSegments->value() << ui->spinRadius->value() << ui->spinHeight->value();
ui->spinHeight->value());
params << ui->spinSegments->value()
<< ui->spinRadius->value()
<< ui->spinHeight->value();
break; break;
case Cylinder: case Cylinder:
m = Primitive::cylinder(ui->spinSegments->value(), m = Primitive::cylinder(ui->spinSegments->value(), ui->spinRadius->value(), ui->spinHeight->value(), ui->spinAngle->value());
ui->spinRadius->value(), params << ui->spinSegments->value() << ui->spinRadius->value() << ui->spinHeight->value() << ui->spinAngle->value();
ui->spinHeight->value(),
ui->spinAngle->value());
params << ui->spinSegments->value()
<< ui->spinRadius->value()
<< ui->spinHeight->value()
<< ui->spinAngle->value();
break; break;
case Torus: case Torus:
m = Primitive::torus(ui->spinSegments->value(), m = Primitive::torus(ui->spinSegments->value(),
@@ -145,32 +121,30 @@ Mesh * PrimitiveEditor::createMesh(QVariantList & params) {
ui->spinRadius->value(), ui->spinRadius->value(),
ui->spinRadius2->value(), ui->spinRadius2->value(),
ui->spinAngle->value()); ui->spinAngle->value());
params << ui->spinSegments->value() params << ui->spinSegments->value() << ui->spinSegments2->value() << ui->spinRadius->value() << ui->spinRadius2->value()
<< ui->spinSegments2->value()
<< ui->spinRadius->value()
<< ui->spinRadius2->value()
<< ui->spinAngle->value(); << ui->spinAngle->value();
break; break;
default: return 0; default: return 0;
} }
params << ui->flipNormals->isChecked(); params << ui->flipNormals->isChecked();
params << ui->colorButton->color(); params << ui->colorButton->color();
if (ui->flipNormals->isChecked()) if (ui->flipNormals->isChecked()) m->flipNormals();
m->flipNormals();
return m; return m;
} }
void PrimitiveEditor::showEditors() { void PrimitiveEditor::showEditors() {
foreach (QWidget * w, all_editors) w->hide(); foreach(QWidget * w, all_editors)
w->hide();
PrimitiveType pt = (PrimitiveType)ui->comboPrimitives->currentIndex(); PrimitiveType pt = (PrimitiveType)ui->comboPrimitives->currentIndex();
QList<QWidget *> wds = editors[pt]; QList<QWidget *> wds = editors[pt];
foreach (QWidget * w, wds) w->show(); foreach(QWidget * w, wds)
w->show();
} }
void PrimitiveEditor::selectionChanged() { void PrimitiveEditor::selectionChanged() {
ObjectBase * so = view->selectedObject();\ ObjectBase * so = view->selectedObject();
can_replace = false; can_replace = false;
if (so) { if (so) {
QVariantList vl = so->property("primitive", &can_replace).toList(); QVariantList vl = so->property("primitive", &can_replace).toList();

View File

@@ -19,9 +19,10 @@
#ifndef PRIMITIVEEDITOR_H #ifndef PRIMITIVEEDITOR_H
#define PRIMITIVEEDITOR_H #define PRIMITIVEEDITOR_H
#include <QWidget>
#include "qglview.h" #include "qglview.h"
#include <QWidget>
namespace Ui { namespace Ui {
class PrimitiveEditor; class PrimitiveEditor;
@@ -30,6 +31,7 @@ class PrimitiveEditor;
class PrimitiveEditor: public QWidget { class PrimitiveEditor: public QWidget {
Q_OBJECT Q_OBJECT
public: public:
enum PrimitiveType { enum PrimitiveType {
Plane, Plane,

View File

@@ -17,13 +17,15 @@
*/ */
#include "propertyeditor.h" #include "propertyeditor.h"
#include "clineedit.h"
#include "colorbutton.h"
#include "qpointedit.h" #include "qpointedit.h"
#include "qrectedit.h" #include "qrectedit.h"
#include "colorbutton.h"
#include "clineedit.h"
#include <QPainter>
#include <QCheckBox>
#include <QApplication> #include <QApplication>
#include <QCheckBox>
#include <QPainter>
QWidget * Delegate::widgetForProperty(QWidget * parent, const QModelIndex & index) const { QWidget * Delegate::widgetForProperty(QWidget * parent, const QModelIndex & index) const {
@@ -35,7 +37,9 @@ QWidget * Delegate::widgetForProperty(QWidget * parent, const QModelIndex & inde
qulonglong key = index.data(Qt::UserRole).toULongLong(); qulonglong key = index.data(Qt::UserRole).toULongLong();
value = index.parent().data(Qt::UserRole); value = index.parent().data(Qt::UserRole);
// QMetaProperty prop = index.parent().data(Qt::UserRole + 1).value<QMetaProperty>(); // QMetaProperty prop = index.parent().data(Qt::UserRole + 1).value<QMetaProperty>();
w = new QCheckBox(parent); type = 14; ((QCheckBox*)w)->setChecked(((value.toULongLong() & key) == key && key != 0) || (value.toULongLong() == 0 && key == 0)); w = new QCheckBox(parent);
type = 14;
((QCheckBox *)w)->setChecked(((value.toULongLong() & key) == key && key != 0) || (value.toULongLong() == 0 && key == 0));
((QCheckBox *)w)->setText("0x" + QString::number(key, 16).toUpper()); ((QCheckBox *)w)->setText("0x" + QString::number(key, 16).toUpper());
connect((QCheckBox *)w, SIGNAL(clicked(bool)), this, SLOT(changedFlag())); connect((QCheckBox *)w, SIGNAL(clicked(bool)), this, SLOT(changedFlag()));
// qDebug() << prop.enumerator().name(); // qDebug() << prop.enumerator().name();
@@ -43,13 +47,15 @@ QWidget * Delegate::widgetForProperty(QWidget * parent, const QModelIndex & inde
if (value.canConvert<PropertyValuePair>()) { if (value.canConvert<PropertyValuePair>()) {
PropertyValuePair prop = value.value<PropertyValuePair>(); PropertyValuePair prop = value.value<PropertyValuePair>();
if (prop.first.isEnumType()) { if (prop.first.isEnumType()) {
w = new QComboBox(parent); type = 13; ((QComboBox*)w)->setCurrentIndex(value.toInt()); w = new QComboBox(parent);
type = 13;
((QComboBox *)w)->setCurrentIndex(value.toInt());
w->setProperty("__prop", QVariant::fromValue<QMetaProperty>(prop.first)); w->setProperty("__prop", QVariant::fromValue<QMetaProperty>(prop.first));
QMetaEnum menum = prop.first.enumerator(); QMetaEnum menum = prop.first.enumerator();
for (int i = 0; i < menum.keyCount(); ++i) { for (int i = 0; i < menum.keyCount(); ++i) {
((QComboBox*)w)->addItem(QString(menum.key(i)) + " (0x" + QString::number(menum.value(i), 16).toUpper() + ")", menum.value(i)); ((QComboBox *)w)
if (menum.value(i) == prop.second.toInt()) ->addItem(QString(menum.key(i)) + " (0x" + QString::number(menum.value(i), 16).toUpper() + ")", menum.value(i));
((QComboBox*)w)->setCurrentIndex(i); if (menum.value(i) == prop.second.toInt()) ((QComboBox *)w)->setCurrentIndex(i);
} }
connect((QComboBox *)w, SIGNAL(currentIndexChanged(int)), this, SLOT(changed())); connect((QComboBox *)w, SIGNAL(currentIndexChanged(int)), this, SLOT(changed()));
} }
@@ -64,73 +70,129 @@ QWidget * Delegate::widgetForProperty(QWidget * parent, const QModelIndex & inde
#else #else
case QMetaType::Int: case QMetaType::Int:
#endif #endif
w = new QSpinBox(parent); type = 2; ((QSpinBox*)w)->setRange(-0x7FFFFFFF, 0x7FFFFFFF); connect((QSpinBox*)w, SIGNAL(valueChanged(int)), this, SLOT(changed())); break; w = new QSpinBox(parent);
type = 2;
((QSpinBox *)w)->setRange(-0x7FFFFFFF, 0x7FFFFFFF);
connect((QSpinBox *)w, SIGNAL(valueChanged(int)), this, SLOT(changed()));
break;
#if QT_VERSION_MAJOR <= 5 #if QT_VERSION_MAJOR <= 5
case QVariant::UInt: case QVariant::UInt:
#else #else
case QMetaType::UInt: case QMetaType::UInt:
#endif #endif
w = new QSpinBox(parent); type = 3; ((QSpinBox*)w)->setRange(0, 0xFFFFFFFF); connect((QSpinBox*)w, SIGNAL(valueChanged(int)), this, SLOT(changed())); break; w = new QSpinBox(parent);
type = 3;
((QSpinBox *)w)->setRange(0, 0xFFFFFFFF);
connect((QSpinBox *)w, SIGNAL(valueChanged(int)), this, SLOT(changed()));
break;
#if QT_VERSION_MAJOR <= 5 #if QT_VERSION_MAJOR <= 5
case QVariant::LongLong: case QVariant::LongLong:
#else #else
case QMetaType::LongLong: case QMetaType::LongLong:
#endif #endif
w = new QSpinBox(parent); type = 4; ((QSpinBox*)w)->setRange(-0x7FFFFFFF, 0x7FFFFFFF); connect((QSpinBox*)w, SIGNAL(valueChanged(int)), this, SLOT(changed())); break; w = new QSpinBox(parent);
type = 4;
((QSpinBox *)w)->setRange(-0x7FFFFFFF, 0x7FFFFFFF);
connect((QSpinBox *)w, SIGNAL(valueChanged(int)), this, SLOT(changed()));
break;
#if QT_VERSION_MAJOR <= 5 #if QT_VERSION_MAJOR <= 5
case QVariant::ULongLong: case QVariant::ULongLong:
#else #else
case QMetaType::ULongLong: case QMetaType::ULongLong:
#endif #endif
w = new QSpinBox(parent); type = 5; ((QSpinBox*)w)->setRange(0, 0xFFFFFFFF); connect((QSpinBox*)w, SIGNAL(valueChanged(int)), this, SLOT(changed())); break; w = new QSpinBox(parent);
type = 5;
((QSpinBox *)w)->setRange(0, 0xFFFFFFFF);
connect((QSpinBox *)w, SIGNAL(valueChanged(int)), this, SLOT(changed()));
break;
#if QT_VERSION_MAJOR <= 5 #if QT_VERSION_MAJOR <= 5
case QVariant::Double: case QVariant::Double:
#else #else
case QMetaType::Double: case QMetaType::Double:
#endif #endif
w = new QDoubleSpinBox(parent); type = 6; ((QDoubleSpinBox*)w)->setRange(-999999999, 999999999); ((QDoubleSpinBox*)w)->setDecimals(3); connect((QDoubleSpinBox*)w, SIGNAL(valueChanged(double)), this, SLOT(changed())); break; w = new QDoubleSpinBox(parent);
type = 6;
((QDoubleSpinBox *)w)->setRange(-999999999, 999999999);
((QDoubleSpinBox *)w)->setDecimals(3);
connect((QDoubleSpinBox *)w, SIGNAL(valueChanged(double)), this, SLOT(changed()));
break;
#if QT_VERSION_MAJOR <= 5 #if QT_VERSION_MAJOR <= 5
case QVariant::Bool: case QVariant::Bool:
#else #else
case QMetaType::Bool: case QMetaType::Bool:
#endif #endif
w = new QCheckBox(parent); type = 7; ((QCheckBox*)w)->setChecked(value.toBool()); connect((QCheckBox*)w, SIGNAL(toggled(bool)), this, SLOT(changed())); break; w = new QCheckBox(parent);
type = 7;
((QCheckBox *)w)->setChecked(value.toBool());
connect((QCheckBox *)w, SIGNAL(toggled(bool)), this, SLOT(changed()));
break;
#if QT_VERSION_MAJOR <= 5 #if QT_VERSION_MAJOR <= 5
case QVariant::Color: case QVariant::Color:
#else #else
case QMetaType::QColor: case QMetaType::QColor:
#endif #endif
w = new ColorButton(parent); type = 8; ((ColorButton*)w)->setUseAlphaChannel(true); ((ColorButton*)w)->setColor(value.value<QColor>()); connect((ColorButton*)w, SIGNAL(colorChanged(QColor)), this, SLOT(changed())); break; w = new ColorButton(parent);
type = 8;
((ColorButton *)w)->setUseAlphaChannel(true);
((ColorButton *)w)->setColor(value.value<QColor>());
connect((ColorButton *)w, SIGNAL(colorChanged(QColor)), this, SLOT(changed()));
break;
#if QT_VERSION_MAJOR <= 5 #if QT_VERSION_MAJOR <= 5
case QVariant::Point: case QVariant::Point:
#else #else
case QMetaType::QPoint: case QMetaType::QPoint:
#endif #endif
w = new QPointEdit(parent); type = 9; ((QPointEdit*)w)->setDecimals(0); ((QPointEdit*)w)->setValue(QPointF(value.toPoint())); connect((QPointEdit*)w, SIGNAL(valueChanged(QPointF)), this, SLOT(changed())); break; w = new QPointEdit(parent);
type = 9;
((QPointEdit *)w)->setDecimals(0);
((QPointEdit *)w)->setValue(QPointF(value.toPoint()));
connect((QPointEdit *)w, SIGNAL(valueChanged(QPointF)), this, SLOT(changed()));
break;
#if QT_VERSION_MAJOR <= 5 #if QT_VERSION_MAJOR <= 5
case QVariant::PointF: case QVariant::PointF:
#else #else
case QMetaType::QPointF: case QMetaType::QPointF:
#endif #endif
w = new QPointEdit(parent); type = 10; ((QPointEdit*)w)->setDecimals(3); ((QPointEdit*)w)->setValue(value.toPointF()); connect((QPointEdit*)w, SIGNAL(valueChanged(QPointF)), this, SLOT(changed())); break; w = new QPointEdit(parent);
type = 10;
((QPointEdit *)w)->setDecimals(3);
((QPointEdit *)w)->setValue(value.toPointF());
connect((QPointEdit *)w, SIGNAL(valueChanged(QPointF)), this, SLOT(changed()));
break;
#if QT_VERSION_MAJOR <= 5 #if QT_VERSION_MAJOR <= 5
case QVariant::Rect: case QVariant::Rect:
#else #else
case QMetaType::QRect: case QMetaType::QRect:
#endif #endif
w = new QRectEdit(parent); type = 11; ((QRectEdit*)w)->setDecimals(0); ((QRectEdit*)w)->setValue(QRectF(value.toRect())); connect((QRectEdit*)w, SIGNAL(valueChanged(QRectF)), this, SLOT(changed())); break; w = new QRectEdit(parent);
type = 11;
((QRectEdit *)w)->setDecimals(0);
((QRectEdit *)w)->setValue(QRectF(value.toRect()));
connect((QRectEdit *)w, SIGNAL(valueChanged(QRectF)), this, SLOT(changed()));
break;
#if QT_VERSION_MAJOR <= 5 #if QT_VERSION_MAJOR <= 5
case QVariant::RectF: case QVariant::RectF:
#else #else
case QMetaType::QRectF: case QMetaType::QRectF:
#endif #endif
w = new QRectEdit(parent); type = 12; ((QRectEdit*)w)->setDecimals(3); ((QRectEdit*)w)->setValue(value.toRectF()); connect((QRectEdit*)w, SIGNAL(valueChanged(QRectF)), this, SLOT(changed())); break; w = new QRectEdit(parent);
type = 12;
((QRectEdit *)w)->setDecimals(3);
((QRectEdit *)w)->setValue(value.toRectF());
connect((QRectEdit *)w, SIGNAL(valueChanged(QRectF)), this, SLOT(changed()));
break;
#if QT_VERSION_MAJOR <= 5 #if QT_VERSION_MAJOR <= 5
case QVariant::String: default: case QVariant::String:
default:
#else #else
case QMetaType::QString: default: case QMetaType::QString:
default:
#endif #endif
w = new CLineEdit(parent); type = 1; ((CLineEdit*)w)->setDefaultText(value.toString()); connect((CLineEdit*)w, SIGNAL(textChanged(QString)), this, SLOT(changed())); break; w = new CLineEdit(parent);
type = 1;
((CLineEdit *)w)->setDefaultText(value.toString());
connect((CLineEdit *)w, SIGNAL(textChanged(QString)), this, SLOT(changed()));
break;
} }
} }
} }
@@ -148,7 +210,10 @@ void Delegate::setWidgetProperty(QWidget * w, const QVariant & value) const {
if (w == 0) return; if (w == 0) return;
switch (w->property("__type").toInt()) { switch (w->property("__type").toInt()) {
case 1: ((CLineEdit *)w)->setText(value.toString()); break; case 1: ((CLineEdit *)w)->setText(value.toString()); break;
case 2: case 3: case 4: case 5: ((QSpinBox*)w)->setValue(value.toInt()); break; case 2:
case 3:
case 4:
case 5: ((QSpinBox *)w)->setValue(value.toInt()); break;
case 6: ((QDoubleSpinBox *)w)->setValue(value.toDouble()); break; case 6: ((QDoubleSpinBox *)w)->setValue(value.toDouble()); break;
case 7: ((QCheckBox *)w)->setChecked(value.toBool()); break; case 7: ((QCheckBox *)w)->setChecked(value.toBool()); break;
case 8: ((ColorButton *)w)->setColor(value.value<QColor>()); break; case 8: ((ColorButton *)w)->setColor(value.value<QColor>()); break;
@@ -175,7 +240,10 @@ const QVariant Delegate::widgetProperty(QWidget * w) const {
case 10: return QVariant::fromValue<QPointF>(((QPointEdit *)w)->value()); break; case 10: return QVariant::fromValue<QPointF>(((QPointEdit *)w)->value()); break;
case 11: return QVariant::fromValue<QRect>(((QRectEdit *)w)->value().toRect()); break; case 11: return QVariant::fromValue<QRect>(((QRectEdit *)w)->value().toRect()); break;
case 12: return QVariant::fromValue<QRectF>(((QRectEdit *)w)->value()); break; case 12: return QVariant::fromValue<QRectF>(((QRectEdit *)w)->value()); break;
case 13: return QVariant::fromValue<PropertyValuePair>(PropertyValuePair(w->property("__prop").value<QMetaProperty>(), ((QComboBox*)w)->itemData(((QComboBox*)w)->currentIndex()))); break; case 13:
return QVariant::fromValue<PropertyValuePair>(
PropertyValuePair(w->property("__prop").value<QMetaProperty>(), ((QComboBox *)w)->itemData(((QComboBox *)w)->currentIndex())));
break;
default: return QVariant(); break; default: return QVariant(); break;
} }
return QVariant(); return QVariant();
@@ -183,8 +251,7 @@ const QVariant Delegate::widgetProperty(QWidget * w) const {
void Delegate::setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const { void Delegate::setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const {
if (index.data(Qt::UserRole + 1).toString() != "__flag") if (index.data(Qt::UserRole + 1).toString() != "__flag") model->setData(index, widgetProperty(editor), Qt::UserRole);
model->setData(index, widgetProperty(editor), Qt::UserRole);
} }
@@ -196,11 +263,18 @@ void Delegate::paint(QPainter * painter, const QStyleOptionViewItem & option, co
QStyleOptionComplex * soc = 0; QStyleOptionComplex * soc = 0;
QString text; QString text;
QRect rect; QRect rect;
QPalette::ColorRole role = (option.state.testFlag(QStyle::State_Selected) && option.state.testFlag(QStyle::State_Active) ? QPalette::HighlightedText : QPalette::WindowText); QPalette::ColorRole role =
(option.state.testFlag(QStyle::State_Selected) && option.state.testFlag(QStyle::State_Active) ? QPalette::HighlightedText
: QPalette::WindowText);
if (index.data(Qt::UserRole + 2).toString() == "__flags") { if (index.data(Qt::UserRole + 2).toString() == "__flags") {
text = "0x" + QString::number(value.toInt(), 16).toUpper(); text = "0x" + QString::number(value.toInt(), 16).toUpper();
style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), style->drawItemText(painter,
Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
Qt::AlignLeft | Qt::AlignVCenter,
option.palette,
true,
text,
role);
return; return;
} }
if (index.data(Qt::UserRole + 1) == "__flag") { if (index.data(Qt::UserRole + 1) == "__flag") {
@@ -210,7 +284,10 @@ void Delegate::paint(QPainter * painter, const QStyleOptionViewItem & option, co
so->rect = option.rect; so->rect = option.rect;
so->palette = option.palette; so->palette = option.palette;
so->fontMetrics = option.fontMetrics; so->fontMetrics = option.fontMetrics;
((QStyleOptionButton*)so)->state = (((value.toULongLong() & key) == key && key != 0) || (value.toULongLong() == 0 && key == 0) ? QStyle::State_On : QStyle::State_Off) | option.state; ((QStyleOptionButton *)so)->state =
(((value.toULongLong() & key) == key && key != 0) || (value.toULongLong() == 0 && key == 0) ? QStyle::State_On
: QStyle::State_Off) |
option.state;
((QStyleOptionButton *)so)->text = "0x" + QString::number(key, 16).toUpper(); ((QStyleOptionButton *)so)->text = "0x" + QString::number(key, 16).toUpper();
if (option.state.testFlag(QStyle::State_Selected)) if (option.state.testFlag(QStyle::State_Selected))
so->palette.setColor(QPalette::WindowText, so->palette.color(QPalette::HighlightedText)); so->palette.setColor(QPalette::WindowText, so->palette.color(QPalette::HighlightedText));
@@ -226,8 +303,13 @@ void Delegate::paint(QPainter * painter, const QStyleOptionViewItem & option, co
break; break;
} }
} }
style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), style->drawItemText(painter,
Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
Qt::AlignLeft | Qt::AlignVCenter,
option.palette,
true,
text,
role);
} }
} else { } else {
#if QT_VERSION_MAJOR <= 5 #if QT_VERSION_MAJOR <= 5
@@ -241,8 +323,13 @@ void Delegate::paint(QPainter * painter, const QStyleOptionViewItem & option, co
case QMetaType::Int: case QMetaType::Int:
#endif #endif
text.setNum(value.toInt()); text.setNum(value.toInt());
style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), style->drawItemText(painter,
Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
Qt::AlignLeft | Qt::AlignVCenter,
option.palette,
true,
text,
role);
break; break;
#if QT_VERSION_MAJOR <= 5 #if QT_VERSION_MAJOR <= 5
case QVariant::UInt: case QVariant::UInt:
@@ -250,8 +337,13 @@ void Delegate::paint(QPainter * painter, const QStyleOptionViewItem & option, co
case QMetaType::UInt: case QMetaType::UInt:
#endif #endif
text.setNum(value.toUInt()); text.setNum(value.toUInt());
style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), style->drawItemText(painter,
Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
Qt::AlignLeft | Qt::AlignVCenter,
option.palette,
true,
text,
role);
break; break;
#if QT_VERSION_MAJOR <= 5 #if QT_VERSION_MAJOR <= 5
case QVariant::LongLong: case QVariant::LongLong:
@@ -259,8 +351,13 @@ void Delegate::paint(QPainter * painter, const QStyleOptionViewItem & option, co
case QMetaType::LongLong: case QMetaType::LongLong:
#endif #endif
text.setNum(value.toLongLong()); text.setNum(value.toLongLong());
style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), style->drawItemText(painter,
Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
Qt::AlignLeft | Qt::AlignVCenter,
option.palette,
true,
text,
role);
break; break;
#if QT_VERSION_MAJOR <= 5 #if QT_VERSION_MAJOR <= 5
case QVariant::ULongLong: case QVariant::ULongLong:
@@ -268,8 +365,13 @@ void Delegate::paint(QPainter * painter, const QStyleOptionViewItem & option, co
case QMetaType::ULongLong: case QMetaType::ULongLong:
#endif #endif
text.setNum(value.toULongLong()); text.setNum(value.toULongLong());
style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), style->drawItemText(painter,
Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
Qt::AlignLeft | Qt::AlignVCenter,
option.palette,
true,
text,
role);
break; break;
#if QT_VERSION_MAJOR <= 5 #if QT_VERSION_MAJOR <= 5
case QVariant::Double: case QVariant::Double:
@@ -277,8 +379,13 @@ void Delegate::paint(QPainter * painter, const QStyleOptionViewItem & option, co
case QMetaType::Double: case QMetaType::Double:
#endif #endif
text.setNum(value.toDouble(), 'f', 3); text.setNum(value.toDouble(), 'f', 3);
style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), style->drawItemText(painter,
Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
Qt::AlignLeft | Qt::AlignVCenter,
option.palette,
true,
text,
role);
break; break;
#if QT_VERSION_MAJOR <= 5 #if QT_VERSION_MAJOR <= 5
case QVariant::Bool: case QVariant::Bool:
@@ -309,8 +416,13 @@ void Delegate::paint(QPainter * painter, const QStyleOptionViewItem & option, co
case QMetaType::QPoint: case QMetaType::QPoint:
#endif #endif
text = pointString(value.toPoint()); text = pointString(value.toPoint());
style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), style->drawItemText(painter,
Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
Qt::AlignLeft | Qt::AlignVCenter,
option.palette,
true,
text,
role);
break; break;
#if QT_VERSION_MAJOR <= 5 #if QT_VERSION_MAJOR <= 5
case QVariant::PointF: case QVariant::PointF:
@@ -318,8 +430,13 @@ void Delegate::paint(QPainter * painter, const QStyleOptionViewItem & option, co
case QMetaType::QPointF: case QMetaType::QPointF:
#endif #endif
text = pointString(value.toPointF()); text = pointString(value.toPointF());
style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), style->drawItemText(painter,
Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
Qt::AlignLeft | Qt::AlignVCenter,
option.palette,
true,
text,
role);
break; break;
#if QT_VERSION_MAJOR <= 5 #if QT_VERSION_MAJOR <= 5
case QVariant::Rect: case QVariant::Rect:
@@ -327,8 +444,13 @@ void Delegate::paint(QPainter * painter, const QStyleOptionViewItem & option, co
case QMetaType::QRect: case QMetaType::QRect:
#endif #endif
text = rectString(value.toRect()); text = rectString(value.toRect());
style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), style->drawItemText(painter,
Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
Qt::AlignLeft | Qt::AlignVCenter,
option.palette,
true,
text,
role);
break; break;
#if QT_VERSION_MAJOR <= 5 #if QT_VERSION_MAJOR <= 5
case QVariant::RectF: case QVariant::RectF:
@@ -336,16 +458,29 @@ void Delegate::paint(QPainter * painter, const QStyleOptionViewItem & option, co
case QMetaType::QRectF: case QMetaType::QRectF:
#endif #endif
text = rectString(value.toRectF()); text = rectString(value.toRectF());
style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), style->drawItemText(painter,
Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
Qt::AlignLeft | Qt::AlignVCenter,
option.palette,
true,
text,
role);
break; break;
#if QT_VERSION_MAJOR <= 5 #if QT_VERSION_MAJOR <= 5
case QVariant::String: default: case QVariant::String:
default:
#else #else
case QMetaType::QString: default: case QMetaType::QString:
default:
#endif #endif
style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, value.toString()), style->drawItemText(
Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, value.toString(), role); painter,
style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, value.toString()),
Qt::AlignLeft | Qt::AlignVCenter,
option.palette,
true,
value.toString(),
role);
break; break;
} }
} }
@@ -361,7 +496,6 @@ void Delegate::paint(QPainter * painter, const QStyleOptionViewItem & option, co
break;*/ break;*/
if (so != 0) delete so; if (so != 0) delete so;
if (soc != 0) delete soc; if (soc != 0) delete soc;
} }
@@ -390,14 +524,12 @@ void Delegate::changedFlag() {
for (int i = 0; i < chldr.size(); ++i) { for (int i = 0; i < chldr.size(); ++i) {
if (chldr[i] == cmi) continue; if (chldr[i] == cmi) continue;
// qDebug() << (chldr[i].data(Qt::UserRole).toULongLong() & cv); // qDebug() << (chldr[i].data(Qt::UserRole).toULongLong() & cv);
if (chldr[i].data(Qt::UserRole).toULongLong() & cv) if (chldr[i].data(Qt::UserRole).toULongLong() & cv) model->setData(chldr[i], false, Qt::UserRole + 3);
model->setData(chldr[i], false, Qt::UserRole + 3);
} }
} }
for (int i = 0; i < chldr.size(); ++i) { for (int i = 0; i < chldr.size(); ++i) {
// qDebug() << chldr[i].data(Qt::UserRole + 3).toBool(); // qDebug() << chldr[i].data(Qt::UserRole + 3).toBool();
if (chldr[i].data(Qt::UserRole + 3).toBool()) if (chldr[i].data(Qt::UserRole + 3).toBool()) val |= chldr[i].data(Qt::UserRole).toULongLong();
val |= chldr[i].data(Qt::UserRole).toULongLong();
} }
} }
for (int i = 0; i < chldr.size(); ++i) { for (int i = 0; i < chldr.size(); ++i) {
@@ -411,7 +543,6 @@ void Delegate::changedFlag() {
} }
PropertyEditor::PropertyEditor(QWidget * parent): QTreeWidget(parent) { PropertyEditor::PropertyEditor(QWidget * parent): QTreeWidget(parent) {
object = 0; object = 0;
active_ = false; active_ = false;
@@ -421,9 +552,7 @@ PropertyEditor::PropertyEditor(QWidget * parent): QTreeWidget(parent) {
} }
PropertyEditor::~PropertyEditor() { PropertyEditor::~PropertyEditor() {}
}
void PropertyEditor::changeEvent(QEvent * e) { void PropertyEditor::changeEvent(QEvent * e) {
@@ -446,7 +575,6 @@ void PropertyEditor::configTree() {
setHeaderLabels(lbls); setHeaderLabels(lbls);
setAlternatingRowColors(true); setAlternatingRowColors(true);
setItemDelegateForColumn(1, new Delegate()); setItemDelegateForColumn(1, new Delegate());
} }
@@ -528,8 +656,7 @@ void PropertyEditor::rebuild() {
ti->setData(1, Qt::UserRole, value); ti->setData(1, Qt::UserRole, value);
ti->setData(1, Qt::UserRole + 2, "__flags"); ti->setData(1, Qt::UserRole + 2, "__flags");
ti->setData(0, Qt::UserRole + 1, QVariant::fromValue<QMetaProperty>(props.back())); ti->setData(0, Qt::UserRole + 1, QVariant::fromValue<QMetaProperty>(props.back()));
} } else if (props.back().isEnumType())
else if (props.back().isEnumType())
value.setValue<PropertyValuePair>(PropertyValuePair(props.back(), value)); value.setValue<PropertyValuePair>(PropertyValuePair(props.back(), value));
// ti->setText(1, value.toString()); // ti->setText(1, value.toString());
ti->setData(1, Qt::UserRole, value); ti->setData(1, Qt::UserRole, value);
@@ -544,6 +671,4 @@ void PropertyEditor::rebuild() {
} }
void PropertyEditor::refresh() { void PropertyEditor::refresh() {}
}

View File

@@ -19,24 +19,30 @@
#ifndef PROPERTYEDITOR_H #ifndef PROPERTYEDITOR_H
#define PROPERTYEDITOR_H #define PROPERTYEDITOR_H
#include <QTreeWidget> #include <QDebug>
#include <QEvent>
#include <QHeaderView> #include <QHeaderView>
#include <QMetaProperty> #include <QMetaProperty>
#include <QEvent>
#include <QDebug>
#include <QStyledItemDelegate> #include <QStyledItemDelegate>
#include <QTreeWidget>
#include <qpiconfigwidget.h> #include <qpiconfigwidget.h>
class Delegate: public QStyledItemDelegate { class Delegate: public QStyledItemDelegate {
Q_OBJECT Q_OBJECT
public: public:
Delegate(QObject * parent = 0): QStyledItemDelegate() { ab = QBrush(QImage(":/icons/alpha.png")); } Delegate(QObject * parent = 0): QStyledItemDelegate() { ab = QBrush(QImage(":/icons/alpha.png")); }
QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const {cmi = const_cast<QModelIndex & >(index); return widgetForProperty(parent, index);} QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const {
cmi = const_cast<QModelIndex &>(index);
return widgetForProperty(parent, index);
}
void setEditorData(QWidget * editor, const QModelIndex & index) const { setWidgetProperty(editor, index.data(Qt::UserRole)); } void setEditorData(QWidget * editor, const QModelIndex & index) const { setWidgetProperty(editor, index.data(Qt::UserRole)); }
void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const; void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const;
void updateEditorGeometry(QWidget * editor, const QStyleOptionViewItem & option, const QModelIndex & index) const {editor->setGeometry(option.rect);} void updateEditorGeometry(QWidget * editor, const QStyleOptionViewItem & option, const QModelIndex & index) const {
editor->setGeometry(option.rect);
}
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const; void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const;
private: private:
@@ -45,10 +51,14 @@ private:
const QVariant widgetProperty(QWidget * w) const; const QVariant widgetProperty(QWidget * w) const;
QString pointString(const QPoint & p) const { return QString::number(p.x()) + " x " + QString::number(p.y()); } QString pointString(const QPoint & p) const { return QString::number(p.x()) + " x " + QString::number(p.y()); }
QString pointString(const QPointF & p) const { return QString::number(p.x()) + " x " + QString::number(p.y()); } QString pointString(const QPointF & p) const { return QString::number(p.x()) + " x " + QString::number(p.y()); }
QString rectString(const QRect & r) const {return QString::number(r.x()) + " x " + QString::number(r.y()) + " : " + QString rectString(const QRect & r) const {
QString::number(r.width()) + " x " + QString::number(r.height());} return QString::number(r.x()) + " x " + QString::number(r.y()) + " : " + QString::number(r.width()) + " x " +
QString rectString(const QRectF & r) const {return QString::number(r.x()) + " x " + QString::number(r.y()) + " : " + QString::number(r.height());
QString::number(r.width()) + " x " + QString::number(r.height());} }
QString rectString(const QRectF & r) const {
return QString::number(r.x()) + " x " + QString::number(r.y()) + " : " + QString::number(r.width()) + " x " +
QString::number(r.height());
}
QBrush ab; QBrush ab;
mutable QModelIndex cmi; mutable QModelIndex cmi;
@@ -56,7 +66,6 @@ private:
private slots: private slots:
void changed() { setModelData((QWidget *)sender(), const_cast<QAbstractItemModel *>(cmi.model()), cmi); } void changed() { setModelData((QWidget *)sender(), const_cast<QAbstractItemModel *>(cmi.model()), cmi); }
void changedFlag(); void changedFlag();
}; };
typedef QPair<QMetaProperty, QVariant> PropertyValuePair; typedef QPair<QMetaProperty, QVariant> PropertyValuePair;
@@ -67,19 +76,29 @@ Q_DECLARE_METATYPE (PropertyValuePair)
class PropertyEditor: public QTreeWidget { class PropertyEditor: public QTreeWidget {
Q_OBJECT Q_OBJECT
public: public:
explicit PropertyEditor(QWidget * parent = 0); explicit PropertyEditor(QWidget * parent = 0);
virtual ~PropertyEditor(); virtual ~PropertyEditor();
void assignObject(QObject * o) {object = o; rebuild();} void assignObject(QObject * o) {
object = o;
rebuild();
}
protected: protected:
void changeEvent(QEvent * e); void changeEvent(QEvent * e);
private: private:
void configTree(); void configTree();
void setItemBackColor(QTreeWidgetItem * i, const QColor & c) {i->setBackground(0, c); i->setBackground(1, c);} void setItemBackColor(QTreeWidgetItem * i, const QColor & c) {
void setItemForeColor(QTreeWidgetItem * i, const QColor & c) {i->setForeground(0, c); i->setForeground(1, c);} i->setBackground(0, c);
i->setBackground(1, c);
}
void setItemForeColor(QTreeWidgetItem * i, const QColor & c) {
i->setForeground(0, c);
i->setForeground(1, c);
}
void rebuild(); void rebuild();
void refresh(); void refresh();
@@ -91,7 +110,6 @@ private:
private slots: private slots:
void itemClicked(QTreeWidgetItem * item, int column); void itemClicked(QTreeWidgetItem * item, int column);
void itemChanged(QTreeWidgetItem * item, int column); void itemChanged(QTreeWidgetItem * item, int column);
}; };
#endif // PROPERTYEDITOR_H #endif // PROPERTYEDITOR_H

View File

@@ -17,13 +17,15 @@
*/ */
#include "scene_tree.h" #include "scene_tree.h"
#include "ui_scene_tree.h"
#include "glcamera.h" #include "glcamera.h"
#include "qglview.h" #include "qglview.h"
#include <QTreeWidget> #include "ui_scene_tree.h"
#include <QScrollBar>
#include <QAction> #include <QAction>
#include <QEvent> #include <QEvent>
#include <QScrollBar>
#include <QTreeWidget>
enum Column { enum Column {
cName, cName,
@@ -67,11 +69,15 @@ SceneTree::SceneTree(QWidget * parent): QWidget(parent) {
ui->treeObjects->addActions(actionsSelection()); ui->treeObjects->addActions(actionsSelection());
ui->treeObjects->addAction(newSeparator()); ui->treeObjects->addAction(newSeparator());
ui->treeObjects->addActions(actionsAdd()); ui->treeObjects->addActions(actionsAdd());
ui->buttonFilter->addActions(QList<QAction*>() << ui->actionFilter_node << ui->actionFilter_mesh << ui->actionFilter_light << ui->actionFilter_camera); ui->buttonFilter->addActions(QList<QAction *>()
<< ui->actionFilter_node << ui->actionFilter_mesh << ui->actionFilter_light << ui->actionFilter_camera);
view = 0; view = 0;
hidden_by_filter = obj_count = 0; hidden_by_filter = obj_count = 0;
block_tree = false; block_tree = false;
connect(ui->treeObjects->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(treeObjects_selectionCnahged())); connect(ui->treeObjects->selectionModel(),
SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
this,
SLOT(treeObjects_selectionCnahged()));
} }
@@ -102,12 +108,9 @@ QList<QAction *> SceneTree::actionsAdd() {
QList<QAction *> SceneTree::actionsSelection() { QList<QAction *> SceneTree::actionsSelection() {
QList<QAction *> ret; QList<QAction *> ret;
ret << ui->actionFocus << newSeparator() ret << ui->actionFocus << newSeparator() << ui->actionGroup << ui->actionClone << newSeparator() << ui->actionSelect_parent
<< ui->actionGroup << ui->actionClone << newSeparator() << ui->actionSelect_by_mesh << ui->actionSelect_by_material << newSeparator() << ui->actionTransfer_transform_to_children
<< ui->actionSelect_parent << ui->actionSelect_by_mesh << ui->actionSelect_by_material << newSeparator() << newSeparator() << ui->actionActive_camera << ui->actionDefault_camera << newSeparator() << ui->actionRemove;
<< ui->actionTransfer_transform_to_children << newSeparator()
<< ui->actionActive_camera << ui->actionDefault_camera << newSeparator()
<< ui->actionRemove;
return ret; return ret;
} }
@@ -129,8 +132,7 @@ void SceneTree::changeEvent(QEvent * e) {
void SceneTree::rememberExpanded(QTreeWidgetItem * ti) { void SceneTree::rememberExpanded(QTreeWidgetItem * ti) {
for (int i = 0; i < ti->childCount(); ++i) { for (int i = 0; i < ti->childCount(); ++i) {
QTreeWidgetItem * ci = ti->child(i); QTreeWidgetItem * ci = ti->child(i);
if (ci->isExpanded()) if (ci->isExpanded()) expanded_ << itemObject(ci);
expanded_ << itemObject(ci);
rememberExpanded(ci); rememberExpanded(ci);
} }
} }
@@ -153,8 +155,7 @@ void SceneTree::makeObjetTree(ObjectBase * o, QTreeWidgetItem * ti) {
ci->setText(cName, co->name()); ci->setText(cName, co->name());
ci->setCheckState(cVis, co->isVisible() ? Qt::Checked : Qt::Unchecked); ci->setCheckState(cVis, co->isVisible() ? Qt::Checked : Qt::Unchecked);
ci->setIcon(cVis, icon_vis[co->isVisible(true)]); ci->setIcon(cVis, icon_vis[co->isVisible(true)]);
if (co->material()) if (co->material()) ci->setText(cMaterial, co->material()->name);
ci->setText(cMaterial, co->material()->name);
ci->setFlags(ci->flags() | Qt::ItemIsEditable); ci->setFlags(ci->flags() | Qt::ItemIsEditable);
ObjectType t = otNode; ObjectType t = otNode;
switch (co->type()) { switch (co->type()) {
@@ -204,8 +205,7 @@ void SceneTree::selectionChanged() {
block_tree = true; block_tree = true;
QList<QTreeWidgetItem *> il = ui->treeObjects->findItems("", Qt::MatchContains | Qt::MatchRecursive); QList<QTreeWidgetItem *> il = ui->treeObjects->findItems("", Qt::MatchContains | Qt::MatchRecursive);
const ObjectBase * fo = 0; const ObjectBase * fo = 0;
if (view->selectedObjects().size() == 1) if (view->selectedObjects().size() == 1) fo = view->selectedObject();
fo = view->selectedObject();
foreach(QTreeWidgetItem * i, il) { foreach(QTreeWidgetItem * i, il) {
ObjectBase * o = itemObject(i); ObjectBase * o = itemObject(i);
i->setSelected(o->isSelected()); i->setSelected(o->isSelected());
@@ -222,8 +222,7 @@ void SceneTree::materialsChanged() {
foreach(QTreeWidgetItem * i, geo_items) { foreach(QTreeWidgetItem * i, geo_items) {
ObjectBase * o = itemObject(i); ObjectBase * o = itemObject(i);
if (!o) continue; if (!o) continue;
if (o->material()) if (o->material()) i->setText(cMaterial, o->material()->name);
i->setText(cMaterial, o->material()->name);
} }
} }
@@ -259,11 +258,12 @@ bool SceneTree::filterTree(QTreeWidgetItem * ti, const QString & filter, int typ
} else { } else {
f = f || cit.contains(filter, Qt::CaseInsensitive); f = f || cit.contains(filter, Qt::CaseInsensitive);
} }
if ((types & t) != t) if ((types & t) != t) f = false;
f = false;
ci->setHidden(!f); ci->setHidden(!f);
if (f) ret = true; if (f)
else ++hidden_by_filter; ret = true;
else
++hidden_by_filter;
} }
} }
return ret; return ret;
@@ -370,8 +370,7 @@ void SceneTree::on_treeObjects_itemMoved(QTreeWidgetItem * item, QTreeWidgetItem
view->scene()->rootObject()->addChild(co); view->scene()->rootObject()->addChild(co);
} else { } else {
ObjectBase * po = itemObject(new_parent); ObjectBase * po = itemObject(new_parent);
if (po) if (po) po->addChild(co);
po->addChild(co);
} }
} }
@@ -458,8 +457,7 @@ void SceneTree::on_actionSelect_parent_triggered() {
QSet<ObjectBase *> nsl; QSet<ObjectBase *> nsl;
foreach(ObjectBase * o, sol) { foreach(ObjectBase * o, sol) {
ObjectBase * po = o->parent(); ObjectBase * po = o->parent();
if (po != view->scene()->rootObject()) if (po != view->scene()->rootObject()) o = po;
o = po;
nsl << o; nsl << o;
} }
view->scene()->selectObjects(nsl.values()); view->scene()->selectObjects(nsl.values());

View File

@@ -19,19 +19,20 @@
#ifndef SCENE_TREE_H #ifndef SCENE_TREE_H
#define SCENE_TREE_H #define SCENE_TREE_H
#include <QWidget>
#include <QIcon>
#include "glscene.h" #include "glscene.h"
#include <QIcon>
#include <QWidget>
class QTreeWidgetItem; class QTreeWidgetItem;
namespace Ui { namespace Ui {
class SceneTree; class SceneTree;
} }
class SceneTree: public QWidget class SceneTree: public QWidget {
{
Q_OBJECT Q_OBJECT
public: public:
SceneTree(QWidget * parent = 0); SceneTree(QWidget * parent = 0);
~SceneTree(); ~SceneTree();
@@ -95,7 +96,6 @@ public slots:
signals: signals:
private: private:
}; };
#endif // SCENE_TREE_H #endif // SCENE_TREE_H

View File

@@ -19,15 +19,15 @@
#ifndef TREEWIDGET_H #ifndef TREEWIDGET_H
#define TREEWIDGET_H #define TREEWIDGET_H
#include <QTreeWidget>
#include <QDropEvent>
#include <QDebug> #include <QDebug>
#include <QTimer> #include <QDropEvent>
#include <QStyledItemDelegate> #include <QStyledItemDelegate>
#include <QTimer>
#include <QTreeWidget>
class InternalMoveTreeWidget: public QTreeWidget class InternalMoveTreeWidget: public QTreeWidget {
{
Q_OBJECT Q_OBJECT
public: public:
InternalMoveTreeWidget(QWidget * parent = 0): QTreeWidget(parent) {} InternalMoveTreeWidget(QWidget * parent = 0): QTreeWidget(parent) {}
@@ -46,7 +46,6 @@ protected:
signals: signals:
void itemMoved(QTreeWidgetItem * item, QTreeWidgetItem * new_parent, int new_index); void itemMoved(QTreeWidgetItem * item, QTreeWidgetItem * new_parent, int new_index);
}; };

View File

@@ -17,7 +17,9 @@
*/ */
#include "view_editor.h" #include "view_editor.h"
#include "ui_view_editor.h" #include "ui_view_editor.h"
#include <QFileDialog> #include <QFileDialog>
#include <colorbutton.h> #include <colorbutton.h>
#include <spinslider.h> #include <spinslider.h>
@@ -64,11 +66,8 @@ void ViewEditor::assignQGLView(QGLView * v) {
void ViewEditor::changeEvent(QEvent * e) { void ViewEditor::changeEvent(QEvent * e) {
QWidget::changeEvent(e); QWidget::changeEvent(e);
switch (e->type()) { switch (e->type()) {
case QEvent::LanguageChange: case QEvent::LanguageChange: ui->retranslateUi(this); break;
ui->retranslateUi(this); default: break;
break;
default:
break;
} }
} }
@@ -161,7 +160,6 @@ void ViewEditor::on_checkService_clicked(bool val) {
void ViewEditor::on_checkCameraLight_stateChanged(int s) { void ViewEditor::on_checkCameraLight_stateChanged(int s) {
if (!view || !active) return; if (!view || !active) return;
view->setCameraLightMode((QGLView::CameraLightMode)s); view->setCameraLightMode((QGLView::CameraLightMode)s);
} }
@@ -205,4 +203,3 @@ void ViewEditor::on_checkVSync_clicked(bool val) {
if (!view || !active) return; if (!view || !active) return;
view->setVSync(val); view->setVSync(val);
} }

View File

@@ -19,16 +19,17 @@
#ifndef VIEW_EDITOR_H #ifndef VIEW_EDITOR_H
#define VIEW_EDITOR_H #define VIEW_EDITOR_H
#include <QWidget>
#include "qglview.h" #include "qglview.h"
#include <QWidget>
namespace Ui { namespace Ui {
class ViewEditor; class ViewEditor;
} }
class ViewEditor: public QWidget class ViewEditor: public QWidget {
{
Q_OBJECT Q_OBJECT
public: public:
explicit ViewEditor(QWidget * parent = 0); explicit ViewEditor(QWidget * parent = 0);