找回密码
 立即注册
查看: 1851|回复: 5

[基础] 反向翻转法线实现一个天空盒

[复制链接]
发表于 2018-8-1 17:37 | 显示全部楼层 |阅读模式
资源信息 Tutorial Information
教程名称: 反向翻转法线实现一个天空盒(发帖教程)
适用引擎: Unity3D  (适用引擎,为空默认为Unity)
教程语种: 中文
教程等级: 1
教程格式: 图文(请用IE9以上浏览器访问本版块)
教程作者: 转载自互联网 (如有问题请短消息联系作者或发表回复)
下载地址: (兑换积分)
点击查看原图
美丽分割线
[code=csharp]using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// made by u3dchina.com
/// </summary>
public class FlipNormals : MonoBehaviour
{
    // Use this for initialization
    void Start()
    {
        Mesh mesh = this.GetComponent<MeshFilter>().mesh;
        Vector3[] normals = mesh.normals;
        for (int i = 0, lenI = normals.Length; i < lenI; i++)
        {
            normals = -1 * normals;
        }

        mesh.normals = normals;
        Debug.Log("subMeshCount:"+mesh.subMeshCount);
        for (int i = 0, lenI = mesh.subMeshCount; i < lenI; i++)
        {
            int[] tris = mesh.GetTriangles(i);

            for (int j = 0, lenJ = tris.Length; j < lenJ; j+=3)
            {
                int temp = tris[j];
                tris[j] = tris[j + 1];
                tris[j + 1] = temp;
            }
            mesh.SetTriangles(tris, i);
        }
    }

    // Update is called once per frame
    void Update()
    {
    }
}[/code]
创建一个character controller、plane、及一个sphere当天空盒,把该脚本拉到sphere就ok了。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
发表于 2018-9-16 22:06 | 显示全部楼层
很不错
发表于 2018-9-16 21:45 | 显示全部楼层
好帖就是要顶
发表于 2018-9-16 21:46 | 显示全部楼层
顶顶多好
发表于 2018-9-16 22:08 | 显示全部楼层
说的非常好
发表于 2018-9-16 22:24 | 显示全部楼层
LZ真是人才
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-4-24 13:07 , Processed in 0.123095 second(s), 31 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表