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