Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to fix 3D mesh normals

I have triangle collection that define mesh surface of my 3D shape, I would like to fix normal of each triangle to point outshape.

I was trying the following (pseudo):


1. define that first triangle normal direction is right direction
2. go over the mesh using kind of DFS like this:
3. triangle = first triangle
4. foreach neigbour in triangle.getNeighbours
5. if angle between neighbor and triangle greater then 180 do neighbor.flip()
6. triangle = neighbor
7. if neighbor already picked then continue to next neighbor
8. continue recursively to 4.

But step 5 in algorithm does not work because cant know if the angle is greater then 180, because i need to know in witch direction (clockwise or counter clockwise).

Could you please help me to understand how to fix the algorithm?

like image 892
Sergey Kucher Avatar asked Dec 12 '25 06:12

Sergey Kucher


1 Answers

There is no need to calculate angle between neighbours. If triangle ABC is oriented (A->B->C), and if neighbour on edge AB is triangle ABD, than it has to have opposite orientation on edge AB. That means, neigbouring triangle has to be orientated B->A->D.

like image 198
Ante Avatar answered Dec 14 '25 19:12

Ante



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!