Skip to content

Commit

Permalink
added texture index functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Dielen committed Jun 12, 2018
1 parent 2f35a03 commit 1154c68
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/InputOutput.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void def_read_mesh(py::module& m, const char *_name) {
bool _edge_color,
bool _face_normal,
bool _face_color,
bool _face_texture_index,
bool _color_alpha,
bool _color_float
)
Expand Down Expand Up @@ -66,11 +67,14 @@ void def_read_mesh(py::module& m, const char *_name) {
options += OM::IO::Options::FaceColor;
mesh.request_face_colors();
}
if (_face_texture_index) {
mesh.request_face_texture_index();
}

if (_color_alpha) options += OM::IO::Options::ColorAlpha;
if (_color_float) options += OM::IO::Options::ColorFloat;

const bool ok = OM::IO::read_mesh(mesh,_filename, options);
const bool ok = OM::IO::read_mesh(mesh, _filename, options);

if (!ok) {
const std::string msg = "File could not be read: " + _filename;
Expand Down Expand Up @@ -120,6 +124,7 @@ void def_read_mesh(py::module& m, const char *_name) {
py::arg("edge_color")=false,
py::arg("face_normal")=false,
py::arg("face_color")=false,
py::arg("face_texture_index")=false,
py::arg("color_alpha")=false,
py::arg("color_float")=false
);
Expand Down
28 changes: 28 additions & 0 deletions src/Mesh.hh
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ void expose_mesh(py::module& m, const char *_name) {
typedef typename Mesh::TexCoord1D TexCoord1D;
typedef typename Mesh::TexCoord2D TexCoord2D;
typedef typename Mesh::TexCoord3D TexCoord3D;
typedef typename Mesh::TextureIndex TextureIndex;

//======================================================================
// KernelT Function Pointers
Expand Down Expand Up @@ -801,6 +802,33 @@ void expose_mesh(py::module& m, const char *_name) {
.def("sedges", sedges)
.def("sfaces", sfaces)

.def("texture_index", [](Mesh& _self, OM::FaceHandle _h) {
if (!_self.has_face_texture_index()) _self.request_face_texture_index();
return _self.texture_index(_h);
})

.def("set_texture_index", [](Mesh& _self, OM::FaceHandle _h, TextureIndex _idx) {
if (!_self.has_face_texture_index()) _self.request_face_texture_index();
_self.set_texture_index(_h, _idx);
})

.def("texture_name", [](Mesh& _self, TextureIndex _idx) {
OM::MPropHandleT<std::map<TextureIndex, std::string> > prop;
if (_self.get_property_handle(prop, "TextureMapping")) {
const auto map = _self.property(prop);
if (map.count(_idx) == 0) {
throw py::index_error();
}
else {
return map.at(_idx);
}
}
else {
PyErr_SetString(PyExc_RuntimeError, "Mesh has no textures.");
throw py::error_already_set();
}
})

//======================================================================
// BaseKernel
//======================================================================
Expand Down

0 comments on commit 1154c68

Please sign in to comment.