Extend NifOverrides to allow material overrides, useful for texture modding e.g. adding normal maps without having to edit the affected meshes

actorid
scrawl 11 years ago
parent ce013315ba
commit b8e9343764

@ -309,12 +309,16 @@ std::string OMW::Engine::loadSettings (Settings::Manager & settings)
// load nif overrides
NifOverrides::Overrides nifOverrides;
if (boost::filesystem::exists(mCfgMgr.getLocalPath().string() + "/transparency-overrides.cfg"))
nifOverrides.loadTransparencyOverrides(mCfgMgr.getLocalPath().string() + "/transparency-overrides.cfg");
else if (boost::filesystem::exists(mCfgMgr.getGlobalPath().string() + "/transparency-overrides.cfg"))
nifOverrides.loadTransparencyOverrides(mCfgMgr.getGlobalPath().string() + "/transparency-overrides.cfg");
settings.setBool("hardware cursors", "GUI", true);
std::string transparencyOverrides = "/transparency-overrides.cfg";
std::string materialOverrides = "/material-overrides.cfg";
if (boost::filesystem::exists(mCfgMgr.getLocalPath().string() + transparencyOverrides))
nifOverrides.loadTransparencyOverrides(mCfgMgr.getLocalPath().string() + transparencyOverrides);
else if (boost::filesystem::exists(mCfgMgr.getGlobalPath().string() + transparencyOverrides))
nifOverrides.loadTransparencyOverrides(mCfgMgr.getGlobalPath().string() + transparencyOverrides);
if (boost::filesystem::exists(mCfgMgr.getLocalPath().string() + materialOverrides))
nifOverrides.loadMaterialOverrides(mCfgMgr.getLocalPath().string() + materialOverrides);
else if (boost::filesystem::exists(mCfgMgr.getGlobalPath().string() + materialOverrides))
nifOverrides.loadMaterialOverrides(mCfgMgr.getGlobalPath().string() + materialOverrides);
return settingspath;
}

@ -157,7 +157,6 @@ Ogre::String NIFMaterialLoader::getMaterial(const Nif::ShapeData *shapedata,
ctrls = ctrls->next;
}
}
needTangents = !texName[Nif::NiTexturingProperty::BumpTexture].empty();
// Alpha modifiers
if(alphaprop)
@ -407,6 +406,12 @@ Ogre::String NIFMaterialLoader::getMaterial(const Nif::ShapeData *shapedata,
instance->setProperty("depth_write", sh::makeProperty(new sh::StringValue(((depthFlags>>1)&1) ? "on" : "off")));
// depth_func???
if (!texName[0].empty())
NifOverrides::Overrides::getMaterialOverrides(texName[0], instance);
// Don't use texName, as it may be overridden
needTangents = !sh::retrieveValue<sh::StringValue>(instance->getProperty("normalMap"), instance).get().empty();
return name;
}

@ -4,14 +4,51 @@
#include <../components/misc/stringops.hpp>
#include "../extern/shiny/Main/MaterialInstance.hpp"
#include <stdexcept>
using namespace NifOverrides;
Ogre::ConfigFile Overrides::mTransparencyOverrides = Ogre::ConfigFile();
Overrides::TransparencyOverrideMap Overrides::mTransparencyOverrides = Overrides::TransparencyOverrideMap();
Overrides::MaterialOverrideMap Overrides::mMaterialOverrides = Overrides::MaterialOverrideMap();
void Overrides::loadTransparencyOverrides (const std::string& file)
{
mTransparencyOverrides.load(file);
Ogre::ConfigFile cf;
cf.load(file);
Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
while (seci.hasMoreElements())
{
Ogre::String sectionName = seci.peekNextKey();
mTransparencyOverrides[sectionName] =
Ogre::StringConverter::parseInt(cf.getSetting("alphaRejectValue", sectionName));
seci.getNext();
}
}
void Overrides::loadMaterialOverrides(const std::string &file)
{
Ogre::ConfigFile cf;
cf.load(file);
Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
while (seci.hasMoreElements())
{
Ogre::String sectionName = seci.peekNextKey();
Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
Ogre::ConfigFile::SettingsMultiMap::iterator i;
std::map<std::string, std::string> overrides;
for (i = settings->begin(); i != settings->end(); ++i)
{
overrides[i->first] = i->second;
}
mMaterialOverrides[sectionName] = overrides;
}
}
TransparencyResult Overrides::getTransparencyOverride(const std::string& texture)
@ -19,20 +56,25 @@ TransparencyResult Overrides::getTransparencyOverride(const std::string& texture
TransparencyResult result;
result.first = false;
std::string tex = texture;
Misc::StringUtils::toLower(tex);
TransparencyOverrideMap::iterator it = mTransparencyOverrides.find(Misc::StringUtils::lowerCase(texture));
if (it != mTransparencyOverrides.end())
{
result.first = true;
result.second = it->second;
}
Ogre::ConfigFile::SectionIterator seci = mTransparencyOverrides.getSectionIterator();
while (seci.hasMoreElements())
return result;
}
void Overrides::getMaterialOverrides(const std::string &texture, sh::MaterialInstance* material)
{
MaterialOverrideMap::iterator it = mMaterialOverrides.find(Misc::StringUtils::lowerCase(texture));
if (it != mMaterialOverrides.end())
{
Ogre::String sectionName = seci.peekNextKey();
if (sectionName == tex)
const std::map<std::string, std::string>& overrides = it->second;
for (std::map<std::string, std::string>::const_iterator it = overrides.begin(); it != overrides.end(); ++it)
{
result.first = true;
result.second = Ogre::StringConverter::parseInt(mTransparencyOverrides.getSetting("alphaRejectValue", sectionName));
break;
material->setProperty(it->first, sh::makeProperty(it->second));
}
seci.getNext();
}
return result;
}

@ -3,19 +3,34 @@
#include <OgreConfigFile.h>
namespace sh
{
class MaterialInstance;
}
namespace NifOverrides
{
typedef std::pair<bool, int> TransparencyResult;
/// \brief provide overrides for some model / texture properties that bethesda has chosen poorly
/// Allows to provide overrides for some material properties in NIF files.
/// NIFs are a bit limited in that they don't allow specifying a material externally, which is
/// painful for texture modding.
/// We also use this to patch up transparency settings in certain NIFs that bethesda has chosen poorly.
class Overrides
{
public:
static Ogre::ConfigFile mTransparencyOverrides;
typedef std::map<std::string, int> TransparencyOverrideMap;
static TransparencyOverrideMap mTransparencyOverrides;
typedef std::map<std::string, std::map<std::string, std::string> > MaterialOverrideMap;
static MaterialOverrideMap mMaterialOverrides;
void loadTransparencyOverrides (const std::string& file);
void loadMaterialOverrides (const std::string& file);
static TransparencyResult getTransparencyOverride(const std::string& texture);
static void getMaterialOverrides (const std::string& texture, sh::MaterialInstance* instance);
};
}

Loading…
Cancel
Save