/// <summary> Initialises the oclussion manager. </summary> private void InitOclussionManager() { // create a list to hold the game objects meshObjects = new List <GameObject>(); // create a list to hold the meshes List <Mesh> meshes = new List <Mesh>(); MeshSplitter.CreateMeshes(width, height, (int)quadWidth, (int)quadHeight, (int)quadXGap, (int)quadYGap, ref meshes); for (int i = 0; i < meshes.Count; ++i) { GameObject newObject = new GameObject("OcclusionMesh" + i); newObject.AddComponent <MeshFilter>(); newObject.AddComponent <MeshRenderer>(); newObject.GetComponent <MeshFilter>().mesh = meshes[i]; newObject.GetComponent <MeshFilter>().mesh.bounds = new Bounds(Vector3.zero, Vector3.one); newObject.transform.SetParent(_depthOcclusionGO.transform, false); newObject.transform.localPosition = Vector3.zero; newObject.transform.localScale = Vector3.one; meshObjects.Add(newObject); } ApplyTexture(currentNativeTexture); }
/// <summary> /// Create separate meshes if there are too many vertices. Note assumes that both width and height are divisible by 4. /// </summary> public static void CreateMeshes(uint width, uint height, int quadWidth, int quadHeight, int quadXGap, int quadYGap, ref List <Mesh> meshes) { // collect the data which, if there were no limits, would be just one mesh. Vector3[] vertices = CalculateVertices(width, height, quadWidth, quadHeight, quadXGap, quadYGap); Vector2[] depthUV = MeshSplitter.CalcualteUVMap(vertices.Length, width, height); Vector2[] quadUV = CalcualteUVQuadTexture(vertices.Length, width, height); int[] indices = CalculateTriangles(vertices.Length); // calculate how many meshes there will be and set the vertex limit uint numMeshes = MeshSplitter.CalculateNumberOfMeshes(width, height); CreateMeshes(numMeshes, vertices, depthUV, quadUV, indices, ref meshes); }
/// <summary> /// Create game objects and attach meshes to them. /// </summary> /// <param name="numMeshes">The number of meshes there are.</param> /// <param name="meshes">The list containing the meshes.</param> private void CreateGameObjects() { // create a list to hold the meshes List <Mesh> meshes = new List <Mesh>(); MeshSplitter.CreateMeshes(width, height, (int)quadWidth, (int)quadHeight, (int)quadXGap, (int)quadYGap, ref meshes); for (int i = 0; i < meshes.Count; ++i) { GameObject newObject = new GameObject("OcclusionMesh" + i); newObject.AddComponent <MeshFilter>(); newObject.AddComponent <MeshRenderer>(); newObject.GetComponent <MeshFilter>().mesh = meshes[i]; newObject.transform.SetParent(gameObject.transform, true); newObject.transform.localPosition = Vector3.zero; newObject.transform.localScale = Vector3.one; meshObjects.Add(newObject); } }