2015-05-12 01:02:15 +00:00
|
|
|
#include "bulletshapemanager.hpp"
|
|
|
|
|
|
|
|
#include <components/vfs/manager.hpp>
|
|
|
|
|
|
|
|
#include <components/nifbullet/bulletnifloader.hpp>
|
|
|
|
|
|
|
|
namespace NifBullet
|
|
|
|
{
|
|
|
|
|
2015-06-11 16:01:00 +00:00
|
|
|
BulletShapeManager::BulletShapeManager(const VFS::Manager* vfs)
|
2015-05-12 01:02:15 +00:00
|
|
|
: mVFS(vfs)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
BulletShapeManager::~BulletShapeManager()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
osg::ref_ptr<BulletShapeInstance> BulletShapeManager::createInstance(const std::string &name)
|
|
|
|
{
|
|
|
|
std::string normalized = name;
|
|
|
|
mVFS->normalizeFilename(normalized);
|
|
|
|
|
|
|
|
osg::ref_ptr<BulletShape> shape;
|
|
|
|
Index::iterator it = mIndex.find(normalized);
|
|
|
|
if (it == mIndex.end())
|
|
|
|
{
|
|
|
|
Files::IStreamPtr file = mVFS->get(normalized);
|
|
|
|
|
|
|
|
// TODO: add support for non-NIF formats
|
2015-11-16 22:26:43 +00:00
|
|
|
size_t extPos = normalized.find_last_of('.');
|
|
|
|
std::string ext;
|
|
|
|
if (extPos != std::string::npos && extPos+1 < normalized.size())
|
|
|
|
ext = normalized.substr(extPos+1);
|
|
|
|
|
|
|
|
if (ext != "nif")
|
|
|
|
return NULL;
|
2015-05-12 01:02:15 +00:00
|
|
|
|
|
|
|
BulletNifLoader loader;
|
|
|
|
// might be worth sharing NIFFiles with SceneManager in some way
|
|
|
|
shape = loader.load(Nif::NIFFilePtr(new Nif::NIFFile(file, normalized)));
|
|
|
|
|
|
|
|
mIndex[normalized] = shape;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
shape = it->second;
|
|
|
|
|
|
|
|
osg::ref_ptr<BulletShapeInstance> instance = shape->makeInstance();
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|