Exemplo n.º 1
0
            public LayerRenderInfo(int queryLayer, int renderLayer, BuildingDef def,
                                   SimHashes element)
            {
                int   width = Grid.WidthInCells / CHUNK_SIZE + 1;
                int   height = Grid.HeightInCells / CHUNK_SIZE + 1;
                float z = Grid.GetLayerZ(def.SceneLayer), decorZOffset;

                this.queryLayer = queryLayer;
                this.element    = element;
                occupiedCells   = new Dictionary <int, int>(CHUNK_SIZE * CHUNK_SIZE / 4);
                renderMaterial  = def.GetMaterial(element);
                renderChunks    = new MeshChunk[width, height];
                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        renderChunks[x, y] = new MeshChunk(renderMaterial, renderLayer, z);
                    }
                }
                // Spawn tile decor if needed
                decorRenderInfo = (element == SimHashes.Void) ? def.DecorPlaceBlockTileInfo :
                                  def.DecorBlockTileInfo;
                if (decorRenderInfo == null)
                {
                    decorMaterial  = null;
                    decorTriangles = null;
                    decorChunks    = null;
                }
                else
                {
                    // Decor has to appear in front to avoid z-fighting
                    if (def.BlockTileIsTransparent)
                    {
                        decorZOffset = Grid.GetLayerZ(Grid.SceneLayer.TileFront) - Grid.
                                       GetLayerZ(Grid.SceneLayer.Liquid) + DECOR_Z_OFFSET;
                    }
                    else
                    {
                        decorZOffset = DECOR_Z_OFFSET;
                    }
                    decorMaterial  = def.GetDecorMaterial(decorRenderInfo);
                    decorTriangles = new List <TriangleInfo>(32);
                    decorChunks    = new MeshChunk[width, height];
                    for (int x = 0; x < width; x++)
                    {
                        for (int y = 0; y < height; y++)
                        {
                            decorChunks[x, y] = new MeshChunk(decorMaterial, renderLayer, z +
                                                              decorZOffset);
                        }
                    }
                }
                atlasInfo = def.GenerateAtlas();
            }