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 // load nif overrides
NifOverrides::Overrides nifOverrides; NifOverrides::Overrides nifOverrides;
if (boost::filesystem::exists(mCfgMgr.getLocalPath().string() + "/transparency-overrides.cfg")) std::string transparencyOverrides = "/transparency-overrides.cfg";
nifOverrides.loadTransparencyOverrides(mCfgMgr.getLocalPath().string() + "/transparency-overrides.cfg"); std::string materialOverrides = "/material-overrides.cfg";
else if (boost::filesystem::exists(mCfgMgr.getGlobalPath().string() + "/transparency-overrides.cfg")) if (boost::filesystem::exists(mCfgMgr.getLocalPath().string() + transparencyOverrides))
nifOverrides.loadTransparencyOverrides(mCfgMgr.getGlobalPath().string() + "/transparency-overrides.cfg"); nifOverrides.loadTransparencyOverrides(mCfgMgr.getLocalPath().string() + transparencyOverrides);
else if (boost::filesystem::exists(mCfgMgr.getGlobalPath().string() + transparencyOverrides))
settings.setBool("hardware cursors", "GUI", true); 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; return settingspath;
} }

@ -157,7 +157,6 @@ Ogre::String NIFMaterialLoader::getMaterial(const Nif::ShapeData *shapedata,
ctrls = ctrls->next; ctrls = ctrls->next;
} }
} }
needTangents = !texName[Nif::NiTexturingProperty::BumpTexture].empty();
// Alpha modifiers // Alpha modifiers
if(alphaprop) 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"))); instance->setProperty("depth_write", sh::makeProperty(new sh::StringValue(((depthFlags>>1)&1) ? "on" : "off")));
// depth_func??? // 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; return name;
} }

@ -4,14 +4,51 @@
#include <../components/misc/stringops.hpp> #include <../components/misc/stringops.hpp>
#include "../extern/shiny/Main/MaterialInstance.hpp"
#include <stdexcept>
using namespace NifOverrides; 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) 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) TransparencyResult Overrides::getTransparencyOverride(const std::string& texture)
@ -19,20 +56,25 @@ TransparencyResult Overrides::getTransparencyOverride(const std::string& texture
TransparencyResult result; TransparencyResult result;
result.first = false; result.first = false;
std::string tex = texture; TransparencyOverrideMap::iterator it = mTransparencyOverrides.find(Misc::StringUtils::lowerCase(texture));
Misc::StringUtils::toLower(tex); if (it != mTransparencyOverrides.end())
{
result.first = true;
result.second = it->second;
}
Ogre::ConfigFile::SectionIterator seci = mTransparencyOverrides.getSectionIterator(); return result;
while (seci.hasMoreElements()) }
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(); const std::map<std::string, std::string>& overrides = it->second;
if (sectionName == tex) for (std::map<std::string, std::string>::const_iterator it = overrides.begin(); it != overrides.end(); ++it)
{ {
result.first = true; material->setProperty(it->first, sh::makeProperty(it->second));
result.second = Ogre::StringConverter::parseInt(mTransparencyOverrides.getSetting("alphaRejectValue", sectionName));
break;
} }
seci.getNext();
} }
return result;
} }

@ -3,19 +3,34 @@
#include <OgreConfigFile.h> #include <OgreConfigFile.h>
namespace sh
{
class MaterialInstance;
}
namespace NifOverrides namespace NifOverrides
{ {
typedef std::pair<bool, int> TransparencyResult; 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 class Overrides
{ {
public: 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 loadTransparencyOverrides (const std::string& file);
void loadMaterialOverrides (const std::string& file);
static TransparencyResult getTransparencyOverride(const std::string& texture); static TransparencyResult getTransparencyOverride(const std::string& texture);
static void getMaterialOverrides (const std::string& texture, sh::MaterialInstance* instance);
}; };
} }

Loading…
Cancel
Save