pouët.net

Go to bottom

3d faces side question

category: general [glöplog]
 
I have a mesh imported from a not-so-good 3d program. The face normals are not correct, some are to the inside, and some to the outside. Also, if I try to calc by myself the normal vector of the triangles, the same.

I want to use two-sided triangles always. Is there any algorithm were given a mesh I can make all the faces the same side?

You know, if two faces are connected, then these should point to the same side.

I believe I could develop an algorithm by myself for this, but maybe there is already one, and you can tell me the name for this kind of algorithm.

Thanks in advance.
added on the 2009-05-16 22:59:27 by texel texel
Sorry so much. Forget this stupid question, I'm silly.

I've just checked my model again, and it have some of the faces reversed in the original model, this is why I'm having problems.
added on the 2009-05-16 23:03:24 by texel texel
Quote:
I want to use two-sided triangles always.

i wonder, doesn't that imply that it doesn't matter if the face is inside or outside? :D
Quote:
i wonder, doesn't that imply that it doesn't matter if the face is inside or outside? :D

The real face is outside.

On more serious note though, is there any algorithm that would do what texel described (determining if polygon should be CW/CCW)? I can imagine one for simple convex meshes, or where only few faces are fliped, but any generic one ?
added on the 2009-05-16 23:59:11 by snoutmate snoutmate
the same way you would do it in 2d, using a crossing test. send a ray from the center of your triangle in the normal direction, test all intersections in the mesh, if the number of intersections is even the orientation is correct.
added on the 2009-05-17 01:20:21 by shiva shiva
shiva:

That would work for closed meshes but... Not all meshes are closed.
added on the 2009-05-17 16:50:19 by texel texel
Quote:
i wonder, doesn't that imply that it doesn't matter if the face is inside or outside? :D


Sure it does. You can have different textures for example, but not only. I'm doing GI, and the illumination is not the same inside or outside an object
added on the 2009-05-17 16:53:16 by texel texel
Quote:

You know, if two faces are connected, then these should point to the same side.


I wonder, maybe we can find an object, like a möbius ring, where inside/outside is not as clear... ;)
added on the 2009-05-18 11:12:36 by baah baah
Sure baah, in a mobius string there is only one side... wtf
added on the 2009-05-18 12:22:31 by texel texel
the face is in your mind!
added on the 2009-05-18 13:02:31 by Deus Deus
I would start with one triangle, call it T, and then decide on a choice of normal direction for T first. Then move to the (max 3) triangles that share edges with T and propagate the normal direction for T to those neighbors. Then do the same thing for the neighbors until you covered the connected component of T.

One have to build some kind of datastructure containing neighboring info first, but that's either fast and easy or already present in your program :)

This works for connected, closed and non-closed combinatorial complexes (== nice meshes ?). If it's closed and embedded into Eucledian 3-space, you can't have any Mobius bands to worry about by embedding theory. If it is non-closed, then the algorithm above will sooner or later run into a case where you encounter a triangle where you have already a normal direction and this choice contradicts the normal direction you are about to assign to it. ( I hope ;) ) (And I see that you are using the terms "inside" and "outside", so I suppose you are not dealing with non-orientable surfaces anyway..)

added on the 2009-05-18 14:39:17 by Hyde Hyde
Just walk across the faces. Start with any face, then flip neighbouring faces if necessary, and recursively process the neighbouring faces the same way. Like a recursive flood fill. You will only walk to connected parts of the mesh, so if some faces still haven't been processed when you're done, pick any unprocessed face and continue from there.

If you don't have the connectivity information the convention is that two faces A and B share an edge if they share two vertices. Also, one of the faces needs flipping if those two vertices appear in the same order in both faces (that means one is CW and the other is CCW).

Once you have all the faces of a connected part of the mesh facing the same way, you need to determine which way is "in" and which is "out". If the mesh is a fully closed surface, you can do this automatically by tracing a line from infinitely far away and towards the mesh. Use the fact that the angle of incidence must be < 90 degrees to check that the normal is facing the right way. If not, flip the whole mesh.

If the mesh is not connected, there are no definitive "in" and "out" directions, but you could try something like this: Define a centre of the mesh as the weighted average of all vertices. Sum up the area of all the faces facing away from and towards this area, now flip the whole thing as needed to maximise the area facing away from the centre.

Of course this fails for moebius strips etc.
added on the 2009-05-18 15:17:42 by doomdoom doomdoom
* oh, and the bit about tracing a line, you're only looking for the first intersection with any face, of course.
added on the 2009-05-18 15:26:21 by doomdoom doomdoom
Randomize all faces' orientations, display the mesh on screen, and pop up a dialog box saying "does the mesh look correct now?". If the user hits "yes", you're done. If not, start over.
added on the 2009-05-18 21:32:52 by kusma kusma
Randomize all faces' orientations, use the mesh in a demo and put it on pouet, then wait until you've got more than 100 comments. If just two or less of the comments mention something like "the mesh seems to bug when running the demo on my laptop (vista, sp8, latest dx drivers, etc. etc.)", you're done. If not, put your source on sourceforge and let someone else start over.
added on the 2009-05-18 21:47:20 by Hyde Hyde

login

Go to top