User Rating: 0 / 5

Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive
 

Create Custom Mesh Post-Processor

Mesh post-processor can be used to alter the geometry after the decal has been projected. 

The method below makes use of Unity's built-in combine functionality to get the job done. Note that if the keepMaterials argument is set to true and the decals use different materials you may not be able to reduce draw calls.

using UnityEngine;
using ch.sycoforge.Decal.Projectors.Geometry;

public class CustomProcessor : IMeshProcessor 
{
    public void Process(IMesh mesh)
    {
        // Iterate over triangles
        for (int i = 0; i < mesh.TriangleIndices.Count - 3; i += 3)
        {
            int t1 = mesh.TriangleIndices[i];
            int t2 = mesh.TriangleIndices[i + 1];
            int t3 = mesh.TriangleIndices[i + 2];

            Vector3 a = mesh.Vertices[t1];
            Vector3 b = mesh.Vertices[t2];
            Vector3 c = mesh.Vertices[t3];

            Vector3 ab = b - a;
            Vector3 ac = c - a;

            // Make something with data
        
        }
    }
}

Each custom processor needs to implement the IMeshProcessor interface.

 

CustomProcessor processor = new CustomProcessor();
...
EasyDecal decal = EasyDecal.ProjectAt(DecalPrefab.gameObject, parent, position, averageNormal);
decal.MeshProcessors.Add(processor);

The custom processor can be hooked to the decal instance as shown in the snippet above.