1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 13:49:55 +00:00
openmw-tes3mp/apps/openmw/mwrender/npcanimation.cpp

600 lines
22 KiB
C++
Raw Normal View History

#include "npcanimation.hpp"
#include <OgreSceneManager.h>
#include <OgreEntity.h>
#include <OgreSubEntity.h>
2012-10-01 15:17:04 +00:00
#include "../mwworld/esmstore.hpp"
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
#include "renderconst.hpp"
2012-04-08 02:02:20 +00:00
using namespace Ogre;
using namespace NifOgre;
namespace MWRender{
NpcAnimation::~NpcAnimation()
{
2012-11-08 09:46:24 +00:00
removeEntities(mHead);
removeEntities(mHair);
removeEntities(mNeck);
removeEntities(mChest);
removeEntities(mGroin);
removeEntities(mSkirt);
removeEntities(mHandL);
removeEntities(mHandR);
removeEntities(mWristL);
removeEntities(mWristR);
removeEntities(mForearmL);
removeEntities(mForearmR);
removeEntities(mUpperArmL);
removeEntities(mUpperArmR);
removeEntities(mFootL);
removeEntities(mFootR);
removeEntities(mAnkleL);
removeEntities(mAnkleR);
removeEntities(mKneeL);
removeEntities(mKneeR);
removeEntities(mUpperLegL);
removeEntities(mUpperLegR);
removeEntities(mClavicleL);
removeEntities(mClavicleR);
removeEntities(mTail);
2011-12-12 04:42:39 +00:00
}
2012-11-08 09:46:24 +00:00
NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, Ogre::SceneNode* node, MWWorld::InventoryStore& inv, int visibilityFlags)
: Animation(),
mStateID(-1),
mInv(inv),
mTimeToChange(0),
mVisibilityFlags(visibilityFlags),
mRobe(mInv.end()),
mHelmet(mInv.end()),
mShirt(mInv.end()),
mCuirass(mInv.end()),
mGreaves(mInv.end()),
mPauldronL(mInv.end()),
mPauldronR(mInv.end()),
mBoots(mInv.end()),
mPants(mInv.end()),
mGloveL(mInv.end()),
mGloveR(mInv.end()),
mSkirtIter(mInv.end())
{
2012-11-08 09:46:24 +00:00
mNpc = ptr.get<ESM::NPC>()->mBase;
for (int init = 0; init < 27; init++)
{
mPartslots[init] = -1; //each slot is empty
mPartPriorities[init] = 0;
}
const MWWorld::ESMStore &store =
MWBase::Environment::get().getWorld()->getStore();
2012-11-08 09:46:24 +00:00
const ESM::Race *race = store.get<ESM::Race>().find(mNpc->mRace);
2012-11-08 09:46:24 +00:00
mHeadModel = "meshes\\" + store.get<ESM::BodyPart>().find(mNpc->mHead)->mModel;
mHairModel = "meshes\\" + store.get<ESM::BodyPart>().find(mNpc->mHair)->mModel;
2012-11-08 09:46:24 +00:00
mBodyPrefix = "b_n_" + mNpc->mRace;
std::transform(mBodyPrefix.begin(), mBodyPrefix.end(), mBodyPrefix.begin(), ::tolower);
2012-09-13 17:03:31 +00:00
mInsert = node;
assert(mInsert);
2012-01-17 14:10:53 +00:00
2012-11-08 09:46:24 +00:00
bool isBeast = (race->mData.mFlags & ESM::Race::Beast) != 0;
std::string smodel = (!isBeast ? "meshes\\base_anim.nif" : "meshes\\base_animkna.nif");
mEntityList = NifOgre::NIFLoader::createEntities(mInsert, &mTextKeys, smodel);
2012-07-17 23:00:03 +00:00
for(size_t i = 0;i < mEntityList.mEntities.size();i++)
2012-04-04 16:53:40 +00:00
{
2012-07-17 23:00:03 +00:00
Ogre::Entity *base = mEntityList.mEntities[i];
2012-09-14 12:34:18 +00:00
base->getUserObjectBindings ().setUserAny (Ogre::Any(-1));
2012-09-13 17:03:31 +00:00
base->setVisibilityFlags(mVisibilityFlags);
bool transparent = false;
for(unsigned int j=0;j < base->getNumSubEntities();++j)
2012-04-04 16:53:40 +00:00
{
Ogre::MaterialPtr mat = base->getSubEntity(j)->getMaterial();
Ogre::Material::TechniqueIterator techIt = mat->getTechniqueIterator();
while (techIt.hasMoreElements())
2012-04-04 16:53:40 +00:00
{
Ogre::Technique* tech = techIt.getNext();
Ogre::Technique::PassIterator passIt = tech->getPassIterator();
while (passIt.hasMoreElements())
{
Ogre::Pass* pass = passIt.getNext();
if (pass->getDepthWriteEnabled() == false)
transparent = true;
}
2012-04-04 16:53:40 +00:00
}
}
base->setRenderQueueGroup(transparent ? RQG_Alpha : RQG_Main);
}
2012-01-17 14:10:53 +00:00
if(mEntityList.mSkelBase)
{
Ogre::AnimationStateSet *aset = mEntityList.mSkelBase->getAllAnimationStates();
Ogre::AnimationStateIterator as = aset->getAnimationStateIterator();
while(as.hasMoreElements())
{
Ogre::AnimationState *state = as.getNext();
state->setEnabled(true);
state->setLoop(false);
}
}
2012-09-17 07:37:50 +00:00
float scale = race->mData.mHeight.mMale;
2012-11-08 09:46:24 +00:00
if (!mNpc->isMale()) {
2012-09-17 07:37:50 +00:00
scale = race->mData.mHeight.mFemale;
}
mInsert->scale(scale, scale, scale);
2012-01-17 14:10:53 +00:00
updateParts();
2012-04-08 21:27:56 +00:00
}
2012-01-17 14:10:53 +00:00
void NpcAnimation::updateParts()
{
bool apparelChanged = false;
const struct {
MWWorld::ContainerStoreIterator *iter;
int slot;
} slotlist[] = {
2012-11-08 09:46:24 +00:00
{ &mRobe, MWWorld::InventoryStore::Slot_Robe },
{ &mSkirtIter, MWWorld::InventoryStore::Slot_Skirt },
{ &mHelmet, MWWorld::InventoryStore::Slot_Helmet },
{ &mCuirass, MWWorld::InventoryStore::Slot_Cuirass },
{ &mGreaves, MWWorld::InventoryStore::Slot_Greaves },
{ &mPauldronL, MWWorld::InventoryStore::Slot_LeftPauldron },
{ &mPauldronR, MWWorld::InventoryStore::Slot_RightPauldron },
{ &mBoots, MWWorld::InventoryStore::Slot_Boots },
{ &mGloveL, MWWorld::InventoryStore::Slot_LeftGauntlet },
{ &mGloveR, MWWorld::InventoryStore::Slot_RightGauntlet },
{ &mShirt, MWWorld::InventoryStore::Slot_Shirt },
{ &mPants, MWWorld::InventoryStore::Slot_Pants },
};
for(size_t i = 0;i < sizeof(slotlist)/sizeof(slotlist[0]);i++)
{
MWWorld::ContainerStoreIterator iter = mInv.getSlot(slotlist[i].slot);
if(*slotlist[i].iter != iter)
{
*slotlist[i].iter = iter;
removePartGroup(slotlist[i].slot);
apparelChanged = true;
}
}
if(apparelChanged)
{
2012-11-08 09:46:24 +00:00
if(mRobe != mInv.end())
{
2012-11-08 09:46:24 +00:00
MWWorld::Ptr ptr = *mRobe;
2012-11-05 12:07:59 +00:00
const ESM::Clothing *clothes = (ptr.get<ESM::Clothing>())->mBase;
2012-09-17 07:37:50 +00:00
std::vector<ESM::PartReference> parts = clothes->mParts.mParts;
addPartGroup(MWWorld::InventoryStore::Slot_Robe, 5, parts);
reserveIndividualPart(ESM::PRT_Groin, MWWorld::InventoryStore::Slot_Robe, 5);
reserveIndividualPart(ESM::PRT_Skirt, MWWorld::InventoryStore::Slot_Robe, 5);
reserveIndividualPart(ESM::PRT_RLeg, MWWorld::InventoryStore::Slot_Robe, 5);
reserveIndividualPart(ESM::PRT_LLeg, MWWorld::InventoryStore::Slot_Robe, 5);
reserveIndividualPart(ESM::PRT_RUpperarm, MWWorld::InventoryStore::Slot_Robe, 5);
reserveIndividualPart(ESM::PRT_LUpperarm, MWWorld::InventoryStore::Slot_Robe, 5);
reserveIndividualPart(ESM::PRT_RKnee, MWWorld::InventoryStore::Slot_Robe, 5);
reserveIndividualPart(ESM::PRT_LKnee, MWWorld::InventoryStore::Slot_Robe, 5);
reserveIndividualPart(ESM::PRT_RForearm, MWWorld::InventoryStore::Slot_Robe, 5);
reserveIndividualPart(ESM::PRT_LForearm, MWWorld::InventoryStore::Slot_Robe, 5);
reserveIndividualPart(ESM::PRT_RPauldron, MWWorld::InventoryStore::Slot_Robe, 5);
reserveIndividualPart(ESM::PRT_LPauldron, MWWorld::InventoryStore::Slot_Robe, 5);
}
2012-11-08 09:46:24 +00:00
if(mSkirtIter != mInv.end())
{
2012-11-08 09:46:24 +00:00
MWWorld::Ptr ptr = *mSkirtIter;
2012-01-17 14:10:53 +00:00
2012-11-05 12:07:59 +00:00
const ESM::Clothing *clothes = (ptr.get<ESM::Clothing>())->mBase;
2012-09-17 07:37:50 +00:00
std::vector<ESM::PartReference> parts = clothes->mParts.mParts;
addPartGroup(MWWorld::InventoryStore::Slot_Skirt, 4, parts);
reserveIndividualPart(ESM::PRT_Groin, MWWorld::InventoryStore::Slot_Skirt, 4);
reserveIndividualPart(ESM::PRT_RLeg, MWWorld::InventoryStore::Slot_Skirt, 4);
reserveIndividualPart(ESM::PRT_LLeg, MWWorld::InventoryStore::Slot_Skirt, 4);
2012-04-15 00:32:46 +00:00
}
2012-11-08 09:46:24 +00:00
if(mHelmet != mInv.end())
{
removeIndividualPart(ESM::PRT_Hair);
2012-11-08 09:46:24 +00:00
const ESM::Armor *armor = (mHelmet->get<ESM::Armor>())->mBase;
2012-09-17 07:37:50 +00:00
std::vector<ESM::PartReference> parts = armor->mParts.mParts;
addPartGroup(MWWorld::InventoryStore::Slot_Helmet, 3, parts);
2012-04-15 00:32:46 +00:00
}
2012-11-08 09:46:24 +00:00
if(mCuirass != mInv.end())
{
2012-11-08 09:46:24 +00:00
const ESM::Armor *armor = (mCuirass->get<ESM::Armor>())->mBase;
2012-09-17 07:37:50 +00:00
std::vector<ESM::PartReference> parts = armor->mParts.mParts;
addPartGroup(MWWorld::InventoryStore::Slot_Cuirass, 3, parts);
2012-04-15 00:32:46 +00:00
}
2012-11-08 09:46:24 +00:00
if(mGreaves != mInv.end())
{
2012-11-08 09:46:24 +00:00
const ESM::Armor *armor = (mGreaves->get<ESM::Armor>())->mBase;
2012-09-17 07:37:50 +00:00
std::vector<ESM::PartReference> parts = armor->mParts.mParts;
addPartGroup(MWWorld::InventoryStore::Slot_Greaves, 3, parts);
2012-04-14 20:44:46 +00:00
}
2012-01-17 14:10:53 +00:00
2012-11-08 09:46:24 +00:00
if(mPauldronL != mInv.end())
{
2012-11-08 09:46:24 +00:00
const ESM::Armor *armor = (mPauldronL->get<ESM::Armor>())->mBase;
2012-09-17 07:37:50 +00:00
std::vector<ESM::PartReference> parts = armor->mParts.mParts;
addPartGroup(MWWorld::InventoryStore::Slot_LeftPauldron, 3, parts);
2012-04-15 02:52:05 +00:00
}
2012-11-08 09:46:24 +00:00
if(mPauldronR != mInv.end())
{
2012-11-08 09:46:24 +00:00
const ESM::Armor *armor = (mPauldronR->get<ESM::Armor>())->mBase;
2012-09-17 07:37:50 +00:00
std::vector<ESM::PartReference> parts = armor->mParts.mParts;
addPartGroup(MWWorld::InventoryStore::Slot_RightPauldron, 3, parts);
2012-04-14 20:44:46 +00:00
}
2012-11-08 09:46:24 +00:00
if(mBoots != mInv.end())
{
2012-11-08 09:46:24 +00:00
if(mBoots->getTypeName() == typeid(ESM::Clothing).name())
2012-04-12 00:16:22 +00:00
{
2012-11-08 09:46:24 +00:00
const ESM::Clothing *clothes = (mBoots->get<ESM::Clothing>())->mBase;
2012-09-17 07:37:50 +00:00
std::vector<ESM::PartReference> parts = clothes->mParts.mParts;
addPartGroup(MWWorld::InventoryStore::Slot_Boots, 2, parts);
2012-04-15 19:16:48 +00:00
}
2012-11-08 09:46:24 +00:00
else if(mBoots->getTypeName() == typeid(ESM::Armor).name())
2012-04-15 19:16:48 +00:00
{
2012-11-08 09:46:24 +00:00
const ESM::Armor *armor = (mBoots->get<ESM::Armor>())->mBase;
2012-09-17 07:37:50 +00:00
std::vector<ESM::PartReference> parts = armor->mParts.mParts;
addPartGroup(MWWorld::InventoryStore::Slot_Boots, 3, parts);
2012-04-12 00:16:22 +00:00
}
}
2012-11-08 09:46:24 +00:00
if(mGloveL != mInv.end())
{
2012-11-08 09:46:24 +00:00
if(mGloveL->getTypeName() == typeid(ESM::Clothing).name())
{
2012-11-08 09:46:24 +00:00
const ESM::Clothing *clothes = (mGloveL->get<ESM::Clothing>())->mBase;
2012-09-17 07:37:50 +00:00
std::vector<ESM::PartReference> parts = clothes->mParts.mParts;
addPartGroup(MWWorld::InventoryStore::Slot_LeftGauntlet, 2, parts);
2012-04-14 22:58:52 +00:00
}
else
{
2012-11-08 09:46:24 +00:00
const ESM::Armor *armor = (mGloveL->get<ESM::Armor>())->mBase;
2012-09-17 07:37:50 +00:00
std::vector<ESM::PartReference> parts = armor->mParts.mParts;
addPartGroup(MWWorld::InventoryStore::Slot_LeftGauntlet, 3, parts);
2012-04-14 23:21:14 +00:00
}
}
2012-11-08 09:46:24 +00:00
if(mGloveR != mInv.end())
{
2012-11-08 09:46:24 +00:00
if(mGloveR->getTypeName() == typeid(ESM::Clothing).name())
{
2012-11-08 09:46:24 +00:00
const ESM::Clothing *clothes = (mGloveR->get<ESM::Clothing>())->mBase;
2012-09-17 07:37:50 +00:00
std::vector<ESM::PartReference> parts = clothes->mParts.mParts;
addPartGroup(MWWorld::InventoryStore::Slot_RightGauntlet, 2, parts);
2012-04-14 23:21:14 +00:00
}
else
{
2012-11-08 09:46:24 +00:00
const ESM::Armor *armor = (mGloveR->get<ESM::Armor>())->mBase;
2012-09-17 07:37:50 +00:00
std::vector<ESM::PartReference> parts = armor->mParts.mParts;
addPartGroup(MWWorld::InventoryStore::Slot_RightGauntlet, 3, parts);
2012-04-15 00:32:46 +00:00
}
2011-12-15 05:33:10 +00:00
}
2012-04-14 03:25:15 +00:00
2012-11-08 09:46:24 +00:00
if(mShirt != mInv.end())
{
2012-11-08 09:46:24 +00:00
const ESM::Clothing *clothes = (mShirt->get<ESM::Clothing>())->mBase;
2012-09-17 07:37:50 +00:00
std::vector<ESM::PartReference> parts = clothes->mParts.mParts;
addPartGroup(MWWorld::InventoryStore::Slot_Shirt, 2, parts);
}
2012-11-08 09:46:24 +00:00
if(mPants != mInv.end())
{
2012-11-08 09:46:24 +00:00
const ESM::Clothing *clothes = (mPants->get<ESM::Clothing>())->mBase;
2012-09-17 07:37:50 +00:00
std::vector<ESM::PartReference> parts = clothes->mParts.mParts;
addPartGroup(MWWorld::InventoryStore::Slot_Pants, 2, parts);
}
}
if(mPartPriorities[ESM::PRT_Head] < 1)
2012-11-08 09:46:24 +00:00
addOrReplaceIndividualPart(ESM::PRT_Head, -1,1, mHeadModel);
if(mPartPriorities[ESM::PRT_Hair] < 1 && mPartPriorities[ESM::PRT_Head] <= 1)
2012-11-08 09:46:24 +00:00
addOrReplaceIndividualPart(ESM::PRT_Hair, -1,1, mHairModel);
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 15:17:04 +00:00
const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore();
for(size_t i = 0;i < sizeof(PartTypeList)/sizeof(PartTypeList[0]);i++)
{
if(mPartPriorities[PartTypeList[i].type] < 1)
{
const ESM::BodyPart *part = NULL;
2012-11-08 09:46:24 +00:00
const MWWorld::Store<ESM::BodyPart> &partStore =
store.get<ESM::BodyPart>();
if (!mNpc->isMale()) {
part = partStore.search(mBodyPrefix + "_f_" + PartTypeList[i].name[0]);
if (part == 0) {
part = partStore.search(mBodyPrefix + "_f_" + PartTypeList[i].name[1]);
2012-04-15 02:52:05 +00:00
}
2012-11-08 09:46:24 +00:00
}
if (part == 0) {
part = partStore.search(mBodyPrefix + "_m_" + PartTypeList[i].name[0]);
}
if (part == 0) {
part = partStore.search(mBodyPrefix + "_m_" + PartTypeList[i].name[1]);
}
2012-04-15 02:52:05 +00:00
if(part)
2012-09-17 07:37:50 +00:00
addOrReplaceIndividualPart(PartTypeList[i].type, -1,1, "meshes\\"+part->mModel);
}
}
}
2012-09-14 12:34:18 +00:00
NifOgre::EntityList NpcAnimation::insertBoundedPart(const std::string &mesh, int group, const std::string &bonename)
{
2012-07-18 18:14:13 +00:00
NifOgre::EntityList entities = NIFLoader::createEntities(mEntityList.mSkelBase, bonename,
mInsert, mesh);
std::vector<Ogre::Entity*> &parts = entities.mEntities;
for(size_t i = 0;i < parts.size();i++)
2012-09-14 12:34:18 +00:00
{
2012-09-13 17:03:31 +00:00
parts[i]->setVisibilityFlags(mVisibilityFlags);
2012-09-14 12:34:18 +00:00
parts[i]->getUserObjectBindings ().setUserAny (Ogre::Any(group));
}
2012-07-18 17:26:25 +00:00
return entities;
2012-04-16 02:49:17 +00:00
}
void NpcAnimation::runAnimation(float timepassed)
{
2012-11-08 09:46:24 +00:00
if(mTimeToChange > .2)
{
2012-11-08 09:46:24 +00:00
mTimeToChange = 0;
updateParts();
2011-12-15 05:33:10 +00:00
}
2012-11-08 09:46:24 +00:00
mTimeToChange += timepassed;
Animation::runAnimation(timepassed);
2012-01-17 14:10:53 +00:00
}
2012-04-13 00:40:11 +00:00
2012-07-18 17:26:25 +00:00
void NpcAnimation::removeEntities(NifOgre::EntityList &entities)
2012-07-17 19:19:50 +00:00
{
2012-07-18 17:26:25 +00:00
assert(&entities != &mEntityList);
2012-07-18 05:47:56 +00:00
Ogre::SceneManager *sceneMgr = mInsert->getCreator();
2012-07-18 17:26:25 +00:00
for(size_t i = 0;i < entities.mEntities.size();i++)
2012-07-18 05:47:56 +00:00
{
2012-07-19 04:39:50 +00:00
entities.mEntities[i]->detachFromParent();
2012-07-18 17:26:25 +00:00
sceneMgr->destroyEntity(entities.mEntities[i]);
2012-07-18 05:47:56 +00:00
}
2012-07-18 17:26:25 +00:00
entities.mEntities.clear();
entities.mSkelBase = NULL;
2012-07-17 19:19:50 +00:00
}
void NpcAnimation::removeIndividualPart(int type)
{
mPartPriorities[type] = 0;
mPartslots[type] = -1;
2012-07-17 19:19:50 +00:00
if(type == ESM::PRT_Head) //0
2012-11-08 09:46:24 +00:00
removeEntities(mHead);
2012-07-17 19:19:50 +00:00
else if(type == ESM::PRT_Hair) //1
2012-11-08 09:46:24 +00:00
removeEntities(mHair);
2012-07-17 19:19:50 +00:00
else if(type == ESM::PRT_Neck) //2
2012-11-08 09:46:24 +00:00
removeEntities(mNeck);
2012-07-19 03:14:23 +00:00
else if(type == ESM::PRT_Cuirass)//3
2012-11-08 09:46:24 +00:00
removeEntities(mChest);
2012-07-17 19:19:50 +00:00
else if(type == ESM::PRT_Groin)//4
2012-11-08 09:46:24 +00:00
removeEntities(mGroin);
2012-07-19 05:32:26 +00:00
else if(type == ESM::PRT_Skirt)//5
2012-11-08 09:46:24 +00:00
removeEntities(mSkirt);
2012-07-19 03:14:23 +00:00
else if(type == ESM::PRT_RHand)//6
2012-11-08 09:46:24 +00:00
removeEntities(mHandR);
2012-07-19 03:14:23 +00:00
else if(type == ESM::PRT_LHand)//7
2012-11-08 09:46:24 +00:00
removeEntities(mHandL);
2012-07-17 19:19:50 +00:00
else if(type == ESM::PRT_RWrist)//8
2012-11-08 09:46:24 +00:00
removeEntities(mWristR);
2012-07-17 19:19:50 +00:00
else if(type == ESM::PRT_LWrist) //9
2012-11-08 09:46:24 +00:00
removeEntities(mWristL);
else if(type == ESM::PRT_Shield) //10
{
}
2012-07-17 19:19:50 +00:00
else if(type == ESM::PRT_RForearm) //11
2012-11-08 09:46:24 +00:00
removeEntities(mForearmR);
2012-07-17 19:19:50 +00:00
else if(type == ESM::PRT_LForearm) //12
2012-11-08 09:46:24 +00:00
removeEntities(mForearmL);
2012-07-17 19:19:50 +00:00
else if(type == ESM::PRT_RUpperarm) //13
2012-11-08 09:46:24 +00:00
removeEntities(mUpperArmR);
2012-07-17 19:19:50 +00:00
else if(type == ESM::PRT_LUpperarm) //14
2012-11-08 09:46:24 +00:00
removeEntities(mUpperArmL);
2012-07-17 19:19:50 +00:00
else if(type == ESM::PRT_RFoot) //15
2012-11-08 09:46:24 +00:00
removeEntities(mFootR);
2012-07-17 19:19:50 +00:00
else if(type == ESM::PRT_LFoot) //16
2012-11-08 09:46:24 +00:00
removeEntities(mFootL);
2012-07-17 19:19:50 +00:00
else if(type == ESM::PRT_RAnkle) //17
2012-11-08 09:46:24 +00:00
removeEntities(mAnkleR);
2012-07-17 19:19:50 +00:00
else if(type == ESM::PRT_LAnkle) //18
2012-11-08 09:46:24 +00:00
removeEntities(mAnkleL);
2012-07-17 19:19:50 +00:00
else if(type == ESM::PRT_RKnee) //19
2012-11-08 09:46:24 +00:00
removeEntities(mKneeR);
2012-07-17 19:19:50 +00:00
else if(type == ESM::PRT_LKnee) //20
2012-11-08 09:46:24 +00:00
removeEntities(mKneeL);
2012-07-17 19:19:50 +00:00
else if(type == ESM::PRT_RLeg) //21
2012-11-08 09:46:24 +00:00
removeEntities(mUpperLegR);
2012-07-17 19:19:50 +00:00
else if(type == ESM::PRT_LLeg) //22
2012-11-08 09:46:24 +00:00
removeEntities(mUpperLegL);
2012-07-17 19:19:50 +00:00
else if(type == ESM::PRT_RPauldron) //23
2012-11-08 09:46:24 +00:00
removeEntities(mClavicleR);
2012-07-17 19:19:50 +00:00
else if(type == ESM::PRT_LPauldron) //24
2012-11-08 09:46:24 +00:00
removeEntities(mClavicleL);
else if(type == ESM::PRT_Weapon) //25
{
}
2012-07-19 03:14:23 +00:00
else if(type == ESM::PRT_Tail) //26
2012-11-08 09:46:24 +00:00
removeEntities(mTail);
}
2012-04-13 00:40:11 +00:00
void NpcAnimation::reserveIndividualPart(int type, int group, int priority)
{
if(priority > mPartPriorities[type])
{
removeIndividualPart(type);
mPartPriorities[type] = priority;
mPartslots[type] = group;
2012-04-13 00:59:30 +00:00
}
}
2012-04-13 02:16:02 +00:00
void NpcAnimation::removePartGroup(int group)
{
for(int i = 0; i < 27; i++)
{
if(mPartslots[i] == group)
removeIndividualPart(i);
}
}
2012-04-13 02:16:02 +00:00
bool NpcAnimation::addOrReplaceIndividualPart(int type, int group, int priority, const std::string &mesh)
{
if(priority <= mPartPriorities[type])
2012-04-13 02:16:02 +00:00
return false;
2012-04-14 22:58:52 +00:00
removeIndividualPart(type);
mPartslots[type] = group;
mPartPriorities[type] = priority;
switch(type)
{
case ESM::PRT_Head: //0
2012-11-08 09:46:24 +00:00
mHead = insertBoundedPart(mesh, group, "Head");
break;
case ESM::PRT_Hair: //1
2012-11-08 09:46:24 +00:00
mHair = insertBoundedPart(mesh, group, "Head");
break;
case ESM::PRT_Neck: //2
2012-11-08 09:46:24 +00:00
mNeck = insertBoundedPart(mesh, group, "Neck");
break;
case ESM::PRT_Cuirass: //3
2012-11-08 09:46:24 +00:00
mChest = insertBoundedPart(mesh, group, "Chest");
break;
case ESM::PRT_Groin: //4
2012-11-08 09:46:24 +00:00
mGroin = insertBoundedPart(mesh, group, "Groin");
break;
case ESM::PRT_Skirt: //5
2012-11-08 09:46:24 +00:00
mSkirt = insertBoundedPart(mesh, group, "Groin");
break;
case ESM::PRT_RHand: //6
2012-11-08 09:46:24 +00:00
mHandR = insertBoundedPart(mesh, group, "Right Hand");
break;
case ESM::PRT_LHand: //7
2012-11-08 09:46:24 +00:00
mHandL = insertBoundedPart(mesh, group, "Left Hand");
break;
case ESM::PRT_RWrist: //8
2012-11-08 09:46:24 +00:00
mWristR = insertBoundedPart(mesh, group, "Right Wrist");
break;
case ESM::PRT_LWrist: //9
2012-11-08 09:46:24 +00:00
mWristL = insertBoundedPart(mesh, group, "Left Wrist");
break;
case ESM::PRT_Shield: //10
break;
case ESM::PRT_RForearm: //11
2012-11-08 09:46:24 +00:00
mForearmR = insertBoundedPart(mesh, group, "Right Forearm");
break;
case ESM::PRT_LForearm: //12
2012-11-08 09:46:24 +00:00
mForearmL = insertBoundedPart(mesh, group, "Left Forearm");
break;
case ESM::PRT_RUpperarm: //13
2012-11-08 09:46:24 +00:00
mUpperArmR = insertBoundedPart(mesh, group, "Right Upper Arm");
break;
case ESM::PRT_LUpperarm: //14
2012-11-08 09:46:24 +00:00
mUpperArmL = insertBoundedPart(mesh, group, "Left Upper Arm");
break;
case ESM::PRT_RFoot: //15
2012-11-08 09:46:24 +00:00
mFootR = insertBoundedPart(mesh, group, "Right Foot");
break;
case ESM::PRT_LFoot: //16
2012-11-08 09:46:24 +00:00
mFootL = insertBoundedPart(mesh, group, "Left Foot");
break;
case ESM::PRT_RAnkle: //17
2012-11-08 09:46:24 +00:00
mAnkleR = insertBoundedPart(mesh, group, "Right Ankle");
break;
case ESM::PRT_LAnkle: //18
2012-11-08 09:46:24 +00:00
mAnkleL = insertBoundedPart(mesh, group, "Left Ankle");
break;
case ESM::PRT_RKnee: //19
2012-11-08 09:46:24 +00:00
mKneeR = insertBoundedPart(mesh, group, "Right Knee");
break;
case ESM::PRT_LKnee: //20
2012-11-08 09:46:24 +00:00
mKneeL = insertBoundedPart(mesh, group, "Left Knee");
break;
case ESM::PRT_RLeg: //21
2012-11-08 09:46:24 +00:00
mUpperLegR = insertBoundedPart(mesh, group, "Right Upper Leg");
break;
case ESM::PRT_LLeg: //22
2012-11-08 09:46:24 +00:00
mUpperLegL = insertBoundedPart(mesh, group, "Left Upper Leg");
break;
case ESM::PRT_RPauldron: //23
2012-11-08 09:46:24 +00:00
mClavicleR = insertBoundedPart(mesh , group, "Right Clavicle");
break;
case ESM::PRT_LPauldron: //24
2012-11-08 09:46:24 +00:00
mClavicleL = insertBoundedPart(mesh, group, "Left Clavicle");
break;
case ESM::PRT_Weapon: //25
break;
case ESM::PRT_Tail: //26
2012-11-08 09:46:24 +00:00
mTail = insertBoundedPart(mesh, group, "Tail");
break;
}
return true;
}
void NpcAnimation::addPartGroup(int group, int priority, std::vector<ESM::PartReference> &parts)
{
for(std::size_t i = 0; i < parts.size(); i++)
{
ESM::PartReference &part = parts[i];
2012-11-08 09:46:24 +00:00
const MWWorld::Store<ESM::BodyPart> &partStore =
MWBase::Environment::get().getWorld()->getStore().get<ESM::BodyPart>();
const ESM::BodyPart *bodypart = 0;
2012-11-08 09:46:24 +00:00
if(!mNpc->isMale())
bodypart = partStore.search(part.mFemale);
if(!bodypart)
2012-11-08 09:46:24 +00:00
bodypart = partStore.search(part.mMale);
if(bodypart)
2012-09-17 07:37:50 +00:00
addOrReplaceIndividualPart(part.mPart, group, priority,"meshes\\" + bodypart->mModel);
else
2012-09-17 07:37:50 +00:00
reserveIndividualPart(part.mPart, group, priority);
2012-04-14 22:58:52 +00:00
}
2012-01-17 14:10:53 +00:00
}
2012-09-13 17:03:31 +00:00
void NpcAnimation::forceUpdate ()
{
updateParts();
}
}