| 1 |
/*************************************************************************** |
| 2 |
* Copyright (c) 2005 Jürgen Riegel <[email protected]> * |
| 3 |
* * |
| 4 |
* This file is part of the FreeCAD CAx development system. * |
| 5 |
* * |
| 6 |
* This library is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Library General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 |
* GNU Library General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Library General Public * |
| 17 |
* License along with this library; see the file COPYING.LIB. If not, * |
| 18 |
* write to the Free Software Foundation, Inc., 59 Temple Place, * |
| 19 |
* Suite 330, Boston, MA 02111-1307, USA * |
| 20 |
* * |
| 21 |
***************************************************************************/ |
| 22 |
|
| 23 |
|
| 24 |
#ifndef APP_MATERIAL_H |
| 25 |
#define APP_MATERIAL_H |
| 26 |
|
| 27 |
#include <Base/Color.h> |
| 28 |
|
| 29 |
namespace App |
| 30 |
{ |
| 31 |
|
| 32 |
/** Material class |
| 33 |
*/ |
| 34 |
class AppExport Material |
| 35 |
{ |
| 36 |
public: |
| 37 |
enum MaterialType |
| 38 |
{ |
| 39 |
BRASS, |
| 40 |
BRONZE, |
| 41 |
COPPER, |
| 42 |
GOLD, |
| 43 |
PEWTER, |
| 44 |
PLASTER, |
| 45 |
PLASTIC, |
| 46 |
SILVER, |
| 47 |
STEEL, |
| 48 |
STONE, |
| 49 |
SHINY_PLASTIC, |
| 50 |
SATIN, |
| 51 |
METALIZED, |
| 52 |
NEON_GNC, |
| 53 |
CHROME, |
| 54 |
ALUMINIUM, |
| 55 |
OBSIDIAN, |
| 56 |
NEON_PHC, |
| 57 |
JADE, |
| 58 |
RUBY, |
| 59 |
EMERALD, |
| 60 |
DEFAULT, |
| 61 |
USER_DEFINED |
| 62 |
}; |
| 63 |
|
| 64 |
public: |
| 65 |
/** @name Constructors |
| 66 |
*/ |
| 67 |
//@{ |
| 68 |
/** Sets the USER_DEFINED material type. The user must set the colors afterwards. */ |
| 69 |
Material(); |
| 70 |
~Material() = default; |
| 71 |
/** Copy constructor. */ |
| 72 |
Material(const Material& other) = default; |
| 73 |
Material(Material&& other) = default; |
| 74 |
/** Defines the colors and shininess for the material \a MatName. If \a MatName isn't defined |
| 75 |
* then USER_DEFINED is set and the user must define the colors itself. |
| 76 |
*/ |
| 77 |
explicit Material(const char* MatName); |
| 78 |
/** Does basically the same as the constructor above unless that it accepts a MaterialType as |
| 79 |
* argument. */ |
| 80 |
explicit Material(MaterialType MatType); |
| 81 |
//@} |
| 82 |
|
| 83 |
/** Set a material by name |
| 84 |
* There are some standard materials defined which are: |
| 85 |
* \li Brass |
| 86 |
* \li Bronze |
| 87 |
* \li Copper |
| 88 |
* \li Gold |
| 89 |
* \li Pewter |
| 90 |
* \li Plaster |
| 91 |
* \li Plastic |
| 92 |
* \li Silver |
| 93 |
* \li Steel |
| 94 |
* \li Stone |
| 95 |
* \li Shiny plastic |
| 96 |
* \li Satin |
| 97 |
* \li Metalized |
| 98 |
* \li Neon GNC |
| 99 |
* \li Chrome |
| 100 |
* \li Aluminium |
| 101 |
* \li Obsidian |
| 102 |
* \li Neon PHC |
| 103 |
* \li Jade |
| 104 |
* \li Ruby |
| 105 |
* \li Emerald |
| 106 |
* Furthermore there two additional modes \a Default which defines a kind of grey metallic and |
| 107 |
* user defined that does nothing. The Base::Color and the other properties of the material are |
| 108 |
* defined in the range [0-1]. If \a MatName is an unknown material name then the type |
| 109 |
* USER_DEFINED is set and the material doesn't get changed. |
| 110 |
*/ |
| 111 |
void set(const char* MatName); |
| 112 |
/** |
| 113 |
* This method is provided for convenience which does basically the same as the method above |
| 114 |
* unless that it accepts a MaterialType as argument. |
| 115 |
*/ |
| 116 |
void setType(MaterialType MatType); |
| 117 |
/** |
| 118 |
* Returns the currently set material type. |
| 119 |
*/ |
| 120 |
MaterialType getType() const |
| 121 |
{ |
| 122 |
return _matType; |
| 123 |
} |
| 124 |
|
| 125 |
/** @name Properties */ |
| 126 |
//@{ |
| 127 |
// NOLINTBEGIN |
| 128 |
Base::Color ambientColor; /**< Defines the ambient color. */ |
| 129 |
Base::Color diffuseColor; /**< Defines the diffuse color. */ |
| 130 |
Base::Color specularColor; /**< Defines the specular color. */ |
| 131 |
Base::Color emissiveColor; /**< Defines the emissive color. */ |
| 132 |
float shininess; |
| 133 |
float transparency; |
| 134 |
std::string image; |
| 135 |
std::string imagePath; |
| 136 |
std::string uuid; |
| 137 |
// NOLINTEND |
| 138 |
//@} |
| 139 |
|
| 140 |
bool operator==(const Material& m) const |
| 141 |
{ |
| 142 |
// clang-format off |
| 143 |
if (!uuid.empty() && uuid == m.uuid) { |
| 144 |
return true; |
| 145 |
} |
| 146 |
return shininess == m.shininess |
| 147 |
&& transparency == m.transparency |
| 148 |
&& ambientColor == m.ambientColor |
| 149 |
&& diffuseColor == m.diffuseColor |
| 150 |
&& specularColor == m.specularColor |
| 151 |
&& emissiveColor == m.emissiveColor |
| 152 |
&& image == m.image |
| 153 |
&& imagePath == m.imagePath; |
| 154 |
// clang-format on |
| 155 |
} |
| 156 |
bool operator!=(const Material& m) const |
| 157 |
{ |
| 158 |
return !operator==(m); |
| 159 |
} |
| 160 |
Material& operator=(const Material& other) = default; |
| 161 |
Material& operator=(Material&& other) = default; |
| 162 |
|
| 163 |
static Material getDefaultAppearance(); |
| 164 |
|
| 165 |
private: |
| 166 |
MaterialType _matType; |
| 167 |
}; |
| 168 |
|
| 169 |
} // namespace App |
| 170 |
|
| 171 |
#endif // APP_MATERIAL_H |