git-svn-id: svn://db.shs.com.ru/libs@65 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -17,23 +17,27 @@
|
||||
*/
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "loader_qgl.h"
|
||||
#include "loader_ase.h"
|
||||
#include "loader_3ds.h"
|
||||
#include "loader_obj.h"
|
||||
#include "loader_dae.h"
|
||||
#include <QGraphicsRectItem>
|
||||
#include <QImageReader>
|
||||
#include <QMessageBox>
|
||||
|
||||
#define EARTH_H 6356863.019 // m
|
||||
#define EARTH_WL 6378245.000 // m
|
||||
|
||||
MainWindow::MainWindow(QWidget * parent): QMainWindow(parent), Ui::MainWindow() {
|
||||
setupUi(this);
|
||||
colorHalo->setColor(view->selectionHaloColor());
|
||||
icon_geo = QIcon(":/icons/type-geo.png");
|
||||
icon_camera = QIcon(":/icons/type-camera.png");
|
||||
icon_light = QIcon(":/icons/type-light.png");
|
||||
|
||||
sel_obj = 0;
|
||||
//spinSliderShine->setDecimals(2);
|
||||
view->camera().setAim(QVector3D());
|
||||
view->camera().setPos(QVector3D(2, 2, 2));
|
||||
view->setFrameShape(QFrame::NoFrame);
|
||||
view->setRenderer(new RendererDeferredShading(view));
|
||||
//view->setRenderer(new RendererSimple(view));
|
||||
view->setMouseRotateEnabled(true);
|
||||
view->setMouseSelectionEnabled(true);
|
||||
view->setSelectionHaloEnabled(true);
|
||||
@@ -43,130 +47,61 @@ MainWindow::MainWindow(QWidget * parent): QMainWindow(parent), Ui::MainWindow()
|
||||
view->setBackColor(Qt::lightGray);
|
||||
view->setDepthStart(1.);
|
||||
view->setDepthEnd(10000.);
|
||||
//view->setLightingMode(QGLView::PerPixel);
|
||||
/*MaterialEditor * o = new MaterialEditor();
|
||||
o->setWindowOpacity(.666);
|
||||
view->addObject(o, Qt::Window);*/
|
||||
/**obj = loadFrom3DSFile("data/test.3DS", 0.15);
|
||||
m.reflectivity = 1;
|
||||
m.reflection.loadPathesFromDirectory("data/e");
|
||||
obj->child("sphere001")->setMaterial(m);*/
|
||||
|
||||
spinFOV->setValue(view->FOV());
|
||||
spinDepthStart->setValue(view->depthStart());
|
||||
spinDepthEnd->setValue(view->depthEnd());
|
||||
groupHoverHalo->setChecked(view->isHoverHaloEnabled());
|
||||
groupSelectionHalo->setChecked(view->isSelectionHaloEnabled());
|
||||
spinHoverHaloFill->setValue(view->hoverHaloFillAlpha());
|
||||
spinSelectionHaloFill->setValue(view->selectionHaloFillAlpha());
|
||||
colorHoverHalo->setColor(view->hoverHaloColor());
|
||||
colorSelectionHalo->setColor(view->selectionHaloColor());
|
||||
checkFXAA->setChecked(view->isFeatureEnabled(QGLView::qglFXAA));
|
||||
checkMSAA->setChecked(view->isFeatureEnabled(QGLView::qglMSAA));
|
||||
colorBack->setColor(view->backColor());
|
||||
colorAmbient->setColor(view->ambientColor());
|
||||
checkCameraOrbit->setChecked(view->isCameraOrbit());
|
||||
|
||||
//m.shine = 40;
|
||||
//m.shine_strength = 1;
|
||||
//m.diffuse.bitmap_path = "celtic_010.jpg";
|
||||
//m.bump.bitmap_path = "celtic_010n.jpg";
|
||||
/*obj->child("cone")->setMaterial(m);
|
||||
m.diffuse.bitmap_path = "proj_plane_d.tga";
|
||||
m.bump.bitmap_path = "proj_plane_n.tga";
|
||||
obj->child("tor")->setMaterial(m);
|
||||
m.reflectivity = 1.;
|
||||
obj->child("sphere")->setMaterial(m);*/
|
||||
//obj->child("teapot")->setRenderMode(GLObjectBase::Point);
|
||||
//obj->child("teapot")->setLineWidth(2.);
|
||||
//obj->child("cone")->setRenderMode(GLObjectBase::Line);
|
||||
//view->camera().setAim(obj->child("sphere001")->pos());
|
||||
GLTextureManager::addSearchPath("data");
|
||||
GLTextureManager::addSearchPath("data/images");
|
||||
GLTextureManager::addSearchPath("data/SU-33_maps");
|
||||
obj = loadFromDAEFile("data/shadows.dae");//new GLPrimitiveEllipsoid(EARTH_WL / 1E+6, EARTH_WL / 1E+6, EARTH_H / 1E+6, 500, 500);//GLPrimitiveCube();
|
||||
//obj->setScale(0.1);
|
||||
//obj->child("Plane001")->material().map_specularity.color_amount = 0.95;
|
||||
//obj = new GLPrimitiveEllipsoid(100, 100, 100, 100, 100);//GLPrimitiveCube();
|
||||
for (int i = 0; i < obj->childCount(); ++i)
|
||||
if (obj->child(i)->type() == GLObjectBase::Light) {
|
||||
//((Light*)obj->child(i))->intensity = 1.5;
|
||||
//((Light*)obj->child(i))->decay_linear = .5;
|
||||
}
|
||||
view->addObject(obj);
|
||||
groupShadows->setChecked(view->isFeatureEnabled(QGLView::qglShadowsEnabled));
|
||||
groupEyeAccomodation->setChecked(view->isFeatureEnabled(QGLView::qglEyeAccomodationEnabled));
|
||||
groupBloom->setChecked(view->isFeatureEnabled(QGLView::qglBloomEnabled));
|
||||
groupMotionBlur->setChecked(view->isFeatureEnabled(QGLView::qglMotionBlurEnabled));
|
||||
groupReflections->setChecked(view->isFeatureEnabled(QGLView::qglDynamicReflectionsEnabled));
|
||||
checkSoftShadows->setChecked(view->isFeatureEnabled(QGLView::qglShadowsSoftEnabled));
|
||||
spinAccom->setValue(view->isFeatureEnabled(QGLView::qglEyeAccomodationTime));
|
||||
spinAccomMS->setValue(view->isFeatureEnabled(QGLView::qglEyeAccomodationMaxSpeed));
|
||||
spinCubemapSize->setValue(view->isFeatureEnabled(QGLView::qglDynamicReflectionsMapSize));
|
||||
spinShadowmapSize->setValue(view->isFeatureEnabled(QGLView::qglShadowsMapSize));
|
||||
spinMotionBlurFactor->setValue(view->isFeatureEnabled(QGLView::qglMotionBlurFactor));
|
||||
spinMotionBlurSteps->setValue(view->isFeatureEnabled(QGLView::qglMotionBlurSteps));
|
||||
spinBloomFactor->setValue(view->isFeatureEnabled(QGLView::qglBloomFactor));
|
||||
spinBloomRadius->setValue(view->isFeatureEnabled(QGLView::qglBloomRadius));
|
||||
spinBloomThreshold->setValue(view->isFeatureEnabled(QGLView::qglBloomThreshold));
|
||||
|
||||
//obj->setPos(1000000, -1000000, -10000000);
|
||||
//obj->child("Box001")->addChild(&(view->camera()));
|
||||
//obj->child("Box001")->VBO().translatePoints(QVector3D(20,30,40));
|
||||
view->camera().setPos(QVector3D(10, -20, 20));
|
||||
view->camera().setAim(obj->pos());
|
||||
view->camera().flyToDistance(500);
|
||||
|
||||
double al = 7.;
|
||||
axis = new GLObjectBase();
|
||||
GLObjectBase * obj;
|
||||
double al = 1.;
|
||||
obj = new GLPrimitiveLine(QVector3D(0, 0, -al), QVector3D(0, 0, al));
|
||||
obj->material().color_diffuse = Qt::darkBlue; obj->setAcceptLight(false);
|
||||
view->addObject(obj);
|
||||
axis->addChild(obj);
|
||||
obj = new GLPrimitiveLine(QVector3D(-al, 0, 0), QVector3D(al, 0, 0));
|
||||
obj->material().color_diffuse = Qt::darkRed; obj->setAcceptLight(false);
|
||||
view->addObject(obj);
|
||||
axis->addChild(obj);
|
||||
obj = new GLPrimitiveLine(QVector3D(0, -al, 0), QVector3D(0, al, 0));
|
||||
obj->material().color_diffuse = Qt::darkGreen; obj->setAcceptLight(false);
|
||||
view->addObject(obj);
|
||||
|
||||
double lat = deg2rad*(-85.), lng = deg2rad*(15.);
|
||||
obj = new GLPrimitiveLine(QVector3D(), QVector3D(cos(lng)*cos(lat), sin(lng)*cos(lat), sin(lat)/*(EARTH_H/EARTH_WL)*/)*5);
|
||||
view->addObject(obj);
|
||||
|
||||
//view->camera().setMode(Camera::AimMatrix);
|
||||
Light * l = new Light(view->camera().pos());
|
||||
/*l->light_type = Light::Cone;
|
||||
l->direction = QVector3D(1., 0.2, -0.2);
|
||||
l->angle_start = 0.;
|
||||
l->angle_end = 120.;*/
|
||||
l->intensity = 0.5;
|
||||
//l->decay_linear = 0.2;
|
||||
l->setName("camera");
|
||||
view->addObject(l);
|
||||
axis->addChild(obj);
|
||||
view->addObject(axis);
|
||||
|
||||
cam_light = new Light(view->camera().pos());
|
||||
cam_light->intensity = 0.5;
|
||||
cam_light->setName("camera");
|
||||
view->camera().addChild(cam_light);
|
||||
view->start(-1);
|
||||
//view->light(0)->light_type = Light::Omni;
|
||||
//obj = loadFrom3DSFile("34.3DS", 0.03);
|
||||
//view->addObject(obj);
|
||||
//view->camera().moveUp(5, true);
|
||||
|
||||
/**ps = new GLParticlesSystem(QVector3D(0,0,5));
|
||||
ps->setEmitterType(GLParticlesSystem::Box);
|
||||
ps->setBirthRate(5);
|
||||
ps->setSize(1.);
|
||||
ps->setLifeDuration(5.);
|
||||
ps->setInitialSpeed(.5);
|
||||
ps->setFadeTime(1.);
|
||||
ps->setSpeedDirectionJitter(1);
|
||||
//ps->setTextureScale(2, 2);
|
||||
ps->setAddVerticalFaceEnabled(true);
|
||||
ps->addForce(QVector3D(0,0,-0.98/20));*/
|
||||
//ps->material().diffuse.bitmap_path = "expl_07.png";
|
||||
//view->addObject(ps);
|
||||
|
||||
/**box = new GLPrimitiveCube();
|
||||
box->setSelectable(false);
|
||||
box->setRenderMode(GLObjectBase::Line);
|
||||
box->setLineWidth(2.);
|
||||
view->addObject(box);
|
||||
box->hide();*/
|
||||
//while (view->lightsCount() >= 5) view->removeLight(view->lightsCount() - 1);
|
||||
//view->addObject(box);
|
||||
|
||||
//obj = obj->clone(true);
|
||||
//obj->move(QVector3D(10,10,0));
|
||||
//view->addObject(obj);
|
||||
|
||||
//view->addObject(obj);
|
||||
//obj = obj->clone(true);
|
||||
//obj->move(QVector3D(10,10,0));
|
||||
//view->addObject(obj);
|
||||
/*int h = 0, dh = 360 / view->lights().size();
|
||||
foreach (Light * i, view->lights()) {
|
||||
i->setColor(QColor::fromHsv(h, 255, 255));
|
||||
i->intensity *= 2;
|
||||
h += dh;
|
||||
}*/
|
||||
startTimer(1000/60);
|
||||
|
||||
//connect(view, SIGNAL(hoverChanged(GLObjectBase*,GLObjectBase*)), this, SLOT(hoverChanged(GLObjectBase*,GLObjectBase*)));
|
||||
treeProperties->assignObject(view);
|
||||
connect(view, SIGNAL(selectionChanged(GLObjectBase*,GLObjectBase*)), this, SLOT(selectionChanged(GLObjectBase*,GLObjectBase*)));
|
||||
connect(view, SIGNAL(glInitializeDone()), this, SLOT(glInit()));
|
||||
connect(matEditor, SIGNAL(changed()), this, SLOT(materialChanged()));
|
||||
//view->addObject(new Light(view->camera().pos()));
|
||||
|
||||
//show();
|
||||
//comboBox->setCurrentIndex(2);
|
||||
}
|
||||
|
||||
|
||||
@@ -177,29 +112,18 @@ MainWindow::~MainWindow() {
|
||||
|
||||
void MainWindow::changeEvent(QEvent * e) {
|
||||
QMainWindow::changeEvent(e);
|
||||
/*if (e->type() == QEvent::LanguageChange) {
|
||||
if (e->type() == QEvent::LanguageChange) {
|
||||
retranslateUi(this);
|
||||
return;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::timerEvent(QTimerEvent * ) {
|
||||
static double t = 0.;
|
||||
if (checkCameraLight->isChecked())
|
||||
view->light(view->lightsCount() - 1)->setPos(view->camera().worldPos());
|
||||
//static double t = 0.;
|
||||
cam_light->setVisible(checkCameraLight->isChecked());
|
||||
//((RendererSimple*)(view->renderer()))->mpos = view->mapFromGlobal(QCursor::pos());
|
||||
//qDebug() << view->camera().angles();
|
||||
//cam_mat.rotate(e->y(), 0., 1., 0.);
|
||||
//view->camera().setTransform(cam_mat);
|
||||
|
||||
/*obj->child("tor")->rotateX(0.5);
|
||||
obj->child("tor")->rotateZ(0.1);
|
||||
obj->child("cone")->rotateZ(1);
|
||||
obj->child("teapot")->rotateY(sin(t));
|
||||
obj->child("sphere")->setPosZ(fabs(sin(t)*5)-0.75);*/
|
||||
t += 0.1;
|
||||
setWindowTitle(QString::number(view->currentFPS(), 'f', 2));
|
||||
statusBar()->showMessage(QString("FPS: %1").arg(QString::number(view->currentFPS(), 'f', 2)));
|
||||
}
|
||||
|
||||
|
||||
@@ -214,34 +138,47 @@ void MainWindow::on_view_glKeyPressEvent(QKeyEvent * e) {
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_view_glMouseMoveEvent(QMouseEvent * e) {
|
||||
cam_mat.rotate(e->x(), 0., 0., 1.);
|
||||
cam_mat.rotate(e->y(), 0., 1., 0.);
|
||||
view->camera().setTransform(cam_mat);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::glInit() {
|
||||
//view->bindTexture(QImage("e/bottom.jpg"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_pushButton_clicked() {
|
||||
//view->removeLight(view->lightsCount() - 1);
|
||||
//setWindowTitle(QString::number(view->lightsCount()));
|
||||
QVector3D wp = view->light(0)->worldPos();
|
||||
view->camera().setPos(wp);
|
||||
view->camera().setAim(wp + (view->light(0)->worldTransform() * QVector4D(view->light(0)->direction)).toVector3D()*100);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::loadFile(const QString & path) {
|
||||
prev_path = path;
|
||||
QCursor pcur = cursor();
|
||||
setCursor(Qt::WaitCursor);
|
||||
importFile(path);
|
||||
}
|
||||
|
||||
setCursor(pcur);
|
||||
|
||||
void MainWindow::importFile(const QString & path) {
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
QFileInfo fi(path);
|
||||
GLObjectBase * o = 0;
|
||||
if (fi.completeSuffix().toLower() == "qgl") o = loadFromQGLFile(path);
|
||||
if (fi.completeSuffix().toLower() == "ase") o = loadFromASEFile(path);
|
||||
if (fi.completeSuffix().toLower() == "3ds") o = loadFrom3DSFile(path);
|
||||
if (fi.completeSuffix().toLower() == "obj") o = loadFromOBJFile(path);
|
||||
if (fi.completeSuffix().toLower() == "dae") o = loadFromDAEFile(path);
|
||||
QApplication::restoreOverrideCursor();
|
||||
if (!o) {
|
||||
QMessageBox::critical(this, "Import", "Can`t load " + path + "!");
|
||||
return;
|
||||
}
|
||||
o->setName(fi.baseName());
|
||||
view->addObject(o);
|
||||
objectsTreeChanged();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::makeObjetTree(const GLObjectBase * o, QTreeWidgetItem * ti) {
|
||||
if (o == axis) return;
|
||||
for (int i = 0; i < o->childCount(); ++i) {
|
||||
const GLObjectBase * co = o->child(i);
|
||||
QTreeWidgetItem * ci = new QTreeWidgetItem(ti);
|
||||
ci->setText(0, co->name());
|
||||
ci->setData(0, Qt::UserRole, quintptr(co));
|
||||
switch (co->type()) {
|
||||
case GLObjectBase::glMesh: ci->setIcon(0, icon_geo); break;
|
||||
case GLObjectBase::glLight: ci->setIcon(0, icon_light); break;
|
||||
case GLObjectBase::glCamera: ci->setIcon(0, icon_camera); break;
|
||||
default: break;
|
||||
}
|
||||
makeObjetTree(co, ci);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -271,25 +208,62 @@ void MainWindow::materialChanged() {
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_pushButton_3_clicked() {
|
||||
QList<GLObjectBase * > ol = view->objects(true);
|
||||
qDebug() << ol.size();
|
||||
foreach (GLObjectBase * i, ol) {
|
||||
i->VBO().rebuffer();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_comboBox_currentIndexChanged(int val) {
|
||||
void MainWindow::on_comboRenderer_currentIndexChanged(int val) {
|
||||
GLRendererBase * pr = 0;
|
||||
switch (val) {
|
||||
case 0: view->setRenderer(new RendererSimple(view), &pr); break;
|
||||
case 2: view->setRenderer(new RendererDeferredShading(view), &pr); break;
|
||||
case 1: view->setRenderer(new RendererDeferredShading(view), &pr); break;
|
||||
}
|
||||
if (pr != 0) delete pr;
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_actionReset_triggered() {
|
||||
view->removeObject(axis, false);
|
||||
view->clearObjects(true);
|
||||
view->addObject(axis);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_actionImport_triggered() {
|
||||
QStringList fl = QFileDialog::getOpenFileNames(this, "Select files", prev_path, "Supported types(*.qgl *.ase *.3ds *.obj *.dae);;"
|
||||
"QGLView(*.qgl);;"
|
||||
"Ascii Scene Export(*.ase);;"
|
||||
"3D Studio(*.3ds);;"
|
||||
"Wavefront OBJ(*.obj);;"
|
||||
"Collada(*.dae)");
|
||||
if (fl.isEmpty()) return;
|
||||
prev_path = fl.back();
|
||||
foreach (QString f, fl)
|
||||
importFile(f);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_actionSave_triggered() {
|
||||
QString f = QFileDialog::getSaveFileName(this, "Select file", prev_path, "QGLView(*.qgl)");
|
||||
if (f.isEmpty()) return;
|
||||
if (f.right(4).toLower() != ".qgl")
|
||||
f += ".qgl";
|
||||
prev_path = f;
|
||||
view->removeObject(axis);
|
||||
saveToQGLFile(f, &(view->rootObject()));
|
||||
view->addObject(axis);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_actionOpen_triggered() {
|
||||
QString f = QFileDialog::getOpenFileName(this, "Select file", prev_path, "Supported types(*.qgl *.ase *.3ds *.obj *.dae);;"
|
||||
"QGLView(*.qgl);;"
|
||||
"Ascii Scene Export(*.ase);;"
|
||||
"3D Studio(*.3ds);;"
|
||||
"Wavefront OBJ(*.obj);;"
|
||||
"Collada(*.dae)");
|
||||
if (f.isEmpty()) return;
|
||||
prev_path = f;
|
||||
importFile(f);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_view_keyEvent(Qt::Key k, Qt::KeyboardModifiers m) {
|
||||
//qDebug() << k;
|
||||
double spd = 0.2;
|
||||
@@ -303,3 +277,33 @@ void MainWindow::on_view_keyEvent(Qt::Key k, Qt::KeyboardModifiers m) {
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_treeObjects_itemClicked(QTreeWidgetItem * ti, int col) {
|
||||
((GLObjectBase*)(ti->data(0, Qt::UserRole).toULongLong()))->select();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::objectsTreeChanged() {
|
||||
treeObjects->clear();
|
||||
makeObjetTree(&(view->rootObject()), treeObjects->invisibleRootItem());
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_pushButton_clicked() {
|
||||
//view->removeLight(view->lightsCount() - 1);
|
||||
//setWindowTitle(QString::number(view->lightsCount()));
|
||||
QVector3D wp = view->light(0)->worldPos();
|
||||
view->camera().setPos(wp);
|
||||
view->camera().setAim(wp + (view->light(0)->worldTransform() * QVector4D(view->light(0)->direction)).toVector3D()*100);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_pushButton_3_clicked() {
|
||||
QList<GLObjectBase * > ol = view->objects(true);
|
||||
qDebug() << ol.size();
|
||||
foreach (GLObjectBase * i, ol) {
|
||||
i->VBO().rebuffer();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user