|
Teapot
Feb 20, 2021 17:24:14 GMT
Post by linuxdeveloper on Feb 20, 2021 17:24:14 GMT
I am trying to render the teapot, but I have realized that the teapot file does not have normal faces as expected by the book. For example here is one of the faces: f 1/1/1 2/2/2 3/3/3 4/4/4 I would expect this to be in the format: f 1 2 3 Did the teapot file change recently? Where can I get the file referenced in the book using the obj format of the book? The file I downloaded was the low-resolution teapot file from: graphics.cs.utah.edu/courses/cs6620/fall2013/?prj=5
|
|
cmo
New Member
Posts: 6
|
Teapot
Feb 20, 2021 20:56:00 GMT
Post by cmo on Feb 20, 2021 20:56:00 GMT
I had the same thoughts when I downloaded that file! Look at page 224 in the book //Faces with Normal Vectors// for more info on the other fields. Assuming you split the file up by whitespace, you could use a regular expression to return just the first number of the slash dilmenated triplet. Or split again on slashes. Or however you're choosing to parse the file
|
|
|
Teapot
Feb 21, 2021 9:17:59 GMT
Post by linuxdeveloper on Feb 21, 2021 9:17:59 GMT
That makes sense.
I am also pretty sure there is an error in the psuedo code on page 216 for the method fan_triangulation(vertices).
He uses vertices[1] and vertices[index and vertices[index+1] to reference the indexes used in the line, for example
f 4 6 8 10
However, he never references back to the original vertices list to get the actual vertices, for example
f v[4] v[6] v[8] f v[4] v[8] b[10]
I believe you need to pass in both the vertices of the face, plus all the vertices collected earlier on such as:
v 1 2 3 v 2 3 4 v 3 4 5 v 4 5 6 <- 4 v 5 6 7 v 6 7 8 <- 6 v 7 8 9 v 8 9 10 <- 8 v 9 10 11 v 10 11 12 <- 10
Am I missing something or is this psuedo code wrong?
|
|
cmo
New Member
Posts: 6
|
Teapot
Feb 21, 2021 22:51:21 GMT
Post by cmo on Feb 21, 2021 22:51:21 GMT
Hmmmm... I think in the psuedo code on page 216 is about the fan triangulation algorithm in a general sense.
You are right though, when parsing polygons from the obj file you have to refer back to the vertices from the file.
It is a little tricky b/c obj files are starting index 1 based, but otherwise not too bad.
|
|
|
Teapot
Feb 27, 2021 19:10:13 GMT
Post by inventordave on Feb 27, 2021 19:10:13 GMT
You need to parse the file as a whole, storing each data section of the file, perhaps in it's own array object (different sections of the file provide different normal/mapping data, on top of the section that defines the triangles in the form of x,y,z tuples), then as I remember, simply use the 1st ref in each n/n/n tuple as an ordinal map to the equiv triangle in the section of the .obj file that defines the x,y,z for each triangle (I assume you store in an array, so remember to -1 from the value to get the array indice, if you didn't think to make array[1] the first storage offset). The 2nd and 3rd values in the n/n/n tuples are for more advanced features, such as mapping textures referenced in the .obj file to the teapot mesh upon rendering. You probably figured it out, but I thought I'd say anyway.
|
|