# Strange cap when extrusion

**URL:** <https://forum.babylonjs.com/t/strange-cap-when-extrusion/15183>\
**Category:** Questions\
**Created:** [October 26, 2020, 2:22pm UTC](https://forum.babylonjs.com/t/strange-cap-when-extrusion/15183 "2020-10-26T14:22:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jiraph](https://avatars.discourse-cdn.com/v4/letter/j/839c29/32.png) [@Jiraph](https://forum.babylonjs.com/u/Jiraph)\
**Post date:** [October 26, 2020, 2:22pm UTC](https://forum.babylonjs.com/t/strange-cap-when-extrusion/15183/1 "2020-10-26T14:22:14Z")

</div>

Hey there !  
I have a problem with the caps on an extruded figure !  
[https://www.babylonjs-playground.com/#0XX50N#4](https://www.babylonjs-playground.com/#0XX50N#4)  
Tried a lot of things wiht the extrudeShape properties but nothing seems to work. I still get artifacts… I’ve been working a lot on this figure because it is quite complicated to draw correctly.  
Thanks !

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [October 26, 2020, 2:47pm UTC](https://forum.babylonjs.com/t/strange-cap-when-extrusion/15183/2 "2020-10-26T14:47:59Z")

</div>

@Evgeni_Popov or @JohnK might have way more valuable insights than me on this topic. I am lame with Geometry 😉

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [October 26, 2020, 3:12pm UTC](https://forum.babylonjs.com/t/strange-cap-when-extrusion/15183/3 "2020-10-26T15:12:42Z")

</div>

The algorithm is working as expected, but does not generate what you want because the shape is concave:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/f/fa2d254f9edb300df160ed0ff01647cc28273b31.png)

To draw the cap, the barycenter of all the points is computed and triangles are drawn by taking this point as a pivot, as you can see in the picture.

For this to work, I think we would need to provide a way for the user to set its own barycenter points that would override the computed ones for the cap start / cap end…

---

<div class="post-metadata">

**Author:** ![Jiraph](https://avatars.discourse-cdn.com/v4/letter/j/839c29/32.png) [@Jiraph](https://forum.babylonjs.com/u/Jiraph)\
**Post date:** [October 26, 2020, 3:19pm UTC](https://forum.babylonjs.com/t/strange-cap-when-extrusion/15183/4 "2020-10-26T15:19:33Z")

</div>

Does it mean I have no solution to fix it ? Shall I modify the shape to be composed of 2 or 3 sub shapes ?

---

<div class="post-metadata">

**Author:** ![Jiraph](https://avatars.discourse-cdn.com/v4/letter/j/839c29/32.png) [@Jiraph](https://forum.babylonjs.com/u/Jiraph)\
**Post date:** [October 26, 2020, 3:35pm UTC](https://forum.babylonjs.com/t/strange-cap-when-extrusion/15183/5 "2020-10-26T15:35:37Z")

</div>

Okay I think I got a solution but I still need you help…  
By duplicating the base shape I can get a “clean” mesh. But it’s doubled. Do you have any solution to cut this mesh in half ?  
[https://www.babylonjs-playground.com/#0XX50N#5](https://www.babylonjs-playground.com/#0XX50N#5)

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [October 26, 2020, 4:14pm UTC](https://forum.babylonjs.com/t/strange-cap-when-extrusion/15183/6 "2020-10-26T16:14:10Z")

</div>

You can try to use a CSG intersect to keep only the upper part.

---

<div class="post-metadata">

**Author:** ![JohnK](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johnk/32/26764_2.png) [@JohnK](https://forum.babylonjs.com/u/JohnK)\
**Post date:** [October 26, 2020, 4:56pm UTC](https://forum.babylonjs.com/t/strange-cap-when-extrusion/15183/7 "2020-10-26T16:56:46Z")

</div>

You can use [ExtrudePolygon](https://doc.babylonjs.com/how_to/parametric_shapes#extruded-non-regular-polygon) instead however it is more limited, the coords for the base shape need to be in (x, z) not (x, y), depth only no extrude path, some rotation and positioning may be needed and outside the playground you need to inject and earcut app see [api](https://doc.babylonjs.com/api/classes/babylon.meshbuilder#extrudepolygon)
