lightpreview: reboot
- link against qbsp + vis + light + embree + tbb + fmt - remove .pro, .ui - setup filesystem watcher - accept .map files via dnd, run qbsp + light + vis
This commit is contained in:
parent
f14f327a9a
commit
d466deed91
|
|
@ -102,16 +102,16 @@ add_subdirectory(common)
|
|||
add_subdirectory(bspinfo)
|
||||
add_subdirectory(bsputil)
|
||||
add_subdirectory(light)
|
||||
|
||||
if (ENABLE_LIGHTPREVIEW)
|
||||
add_subdirectory(lightpreview)
|
||||
endif ()
|
||||
|
||||
add_subdirectory(qbsp)
|
||||
add_subdirectory(vis)
|
||||
|
||||
option(DISABLE_TESTS "Disables Tests" OFF)
|
||||
option(DISABLE_DOCS "Disables Docs" OFF)
|
||||
option(ENABLE_LIGHTPREVIEW "Enable light preview tool" OFF)
|
||||
|
||||
if (ENABLE_LIGHTPREVIEW)
|
||||
add_subdirectory(lightpreview)
|
||||
endif ()
|
||||
|
||||
if(NOT DISABLE_TESTS)
|
||||
# just creates testmaps.hh with absolute path to the testmaps source directory.
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ project (lightpreview CXX)
|
|||
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
|
||||
find_package(Qt5Widgets)
|
||||
|
||||
|
|
@ -11,10 +10,29 @@ add_executable(lightpreview
|
|||
mainwindow.cpp
|
||||
mainwindow.h
|
||||
glview.cpp
|
||||
glview.h
|
||||
${QBSP_SOURCES})
|
||||
glview.h)
|
||||
|
||||
target_link_libraries(lightpreview Qt5::Widgets)
|
||||
find_package(embree 3.0 REQUIRED)
|
||||
INCLUDE_DIRECTORIES(${EMBREE_INCLUDE_DIRS})
|
||||
|
||||
# HACK: Windows embree .dll's from https://github.com/embree/embree/releases ship with a tbb12.dll
|
||||
# and we need to copy it from the embree/bin directory to our light.exe/testlight.exe dir in order for them to run
|
||||
find_file(EMBREE_TBB_DLL tbb12.dll
|
||||
"${EMBREE_ROOT_DIR}/bin"
|
||||
NO_DEFAULT_PATH)
|
||||
if (NOT EMBREE_TBB_DLL STREQUAL EMBREE_TBB_DLL-NOTFOUND)
|
||||
message(STATUS "Found embree EMBREE_TBB_DLL: ${EMBREE_TBB_DLL}")
|
||||
endif()
|
||||
|
||||
target_link_libraries(lightpreview
|
||||
Qt5::Widgets
|
||||
libqbsp
|
||||
liblight
|
||||
libvis
|
||||
common
|
||||
TBB::tbb
|
||||
TBB::tbbmalloc
|
||||
fmt::fmt)
|
||||
|
||||
# from: http://stackoverflow.com/questions/40564443/copying-qt-dlls-to-executable-directory-on-windows-using-cmake
|
||||
# Copy Qt DLL's to bin directory for debugging
|
||||
|
|
@ -25,6 +43,17 @@ add_custom_command(
|
|||
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:Qt5::Core> $<TARGET_FILE_DIR:lightpreview>
|
||||
)
|
||||
|
||||
# HACK: copy .dll dependencies
|
||||
add_custom_command(TARGET lightpreview POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:embree>" "$<TARGET_FILE_DIR:lightpreview>"
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:TBB::tbb>" "$<TARGET_FILE_DIR:lightpreview>"
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:TBB::tbbmalloc>" "$<TARGET_FILE_DIR:lightpreview>"
|
||||
)
|
||||
if (NOT EMBREE_TBB_DLL STREQUAL EMBREE_TBB_DLL-NOTFOUND)
|
||||
add_custom_command(TARGET lightpreview POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${EMBREE_TBB_DLL}" "$<TARGET_FILE_DIR:lightpreview>")
|
||||
endif()
|
||||
|
||||
# Install Qt DLL's
|
||||
install(FILES $<TARGET_FILE:Qt5::Widgets> DESTINATION bin)
|
||||
install(FILES $<TARGET_FILE:Qt5::Gui> DESTINATION bin)
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ See file, 'COPYING', for details.
|
|||
#include <QTime>
|
||||
#include <fmt/core.h>
|
||||
|
||||
#include <common/bspfile.hh>
|
||||
|
||||
GLView::GLView(QWidget *parent)
|
||||
: QOpenGLWidget(parent),
|
||||
m_keysPressed(0),
|
||||
|
|
@ -236,3 +238,5 @@ void GLView::timerEvent(QTimerEvent *event)
|
|||
|
||||
update(); // schedule a repaint
|
||||
}
|
||||
|
||||
void GLView::renderBSP(const mbsp_t &bsp) { }
|
||||
|
|
@ -38,6 +38,8 @@ enum class keys_t : uint32_t
|
|||
left = 8
|
||||
};
|
||||
|
||||
struct mbsp_t;
|
||||
|
||||
class GLView : public QOpenGLWidget, protected QOpenGLFunctions
|
||||
{
|
||||
private:
|
||||
|
|
@ -67,6 +69,8 @@ public:
|
|||
GLView(QWidget *parent = nullptr);
|
||||
~GLView();
|
||||
|
||||
void renderBSP(const mbsp_t &bsp);
|
||||
|
||||
protected:
|
||||
void initializeGL() override;
|
||||
void paintGL() override;
|
||||
|
|
|
|||
|
|
@ -1,33 +0,0 @@
|
|||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2017-03-20T13:10:04
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
TARGET = lightpreview
|
||||
TEMPLATE = app
|
||||
|
||||
# The following define makes your compiler emit warnings if you use
|
||||
# any feature of Qt which as been marked as deprecated (the exact warnings
|
||||
# depend on your compiler). Please consult the documentation of the
|
||||
# deprecated API in order to know how to port your code away from it.
|
||||
DEFINES += QT_DEPRECATED_WARNINGS
|
||||
|
||||
# You can also make your code fail to compile if you use deprecated APIs.
|
||||
# In order to do so, uncomment the following line.
|
||||
# You can also select to disable deprecated APIs only up to a certain version of Qt.
|
||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||
|
||||
|
||||
SOURCES += main.cpp\
|
||||
mainwindow.cpp \
|
||||
glview.cpp
|
||||
|
||||
HEADERS += mainwindow.h \
|
||||
glview.h
|
||||
|
||||
FORMS += mainwindow.ui
|
||||
|
|
@ -18,16 +18,130 @@ See file, 'COPYING', for details.
|
|||
*/
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
#include <QDragEnterEvent>
|
||||
#include <QMimeData>
|
||||
#include <QFileSystemWatcher>
|
||||
|
||||
#include <common/bspfile.hh>
|
||||
#include <qbsp/qbsp.hh>
|
||||
#include <vis/vis.hh>
|
||||
#include <light/light.hh>
|
||||
|
||||
#include "glview.h"
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent),
|
||||
ui(new Ui::MainWindow)
|
||||
: QMainWindow(parent)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
resize(640, 480);
|
||||
glView = new GLView();
|
||||
this->setCentralWidget(glView);
|
||||
|
||||
setAcceptDrops(true);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
MainWindow::~MainWindow() { }
|
||||
|
||||
void MainWindow::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
delete ui;
|
||||
if (event->mimeData()->hasUrls())
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
|
||||
void MainWindow::dropEvent(QDropEvent *event)
|
||||
{
|
||||
auto urls = event->mimeData()->urls();
|
||||
if (!urls.empty()) {
|
||||
const QUrl &url = urls[0];
|
||||
if (url.isLocalFile()) {
|
||||
loadFile(url.toLocalFile());
|
||||
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::loadFile(const QString &file)
|
||||
{
|
||||
qDebug() << "load " << file;
|
||||
|
||||
if (m_watcher) {
|
||||
delete m_watcher;
|
||||
}
|
||||
m_watcher = new QFileSystemWatcher(this);
|
||||
|
||||
// start watching it
|
||||
qDebug() << "adding path: " << m_watcher->addPath(file);
|
||||
connect(m_watcher, &QFileSystemWatcher::fileChanged, this,
|
||||
[](const QString &path) { qDebug() << "got change notif for " << path; });
|
||||
|
||||
loadFileInternal(file);
|
||||
}
|
||||
|
||||
std::filesystem::path MakeFSPath(const QString &string)
|
||||
{
|
||||
return std::filesystem::path{string.toStdU16String()};
|
||||
}
|
||||
|
||||
static bspdata_t QbspVisLight_Common(const std::filesystem::path &name, std::vector<std::string> extra_qbsp_args,
|
||||
std::vector<std::string> extra_light_args, bool run_vis)
|
||||
{
|
||||
auto bsp_path = name;
|
||||
bsp_path.replace_extension(".bsp");
|
||||
|
||||
std::vector<std::string> args{
|
||||
"", // the exe path, which we're ignoring in this case
|
||||
};
|
||||
for (auto &extra : extra_qbsp_args) {
|
||||
args.push_back(extra);
|
||||
}
|
||||
args.push_back(name.string());
|
||||
|
||||
// run qbsp
|
||||
|
||||
InitQBSP(args);
|
||||
ProcessFile();
|
||||
|
||||
// run vis
|
||||
if (run_vis) {
|
||||
std::vector<std::string> vis_args{
|
||||
"", // the exe path, which we're ignoring in this case
|
||||
};
|
||||
vis_args.push_back(name.string());
|
||||
vis_main(vis_args);
|
||||
}
|
||||
|
||||
// run light
|
||||
{
|
||||
std::vector<std::string> light_args{
|
||||
"", // the exe path, which we're ignoring in this case
|
||||
};
|
||||
for (auto &arg : extra_light_args) {
|
||||
light_args.push_back(arg);
|
||||
}
|
||||
light_args.push_back(name.string());
|
||||
|
||||
light_main(light_args);
|
||||
}
|
||||
|
||||
// serialize obj
|
||||
{
|
||||
bspdata_t bspdata;
|
||||
LoadBSPFile(bsp_path, &bspdata);
|
||||
|
||||
ConvertBSPFormat(&bspdata, &bspver_generic);
|
||||
|
||||
return std::move(bspdata);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::loadFileInternal(const QString &file)
|
||||
{
|
||||
qDebug() << "loadFileInternal " << file;
|
||||
|
||||
auto d = QbspVisLight_Common(MakeFSPath(file), {}, {}, true);
|
||||
|
||||
const auto &bsp = std::get<mbsp_t>(d.bsp);
|
||||
|
||||
glView->renderBSP(bsp);
|
||||
}
|
||||
|
|
@ -21,19 +21,29 @@ See file, 'COPYING', for details.
|
|||
|
||||
#include <QMainWindow>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class MainWindow;
|
||||
}
|
||||
class GLView;
|
||||
class QFileSystemWatcher;
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
QFileSystemWatcher *m_watcher = nullptr;
|
||||
QString m_mapFile;
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
|
||||
protected:
|
||||
void dragEnterEvent(QDragEnterEvent *event) override;
|
||||
void dropEvent(QDropEvent *event) override;
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
void loadFile(const QString &file);
|
||||
void loadFileInternal(const QString &file);
|
||||
|
||||
private:
|
||||
GLView *glView;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,80 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>499</width>
|
||||
<height>423</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="GLView" name="glView"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menuBar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>499</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
<property name="title">
|
||||
<string>File</string>
|
||||
</property>
|
||||
<addaction name="actionOpen"/>
|
||||
</widget>
|
||||
<addaction name="menuFile"/>
|
||||
</widget>
|
||||
<widget class="QToolBar" name="mainToolBar">
|
||||
<attribute name="toolBarArea">
|
||||
<enum>TopToolBarArea</enum>
|
||||
</attribute>
|
||||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusBar"/>
|
||||
<action name="actionOpen">
|
||||
<property name="text">
|
||||
<string>Open</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+O</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>GLView</class>
|
||||
<extends>QOpenGLWidget</extends>
|
||||
<header>glview.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Loading…
Reference in New Issue