tinyrenderer icon indicating copy to clipboard operation
tinyrenderer copied to clipboard

Can't Open Other OBJ Files

Open bengangllipson opened this issue 5 years ago • 2 comments

These lessons work very well for the sample OBJ files that you provide, but I'm having trouble loading in other OBJ files. I pulled a few from https://groups.csail.mit.edu/graphics/classes/6.837/F03/models/ and they either threw segmentation faults or drew the geometry completely wrong.

bengangllipson avatar Feb 25 '20 22:02 bengangllipson

I managed to figure out the problem! Model.cpp has this line of code when reading a face from an OBJ file (line starting with "f").

while (iss >> idx >> trash >> itrash >> trash >> itrash)

Meaning it expects 4 characters after each index, specifically a slash followed by a number followed by a slash followed by another number. But not all OBJ files define vt's and vn's so some define faces like this:

f 2227 2077 2049

I changed the code to do this instead:

while (iss >> idx)

and it worked, but ideally it'd be able to handle either format. Will keep looking...

bengangllipson avatar Feb 26 '20 17:02 bengangllipson

Proof that I could render those sample models: Screen Shot 2020-02-26 at 11 48 20 AM

bengangllipson avatar Feb 26 '20 17:02 bengangllipson