]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/model/SGReaderWriterXML.cxx
Add writeLocalData functions for internal scenegraph classes
[simgear.git] / simgear / scene / model / SGReaderWriterXML.cxx
index 020547e3e74ff4cfda524762f4bd28140c3cb78d..31c0c56dddaf42ad27e0589a78851e9a30cc2539 100644 (file)
@@ -41,6 +41,7 @@
 #include "animation.hxx"
 #include "particles.hxx"
 #include "model.hxx"
+#include "SGText.hxx"
 
 using namespace simgear;
 
@@ -114,7 +115,7 @@ sgLoad3DModel_internal(const string &path,
 
     SGSharedPtr<SGPropertyNode> prop_root;
     osg::Node *(*load_panel)(SGPropertyNode *)=0;
-    SGModelData *data=0;
+    osg::ref_ptr<SGModelData> data;
 
     if (xmlOptions) {
         prop_root = xmlOptions->getPropRoot();
@@ -169,7 +170,9 @@ sgLoad3DModel_internal(const string &path,
     }
 
     osg::ref_ptr<SGReaderWriterXMLOptions> options
-    = new SGReaderWriterXMLOptions(*osgDB::Registry::instance()->getOptions());
+    = new SGReaderWriterXMLOptions(*options_);
+    options->setPropRoot(prop_root);
+    options->setLoadPanel(load_panel);
 
     // Assume that textures are in
     // the same location as the XML file.
@@ -227,8 +230,12 @@ sgLoad3DModel_internal(const string &path,
         } else {
             submodelpath = submodelFileName;
         }
+        osg::ref_ptr<SGReaderWriterXMLOptions> options;
+        options = new SGReaderWriterXMLOptions(*options_);
+        options->setPropRoot(prop_root);
+        options->setLoadPanel(load_panel);
         try {
-            submodel = sgLoad3DModel_internal(submodelpath.str(), options_,
+            submodel = sgLoad3DModel_internal(submodelpath.str(), options.get(),
                                               sub_props->getNode("overlay"));
         } catch (const sg_throwable &t) {
             SG_LOG(SG_INPUT, SG_ALERT, "Failed to load submodel: " << t.getFormattedMessage());
@@ -299,8 +306,12 @@ sgLoad3DModel_internal(const string &path,
                         options.get()));
     }
 
-    if (data) {
-        options->setModelData(data);
+    std::vector<SGPropertyNode_ptr> text_nodes;
+    text_nodes = props->getChildren("text");
+    for (unsigned i = 0; i < text_nodes.size(); ++i) {
+        group->addChild(SGText::appendText(text_nodes[i],
+                        prop_root,
+                        options.get()));
     }
 
     std::vector<SGPropertyNode_ptr> animation_nodes;
@@ -313,9 +324,12 @@ sgLoad3DModel_internal(const string &path,
     if (!needTransform && group->getNumChildren() < 2) {
         model = group->getChild(0);
         group->removeChild(model.get());
-        model->setUserData(group->getUserData());
+        if (data.valid())
+            data->modelLoaded(modelpath.str(), props, model.get());
         return model.release();
     }
+    if (data.valid())
+        data->modelLoaded(modelpath.str(), props, group.get());
     if (props->hasChild("debug-outfile")) {
         std::string outputfile = props->getStringValue("debug-outfile",
                                  "debug-model.osg");