ReverseNormals

From Unify Community Wiki
Revision as of 13:54, 8 November 2007 by Opless (Talk | contribs)

Jump to: navigation, search

Author: Joachim Ante

Description

This script lets you reverse normals. The normals will only be reversed in playmode so it will still look inverted when viewing in edit mode.

Usage

Attach the script to the mesh you want normals to be reversed

CSharp- ReverseNormals.cs

<csharp> using UnityEngine; using System.Collections;

[RequireComponent(typeof(MeshFilter))] public class ReverseNormals : MonoBehaviour {

void Start () { MeshFilter filter = GetComponent(typeof (MeshFilter)) as MeshFilter; if (filter != null) { Mesh 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); } } } } </csharp>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox