Attach NPC parts to the proper bone

actorid
Chris Robinson 13 years ago
parent 04e496a6ca
commit db948969c9

@ -341,7 +341,8 @@ void NpcAnimation::updateParts()
NifOgre::EntityList NpcAnimation::insertBoundedPart(const std::string &mesh, const std::string &bonename)
{
NifOgre::EntityList entities = NIFLoader::createEntities(mInsert, mesh);
NifOgre::EntityList entities = NIFLoader::createEntities(mEntityList.mSkelBase, bonename,
mInsert->getCreator(), mesh);
std::vector<Ogre::Entity*> &parts = entities.mEntities;
for(size_t i = 0;i < parts.size();i++)
parts[i]->setVisibilityFlags(RV_Actors);

@ -915,6 +915,49 @@ EntityList NIFLoader::createEntities(Ogre::SceneNode *parent, const std::string
return entitylist;
}
EntityList NIFLoader::createEntities(Ogre::Entity *parent, const std::string &bonename,
Ogre::SceneManager *sceneMgr,
const std::string &name,
const std::string &group)
{
EntityList entitylist;
MeshPairList meshes = load(name, group);
if(meshes.size() == 0)
return entitylist;
for(size_t i = 0;i < meshes.size();i++)
{
entitylist.mEntities.push_back(sceneMgr->createEntity(meshes[i].first->getName()));
Ogre::Entity *entity = entitylist.mEntities.back();
if(!entitylist.mSkelBase && entity->hasSkeleton())
entitylist.mSkelBase = entity;
}
if(entitylist.mSkelBase)
{
parent->attachObjectToBone(bonename, entitylist.mSkelBase);
for(size_t i = 0;i < entitylist.mEntities.size();i++)
{
Ogre::Entity *entity = entitylist.mEntities[i];
if(entity != entitylist.mSkelBase && entity->hasSkeleton())
{
entity->shareSkeletonInstanceWith(entitylist.mSkelBase);
parent->attachObjectToBone(bonename, entity);
}
else if(entity != entitylist.mSkelBase)
entitylist.mSkelBase->attachObjectToBone(meshes[i].second, entity);
}
}
else
{
for(size_t i = 0;i < entitylist.mEntities.size();i++)
parent->attachObjectToBone(bonename, entitylist.mEntities[i]);
}
return entitylist;
}
/* More code currently not in use, from the old D source. This was
used in the first attempt at loading NIF meshes, where each submesh

@ -58,6 +58,7 @@ namespace Nif
namespace NifOgre
{
// FIXME: This should not be in NifOgre, it works agnostic of what model format is used
struct EntityList {
std::vector<Ogre::Entity*> mEntities;
Ogre::Entity *mSkelBase;
@ -89,6 +90,11 @@ class NIFLoader
static MeshPairList load(const std::string &name, const std::string &group);
public:
static EntityList createEntities(Ogre::Entity *parent, const std::string &bonename,
Ogre::SceneManager *sceneMgr,
const std::string &name,
const std::string &group="General");
static EntityList createEntities(Ogre::SceneNode *parent,
const std::string &name,
const std::string &group="General");

Loading…
Cancel
Save