| | 1 | | // <copyright file="ObjMaterialFileReader9.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 | |
|
| | 10 | | using System.Diagnostics.CodeAnalysis; |
| | 11 | | using System.Globalization; |
| | 12 | | using System.Text; |
| | 13 | |
|
| | 14 | | #if NET9_0_OR_GREATER |
| | 15 | | using SpanSplitEnumerator = System.MemoryExtensions.SpanSplitEnumerator<char>; |
| | 16 | | #else |
| | 17 | | using SpanSplitEnumerator = Polyfills.Polyfill.SpanSplitEnumerator<char>; |
| | 18 | | #endif |
| | 19 | |
|
| | 20 | | namespace JeremyAnsel.Media.WavefrontObj |
| | 21 | | { |
| | 22 | | internal static class ObjMaterialFileReader9 |
| | 23 | | { |
| | 24 | | private static void MoveNextSkipEmpty(ref SpanSplitEnumerator values) |
| | 25 | | { |
| 3966 | 26 | | while (values.MoveNext()) |
| | 27 | | { |
| 3966 | 28 | | if (values.Current.Start.Value != values.Current.End.Value) |
| | 29 | | { |
| 3948 | 30 | | return; |
| | 31 | | } |
| | 32 | | } |
| 0 | 33 | | } |
| | 34 | |
|
| | 35 | | private static ReadOnlySpan<char> GetNextValue(ref ReadOnlySpan<char> currentLine, ref SpanSplitEnumerator value |
| | 36 | | { |
| 2199 | 37 | | MoveNextSkipEmpty(ref values); |
| 2199 | 38 | | return currentLine[values.Current]; |
| | 39 | | } |
| | 40 | |
|
| | 41 | | private static float FloatParse(ReadOnlySpan<char> s) |
| | 42 | | { |
| 345 | 43 | | return float.Parse(s, NumberStyles.Float, CultureInfo.InvariantCulture); |
| | 44 | | } |
| | 45 | |
|
| | 46 | | private static int IntParse(ReadOnlySpan<char> s) |
| | 47 | | { |
| 12 | 48 | | return int.Parse(s, NumberStyles.Integer, CultureInfo.InvariantCulture); |
| | 49 | | } |
| | 50 | |
|
| | 51 | | [SuppressMessage("Globalization", "CA1303:Ne pas passer de littéraux en paramètres localisés", Justification = " |
| | 52 | | public static ObjMaterialFile FromStream(Stream? stream) |
| | 53 | | { |
| 939 | 54 | | if (stream == null) |
| | 55 | | { |
| 3 | 56 | | throw new ArgumentNullException(nameof(stream)); |
| | 57 | | } |
| | 58 | |
|
| 936 | 59 | | var mtl = new ObjMaterialFile(); |
| 936 | 60 | | var lineReader = new LineReader9(); |
| | 61 | |
|
| 936 | 62 | | ObjMaterial? currentMaterial = null; |
| | 63 | |
|
| 936 | 64 | | int valueBufferSize = 16; |
| 936 | 65 | | Span<char> valueBuffer = stackalloc char[valueBufferSize]; |
| | 66 | |
|
| 4941 | 67 | | foreach (var currentLineString in lineReader.Read9(stream)) |
| | 68 | | { |
| 1749 | 69 | | ReadOnlySpan<char> currentLine = currentLineString.Buffer.AsSpan()[..currentLineString.Length]; |
| | 70 | |
|
| 1749 | 71 | | int valuesCount = 0; |
| | 72 | |
|
| 11796 | 73 | | foreach (Range range in currentLine.SplitAny(LineReader9.LineSeparators)) |
| | 74 | | { |
| 4149 | 75 | | if (currentLine[range].Length == 0) |
| | 76 | | { |
| | 77 | | continue; |
| | 78 | | } |
| | 79 | |
|
| 4113 | 80 | | valuesCount++; |
| | 81 | | } |
| | 82 | |
|
| 1749 | 83 | | SpanSplitEnumerator values = currentLine.SplitAny(LineReader9.LineSeparators); |
| | 84 | |
|
| 1749 | 85 | | MoveNextSkipEmpty(ref values); |
| | 86 | |
|
| 1749 | 87 | | if (values.Current.End.Value - values.Current.Start.Value > valueBufferSize) |
| | 88 | | { |
| | 89 | | continue; |
| | 90 | | } |
| | 91 | |
|
| 1746 | 92 | | ReadOnlySpan<char> value0 = currentLine[values.Current]; |
| 1746 | 93 | | int value0Length = value0.ToLowerInvariant(valueBuffer); |
| | 94 | |
|
| | 95 | | //if (value0Length == -1) |
| | 96 | | //{ |
| | 97 | | // throw new InvalidDataException("the buffer is too small"); |
| | 98 | | //} |
| | 99 | |
|
| 1746 | 100 | | switch (valueBuffer[..value0Length]) |
| | 101 | | { |
| | 102 | | case "newmtl": |
| | 103 | | { |
| 831 | 104 | | if (valuesCount < 2) |
| | 105 | | { |
| 3 | 106 | | throw new InvalidDataException("A newmtl statement must specify a name."); |
| | 107 | | } |
| | 108 | |
|
| 828 | 109 | | var sb = new StringBuilder(); |
| | 110 | |
|
| 828 | 111 | | sb.Append(GetNextValue(ref currentLine, ref values)); |
| | 112 | |
|
| 1668 | 113 | | for (int i = 2; i < valuesCount; i++) |
| | 114 | | { |
| 6 | 115 | | sb.Append(' '); |
| 6 | 116 | | sb.Append(GetNextValue(ref currentLine, ref values)); |
| | 117 | | } |
| | 118 | |
|
| 828 | 119 | | currentMaterial = new ObjMaterial |
| 828 | 120 | | { |
| 828 | 121 | | Name = sb.ToString() |
| 828 | 122 | | }; |
| | 123 | |
|
| 828 | 124 | | mtl.Materials.Add(currentMaterial); |
| | 125 | |
|
| 828 | 126 | | break; |
| | 127 | | } |
| | 128 | |
|
| | 129 | | case "ka": |
| 45 | 130 | | if (currentMaterial == null) |
| | 131 | | { |
| 3 | 132 | | throw new InvalidDataException("The material name is not specified."); |
| | 133 | | } |
| | 134 | |
|
| 42 | 135 | | currentMaterial.AmbientColor = ParseMaterialColor("Ka", value0, ref currentLine, ref values, val |
| 24 | 136 | | break; |
| | 137 | |
|
| | 138 | | case "kd": |
| 45 | 139 | | if (currentMaterial == null) |
| | 140 | | { |
| 3 | 141 | | throw new InvalidDataException("The material name is not specified."); |
| | 142 | | } |
| | 143 | |
|
| 42 | 144 | | currentMaterial.DiffuseColor = ParseMaterialColor("Kd", value0, ref currentLine, ref values, val |
| 24 | 145 | | break; |
| | 146 | |
|
| | 147 | | case "ke": |
| 45 | 148 | | if (currentMaterial == null) |
| | 149 | | { |
| 3 | 150 | | throw new InvalidDataException("The material name is not specified."); |
| | 151 | | } |
| | 152 | |
|
| 42 | 153 | | currentMaterial.EmissiveColor = ParseMaterialColor("Ke", value0, ref currentLine, ref values, va |
| 24 | 154 | | break; |
| | 155 | |
|
| | 156 | | case "ks": |
| 45 | 157 | | if (currentMaterial == null) |
| | 158 | | { |
| 3 | 159 | | throw new InvalidDataException("The material name is not specified."); |
| | 160 | | } |
| | 161 | |
|
| 42 | 162 | | currentMaterial.SpecularColor = ParseMaterialColor("Ks", value0, ref currentLine, ref values, va |
| 24 | 163 | | break; |
| | 164 | |
|
| | 165 | | case "tf": |
| 45 | 166 | | if (currentMaterial == null) |
| | 167 | | { |
| 3 | 168 | | throw new InvalidDataException("The material name is not specified."); |
| | 169 | | } |
| | 170 | |
|
| 42 | 171 | | currentMaterial.TransmissionColor = ParseMaterialColor("Tf", value0, ref currentLine, ref values |
| 24 | 172 | | break; |
| | 173 | |
|
| | 174 | | case "illum": |
| 12 | 175 | | if (currentMaterial == null) |
| | 176 | | { |
| 3 | 177 | | throw new InvalidDataException("The material name is not specified."); |
| | 178 | | } |
| | 179 | |
|
| 9 | 180 | | if (valuesCount < 2) |
| | 181 | | { |
| 3 | 182 | | throw new InvalidDataException("An illum statement must specify an illumination model."); |
| | 183 | | } |
| | 184 | |
|
| 6 | 185 | | if (valuesCount != 2) |
| | 186 | | { |
| 3 | 187 | | throw new InvalidDataException("An illum statement has too many values."); |
| | 188 | | } |
| | 189 | |
|
| 3 | 190 | | currentMaterial.IlluminationModel = IntParse(GetNextValue(ref currentLine, ref values)); |
| 3 | 191 | | break; |
| | 192 | |
|
| | 193 | | case "d": |
| | 194 | | { |
| 21 | 195 | | if (currentMaterial == null) |
| | 196 | | { |
| 3 | 197 | | throw new InvalidDataException("The material name is not specified."); |
| | 198 | | } |
| | 199 | |
|
| 18 | 200 | | if (valuesCount < 2) |
| | 201 | | { |
| 3 | 202 | | throw new InvalidDataException("A d statement must specify a factor."); |
| | 203 | | } |
| | 204 | |
|
| 15 | 205 | | var value1 = GetNextValue(ref currentLine, ref values); |
| | 206 | |
|
| 15 | 207 | | if (value1.Equals("-halo", StringComparison.OrdinalIgnoreCase)) |
| | 208 | | { |
| 9 | 209 | | if (valuesCount < 3) |
| | 210 | | { |
| 3 | 211 | | throw new InvalidDataException("A d statement must specify a factor."); |
| | 212 | | } |
| | 213 | |
|
| 6 | 214 | | if (valuesCount != 3) |
| | 215 | | { |
| 3 | 216 | | throw new InvalidDataException("A d statement has too many values."); |
| | 217 | | } |
| | 218 | |
|
| 3 | 219 | | currentMaterial.IsHaloDissolve = true; |
| 3 | 220 | | currentMaterial.DissolveFactor = FloatParse(GetNextValue(ref currentLine, ref values)); |
| | 221 | | } |
| | 222 | | else |
| | 223 | | { |
| 6 | 224 | | if (valuesCount != 2) |
| | 225 | | { |
| 3 | 226 | | throw new InvalidDataException("A d statement has too many values."); |
| | 227 | | } |
| | 228 | |
|
| 3 | 229 | | currentMaterial.DissolveFactor = FloatParse(value1); |
| | 230 | | } |
| | 231 | |
|
| 3 | 232 | | break; |
| | 233 | | } |
| | 234 | |
|
| | 235 | | case "ns": |
| 12 | 236 | | if (currentMaterial == null) |
| | 237 | | { |
| 3 | 238 | | throw new InvalidDataException("The material name is not specified."); |
| | 239 | | } |
| | 240 | |
|
| 9 | 241 | | if (valuesCount < 2) |
| | 242 | | { |
| 3 | 243 | | throw new InvalidDataException("A Ns statement must specify a specular exponent."); |
| | 244 | | } |
| | 245 | |
|
| 6 | 246 | | if (valuesCount != 2) |
| | 247 | | { |
| 3 | 248 | | throw new InvalidDataException("A Ns statement has too many values."); |
| | 249 | | } |
| | 250 | |
|
| 3 | 251 | | currentMaterial.SpecularExponent = FloatParse(GetNextValue(ref currentLine, ref values)); |
| 3 | 252 | | break; |
| | 253 | |
|
| | 254 | | case "sharpness": |
| 12 | 255 | | if (currentMaterial == null) |
| | 256 | | { |
| 3 | 257 | | throw new InvalidDataException("The material name is not specified."); |
| | 258 | | } |
| | 259 | |
|
| 9 | 260 | | if (valuesCount < 2) |
| | 261 | | { |
| 3 | 262 | | throw new InvalidDataException("A sharpness statement must specify a sharpness value."); |
| | 263 | | } |
| | 264 | |
|
| 6 | 265 | | if (valuesCount != 2) |
| | 266 | | { |
| 3 | 267 | | throw new InvalidDataException("A sharpness statement has too many values."); |
| | 268 | | } |
| | 269 | |
|
| 3 | 270 | | currentMaterial.Sharpness = IntParse(GetNextValue(ref currentLine, ref values)); |
| 3 | 271 | | break; |
| | 272 | |
|
| | 273 | | case "ni": |
| 12 | 274 | | if (currentMaterial == null) |
| | 275 | | { |
| 3 | 276 | | throw new InvalidDataException("The material name is not specified."); |
| | 277 | | } |
| | 278 | |
|
| 9 | 279 | | if (valuesCount < 2) |
| | 280 | | { |
| 3 | 281 | | throw new InvalidDataException("A Ni statement must specify an optical density."); |
| | 282 | | } |
| | 283 | |
|
| 6 | 284 | | if (valuesCount != 2) |
| | 285 | | { |
| 3 | 286 | | throw new InvalidDataException("A Ni statement has too many values."); |
| | 287 | | } |
| | 288 | |
|
| 3 | 289 | | currentMaterial.OpticalDensity = FloatParse(GetNextValue(ref currentLine, ref values)); |
| 3 | 290 | | break; |
| | 291 | |
|
| | 292 | | case "map_aat": |
| | 293 | | { |
| 18 | 294 | | if (currentMaterial == null) |
| | 295 | | { |
| 3 | 296 | | throw new InvalidDataException("The material name is not specified."); |
| | 297 | | } |
| | 298 | |
|
| 15 | 299 | | if (valuesCount < 2) |
| | 300 | | { |
| 3 | 301 | | throw new InvalidDataException("A map_aat statement must specify a value."); |
| | 302 | | } |
| | 303 | |
|
| 12 | 304 | | if (valuesCount != 2) |
| | 305 | | { |
| 3 | 306 | | throw new InvalidDataException("A map_aat statement has too many values."); |
| | 307 | | } |
| | 308 | |
|
| 9 | 309 | | var value1 = GetNextValue(ref currentLine, ref values); |
| | 310 | |
|
| 9 | 311 | | if (value1.Equals("on", StringComparison.OrdinalIgnoreCase)) |
| | 312 | | { |
| 3 | 313 | | currentMaterial.IsAntiAliasingEnabled = true; |
| | 314 | | } |
| 6 | 315 | | else if (value1.Equals("off", StringComparison.OrdinalIgnoreCase)) |
| | 316 | | { |
| 3 | 317 | | currentMaterial.IsAntiAliasingEnabled = false; |
| | 318 | | } |
| | 319 | | else |
| | 320 | | { |
| 3 | 321 | | throw new InvalidDataException("A map_aat statement must specify on or off."); |
| | 322 | | } |
| | 323 | |
|
| | 324 | | break; |
| | 325 | | } |
| | 326 | |
|
| | 327 | | case "map_ka": |
| 201 | 328 | | if (currentMaterial == null) |
| | 329 | | { |
| 3 | 330 | | throw new InvalidDataException("The material name is not specified."); |
| | 331 | | } |
| | 332 | |
|
| 198 | 333 | | currentMaterial.AmbientMap = ParseMaterialMap("map_Ka", value0, ref currentLine, ref values, val |
| 96 | 334 | | break; |
| | 335 | |
|
| | 336 | | case "map_kd": |
| 21 | 337 | | if (currentMaterial == null) |
| | 338 | | { |
| 3 | 339 | | throw new InvalidDataException("The material name is not specified."); |
| | 340 | | } |
| | 341 | |
|
| 18 | 342 | | currentMaterial.DiffuseMap = ParseMaterialMap("map_Kd", value0, ref currentLine, ref values, val |
| 15 | 343 | | break; |
| | 344 | |
|
| | 345 | | case "map_ke": |
| 21 | 346 | | if (currentMaterial == null) |
| | 347 | | { |
| 3 | 348 | | throw new InvalidDataException("The material name is not specified."); |
| | 349 | | } |
| | 350 | |
|
| 18 | 351 | | currentMaterial.EmissiveMap = ParseMaterialMap("map_Ke", value0, ref currentLine, ref values, va |
| 15 | 352 | | break; |
| | 353 | |
|
| | 354 | | case "map_ks": |
| 21 | 355 | | if (currentMaterial == null) |
| | 356 | | { |
| 3 | 357 | | throw new InvalidDataException("The material name is not specified."); |
| | 358 | | } |
| | 359 | |
|
| 18 | 360 | | currentMaterial.SpecularMap = ParseMaterialMap("map_Ks", value0, ref currentLine, ref values, va |
| 15 | 361 | | break; |
| | 362 | |
|
| | 363 | | case "map_ns": |
| 21 | 364 | | if (currentMaterial == null) |
| | 365 | | { |
| 3 | 366 | | throw new InvalidDataException("The material name is not specified."); |
| | 367 | | } |
| | 368 | |
|
| 18 | 369 | | currentMaterial.SpecularExponentMap = ParseMaterialMap("map_Ns", value0, ref currentLine, ref va |
| 15 | 370 | | break; |
| | 371 | |
|
| | 372 | | case "map_d": |
| | 373 | | case "map_tr": |
| 21 | 374 | | if (currentMaterial == null) |
| | 375 | | { |
| 3 | 376 | | throw new InvalidDataException("The material name is not specified."); |
| | 377 | | } |
| | 378 | |
|
| 18 | 379 | | currentMaterial.DissolveMap = ParseMaterialMap("map_d", value0, ref currentLine, ref values, val |
| 15 | 380 | | break; |
| | 381 | |
|
| | 382 | | case "decal": |
| | 383 | | case "map_decal": |
| 15 | 384 | | if (currentMaterial == null) |
| | 385 | | { |
| 3 | 386 | | throw new InvalidDataException("The material name is not specified."); |
| | 387 | | } |
| | 388 | |
|
| 12 | 389 | | currentMaterial.DecalMap = ParseMaterialMap("decal", value0, ref currentLine, ref values, values |
| 9 | 390 | | break; |
| | 391 | |
|
| | 392 | | case "disp": |
| | 393 | | case "map_disp": |
| 15 | 394 | | if (currentMaterial == null) |
| | 395 | | { |
| 3 | 396 | | throw new InvalidDataException("The material name is not specified."); |
| | 397 | | } |
| | 398 | |
|
| 12 | 399 | | currentMaterial.DispMap = ParseMaterialMap("disp", value0, ref currentLine, ref values, valuesCo |
| 9 | 400 | | break; |
| | 401 | |
|
| | 402 | | case "bump": |
| | 403 | | case "map_bump": |
| 9 | 404 | | if (currentMaterial == null) |
| | 405 | | { |
| 3 | 406 | | throw new InvalidDataException("The material name is not specified."); |
| | 407 | | } |
| | 408 | |
|
| 6 | 409 | | currentMaterial.BumpMap = ParseMaterialMap("bump", value0, ref currentLine, ref values, valuesCo |
| 3 | 410 | | break; |
| | 411 | |
|
| | 412 | | case "refl": |
| | 413 | | case "map_refl": |
| 84 | 414 | | if (currentMaterial == null) |
| | 415 | | { |
| 3 | 416 | | throw new InvalidDataException("The material name is not specified."); |
| | 417 | | } |
| | 418 | |
|
| 81 | 419 | | if (valuesCount < 4) |
| | 420 | | { |
| 12 | 421 | | throw new InvalidDataException("A refl statement must specify a type and a file name."); |
| | 422 | | } |
| | 423 | |
|
| 69 | 424 | | ObjMaterialMap materialMap = ParseMaterialMap("refl", value0, ref currentLine, ref values, value |
| | 425 | |
|
| | 426 | | switch (materialMapType) |
| | 427 | | { |
| | 428 | | case MaterialMapType.Sphere: |
| 9 | 429 | | currentMaterial.ReflectionMap.Sphere = materialMap; |
| 9 | 430 | | break; |
| | 431 | |
|
| | 432 | | case MaterialMapType.CubeTop: |
| 9 | 433 | | currentMaterial.ReflectionMap.CubeTop = materialMap; |
| 9 | 434 | | break; |
| | 435 | |
|
| | 436 | | case MaterialMapType.CubeBottom: |
| 9 | 437 | | currentMaterial.ReflectionMap.CubeBottom = materialMap; |
| 9 | 438 | | break; |
| | 439 | |
|
| | 440 | | case MaterialMapType.CubeFront: |
| 9 | 441 | | currentMaterial.ReflectionMap.CubeFront = materialMap; |
| 9 | 442 | | break; |
| | 443 | |
|
| | 444 | | case MaterialMapType.CubeBack: |
| 9 | 445 | | currentMaterial.ReflectionMap.CubeBack = materialMap; |
| 9 | 446 | | break; |
| | 447 | |
|
| | 448 | | case MaterialMapType.CubeLeft: |
| 9 | 449 | | currentMaterial.ReflectionMap.CubeLeft = materialMap; |
| 9 | 450 | | break; |
| | 451 | |
|
| | 452 | | case MaterialMapType.CubeRight: |
| 9 | 453 | | currentMaterial.ReflectionMap.CubeRight = materialMap; |
| 9 | 454 | | break; |
| | 455 | | } |
| | 456 | |
|
| | 457 | | break; |
| | 458 | | case "pr": |
| 12 | 459 | | if (currentMaterial == null) |
| | 460 | | { |
| 3 | 461 | | throw new InvalidDataException("The material name is not specified."); |
| | 462 | | } |
| | 463 | |
|
| 9 | 464 | | if (valuesCount < 2) |
| | 465 | | { |
| 3 | 466 | | throw new InvalidDataException("A Pr statement must specify an optical density."); |
| | 467 | | } |
| | 468 | |
|
| 6 | 469 | | if (valuesCount != 2) |
| | 470 | | { |
| 3 | 471 | | throw new InvalidDataException("A Pr statement has too many values."); |
| | 472 | | } |
| | 473 | |
|
| 3 | 474 | | currentMaterial.Roughness = FloatParse(GetNextValue(ref currentLine, ref values)); |
| 3 | 475 | | break; |
| | 476 | | case "map_pr": |
| 21 | 477 | | if (currentMaterial == null) |
| | 478 | | { |
| 3 | 479 | | throw new InvalidDataException("The material name is not specified."); |
| | 480 | | } |
| | 481 | |
|
| 18 | 482 | | currentMaterial.RoughnessMap = ParseMaterialMap("map_Pr", value0, ref currentLine, ref values, v |
| 15 | 483 | | break; |
| | 484 | | case "pm": |
| 12 | 485 | | if (currentMaterial == null) |
| | 486 | | { |
| 3 | 487 | | throw new InvalidDataException("The material name is not specified."); |
| | 488 | | } |
| | 489 | |
|
| 9 | 490 | | if (valuesCount < 2) |
| | 491 | | { |
| 3 | 492 | | throw new InvalidDataException("A Pm statement must specify an optical density."); |
| | 493 | | } |
| | 494 | |
|
| 6 | 495 | | if (valuesCount != 2) |
| | 496 | | { |
| 3 | 497 | | throw new InvalidDataException("A Pm statement has too many values."); |
| | 498 | | } |
| | 499 | |
|
| 3 | 500 | | currentMaterial.Metallic = FloatParse(GetNextValue(ref currentLine, ref values)); |
| 3 | 501 | | break; |
| | 502 | | case "map_pm": |
| 21 | 503 | | if (currentMaterial == null) |
| | 504 | | { |
| 3 | 505 | | throw new InvalidDataException("The material name is not specified."); |
| | 506 | | } |
| | 507 | |
|
| 18 | 508 | | currentMaterial.MetallicMap = ParseMaterialMap("map_Pm", value0, ref currentLine, ref values, va |
| 15 | 509 | | break; |
| | 510 | | case "ps": |
| 12 | 511 | | if (currentMaterial == null) |
| | 512 | | { |
| 3 | 513 | | throw new InvalidDataException("The material name is not specified."); |
| | 514 | | } |
| | 515 | |
|
| 9 | 516 | | if (valuesCount < 2) |
| | 517 | | { |
| 3 | 518 | | throw new InvalidDataException("A Ps statement must specify an optical density."); |
| | 519 | | } |
| | 520 | |
|
| 6 | 521 | | if (valuesCount != 2) |
| | 522 | | { |
| 3 | 523 | | throw new InvalidDataException("A Ps statement has too many values."); |
| | 524 | | } |
| | 525 | |
|
| 3 | 526 | | currentMaterial.Sheen = FloatParse(GetNextValue(ref currentLine, ref values)); |
| 3 | 527 | | break; |
| | 528 | | case "map_ps": |
| 21 | 529 | | if (currentMaterial == null) |
| | 530 | | { |
| 3 | 531 | | throw new InvalidDataException("The material name is not specified."); |
| | 532 | | } |
| | 533 | |
|
| 18 | 534 | | currentMaterial.SheenMap = ParseMaterialMap("map_Ps", value0, ref currentLine, ref values, value |
| 15 | 535 | | break; |
| | 536 | | case "pc": |
| 12 | 537 | | if (currentMaterial == null) |
| | 538 | | { |
| 3 | 539 | | throw new InvalidDataException("The material name is not specified."); |
| | 540 | | } |
| | 541 | |
|
| 9 | 542 | | if (valuesCount < 2) |
| | 543 | | { |
| 3 | 544 | | throw new InvalidDataException("A Pc statement must specify an optical density."); |
| | 545 | | } |
| | 546 | |
|
| 6 | 547 | | if (valuesCount != 2) |
| | 548 | | { |
| 3 | 549 | | throw new InvalidDataException("A Pc statement has too many values."); |
| | 550 | | } |
| | 551 | |
|
| 3 | 552 | | currentMaterial.ClearCoatThickness = FloatParse(GetNextValue(ref currentLine, ref values)); |
| 3 | 553 | | break; |
| | 554 | | case "pcr": |
| 12 | 555 | | if (currentMaterial == null) |
| | 556 | | { |
| 3 | 557 | | throw new InvalidDataException("The material name is not specified."); |
| | 558 | | } |
| | 559 | |
|
| 9 | 560 | | if (valuesCount < 2) |
| | 561 | | { |
| 3 | 562 | | throw new InvalidDataException("A Pcr statement must specify an optical density."); |
| | 563 | | } |
| | 564 | |
|
| 6 | 565 | | if (valuesCount != 2) |
| | 566 | | { |
| 3 | 567 | | throw new InvalidDataException("A Pcr statement has too many values."); |
| | 568 | | } |
| | 569 | |
|
| 3 | 570 | | currentMaterial.ClearCoatRoughness = FloatParse(GetNextValue(ref currentLine, ref values)); |
| 3 | 571 | | break; |
| | 572 | | case "aniso": |
| 12 | 573 | | if (currentMaterial == null) |
| | 574 | | { |
| 3 | 575 | | throw new InvalidDataException("The material name is not specified."); |
| | 576 | | } |
| | 577 | |
|
| 9 | 578 | | if (valuesCount < 2) |
| | 579 | | { |
| 3 | 580 | | throw new InvalidDataException("A aniso statement must specify an optical density."); |
| | 581 | | } |
| | 582 | |
|
| 6 | 583 | | if (valuesCount != 2) |
| | 584 | | { |
| 3 | 585 | | throw new InvalidDataException("A aniso statement has too many values."); |
| | 586 | | } |
| | 587 | |
|
| 3 | 588 | | currentMaterial.Anisotropy = FloatParse(GetNextValue(ref currentLine, ref values)); |
| 3 | 589 | | break; |
| | 590 | | case "anisor": |
| 12 | 591 | | if (currentMaterial == null) |
| | 592 | | { |
| 3 | 593 | | throw new InvalidDataException("The material name is not specified."); |
| | 594 | | } |
| | 595 | |
|
| 9 | 596 | | if (valuesCount < 2) |
| | 597 | | { |
| 3 | 598 | | throw new InvalidDataException("A anisor statement must specify an optical density."); |
| | 599 | | } |
| | 600 | |
|
| 6 | 601 | | if (valuesCount != 2) |
| | 602 | | { |
| 3 | 603 | | throw new InvalidDataException("A anisor statement has too many values."); |
| | 604 | | } |
| | 605 | |
|
| 3 | 606 | | currentMaterial.AnisotropyRotation = FloatParse(GetNextValue(ref currentLine, ref values)); |
| 3 | 607 | | break; |
| | 608 | | case "norm": |
| 21 | 609 | | if (currentMaterial == null) |
| | 610 | | { |
| 3 | 611 | | throw new InvalidDataException("The material name is not specified."); |
| | 612 | | } |
| | 613 | |
|
| 18 | 614 | | currentMaterial.Norm = ParseMaterialMap("norm", value0, ref currentLine, ref values, valuesCount |
| | 615 | | break; |
| | 616 | | } |
| | 617 | | } |
| | 618 | |
|
| 507 | 619 | | mtl.HeaderText = string.Join("\n", lineReader.HeaderTextLines.ToArray()); |
| | 620 | |
|
| 507 | 621 | | return mtl; |
| | 622 | | } |
| | 623 | |
|
| | 624 | | [SuppressMessage("Globalization", "CA1303:Ne pas passer de littéraux en paramètres localisés", Justification = " |
| | 625 | | private static ObjMaterialColor ParseMaterialColor(ReadOnlySpan<char> statement, ReadOnlySpan<char> value0, ref |
| | 626 | | { |
| 210 | 627 | | if (valuesCount < 2) |
| | 628 | | { |
| 15 | 629 | | throw new InvalidDataException(string.Concat("A ", statement, " statement must specify a color.")); |
| | 630 | | } |
| | 631 | |
|
| 195 | 632 | | var color = new ObjMaterialColor(); |
| | 633 | |
|
| 195 | 634 | | int valueBufferSize = 16; |
| 195 | 635 | | Span<char> valueBuffer = stackalloc char[valueBufferSize]; |
| | 636 | |
|
| 195 | 637 | | ReadOnlySpan<char> value1 = GetNextValue(ref currentLine, ref values); |
| 195 | 638 | | int value1Length = value1.ToLowerInvariant(valueBuffer); |
| | 639 | |
|
| | 640 | | //if (value1Length == -1) |
| | 641 | | //{ |
| | 642 | | // throw new InvalidDataException("the buffer is too small"); |
| | 643 | | //} |
| | 644 | |
|
| 195 | 645 | | int index = 1; |
| | 646 | |
|
| 195 | 647 | | switch (valueBuffer[..value1Length]) |
| | 648 | | { |
| | 649 | | case "spectral": |
| 75 | 650 | | index++; |
| | 651 | |
|
| 75 | 652 | | if (valuesCount - index < 1) |
| | 653 | | { |
| 15 | 654 | | throw new InvalidDataException(string.Concat("A ", statement, " spectral statement must specify |
| | 655 | | } |
| | 656 | |
|
| 60 | 657 | | color.SpectralFileName = GetNextValue(ref currentLine, ref values).ToString(); |
| 60 | 658 | | index++; |
| | 659 | |
|
| 60 | 660 | | if (valuesCount > index) |
| | 661 | | { |
| 30 | 662 | | color.SpectralFactor = FloatParse(GetNextValue(ref currentLine, ref values)); |
| 30 | 663 | | index++; |
| | 664 | | } |
| | 665 | |
|
| 30 | 666 | | break; |
| | 667 | |
|
| | 668 | | case "xyz": |
| 60 | 669 | | index++; |
| | 670 | |
|
| 60 | 671 | | if (valuesCount - index < 1) |
| | 672 | | { |
| 15 | 673 | | throw new InvalidDataException(string.Concat("A ", statement, " xyz statement must specify a col |
| | 674 | | } |
| | 675 | |
|
| 45 | 676 | | color.UseXYZColorSpace = true; |
| | 677 | |
|
| 45 | 678 | | var xyz = new ObjVector3(); |
| | 679 | |
|
| 45 | 680 | | xyz.X = FloatParse(GetNextValue(ref currentLine, ref values)); |
| 45 | 681 | | index++; |
| | 682 | |
|
| 45 | 683 | | if (valuesCount > index) |
| | 684 | | { |
| 30 | 685 | | if (valuesCount - index < 2) |
| | 686 | | { |
| 15 | 687 | | throw new InvalidDataException(string.Concat("A ", statement, " xyz statement must specify a |
| | 688 | | } |
| | 689 | |
|
| 15 | 690 | | xyz.Y = FloatParse(GetNextValue(ref currentLine, ref values)); |
| 15 | 691 | | xyz.Z = FloatParse(GetNextValue(ref currentLine, ref values)); |
| 15 | 692 | | index += 2; |
| | 693 | | } |
| | 694 | | else |
| | 695 | | { |
| 15 | 696 | | xyz.Y = xyz.X; |
| 15 | 697 | | xyz.Z = xyz.X; |
| | 698 | | } |
| | 699 | |
|
| 30 | 700 | | color.Color = xyz; |
| 30 | 701 | | break; |
| | 702 | |
|
| | 703 | | default: |
| 60 | 704 | | var rgb = new ObjVector3(); |
| | 705 | |
|
| 60 | 706 | | rgb.X = FloatParse(value1); |
| 60 | 707 | | index++; |
| | 708 | |
|
| 60 | 709 | | if (valuesCount > index) |
| | 710 | | { |
| 45 | 711 | | if (valuesCount - index < 2) |
| | 712 | | { |
| 15 | 713 | | throw new InvalidDataException(string.Concat("A ", statement, " statement must specify a RGB |
| | 714 | | } |
| | 715 | |
|
| 30 | 716 | | rgb.Y = FloatParse(GetNextValue(ref currentLine, ref values)); |
| 30 | 717 | | rgb.Z = FloatParse(GetNextValue(ref currentLine, ref values)); |
| 30 | 718 | | index += 2; |
| | 719 | | } |
| | 720 | | else |
| | 721 | | { |
| 15 | 722 | | rgb.Y = rgb.X; |
| 15 | 723 | | rgb.Z = rgb.X; |
| | 724 | | } |
| | 725 | |
|
| 45 | 726 | | color.Color = rgb; |
| | 727 | | break; |
| | 728 | | } |
| | 729 | |
|
| 135 | 730 | | if (index != valuesCount) |
| | 731 | | { |
| 15 | 732 | | throw new InvalidDataException(string.Concat("A ", statement, " statement has too many values.")); |
| | 733 | | } |
| | 734 | |
|
| 120 | 735 | | return color; |
| | 736 | | } |
| | 737 | |
|
| | 738 | | private enum MaterialMapType |
| | 739 | | { |
| | 740 | | None, |
| | 741 | | Sphere, |
| | 742 | | CubeTop, |
| | 743 | | CubeBottom, |
| | 744 | | CubeFront, |
| | 745 | | CubeBack, |
| | 746 | | CubeLeft, |
| | 747 | | CubeRight |
| | 748 | | } |
| | 749 | |
|
| | 750 | | [SuppressMessage("Globalization", "CA1303:Ne pas passer de littéraux en paramètres localisés", Justification = " |
| | 751 | | private static ObjMaterialMap ParseMaterialMap(ReadOnlySpan<char> statement, ReadOnlySpan<char> value0, ref Read |
| | 752 | | { |
| 390 | 753 | | return ParseMaterialMap(statement, value0, ref currentLine, ref values, valuesCount, out _); |
| | 754 | | } |
| | 755 | |
|
| | 756 | | [SuppressMessage("Globalization", "CA1303:Ne pas passer de littéraux en paramètres localisés", Justification = " |
| | 757 | | private static ObjMaterialMap ParseMaterialMap(ReadOnlySpan<char> statement, ReadOnlySpan<char> value0, ref Read |
| | 758 | | { |
| 459 | 759 | | materialMapType = MaterialMapType.None; |
| | 760 | |
|
| 459 | 761 | | var map = new ObjMaterialMap(); |
| | 762 | |
|
| 459 | 763 | | int valueBufferSize = 16; |
| 459 | 764 | | Span<char> valueBuffer = stackalloc char[valueBufferSize]; |
| | 765 | |
|
| 1347 | 766 | | for (int index = 0; index < valuesCount;) |
| | 767 | | { |
| 630 | 768 | | index++; |
| | 769 | |
|
| 630 | 770 | | if (valuesCount - index < 1) |
| | 771 | | { |
| 66 | 772 | | throw new InvalidDataException(string.Concat("A ", statement, " statement must specify a filename.") |
| | 773 | | } |
| | 774 | |
|
| 564 | 775 | | ReadOnlySpan<char> value1 = GetNextValue(ref currentLine, ref values); |
| 564 | 776 | | int value1Length = value1.ToLowerInvariant(valueBuffer); |
| | 777 | |
|
| | 778 | | // Value1Length is -1 when the buffer is too small. |
| | 779 | | // This should only happen if the value is a file name and not an option |
| 564 | 780 | | if (value1Length == -1) |
| | 781 | | { |
| 60 | 782 | | if (index == 1) |
| | 783 | | { |
| 60 | 784 | | if (statement.Equals("refl", StringComparison.OrdinalIgnoreCase)) |
| | 785 | | { |
| 0 | 786 | | throw new InvalidDataException("A refl statement must specify a type."); |
| | 787 | | } |
| | 788 | | } |
| | 789 | |
|
| 60 | 790 | | var sb = new StringBuilder(); |
| | 791 | |
|
| 60 | 792 | | sb.Append(value1); |
| | 793 | |
|
| 180 | 794 | | for (int i = index + 1; i < valuesCount; i++) |
| | 795 | | { |
| 30 | 796 | | sb.Append(' '); |
| 30 | 797 | | sb.Append(GetNextValue(ref currentLine, ref values)); |
| | 798 | | } |
| | 799 | |
|
| 60 | 800 | | string filename = sb.ToString(); |
| | 801 | |
|
| 60 | 802 | | map.FileName = filename; |
| 60 | 803 | | return map; |
| | 804 | | } |
| | 805 | |
|
| 504 | 806 | | if (statement.Equals("refl", StringComparison.OrdinalIgnoreCase)) |
| | 807 | | { |
| 135 | 808 | | if (index == 1) |
| | 809 | | { |
| 69 | 810 | | if (!MemoryExtensions.Equals(valueBuffer[..value1Length], "-type", StringComparison.OrdinalIgnor |
| | 811 | | { |
| 3 | 812 | | throw new InvalidDataException("A refl statement must specify a type."); |
| | 813 | | } |
| | 814 | | } |
| | 815 | | } |
| | 816 | |
|
| 501 | 817 | | switch (valueBuffer[..value1Length]) |
| | 818 | | { |
| | 819 | | case "-type": |
| 72 | 820 | | if (valuesCount - index < 2) |
| | 821 | | { |
| 3 | 822 | | throw new InvalidDataException(string.Concat("A ", statement, " -type option must specify a |
| | 823 | | } |
| | 824 | |
|
| 69 | 825 | | if (statement.Equals("refl", StringComparison.OrdinalIgnoreCase)) |
| | 826 | | { |
| 66 | 827 | | ReadOnlySpan<char> value2 = GetNextValue(ref currentLine, ref values); |
| 66 | 828 | | int value2Length = value2.ToLowerInvariant(valueBuffer); |
| | 829 | |
|
| | 830 | | //if (value2Length == -1) |
| | 831 | | //{ |
| | 832 | | // throw new InvalidDataException("the buffer is too small"); |
| | 833 | | //} |
| | 834 | |
|
| 66 | 835 | | switch (valueBuffer[..value2Length]) |
| | 836 | | { |
| | 837 | | case "sphere": |
| 9 | 838 | | materialMapType = MaterialMapType.Sphere; |
| 9 | 839 | | break; |
| | 840 | |
|
| | 841 | | case "cube_top": |
| 9 | 842 | | materialMapType = MaterialMapType.CubeTop; |
| 9 | 843 | | break; |
| | 844 | |
|
| | 845 | | case "cube_bottom": |
| 9 | 846 | | materialMapType = MaterialMapType.CubeBottom; |
| 9 | 847 | | break; |
| | 848 | |
|
| | 849 | | case "cube_front": |
| 9 | 850 | | materialMapType = MaterialMapType.CubeFront; |
| 9 | 851 | | break; |
| | 852 | |
|
| | 853 | | case "cube_back": |
| 9 | 854 | | materialMapType = MaterialMapType.CubeBack; |
| 9 | 855 | | break; |
| | 856 | |
|
| | 857 | | case "cube_left": |
| 9 | 858 | | materialMapType = MaterialMapType.CubeLeft; |
| 9 | 859 | | break; |
| | 860 | |
|
| | 861 | | case "cube_right": |
| 9 | 862 | | materialMapType = MaterialMapType.CubeRight; |
| 9 | 863 | | break; |
| | 864 | | } |
| | 865 | | } |
| | 866 | | else |
| | 867 | | { |
| 3 | 868 | | GetNextValue(ref currentLine, ref values); |
| | 869 | | } |
| | 870 | |
|
| 69 | 871 | | index++; |
| 69 | 872 | | break; |
| | 873 | |
|
| | 874 | | case "-blenu": |
| | 875 | | { |
| 15 | 876 | | if (valuesCount - index < 2) |
| | 877 | | { |
| 3 | 878 | | throw new InvalidDataException(string.Concat("A ", statement, " -blenu option must speci |
| | 879 | | } |
| | 880 | |
|
| 12 | 881 | | var value2 = GetNextValue(ref currentLine, ref values); |
| | 882 | |
|
| 12 | 883 | | if (value2.Equals("on", StringComparison.OrdinalIgnoreCase)) |
| | 884 | | { |
| 3 | 885 | | map.IsHorizontalBlendingEnabled = true; |
| | 886 | | } |
| 9 | 887 | | else if (value2.Equals("off", StringComparison.OrdinalIgnoreCase)) |
| | 888 | | { |
| 3 | 889 | | map.IsHorizontalBlendingEnabled = false; |
| | 890 | | } |
| | 891 | | else |
| | 892 | | { |
| 6 | 893 | | throw new InvalidDataException(string.Concat("A ", statement, " -blenu option must speci |
| | 894 | | } |
| | 895 | |
|
| 6 | 896 | | index++; |
| 6 | 897 | | break; |
| | 898 | | } |
| | 899 | |
|
| | 900 | | case "-blenv": |
| | 901 | | { |
| 15 | 902 | | if (valuesCount - index < 2) |
| | 903 | | { |
| 3 | 904 | | throw new InvalidDataException(string.Concat("A ", statement, " -blenv option must speci |
| | 905 | | } |
| | 906 | |
|
| 12 | 907 | | var value2 = GetNextValue(ref currentLine, ref values); |
| | 908 | |
|
| 12 | 909 | | if (value2.Equals("on", StringComparison.OrdinalIgnoreCase)) |
| | 910 | | { |
| 3 | 911 | | map.IsVerticalBlendingEnabled = true; |
| | 912 | | } |
| 9 | 913 | | else if (value2.Equals("off", StringComparison.OrdinalIgnoreCase)) |
| | 914 | | { |
| 3 | 915 | | map.IsVerticalBlendingEnabled = false; |
| | 916 | | } |
| | 917 | | else |
| | 918 | | { |
| 6 | 919 | | throw new InvalidDataException(string.Concat("A ", statement, " -blenv option must speci |
| | 920 | | } |
| | 921 | |
|
| 6 | 922 | | index++; |
| 6 | 923 | | break; |
| | 924 | | } |
| | 925 | |
|
| | 926 | | case "-bm": |
| 9 | 927 | | if (valuesCount - index < 2) |
| | 928 | | { |
| 3 | 929 | | throw new InvalidDataException(string.Concat("A ", statement, " -bm option must specify a va |
| | 930 | | } |
| | 931 | |
|
| 6 | 932 | | map.BumpMultiplier = FloatParse(GetNextValue(ref currentLine, ref values)); |
| | 933 | |
|
| 6 | 934 | | index++; |
| 6 | 935 | | break; |
| | 936 | |
|
| | 937 | | case "-boost": |
| 9 | 938 | | if (valuesCount - index < 2) |
| | 939 | | { |
| 3 | 940 | | throw new InvalidDataException(string.Concat("A ", statement, " -boost option must specify a |
| | 941 | | } |
| | 942 | |
|
| 6 | 943 | | map.Boost = FloatParse(GetNextValue(ref currentLine, ref values)); |
| | 944 | |
|
| 6 | 945 | | index++; |
| 6 | 946 | | break; |
| | 947 | |
|
| | 948 | | case "-cc": |
| | 949 | | { |
| 15 | 950 | | if (valuesCount - index < 2) |
| | 951 | | { |
| 3 | 952 | | throw new InvalidDataException(string.Concat("A ", statement, " -cc option must specify |
| | 953 | | } |
| | 954 | |
|
| 12 | 955 | | var value2 = GetNextValue(ref currentLine, ref values); |
| | 956 | |
|
| 12 | 957 | | if (value2.Equals("on", StringComparison.OrdinalIgnoreCase)) |
| | 958 | | { |
| 3 | 959 | | map.IsColorCorrectionEnabled = true; |
| | 960 | | } |
| 9 | 961 | | else if (value2.Equals("off", StringComparison.OrdinalIgnoreCase)) |
| | 962 | | { |
| 3 | 963 | | map.IsColorCorrectionEnabled = false; |
| | 964 | | } |
| | 965 | | else |
| | 966 | | { |
| 6 | 967 | | throw new InvalidDataException(string.Concat("A ", statement, " -cc option must specify |
| | 968 | | } |
| | 969 | |
|
| 6 | 970 | | index++; |
| 6 | 971 | | break; |
| | 972 | | } |
| | 973 | |
|
| | 974 | | case "-clamp": |
| | 975 | | { |
| 15 | 976 | | if (valuesCount - index < 2) |
| | 977 | | { |
| 3 | 978 | | throw new InvalidDataException(string.Concat("A ", statement, " -clamp option must speci |
| | 979 | | } |
| | 980 | |
|
| 12 | 981 | | var value2 = GetNextValue(ref currentLine, ref values); |
| | 982 | |
|
| 12 | 983 | | if (value2.Equals("on", StringComparison.OrdinalIgnoreCase)) |
| | 984 | | { |
| 3 | 985 | | map.IsClampingEnabled = true; |
| | 986 | | } |
| 9 | 987 | | else if (value2.Equals("off", StringComparison.OrdinalIgnoreCase)) |
| | 988 | | { |
| 3 | 989 | | map.IsClampingEnabled = false; |
| | 990 | | } |
| | 991 | | else |
| | 992 | | { |
| 6 | 993 | | throw new InvalidDataException(string.Concat("A ", statement, " -clamp option must speci |
| | 994 | | } |
| | 995 | |
|
| 6 | 996 | | index++; |
| 6 | 997 | | break; |
| | 998 | | } |
| | 999 | |
|
| | 1000 | | case "-imfchan": |
| | 1001 | | { |
| 27 | 1002 | | if (valuesCount - index < 2) |
| | 1003 | | { |
| 3 | 1004 | | throw new InvalidDataException(string.Concat("A ", statement, " -imfchan option must spe |
| | 1005 | | } |
| | 1006 | |
|
| 24 | 1007 | | ReadOnlySpan<char> value2 = GetNextValue(ref currentLine, ref values); |
| 24 | 1008 | | int value2Length = value2.ToLowerInvariant(valueBuffer); |
| | 1009 | |
|
| | 1010 | | //if (value2Length == -1) |
| | 1011 | | //{ |
| | 1012 | | // throw new InvalidDataException("the buffer is too small"); |
| | 1013 | | //} |
| | 1014 | |
|
| 24 | 1015 | | switch (valueBuffer[..value2Length]) |
| | 1016 | | { |
| | 1017 | | case "r": |
| 3 | 1018 | | map.ScalarChannel = ObjMapChannel.Red; |
| 3 | 1019 | | break; |
| | 1020 | |
|
| | 1021 | | case "g": |
| 3 | 1022 | | map.ScalarChannel = ObjMapChannel.Green; |
| 3 | 1023 | | break; |
| | 1024 | |
|
| | 1025 | | case "b": |
| 3 | 1026 | | map.ScalarChannel = ObjMapChannel.Blue; |
| 3 | 1027 | | break; |
| | 1028 | |
|
| | 1029 | | case "m": |
| 3 | 1030 | | map.ScalarChannel = ObjMapChannel.Matte; |
| 3 | 1031 | | break; |
| | 1032 | |
|
| | 1033 | | case "l": |
| 3 | 1034 | | map.ScalarChannel = ObjMapChannel.Luminance; |
| 3 | 1035 | | break; |
| | 1036 | |
|
| | 1037 | | case "z": |
| 3 | 1038 | | map.ScalarChannel = ObjMapChannel.Depth; |
| 3 | 1039 | | break; |
| | 1040 | |
|
| | 1041 | | default: |
| 6 | 1042 | | throw new InvalidDataException(string.Concat("A ", statement, " -imfchan option must |
| | 1043 | | } |
| | 1044 | |
|
| 18 | 1045 | | index++; |
| 18 | 1046 | | break; |
| | 1047 | | } |
| | 1048 | |
|
| | 1049 | | case "-mm": |
| 12 | 1050 | | if (valuesCount - index < 3) |
| | 1051 | | { |
| 6 | 1052 | | throw new InvalidDataException(string.Concat("A ", statement, " -mm option must specify a ba |
| | 1053 | | } |
| | 1054 | |
|
| 6 | 1055 | | map.ModifierBase = FloatParse(GetNextValue(ref currentLine, ref values)); |
| 6 | 1056 | | map.ModifierGain = FloatParse(GetNextValue(ref currentLine, ref values)); |
| | 1057 | |
|
| 6 | 1058 | | index += 2; |
| 6 | 1059 | | break; |
| | 1060 | |
|
| | 1061 | | case "-o": |
| 15 | 1062 | | if (valuesCount - index < 2) |
| | 1063 | | { |
| 3 | 1064 | | throw new InvalidDataException(string.Concat("A ", statement, " -o option must specify at le |
| | 1065 | | } |
| | 1066 | |
|
| 12 | 1067 | | var offset = new ObjVector3(); |
| | 1068 | |
|
| 12 | 1069 | | offset.X = FloatParse(GetNextValue(ref currentLine, ref values)); |
| | 1070 | |
|
| 12 | 1071 | | if (valuesCount - index > 3) |
| | 1072 | | { |
| 6 | 1073 | | offset.Y = FloatParse(GetNextValue(ref currentLine, ref values)); |
| | 1074 | |
|
| 6 | 1075 | | if (valuesCount - index > 4) |
| | 1076 | | { |
| 3 | 1077 | | offset.Z = FloatParse(GetNextValue(ref currentLine, ref values)); |
| 3 | 1078 | | index++; |
| | 1079 | | } |
| | 1080 | |
|
| 6 | 1081 | | index++; |
| | 1082 | | } |
| | 1083 | |
|
| 12 | 1084 | | index++; |
| | 1085 | |
|
| 12 | 1086 | | map.Offset = offset; |
| 12 | 1087 | | break; |
| | 1088 | |
|
| | 1089 | | case "-s": |
| 15 | 1090 | | if (valuesCount - index < 2) |
| | 1091 | | { |
| 3 | 1092 | | throw new InvalidDataException(string.Concat("A ", statement, " -s option must specify at le |
| | 1093 | | } |
| | 1094 | |
|
| 12 | 1095 | | var scale = new ObjVector3(1.0f, 1.0f, 1.0f); |
| | 1096 | |
|
| 12 | 1097 | | scale.X = FloatParse(GetNextValue(ref currentLine, ref values)); |
| | 1098 | |
|
| 12 | 1099 | | if (valuesCount - index > 3) |
| | 1100 | | { |
| 6 | 1101 | | scale.Y = FloatParse(GetNextValue(ref currentLine, ref values)); |
| | 1102 | |
|
| 6 | 1103 | | if (valuesCount - index > 4) |
| | 1104 | | { |
| 3 | 1105 | | scale.Z = FloatParse(GetNextValue(ref currentLine, ref values)); |
| 3 | 1106 | | index++; |
| | 1107 | | } |
| | 1108 | |
|
| 6 | 1109 | | index++; |
| | 1110 | | } |
| | 1111 | |
|
| 12 | 1112 | | index++; |
| | 1113 | |
|
| 12 | 1114 | | map.Scale = scale; |
| 12 | 1115 | | break; |
| | 1116 | |
|
| | 1117 | | case "-t": |
| 15 | 1118 | | if (valuesCount - index < 2) |
| | 1119 | | { |
| 3 | 1120 | | throw new InvalidDataException(string.Concat("A ", statement, " -t option must specify at le |
| | 1121 | | } |
| | 1122 | |
|
| 12 | 1123 | | var turbulence = new ObjVector3(); |
| | 1124 | |
|
| 12 | 1125 | | turbulence.X = FloatParse(GetNextValue(ref currentLine, ref values)); |
| | 1126 | |
|
| 12 | 1127 | | if (valuesCount - index > 3) |
| | 1128 | | { |
| 6 | 1129 | | turbulence.Y = FloatParse(GetNextValue(ref currentLine, ref values)); |
| | 1130 | |
|
| 6 | 1131 | | if (valuesCount - index > 4) |
| | 1132 | | { |
| 3 | 1133 | | turbulence.Z = FloatParse(GetNextValue(ref currentLine, ref values)); |
| 3 | 1134 | | index++; |
| | 1135 | | } |
| | 1136 | |
|
| 6 | 1137 | | index++; |
| | 1138 | | } |
| | 1139 | |
|
| 12 | 1140 | | index++; |
| | 1141 | |
|
| 12 | 1142 | | map.Turbulence = turbulence; |
| 12 | 1143 | | break; |
| | 1144 | |
|
| | 1145 | | case "-texres": |
| 9 | 1146 | | if (valuesCount - index < 2) |
| | 1147 | | { |
| 3 | 1148 | | throw new InvalidDataException(string.Concat("A ", statement, " -texres option must specify |
| | 1149 | | } |
| | 1150 | |
|
| 6 | 1151 | | map.TextureResolution = IntParse(GetNextValue(ref currentLine, ref values)); |
| | 1152 | |
|
| 6 | 1153 | | index++; |
| 6 | 1154 | | break; |
| | 1155 | |
|
| | 1156 | | default: |
| | 1157 | | { |
| 258 | 1158 | | var sb = new StringBuilder(); |
| | 1159 | |
|
| 258 | 1160 | | sb.Append(value1); |
| | 1161 | |
|
| 630 | 1162 | | for (int i = index + 1; i < valuesCount; i++) |
| | 1163 | | { |
| 57 | 1164 | | sb.Append(' '); |
| 57 | 1165 | | sb.Append(GetNextValue(ref currentLine, ref values)); |
| | 1166 | | } |
| | 1167 | |
|
| 258 | 1168 | | string filename = sb.ToString(); |
| | 1169 | |
|
| 258 | 1170 | | map.FileName = filename; |
| 258 | 1171 | | index = valuesCount; |
| | 1172 | |
|
| | 1173 | | break; |
| | 1174 | | } |
| | 1175 | | } |
| | 1176 | | } |
| | 1177 | |
|
| 258 | 1178 | | return map; |
| | 1179 | | } |
| | 1180 | | } |
| | 1181 | | } |
| | 1182 | |
|
| | 1183 | | #endif |
| | 1184 | |
|