1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-09-15 06:52:34 +02: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;
}
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;
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

View File

@ -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()) );
}
}

View File

@ -4,9 +4,11 @@
#include <QMouseEvent>
#include <engine/GameObject.hpp>
#include <engine/Animator.hpp>
#include <QFileDialog>
#include <algorithm>
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) {

View File

@ -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);

View File

@ -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()));