]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/model.cxx
Improove texture sharing.
[simgear.git] / simgear / scene / model / model.cxx
1 // model.cxx - manage a 3D aircraft model.
2 // Written by David Megginson, started 2002.
3 //
4 // This file is in the Public Domain, and comes with no warranty.
5
6 #ifdef HAVE_CONFIG_H
7 #include <simgear_config.h>
8 #endif
9
10 #include <osg/observer_ptr>
11 #include <osg/ref_ptr>
12 #include <osg/Group>
13 #include <osg/NodeCallback>
14 #include <osg/Switch>
15 #include <osg/MatrixTransform>
16 #include <osgDB/Archive>
17 #include <osgDB/FileNameUtils>
18 #include <osgDB/FileUtils>
19 #include <osgDB/ReadFile>
20 #include <osgDB/WriteFile>
21 #include <osgDB/Registry>
22 #include <osgDB/SharedStateManager>
23 #include <osgUtil/Optimizer>
24
25 #include <simgear/scene/util/SGSceneFeatures.hxx>
26 #include <simgear/scene/util/SGStateAttributeVisitor.hxx>
27 #include <simgear/scene/util/SGTextureStateAttributeVisitor.hxx>
28
29 #include <simgear/structure/exception.hxx>
30 #include <simgear/props/props.hxx>
31 #include <simgear/props/props_io.hxx>
32 #include <simgear/props/condition.hxx>
33
34 #include "animation.hxx"
35 #include "model.hxx"
36
37 SG_USING_STD(vector);
38 SG_USING_STD(set);
39
40 // Little helper class that holds an extra reference to a
41 // loaded 3d model.
42 // Since we clone all structural nodes from our 3d models,
43 // the database pager will only see one single reference to
44 // top node of the model and expire it relatively fast.
45 // We attach that extra reference to every model cloned from
46 // a base model in the pager. When that cloned model is deleted
47 // this extra reference is deleted too. So if there are no
48 // cloned models left the model will expire.
49 class SGDatabaseReference : public osg::Observer {
50 public:
51   SGDatabaseReference(osg::Referenced* referenced) :
52     mReferenced(referenced)
53   { }
54   virtual void objectDeleted(void*)
55   {
56     mReferenced = 0;
57   }
58 private:
59   osg::ref_ptr<osg::Referenced> mReferenced;
60 };
61
62 // Visitor for 
63 class SGTextureUpdateVisitor : public SGTextureStateAttributeVisitor {
64 public:
65   SGTextureUpdateVisitor(const osgDB::FilePathList& pathList) :
66     mPathList(pathList)
67   { }
68   osg::Texture2D* textureReplace(int unit,
69                                  osg::StateSet::RefAttributePair& refAttr)
70   {
71     osg::Texture2D* texture;
72     texture = dynamic_cast<osg::Texture2D*>(refAttr.first.get());
73     if (!texture)
74       return 0;
75     
76     osg::ref_ptr<osg::Image> image = texture->getImage(0);
77     if (!image)
78       return 0;
79
80     // The currently loaded file name
81     std::string fullFilePath = image->getFileName();
82     // The short name
83     std::string fileName = osgDB::getSimpleFileName(fullFilePath);
84     // The name that should be found with the current database path
85     std::string fullLiveryFile = osgDB::findFileInPath(fileName, mPathList);
86     // If they are identical then there is nothing to do
87     if (fullLiveryFile == fullFilePath)
88       return 0;
89
90     image = osgDB::readImageFile(fullLiveryFile);
91     if (!image)
92       return 0;
93
94     osg::CopyOp copyOp(osg::CopyOp::DEEP_COPY_ALL &
95                        ~osg::CopyOp::DEEP_COPY_IMAGES);
96     texture = static_cast<osg::Texture2D*>(copyOp(texture));
97     if (!texture)
98       return 0;
99     texture->setImage(image.get());
100     return texture;
101   }
102   virtual void apply(osg::StateSet* stateSet)
103   {
104     if (!stateSet)
105       return;
106
107     // get a copy that we can safely modify the statesets values.
108     osg::StateSet::TextureAttributeList attrList;
109     attrList = stateSet->getTextureAttributeList();
110     for (unsigned unit = 0; unit < attrList.size(); ++unit) {
111       osg::StateSet::AttributeList::iterator i;
112       i = attrList[unit].begin();
113       while (i != attrList[unit].end()) {
114         osg::Texture2D* texture = textureReplace(unit, i->second);
115         if (texture) {
116           stateSet->removeTextureAttribute(unit, i->second.first.get());
117           stateSet->setTextureAttribute(unit, texture, i->second.second);
118           stateSet->setTextureMode(unit, GL_TEXTURE_2D,
119                                    osg::StateAttribute::ON);
120         }
121         ++i;
122       }
123     }
124   }
125
126 private:
127   osgDB::FilePathList mPathList;
128 };
129
130 class SGTexCompressionVisitor : public SGTextureStateAttributeVisitor {
131 public:
132   virtual void apply(int, osg::StateSet::RefAttributePair& refAttr)
133   {
134     osg::Texture2D* texture;
135     texture = dynamic_cast<osg::Texture2D*>(refAttr.first.get());
136     if (!texture)
137       return;
138     
139     // Hmm, true??
140     texture->setDataVariance(osg::Object::STATIC);
141
142     osg::Image* image = texture->getImage(0);
143     if (!image)
144       return;
145
146     int s = image->s();
147     int t = image->t();
148
149     if (s <= t && 32 <= s) {
150       SGSceneFeatures::instance()->setTextureCompression(texture);
151     } else if (t < s && 32 <= t) {
152       SGSceneFeatures::instance()->setTextureCompression(texture);
153     }
154   }
155 };
156
157 class SGTexDataVarianceVisitor : public SGTextureStateAttributeVisitor {
158 public:
159   virtual void apply(int, osg::StateSet::RefAttributePair& refAttr)
160   {
161     osg::Texture* texture;
162     texture = dynamic_cast<osg::Texture*>(refAttr.first.get());
163     if (!texture)
164       return;
165     
166     texture->setDataVariance(osg::Object::STATIC);
167   }
168 };
169
170 class SGAcMaterialCrippleVisitor : public SGStateAttributeVisitor {
171 public:
172   virtual void apply(osg::StateSet::RefAttributePair& refAttr)
173   {
174     osg::Material* material;
175     material = dynamic_cast<osg::Material*>(refAttr.first.get());
176     if (!material)
177       return;
178     material->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE);
179   }
180 };
181
182 class SGReadFileCallback :
183   public osgDB::Registry::ReadFileCallback {
184 public:
185   virtual osgDB::ReaderWriter::ReadResult
186   readImage(const std::string& fileName,
187             const osgDB::ReaderWriter::Options* opt)
188   {
189     std::string absFileName = osgDB::findDataFile(fileName);
190     if (!osgDB::fileExists(absFileName)) {
191       SG_LOG(SG_IO, SG_ALERT, "Cannot find image file \""
192              << fileName << "\"");
193       return osgDB::ReaderWriter::ReadResult::FILE_NOT_FOUND;
194     }
195
196     osgDB::Registry* registry = osgDB::Registry::instance();
197     osgDB::ReaderWriter::ReadResult res;
198     res = registry->readImageImplementation(absFileName, opt);
199     if (res.loadedFromCache())
200       SG_LOG(SG_IO, SG_INFO, "Returning cached image \""
201              << res.getImage()->getFileName() << "\"");
202     else
203       SG_LOG(SG_IO, SG_INFO, "Reading image \""
204              << res.getImage()->getFileName() << "\"");
205
206     return res;
207   }
208
209   virtual osgDB::ReaderWriter::ReadResult
210   readNode(const std::string& fileName,
211            const osgDB::ReaderWriter::Options* opt)
212   {
213     osgDB::Registry* registry = osgDB::Registry::instance();
214     osgDB::ReaderWriter::ReadResult res;
215     osg::Node* cached = 0;
216     // The BTG loader automatically looks for ".btg.gz" if a file with
217     // the .btg extension doesn't exist. Also, we don't want to add
218     // nodes, run the optimizer, etc. on the btg model.So, let it do
219     // its thing.
220     if (osgDB::equalCaseInsensitive(osgDB::getFileExtension(fileName), "btg")) {
221       return registry->readNodeImplementation(fileName, opt);
222     }
223     // First, look for a file with the same name, and the extension
224     // ".osg" and, if it exists, load it instead. This allows for
225     // substitution of optimized models for ones named in the scenery.
226     bool optimizeModel = true;
227     std::string fileSansExtension = osgDB::getNameLessExtension(fileName);
228     std::string osgFileName = fileSansExtension + ".osg";
229     std::string absFileName = osgDB::findDataFile(osgFileName);
230     if (osgDB::fileExists(absFileName)) {
231       optimizeModel = false;
232     } else {
233       absFileName = osgDB::findDataFile(fileName);
234     }
235     if (!osgDB::fileExists(absFileName)) {
236       SG_LOG(SG_IO, SG_ALERT, "Cannot find model file \""
237              << fileName << "\"");
238       return osgDB::ReaderWriter::ReadResult::FILE_NOT_FOUND;
239     }
240     cached
241         = dynamic_cast<osg::Node*>(registry->getFromObjectCache(absFileName));
242     if (cached) {
243       SG_LOG(SG_IO, SG_INFO, "Got cached model \""
244              << absFileName << "\"");
245     } else {
246       SG_LOG(SG_IO, SG_INFO, "Reading model \""
247              << absFileName << "\"");
248       res = registry->readNodeImplementation(absFileName, opt);
249       if (!res.validNode())
250         return res;
251
252       bool needTristrip = true;
253       if (osgDB::getLowerCaseFileExtension(fileName) == "ac") {
254         // we get optimal geometry from the loader.
255         needTristrip = false;
256         osg::Matrix m(1, 0, 0, 0,
257                       0, 0, 1, 0,
258                       0, -1, 0, 0,
259                       0, 0, 0, 1);
260         
261         osg::ref_ptr<osg::Group> root = new osg::Group;
262         osg::MatrixTransform* transform = new osg::MatrixTransform;
263         root->addChild(transform);
264         
265         transform->setDataVariance(osg::Object::STATIC);
266         transform->setMatrix(m);
267         transform->addChild(res.getNode());
268         
269         res = osgDB::ReaderWriter::ReadResult(0);
270
271         if (optimizeModel) {
272           osgUtil::Optimizer optimizer;
273           unsigned opts = osgUtil::Optimizer::FLATTEN_STATIC_TRANSFORMS;
274           optimizer.optimize(root.get(), opts);
275         }
276
277         // strip away unneeded groups
278         if (root->getNumChildren() == 1 && root->getName().empty()) {
279           res = osgDB::ReaderWriter::ReadResult(root->getChild(0));
280         } else
281           res = osgDB::ReaderWriter::ReadResult(root.get());
282         
283         // Ok, this step is questionable.
284         // It is there to have the same visual appearance of ac objects for the
285         // first cut. Osg's ac3d loader will correctly set materials from the
286         // ac file. But the old plib loader used GL_AMBIENT_AND_DIFFUSE for the
287         // materials that in effect igored the ambient part specified in the
288         // file. We emulate that for the first cut here by changing all
289         // ac models here. But in the long term we should use the
290         // unchanged model and fix the input files instead ...
291         SGAcMaterialCrippleVisitor matCriple;
292         res.getNode()->accept(matCriple);
293       }
294
295       if (optimizeModel) {
296         osgUtil::Optimizer optimizer;
297         unsigned opts = 0;
298         // Don't use this one. It will break animation names ...
299         // opts |= osgUtil::Optimizer::REMOVE_REDUNDANT_NODES;
300
301         // opts |= osgUtil::Optimizer::REMOVE_LOADED_PROXY_NODES;
302         // opts |= osgUtil::Optimizer::COMBINE_ADJACENT_LODS;
303         // opts |= osgUtil::Optimizer::SHARE_DUPLICATE_STATE;
304         opts |= osgUtil::Optimizer::MERGE_GEOMETRY;
305         // opts |= osgUtil::Optimizer::CHECK_GEOMETRY;
306         // opts |= osgUtil::Optimizer::SPATIALIZE_GROUPS;
307         // opts |= osgUtil::Optimizer::COPY_SHARED_NODES;
308         opts |= osgUtil::Optimizer::FLATTEN_STATIC_TRANSFORMS;
309         if (needTristrip)
310           opts |= osgUtil::Optimizer::TRISTRIP_GEOMETRY;
311         // opts |= osgUtil::Optimizer::TESSELATE_GEOMETRY;
312         // opts |= osgUtil::Optimizer::OPTIMIZE_TEXTURE_SETTINGS;
313         optimizer.optimize(res.getNode(), opts);
314       }
315       // Make sure the data variance of sharable objects is set to STATIC ...
316       SGTexDataVarianceVisitor dataVarianceVisitor;
317       res.getNode()->accept(dataVarianceVisitor);
318       // ... so that textures are now globally shared
319       registry->getSharedStateManager()->share(res.getNode());
320       
321       SGTexCompressionVisitor texComp;
322       res.getNode()->accept(texComp);
323       cached = res.getNode();
324       registry->addEntryToObjectCache(absFileName, cached);
325     }
326     // Add an extra reference to the model stored in the database.
327     // That it to avoid expiring the object from the cache even if it is still
328     // in use. Note that the object cache will think that a model is unused
329     // if the reference count is 1. If we clone all structural nodes here
330     // we need that extra reference to the original object
331     SGDatabaseReference* databaseReference;
332     databaseReference = new SGDatabaseReference(cached);
333     osg::CopyOp::CopyFlags flags = osg::CopyOp::DEEP_COPY_ALL;
334     flags &= ~osg::CopyOp::DEEP_COPY_TEXTURES;
335     flags &= ~osg::CopyOp::DEEP_COPY_IMAGES;
336     flags &= ~osg::CopyOp::DEEP_COPY_ARRAYS;
337     flags &= ~osg::CopyOp::DEEP_COPY_PRIMITIVES;
338     // This will safe display lists ...
339     flags &= ~osg::CopyOp::DEEP_COPY_DRAWABLES;
340     flags &= ~osg::CopyOp::DEEP_COPY_SHAPES;
341     res = osgDB::ReaderWriter::ReadResult(osg::CopyOp(flags)(cached));
342     res.getNode()->addObserver(databaseReference);
343
344     // Update liveries
345     SGTextureUpdateVisitor liveryUpdate(osgDB::getDataFilePathList());
346     res.getNode()->accept(liveryUpdate);
347
348     // Make sure the data variance of sharable objects is set to STATIC ...
349     SGTexDataVarianceVisitor dataVarianceVisitor;
350     res.getNode()->accept(dataVarianceVisitor);
351     // ... so that textures are now globally shared
352     registry->getOrCreateSharedStateManager()->share(res.getNode(), 0);
353
354     return res;
355   }
356 };
357
358 class SGReadCallbackInstaller {
359 public:
360   SGReadCallbackInstaller()
361   {
362     osg::Referenced::setThreadSafeReferenceCounting(true);
363
364     osgDB::Registry* registry = osgDB::Registry::instance();
365     osgDB::ReaderWriter::Options* options = new osgDB::ReaderWriter::Options;
366     // We manage node caching ourselves
367     int cacheOptions = osgDB::ReaderWriter::Options::CACHE_ALL
368       & ~osgDB::ReaderWriter::Options::CACHE_NODES;
369     options->
370       setObjectCacheHint((osgDB::ReaderWriter::Options::CacheHintOptions)cacheOptions);
371     registry->setOptions(options);
372     registry->getOrCreateSharedStateManager()->setShareMode(osgDB::SharedStateManager::SHARE_TEXTURES);
373     registry->setReadFileCallback(new SGReadFileCallback);
374   }
375 };
376
377 static SGReadCallbackInstaller readCallbackInstaller;
378
379 osg::Texture2D*
380 SGLoadTexture2D(const std::string& path, bool wrapu, bool wrapv, int)
381 {
382   osg::Image* image = osgDB::readImageFile(path);
383   osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
384   texture->setImage(image);
385   texture->setDataVariance(osg::Object::STATIC);
386   if (wrapu)
387     texture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
388   else
389     texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP);
390   if (wrapv)
391     texture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
392   else
393     texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP);
394
395   if (image) {
396     int s = image->s();
397     int t = image->t();
398
399     if (s <= t && 32 <= s) {
400       SGSceneFeatures::instance()->setTextureCompression(texture.get());
401     } else if (t < s && 32 <= t) {
402       SGSceneFeatures::instance()->setTextureCompression(texture.get());
403     }
404   }
405
406   // Make sure the texture is shared if we already have the same texture
407   // somewhere ...
408   {
409     osg::ref_ptr<osg::Node> tmpNode = new osg::Node;
410     osg::StateSet* stateSet = tmpNode->getOrCreateStateSet();
411     stateSet->setTextureAttribute(0, texture.get());
412
413     // OSGFIXME: don't forget that mutex here
414     osgDB::Registry* registry = osgDB::Registry::instance();
415     registry->getSharedStateManager()->share(tmpNode.get(), 0);
416
417     // should be the same, but be paranoid ...
418     stateSet = tmpNode->getStateSet();
419     osg::StateAttribute* stateAttr;
420     stateAttr = stateSet->getTextureAttribute(0, osg::StateAttribute::TEXTURE);
421     osg::Texture2D* texture2D = dynamic_cast<osg::Texture2D*>(stateAttr);
422     if (texture2D)
423       texture = texture2D;
424   }
425
426   return texture.release();
427 }
428
429 class SGSwitchUpdateCallback : public osg::NodeCallback {
430 public:
431   SGSwitchUpdateCallback(SGCondition* condition) :
432     mCondition(condition) {}
433   virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
434   { 
435     assert(dynamic_cast<osg::Switch*>(node));
436     osg::Switch* s = static_cast<osg::Switch*>(node);
437
438     if (mCondition && mCondition->test()) {
439       s->setAllChildrenOn();
440       // note, callback is responsible for scenegraph traversal so
441       // should always include call traverse(node,nv) to ensure 
442       // that the rest of cullbacks and the scene graph are traversed.
443       traverse(node, nv);
444     } else
445       s->setAllChildrenOff();
446   }
447
448 private:
449   SGSharedPtr<SGCondition> mCondition;
450 };
451
452 \f
453 ////////////////////////////////////////////////////////////////////////
454 // Global functions.
455 ////////////////////////////////////////////////////////////////////////
456
457 osg::Node *
458 sgLoad3DModel( const string &fg_root, const string &path,
459                SGPropertyNode *prop_root,
460                double sim_time_sec, osg::Node *(*load_panel)(SGPropertyNode *),
461                SGModelData *data,
462                const SGPath& externalTexturePath )
463 {
464   osg::ref_ptr<osg::Node> model;
465   SGPropertyNode props;
466
467   // Load the 3D aircraft object itself
468   SGPath modelpath = path, texturepath = path;
469   if ( !ulIsAbsolutePathName( path.c_str() ) ) {
470     SGPath tmp = fg_root;
471     tmp.append(modelpath.str());
472     modelpath = texturepath = tmp;
473   }
474
475   // Check for an XML wrapper
476   if (modelpath.str().substr(modelpath.str().size() - 4, 4) == ".xml") {
477     readProperties(modelpath.str(), &props);
478     if (props.hasValue("/path")) {
479       modelpath = modelpath.dir();
480       modelpath.append(props.getStringValue("/path"));
481       if (props.hasValue("/texture-path")) {
482         texturepath = texturepath.dir();
483         texturepath.append(props.getStringValue("/texture-path"));
484       }
485     } else {
486       if (!model)
487         model = new osg::Switch;
488     }
489   }
490
491   osgDB::FilePathList pathList = osgDB::getDataFilePathList();
492   osgDB::Registry::instance()->initFilePathLists();
493
494   // Assume that textures are in
495   // the same location as the XML file.
496   if (!model) {
497     if (texturepath.extension() != "")
498           texturepath = texturepath.dir();
499
500     osgDB::Registry::instance()->getDataFilePathList().push_front(texturepath.str());
501
502     model = osgDB::readNodeFile(modelpath.str());
503     if (model == 0)
504       throw sg_io_exception("Failed to load 3D model", 
505                             sg_location(modelpath.str()));
506   }
507
508   osgDB::Registry::instance()->getDataFilePathList().push_front(externalTexturePath.str());
509
510   // Set up the alignment node
511   osg::ref_ptr<osg::MatrixTransform> alignmainmodel = new osg::MatrixTransform;
512   alignmainmodel->addChild(model.get());
513   osg::Matrix res_matrix;
514   res_matrix.makeRotate(
515     props.getFloatValue("/offsets/pitch-deg", 0.0)*SG_DEGREES_TO_RADIANS,
516     osg::Vec3(0, 1, 0),
517     props.getFloatValue("/offsets/roll-deg", 0.0)*SG_DEGREES_TO_RADIANS,
518     osg::Vec3(1, 0, 0),
519     props.getFloatValue("/offsets/heading-deg", 0.0)*SG_DEGREES_TO_RADIANS,
520     osg::Vec3(0, 0, 1));
521
522   osg::Matrix tmat;
523   tmat.makeTranslate(props.getFloatValue("/offsets/x-m", 0.0),
524                      props.getFloatValue("/offsets/y-m", 0.0),
525                      props.getFloatValue("/offsets/z-m", 0.0));
526   alignmainmodel->setMatrix(res_matrix*tmat);
527
528   // Load sub-models
529   vector<SGPropertyNode_ptr> model_nodes = props.getChildren("model");
530   for (unsigned i = 0; i < model_nodes.size(); i++) {
531     SGPropertyNode_ptr node = model_nodes[i];
532     osg::ref_ptr<osg::MatrixTransform> align = new osg::MatrixTransform;
533     res_matrix.makeIdentity();
534     res_matrix.makeRotate(
535       node->getDoubleValue("offsets/pitch-deg", 0.0)*SG_DEGREES_TO_RADIANS,
536       osg::Vec3(0, 1, 0),
537       node->getDoubleValue("offsets/roll-deg", 0.0)*SG_DEGREES_TO_RADIANS,
538       osg::Vec3(1, 0, 0),
539       node->getDoubleValue("offsets/heading-deg", 0.0)*SG_DEGREES_TO_RADIANS,
540       osg::Vec3(0, 0, 1));
541     
542     tmat.makeIdentity();
543     tmat.makeTranslate(node->getDoubleValue("offsets/x-m", 0),
544                        node->getDoubleValue("offsets/y-m", 0),
545                        node->getDoubleValue("offsets/z-m", 0));
546     align->setMatrix(res_matrix*tmat);
547
548     osg::ref_ptr<osg::Node> kid;
549     const char* submodel = node->getStringValue("path");
550     try {
551       kid = sgLoad3DModel( fg_root, submodel, prop_root, sim_time_sec, load_panel );
552
553     } catch (const sg_throwable &t) {
554       SG_LOG(SG_INPUT, SG_ALERT, "Failed to load submodel: " << t.getFormattedMessage());
555       throw;
556     }
557     align->addChild(kid.get());
558
559     align->setName(node->getStringValue("name", ""));
560
561     SGPropertyNode *cond = node->getNode("condition", false);
562     if (cond) {
563       osg::ref_ptr<osg::Switch> sw = new osg::Switch;
564       sw->setUpdateCallback(new SGSwitchUpdateCallback(sgReadCondition(prop_root, cond)));
565       alignmainmodel->addChild(sw.get());
566       sw->addChild(align.get());
567       sw->setName("submodel condition switch");
568     } else {
569       alignmainmodel->addChild(align.get());
570     }
571   }
572
573   if ( load_panel ) {
574     // Load panels
575     vector<SGPropertyNode_ptr> panel_nodes = props.getChildren("panel");
576     for (unsigned i = 0; i < panel_nodes.size(); i++) {
577         SG_LOG(SG_INPUT, SG_DEBUG, "Loading a panel");
578         osg::ref_ptr<osg::Node> panel = load_panel(panel_nodes[i]);
579         if (panel_nodes[i]->hasValue("name"))
580             panel->setName((char *)panel_nodes[i]->getStringValue("name"));
581         alignmainmodel->addChild(panel.get());
582     }
583   }
584
585   if (data) {
586     alignmainmodel->setUserData(data);
587     data->modelLoaded(path, &props, alignmainmodel.get());
588   }
589
590   std::vector<SGPropertyNode_ptr> animation_nodes;
591   animation_nodes = props.getChildren("animation");
592   for (unsigned i = 0; i < animation_nodes.size(); ++i)
593     /// OSGFIXME: duh, why not only model?????
594     SGAnimation::animate(alignmainmodel.get(), animation_nodes[i], prop_root);
595
596   // restore old path list
597   osgDB::setDataFilePathList(pathList);
598
599   if (props.hasChild("debug-outfile")) {
600     std::string outputfile = props.getStringValue("debug-outfile",
601                                                   "debug-model.osg");
602     osgDB::writeNodeFile(*alignmainmodel, outputfile);
603   }
604
605   return alignmainmodel.release();
606 }
607
608 // end of model.cxx