Created
May 28, 2017 07:41
-
-
Save tarukosu/bf842cfb4e94488bb7765cee461ed9f0 to your computer and use it in GitHub Desktop.
MeshReproject.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class MeshReproject : MonoBehaviour | |
{ | |
public Camera ProjectionPerspective; | |
Mesh mesh; | |
Vector3[] vertices; | |
Vector2[] uvs; | |
void Start() | |
{ | |
mesh = GetComponent<MeshFilter>().mesh; | |
mesh.MarkDynamic(); | |
} | |
void Update() | |
{ | |
mesh = GetComponent<MeshFilter>().mesh; | |
vertices = mesh.vertices; | |
uvs = new Vector2[vertices.Length]; | |
Vector2 ScreenPosition; | |
for (int i = 0; i < uvs.Length; i++) | |
{ | |
ScreenPosition = ProjectionPerspective.WorldToViewportPoint(transform.TransformPoint(vertices[i])); | |
uvs[i].Set(ScreenPosition.x, ScreenPosition.y); | |
} | |
mesh.uv = uvs; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment