I am looking to use dynamic mesh decals instead of projectors for blob shadows.
How can I quickly and efficiently get all the triangles within a box collider to then use to dynamically create a mesh and update it every frame? Ray cast is the only thing that seems to return triangle indexes. The Decal System created by Dantus does all this and more but it’s not open source and I want to improve my programming a bit by creating my own. Any ideas of how this is done? Thanks
The basics for the understanding are quite simple. I’ll quickly explain the mesh case. Terrains have to be handled differently.
Get the mesh onto which you perform the projection.
Get the mesh data of it.
Cut that mesh. Based on your projector’s transform, you get 6 surrounding planes. At each of them you need to perform a cut.
Take that mesh and visualize it with a new mesh renderer.
Obviously step 3 is the most complex one. You will always get the whole mesh in Unity. Go through all the triangles in order to know the edges. Test for each edge if one vertex is inside the plane and one is outside. In that case a cut is necessary. That topic is described in more detail here: http://www.gamasutra.com/blogs/DavidRosen/20091109/3518/How_To_Project_Decals.php .
Beside that, there is or was an open source implementation of an outdated version of Frameshift Decal. I don’t have it, but in the case you find it, it may be useful for you.
Further there is certainly the Decal implementation in Unity’s Bootcamp Demo (not sure about the exact name). In my opinion, it’s a very good implementation. It has the drawback that it was made for one particular use case, meaning it is not a generally usable solution. But you will find about all the required ideas in this implementation. It doesn’t mean you have to use that one, but it may be very useful if you are stuck to check that example and understand how they solved certain issues.