using UnityEngine;
using System.Collections;
public class doubleSideShader : MonoBehaviour {
// Use this for initialization
void Start () {
Mesh mesh = GetComponent().mesh;
Vector3[] vertices = mesh.vertices;
Vector2[] uv = mesh.uv;
Vector3[] normals = mesh.normals;
int szV = vertices.Length;
Vector3[] newVerts = new Vector3[szV * 2];
Vector2[] newUv = new Vector2[szV * 2];
Vector3[] newNorms = new Vector3[szV * 2];
for (int j = 0; j < szV; j++)
{
// duplicate vertices and uvs:
newVerts[j] = newVerts[j + szV] = vertices[j];
newUv[j] = newUv[j + szV] = uv[j];
// copy the original normals...
newNorms[j] = normals[j];
// and revert the new ones
newNorms[j + szV] = -normals[j];
}
int[] triangles = mesh.triangles;
int szT = triangles.Length;
int[] newTris = new int[szT * 2]; // double the triangles
for (int i = 0, j = 0; i < szT; i += 3)
{
// copy the original triangle
newTris[i] = triangles[i];
newTris[i + 1] = triangles[i + 1];
newTris[i + 2] = triangles[i + 2];
// save the new reversed triangle
j = i + szT;
newTris[j] = triangles[i] + szV;
newTris[j + 2] = triangles[i + 1] + szV;
newTris[j + 1] = triangles[i + 2] + szV;
}
mesh.vertices = newVerts;
mesh.uv = newUv;
mesh.normals = newNorms;
mesh.triangles = newTris; // assign triangles last!
}
// Update is called once per frame
void Update () {
}
}
2015年11月12日 星期四
Unity - 攝影機 看到 物體的內部
在需要被看到內部的物體使用此Script
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言