2011-12-11 22:40:00 -05:00
|
|
|
#include "npcanimation.hpp"
|
|
|
|
|
2012-07-03 15:32:38 +02:00
|
|
|
#include <OgreSceneManager.h>
|
|
|
|
#include <OgreEntity.h>
|
2013-04-07 02:08:33 -07:00
|
|
|
#include <OgreParticleSystem.h>
|
2012-07-03 15:32:38 +02:00
|
|
|
#include <OgreSubEntity.h>
|
|
|
|
|
2012-10-01 19:17:04 +04:00
|
|
|
#include "../mwworld/esmstore.hpp"
|
2013-02-23 08:03:52 -08:00
|
|
|
#include "../mwworld/inventorystore.hpp"
|
|
|
|
#include "../mwworld/class.hpp"
|
2012-07-03 13:15:20 +02:00
|
|
|
|
2012-04-23 15:27:03 +02:00
|
|
|
#include "../mwbase/environment.hpp"
|
2012-07-03 12:30:50 +02:00
|
|
|
#include "../mwbase/world.hpp"
|
|
|
|
|
|
|
|
#include "renderconst.hpp"
|
2012-04-07 22:02:20 -04:00
|
|
|
|
2012-07-12 20:12:18 -07:00
|
|
|
|
2013-01-06 01:59:18 -08:00
|
|
|
namespace MWRender
|
|
|
|
{
|
|
|
|
|
2013-01-06 05:39:39 -08:00
|
|
|
const NpcAnimation::PartInfo NpcAnimation::sPartList[NpcAnimation::sPartListSize] = {
|
2013-02-02 02:53:22 -08:00
|
|
|
{ ESM::PRT_Head, "Head" },
|
|
|
|
{ ESM::PRT_Hair, "Head" },
|
|
|
|
{ ESM::PRT_Neck, "Neck" },
|
|
|
|
{ ESM::PRT_Cuirass, "Chest" },
|
|
|
|
{ ESM::PRT_Groin, "Groin" },
|
|
|
|
{ ESM::PRT_Skirt, "Groin" },
|
|
|
|
{ ESM::PRT_RHand, "Right Hand" },
|
|
|
|
{ ESM::PRT_LHand, "Left Hand" },
|
|
|
|
{ ESM::PRT_RWrist, "Right Wrist" },
|
|
|
|
{ ESM::PRT_LWrist, "Left Wrist" },
|
|
|
|
{ ESM::PRT_Shield, "Shield" },
|
|
|
|
{ ESM::PRT_RForearm, "Right Forearm" },
|
|
|
|
{ ESM::PRT_LForearm, "Left Forearm" },
|
|
|
|
{ ESM::PRT_RUpperarm, "Right Upper Arm" },
|
|
|
|
{ ESM::PRT_LUpperarm, "Left Upper Arm" },
|
|
|
|
{ ESM::PRT_RFoot, "Right Foot" },
|
|
|
|
{ ESM::PRT_LFoot, "Left Foot" },
|
|
|
|
{ ESM::PRT_RAnkle, "Right Ankle" },
|
|
|
|
{ ESM::PRT_LAnkle, "Left Ankle" },
|
|
|
|
{ ESM::PRT_RKnee, "Right Knee" },
|
|
|
|
{ ESM::PRT_LKnee, "Left Knee" },
|
|
|
|
{ ESM::PRT_RLeg, "Right Upper Leg" },
|
|
|
|
{ ESM::PRT_LLeg, "Left Upper Leg" },
|
|
|
|
{ ESM::PRT_RPauldron, "Right Clavicle" },
|
|
|
|
{ ESM::PRT_LPauldron, "Left Clavicle" },
|
|
|
|
{ ESM::PRT_Weapon, "Weapon" },
|
|
|
|
{ ESM::PRT_Tail, "Tail" }
|
2013-01-06 01:59:18 -08:00
|
|
|
};
|
|
|
|
|
2012-07-12 20:12:18 -07:00
|
|
|
NpcAnimation::~NpcAnimation()
|
|
|
|
{
|
2013-04-07 13:02:46 -07:00
|
|
|
Ogre::SceneManager *sceneMgr = mInsert->getCreator();
|
2013-01-06 01:59:18 -08:00
|
|
|
for(size_t i = 0;i < sPartListSize;i++)
|
2013-04-07 13:02:46 -07:00
|
|
|
destroyObjectList(sceneMgr, mObjectParts[i]);
|
2011-12-11 23:42:39 -05:00
|
|
|
}
|
2011-12-11 22:40:00 -05:00
|
|
|
|
2011-12-25 22:37:26 -05:00
|
|
|
|
2013-04-09 09:07:05 -07:00
|
|
|
NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, Ogre::SceneNode* node, MWWorld::InventoryStore& inv, int visibilityFlags, ViewMode viewMode)
|
2013-01-06 17:05:48 -08:00
|
|
|
: Animation(ptr),
|
2012-11-08 13:46:24 +04:00
|
|
|
mStateID(-1),
|
|
|
|
mTimeToChange(0),
|
|
|
|
mVisibilityFlags(visibilityFlags),
|
2013-02-23 08:03:52 -08:00
|
|
|
mRobe(inv.end()),
|
|
|
|
mHelmet(inv.end()),
|
|
|
|
mShirt(inv.end()),
|
|
|
|
mCuirass(inv.end()),
|
|
|
|
mGreaves(inv.end()),
|
|
|
|
mPauldronL(inv.end()),
|
|
|
|
mPauldronR(inv.end()),
|
|
|
|
mBoots(inv.end()),
|
|
|
|
mPants(inv.end()),
|
|
|
|
mGloveL(inv.end()),
|
|
|
|
mGloveR(inv.end()),
|
2013-03-06 18:03:47 +01:00
|
|
|
mSkirtIter(inv.end()),
|
2013-04-09 09:07:05 -07:00
|
|
|
mViewMode(viewMode)
|
2012-07-12 20:12:18 -07:00
|
|
|
{
|
2013-01-06 17:05:48 -08:00
|
|
|
mNpc = mPtr.get<ESM::NPC>()->mBase;
|
2012-07-12 20:12:18 -07:00
|
|
|
|
2013-01-06 05:39:39 -08:00
|
|
|
for(size_t i = 0;i < sPartListSize;i++)
|
2012-07-12 20:12:18 -07:00
|
|
|
{
|
2013-01-06 05:39:39 -08:00
|
|
|
mPartslots[i] = -1; //each slot is empty
|
|
|
|
mPartPriorities[i] = 0;
|
2012-07-12 20:12:18 -07:00
|
|
|
}
|
|
|
|
|
2012-11-06 11:53:00 +04:00
|
|
|
const MWWorld::ESMStore &store =
|
|
|
|
MWBase::Environment::get().getWorld()->getStore();
|
2012-11-08 13:46:24 +04:00
|
|
|
const ESM::Race *race = store.get<ESM::Race>().find(mNpc->mRace);
|
2011-12-11 22:40:00 -05:00
|
|
|
|
2012-11-08 13:46:24 +04:00
|
|
|
mHeadModel = "meshes\\" + store.get<ESM::BodyPart>().find(mNpc->mHead)->mModel;
|
|
|
|
mHairModel = "meshes\\" + store.get<ESM::BodyPart>().find(mNpc->mHair)->mModel;
|
2011-12-11 22:40:00 -05:00
|
|
|
|
2012-11-08 13:46:24 +04:00
|
|
|
mBodyPrefix = "b_n_" + mNpc->mRace;
|
2013-01-09 20:51:52 +01:00
|
|
|
Misc::StringUtils::toLower(mBodyPrefix);
|
2011-12-11 22:40:00 -05:00
|
|
|
|
2012-11-08 13:46:24 +04:00
|
|
|
bool isBeast = (race->mData.mFlags & ESM::Race::Beast) != 0;
|
2012-07-12 20:12:18 -07:00
|
|
|
std::string smodel = (!isBeast ? "meshes\\base_anim.nif" : "meshes\\base_animkna.nif");
|
2012-07-13 18:25:35 -07:00
|
|
|
|
2013-04-07 01:52:35 -07:00
|
|
|
createObjectList(node, smodel);
|
|
|
|
for(size_t i = 0;i < mObjectList.mEntities.size();i++)
|
2012-04-04 18:53:40 +02:00
|
|
|
{
|
2013-04-07 01:52:35 -07:00
|
|
|
Ogre::Entity *base = mObjectList.mEntities[i];
|
2012-07-17 11:38:20 -07:00
|
|
|
|
2013-01-06 01:59:18 -08:00
|
|
|
base->getUserObjectBindings().setUserAny(Ogre::Any(-1));
|
2013-02-03 15:46:23 +01:00
|
|
|
if (mVisibilityFlags != 0)
|
|
|
|
base->setVisibilityFlags(mVisibilityFlags);
|
2013-01-06 01:59:18 -08:00
|
|
|
|
2013-03-04 16:57:00 +01:00
|
|
|
for(unsigned int j=0; j < base->getNumSubEntities(); ++j)
|
2012-04-04 18:53:40 +02:00
|
|
|
{
|
2013-03-04 16:57:00 +01:00
|
|
|
Ogre::SubEntity* subEnt = base->getSubEntity(j);
|
|
|
|
subEnt->setRenderQueueGroup(subEnt->getMaterial()->isTransparent() ? RQG_Alpha : RQG_Main);
|
2012-04-04 18:53:40 +02:00
|
|
|
}
|
2012-07-17 11:38:20 -07:00
|
|
|
}
|
2013-04-07 02:08:33 -07:00
|
|
|
for(size_t i = 0;i < mObjectList.mParticles.size();i++)
|
|
|
|
{
|
|
|
|
Ogre::ParticleSystem *part = mObjectList.mParticles[i];
|
|
|
|
|
|
|
|
part->getUserObjectBindings().setUserAny(Ogre::Any(-1));
|
|
|
|
if(mVisibilityFlags != 0)
|
|
|
|
part->setVisibilityFlags(mVisibilityFlags);
|
|
|
|
part->setRenderQueueGroup(RQG_Alpha);
|
|
|
|
}
|
2012-01-17 15:10:53 +01:00
|
|
|
|
2013-02-23 03:34:03 -08:00
|
|
|
std::vector<std::string> skelnames(1, smodel);
|
2013-02-05 18:09:43 -08:00
|
|
|
if(!mNpc->isMale() && !isBeast)
|
2013-02-23 03:34:03 -08:00
|
|
|
skelnames.push_back("meshes\\base_anim_female.nif");
|
2013-02-05 18:09:43 -08:00
|
|
|
else if(mBodyPrefix.find("argonian") != std::string::npos)
|
2013-02-23 03:34:03 -08:00
|
|
|
skelnames.push_back("meshes\\argonian_swimkna.nif");
|
2013-02-05 18:09:43 -08:00
|
|
|
if(mNpc->mModel.length() > 0)
|
2013-02-23 03:34:03 -08:00
|
|
|
skelnames.push_back("meshes\\"+Misc::StringUtils::lowerCase(mNpc->mModel));
|
|
|
|
setAnimationSources(skelnames);
|
2012-01-17 15:10:53 +01:00
|
|
|
|
2013-02-22 10:15:29 -08:00
|
|
|
updateParts(true);
|
2012-04-08 17:27:56 -04:00
|
|
|
}
|
2012-01-17 15:10:53 +01:00
|
|
|
|
2013-02-22 10:15:29 -08:00
|
|
|
void NpcAnimation::updateParts(bool forceupdate)
|
2012-07-12 20:12:18 -07:00
|
|
|
{
|
2013-01-06 01:59:18 -08:00
|
|
|
static const struct {
|
2013-01-09 07:43:10 -08:00
|
|
|
int numRemoveParts; // Max: 1
|
|
|
|
ESM::PartReferenceType removeParts[1];
|
2011-12-11 22:40:00 -05:00
|
|
|
|
2013-01-09 07:43:10 -08:00
|
|
|
MWWorld::ContainerStoreIterator NpcAnimation::*part;
|
2012-07-18 10:09:16 -07:00
|
|
|
int slot;
|
2013-01-09 07:43:10 -08:00
|
|
|
|
|
|
|
int numReserveParts; // Max: 12
|
|
|
|
ESM::PartReferenceType reserveParts[12];
|
2012-07-18 10:09:16 -07:00
|
|
|
} slotlist[] = {
|
2013-01-09 07:43:10 -08:00
|
|
|
{ 0, { },
|
|
|
|
&NpcAnimation::mRobe, MWWorld::InventoryStore::Slot_Robe,
|
|
|
|
12, { ESM::PRT_Groin, ESM::PRT_Skirt, ESM::PRT_RLeg, ESM::PRT_LLeg,
|
|
|
|
ESM::PRT_RUpperarm, ESM::PRT_LUpperarm, ESM::PRT_RKnee, ESM::PRT_LKnee,
|
|
|
|
ESM::PRT_RForearm, ESM::PRT_LForearm, ESM::PRT_RPauldron, ESM::PRT_LPauldron }
|
|
|
|
},
|
|
|
|
|
|
|
|
{ 0, { },
|
|
|
|
&NpcAnimation::mSkirtIter, MWWorld::InventoryStore::Slot_Skirt,
|
|
|
|
3, { ESM::PRT_Groin, ESM::PRT_RLeg, ESM::PRT_LLeg }
|
|
|
|
},
|
|
|
|
|
|
|
|
{ 1, { ESM::PRT_Hair },
|
|
|
|
&NpcAnimation::mHelmet, MWWorld::InventoryStore::Slot_Helmet,
|
|
|
|
0, { }
|
|
|
|
},
|
|
|
|
|
|
|
|
{ 0, { },
|
|
|
|
&NpcAnimation::mCuirass, MWWorld::InventoryStore::Slot_Cuirass,
|
|
|
|
0, { }
|
|
|
|
},
|
|
|
|
|
|
|
|
{ 0, { },
|
|
|
|
&NpcAnimation::mGreaves, MWWorld::InventoryStore::Slot_Greaves,
|
|
|
|
0, { }
|
|
|
|
},
|
|
|
|
|
|
|
|
{ 0, { },
|
|
|
|
&NpcAnimation::mPauldronL, MWWorld::InventoryStore::Slot_LeftPauldron,
|
|
|
|
0, { }
|
|
|
|
},
|
|
|
|
|
|
|
|
{ 0, { },
|
|
|
|
&NpcAnimation::mPauldronR, MWWorld::InventoryStore::Slot_RightPauldron,
|
|
|
|
0, { }
|
|
|
|
},
|
|
|
|
|
|
|
|
{ 0, { },
|
|
|
|
&NpcAnimation::mBoots, MWWorld::InventoryStore::Slot_Boots,
|
|
|
|
0, { }
|
|
|
|
},
|
|
|
|
|
|
|
|
{ 0, { },
|
|
|
|
&NpcAnimation::mGloveL, MWWorld::InventoryStore::Slot_LeftGauntlet,
|
|
|
|
0, { }
|
|
|
|
},
|
|
|
|
|
|
|
|
{ 0, { },
|
|
|
|
&NpcAnimation::mGloveR, MWWorld::InventoryStore::Slot_RightGauntlet,
|
|
|
|
0, { }
|
|
|
|
},
|
|
|
|
|
|
|
|
{ 0, { },
|
|
|
|
&NpcAnimation::mShirt, MWWorld::InventoryStore::Slot_Shirt,
|
|
|
|
0, { }
|
|
|
|
},
|
|
|
|
|
|
|
|
{ 0, { },
|
|
|
|
&NpcAnimation::mPants, MWWorld::InventoryStore::Slot_Pants,
|
|
|
|
0, { }
|
|
|
|
},
|
2012-07-18 10:09:16 -07:00
|
|
|
};
|
2013-01-09 07:43:10 -08:00
|
|
|
static const size_t slotlistsize = sizeof(slotlist)/sizeof(slotlist[0]);
|
|
|
|
|
2013-02-23 08:03:52 -08:00
|
|
|
MWWorld::InventoryStore &inv = MWWorld::Class::get(mPtr).getInventoryStore(mPtr);
|
2013-02-22 10:15:29 -08:00
|
|
|
for(size_t i = 0;!forceupdate && i < slotlistsize;i++)
|
2012-07-12 20:12:18 -07:00
|
|
|
{
|
2013-02-23 08:03:52 -08:00
|
|
|
MWWorld::ContainerStoreIterator iter = inv.getSlot(slotlist[i].slot);
|
2013-02-22 10:15:29 -08:00
|
|
|
if(this->*slotlist[i].part != iter)
|
2012-07-18 10:09:16 -07:00
|
|
|
{
|
2013-02-22 10:15:29 -08:00
|
|
|
forceupdate = true;
|
|
|
|
break;
|
2012-07-18 10:09:16 -07:00
|
|
|
}
|
2012-07-12 20:12:18 -07:00
|
|
|
}
|
2013-02-22 10:15:29 -08:00
|
|
|
if(!forceupdate)
|
|
|
|
return;
|
2011-12-11 22:40:00 -05:00
|
|
|
|
2013-04-09 09:07:05 -07:00
|
|
|
for(size_t i = 0;i < slotlistsize && mViewMode != VM_HeadOnly;i++)
|
2012-07-12 20:12:18 -07:00
|
|
|
{
|
2013-02-23 08:03:52 -08:00
|
|
|
MWWorld::ContainerStoreIterator iter = inv.getSlot(slotlist[i].slot);
|
2012-04-15 22:06:05 +02:00
|
|
|
|
2013-01-09 07:43:10 -08:00
|
|
|
this->*slotlist[i].part = iter;
|
|
|
|
removePartGroup(slotlist[i].slot);
|
2012-01-17 15:10:53 +01:00
|
|
|
|
2013-02-23 08:03:52 -08:00
|
|
|
if(this->*slotlist[i].part == inv.end())
|
2013-01-09 07:43:10 -08:00
|
|
|
continue;
|
2012-04-15 22:06:05 +02:00
|
|
|
|
2013-01-09 07:43:10 -08:00
|
|
|
for(int rem = 0;rem < slotlist[i].numRemoveParts;rem++)
|
|
|
|
removeIndividualPart(slotlist[i].removeParts[rem]);
|
2012-04-13 23:25:15 -04:00
|
|
|
|
2013-01-09 07:43:10 -08:00
|
|
|
int prio = 1;
|
|
|
|
MWWorld::ContainerStoreIterator &store = this->*slotlist[i].part;
|
|
|
|
if(store->getTypeName() == typeid(ESM::Clothing).name())
|
2012-07-12 20:12:18 -07:00
|
|
|
{
|
2013-01-09 07:43:10 -08:00
|
|
|
prio = ((slotlist[i].numReserveParts+1)<<1) + 0;
|
|
|
|
const ESM::Clothing *clothes = store->get<ESM::Clothing>()->mBase;
|
2013-01-09 08:03:28 -08:00
|
|
|
addPartGroup(slotlist[i].slot, prio, clothes->mParts.mParts);
|
2012-07-12 20:12:18 -07:00
|
|
|
}
|
2013-01-09 07:43:10 -08:00
|
|
|
else if(store->getTypeName() == typeid(ESM::Armor).name())
|
2012-07-12 20:12:18 -07:00
|
|
|
{
|
2013-01-09 07:43:10 -08:00
|
|
|
prio = ((slotlist[i].numReserveParts+1)<<1) + 1;
|
|
|
|
const ESM::Armor *armor = store->get<ESM::Armor>()->mBase;
|
2013-01-09 08:03:28 -08:00
|
|
|
addPartGroup(slotlist[i].slot, prio, armor->mParts.mParts);
|
2012-07-12 20:12:18 -07:00
|
|
|
}
|
2012-01-17 15:10:53 +01:00
|
|
|
|
2013-01-09 07:43:10 -08:00
|
|
|
for(int res = 0;res < slotlist[i].numReserveParts;res++)
|
|
|
|
reserveIndividualPart(slotlist[i].reserveParts[res], slotlist[i].slot, prio);
|
2012-07-12 20:12:18 -07:00
|
|
|
}
|
2012-04-15 22:06:05 +02:00
|
|
|
|
2012-07-13 03:51:58 -07:00
|
|
|
if(mPartPriorities[ESM::PRT_Head] < 1)
|
2012-11-08 13:46:24 +04:00
|
|
|
addOrReplaceIndividualPart(ESM::PRT_Head, -1,1, mHeadModel);
|
2012-07-17 10:57:15 -07:00
|
|
|
if(mPartPriorities[ESM::PRT_Hair] < 1 && mPartPriorities[ESM::PRT_Head] <= 1)
|
2012-11-08 13:46:24 +04:00
|
|
|
addOrReplaceIndividualPart(ESM::PRT_Hair, -1,1, mHairModel);
|
2012-07-12 20:12:18 -07:00
|
|
|
|
2013-04-09 09:07:05 -07:00
|
|
|
if(mViewMode == VM_HeadOnly)
|
2013-03-06 18:03:47 +01:00
|
|
|
return;
|
|
|
|
|
2012-07-12 20:12:18 -07:00
|
|
|
static const struct {
|
|
|
|
ESM::PartReferenceType type;
|
|
|
|
const char name[2][12];
|
|
|
|
} PartTypeList[] = {
|
|
|
|
{ ESM::PRT_Neck, { "neck", "" } },
|
|
|
|
{ ESM::PRT_Cuirass, { "chest", "" } },
|
|
|
|
{ ESM::PRT_Groin, { "groin", "" } },
|
|
|
|
{ ESM::PRT_RHand, { "hand", "hands" } },
|
|
|
|
{ ESM::PRT_LHand, { "hand", "hands" } },
|
|
|
|
{ ESM::PRT_RWrist, { "wrist", "" } },
|
|
|
|
{ ESM::PRT_LWrist, { "wrist", "" } },
|
|
|
|
{ ESM::PRT_RForearm, { "forearm", "" } },
|
|
|
|
{ ESM::PRT_LForearm, { "forearm", "" } },
|
|
|
|
{ ESM::PRT_RUpperarm, { "upper arm", "" } },
|
|
|
|
{ ESM::PRT_LUpperarm, { "upper arm", "" } },
|
|
|
|
{ ESM::PRT_RFoot, { "foot", "feet" } },
|
|
|
|
{ ESM::PRT_LFoot, { "foot", "feet" } },
|
|
|
|
{ ESM::PRT_RAnkle, { "ankle", "" } },
|
|
|
|
{ ESM::PRT_LAnkle, { "ankle", "" } },
|
|
|
|
{ ESM::PRT_RKnee, { "knee", "" } },
|
|
|
|
{ ESM::PRT_LKnee, { "knee", "" } },
|
|
|
|
{ ESM::PRT_RLeg, { "upper leg", "" } },
|
|
|
|
{ ESM::PRT_LLeg, { "upper leg", "" } },
|
|
|
|
{ ESM::PRT_Tail, { "tail", "" } }
|
|
|
|
};
|
|
|
|
|
2012-10-01 19:17:04 +04:00
|
|
|
const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore();
|
2012-07-12 20:12:18 -07:00
|
|
|
for(size_t i = 0;i < sizeof(PartTypeList)/sizeof(PartTypeList[0]);i++)
|
|
|
|
{
|
2012-07-17 10:57:15 -07:00
|
|
|
if(mPartPriorities[PartTypeList[i].type] < 1)
|
2012-07-12 20:12:18 -07:00
|
|
|
{
|
|
|
|
const ESM::BodyPart *part = NULL;
|
2013-01-06 01:59:18 -08:00
|
|
|
const MWWorld::Store<ESM::BodyPart> &partStore = store.get<ESM::BodyPart>();
|
2012-11-08 13:46:24 +04:00
|
|
|
|
2013-01-06 01:59:18 -08:00
|
|
|
if(!mNpc->isMale())
|
|
|
|
{
|
2012-11-08 13:46:24 +04:00
|
|
|
part = partStore.search(mBodyPrefix + "_f_" + PartTypeList[i].name[0]);
|
2013-01-06 01:59:18 -08:00
|
|
|
if(part == 0)
|
2012-11-08 13:46:24 +04:00
|
|
|
part = partStore.search(mBodyPrefix + "_f_" + PartTypeList[i].name[1]);
|
|
|
|
}
|
2013-01-06 01:59:18 -08:00
|
|
|
if(part == 0)
|
2012-11-08 13:46:24 +04:00
|
|
|
part = partStore.search(mBodyPrefix + "_m_" + PartTypeList[i].name[0]);
|
2013-01-06 01:59:18 -08:00
|
|
|
if(part == 0)
|
2012-11-08 13:46:24 +04:00
|
|
|
part = partStore.search(mBodyPrefix + "_m_" + PartTypeList[i].name[1]);
|
2012-04-14 22:52:05 -04:00
|
|
|
|
2012-07-12 20:12:18 -07:00
|
|
|
if(part)
|
2012-09-17 11:37:50 +04:00
|
|
|
addOrReplaceIndividualPart(PartTypeList[i].type, -1,1, "meshes\\"+part->mModel);
|
2012-07-12 20:12:18 -07:00
|
|
|
}
|
|
|
|
}
|
2011-12-11 22:40:00 -05:00
|
|
|
}
|
|
|
|
|
2013-04-07 01:52:35 -07:00
|
|
|
NifOgre::ObjectList NpcAnimation::insertBoundedPart(const std::string &model, int group, const std::string &bonename)
|
2012-07-12 20:12:18 -07:00
|
|
|
{
|
2013-04-07 01:52:35 -07:00
|
|
|
NifOgre::ObjectList objects = NifOgre::Loader::createObjects(mObjectList.mSkelBase, bonename,
|
|
|
|
mInsert, model);
|
2013-04-07 02:08:33 -07:00
|
|
|
for(size_t i = 0;i < objects.mEntities.size();i++)
|
2012-09-14 14:34:18 +02:00
|
|
|
{
|
2013-04-07 02:08:33 -07:00
|
|
|
objects.mEntities[i]->getUserObjectBindings().setUserAny(Ogre::Any(group));
|
|
|
|
if(mVisibilityFlags != 0)
|
|
|
|
objects.mEntities[i]->setVisibilityFlags(mVisibilityFlags);
|
2013-03-01 13:27:25 -08:00
|
|
|
|
2013-04-07 02:08:33 -07:00
|
|
|
for(unsigned int j=0; j < objects.mEntities[i]->getNumSubEntities(); ++j)
|
2013-03-01 13:27:25 -08:00
|
|
|
{
|
2013-04-07 02:08:33 -07:00
|
|
|
Ogre::SubEntity* subEnt = objects.mEntities[i]->getSubEntity(j);
|
2013-03-04 16:57:00 +01:00
|
|
|
subEnt->setRenderQueueGroup(subEnt->getMaterial()->isTransparent() ? RQG_Alpha : RQG_Main);
|
2013-03-01 13:27:25 -08:00
|
|
|
}
|
2012-09-14 14:34:18 +02:00
|
|
|
}
|
2013-04-07 02:08:33 -07:00
|
|
|
for(size_t i = 0;i < objects.mParticles.size();i++)
|
|
|
|
{
|
|
|
|
objects.mParticles[i]->getUserObjectBindings().setUserAny(Ogre::Any(group));
|
|
|
|
if(mVisibilityFlags != 0)
|
|
|
|
objects.mParticles[i]->setVisibilityFlags(mVisibilityFlags);
|
|
|
|
objects.mParticles[i]->setRenderQueueGroup(RQG_Alpha);
|
|
|
|
}
|
2013-04-07 01:52:35 -07:00
|
|
|
if(objects.mSkelBase)
|
2013-01-30 09:29:16 -08:00
|
|
|
{
|
2013-04-07 01:52:35 -07:00
|
|
|
Ogre::AnimationStateSet *aset = objects.mSkelBase->getAllAnimationStates();
|
2013-01-30 09:29:16 -08:00
|
|
|
Ogre::AnimationStateIterator asiter = aset->getAnimationStateIterator();
|
|
|
|
while(asiter.hasMoreElements())
|
|
|
|
{
|
|
|
|
Ogre::AnimationState *state = asiter.getNext();
|
|
|
|
state->setEnabled(false);
|
|
|
|
state->setLoop(false);
|
|
|
|
}
|
2013-04-07 01:52:35 -07:00
|
|
|
Ogre::SkeletonInstance *skelinst = objects.mSkelBase->getSkeleton();
|
2013-01-30 09:29:16 -08:00
|
|
|
Ogre::Skeleton::BoneIterator boneiter = skelinst->getBoneIterator();
|
|
|
|
while(boneiter.hasMoreElements())
|
|
|
|
boneiter.getNext()->setManuallyControlled(true);
|
|
|
|
}
|
2013-04-07 01:52:35 -07:00
|
|
|
return objects;
|
2012-04-15 22:49:17 -04:00
|
|
|
}
|
2012-04-15 22:06:05 +02:00
|
|
|
|
2013-01-18 16:21:29 -08:00
|
|
|
Ogre::Vector3 NpcAnimation::runAnimation(float timepassed)
|
2012-07-12 20:12:18 -07:00
|
|
|
{
|
2013-02-22 10:15:29 -08:00
|
|
|
if(mTimeToChange <= 0.0f)
|
2012-07-12 20:12:18 -07:00
|
|
|
{
|
2013-02-22 10:15:29 -08:00
|
|
|
mTimeToChange = 0.2f;
|
2012-07-12 20:12:18 -07:00
|
|
|
updateParts();
|
2011-12-15 00:33:10 -05:00
|
|
|
}
|
2013-02-22 10:15:29 -08:00
|
|
|
mTimeToChange -= timepassed;
|
2012-04-15 22:06:05 +02:00
|
|
|
|
2013-01-30 09:29:16 -08:00
|
|
|
Ogre::Vector3 ret = Animation::runAnimation(timepassed);
|
2013-04-07 01:52:35 -07:00
|
|
|
const Ogre::SkeletonInstance *skelsrc = mObjectList.mSkelBase->getSkeleton();
|
2013-01-30 09:29:16 -08:00
|
|
|
for(size_t i = 0;i < sPartListSize;i++)
|
|
|
|
{
|
2013-04-07 01:52:35 -07:00
|
|
|
Ogre::Entity *ent = mObjectParts[i].mSkelBase;
|
2013-01-30 09:29:16 -08:00
|
|
|
if(!ent) continue;
|
|
|
|
updateSkeletonInstance(skelsrc, ent->getSkeleton());
|
|
|
|
ent->getAllAnimationStates()->_notifyDirty();
|
|
|
|
}
|
|
|
|
return ret;
|
2012-01-17 15:10:53 +01:00
|
|
|
}
|
2012-04-12 20:40:11 -04:00
|
|
|
|
2012-07-12 20:12:18 -07:00
|
|
|
void NpcAnimation::removeIndividualPart(int type)
|
|
|
|
{
|
2012-07-17 10:57:15 -07:00
|
|
|
mPartPriorities[type] = 0;
|
|
|
|
mPartslots[type] = -1;
|
2012-04-15 22:06:05 +02:00
|
|
|
|
2013-01-06 01:59:18 -08:00
|
|
|
for(size_t i = 0;i < sPartListSize;i++)
|
2012-07-12 20:12:18 -07:00
|
|
|
{
|
2013-01-06 01:59:18 -08:00
|
|
|
if(type == sPartList[i].type)
|
|
|
|
{
|
2013-04-07 13:02:46 -07:00
|
|
|
destroyObjectList(mInsert->getCreator(), mObjectParts[i]);
|
2013-01-06 01:59:18 -08:00
|
|
|
break;
|
|
|
|
}
|
2012-07-12 20:12:18 -07:00
|
|
|
}
|
|
|
|
}
|
2012-04-12 20:40:11 -04:00
|
|
|
|
2012-07-12 20:12:18 -07:00
|
|
|
void NpcAnimation::reserveIndividualPart(int type, int group, int priority)
|
|
|
|
{
|
2012-07-17 10:57:15 -07:00
|
|
|
if(priority > mPartPriorities[type])
|
2012-07-12 20:12:18 -07:00
|
|
|
{
|
|
|
|
removeIndividualPart(type);
|
2012-07-17 10:57:15 -07:00
|
|
|
mPartPriorities[type] = priority;
|
|
|
|
mPartslots[type] = group;
|
2012-04-12 20:59:30 -04:00
|
|
|
}
|
2012-07-12 20:12:18 -07:00
|
|
|
}
|
2012-04-12 22:16:02 -04:00
|
|
|
|
2012-07-12 20:12:18 -07:00
|
|
|
void NpcAnimation::removePartGroup(int group)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < 27; i++)
|
|
|
|
{
|
2012-07-17 10:57:15 -07:00
|
|
|
if(mPartslots[i] == group)
|
2012-07-12 20:12:18 -07:00
|
|
|
removeIndividualPart(i);
|
|
|
|
}
|
|
|
|
}
|
2012-04-12 22:16:02 -04:00
|
|
|
|
2012-07-12 20:12:18 -07:00
|
|
|
bool NpcAnimation::addOrReplaceIndividualPart(int type, int group, int priority, const std::string &mesh)
|
|
|
|
{
|
2012-07-17 10:57:15 -07:00
|
|
|
if(priority <= mPartPriorities[type])
|
2012-04-12 22:16:02 -04:00
|
|
|
return false;
|
2012-04-14 18:58:52 -04:00
|
|
|
|
2012-07-12 20:12:18 -07:00
|
|
|
removeIndividualPart(type);
|
2012-07-17 10:57:15 -07:00
|
|
|
mPartslots[type] = group;
|
|
|
|
mPartPriorities[type] = priority;
|
2013-01-06 01:59:18 -08:00
|
|
|
|
|
|
|
for(size_t i = 0;i < sPartListSize;i++)
|
2012-07-12 20:12:18 -07:00
|
|
|
{
|
2013-01-06 01:59:18 -08:00
|
|
|
if(type == sPartList[i].type)
|
|
|
|
{
|
2013-04-07 01:52:35 -07:00
|
|
|
mObjectParts[i] = insertBoundedPart(mesh, group, sPartList[i].name);
|
2012-07-12 20:12:18 -07:00
|
|
|
break;
|
2013-01-06 01:59:18 -08:00
|
|
|
}
|
2012-07-12 20:12:18 -07:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-04-15 22:06:05 +02:00
|
|
|
|
2013-01-09 08:03:28 -08:00
|
|
|
void NpcAnimation::addPartGroup(int group, int priority, const std::vector<ESM::PartReference> &parts)
|
2012-07-12 20:12:18 -07:00
|
|
|
{
|
|
|
|
for(std::size_t i = 0; i < parts.size(); i++)
|
|
|
|
{
|
2013-01-09 08:03:28 -08:00
|
|
|
const ESM::PartReference &part = parts[i];
|
2012-04-16 14:06:27 +02:00
|
|
|
|
2012-11-08 13:46:24 +04:00
|
|
|
const MWWorld::Store<ESM::BodyPart> &partStore =
|
2012-11-06 11:53:00 +04:00
|
|
|
MWBase::Environment::get().getWorld()->getStore().get<ESM::BodyPart>();
|
|
|
|
|
2012-07-12 20:12:18 -07:00
|
|
|
const ESM::BodyPart *bodypart = 0;
|
2012-11-08 13:46:24 +04:00
|
|
|
if(!mNpc->isMale())
|
|
|
|
bodypart = partStore.search(part.mFemale);
|
2012-07-12 20:12:18 -07:00
|
|
|
if(!bodypart)
|
2012-11-08 13:46:24 +04:00
|
|
|
bodypart = partStore.search(part.mMale);
|
2012-04-15 22:06:05 +02:00
|
|
|
|
2012-07-12 20:12:18 -07:00
|
|
|
if(bodypart)
|
2013-01-09 07:43:10 -08:00
|
|
|
addOrReplaceIndividualPart(part.mPart, group, priority, "meshes\\"+bodypart->mModel);
|
2012-07-12 20:12:18 -07:00
|
|
|
else
|
2012-09-17 11:37:50 +04:00
|
|
|
reserveIndividualPart(part.mPart, group, priority);
|
2012-04-14 18:58:52 -04:00
|
|
|
}
|
2012-01-17 15:10:53 +01:00
|
|
|
}
|
2012-07-12 20:12:18 -07:00
|
|
|
|
|
|
|
}
|