1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-07 03:12:36 +01:00

Add model export to rwviewer

This commit is contained in:
Daniel Evans 2014-06-10 00:46:48 +01:00
parent e060b6d0b1
commit 229e8627d2
6 changed files with 49 additions and 5 deletions

View File

@ -68,3 +68,8 @@ QVariant ItemListModel::headerData(int section, Qt::Orientation orientation, int
} }
return QVariant::Invalid; 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();
}

View File

@ -11,13 +11,13 @@ class ItemListModel : public QAbstractTableModel
GameWorld* _world; GameWorld* _world;
qint16 getIDOf(unsigned int row ) const;
public: public:
explicit ItemListModel(GameWorld* _world, QObject *parent = 0); explicit ItemListModel(GameWorld* _world, QObject *parent = 0);
GameWorld* world() const { return _world; } GameWorld* world() const { return _world; }
qint16 getIDOf(unsigned int row ) const;
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const; virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
virtual int columnCount(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 data(const QModelIndex& index, int role = Qt::DisplayRole) const;
virtual QVariant headerData(int section, Qt::Orientation orientation, 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 #endif // ITEMLISTMODEL_HPP

View File

@ -15,6 +15,7 @@ ItemListWidget::ItemListWidget(QWidget* parent, Qt::WindowFlags flags)
table = new QTableView(); table = new QTableView();
layout->addWidget(searchbox); layout->addWidget(searchbox);
layout->addWidget(table); layout->addWidget(table);
table->setSelectionBehavior(QAbstractItemView::SelectRows);
intermediate->setLayout(layout); intermediate->setLayout(layout);
setWidget(intermediate); setWidget(intermediate);
@ -36,7 +37,7 @@ void ItemListWidget::selectedIndexChanged(const QModelIndex& current)
{ {
auto mts = filter->mapToSource(current); auto mts = filter->mapToSource(current);
if( mts.isValid() ) { if( mts.isValid() ) {
emit selectedItemChanged( current.internalId() ); emit selectedItemChanged( model->getIDOf(mts.row()) );
} }
} }

View File

@ -4,9 +4,11 @@
#include <QMouseEvent> #include <QMouseEvent>
#include <engine/GameObject.hpp> #include <engine/GameObject.hpp>
#include <engine/Animator.hpp> #include <engine/Animator.hpp>
#include <QFileDialog>
#include <algorithm>
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), dummyObject(nullptr), : QGLWidget(parent, shareWidget, f), gworld(nullptr), dummyObject(nullptr), currentObjectID(0),
cmodel(nullptr), canimation(nullptr), viewDistance(1.f), dragging(false) cmodel(nullptr), canimation(nullptr), viewDistance(1.f), dragging(false)
{ {
} }
@ -81,6 +83,7 @@ GameWorld* ViewerWidget::world()
void ViewerWidget::showItem(qint16 item) void ViewerWidget::showItem(qint16 item)
{ {
currentObjectID = item;
// TODO: actually show items. // 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 ModelHandle* ViewerWidget::currentModel() const
{ {
return cmodel; return cmodel;
@ -105,8 +132,11 @@ void ViewerWidget::setGamePath(const std::string &path)
{ {
if( gworld ) delete gworld; if( gworld ) delete gworld;
gworld = new GameWorld(path); 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(); for(auto it = gworld->gameData.ideLocations.begin();
it != gworld->gameData.ideLocations.end(); it != gworld->gameData.ideLocations.end();
++it) { ++it) {

View File

@ -18,6 +18,7 @@ class ViewerWidget : public QGLWidget
GameWorld* gworld; GameWorld* gworld;
GameObject* dummyObject; GameObject* dummyObject;
quint16 currentObjectID;
ModelHandle* cmodel; ModelHandle* cmodel;
Animation* canimation; Animation* canimation;
@ -50,6 +51,8 @@ public slots:
void showAnimation(Animation* anim); void showAnimation(Animation* anim);
void exportModel();
signals: signals:
void dataLoaded(GameWorld* world); void dataLoaded(GameWorld* world);

View File

@ -48,6 +48,9 @@ ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags): QMainWindow(
ex->setShortcut(QKeySequence::Quit); ex->setShortcut(QKeySequence::Quit);
connect(ex, SIGNAL(triggered()), QApplication::instance(), SLOT(closeAllWindows())); 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"); QMenu* anim = mb->addMenu("&Animation");
anim->addAction("Load &Animations", this, SLOT(openAnimations())); anim->addAction("Load &Animations", this, SLOT(openAnimations()));