PDA

View Full Version : How do I use smoothing groups from .obj files?



starwarsmace
02-17-2015, 10:09 PM
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. :) Thank you in advance.

__bob__
02-18-2015, 07:21 AM
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.

starwarsmace
02-18-2015, 03:32 PM
May be your talking about normal smoothing?


Good obj loader like assimp can do yhis for you.

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

1631
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?

GClements
02-18-2015, 05:02 PM
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. :)

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).

starwarsmace
02-18-2015, 05:59 PM
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).

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

starwarsmace
02-19-2015, 07:55 PM
Anyone know about this?

starwarsmace
02-20-2015, 09:31 PM
I really need this! Im sure someone knows...

Alfonse Reinheart
02-20-2015, 10:14 PM
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?

starwarsmace
02-21-2015, 04:35 PM
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?

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

Alfonse Reinheart
02-21-2015, 04:41 PM
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.

NecroTheif
02-26-2015, 03:07 PM
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).

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?

NecroTheif
02-26-2015, 03:24 PM
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?

GClements
02-26-2015, 04:55 PM
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?
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.


So would the faces under both "s 2" groups be done together?
Yes. They're all in smoothing group #2.


And why is there an "s off" Is it just it's own smoothing group?
"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.