From b86a856badfba08daf883d76da5adc7e859a3306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=80=D0=B0=20=D0=A1=D1=82=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=BD=D0=B0=D1=8F?= Date: Mon, 12 Aug 2019 21:33:29 +0400 Subject: [PATCH 1/4] Use locale insensitive stof --- Source/OBJ_Loader.h | 63 +++++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 20 deletions(-) diff --git a/Source/OBJ_Loader.h b/Source/OBJ_Loader.h index 0b7d010..bd5d3e9 100644 --- a/Source/OBJ_Loader.h +++ b/Source/OBJ_Loader.h @@ -17,6 +17,9 @@ // Math.h - STD math Library #include +// Locale.h - C locale library +#include + // Print progress to console while loading (large models) #define OBJL_CONSOLE_OUTPUT @@ -404,6 +407,26 @@ namespace objl idx--; return elements[idx]; } + + // Locale insensitive stof + float li_stof (const std::string& str) + { + char* point = localeconv()->decimal_point; + + if (std::string(".") != point) + { + unsigned long point_it = str.find("."); + std::string temp_str = str; + + temp_str.replace(point_it, point_it + 1, point); + + return std::stof(temp_str); + } + else + { + return std::stof(str); + } + } } // Class: Loader @@ -542,9 +565,9 @@ namespace objl Vector3 vpos; algorithm::split(algorithm::tail(curline), spos, " "); - vpos.X = std::stof(spos[0]); - vpos.Y = std::stof(spos[1]); - vpos.Z = std::stof(spos[2]); + vpos.X = algorithm::li_stof(spos[0]); + vpos.Y = algorithm::li_stof(spos[1]); + vpos.Z = algorithm::li_stof(spos[2]); Positions.push_back(vpos); } @@ -555,8 +578,8 @@ namespace objl Vector2 vtex; algorithm::split(algorithm::tail(curline), stex, " "); - vtex.X = std::stof(stex[0]); - vtex.Y = std::stof(stex[1]); + vtex.X = algorithm::li_stof(stex[0]); + vtex.Y = algorithm::li_stof(stex[1]); TCoords.push_back(vtex); } @@ -567,9 +590,9 @@ namespace objl Vector3 vnor; algorithm::split(algorithm::tail(curline), snor, " "); - vnor.X = std::stof(snor[0]); - vnor.Y = std::stof(snor[1]); - vnor.Z = std::stof(snor[2]); + vnor.X = algorithm::li_stof(snor[0]); + vnor.Y = algorithm::li_stof(snor[1]); + vnor.Z = algorithm::li_stof(snor[2]); Normals.push_back(vnor); } @@ -1068,9 +1091,9 @@ namespace objl if (temp.size() != 3) continue; - tempMaterial.Ka.X = std::stof(temp[0]); - tempMaterial.Ka.Y = std::stof(temp[1]); - tempMaterial.Ka.Z = std::stof(temp[2]); + tempMaterial.Ka.X = algorithm::li_stof(temp[0]); + tempMaterial.Ka.Y = algorithm::li_stof(temp[1]); + tempMaterial.Ka.Z = algorithm::li_stof(temp[2]); } // Diffuse Color if (algorithm::firstToken(curline) == "Kd") @@ -1081,9 +1104,9 @@ namespace objl if (temp.size() != 3) continue; - tempMaterial.Kd.X = std::stof(temp[0]); - tempMaterial.Kd.Y = std::stof(temp[1]); - tempMaterial.Kd.Z = std::stof(temp[2]); + tempMaterial.Kd.X = algorithm::li_stof(temp[0]); + tempMaterial.Kd.Y = algorithm::li_stof(temp[1]); + tempMaterial.Kd.Z = algorithm::li_stof(temp[2]); } // Specular Color if (algorithm::firstToken(curline) == "Ks") @@ -1094,24 +1117,24 @@ namespace objl if (temp.size() != 3) continue; - tempMaterial.Ks.X = std::stof(temp[0]); - tempMaterial.Ks.Y = std::stof(temp[1]); - tempMaterial.Ks.Z = std::stof(temp[2]); + tempMaterial.Ks.X = algorithm::li_stof(temp[0]); + tempMaterial.Ks.Y = algorithm::li_stof(temp[1]); + tempMaterial.Ks.Z = algorithm::li_stof(temp[2]); } // Specular Exponent if (algorithm::firstToken(curline) == "Ns") { - tempMaterial.Ns = std::stof(algorithm::tail(curline)); + tempMaterial.Ns = algorithm::li_stof(algorithm::tail(curline)); } // Optical Density if (algorithm::firstToken(curline) == "Ni") { - tempMaterial.Ni = std::stof(algorithm::tail(curline)); + tempMaterial.Ni = algorithm::li_stof(algorithm::tail(curline)); } // Dissolve if (algorithm::firstToken(curline) == "d") { - tempMaterial.d = std::stof(algorithm::tail(curline)); + tempMaterial.d = algorithm::li_stof(algorithm::tail(curline)); } // Illumination if (algorithm::firstToken(curline) == "illum") From 798897222ccc10416352266aa9ba9c2a07f37170 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=80=D0=B0=20=D0=A1=D1=82=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=BD=D0=B0=D1=8F?= Date: Mon, 12 Aug 2019 21:34:42 +0400 Subject: [PATCH 2/4] Remove pointless expression --- Source/OBJ_Loader.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/OBJ_Loader.h b/Source/OBJ_Loader.h index bd5d3e9..1e565a4 100644 --- a/Source/OBJ_Loader.h +++ b/Source/OBJ_Loader.h @@ -153,7 +153,6 @@ namespace objl { Material() { - name; Ns = 0.0f; Ni = 0.0f; d = 0.0f; From 8674d2ef02b4a9940534e7c90757506dc12a2b3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=80=D0=B0=20=D0=A1=D1=82=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=BD=D0=B0=D1=8F?= Date: Mon, 12 Aug 2019 21:35:43 +0400 Subject: [PATCH 3/4] Fix interior vertex condition --- Source/OBJ_Loader.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/OBJ_Loader.h b/Source/OBJ_Loader.h index 1e565a4..15c32d4 100644 --- a/Source/OBJ_Loader.h +++ b/Source/OBJ_Loader.h @@ -969,7 +969,7 @@ namespace objl // If Vertex is not an interior vertex float angle = math::AngleBetweenV3(pPrev.Position - pCur.Position, pNext.Position - pCur.Position) * (180 / 3.14159265359); - if (angle <= 0 && angle >= 180) + if (angle <= 0 || angle >= 180) continue; // If any vertices are within this triangle From 9a728c073c5229f634fc84f1dbc5ba4d46ea8e0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=80=D0=B0=20=D0=A1=D1=82=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=BD=D0=B0=D1=8F?= Date: Mon, 12 Aug 2019 21:36:21 +0400 Subject: [PATCH 4/4] Use cmath header instead of math.h --- Source/OBJ_Loader.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/OBJ_Loader.h b/Source/OBJ_Loader.h index 15c32d4..ace2134 100644 --- a/Source/OBJ_Loader.h +++ b/Source/OBJ_Loader.h @@ -14,8 +14,8 @@ // fStream - STD File I/O Library #include -// Math.h - STD math Library -#include +// Cmath - STD math Library +#include // Locale.h - C locale library #include