forked from mirror/openmw-tes3mp
Merge branch 'preview' of https://github.com/zinnschlag/openmw into Editor-Dialog
Conflicts: apps/opencs/CMakeLists.txt apps/opencs/view/world/subviews.cppactorid
commit
6416ae90d2
@ -0,0 +1,72 @@
|
||||
|
||||
#include "previewwidget.hpp"
|
||||
|
||||
#include <OgreSceneManager.h>
|
||||
|
||||
#include "../../model/world/data.hpp"
|
||||
|
||||
void CSVRender::PreviewWidget::setup (const std::string& id)
|
||||
{
|
||||
setNavigation (&mOrbit);
|
||||
|
||||
int column = mData.getReferenceables().findColumnIndex (CSMWorld::Columns::ColumnId_Model);
|
||||
|
||||
int row = mData.getReferenceables().getIndex (id);
|
||||
|
||||
QVariant value = mData.getReferenceables().getData (row, column);
|
||||
|
||||
if (!value.isValid())
|
||||
return;
|
||||
|
||||
std::string model = value.toString().toUtf8().constData();
|
||||
|
||||
if (model.empty())
|
||||
return;
|
||||
|
||||
mNode = getSceneManager()->getRootSceneNode()->createChildSceneNode();
|
||||
mNode->setPosition (Ogre::Vector3 (0, 0, 0));
|
||||
|
||||
mObject = NifOgre::Loader::createObjects (mNode, "Meshes\\" + model);
|
||||
}
|
||||
|
||||
void CSVRender::PreviewWidget::adjust (const std::string& id)
|
||||
{
|
||||
if (mNode)
|
||||
{
|
||||
int row = mData.getReferences().getIndex (id);
|
||||
|
||||
float scale = mData.getReferences().getData (row, mData.getReferences().
|
||||
findColumnIndex (CSMWorld::Columns::ColumnId_Scale)).toFloat();
|
||||
float rotX = mData.getReferences().getData (row, mData.getReferences().
|
||||
findColumnIndex (CSMWorld::Columns::ColumnId_PositionXRot)).toFloat();
|
||||
float rotY = mData.getReferences().getData (row, mData.getReferences().
|
||||
findColumnIndex (CSMWorld::Columns::ColumnId_PositionYRot)).toFloat();
|
||||
float rotZ = mData.getReferences().getData (row, mData.getReferences().
|
||||
findColumnIndex (CSMWorld::Columns::ColumnId_PositionZRot)).toFloat();
|
||||
|
||||
mNode->setScale (scale, scale, scale);
|
||||
|
||||
Ogre::Quaternion xr (Ogre::Radian(-rotX), Ogre::Vector3::UNIT_X);
|
||||
|
||||
Ogre::Quaternion yr (Ogre::Radian(-rotY), Ogre::Vector3::UNIT_Y);
|
||||
|
||||
Ogre::Quaternion zr (Ogre::Radian(-rotZ), Ogre::Vector3::UNIT_Z);
|
||||
|
||||
mNode->setOrientation (xr*yr*zr);
|
||||
}
|
||||
}
|
||||
|
||||
CSVRender::PreviewWidget::PreviewWidget (const CSMWorld::Data& data,
|
||||
const std::string& referenceableId, QWidget *parent)
|
||||
: SceneWidget (parent), mData (data), mNode (0)
|
||||
{
|
||||
setup (referenceableId);
|
||||
}
|
||||
|
||||
CSVRender::PreviewWidget::PreviewWidget (const CSMWorld::Data& data,
|
||||
const std::string& referenceableId, const std::string& referenceId, QWidget *parent)
|
||||
: SceneWidget (parent), mData (data)
|
||||
{
|
||||
setup (referenceableId);
|
||||
adjust (referenceId);
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
#ifndef OPENCS_VIEW_PREVIEWWIDGET_H
|
||||
#define OPENCS_VIEW_PREVIEWWIDGET_H
|
||||
|
||||
#include <components/nifogre/ogrenifloader.hpp>
|
||||
|
||||
#include "scenewidget.hpp"
|
||||
|
||||
#include "navigationorbit.hpp"
|
||||
|
||||
namespace CSMWorld
|
||||
{
|
||||
class Data;
|
||||
}
|
||||
|
||||
namespace CSVRender
|
||||
{
|
||||
class PreviewWidget : public SceneWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
const CSMWorld::Data& mData;
|
||||
CSVRender::NavigationOrbit mOrbit;
|
||||
NifOgre::ObjectScenePtr mObject;
|
||||
Ogre::SceneNode *mNode;
|
||||
|
||||
void setup (const std::string& id);
|
||||
///< \param id ID of the referenceable to be viewed
|
||||
|
||||
void adjust (const std::string& id);
|
||||
///< \param id ID of the reference to be viewed
|
||||
|
||||
public:
|
||||
|
||||
PreviewWidget (const CSMWorld::Data& data, const std::string& referenceableId,
|
||||
QWidget *parent = 0);
|
||||
|
||||
PreviewWidget (const CSMWorld::Data& data, const std::string& referenceableId,
|
||||
const std::string& referenceId, QWidget *parent = 0);
|
||||
|
||||
signals:
|
||||
|
||||
void closeRequest();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,52 @@
|
||||
|
||||
#include "previewsubview.hpp"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
|
||||
#include "../render/scenewidget.hpp"
|
||||
|
||||
#include "scenetoolbar.hpp"
|
||||
|
||||
#include "../render/previewwidget.hpp"
|
||||
|
||||
CSVWorld::PreviewSubView::PreviewSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document)
|
||||
: SubView (id)
|
||||
{
|
||||
QHBoxLayout *layout = new QHBoxLayout;
|
||||
|
||||
layout->setContentsMargins (QMargins (0, 0, 0, 0));
|
||||
|
||||
if (document.getData().getReferenceables().searchId (id.getId())==-1)
|
||||
{
|
||||
std::string referenceableId =
|
||||
document.getData().getReferences().getRecord (id.getId()).get().mRefID;
|
||||
|
||||
setWindowTitle (("Preview: Reference to " + referenceableId).c_str());
|
||||
|
||||
mScene =
|
||||
new CSVRender::PreviewWidget (document.getData(), referenceableId, id.getId(), this);
|
||||
}
|
||||
else
|
||||
mScene = new CSVRender::PreviewWidget (document.getData(), id.getId(), this);
|
||||
|
||||
SceneToolbar *toolbar = new SceneToolbar (48, this);
|
||||
|
||||
layout->addWidget (toolbar, 0);
|
||||
|
||||
layout->addWidget (mScene, 1);
|
||||
|
||||
QWidget *widget = new QWidget;
|
||||
|
||||
widget->setLayout (layout);
|
||||
|
||||
setWidget (widget);
|
||||
|
||||
connect (mScene, SIGNAL (closeRequest()), this, SLOT (closeRequest()));
|
||||
}
|
||||
|
||||
void CSVWorld::PreviewSubView::setEditLock (bool locked) {}
|
||||
|
||||
void CSVWorld::PreviewSubView::closeRequest()
|
||||
{
|
||||
deleteLater();
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
#ifndef CSV_WORLD_PREVIEWSUBVIEW_H
|
||||
#define CSV_WORLD_PREVIEWSUBVIEW_H
|
||||
|
||||
#include "../doc/subview.hpp"
|
||||
|
||||
namespace CSMDoc
|
||||
{
|
||||
class Document;
|
||||
}
|
||||
|
||||
namespace CSVRender
|
||||
{
|
||||
class PreviewWidget;
|
||||
}
|
||||
|
||||
namespace CSVWorld
|
||||
{
|
||||
class PreviewSubView : public CSVDoc::SubView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
CSVRender::PreviewWidget *mScene;
|
||||
|
||||
public:
|
||||
|
||||
PreviewSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document);
|
||||
|
||||
virtual void setEditLock (bool locked);
|
||||
|
||||
private slots:
|
||||
|
||||
void closeRequest();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,53 @@
|
||||
|
||||
#include "resources.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <OgreResourceGroupManager.h>
|
||||
#include <OgreStringConverter.h>
|
||||
|
||||
#include "bsa_archive.hpp"
|
||||
|
||||
void Bsa::registerResources (const Files::Collections& collections,
|
||||
const std::vector<std::string>& archives, bool useLooseFiles, bool fsStrict)
|
||||
{
|
||||
const Files::PathContainer& dataDirs = collections.getPaths();
|
||||
|
||||
int i=0;
|
||||
|
||||
if (useLooseFiles)
|
||||
for (Files::PathContainer::const_iterator iter = dataDirs.begin(); iter != dataDirs.end(); ++iter)
|
||||
{
|
||||
// Last data dir has the highest priority
|
||||
std::string groupName = "Data" + Ogre::StringConverter::toString(dataDirs.size()-i, 8, '0');
|
||||
Ogre::ResourceGroupManager::getSingleton ().createResourceGroup (groupName);
|
||||
|
||||
std::string dataDirectory = iter->string();
|
||||
std::cout << "Data dir " << dataDirectory << std::endl;
|
||||
Bsa::addDir(dataDirectory, fsStrict, groupName);
|
||||
++i;
|
||||
}
|
||||
|
||||
i=0;
|
||||
for (std::vector<std::string>::const_iterator archive = archives.begin(); archive != archives.end(); ++archive)
|
||||
{
|
||||
if (collections.doesExist(*archive))
|
||||
{
|
||||
// Last BSA has the highest priority
|
||||
std::string groupName = "DataBSA" + Ogre::StringConverter::toString(archives.size()-i, 8, '0');
|
||||
|
||||
Ogre::ResourceGroupManager::getSingleton ().createResourceGroup (groupName);
|
||||
|
||||
const std::string archivePath = collections.getPath(*archive).string();
|
||||
std::cout << "Adding BSA archive " << archivePath << std::endl;
|
||||
Bsa::addBSA(archivePath, groupName);
|
||||
++i;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::stringstream message;
|
||||
message << "Archive '" << *archive << "' not found";
|
||||
throw std::runtime_error(message.str());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
#ifndef BSA_BSA_RESOURCES_H
|
||||
#define BSA_BSA_RESOURCES_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "../files/collections.hpp"
|
||||
|
||||
namespace Bsa
|
||||
{
|
||||
void registerResources (const Files::Collections& collections,
|
||||
const std::vector<std::string>& archives, bool useLooseFiles, bool fsStrict);
|
||||
///< Register resources directories and archives as OGRE resources groups
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue