Multiple Boolean Mesh Operations at Runtime

Hi, I am working on a project that a machine will carve/alter a mesh with a blade or cylinderic head with inputs from a user. Now I have a trigger mesh collider on cylinderic head and a basic cube as the mesh to be cut. With basic WASD inputs I am moving the head on the cube and trying to carve something on it. Using GitHub - karl-/pb_CSG: A C# port of CSG.js by Evan W (http://evanw.github.io/csg.js/). to remove the cyclinderic shape from the cube for now. Here is my current code: (I check the current position of the blade because it does not stop colliding so when it does not move I bypass colliding)

 private void OnTriggerStay(Collider other)
    {
        if (!Mathf.Approximately(Vector3.Distance(_lastPosition, transform.position), 0f))
        {
            var  _other = new GameObject();
            Model result = CSG.Subtract(other.gameObject, this.gameObject);

            _other.AddComponent<MeshFilter>().sharedMesh = result.mesh;
            _other.AddComponent<MeshRenderer>().sharedMaterials = result.materials.ToArray();

            GenerateBarycentric(_other);
            Destroy(other.gameObject);
       }
    }

Do you have any suggestions about any part of this. Maybe another library to use or another way to achieve this.

1 Like

No one ? Really ?

Boolean operations at runtime are simply not used in majority of games.

The only game that implements runtime CSG that I know of is Red Faction 1. Released 2001.

Nobody ever bothered with something like that since.

In your scenario you never described what the problem is. If you’re trying to simulate carving process, then you’re trying to implement CAD by yourself and that’s not simple.

You can approximate the carving process with voxels or heightmap. It will not be ideal.

I am trying to build a simulation for CNC Mill table basically. So I will be subtracting the mill’s mesh from the other mesh.

And that is a VERY hard problem to solve. It is also not normally done by subtracting mill mesh from the detail, instead you’d build a trajectory, form solids from trajectory and subtract that.

Is your table 3 axis or 4 axis?

In case of 3 axis, like I said, you can approximate process using a heightmap. to represent the detail. In case of 4 axis, you’ll want voxels.

Table is 3 axis. I see. I have another question then can I get help from opencascade like can I exchange data between Unity and Open Cascade fast so that I use the Open Cascade’s calculations

I haven’t worked with it.

Does it have an API? If it does, you’ll probably be able to talk to it, but that might require writing glue code or helper functions yourself. I do not see anything for it on asset store.

Basically, in case of unity you have access to C# for scripting that means you’ll be able to exchange data with an external program through sockets, web requests, json, and if it allows it, you could talk to a dll through native plugin interface and System.Runtime.InteropServices.

Thank you I will look into it. It does have an API apparently.

1 Like

for marching cubes, here’s some inspiration/info:

1 Like

Yeah, basically, to keep your sanity, the best idea is to turn it into some form that is not polygons.

The problem is that the data can be dense to the point that you’ll only have one log you can saw in your whole scene.

Most of the time when people offer some sort of “dynamic slicing” of polygonal objects, they slice objects with planes, as it is easier to implement than free form cut.

For example, IIRC farming simulator had free form sawing of trees, but it was basically a plane slice. Similar thing happened with, say, Metal Gear Rising, or Cooking Simulator (VR), etc.

Nobody really does free-form cutting. Ever.