Commit 388124c7 authored by MURRAY David's avatar MURRAY David
Browse files

fix use texture of indices

parent 6565020b
......@@ -320,6 +320,7 @@ public:
//Multi material
static constexpr char const *const TEXTURE_INDEX_MK = "texture";
static constexpr char const *const MAT_INDEX_AT = "index";
//ATTRIBUTE VALUES
static constexpr char const *const BCKG_UNIFORM_TYPE_VAL = "uniform";
......
......@@ -244,9 +244,10 @@ bool SceneParser::parseGlobalMaterials(Scene &scene)
bool rOK = true;
for (int j = 0; j < multi_mat->size(); ++j)
{
rOK &= _brdf_map.count(multi_mat->getAllNames()[j]) == 1;
std::string name = multi_mat->getAllNames()[j];
rOK &= _brdf_map.count(name) == 1;
if (rOK)
multi_mat->addMRFIdEntry(_brdf_map[multi_mat->getAllNames()[j]]);
multi_mat->addMRFIdEntry(_brdf_map[name]);
else
break;
}
......@@ -3050,7 +3051,7 @@ bool SceneParser::parseIndexedUTIATexture(
rOK &= a_tex_element->QueryUnsignedAttribute(SceneLexer::UTIA_PHI_I_AT, &phi_i);
idx_utia_mat->setPhiIDiv((rOK != XML_SUCCESS) ? 1 : phi_i, tex_index);
const char *param;
int paramOK = a_tex_element->QueryStringAttribute(SceneLexer::UTIA_PARAMETERIZATION_AT, &param);
if (paramOK != XML_SUCCESS)
......@@ -3189,7 +3190,6 @@ bool SceneParser::parseMultiMaterial(
_loger->trace("Materials Found ! Parsing it....");
bool rOK = true;
for (; material; material = material->NextSiblingElement())
{
std::string element_name = material->Name();
......@@ -3203,10 +3203,18 @@ bool SceneParser::parseMultiMaterial(
//multi_mat->addEntry(_brdf_map[name], name);
multi_mat->addNameEntry(name);
unsigned int idx;
int rOK = material->QueryUnsignedAttribute(SceneLexer::MAT_INDEX_AT, &idx);
if (rOK == XML_SUCCESS)
{
multi_mat->addLocalIdEntry(idx);
}
}
}
return rOK;
return true;
}
bool SceneParser::parseTexture(XMLElement *a_mat_element, char const *texture_markup, std::string &path)
......
......@@ -13,7 +13,7 @@ mrf::image::IMAGE_LOAD_SAVE_FLAGS MultiMaterial::loadIndexTexture(std::string co
{
try
{
_index_map = mrf::image::load(path);
_index_map = mrf::image::loadColorImage(path, true);
_index_texture_path = std::string(path);
}
catch (mrf::image::IMAGE_LOAD_SAVE_FLAGS &error)
......@@ -30,10 +30,11 @@ void MultiMaterial::normalizeMapIndices(std::string exportPath)
if (!_normalized)
{
std::map<unsigned int, int> matToIndex;
for (int i = 0; i < _mrf_indices.size(); ++i)
for (int i = 0; i < _local_indices.size(); ++i)
{
unsigned int mat = _mrf_indices[i];
unsigned int mat = _local_indices[i];
matToIndex[mat] = i;
std::cout << i << " | " << matToIndex[mat] << std::endl;
}
for (int i = 0; i < _index_map.get()->width() * _index_map.get()->height(); ++i)
......@@ -41,14 +42,14 @@ void MultiMaterial::normalizeMapIndices(std::string exportPath)
mrf::color::Color pixel = _index_map.get()->getPixel(i);
int mat;
if (matToIndex.count(pixel.x() * 255) > 0)
if (matToIndex.count(pixel.x() * 255) == 1)
{
mat = matToIndex.at(pixel.x() * 255);
}
else
{
//material is not among the provided UTIA files, disable it.
mat = -1;
mat = matToIndex.at(0);
}
pixel.r() = mat / 255.f;
......
......@@ -19,6 +19,7 @@ class MRF_CORE_EXPORT MultiMaterial: public BRDF
{
protected:
std::vector<unsigned int> _mrf_indices;
std::vector<unsigned int> _local_indices;
std::vector<std::string> _names;
std::string _index_texture_path;
......@@ -31,17 +32,20 @@ public:
~MultiMaterial();
//void addEntry(unsigned int idx, std::string name) { _material_map[idx] = name; }
void addEntry(unsigned int mrf_idx, std::string name)
void addEntry(unsigned int mrf_idx, std::string name, unsigned int local_idx)
{
_mrf_indices.push_back(mrf_idx);
_names.push_back(name);
_local_indices.push_back(local_idx);
}
void addMRFIdEntry(unsigned int idx) { _mrf_indices.push_back(idx); }
void addLocalIdEntry(unsigned int idx) { _local_indices.push_back(idx); }
void addNameEntry(std::string name) { _names.push_back(name); }
mrf::image::IMAGE_LOAD_SAVE_FLAGS loadIndexTexture(std::string const &path);
std::vector<unsigned int> &getAllMRFId() { return _mrf_indices; }
std::vector<unsigned int> &getAllLocalId() { return _local_indices; }
std::vector<std::string> & getAllNames() { return _names; }
std::string getTexturePath() const { return _index_texture_path; }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment