纳金网

标题: 求高手指点uv旋转如何以中心(0.5,0.5)为轴旋转 [打印本页]

作者: herry7x    时间: 2013-9-30 10:24
标题: 求高手指点uv旋转如何以中心(0.5,0.5)为轴旋转
下面这个脚本是uv旋转脚本,不过旋转的效果不是在中心,而是以左上角为中心旋转。求高人指点,下面的代码如何修改可以达到沿中心旋转的目的。

        var rotateSpeed = 30;
        var texture : Texture;

        function Start() {
                // Create a new material with a shader
                // that rotates the texture. Texture rotation
                // is performed with a _Rotation matrix.
                var m : Material = new Material (
                        "Shader \"Rotating Texture\" {" +
                        "Properties { _MainTex (\"Base\", 2D) = \"white\" {} }" +
                        "SubShader {" +
                        "        Pass {" +
                        "                Material { Diffuse (1,1,1,0) Ambient (1,1,1,0) }" +
                        "                Lighting On" +
                        "                SetTexture [_MainTex] {" +
                        "                        matrix [_Rotation]" +
                        "                        combine texture * primary double, texture" +
                        "                }" +
                        "        }" +
                        "}" +
                        "}"
                );
                m.mainTexture = texture;
                renderer.material = m;
        }

        function Update() {
                // Construct a rotation matrix and set it for the shader
                var rot = Quaternion.Euler (0, 0, Time.time * rotateSpeed);
                var m = Matrix4x4.TRS (Vector3(0.5,0.5,0), rot, Vector3(1,1,1) );
                renderer.material.SetMatrix ("_Rotation", m);

        }

原始贴图.JPG (24.26 KB, 下载次数: 396)

原始贴图.JPG

3.JPG (24.94 KB, 下载次数: 387)

3.JPG

2.JPG (24.72 KB, 下载次数: 380)

2.JPG

1.JPG (24.23 KB, 下载次数: 422)

1.JPG


作者: herry7x    时间: 2013-9-30 11:17
搞定了!各位

代码在下面,给大家分享一下吧。

        var rotateSpeed = 30;
        var texture : Texture;

        function Start() {
                // Create a new material with a shader
                // that rotates the texture. Texture rotation
                // is performed with a _Rotation matrix.
                var m : Material = new Material (
                        "Shader \"Rotating Texture\" {" +
                        "roperties { _MainTex (\"Base\", 2D) = \"white\" {} }" +
                        "SubShader {" +
                        "        Pass {" +
                        "                Material { Diffuse (1,1,1,0) Ambient (1,1,1,0) }" +
                        "                Lighting On" +
                        "                SetTexture [_MainTex] {" +
                        "                        matrix [_Rotation]" +
                        "                        combine texture * primary double, texture" +
                        "                }" +
                        "        }" +
                        "}" +
                        "}"
                );
                m.mainTexture = texture;
                renderer.material = m;
        }

        function Update() {
                // Construct a rotation matrix and set it for the shader
                var rot = Quaternion.Euler (0, 0, Time.time * rotateSpeed);
                var m = Matrix4x4.TRS (Vector3(0.5,0.5,0), rot, Vector3(1,1,1) );
                var n = Matrix4x4.TRS (Vector3(-0.5,-0.5,0), Quaternion.identity, Vector3(1,1,1) );
                renderer.material.SetMatrix ("_Rotation", m*n);

        }




欢迎光临 纳金网 (http://wwww.narkii.com/club/) Powered by Discuz! X2.5