# When combining holes cut with polygon mesh builder and CSG, things do not fully cut through

**URL:** <https://forum.babylonjs.com/t/when-combining-holes-cut-with-polygon-mesh-builder-and-csg-things-do-not-fully-cut-through/30029>\
**Category:** Bugs\
**Tags:** csg\
**Created:** [May 4, 2022, 6:51pm UTC](https://forum.babylonjs.com/t/when-combining-holes-cut-with-polygon-mesh-builder-and-csg-things-do-not-fully-cut-through/30029 "2022-05-04T18:51:40Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![jekelija](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jekelija/32/5458_2.png) [@jekelija](https://forum.babylonjs.com/u/jekelija)\
**Post date:** [May 4, 2022, 6:51pm UTC](https://forum.babylonjs.com/t/when-combining-holes-cut-with-polygon-mesh-builder-and-csg-things-do-not-fully-cut-through/30029/1 "2022-05-04T18:51:40Z")

</div>

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

Both the wall and the paint layer have a hole cut out of them at the top. (if you want to see the “cut” area of the paint, simply dont dispose of the box). The cut area of the wall, instead of remaining fully cut out, somehow gets the material of the cutout of the paint layer applied to it. How can i go about fixing this?

---

<div class="post-metadata">

**Author:** ![jekelija](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jekelija/32/5458_2.png) [@jekelija](https://forum.babylonjs.com/u/jekelija)\
**Post date:** [May 4, 2022, 7:19pm UTC](https://forum.babylonjs.com/t/when-combining-holes-cut-with-polygon-mesh-builder-and-csg-things-do-not-fully-cut-through/30029/2 "2022-05-04T19:19:24Z")

</div>

Even stranger, when i add motion, that blue box travels with it. see updated playground [https://playground.babylonjs.com/#EYJF9P#1](https://playground.babylonjs.com/#EYJF9P#1)

---

<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:** [May 5, 2022, 9:41am UTC](https://forum.babylonjs.com/t/when-combining-holes-cut-with-polygon-mesh-builder-and-csg-things-do-not-fully-cut-through/30029/3 "2022-05-05T09:41:31Z")

</div>

I’m sorry but I’m sure to understand your problem.  
CSG is a one time operation. once it’s done, you get a mesh that can be moved but no other CSG will happen.  
What do you want to achieve ?

---

<div class="post-metadata">

**Author:** ![jekelija](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jekelija/32/5458_2.png) [@jekelija](https://forum.babylonjs.com/u/jekelija)\
**Post date:** [May 5, 2022, 1:35pm UTC](https://forum.babylonjs.com/t/when-combining-holes-cut-with-polygon-mesh-builder-and-csg-things-do-not-fully-cut-through/30029/4 "2022-05-05T13:35:33Z")

</div>

So there are two different types of cutouts occurring. One using CSG, and one using PolygonMeshBuilder. I would expect a result like the following image. The CSG cutout for the Paint is actually outside of the paint entirely, so should have no real effect. The cutout for the wall using PolygonMeshBuilder is inside the wall, so should cutout the wall. Instead, it appears as if the CSG cutout that is outside of the paint is somehow applying the paint material to the cutout area

 ![babylon bug](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/1/b/1b043be9d76ef7cc4fb3e89dfce7dc3d9e30a431.png)

---

<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:** [May 5, 2022, 1:47pm UTC](https://forum.babylonjs.com/t/when-combining-holes-cut-with-polygon-mesh-builder-and-csg-things-do-not-fully-cut-through/30029/5 "2022-05-05T13:47:22Z")

</div>

CSG has weird result when using not closed geometry. And the result with just a plane is not what you expect, I guess.  
Changing it to a box with thickness should solve your issue:

[Test Holes Cut | Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#EYJF9P#2)

---

<div class="post-metadata">

**Author:** ![jekelija](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jekelija/32/5458_2.png) [@jekelija](https://forum.babylonjs.com/u/jekelija)\
**Post date:** [May 5, 2022, 1:58pm UTC](https://forum.babylonjs.com/t/when-combining-holes-cut-with-polygon-mesh-builder-and-csg-things-do-not-fully-cut-through/30029/6 "2022-05-05T13:58:08Z")

</div>

> [@Cedric](#):
>
> Test Holes Cut | Babylon.js Playground ([babylonjs.com](http://babylonjs.com))

Unfortunately we cannot change it to a box with thickness. It is a paint layer on a wall, something that would inherently have no thickness, and is pretty firmly baked into our platform. I take it this is just a known issue, and not something that we can do anything about?

---

<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:** [May 5, 2022, 2:01pm UTC](https://forum.babylonjs.com/t/when-combining-holes-cut-with-polygon-mesh-builder-and-csg-things-do-not-fully-cut-through/30029/7 "2022-05-05T14:01:42Z")

</div>

unfortunately, it’s by design.  
but, I think, with a bit of work and effort, you can clip a mesh by a plane.  
I guess your primary need is to be able to cut a mesh and discarded faces that aren’t on the ‘good’ side.  
It’s a matter of running thru all the triangles, and checking is its vertices position are on the positive or negative side.

---

<div class="post-metadata">

**Author:** ![jekelija](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jekelija/32/5458_2.png) [@jekelija](https://forum.babylonjs.com/u/jekelija)\
**Post date:** [May 5, 2022, 2:46pm UTC](https://forum.babylonjs.com/t/when-combining-holes-cut-with-polygon-mesh-builder-and-csg-things-do-not-fully-cut-through/30029/8 "2022-05-05T14:46:14Z")

</div>

This actually used to work in babylon 4.2.1. Do we know what changed?

---

<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:** [May 5, 2022, 2:57pm UTC](https://forum.babylonjs.com/t/when-combining-holes-cut-with-polygon-mesh-builder-and-csg-things-do-not-fully-cut-through/30029/9 "2022-05-05T14:57:33Z")

</div>

I see the same behavior between 5.5.0 and 4.2.1.

---

<div class="post-metadata">

**Author:** ![jekelija](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jekelija/32/5458_2.png) [@jekelija](https://forum.babylonjs.com/u/jekelija)\
**Post date:** [May 5, 2022, 3:00pm UTC](https://forum.babylonjs.com/t/when-combining-holes-cut-with-polygon-mesh-builder-and-csg-things-do-not-fully-cut-through/30029/10 "2022-05-05T15:00:07Z")

</div>

Oh weird. I see it in the playground too. In our code base though, its different. We must be doing something different than i did in the playground. For now, im going to try adding the slightest bit of depth to our paint layer and see if that resolves it

---

<div class="post-metadata">

**Author:** ![imerso](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/imerso/32/46445_2.png) [@imerso](https://forum.babylonjs.com/u/imerso)\
**Post date:** [May 5, 2022, 3:16pm UTC](https://forum.babylonjs.com/t/when-combining-holes-cut-with-polygon-mesh-builder-and-csg-things-do-not-fully-cut-through/30029/11 "2022-05-05T15:16:07Z")

</div>

On such a case, maybe you could consider using an opacity texture to make those holes. Just an idea.

---

<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:** [May 9, 2022, 6:48pm UTC](https://forum.babylonjs.com/t/when-combining-holes-cut-with-polygon-mesh-builder-and-csg-things-do-not-fully-cut-through/30029/12 "2022-05-09T18:48:13Z")

</div>

Stencils might be another option

---

<div class="post-metadata">

**Author:** ![imerso](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/imerso/32/46445_2.png) [@imerso](https://forum.babylonjs.com/u/imerso)\
**Post date:** [May 9, 2022, 9:42pm UTC](https://forum.babylonjs.com/t/when-combining-holes-cut-with-polygon-mesh-builder-and-csg-things-do-not-fully-cut-through/30029/13 "2022-05-09T21:42:08Z")

</div>

Much better indeed, and here is a PG just for the fun of it:

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