Skip to content

Commit

Permalink
Fix #2299 setting a model directly on the modelsymbol doesn't work
Browse files Browse the repository at this point in the history
  • Loading branch information
gwaldron committed Jul 5, 2023
1 parent edfd84e commit 01e8738
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/osgEarth/InstanceResource
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ namespace osgEarth { namespace Util
optional<URI>& uri() { return _uri; }
const optional<URI>& uri() const { return _uri; }

//! For programmaticly set nodes only
osg::ref_ptr<osg::Node>& node() { return _node; }
const osg::ref_ptr<osg::Node>& node() const { return _node; }

public: // serialization methods

virtual Config getConfig() const;
Expand All @@ -62,7 +66,8 @@ namespace osgEarth { namespace Util
/** Constructs a new resource. */
InstanceResource( const Config& conf =Config() );

optional<URI> _uri;
optional<URI> _uri;
osg::ref_ptr<osg::Node> _node;

virtual osg::Node* createNodeFromURI( const URI& uri, const osgDB::Options* dbOptions ) const =0;
};
Expand Down
5 changes: 4 additions & 1 deletion src/osgEarth/InstanceResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,8 @@ InstanceResource::getConfig() const
osg::Node*
InstanceResource::createNode( const osgDB::Options* dbOptions ) const
{
return createNodeFromURI( _uri.value(), dbOptions );
if (_node.valid())
return _node.get();
else
return createNodeFromURI( _uri.value(), dbOptions );
}
13 changes: 10 additions & 3 deletions src/osgEarth/SubstituteModelFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ SubstituteModelFilter::findResource(const URI& uri,
osg::ref_ptr<InstanceResource>& output )
{
// be careful about refptrs here since _instanceCache is an LRU.

InstanceCache::Record rec;
if ( _instanceCache.get(uri, rec) )
{
Expand All @@ -129,8 +128,16 @@ SubstituteModelFilter::findResource(const URI& uri,
{
// create it on the fly:
output = symbol->createResource();
output->uri() = uri;
_instanceCache.insert( uri, output.get() );

if (!uri.empty())
{
output->uri() = uri;
_instanceCache.insert(uri, output.get());
}
else if (symbol->asModel())
{
output->node() = symbol->asModel()->getModel();
}
}

// failed to find the instance.
Expand Down

0 comments on commit 01e8738

Please sign in to comment.