]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/model/model.cxx
Redefine the default PLIB loader behavior : don't clear the texture cache after every...
[simgear.git] / simgear / scene / model / model.cxx
index fe3c5c5b71f49da2e88d2915a26b2a5ef6d6ba67..edb91f27a8e1bae88fc28c3072f612d530b899a2 100644 (file)
@@ -7,8 +7,6 @@
 #include <simgear_config.h>
 #endif
 
-#include <simgear/compiler.h>
-
 #include <string.h>             // for strcmp()
 
 #include <vector>
@@ -236,6 +234,12 @@ static void makeDList( ssgBranch *b, const set<ssgBranch *> &ignore )
   }
 }
 
+class sgLoaderOptions : public ssgLoaderOptions {
+public:
+  void endLoad() {} // Avoid clearing the texture cache after every model load
+};
+
+static sgLoaderOptions loaderOptions;
 
 \f
 ////////////////////////////////////////////////////////////////////////
@@ -282,7 +286,7 @@ sgLoad3DModel( const string &fg_root, const string &path,
           texturepath = texturepath.dir();
 
     ssgTexturePath((char *)texturepath.c_str());
-    model = (ssgBranch *)ssgLoad((char *)modelpath.c_str());
+    model = (ssgBranch *)ssgLoad((char *)modelpath.c_str(), &loaderOptions);
     if (model == 0)
       throw sg_io_exception("Failed to load 3D model", 
                          sg_location(modelpath.str()));
@@ -319,8 +323,15 @@ sgLoad3DModel( const string &fg_root, const string &path,
                         node->getFloatValue("offsets/z-m", 0.0));
     align->setTransform(res_matrix);
 
-    ssgBranch * kid = sgLoad3DModel( fg_root, node->getStringValue("path"),
-                                     prop_root, sim_time_sec, load_panel );
+    ssgBranch * kid;
+    const char * submodel = node->getStringValue("path");
+    try {
+      kid = sgLoad3DModel( fg_root, submodel, prop_root, sim_time_sec, load_panel );
+
+    } catch (const sg_throwable &t) {
+      SG_LOG(SG_INPUT, SG_ALERT, "Failed to load submodel: " << t.getFormattedMessage());
+      throw;
+    }
     align->addKid(kid);
     align->setName(node->getStringValue("name", ""));
     model->addKid(align);
@@ -339,8 +350,8 @@ sgLoad3DModel( const string &fg_root, const string &path,
   }
 
   if (data) {
-    data->modelLoaded(path, &props, model);
-    model->setUserData(data);
+    alignmainmodel->setUserData(data);
+    data->modelLoaded(path, &props, alignmainmodel);
   }
                                 // Load animations
   set<ssgBranch *> ignore_branches;