< Summary

Line coverage
100%
Covered lines: 331
Uncovered lines: 0
Coverable lines: 331
Total lines: 791
Line coverage: 100%
Branch coverage
97%
Covered branches: 377
Total branches: 385
Branch coverage: 97.9%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
FromStream(...)96.53%231231100%
ParseMaterialColor(...)100%2424100%
ParseMaterialMap(...)100%130130100%

File(s)

https://raw.githubusercontent.com/JeremyAnsel/JeremyAnsel.Media.WavefrontObj/dbbfcd213b7c54f49194f82fcd56e790cca193c3/JeremyAnsel.Media.WavefrontObj/JeremyAnsel.Media.WavefrontObj/ObjMaterialFileReader.cs

#LineLine coverage
 1// <copyright file="ObjMaterialFileReader.cs" company="Jérémy Ansel">
 2// Copyright (c) 2017, 2019 Jérémy Ansel
 3// </copyright>
 4// <license>
 5// Licensed under the MIT license. See LICENSE.txt
 6// </license>
 7
 8using System.Diagnostics.CodeAnalysis;
 9using System.Globalization;
 10
 11namespace JeremyAnsel.Media.WavefrontObj
 12{
 13    internal static class ObjMaterialFileReader
 14    {
 15        [SuppressMessage("Globalization", "CA1303:Ne pas passer de littéraux en paramètres localisés", Justification = "
 16        public static ObjMaterialFile FromStream(Stream? stream)
 17        {
 67818            if (stream == null)
 19            {
 320                throw new ArgumentNullException(nameof(stream));
 21            }
 22
 67523            var mtl = new ObjMaterialFile();
 67524            var lineReader = new LineReader();
 25
 67526            ObjMaterial? currentMaterial = null;
 27
 347428            foreach (var values in lineReader.Read(stream))
 29            {
 126930                switch (values[0].ToLowerInvariant())
 31                {
 32                    case "newmtl":
 60933                        if (values.Length < 2)
 34                        {
 335                            throw new InvalidDataException("A newmtl statement must specify a name.");
 36                        }
 37
 60638                        currentMaterial = new ObjMaterial
 60639                        {
 60640                            Name = string.Join(" ", values, 1, values.Length - 1)
 60641                        };
 42
 60643                        mtl.Materials.Add(currentMaterial);
 44
 60645                        break;
 46
 47                    case "ka":
 4248                        if (currentMaterial == null)
 49                        {
 350                            throw new InvalidDataException("The material name is not specified.");
 51                        }
 52
 3953                        currentMaterial.AmbientColor = ObjMaterialFileReader.ParseMaterialColor("Ka", values);
 1854                        break;
 55
 56                    case "kd":
 4257                        if (currentMaterial == null)
 58                        {
 359                            throw new InvalidDataException("The material name is not specified.");
 60                        }
 61
 3962                        currentMaterial.DiffuseColor = ObjMaterialFileReader.ParseMaterialColor("Kd", values);
 1863                        break;
 64
 65                    case "ke":
 4266                        if (currentMaterial == null)
 67                        {
 368                            throw new InvalidDataException("The material name is not specified.");
 69                        }
 70
 3971                        currentMaterial.EmissiveColor = ObjMaterialFileReader.ParseMaterialColor("Ke", values);
 1872                        break;
 73
 74                    case "ks":
 4275                        if (currentMaterial == null)
 76                        {
 377                            throw new InvalidDataException("The material name is not specified.");
 78                        }
 79
 3980                        currentMaterial.SpecularColor = ObjMaterialFileReader.ParseMaterialColor("Ks", values);
 1881                        break;
 82
 83                    case "tf":
 4284                        if (currentMaterial == null)
 85                        {
 386                            throw new InvalidDataException("The material name is not specified.");
 87                        }
 88
 3989                        currentMaterial.TransmissionColor = ObjMaterialFileReader.ParseMaterialColor("Tf", values);
 1890                        break;
 91
 92                    case "illum":
 1293                        if (currentMaterial == null)
 94                        {
 395                            throw new InvalidDataException("The material name is not specified.");
 96                        }
 97
 998                        if (values.Length < 2)
 99                        {
 3100                            throw new InvalidDataException("An illum statement must specify an illumination model.");
 101                        }
 102
 6103                        if (values.Length != 2)
 104                        {
 3105                            throw new InvalidDataException("An illum statement has too many values.");
 106                        }
 107
 3108                        currentMaterial.IlluminationModel = int.Parse(values[1], CultureInfo.InvariantCulture);
 3109                        break;
 110
 111                    case "d":
 21112                        if (currentMaterial == null)
 113                        {
 3114                            throw new InvalidDataException("The material name is not specified.");
 115                        }
 116
 18117                        if (values.Length < 2)
 118                        {
 3119                            throw new InvalidDataException("A d statement must specify a factor.");
 120                        }
 121
 15122                        if (string.Equals(values[1], "-halo", StringComparison.OrdinalIgnoreCase))
 123                        {
 9124                            if (values.Length < 3)
 125                            {
 3126                                throw new InvalidDataException("A d statement must specify a factor.");
 127                            }
 128
 6129                            if (values.Length != 3)
 130                            {
 3131                                throw new InvalidDataException("A d statement has too many values.");
 132                            }
 133
 3134                            currentMaterial.IsHaloDissolve = true;
 3135                            currentMaterial.DissolveFactor = float.Parse(values[2], CultureInfo.InvariantCulture);
 136                        }
 137                        else
 138                        {
 6139                            if (values.Length != 2)
 140                            {
 3141                                throw new InvalidDataException("A d statement has too many values.");
 142                            }
 143
 3144                            currentMaterial.DissolveFactor = float.Parse(values[1], CultureInfo.InvariantCulture);
 145                        }
 146
 3147                        break;
 148
 149                    case "ns":
 12150                        if (currentMaterial == null)
 151                        {
 3152                            throw new InvalidDataException("The material name is not specified.");
 153                        }
 154
 9155                        if (values.Length < 2)
 156                        {
 3157                            throw new InvalidDataException("A Ns statement must specify a specular exponent.");
 158                        }
 159
 6160                        if (values.Length != 2)
 161                        {
 3162                            throw new InvalidDataException("A Ns statement has too many values.");
 163                        }
 164
 3165                        currentMaterial.SpecularExponent = float.Parse(values[1], CultureInfo.InvariantCulture);
 3166                        break;
 167
 168                    case "sharpness":
 12169                        if (currentMaterial == null)
 170                        {
 3171                            throw new InvalidDataException("The material name is not specified.");
 172                        }
 173
 9174                        if (values.Length < 2)
 175                        {
 3176                            throw new InvalidDataException("A sharpness statement must specify a sharpness value.");
 177                        }
 178
 6179                        if (values.Length != 2)
 180                        {
 3181                            throw new InvalidDataException("A sharpness statement has too many values.");
 182                        }
 183
 3184                        currentMaterial.Sharpness = int.Parse(values[1], CultureInfo.InvariantCulture);
 3185                        break;
 186
 187                    case "ni":
 12188                        if (currentMaterial == null)
 189                        {
 3190                            throw new InvalidDataException("The material name is not specified.");
 191                        }
 192
 9193                        if (values.Length < 2)
 194                        {
 3195                            throw new InvalidDataException("A Ni statement must specify an optical density.");
 196                        }
 197
 6198                        if (values.Length != 2)
 199                        {
 3200                            throw new InvalidDataException("A Ni statement has too many values.");
 201                        }
 202
 3203                        currentMaterial.OpticalDensity = float.Parse(values[1], CultureInfo.InvariantCulture);
 3204                        break;
 205
 206                    case "map_aat":
 18207                        if (currentMaterial == null)
 208                        {
 3209                            throw new InvalidDataException("The material name is not specified.");
 210                        }
 211
 15212                        if (values.Length < 2)
 213                        {
 3214                            throw new InvalidDataException("A map_aat statement must specify a value.");
 215                        }
 216
 12217                        if (values.Length != 2)
 218                        {
 3219                            throw new InvalidDataException("A map_aat statement has too many values.");
 220                        }
 221
 9222                        if (string.Equals(values[1], "on", StringComparison.OrdinalIgnoreCase))
 223                        {
 3224                            currentMaterial.IsAntiAliasingEnabled = true;
 225                        }
 6226                        else if (string.Equals(values[1], "off", StringComparison.OrdinalIgnoreCase))
 227                        {
 3228                            currentMaterial.IsAntiAliasingEnabled = false;
 229                        }
 230                        else
 231                        {
 3232                            throw new InvalidDataException("A map_aat statement must specify on or off.");
 233                        }
 234
 235                        break;
 236
 237                    case "map_ka":
 195238                        if (currentMaterial == null)
 239                        {
 3240                            throw new InvalidDataException("The material name is not specified.");
 241                        }
 242
 192243                        currentMaterial.AmbientMap = ObjMaterialFileReader.ParseMaterialMap("map_Ka", values);
 84244                        break;
 245
 246                    case "map_kd":
 15247                        if (currentMaterial == null)
 248                        {
 3249                            throw new InvalidDataException("The material name is not specified.");
 250                        }
 251
 12252                        currentMaterial.DiffuseMap = ObjMaterialFileReader.ParseMaterialMap("map_Kd", values);
 3253                        break;
 254
 255                    case "map_ke":
 15256                        if (currentMaterial == null)
 257                        {
 3258                            throw new InvalidDataException("The material name is not specified.");
 259                        }
 260
 12261                        currentMaterial.EmissiveMap = ObjMaterialFileReader.ParseMaterialMap("map_Ke", values);
 3262                        break;
 263
 264                    case "map_ks":
 15265                        if (currentMaterial == null)
 266                        {
 3267                            throw new InvalidDataException("The material name is not specified.");
 268                        }
 269
 12270                        currentMaterial.SpecularMap = ObjMaterialFileReader.ParseMaterialMap("map_Ks", values);
 3271                        break;
 272
 273                    case "map_ns":
 15274                        if (currentMaterial == null)
 275                        {
 3276                            throw new InvalidDataException("The material name is not specified.");
 277                        }
 278
 12279                        currentMaterial.SpecularExponentMap = ObjMaterialFileReader.ParseMaterialMap("map_Ns", values);
 3280                        break;
 281
 282                    case "map_d":
 283                    case "map_tr":
 15284                        if (currentMaterial == null)
 285                        {
 3286                            throw new InvalidDataException("The material name is not specified.");
 287                        }
 288
 12289                        currentMaterial.DissolveMap = ObjMaterialFileReader.ParseMaterialMap("map_d", values);
 3290                        break;
 291
 292                    case "decal":
 293                    case "map_decal":
 15294                        if (currentMaterial == null)
 295                        {
 3296                            throw new InvalidDataException("The material name is not specified.");
 297                        }
 298
 12299                        currentMaterial.DecalMap = ObjMaterialFileReader.ParseMaterialMap("decal", values);
 3300                        break;
 301
 302                    case "disp":
 303                    case "map_disp":
 15304                        if (currentMaterial == null)
 305                        {
 3306                            throw new InvalidDataException("The material name is not specified.");
 307                        }
 308
 12309                        currentMaterial.DispMap = ObjMaterialFileReader.ParseMaterialMap("disp", values);
 3310                        break;
 311
 312                    case "bump":
 313                    case "map_bump":
 15314                        if (currentMaterial == null)
 315                        {
 3316                            throw new InvalidDataException("The material name is not specified.");
 317                        }
 318
 12319                        currentMaterial.BumpMap = ObjMaterialFileReader.ParseMaterialMap("bump", values);
 3320                        break;
 321
 322                    case "refl":
 323                    case "map_refl":
 45324                        if (currentMaterial == null)
 325                        {
 3326                            throw new InvalidDataException("The material name is not specified.");
 327                        }
 328
 42329                        if (values.Length < 4)
 330                        {
 9331                            throw new InvalidDataException("A refl statement must specify a type and a file name.");
 332                        }
 333
 33334                        if (!string.Equals(values[1], "-type", StringComparison.OrdinalIgnoreCase))
 335                        {
 3336                            throw new InvalidDataException("A refl statement must specify a type.");
 337                        }
 338
 30339                        switch (values[2].ToLowerInvariant())
 340                        {
 341                            case "sphere":
 9342                                currentMaterial.ReflectionMap.Sphere = ObjMaterialFileReader.ParseMaterialMap("refl", va
 3343                                break;
 344
 345                            case "cube_top":
 3346                                currentMaterial.ReflectionMap.CubeTop = ObjMaterialFileReader.ParseMaterialMap("refl", v
 3347                                break;
 348
 349                            case "cube_bottom":
 3350                                currentMaterial.ReflectionMap.CubeBottom = ObjMaterialFileReader.ParseMaterialMap("refl"
 3351                                break;
 352
 353                            case "cube_front":
 3354                                currentMaterial.ReflectionMap.CubeFront = ObjMaterialFileReader.ParseMaterialMap("refl",
 3355                                break;
 356
 357                            case "cube_back":
 3358                                currentMaterial.ReflectionMap.CubeBack = ObjMaterialFileReader.ParseMaterialMap("refl", 
 3359                                break;
 360
 361                            case "cube_left":
 3362                                currentMaterial.ReflectionMap.CubeLeft = ObjMaterialFileReader.ParseMaterialMap("refl", 
 3363                                break;
 364
 365                            case "cube_right":
 3366                                currentMaterial.ReflectionMap.CubeRight = ObjMaterialFileReader.ParseMaterialMap("refl",
 367                                break;
 368                        }
 369
 370                        break;
 371                }
 372            }
 373
 261374            mtl.HeaderText = string.Join("\n", lineReader.HeaderTextLines.ToArray());
 375
 261376            return mtl;
 377        }
 378
 379        [SuppressMessage("Globalization", "CA1303:Ne pas passer de littéraux en paramètres localisés", Justification = "
 380        private static ObjMaterialColor ParseMaterialColor(string statement, string[] values)
 381        {
 195382            if (values.Length < 2)
 383            {
 15384                throw new InvalidDataException(string.Concat("A ", statement, " statement must specify a color."));
 385            }
 386
 180387            var color = new ObjMaterialColor();
 388
 180389            int index = 1;
 390
 180391            switch (values[1].ToLowerInvariant())
 392            {
 393                case "spectral":
 60394                    index++;
 395
 60396                    if (values.Length - index < 1)
 397                    {
 15398                        throw new InvalidDataException(string.Concat("A ", statement, " spectral statement must specify 
 399                    }
 400
 45401                    if (!Path.HasExtension(values[index]))
 402                    {
 15403                        throw new InvalidDataException("A filename must have an extension.");
 404                    }
 405
 30406                    color.SpectralFileName = values[index];
 30407                    index++;
 408
 30409                    if (values.Length > index)
 410                    {
 15411                        color.SpectralFactor = float.Parse(values[index], CultureInfo.InvariantCulture);
 15412                        index++;
 413                    }
 414
 15415                    break;
 416
 417                case "xyz":
 60418                    index++;
 419
 60420                    if (values.Length - index < 1)
 421                    {
 15422                        throw new InvalidDataException(string.Concat("A ", statement, " xyz statement must specify a col
 423                    }
 424
 45425                    color.UseXYZColorSpace = true;
 426
 45427                    var xyz = new ObjVector3();
 428
 45429                    xyz.X = float.Parse(values[index], CultureInfo.InvariantCulture);
 45430                    index++;
 431
 45432                    if (values.Length > index)
 433                    {
 30434                        if (values.Length - index < 2)
 435                        {
 15436                            throw new InvalidDataException(string.Concat("A ", statement, " xyz statement must specify a
 437                        }
 438
 15439                        xyz.Y = float.Parse(values[index], CultureInfo.InvariantCulture);
 15440                        xyz.Z = float.Parse(values[index + 1], CultureInfo.InvariantCulture);
 15441                        index += 2;
 442                    }
 443                    else
 444                    {
 15445                        xyz.Y = xyz.X;
 15446                        xyz.Z = xyz.X;
 447                    }
 448
 30449                    color.Color = xyz;
 30450                    break;
 451
 452                default:
 60453                    var rgb = new ObjVector3();
 454
 60455                    rgb.X = float.Parse(values[index], CultureInfo.InvariantCulture);
 60456                    index++;
 457
 60458                    if (values.Length > index)
 459                    {
 45460                        if (values.Length - index < 2)
 461                        {
 15462                            throw new InvalidDataException(string.Concat("A ", statement, " statement must specify a RGB
 463                        }
 464
 30465                        rgb.Y = float.Parse(values[index], CultureInfo.InvariantCulture);
 30466                        rgb.Z = float.Parse(values[index + 1], CultureInfo.InvariantCulture);
 30467                        index += 2;
 468                    }
 469                    else
 470                    {
 15471                        rgb.Y = rgb.X;
 15472                        rgb.Z = rgb.X;
 473                    }
 474
 45475                    color.Color = rgb;
 476                    break;
 477            }
 478
 105479            if (index != values.Length)
 480            {
 15481                throw new InvalidDataException(string.Concat("A ", statement, " statement has too many values."));
 482            }
 483
 90484            return color;
 485        }
 486
 487        [SuppressMessage("Globalization", "CA1303:Ne pas passer de littéraux en paramètres localisés", Justification = "
 488        private static ObjMaterialMap ParseMaterialMap(string statement, string[] values)
 489        {
 315490            var map = new ObjMaterialMap();
 491
 891492            for (int index = 0; index < values.Length;)
 493            {
 447494                index++;
 495
 447496                if (values.Length - index < 1)
 497                {
 54498                    throw new InvalidDataException(string.Concat("A ", statement, " statement must specify a filename.")
 499                }
 500
 393501                switch (values[index].ToLowerInvariant())
 502                {
 503                    case "-type":
 33504                        if (values.Length - index < 2)
 505                        {
 3506                            throw new InvalidDataException(string.Concat("A ", statement, " -type option must specify a 
 507                        }
 508
 30509                        index++;
 30510                        break;
 511
 512                    case "-blenu":
 15513                        if (values.Length - index < 2)
 514                        {
 3515                            throw new InvalidDataException(string.Concat("A ", statement, " -blenu option must specify a
 516                        }
 517
 12518                        if (string.Equals(values[index + 1], "on", StringComparison.OrdinalIgnoreCase))
 519                        {
 3520                            map.IsHorizontalBlendingEnabled = true;
 521                        }
 9522                        else if (string.Equals(values[index + 1], "off", StringComparison.OrdinalIgnoreCase))
 523                        {
 3524                            map.IsHorizontalBlendingEnabled = false;
 525                        }
 526                        else
 527                        {
 6528                            throw new InvalidDataException(string.Concat("A ", statement, " -blenu option must specify o
 529                        }
 530
 6531                        index++;
 6532                        break;
 533
 534                    case "-blenv":
 15535                        if (values.Length - index < 2)
 536                        {
 3537                            throw new InvalidDataException(string.Concat("A ", statement, " -blenv option must specify a
 538                        }
 539
 12540                        if (string.Equals(values[index + 1], "on", StringComparison.OrdinalIgnoreCase))
 541                        {
 3542                            map.IsVerticalBlendingEnabled = true;
 543                        }
 9544                        else if (string.Equals(values[index + 1], "off", StringComparison.OrdinalIgnoreCase))
 545                        {
 3546                            map.IsVerticalBlendingEnabled = false;
 547                        }
 548                        else
 549                        {
 6550                            throw new InvalidDataException(string.Concat("A ", statement, " -blenv option must specify o
 551                        }
 552
 6553                        index++;
 6554                        break;
 555
 556                    case "-bm":
 9557                        if (values.Length - index < 2)
 558                        {
 3559                            throw new InvalidDataException(string.Concat("A ", statement, " -bm option must specify a va
 560                        }
 561
 6562                        map.BumpMultiplier = float.Parse(values[index + 1], CultureInfo.InvariantCulture);
 563
 6564                        index++;
 6565                        break;
 566
 567                    case "-boost":
 9568                        if (values.Length - index < 2)
 569                        {
 3570                            throw new InvalidDataException(string.Concat("A ", statement, " -boost option must specify a
 571                        }
 572
 6573                        map.Boost = float.Parse(values[index + 1], CultureInfo.InvariantCulture);
 574
 6575                        index++;
 6576                        break;
 577
 578                    case "-cc":
 15579                        if (values.Length - index < 2)
 580                        {
 3581                            throw new InvalidDataException(string.Concat("A ", statement, " -cc option must specify a va
 582                        }
 583
 12584                        if (string.Equals(values[index + 1], "on", StringComparison.OrdinalIgnoreCase))
 585                        {
 3586                            map.IsColorCorrectionEnabled = true;
 587                        }
 9588                        else if (string.Equals(values[index + 1], "off", StringComparison.OrdinalIgnoreCase))
 589                        {
 3590                            map.IsColorCorrectionEnabled = false;
 591                        }
 592                        else
 593                        {
 6594                            throw new InvalidDataException(string.Concat("A ", statement, " -cc option must specify on o
 595                        }
 596
 6597                        index++;
 6598                        break;
 599
 600                    case "-clamp":
 15601                        if (values.Length - index < 2)
 602                        {
 3603                            throw new InvalidDataException(string.Concat("A ", statement, " -clamp option must specify a
 604                        }
 605
 12606                        if (string.Equals(values[index + 1], "on", StringComparison.OrdinalIgnoreCase))
 607                        {
 3608                            map.IsClampingEnabled = true;
 609                        }
 9610                        else if (string.Equals(values[index + 1], "off", StringComparison.OrdinalIgnoreCase))
 611                        {
 3612                            map.IsClampingEnabled = false;
 613                        }
 614                        else
 615                        {
 6616                            throw new InvalidDataException(string.Concat("A ", statement, " -clamp option must specify o
 617                        }
 618
 6619                        index++;
 6620                        break;
 621
 622                    case "-imfchan":
 27623                        if (values.Length - index < 2)
 624                        {
 3625                            throw new InvalidDataException(string.Concat("A ", statement, " -imfchan option must specify
 626                        }
 627
 24628                        switch (values[index + 1].ToLowerInvariant())
 629                        {
 630                            case "r":
 3631                                map.ScalarChannel = ObjMapChannel.Red;
 3632                                break;
 633
 634                            case "g":
 3635                                map.ScalarChannel = ObjMapChannel.Green;
 3636                                break;
 637
 638                            case "b":
 3639                                map.ScalarChannel = ObjMapChannel.Blue;
 3640                                break;
 641
 642                            case "m":
 3643                                map.ScalarChannel = ObjMapChannel.Matte;
 3644                                break;
 645
 646                            case "l":
 3647                                map.ScalarChannel = ObjMapChannel.Luminance;
 3648                                break;
 649
 650                            case "z":
 3651                                map.ScalarChannel = ObjMapChannel.Depth;
 3652                                break;
 653
 654                            default:
 6655                                throw new InvalidDataException(string.Concat("A ", statement, " -imfchan option must spe
 656                        }
 657
 18658                        index++;
 18659                        break;
 660
 661                    case "-mm":
 12662                        if (values.Length - index < 3)
 663                        {
 6664                            throw new InvalidDataException(string.Concat("A ", statement, " -mm option must specify a ba
 665                        }
 666
 6667                        map.ModifierBase = float.Parse(values[index + 1], CultureInfo.InvariantCulture);
 6668                        map.ModifierGain = float.Parse(values[index + 2], CultureInfo.InvariantCulture);
 669
 6670                        index += 2;
 6671                        break;
 672
 673                    case "-o":
 15674                        if (values.Length - index < 2)
 675                        {
 3676                            throw new InvalidDataException(string.Concat("A ", statement, " -o option must specify at le
 677                        }
 678
 12679                        var offset = new ObjVector3();
 680
 12681                        offset.X = float.Parse(values[index + 1], CultureInfo.InvariantCulture);
 682
 12683                        if (values.Length - index > 3)
 684                        {
 6685                            offset.Y = float.Parse(values[index + 2], CultureInfo.InvariantCulture);
 686
 6687                            if (values.Length - index > 4)
 688                            {
 3689                                offset.Z = float.Parse(values[index + 3], CultureInfo.InvariantCulture);
 3690                                index++;
 691                            }
 692
 6693                            index++;
 694                        }
 695
 12696                        index++;
 697
 12698                        map.Offset = offset;
 12699                        break;
 700
 701                    case "-s":
 15702                        if (values.Length - index < 2)
 703                        {
 3704                            throw new InvalidDataException(string.Concat("A ", statement, " -s option must specify at le
 705                        }
 706
 12707                        var scale = new ObjVector3(1.0f, 1.0f, 1.0f);
 708
 12709                        scale.X = float.Parse(values[index + 1], CultureInfo.InvariantCulture);
 710
 12711                        if (values.Length - index > 3)
 712                        {
 6713                            scale.Y = float.Parse(values[index + 2], CultureInfo.InvariantCulture);
 714
 6715                            if (values.Length - index > 4)
 716                            {
 3717                                scale.Z = float.Parse(values[index + 3], CultureInfo.InvariantCulture);
 3718                                index++;
 719                            }
 720
 6721                            index++;
 722                        }
 723
 12724                        index++;
 725
 12726                        map.Scale = scale;
 12727                        break;
 728
 729                    case "-t":
 15730                        if (values.Length - index < 2)
 731                        {
 3732                            throw new InvalidDataException(string.Concat("A ", statement, " -t option must specify at le
 733                        }
 734
 12735                        var turbulence = new ObjVector3();
 736
 12737                        turbulence.X = float.Parse(values[index + 1], CultureInfo.InvariantCulture);
 738
 12739                        if (values.Length - index > 3)
 740                        {
 6741                            turbulence.Y = float.Parse(values[index + 2], CultureInfo.InvariantCulture);
 742
 6743                            if (values.Length - index > 4)
 744                            {
 3745                                turbulence.Z = float.Parse(values[index + 3], CultureInfo.InvariantCulture);
 3746                                index++;
 747                            }
 748
 6749                            index++;
 750                        }
 751
 12752                        index++;
 753
 12754                        map.Turbulence = turbulence;
 12755                        break;
 756
 757                    case "-texres":
 9758                        if (values.Length - index < 2)
 759                        {
 3760                            throw new InvalidDataException(string.Concat("A ", statement, " -texres option must specify 
 761                        }
 762
 6763                        map.TextureResolution = int.Parse(values[index + 1], CultureInfo.InvariantCulture);
 764
 6765                        index++;
 6766                        break;
 767
 768                    default:
 189769                        string filename = string.Join(" ", values, index, values.Length - index);
 770
 189771                        if (!Path.HasExtension(filename))
 772                        {
 30773                            throw new InvalidDataException("A filename must have an extension.");
 774                        }
 159775                        if (Path.GetExtension(filename).Contains(" "))
 776                        {
 30777                            throw new InvalidDataException("A filename extension must not have whitespace.");
 778                        }
 779
 129780                        map.FileName = filename;
 129781                        index = values.Length;
 782
 783                        break;
 784                }
 785            }
 786
 129787            return map;
 788        }
 789    }
 790}
 791