Skip to content

Commit e3508c3

Browse files
committed
Added mapping from material index to to material name (#131) to Python wrapper.
1 parent 8e7da82 commit e3508c3

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

python/main.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ PyObject* pyTupleFromfloat3(float array[3]) {
2929
extern "C" {
3030

3131
static PyObject* pyLoadObj(PyObject* self, PyObject* args) {
32-
PyObject *rtndict, *pyshapes, *pymaterials, *attribobj, *current, *meshobj;
32+
PyObject *rtndict, *pyshapes, *pymaterials, *pymaterial_indices, *attribobj, *current, *meshobj;
3333

3434
char const* current_name;
3535
char const* filename;
@@ -48,6 +48,7 @@ static PyObject* pyLoadObj(PyObject* self, PyObject* args) {
4848

4949
pyshapes = PyDict_New();
5050
pymaterials = PyDict_New();
51+
pymaterial_indices = PyDict_New();
5152
rtndict = PyDict_New();
5253

5354
attribobj = PyDict_New();
@@ -123,6 +124,7 @@ static PyObject* pyLoadObj(PyObject* self, PyObject* args) {
123124
PyDict_SetItemString(pyshapes, (*shape).name.c_str(), meshobj);
124125
}
125126

127+
long material_index = 0;
126128
for (std::vector<tinyobj::material_t>::iterator mat = materials.begin();
127129
mat != materials.end(); mat++) {
128130
PyObject* matobj = PyDict_New();
@@ -168,10 +170,12 @@ static PyObject* pyLoadObj(PyObject* self, PyObject* args) {
168170
PyDict_SetItemString(matobj, "unknown_parameter", unknown_parameter);
169171

170172
PyDict_SetItemString(pymaterials, (*mat).name.c_str(), matobj);
173+
PyDict_SetItemString(pymaterial_indices, PyLong_FromLong(material_index++), (*mat).name.c_str());
171174
}
172175

173176
PyDict_SetItemString(rtndict, "shapes", pyshapes);
174177
PyDict_SetItemString(rtndict, "materials", pymaterials);
178+
PyDict_SetItemString(rtndict, "material_indices", pymaterial_indices);
175179
PyDict_SetItemString(rtndict, "attribs", attribobj);
176180

177181
return rtndict;

0 commit comments

Comments
 (0)