2015-04-13 02:48:29 +02:00
|
|
|
#include "ModelViewer.hpp"
|
2016-04-16 15:06:02 +02:00
|
|
|
#include <QDebug>
|
2015-04-13 02:48:29 +02:00
|
|
|
#include <widgets/ModelFramesWidget.hpp>
|
2015-04-14 02:06:50 +02:00
|
|
|
#include <data/Skeleton.hpp>
|
2016-04-16 15:06:02 +02:00
|
|
|
#include <engine/Animator.hpp>
|
2015-04-27 03:09:56 +02:00
|
|
|
#include <objects/GameObject.hpp>
|
2016-04-16 15:06:02 +02:00
|
|
|
#include "ViewerWidget.hpp"
|
2015-04-13 02:48:29 +02:00
|
|
|
|
|
|
|
ModelViewer::ModelViewer(ViewerWidget* viewer, QWidget* parent, Qt::WindowFlags f)
|
2015-04-14 02:06:50 +02:00
|
|
|
: QWidget(parent, f), _world(nullptr), viewing(nullptr), skeleton(nullptr)
|
2015-04-13 02:48:29 +02:00
|
|
|
{
|
|
|
|
mainSplit = new QSplitter;
|
|
|
|
mainLayout = new QVBoxLayout;
|
|
|
|
|
|
|
|
viewerWidget = viewer;
|
|
|
|
viewerWidget->setMinimumSize(250,250);
|
|
|
|
|
2016-04-16 15:06:02 +02:00
|
|
|
animationWidget = new AnimationListWidget;
|
|
|
|
connect(animationWidget, SIGNAL(selectedAnimationChanged(Animation*)),
|
|
|
|
SLOT(playAnimation(Animation*)));
|
|
|
|
|
2015-04-13 02:48:29 +02:00
|
|
|
frames = new ModelFramesWidget;
|
|
|
|
frames->setMaximumWidth(300);
|
|
|
|
|
|
|
|
mainSplit->addWidget(frames);
|
2016-04-16 15:06:02 +02:00
|
|
|
mainSplit->addWidget(animationWidget);
|
2015-04-13 02:48:29 +02:00
|
|
|
mainLayout->addWidget(mainSplit);
|
|
|
|
|
|
|
|
this->setLayout(mainLayout);
|
|
|
|
|
2015-04-13 03:09:14 +02:00
|
|
|
connect(frames, SIGNAL(selectedFrameChanged(ModelFrame*)),
|
|
|
|
viewerWidget, SLOT(selectFrame(ModelFrame*)));
|
2015-04-13 02:48:29 +02:00
|
|
|
setViewerWidget(viewerWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModelViewer::setViewerWidget(ViewerWidget* widget)
|
|
|
|
{
|
|
|
|
viewerWidget = widget;
|
|
|
|
mainSplit->addWidget(viewerWidget);
|
|
|
|
showModel(viewing);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModelViewer::showData(GameWorld* world)
|
|
|
|
{
|
|
|
|
_world = world;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModelViewer::showModel(Model* model)
|
|
|
|
{
|
|
|
|
viewing = model;
|
2015-04-14 02:06:50 +02:00
|
|
|
if( skeleton )
|
|
|
|
{
|
|
|
|
delete skeleton;
|
|
|
|
}
|
|
|
|
skeleton = new Skeleton();
|
2015-04-13 02:48:29 +02:00
|
|
|
viewerWidget->showModel(model);
|
2015-04-14 02:06:50 +02:00
|
|
|
frames->setModel(model, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModelViewer::showObject(uint16_t object)
|
|
|
|
{
|
|
|
|
viewerWidget->showObject(object);
|
|
|
|
viewing = viewerWidget->currentModel();
|
|
|
|
skeleton = viewerWidget->currentObject()->skeleton;
|
|
|
|
frames->setModel(viewing, skeleton);
|
2015-04-13 02:48:29 +02:00
|
|
|
}
|
2016-04-16 15:06:02 +02:00
|
|
|
|
|
|
|
void ModelViewer::loadAnimations(const QString& file)
|
|
|
|
{
|
|
|
|
std::ifstream dfile(file.toStdString().c_str());
|
|
|
|
AnimationList anims;
|
|
|
|
|
|
|
|
if(dfile.is_open())
|
|
|
|
{
|
|
|
|
dfile.seekg(0, std::ios_base::end);
|
|
|
|
size_t length = dfile.tellg();
|
|
|
|
dfile.seekg(0);
|
|
|
|
char *file = new char[length];
|
|
|
|
dfile.read(file, length);
|
|
|
|
|
|
|
|
LoaderIFP loader;
|
|
|
|
if( loader.loadFromMemory(file) ) {
|
|
|
|
for(auto& f : loader.animations) {
|
|
|
|
anims.push_back(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete[] file;
|
|
|
|
}
|
|
|
|
|
|
|
|
animationWidget->setAnimations(anims);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModelViewer::playAnimation(Animation* anim)
|
|
|
|
{
|
2016-04-17 05:54:19 +02:00
|
|
|
viewerWidget->currentObject()->animator->playAnimation(0, anim, 1.f, true);
|
2016-04-16 15:06:02 +02:00
|
|
|
}
|