Example #1
0
    void PaintVertexColors()
    {
        if (curMesh)
        {
            Vector3[] verts  = curMesh.vertices;
            Color[]   colors = new Color[0];

            if (curMesh.colors.Length > 0)
            {
                colors = curMesh.colors;
            }
            else
            {
                colors = new Color[verts.Length];
            }

            for (int i = 0; i < verts.Length; i++)
            {
                Vector3 vertPos = curGO.transform.TransformPoint(verts[i]);
                float   sqrMag  = (vertPos - curHit.point).sqrMagnitude;
                if (sqrMag > brushSize)
                {
                    continue;
                }

                float falloff = FindMesh.LinearFalloff(sqrMag, brushSize);
                falloff   = Mathf.Pow(falloff, brushFalloff * 3f) * brushOpacity;
                colors[i] = foregroundColor;
                //Falloff på paintin
                //colors[i] = FindMesh.VtxColorLerp(colors[i], foregroundColor, falloff);
            }

            curMesh.colors = colors;
        }
    }
Example #2
0
    void PaintVertexColors()
    {
        if (curMesh)
        {
            //Find the vertices off the current mesh and store its current colors in an array
            Vector3[] verts  = curMesh.vertices;
            Color[]   colors = new Color[0];

            if (curMesh.colors.Length > 0)
            {
                colors = curMesh.colors;
            }
            else
            {
                colors = new Color[verts.Length];
            }

            for (int i = 0; i < verts.Length; i++)
            {
                // square the distance we compare with & get the transformPoints off the vertices
                Vector3 vertPos = curGO.transform.TransformPoint(verts[i]);
                float   sqrMag  = (vertPos - curHit.point).sqrMagnitude;
                if (sqrMag > brushSize)
                {
                    continue;
                }

                //Falloff to make it more realistic
                float falloff = FindMesh.LinearFalloff(sqrMag, brushSize);
                falloff   = Mathf.Pow(falloff, brushFalloff * 3f) * brushOpacity;
                colors[i] = FindMesh.VtxColorLerp(colors[i], foregroundColor, falloff);
            }
            curMesh.colors = colors;
        }
    }