hey everyone this is my first time to post a question on the unity3d ask forum :D anyway i've been working on a cubical based engine and the chunks seems to take long to load when they are more than 6*6*6 but it takes about 4-5 seconds to load a chunk 12*12*12 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 test = new List ();
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 givenVertices;
List givenTriangles;
List givenUvs;
List faces;
bool[] boolFaces;
List vecFaces;
List strFaces;
List optimisedTriangles;
Mesh mesh;
void Start (){
givenVertices = new List ();
givenTriangles = new List ();
givenUvs = new List ();
faces = new List ();
vecFaces = new List ();
strFaces = new List ();
optimisedTriangles = new List ();
mesh = new Mesh ();
for(int x=0; x ().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] + " )");
*/
}
}
↧