Browse Source

Collada: correct parsing of float data in xml nodes.

Kim Kulling 5 years ago
parent
commit
be5089ae40

+ 8 - 5
code/AssetLib/Collada/ColladaParser.cpp

@@ -990,20 +990,23 @@ void ColladaParser::ReadCamera(XmlNode &node, Collada::Camera &camera) {
     xmlIt.collectChildrenPreOrder(node);
     XmlNode currentNode;
 
+    std::string out;
     while (xmlIt.getNext(currentNode)) {
         const std::string &currentName = currentNode.name();
         if (currentName == "orthographic") {
             camera.mOrtho = true;
         } else if (currentName == "xfov" || currentName == "xmag") {
-            XmlParser::getFloatAttribute(currentNode, currentName.c_str(), (ai_real &)camera.mHorFov);
+            XmlParser::getValueAsFloat(currentNode, camera.mHorFov);
         } else if (currentName == "yfov" || currentName == "ymag") {
-            XmlParser::getFloatAttribute(currentNode, currentName.c_str(), (ai_real &)camera.mVerFov);
+            XmlParser::getValueAsFloat(currentNode, camera.mVerFov);
+            camera.mVerFov = (ai_real)std::atof(out.c_str());
         } else if (currentName == "aspect_ratio") {
-            XmlParser::getFloatAttribute(currentNode, currentName.c_str(), (ai_real &)camera.mAspect);
+            XmlParser::getValueAsFloat(currentNode, camera.mAspect);
+            camera.mAspect = (ai_real)std::atof(out.c_str());
         } else if (currentName == "znear") {
-            XmlParser::getFloatAttribute(currentNode, currentName.c_str(), (ai_real &)camera.mZNear);
+            XmlParser::getValueAsFloat(currentNode, camera.mZNear);
         } else if (currentName == "zfar") {
-            XmlParser::getFloatAttribute(currentNode, currentName.c_str(), (ai_real &)camera.mZFar);
+            XmlParser::getValueAsFloat(currentNode, camera.mZFar);
         }
     }
 }

+ 11 - 0
include/assimp/XmlParser.h

@@ -217,6 +217,17 @@ public:
         return true;
     }
 
+    static inline bool getValueAsFloat( XmlNode &node, ai_real &v ) {
+        if (node.empty()) {
+            return false;
+        }
+
+        v = node.text().as_float();
+
+        return true;
+
+    }
+
  private:
     pugi::xml_document *mDoc;
     TNodeType mCurrent;

+ 1 - 1
test/unit/utAMFImportExport.cpp

@@ -49,7 +49,7 @@ using namespace Assimp;
 
 class utAMFImportExport : public AbstractImportExportBase {
 public:
-    virtual bool importerTest() {
+    bool importerTest() override {
         Assimp::Importer importer;
         const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/AMF/test1.amf", aiProcess_ValidateDataStructure);
         return nullptr != scene;