Sign in to follow this  
Caesar

3ds and face cw/ccw

Recommended Posts

Caesar    126
hi how do I learn whether the vertices in a face in a 3ds file are in CW or CCW order? I know there's a faceflag for each flag, but don't think that's what I'm looking for (I enable back face culling to see whether the object is CW or CCW, but they all have the flag set to 7 (decimal). Any idea where to look? (I'm looking at lib3ds now, but haven't found it yet)

Share this post


Link to post
Share on other sites
Damocles    133
Unless you specifically tell 3DS to reverse the facing of a tile (flip the normal)then they will all be the same direction, and so for the entire mesh you can decide if you need to cull the back or front (usually the back). Lib3ds will load them in the same way they are saved out from 3DS, so it will preserve the direction too.

If needs be, then there is a way of telling if a triangle is cw or ccw. Something to do with computing the area of the triangle I think, but I can't remember off hand.

Share this post


Link to post
Share on other sites
Yann L    1802
Quote:
Original post by Damocles
If needs be, then there is a way of telling if a triangle is cw or ccw. Something to do with computing the area of the triangle I think, but I can't remember off hand.

This is from the top of my head:

// A, B, C are the three triangle vertex positions in 3D space
// N is the (normalized) face normal
// If s < 0 then CCW, if s > 0 then CW (or the other way round, depends on your coordsys
// If s == 0 then the face is degenerated

float s = dot(N, cross(A, B) + cross(B, C) + cross(C, A));


Share this post


Link to post
Share on other sites
Caesar    126
Oh, I see. The problem is I'm loading files I've downloaded from the internet and some have the vertex order messed up (CW instead of CCW) (I compute the normals myself instead of loading them). Also, I believe that while you can tell whether the face is CW or CCW, it depends on the actual point of view and thereby you'd need to know whether a certain tri should be facing you or not when you're standing at some specific point in space. Or did I get it totally wrong?

Share this post


Link to post
Share on other sites
Caesar    126
Only now that I read Yann L's post I get it. I need to compare the loaded normal with the one I compute and see if they're the same or not and depending on that, rearrange the vertices to go CW/CCW (the way I want them)

thanks guys

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this