Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d8e95e4

Browse files
authored
Merge pull request tinyobjloader#214 from tim37021/master
Add numpy_indices method
2 parents 80d2ded + d0195db commit d8e95e4

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

python/bindings.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "pybind11/pybind11.h"
22
#include "pybind11/stl.h"
33
#include "pybind11/numpy.h"
4+
#include <cstring>
45

56
// Use double precision for better python integration.
67
#define TINYOBJLOADER_USE_DOUBLE
@@ -114,7 +115,13 @@ PYBIND11_MODULE(tinyobjloader, tobj_module)
114115

115116
py::class_<mesh_t>(tobj_module, "mesh_t")
116117
.def(py::init<>())
117-
.def_readonly("indices", &mesh_t::indices);
118+
.def_readonly("indices", &mesh_t::indices)
119+
.def("numpy_indices", [] (mesh_t &instance) {
120+
auto ret = py::array_t<int>(instance.indices.size() * 3);
121+
py::buffer_info buf = ret.request();
122+
memcpy(buf.ptr, instance.indices.data(), instance.indices.size() * 3 * sizeof(int));
123+
return ret;
124+
});
118125

119126
py::class_<lines_t>(tobj_module, "lines_t")
120127
.def(py::init<>());

0 commit comments

Comments
 (0)