From f5d51e6edbb55b8ccc02cb7c7120869e78e5afa0 Mon Sep 17 00:00:00 2001 From: MaKiPL Date: Sun, 12 Jul 2015 17:33:59 +0200 Subject: [PATCH 1/2] Fixed BadFormat exception ObjFileFormat Float parse thrown exception when tried to parse "." separated values. Fixed it to use "," instead of "." --- .../SharpGL.Serialization/Wavefront/ObjFileFormat.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/source/SharpGL/Core/SharpGL.Serialization/Wavefront/ObjFileFormat.cs b/source/SharpGL/Core/SharpGL.Serialization/Wavefront/ObjFileFormat.cs index 4ff432b0..96207653 100644 --- a/source/SharpGL/Core/SharpGL.Serialization/Wavefront/ObjFileFormat.cs +++ b/source/SharpGL/Core/SharpGL.Serialization/Wavefront/ObjFileFormat.cs @@ -169,7 +169,9 @@ public Scene LoadData(string path) { // Get the texture coord strings. string[] values = line.Substring(3).Split(split, StringSplitOptions.RemoveEmptyEntries); - + float x = float.Parse(values[0]); + float y = float.Parse(values[1]); + // Parse texture coordinates. float u = float.Parse(values[0]); float v = float.Parse(values[1]); @@ -185,6 +187,9 @@ public Scene LoadData(string path) { // Get the normal coord strings. string[] values = line.Substring(3).Split(split, StringSplitOptions.RemoveEmptyEntries); + values[0] = values[0].Replace(".", ","); + values[1] = values[1].Replace(".", ","); + values[2] = values[2].Replace(".", ","); // Parse normal coordinates. float x = float.Parse(values[0]); @@ -202,6 +207,9 @@ public Scene LoadData(string path) { // Get the vertex coord strings. string[] values = line.Substring(2).Split(split, StringSplitOptions.RemoveEmptyEntries); + values[0] = values[0].Replace(".", ","); + values[1] = values[1].Replace(".", ","); + values[2] = values[2].Replace(".", ","); // Parse vertex coordinates. float x = float.Parse(values[0]); @@ -396,4 +404,4 @@ public string Filter get { return "Wavefont Obj Files (*.obj)|*.obj"; } } } -} \ No newline at end of file +} From dda889638e0f55a0a803cbca8eacc46e698687ca Mon Sep 17 00:00:00 2001 From: MaKiPL Date: Sun, 12 Jul 2015 17:49:05 +0200 Subject: [PATCH 2/2] Fixed material badParse leftover I missed one thing. Material parser also tried to parse point separated value. --- .../Core/SharpGL.Serialization/Wavefront/ObjFileFormat.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/SharpGL/Core/SharpGL.Serialization/Wavefront/ObjFileFormat.cs b/source/SharpGL/Core/SharpGL.Serialization/Wavefront/ObjFileFormat.cs index 96207653..740c8f6c 100644 --- a/source/SharpGL/Core/SharpGL.Serialization/Wavefront/ObjFileFormat.cs +++ b/source/SharpGL/Core/SharpGL.Serialization/Wavefront/ObjFileFormat.cs @@ -21,6 +21,9 @@ private System.Drawing.Color ReadMaterialColor(string line, float alpha) string[] lineParts = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (lineParts.Length >= 4) { + lineParts[1] = lineParts[1].Replace(".", ","); + lineParts[2] = lineParts[1].Replace(".", ","); + lineParts[3] = lineParts[1].Replace(".", ","); // Convert float a,r,g,b values to byte values. Make sure they fall in 0-255 range. int a = Convert.ToInt32(255 * alpha); if (a < 0) a = 0; if (a > 255) a = 255;