mirror of https://github.com/OpenMW/openmw.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.3 KiB
C++
57 lines
1.3 KiB
C++
10 years ago
|
#include "bulletshapemanager.hpp"
|
||
|
|
||
|
#include <components/vfs/manager.hpp>
|
||
|
|
||
|
#include <components/nifbullet/bulletnifloader.hpp>
|
||
|
|
||
9 years ago
|
#include "bulletshape.hpp"
|
||
|
|
||
|
namespace Resource
|
||
10 years ago
|
{
|
||
|
|
||
10 years ago
|
BulletShapeManager::BulletShapeManager(const VFS::Manager* vfs)
|
||
10 years ago
|
: 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
|
||
9 years ago
|
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;
|
||
10 years ago
|
|
||
9 years ago
|
NifBullet::BulletNifLoader loader;
|
||
10 years ago
|
// 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;
|
||
|
}
|
||
|
|
||
|
}
|