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 add_openmw_dir (mwrender
actors objects renderingmanager animation sky npcanimation vismask actors objects renderingmanager animation sky npcanimation vismask
# debugging camera creatureanimation activatoranimation creatureanimation
# debugging camera activatoranimation
# renderinginterface localmap occlusionquery water shadows # renderinginterface localmap occlusionquery water shadows
# characterpreview globalmap ripplesimulation refraction # characterpreview globalmap ripplesimulation refraction
# terrainstorage renderconst effectmanager weaponanimation # terrainstorage renderconst effectmanager weaponanimation

@ -497,6 +497,7 @@ void OMW::Engine::go()
{ {
double dt = frameTimer.time_s(); double dt = frameTimer.time_s();
frameTimer.setStartTick(); frameTimer.setStartTick();
//dt = std::min(dt, 0.2f);
// frameRenderingQueued(dt); // frameRenderingQueued(dt);
MWBase::Environment::get().getWorld()->update(dt, false); MWBase::Environment::get().getWorld()->update(dt, false);
@ -507,18 +508,6 @@ void OMW::Engine::go()
mViewer.frame(/*simulationTime*/); 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 // Save user settings
settings.saveUser(settingspath); settings.saveUser(settingspath);

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

@ -15,17 +15,17 @@ namespace MWRender
class CreatureAnimation : public Animation class CreatureAnimation : public Animation
{ {
public: public:
CreatureAnimation(const MWWorld::Ptr& ptr, const std::string &model); CreatureAnimation(const MWWorld::Ptr &ptr, const std::string& model, Resource::ResourceSystem* resourceSystem);
virtual ~CreatureAnimation() {} virtual ~CreatureAnimation() {}
}; };
// For creatures with weapons and shields // For creatures with weapons and shields
// Animation is already virtual anyway, so might as well make a separate class. // 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. // 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: 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 ~CreatureWeaponAnimation() {}
virtual void equipmentChanged() { updateParts(); } virtual void equipmentChanged() { updateParts(); }
@ -35,31 +35,31 @@ namespace MWRender
void updateParts(); void updateParts();
void updatePart(NifOgre::ObjectScenePtr& scene, int slot); void updatePart(PartHolderPtr& scene, int slot);
virtual void attachArrow(); virtual void attachArrow();
virtual void releaseArrow(); 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 /// A relative factor (0-1) that decides if and how much the skeleton should be pitched
/// to indicate the facing orientation of the character. /// 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 // WeaponAnimation
virtual NifOgre::ObjectScenePtr getWeapon() { return mWeapon; } //virtual NifOgre::ObjectScenePtr getWeapon() { return mWeapon; }
virtual void showWeapon(bool show) { showWeapons(show); } //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);
private: private:
NifOgre::ObjectScenePtr mWeapon; PartHolderPtr mWeapon;
NifOgre::ObjectScenePtr mShield; PartHolderPtr mShield;
bool mShowWeapons; bool mShowWeapons;
bool mShowCarriedLeft; bool mShowCarriedLeft;
Ogre::SharedPtr<WeaponAnimationTime> mWeaponAnimationTime; //Ogre::SharedPtr<WeaponAnimationTime> mWeaponAnimationTime;
}; };
} }

@ -1,15 +1,5 @@
#include "npcanimation.hpp" #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 <openengine/misc/rng.hpp>
#include <components/misc/resourcehelpers.hpp> #include <components/misc/resourcehelpers.hpp>
@ -575,18 +565,6 @@ void NpcAnimation::addFirstPersonOffset(const Ogre::Vector3 &offset)
mFirstPersonOffset += 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) 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); osg::ref_ptr<osg::Node> instance = mResourceSystem->getSceneManager()->createInstance(model);

@ -26,6 +26,7 @@
#include "renderconst.hpp" #include "renderconst.hpp"
#include "animation.hpp" #include "animation.hpp"
#include "npcanimation.hpp" #include "npcanimation.hpp"
#include "creatureanimation.hpp"
namespace namespace
{ {
@ -194,7 +195,13 @@ void Objects::insertCreature(const MWWorld::Ptr &ptr, const std::string &mesh, b
insertBegin(ptr); insertBegin(ptr);
// CreatureAnimation // 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())); mObjects.insert(std::make_pair(ptr, anim.release()));
} }

Loading…
Cancel
Save