mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-21 11:53:51 +00:00
consider all material properties for nif material sharing, instead of just the texture
This commit is contained in:
parent
7cf2fc4009
commit
281e15f58e
1 changed files with 29 additions and 18 deletions
|
@ -39,6 +39,7 @@
|
||||||
|
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
|
#include <boost/functional/hash.hpp>
|
||||||
|
|
||||||
#include <extern/shiny/Main/Factory.hpp>
|
#include <extern/shiny/Main/Factory.hpp>
|
||||||
|
|
||||||
|
@ -441,7 +442,7 @@ static CompareFunction getTestMode(int mode)
|
||||||
|
|
||||||
class NIFMaterialLoader {
|
class NIFMaterialLoader {
|
||||||
|
|
||||||
static std::multimap<std::string,std::string> MaterialMap;
|
static std::map<size_t,std::string> MaterialMap;
|
||||||
|
|
||||||
static void warn(const std::string &msg)
|
static void warn(const std::string &msg)
|
||||||
{
|
{
|
||||||
|
@ -473,6 +474,8 @@ static Ogre::String getMaterial(const NiTriShape *shape, const Ogre::String &nam
|
||||||
ubyte alphaTest = 0;
|
ubyte alphaTest = 0;
|
||||||
Ogre::String texName;
|
Ogre::String texName;
|
||||||
|
|
||||||
|
bool vertexColour = (shape->data->colors.size() != 0);
|
||||||
|
|
||||||
// These are set below if present
|
// These are set below if present
|
||||||
const NiTexturingProperty *t = NULL;
|
const NiTexturingProperty *t = NULL;
|
||||||
const NiMaterialProperty *m = NULL;
|
const NiMaterialProperty *m = NULL;
|
||||||
|
@ -537,23 +540,32 @@ static Ogre::String getMaterial(const NiTriShape *shape, const Ogre::String &nam
|
||||||
Ogre::String matname = name;
|
Ogre::String matname = name;
|
||||||
if (m || !texName.empty())
|
if (m || !texName.empty())
|
||||||
{
|
{
|
||||||
// If we're here, then this mesh has a material. Thus we
|
// Generate a hash out of all properties that can affect the material.
|
||||||
// need to calculate a snappy material name. It should
|
size_t h = 0;
|
||||||
// contain the mesh name (mesh->getName()) but also has to
|
boost::hash_combine(h, ambient.x);
|
||||||
// be unique. One mesh may use many materials.
|
boost::hash_combine(h, ambient.y);
|
||||||
std::multimap<std::string,std::string>::iterator itr = MaterialMap.find(texName);
|
boost::hash_combine(h, ambient.z);
|
||||||
std::multimap<std::string,std::string>::iterator lastElement;
|
boost::hash_combine(h, diffuse.x);
|
||||||
lastElement = MaterialMap.upper_bound(texName);
|
boost::hash_combine(h, diffuse.y);
|
||||||
|
boost::hash_combine(h, diffuse.z);
|
||||||
|
boost::hash_combine(h, specular.x);
|
||||||
|
boost::hash_combine(h, specular.y);
|
||||||
|
boost::hash_combine(h, specular.z);
|
||||||
|
boost::hash_combine(h, emissive.x);
|
||||||
|
boost::hash_combine(h, emissive.y);
|
||||||
|
boost::hash_combine(h, emissive.z);
|
||||||
|
boost::hash_combine(h, texName);
|
||||||
|
boost::hash_combine(h, vertexColour);
|
||||||
|
boost::hash_combine(h, alphaFlags);
|
||||||
|
|
||||||
|
std::map<size_t,std::string>::iterator itr = MaterialMap.find(h);
|
||||||
if (itr != MaterialMap.end())
|
if (itr != MaterialMap.end())
|
||||||
{
|
{
|
||||||
for ( ; itr != lastElement; ++itr)
|
// a suitable material exists already - use it
|
||||||
{
|
return itr->second;
|
||||||
//std::cout << "OK!";
|
|
||||||
//MaterialPtr mat = MaterialManager::getSingleton().getByName(itr->second,recourceGroup);
|
|
||||||
return itr->second;
|
|
||||||
//if( mat->getA
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// not found, create a new one
|
||||||
|
MaterialMap.insert(std::make_pair(h, matname));
|
||||||
}
|
}
|
||||||
|
|
||||||
// No existing material like this. Create a new one.
|
// No existing material like this. Create a new one.
|
||||||
|
@ -572,7 +584,7 @@ static Ogre::String getMaterial(const NiTriShape *shape, const Ogre::String &nam
|
||||||
|
|
||||||
instance->setProperty ("diffuseMap", sh::makeProperty(texName));
|
instance->setProperty ("diffuseMap", sh::makeProperty(texName));
|
||||||
|
|
||||||
if (shape->data->colors.size() != 0)
|
if (vertexColour)
|
||||||
instance->setProperty ("has_vertex_colour", sh::makeProperty<sh::BooleanValue>(new sh::BooleanValue(true)));
|
instance->setProperty ("has_vertex_colour", sh::makeProperty<sh::BooleanValue>(new sh::BooleanValue(true)));
|
||||||
|
|
||||||
// Add transparency if NiAlphaProperty was present
|
// Add transparency if NiAlphaProperty was present
|
||||||
|
@ -628,12 +640,11 @@ static Ogre::String getMaterial(const NiTriShape *shape, const Ogre::String &nam
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
MaterialMap.insert(std::make_pair(texName, matname));
|
|
||||||
return matname;
|
return matname;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
std::multimap<std::string,std::string> NIFMaterialLoader::MaterialMap;
|
std::map<size_t,std::string> NIFMaterialLoader::MaterialMap;
|
||||||
|
|
||||||
|
|
||||||
class NIFMeshLoader : Ogre::ManualResourceLoader
|
class NIFMeshLoader : Ogre::ManualResourceLoader
|
||||||
|
|
Loading…
Reference in a new issue