Skip to content

Commit

Permalink
Fixes for a ModelSymbol with a model node instead of a URI.
Browse files Browse the repository at this point in the history
Fixes #2312.
  • Loading branch information
jasonbeverage committed Dec 8, 2023
1 parent 5e47b4d commit a2048c2
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions src/osgEarth/SubstituteModelFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ SubstituteModelFilter::process(const FeatureList& features,

// first, go through the features and build the model cache. Apply the model matrix' scale
// factor to any AutoTransforms directly (cloning them as necessary)
std::map< std::pair<URI, float>, osg::ref_ptr<osg::Node> > uniqueModels;
std::map< std::pair<std::string, float>, osg::ref_ptr<osg::Node> > uniqueModels;

// URI cache speeds up URI creation since it can be slow.
std::unordered_map<std::string, URI> uriCache;
Expand Down Expand Up @@ -307,12 +307,28 @@ SubstituteModelFilter::process(const FeatureList& features,
calculateGeometryHeading(input, context);
}
// evaluate the instance URI expression:
const std::string& st = input->eval(uriEx, &context);
URI& instanceURI = uriCache[st];
if(instanceURI.empty()) // Create a map, to reuse URI's, since they take a long time to create
{
instanceURI = URI( st, uriEx.uriContext() );
}
std::string resourceKey;
if (symbol->url().isSet())
{
resourceKey = input->eval(uriEx, &context);
}
else if (modelSymbol && modelSymbol->getModel())
{
resourceKey = Stringify() << modelSymbol->getModel();
}
else if (iconSymbol && iconSymbol->getImage())
{
resourceKey = Stringify() << iconSymbol->getImage();
}
URI instanceURI;
if (symbol->url().isSet())
{
instanceURI = uriCache[resourceKey];
if (instanceURI.empty()) // Create a map, to reuse URI's, since they take a long time to create
{
instanceURI = URI(resourceKey, uriEx.uriContext());
}
}

// find the corresponding marker in the cache
osg::ref_ptr<InstanceResource> instance;
Expand Down Expand Up @@ -374,7 +390,7 @@ SubstituteModelFilter::process(const FeatureList& features,
}

// now that we have a marker source, create a node for it
std::pair<URI,float> key( instanceURI, iconSymbol? scale : 1.0f ); //use 1.0 for models, since we don't want unique models based on scaling
std::pair<std::string,float> key( resourceKey, iconSymbol? scale : 1.0f ); //use 1.0 for models, since we don't want unique models based on scaling

// cache nodes per instance.
osg::ref_ptr<osg::Node>& model = uniqueModels[key];
Expand Down

0 comments on commit a2048c2

Please sign in to comment.