Hi Guys.
I am trying to generate a mesh through some points, for now I’m just using game objects and setting the vertices to that, but eventually once I have it working in basic form I will get more advanced and dynamically feed vector3s to it to constantly generate my mesh.
But what I don’t really understand is triangles :S can someone help me out?
Here is my code: it should create a plane sort of mesh through 6 points, it does 4 of them fine, but wort do six:
using UnityEngine;
using System.Collections;
//PlaneExtrude1
[RequireComponent(typeof(MeshFilter),typeof(MeshRenderer))]
public class Extrusion : MonoBehaviour
{
public Transform Point1;
public Transform Point2;
public Transform Point3;
public Transform Point4;
public Transform Point5;
public Transform Point6;
private Mesh m_Mesh = null;
void Start ()
{
m_Mesh = new Mesh();
Vector3[] vertices = new Vector3[6];
int[] tris = new int[9];
for (int i = 0;i<4;i++)
vertices[i] = new Vector3();
tris[0] = 0;
tris[1] = 1;
tris[2] = 2;
tris[3] = 2;
tris[4] = 3;
tris[5] = 0;
tris[6] = 0;
tris[7] = 1;
tris[8] = 2;
m_Mesh.vertices = vertices;
m_Mesh.triangles = tris;
MeshFilter filter = GetComponent<MeshFilter>();
filter.sharedMesh = m_Mesh;
}
public Vector3[] newVertices;
void UpdateMesh(Vector3 P1, Vector3 P2)
{
//Vector3[] newVertices = m_Mesh.vertices;
newVertices = m_Mesh.vertices;
//vertices[2] = P2 + newDir;
//vertices[3] = P1 + newDir;
newVertices[0] = P1;
newVertices[1] = P2;
newVertices[2] = Point3.transform.position;
newVertices[3] = Point4.transform.position;
newVertices[4] = Point5.transform.position;
newVertices[5] = Point6.transform.position;
m_Mesh.vertices = newVertices;
m_Mesh.RecalculateBounds();
m_Mesh.RecalculateNormals();
}
void Update ()
{
UpdateMesh(Point1.position, Point2.position);
}
}
Any help would be appreciated! Thanks!