资源大湿 发表于 2018-8-1 17:37

反向翻转法线实现一个天空盒

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;
                tris = tris;
                tris = temp;
            }
            mesh.SetTriangles(tris, i);
      }
    }

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

xunlizhimeng 发表于 2018-9-16 22:06

很不错

oushenu3d 发表于 2018-9-16 21:45

好帖就是要顶

3D新手 发表于 2018-9-16 21:46

顶顶多好

bluetimeaq 发表于 2018-9-16 22:08

说的非常好

lufdidi 发表于 2018-9-16 22:24

LZ真是人才
页: [1]
查看完整版本: 反向翻转法线实现一个天空盒