Skip to content

smitdylan2001/com.devdunkstudio.meshcutout

Repository files navigation

Mesh Cutout Unity

unity 2020.3

unity 2021.3

Mesh Cutout is a simple asset used to generate meshes/cutouts based on the distance to an object at runtime in a performant manner.

Supported in ALL graphics pipelines, since the tool modifies the mesh data directly.

Import

How To Use

  • Make sure the meshes used for Mesh Cutout have ‘Read/Write Enabled’ on. image

  • Put ‘CutoutMesh.cs’ on an object with a MeshFilter component image

  • Change Cutout mode to desired mode

  • Add Reference Object transform (can be left empty if manually calling CutoutMesh.UpdateCarvedMesh();)

  • Configure the minimum and maximum distances

  • Enable Generate on Start to generate the cutout immediately on start

  • Enable Generate on Update to generate the cutout every frame

  • Enable Generate on FixedUpdate to generate the cutout every FixedUpdate interval

  • To manually trigger the meshing call CutoutMesh.UpdateCarvedMesh(); (required a ReferenceObject Transform if not filled in inspector)

Demo

  • Simple cutout (enclosing) image
  • Simple cutout with hole (enclosing) image
  • Simple cutout with hole (touching) image
  • Complex mesh with cutout (touching) image
  • Complex mesh with cutout and hole (touching) image
  • Complex mesh with cutout and hole (enclosing) image

Limitations

How to contribute

  • All contributions for flexibility, performance and usability are welcome
  • Follow code conventions from CutoutMesh.cs
  • For changes in functionality (such as multiple reference objects), make a new script
  • Potential contributions:
    • Performance optimization
    • multithread support (jobified for loop and/or 1 job per meshed object)
    • run in editor
    • cutout preview system
    • Multiple reference objects support
    • Update Mesh Collider

Special Credits:

Bunny83 on Unity Forums for writing most of the script: https://forum.unity.com/threads/loop-through-triangles-performance-issue.1280498

About

Performant Cutout script for Unity

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages