From 229e8627d259989f9d60a023d478636c12e05f1c Mon Sep 17 00:00:00 2001 From: Daniel Evans Date: Tue, 10 Jun 2014 00:46:48 +0100 Subject: [PATCH] Add model export to rwviewer --- rwviewer/ItemListModel.cpp | 5 +++++ rwviewer/ItemListModel.hpp | 6 ++++-- rwviewer/ItemListWidget.cpp | 3 ++- rwviewer/ViewerWidget.cpp | 34 ++++++++++++++++++++++++++++++++-- rwviewer/ViewerWidget.hpp | 3 +++ rwviewer/ViewerWindow.cpp | 3 +++ 6 files changed, 49 insertions(+), 5 deletions(-) diff --git a/rwviewer/ItemListModel.cpp b/rwviewer/ItemListModel.cpp index 0e5cfd83..56bbb254 100644 --- a/rwviewer/ItemListModel.cpp +++ b/rwviewer/ItemListModel.cpp @@ -68,3 +68,8 @@ QVariant ItemListModel::headerData(int section, Qt::Orientation orientation, int } return QVariant::Invalid; } + +QModelIndex ItemListModel::index(int row, int column, const QModelIndex &parent) const +{ + return hasIndex(row, column, parent) ? createIndex(row, column, getIDOf(row)) : QModelIndex(); +} diff --git a/rwviewer/ItemListModel.hpp b/rwviewer/ItemListModel.hpp index 385058d7..3acb6f43 100644 --- a/rwviewer/ItemListModel.hpp +++ b/rwviewer/ItemListModel.hpp @@ -11,13 +11,13 @@ class ItemListModel : public QAbstractTableModel GameWorld* _world; - qint16 getIDOf(unsigned int row ) const; - public: explicit ItemListModel(GameWorld* _world, QObject *parent = 0); GameWorld* world() const { return _world; } + qint16 getIDOf(unsigned int row ) const; + virtual int rowCount(const QModelIndex& parent = QModelIndex()) const; virtual int columnCount(const QModelIndex& parent = QModelIndex()) const; @@ -25,6 +25,8 @@ public: virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; + + QModelIndex index(int row, int column, const QModelIndex &parent) const; }; #endif // ITEMLISTMODEL_HPP diff --git a/rwviewer/ItemListWidget.cpp b/rwviewer/ItemListWidget.cpp index f045daf8..a84b073d 100644 --- a/rwviewer/ItemListWidget.cpp +++ b/rwviewer/ItemListWidget.cpp @@ -15,6 +15,7 @@ ItemListWidget::ItemListWidget(QWidget* parent, Qt::WindowFlags flags) table = new QTableView(); layout->addWidget(searchbox); layout->addWidget(table); + table->setSelectionBehavior(QAbstractItemView::SelectRows); intermediate->setLayout(layout); setWidget(intermediate); @@ -36,7 +37,7 @@ void ItemListWidget::selectedIndexChanged(const QModelIndex& current) { auto mts = filter->mapToSource(current); if( mts.isValid() ) { - emit selectedItemChanged( current.internalId() ); + emit selectedItemChanged( model->getIDOf(mts.row()) ); } } diff --git a/rwviewer/ViewerWidget.cpp b/rwviewer/ViewerWidget.cpp index be84e6c1..22b53357 100644 --- a/rwviewer/ViewerWidget.cpp +++ b/rwviewer/ViewerWidget.cpp @@ -4,9 +4,11 @@ #include #include #include +#include +#include ViewerWidget::ViewerWidget(QWidget* parent, const QGLWidget* shareWidget, Qt::WindowFlags f) -: QGLWidget(parent, shareWidget, f), gworld(nullptr), dummyObject(nullptr), +: QGLWidget(parent, shareWidget, f), gworld(nullptr), dummyObject(nullptr), currentObjectID(0), cmodel(nullptr), canimation(nullptr), viewDistance(1.f), dragging(false) { } @@ -81,6 +83,7 @@ GameWorld* ViewerWidget::world() void ViewerWidget::showItem(qint16 item) { + currentObjectID = item; // TODO: actually show items. } @@ -96,6 +99,30 @@ void ViewerWidget::showAnimation(Animation *anim) } } +void ViewerWidget::exportModel() +{ + QString toSv = QFileDialog::getSaveFileName(this, + "Export Model", + QDir::homePath(), + "Model (*.DFF)"); + + if( toSv.size() == 0 ) return; + + auto it = world()->objectTypes.find(currentObjectID); + if( it != world()->objectTypes.end() ) { + for( auto& archive : world()->gameData.archives ) { + for(size_t i = 0; i < archive.second.getAssetCount(); ++i) { + auto& assetI = archive.second.getAssetInfoByIndex(i); + std::string q(assetI.name); + std::transform(q.begin(), q.end(), q.begin(), ::tolower); + if( q.find(it->second->modelName) != q.npos ) { + archive.second.saveAsset(q, toSv.toStdString()); + } + } + } + } +} + ModelHandle* ViewerWidget::currentModel() const { return cmodel; @@ -105,8 +132,11 @@ void ViewerWidget::setGamePath(const std::string &path) { if( gworld ) delete gworld; gworld = new GameWorld(path); - gworld->gameData.load(); + gworld->gameData.loadIMG("/models/gta3"); + gworld->gameData.loadIMG("/models/txd"); + + gworld->gameData.load(); for(auto it = gworld->gameData.ideLocations.begin(); it != gworld->gameData.ideLocations.end(); ++it) { diff --git a/rwviewer/ViewerWidget.hpp b/rwviewer/ViewerWidget.hpp index 8927c6d0..fad7a6f8 100644 --- a/rwviewer/ViewerWidget.hpp +++ b/rwviewer/ViewerWidget.hpp @@ -18,6 +18,7 @@ class ViewerWidget : public QGLWidget GameWorld* gworld; GameObject* dummyObject; + quint16 currentObjectID; ModelHandle* cmodel; Animation* canimation; @@ -50,6 +51,8 @@ public slots: void showAnimation(Animation* anim); + void exportModel(); + signals: void dataLoaded(GameWorld* world); diff --git a/rwviewer/ViewerWindow.cpp b/rwviewer/ViewerWindow.cpp index 7ca30fe6..b88a10a3 100644 --- a/rwviewer/ViewerWindow.cpp +++ b/rwviewer/ViewerWindow.cpp @@ -48,6 +48,9 @@ ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags): QMainWindow( ex->setShortcut(QKeySequence::Quit); connect(ex, SIGNAL(triggered()), QApplication::instance(), SLOT(closeAllWindows())); + QMenu* data = mb->addMenu("&Data"); + data->addAction("Export &Model", viewer, SLOT(exportModel())); + QMenu* anim = mb->addMenu("&Animation"); anim->addAction("Load &Animations", this, SLOT(openAnimations()));