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.
- Go to Package Manager
- Go to Add Package from Git URL
- Add 'https://github.com/smitdylan2001/com.devdunkstudio.meshcutout.git'
- Click Add
-
Make sure the meshes used for Mesh Cutout have ‘Read/Write Enabled’ on.
-
Put ‘CutoutMesh.cs’ on an object with a MeshFilter component
-
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)
- Simple cutout (enclosing)
- Simple cutout with hole (enclosing)
- Simple cutout with hole (touching)
- Complex mesh with cutout (touching)
- Complex mesh with cutout and hole (touching)
- Complex mesh with cutout and hole (enclosing)
- Currently only 1 reference object is supported
- Code runs on main thread (could potentially be faster with job system/burst support)
- Read/Write Enabled has to be enabled resulting in more memory allocation
- Could Potentially use MeshData for more performance: https://docs.unity3d.com/2020.1/Documentation/ScriptReference/Mesh.MeshData.html
- 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
Bunny83 on Unity Forums for writing most of the script: https://forum.unity.com/threads/loop-through-triangles-performance-issue.1280498