< Summary

Line coverage
100%
Covered lines: 421
Uncovered lines: 0
Coverable lines: 421
Total lines: 1005
Line coverage: 100%
Branch coverage
98%
Covered branches: 476
Total branches: 483
Branch coverage: 98.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
FromStream(...)97.8%319319100%
ParseMaterialColor(...)100%2222100%
ParseMaterialMap(...)100%142142100%

File(s)

https://raw.githubusercontent.com/JeremyAnsel/JeremyAnsel.Media.WavefrontObj/7b5b951766c69f14731a856f32198cdbf1fc6847/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
 8#if !NET6_0_OR_GREATER
 9
 10using System.Diagnostics.CodeAnalysis;
 11using System.Globalization;
 12
 13namespace JeremyAnsel.Media.WavefrontObj
 14{
 15    internal static class ObjMaterialFileReader
 16    {
 17        [SuppressMessage("Globalization", "CA1303:Ne pas passer de littéraux en paramètres localisés", Justification = "
 18        public static ObjMaterialFile FromStream(Stream? stream, ObjMaterialFileReaderSettings settings)
 19        {
 43320            if (stream == null)
 21            {
 122                throw new ArgumentNullException(nameof(stream));
 23            }
 24
 43225            var mtl = new ObjMaterialFile();
 43226            var lineReader = new LineReader();
 27
 43228            ObjMaterial? currentMaterial = null;
 29
 236530            foreach (string currentLine in lineReader.Read(stream))
 31            {
 82232                string[] values = currentLine.Split(LineReader.LineSeparators, StringSplitOptions.RemoveEmptyEntries);
 33
 82234                switch (values[0].ToLowerInvariant())
 35                {
 36                    case "newmtl":
 39737                        if (values.Length < 2)
 38                        {
 139                            throw new InvalidDataException("A newmtl statement must specify a name.");
 40                        }
 41
 39642                        currentMaterial = new ObjMaterial
 39643                        {
 39644                            Name = string.Join(" ", values, 1, values.Length - 1)
 39645                        };
 46
 39647                        mtl.Materials.Add(currentMaterial);
 48
 39649                        break;
 50
 51                    case "ka":
 1552                        if (currentMaterial == null)
 53                        {
 154                            throw new InvalidDataException("The material name is not specified.");
 55                        }
 56
 1457                        currentMaterial.AmbientColor = ObjMaterialFileReader.ParseMaterialColor("Ka", values);
 858                        break;
 59
 60                    case "kd":
 1561                        if (currentMaterial == null)
 62                        {
 163                            throw new InvalidDataException("The material name is not specified.");
 64                        }
 65
 1466                        currentMaterial.DiffuseColor = ObjMaterialFileReader.ParseMaterialColor("Kd", values);
 867                        break;
 68
 69                    case "ke":
 1570                        if (currentMaterial == null)
 71                        {
 172                            throw new InvalidDataException("The material name is not specified.");
 73                        }
 74
 1475                        currentMaterial.EmissiveColor = ObjMaterialFileReader.ParseMaterialColor("Ke", values);
 876                        break;
 77
 78                    case "ks":
 1579                        if (currentMaterial == null)
 80                        {
 181                            throw new InvalidDataException("The material name is not specified.");
 82                        }
 83
 1484                        currentMaterial.SpecularColor = ObjMaterialFileReader.ParseMaterialColor("Ks", values);
 885                        break;
 86
 87                    case "tf":
 1588                        if (currentMaterial == null)
 89                        {
 190                            throw new InvalidDataException("The material name is not specified.");
 91                        }
 92
 1493                        currentMaterial.TransmissionColor = ObjMaterialFileReader.ParseMaterialColor("Tf", values);
 894                        break;
 95
 96                    case "illum":
 497                        if (currentMaterial == null)
 98                        {
 199                            throw new InvalidDataException("The material name is not specified.");
 100                        }
 101
 3102                        if (values.Length < 2)
 103                        {
 1104                            throw new InvalidDataException("An illum statement must specify an illumination model.");
 105                        }
 106
 2107                        if (values.Length != 2)
 108                        {
 1109                            throw new InvalidDataException("An illum statement has too many values.");
 110                        }
 111
 1112                        currentMaterial.IlluminationModel = int.Parse(values[1], CultureInfo.InvariantCulture);
 1113                        break;
 114
 115                    case "d":
 7116                        if (currentMaterial == null)
 117                        {
 1118                            throw new InvalidDataException("The material name is not specified.");
 119                        }
 120
 6121                        if (values.Length < 2)
 122                        {
 1123                            throw new InvalidDataException("A d statement must specify a factor.");
 124                        }
 125
 5126                        if (string.Equals(values[1], "-halo", StringComparison.OrdinalIgnoreCase))
 127                        {
 3128                            if (values.Length < 3)
 129                            {
 1130                                throw new InvalidDataException("A d statement must specify a factor.");
 131                            }
 132
 2133                            if (values.Length != 3)
 134                            {
 1135                                throw new InvalidDataException("A d statement has too many values.");
 136                            }
 137
 1138                            currentMaterial.IsHaloDissolve = true;
 1139                            currentMaterial.DissolveFactor = float.Parse(values[2], CultureInfo.InvariantCulture);
 140                        }
 141                        else
 142                        {
 2143                            if (values.Length != 2)
 144                            {
 1145                                throw new InvalidDataException("A d statement has too many values.");
 146                            }
 147
 1148                            currentMaterial.DissolveFactor = float.Parse(values[1], CultureInfo.InvariantCulture);
 149                        }
 150
 1151                        break;
 152
 153                    case "ns":
 4154                        if (currentMaterial == null)
 155                        {
 1156                            throw new InvalidDataException("The material name is not specified.");
 157                        }
 158
 3159                        if (values.Length < 2)
 160                        {
 1161                            throw new InvalidDataException("A Ns statement must specify a specular exponent.");
 162                        }
 163
 2164                        if (values.Length != 2)
 165                        {
 1166                            throw new InvalidDataException("A Ns statement has too many values.");
 167                        }
 168
 1169                        currentMaterial.SpecularExponent = float.Parse(values[1], CultureInfo.InvariantCulture);
 1170                        break;
 171
 172                    case "sharpness":
 4173                        if (currentMaterial == null)
 174                        {
 1175                            throw new InvalidDataException("The material name is not specified.");
 176                        }
 177
 3178                        if (values.Length < 2)
 179                        {
 1180                            throw new InvalidDataException("A sharpness statement must specify a sharpness value.");
 181                        }
 182
 2183                        if (values.Length != 2)
 184                        {
 1185                            throw new InvalidDataException("A sharpness statement has too many values.");
 186                        }
 187
 1188                        currentMaterial.Sharpness = int.Parse(values[1], CultureInfo.InvariantCulture);
 1189                        break;
 190
 191                    case "ni":
 4192                        if (currentMaterial == null)
 193                        {
 1194                            throw new InvalidDataException("The material name is not specified.");
 195                        }
 196
 3197                        if (values.Length < 2)
 198                        {
 1199                            throw new InvalidDataException("A Ni statement must specify an optical density.");
 200                        }
 201
 2202                        if (values.Length != 2)
 203                        {
 1204                            throw new InvalidDataException("A Ni statement has too many values.");
 205                        }
 206
 1207                        currentMaterial.OpticalDensity = float.Parse(values[1], CultureInfo.InvariantCulture);
 1208                        break;
 209
 210                    case "map_aat":
 6211                        if (currentMaterial == null)
 212                        {
 1213                            throw new InvalidDataException("The material name is not specified.");
 214                        }
 215
 5216                        if (values.Length < 2)
 217                        {
 1218                            throw new InvalidDataException("A map_aat statement must specify a value.");
 219                        }
 220
 4221                        if (values.Length != 2)
 222                        {
 1223                            throw new InvalidDataException("A map_aat statement has too many values.");
 224                        }
 225
 3226                        if (string.Equals(values[1], "on", StringComparison.OrdinalIgnoreCase))
 227                        {
 1228                            currentMaterial.IsAntiAliasingEnabled = true;
 229                        }
 2230                        else if (string.Equals(values[1], "off", StringComparison.OrdinalIgnoreCase))
 231                        {
 1232                            currentMaterial.IsAntiAliasingEnabled = false;
 233                        }
 234                        else
 235                        {
 1236                            throw new InvalidDataException("A map_aat statement must specify on or off.");
 237                        }
 238
 239                        break;
 240
 241                    case "map_ka":
 132242                        if (currentMaterial == null)
 243                        {
 1244                            throw new InvalidDataException("The material name is not specified.");
 245                        }
 246
 131247                        currentMaterial.AmbientMap = ObjMaterialFileReader.ParseMaterialMap("map_Ka", values, currentLin
 97248                        break;
 249
 250                    case "map_kd":
 13251                        if (currentMaterial == null)
 252                        {
 1253                            throw new InvalidDataException("The material name is not specified.");
 254                        }
 255
 12256                        currentMaterial.DiffuseMap = ObjMaterialFileReader.ParseMaterialMap("map_Kd", values, currentLin
 11257                        break;
 258
 259                    case "map_ke":
 13260                        if (currentMaterial == null)
 261                        {
 1262                            throw new InvalidDataException("The material name is not specified.");
 263                        }
 264
 12265                        currentMaterial.EmissiveMap = ObjMaterialFileReader.ParseMaterialMap("map_Ke", values, currentLi
 11266                        break;
 267
 268                    case "map_ks":
 13269                        if (currentMaterial == null)
 270                        {
 1271                            throw new InvalidDataException("The material name is not specified.");
 272                        }
 273
 12274                        currentMaterial.SpecularMap = ObjMaterialFileReader.ParseMaterialMap("map_Ks", values, currentLi
 11275                        break;
 276
 277                    case "map_ns":
 13278                        if (currentMaterial == null)
 279                        {
 1280                            throw new InvalidDataException("The material name is not specified.");
 281                        }
 282
 12283                        currentMaterial.SpecularExponentMap = ObjMaterialFileReader.ParseMaterialMap("map_Ns", values, c
 11284                        break;
 285
 286                    case "map_d":
 287                    case "map_tr":
 13288                        if (currentMaterial == null)
 289                        {
 1290                            throw new InvalidDataException("The material name is not specified.");
 291                        }
 292
 12293                        currentMaterial.DissolveMap = ObjMaterialFileReader.ParseMaterialMap("map_d", values, currentLin
 11294                        break;
 295
 296                    case "decal":
 297                    case "map_decal":
 5298                        if (currentMaterial == null)
 299                        {
 1300                            throw new InvalidDataException("The material name is not specified.");
 301                        }
 302
 4303                        currentMaterial.DecalMap = ObjMaterialFileReader.ParseMaterialMap("decal", values, currentLine, 
 3304                        break;
 305
 306                    case "disp":
 307                    case "map_disp":
 5308                        if (currentMaterial == null)
 309                        {
 1310                            throw new InvalidDataException("The material name is not specified.");
 311                        }
 312
 4313                        currentMaterial.DispMap = ObjMaterialFileReader.ParseMaterialMap("disp", values, currentLine, se
 3314                        break;
 315
 316                    case "bump":
 317                    case "map_bump":
 3318                        if (currentMaterial == null)
 319                        {
 1320                            throw new InvalidDataException("The material name is not specified.");
 321                        }
 322
 2323                        currentMaterial.BumpMap = ObjMaterialFileReader.ParseMaterialMap("bump", values, currentLine, se
 1324                        break;
 325
 326                    case "refl":
 327                    case "map_refl":
 28328                        if (currentMaterial == null)
 329                        {
 1330                            throw new InvalidDataException("The material name is not specified.");
 331                        }
 332
 27333                        if (values.Length < 4)
 334                        {
 4335                            throw new InvalidDataException("A refl statement must specify a type and a file name.");
 336                        }
 337
 23338                        if (!string.Equals(values[1], "-type", StringComparison.OrdinalIgnoreCase))
 339                        {
 1340                            throw new InvalidDataException("A refl statement must specify a type.");
 341                        }
 342
 22343                        switch (values[2].ToLowerInvariant())
 344                        {
 345                            case "sphere":
 3346                                currentMaterial.ReflectionMap.Sphere = ObjMaterialFileReader.ParseMaterialMap("refl", va
 3347                                break;
 348
 349                            case "cube_top":
 3350                                currentMaterial.ReflectionMap.CubeTop = ObjMaterialFileReader.ParseMaterialMap("refl", v
 3351                                break;
 352
 353                            case "cube_bottom":
 3354                                currentMaterial.ReflectionMap.CubeBottom = ObjMaterialFileReader.ParseMaterialMap("refl"
 3355                                break;
 356
 357                            case "cube_front":
 3358                                currentMaterial.ReflectionMap.CubeFront = ObjMaterialFileReader.ParseMaterialMap("refl",
 3359                                break;
 360
 361                            case "cube_back":
 3362                                currentMaterial.ReflectionMap.CubeBack = ObjMaterialFileReader.ParseMaterialMap("refl", 
 3363                                break;
 364
 365                            case "cube_left":
 3366                                currentMaterial.ReflectionMap.CubeLeft = ObjMaterialFileReader.ParseMaterialMap("refl", 
 3367                                break;
 368
 369                            case "cube_right":
 3370                                currentMaterial.ReflectionMap.CubeRight = ObjMaterialFileReader.ParseMaterialMap("refl",
 3371                                break;
 372                        }
 373
 374                        break;
 375                    case "pr":
 4376                        if (currentMaterial == null)
 377                        {
 1378                            throw new InvalidDataException("The material name is not specified.");
 379                        }
 380
 3381                        if (values.Length < 2)
 382                        {
 1383                            throw new InvalidDataException("A Pr statement must specify an optical density.");
 384                        }
 385
 2386                        if (values.Length != 2)
 387                        {
 1388                            throw new InvalidDataException("A Pr statement has too many values.");
 389                        }
 390
 1391                        currentMaterial.Roughness = float.Parse(values[1], CultureInfo.InvariantCulture);
 1392                        break;
 393                    case "map_pr":
 13394                        if (currentMaterial == null)
 395                        {
 1396                            throw new InvalidDataException("The material name is not specified.");
 397                        }
 398
 12399                        currentMaterial.RoughnessMap = ObjMaterialFileReader.ParseMaterialMap("map_Pr", values, currentL
 11400                        break;
 401                    case "pm":
 4402                        if (currentMaterial == null)
 403                        {
 1404                            throw new InvalidDataException("The material name is not specified.");
 405                        }
 406
 3407                        if (values.Length < 2)
 408                        {
 1409                            throw new InvalidDataException("A Pm statement must specify an optical density.");
 410                        }
 411
 2412                        if (values.Length != 2)
 413                        {
 1414                            throw new InvalidDataException("A Pm statement has too many values.");
 415                        }
 416
 1417                        currentMaterial.Metallic = float.Parse(values[1], CultureInfo.InvariantCulture);
 1418                        break;
 419                    case "map_pm":
 13420                        if (currentMaterial == null)
 421                        {
 1422                            throw new InvalidDataException("The material name is not specified.");
 423                        }
 424
 12425                        currentMaterial.MetallicMap = ObjMaterialFileReader.ParseMaterialMap("map_Pm", values, currentLi
 11426                        break;
 427                    case "ps":
 4428                        if (currentMaterial == null)
 429                        {
 1430                            throw new InvalidDataException("The material name is not specified.");
 431                        }
 432
 3433                        if (values.Length < 2)
 434                        {
 1435                            throw new InvalidDataException("A Ps statement must specify an optical density.");
 436                        }
 437
 2438                        if (values.Length != 2)
 439                        {
 1440                            throw new InvalidDataException("A Ps statement has too many values.");
 441                        }
 442
 1443                        currentMaterial.Sheen = float.Parse(values[1], CultureInfo.InvariantCulture);
 1444                        break;
 445                    case "map_ps":
 13446                        if (currentMaterial == null)
 447                        {
 1448                            throw new InvalidDataException("The material name is not specified.");
 449                        }
 450
 12451                        currentMaterial.SheenMap = ObjMaterialFileReader.ParseMaterialMap("map_Ps", values, currentLine,
 11452                        break;
 453                    case "pc":
 4454                        if (currentMaterial == null)
 455                        {
 1456                            throw new InvalidDataException("The material name is not specified.");
 457                        }
 458
 3459                        if (values.Length < 2)
 460                        {
 1461                            throw new InvalidDataException("A Pc statement must specify an optical density.");
 462                        }
 463
 2464                        if (values.Length != 2)
 465                        {
 1466                            throw new InvalidDataException("A Pc statement has too many values.");
 467                        }
 468
 1469                        currentMaterial.ClearCoatThickness = float.Parse(values[1], CultureInfo.InvariantCulture);
 1470                        break;
 471                    case "pcr":
 4472                        if (currentMaterial == null)
 473                        {
 1474                            throw new InvalidDataException("The material name is not specified.");
 475                        }
 476
 3477                        if (values.Length < 2)
 478                        {
 1479                            throw new InvalidDataException("A Pcr statement must specify an optical density.");
 480                        }
 481
 2482                        if (values.Length != 2)
 483                        {
 1484                            throw new InvalidDataException("A Pcr statement has too many values.");
 485                        }
 486
 1487                        currentMaterial.ClearCoatRoughness = float.Parse(values[1], CultureInfo.InvariantCulture);
 1488                        break;
 489                    case "aniso":
 4490                        if (currentMaterial == null)
 491                        {
 1492                            throw new InvalidDataException("The material name is not specified.");
 493                        }
 494
 3495                        if (values.Length < 2)
 496                        {
 1497                            throw new InvalidDataException("A aniso statement must specify an optical density.");
 498                        }
 499
 2500                        if (values.Length != 2)
 501                        {
 1502                            throw new InvalidDataException("A aniso statement has too many values.");
 503                        }
 504
 1505                        currentMaterial.Anisotropy = float.Parse(values[1], CultureInfo.InvariantCulture);
 1506                        break;
 507                    case "anisor":
 4508                        if (currentMaterial == null)
 509                        {
 1510                            throw new InvalidDataException("The material name is not specified.");
 511                        }
 512
 3513                        if (values.Length < 2)
 514                        {
 1515                            throw new InvalidDataException("A anisor statement must specify an optical density.");
 516                        }
 517
 2518                        if (values.Length != 2)
 519                        {
 1520                            throw new InvalidDataException("A anisor statement has too many values.");
 521                        }
 522
 1523                        currentMaterial.AnisotropyRotation = float.Parse(values[1], CultureInfo.InvariantCulture);
 1524                        break;
 525                    case "norm":
 13526                        if (currentMaterial == null)
 527                        {
 1528                            throw new InvalidDataException("The material name is not specified.");
 529                        }
 530
 12531                        currentMaterial.Norm = ObjMaterialFileReader.ParseMaterialMap("norm", values, currentLine, setti
 532                        break;
 533                }
 534            }
 535
 289536            mtl.HeaderText = string.Join("\n", lineReader.HeaderTextLines.ToArray());
 537
 289538            return mtl;
 539        }
 540
 541        [SuppressMessage("Globalization", "CA1303:Ne pas passer de littéraux en paramètres localisés", Justification = "
 542        private static ObjMaterialColor ParseMaterialColor(string statement, string[] values)
 543        {
 70544            if (values.Length < 2)
 545            {
 5546                throw new InvalidDataException(string.Concat("A ", statement, " statement must specify a color."));
 547            }
 548
 65549            var color = new ObjMaterialColor();
 550
 65551            int index = 1;
 552
 65553            switch (values[1].ToLowerInvariant())
 554            {
 555                case "spectral":
 20556                    index++;
 557
 20558                    if (values.Length - index < 1)
 559                    {
 5560                        throw new InvalidDataException(string.Concat("A ", statement, " spectral statement must specify 
 561                    }
 562
 15563                    color.SpectralFileName = values[index];
 15564                    index++;
 565
 15566                    if (values.Length > index)
 567                    {
 10568                        color.SpectralFactor = float.Parse(values[index], CultureInfo.InvariantCulture);
 10569                        index++;
 570                    }
 571
 10572                    break;
 573
 574                case "xyz":
 575                    {
 20576                        index++;
 577
 20578                        if (values.Length - index < 1)
 579                        {
 5580                            throw new InvalidDataException(string.Concat("A ", statement, " xyz statement must specify a
 581                        }
 582
 15583                        color.UseXYZColorSpace = true;
 584
 15585                        var xyz = new ObjVector3();
 586
 15587                        xyz.X = float.Parse(values[index], CultureInfo.InvariantCulture);
 15588                        index++;
 589
 15590                        if (values.Length > index)
 591                        {
 10592                            if (values.Length - index < 2)
 593                            {
 5594                                throw new InvalidDataException(string.Concat("A ", statement, " xyz statement must speci
 595                            }
 596
 5597                            xyz.Y = float.Parse(values[index], CultureInfo.InvariantCulture);
 5598                            xyz.Z = float.Parse(values[index + 1], CultureInfo.InvariantCulture);
 5599                            index += 2;
 600                        }
 601                        else
 602                        {
 5603                            xyz.Y = xyz.X;
 5604                            xyz.Z = xyz.X;
 605                        }
 606
 10607                        color.Color = xyz;
 10608                        break;
 609                    }
 610
 611                default:
 612                    {
 25613                        var rgb = new ObjVector3();
 614
 25615                        rgb.X = float.Parse(values[index], CultureInfo.InvariantCulture);
 25616                        index++;
 617
 25618                        if (values.Length > index)
 619                        {
 20620                            if (values.Length - index < 2)
 621                            {
 5622                                throw new InvalidDataException(string.Concat("A ", statement, " statement must specify a
 623                            }
 624
 15625                            rgb.Y = float.Parse(values[index], CultureInfo.InvariantCulture);
 15626                            rgb.Z = float.Parse(values[index + 1], CultureInfo.InvariantCulture);
 15627                            index += 2;
 628                        }
 629                        else
 630                        {
 5631                            rgb.Y = rgb.X;
 5632                            rgb.Z = rgb.X;
 633                        }
 634
 20635                        color.Color = rgb;
 636                        break;
 637                    }
 638            }
 639
 45640            if (index != values.Length)
 641            {
 5642                throw new InvalidDataException(string.Concat("A ", statement, " statement has too many values."));
 643            }
 644
 40645            return color;
 646        }
 647
 648        [SuppressMessage("Globalization", "CA1303:Ne pas passer de littéraux en paramètres localisés", Justification = "
 649        private static ObjMaterialMap ParseMaterialMap(string statement, string[] values, string currentLine, ObjMateria
 650        {
 270651            var map = new ObjMaterialMap();
 652
 879653            for (int index = 0; index < values.Length;)
 654            {
 385655                index++;
 656
 385657                if (values.Length - index < 1)
 658                {
 22659                    throw new InvalidDataException(string.Concat("A ", statement, " statement must specify a filename.")
 660                }
 661
 363662                switch (values[index].ToLowerInvariant())
 663                {
 664                    case "-type":
 23665                        if (values.Length - index < 2)
 666                        {
 1667                            throw new InvalidDataException(string.Concat("A ", statement, " -type option must specify a 
 668                        }
 669
 22670                        index++;
 22671                        break;
 672
 673                    case "-blenu":
 7674                        if (values.Length - index < 2)
 675                        {
 1676                            throw new InvalidDataException(string.Concat("A ", statement, " -blenu option must specify a
 677                        }
 678
 6679                        if (string.Equals(values[index + 1], "on", StringComparison.OrdinalIgnoreCase))
 680                        {
 2681                            map.IsHorizontalBlendingEnabled = true;
 682                        }
 4683                        else if (string.Equals(values[index + 1], "off", StringComparison.OrdinalIgnoreCase))
 684                        {
 2685                            map.IsHorizontalBlendingEnabled = false;
 686                        }
 687                        else
 688                        {
 2689                            throw new InvalidDataException(string.Concat("A ", statement, " -blenu option must specify o
 690                        }
 691
 4692                        index++;
 4693                        break;
 694
 695                    case "-blenv":
 7696                        if (values.Length - index < 2)
 697                        {
 1698                            throw new InvalidDataException(string.Concat("A ", statement, " -blenv option must specify a
 699                        }
 700
 6701                        if (string.Equals(values[index + 1], "on", StringComparison.OrdinalIgnoreCase))
 702                        {
 2703                            map.IsVerticalBlendingEnabled = true;
 704                        }
 4705                        else if (string.Equals(values[index + 1], "off", StringComparison.OrdinalIgnoreCase))
 706                        {
 2707                            map.IsVerticalBlendingEnabled = false;
 708                        }
 709                        else
 710                        {
 2711                            throw new InvalidDataException(string.Concat("A ", statement, " -blenv option must specify o
 712                        }
 713
 4714                        index++;
 4715                        break;
 716
 717                    case "-bm":
 6718                        if (values.Length - index < 2)
 719                        {
 1720                            throw new InvalidDataException(string.Concat("A ", statement, " -bm option must specify a va
 721                        }
 722
 5723                        map.BumpMultiplier = float.Parse(values[index + 1], CultureInfo.InvariantCulture);
 724
 5725                        index++;
 5726                        break;
 727
 728                    case "-boost":
 6729                        if (values.Length - index < 2)
 730                        {
 1731                            throw new InvalidDataException(string.Concat("A ", statement, " -boost option must specify a
 732                        }
 733
 5734                        map.Boost = float.Parse(values[index + 1], CultureInfo.InvariantCulture);
 735
 5736                        index++;
 5737                        break;
 738
 739                    case "-cc":
 7740                        if (values.Length - index < 2)
 741                        {
 1742                            throw new InvalidDataException(string.Concat("A ", statement, " -cc option must specify a va
 743                        }
 744
 6745                        if (string.Equals(values[index + 1], "on", StringComparison.OrdinalIgnoreCase))
 746                        {
 2747                            map.IsColorCorrectionEnabled = true;
 748                        }
 4749                        else if (string.Equals(values[index + 1], "off", StringComparison.OrdinalIgnoreCase))
 750                        {
 2751                            map.IsColorCorrectionEnabled = false;
 752                        }
 753                        else
 754                        {
 2755                            throw new InvalidDataException(string.Concat("A ", statement, " -cc option must specify on o
 756                        }
 757
 4758                        index++;
 4759                        break;
 760
 761                    case "-clamp":
 7762                        if (values.Length - index < 2)
 763                        {
 1764                            throw new InvalidDataException(string.Concat("A ", statement, " -clamp option must specify a
 765                        }
 766
 6767                        if (string.Equals(values[index + 1], "on", StringComparison.OrdinalIgnoreCase))
 768                        {
 2769                            map.IsClampingEnabled = true;
 770                        }
 4771                        else if (string.Equals(values[index + 1], "off", StringComparison.OrdinalIgnoreCase))
 772                        {
 2773                            map.IsClampingEnabled = false;
 774                        }
 775                        else
 776                        {
 2777                            throw new InvalidDataException(string.Concat("A ", statement, " -clamp option must specify o
 778                        }
 779
 4780                        index++;
 4781                        break;
 782
 783                    case "-imfchan":
 21784                        if (values.Length - index < 2)
 785                        {
 1786                            throw new InvalidDataException(string.Concat("A ", statement, " -imfchan option must specify
 787                        }
 788
 20789                        switch (values[index + 1].ToLowerInvariant())
 790                        {
 791                            case "r":
 3792                                map.ScalarChannel = ObjMapChannel.Red;
 3793                                break;
 794
 795                            case "g":
 3796                                map.ScalarChannel = ObjMapChannel.Green;
 3797                                break;
 798
 799                            case "b":
 3800                                map.ScalarChannel = ObjMapChannel.Blue;
 3801                                break;
 802
 803                            case "m":
 3804                                map.ScalarChannel = ObjMapChannel.Matte;
 3805                                break;
 806
 807                            case "l":
 3808                                map.ScalarChannel = ObjMapChannel.Luminance;
 3809                                break;
 810
 811                            case "z":
 3812                                map.ScalarChannel = ObjMapChannel.Depth;
 3813                                break;
 814
 815                            default:
 2816                                throw new InvalidDataException(string.Concat("A ", statement, " -imfchan option must spe
 817                        }
 818
 18819                        index++;
 18820                        break;
 821
 822                    case "-mm":
 7823                        if (values.Length - index < 3)
 824                        {
 2825                            throw new InvalidDataException(string.Concat("A ", statement, " -mm option must specify a ba
 826                        }
 827
 5828                        map.ModifierBase = float.Parse(values[index + 1], CultureInfo.InvariantCulture);
 5829                        map.ModifierGain = float.Parse(values[index + 2], CultureInfo.InvariantCulture);
 830
 5831                        index += 2;
 5832                        break;
 833
 834                    case "-o":
 14835                        if (values.Length - index < 2)
 836                        {
 1837                            throw new InvalidDataException(string.Concat("A ", statement, " -o option must specify at le
 838                        }
 839
 13840                        var offset = new ObjVector3();
 841
 13842                        offset.X = float.Parse(values[index + 1], CultureInfo.InvariantCulture);
 13843                        index++;
 844
 13845                        if (values.Length - index > 2)
 846                        {
 10847                            if (float.TryParse(values[index + 1], NumberStyles.Float, CultureInfo.InvariantCulture, out 
 848                            {
 8849                                offset.Y = v;
 8850                                index++;
 851                            }
 852                            else
 853                            {
 2854                                map.Offset = offset;
 2855                                break;
 856                            }
 857
 8858                            if (values.Length - index > 2)
 859                            {
 6860                                if (float.TryParse(values[index + 1], NumberStyles.Float, CultureInfo.InvariantCulture, 
 861                                {
 4862                                    offset.Z = v;
 4863                                    index++;
 864                                }
 865                                else
 866                                {
 2867                                    map.Offset = offset;
 2868                                    break;
 869                                }
 870                            }
 871                        }
 872
 9873                        map.Offset = offset;
 9874                        break;
 875
 876                    case "-s":
 877                        {
 14878                            if (values.Length - index < 2)
 879                            {
 1880                                throw new InvalidDataException(string.Concat("A ", statement, " -s option must specify a
 881                            }
 882
 13883                            var scale = new ObjVector3(1.0f, 1.0f, 1.0f);
 884
 13885                            scale.X = float.Parse(values[index + 1], CultureInfo.InvariantCulture);
 13886                            index++;
 887
 13888                            if (values.Length - index > 2)
 889                            {
 10890                                if (float.TryParse(values[index + 1], NumberStyles.Float, CultureInfo.InvariantCulture, 
 891                                {
 8892                                    scale.Y = v;
 8893                                    index++;
 894                                }
 895                                else
 896                                {
 2897                                    map.Scale = scale;
 2898                                    break;
 899                                }
 900
 8901                                if (values.Length - index > 2)
 902                                {
 6903                                    if (float.TryParse(values[index + 1], NumberStyles.Float, CultureInfo.InvariantCultu
 904                                    {
 4905                                        scale.Z = v;
 4906                                        index++;
 907                                    }
 908                                    else
 909                                    {
 2910                                        map.Scale = scale;
 2911                                        break;
 912                                    }
 913                                }
 914                            }
 915
 9916                            map.Scale = scale;
 9917                            break;
 918                        }
 919
 920                    case "-t":
 921                        {
 14922                            if (values.Length - index < 2)
 923                            {
 1924                                throw new InvalidDataException(string.Concat("A ", statement, " -t option must specify a
 925                            }
 926
 13927                            var turbulence = new ObjVector3();
 928
 13929                            turbulence.X = float.Parse(values[index + 1], CultureInfo.InvariantCulture);
 13930                            index++;
 931
 13932                            if (values.Length - index > 2)
 933                            {
 10934                                if (float.TryParse(values[index + 1], NumberStyles.Float, CultureInfo.InvariantCulture, 
 935                                {
 8936                                    turbulence.Y = v;
 8937                                    index++;
 938                                }
 939                                else
 940                                {
 2941                                    map.Turbulence = turbulence;
 2942                                    break;
 943                                }
 944
 8945                                if (values.Length - index > 2)
 946                                {
 6947                                    if (float.TryParse(values[index + 1], NumberStyles.Float, CultureInfo.InvariantCultu
 948                                    {
 4949                                        turbulence.Z = v;
 4950                                        index++;
 951                                    }
 952                                    else
 953                                    {
 2954                                        map.Turbulence = turbulence;
 2955                                        break;
 956                                    }
 957                                }
 958                            }
 959
 9960                            map.Turbulence = turbulence;
 9961                            break;
 962                        }
 963
 964                    case "-texres":
 6965                        if (values.Length - index < 2)
 966                        {
 1967                            throw new InvalidDataException(string.Concat("A ", statement, " -texres option must specify 
 968                        }
 969
 5970                        map.TextureResolution = int.Parse(values[index + 1], CultureInfo.InvariantCulture);
 971
 5972                        index++;
 5973                        break;
 974
 975                    default:
 976                        {
 224977                            if (settings.KeepWhitespacesOfMapFileReferences)
 978                            {
 70979                                var charsRead = 0;
 340980                                for (var i = 1; i < index; i++)
 981                                {
 100982                                    charsRead += values[i].Length;
 983                                }
 70984                                map.FileName = currentLine.Remove(0, statement.Length + charsRead + index);
 985                            }
 986                            else
 987                            {
 154988                                string filename = string.Join(" ", values, index, values.Length - index);
 989
 154990                                map.FileName = filename;
 991                            }
 224992                            index = values.Length;
 993
 994                            break;
 995                        }
 996                }
 997            }
 998
 224999            return map;
 1000        }
 1001    }
 1002}
 1003
 1004#endif
 1005