NpcAnimation compiles

c++11
scrawl 10 years ago
parent 13a1ba0aab
commit 5b8c28f641

@ -20,8 +20,8 @@ set(GAME_HEADER
source_group(game FILES ${GAME} ${GAME_HEADER})
add_openmw_dir (mwrender
actors objects renderingmanager animation sky
# debugging camera npcanimation creatureanimation activatoranimation
actors objects renderingmanager animation sky npcanimation
# debugging camera creatureanimation activatoranimation
# renderinginterface localmap occlusionquery water shadows
# characterpreview globalmap ripplesimulation refraction
# terrainstorage renderconst effectmanager weaponanimation

@ -10,9 +10,9 @@
namespace MWRender
{
Animation::Animation(const MWWorld::Ptr &ptr, osg::ref_ptr<osg::Group> node, Resource::ResourceSystem* resourceSystem)
Animation::Animation(const MWWorld::Ptr &ptr, osg::ref_ptr<osg::Group> parentNode, Resource::ResourceSystem* resourceSystem)
: mPtr(ptr)
, mInsert(node)
, mInsert(parentNode)
, mResourceSystem(resourceSystem)
{

@ -174,7 +174,7 @@ protected:
public:
Animation(const MWWorld::Ptr &ptr, osg::ref_ptr<osg::Group> node, Resource::ResourceSystem* resourceSystem);
Animation(const MWWorld::Ptr &ptr, osg::ref_ptr<osg::Group> parentNode, Resource::ResourceSystem* resourceSystem);
virtual ~Animation();
osg::Group* getOrCreateObjectRoot();

@ -10,12 +10,14 @@
#include <OgreBone.h>
#include <OgreTechnique.h>
#include <extern/shiny/Main/Factory.hpp>
#include <openengine/misc/rng.hpp>
#include <components/misc/resourcehelpers.hpp>
#include <components/resource/resourcesystem.hpp>
#include <components/resource/scenemanager.hpp>
#include <components/sceneutil/attach.hpp>
#include "../mwworld/esmstore.hpp"
#include "../mwworld/inventorystore.hpp"
#include "../mwworld/class.hpp"
@ -69,27 +71,13 @@ std::string getVampireHead(const std::string& race, bool female)
return "meshes\\" + bodyPart->mModel;
}
bool isSkinned (NifOgre::ObjectScenePtr scene)
{
if (scene->mSkelBase == NULL)
return false;
for(size_t j = 0; j < scene->mEntities.size(); j++)
{
Ogre::Entity *ent = scene->mEntities[j];
if(scene->mSkelBase != ent && ent->hasSkeleton())
{
return true;
}
}
return false;
}
}
namespace MWRender
{
/*
HeadAnimationTime::HeadAnimationTime(MWWorld::Ptr reference)
: mReference(reference), mTalkStart(0), mTalkStop(0), mBlinkStart(0), mBlinkStop(0), mValue(0), mEnabled(true)
{
@ -159,6 +147,7 @@ void HeadAnimationTime::setBlinkStop(float value)
{
mBlinkStop = value;
}
*/
static NpcAnimation::PartBoneMap createPartListMap()
{
@ -201,8 +190,8 @@ NpcAnimation::~NpcAnimation()
}
NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, Ogre::SceneNode* node, int visibilityFlags, bool disableListener, bool disableSounds, ViewMode viewMode)
: Animation(ptr, node),
NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, osg::ref_ptr<osg::Group> parentNode, Resource::ResourceSystem* resourceSystem, int visibilityFlags, bool disableListener, bool disableSounds, ViewMode viewMode)
: Animation(ptr, parentNode, resourceSystem),
mVisibilityFlags(visibilityFlags),
mListenerDisabled(disableListener),
mViewMode(viewMode),
@ -217,8 +206,8 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, Ogre::SceneNode* node, int v
{
mNpc = mPtr.get<ESM::NPC>()->mBase;
mHeadAnimationTime = Ogre::SharedPtr<HeadAnimationTime>(new HeadAnimationTime(mPtr));
mWeaponAnimationTime = Ogre::SharedPtr<WeaponAnimationTime>(new WeaponAnimationTime(this));
//mHeadAnimationTime = Ogre::SharedPtr<HeadAnimationTime>(new HeadAnimationTime(mPtr));
//mWeaponAnimationTime = Ogre::SharedPtr<WeaponAnimationTime>(new WeaponAnimationTime(this));
for(size_t i = 0;i < ESM::PRT_Count;i++)
{
@ -251,7 +240,7 @@ void NpcAnimation::rebuild()
void NpcAnimation::updateNpcBase()
{
clearAnimSources();
//clearAnimSources();
const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore();
const ESM::Race *race = store.get<ESM::Race>().find(mNpc->mRace);
@ -296,9 +285,10 @@ void NpcAnimation::updateNpcBase()
(!isWerewolf ? !isBeast ? "meshes\\base_anim.1st.nif"
: "meshes\\base_animkna.1st.nif"
: "meshes\\wolf\\skin.1st.nif");
smodel = Misc::ResourceHelpers::correctActorModelPath(smodel);
setObjectRoot(smodel, true);
smodel = Misc::ResourceHelpers::correctActorModelPath(smodel, mResourceSystem->getVFS());
setObjectRoot(smodel /*, baseonly = true*/);
/*
if(mViewMode != VM_FirstPerson)
{
addAnimSource(smodel);
@ -318,9 +308,8 @@ void NpcAnimation::updateNpcBase()
addAnimSource(smodel);
else
{
/* A bit counter-intuitive, but unlike third-person anims, it seems
* beast races get both base_anim.1st.nif and base_animkna.1st.nif.
*/
// A bit counter-intuitive, but unlike third-person anims, it seems
// beast races get both base_anim.1st.nif and base_animkna.1st.nif.
addAnimSource("meshes\\xbase_anim.1st.nif");
if(isBeast)
addAnimSource("meshes\\xbase_animkna.1st.nif");
@ -328,18 +317,19 @@ void NpcAnimation::updateNpcBase()
addAnimSource("meshes\\xbase_anim_female.1st.nif");
}
}
*/
for(size_t i = 0;i < ESM::PRT_Count;i++)
removeIndividualPart((ESM::PartReferenceType)i);
updateParts();
mWeaponAnimationTime->updateStartTime();
//mWeaponAnimationTime->updateStartTime();
}
void NpcAnimation::updateParts()
{
if (!mSkelBase)
return;
//if (!mSkelBase)
// return;
mAlpha = 1.f;
const MWWorld::Class &cls = mPtr.getClass();
@ -379,7 +369,7 @@ void NpcAnimation::updateParts()
};
static const size_t slotlistsize = sizeof(slotlist)/sizeof(slotlist[0]);
bool wasArrowAttached = (mAmmunition.get() != NULL);
bool wasArrowAttached = 0;//(mAmmunition.get() != NULL);
MWWorld::InventoryStore& inv = mPtr.getClass().getInventoryStore(mPtr);
for(size_t i = 0;i < slotlistsize && mViewMode != VM_HeadOnly;i++)
@ -396,7 +386,8 @@ void NpcAnimation::updateParts()
int prio = 1;
bool enchantedGlow = !store->getClass().getEnchantment(*store).empty();
Ogre::Vector3 glowColor = getEnchantmentColor(*store);
//Ogre::Vector3 glowColor = getEnchantmentColor(*store);
Ogre::Vector3 glowColor (1,1,1);
if(store->getTypeName() == typeid(ESM::Clothing).name())
{
prio = ((slotlist[i].mBasePriority+1)<<1) + 0;
@ -448,7 +439,7 @@ void NpcAnimation::updateParts()
const ESM::Light *light = part.get<ESM::Light>()->mBase;
addOrReplaceIndividualPart(ESM::PRT_Shield, MWWorld::InventoryStore::Slot_CarriedLeft,
1, "meshes\\"+light->mModel);
addExtraLight(mInsert->getCreator(), mObjectParts[ESM::PRT_Shield], light);
//addExtraLight(mInsert->getCreator(), mObjectParts[ESM::PRT_Shield], light);
}
}
@ -597,6 +588,15 @@ public:
}
};
PartHolderPtr NpcAnimation::insertBoundedPart(const std::string& model, int group, const std::string& bonename, const std::string& bonefilter, bool enchantedGlow, Ogre::Vector3* glowColor)
{
osg::ref_ptr<osg::Node> instance = mResourceSystem->getSceneManager()->createInstance(model);
std::cout << "inserting " << model << std::endl;
osg::ref_ptr<osg::Node> attached = SceneUtil::attach(instance, mObjectRoot, bonefilter, bonename);
return PartHolderPtr(new PartHolder(attached));
}
/*
NifOgre::ObjectScenePtr NpcAnimation::insertBoundedPart(const std::string &model, int group, const std::string &bonename, const std::string &bonefilter, bool enchantedGlow, Ogre::Vector3* glowColor)
{
NifOgre::ObjectScenePtr objects = NifOgre::Loader::createObjects(mSkelBase, bonename, bonefilter, mInsert, model);
@ -624,7 +624,9 @@ NifOgre::ObjectScenePtr NpcAnimation::insertBoundedPart(const std::string &model
return objects;
}
*/
/*
Ogre::Vector3 NpcAnimation::runAnimation(float timepassed)
{
Ogre::Vector3 ret = Animation::runAnimation(timepassed);
@ -675,13 +677,14 @@ Ogre::Vector3 NpcAnimation::runAnimation(float timepassed)
return ret;
}
*/
void NpcAnimation::removeIndividualPart(ESM::PartReferenceType type)
{
mPartPriorities[type] = 0;
mPartslots[type] = -1;
mObjectParts[type].setNull();
//mObjectParts[type].setNull();
if (!mSoundIds[type].empty() && !mSoundsDisabled)
{
MWBase::Environment::get().getSoundManager()->stopSound3D(mPtr, mSoundIds[type]);
@ -743,6 +746,7 @@ bool NpcAnimation::addOrReplaceIndividualPart(ESM::PartReferenceType type, int g
}
}
}
/*
if(mObjectParts[type]->mSkelBase)
{
Ogre::SkeletonInstance *skel = mObjectParts[type]->mSkelBase->getSkeleton();
@ -795,6 +799,7 @@ bool NpcAnimation::addOrReplaceIndividualPart(ESM::PartReferenceType type, int g
ctrl->setSource(mWeaponAnimationTime);
}
}
*/
return true;
}
@ -856,7 +861,7 @@ void NpcAnimation::showWeapons(bool showWeapon)
MWWorld::ContainerStoreIterator weapon = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedRight);
if(weapon != inv.end())
{
Ogre::Vector3 glowColor = getEnchantmentColor(*weapon);
Ogre::Vector3 glowColor (1,1,1); //= getEnchantmentColor(*weapon);
std::string mesh = weapon->getClass().getModel(*weapon);
addOrReplaceIndividualPart(ESM::PRT_Weapon, MWWorld::InventoryStore::Slot_CarriedRight, 1,
mesh, !weapon->getClass().getEnchantment(*weapon).empty(), &glowColor);
@ -868,11 +873,11 @@ void NpcAnimation::showWeapons(bool showWeapon)
MWWorld::ContainerStoreIterator ammo = inv.getSlot(MWWorld::InventoryStore::Slot_Ammunition);
if (ammo != inv.end() && ammo->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::Bolt)
attachArrow();
else
mAmmunition.setNull();
//else
//mAmmunition.setNull();
}
else
mAmmunition.setNull();
//else
//mAmmunition.setNull();
}
}
else
@ -889,29 +894,19 @@ void NpcAnimation::showCarriedLeft(bool show)
MWWorld::ContainerStoreIterator iter = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedLeft);
if(show && iter != inv.end())
{
Ogre::Vector3 glowColor = getEnchantmentColor(*iter);
Ogre::Vector3 glowColor(1,1,1);// = getEnchantmentColor(*iter);
std::string mesh = iter->getClass().getModel(*iter);
if (addOrReplaceIndividualPart(ESM::PRT_Shield, MWWorld::InventoryStore::Slot_CarriedLeft, 1,
mesh, !iter->getClass().getEnchantment(*iter).empty(), &glowColor))
{
if (iter->getTypeName() == typeid(ESM::Light).name())
addExtraLight(mInsert->getCreator(), mObjectParts[ESM::PRT_Shield], iter->get<ESM::Light>()->mBase);
//if (iter->getTypeName() == typeid(ESM::Light).name())
//addExtraLight(mInsert->getCreator(), mObjectParts[ESM::PRT_Shield], iter->get<ESM::Light>()->mBase);
}
}
else
removeIndividualPart(ESM::PRT_Shield);
}
void NpcAnimation::configureAddedObject(NifOgre::ObjectScenePtr object, MWWorld::Ptr ptr, int slot)
{
Ogre::Vector3 glowColor = getEnchantmentColor(ptr);
setRenderProperties(object, (mViewMode == VM_FirstPerson) ? RV_FirstPerson : mVisibilityFlags, RQG_Main, RQG_Alpha, 0,
!ptr.getClass().getEnchantment(ptr).empty(), &glowColor);
std::for_each(object->mEntities.begin(), object->mEntities.end(), SetObjectGroup(slot));
std::for_each(object->mParticles.begin(), object->mParticles.end(), SetObjectGroup(slot));
}
void NpcAnimation::attachArrow()
{
WeaponAnimation::attachArrow(mPtr);
@ -942,11 +937,13 @@ void NpcAnimation::permanentEffectAdded(const ESM::MagicEffect *magicEffect, boo
if (!magicEffect->mHit.empty())
{
/*
const ESM::Static* castStatic = MWBase::Environment::get().getWorld()->getStore().get<ESM::Static>().find (magicEffect->mHit);
bool loop = (magicEffect->mData.mFlags & ESM::MagicEffect::ContinuousVfx) != 0;
// Don't play particle VFX unless the effect is new or it should be looping.
if (isNew || loop)
addEffect("meshes\\" + castStatic->mModel, magicEffect->mIndex, loop, "");
*/
}
}
@ -956,67 +953,17 @@ void NpcAnimation::setAlpha(float alpha)
return;
mAlpha = alpha;
for (int i=0; i<ESM::PRT_Count; ++i)
{
if (mObjectParts[i].isNull())
continue;
for (unsigned int j=0; j<mObjectParts[i]->mEntities.size(); ++j)
{
Ogre::Entity* ent = mObjectParts[i]->mEntities[j];
if (ent != mObjectParts[i]->mSkelBase)
applyAlpha(alpha, ent, mObjectParts[i]);
}
}
// TODO
}
void NpcAnimation::enableHeadAnimation(bool enable)
{
mHeadAnimationTime->setEnabled(enable);
}
void NpcAnimation::preRender(Ogre::Camera *camera)
{
Animation::preRender(camera);
for (int i=0; i<ESM::PRT_Count; ++i)
{
if (mObjectParts[i].isNull())
continue;
mObjectParts[i]->rotateBillboardNodes(camera);
}
//mHeadAnimationTime->setEnabled(enable);
}
void NpcAnimation::applyAlpha(float alpha, Ogre::Entity *ent, NifOgre::ObjectScenePtr scene)
void NpcAnimation::setWeaponGroup(const std::string &group)
{
sh::Factory::getInstance()._ensureMaterial(ent->getSubEntity(0)->getMaterial()->getName(), "Default");
ent->getSubEntity(0)->setRenderQueueGroup(alpha != 1.f || ent->getSubEntity(0)->getMaterial()->isTransparent()
? RQG_Alpha : RQG_Main);
Ogre::MaterialPtr mat = scene->mMaterialControllerMgr.getWritableMaterial(ent);
if (mAlpha == 1.f)
{
// Don't bother remembering what the original values were. Just remove the techniques and let the factory restore them.
mat->removeAllTechniques();
sh::Factory::getInstance()._ensureMaterial(mat->getName(), "Default");
return;
}
Ogre::Material::TechniqueIterator techs = mat->getTechniqueIterator();
while(techs.hasMoreElements())
{
Ogre::Technique *tech = techs.getNext();
Ogre::Technique::PassIterator passes = tech->getPassIterator();
while(passes.hasMoreElements())
{
Ogre::Pass *pass = passes.getNext();
pass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
Ogre::ColourValue diffuse = pass->getDiffuse();
diffuse.a = alpha;
pass->setDiffuse(diffuse);
pass->setVertexColourTracking(pass->getVertexColourTracking() &~Ogre::TVC_DIFFUSE);
}
}
//mWeaponAnimationTime->
}
void NpcAnimation::equipmentChanged()

@ -15,6 +15,7 @@ namespace ESM
namespace MWRender
{
/*
class HeadAnimationTime : public Ogre::ControllerValue<Ogre::Real>
{
private:
@ -47,6 +48,27 @@ public:
virtual void setValue(Ogre::Real value)
{ }
};
*/
/// @brief Detaches the node from its parent when the object goes out of scope.
class PartHolder
{
public:
PartHolder(osg::ref_ptr<osg::Node> node)
: mNode(node)
{
}
~PartHolder()
{
if (mNode->getNumParents())
mNode->getParent(0)->removeChild(mNode);
}
private:
osg::ref_ptr<osg::Node> mNode;
};
typedef boost::shared_ptr<PartHolder> PartHolderPtr;
class NpcAnimation : public Animation, public WeaponAnimation, public MWWorld::InventoryStoreListener
{
@ -69,7 +91,7 @@ private:
bool mListenerDisabled;
// Bounded Parts
NifOgre::ObjectScenePtr mObjectParts[ESM::PRT_Count];
PartHolderPtr mObjectParts[ESM::PRT_Count];
std::string mSoundIds[ESM::PRT_Count];
const ESM::NPC *mNpc;
@ -94,8 +116,8 @@ private:
Ogre::Vector3 mFirstPersonOffset;
Ogre::SharedPtr<HeadAnimationTime> mHeadAnimationTime;
Ogre::SharedPtr<WeaponAnimationTime> mWeaponAnimationTime;
//Ogre::SharedPtr<HeadAnimationTime> mHeadAnimationTime;
//Ogre::SharedPtr<WeaponAnimationTime> mWeaponAnimationTime;
float mAlpha;
bool mSoundsDisabled;
@ -105,9 +127,8 @@ private:
void updateNpcBase();
NifOgre::ObjectScenePtr insertBoundedPart(const std::string &model, int group, const std::string &bonename,
const std::string &bonefilter,
bool enchantedGlow, Ogre::Vector3* glowColor=NULL);
PartHolderPtr insertBoundedPart(const std::string &model, int group, const std::string &bonename,
const std::string &bonefilter, bool enchantedGlow, Ogre::Vector3* glowColor=NULL);
void removeIndividualPart(ESM::PartReferenceType type);
void reserveIndividualPart(ESM::PartReferenceType type, int group, int priority);
@ -118,7 +139,7 @@ private:
void addPartGroup(int group, int priority, const std::vector<ESM::PartReference> &parts,
bool enchantedGlow=false, Ogre::Vector3* glowColor=NULL);
void applyAlpha(float alpha, Ogre::Entity* ent, NifOgre::ObjectScenePtr scene);
//void applyAlpha(float alpha, Ogre::Entity* ent, NifOgre::ObjectScenePtr scene);
public:
/**
@ -132,15 +153,16 @@ public:
* @param disableSounds Same as \a disableListener but for playing items sounds
* @param viewMode
*/
NpcAnimation(const MWWorld::Ptr& ptr, Ogre::SceneNode* node, int visibilityFlags, bool disableListener = false,
NpcAnimation(const MWWorld::Ptr& ptr, osg::ref_ptr<osg::Group> parentNode, Resource::ResourceSystem* resourceSystem,
int visibilityFlags, bool disableListener = false,
bool disableSounds = false, ViewMode viewMode=VM_Normal);
virtual ~NpcAnimation();
virtual void enableHeadAnimation(bool enable);
virtual void setWeaponGroup(const std::string& group) { mWeaponAnimationTime->setGroup(group); }
virtual void setWeaponGroup(const std::string& group);
virtual Ogre::Vector3 runAnimation(float timepassed);
//virtual Ogre::Vector3 runAnimation(float timepassed);
/// A relative factor (0-1) that decides if and how much the skeleton should be pitched
/// to indicate the facing orientation of the character.
@ -158,9 +180,9 @@ public:
virtual void releaseArrow();
// WeaponAnimation
virtual NifOgre::ObjectScenePtr getWeapon() { return mObjectParts[ESM::PRT_Weapon]; }
//virtual NifOgre::ObjectScenePtr getWeapon() { return mObjectParts[ESM::PRT_Weapon]; }
virtual void showWeapon(bool show) { showWeapons(show); }
virtual void configureAddedObject(NifOgre::ObjectScenePtr object, MWWorld::Ptr ptr, int slot);
//virtual void configureAddedObject(NifOgre::ObjectScenePtr object, MWWorld::Ptr ptr, int slot);
void setViewMode(ViewMode viewMode);
@ -178,9 +200,6 @@ public:
virtual void setAlpha(float alpha);
virtual void setVampire(bool vampire);
/// Prepare this animation for being rendered with \a camera (rotates billboard nodes)
virtual void preRender (Ogre::Camera* camera);
};
}

@ -25,6 +25,7 @@
#include "renderconst.hpp"
#include "animation.hpp"
#include "npcanimation.hpp"
namespace
{
@ -199,7 +200,10 @@ void Objects::insertCreature(const MWWorld::Ptr &ptr, const std::string &mesh, b
void Objects::insertNPC(const MWWorld::Ptr &ptr)
{
insertBegin(ptr);
std::auto_ptr<NpcAnimation> anim (new NpcAnimation(ptr, osg::ref_ptr<osg::Group>(ptr.getRefData().getBaseNode()), mResourceSystem, 0));
mObjects.insert(std::make_pair(ptr, anim.release()));
}
bool Objects::deleteObject (const MWWorld::Ptr& ptr)

@ -1,10 +1,6 @@
#ifndef OPENMW_MWRENDER_WEAPONANIMATION_H
#define OPENMW_MWRENDER_WEAPONANIMATION_H
#include <OgreController.h>
#include <components/nifogre/ogrenifloader.hpp>
#include "../mwworld/ptr.hpp"
namespace MWRender
@ -12,6 +8,7 @@ namespace MWRender
class Animation;
/*
class WeaponAnimationTime : public Ogre::ControllerValue<Ogre::Real>
{
private:
@ -27,6 +24,7 @@ namespace MWRender
virtual void setValue(Ogre::Real value)
{ }
};
*/
/// Handles attach & release of projectiles for ranged weapons
class WeaponAnimation
@ -36,23 +34,23 @@ namespace MWRender
virtual ~WeaponAnimation() {}
/// @note If no weapon (or an invalid weapon) is equipped, this function is a no-op.
void attachArrow(MWWorld::Ptr actor);
void attachArrow(MWWorld::Ptr actor) {}
/// @note If no weapon (or an invalid weapon) is equipped, this function is a no-op.
void releaseArrow(MWWorld::Ptr actor);
void releaseArrow(MWWorld::Ptr actor) {}
protected:
NifOgre::ObjectScenePtr mAmmunition;
//NifOgre::ObjectScenePtr mAmmunition;
virtual NifOgre::ObjectScenePtr getWeapon() = 0;
//virtual NifOgre::ObjectScenePtr getWeapon() = 0;
virtual void showWeapon(bool show) = 0;
virtual void configureAddedObject(NifOgre::ObjectScenePtr object, MWWorld::Ptr ptr, int slot) = 0;
//virtual void configureAddedObject(NifOgre::ObjectScenePtr object, MWWorld::Ptr ptr, int slot) = 0;
/// A relative factor (0-1) that decides if and how much the skeleton should be pitched
/// to indicate the facing orientation of the character, for ranged weapon aiming.
float mPitchFactor;
void pitchSkeleton(float xrot, Ogre::SkeletonInstance* skel);
//void pitchSkeleton(float xrot, Ogre::SkeletonInstance* skel);
};
}

Loading…
Cancel
Save