1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 21:23:52 +00:00

Attach NPC parts to the proper bone

This commit is contained in:
Chris Robinson 2012-07-18 11:14:13 -07:00
parent 04e496a6ca
commit db948969c9
3 changed files with 51 additions and 1 deletions

View file

@ -341,7 +341,8 @@ void NpcAnimation::updateParts()
NifOgre::EntityList NpcAnimation::insertBoundedPart(const std::string &mesh, const std::string &bonename) 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; std::vector<Ogre::Entity*> &parts = entities.mEntities;
for(size_t i = 0;i < parts.size();i++) for(size_t i = 0;i < parts.size();i++)
parts[i]->setVisibilityFlags(RV_Actors); parts[i]->setVisibilityFlags(RV_Actors);

View file

@ -915,6 +915,49 @@ EntityList NIFLoader::createEntities(Ogre::SceneNode *parent, const std::string
return entitylist; 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 /* 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 used in the first attempt at loading NIF meshes, where each submesh

View file

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