|
11 | 11 | #include <clocale> |
12 | 12 | #include <ios> |
13 | 13 | #include <osg/LightModel> |
| 14 | +#include <osg/Version> |
14 | 15 | #include <osgDB/FileNameUtils> |
15 | 16 | #include <gepetto/viewer/leaf-node-collada.h> |
16 | 17 |
|
@@ -49,15 +50,44 @@ namespace graphics { |
49 | 50 | } |
50 | 51 | } |
51 | 52 |
|
| 53 | +#if OSG_VERSION_LESS_THAN(3,3,3) |
| 54 | + struct ObjectCache { |
| 55 | + typedef std::map<std::string, osg::NodeRefPtr> Map_t; |
| 56 | + Map_t map_; |
| 57 | + bool get (const std::string& name, osg::NodeRefPtr& node) const |
| 58 | + { |
| 59 | + Map_t::const_iterator it = map_.find (name); |
| 60 | + if (it != map_.end()) { |
| 61 | + node = it->second; |
| 62 | + return true; |
| 63 | + } |
| 64 | + return false; |
| 65 | + } |
| 66 | + void add (const std::string& name, osg::NodeRefPtr& node) |
| 67 | + { |
| 68 | + map_.insert (std::make_pair(name,node)); |
| 69 | + } |
| 70 | + }; |
| 71 | +#endif |
| 72 | + |
52 | 73 | /* Declaration of private function members */ |
53 | 74 |
|
54 | 75 | void LeafNodeCollada::init() |
55 | 76 | { |
| 77 | +#if OSG_VERSION_GREATER_OR_EQUAL(3,3,3) |
| 78 | + static osg::ref_ptr<osgDB::ObjectCache> object_cache (new osgDB::ObjectCache); |
| 79 | +#else |
| 80 | + static ObjectCache object_cache; |
| 81 | + if (!collada_ptr_) |
| 82 | + object_cache.get(collada_file_path_, collada_ptr_); |
| 83 | +#endif |
| 84 | + |
56 | 85 | if (!collada_ptr_) { |
57 | 86 | // Setup cache |
58 | 87 | const osg::ref_ptr<osgDB::Options> options = new osgDB::Options(); |
59 | | - static osg::ref_ptr<osgDB::ObjectCache> object_cache (new osgDB::ObjectCache); |
| 88 | +#if OSG_VERSION_GREATER_OR_EQUAL(3,3,3) |
60 | 89 | options->setObjectCache (object_cache); |
| 90 | +#endif |
61 | 91 | options->setObjectCacheHint(osgDB::Options::CACHE_ALL); |
62 | 92 |
|
63 | 93 | if (!fileExists(collada_file_path_.c_str())) |
@@ -101,6 +131,9 @@ namespace graphics { |
101 | 131 | } |
102 | 132 | if (!collada_ptr_) |
103 | 133 | throw std::invalid_argument(std::string("File ") + collada_file_path_ + std::string(" found but could not be opened. Check that a plugin exist.")); |
| 134 | +#if OSG_VERSION_LESS_THAN(3,3,3) |
| 135 | + object_cache.add(collada_file_path_, collada_ptr_); |
| 136 | +#endif |
104 | 137 |
|
105 | 138 | /* Allow transparency */ |
106 | 139 | collada_ptr_->getOrCreateStateSet()->setMode(GL_BLEND, ::osg::StateAttribute::ON); |
|
0 commit comments