﻿using UnityEngine;
using System.Collections;

public class MeshWireFrame : MonoBehaviour {

	void Awake () {
		MeshFilter meshFilter = GetComponent<MeshFilter>();
		int[] triangles = meshFilter.mesh.GetTriangles (0);
		meshFilter.mesh.SetIndices(MakeIndices(triangles), MeshTopology.Lines, 0);
	}

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}

	public int[] MakeIndices(int[] triangles)
	{
		int[] indices = new int[2 * triangles.Length];
		int i = 0;
		for( int t = 0; t < triangles.Length; t+=3 )
		{
			indices[i++] = triangles[t];        //start
			indices[i++] = triangles[t + 1];   //end
			indices[i++] = triangles[t + 1];   //start
			indices[i++] = triangles[t + 2];   //end
			indices[i++] = triangles[t + 2];   //start
			indices[i++] = triangles[t];        //end
		}
		return indices;
	}
}
