1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-22 10:22:52 +01:00
openrw/rwviewer/views/ModelViewer.cpp
Daniel Evans 6f9c3db52e Overahaul of rwviewer to simplify the code and improve usability
- Shared ViewerWidget has been removed. Now multiple instances exist
2018-01-27 21:44:18 +00:00

58 lines
1.5 KiB
C++

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