GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add numpy_indices method · CppWorks/tinyobjloader@d0195db

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • python
    • bindings.cc
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎python/bindings.cc‎

Copy file name to clipboardExpand all lines: python/bindings.cc
+8-1Lines 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 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.