Remove BulletNifLoader dependency on keyframe manager

This will make threaded loading easier.
c++11
scrawl 10 years ago
parent f81c3bcd6d
commit cdc47fa874

@ -66,11 +66,6 @@ BulletNifLoader::~BulletNifLoader()
{
}
void BulletNifLoader::setAnimatedNodes(const std::set<std::string> &animatedNodes)
{
mAnimatedNodes = animatedNodes;
}
osg::ref_ptr<BulletShape> BulletNifLoader::load(const Nif::NIFFilePtr nif)
{
mShape = new BulletShape;
@ -110,7 +105,20 @@ osg::ref_ptr<BulletShape> BulletNifLoader::load(const Nif::NIFFilePtr nif)
else
{
bool autogenerated = hasAutoGeneratedCollision(node);
handleNode(node, 0, autogenerated, false, autogenerated);
bool isAnimated = false;
// files with the name convention xmodel.nif usually have keyframes stored in a separate file xmodel.kf (see Animation::addAnimSource).
// assume all nodes in the file will be animated
std::string filename = nif->getFilename();
size_t slashpos = filename.find_last_of("/\\");
if (slashpos == std::string::npos)
slashpos = 0;
if (slashpos+1 < filename.size() && (filename[slashpos+1] == 'x' || filename[slashpos+1] == 'X'))
{
isAnimated = true;
}
handleNode(node, 0, autogenerated, isAnimated, autogenerated);
if (mCompoundShape)
{
@ -192,9 +200,6 @@ void BulletNifLoader::handleNode(const Nif::Node *node, int flags,
&& (node->controller->flags & Nif::NiNode::ControllerFlag_Active))
isAnimated = true;
if (mAnimatedNodes.find(node->name) != mAnimatedNodes.end())
isAnimated = true;
isCollisionNode = isCollisionNode || (node->recType == Nif::RC_RootCollisionNode);
// Don't collide with AvoidNode shapes

@ -91,8 +91,6 @@ public:
abort();
}
void setAnimatedNodes(const std::set<std::string>& animatedNodes);
osg::ref_ptr<BulletShape> load(const Nif::NIFFilePtr file);
private:
@ -108,8 +106,6 @@ private:
btTriangleMesh* mStaticMesh;
std::set<std::string> mAnimatedNodes;
osg::ref_ptr<BulletShape> mShape;
};

@ -34,20 +34,7 @@ osg::ref_ptr<BulletShapeInstance> BulletShapeManager::createInstance(const std::
// TODO: add support for non-NIF formats
std::string kfname = normalized;
if(kfname.size() > 4 && kfname.compare(kfname.size()-4, 4, ".nif") == 0)
kfname.replace(kfname.size()-4, 4, ".kf");
std::set<std::string> animatedNodes;
if (mVFS->exists(kfname))
{
osg::ref_ptr<const NifOsg::KeyframeHolder> keyframes = mSceneManager->getKeyframes(kfname);
for (NifOsg::KeyframeHolder::KeyframeControllerMap::const_iterator it = keyframes->mKeyframeControllers.begin();
it != keyframes->mKeyframeControllers.end(); ++it)
animatedNodes.insert(it->first);
}
BulletNifLoader loader;
loader.setAnimatedNodes(animatedNodes);
// might be worth sharing NIFFiles with SceneManager in some way
shape = loader.load(Nif::NIFFilePtr(new Nif::NIFFile(file, normalized)));

Loading…
Cancel
Save