Last active
February 8, 2018 09:38
-
-
Save andybak/d458751b92cc86c44bc44f8540a8b29b to your computer and use it in GitHub Desktop.
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 System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
[ExecuteInEditMode] . // Runs the code in the editor as well as in Play mode | |
[RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))] . // Create the required components when you first add the script | |
public class Tetra : MonoBehaviour { | |
// Use this for initialization | |
void Start () { | |
// Get the meshfilter component from the current gameobject | |
MeshFilter meshFilter = GetComponent<MeshFilter>(); | |
// Create an empty mesh if there isn't already one on the meshfilter | |
mesh = new Mesh(); | |
// Calculate the vertex positions | |
Vector3 p0 = new Vector3(0,0,0); | |
Vector3 p1 = new Vector3(1,0,0); | |
Vector3 p2 = new Vector3(0.5f,0,Mathf.Sqrt(0.75f)); | |
Vector3 p3 = new Vector3(0.5f,Mathf.Sqrt(0.75f),Mathf.Sqrt(0.75f)/3); | |
// Assign the vertices to the mesh | |
mesh.vertices = new Vector3[]{ | |
p0,p1,p2, | |
p0,p2,p3, | |
p2,p1,p3, | |
p0,p3,p1 | |
}; | |
mesh.triangles = new int[]{ | |
0,1,2, | |
3,4,5, | |
6,7,8, | |
9,10,11 | |
}; | |
mesh.RecalculateNormals(); | |
mesh.RecalculateBounds(); | |
meshFilter.sharedMesh = mesh; | |
} | |
// Update is called once per frame | |
void Update () { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment