@@ -365,29 +365,33 @@ void AssimpLoader::setLightColorsFromAssimp(
365
365
void AssimpLoader::loadEmbeddedTexture (
366
366
const aiTexture * texture, const std::string & resource_path)
367
367
{
368
- if (texture == nullptr ) {
369
- RVIZ_RENDERING_LOG_ERROR_STREAM (" null texture!" );
370
- return ;
371
- }
368
+ // Check if the embedded texture already exists within TextureManager before proceeding to
369
+ // load it.
370
+ if (!Ogre::TextureManager::getSingleton ().resourceExists (resource_path, ROS_PACKAGE_NAME)) {
371
+ if (texture == nullptr ) {
372
+ RVIZ_RENDERING_LOG_ERROR_STREAM (" null texture!" );
373
+ return ;
374
+ }
372
375
373
- // use the format hint to try to load the image
374
- std::string format_hint (
375
- texture->achFormatHint ,
376
- strnlen (texture->achFormatHint , sizeof (texture->achFormatHint )));
376
+ // use the format hint to try to load the image
377
+ std::string format_hint (
378
+ texture->achFormatHint ,
379
+ strnlen (texture->achFormatHint , sizeof (texture->achFormatHint )));
377
380
378
- Ogre::DataStreamPtr stream (
379
- new Ogre::MemoryDataStream (
380
- (unsigned char *)texture->pcData , texture->mWidth ));
381
+ Ogre::DataStreamPtr stream (
382
+ new Ogre::MemoryDataStream (
383
+ (unsigned char *)texture->pcData , texture->mWidth ));
381
384
382
- try {
383
- Ogre::Image image;
384
- image.load (stream, format_hint.c_str ());
385
- Ogre::TextureManager::getSingleton ().loadImage (
386
- resource_path, ROS_PACKAGE_NAME, image);
387
- } catch (Ogre::Exception & e) {
388
- RVIZ_RENDERING_LOG_ERROR_STREAM (
389
- " Could not load texture [" << resource_path.c_str () <<
390
- " ] with format hint [" << format_hint << " ]: " << e.what ());
385
+ try {
386
+ Ogre::Image image;
387
+ image.load (stream, format_hint.c_str ());
388
+ Ogre::TextureManager::getSingleton ().loadImage (
389
+ resource_path, ROS_PACKAGE_NAME, image);
390
+ } catch (Ogre::Exception & e) {
391
+ RVIZ_RENDERING_LOG_ERROR_STREAM (
392
+ " Could not load texture [" << resource_path.c_str () <<
393
+ " ] with format hint [" << format_hint << " ]: " << e.what ());
394
+ }
391
395
}
392
396
}
393
397
0 commit comments