CreatureAnimation compiles

c++11
scrawl 10 years ago
parent 27cfe8fb58
commit 9c4b2ea61a

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

@ -497,6 +497,7 @@ void OMW::Engine::go()
{
double dt = frameTimer.time_s();
frameTimer.setStartTick();
//dt = std::min(dt, 0.2f);
// frameRenderingQueued(dt);
MWBase::Environment::get().getWorld()->update(dt, false);
@ -507,18 +508,6 @@ void OMW::Engine::go()
mViewer.frame(/*simulationTime*/);
}
/*
Ogre::Timer timer;
while (!MWBase::Environment::get().getStateManager()->hasQuitRequest())
{
float dt = timer.getMilliseconds()/1000.f;
dt = std::min(dt, 0.2f);
timer.reset();
Ogre::Root::getSingleton().renderOneFrame(dt);
}
*/
// Save user settings
settings.saveUser(settingspath);

@ -1,11 +1,13 @@
#include "creatureanimation.hpp"
#include <OgreEntity.h>
#include <OgreSkeletonInstance.h>
#include <OgreBone.h>
#include <components/esm/loadcrea.hpp>
#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"
@ -16,45 +18,46 @@ namespace MWRender
{
CreatureAnimation::CreatureAnimation(const MWWorld::Ptr &ptr, const std::string& model)
: Animation(ptr, ptr.getRefData().getBaseNode())
CreatureAnimation::CreatureAnimation(const MWWorld::Ptr &ptr,
const std::string& model, Resource::ResourceSystem* resourceSystem)
: Animation(ptr, osg::ref_ptr<osg::Group>(ptr.getRefData().getBaseNode()), resourceSystem)
{
MWWorld::LiveCellRef<ESM::Creature> *ref = mPtr.get<ESM::Creature>();
//MWWorld::LiveCellRef<ESM::Creature> *ref = mPtr.get<ESM::Creature>();
if(!model.empty())
{
setObjectRoot(model, false);
setRenderProperties(mObjectRoot, RV_Actors, RQG_Main, RQG_Alpha);
setObjectRoot(model /* , baseonly = false */);
//setRenderProperties(mObjectRoot, RV_Actors, RQG_Main, RQG_Alpha);
if((ref->mBase->mFlags&ESM::Creature::Bipedal))
addAnimSource("meshes\\xbase_anim.nif");
addAnimSource(model);
//if((ref->mBase->mFlags&ESM::Creature::Bipedal))
// addAnimSource("meshes\\xbase_anim.nif");
//addAnimSource(model);
}
}
CreatureWeaponAnimation::CreatureWeaponAnimation(const MWWorld::Ptr &ptr, const std::string& model)
: Animation(ptr, ptr.getRefData().getBaseNode())
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)
{
MWWorld::LiveCellRef<ESM::Creature> *ref = mPtr.get<ESM::Creature>();
//MWWorld::LiveCellRef<ESM::Creature> *ref = mPtr.get<ESM::Creature>();
if(!model.empty())
{
setObjectRoot(model, false);
setRenderProperties(mObjectRoot, RV_Actors, RQG_Main, RQG_Alpha);
setObjectRoot(model /* , baseonly = false*/);
//setRenderProperties(mObjectRoot, RV_Actors, RQG_Main, RQG_Alpha);
if((ref->mBase->mFlags&ESM::Creature::Bipedal))
addAnimSource("meshes\\xbase_anim.nif");
addAnimSource(model);
//if((ref->mBase->mFlags&ESM::Creature::Bipedal))
// addAnimSource("meshes\\xbase_anim.nif");
//addAnimSource(model);
mPtr.getClass().getInventoryStore(mPtr).setListener(this, mPtr);
updateParts();
}
mWeaponAnimationTime = Ogre::SharedPtr<WeaponAnimationTime>(new WeaponAnimationTime(this));
//mWeaponAnimationTime = Ogre::SharedPtr<WeaponAnimationTime>(new WeaponAnimationTime(this));
}
void CreatureWeaponAnimation::showWeapons(bool showWeapon)
@ -77,8 +80,8 @@ void CreatureWeaponAnimation::showCarriedLeft(bool show)
void CreatureWeaponAnimation::updateParts()
{
mWeapon.setNull();
mShield.setNull();
mWeapon.reset();
mShield.reset();
if (mShowWeapons)
updatePart(mWeapon, MWWorld::InventoryStore::Slot_CarriedRight);
@ -86,9 +89,9 @@ void CreatureWeaponAnimation::updateParts()
updatePart(mShield, MWWorld::InventoryStore::Slot_CarriedLeft);
}
void CreatureWeaponAnimation::updatePart(NifOgre::ObjectScenePtr& scene, int slot)
void CreatureWeaponAnimation::updatePart(PartHolderPtr& scene, int slot)
{
if (!mSkelBase)
if (!mObjectRoot)
return;
MWWorld::InventoryStore& inv = mPtr.getClass().getInventoryStore(mPtr);
@ -96,7 +99,7 @@ void CreatureWeaponAnimation::updatePart(NifOgre::ObjectScenePtr& scene, int slo
if (it == inv.end())
{
scene.setNull();
scene.reset();
return;
}
MWWorld::Ptr item = *it;
@ -107,13 +110,16 @@ void CreatureWeaponAnimation::updatePart(NifOgre::ObjectScenePtr& scene, int slo
else
bonename = "Shield Bone";
scene = NifOgre::Loader::createObjects(mSkelBase, bonename, bonename, mInsert, item.getClass().getModel(item));
Ogre::Vector3 glowColor = getEnchantmentColor(item);
osg::ref_ptr<osg::Node> node = mResourceSystem->getSceneManager()->createInstance(item.getClass().getModel(item));
SceneUtil::attach(node, mObjectRoot, bonename, bonename);
setRenderProperties(scene, RV_Actors, RQG_Main, RQG_Alpha, 0,
!item.getClass().getEnchantment(item).empty(), &glowColor);
scene.reset(new PartHolder(node));
if (!item.getClass().getEnchantment(item).empty())
addGlow(node, 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)
@ -121,12 +127,14 @@ void CreatureWeaponAnimation::updatePart(NifOgre::ObjectScenePtr& scene, int slo
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();
// FIXME: code duplicated from NpcAnimation
/*
if(scene->mSkelBase)
{
Ogre::SkeletonInstance *skel = scene->mSkelBase->getSkeleton();
@ -149,7 +157,9 @@ void CreatureWeaponAnimation::updatePart(NifOgre::ObjectScenePtr& scene, int slo
}
updateSkeletonInstance(mSkelBase->getSkeleton(), skel);
}
*/
/*
std::vector<Ogre::Controller<Ogre::Real> >::iterator ctrl(scene->mControllers.begin());
for(;ctrl != scene->mControllers.end();++ctrl)
{
@ -161,45 +171,39 @@ void CreatureWeaponAnimation::updatePart(NifOgre::ObjectScenePtr& scene, int slo
ctrl->setSource(Ogre::SharedPtr<NullAnimationTime>(new NullAnimationTime()));
}
}
*/
}
/*
void CreatureWeaponAnimation::configureAddedObject(NifOgre::ObjectScenePtr object, MWWorld::Ptr ptr, int slot)
{
Ogre::Vector3 glowColor = getEnchantmentColor(ptr);
//Ogre::Vector3 glowColor = getEnchantmentColor(ptr);
setRenderProperties(object, RV_Actors, RQG_Main, RQG_Alpha, 0,
!ptr.getClass().getEnchantment(ptr).empty(), &glowColor);
//setRenderProperties(object, RV_Actors, RQG_Main, RQG_Alpha, 0,
// !ptr.getClass().getEnchantment(ptr).empty(), &glowColor);
}
*/
void CreatureWeaponAnimation::attachArrow()
{
WeaponAnimation::attachArrow(mPtr);
//WeaponAnimation::attachArrow(mPtr);
}
void CreatureWeaponAnimation::releaseArrow()
{
WeaponAnimation::releaseArrow(mPtr);
//WeaponAnimation::releaseArrow(mPtr);
}
Ogre::Vector3 CreatureWeaponAnimation::runAnimation(float duration)
osg::Vec3f CreatureWeaponAnimation::runAnimation(float duration)
{
/*
Ogre::Vector3 ret = Animation::runAnimation(duration);
if (mSkelBase)
pitchSkeleton(mPtr.getRefData().getPosition().rot[0], mSkelBase->getSkeleton());
*/
if (!mWeapon.isNull())
{
for (unsigned int i=0; i<mWeapon->mControllers.size(); ++i)
mWeapon->mControllers[i].update();
}
if (!mShield.isNull())
{
for (unsigned int i=0; i<mShield->mControllers.size(); ++i)
mShield->mControllers[i].update();
}
return ret;
return osg::Vec3f();
}
}

@ -15,17 +15,17 @@ namespace MWRender
class CreatureAnimation : public Animation
{
public:
CreatureAnimation(const MWWorld::Ptr& ptr, const std::string &model);
CreatureAnimation(const MWWorld::Ptr &ptr, const std::string& model, Resource::ResourceSystem* resourceSystem);
virtual ~CreatureAnimation() {}
};
// For creatures with weapons and shields
// Animation is already virtual anyway, so might as well make a separate class.
// Most creatures don't need weapons/shields, so this will save some memory.
class CreatureWeaponAnimation : public Animation, public WeaponAnimation, public MWWorld::InventoryStoreListener
class CreatureWeaponAnimation : public Animation/*, public WeaponAnimation*/, public MWWorld::InventoryStoreListener
{
public:
CreatureWeaponAnimation(const MWWorld::Ptr& ptr, const std::string &model);
CreatureWeaponAnimation(const MWWorld::Ptr &ptr, const std::string& model, Resource::ResourceSystem* resourceSystem);
virtual ~CreatureWeaponAnimation() {}
virtual void equipmentChanged() { updateParts(); }
@ -35,31 +35,31 @@ namespace MWRender
void updateParts();
void updatePart(NifOgre::ObjectScenePtr& scene, int slot);
void updatePart(PartHolderPtr& scene, int slot);
virtual void attachArrow();
virtual void releaseArrow();
virtual Ogre::Vector3 runAnimation(float duration);
virtual osg::Vec3f runAnimation(float duration);
/// A relative factor (0-1) that decides if and how much the skeleton should be pitched
/// to indicate the facing orientation of the character.
virtual void setPitchFactor(float factor) { mPitchFactor = factor; }
//virtual void setPitchFactor(float factor) { mPitchFactor = factor; }
virtual void setWeaponGroup(const std::string& group) { mWeaponAnimationTime->setGroup(group); }
//virtual void setWeaponGroup(const std::string& group) { mWeaponAnimationTime->setGroup(group); }
// WeaponAnimation
virtual NifOgre::ObjectScenePtr getWeapon() { return mWeapon; }
virtual void showWeapon(bool show) { showWeapons(show); }
virtual void configureAddedObject(NifOgre::ObjectScenePtr object, MWWorld::Ptr ptr, int slot);
//virtual NifOgre::ObjectScenePtr getWeapon() { return mWeapon; }
//virtual void showWeapon(bool show) { showWeapons(show); }
//virtual void configureAddedObject(NifOgre::ObjectScenePtr object, MWWorld::Ptr ptr, int slot);
private:
NifOgre::ObjectScenePtr mWeapon;
NifOgre::ObjectScenePtr mShield;
PartHolderPtr mWeapon;
PartHolderPtr mShield;
bool mShowWeapons;
bool mShowCarriedLeft;
Ogre::SharedPtr<WeaponAnimationTime> mWeaponAnimationTime;
//Ogre::SharedPtr<WeaponAnimationTime> mWeaponAnimationTime;
};
}

@ -1,15 +1,5 @@
#include "npcanimation.hpp"
#include <OgreSceneManager.h>
#include <OgreEntity.h>
#include <OgreParticleSystem.h>
#include <OgreSubEntity.h>
#include <OgreSkeleton.h>
#include <OgreSkeletonInstance.h>
#include <OgreSceneNode.h>
#include <OgreBone.h>
#include <OgreTechnique.h>
#include <openengine/misc/rng.hpp>
#include <components/misc/resourcehelpers.hpp>
@ -575,18 +565,6 @@ void NpcAnimation::addFirstPersonOffset(const Ogre::Vector3 &offset)
mFirstPersonOffset += offset;
}
class SetObjectGroup {
int mGroup;
public:
SetObjectGroup(int group) : mGroup(group) { }
void operator()(Ogre::MovableObject *obj) const
{
obj->getUserObjectBindings().setUserAny(Ogre::Any(mGroup));
}
};
Animation::PartHolderPtr NpcAnimation::insertBoundedPart(const std::string& model, int group, const std::string& bonename, const std::string& bonefilter, bool enchantedGlow, osg::Vec4f* glowColor)
{
osg::ref_ptr<osg::Node> instance = mResourceSystem->getSceneManager()->createInstance(model);

@ -26,6 +26,7 @@
#include "renderconst.hpp"
#include "animation.hpp"
#include "npcanimation.hpp"
#include "creatureanimation.hpp"
namespace
{
@ -194,7 +195,13 @@ void Objects::insertCreature(const MWWorld::Ptr &ptr, const std::string &mesh, b
insertBegin(ptr);
// CreatureAnimation
std::auto_ptr<ObjectAnimation> anim (new ObjectAnimation(ptr, mesh, mResourceSystem));
std::auto_ptr<Animation> anim;
if (weaponsShields)
anim.reset(new CreatureWeaponAnimation(ptr, mesh, mResourceSystem));
else
anim.reset(new CreatureAnimation(ptr, mesh, mResourceSystem));
mObjects.insert(std::make_pair(ptr, anim.release()));
}

Loading…
Cancel
Save