示例#1
0
        Task BuildCellsAsync(TerrainGeometryCellsComponent geo, TerrainConfigurationComponent config)
        {
            // Set the height and width of each terrain cell to a fixed 33x33 vertex array.
            int cellHeight = 33;
            int cellWidth  = 33;

            // Calculate the number of cells needed to store the terrain data.
            int cellRowCount = (config.Width - 1) / (cellWidth - 1);
            var m_CellCount  = cellRowCount * cellRowCount;

            // Create the terrain cell array.
            var TerrainCells = new TerrainGeometryCellsComponent.TerrainCell[m_CellCount];

            try {
                // Loop through and initialize all the terrain cells.
                for (int j = 0; j < cellRowCount; j++)
                {
                    for (int i = 0; i < cellRowCount; i++)
                    {
                        int index = (cellRowCount * j) + i;
                        TerrainCells[index] = geo.BuildCell(i, j, cellHeight, cellWidth, config.Width);
                    }
                }
            }catch (Exception ex) {
                ex.ToString();
            }

            geo.Cells = TerrainCells;

            return(Task.FromResult(0));
        }
示例#2
0
        static void BuildGeometry(Vector3[] HeightMap, TerrainConfigurationComponent config, TerrainGeometryCellsComponent geometry)
        {
            var width    = config.Width;
            var height   = config.Height;
            var count    = (width - 1) * (height - 1) * 6;
            var indices  = new int[count];
            var vertices = HeightMap;//.ToArray();
            var index    = 0;

            for (int j = 0; j < (height - 1); j++)
            {
                var row  = height * j;
                var row2 = height * (j + 1);
                for (int i = 0; i < (width - 1); i++)
                {
                    var indx1 = row + i;
                    var indx2 = row + i + 1;
                    var indx3 = row2 + i;
                    var indx4 = row2 + i + 1;

                    indices[index++] = indx1;
                    indices[index++] = indx2;
                    indices[index++] = indx3;

                    indices[index++] = indx2;
                    indices[index++] = indx4;
                    indices[index++] = indx3;
                }
            }
            var normals = vertices.CalculateNormals(indices);

            geometry.Indices   = indices.ToImmutableArray();
            geometry.Positions = vertices.ToImmutableArray();
            geometry.Normals   = normals.ToImmutableArray();
            CalculateTextureCoordinates(HeightMap, width, height, config.TextureRepeat, out var t1, out var t2);
            geometry.TextureCoordinates      = t1.ToImmutableArray();
            geometry.NormalMapTexCoordinates = t2;
            geometry.Color = V4Colors.White;

            ComputeTangents(geometry);

            //Light.SetAmbientColor(0.05f, 0.05f, 0.05f, 1.0f);
            //Light.SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f);
        }
示例#3
0
 public TerrainGeneratorComponent(int width, int height, TerrainConfigurationComponent terrainParams)
 {
     this.width         = width;
     this.height        = height;
     this.terrainParams = terrainParams;
 }