diff --git a/src/ui/widgets/uvedit.cpp b/src/ui/widgets/uvedit.cpp index 1360e7a53..4602c75b4 100644 --- a/src/ui/widgets/uvedit.cpp +++ b/src/ui/widgets/uvedit.cpp @@ -34,6 +34,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "message.h" #include "nifskope.h" +#include "io/material.h" #include "gl/gltex.h" #include "gl/gltools.h" #include "model/nifmodel.h" @@ -920,19 +921,32 @@ bool UVWidget::setNifData( NifModel * nifModel, const QModelIndex & nifIndex ) iTexProp = nif->getBlock( l, "BSLightingShaderProperty" ); if ( iTexProp.isValid() ) { - QModelIndex iTexSource = nif->getBlock( nif->getLink( iTexProp, "Texture Set" ) ); - - if ( iTexSource.isValid() ) { - // Assume that a FO3 mesh never has embedded textures... - //texsource = iTexSource; - //return true; - QModelIndex iTextures = nif->getIndex( iTexSource, "Textures" ); - - if ( iTextures.isValid() ) { - texfile = TexCache::find( nif->get( iTextures.child( 0, 0 ) ), nif->getFolder() ); - return true; + // FO4 BGSM + // Check it first because FO4 BSLightingShaderProperty + // usually also has "Texture Set" node + // with textures not blank sometimes. + QString name = nif->get( iTexProp, "Name" ); + if ( name.endsWith( ".bgsm", Qt::CaseInsensitive ) ) { + QScopedPointer mat( new ShaderMaterial(name) ); + if ( mat && mat->isValid() ) { + texfile = TexCache::find( mat->textures()[0], nif->getFolder() ); + return true; + } + } else { + QModelIndex iTexSource = nif->getBlock( nif->getLink( iTexProp, "Texture Set" ) ); + + if ( iTexSource.isValid() ) { + // Assume that a FO3 mesh never has embedded textures... + //texsource = iTexSource; + //return true; + QModelIndex iTextures = nif->getIndex( iTexSource, "Textures" ); + + if ( iTextures.isValid() ) { + texfile = TexCache::find( nif->get( iTextures.child( 0, 0 ) ), nif->getFolder() ); + return true; + } } - } + } } else { iTexProp = nif->getBlock( l, "BSEffectShaderProperty" );