-
Notifications
You must be signed in to change notification settings - Fork 65
Shape indexing was broken when TINYOBJ_FLAG_TRIANGULATE
flag was present.
#60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
shape.offset_index
TINYOBJ_FLAG_TRIANGULATE
flag was present.
👀 Let me give some time to review PR |
Alright, I came up with minimal reproduction sample: Expand to show the file
v -1.0 -2.0 -1.0
v 1.0 -2.0 -1.0
v -1.0 -2.0 1.0
v 1.0 -2.0 1.0
v 1.0 0.0 -1.0
v -1.0 0.0 -1.0
v 1.0 0.0 1.0
v -1.0 0.0 1.0
v 1.0 2.0 -1.0
v -1.0 2.0 -1.0
v 1.0 2.0 1.0
v -1.0 2.0 1.0
g bottom
f 2 1 3 4
g left_bottom
f 1 6 8 3
g left_top
f 6 10 12 8
g right_bottom
f 2 5 7 4
g right_bottom
f 5 9 11 7
g back
f 3 4 11 12
g front
f 1 2 9 10
g top_half1
f 9 11 10
g top_half2
f 12 11 10 Expected result from
(After triangulation there should be 16 faces in total) Actual result from
(but the number of face commands is counted instead) |
Awesome! Can I add it to regression test case? |
Already ahead of you. |
I ended up making a model with different combinations of triangles and quads to cover as many cases. |
@wendyn-projects Awesome! Thanks! I still need to figure out what
Probably current |
I figured and if I look at
What's missing is I am just trying to fix a case where you have quads in a model and put up a triangulation flag.
I can give it a try if there is a chance of getting this added, what do you think? |
This way it shows how it would be calculated even when not knowing we are working with triangles.
Good find > #2 (comment) I think it'd be better first rewrite corresponding variable names to |
I wanted to load a model I downloaded from this site.
.

If you want to try it on that model, note that some faces consist of like 16 vertices - necessitating larger value for
TINYOBJ_MAX_FACES_PER_F_LINE
.The model is suppose to look something like this:
It works when I render whole vertex buffer but when I try to render individual shapes it looks really weird:
It turned out the number of faces for each shape is counted for each face command
However the number of face commands isn't the same as number of faces after we split some into triangles.

Luckily the command also has some information about the face!
So I figured I can just calculate how many triangles the face was split into and add that instead.
Now I don't know what ½ of the variable names mean, but apparently
commands[i].num_f_num_verts
does the thing: