File indexing completed on 2025-01-18 10:03:48
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef _Graphic3d_MaterialAspect_HeaderFile
0017 #define _Graphic3d_MaterialAspect_HeaderFile
0018
0019 #include <Graphic3d_BSDF.hxx>
0020 #include <Graphic3d_PBRMaterial.hxx>
0021 #include <Graphic3d_NameOfMaterial.hxx>
0022 #include <Graphic3d_TypeOfMaterial.hxx>
0023 #include <Graphic3d_TypeOfReflection.hxx>
0024 #include <TCollection_AsciiString.hxx>
0025 #include <Quantity_Color.hxx>
0026
0027
0028
0029
0030
0031
0032 class Graphic3d_MaterialAspect
0033 {
0034 public:
0035 DEFINE_STANDARD_ALLOC
0036
0037
0038 static Standard_Integer NumberOfMaterials() { return Graphic3d_NameOfMaterial_DEFAULT; }
0039
0040
0041 Standard_EXPORT static Standard_CString MaterialName (const Standard_Integer theRank);
0042
0043
0044 Standard_EXPORT static Graphic3d_TypeOfMaterial MaterialType (const Standard_Integer theRank);
0045
0046
0047
0048
0049
0050 Standard_EXPORT static Standard_Boolean MaterialFromName (const Standard_CString theName,
0051 Graphic3d_NameOfMaterial& theMat);
0052
0053
0054 static Graphic3d_NameOfMaterial MaterialFromName (const Standard_CString theName)
0055 {
0056 Graphic3d_NameOfMaterial aMat = Graphic3d_NameOfMaterial_DEFAULT;
0057 MaterialFromName (theName, aMat);
0058 return aMat;
0059 }
0060
0061 public:
0062
0063
0064 Standard_EXPORT Graphic3d_MaterialAspect();
0065
0066
0067 Standard_EXPORT Graphic3d_MaterialAspect (const Graphic3d_NameOfMaterial theName);
0068
0069
0070 Graphic3d_NameOfMaterial Name() const { return myMaterialName; }
0071
0072
0073 Graphic3d_NameOfMaterial RequestedName() const { return myRequestedMaterialName; }
0074
0075
0076
0077
0078
0079 const TCollection_AsciiString& StringName() const { return myStringName; }
0080
0081
0082 Standard_CString MaterialName() const { return myStringName.ToCString(); }
0083
0084
0085
0086 void SetMaterialName (const TCollection_AsciiString& theName)
0087 {
0088
0089
0090 myMaterialName = Graphic3d_NameOfMaterial_UserDefined;
0091 myStringName = theName;
0092 }
0093
0094
0095
0096
0097 void Reset()
0098 {
0099 init (myRequestedMaterialName);
0100 }
0101
0102
0103
0104 const Quantity_Color& Color() const { return myColors[Graphic3d_TOR_DIFFUSE]; }
0105
0106
0107
0108 Standard_EXPORT void SetColor (const Quantity_Color& theColor);
0109
0110
0111 Standard_ShortReal Transparency() const { return myTransparencyCoef; }
0112
0113
0114 Standard_ShortReal Alpha() const { return 1.0f - myTransparencyCoef; }
0115
0116
0117
0118
0119
0120
0121 Standard_EXPORT void SetTransparency (const Standard_ShortReal theValue);
0122
0123
0124 void SetAlpha (Standard_ShortReal theValue) { SetTransparency (1.0f - theValue); }
0125
0126
0127 const Quantity_Color& AmbientColor() const { return myColors[Graphic3d_TOR_AMBIENT]; }
0128
0129
0130 Standard_EXPORT void SetAmbientColor (const Quantity_Color& theColor);
0131
0132
0133 const Quantity_Color& DiffuseColor() const { return myColors[Graphic3d_TOR_DIFFUSE]; }
0134
0135
0136 Standard_EXPORT void SetDiffuseColor (const Quantity_Color& theColor);
0137
0138
0139 const Quantity_Color& SpecularColor() const { return myColors[Graphic3d_TOR_SPECULAR]; }
0140
0141
0142 Standard_EXPORT void SetSpecularColor (const Quantity_Color& theColor);
0143
0144
0145 const Quantity_Color& EmissiveColor() const { return myColors[Graphic3d_TOR_EMISSION]; }
0146
0147
0148 Standard_EXPORT void SetEmissiveColor (const Quantity_Color& theColor);
0149
0150
0151 Standard_ShortReal Shininess() const { return myShininess; }
0152
0153
0154
0155 Standard_EXPORT void SetShininess (const Standard_ShortReal theValue);
0156
0157
0158
0159 Standard_EXPORT void IncreaseShine (const Standard_ShortReal theDelta);
0160
0161
0162 Standard_ShortReal RefractionIndex() const { return myRefractionIndex; }
0163
0164
0165
0166 Standard_EXPORT void SetRefractionIndex (const Standard_ShortReal theValue);
0167
0168
0169 const Graphic3d_BSDF& BSDF() const { return myBSDF; }
0170
0171
0172 void SetBSDF (const Graphic3d_BSDF& theBSDF) { myBSDF = theBSDF; }
0173
0174
0175 const Graphic3d_PBRMaterial& PBRMaterial () const { return myPBRMaterial; }
0176
0177
0178 void SetPBRMaterial (const Graphic3d_PBRMaterial& thePBRMaterial) { myPBRMaterial = thePBRMaterial; }
0179
0180
0181 Standard_Boolean ReflectionMode (const Graphic3d_TypeOfReflection theType) const
0182 {
0183 return !myColors[theType].IsEqual (Quantity_NOC_BLACK);
0184 }
0185
0186
0187 Graphic3d_TypeOfMaterial MaterialType() const { return myMaterialType; }
0188
0189
0190 Standard_Boolean MaterialType (const Graphic3d_TypeOfMaterial theType) const { return myMaterialType == theType; }
0191
0192
0193 Standard_EXPORT void SetMaterialType (const Graphic3d_TypeOfMaterial theType);
0194
0195
0196 Standard_Boolean IsDifferent (const Graphic3d_MaterialAspect& theOther) const { return !IsEqual (theOther); }
0197
0198
0199 Standard_Boolean operator!= (const Graphic3d_MaterialAspect& theOther) const { return IsDifferent (theOther); }
0200
0201
0202 Standard_Boolean IsEqual (const Graphic3d_MaterialAspect& theOther) const
0203 {
0204 return myTransparencyCoef == theOther.myTransparencyCoef
0205 && myRefractionIndex == theOther.myRefractionIndex
0206 && myBSDF == theOther.myBSDF
0207 && myPBRMaterial == theOther.myPBRMaterial
0208 && myShininess == theOther.myShininess
0209 && myColors[Graphic3d_TOR_AMBIENT] == theOther.myColors[Graphic3d_TOR_AMBIENT]
0210 && myColors[Graphic3d_TOR_DIFFUSE] == theOther.myColors[Graphic3d_TOR_DIFFUSE]
0211 && myColors[Graphic3d_TOR_SPECULAR] == theOther.myColors[Graphic3d_TOR_SPECULAR]
0212 && myColors[Graphic3d_TOR_EMISSION] == theOther.myColors[Graphic3d_TOR_EMISSION];
0213 }
0214
0215
0216 Standard_Boolean operator== (const Graphic3d_MaterialAspect& theOther) const { return IsEqual (theOther); }
0217
0218
0219 Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
0220
0221 public:
0222
0223
0224 Standard_DEPRECATED("Deprecated method, specific material component should be zerroed instead")
0225 void SetReflectionModeOff (const Graphic3d_TypeOfReflection theType)
0226 {
0227 if (!ReflectionMode (theType))
0228 {
0229 return;
0230 }
0231
0232 switch (theType)
0233 {
0234 case Graphic3d_TOR_AMBIENT: SetAmbientColor (Quantity_NOC_BLACK); break;
0235 case Graphic3d_TOR_DIFFUSE: SetDiffuseColor (Quantity_NOC_BLACK); break;
0236 case Graphic3d_TOR_SPECULAR: SetSpecularColor(Quantity_NOC_BLACK); break;
0237 case Graphic3d_TOR_EMISSION: SetEmissiveColor(Quantity_NOC_BLACK); break;
0238 }
0239 }
0240
0241 private:
0242
0243
0244 Standard_EXPORT void init (const Graphic3d_NameOfMaterial theName);
0245
0246
0247 void setUserMaterial()
0248 {
0249
0250
0251 if (myMaterialName != Graphic3d_NameOfMaterial_UserDefined)
0252 {
0253 myMaterialName = Graphic3d_NameOfMaterial_UserDefined;
0254 myStringName = "UserDefined";
0255 }
0256 }
0257
0258 private:
0259
0260 Graphic3d_BSDF myBSDF;
0261 Graphic3d_PBRMaterial myPBRMaterial;
0262 TCollection_AsciiString myStringName;
0263 Quantity_Color myColors[Graphic3d_TypeOfReflection_NB];
0264 Standard_ShortReal myTransparencyCoef;
0265 Standard_ShortReal myRefractionIndex;
0266 Standard_ShortReal myShininess;
0267
0268 Graphic3d_TypeOfMaterial myMaterialType;
0269 Graphic3d_NameOfMaterial myMaterialName;
0270 Graphic3d_NameOfMaterial myRequestedMaterialName;
0271
0272 };
0273
0274 #endif