|
|
|||
File indexing completed on 2026-09-26 09:05:19
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 0030 //! screen (albedo, metalness, roughness - not just a single color as in case of XCAFDoc_Color). It 0031 //! is expected to correlate with physical material properties (XCAFDoc_Material), but not 0032 //! necessarily (like painted/polished/rusty object). 0033 //! 0034 //! The document defines the list of visualization materials via global attribute 0035 //! XCAFDoc_VisMaterialTool, while particular material assignment to the shape is done through 0036 //! tree-nodes links. Therefore, XCAFDoc_VisMaterialTool methods should be used for managing 0037 //! XCAFDoc_VisMaterial attributes. 0038 //! 0039 //! Visualization material definition consists of two options: Common and PBR (for Physically Based 0040 //! Rendering). Common material definition is an obsolete model defined by very first version of 0041 //! OpenGL graphics API and having specific hardware-accelerated implementation in past (like T&L). 0042 //! PBR metallic-roughness model is closer to physical material properties, and intended to be used 0043 //! within physically-based renderer. 0044 //! 0045 //! For compatibility reasons, this attribute allows defining both material models, 0046 //! so that it is up-to Data Exchange and Application deciding which one to define and use for 0047 //! rendering (depending on viewer capabilities). Automatic conversion from one model to another is 0048 //! possible, but lossy (converted material will not look the same). 0049 //! 0050 //! Within Data Exchange, different file formats have different capabilities for storing 0051 //! visualization material properties from simple color (STEP, IGES), to common (OBJ, glTF 1.0) and 0052 //! PBR (glTF 2.0). This should be taken into account while defining or converting document into one 0053 //! or another format - material definition might be lost or disturbed. 0054 //! 0055 //! @sa XCAFDoc_VisMaterialTool 0056 class XCAFDoc_VisMaterial : public TDF_Attribute 0057 { 0058 DEFINE_STANDARD_RTTIEXT(XCAFDoc_VisMaterial, TDF_Attribute) 0059 public: 0060 //! Return attribute GUID. 0061 Standard_EXPORT static const Standard_GUID& GetID(); 0062 0063 public: 0064 //! Empty constructor. 0065 Standard_EXPORT XCAFDoc_VisMaterial(); 0066 0067 //! Return TRUE if material definition is empty. 0068 bool IsEmpty() const { return !myPbrMat.IsDefined && !myCommonMat.IsDefined; } 0069 0070 //! Fill in material aspect. 0071 Standard_EXPORT void FillMaterialAspect(Graphic3d_MaterialAspect& theAspect) const; 0072 0073 //! Fill in graphic aspects. 0074 Standard_EXPORT void FillAspect(const occ::handle<Graphic3d_Aspects>& theAspect) const; 0075 0076 //! Return TRUE if metal-roughness PBR material is defined; FALSE by default. 0077 bool HasPbrMaterial() const { return myPbrMat.IsDefined; } 0078 0079 //! Return metal-roughness PBR material. 0080 //! Note that default constructor creates an empty material (@sa 0081 //! XCAFDoc_VisMaterialPBR::IsDefined). 0082 const XCAFDoc_VisMaterialPBR& PbrMaterial() const { return myPbrMat; } 0083 0084 //! Setup metal-roughness PBR material. 0085 Standard_EXPORT void SetPbrMaterial(const XCAFDoc_VisMaterialPBR& theMaterial); 0086 0087 //! Setup undefined metal-roughness PBR material. 0088 void UnsetPbrMaterial() 0089 { 0090 XCAFDoc_VisMaterialPBR anEmpty; 0091 anEmpty.IsDefined = false; 0092 SetPbrMaterial(anEmpty); 0093 } 0094 0095 //! Return TRUE if common material is defined; FALSE by default. 0096 bool HasCommonMaterial() const { return myCommonMat.IsDefined; } 0097 0098 //! Return common material. 0099 //! Note that default constructor creates an empty material (@sa 0100 //! XCAFDoc_VisMaterialCommon::IsDefined). 0101 const XCAFDoc_VisMaterialCommon& CommonMaterial() const { return myCommonMat; } 0102 0103 //! Setup common material. 0104 Standard_EXPORT void SetCommonMaterial(const XCAFDoc_VisMaterialCommon& theMaterial); 0105 0106 //! Setup undefined common material. 0107 void UnsetCommonMaterial() 0108 { 0109 XCAFDoc_VisMaterialCommon anEmpty; 0110 anEmpty.IsDefined = false; 0111 SetCommonMaterial(anEmpty); 0112 } 0113 0114 //! Return base color. 0115 Standard_EXPORT Quantity_ColorRGBA BaseColor() const; 0116 0117 //! Return alpha mode; Graphic3d_AlphaMode_BlendAuto by default. 0118 Graphic3d_AlphaMode AlphaMode() const { return myAlphaMode; } 0119 0120 //! Return alpha cutoff value; 0.5 by default. 0121 float AlphaCutOff() const { return myAlphaCutOff; } 0122 0123 //! Set alpha mode. 0124 Standard_EXPORT void SetAlphaMode(Graphic3d_AlphaMode theMode, float theCutOff = 0.5f); 0125 0126 //! Returns if the material is double or single sided; Graphic3d_TypeOfBackfacingModel_Auto by 0127 //! default. 0128 Graphic3d_TypeOfBackfacingModel FaceCulling() const { return myFaceCulling; } 0129 0130 //! Specifies whether the material is double or single sided. 0131 Standard_EXPORT void SetFaceCulling(Graphic3d_TypeOfBackfacingModel theFaceCulling); 0132 0133 Standard_DEPRECATED("Deprecated method, FaceCulling() should be used instead") 0134 bool IsDoubleSided() const 0135 { 0136 return myFaceCulling == Graphic3d_TypeOfBackfacingModel_DoubleSided; 0137 } 0138 0139 Standard_DEPRECATED("Deprecated method, SetFaceCulling() should be used " 0140 "instead") 0141 void SetDoubleSided(bool theIsDoubleSided) 0142 { 0143 SetFaceCulling(theIsDoubleSided ? Graphic3d_TypeOfBackfacingModel_DoubleSided 0144 : Graphic3d_TypeOfBackfacingModel_Auto); 0145 } 0146 0147 //! Return material name / tag (transient data, not stored in the document). 0148 const occ::handle<TCollection_HAsciiString>& RawName() const { return myRawName; } 0149 0150 //! Set material name / tag (transient data, not stored in the document). 0151 void SetRawName(const occ::handle<TCollection_HAsciiString>& theName) { myRawName = theName; } 0152 0153 //! Compare two materials. 0154 //! Performs deep comparison by actual values - e.g. can be useful for merging materials. 0155 bool IsEqual(const occ::handle<XCAFDoc_VisMaterial>& theOther) const 0156 { 0157 if (theOther.get() == this) 0158 { 0159 return true; 0160 } 0161 return theOther->myFaceCulling == myFaceCulling && theOther->myAlphaCutOff == myAlphaCutOff 0162 && theOther->myAlphaMode == myAlphaMode && theOther->myCommonMat.IsEqual(myCommonMat) 0163 && theOther->myPbrMat.IsEqual(myPbrMat); 0164 } 0165 0166 //! Return Common material or convert PBR into Common material. 0167 Standard_EXPORT XCAFDoc_VisMaterialCommon ConvertToCommonMaterial(); 0168 0169 //! Return PBR material or convert Common into PBR material. 0170 Standard_EXPORT XCAFDoc_VisMaterialPBR ConvertToPbrMaterial(); 0171 0172 public: //! @name interface implementation 0173 //! Return GUID of this attribute type. 0174 const Standard_GUID& ID() const override { return GetID(); } 0175 0176 //! Restore attribute from specified state. 0177 //! @param[in] theWith attribute state to restore (copy into this) 0178 Standard_EXPORT void Restore(const occ::handle<TDF_Attribute>& theWith) override; 0179 0180 //! Create a new empty attribute. 0181 Standard_EXPORT occ::handle<TDF_Attribute> NewEmpty() const override; 0182 0183 //! Paste this attribute into another one. 0184 //! @param theInto [in/out] target attribute to copy this into 0185 //! @param[in] theRelTable relocation table 0186 Standard_EXPORT void Paste(const occ::handle<TDF_Attribute>& theInto, 0187 const occ::handle<TDF_RelocationTable>& theRelTable) const override; 0188 0189 //! Dumps the content of me into the stream 0190 Standard_EXPORT void DumpJson(Standard_OStream& theOStream, int theDepth = -1) const override; 0191 0192 private: 0193 occ::handle<TCollection_HAsciiString> myRawName; //!< material name / tag (transient data) 0194 XCAFDoc_VisMaterialPBR myPbrMat; //!< metal-roughness material definition 0195 XCAFDoc_VisMaterialCommon myCommonMat; //!< common material definition 0196 // clang-format off 0197 Graphic3d_AlphaMode myAlphaMode; //!< alpha mode; Graphic3d_AlphaMode_BlendAuto by default 0198 float myAlphaCutOff; //!< alpha cutoff value; 0.5 by default 0199 Graphic3d_TypeOfBackfacingModel myFaceCulling; //!< specifies whether the material is double/single sided 0200 // clang-format on 0201 }; 0202 0203 #endif // _XCAFDoc_VisMaterial_HeaderFile
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|