https://github.com/aniketrajnish/unity-collider-optimizer
Optimizes mesh and polygon colliders in Unity
https://github.com/aniketrajnish/unity-collider-optimizer
collider collider2d game-development meshcollider polygoncollider2d qem quadric-error-metrics ramer-douglas-peucker unity-tool unity2d unity3d
Last synced: about 2 months ago
JSON representation
Optimizes mesh and polygon colliders in Unity
- Host: GitHub
- URL: https://github.com/aniketrajnish/unity-collider-optimizer
- Owner: aniketrajnish
- License: mit
- Created: 2023-09-30T18:24:06.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-06T07:11:34.000Z (about 1 year ago)
- Last Synced: 2025-03-30T01:11:10.281Z (2 months ago)
- Topics: collider, collider2d, game-development, meshcollider, polygoncollider2d, qem, quadric-error-metrics, ramer-douglas-peucker, unity-tool, unity2d, unity3d
- Language: C#
- Homepage:
- Size: 2.17 MB
- Stars: 406
- Watchers: 15
- Forks: 23
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Unity Collider Optimizer
Optimizes Mesh & Polygon colliders in Unity.

## Polygon Collider Optimizer
|  |  |  |
|:---:|:---:|:---:|
| Original Sprite | Unity Polygon Collider | Optimized Polygon Collider |
|**Path Count**| *213 paths* | *23 paths* |The tool uses a [C# implementation](https://www.codeproject.com/Articles/18936/A-C-Implementation-of-Douglas-Peucker-Line-Appro) of the Ramer Douglas Peucker Algorithm to smooth the polylines and reduce the number of paths created by a Polygon Collider in Unity.
#### Performance Comparison
https://github.com/aniketrajnish/Unity-Collider-Optimizer/assets/58925008/e134f0c6-4c08-4552-b69f-22e7f3b61ebe
You can run this test on your machine by cloning the project and going to the `Polygon Collider Optimization Test` scene in Unity.
#### Usage
* Download the `collideroptimizationpackage_2d_v004.unitypackage` package from the [Releases](https://github.com/aniketrajnish/Unity-Collider-Optimizer/releases/).
* Import all the assets from the package in your unity project.
* Attach the `PolygonColliderOptimizer.cs` script on your 2D sprite.
* Adjust the `optimizationFactor` to control the amount of optimzation you need.https://github.com/aniketrajnish/Unity-Collider-Optimizer/assets/58925008/74f5bdd1-f5c8-4c44-b745-78211919aae3
## Mesh Collider Optimizer
|  |  |  |
|:---:|:---:|:---:|
| Original Mesh | Unity Mesh Collider | Optimized Mesh Collider |
|**Triangles Count**| *9132 tris* | *2416 tris* |The tool uses the [Computational Geometry Unity Library](https://github.com/Habrador/Computational-geometry) by Erik Nordeus 🐐 to perfrom the Quadric Error Metrics simplification on the shared mesh of the mesh collider.
#### Performance Comparison
https://github.com/aniketrajnish/Unity-Collider-Optimizer/assets/58925008/cfba7837-a81e-4891-9594-501fbf31680f
You can run this test on your machine by cloning the project and going to the `Mesh Collider Optimization Test` scene in Unity.
#### Usage
* Download the `collideroptimizationpackage_3d_v004.unitypackage` package from the [Releases](https://github.com/aniketrajnish/Unity-Collider-Optimizer/releases/).
* Import all the assets from the package in your unity project.
* Attach the `MeshColliderOptimizer.cs` script on your 2D sprite.
* Choose the connecting mode between _Fast, Precise, and No._
* Adjust the `optimizationFactor` to control the amount of optimzation you need.
* Choose the mesh style to be _Soft, Hard or both_.
* **Warning: Choosing the "Fast" mode would likely lead to errors, Precise mode is recommended for most of the meshes.**https://github.com/aniketrajnish/Unity-Collider-Optimizer/assets/58925008/ddb08b48-d241-494c-a6f4-0a822424964a
## Updates
#### v004
* Added the functionality to save and load the optimized colliders as assets.
* Fixed the refresh bug.
https://github.com/aniketrajnish/Unity-Collider-Optimizer/assets/58925008/ba42c61c-4ea1-419d-bf81-324304a218b8## Contribution
Contributions to the project are welcome. Currently working on converting the QEM algorithm to a coroutine to stop the main Unity thread from freezing.## Known Bugs
* ~~If a prefab is made out of a gameobject having Polygon Collider Optimizer, it keeps refreshing itself.~~ **[FIXED]**
* Choosing Hard Edge Mesh Style decreases the number of triangles but induces additional vertices (doesn't affect the performance).## License
MIT License