@@ -48,7 +48,7 @@ static PyObject* pyLoadObj(PyObject* self, PyObject* args) { |
48 | 48 |
|
49 | 49 | pyshapes = PyDict_New(); |
50 | 50 | pymaterials = PyDict_New(); |
51 | | - pymaterial_indices = PyDict_New(); |
| 51 | + pymaterial_indices = PyList_New(0); |
52 | 52 | rtndict = PyDict_New(); |
53 | 53 |
|
54 | 54 | attribobj = PyDict_New(); |
@@ -124,53 +124,52 @@ static PyObject* pyLoadObj(PyObject* self, PyObject* args) { |
124 | 124 | PyDict_SetItemString(pyshapes, (*shape).name.c_str(), meshobj); |
125 | 125 | } |
126 | 126 |
|
127 | | - long material_index = 0; |
128 | 127 | for (std::vector<tinyobj::material_t>::iterator mat = materials.begin(); |
129 | 128 | mat != materials.end(); mat++) { |
130 | 129 | PyObject* matobj = PyDict_New(); |
131 | 130 | PyObject* unknown_parameter = PyDict_New(); |
132 | 131 |
|
133 | 132 | for (std::map<std::string, std::string>::iterator p = |
134 | | - (*mat).unknown_parameter.begin(); |
135 | | - p != (*mat).unknown_parameter.end(); ++p) { |
| 133 | + mat->unknown_parameter.begin(); |
| 134 | + p != mat->unknown_parameter.end(); ++p) { |
136 | 135 | PyDict_SetItemString(unknown_parameter, p->first.c_str(), |
137 | 136 | PyUnicode_FromString(p->second.c_str())); |
138 | 137 | } |
139 | 138 |
|
140 | 139 | PyDict_SetItemString(matobj, "shininess", |
141 | | - PyFloat_FromDouble((*mat).shininess)); |
142 | | - PyDict_SetItemString(matobj, "ior", PyFloat_FromDouble((*mat).ior)); |
| 140 | + PyFloat_FromDouble(mat->shininess)); |
| 141 | + PyDict_SetItemString(matobj, "ior", PyFloat_FromDouble(mat->ior)); |
143 | 142 | PyDict_SetItemString(matobj, "dissolve", |
144 | | - PyFloat_FromDouble((*mat).dissolve)); |
145 | | - PyDict_SetItemString(matobj, "illum", PyLong_FromLong((*mat).illum)); |
| 143 | + PyFloat_FromDouble(mat->dissolve)); |
| 144 | + PyDict_SetItemString(matobj, "illum", PyLong_FromLong(mat->illum)); |
146 | 145 | PyDict_SetItemString(matobj, "ambient_texname", |
147 | | - PyUnicode_FromString((*mat).ambient_texname.c_str())); |
| 146 | + PyUnicode_FromString(mat->ambient_texname.c_str())); |
148 | 147 | PyDict_SetItemString(matobj, "diffuse_texname", |
149 | | - PyUnicode_FromString((*mat).diffuse_texname.c_str())); |
| 148 | + PyUnicode_FromString(mat->diffuse_texname.c_str())); |
150 | 149 | PyDict_SetItemString(matobj, "specular_texname", |
151 | | - PyUnicode_FromString((*mat).specular_texname.c_str())); |
| 150 | + PyUnicode_FromString(mat->specular_texname.c_str())); |
152 | 151 | PyDict_SetItemString( |
153 | 152 | matobj, "specular_highlight_texname", |
154 | | - PyUnicode_FromString((*mat).specular_highlight_texname.c_str())); |
| 153 | + PyUnicode_FromString(mat->specular_highlight_texname.c_str())); |
155 | 154 | PyDict_SetItemString(matobj, "bump_texname", |
156 | | - PyUnicode_FromString((*mat).bump_texname.c_str())); |
| 155 | + PyUnicode_FromString(mat->bump_texname.c_str())); |
157 | 156 | PyDict_SetItemString( |
158 | 157 | matobj, "displacement_texname", |
159 | | - PyUnicode_FromString((*mat).displacement_texname.c_str())); |
| 158 | + PyUnicode_FromString(mat->displacement_texname.c_str())); |
160 | 159 | PyDict_SetItemString(matobj, "alpha_texname", |
161 | | - PyUnicode_FromString((*mat).alpha_texname.c_str())); |
162 | | - PyDict_SetItemString(matobj, "ambient", pyTupleFromfloat3((*mat).ambient)); |
163 | | - PyDict_SetItemString(matobj, "diffuse", pyTupleFromfloat3((*mat).diffuse)); |
| 160 | + PyUnicode_FromString(mat->alpha_texname.c_str())); |
| 161 | + PyDict_SetItemString(matobj, "ambient", pyTupleFromfloat3(mat->ambient)); |
| 162 | + PyDict_SetItemString(matobj, "diffuse", pyTupleFromfloat3(mat->diffuse)); |
164 | 163 | PyDict_SetItemString(matobj, "specular", |
165 | | - pyTupleFromfloat3((*mat).specular)); |
| 164 | + pyTupleFromfloat3(mat->specular)); |
166 | 165 | PyDict_SetItemString(matobj, "transmittance", |
167 | | - pyTupleFromfloat3((*mat).transmittance)); |
| 166 | + pyTupleFromfloat3(mat->transmittance)); |
168 | 167 | PyDict_SetItemString(matobj, "emission", |
169 | | - pyTupleFromfloat3((*mat).emission)); |
| 168 | + pyTupleFromfloat3(mat->emission)); |
170 | 169 | PyDict_SetItemString(matobj, "unknown_parameter", unknown_parameter); |
171 | 170 |
|
172 | | - PyDict_SetItemString(pymaterials, (*mat).name.c_str(), matobj); |
173 | | - PyDict_SetItemString(pymaterial_indices, PyLong_FromLong(material_index++), (*mat).name.c_str()); |
| 171 | + PyDict_SetItemString(pymaterials, mat->name.c_str(), matobj); |
| 172 | + PyList_Append(pymaterial_indices, PyUnicode_FromString(mat->name.c_str())); |
174 | 173 | } |
175 | 174 |
|
176 | 175 | PyDict_SetItemString(rtndict, "shapes", pyshapes); |
|