查看: 3022|回复: 1
打印 上一主题 下一主题

[提问] 求高手指点uv旋转如何以中心(0.5,0.5)为轴旋转

[复制链接]

20

主题

5

听众

1090

积分

助理设计师

Rank: 4

纳金币
105
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

跳转到指定楼层
楼主
发表于 2013-9-30 10:24:01 |只看该作者 |倒序浏览
下面这个脚本是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, 下载次数: 342)

原始贴图.JPG

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

3.JPG

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

2.JPG

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

1.JPG

分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

20

主题

5

听众

1090

积分

助理设计师

Rank: 4

纳金币
105
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

沙发
发表于 2013-9-30 11:17:35 |只看该作者
搞定了!各位

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

        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);

        }
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

关闭

站长推荐上一条 /1 下一条

手机版|纳金网 ( 闽ICP备08008928号

GMT+8, 2024-5-1 19:39 , Processed in 0.091327 second(s), 34 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部