cube based enging

hey everyone this is my first time to post a question on the unity3d ask forum :smiley: anyway i’ve been working on a cubical based engine and the chunks seems to take long to load when they are more than 666 but it takes about 4-5 seconds to load a chunk 121212 size ! and no matter how i adjust my code to had smaller log() ! it still take the same amount of time ! i used arrays to create the vertices and then throw them with the triangles arrays to the an empty GO mesh ! if u need any farther info ask away and here is all the code used for the chunk and all related classes

face Class

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

public class TestFace {
	Vector3 vertex1;
	Vector3 vertex2;
	Vector3 vertex3;
	Vector3 vertex4;

	public TestFace(Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4){
		vertex1 = v1;
		vertex2 = v2;
		vertex3 = v3;
		vertex4 = v4;
		//Debug.Log ("("+v1.ToString ()+":"+v2.ToString ()+":"+v3.ToString ()+":"+v4.ToString ()+")");

	}

	public Vector3[] toVec(){
		return new Vector3[]{vertex1, vertex2, vertex3, vertex4};
	}

	public string toStr(){
		return "("+vertex1.ToString ()+":"+vertex2.ToString ()+":"+vertex3.ToString ()+":"+vertex4.ToString ()+")";
	}

	public string flip(){
		List<Vector3> test = new List<Vector3> ();
		test.Add (vertex4);
		test.Add (vertex2);
		test.Add (vertex3);
		test.Add (vertex1);
		//return test;
		return "("+vertex4.ToString ()+":"+vertex2.ToString ()+":"+vertex3.ToString ()+":"+vertex1.ToString ()+")";
	}
}

and the chunk class

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[RequireComponent(typeof(MeshFilter))]
[RequireComponent(typeof(MeshRenderer))]

public class TestChunk : MonoBehaviour {

	// Variables
	public int chunkWidth, chunkHeight;
	List<Vector3> givenVertices;
	List<int> givenTriangles;
	List<Vector2> givenUvs;

	List<TestFace> faces;
	bool[] boolFaces;
	List<Vector3[]> vecFaces;
	List<string> strFaces;
	List<int> optimisedTriangles;

	Mesh mesh;

	
	void Start (){
		givenVertices = new List<Vector3> ();
		givenTriangles = new List<int> ();
		givenUvs = new List<Vector2> ();

		faces = new List<TestFace> ();
		vecFaces = new List<Vector3[]> ();
		strFaces = new List<string> ();
		optimisedTriangles = new List<int> ();
		mesh = new Mesh ();

		for(int x=0; x<chunkWidth; x++){
			for(int z=0; z<chunkWidth; z++){
				for(int y=0; y<chunkHeight; y++){
					addBlock(x,y,z);
				}
			}
		}
		optimise ();
		creatMesh ();
	}

	void Update() {

	}

	void addBlock(int x, int y, int z){
		faces.Add (new TestFace (new Vector3 (x,y+1,z), new Vector3 (x,y+1,z+1), new Vector3 (x+1,y+1,z), new Vector3 (x+1,y+1,z+1))); // Creating the Top Face of the Block
		faces.Add (new TestFace (new Vector3 (x+1,y,z+1), new Vector3 (x,y,z+1), new Vector3 (x+1,y,z), new Vector3 (x,y,z)));		   // Creating the Bottom Face of the Block
		faces.Add (new TestFace (new Vector3 (x,y,z), new Vector3 (x,y,z+1), new Vector3 (x,y+1,z), new Vector3 (x,y+1,z+1))); // Creating the Front Face of the Block
		faces.Add (new TestFace (new Vector3 (x+1,y+1,z+1), new Vector3 (x+1,y,z+1), new Vector3 (x+1,y+1,z), new Vector3 (x+1,y,z))); // Creating the Back Face of the Block
		faces.Add (new TestFace (new Vector3 (x+1,y,z), new Vector3 (x,y,z), new Vector3 (x+1,y+1,z), new Vector3 (x,y+1,z))); // Creating the Right Face of the Block
		faces.Add (new TestFace (new Vector3 (x,y+1,z+1), new Vector3 (x,y,z+1), new Vector3 (x+1,y+1,z+1), new Vector3 (x+1,y,z+1))); // Creating the Left Face of the Block
	}

	void optimise(){

		// Calculating Lists
		calculate_vecFaces ();
		boolFaces = new bool[vecFaces.Count];

		// Fixing the bools And Calculating the givenTriangles & givenVertices
		for(int i=0; i<vecFaces.Count; i++){
			//calculating the givenVertices
			givenVertices.Add(vecFaces*[0]);*

_ givenVertices.Add(vecFaces*[1]);_
_ givenVertices.Add(vecFaces[2]);
givenVertices.Add(vecFaces[3]);
//calculating the givenUvs*

* givenUvs.Add (new Vector2(0,0));
givenUvs.Add (new Vector2(0,1));
givenUvs.Add (new Vector2(1,0));
givenUvs.Add (new Vector2(1,1));
//calculating the givenTriangles*

givenTriangles.Add (i4);
givenTriangles.Add (i4 +1);

givenTriangles.Add (i4 +2);
givenTriangles.Add (i4 +2);

givenTriangles.Add (i4 +1);
givenTriangles.Add (i4 +3);

* //Fixing the bools*_

_ Debug.Log(faces*.flip () + " : " + strFaces[0]);
if(strFaces.Contains(faces.flip ())){
boolFaces = false;
Debug.Log("accessed … ");
}else{
boolFaces = true;
}
}*_

* // Creating the optimised Triangles*
* for(int i=0; i<boolFaces.Length; i++){*
* //Debug.Log(boolFaces[0].ToString() + " : " + boolFaces[1].ToString() + " : " + boolFaces[2].ToString() + " : " + boolFaces[3].ToString() + " : " + boolFaces[4].ToString() + " : " + boolFaces[5].ToString());*
_ if(boolFaces*){
//Debug.Log(i6 +1);

optimisedTriangles.Add(givenTriangles[i*6 + 0]);
optimisedTriangles.Add(givenTriangles[i*6 + 1]);
optimisedTriangles.Add(givenTriangles[i*6 + 2]);
optimisedTriangles.Add(givenTriangles[i*6 + 3]);
optimisedTriangles.Add(givenTriangles[i*6 + 4]);
optimisedTriangles.Add(givenTriangles[i*6 + 5]);
* }
}
}*_

* void calculate_vecFaces(){
_ for(int i=0; i<faces.Count; i++){
vecFaces.Add(faces.toVec());
strFaces.Add(faces.toStr ());
}
}*_

* void creatMesh(){*
* mesh.vertices = givenVertices.ToArray ();*
* mesh.triangles = optimisedTriangles.ToArray ();*
* mesh.uv = givenUvs.ToArray ();*
* mesh.RecalculateBounds ();*
* mesh.RecalculateNormals ();*
* GetComponent ().mesh = mesh;*
* Debug.Log (GetComponent ().mesh.vertices.Length);*
* Debug.Log (GetComponent ().mesh.triangles.Length);*

_ /
Debug.Log (“given >> " + givenTriangles.Count);
Debug.Log (“Optimised >> " + optimisedTriangles.Count);
Debug.Log (”( " + optimisedTriangles[0] + " : " + optimisedTriangles[1] + " : " + optimisedTriangles[2] + " : " + optimisedTriangles[3] + " : " + optimisedTriangles[4] + " : " + optimisedTriangles[5] + " : " +
optimisedTriangles[6] + " : " + optimisedTriangles[7] + " : " + optimisedTriangles[8] + " : " + optimisedTriangles[9] + " : " + optimisedTriangles[10] + " : " + optimisedTriangles[11] + " )”);
/
}

}_

Running this through the Unity Profiler will show you where the code is running slowly, and that is where you want to concentrate your optimization. Use Deep Profile to allow drilling into functions.