public void Rebuild(BlockTileRenderer renderer, int chunk_x, int chunk_y, List <Vector3> vertices, List <Vector2> uvs, List <int> indices, List <Color> colours) { if (dirtyChunks[chunk_x, chunk_y] || renderer.ForceRebuild) { dirtyChunks[chunk_x, chunk_y] = false; vertices.Clear(); uvs.Clear(); indices.Clear(); colours.Clear(); for (int i = chunk_y * 16; i < chunk_y * 16 + 16; i++) { for (int j = chunk_x * 16; j < chunk_x * 16 + 16; j++) { int num = i * Grid.WidthInCells + j; if (occupiedCells.ContainsKey(num)) { Bits connectionBits = renderer.GetConnectionBits(j, i, queryLayer); for (int k = 0; k < atlasInfo.Length; k++) { bool flag = (atlasInfo[k].requiredConnections & connectionBits) == atlasInfo[k].requiredConnections; bool flag2 = (atlasInfo[k].forbiddenConnections & connectionBits) != (Bits)0; if (flag && !flag2) { Color cellColour = renderer.GetCellColour(num, element); AddVertexInfo(atlasInfo[k], trimUVSize, j, i, connectionBits, cellColour, vertices, uvs, indices, colours); break; } } } } } Mesh mesh = meshChunks[chunk_x, chunk_y]; if (vertices.Count > 0) { if ((UnityEngine.Object)mesh == (UnityEngine.Object)null) { mesh = new Mesh(); mesh.name = "BlockTile"; meshChunks[chunk_x, chunk_y] = mesh; } mesh.Clear(); mesh.SetVertices(vertices); mesh.SetUVs(0, uvs); mesh.SetColors(colours); mesh.SetTriangles(indices, 0); } else if ((UnityEngine.Object)mesh != (UnityEngine.Object)null) { meshChunks[chunk_x, chunk_y] = null; mesh = null; } if (decorRenderInfo != null) { decorRenderInfo.Rebuild(renderer, occupiedCells, chunk_x, chunk_y, decorZOffset, 16, vertices, uvs, colours, indices, element); } } }
public void Rebuild(BlockTileRenderer renderer, Dictionary <int, int> occupiedCells, int chunk_x, int chunk_y, float z_offset, int chunkEdgeSize, List <Vector3> vertices, List <Vector2> uvs, List <Color> colours, List <int> indices, SimHashes element) { vertices.Clear(); uvs.Clear(); triangles.Clear(); colours.Clear(); indices.Clear(); for (int i = chunk_y * chunkEdgeSize; i < chunk_y * chunkEdgeSize + chunkEdgeSize; i++) { for (int j = chunk_x * chunkEdgeSize; j < chunk_x * chunkEdgeSize + chunkEdgeSize; j++) { int num = i * Grid.WidthInCells + j; if (occupiedCells.ContainsKey(num)) { Color cellColour = renderer.GetCellColour(num, element); Bits decorConnectionBits = renderer.GetDecorConnectionBits(j, i, queryLayer); AddDecor(j, i, z_offset, decorConnectionBits, cellColour, vertices, uvs, triangles, colours); } } } if (vertices.Count > 0) { Mesh mesh = meshChunks[chunk_x, chunk_y]; if ((UnityEngine.Object)mesh == (UnityEngine.Object)null) { mesh = new Mesh(); mesh.name = "DecorRender"; meshChunks[chunk_x, chunk_y] = mesh; } triangles.Sort((TriangleInfo a, TriangleInfo b) => a.sortOrder.CompareTo(b.sortOrder)); for (int k = 0; k < triangles.Count; k++) { TriangleInfo triangleInfo = triangles[k]; indices.Add(triangleInfo.i0); TriangleInfo triangleInfo2 = triangles[k]; indices.Add(triangleInfo2.i1); TriangleInfo triangleInfo3 = triangles[k]; indices.Add(triangleInfo3.i2); } mesh.Clear(); mesh.SetVertices(vertices); mesh.SetUVs(0, uvs); mesh.SetColors(colours); mesh.SetTriangles(indices, 0); } else { meshChunks[chunk_x, chunk_y] = null; } }
public RenderInfo(BlockTileRenderer renderer, int queryLayer, int renderLayer, BuildingDef def, SimHashes element) { this.queryLayer = queryLayer; this.renderLayer = renderLayer; rootPosition = new Vector3(0f, 0f, Grid.GetLayerZ(def.SceneLayer)); this.element = element; material = new Material(def.BlockTileMaterial); if (def.BlockTileIsTransparent) { material.renderQueue = RenderQueues.Liquid; decorZOffset = Grid.GetLayerZ(Grid.SceneLayer.TileFront) - Grid.GetLayerZ(Grid.SceneLayer.Liquid) - 1f; } else if (def.SceneLayer == Grid.SceneLayer.TileMain) { material.renderQueue = RenderQueues.BlockTiles; } material.DisableKeyword("ENABLE_SHINE"); if (element != SimHashes.Void) { material.SetTexture("_MainTex", def.BlockTileAtlas.texture); material.name = def.BlockTileAtlas.name + "Mat"; if ((UnityEngine.Object)def.BlockTileShineAtlas != (UnityEngine.Object)null) { material.SetTexture("_SpecularTex", def.BlockTileShineAtlas.texture); material.EnableKeyword("ENABLE_SHINE"); } } else { material.SetTexture("_MainTex", def.BlockTilePlaceAtlas.texture); material.name = def.BlockTilePlaceAtlas.name + "Mat"; } int num = Grid.WidthInCells / 16; int num2 = Grid.HeightInCells / 16; meshChunks = new Mesh[num, num2]; dirtyChunks = new bool[num, num2]; for (int i = 0; i < num2; i++) { for (int j = 0; j < num; j++) { dirtyChunks[j, i] = true; } } BlockTileDecorInfo blockTileDecorInfo = (element != SimHashes.Void) ? def.DecorBlockTileInfo : def.DecorPlaceBlockTileInfo; if ((bool)blockTileDecorInfo) { decorRenderInfo = new DecorRenderInfo(num, num2, queryLayer, def, blockTileDecorInfo); } string name = def.BlockTileAtlas.items[0].name; int length = name.Length; int num3 = length -= 4; int num4 = num3 - 8; int num5 = num4 - 1; int startIndex = num5 - 8; atlasInfo = new AtlasInfo[def.BlockTileAtlas.items.Length]; for (int k = 0; k < atlasInfo.Length; k++) { TextureAtlas.Item item = def.BlockTileAtlas.items[k]; string value = item.name.Substring(startIndex, 8); string value2 = item.name.Substring(num4, 8); int requiredConnections = Convert.ToInt32(value, 2); int forbiddenConnections = Convert.ToInt32(value2, 2); atlasInfo[k].requiredConnections = (Bits)requiredConnections; atlasInfo[k].forbiddenConnections = (Bits)forbiddenConnections; atlasInfo[k].uvBox = item.uvBox; atlasInfo[k].name = item.name; } trimUVSize = new Vector2(0.03125f, 0.03125f); }