//[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;
    }
Example #3
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]);
        }
    }
Example #4
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]);
        }
    }