Пример #1
0
        void InitBrushes()
        {
            heightBrush = new HeightBrush();
            grassBrush  = new GrassBrush();
            noneBrush   = new NoneBrush();

            currentBrushStrategy = heightBrush;
        }
    //This Function is called when you click the menu entry
    private static void CreateGrassBrush()
    {
        string     fileName = "GrassBrush";
        GrassBrush mytb     = ScriptableObject.CreateInstance <GrassBrush>();

        mytb.name = fileName + ".asset";
        AssetDatabase.CreateAsset(mytb, "Assets/" + mytb.name + "");
    }
Пример #3
0
    public static void DrawPoint(Texture2D tex, Vector2 uv, GrassBrush brush)
    {
        int w = tex.width;
        int h = tex.height;
        int x = 0;
        int y = 0;

        Undo.RegisterCompleteObjectUndo(tex, "");
        var colorStartBuffer = tex.GetPixels();

        TexUV2Index(w, h, uv, ref x, ref y);
        int count = (int)(brush.texPaint01Size * w * 1.5f);


        for (int i = -count; i < count; i++)
        {
            for (int j = -count; j < count; j++)
            {
                int _x = x + i;
                int _y = y + j;
                if (_x < 0 || _x >= w)
                {
                    continue;
                }
                if (_y < 0 || _y >= h)
                {
                    continue;
                }

                Vector2 uv2 = TexUV(w, h, _x, _y);
                float   dis = Vector2.Distance(uv, uv2);

                if (dis < brush.texPaint01Size)
                {
                    int   index = XYtoIndex(w, h, _x, _y);
                    var   c     = colorStartBuffer [index];
                    float f     = 0;
                    float mod   = brush.force;
                    if (brush.soft)
                    {
                        float pcg = dis / brush.texPaint01Size;
                        mod *= 1 - Mathf.Clamp01(pcg - (1 - brush.softEdge)) / brush.softEdge;
                    }
                    if (brush.mode == GrassBrushMode.Paint)
                    {
                        f = c.r + mod;
                    }
                    else if (brush.mode == GrassBrushMode.Erase)
                    {
                        f = c.r - mod;
                    }
                    f = Mathf.Clamp01(f);


                    colorStartBuffer [index] = new Color(f, f, f, f);
                }
            }
        }
        tex.SetPixels(colorStartBuffer);
        tex.Apply();



//		colorStartBuffer = tex.GetPixels ();
//		brushBuffer = new float[tex.width, tex.height];
//
//		SWUndo.RegisterCompleteObjectUndo (tex);
//		SWTexThread_TexDrawPoint t = new SWTexThread_TexDrawPoint (tex, _brush);
//		t.Process (_uv);
    }
Пример #4
0
 void OnEnable()
 {
     _target = target as GrassBrush;
 }