1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-09-03 17:19:46 +02:00

Frame information

This commit is contained in:
Daniel Evans 2014-02-12 06:42:07 +00:00
parent 8c25712ea6
commit 1b9687dedd
10 changed files with 197 additions and 11 deletions

View File

@ -51,6 +51,9 @@ public:
glm::mat4 getMatrix() const glm::mat4 getMatrix() const
{ return (parentFrame? parentFrame->getMatrix() : glm::mat4()) * matrix; } { return (parentFrame? parentFrame->getMatrix() : glm::mat4()) * matrix; }
ModelFrame* getParent() const
{ return parentFrame; }
const std::vector<ModelFrame*>& getChildren() const const std::vector<ModelFrame*>& getChildren() const
{ return childs; } { return childs; }

View File

@ -8,7 +8,9 @@ add_executable(rwviewer
ViewerWindow.cpp ViewerWindow.cpp
ViewerWidget.cpp ViewerWidget.cpp
IMGArchiveModel.cpp IMGArchiveModel.cpp
ArchiveContentsWidget.cpp) ArchiveContentsWidget.cpp
DFFFramesTreeModel.cpp
ModelFramesWidget.cpp)
include_directories(../rwengine/include /usr/include/bullet) include_directories(../rwengine/include /usr/include/bullet)

View File

@ -0,0 +1,78 @@
#include "DFFFramesTreeModel.hpp"
#include <render/Model.hpp>
DFFFramesTreeModel::DFFFramesTreeModel(Model* m, QObject* parent)
: QAbstractItemModel(parent), model(m)
{
}
int DFFFramesTreeModel::columnCount(const QModelIndex& parent) const
{
return 1;
}
int DFFFramesTreeModel::rowCount(const QModelIndex& parent) const
{
ModelFrame* f = static_cast<ModelFrame*>(parent.internalPointer());
if(f) {
return f->getChildren().size();
}
if(parent.row() == -1) {
return 1;
}
return 0;
}
QModelIndex DFFFramesTreeModel::index(int row, int column, const QModelIndex& parent) const
{
if(parent.row() == -1 && parent.column() == -1) {
return createIndex(row, column, model->frames[model->rootFrameIdx]);
}
ModelFrame* f = static_cast<ModelFrame*>(parent.internalPointer());
ModelFrame* p = f->getChildren()[row];
return createIndex(row, column, p);
}
QModelIndex DFFFramesTreeModel::parent(const QModelIndex& child) const
{
ModelFrame* c = static_cast<ModelFrame*>(child.internalPointer());
if(c->getParent()) {
auto cp = c->getParent();
if(cp->getParent()) {
for(int i = 0; i < cp->getParent()->getChildren().size(); ++i) {
if(cp->getParent()->getChildren()[i] == c->getParent()) {
return createIndex(i, 0, c->getParent());
}
}
}
else {
return createIndex(0,0, cp);
}
}
return QModelIndex();
}
QVariant DFFFramesTreeModel::data(const QModelIndex& index, int role) const
{
ModelFrame* f = static_cast<ModelFrame*>(index.internalPointer());
if(role == Qt::DisplayRole) {
if(index.column() == 0) {
return QString(f->getName().c_str());
}
}
return QVariant();
}
QVariant DFFFramesTreeModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if(orientation == Qt::Horizontal) {
if(role == Qt::DisplayRole) {
return "Name";
}
}
return QVariant();
}

View File

@ -0,0 +1,27 @@
#pragma once
#ifndef _DFFFRAMESTREEMODEL_HPP_
#define _DFFFRAMESTREEMODEL_HPP_
#include <QAbstractItemModel>
class Model;
class DFFFramesTreeModel : public QAbstractItemModel
{
Model* model;
public:
explicit DFFFramesTreeModel(Model* m, QObject* parent = 0);
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
virtual QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const;
virtual QModelIndex parent(const QModelIndex& child) const;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
};
#endif

View File

@ -0,0 +1,26 @@
#include "ModelFramesWidget.hpp"
ModelFramesWidget::ModelFramesWidget(QWidget* parent, Qt::WindowFlags flags)
: QDockWidget(parent, flags), gmodel(nullptr), framemodel(nullptr)
{
setWindowTitle("Frames");
tree = new QTreeView;
setWidget(tree);
}
void ModelFramesWidget::setModel(Model* model)
{
if(framemodel) {
delete framemodel;
framemodel = nullptr;
tree->setModel(nullptr);
}
gmodel = model;
if(model != nullptr) {
framemodel = new DFFFramesTreeModel(model, this);
tree->setModel(framemodel);
}
else {
tree->setDisabled(true);
}
}

View File

@ -0,0 +1,23 @@
#pragma once
#ifndef _MODELFRAMESWIDGET_HPP_
#define _MODELFRAMESWIDGET_HPP_
#include <QDockWidget>
#include <QTreeView>
#include "DFFFramesTreeModel.hpp"
class Model;
class ModelFramesWidget : public QDockWidget
{
Q_OBJECT
Model* gmodel;
DFFFramesTreeModel* framemodel;
QTreeView* tree;
public:
ModelFramesWidget(QWidget* parent = 0, Qt::WindowFlags flags = 0);
void setModel(Model* model);
};
#endif

View File

@ -4,7 +4,7 @@
#include <QMouseEvent> #include <QMouseEvent>
ViewerWidget::ViewerWidget(QWidget* parent, const QGLWidget* shareWidget, Qt::WindowFlags f) ViewerWidget::ViewerWidget(QWidget* parent, const QGLWidget* shareWidget, Qt::WindowFlags f)
: QGLWidget(parent, shareWidget, f), gworld(nullptr), currentModel(nullptr), : QGLWidget(parent, shareWidget, f), gworld(nullptr), cmodel(nullptr),
viewDistance(1.f), dragging(false), fm(ViewerWidget::UNK) viewDistance(1.f), dragging(false), fm(ViewerWidget::UNK)
{ {
} }
@ -42,7 +42,7 @@ void ViewerWidget::paintGL()
r.camera.frustum.fov = 60.f; r.camera.frustum.fov = 60.f;
r.camera.frustum.aspectRatio = width()/(height()*1.f); r.camera.frustum.aspectRatio = width()/(height()*1.f);
if(currentModel) { if(cmodel) {
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glm::mat4 m; glm::mat4 m;
@ -64,7 +64,7 @@ void ViewerWidget::paintGL()
glUniformMatrix4fv(r.uniView, 1, GL_FALSE, glm::value_ptr(view)); glUniformMatrix4fv(r.uniView, 1, GL_FALSE, glm::value_ptr(view));
glUniformMatrix4fv(r.uniProj, 1, GL_FALSE, glm::value_ptr(proj)); glUniformMatrix4fv(r.uniProj, 1, GL_FALSE, glm::value_ptr(proj));
gworld->renderer.renderModel(currentModel, m); gworld->renderer.renderModel(cmodel, m);
} }
} }
@ -75,7 +75,7 @@ GameWorld* ViewerWidget::world()
void ViewerWidget::showFile(const QString& file) void ViewerWidget::showFile(const QString& file)
{ {
currentModel = nullptr; cmodel = nullptr;
currentFile = file; currentFile = file;
QString low = file.toLower(); QString low = file.toLower();
if(low.endsWith("dff")) { if(low.endsWith("dff")) {
@ -96,10 +96,10 @@ void ViewerWidget::showDFF(const QString& file)
auto mit = gworld->gameData.models.find(basename.toStdString()); auto mit = gworld->gameData.models.find(basename.toStdString());
if(mit != gworld->gameData.models.end()) { if(mit != gworld->gameData.models.end()) {
// TODO better error handling // TODO better error handling
currentModel = mit->second; cmodel = mit->second;
float radius = 0.f; float radius = 0.f;
for(auto& g for(auto& g
: currentModel->geometries) { : cmodel->geometries) {
radius = std::max( radius = std::max(
radius, radius,
glm::length(g->geometryBounds.center)+g->geometryBounds.radius); glm::length(g->geometryBounds.center)+g->geometryBounds.radius);
@ -115,6 +115,16 @@ void ViewerWidget::showTXD(const QString& file)
fm = ViewerWidget::TXD; fm = ViewerWidget::TXD;
} }
Model* ViewerWidget::currentModel() const
{
return cmodel;
}
ViewerWidget::FileMode ViewerWidget::fileMode() const
{
return fm;
}
void ViewerWidget::mousePressEvent(QMouseEvent* e) void ViewerWidget::mousePressEvent(QMouseEvent* e)
{ {
dragging = true; dragging = true;

View File

@ -16,7 +16,7 @@ class ViewerWidget : public QGLWidget
QTimer timer; QTimer timer;
GameWorld* gworld; GameWorld* gworld;
Model* currentModel; Model* cmodel;
float viewDistance; float viewDistance;
glm::vec2 viewAngles; glm::vec2 viewAngles;
@ -38,6 +38,10 @@ public:
virtual void paintGL(); virtual void paintGL();
FileMode fileMode() const;
Model* currentModel() const;
GameWorld* world(); GameWorld* world();
public slots: public slots:

View File

@ -2,6 +2,7 @@
#include <engine/GameWorld.hpp> #include <engine/GameWorld.hpp>
#include "ViewerWidget.hpp" #include "ViewerWidget.hpp"
#include "ArchiveContentsWidget.hpp" #include "ArchiveContentsWidget.hpp"
#include "ModelFramesWidget.hpp"
#include <QMenuBar> #include <QMenuBar>
#include <QFileDialog> #include <QFileDialog>
#include <QApplication> #include <QApplication>
@ -20,6 +21,10 @@ ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags): QMainWindow(
archivewidget->setObjectName("archivewidget"); archivewidget->setObjectName("archivewidget");
this->addDockWidget(Qt::LeftDockWidgetArea, archivewidget); this->addDockWidget(Qt::LeftDockWidgetArea, archivewidget);
frameswidget = new ModelFramesWidget;
frameswidget->setObjectName("frameswidget");
this->addDockWidget(Qt::RightDockWidgetArea, frameswidget);
QMenuBar* mb = this->menuBar(); QMenuBar* mb = this->menuBar();
QMenu* file = mb->addMenu("&File"); QMenu* file = mb->addMenu("&File");
file->addAction("Open &Archive", this, SLOT(openArchive())); file->addAction("Open &Archive", this, SLOT(openArchive()));
@ -33,7 +38,7 @@ ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags): QMainWindow(
file->addAction("E&xit", QApplication::instance(), SLOT(quit()), QKeySequence::Quit); file->addAction("E&xit", QApplication::instance(), SLOT(quit()), QKeySequence::Quit);
connect(archivewidget, SIGNAL(selectedFileChanged(QString)), viewer, SLOT(showFile(QString))); connect(archivewidget, SIGNAL(selectedFileChanged(QString)), viewer, SLOT(showFile(QString)));
connect(viewer, SIGNAL(fileOpened(QString)), SLOT(updateTitle(QString))); connect(viewer, SIGNAL(fileOpened(QString)), SLOT(openFileChanged(QString)));
QSettings settings("OpenRW", "rwviewer"); QSettings settings("OpenRW", "rwviewer");
restoreGeometry(settings.value("geometry").toByteArray()); restoreGeometry(settings.value("geometry").toByteArray());
@ -83,9 +88,15 @@ void ViewerWindow::openArchive()
} }
} }
void ViewerWindow::updateTitle(const QString& name) void ViewerWindow::openFileChanged(const QString& name)
{ {
setWindowTitle(name); setWindowTitle(name);
if(viewer->fileMode() == ViewerWidget::DFF) {
frameswidget->setModel(viewer->currentModel());
}
else {
frameswidget->setModel(nullptr);
}
} }
void ViewerWindow::openRecent() void ViewerWindow::openRecent()

View File

@ -3,6 +3,7 @@
#define _VIEWERWINDOW_HPP_ #define _VIEWERWINDOW_HPP_
#include <QMainWindow> #include <QMainWindow>
class ModelFramesWidget;
class ArchiveContentsWidget; class ArchiveContentsWidget;
class ViewerWidget; class ViewerWidget;
class ViewerWindow : public QMainWindow class ViewerWindow : public QMainWindow
@ -11,6 +12,7 @@ class ViewerWindow : public QMainWindow
ViewerWidget* viewer; ViewerWidget* viewer;
ArchiveContentsWidget* archivewidget; ArchiveContentsWidget* archivewidget;
ModelFramesWidget* frameswidget;
public: public:
ViewerWindow(QWidget* parent = 0, Qt::WindowFlags flags = 0); ViewerWindow(QWidget* parent = 0, Qt::WindowFlags flags = 0);
@ -22,10 +24,10 @@ public:
public slots: public slots:
void openArchive(); void openArchive();
void updateTitle(const QString& name);
private slots: private slots:
void openFileChanged(const QString& name);
void openRecent(); void openRecent();
private: private: