Skip to content

Commit 1c6dbf9

Browse files
committed
Merge branch 'master' of github.com:syoyo/tinyobjloader
2 parents 88ad575 + 5cd30b7 commit 1c6dbf9

File tree

8 files changed

+171
-60
lines changed

8 files changed

+171
-60
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ TinyObjLoader is successfully used in ...
5858
* cudabox: CUDA Solid Voxelizer Engine https://github.com/gaspardzoss/cudavox
5959
* Drake: A planning, control, and analysis toolbox for nonlinear dynamical systems https://github.com/RobotLocomotion/drake
6060
* VFPR - a Vulkan Forward Plus Renderer : https://github.com/WindyDarian/Vulkan-Forward-Plus-Renderer
61-
* Your project here!
61+
* Your project here! (Letting us know via github issue is welcome!)
6262

6363
### Old version(v0.9.x)
6464

models/issue-140-zero-face-idx.mtl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
newmtl main
2+
Kd 1 1 1

models/issue-140-zero-face-idx.obj

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
mtllib issue-140-zero-face-idx.mtl
2+
3+
v -0.5 -0.5 0
4+
v 0.5 -0.5 0
5+
v 0.5 0.5 0
6+
v -0.5 0.5 0
7+
8+
vt 0 0 0
9+
vt 1 0 0
10+
vt 1 1 0
11+
vt 0 1 0
12+
13+
vn 0 0 -1
14+
15+
usemtl main
16+
f 0/0/0 1/1/0 3/3/0
17+
f 1/1/0 3/3/0 2/2/0

models/norm-texopt.mtl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
newmtl default
2+
Ka 0 0 0
3+
Kd 0 0 0
4+
Ks 0 0 0
5+
Kt 0.1 0.2 0.3
6+
norm -bm 3 normalmap.jpg
7+

models/norm-texopt.obj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
mtllib norm-texopt.mtl
2+
o Test
3+
v 1.864151 -1.219172 -5.532511
4+
v 0.575869 -0.666304 5.896140
5+
v 0.940448 1.000000 -1.971128
6+
usemtl default
7+
f 1 2 3

python/main.cpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static PyObject* pyLoadObj(PyObject* self, PyObject* args) {
4848

4949
pyshapes = PyDict_New();
5050
pymaterials = PyDict_New();
51-
pymaterial_indices = PyDict_New();
51+
pymaterial_indices = PyList_New(0);
5252
rtndict = PyDict_New();
5353

5454
attribobj = PyDict_New();
@@ -124,53 +124,52 @@ static PyObject* pyLoadObj(PyObject* self, PyObject* args) {
124124
PyDict_SetItemString(pyshapes, (*shape).name.c_str(), meshobj);
125125
}
126126

127-
long material_index = 0;
128127
for (std::vector<tinyobj::material_t>::iterator mat = materials.begin();
129128
mat != materials.end(); mat++) {
130129
PyObject* matobj = PyDict_New();
131130
PyObject* unknown_parameter = PyDict_New();
132131

133132
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) {
136135
PyDict_SetItemString(unknown_parameter, p->first.c_str(),
137136
PyUnicode_FromString(p->second.c_str()));
138137
}
139138

140139
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));
143142
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));
146145
PyDict_SetItemString(matobj, "ambient_texname",
147-
PyUnicode_FromString((*mat).ambient_texname.c_str()));
146+
PyUnicode_FromString(mat->ambient_texname.c_str()));
148147
PyDict_SetItemString(matobj, "diffuse_texname",
149-
PyUnicode_FromString((*mat).diffuse_texname.c_str()));
148+
PyUnicode_FromString(mat->diffuse_texname.c_str()));
150149
PyDict_SetItemString(matobj, "specular_texname",
151-
PyUnicode_FromString((*mat).specular_texname.c_str()));
150+
PyUnicode_FromString(mat->specular_texname.c_str()));
152151
PyDict_SetItemString(
153152
matobj, "specular_highlight_texname",
154-
PyUnicode_FromString((*mat).specular_highlight_texname.c_str()));
153+
PyUnicode_FromString(mat->specular_highlight_texname.c_str()));
155154
PyDict_SetItemString(matobj, "bump_texname",
156-
PyUnicode_FromString((*mat).bump_texname.c_str()));
155+
PyUnicode_FromString(mat->bump_texname.c_str()));
157156
PyDict_SetItemString(
158157
matobj, "displacement_texname",
159-
PyUnicode_FromString((*mat).displacement_texname.c_str()));
158+
PyUnicode_FromString(mat->displacement_texname.c_str()));
160159
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));
164163
PyDict_SetItemString(matobj, "specular",
165-
pyTupleFromfloat3((*mat).specular));
164+
pyTupleFromfloat3(mat->specular));
166165
PyDict_SetItemString(matobj, "transmittance",
167-
pyTupleFromfloat3((*mat).transmittance));
166+
pyTupleFromfloat3(mat->transmittance));
168167
PyDict_SetItemString(matobj, "emission",
169-
pyTupleFromfloat3((*mat).emission));
168+
pyTupleFromfloat3(mat->emission));
170169
PyDict_SetItemString(matobj, "unknown_parameter", unknown_parameter);
171170

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()));
174173
}
175174

176175
PyDict_SetItemString(rtndict, "shapes", pyshapes);

tests/tester.cc

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,13 +631,14 @@ TEST_CASE("vertex-col-ext", "[Issue144]") {
631631
std::vector<tinyobj::material_t> materials;
632632

633633
std::string err;
634+
634635
bool ret = tinyobj::LoadObj(&attrib, &shapes, &materials, &err, "../models/cube-vertexcol.obj", gMtlBasePath);
635636

636637
if (!err.empty()) {
637638
std::cerr << err << std::endl;
638639
}
639640

640-
PrintInfo(attrib, shapes, materials);
641+
//PrintInfo(attrib, shapes, materials);
641642

642643
REQUIRE(true == ret);
643644
REQUIRE((8 * 3) == attrib.colors.size());
@@ -655,6 +656,41 @@ TEST_CASE("vertex-col-ext", "[Issue144]") {
655656
REQUIRE(1 == Approx(attrib.colors[3 * 7 + 0]));
656657
REQUIRE(1 == Approx(attrib.colors[3 * 7 + 1]));
657658
REQUIRE(1 == Approx(attrib.colors[3 * 7 + 2]));
659+
}
660+
661+
TEST_CASE("norm_texopts", "[norm]") {
662+
tinyobj::attrib_t attrib;
663+
std::vector<tinyobj::shape_t> shapes;
664+
std::vector<tinyobj::material_t> materials;
665+
666+
std::string err;
667+
bool ret = tinyobj::LoadObj(&attrib, &shapes, &materials, &err, "../models/norm-texopt.obj", gMtlBasePath);
668+
669+
if (!err.empty()) {
670+
std::cerr << err << std::endl;
671+
}
672+
673+
REQUIRE(true == ret);
674+
REQUIRE(1 == shapes.size());
675+
REQUIRE(1 == materials.size());
676+
REQUIRE(3.0 == Approx(materials[0].normal_texopt.bump_multiplier));
677+
678+
}
679+
680+
TEST_CASE("zero-face-idx-value", "[Issue140]") {
681+
tinyobj::attrib_t attrib;
682+
std::vector<tinyobj::shape_t> shapes;
683+
std::vector<tinyobj::material_t> materials;
684+
685+
std::string err;
686+
bool ret = tinyobj::LoadObj(&attrib, &shapes, &materials, &err, "../models/issue-140-zero-face-idx.obj", gMtlBasePath);
687+
688+
689+
if (!err.empty()) {
690+
std::cerr << err << std::endl;
691+
}
692+
REQUIRE(false == ret);
693+
REQUIRE(!err.empty());
658694

659695
}
660696

0 commit comments

Comments
 (0)