2015-02-23 20:06:10 +00:00
|
|
|
#include <osgViewer/Viewer>
|
2015-02-26 20:20:07 +00:00
|
|
|
#include <osgViewer/ViewerEventHandlers>
|
2015-02-23 20:06:10 +00:00
|
|
|
|
|
|
|
#include <components/bsa/bsa_file.hpp>
|
|
|
|
#include <components/nif/niffile.hpp>
|
|
|
|
|
|
|
|
#include <components/nifosg/nifloader.hpp>
|
|
|
|
|
2015-03-17 20:59:39 +00:00
|
|
|
#include <components/vfs/manager.hpp>
|
|
|
|
#include <components/vfs/bsaarchive.hpp>
|
|
|
|
|
2015-02-23 20:06:10 +00:00
|
|
|
#include <osgGA/TrackballManipulator>
|
|
|
|
|
|
|
|
#include <osgDB/WriteFile>
|
|
|
|
|
|
|
|
#include <osg/PolygonMode>
|
|
|
|
|
|
|
|
// EventHandler to toggle wireframe when 'w' key is pressed
|
2015-02-26 20:20:07 +00:00
|
|
|
class WireframeKeyHandler : public osgGA::GUIEventHandler
|
2015-02-23 20:06:10 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-03-17 17:53:56 +00:00
|
|
|
WireframeKeyHandler()
|
2015-02-23 20:06:10 +00:00
|
|
|
: mWireframe(false)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool handle(const osgGA::GUIEventAdapter& adapter,osgGA::GUIActionAdapter& action)
|
|
|
|
{
|
|
|
|
switch (adapter.getEventType())
|
|
|
|
{
|
|
|
|
case osgGA::GUIEventAdapter::KEYDOWN:
|
|
|
|
if (adapter.getKey() == osgGA::GUIEventAdapter::KEY_W)
|
|
|
|
{
|
|
|
|
mWireframe = !mWireframe;
|
2015-03-17 17:53:56 +00:00
|
|
|
// applying state from an event handler doesn't appear to be safe, so do it in the frame update
|
2015-02-23 20:06:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-17 17:53:56 +00:00
|
|
|
bool getWireframe() const
|
|
|
|
{
|
|
|
|
return mWireframe;
|
|
|
|
}
|
|
|
|
|
2015-02-23 20:06:10 +00:00
|
|
|
private:
|
|
|
|
bool mWireframe;
|
|
|
|
};
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
if (argc < 3)
|
|
|
|
{
|
|
|
|
std::cout << "Usage: " << argv[0] << " <BSA file> <NIF file>" << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-03-17 20:59:39 +00:00
|
|
|
VFS::Manager resourceMgr (false);
|
|
|
|
resourceMgr.addArchive(new VFS::BsaArchive(argv[1]));
|
|
|
|
resourceMgr.buildIndex();
|
2015-02-23 20:06:10 +00:00
|
|
|
|
2015-03-17 20:59:39 +00:00
|
|
|
Nif::NIFFilePtr nif(new Nif::NIFFile(resourceMgr.get(argv[2]), std::string(argv[2])));
|
2015-02-23 20:06:10 +00:00
|
|
|
|
|
|
|
osgViewer::Viewer viewer;
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Group> root(new osg::Group());
|
|
|
|
root->getOrCreateStateSet()->setMode(GL_CULL_FACE, osg::StateAttribute::ON);
|
|
|
|
// To prevent lighting issues with scaled meshes
|
|
|
|
root->getOrCreateStateSet()->setMode(GL_NORMALIZE, osg::StateAttribute::ON);
|
|
|
|
|
2015-02-26 20:20:07 +00:00
|
|
|
|
|
|
|
//osgDB::writeNodeFile(*newNode, "out.osg");
|
|
|
|
|
|
|
|
std::vector<NifOsg::Controller > controllers;
|
2015-02-23 20:06:10 +00:00
|
|
|
osg::Group* newNode = new osg::Group;
|
|
|
|
NifOsg::Loader loader;
|
2015-03-17 20:59:39 +00:00
|
|
|
loader.resourceManager = &resourceMgr;
|
2015-02-23 20:06:10 +00:00
|
|
|
loader.loadAsSkeleton(nif, newNode);
|
|
|
|
|
2015-02-26 20:20:07 +00:00
|
|
|
for (unsigned int i=0; i<loader.mControllers.size(); ++i)
|
|
|
|
controllers.push_back(loader.mControllers[i]);
|
2015-02-23 20:06:10 +00:00
|
|
|
|
|
|
|
for (int x=0; x<1;++x)
|
|
|
|
{
|
|
|
|
root->addChild(newNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
viewer.setSceneData(root);
|
|
|
|
|
|
|
|
viewer.setUpViewInWindow(0, 0, 800, 600);
|
|
|
|
viewer.realize();
|
|
|
|
viewer.setCameraManipulator(new osgGA::TrackballManipulator());
|
2015-03-17 17:53:56 +00:00
|
|
|
|
|
|
|
WireframeKeyHandler* keyHandler = new WireframeKeyHandler;
|
|
|
|
|
|
|
|
viewer.addEventHandler(keyHandler);
|
2015-02-26 20:20:07 +00:00
|
|
|
viewer.addEventHandler(new osgViewer::StatsHandler);
|
2015-02-23 20:06:10 +00:00
|
|
|
|
2015-03-17 17:53:56 +00:00
|
|
|
bool wireframe = false;
|
|
|
|
|
2015-02-23 20:06:10 +00:00
|
|
|
while (!viewer.done())
|
|
|
|
{
|
2015-03-17 17:53:56 +00:00
|
|
|
|
|
|
|
if (wireframe != keyHandler->getWireframe())
|
|
|
|
{
|
|
|
|
wireframe = keyHandler->getWireframe();
|
|
|
|
osg::PolygonMode* mode = new osg::PolygonMode;
|
|
|
|
mode->setMode(osg::PolygonMode::FRONT_AND_BACK,
|
|
|
|
wireframe ? osg::PolygonMode::LINE : osg::PolygonMode::FILL);
|
|
|
|
root->getOrCreateStateSet()->setAttributeAndModes(mode, osg::StateAttribute::ON);
|
|
|
|
root->getOrCreateStateSet()->setMode(GL_CULL_FACE, wireframe ? osg::StateAttribute::OFF
|
|
|
|
: osg::StateAttribute::ON);
|
|
|
|
}
|
|
|
|
|
2015-02-23 20:06:10 +00:00
|
|
|
viewer.frame();
|
|
|
|
|
2015-02-26 20:20:07 +00:00
|
|
|
for (unsigned int i=0; i<controllers.size(); ++i)
|
|
|
|
controllers[i].update();
|
2015-02-23 20:06:10 +00:00
|
|
|
}
|
2015-02-26 20:20:07 +00:00
|
|
|
|
2015-02-23 20:06:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|