Hy guis i’m working on a marching cube.
I have made a procedural cube with only 8tris, but i need to make it with 24tris and i have problem hear it is the 8tris cube code;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class CubeCreator : MonoBehaviour {
Vector3[] MeshVertex;
Vector2[] MeshUv;
int[] MeshTriangles;
public float MeshX;
public float MeshY;
public float MeshZ;
public Mesh TheMesh;
public Vector3[] Vertex;
// Use this for initialization
void Start () {
DrawCube();
}
void DrawCube () {
TheMesh = new Mesh ();
GetComponent<MeshFilter>().mesh = TheMesh;
GetComponent<MeshCollider>().sharedMesh = TheMesh;
TheMesh.Clear();
Vertex[0] = new Vector3(0,0,0);
Vertex[1] = new Vector3(MeshX,0,0);
Vertex[2] = new Vector3(0,MeshY,0);
Vertex[3] = new Vector3(0,0,MeshZ);
Vertex[4] = new Vector3(MeshX,0,MeshZ);
Vertex[5] = new Vector3(MeshX,MeshY,0);
Vertex[6] = new Vector3(0,MeshY,MeshZ);
Vertex[7] = new Vector3(MeshX,MeshY,MeshZ);
MeshVertex = new Vector3[]{Vertex[0],Vertex[1],Vertex[2],Vertex[3],Vertex[4],Vertex[5],Vertex[6],Vertex[7]};
MeshTriangles = new int[]{
//Frontale
0,2,1, 1,2,5,
//Faccia Giù
3,0,1, 1,4,3,
//Faccia Destra
0,3,2, 2,3,6,
//Faccia Sinistra
1,5,4, 5,7,4,
//Faccia Dietra
6,3,4, 6,4,7,
//Faccia Su
6,5,2, 7,5,6
};
TheMesh.vertices= MeshVertex;
TheMesh.triangles = MeshTriangles;
TheMesh.uv = MeshUv;
TheMesh.RecalculateNormals();
TheMesh.RecalculateBounds();
TheMesh.Optimize();
renderer.material.color = Color.green;
}
}