...
  View open merge request
Commits (3)
......@@ -112,6 +112,15 @@ void remove_duplicated_vertices(BaseImporter::VHandles& _indices)
_indices.erase(endIter,_indices.end());
}
unsigned int hexToInt(const std::string& hex)
{
unsigned int x;
std::stringstream ss;
ss << std::hex << hex;
ss >> x;
return x;
}
//-----------------------------------------------------------------------------
_OBJReader_::
......@@ -397,6 +406,40 @@ read_vertices(std::istream& _in, BaseImporter& _bi, Options& _opt,
}
}
}
// Note from ZBrush regarding colors in the MRGB block:
// The following MRGB block contains ZBrush Vertex Color (Polypaint) and masking output as 4 hexadecimal values per vertex. The vertex color format is MMRRGGBB with up to 64 entries per MRGB line.
else if (userOptions.vertex_has_color() && keyWrd == "#MRGB")
{
char hexM[2];
char hexR[2];
char hexG[2];
char hexB[2];
stream >> std::ws;
while (true)
{
stream.read(hexM, 2);
stream.read(hexR, 2);
stream.read(hexG, 2);
stream.read(hexB, 2);
if (!stream.fail())
{
float m = static_cast<float>(hexToInt(hexM)) / 255.0;
float r = static_cast<float>(hexToInt(hexR)) / 255.0;
float g = static_cast<float>(hexToInt(hexG)) / 255.0;
float b = static_cast<float>(hexToInt(hexB)) / 255.0;
colors.push_back(OpenMesh::Vec3f(r, g, b));
fileOptions += Options::VertexColor;
}
else
{
break;
}
}
}
}
return true;
......
......@@ -235,12 +235,6 @@ write(std::ostream& _out, BaseExporter& _be, Options _opt, std::streamsize _prec
return false;
}
// check for unsupported writer features
if (_opt.check(Options::VertexColor) ) {
omerr() << "[OBJWriter] : VertexColor not supported by OBJ Writer" << std::endl;
return false;
}
//create material file if needed
if ( _opt.check(Options::FaceColor) ){
......@@ -311,7 +305,15 @@ write(std::ostream& _out, BaseExporter& _be, Options _opt, std::streamsize _prec
n = _be.normal(vh);
t = _be.texcoord(vh);
_out << "v " << v[0] <<" "<< v[1] <<" "<< v[2] << '\n';
std::stringstream colorStream;
colorStream.precision(_precision);
if (_opt.check(Options::VertexColor))
{
c = _be.colorf(vh);
colorStream << std::fixed << " " << c[0] << " " << c[1] << " " << c[2];
}
_out << "v " << v[0] <<" "<< v[1] <<" "<< v[2] << colorStream.str() << '\n';
if (_opt.check(Options::VertexNormal))
_out << "vn " << n[0] <<" "<< n[1] <<" "<< n[2] << '\n';
......