Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling .obj files: Why is it possible to have more vertextextures (vt) than vertices (v)?

Tags:

wavefront

.obj

I am working on a .obj handler in c++. Importing the data shouldn't be a Problem, but i do not understand why it is possible, that a .obj (e.g. exported from blender) has more 'vt' entries than 'v' entires. If someone could explain me that, i would be very happy!

Thanks!

like image 480
Chrizzldi Avatar asked Jan 05 '15 10:01

Chrizzldi


People also ask

What does Vt mean in OBJ file?

vt is the reference number for a texture vertex in the face element. It always follows the first slash. vn is an optional argument. vn is the reference number for a vertex normal in the face element. It must always follow the second slash.

Does OBJ contain vertex color?

Vertex colors are not part of the original OBJ file format specification.

How do .OBJ files work?

An OBJ file (. obj) contains information about the geometry of 3D objects. The files are used for exchanging information, CAD, and 3D printing. OBJ files can support unlimited colors, and one file can define multiple objects.

How do I read .OBJ files?

Just install the software OBJ Viewer To begin viewing 3D files, simply do the following Install the extension OBJ Viewer Click on the extension icon Choose the 3D file you wish to open Begin viewing your 3D files online today! This 3D viewer works for both STL and OBJ file formats.


2 Answers

The number of position, normal and texture coordinates may be different because two vertices may share a coordinate in one space but differ in another.

Think of a box (8 verts) using 6 different rectangular shapes (one per face) in texture space -> that's 6*4=24 texture coordinates.

Edit: A common uv-map for a box looks like below (14 texture coordinates). I've annotated three different vertices: A, B and C. Note that in a box every vertex is adjacent to three faces which has to be true in the uv-map also. C gets a texture coordinate which is adjacent to three faces, but B has to be duplicated and A tripled to do so.

Box-uv

like image 96
BeyelerStudios Avatar answered Nov 07 '22 15:11

BeyelerStudios


I found the source of the problem. I had prematurely optimized my program, and didn't realize that texture coordinates could be of a larger quantity than vertex coordinates due to the fact that textures are mapped per face rather than per vertex, so each vertex could have many texture coordinates mapped to it. Hopefully someone will learn from my mistakes.

Something I found strange though was initializing an sf::RenderWindow prior to running my .obj parser resulted in no error messages being thrown and the crash to be reported in a completely different area than it was actually happening.

like image 43
David Hartman Avatar answered Nov 07 '22 13:11

David Hartman