Loading models with vertex normals, but no face normals

Here you can talk about anything related to Visualization Library, 3D graphics, visualization techniques, ask for help or advices, suggest new features, report and track bugs etc.

Loading models with vertex normals, but no face normals

Postby salvorhardin » Tue Jul 27, 2010 11:52 am

Hi,

I love VL, especially the IO design, so I hope I can get past the only remaining roadblock to using it.

I'm trying to load and display wavefront .OBJ files. The .OBJ files contain vertex normals (vn) but the face (f) entries are missing face normals.

In VL, the vertex normals do not seem to have any effect if the face normals are missing in .OBJ files.

In ASSIMP viewer, the vertex normals appear to make models look very nice, even if the face normals are missing. If I remove vn from .OBJ, then ASSIMP viewer renders like "hard normals".

I'm required to render and print .OBJ files containing vn but missing face normals. What is the best approach using VL? I'm new to OpenGL and VL, so any advice would be helpful.

I've attached a comparison screenshot and a .OBJ file with missing face normals.
Attachments
comparison.png
Comparison screenshot of tor_nfn.obj rendered in VL and ASSIMP
comparison.png (93.17 KiB) Viewed 82 times
tor_nfn.zip
OBJ with vertex normals but no face normals
(929 Bytes) Downloaded 16 times
salvorhardin
 
Posts: 17
Joined: Tue Jul 27, 2010 9:49 am

Re: Loading models with vertex normals, but no face normals

Postby Michele » Wed Jul 28, 2010 3:56 am

To me it looks like the file format of the given .obj file is not correct, as no normal index is specified in the face data, I think the face data should look like:

f 1//1 4//2 3//3 2//4
f 17//5 15//6 16//7 18//8
f 7//9 1//10 2//11 8//12
...
instead of

f 1 4 3 2
f 17 15 16 18
f 7 1 2 8
...
in this case VL assumes there are no normals so they get recomputed by VL at loading time, producing the hard normals visible in the picture.

You should modify your exporter (or post-process the .obj file) to produce a correct output or write a custom OBJ loader for VL based on the existing one (should not be too difficult, just put some extra logic in the existing one).

VL seems to be stricter than ASSIMP. VL does not make any assumption on the data layout and just sticks to what the face info says even if in this case (for a human) is quite obvious that the normal count equals the face-vertex count.

You might want to preprocess the OBJ file before feeding it to VL, for example by loading the OBJ file, adding the face data, writing the resulting OBJ data into a MemoryFile and then feeding this new MemoryFile to the VL loader. The beauty of this approach is that it allows you to do everything in memory (if memory consumption is not an issue) and use the existing vlOBJ loader. Of course you would need to do a basic parsing of the OBJ file on your own but this shouldn't be too difficult either given the tools present in VL (vl::String, file handling, vl::TextStream etc.). If this option is not viable for some reason you'll have to make your customized OBJ loader as said before.

Cheers,

Michele
Michele
Site Admin
 
Posts: 101
Joined: Tue Apr 14, 2009 3:40 pm

Re: Loading models with vertex normals, but no face normals

Postby salvorhardin » Wed Jul 28, 2010 5:15 am

Thanks! I like your idea of using preprocessing.

I literally started programming 3D this week and OpenGL for just a few days. So I hope my questions aren't too naive or crazy.

I'm wondering if normals for face (f) data in .OBJ can be "filled-in" automatically if the vn exactly corresponds to v, like this:

f 1//1 4//4 3//3 2//2

In other words, using v1//vn1, v2//vn2, etc. so numbers on each side of // are always equal. Is this idea crazy or worth investigating?

I have some questions about Geometry::computeNormals() which I'll defer to a new thread.

Thanks again!
salvorhardin
 
Posts: 17
Joined: Tue Jul 27, 2010 9:49 am

Re: Loading models with vertex normals, but no face normals

Postby Michele » Fri Jul 30, 2010 3:55 am

Yes, except that the number of vertices and the number of normals do not match if you look at your obj file. It looks like the vertex index should remain the same as it is now, while the normal index should simply progress from 1 to n as shown in the example in my previous post.

Mic

PS.
See also http://en.wikipedia.org/wiki/Obj for more info on the .OBJ file format.
Michele
Site Admin
 
Posts: 101
Joined: Tue Apr 14, 2009 3:40 pm


Return to Visualization Library General Forum

Who is online

Users browsing this forum: No registered users and 1 guest