Ejemplo n.º 1
0
    static public bool NtfModifyTexture(Vector3 hitPos)
    {
        if (mTexObj == null)
        {
            return(false);
        }

        if (!TexMixBrush.IsBrushOK())
        {
            return(false);
        }

        Vector3 vs = mTarget.GetComponent <Collider>().bounds.size;
        float   fu = (vs.x * 0.5f + hitPos.x) / vs.x;
        float   fv = 1.0f - (vs.z * 0.5f + hitPos.z) / vs.z;


        //float fu = hitPos.x/vs.x;
        //float fv = 1.0f - hitPos.z/vs.z;

        Vector2 uv = new Vector2(fu, fv);

        //	Debug.Log("UV = " + uv.ToString());
        return(NtfModifyTexture(uv));
    }
Ejemplo n.º 2
0
    // 淇?敼娣峰悎姣斾緥鍥诫 杈撳叆鐐瑰嚮鐐箄v, 涔嬪悗鏍规嵁閰嶇疆澶勭悊
    static public bool NtfModifyTexture(Vector2 uv)
    {
        if (mTexObj == null)
        {
            return(false);
        }

        if (!TexMixBrush.IsBrushOK())
        {
            return(false);
        }
        Texture2D brushTex = TexMixBrush.GetTexObj();

        int mBrushW = brushTex.width / 2;
        int mBrushH = brushTex.height / 2;

        int cx = (int)(uv.x * mTexObj.width);
        int cy = (int)(uv.y * mTexObj.height);

        int xMin = Mathf.Max(0, cx - mBrushW);
        int yMin = Mathf.Max(0, cy - mBrushH);

        int xMax = Mathf.Min(mTexObj.width - 1, cx + mBrushW);
        int yMax = Mathf.Min(mTexObj.height - 1, cy + mBrushH);

        int   myW  = xMax - xMin;
        int   myH  = yMax - yMin;
        float fVal = mbErase ? -mfValue : mfValue;

        Color[] cold = mTexObj.GetPixels(xMin, yMin, myW, myH, 0);

        if (cold.Length <= 0)
        {
            return(false);
        }

        TexMixCMD cmd = new TexMixCMD();

        cmd.mMinX = xMin;
        cmd.mMinY = yMin;
        cmd.mRctW = myW;
        cmd.mRctH = myH;
        cmd.mBack = new Color[cold.Length];
        cmd.mNext = new Color[cold.Length];

        Color[] cols = TexMixBrush.GetColors();
        for (int i = 0; i < cold.Length; ++i)
        {
            cmd.mBack[i].r = cold[i].r;
            cmd.mBack[i].g = cold[i].g;
            cmd.mBack[i].b = cold[i].b;
            cmd.mBack[i].a = cold[i].a;
            //Debug.Log(cmd.mBack[i]);
            float fval = cold[i][mMixLvl] + cols[i].a * fVal;
            cold[i][mMixLvl] = Mathf.Clamp(fval, 0.0f, 1.0f);

            cmd.mNext[i].r = cold[i].r;
            cmd.mNext[i].g = cold[i].g;
            cmd.mNext[i].b = cold[i].b;
            cmd.mNext[i].a = cold[i].a;
        }

        mUndoMng.NtfAddUndoCmd(cmd);

        mTexObj.SetPixels(xMin, yMin, myW, myH, cold, 0);
        mTexObj.Apply();
        mTarget.GetComponent <Renderer>().material.SetTexture("_TexMix", mTexObj);
        return(true);
    }