Eight Triangle Quad

By Plump Helmet Studios on

Eight Triangle Quad

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))]
public class SuperQuad : MonoBehaviour
{
    Mesh mesh;
    Vector3[] vertices;
    int[] triangles;

    void Awake()
    {
        mesh = GetComponent<MeshFilter>().mesh;
        vertices = new Vector3[] {
            new Vector3(0, 0, 0),
            new Vector3(1, 0, 0),
            new Vector3(2, 0, 0),
            new Vector3(2, 1, 0),
            new Vector3(2, 2, 0),
            new Vector3(1, 2, 0),
            new Vector3(0, 2, 0),
            new Vector3(0, 1, 0),
            new Vector3(1, 1, 0)
        };
        triangles = new int[] {
            0, 8, 1, // bottom left
            0, 7, 8,
            1, 8, 2, // bottom right
            2, 8, 3,
            3, 8, 4, // top right
            8, 5, 4,
            7, 6, 8, // top left
            8, 6, 5
        };
    }

    void Start()
    {
        mesh.Clear();
        mesh.vertices = vertices;
        mesh.triangles = triangles;
        mesh.RecalculateNormals();
    }
}