Browse Source

Locale independent meter scale

`XmlParser::getRealAttribute(...)` will call `strtod` (or `wcstod`) which are both locale dependent. So on a German locale system a scale of 0.01 meter will be parsed to 0. In order to avoid that I use the `fast_atoreal_move<ai_real>()` method.
tanolino 3 years ago
parent
commit
04d2d13172
1 changed files with 10 additions and 1 deletions
  1. 10 1
      code/AssetLib/Collada/ColladaParser.cpp

+ 10 - 1
code/AssetLib/Collada/ColladaParser.cpp

@@ -331,7 +331,16 @@ void ColladaParser::ReadAssetInfo(XmlNode &node) {
         const std::string &currentName = currentNode.name();
         const std::string &currentName = currentNode.name();
         if (currentName == "unit") {
         if (currentName == "unit") {
             mUnitSize = 1.f;
             mUnitSize = 1.f;
-            XmlParser::getRealAttribute(currentNode, "meter", mUnitSize);
+            std::string tUnitSizeString;
+            if (XmlParser::getStdStrAttribute(currentNode, "meter", tUnitSizeString)) {
+                try {
+                    fast_atoreal_move<ai_real>(tUnitSizeString.data(), mUnitSize);
+                } catch (DeadlyImportError die) {
+                    std::string warning("Collada: Failed to parse meter parameter to real number. Exception:\n");
+                    warning.append(die.what());
+                    ASSIMP_LOG_WARN(warning.data());
+                }
+            }
         } else if (currentName == "up_axis") {
         } else if (currentName == "up_axis") {
             std::string v;
             std::string v;
             if (!XmlParser::getValueAsString(currentNode, v)) {
             if (!XmlParser::getValueAsString(currentNode, v)) {