Skip to content

Commit dc137fd

Browse files
author
wendyn-projects
committed
I added test for checking shape offsets after triangulation.
1 parent 0feb2e0 commit dc137fd

File tree

4 files changed

+99
-0
lines changed

4 files changed

+99
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# OBJ File: 'house'
2+
# by WENDYN
3+
4+
o house
5+
v -1.0000 0.0000 -1.0000
6+
v 1.0000 0.0000 -1.0000
7+
v 1.0000 0.0000 1.0000
8+
v -1.0000 0.0000 1.0000
9+
v -1.0000 1.0000 -1.0000
10+
v 1.0000 1.0000 -1.0000
11+
v 1.0000 1.0000 1.0000
12+
v -1.0000 1.0000 1.0000
13+
v 0.0000 2.0000 -1.0000
14+
v 0.0000 2.0000 1.0000
15+
16+
vn 0.0000 -1.0000 0.0000
17+
vn 0.0000 0.0000 -1.0000
18+
vn -1.0000 0.0000 0.0000
19+
vn 0.0000 0.0000 1.0000
20+
vn 1.0000 0.0000 0.0000
21+
vn 0.0000 1.0000 0.0000
22+
vn -0.7071 0.7071 0.0000
23+
vn 0.7071 0.7071 0.0000
24+
25+
s off
26+
g base
27+
f 1//1 2//1 3//1 4//1
28+
29+
g facade
30+
f 1//2 2//2 6//2 5//2
31+
f 5//2 6//2 9//2
32+
33+
g left_wall
34+
f 4//3 1//3 5//3 8//3
35+
36+
g back_wall
37+
f 3//4 4//4 8//4 7//4
38+
39+
g back_roof_wall
40+
f 7//4 8//4 10//4
41+
42+
g right_wall
43+
f 2//5 3//5 7//5 6//5
44+
45+
g floor
46+
f 5//6 6//6 7//6
47+
f 5//6 7//6 8//6
48+
49+
g left_roof
50+
f 8//7 5//7 9//7 10//7
51+
52+
g right_roof
53+
f 6//8 7//8 10//8 9//8
54+
55+
# TODO: Remove extra content at the end of the file when
56+
# https://github.com/syoyo/tinyobjloader-c/issues/12 is fixed

test/tinyobj_regression_tests.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,44 @@ void test_tinyobj_negative_exponent(void)
8383
TEST_CHECK(float_equals(attrib.vertices[2], 2.0e-0f));
8484
}
8585
}
86+
87+
void test_tinyobj_shapes_triangulation(void)
88+
{
89+
{
90+
const char * filename = "fixtures/shapes-triangulation.obj";
91+
92+
tinyobj_shape_t * shape = NULL;
93+
tinyobj_material_t * material = NULL;
94+
tinyobj_attrib_t attrib;
95+
96+
unsigned long num_shapes;
97+
unsigned long num_materials;
98+
99+
tinyobj_attrib_init(&attrib);
100+
101+
int result = tinyobj_parse_obj(&attrib, &shape, &num_shapes, &material, &num_materials, filename, loadFile, NULL, TINYOBJ_FLAG_TRIANGULATE);
102+
103+
TEST_CHECK(result == TINYOBJ_SUCCESS);
104+
105+
TEST_CHECK(num_shapes == 9);
106+
107+
TEST_CHECK(shape[0].face_offset == 0);
108+
TEST_CHECK(shape[0].length == 2);
109+
TEST_CHECK(shape[1].face_offset == 2);
110+
TEST_CHECK(shape[1].length == 3);
111+
TEST_CHECK(shape[2].face_offset == 5);
112+
TEST_CHECK(shape[2].length == 2);
113+
TEST_CHECK(shape[3].face_offset == 7);
114+
TEST_CHECK(shape[3].length == 2);
115+
TEST_CHECK(shape[4].face_offset == 9);
116+
TEST_CHECK(shape[4].length == 1);
117+
TEST_CHECK(shape[5].face_offset == 10);
118+
TEST_CHECK(shape[5].length == 2);
119+
TEST_CHECK(shape[6].face_offset == 12);
120+
TEST_CHECK(shape[6].length == 2);
121+
TEST_CHECK(shape[7].face_offset == 14);
122+
TEST_CHECK(shape[7].length == 2);
123+
TEST_CHECK(shape[8].face_offset == 16);
124+
TEST_CHECK(shape[8].length == 2);
125+
}
126+
}

test/tinyobj_regression_tests.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33

44
void test_tinyobj_crlf_string(void);
55
void test_tinyobj_negative_exponent(void);
6+
void test_tinyobj_shapes_triangulation(void);
67

78
#endif

test/tinyobj_tests.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ TEST_LIST = {
3434

3535
{ "crlf_string", test_tinyobj_crlf_string },
3636
{ "negative_exponent_issue26", test_tinyobj_negative_exponent },
37+
{ "shapes_triangulation", test_tinyobj_shapes_triangulation },
3738

3839
{ 0 } // required by acutest
3940
};

0 commit comments

Comments
 (0)