# ConvexHull faces

**URL:** <https://forum.babylonjs.com/t/convexhull-faces/42187>\
**Category:** Questions\
**Tags:** geometry\
**Created:** [July 5, 2023, 9:16pm UTC](https://forum.babylonjs.com/t/convexhull-faces/42187 "2023-07-05T21:16:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![WillemCramer](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/willemcramer/32/11696_2.png) [@WillemCramer](https://forum.babylonjs.com/u/WillemCramer)\
**Post date:** [July 5, 2023, 9:16pm UTC](https://forum.babylonjs.com/t/convexhull-faces/42187/1 "2023-07-05T21:16:56Z")

</div>

With the enormous contribution of @carolhmj I have this ConvexHull going on but there are some things going on that i don’t understand. Focus on the buildRenderableMesh() section from line 379- 421.  
Probably best have the console open too.  
Because the convex-hull I did a `this.renderableMesh.forceSharedVertices();`  
but ended up with way too many faces for the vertices so i tried a `this.faces = this.faces.filter(face => face.mark === 0); ` in line 385.  
faces are marked with a `const FaceTypes = { VISIBLE: 0, NON_CONVEX: 1, DELETED: 2, }`  
in lines 425 - 429

Questions:

- what to do with the newFaces which are also marked as 0 (visible)
- why can’t i set colors to the vertices (mesh turns black)
- what’s going on with the faces/facets? when you run the script a couple of times and rotate the mesh you’ll find it’s sometimes perfect and sometimes you see glitches  
Thanks in advance 🙂

> **[Babylon.js Playground](https://playground.babylonjs.com/#UZWVCC%2344)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [July 6, 2023, 8:14am UTC](https://forum.babylonjs.com/t/convexhull-faces/42187/2 "2023-07-06T08:14:27Z")

</div>

I can answer for the vertex color: you have to push values and not color object.  
Change visible in this PG:

> **[Babylon.js Playground](https://playground.babylonjs.com/#UZWVCC%2346)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

For the rest, I’ll let @carolhmj 🙂

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [July 6, 2023, 3:06pm UTC](https://forum.babylonjs.com/t/convexhull-faces/42187/3 "2023-07-06T15:06:14Z")

</div>

The code there is an implementation of the 3D Quickhull algorithm, the original repo has a pdf containing some implementation details and references I used. It’s been a while through so not all the details are clear on my mind anymore 😛

- newFaces should be only part of the hull construction process so you should just be able to ignore it
- Cedric already answered that 🙂
- This looks like faces with inside pointing normals that aren’t being marked as deleted, it’s probably a bug in the hull construction code 😅 You could debug it and see where’s that happening, or you could remove these faces after the hull is constructed.

---

<div class="post-metadata">

**Author:** ![WillemCramer](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/willemcramer/32/11696_2.png) [@WillemCramer](https://forum.babylonjs.com/u/WillemCramer)\
**Post date:** [July 7, 2023, 3:34pm UTC](https://forum.babylonjs.com/t/convexhull-faces/42187/4 "2023-07-07T15:34:28Z")

</div>

Thanks for looking into that @Cedric 🙂 I just didn’t know that.  
And thank you for doing this @carolhmj , you did a great job and I am very grateful!

---

<div class="post-metadata">

**Author:** ![WillemCramer](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/willemcramer/32/11696_2.png) [@WillemCramer](https://forum.babylonjs.com/u/WillemCramer)\
**Post date:** [July 8, 2023, 7:34am UTC](https://forum.babylonjs.com/t/convexhull-faces/42187/5 "2023-07-08T07:34:57Z")

</div>

It’s not perfect yet but it appears to be better 🙂

> **[Babylon.js Playground](https://playground.babylonjs.com/#UZWVCC%2349)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [July 10, 2023, 12:54pm UTC](https://forum.babylonjs.com/t/convexhull-faces/42187/6 "2023-07-10T12:54:47Z")

</div>

Nice!!! 😄
