public void RefreshMeshData(UpdateFlags updateFlag = UpdateFlags.All) { //Debug.Log("RefreshMeshData,chunk=" + x + ",z=" + z); UnityEngine.Profiling.Profiler.BeginSample("RefreshMeshData"); if (updateFlag.HasFlag(UpdateFlags.Collidable)) { collidable.Clear(); } if (updateFlag.HasFlag(UpdateFlags.NotCollidable)) { notCollidable.Clear(); } if (updateFlag.HasFlag(UpdateFlags.Water)) { water.Clear(); } for (int sectionIndex = 0; sectionIndex < Sections.Count; sectionIndex++) { TagNodeCompound Section = Sections[sectionIndex] as TagNodeCompound; TagNodeByteArray Blocks = Section["Blocks"] as TagNodeByteArray; TagNodeByteArray Data = Section["Data"] as TagNodeByteArray; for (int yInSection = 0; yInSection < 16; yInSection++) { for (int zInSection = 0; zInSection < 16; zInSection++) { for (int xInSection = 0; xInSection < 16; xInSection++) { int blockPos = yInSection * 16 * 16 + zInSection * 16 + xInSection; byte rawType = Blocks.Data[blockPos]; NBTBlock generator = NBTGeneratorManager.GetMeshGenerator(rawType); int worldY = yInSection + sectionIndex * 16; if (generator != null) { pos.Set(xInSection, worldY, zInSection); byte blockData = NBTHelper.GetNibble(Data.Data, blockPos); try { if (generator.isTileEntity) { tileEntityList.Add(pos); } else { AddCube(generator, blockData, updateFlag); } } catch (System.Exception e) { int worldX = x * 16 + xInSection; int worldZ = z * 16 + zInSection; Vector3Int worldPos = new Vector3Int(worldX, worldY, worldZ); Debug.LogError(generator.GetType() + ",pos=" + worldPos + "\n" + e.ToString()); } } else if (rawType != 0 && rawType != 11) { int worldX = x * 16 + xInSection; int worldZ = z * 16 + zInSection; Vector3Int worldPos = new Vector3Int(worldX, worldY, worldZ); Debug.LogWarning("generator not exist" + ",pos=" + worldPos + ", type=" + rawType); } } } } } UnityEngine.Profiling.Profiler.EndSample(); }
public void RefreshMeshData() { //Debug.Log("RefreshMeshData,chunk=" + x + ",z=" + z); collidable.Clear(); notCollidable.Clear(); water.Clear(); Vector3Int pos = new Vector3Int(); for (int sectionIndex = 0; sectionIndex < Sections.Count; sectionIndex++) { TagNodeCompound Section = Sections[sectionIndex] as TagNodeCompound; TagNodeByteArray Blocks = Section["Blocks"] as TagNodeByteArray; TagNodeByteArray Data = Section["Data"] as TagNodeByteArray; TagNodeByteArray SkyLight = Section["SkyLight"] as TagNodeByteArray; for (int yInSection = 0; yInSection < 16; yInSection++) { for (int zInSection = 0; zInSection < 16; zInSection++) { for (int xInSection = 0; xInSection < 16; xInSection++) { int blockPos = yInSection * 16 * 16 + zInSection * 16 + xInSection; byte rawType = Blocks.Data[blockPos]; NBTBlock generator = NBTGeneratorManager.GetMeshGenerator(rawType); if (generator != null) { int worldY = yInSection + sectionIndex * 16; pos.Set(xInSection, worldY, zInSection); byte blockData = NBTHelper.GetNibble(Data.Data, blockPos); byte skyLight = NBTHelper.GetNibble(SkyLight.Data, blockPos); try { if (generator is NBTStationaryWater) { //generator.GenerateMeshInChunk(this, blockData, pos, water); } else if (generator is NBTPlant) { generator.AddCube(this, blockData, skyLight, pos, notCollidable); } else { generator.AddCube(this, blockData, skyLight, pos, collidable); } } catch (System.Exception e) { Debug.LogWarning(generator.GetType() + "\n" + e.ToString()); } } else if (rawType != 0 && rawType != 11) { Debug.LogWarning("generator not exist, type=" + rawType); } } } } } hasBuiltMesh = true; isDirty = false; }