Move getEnchantmentColor() from Animation to Class

pull/541/head
Andrei Kortunov 5 years ago
parent 06ba80e19b
commit 4c92f0c4e1

@ -238,7 +238,7 @@ void ActorAnimation::updateHolsteredWeapon(bool showHolsteredWeapons)
{ {
if (showHolsteredWeapons) if (showHolsteredWeapons)
{ {
osg::Vec4f glowColor = getEnchantmentColor(*weapon); osg::Vec4f glowColor = weapon->getClass().getEnchantmentColor(*weapon);
mScabbard = getWeaponPart(mesh, boneName, isEnchanted, &glowColor); mScabbard = getWeaponPart(mesh, boneName, isEnchanted, &glowColor);
if (mScabbard) if (mScabbard)
resetControllers(mScabbard->getNode()); resetControllers(mScabbard->getNode());
@ -271,7 +271,7 @@ void ActorAnimation::updateHolsteredWeapon(bool showHolsteredWeapons)
if (isEnchanted) if (isEnchanted)
{ {
osg::Vec4f glowColor = getEnchantmentColor(*weapon); osg::Vec4f glowColor = weapon->getClass().getEnchantmentColor(*weapon);
addGlow(weaponNode, glowColor); addGlow(weaponNode, glowColor);
} }
} }
@ -347,7 +347,7 @@ void ActorAnimation::updateQuiver()
} }
// Add new ones // Add new ones
osg::Vec4f glowColor = getEnchantmentColor(*ammo); osg::Vec4f glowColor = ammo->getClass().getEnchantmentColor(*ammo);
std::string model = ammo->getClass().getModel(*ammo); std::string model = ammo->getClass().getModel(*ammo);
for (unsigned int i=0; i<ammoCount; ++i) for (unsigned int i=0; i<ammoCount; ++i)
{ {

@ -1658,31 +1658,6 @@ namespace MWRender
mResourceSystem->getSceneManager()->recreateShaders(node); mResourceSystem->getSceneManager()->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<ESM::Enchantment>().search(enchantmentName);
if (!enchantment)
return result;
assert (enchantment->mEffects.mList.size());
const ESM::MagicEffect* magicEffect = MWBase::Environment::get().getWorld()->getStore().get<ESM::MagicEffect>().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<osg::Group> parent, const ESM::Light *esmLight) void Animation::addExtraLight(osg::ref_ptr<osg::Group> parent, const ESM::Light *esmLight)
{ {
bool exterior = mPtr.isInCell() && mPtr.getCell()->getCell()->isExterior(); bool exterior = mPtr.isInCell() && mPtr.getCell()->getCell()->isExterior();
@ -2001,7 +1976,7 @@ namespace MWRender
addAnimSource(model, model); addAnimSource(model, model);
if (!ptr.getClass().getEnchantment(ptr).empty()) if (!ptr.getClass().getEnchantment(ptr).empty())
addGlow(mObjectRoot, getEnchantmentColor(ptr)); addGlow(mObjectRoot, ptr.getClass().getEnchantmentColor(ptr));
} }
if (ptr.getTypeName() == typeid(ESM::Light).name() && allowLight) if (ptr.getTypeName() == typeid(ESM::Light).name() && allowLight)
addExtraLight(getOrCreateObjectRoot(), ptr.get<ESM::Light>()->mBase); addExtraLight(getOrCreateObjectRoot(), ptr.get<ESM::Light>()->mBase);

@ -330,8 +330,6 @@ protected:
*/ */
virtual void addControllers(); virtual void addControllers();
osg::Vec4f getEnchantmentColor(const MWWorld::ConstPtr& item) const;
void addGlow(osg::ref_ptr<osg::Node> node, osg::Vec4f glowColor, float glowDuration = -1); void addGlow(osg::ref_ptr<osg::Node> node, osg::Vec4f glowColor, float glowDuration = -1);
/// Set the render bin for this animation's object root. May be customized by subclasses. /// Set the render bin for this animation's object root. May be customized by subclasses.

@ -132,7 +132,7 @@ void CreatureWeaponAnimation::updatePart(PartHolderPtr& scene, int slot)
scene.reset(new PartHolder(attached)); scene.reset(new PartHolder(attached));
if (!item.getClass().getEnchantment(item).empty()) if (!item.getClass().getEnchantment(item).empty())
addGlow(attached, getEnchantmentColor(item)); addGlow(attached, item.getClass().getEnchantmentColor(item));
// Crossbows start out with a bolt attached // Crossbows start out with a bolt attached
// FIXME: code duplicated from NpcAnimation // FIXME: code duplicated from NpcAnimation

@ -572,7 +572,7 @@ void NpcAnimation::updateParts()
int prio = 1; int prio = 1;
bool enchantedGlow = !store->getClass().getEnchantment(*store).empty(); 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()) if(store->getTypeName() == typeid(ESM::Clothing).name())
{ {
prio = ((slotlist[i].mBasePriority+1)<<1) + 0; 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); MWWorld::ConstContainerStoreIterator weapon = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedRight);
if(weapon != inv.end()) if(weapon != inv.end())
{ {
osg::Vec4f glowColor = getEnchantmentColor(*weapon); osg::Vec4f glowColor = weapon->getClass().getEnchantmentColor(*weapon);
std::string mesh = weapon->getClass().getModel(*weapon); std::string mesh = weapon->getClass().getModel(*weapon);
addOrReplaceIndividualPart(ESM::PRT_Weapon, MWWorld::InventoryStore::Slot_CarriedRight, 1, addOrReplaceIndividualPart(ESM::PRT_Weapon, MWWorld::InventoryStore::Slot_CarriedRight, 1,
mesh, !weapon->getClass().getEnchantment(*weapon).empty(), &glowColor); 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); MWWorld::ConstContainerStoreIterator iter = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedLeft);
if(show && iter != inv.end()) if(show && iter != inv.end())
{ {
osg::Vec4f glowColor = getEnchantmentColor(*iter); osg::Vec4f glowColor = iter->getClass().getEnchantmentColor(*iter);
std::string mesh = iter->getClass().getModel(*iter); std::string mesh = iter->getClass().getModel(*iter);
if (addOrReplaceIndividualPart(ESM::PRT_Shield, MWWorld::InventoryStore::Slot_CarriedLeft, 1, if (addOrReplaceIndividualPart(ESM::PRT_Shield, MWWorld::InventoryStore::Slot_CarriedLeft, 1,
mesh, !iter->getClass().getEnchantment(*iter).empty(), &glowColor)) mesh, !iter->getClass().getEnchantment(*iter).empty(), &glowColor))

@ -507,4 +507,28 @@ namespace MWWorld
{ {
throw std::runtime_error("class does not support armor ratings"); 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<ESM::Enchantment>().search(enchantmentName);
if (!enchantment)
return result;
assert (enchantment->mEffects.mList.size());
const ESM::MagicEffect* magicEffect = MWBase::Environment::get().getWorld()->getStore().get<ESM::MagicEffect>().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;
}
} }

@ -6,6 +6,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <osg/Vec4f>
#include "ptr.hpp" #include "ptr.hpp"
namespace ESM namespace ESM
@ -367,6 +369,8 @@ namespace MWWorld
/// Get the effective armor rating, factoring in the actor's skills, for the given armor. /// 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 float getEffectiveArmorRating(const MWWorld::ConstPtr& armor, const MWWorld::Ptr& actor) const;
virtual osg::Vec4f getEnchantmentColor(const MWWorld::ConstPtr& item) const;
}; };
} }

Loading…
Cancel
Save