Example #1
0
        /// <summary>
        /// Constructs a new <see cref="MapPatch"/> object using the supplied string array as data.
        /// </summary>
        /// <param name="lines">Data to parse.</param>
        public MapPatch(string[] lines)
        {
            texture = lines[2];
            List <Vertex> vertices = new List <Vertex>(9);

            switch (lines[0])
            {
            case "patchDef3":
            case "patchDef2": {
                string[] line = lines[3].Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                dims = new Vector2(float.Parse(line[1], _format), float.Parse(line[2], _format));
                for (int i = 0; i < dims.X(); ++i)
                {
                    line = lines[i + 5].Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    for (int j = 0; j < dims.Y(); ++j)
                    {
                        Vector3 point  = new Vector3(float.Parse(line[2 + (j * 7)], _format), float.Parse(line[3 + (j * 7)], _format), float.Parse(line[4 + (j * 7)], _format));
                        Vector2 uv     = new Vector2(float.Parse(line[5 + (j * 7)], _format), float.Parse(line[6 + (j * 7)], _format));
                        Vertex  vertex = new Vertex
                        {
                            position = point,
                            uv0      = uv,
                            color    = ColorExtensions.FromArgb(255, 255, 255, 255),
                        };
                        vertices.Add(vertex);
                    }
                }
                break;
            }

            case "patchTerrainDef3": {
                string[] line = lines[3].Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                dims = new Vector2(float.Parse(line[1], _format), float.Parse(line[2], _format));
                for (int i = 0; i < dims.X(); ++i)
                {
                    line = lines[i + 5].Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    for (int j = 0; j < dims.Y(); ++j)
                    {
                        Vector3 point  = new Vector3(float.Parse(line[2 + (j * 12)], _format), float.Parse(line[3 + (j * 12)], _format), float.Parse(line[4 + (j * 12)], _format));
                        Vector2 uv     = new Vector2(float.Parse(line[5 + (j * 12)], _format), float.Parse(line[6 + (j * 12)], _format));
                        Color   color  = ColorExtensions.FromArgb(byte.Parse(line[7 + (j * 12)]), byte.Parse(line[8 + (j * 12)]), byte.Parse(line[9 + (j * 12)]), byte.Parse(line[10 + (j * 12)]));
                        Vertex  vertex = new Vertex
                        {
                            position = point,
                            uv0      = uv,
                            color    = color,
                        };
                        vertices.Add(vertex);
                    }
                }
                break;
            }

            default: {
                throw new ArgumentException($"Unknown patch type {lines[0]}! Call a scientist! ");
            }
            }
        }
 private void DefaultButton_Click(object sender, RoutedEventArgs e)
 {
     Colors.Clear();
     foreach (uint color in _keyName.Equals("Color") ? _defaultAccentColors : _defaultComplementaryColors)
     {
         Colors.Add(new SolidColorBrush(ColorExtensions.FromArgb(color)));
     }
     ColorsList.ItemsSource   = Colors;
     ColorsList.SelectedIndex = 0;
 }
 private void ReadButton_Click(object sender, RoutedEventArgs e)
 {
     Colors.Clear();
     for (int j = 0; j < _defaultAccentColors.Length; j++)
     {
         Colors.Add(new SolidColorBrush(ColorExtensions.FromArgb(_colorEntries[0, j].Value)));
     }
     ColorsList.ItemsSource   = Colors;
     ColorsList.SelectedIndex = 0;
 }