Skip to content

Instantly share code, notes, and snippets.

@tarukosu
Created May 28, 2017 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tarukosu/bf842cfb4e94488bb7765cee461ed9f0 to your computer and use it in GitHub Desktop.
Save tarukosu/bf842cfb4e94488bb7765cee461ed9f0 to your computer and use it in GitHub Desktop.
MeshReproject.cs
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