Пример #1
0
    //[SerializeField]
    //Toggle translate, rotate, scale;
    //Toggle currentToggle;

    //[SerializeField]
    //Slider xSlider, ySlider, zSlider;

    public void UpdateTexture(Vector2 translation, float rotation, Vector2 scale)
    {
        //curTranslation += translation;
        //curScale *= scale;
        //curRotation += rotation;
        //Debug.Log("New translation: " + curTranslation + "; New rotation: " + curRotation + "; New scale: " + curScale);
        Matrix3x3 trsMatrix       = Matrix3x3Helpers.CreateTRS(translation, rotation, scale);
        Matrix3x3 translateMatrix = Matrix3x3Helpers.CreateTranslation(translation);
        Matrix3x3 rotateMatrix    = Matrix3x3Helpers.CreateRotation(rotation);
        Matrix3x3 scaleMatrix     = Matrix3x3Helpers.CreateScale(scale);

        Mesh theMesh = GetComponent <MeshFilter>().mesh;

        Vector2[] uv = theMesh.uv;

        for (int i = 0; i < uv.Length; ++i)
        {
            //    uv[i] = trsMatrix * uv[i];
            uv[i] = translateMatrix * uv[i];
            uv[i] = rotateMatrix * uv[i];
            uv[i] = scaleMatrix * uv[i];
        }
        trsMatrix = Matrix3x3.identity;

        theMesh.uv = uv;
    }
    public void Rotate(float r)
    {
        rotate += r;
        Mesh theMesh = GetComponent <MeshFilter>().mesh;

        Vector2[] uv       = theMesh.uv;
        Matrix3x3 myMatrix = Matrix3x3Helpers.CreateRotation(r);

        for (int i = 0; i < uv.Length; i++)
        {
            uv[i] = Matrix3x3.MultiplyVector2(myMatrix, uv[i]);
        }
        theMesh.uv = uv;
    }
    public void Translate(Vector2 t)
    {
        translate += t;
        Mesh theMesh = GetComponent <MeshFilter>().mesh;

        Vector2[] uv       = theMesh.uv;
        Matrix3x3 myMatrix = Matrix3x3Helpers.CreateTranslation(t);

        for (int i = 0; i < uv.Length; i++)
        {
            uv[i] = Matrix3x3.MultiplyVector2(myMatrix, uv[i]);
        }
        theMesh.uv = uv;
    }
Пример #4
0
    void QuadTextureTRS(ref Vector2[] uv)
    {
        float     rot         = rotation + rdelta;
        Vector2   translation = new Vector2(xTranslation, yTranslation);
        Vector2   scale       = new Vector2(xScale, yScale);
        Matrix3x3 matrixTRS   = Matrix3x3Helpers.CreateTRS(translation, rot, scale);

        for (int i = 0, y = 0; y <= ySize; y++)
        {
            for (int x = 0; x <= xSize; x++, i++)
            {
                uv[i] = Matrix3x3.MultiplyVector2(matrixTRS, originUV[i]);
            }
        }
    }
    public void Scale(Vector2 s)
    {
        scale.x *= s.x;
        scale.y *= s.y;
        Mesh theMesh = GetComponent <MeshFilter>().mesh;

        Vector2[] uv       = theMesh.uv;
        Matrix3x3 myMatrix = Matrix3x3Helpers.CreateScale(s);

        for (int i = 0; i < uv.Length; i++)
        {
            uv[i] = Matrix3x3.MultiplyVector2(myMatrix, uv[i]);
        }
        theMesh.uv = uv;
    }
Пример #6
0
    void ChangeTextureTransform(Vector2[] uv)
    {
        // Calculate the texture transform using the given helpers
        Matrix3x3 translation = Matrix3x3Helpers.CreateTranslation(new Vector2(UVtransform.localPosition.x, UVtransform.localPosition.y));
        Matrix3x3 scale       = Matrix3x3Helpers.CreateScale(new Vector2(UVtransform.localScale.x, UVtransform.localScale.y));
        Matrix3x3 rotation    = Matrix3x3Helpers.CreateRotation(UVtransform.localRotation.eulerAngles.z);
        Matrix3x3 m           = translation * rotation * scale;

        ComputeUV(uv);

        for (int i = 0; i < uv.Length; ++i)
        {
            uv[i] = Matrix3x3.MultiplyVector2(m, uv[i]);
        }
    }
Пример #7
0
    // Use this for initialization
    void UpdateTextureTransform(Vector2[] uv)
    {
        Matrix3x3 t = Matrix3x3Helpers.CreateTranslation(new
                                                         Vector2(mTextureTransform.localPosition.x, mTextureTransform.localPosition.y));
        Matrix3x3 s = Matrix3x3Helpers.CreateScale(new
                                                   Vector2(mTextureTransform.localScale.x, mTextureTransform.localScale.y));
        Matrix3x3 r = Matrix3x3Helpers.CreateRotation(mTextureTransform.localRotation.eulerAngles.z);
        Matrix3x3 m = t * r * s;

        ComputeUV(uv);
        for (int i = 0; i < uv.Length; i++)
        {
            uv[i] = Matrix3x3.MultiplyVector2(m, uv[i]);
        }
    }
    // Creates a 3x3Matrix to calculate get new UV values from the original values
    private void TransformTexture()
    {
        Matrix3x3 TRS = Matrix3x3Helpers.CreateTRS(new Vector2(translationX, translationY), rotationZ, new Vector2(scaleX, scaleY));

        if (originalUV.Length != myMesh.uv.Length)
        {
            originalUV = myMesh.uv;
        }
        Vector2[] uv = new Vector2[originalUV.Length];
        for (int i = 0; i < uv.Length; i++)
        {
            uv[i] = TRS * originalUV[i];
        }
        myMesh.uv = uv;
    }
Пример #9
0
    private void SetSelectedXform(ref Vector2 p, ref float q)
    {
        if (T.isOn)
        {
            float temp1, temp2;
            temp1 = tx;
            temp2 = ty;
            tx    = p.x;
            ty    = p.y;
            p.x   = p.x - temp1;
            p.y   = p.y - temp2;

            //mSelected.localPosition = p;
            Mesh      theMesh = MyMesh.GetComponent <MeshFilter>().mesh;
            Vector2[] uv      = theMesh.uv;
            Matrix3x3 m       = Matrix3x3Helpers.CreateTRS(p, 0, Vector2.one);
            for (int i = 0; i < uv.Length; i++)
            {
                uv[i] = Matrix3x3.MultiplyVector3(m, uv[i]);
            }
            theMesh.uv = uv;
        }
        else if (S.isOn && p.x > 0 && p.y > 0)
        {
            sx = p.x;
            sy = p.y;
            Mesh      theMesh    = MyMesh.GetComponent <MeshFilter>().mesh;
            Vector2[] uv         = theMesh.uv;
            float     x2         = 0 + tx;
            float     y2         = 0 + ty;
            float     resolution = Mathf.Sqrt(uv.Length);
            for (int i = 0; i < uv.Length; i++)
            {
                if (x2 > p.x + tx)
                {
                    y2 += (p.y / ((float)resolution - 1));
                    x2  = 0 + tx;
                }
                uv[i] = new Vector2(x2, y2);
                x2   += (p.x / ((float)resolution - 1));
            }
            theMesh.uv = uv;

            /*//mSelected.localScale = p;
             * Mesh theMesh = MyMesh.GetComponent<MeshFilter>().mesh;
             * Vector2[] uv = theMesh.uv;
             * Matrix3x3 m = Matrix3x3Helpers.CreateTRS(Vector2.zero, 0, p);
             * for (int i = 0; i < uv.Length; i++)
             * {
             *  uv[i] = Matrix3x3.MultiplyVector3(m, uv[i]);
             * }
             * theMesh.uv = uv;*/
        }
        else
        {
            //mSelected.localRotation *= q;
            Mesh      theMesh = MyMesh.GetComponent <MeshFilter>().mesh;
            Vector2[] uv      = theMesh.uv;
            Matrix3x3 m       = Matrix3x3Helpers.CreateTRS(Vector2.zero, q, Vector2.one);
            for (int i = 0; i < uv.Length; i++)
            {
                uv[i] = Matrix3x3.MultiplyVector3(m, uv[i]);
            }
            theMesh.uv = uv;
        }
    }