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();
    }
}

First Cube

By Plump Helmet Studios on

First Cube

And so, with the end of the second day in operation, Plump Helmet Studios produces it's first cube. The beginnings are humble, the achievements small, but every great journey begins with a simple step.

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

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

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

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

Hello World

By Plump Helmet Studios on

Hello World

The Plump Helmet Studios website is currently under construction. In time, it will show case our progress towards making some beautiful indie games. Right now, though, it is but a seed. Here's to the future!

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

public class HelloWorld : MonoBehaviour
{
    Mesh mesh;
    List<Vector3> vertices;
    List<int> triangles;
    int[][] helloWorldMessageData;
    Vector3 offset;

    void Awake()
    {
        mesh = GetComponent<MeshFilter>().mesh;
        vertices = new List<Vector3>();
        triangles = new List<int>();
        helloWorldMessageData = new int[][] {
            new int[] { 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0 },
            new int[] { 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1 },
            new int[] { 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1 },
            new int[] { 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1 },
            new int[] { 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0 }

        };
        offset = new Vector3(helloWorldMessageData[0].Length / 2, 0, helloWorldMessageData.Length / 2);
    }

    void Start()
    {
        GenerateMeshData();
        CreateNewMesh();
    }

    void GenerateMeshData()
    {
        for (int z = 0; z < helloWorldMessageData.Length; z++)
        {
            for (int x = 0; x < helloWorldMessageData[z].Length; x++)
            {
                if (helloWorldMessageData[z][x] == 1)
                {
                    GenerateQuad(z, x);
                }
            }
        }
    }

    void GenerateQuad(int z, int x)
    {
        int vIdx = vertices.Count;
        vertices.Add(new Vector3(x - offset.x, 0, z - offset.z));
        vertices.Add(new Vector3(x - offset.x, 0, z - offset.z + 1));
        vertices.Add(new Vector3(x - offset.x + 1, 0, z - offset.z));
        vertices.Add(new Vector3(x - offset.x + 1, 0, z - offset.z + 1));
        triangles.AddRange(new int[] { vIdx, vIdx + 1, vIdx + 2 });
        triangles.AddRange(new int[] { vIdx + 2, vIdx + 1, vIdx + 3 });
    }

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