2011-12-12 03:40:00 +00:00
|
|
|
#include "creatureanimation.hpp"
|
2012-07-03 13:32:38 +00:00
|
|
|
|
2017-02-03 22:15:37 +00:00
|
|
|
#include <osg/MatrixTransform>
|
|
|
|
|
2014-02-23 19:11:05 +00:00
|
|
|
#include <components/esm/loadcrea.hpp>
|
2018-08-14 19:05:43 +00:00
|
|
|
#include <components/debug/debuglog.hpp>
|
2015-04-19 01:05:47 +00:00
|
|
|
#include <components/resource/resourcesystem.hpp>
|
|
|
|
#include <components/resource/scenemanager.hpp>
|
|
|
|
#include <components/sceneutil/attach.hpp>
|
2015-05-30 23:07:43 +00:00
|
|
|
#include <components/sceneutil/visitor.hpp>
|
2015-11-20 20:57:04 +00:00
|
|
|
#include <components/sceneutil/positionattitudetransform.hpp>
|
2016-07-02 18:19:55 +00:00
|
|
|
#include <components/sceneutil/skeleton.hpp>
|
2015-04-19 01:05:47 +00:00
|
|
|
|
2017-02-03 22:15:37 +00:00
|
|
|
#include <components/misc/stringops.hpp>
|
|
|
|
|
2012-07-03 10:30:50 +00:00
|
|
|
#include "../mwbase/world.hpp"
|
2011-12-12 03:40:00 +00:00
|
|
|
|
2014-01-19 12:05:26 +00:00
|
|
|
#include "../mwworld/class.hpp"
|
|
|
|
|
2013-01-19 00:21:29 +00:00
|
|
|
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)
|
2016-10-08 01:49:50 +00:00
|
|
|
: ActorAnimation(ptr, osg::ref_ptr<osg::Group>(ptr.getRefData().getBaseNode()), resourceSystem)
|
2012-07-13 03:12:18 +00:00
|
|
|
{
|
2015-04-23 18:41:31 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::Creature> *ref = mPtr.get<ESM::Creature>();
|
2011-12-12 03:40:00 +00:00
|
|
|
|
2014-01-19 12:05:26 +00:00
|
|
|
if(!model.empty())
|
2012-07-13 03:12:18 +00:00
|
|
|
{
|
2015-08-15 17:01:21 +00:00
|
|
|
setObjectRoot(model, false, false, true);
|
2014-01-19 12:05:26 +00:00
|
|
|
|
2015-04-23 18:41:31 +00:00
|
|
|
if((ref->mBase->mFlags&ESM::Creature::Bipedal))
|
2017-11-10 21:02:43 +00:00
|
|
|
addAnimSource("meshes\\xbase_anim.nif", model);
|
|
|
|
addAnimSource(model, model);
|
2014-01-19 12:05:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-13 03:12:18 +00:00
|
|
|
|
2015-04-19 01:05:47 +00:00
|
|
|
CreatureWeaponAnimation::CreatureWeaponAnimation(const MWWorld::Ptr &ptr, const std::string& model, Resource::ResourceSystem* resourceSystem)
|
2016-10-08 01:49:50 +00:00
|
|
|
: ActorAnimation(ptr, osg::ref_ptr<osg::Group>(ptr.getRefData().getBaseNode()), resourceSystem)
|
2014-01-19 12:31:17 +00:00
|
|
|
, mShowWeapons(false)
|
|
|
|
, mShowCarriedLeft(false)
|
2014-01-19 12:05:26 +00:00
|
|
|
{
|
2015-04-23 18:41:31 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::Creature> *ref = mPtr.get<ESM::Creature>();
|
2014-01-19 12:05:26 +00:00
|
|
|
|
|
|
|
if(!model.empty())
|
|
|
|
{
|
2015-08-15 17:01:21 +00:00
|
|
|
setObjectRoot(model, true, false, true);
|
2013-05-07 23:59:32 +00:00
|
|
|
|
2015-04-23 18:41:31 +00:00
|
|
|
if((ref->mBase->mFlags&ESM::Creature::Bipedal))
|
2017-11-10 21:02:43 +00:00
|
|
|
addAnimSource("meshes\\xbase_anim.nif", model);
|
|
|
|
addAnimSource(model, model);
|
2014-01-19 12:05:26 +00:00
|
|
|
|
2016-10-08 01:49:50 +00:00
|
|
|
mPtr.getClass().getInventoryStore(mPtr).setInvListener(this, mPtr);
|
2014-01-19 12:05:26 +00:00
|
|
|
|
|
|
|
updateParts();
|
|
|
|
}
|
2014-03-12 10:30:44 +00:00
|
|
|
|
2017-05-05 17:26:09 +00:00
|
|
|
mWeaponAnimationTime = std::shared_ptr<WeaponAnimationTime>(new WeaponAnimationTime(this));
|
2014-01-19 12:05:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2016-06-07 00:42:57 +00:00
|
|
|
mAmmunition.reset();
|
2015-04-19 01:05:47 +00:00
|
|
|
mWeapon.reset();
|
|
|
|
mShield.reset();
|
2014-01-19 12:05:26 +00:00
|
|
|
|
|
|
|
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)
|
2014-01-19 12:05:26 +00:00
|
|
|
{
|
2015-04-19 01:05:47 +00:00
|
|
|
if (!mObjectRoot)
|
2015-03-02 14:19:57 +00:00
|
|
|
return;
|
|
|
|
|
2017-02-28 14:31:51 +00:00
|
|
|
const MWWorld::InventoryStore& inv = mPtr.getClass().getInventoryStore(mPtr);
|
|
|
|
MWWorld::ConstContainerStoreIterator it = inv.getSlot(slot);
|
2014-01-19 12:05:26 +00:00
|
|
|
|
|
|
|
if (it == inv.end())
|
|
|
|
{
|
2015-04-19 01:05:47 +00:00
|
|
|
scene.reset();
|
2014-01-19 12:05:26 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-02-28 14:31:51 +00:00
|
|
|
MWWorld::ConstPtr item = *it;
|
2014-01-19 12:05:26 +00:00
|
|
|
|
|
|
|
std::string bonename;
|
|
|
|
if (slot == MWWorld::InventoryStore::Slot_CarriedRight)
|
|
|
|
bonename = "Weapon Bone";
|
|
|
|
else
|
|
|
|
bonename = "Shield Bone";
|
|
|
|
|
2017-02-03 22:15:37 +00:00
|
|
|
try
|
2014-03-12 10:30:44 +00:00
|
|
|
{
|
2017-02-03 22:15:37 +00:00
|
|
|
osg::ref_ptr<osg::Node> node = mResourceSystem->getSceneManager()->getInstance(item.getClass().getModel(item));
|
|
|
|
|
|
|
|
const NodeMap& nodeMap = getNodeMap();
|
2017-09-09 20:22:16 +00:00
|
|
|
NodeMap::const_iterator found = nodeMap.find(Misc::StringUtils::lowerCase(bonename));
|
2017-02-03 22:15:37 +00:00
|
|
|
if (found == nodeMap.end())
|
|
|
|
throw std::runtime_error("Can't find attachment node " + bonename);
|
|
|
|
osg::ref_ptr<osg::Node> attached = SceneUtil::attach(node, mObjectRoot, bonename, found->second.get());
|
|
|
|
|
|
|
|
scene.reset(new PartHolder(attached));
|
|
|
|
|
|
|
|
if (!item.getClass().getEnchantment(item).empty())
|
|
|
|
addGlow(attached, getEnchantmentColor(item));
|
|
|
|
|
|
|
|
// Crossbows start out with a bolt attached
|
|
|
|
// FIXME: code duplicated from NpcAnimation
|
|
|
|
if (slot == MWWorld::InventoryStore::Slot_CarriedRight &&
|
|
|
|
item.getTypeName() == typeid(ESM::Weapon).name() &&
|
|
|
|
item.get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::MarksmanCrossbow)
|
|
|
|
{
|
2017-02-28 14:31:51 +00:00
|
|
|
MWWorld::ConstContainerStoreIterator ammo = inv.getSlot(MWWorld::InventoryStore::Slot_Ammunition);
|
2017-02-03 22:15:37 +00:00
|
|
|
if (ammo != inv.end() && ammo->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::Bolt)
|
|
|
|
attachArrow();
|
|
|
|
else
|
|
|
|
mAmmunition.reset();
|
|
|
|
}
|
2015-05-30 23:07:43 +00:00
|
|
|
else
|
|
|
|
mAmmunition.reset();
|
2014-03-12 10:30:44 +00:00
|
|
|
|
2017-05-05 17:26:09 +00:00
|
|
|
std::shared_ptr<SceneUtil::ControllerSource> source;
|
2015-05-30 23:07:43 +00:00
|
|
|
|
2017-02-03 22:15:37 +00:00
|
|
|
if (slot == MWWorld::InventoryStore::Slot_CarriedRight)
|
|
|
|
source = mWeaponAnimationTime;
|
|
|
|
else
|
|
|
|
source.reset(new NullAnimationTime);
|
2015-05-30 23:07:43 +00:00
|
|
|
|
2017-02-03 22:15:37 +00:00
|
|
|
SceneUtil::AssignControllerSourcesVisitor assignVisitor(source);
|
|
|
|
attached->accept(assignVisitor);
|
|
|
|
}
|
|
|
|
catch (std::exception& e)
|
|
|
|
{
|
2018-08-14 19:05:43 +00:00
|
|
|
Log(Debug::Error) << "Can not add creature part: " << e.what();
|
2017-02-03 22:15:37 +00:00
|
|
|
}
|
2011-12-12 03:40:00 +00:00
|
|
|
}
|
2011-12-26 03:37:26 +00:00
|
|
|
|
2014-03-12 10:30:44 +00:00
|
|
|
void CreatureWeaponAnimation::attachArrow()
|
|
|
|
{
|
2015-05-30 23:07:43 +00:00
|
|
|
WeaponAnimation::attachArrow(mPtr);
|
2014-03-12 10:30:44 +00:00
|
|
|
}
|
|
|
|
|
2015-06-26 03:15:07 +00:00
|
|
|
void CreatureWeaponAnimation::releaseArrow(float attackStrength)
|
2014-03-12 10:30:44 +00:00
|
|
|
{
|
2015-06-26 03:15:07 +00:00
|
|
|
WeaponAnimation::releaseArrow(mPtr, attackStrength);
|
2015-05-30 23:07:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
osg::Group *CreatureWeaponAnimation::getArrowBone()
|
|
|
|
{
|
|
|
|
if (!mWeapon)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
SceneUtil::FindByNameVisitor findVisitor ("ArrowBone");
|
|
|
|
mWeapon->getNode()->accept(findVisitor);
|
|
|
|
|
|
|
|
return findVisitor.mFoundNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
osg::Node *CreatureWeaponAnimation::getWeaponNode()
|
|
|
|
{
|
|
|
|
return mWeapon ? mWeapon->getNode().get() : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Resource::ResourceSystem *CreatureWeaponAnimation::getResourceSystem()
|
|
|
|
{
|
|
|
|
return mResourceSystem;
|
2014-03-12 10:30:44 +00:00
|
|
|
}
|
|
|
|
|
2015-05-31 16:53:16 +00:00
|
|
|
void CreatureWeaponAnimation::addControllers()
|
|
|
|
{
|
2015-06-22 19:06:27 +00:00
|
|
|
Animation::addControllers();
|
2015-05-31 16:53:16 +00:00
|
|
|
WeaponAnimation::addControllers(mNodeMap, mActiveControllers, mObjectRoot.get());
|
|
|
|
}
|
|
|
|
|
2015-04-19 01:05:47 +00:00
|
|
|
osg::Vec3f CreatureWeaponAnimation::runAnimation(float duration)
|
2014-03-12 10:30:44 +00:00
|
|
|
{
|
2015-05-21 23:54:06 +00:00
|
|
|
osg::Vec3f ret = Animation::runAnimation(duration);
|
2015-03-02 14:19:57 +00:00
|
|
|
|
2015-05-31 16:53:16 +00:00
|
|
|
WeaponAnimation::configureControllers(mPtr.getRefData().getPosition().rot[0]);
|
2014-06-27 01:11:37 +00:00
|
|
|
|
2015-05-21 23:54:06 +00:00
|
|
|
return ret;
|
2014-03-12 10:30:44 +00:00
|
|
|
}
|
|
|
|
|
2012-01-17 14:10:53 +00:00
|
|
|
}
|