diff --git a/lightpreview/glview.cpp b/lightpreview/glview.cpp index 4aca21b7..c34afbd9 100644 --- a/lightpreview/glview.cpp +++ b/lightpreview/glview.cpp @@ -311,6 +311,11 @@ void GLView::setDrawFlat(bool drawflat) update(); } +void GLView::setKeepOrigin(bool keeporigin) +{ + m_keepOrigin = keeporigin; +} + void GLView::takeScreenshot(int w, int h) { // update aspect ratio @@ -345,7 +350,7 @@ void GLView::takeScreenshot(int w, int h) update(); } -void GLView::renderBSP(const QString &file, const mbsp_t &bsp, const std::vector &entities) +void GLView::renderBSP(const QString &file, const mbsp_t &bsp, const bspxentries_t &bspx, const std::vector &entities) { // FIXME: move to a lightpreview_settings settings::common_settings settings; @@ -357,7 +362,7 @@ void GLView::renderBSP(const QString &file, const mbsp_t &bsp, const std::vector img::load_textures(&bsp, settings); // build lightmap atlas - auto atlas = build_lightmap_atlas(bsp, bspxentries_t{}, false, false); + auto atlas = build_lightmap_atlas(bsp, bspx, false, true); // NOTE: according to https://doc.qt.io/qt-6/qopenglwidget.html#resource-initialization-and-cleanup // we can only do this after `initializeGL()` has run once. @@ -441,6 +446,11 @@ void GLView::renderBSP(const QString &file, const mbsp_t &bsp, const std::vector // determine opacity float opacity = 1.0f; if (bsp.loadversion->game->id == GAME_QUAKE_II) { + + if (texinfo->flags.native & (Q2_SURF_NODRAW | Q2_SURF_SKY)) { + continue; + } + if (texinfo->flags.native & Q2_SURF_TRANS33) { opacity = 0.33f; } diff --git a/lightpreview/glview.h b/lightpreview/glview.h index c46622e8..7ff020dc 100644 --- a/lightpreview/glview.h +++ b/lightpreview/glview.h @@ -34,6 +34,7 @@ See file, 'COPYING', for details. #include #include #include +#include enum class keys_t : uint32_t { @@ -77,6 +78,7 @@ private: bool m_drawNormals = false; bool m_showTris = false; bool m_drawFlat = false; + bool m_keepOrigin = false; QOpenGLVertexArrayObject m_vao; QOpenGLBuffer m_vbo; @@ -113,13 +115,15 @@ public: GLView(QWidget *parent = nullptr); ~GLView(); - void renderBSP(const QString &file, const mbsp_t &bsp, const std::vector &entities); + void renderBSP(const QString &file, const mbsp_t &bsp, const bspxentries_t &bspx, const std::vector &entities); void setCamera(const qvec3d &origin, const qvec3d &fwd); void setLighmapOnly(bool lighmapOnly); void setFullbright(bool fullbright); void setDrawNormals(bool drawnormals); void setShowTris(bool showtris); void setDrawFlat(bool drawflat); + void setKeepOrigin(bool keeporigin); + const bool &getKeepOrigin() const { return m_keepOrigin; } void takeScreenshot(int w, int h); diff --git a/lightpreview/mainwindow.cpp b/lightpreview/mainwindow.cpp index 619bd629..08d3eb0e 100644 --- a/lightpreview/mainwindow.cpp +++ b/lightpreview/mainwindow.cpp @@ -80,12 +80,15 @@ MainWindow::MainWindow(QWidget *parent) auto *showtris = new QCheckBox(tr("Show Tris")); + auto *keepposition = new QCheckBox(tr("Keep Camera Pos")); + formLayout->addRow(tr("qbsp"), qbsp_options); formLayout->addRow(vis_checkbox, vis_options); formLayout->addRow(tr("light"), light_options); formLayout->addRow(reload_button); formLayout->addRow(rendermode_group); formLayout->addRow(showtris); + formLayout->addRow(keepposition); auto *form = new QWidget(); form->setLayout(formLayout); @@ -114,6 +117,7 @@ MainWindow::MainWindow(QWidget *parent) connect(normals, &QAbstractButton::toggled, this, [=](bool checked) { glView->setDrawNormals(checked); }); connect(showtris, &QAbstractButton::toggled, this, [=](bool checked) { glView->setShowTris(checked); }); connect(drawflat, &QAbstractButton::toggled, this, [=](bool checked) { glView->setDrawFlat(checked); }); + connect(keepposition, &QAbstractButton::toggled, this, [=](bool checked) { glView->setKeepOrigin(checked); }); setupMenu(); } @@ -286,6 +290,8 @@ void MainWindow::reload() void MainWindow::loadFileInternal(const QString &file, bool is_reload) { + qDebug() << "loadFileInternal " << file; + // persist settings QSettings s; s.setValue("qbsp_options", qbsp_options->text()); @@ -298,19 +304,43 @@ void MainWindow::loadFileInternal(const QString &file, bool is_reload) setWindowTitle(QFileInfo(file).fileName() + " - lightpreview"); fs::path fs_path = MakeFSPath(file); + + bspdata_t d; - qDebug() << "loadFileInternal " << file; + if (fs_path.extension().compare(".bsp") == 0) { - auto d = QbspVisLight_Common( - fs_path, ParseArgs(qbsp_options), ParseArgs(vis_options), ParseArgs(light_options), vis_checkbox->isChecked()); + LoadBSPFile(fs_path, &d); + + auto opts = ParseArgs(light_options); + + std::vector argPtrs; + + for (const std::string &arg : opts) { + argPtrs.push_back(arg.data()); + } + + settings::common_settings settings; + + settings.preinitialize(argPtrs.size(), argPtrs.data()); + settings.initialize(argPtrs.size(), argPtrs.data()); + settings.postinitialize(argPtrs.size(), argPtrs.data()); + + d.version->game->init_filesystem(fs_path, settings); + + ConvertBSPFormat(&d, &bspver_generic); + + } else { + d = QbspVisLight_Common( + fs_path, ParseArgs(qbsp_options), ParseArgs(vis_options), ParseArgs(light_options), vis_checkbox->isChecked()); + } const auto &bsp = std::get(d.bsp); auto ents = EntData_Parse(bsp); - glView->renderBSP(file, bsp, ents); + glView->renderBSP(file, bsp, d.bspx.entries, ents); - if (!is_reload) { + if (!is_reload && !glView->getKeepOrigin()) { for (auto &ent : ents) { if (ent.get("classname") == "info_player_start") { qvec3d origin;