I have a file that defines a 3D model’s vertexes, normals, and connectivity information.
Sample:
v -2.491060 -2.491060 0.000000
v 2.491060 -2.491060 0.000000
v -2.491060 2.491060 0.000000
v 2.491060 2.491060 0.000000
vt 0.000000 0.000000
vt 1.000000 0.000000
vt 0.000000 1.000000
vt 1.000000 1.000000
f 1/1 2/2 3/3
f 3/3 2/2 4/1
Where:
v vertex coordinate (x, y, z position)
vt texture coordinate (u, v coordinate)
f polygon connectivity information with vertex and texture indices
What would be the best way to read in and store this information? A custom class / struct that has an internal array of each vertex and connectivity information? I think I’ve once before read in data in a delimited fashion with C++, but it was of the same data type, so I chucked it into a multidimensional array. Should I just use stringstreams and a custom struct / class maybe?
EDIT Disclosure, this is for my 3D Graphics class, but I’m just seeking advisement here, not a fully written project, etc.
First there’s one fact, you have to store them in dynamic arrays. As I know, wavefront doesn’t hold any information about how many vertices there are in a 3D-Obj file. Same for vertexnormals, texturecoordinates and faces.
So I would tend to read them (vertices,normals,etc.) into structs and delete them after defining your triangles. Stringstreams and custom structs sounds good to me, so you are able to use regular expressions for reading out the necessary vertex/face data.
I’m java-programmer (not too long), so sorry if I’m wrong :/
This is perhaps a little bit complicated version of my .obj loader in my project: https://github.com/Chrise55/Llama3D/blob/master/src/llama/zoo1/llgeometry/LLLoadGeometry.java
It’s java, but maybe it could help you? :/