From 1e4328f669097365e8fb1b17a97541c334f2f273 Mon Sep 17 00:00:00 2001 From: Ezio Helios Date: Tue, 19 Dec 2023 17:14:43 +0800 Subject: [PATCH 1/2] replace `line` with `trimmedLine` to do slicing --- Obj2Tiles/Utils.cs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/Obj2Tiles/Utils.cs b/Obj2Tiles/Utils.cs index 3e8f410..9e3b423 100644 --- a/Obj2Tiles/Utils.cs +++ b/Obj2Tiles/Utils.cs @@ -18,10 +18,12 @@ public static IEnumerable GetObjDependencies(string objPath) foreach (var line in objFile) { - if (!line.StartsWith("mtllib")) continue; + var trimmedLine = line.Trim(); + + if (!trimmedLine.StartsWith("mtllib")) continue; - var mtlPath = Path.Combine(folderName, line[7..].Trim()); - dependencies.Add(line[7..].Trim()); + var mtlPath = Path.Combine(folderName, trimmedLine[7..].Trim()); + dependencies.Add(trimmedLine[7..].Trim()); dependencies.AddRange(GetMtlDependencies(mtlPath)); } @@ -42,70 +44,70 @@ private static IEnumerable GetMtlDependencies(string mtlPath) if (trimmedLine.StartsWith("map_Kd")) { - dependencies.Add(line[7..].Trim()); + dependencies.Add(trimmedLine[7..].Trim()); continue; } if (trimmedLine.StartsWith("map_Ka")) { - dependencies.Add(line[7..].Trim()); + dependencies.Add(trimmedLine[7..].Trim()); continue; } if (trimmedLine.StartsWith("norm")) { - dependencies.Add(line[5..].Trim()); + dependencies.Add(trimmedLine[5..].Trim()); continue; } if (trimmedLine.StartsWith("map_Ks")) { - dependencies.Add(line[7..].Trim()); + dependencies.Add(trimmedLine[7..].Trim()); continue; } if (trimmedLine.StartsWith("map_Bump")) { - dependencies.Add(line[8..].Trim()); + dependencies.Add(trimmedLine[8..].Trim()); continue; } if (trimmedLine.StartsWith("map_d")) { - dependencies.Add(line[6..].Trim()); + dependencies.Add(trimmedLine[6..].Trim()); continue; } if (trimmedLine.StartsWith("map_Ns")) { - dependencies.Add(line[7..].Trim()); + dependencies.Add(trimmedLine[7..]); continue; } if (trimmedLine.StartsWith("bump")) { - dependencies.Add(line[5..].Trim()); + dependencies.Add(trimmedLine[5..].Trim()); continue; } if (trimmedLine.StartsWith("disp")) { - dependencies.Add(line[5..].Trim()); + dependencies.Add(trimmedLine[5..].Trim()); continue; } if (trimmedLine.StartsWith("decal")) { - dependencies.Add(line[6..].Trim()); + dependencies.Add(trimmedLine[6..].Trim()); continue; } From 20822e94246f4306a6531c71e4282a819c15edc8 Mon Sep 17 00:00:00 2001 From: Ezio Helios <78869679+EzioHelios@users.noreply.github.com> Date: Tue, 19 Dec 2023 17:20:57 +0800 Subject: [PATCH 2/2] Update Utils.cs --- Obj2Tiles/Utils.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Obj2Tiles/Utils.cs b/Obj2Tiles/Utils.cs index 9e3b423..7a16a4c 100644 --- a/Obj2Tiles/Utils.cs +++ b/Obj2Tiles/Utils.cs @@ -86,7 +86,7 @@ private static IEnumerable GetMtlDependencies(string mtlPath) if (trimmedLine.StartsWith("map_Ns")) { - dependencies.Add(trimmedLine[7..]); + dependencies.Add(trimmedLine[7..].Trim()); continue; } @@ -172,4 +172,4 @@ public static void ConvertB3dm(string objPath, string destPath) File.WriteAllBytes(destPath, b3dm.ToBytes()); } -} \ No newline at end of file +}