Skip to content

Commit 17a6941

Browse files
committed
Make ObjReaderConfig optional when calling ParseFrom***() function.
1 parent d6e9bfa commit 17a6941

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

python/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
all:
22
python setup.py build
3+
4+
t:
5+
python sample.py
6+
7+
.PHONY: t

python/bindings.cc

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ PYBIND11_MODULE(tinyobj, tobj_module)
1313
tobj_module.doc() = "Python bindings for TinyObjLoader.";
1414

1515
// register struct
16+
py::class_<ObjReaderConfig>(tobj_module, "ObjReaderConfig")
17+
.def(py::init<>())
18+
.def_readwrite("triangulate", &ObjReaderConfig::triangulate);
19+
1620
// py::init<>() for default constructor
1721
py::class_<ObjReader>(tobj_module, "ObjReader")
1822
.def(py::init<>())
19-
.def("ParseFromFile", &ObjReader::ParseFromFile)
20-
.def("ParseFromString", &ObjReader::ParseFromString)
23+
.def("ParseFromFile", &ObjReader::ParseFromFile, py::arg("filename"), py::arg("option") = ObjReaderConfig())
24+
.def("ParseFromString", &ObjReader::ParseFromString, py::arg("obj_text"), py::arg("mtl_text"), py::arg("option") = ObjReaderConfig())
2125
.def("Valid", &ObjReader::Valid)
2226
.def("GetAttrib", &ObjReader::GetAttrib)
2327
.def("GetShapes", &ObjReader::GetShapes)
@@ -31,16 +35,16 @@ PYBIND11_MODULE(tinyobj, tobj_module)
3135

3236
py::class_<shape_t>(tobj_module, "shape_t")
3337
.def(py::init<>())
34-
.def_readonly("name", &shape_t::name)
35-
.def_readonly("mesh", &shape_t::mesh)
36-
.def_readonly("lines", &shape_t::lines)
37-
.def_readonly("points", &shape_t::points);
38+
.def_readwrite("name", &shape_t::name)
39+
.def_readwrite("mesh", &shape_t::mesh)
40+
.def_readwrite("lines", &shape_t::lines)
41+
.def_readwrite("points", &shape_t::points);
3842

3943
py::class_<index_t>(tobj_module, "index_t")
4044
.def(py::init<>())
41-
.def_readonly("vertex_index", &index_t::vertex_index)
42-
.def_readonly("normal_index", &index_t::normal_index)
43-
.def_readonly("texcoord_index", &index_t::texcoord_index)
45+
.def_readwrite("vertex_index", &index_t::vertex_index)
46+
.def_readwrite("normal_index", &index_t::normal_index)
47+
.def_readwrite("texcoord_index", &index_t::texcoord_index)
4448
;
4549

4650
// TODO(syoyo): write more bindings
@@ -57,8 +61,5 @@ PYBIND11_MODULE(tinyobj, tobj_module)
5761
py::class_<points_t>(tobj_module, "points_t")
5862
.def(py::init<>());
5963

60-
py::class_<ObjReaderConfig>(tobj_module, "ObjReaderConfig")
61-
.def(py::init<>());
62-
6364
}
6465

python/sample.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33

44
filename = "../models/cornell_box.obj";
55

6-
config = tinyobj.ObjReaderConfig()
76

87
reader = tinyobj.ObjReader()
98

10-
ret = reader.ParseFromFile(filename, config)
9+
# Load .obj(and .mtl) using default configuration
10+
ret = reader.ParseFromFile(filename)
11+
12+
# Optionally you can set custom `config`
13+
# config = tinyobj.ObjReaderConfig()
14+
# config.triangulate = False
15+
# ret = reader.ParseFromFile(filename, config)
1116

1217
if ret == False:
1318
print("Failed to load : ", filename)

tiny_obj_loader.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ class ObjReader {
415415
/// @param[in] filename wavefront .obj filename
416416
/// @param[in] config Reader configuration
417417
///
418-
bool ParseFromFile(const std::string &filename, const ObjReaderConfig &config);
418+
bool ParseFromFile(const std::string &filename, const ObjReaderConfig &config = ObjReaderConfig());
419419

420420
///
421421
/// Parse .obj from a text string.
@@ -426,7 +426,7 @@ class ObjReader {
426426
/// @param[in] mtl_text wavefront .mtl filename
427427
/// @param[in] config Reader configuration
428428
///
429-
bool ParseFromString(const std::string &obj_text, const std::string &mtl_text, const ObjReaderConfig &config);
429+
bool ParseFromString(const std::string &obj_text, const std::string &mtl_text, const ObjReaderConfig &config = ObjReaderConfig());
430430

431431
///
432432
/// .obj was loaded or parsed correctly.

0 commit comments

Comments
 (0)