diff --git a/src/XCAFDoc/XCAFDoc_VisMaterial.cxx b/src/XCAFDoc/XCAFDoc_VisMaterial.cxx index 9e223b9f51..37dd94f403 100644 --- a/src/XCAFDoc/XCAFDoc_VisMaterial.cxx +++ b/src/XCAFDoc/XCAFDoc_VisMaterial.cxx @@ -294,23 +294,23 @@ void XCAFDoc_VisMaterial::FillAspect (const Handle(Graphic3d_Aspects)& theAspect Handle(Graphic3d_TextureSet) aTextureSet = new Graphic3d_TextureSet (aNbTexUnits); if (!aColorTexture.IsNull()) { - aTextureSet->SetValue (aTexIter++, new XCAFPrs_Texture (*aColorTexture, Graphic3d_TextureUnit_BaseColor)); + aTextureSet->SetValue (aTexIter++, new XCAFPrs_Texture (aColorTexture, Graphic3d_TextureUnit_BaseColor)); } if (!myPbrMat.EmissiveTexture.IsNull()) { - aTextureSet->SetValue (aTexIter++, new XCAFPrs_Texture (*myPbrMat.EmissiveTexture, Graphic3d_TextureUnit_Emissive)); + aTextureSet->SetValue (aTexIter++, new XCAFPrs_Texture (myPbrMat.EmissiveTexture, Graphic3d_TextureUnit_Emissive)); } if (!myPbrMat.OcclusionTexture.IsNull()) { - aTextureSet->SetValue (aTexIter++, new XCAFPrs_Texture (*myPbrMat.OcclusionTexture, Graphic3d_TextureUnit_Occlusion)); + aTextureSet->SetValue (aTexIter++, new XCAFPrs_Texture (myPbrMat.OcclusionTexture, Graphic3d_TextureUnit_Occlusion)); } if (!myPbrMat.NormalTexture.IsNull()) { - aTextureSet->SetValue (aTexIter++, new XCAFPrs_Texture (*myPbrMat.NormalTexture, Graphic3d_TextureUnit_Normal)); + aTextureSet->SetValue (aTexIter++, new XCAFPrs_Texture (myPbrMat.NormalTexture, Graphic3d_TextureUnit_Normal)); } if (!myPbrMat.MetallicRoughnessTexture.IsNull()) { - aTextureSet->SetValue (aTexIter++, new XCAFPrs_Texture (*myPbrMat.MetallicRoughnessTexture, Graphic3d_TextureUnit_MetallicRoughness)); + aTextureSet->SetValue (aTexIter++, new XCAFPrs_Texture (myPbrMat.MetallicRoughnessTexture, Graphic3d_TextureUnit_MetallicRoughness)); } theAspect->SetTextureSet (aTextureSet); diff --git a/src/XCAFPrs/XCAFPrs_Texture.cxx b/src/XCAFPrs/XCAFPrs_Texture.cxx index 178e28b7b1..f917c16f01 100644 --- a/src/XCAFPrs/XCAFPrs_Texture.cxx +++ b/src/XCAFPrs/XCAFPrs_Texture.cxx @@ -21,14 +21,14 @@ IMPLEMENT_STANDARD_RTTIEXT(XCAFPrs_Texture, Graphic3d_Texture2D) //function : XCAFPrs_Texture //purpose : //======================================================================= -XCAFPrs_Texture::XCAFPrs_Texture (const Image_Texture& theImageSource, +XCAFPrs_Texture::XCAFPrs_Texture (const Handle(Image_Texture)& theImageSource, const Graphic3d_TextureUnit theUnit) : Graphic3d_Texture2D (""), myImageSource (theImageSource) { - if (!myImageSource.TextureId().IsEmpty()) + if (!myImageSource.IsNull() && !myImageSource->TextureId().IsEmpty()) { - myTexId = myImageSource.TextureId(); + myTexId = myImageSource->TextureId(); } myParams->SetTextureUnit (theUnit); myIsColorMap = theUnit == Graphic3d_TextureUnit_BaseColor @@ -41,7 +41,7 @@ XCAFPrs_Texture::XCAFPrs_Texture (const Image_Texture& theImageSource, //======================================================================= Handle(Image_CompressedPixMap) XCAFPrs_Texture::GetCompressedImage (const Handle(Image_SupportedFormats)& theSupported) { - return myImageSource.ReadCompressedImage (theSupported); + return !myImageSource.IsNull() ? myImageSource->ReadCompressedImage (theSupported) : Handle(Image_CompressedPixMap)(); } //======================================================================= @@ -50,7 +50,11 @@ Handle(Image_CompressedPixMap) XCAFPrs_Texture::GetCompressedImage (const Handle //======================================================================= Handle(Image_PixMap) XCAFPrs_Texture::GetImage (const Handle(Image_SupportedFormats)& theSupported) { - Handle(Image_PixMap) anImage = myImageSource.ReadImage (theSupported); - convertToCompatible (theSupported, anImage); + Handle(Image_PixMap) anImage; + if (!myImageSource.IsNull()) + { + anImage = myImageSource->ReadImage(theSupported); + convertToCompatible(theSupported, anImage); + } return anImage; } diff --git a/src/XCAFPrs/XCAFPrs_Texture.hxx b/src/XCAFPrs/XCAFPrs_Texture.hxx index 8c86b52625..d0742d772d 100644 --- a/src/XCAFPrs/XCAFPrs_Texture.hxx +++ b/src/XCAFPrs/XCAFPrs_Texture.hxx @@ -27,8 +27,8 @@ class XCAFPrs_Texture : public Graphic3d_Texture2D public: //! Constructor. - Standard_EXPORT explicit XCAFPrs_Texture (const Image_Texture& theImageSource, - const Graphic3d_TextureUnit theUnit); + Standard_EXPORT XCAFPrs_Texture (const Handle(Image_Texture)& theImageSource, + const Graphic3d_TextureUnit theUnit); //! Image reader. Standard_EXPORT virtual Handle(Image_CompressedPixMap) GetCompressedImage (const Handle(Image_SupportedFormats)& theSupported) Standard_OVERRIDE; @@ -37,12 +37,11 @@ public: Standard_EXPORT virtual Handle(Image_PixMap) GetImage (const Handle(Image_SupportedFormats)& theSupported) Standard_OVERRIDE; //! Return image source. - const Image_Texture& GetImageSource() const { return myImageSource; } + const Handle(Image_Texture)& GetImageSource() const { return myImageSource; } protected: - Image_Texture myImageSource; - + Handle(Image_Texture) myImageSource; }; #endif // _XCAFPrs_Texture_HeaderFile