diff --git a/apps/openmw/mwrender/actoranimation.cpp b/apps/openmw/mwrender/actoranimation.cpp index c54e28426..a99fd7242 100644 --- a/apps/openmw/mwrender/actoranimation.cpp +++ b/apps/openmw/mwrender/actoranimation.cpp @@ -238,7 +238,7 @@ void ActorAnimation::updateHolsteredWeapon(bool showHolsteredWeapons) { if (showHolsteredWeapons) { - osg::Vec4f glowColor = getEnchantmentColor(*weapon); + osg::Vec4f glowColor = weapon->getClass().getEnchantmentColor(*weapon); mScabbard = getWeaponPart(mesh, boneName, isEnchanted, &glowColor); if (mScabbard) resetControllers(mScabbard->getNode()); @@ -271,7 +271,7 @@ void ActorAnimation::updateHolsteredWeapon(bool showHolsteredWeapons) if (isEnchanted) { - osg::Vec4f glowColor = getEnchantmentColor(*weapon); + osg::Vec4f glowColor = weapon->getClass().getEnchantmentColor(*weapon); addGlow(weaponNode, glowColor); } } @@ -347,7 +347,7 @@ void ActorAnimation::updateQuiver() } // Add new ones - osg::Vec4f glowColor = getEnchantmentColor(*ammo); + osg::Vec4f glowColor = ammo->getClass().getEnchantmentColor(*ammo); std::string model = ammo->getClass().getModel(*ammo); for (unsigned int i=0; igetSceneManager()->recreateShaders(node); } - // TODO: Should not be here - osg::Vec4f Animation::getEnchantmentColor(const MWWorld::ConstPtr& item) const - { - osg::Vec4f result(1,1,1,1); - std::string enchantmentName = item.getClass().getEnchantment(item); - if (enchantmentName.empty()) - return result; - - const ESM::Enchantment* enchantment = MWBase::Environment::get().getWorld()->getStore().get().search(enchantmentName); - if (!enchantment) - return result; - - assert (enchantment->mEffects.mList.size()); - - const ESM::MagicEffect* magicEffect = MWBase::Environment::get().getWorld()->getStore().get().search( - enchantment->mEffects.mList.front().mEffectID); - if (!magicEffect) - return result; - - result.x() = magicEffect->mData.mRed / 255.f; - result.y() = magicEffect->mData.mGreen / 255.f; - result.z() = magicEffect->mData.mBlue / 255.f; - return result; - } - void Animation::addExtraLight(osg::ref_ptr parent, const ESM::Light *esmLight) { bool exterior = mPtr.isInCell() && mPtr.getCell()->getCell()->isExterior(); @@ -2001,7 +1976,7 @@ namespace MWRender addAnimSource(model, model); if (!ptr.getClass().getEnchantment(ptr).empty()) - addGlow(mObjectRoot, getEnchantmentColor(ptr)); + addGlow(mObjectRoot, ptr.getClass().getEnchantmentColor(ptr)); } if (ptr.getTypeName() == typeid(ESM::Light).name() && allowLight) addExtraLight(getOrCreateObjectRoot(), ptr.get()->mBase); diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index 95007d888..bf142689e 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -330,8 +330,6 @@ protected: */ virtual void addControllers(); - osg::Vec4f getEnchantmentColor(const MWWorld::ConstPtr& item) const; - void addGlow(osg::ref_ptr node, osg::Vec4f glowColor, float glowDuration = -1); /// Set the render bin for this animation's object root. May be customized by subclasses. diff --git a/apps/openmw/mwrender/creatureanimation.cpp b/apps/openmw/mwrender/creatureanimation.cpp index aeee69ab0..dbd8e6cbf 100644 --- a/apps/openmw/mwrender/creatureanimation.cpp +++ b/apps/openmw/mwrender/creatureanimation.cpp @@ -132,7 +132,7 @@ void CreatureWeaponAnimation::updatePart(PartHolderPtr& scene, int slot) scene.reset(new PartHolder(attached)); if (!item.getClass().getEnchantment(item).empty()) - addGlow(attached, getEnchantmentColor(item)); + addGlow(attached, item.getClass().getEnchantmentColor(item)); // Crossbows start out with a bolt attached // FIXME: code duplicated from NpcAnimation diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index e7f7d878b..64504245a 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -572,7 +572,7 @@ void NpcAnimation::updateParts() int prio = 1; bool enchantedGlow = !store->getClass().getEnchantment(*store).empty(); - osg::Vec4f glowColor = getEnchantmentColor(*store); + osg::Vec4f glowColor = store->getClass().getEnchantmentColor(*store); if(store->getTypeName() == typeid(ESM::Clothing).name()) { prio = ((slotlist[i].mBasePriority+1)<<1) + 0; @@ -897,7 +897,7 @@ void NpcAnimation::showWeapons(bool showWeapon) MWWorld::ConstContainerStoreIterator weapon = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedRight); if(weapon != inv.end()) { - osg::Vec4f glowColor = getEnchantmentColor(*weapon); + osg::Vec4f glowColor = weapon->getClass().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); @@ -931,7 +931,7 @@ void NpcAnimation::showCarriedLeft(bool show) MWWorld::ConstContainerStoreIterator iter = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedLeft); if(show && iter != inv.end()) { - osg::Vec4f glowColor = getEnchantmentColor(*iter); + osg::Vec4f glowColor = iter->getClass().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)) diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index 472db15c5..f84c7bb8b 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -507,4 +507,28 @@ namespace MWWorld { throw std::runtime_error("class does not support armor ratings"); } + + osg::Vec4f Class::getEnchantmentColor(const MWWorld::ConstPtr& item) const + { + osg::Vec4f result(1,1,1,1); + std::string enchantmentName = item.getClass().getEnchantment(item); + if (enchantmentName.empty()) + return result; + + const ESM::Enchantment* enchantment = MWBase::Environment::get().getWorld()->getStore().get().search(enchantmentName); + if (!enchantment) + return result; + + assert (enchantment->mEffects.mList.size()); + + const ESM::MagicEffect* magicEffect = MWBase::Environment::get().getWorld()->getStore().get().search( + enchantment->mEffects.mList.front().mEffectID); + if (!magicEffect) + return result; + + result.x() = magicEffect->mData.mRed / 255.f; + result.y() = magicEffect->mData.mGreen / 255.f; + result.z() = magicEffect->mData.mBlue / 255.f; + return result; + } } diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index 2be54e7ba..8e5cfb981 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -6,6 +6,8 @@ #include #include +#include + #include "ptr.hpp" namespace ESM @@ -367,6 +369,8 @@ namespace MWWorld /// Get the effective armor rating, factoring in the actor's skills, for the given armor. virtual float getEffectiveArmorRating(const MWWorld::ConstPtr& armor, const MWWorld::Ptr& actor) const; + + virtual osg::Vec4f getEnchantmentColor(const MWWorld::ConstPtr& item) const; }; }