Skip to content

A realtime mesh slicer capable of dynamically separating concave objects into multiple parts.

License

Notifications You must be signed in to change notification settings

olafvisker/simpleslice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

simpleslice

A realtime mesh slicer for the game engine Unity3d, capable of dynamically separating concave objects into multiple parts.

how to use

Simply add the MeshSlicer.cs to your project. The code below shows you how to separate a rigidbody into two rigidbodies.

private MeshSlicer meshSlicer = new MeshSlicer();

private void Update() {
    if (Input.GetMouseButtonDown(0)){
        RaycastHit hit;
        var ray = new Ray(transform.position, transform.forward);
        if (Physics.Raycast(ray, out hit)){ 
            Cut(hit.transform.gameObject, transform.up, hit.point); 
        }
    }
}

private void Cut(GameObject target, Vector3 normal, Vector3 point) {
    var gos = meshSlicer.CutGameObject(target, normal, point);

    gos.Item1.AddComponent<Rigidbody>();
    gos.Item1.AddComponent<MeshCollider>();
    gos.Item1.GetComponent<MeshCollider>().convex = true;

    gos.Item2.AddComponent<Rigidbody>();        
    gos.Item2.AddComponent<MeshCollider>();       
    gos.Item2.GetComponent<MeshCollider>().convex = true;
    Destroy(target);
}

example

slice_img

enjoy!

About

A realtime mesh slicer capable of dynamically separating concave objects into multiple parts.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages