WarpUp (59/72)

From:MORB
Date:14 Apr 00 at 15:41:47
Subject:Re: [3DWorld] Creating normal vectors

You wrote:
>Hello, a problem with normals...

>A program reads the triangles and quads from files created with the cinema4D
>raytracer. Unfortunatly, the surfaces are not in an appropriate order to
>create normals out of them. Somehow I have to examine the structure to see
>which side of a triangle is the outside of the object. (I hope you can follow
>me)

>For convex objects I can calculade the center of the object and make a
>scalar-product between vector from center to the point of question and the
>normal. If both vectors point in the same direction, the normal vector is
>correct, otherwise I have to flip it. But this is very complicated - is there
>an easier way to do this?

>It also works with convex objects. How do I do this job with irregular
>objects? Any ideas?

I think you can make all the normal go in the same direction more or less
easily if you object is a closed mesh. Just pick up a triangle, and
look at the neighbours triangles. You can make all the neighbours
triangles have their vertex in the same order as the triangle you
picked:

For example, if you picked the triangle 1, you have vertex a,b and c
clockwise. So you know that for triangle 2, you can have his vertex
clockwise ordered if you put them in the following order: b,a,d.

That is, you take the two points shared between the two triangles (a
and b), you swap them (b,a) and you add the third point (d), giving
you the (b,a,d) order. Do this for all the neighbours, and then for
the neighbours of the neighbours, until all the triangles are done.

The only problem is that this work if the first triangle that you pick
is oriented in the good way, otherwise they will all end up oriented in
the bad way. If it's the case, you can just flip all the triangles to
have them in the good way.

Ps. I never tested all of this, so maybe it doesn't work at all :))



Antoine 'MORB' Chavasse / CdBS Software
http://CdBSSoftware.net