Splicing dynamically created shapes into two parts (maybe with parent?)

Hello!

My problem now consists on this kind of scenario, I need to splice this block of meshes in half by giving it a point A to a point B, the idea is that they have to be separated into two pieces to be manipulated individually and also each piece has to be able to render edges to identify them. Merge them in my case is not an option. Maybe parenting them? I tried it but in the way the meshes are created is kind of difficult to parent it to each other without a node. For context my meshes are dynamically created by a JSON and thanks to a for loop they take a coodinate and repeat the mesh by a number of repetition given in the json file, the problem is that those are meshes created dynamically and I have to split every mesh at the same time in the same coordinate.

I tried also following this answer Cutting / Splitting objects into two but after trying it in my local project it seems that it turn quite difficult to add to the way that my shape is built, also the user who answered used a rotation by camera to signal the cutting direction instead of a point B that is my case and also this one just uses one mesh to do the cut where in my case are multiple meshes that I have to split.

Any other way that I could manage or suggest to board this problem?

Here is the PG of the shape in question.

https://www.babylonjs.com/demos/csg/

look up the CSG

1 Like

Yup CSG would be the easiest https://www.babylonjs-playground.com/#B2DP5I#7

1 Like

yeah, it would be the easiest but I still don’t understand if CSG functions can slice multiple parented or just multiple meshes at once in the same position that’s is my question in general, I know I can create a box and cut it in the general position of the box and then make it vanish but I don’t find anywhere if CSG can do it with multiple meshes at once.

For example I found one PG somewhere that approach what I want https://playground.babylonjs.com/#0ZUCZB#3 but can I do the same here but with multiple meshes at once?

unfortunately you might need to merge your meshes first as CSG won t work on several of them except if you apply it individually to all of them

well… If that’s the case, if I merge the mesh there is a way to unmerge it? it could sound kind of weird but I need to have those meshes like they are shown on my PG. or maybe I can take another route… is there a way to parent one mesh, cut that one and the others do the same as they are parented?

1 Like

In the end I solved my own problem, yeah using CSG was the way to go, but as @sebavan said that if I wanted to do it in group I would have to merge so… instead of doing that I just looped the meshes and made a polygon of the size of the chunk I want to cut and then applied CSG. Now if I want to manipulate those meshes I just need to call the name of the mesh plus the side I want to manipulate.

Here is my PG with the solution for people who are trying to do something similar.

2 Likes