<p>A very simple, but computationally expensive, way to do this is to pick a triangle, preferably one that you know has the winding you want.</p>
<p>Then search every triangle in the soup for triangles that share an edge with the chosen triangle.</p>
<p>For every triangle that shares an edge, check that its winding is the same as the chosen triangle. The winding is the same iff the ordering of the vertices on the shared edge <strike>are the same</strike> <em>are the opposite</em>. If the ordering is different swap the order of any two vertices on the found triangle.</p>
<p>Remove found triangles from the original set as they are discovered.</p>
<p>Wash rinse repeat.</p>
<p>It is usually easiest to implement this algorithm using indexed triangles, it is straight forward to index a set of vertices. (1:iterate over every vertex and assign a new index to only those that are unique, then 2:iterate over every triangle and assign an index from the index pool created in step 1.)</p>
<p>One nice thing about this algorithm is there are extra &quot;whistle while you work&quot; things that can be done to check the integrity of the polyhedron.</p>
<ol>
<li><p>Keep a count of edges that don't share an edge with any other triangle. At the end if this number is non-zero then the polyhedron is not &quot;water tight&quot;. This can be a good starting point for making the polyhedron water tight.</p>
</li>
<li><p>It is possible to have triangles that are not connected to the original chosen triangle, meaning the soup is either inconsistent, or defines multiple polyhedrons.</p>
</li>
</ol>
<p>Lastly, this algorithm is so easy to code up it can be used to compare other more advance techniques against.</p>

CC BY-SA 4.0
2022-09-04T15:57:02.553Z
An easy enhancement is to build a hash table mapping edges (as ordered pairs of vertex IDs) to triangles, so given an edge it's easy to find the other triangle that shares it, rather than searching through the whole mesh in a quadratic fashion.
Nathan Reed
CC BY-SA 4.0
2022-09-07T15:48:10.463Z
The winding is the same iff the ordering of the vertices on the shared edge are *different*, though.
Christian Rau
CC BY-SA 4.0
2022-09-04T14:37:24.237Z
2022-09-08T11:00:54.237Z
2022-09-08T11:00:54.237Z
pmw1234
<p>I am using c++. I have to find vertex normal in mesh. The mesh is triangle soup. The winding order is inconsistent. I know that it is the sum of all faces normals arround the vertex. But I don't know how to set correct direction of faces (triangles) normals.
I want to know for algorythm for this.</p>

CC BY-SA 4.0
2022-09-03T22:17:55.303Z
Do you mean that you have a mesh with inconsistent winding order on the triangles and you need to standardize it?
Nathan Reed
CC BY-SA 4.0
2022-09-04T09:24:27.453Z
@Nathan Reed. Yes I mean this
Vladimir Yanakiev
<c++><mesh>
Computing vertex normals in mesh triangle soup
Vladimir Yanakiev
# Computing vertex normals in mesh triangle soup

(Asked by: username_0 on 2022-09-03)

I am using c++. I have to find vertex normal in mesh. The mesh is triangle soup. The winding order is inconsistent. I know that it is the sum of all faces normals arround the vertex. But I don't know how to set correct direction of faces (triangles) normals.
I want to know for algorythm for this.

**Tags:** c++, mesh

> **Comments:**
> **username_1**: Do you mean that you have a mesh with inconsistent winding order on the triangles and you need to standardize it?  
> **username_0**: @username_1. Yes I mean this  

---

## 1 answers

### Answer by username_2 on 2022-09-04. Score: 4 | Accepted answer

A very simple, but computationally expensive, way to do this is to pick a triangle, preferably one that you know has the winding you want.

Then search every triangle in the soup for triangles that share an edge with the chosen triangle.

For every triangle that shares an edge, check that its winding is the same as the chosen triangle. The winding is the same iff the ordering of the vertices on the shared edge are the same *are the opposite*. If the ordering is different swap the order of any two vertices on the found triangle.

Remove found triangles from the original set as they are discovered.

Wash rinse repeat.

It is usually easiest to implement this algorithm using indexed triangles, it is straight forward to index a set of vertices. (1:iterate over every vertex and assign a new index to only those that are unique, then 2:iterate over every triangle and assign an index from the index pool created in step 1.)

One nice thing about this algorithm is there are extra "whistle while you work" things that can be done to check the integrity of the polyhedron.

1. Keep a count of edges that don't share an edge with any other triangle. At the end if this number is non-zero then the polyhedron is not "water tight". This can be a good starting point for making the polyhedron water tight.
2. It is possible to have triangles that are not connected to the original chosen triangle, meaning the soup is either inconsistent, or defines multiple polyhedrons.

Lastly, this algorithm is so easy to code up it can be used to compare other more advance techniques against.

> **Comments:**
> **username_1**: An easy enhancement is to build a hash table mapping edges (as ordered pairs of vertex IDs) to triangles, so given an edge it's easy to find the other triangle that shares it, rather than searching through the whole mesh in a quadratic fashion.  
> **username_3**: The winding is the same iff the ordering of the vertices on the shared edge are *different*, though.  

---

