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

184 lines
5.2 KiB
C++
Raw Normal View History

#include "creatureanimation.hpp"
2014-02-23 19:11:05 +00:00
#include <components/esm/loadcrea.hpp>
2015-04-19 01:05:47 +00:00
#include <osg/PositionAttitudeTransform>
#include <components/resource/resourcesystem.hpp>
#include <components/resource/scenemanager.hpp>
#include <components/sceneutil/attach.hpp>
#include "../mwbase/world.hpp"
#include "../mwworld/class.hpp"
2014-02-23 19:11:05 +00:00
#include "renderconst.hpp"
namespace MWRender
{
2011-12-12 04:42:39 +00:00
2015-04-19 01:05:47 +00:00
CreatureAnimation::CreatureAnimation(const MWWorld::Ptr &ptr,
const std::string& model, Resource::ResourceSystem* resourceSystem)
: Animation(ptr, osg::ref_ptr<osg::Group>(ptr.getRefData().getBaseNode()), resourceSystem)
{
2015-04-19 01:05:47 +00:00
//MWWorld::LiveCellRef<ESM::Creature> *ref = mPtr.get<ESM::Creature>();
if(!model.empty())
{
2015-04-19 01:05:47 +00:00
setObjectRoot(model /* , baseonly = false */);
//setRenderProperties(mObjectRoot, RV_Actors, RQG_Main, RQG_Alpha);
2015-04-19 01:05:47 +00:00
//if((ref->mBase->mFlags&ESM::Creature::Bipedal))
// addAnimSource("meshes\\xbase_anim.nif");
//addAnimSource(model);
}
}
2015-04-19 01:05:47 +00:00
CreatureWeaponAnimation::CreatureWeaponAnimation(const MWWorld::Ptr &ptr, const std::string& model, Resource::ResourceSystem* resourceSystem)
: Animation(ptr, osg::ref_ptr<osg::Group>(ptr.getRefData().getBaseNode()), resourceSystem)
, mShowWeapons(false)
, mShowCarriedLeft(false)
{
2015-04-19 01:05:47 +00:00
//MWWorld::LiveCellRef<ESM::Creature> *ref = mPtr.get<ESM::Creature>();
if(!model.empty())
{
2015-04-19 01:05:47 +00:00
setObjectRoot(model /* , baseonly = false*/);
//setRenderProperties(mObjectRoot, RV_Actors, RQG_Main, RQG_Alpha);
2015-04-19 01:05:47 +00:00
//if((ref->mBase->mFlags&ESM::Creature::Bipedal))
// addAnimSource("meshes\\xbase_anim.nif");
//addAnimSource(model);
mPtr.getClass().getInventoryStore(mPtr).setListener(this, mPtr);
updateParts();
}
2014-03-12 10:30:44 +00:00
2015-04-19 01:05:47 +00:00
//mWeaponAnimationTime = Ogre::SharedPtr<WeaponAnimationTime>(new WeaponAnimationTime(this));
}
void CreatureWeaponAnimation::showWeapons(bool showWeapon)
{
if (showWeapon != mShowWeapons)
{
mShowWeapons = showWeapon;
updateParts();
}
}
void CreatureWeaponAnimation::showCarriedLeft(bool show)
{
if (show != mShowCarriedLeft)
{
mShowCarriedLeft = show;
updateParts();
}
}
void CreatureWeaponAnimation::updateParts()
{
2015-04-19 01:05:47 +00:00
mWeapon.reset();
mShield.reset();
if (mShowWeapons)
updatePart(mWeapon, MWWorld::InventoryStore::Slot_CarriedRight);
if (mShowCarriedLeft)
updatePart(mShield, MWWorld::InventoryStore::Slot_CarriedLeft);
}
2015-04-19 01:05:47 +00:00
void CreatureWeaponAnimation::updatePart(PartHolderPtr& scene, int slot)
{
2015-04-19 01:05:47 +00:00
if (!mObjectRoot)
return;
MWWorld::InventoryStore& inv = mPtr.getClass().getInventoryStore(mPtr);
MWWorld::ContainerStoreIterator it = inv.getSlot(slot);
if (it == inv.end())
{
2015-04-19 01:05:47 +00:00
scene.reset();
return;
}
MWWorld::Ptr item = *it;
std::string bonename;
if (slot == MWWorld::InventoryStore::Slot_CarriedRight)
bonename = "Weapon Bone";
else
bonename = "Shield Bone";
2015-04-19 01:05:47 +00:00
osg::ref_ptr<osg::Node> node = mResourceSystem->getSceneManager()->createInstance(item.getClass().getModel(item));
SceneUtil::attach(node, mObjectRoot, bonename, bonename);
2015-04-19 01:05:47 +00:00
scene.reset(new PartHolder(node));
if (!item.getClass().getEnchantment(item).empty())
addGlow(node, getEnchantmentColor(item));
2014-03-12 10:30:44 +00:00
// Crossbows start out with a bolt attached
2015-04-19 01:05:47 +00:00
// FIXME: code duplicated from NpcAnimation
2014-03-12 10:30:44 +00:00
if (slot == MWWorld::InventoryStore::Slot_CarriedRight &&
item.getTypeName() == typeid(ESM::Weapon).name() &&
item.get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::MarksmanCrossbow)
{
MWWorld::ContainerStoreIterator ammo = inv.getSlot(MWWorld::InventoryStore::Slot_Ammunition);
if (ammo != inv.end() && ammo->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::Bolt)
attachArrow();
2015-04-19 01:05:47 +00:00
//else
// mAmmunition.setNull();
2014-03-12 10:30:44 +00:00
}
2015-04-19 01:05:47 +00:00
//else
//mAmmunition.setNull();
2014-03-12 10:30:44 +00:00
2015-04-19 01:05:47 +00:00
/*
std::vector<Ogre::Controller<Ogre::Real> >::iterator ctrl(scene->mControllers.begin());
2014-09-26 15:12:48 +00:00
for(;ctrl != scene->mControllers.end();++ctrl)
{
if(ctrl->getSource().isNull())
2014-03-12 10:30:44 +00:00
{
if (slot == MWWorld::InventoryStore::Slot_CarriedRight)
ctrl->setSource(mWeaponAnimationTime);
else
ctrl->setSource(Ogre::SharedPtr<NullAnimationTime>(new NullAnimationTime()));
}
}
2015-04-19 01:05:47 +00:00
*/
}
2015-04-19 01:05:47 +00:00
/*
2014-03-12 10:30:44 +00:00
void CreatureWeaponAnimation::configureAddedObject(NifOgre::ObjectScenePtr object, MWWorld::Ptr ptr, int slot)
{
2015-04-19 01:05:47 +00:00
//Ogre::Vector3 glowColor = getEnchantmentColor(ptr);
2014-03-12 10:30:44 +00:00
2015-04-19 01:05:47 +00:00
//setRenderProperties(object, RV_Actors, RQG_Main, RQG_Alpha, 0,
// !ptr.getClass().getEnchantment(ptr).empty(), &glowColor);
2014-03-12 10:30:44 +00:00
}
2015-04-19 01:05:47 +00:00
*/
2014-03-12 10:30:44 +00:00
void CreatureWeaponAnimation::attachArrow()
{
2015-04-19 01:05:47 +00:00
//WeaponAnimation::attachArrow(mPtr);
2014-03-12 10:30:44 +00:00
}
void CreatureWeaponAnimation::releaseArrow()
{
2015-04-19 01:05:47 +00:00
//WeaponAnimation::releaseArrow(mPtr);
2014-03-12 10:30:44 +00:00
}
2015-04-19 01:05:47 +00:00
osg::Vec3f CreatureWeaponAnimation::runAnimation(float duration)
2014-03-12 10:30:44 +00:00
{
2015-04-19 01:05:47 +00:00
/*
2014-03-12 10:30:44 +00:00
Ogre::Vector3 ret = Animation::runAnimation(duration);
if (mSkelBase)
pitchSkeleton(mPtr.getRefData().getPosition().rot[0], mSkelBase->getSkeleton());
2015-04-19 01:05:47 +00:00
*/
2015-04-19 01:05:47 +00:00
return osg::Vec3f();
2014-03-12 10:30:44 +00:00
}
2012-01-17 14:10:53 +00:00
}