/////////////////////////////////// // Assemble high resolution terrain and block // IEnumerator AssembleHTBlock() { if (working && currentLoadingHTerrainBlock.Count > 0) { float startTimeAssembleHT = Time.time; ADTRootData.MeshBlockData HTData = ADTRootData.MeshBlockDataQueue.Dequeue(); QueueItem HTGroupItem = currentLoadingHTerrainBlock.Dequeue(); if (HTGroupItem.Block != null) { HTGroupItem.Block.name = HTGroupItem.mapName + "_" + HTGroupItem.x + "_" + HTGroupItem.y; // generate mesh objects // int frameSpread = 8; // spreading terrain chunks creation over multiple frames for (int i = 1; i <= frameSpread; i++) { CreateHTBlockQuarter(frameSpread, i, HTData, HTGroupItem.Block); yield return(null); } if (working) { try { // Batch terrain meshes // StaticBatchingUtility.Combine(HTGroupItem.Block); HTGroupItem.Block.GetComponent <ADTBlock>().enabled = true; LoadedQueueItems.Add(HTGroupItem); // request Objs // ADTObjQueue.Add(HTGroupItem); currentLoadingObjBlock.Enqueue(HTGroupItem); // request the LTexture // mapTextureQueue.Enqueue(HTGroupItem); // request the HTexture // ADTTexQueue.Add(HTGroupItem); currentLoadingHTextureBlock.Enqueue(HTGroupItem); } catch { } } } frameBusy = false; finishedTimeAssembleHT = Time.time - startTimeAssembleHT; } }
// Create a part of the ADT block meshes // private void CreateHTBlockQuarter(int fS, int Q, ADTRootData.MeshBlockData data, GameObject Block) { if (working && Block != null) { for (int i = (256 / fS) * (Q - 1); i < (256 / fS) * Q; i++) { ////////////////////////////// #region Create GameObject GameObject Chunk = Instantiate(ChunkPrefab); Chunk.isStatic = true; Chunk.layer = 9; Chunk.name = "chunk_" + i.ToString(); Chunk.transform.position = data.meshChunksData[i].MeshPosition; Chunk.transform.SetParent(Block.transform); #endregion ////////////////////////////// ////////////////////////////// #region Create Mesh Mesh mesh0 = new Mesh(); mesh0.vertices = data.meshChunksData[i].VertexArray; mesh0.triangles = data.meshChunksData[i].TriangleArray; mesh0.uv = ADT.Chunk_UVs; mesh0.uv2 = ADT.Chunk_UVs2[i]; mesh0.normals = data.meshChunksData[i].VertexNormals; mesh0.colors32 = data.meshChunksData[i].VertexColors; //Chunk.GetComponent<MeshFilter>().mesh = mesh0; Chunk.GetComponent <ADTChunk>().mesh = mesh0; Chunk.GetComponent <MeshFilter>().sharedMesh = Chunk.GetComponent <ADTChunk>().mesh; Chunk.GetComponent <MeshCollider>().sharedMesh = mesh0; //mesh0.Clear(); //mesh0 = null; #endregion ////////////////////////////// } } }