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