Skip to content

Commit dcad3e6

Browse files
committed
Add per-face smoothing groupd ids to mesh_t.
Add unit test for smoothing groups.
1 parent 2dfc37a commit dcad3e6

File tree

4 files changed

+330
-201
lines changed

4 files changed

+330
-201
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
newmtl test1
2+
Ns 10.0000
3+
Ni 1.5000
4+
d 1.0000
5+
Tr 0.0000
6+
Tf 1.0000 1.0000 1.0000
7+
illum 2
8+
Ka 0.0000 0.0000 0.0000
9+
Kd 0.5 0.2 0.2
10+
Ks 0.0000 0.0000 0.0000
11+
Ke 0.0000 0.0000 0.0000
12+
13+
newmtl test2
14+
Ns 10.0000
15+
Ni 1.5000
16+
d 1.0000
17+
Tr 0.0000
18+
Tf 1.0000 1.0000 1.0000
19+
illum 2
20+
Ka 0.0000 0.0000 0.0000
21+
Kd 0.2 0.5 0.2
22+
Ks 0.0000 0.0000 0.0000
23+
Ke 0.0000 0.0000 0.0000
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
# cube.obj
3+
#
4+
5+
mtllib issue-162-smoothing-group.mtl
6+
7+
v -0.500000 -0.500000 0.500000
8+
v 0.500000 -0.500000 0.500000
9+
v -0.500000 0.500000 0.500000
10+
v 0.500000 0.500000 0.500000
11+
v -0.500000 0.500000 -0.500000
12+
v 0.500000 0.500000 -0.500000
13+
v -0.500000 -0.500000 -0.500000
14+
v 0.500000 -0.500000 -0.500000
15+
16+
vt 0.000000 0.000000
17+
vt 1.000000 0.000000
18+
vt 0.000000 1.000000
19+
vt 1.000000 1.000000
20+
21+
vn 0.000000 0.000000 1.000000
22+
vn 0.000000 1.000000 0.000000
23+
vn 0.000000 0.000000 -1.000000
24+
vn 0.000000 -1.000000 0.000000
25+
vn 1.000000 0.000000 0.000000
26+
vn -1.000000 0.000000 0.000000
27+
28+
usemtl test1
29+
g test1
30+
s 1
31+
f 1/1/1 2/2/1 3/3/1
32+
f 3/3/1 2/2/1 4/4/1
33+
34+
usemtl test2
35+
g test2
36+
37+
s off
38+
f 3/1/2 4/2/2 5/3/2
39+
f 5/3/2 4/2/2 6/4/2
40+
s 3
41+
f 5/4/3 6/3/3 7/2/3
42+
f 7/2/3 6/3/3 8/1/3
43+
s 4
44+
f 7/1/4 8/2/4 1/3/4
45+
f 1/3/4 8/2/4 2/4/4
46+
s 0
47+
f 2/1/5 8/2/5 4/3/5
48+
f 4/3/5 8/2/5 6/4/5
49+
s 6
50+
f 7/1/6 1/2/6 5/3/6
51+
f 5/3/6 1/2/6 3/4/6

tests/tester.cc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,40 @@ TEST_CASE("texture-name-whitespace", "[Issue145]") {
717717

718718
}
719719

720+
TEST_CASE("smoothing-group", "[Issue162]") {
721+
tinyobj::attrib_t attrib;
722+
std::vector<tinyobj::shape_t> shapes;
723+
std::vector<tinyobj::material_t> materials;
724+
725+
std::string err;
726+
bool ret = tinyobj::LoadObj(&attrib, &shapes, &materials, &err, "../models/issue-162-smoothing-group.obj", gMtlBasePath);
727+
728+
729+
if (!err.empty()) {
730+
std::cerr << "[Issue162] " << err << std::endl;
731+
}
732+
733+
REQUIRE(true == ret);
734+
REQUIRE(2 == shapes.size());
735+
736+
REQUIRE(2 == shapes[0].mesh.smoothing_group_ids.size());
737+
REQUIRE(1 == shapes[0].mesh.smoothing_group_ids[0]);
738+
REQUIRE(1 == shapes[0].mesh.smoothing_group_ids[1]);
739+
740+
REQUIRE(10 == shapes[1].mesh.smoothing_group_ids.size());
741+
REQUIRE(0 == shapes[1].mesh.smoothing_group_ids[0]);
742+
REQUIRE(0 == shapes[1].mesh.smoothing_group_ids[1]);
743+
REQUIRE(3 == shapes[1].mesh.smoothing_group_ids[2]);
744+
REQUIRE(3 == shapes[1].mesh.smoothing_group_ids[3]);
745+
REQUIRE(4 == shapes[1].mesh.smoothing_group_ids[4]);
746+
REQUIRE(4 == shapes[1].mesh.smoothing_group_ids[5]);
747+
REQUIRE(0 == shapes[1].mesh.smoothing_group_ids[6]);
748+
REQUIRE(0 == shapes[1].mesh.smoothing_group_ids[7]);
749+
REQUIRE(6 == shapes[1].mesh.smoothing_group_ids[8]);
750+
REQUIRE(6 == shapes[1].mesh.smoothing_group_ids[9]);
751+
752+
}
753+
720754
#if 0
721755
int
722756
main(

0 commit comments

Comments
 (0)