public static Vector3 SculptMesh(Vector3 aVert, Vector3 aNormal, IP_BrushData brushData, float aFalloff)
        {
            switch (brushData.sculptState)
            {
            case IP_SculptState.NormalDir:
                //Normal direction displacement
                aVert += (aNormal * (brushData.opacity * brushData.sculptIntensity) * 0.1f * aFalloff) * (float)brushData.sculptDir;
                break;

            case IP_SculptState.WorldUpDir:
                aVert += (Vector3.up * (brushData.opacity * brushData.sculptIntensity) * 0.1f * aFalloff) * (float)brushData.sculptDir;
                break;

            case IP_SculptState.Flatten:
                aVert = new Vector3(aVert.x, brushData.startHeight, aVert.z);
                break;

            default:
                break;
            }
            return(aVert);
        }
 public static Color PaintMesh(Color aColor, IP_BrushData brushData, float aFalloff)
 {
     aColor = Color.Lerp(aColor, brushData.brushColor, (brushData.opacity * aFalloff) * 0.1f);
     return(aColor);
 }
        public static void HandleBrush(GameObject aGO, Mesh aMesh, Vector3 brushPos, IP_BrushData brushData, IP_VTXPainterState aState)
        {
            if (aGO && aMesh)
            {
                Vector3[] verts   = aMesh.vertices;
                Vector3[] normals = aMesh.normals;


                //Check to see if the Object has colors
                Color[] colors = new Color[aMesh.vertexCount];
                if (aMesh.colors.Length > 0)
                {
                    colors = aMesh.colors;
                }
                else
                {
                    for (int i = 0; i < aMesh.vertexCount; i++)
                    {
                        colors[i] = Color.black;
                    }
                }


                //process the brush action
                for (int i = 0; i < verts.Length; i++)
                {
                    float mag = (aGO.transform.TransformPoint(verts[i]) - brushPos).magnitude;
                    if (mag > brushData.brushSize)
                    {
                        continue;
                    }

                    //Get Falloff
                    float curFalloff = 1f;
                    if (mag > brushData.falloffSize)
                    {
                        curFalloff = (brushData.brushSize / mag) * 0.1f;
                    }

                    switch (aState)
                    {
                    case IP_VTXPainterState.Sculpting:
                        verts[i] = SculptMesh(verts[i], normals[i], brushData, curFalloff);
                        break;

                    case IP_VTXPainterState.Painting:
                        colors[i] = PaintMesh(colors[i], brushData, curFalloff);
                        break;

                    default:
                        break;
                    }

                    //Draw Some Handles
                    Handles.color = Color.yellow;
                }


                //Handle any clean up we need
                switch (aState)
                {
                case IP_VTXPainterState.Sculpting:
                    aMesh.vertices = verts;
                    aMesh.RecalculateBounds();
                    aMesh.RecalculateNormals();
                    break;

                case IP_VTXPainterState.Painting:
                    aMesh.colors = colors;
                    break;

                default:
                    break;
                }
            }
        }