Open syoyo opened 5 years ago
Maybe num_face_verts
or num_verts_per_face
. I agree as it is now it is confusing.
Currently,
num_face = the number of
f
lines num_face_num_verts = length of face_num_verts.
Are you sure about this?
For example, a cube regularly will have num_faces=24, <6 faces>*<1 square per face>*<4 vertexes per square>*
And the same cube will triangulation will have num_faces=36, <6 faces>*<2 triangles per face>*<3 vertexes per triangle>
In this example I have 6 "f lines" but my num_faces comes out to 24 and 36 respectively:
#define TINYOBJ_LOADER_C_IMPLEMENTATION
#include "tinyobj_loader_c.h"
//A box in .obj format. Made in blender, removed .mtl
#define box "\
# Blender v2.77 (sub 0) OBJ File: ''\n\
# www.blender.org\n\
o Cube\n\
v 8.000000 -8.000000 -8.000000\n\
v 8.000000 -8.000000 8.000000\n\
v -8.000000 -8.000000 8.000000\n\
v -8.000000 -8.000000 -8.000000\n\
v 8.000000 8.000000 -8.000000\n\
v 8.000000 8.000000 8.000000\n\
v -8.000000 8.000000 8.000000\n\
v -8.000000 8.000000 -8.000000\n\
vn 0.0000 -1.0000 0.0000\n\
vn 0.0000 1.0000 0.0000\n\
vn 1.0000 0.0000 0.0000\n\
vn -0.0000 -0.0000 1.0000\n\
vn -1.0000 -0.0000 -0.0000\n\
vn 0.0000 0.0000 -1.0000\n\
usemtl Material\n\
s off\n\
f 1//1 2//1 3//1 4//1\n\
f 5//2 8//2 7//2 6//2\n\
f 1//3 5//3 6//3 2//3\n\
f 2//4 6//4 7//4 3//4\n\
f 3//5 7//5 8//5 4//5\n\
f 5//6 1//6 4//6 8//6\n\
"
int main(int argv, char** argc){
size_t box_size = strlen(box);
tinyobj_attrib_t attrib1, attrib2;
tinyobj_attrib_init(&attrib1);
tinyobj_attrib_init(&attrib2);
tinyobj_shape_t *shape1, *shape2;
tinyobj_material_t *material1, *material2;
size_t num_shapes1, num_materials1, num_shapes2, num_materials2;
int err1 = tinyobj_parse_obj(&attrib1, &shape1, &num_shapes1, &material1, &num_materials1, box, box_size, 0);
int err2 = tinyobj_parse_obj(&attrib2, &shape2, &num_shapes2, &material2, &num_materials2, box, box_size, TINYOBJ_FLAG_TRIANGULATE);
if(err1 != TINYOBJ_SUCCESS || err2 != TINYOBJ_SUCCESS){
printf("Failed to load object\n");
exit(-1);
}
printf("attrib1.num_faces: %u\n",attrib1.num_faces);
printf("attrib1.num_face_num_verts: %u\n", attrib1.num_face_num_verts);
printf("attrib1.num_vertices: %u\n",attrib1.num_vertices);
printf("attrib2.num_faces: %u\n",attrib2.num_faces);
printf("attrib2.num_face_num_verts: %u\n", attrib2.num_face_num_verts);
printf("attrib2.num_vertices: %u\n",attrib2.num_vertices);
return 0;
}
attrib1.num_faces: 24
attrib1.num_face_num_verts: 6
attrib1.num_vertices: 8
attrib2.num_faces: 36
attrib2.num_face_num_verts: 12
attrib2.num_vertices: 8
Are you sure about this?
Oh, yes, triangulation will change the situation. I have to modify a comment.
Also, as you know, for a triangulated mesh all faces have 3 vertices(triangles), so num_face_num_verts * 3
matches with num_faces
We need to choose more better name for these variables.
Currently,
num_face = the number of
f
lines num_face_num_verts = length of face_num_verts.Each face_num_verts contains the number of vertices of a primitive(face). (e.g. 3(triangle), 4(quads))
If we dont triangulate face(primitive), num_face == num_face_num_verts.