Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:05:34

0001 // Copyright (c) 2019 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _XCAFDoc_VisMaterial_HeaderFile
0015 #define _XCAFDoc_VisMaterial_HeaderFile
0016 
0017 #include <Graphic3d_AlphaMode.hxx>
0018 #include <Graphic3d_TypeOfBackfacingModel.hxx>
0019 #include <TCollection_HAsciiString.hxx>
0020 #include <TDF_Attribute.hxx>
0021 #include <XCAFDoc_VisMaterialCommon.hxx>
0022 #include <XCAFDoc_VisMaterialPBR.hxx>
0023 
0024 class Graphic3d_Aspects;
0025 class Graphic3d_MaterialAspect;
0026 
0027 //! Attribute storing Material definition for visualization purposes.
0028 //!
0029 //! Visualization material provides extended information about how object should be displayed on the screen
0030 //! (albedo, metalness, roughness - not just a single color as in case of XCAFDoc_Color).
0031 //! It is expected to correlate with physical material properties (XCAFDoc_Material), but not necessarily (like painted/polished/rusty object).
0032 //!
0033 //! The document defines the list of visualization materials via global attribute XCAFDoc_VisMaterialTool,
0034 //! while particular material assignment to the shape is done through tree-nodes links.
0035 //! Therefore, XCAFDoc_VisMaterialTool methods should be used for managing XCAFDoc_VisMaterial attributes.
0036 //!
0037 //! Visualization material definition consists of two options: Common and PBR (for Physically Based Rendering).
0038 //! Common material definition is an obsolete model defined by very first version of OpenGL graphics API
0039 //! and having specific hardware-accelerated implementation in past (like T&L).
0040 //! PBR metallic-roughness model is closer to physical material properties, and intended to be used within physically-based renderer.
0041 //!
0042 //! For compatibility reasons, this attribute allows defining both material models,
0043 //! so that it is up-to Data Exchange and Application deciding which one to define and use for rendering (depending on viewer capabilities).
0044 //! Automatic conversion from one model to another is possible, but lossy (converted material will not look the same).
0045 //!
0046 //! Within Data Exchange, different file formats have different capabilities for storing visualization material properties
0047 //! from simple color (STEP, IGES), to common (OBJ, glTF 1.0) and PBR (glTF 2.0).
0048 //! This should be taken into account while defining or converting document into one or another format - material definition might be lost or disturbed.
0049 //!
0050 //! @sa XCAFDoc_VisMaterialTool
0051 class XCAFDoc_VisMaterial : public TDF_Attribute
0052 {
0053   DEFINE_STANDARD_RTTIEXT(XCAFDoc_VisMaterial, TDF_Attribute)
0054 public:
0055 
0056   //! Return attribute GUID.
0057   Standard_EXPORT static const Standard_GUID& GetID();
0058 
0059 public:
0060 
0061   //! Empty constructor.
0062   Standard_EXPORT XCAFDoc_VisMaterial();
0063 
0064   //! Return TRUE if material definition is empty.
0065   bool IsEmpty() const { return !myPbrMat.IsDefined && !myCommonMat.IsDefined; }
0066 
0067   //! Fill in material aspect.
0068   Standard_EXPORT void FillMaterialAspect (Graphic3d_MaterialAspect& theAspect) const;
0069 
0070   //! Fill in graphic aspects.
0071   Standard_EXPORT void FillAspect (const Handle(Graphic3d_Aspects)& theAspect) const;
0072 
0073   //! Return TRUE if metal-roughness PBR material is defined; FALSE by default.
0074   Standard_Boolean HasPbrMaterial() const { return myPbrMat.IsDefined; }
0075 
0076   //! Return metal-roughness PBR material.
0077   //! Note that default constructor creates an empty material (@sa XCAFDoc_VisMaterialPBR::IsDefined).
0078   const XCAFDoc_VisMaterialPBR& PbrMaterial() const { return myPbrMat; }
0079 
0080   //! Setup metal-roughness PBR material.
0081   Standard_EXPORT void SetPbrMaterial (const XCAFDoc_VisMaterialPBR& theMaterial);
0082 
0083   //! Setup undefined metal-roughness PBR material.
0084   void UnsetPbrMaterial()
0085   {
0086     XCAFDoc_VisMaterialPBR anEmpty;
0087     anEmpty.IsDefined = false;
0088     SetPbrMaterial (anEmpty);
0089   }
0090 
0091   //! Return TRUE if common material is defined; FALSE by default.
0092   Standard_Boolean HasCommonMaterial() const { return myCommonMat.IsDefined; }
0093 
0094   //! Return common material.
0095   //! Note that default constructor creates an empty material (@sa XCAFDoc_VisMaterialCommon::IsDefined).
0096   const XCAFDoc_VisMaterialCommon& CommonMaterial() const { return myCommonMat; }
0097 
0098   //! Setup common material.
0099   Standard_EXPORT void SetCommonMaterial (const XCAFDoc_VisMaterialCommon& theMaterial);
0100 
0101   //! Setup undefined common material.
0102   void UnsetCommonMaterial()
0103   {
0104     XCAFDoc_VisMaterialCommon anEmpty;
0105     anEmpty.IsDefined = false;
0106     SetCommonMaterial (anEmpty);
0107   }
0108 
0109   //! Return base color.
0110   Standard_EXPORT Quantity_ColorRGBA BaseColor() const;
0111 
0112   //! Return alpha mode; Graphic3d_AlphaMode_BlendAuto by default.
0113   Graphic3d_AlphaMode AlphaMode() const { return myAlphaMode; }
0114 
0115   //! Return alpha cutoff value; 0.5 by default.
0116   Standard_ShortReal AlphaCutOff() const { return myAlphaCutOff; }
0117 
0118   //! Set alpha mode.
0119   Standard_EXPORT void SetAlphaMode (Graphic3d_AlphaMode theMode,
0120                                      Standard_ShortReal  theCutOff = 0.5f);
0121 
0122   //! Returns if the material is double or single sided; Graphic3d_TypeOfBackfacingModel_Auto by default.
0123   Graphic3d_TypeOfBackfacingModel FaceCulling() const { return myFaceCulling; }
0124 
0125   //! Specifies whether the material is double or single sided.
0126   Standard_EXPORT void SetFaceCulling (Graphic3d_TypeOfBackfacingModel theFaceCulling);
0127 
0128   Standard_DEPRECATED("Deprecated method, FaceCulling() should be used instead")
0129   Standard_Boolean IsDoubleSided() const { return myFaceCulling == Graphic3d_TypeOfBackfacingModel_DoubleSided; }
0130 
0131   Standard_DEPRECATED("Deprecated method, SetFaceCulling() should be used instead")
0132   void SetDoubleSided (Standard_Boolean theIsDoubleSided)
0133   {
0134     SetFaceCulling (theIsDoubleSided ? Graphic3d_TypeOfBackfacingModel_DoubleSided : Graphic3d_TypeOfBackfacingModel_Auto);
0135   }
0136 
0137   //! Return material name / tag (transient data, not stored in the document).
0138   const Handle(TCollection_HAsciiString)& RawName() const { return myRawName; }
0139 
0140   //! Set material name / tag (transient data, not stored in the document).
0141   void SetRawName (const Handle(TCollection_HAsciiString)& theName) { myRawName = theName; }
0142 
0143   //! Compare two materials.
0144   //! Performs deep comparison by actual values - e.g. can be useful for merging materials.
0145   Standard_Boolean IsEqual (const Handle(XCAFDoc_VisMaterial)& theOther) const
0146   {
0147     if (theOther.get() == this)
0148     {
0149       return true;
0150     }
0151     return theOther->myFaceCulling == myFaceCulling
0152         && theOther->myAlphaCutOff == myAlphaCutOff
0153         && theOther->myAlphaMode == myAlphaMode
0154         && theOther->myCommonMat.IsEqual (myCommonMat)
0155         && theOther->myPbrMat.IsEqual (myPbrMat);
0156   }
0157 
0158   //! Return Common material or convert PBR into Common material.
0159   Standard_EXPORT XCAFDoc_VisMaterialCommon ConvertToCommonMaterial();
0160 
0161   //! Return PBR material or convert Common into PBR material.
0162   Standard_EXPORT XCAFDoc_VisMaterialPBR ConvertToPbrMaterial();
0163 
0164 public: //! @name interface implementation
0165 
0166   //! Return GUID of this attribute type.
0167   virtual const Standard_GUID& ID() const Standard_OVERRIDE { return GetID(); }
0168 
0169   //! Restore attribute from specified state.
0170   //! @param theWith [in] attribute state to restore (copy into this)
0171   Standard_EXPORT virtual void Restore (const Handle(TDF_Attribute)& theWith) Standard_OVERRIDE;
0172 
0173   //! Create a new empty attribute.
0174   Standard_EXPORT virtual Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
0175 
0176   //! Paste this attribute into another one.
0177   //! @param theInto [in/out] target attribute to copy this into
0178   //! @param theRelTable [in] relocation table
0179   Standard_EXPORT virtual void Paste (const Handle(TDF_Attribute)& theInto,
0180                                       const Handle(TDF_RelocationTable)& theRelTable) const Standard_OVERRIDE;
0181   
0182   //! Dumps the content of me into the stream
0183   Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
0184 
0185 private:
0186 
0187   Handle(TCollection_HAsciiString) myRawName;       //!< material name / tag (transient data)
0188   XCAFDoc_VisMaterialPBR           myPbrMat;        //!< metal-roughness material definition
0189   XCAFDoc_VisMaterialCommon        myCommonMat;     //!< common material definition
0190   Graphic3d_AlphaMode              myAlphaMode;     //!< alpha mode; Graphic3d_AlphaMode_BlendAuto by default
0191   Standard_ShortReal               myAlphaCutOff;   //!< alpha cutoff value; 0.5 by default
0192   Graphic3d_TypeOfBackfacingModel  myFaceCulling;   //!< specifies whether the material is double/single sided
0193 
0194 };
0195 
0196 DEFINE_STANDARD_HANDLE(XCAFDoc_VisMaterial, TDF_Attribute)
0197 
0198 #endif // _XCAFDoc_VisMaterial_HeaderFile