Skip to content

Commit

Permalink
Check if source coords are outside the image in v2::extract_texture
Browse files Browse the repository at this point in the history
If the head is partially outside the image, previously the extraction would crash here.
We can just skip a triangle if any of its vertex coordinates are outside of the image.
  • Loading branch information
patrikhuber committed Apr 26, 2020
1 parent 4ef5c99 commit 442497e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions include/eos/render/texture_extraction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,14 @@ extract_texture(const core::Mesh& mesh, glm::mat4x4 view_model_matrix, glm::mat4
wnd_coords[tvi[2]].x / image.width(),
wnd_coords[tvi[2]].y / image.height() // (maybe '1 - wndcoords...'?) wndcoords of the projected/rendered model triangle (in the input img). Normalised to 0,1.
)};
// The wnd_coords (now p[a|b|c].texcoords) can actually be outside the image, if the head is
// outside the image. Just skip the whole triangle if that is the case:
if (pa.texcoords.x < 0 || pa.texcoords.x > 1 || pa.texcoords.y < 0 || pa.texcoords.y > 1 ||
pb.texcoords.x < 0 || pb.texcoords.x > 1 || pb.texcoords.y < 0 || pb.texcoords.y > 1 ||
pc.texcoords.x < 0 || pc.texcoords.x > 1 || pc.texcoords.y < 0 || pc.texcoords.y > 1)
{
continue;
}
extraction_rasterizer.raster_triangle(pa, pb, pc, image_to_extract_from_as_tex);
}
}
Expand Down

0 comments on commit 442497e

Please sign in to comment.