MCPcopy Create free account
hub / github.com/BoomingTech/Piccolo / PYBIND11_MODULE

Function PYBIND11_MODULE

engine/3rdparty/tinyobjloader/python/bindings.cc:17–162  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15using namespace tinyobj;
16
17PYBIND11_MODULE(tinyobjloader, tobj_module)
18{
19 tobj_module.doc() = "Python bindings for TinyObjLoader.";
20
21 // register struct
22 py::class_<ObjReaderConfig>(tobj_module, "ObjReaderConfig")
23 .def(py::init<>())
24 .def_readwrite("triangulate", &ObjReaderConfig::triangulate);
25
26 // py::init<>() for default constructor
27 py::class_<ObjReader>(tobj_module, "ObjReader")
28 .def(py::init<>())
29 .def("ParseFromFile", &ObjReader::ParseFromFile, py::arg("filename"), py::arg("option") = ObjReaderConfig())
30 .def("ParseFromString", &ObjReader::ParseFromString, py::arg("obj_text"), py::arg("mtl_text"), py::arg("option") = ObjReaderConfig())
31 .def("Valid", &ObjReader::Valid)
32 .def("GetAttrib", &ObjReader::GetAttrib)
33 .def("GetShapes", &ObjReader::GetShapes)
34 .def("GetMaterials", &ObjReader::GetMaterials)
35 .def("Warning", &ObjReader::Warning)
36 .def("Error", &ObjReader::Error);
37
38 py::class_<attrib_t>(tobj_module, "attrib_t")
39 .def(py::init<>())
40 .def_readonly("vertices", &attrib_t::vertices)
41 .def("numpy_vertices", [] (attrib_t &instance) {
42 auto ret = py::array_t<real_t>(instance.vertices.size());
43 py::buffer_info buf = ret.request();
44 memcpy(buf.ptr, instance.vertices.data(), instance.vertices.size() * sizeof(real_t));
45 return ret;
46 })
47 .def_readonly("normals", &attrib_t::normals)
48 .def_readonly("texcoords", &attrib_t::texcoords)
49 .def_readonly("colors", &attrib_t::colors)
50 ;
51
52 py::class_<shape_t>(tobj_module, "shape_t")
53 .def(py::init<>())
54 .def_readwrite("name", &shape_t::name)
55 .def_readwrite("mesh", &shape_t::mesh)
56 .def_readwrite("lines", &shape_t::lines)
57 .def_readwrite("points", &shape_t::points);
58
59 py::class_<index_t>(tobj_module, "index_t")
60 .def(py::init<>())
61 .def_readwrite("vertex_index", &index_t::vertex_index)
62 .def_readwrite("normal_index", &index_t::normal_index)
63 .def_readwrite("texcoord_index", &index_t::texcoord_index)
64 ;
65
66 // NOTE(syoyo): It looks it is rather difficult to expose assignment by array index to
67 // python world for array variable.
68 // For example following python scripting does not work well.
69 //
70 // print(mat.diffuse)
71 // >>> [0.1, 0.2, 0.3]
72 // mat.diffuse[1] = 1.0
73 // print(mat.diffuse)
74 // >>> [0.1, 0.2, 0.3] # No modification

Callers

nothing calls this directly

Calls 4

argFunction · 0.85
ObjReaderConfigClass · 0.85
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected