# Is there a merge vertices / smooth normals utility with a crease angle argument available?

**URL:** <https://discourse.threejs.org/t/is-there-a-merge-vertices-smooth-normals-utility-with-a-crease-angle-argument-available/37679>\
**Category:** Questions\
**Tags:** geometry\
**Created:** [May 1, 2022, 2:54am UTC](https://discourse.threejs.org/t/is-there-a-merge-vertices-smooth-normals-utility-with-a-crease-angle-argument-available/37679 "2022-05-01T02:54:33Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![gkjohnson](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/gkjohnson/32/2298_2.png) [@gkjohnson](https://discourse.threejs.org/u/gkjohnson)\
**Post date:** [May 1, 2022, 2:54am UTC](https://discourse.threejs.org/t/is-there-a-merge-vertices-smooth-normals-utility-with-a-crease-angle-argument-available/37679/1 "2022-05-01T02:54:33Z")

</div>

Hello! I have an STL model that is a set of faces with face normals but I’d like to smooth them. Right now my process is to remove the existing normals, merge the geometry vertices and then run “computeVertexNormals” but that has the undesired effect of smoothing the “hard edges”, as well. Think a cyclinder geometry where you want to smooth the caps and body of the geometry without smoothing the hard end edges.

Here’s an old code pen (three.js r86) but it’s only built for the legacy Geometry class: [codepen](https://codepen.io/Ni55aN/pen/zROmoe).

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/e/d/edad0442262d8ce3be4fcbb2900a8b979ee352c9.png)

Does anyone know if there’s one available for a modern three.js BufferGeometry?

---

<div class="post-metadata">

**Author:** ![vielzutun.ch](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/vielzutun.ch/32/21366_2.png) [@vielzutun.ch](https://discourse.threejs.org/u/vielzutun.ch)\
**Post date:** [May 1, 2022, 3:15am UTC](https://discourse.threejs.org/t/is-there-a-merge-vertices-smooth-normals-utility-with-a-crease-angle-argument-available/37679/2 "2022-05-01T03:15:10Z")

</div>

For a cylinder geometry I achieve the desired result using a stock LatheGeometry and **duplicating** the path vertices where I want hard edges. This may be a hack, but for LatheGeometries it trips the ‘computeVertexNormal’ algorithm in the desired way.

---

<div class="post-metadata">

**Author:** ![gkjohnson](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/gkjohnson/32/2298_2.png) [@gkjohnson](https://discourse.threejs.org/u/gkjohnson)\
**Post date:** [May 1, 2022, 3:22am UTC](https://discourse.threejs.org/t/is-there-a-merge-vertices-smooth-normals-utility-with-a-crease-angle-argument-available/37679/3 "2022-05-01T03:22:14Z")

</div>

A cylinder is just a simple demonstration case. As I mentioned I have an STL file that is basically just a soup of triangles that I need to remerge the vertices for.

---

<div class="post-metadata">

**Author:** ![rrrr\_rrrr](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/rrrr_rrrr/32/7697_2.png) [@rrrr\_rrrr](https://discourse.threejs.org/u/rrrr_rrrr)\
**Post date:** [May 1, 2022, 8:00am UTC](https://discourse.threejs.org/t/is-there-a-merge-vertices-smooth-normals-utility-with-a-crease-angle-argument-available/37679/4 "2022-05-01T08:00:36Z")

</div>

> [@gkjohnson](#):
>
> Is there a merge vertices / smooth normals utility with a crease angle argument available?

If you want UVs and seamless mesh, the answer is no!

To do “hard edges”, there are 2 ways:

- Group the target faces with material flatShading: !0.
- Make sure the faces do not share any vertices.

BTW, there is no all scenario algorithm can do normals that can deal wtth seams, and hard/smoth edges.

---

<div class="post-metadata">

**Author:** ![gkjohnson](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/gkjohnson/32/2298_2.png) [@gkjohnson](https://discourse.threejs.org/u/gkjohnson)\
**Post date:** [May 1, 2022, 1:58pm UTC](https://discourse.threejs.org/t/is-there-a-merge-vertices-smooth-normals-utility-with-a-crease-angle-argument-available/37679/5 "2022-05-01T13:58:54Z")

</div>

My question isn’t about whether or not it’s possible - I know it is. I provided a demonstration above working for the old THREE.Geometry. And I’ve written algorithms like this myself previously.

What I’m asking for is whether or not one has already been written so I don’t have to look into building on myself.

---

<div class="post-metadata">

**Author:** ![gkjohnson](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/gkjohnson/32/2298_2.png) [@gkjohnson](https://discourse.threejs.org/u/gkjohnson)\
**Post date:** [May 1, 2022, 6:19pm UTC](https://discourse.threejs.org/t/is-there-a-merge-vertices-smooth-normals-utility-with-a-crease-angle-argument-available/37679/6 "2022-05-01T18:19:41Z")

</div>

I went ahead and wrote a function:

> <https://github.com/mrdoob/three.js/pull/23989>
>
> Related issue: #3670
> 
> \*\*Description\*\*
> 
> Adds a function to generate a new, no…n-indexed geometry with smooth normals for edges where the faces are within the provided angle threshold.
> 
> Also related: https://discourse.threejs.org/t/is-there-a-merge-vertices-smooth-normals-utility-with-a-crease-angle-argument-available/37679

---

<div class="post-metadata">

**Author:** ![vielzutun.ch](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/vielzutun.ch/32/21366_2.png) [@vielzutun.ch](https://discourse.threejs.org/u/vielzutun.ch)\
**Post date:** [May 1, 2022, 6:32pm UTC](https://discourse.threejs.org/t/is-there-a-merge-vertices-smooth-normals-utility-with-a-crease-angle-argument-available/37679/7 "2022-05-01T18:32:03Z")

</div>

I didn’t check whether your solution is sound, but I like your attitude! 👏 👍

---

<div class="post-metadata">

**Author:** ![rrrr\_rrrr](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/rrrr_rrrr/32/7697_2.png) [@rrrr\_rrrr](https://discourse.threejs.org/u/rrrr_rrrr)\
**Post date:** [May 3, 2022, 5:00am UTC](https://discourse.threejs.org/t/is-there-a-merge-vertices-smooth-normals-utility-with-a-crease-angle-argument-available/37679/8 "2022-05-03T05:00:13Z")

</div>

> [@gkjohnson](#):
>
> My question isn’t about whether or not it’s possible - I know it is. I provided a demonstration above working for the old THREE.Geometry

The key words here are **merge vertices** as indicated in your question. By doing so, there is a high chance that you will end up with messed up uvs, normal and other attributes that depend on overlapping vertices.
