November 2016

A BSP Compiler for Unity 3D

This is a bit obscure, but recently I’ve been finding myself needing to write some code to answer the question “is this object in an area or not.” Unity3D provides some functionality to do this, but it tends to be a bit imprecise in that only very simple primitives can be used (box collider, sphere collider, convex hull, etc.).

So, in order to automate this a bit, I built some tools to make this a bit easier. You can see/download the result on github.

screenshot

On the left is the original mesh, on the right is a visualization showing which convex “zones” are created.

What this basically does is takes the selected mesh, and “fills” it with convex colliders marked as triggers. You can then use those triggers however you want.

Some caveats: It’s better to do this with low detail models, as the compiler can take quite a while on larger models. Also while there’s not a hard requirement that the meshes are sealed, the results generally will be better if they are.