1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-09 20:32:43 +01:00
openrw/rwviewer/views/ModelViewer.cpp

59 lines
1.5 KiB
C++
Raw Normal View History

2015-04-13 02:48:29 +02:00
#include "ModelViewer.hpp"
#include <QDebug>
#include <engine/Animator.hpp>
2016-09-09 22:13:21 +02:00
#include <fstream>
2015-04-27 03:09:56 +02:00
#include <objects/GameObject.hpp>
#include <platform/FileHandle.hpp>
2016-09-09 22:13:21 +02:00
#include <widgets/ModelFramesWidget.hpp>
#include "ViewerWidget.hpp"
2015-04-13 02:48:29 +02:00
ModelViewer::ModelViewer(QWidget* parent, Qt::WindowFlags f)
2017-01-08 20:46:00 +01:00
: ViewerInterface(parent, f), viewing(nullptr) {
2016-09-09 22:13:21 +02:00
mainSplit = new QSplitter;
mainLayout = new QVBoxLayout;
2015-04-13 02:48:29 +02:00
2016-09-09 22:13:21 +02:00
frames = new ModelFramesWidget;
frames->setMaximumWidth(300);
2015-04-13 02:48:29 +02:00
viewerWidget = createViewer();
viewerWidget->setMode(ViewerWidget::Mode::Model);
2016-09-09 22:13:21 +02:00
mainSplit->addWidget(frames);
mainSplit->addWidget(QWidget::createWindowContainer(viewerWidget));
2016-09-09 22:13:21 +02:00
mainLayout->addWidget(mainSplit);
2015-04-13 02:48:29 +02:00
setLayout(mainLayout);
2015-04-13 02:48:29 +02:00
}
void ModelViewer::showModel(ClumpPtr model) {
2016-09-09 22:13:21 +02:00
viewing = model;
viewerWidget->showModel(model);
2017-01-08 20:46:00 +01:00
frames->setModel(model);
}
2016-09-09 22:13:21 +02:00
void ModelViewer::showObject(uint16_t object) {
auto def = world()->data->modelinfo[object].get();
if (!def) {
return;
}
2016-09-09 22:13:21 +02:00
auto modelName = def->name + ".dff";
auto textureName = def->name + ".txd";
auto textures = world()->data->loadTextureArchive(textureName);
2016-09-09 22:13:21 +02:00
LoaderDFF dffLoader;
dffLoader.setTextureLookupCallback(
[&](const std::string& texture, const std::string&) {
return textures.at(texture);
});
2016-09-09 22:13:21 +02:00
auto file = world()->data->index.openFile(modelName);
if (!file.data) {
RW_ERROR("Couldn't load " << modelName);
return;
2016-09-09 22:13:21 +02:00
}
showModel(dffLoader.loadFromMemory(file));
}