How do I use smoothing groups from .obj files?

So I need to get smoothing groups from a .obj and somehow smooth it(not really sure what means. Is it that the edges are together?) Would I have to parse the .obj file and smooth it with opengl code or is there some built in function. I am using the opengl that comes with minecraftforge(GL11). I am a beginner with opengl so I might not get all the terms. :slight_smile: Thank you in advance.

May be your talking about normal smoothing?
http://www.theappguruz.com/wp-content/uploads/2015/01/smooth_or_sharp.png

Good obj loader like assimp can do yhis for you.

[QUOTE=bob;1264420]May be your talking about normal smoothing?

Good obj loader like assimp can do yhis for you.[/QUOTE]

minecraftforge has a .obj loader.(not sure whether it is good or not)

[ATTACH]904[/ATTACH]
That code came from the minecraftforge wavefront loader. Does that already smooth it? If not, is it possible I could use it to make my own?

Smoothing groups are an alternative to providing explicit vertex normals. If a polygon’s vertices include normal references, those supersede any smoothing group.

Generating vertex normals usually involves calculating face normals for each face, then calculating a normal for each vertex as the average of the face normals of all of the faces which use that vertex.

When smoothing groups are used, this process is performed separately for each smoothing group. So if a vertex is used by faces in multiple smoothing groups, there will be multiple normals associated with it. Each normal is calculated as the average of the face normals for all of the associated faces in a specific group.

The end result is that where the faces on either side of an edge belong to different smoothing groups, the faces will use different normals for the same vertex, meaning that the edge will appear as a sharp corner (i.e. there will be a discontinuity in the lighting).

[QUOTE=GClements;1264445]Smoothing groups are an alternative to providing explicit vertex normals. If a polygon’s vertices include normal references, those supersede any smoothing group.

Generating vertex normals usually involves calculating face normals for each face, then calculating a normal for each vertex as the average of the face normals of all of the faces which use that vertex.

When smoothing groups are used, this process is performed separately for each smoothing group. So if a vertex is used by faces in multiple smoothing groups, there will be multiple normals associated with it. Each normal is calculated as the average of the face normals for all of the associated faces in a specific group.

The end result is that where the faces on either side of an edge belong to different smoothing groups, the faces will use different normals for the same vertex, meaning that the edge will appear as a sharp corner (i.e. there will be a discontinuity in the lighting).[/QUOTE]

Thank you for the explanation but how would I do this?

Anyone know about this?

I really need this! Im sure someone knows…

Anyone know about what? GCelements just explained what you need to do. You didn’t explain what part of that you didn’t understand, so it’s rather hard to know what to help you with.

Or do you just want someone to write source code for you?

[QUOTE=Alfonse Reinheart;1264488]Anyone know about what? GCelements just explained what you need to do. You didn’t explain what part of that you didn’t understand, so it’s rather hard to know what to help you with.

Or do you just want someone to write source code for you?[/QUOTE]

How would I make it so the faces will use different normals for the same vertex?

Because the same vertex isn’t the same if it has two normals on it.

A vertex is a unique combination of different attributes, including things like positions, colors, normals, etc. If a position is used with two normals, then that’s really two vertices that happen to use the same position.

[QUOTE=GClements;1264445]
Smoothing groups are an alternative to providing explicit vertex normals. If a polygon’s vertices include normal references, those supersede any smoothing group.

Generating vertex normals usually involves calculating face normals for each face, then calculating a normal for each vertex as the average of the face normals of all of the faces which use that vertex.

When smoothing groups are used, this process is performed separately for each smoothing group. So if a vertex is used by faces in multiple smoothing groups, there will be multiple normals associated with it. Each normal is calculated as the average of the face normals for all of the associated faces in a specific group.

The end result is that where the faces on either side of an edge belong to different smoothing groups, the faces will use different normals for the same vertex, meaning that the edge will appear as a sharp corner (i.e. there will be a discontinuity in the lighting).[/QUOTE]

So let me make sure i’m getting this right. For each smoothing group you would calculate the normals of each face, and then you would add each vertex when the normal of each vertex is the average of the normals of the faces in the smoothing group? And then you would do that for each smoothing group? Add each vertex multiple times?

Also the labels in the obj file are like:
s 2

faces

s 4

faces

s 2

faces

s off

faces

So would the faces under both “s 2” groups be done together? And why is there an “s off” Is it just it’s own smoothing group?

Well, you’d probably perform the calculations as-needed, rather than processing all vertices and faces for each smoothing group. A given face only has a single normal, a vertex has one normal for each smoothing group, regardless of how many faces in that group refer to it.

Essentially, the vertex normal for a specific vertex ID and smoothing group ID is the normalised average of the face normals for all faces in that smoothing group which reference that vertex ID. Typically, you average the un-normalised face normals, so that larger faces are given more weight in the calculation.

Yes. They’re all in smoothing group #2.

“s off” or “s 0” disable smoothing; the effect is as if each face is in a separate smoothing group, i.e. all of its vertices use the face normal, resulting in a faceted appearance. This is useful for faces which are actual flat faces rather than approximating a portion of a smooth surface.