|
| 1 | +#include "pybind11/pybind11.h" |
| 2 | +#include "pybind11/stl.h" |
| 3 | + |
| 4 | +#include "tiny_obj_loader.h" |
| 5 | + |
| 6 | + |
| 7 | +namespace py = pybind11; |
| 8 | + |
| 9 | +using namespace tinyobj; |
| 10 | + |
| 11 | +// Simple wrapper for LoadObj. |
| 12 | +// TODO(syoyo): Make it more pythonic. |
| 13 | +bool load_obj(attrib_t *attrib, std::vector<shape_t> *shapes, |
| 14 | + std::vector<material_t> *materials, |
| 15 | + std::string *warn, std::string *err, |
| 16 | + const std::string &filename, |
| 17 | + const std::string &mtl_basedir = "./", |
| 18 | + bool triangulate = true, |
| 19 | + bool default_vcols_fallback = true) |
| 20 | +{ |
| 21 | + return LoadObj(attrib, shapes, materials, warn, err, filename.c_str(), mtl_basedir.c_str(), triangulate, default_vcols_fallback); |
| 22 | +} |
| 23 | + |
| 24 | +// Simple wrapper for LoadMtl. |
| 25 | +// TODO(syoyo): Make it more pythonic. |
| 26 | +void load_mtl(std::map<std::string, int> *material_map, |
| 27 | + std::vector<material_t> *materials, std::istream *inStream, |
| 28 | + std::string *warning, std::string *err) { |
| 29 | + LoadMtl(material_map, materials, inStream, warning, err); |
| 30 | +} |
| 31 | + |
| 32 | + |
| 33 | +PYBIND11_MODULE(tinyobjloader, tobj_module) |
| 34 | +{ |
| 35 | + tobj_module.doc() = "Python bindings for TinyObjLoader."; |
| 36 | + |
| 37 | + // register struct |
| 38 | + py::class_<attrib_t>(tobj_module, "Attrib"); |
| 39 | + py::class_<shape_t>(tobj_module, "Shape"); |
| 40 | + py::class_<material_t>(tobj_module, "Material"); |
| 41 | + |
| 42 | + tobj_module.def("load_obj", &load_obj, "Load wavefront .obj file."); |
| 43 | + tobj_module.def("load_mtl", &load_mtl, "Load wavefront material file."); |
| 44 | +} |
| 45 | + |
0 commit comments