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