Пример #1
0
 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);
         }
     }
 }
Пример #2
0
 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;
     }
 }