From 45fd6ac588be35c3aec49737ced30e87418230ec Mon Sep 17 00:00:00 2001 From: Jonathan Date: Sun, 21 May 2023 22:39:00 -0400 Subject: [PATCH] lightpreview: render bmodels --- lightpreview/glview.cpp | 51 ++++++++++++++++++++++++++++--------- lightpreview/glview.h | 3 ++- lightpreview/mainwindow.cpp | 6 ++--- 3 files changed, 44 insertions(+), 16 deletions(-) diff --git a/lightpreview/glview.cpp b/lightpreview/glview.cpp index 8f2b3edb..c49ded51 100644 --- a/lightpreview/glview.cpp +++ b/lightpreview/glview.cpp @@ -176,7 +176,7 @@ void GLView::setCamera(const qvec3d &origin, const qvec3d &fwd) m_cameraFwd = { (float) fwd[0], (float) fwd[1], (float) fwd[2] }; } -void GLView::renderBSP(const QString &file, const mbsp_t &bsp) +void GLView::renderBSP(const QString &file, const mbsp_t &bsp, const std::vector &entities) { // FIXME: move to a lightpreview_settings settings::common_settings settings; @@ -213,20 +213,47 @@ void GLView::renderBSP(const QString &file, const mbsp_t &bsp) lightmap_texture->setMinificationFilter(QOpenGLTexture::Linear); } - auto &m = bsp.dmodels[0]; - // collect faces grouped by texture name std::map> faces_by_texname; - for (int i = m.firstface; i < m.firstface + m.numfaces; ++i) { - auto &f = bsp.dfaces[i]; - std::string t = Face_TextureName(&bsp, &f); - // FIXME: keep empty texture names? - if (t.empty()) - continue; - if (f.numedges < 3) - continue; - faces_by_texname[t].push_back(&f); + // collect entity bmodels + for (int mi = 0; mi < bsp.dmodels.size(); mi++) + { + qvec3d origin {}; + + if (mi != 0) + { + // find matching entity + std::string modelStr = fmt::format("*{}", mi); + bool found = false; + + for (auto &ent : entities) + { + if (ent.get("model") == modelStr) + { + found = true; + ent.get_vector("origin", origin); + break; + } + } + + if (!found) + continue; + } + + auto &m = bsp.dmodels[mi]; + + for (int i = m.firstface; i < m.firstface + m.numfaces; ++i) { + auto &f = bsp.dfaces[i]; + std::string t = Face_TextureName(&bsp, &f); + // FIXME: keep empty texture names? + if (t.empty()) + continue; + if (f.numedges < 3) + continue; + faces_by_texname[t].push_back(&f); + } + } // populate the vertex/index buffers diff --git a/lightpreview/glview.h b/lightpreview/glview.h index e3e0dad9..65eb76ad 100644 --- a/lightpreview/glview.h +++ b/lightpreview/glview.h @@ -33,6 +33,7 @@ See file, 'COPYING', for details. #include #include +#include enum class keys_t : uint32_t { @@ -94,7 +95,7 @@ public: GLView(QWidget *parent = nullptr); ~GLView(); - void renderBSP(const QString &file, const mbsp_t &bsp); + void renderBSP(const QString &file, const mbsp_t &bsp, const std::vector &entities); void setCamera(const qvec3d &origin, const qvec3d &fwd); protected: diff --git a/lightpreview/mainwindow.cpp b/lightpreview/mainwindow.cpp index cee20d11..0e28b131 100644 --- a/lightpreview/mainwindow.cpp +++ b/lightpreview/mainwindow.cpp @@ -234,12 +234,12 @@ void MainWindow::loadFileInternal(const QString &file, bool is_reload) const auto &bsp = std::get(d.bsp); - glView->renderBSP(file, bsp); + auto ents = EntData_Parse(bsp); + + glView->renderBSP(file, bsp, ents); if (!is_reload) { - auto ents = EntData_Parse(bsp); - for (auto &ent : ents) { if (ent.get("classname") == "info_player_start")