InvertedSphere

Unity3D/C# 2021. 7. 30. 14:01
반응형

https://gist.github.com/unity3dcollege/d059b376f7461d908107e97534ed9e04

 

InvertedSphere.cs

GitHub Gist: instantly share code, notes, and snippets.

gist.github.com

 

 

 

 

 

Normal 뒤집기 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof(MeshFilter))]
public class ReverseNormal : MonoBehaviour
{
    private void Start()
    {
        var filter = this.GetComponent<MeshFilter>();
        if (filter != null) {
            var mesh = filter.mesh;

            Vector3[] normals = mesh.normals;
            for (int i = 0; i < normals.Length; i++) {
                normals[i] = -normals[i];
            }
            mesh.normals = normals;

            for (int m = 0; m < mesh.subMeshCount; m++) {
                int[] triangles = mesh.GetTriangles(m);
                for (int i = 0; i < triangles.Length; i += 3) {
                    int temp = triangles[i + 0];
                    triangles[i + 0] = triangles[i + 1];
                    triangles[i + 1] = temp;
                }
                mesh.SetTriangles(triangles, m);
            }

        }

        
    }
}
반응형

'Unity3D > C#' 카테고리의 다른 글

C# 강좌 Day-02 (변수와 값)  (0) 2021.08.14
C# 강좌 Day-01 (HelloWorld)  (0) 2021.08.14
싱글톤(Singletone) vs C#정적클래스(static class) 차이점  (0) 2021.03.25
2048  (0) 2021.03.19
IComparable.CompareTo(Object) 메서드  (0) 2021.03.16
: