Skip to content

Commit d683d5a

Browse files
authored
Merge pull request #81 from jmirabel/osg_3.2.1, fix#80
Fix compatibility with OSG < 3.3.3
2 parents 609161f + a98f5ba commit d683d5a

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

src/gvtools.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ int main (int argc, char** argv)
8787
simplified = input;
8888
} else {
8989
simplifier.setSampleRatio(ratio);
90-
simplified = input->clone(osg::CopyOp::DEEP_COPY_ALL)->asNode();
90+
simplified = dynamic_cast<osg::Node*>(input->clone(osg::CopyOp::DEEP_COPY_ALL));
9191
simplified->accept (simplifier);
9292
}
9393
lod->addChild (simplified, minDists[i], maxDists[i]);

src/leaf-node-collada.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <clocale>
1212
#include <ios>
1313
#include <osg/LightModel>
14+
#include <osg/Version>
1415
#include <osgDB/FileNameUtils>
1516
#include <gepetto/viewer/leaf-node-collada.h>
1617

@@ -49,15 +50,44 @@ namespace graphics {
4950
}
5051
}
5152

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+
5273
/* Declaration of private function members */
5374

5475
void LeafNodeCollada::init()
5576
{
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+
5685
if (!collada_ptr_) {
5786
// Setup cache
5887
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)
6089
options->setObjectCache (object_cache);
90+
#endif
6191
options->setObjectCacheHint(osgDB::Options::CACHE_ALL);
6292

6393
if (!fileExists(collada_file_path_.c_str()))
@@ -101,6 +131,9 @@ namespace graphics {
101131
}
102132
if (!collada_ptr_)
103133
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
104137

105138
/* Allow transparency */
106139
collada_ptr_->getOrCreateStateSet()->setMode(GL_BLEND, ::osg::StateAttribute::ON);

0 commit comments

Comments
 (0)