How to make and discard lots of triangles really fast, solid filling / clip plane

So I’m using clip planes to cut stuff up, and I want that stuff to look like it’s solid, not see the insides of it.

Here’s what I have in mind, I’m thinking of doing this per frame,

this way I can have texture patterns as solid filling, won’t have a problem for alpha meshes etc

What babylon api would be best to utilise for this?

My concerns are,

  • if it’s something that creates and discards actual objects, GC will cry about it
  • if it takes multiple draw calls it might be inefficient

I’m thinking the whole thing would be just 1 mesh and somehow I can just change the vertex buffer for that per frame?

What would be the best way to do this? tysm : )

Edit: I did read up on previous discussions regarding solid filling on clip planes and those essentially use detecting backfaces and using that info to display a color.

I don’t wanna go that route because for alpha meshes it just incorrectly detects false backfaces, and I wanna be able to do some wacky stuff w/ it like not even a solid thing, but give the clipped boundary a border, make it have pattens as textures etc : P

Hi @Heaust-ops

if I understand correctly, you want to cut mesh by a plane. and render the inside cut part of the mesh with a special shader.
So, basically, the mesh you want to render is the intersection of the plane and the mesh.
if I’m correct, then it depends of you source mesh.
if the mesh is convex, it’s easy to compute with a triangle fan.
if the mesh is concave, a Delaunay triangulation migh be a start Delaunay triangulation - Wikipedia

if it’s only at render time, I think it’s possible using the stencil buffer:

  • render mesh back faces with stencil increment
  • render mesh front faces with stencil decrement
  • render full screen quad where stencil value is 1
2 Likes

Hi, thank you so much for your reply!


yepp totally agree w/ the stencil approach, I’d still like to use actual geometry though for the following reason

I don’t wanna go that route because for alpha meshes it just incorrectly detects false backfaces, and I wanna be able to do some wacky stuff w/ it like not even a solid thing, but give the clipped boundary a border, make it have pattens as textures


if the mesh is convex, it’s easy to compute with a triangle fan.
if the mesh is concave, a Delaunay triangulation migh be a start Delaunay triangulation - Wikipedia

Tysm : D


My problem was though,

say I do this,

  • for every mesh I make a covering
  • those coverings are also their own mesh
  • this is done per frame so new meshes are made and discarded per frame

this is probably not very efficient and will likely cause slowdowns w/ many drawcalls and many garbage collector calls. [right half of the image]

so I want every covering triangle for every mesh to be part of one big mesh. and the triangles of that mesh will change every frame (a new set of triangles every frame). [left half of the image]

I wanted to know how i might achieve this
is there an api i can use to explicitly define the triangles of a mesh per frame : O

Yes, did you check this?

https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/custom/custom

1 Like

I tried to simplify the creation of a custom mesh with triangles:

CAD | Babylon.js Playground (babylonjs-playground.com)

1 Like

Hi, thank you so much! that’s exactly what I needed : D

1 Like

Woah, this is amazing :smiley:

thanks a ton <3

2 Likes