Commit c42cd9f4 authored by Jan Möbius's avatar Jan Möbius
Browse files

Workaround uninitialized colors

parent b2b2721e
......@@ -144,6 +144,15 @@ Material& FileOBJPlugin::getMaterial(MeshT& _mesh, const OpenMesh::FaceHandle& _
OpenMesh::Vec4f c = _mesh.color( _fh );
// If one of the entries is out of range, assume uninitialized color and set to default
// Ugly hack to ensure that materials will only be generated if initialized
if ( c[0] > 255.0 || c[1] > 255.0 || c[2] > 255.0 || c[0] < 0.0 || c[1] < 0.0 || c[2] < 0.0) {
c[0] = 155.0;
c[1] = 155.0;
c[2] = 155.0;
c[3] = 1.0;
}
// First off, try to fetch texture index of current face/object...
if(!textureIndexPropFetched_) {
emit textureIndexPropertyName(_objId, textureIndexPropertyName_);
......@@ -321,8 +330,8 @@ bool FileOBJPlugin::writeMesh(std::ostream& _out, QString _filename, MeshT& _mes
// If mesh has halfedge tex coords, write them out instead of vertex texcoords
if(optionVertexTexCoords && _mesh.has_halfedge_texcoords2D()) {
int count = 1;
for (f_it = _mesh.faces_begin(); f_it != _mesh.faces_end(); ++f_it) {
for(fh_it=_mesh.fh_iter(*f_it); fh_it.is_valid(); ++fh_it) {
for ( auto f_it : _mesh.faces() ) {
for(fh_it=_mesh.fh_iter(f_it); fh_it.is_valid(); ++fh_it) {
typename MeshT::TexCoord2D t = _mesh.texcoord2D(*fh_it);
_out << "vt " << t[0] << " " << t[1] << '\n';
vtMap.insert(std::pair<typename MeshT::HalfedgeHandle, int>(*fh_it, count));
......@@ -333,19 +342,19 @@ bool FileOBJPlugin::writeMesh(std::ostream& _out, QString _filename, MeshT& _mes
Material lastMat;
// we do not want to write seperators if we only write vertex indices
// we do not want to write separators if we only write vertex indices
bool vertexOnly = !(optionVertexTexCoords && _mesh.has_halfedge_texcoords2D())
&& !(optionVertexTexCoords && !_mesh.has_halfedge_texcoords2D() && _mesh.has_vertex_texcoords2D())
&& !(optionVertexNormals);
for (f_it = _mesh.faces_begin(); f_it != _mesh.faces_end(); ++f_it){
for ( auto f_it : _mesh.faces() ){
if (useMaterial && optionFaceColors) {
Material& material = getMaterial(_mesh, *f_it, _objId);
Material& material = getMaterial(_mesh, f_it, _objId);
// If we are ina a new material block, specify in the file which material to use
if(lastMat != material) {
if(lastMat.material_number() != material.material_number() ) {
_out << "usemtl " << material << '\n';
lastMat = material;
}
......@@ -354,7 +363,7 @@ bool FileOBJPlugin::writeMesh(std::ostream& _out, QString _filename, MeshT& _mes
_out << "f";
// Write out face information
for(fh_it=_mesh.fh_iter(*f_it); fh_it.is_valid(); ++fh_it) {
for(fh_it=_mesh.fh_iter(f_it); fh_it.is_valid(); ++fh_it) {
// Write vertex index
idx = _mesh.to_vertex_handle(*fh_it).idx() + 1;
......
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