Material: Material appearance
Uses new material system for appearance Each feature object now has a property called ShapeMaterial that describes its physical properties. If it has a shape, it has a material. The ShapeColor attribute is replaced by a ShapeAppearance attribute. This is a material list that describes all appearance properties, not just diffuse color. As a list in can be used for all elements of a shape, such as edges and faces. A new widget is provided to allow the user to select materials in a consistent fashion. It can also launch the material editor with its more advanced capabilities.
This commit is contained in:
committed by
Chris Hennes
parent
37c38acd19
commit
ba20441935
@@ -173,3 +173,12 @@ DocumentObject *GeoFeature::resolveElement(DocumentObject *obj, const char *subn
|
||||
return sobj;
|
||||
}
|
||||
|
||||
App::Material GeoFeature::getMaterialAppearance() const
|
||||
{
|
||||
return App::Material(App::Material::DEFAULT);
|
||||
}
|
||||
|
||||
void GeoFeature::setMaterialAppearance(const App::Material& material)
|
||||
{
|
||||
Q_UNUSED(material)
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "DocumentObject.h"
|
||||
#include "PropertyGeo.h"
|
||||
#include "MappedElement.h"
|
||||
#include "Material.h"
|
||||
|
||||
namespace App
|
||||
{
|
||||
@@ -120,6 +121,25 @@ public:
|
||||
* @return Base::Placement The transformation from the global reference coordinate system
|
||||
*/
|
||||
Base::Placement globalPlacement() const;
|
||||
/**
|
||||
* @brief Virtual function to get an App::Material object describing the appearance
|
||||
*
|
||||
* The appearance properties are described by the underlying features material. This can not
|
||||
* be accessed directly from within the Gui module. This virtual function will return a
|
||||
* App::Material object describing the appearance properties of the material.
|
||||
*
|
||||
* @return App::Material the appearance properties of the object material
|
||||
*/
|
||||
virtual App::Material getMaterialAppearance() const;
|
||||
|
||||
/**
|
||||
* @brief Virtual function to set the appearance with an App::Material object
|
||||
*
|
||||
* The appearance properties are described by the underlying features material. This cannot
|
||||
* be accessed directly from within the Gui module. This virtual function will set the
|
||||
* appearance from an App::Material object.
|
||||
*/
|
||||
virtual void setMaterialAppearance(const App::Material& material);
|
||||
|
||||
protected:
|
||||
std::pair<std::string, std::string> _getElementName(const char* name,
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
# include <cstring>
|
||||
#include <cstring>
|
||||
#endif
|
||||
|
||||
#include "Material.h"
|
||||
@@ -36,113 +36,123 @@ using namespace App;
|
||||
// Material
|
||||
//===========================================================================
|
||||
Material::Material()
|
||||
: shininess{0.9000f}
|
||||
, transparency{}
|
||||
: shininess {0.9000f}
|
||||
, transparency {}
|
||||
{
|
||||
setType(STEEL);
|
||||
setType(USER_DEFINED);
|
||||
}
|
||||
|
||||
Material::Material(const Material& other)
|
||||
: ambientColor(other.ambientColor)
|
||||
, diffuseColor(other.diffuseColor)
|
||||
, specularColor(other.specularColor)
|
||||
, emissiveColor(other.emissiveColor)
|
||||
, shininess(other.shininess)
|
||||
, transparency(other.transparency)
|
||||
, uuid(other.uuid)
|
||||
, _matType(other._matType)
|
||||
{
|
||||
}
|
||||
|
||||
Material::Material(const char* MatName)
|
||||
: shininess{0.9000f}
|
||||
, transparency{}
|
||||
: shininess {0.9000f}
|
||||
, transparency {}
|
||||
{
|
||||
set(MatName);
|
||||
}
|
||||
|
||||
Material::Material(const MaterialType MatType)
|
||||
: shininess{0.9000f}
|
||||
, transparency{}
|
||||
: shininess {0.9000f}
|
||||
, transparency {}
|
||||
{
|
||||
setType(MatType);
|
||||
}
|
||||
|
||||
Material& Material::operator=(const Material& other)
|
||||
{
|
||||
if (this == &other) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
_matType = other._matType;
|
||||
ambientColor = other.ambientColor;
|
||||
diffuseColor = other.diffuseColor;
|
||||
specularColor = other.specularColor;
|
||||
emissiveColor = other.emissiveColor;
|
||||
shininess = other.shininess;
|
||||
transparency = other.transparency;
|
||||
uuid = other.uuid;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Material::set(const char* MatName)
|
||||
{
|
||||
if (strcmp("Brass",MatName) == 0 ) {
|
||||
if (strcmp("Brass", MatName) == 0) {
|
||||
setType(BRASS);
|
||||
}
|
||||
else if (strcmp("Bronze",MatName) == 0 ) {
|
||||
else if (strcmp("Bronze", MatName) == 0) {
|
||||
setType(BRONZE);
|
||||
}
|
||||
else if (strcmp("Copper",MatName) == 0 ) {
|
||||
else if (strcmp("Copper", MatName) == 0) {
|
||||
setType(COPPER);
|
||||
}
|
||||
else if (strcmp("Gold",MatName) == 0 ) {
|
||||
// ambientColor.set(0.3f,0.1f,0.1f);
|
||||
// diffuseColor.set(0.8f,0.7f,0.2f);
|
||||
// specularColor.set(0.4f,0.3f,0.1f);
|
||||
// shininess = .4f;
|
||||
// transparency = .0f;
|
||||
//// ambientColor.set(0.3f,0.1f,0.1f);
|
||||
//// diffuseColor.set(0.22f,0.15f,0.00f);
|
||||
//// specularColor.set(0.71f,0.70f,0.56f);
|
||||
//// shininess = .16f;
|
||||
//// transparency = .0f;
|
||||
//// ambientColor.set(0.24725f, 0.1995f, 0.0745f);
|
||||
//// diffuseColor.set(0.75164f, 0.60648f, 0.22648f);
|
||||
//// specularColor.set(0.628281f, 0.555802f, 0.366065f);
|
||||
//// shininess = .16f;
|
||||
//// transparency = .0f;
|
||||
else if (strcmp("Gold", MatName) == 0) {
|
||||
setType(GOLD);
|
||||
}
|
||||
else if (strcmp("Pewter",MatName) == 0 ) {
|
||||
else if (strcmp("Pewter", MatName) == 0) {
|
||||
setType(PEWTER);
|
||||
}
|
||||
else if (strcmp("Plaster",MatName) == 0 ) {
|
||||
else if (strcmp("Plaster", MatName) == 0) {
|
||||
setType(PLASTER);
|
||||
}
|
||||
else if (strcmp("Plastic",MatName) == 0 ) {
|
||||
else if (strcmp("Plastic", MatName) == 0) {
|
||||
setType(PLASTIC);
|
||||
}
|
||||
else if (strcmp("Silver",MatName) == 0 ) {
|
||||
else if (strcmp("Silver", MatName) == 0) {
|
||||
setType(SILVER);
|
||||
}
|
||||
else if (strcmp("Steel",MatName) == 0 ) {
|
||||
else if (strcmp("Steel", MatName) == 0) {
|
||||
setType(STEEL);
|
||||
}
|
||||
else if (strcmp("Stone",MatName) == 0 ) {
|
||||
// ambientColor.set(0.0f,0.0f,0.0f);
|
||||
// diffuseColor.set(0.0f,0.0f,0.0f);
|
||||
// specularColor.set(0.4f,0.3f,0.1f);
|
||||
// shininess = .4f;
|
||||
// transparency = .0f;
|
||||
else if (strcmp("Stone", MatName) == 0) {
|
||||
setType(STONE);
|
||||
}
|
||||
else if (strcmp("Shiny plastic",MatName) == 0 ) {
|
||||
else if (strcmp("Shiny plastic", MatName) == 0) {
|
||||
setType(SHINY_PLASTIC);
|
||||
}
|
||||
else if (strcmp("Satin",MatName) == 0 ) {
|
||||
else if (strcmp("Satin", MatName) == 0) {
|
||||
setType(SATIN);
|
||||
}
|
||||
else if (strcmp("Metalized",MatName) == 0 ) {
|
||||
else if (strcmp("Metalized", MatName) == 0) {
|
||||
setType(METALIZED);
|
||||
}
|
||||
else if (strcmp("Neon GNC",MatName) == 0 ) {
|
||||
else if (strcmp("Neon GNC", MatName) == 0) {
|
||||
setType(NEON_GNC);
|
||||
}
|
||||
else if (strcmp("Chrome",MatName) == 0 ) {
|
||||
else if (strcmp("Chrome", MatName) == 0) {
|
||||
setType(CHROME);
|
||||
}
|
||||
else if (strcmp("Aluminium",MatName) == 0 ) {
|
||||
else if (strcmp("Aluminium", MatName) == 0) {
|
||||
setType(ALUMINIUM);
|
||||
}
|
||||
else if (strcmp("Obsidian",MatName) == 0 ) {
|
||||
else if (strcmp("Obsidian", MatName) == 0) {
|
||||
setType(OBSIDIAN);
|
||||
}
|
||||
else if (strcmp("Neon PHC",MatName) == 0 ) {
|
||||
else if (strcmp("Neon PHC", MatName) == 0) {
|
||||
setType(NEON_PHC);
|
||||
}
|
||||
else if (strcmp("Jade",MatName) == 0 ) {
|
||||
else if (strcmp("Jade", MatName) == 0) {
|
||||
setType(JADE);
|
||||
}
|
||||
else if (strcmp("Ruby",MatName) == 0 ) {
|
||||
else if (strcmp("Ruby", MatName) == 0) {
|
||||
setType(RUBY);
|
||||
}
|
||||
else if (strcmp("Emerald",MatName) == 0 ) {
|
||||
else if (strcmp("Emerald", MatName) == 0) {
|
||||
setType(EMERALD);
|
||||
}
|
||||
else if (strcmp("Default",MatName) == 0 ) {
|
||||
else if (strcmp("Default", MatName) == 0) {
|
||||
setType(DEFAULT);
|
||||
}
|
||||
else {
|
||||
@@ -153,185 +163,184 @@ void Material::set(const char* MatName)
|
||||
void Material::setType(const MaterialType MatType)
|
||||
{
|
||||
_matType = MatType;
|
||||
switch (MatType)
|
||||
{
|
||||
case BRASS:
|
||||
ambientColor .set(0.3294f,0.2235f,0.0275f);
|
||||
diffuseColor .set(0.7804f,0.5686f,0.1137f);
|
||||
specularColor.set(0.9922f,0.9412f,0.8078f);
|
||||
emissiveColor.set(0.0000f,0.0000f,0.0000f);
|
||||
shininess = 0.2179f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case BRONZE:
|
||||
ambientColor .set(0.2125f,0.1275f,0.0540f);
|
||||
diffuseColor .set(0.7140f,0.4284f,0.1814f);
|
||||
specularColor.set(0.3935f,0.2719f,0.1667f);
|
||||
emissiveColor.set(0.0000f,0.0000f,0.0000f);
|
||||
shininess = 0.2000f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case COPPER:
|
||||
ambientColor .set(0.3300f,0.2600f,0.2300f);
|
||||
diffuseColor .set(0.5000f,0.1100f,0.0000f);
|
||||
specularColor.set(0.9500f,0.7300f,0.0000f);
|
||||
emissiveColor.set(0.0000f,0.0000f,0.0000f);
|
||||
shininess = 0.9300f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case GOLD:
|
||||
ambientColor .set(0.3000f,0.2306f,0.0953f);
|
||||
diffuseColor .set(0.4000f,0.2760f,0.0000f);
|
||||
specularColor.set(0.9000f,0.8820f,0.7020f);
|
||||
emissiveColor.set(0.0000f,0.0000f,0.0000f);
|
||||
shininess = 0.0625f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case PEWTER:
|
||||
ambientColor .set(0.1059f,0.0588f,0.1137f);
|
||||
diffuseColor .set(0.4275f,0.4706f,0.5412f);
|
||||
specularColor.set(0.3333f,0.3333f,0.5216f);
|
||||
emissiveColor.set(0.0000f,0.0000f,0.0000f);
|
||||
shininess = 0.0769f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case PLASTER:
|
||||
ambientColor .set(0.0500f,0.0500f,0.0500f);
|
||||
diffuseColor .set(0.1167f,0.1167f,0.1167f);
|
||||
specularColor.set(0.0305f,0.0305f,0.0305f);
|
||||
emissiveColor.set(0.0000f,0.0000f,0.0000f);
|
||||
shininess = 0.0078f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case PLASTIC:
|
||||
ambientColor .set(0.1000f,0.1000f,0.1000f);
|
||||
diffuseColor .set(0.0000f,0.0000f,0.0000f);
|
||||
specularColor.set(0.0600f,0.0600f,0.0600f);
|
||||
emissiveColor.set(0.0000f,0.0000f,0.0000f);
|
||||
shininess = 0.0078f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case SILVER:
|
||||
ambientColor .set(0.1922f,0.1922f,0.1922f);
|
||||
diffuseColor .set(0.5075f,0.5075f,0.5075f);
|
||||
specularColor.set(0.5083f,0.5083f,0.5083f);
|
||||
emissiveColor.set(0.0000f,0.0000f,0.0000f);
|
||||
shininess = 0.2000f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case STEEL:
|
||||
ambientColor .set(0.0020f,0.0020f,0.0020f);
|
||||
diffuseColor .set(0.0000f,0.0000f,0.0000f);
|
||||
specularColor.set(0.9800f,0.9800f,0.9800f);
|
||||
emissiveColor.set(0.0000f,0.0000f,0.0000f);
|
||||
shininess = 0.0600f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case STONE:
|
||||
ambientColor .set(0.1900f,0.1520f,0.1178f);
|
||||
diffuseColor .set(0.7500f,0.6000f,0.4650f);
|
||||
specularColor.set(0.0784f,0.0800f,0.0480f);
|
||||
emissiveColor.set(0.0000f,0.0000f,0.0000f);
|
||||
shininess = 0.1700f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case SHINY_PLASTIC:
|
||||
ambientColor .set(0.0880f,0.0880f,0.0880f);
|
||||
diffuseColor .set(0.0000f,0.0000f,0.0000f);
|
||||
specularColor.set(1.0000f,1.0000f,1.0000f);
|
||||
emissiveColor.set(0.0000f,0.0000f,0.0000f);
|
||||
shininess = 1.0000f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case SATIN:
|
||||
ambientColor .set(0.0660f,0.0660f,0.0660f);
|
||||
diffuseColor .set(0.0000f,0.0000f,0.0000f);
|
||||
specularColor.set(0.4400f,0.4400f,0.4400f);
|
||||
emissiveColor.set(0.0000f,0.0000f,0.0000f);
|
||||
shininess = 0.0938f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case METALIZED:
|
||||
ambientColor .set(0.1800f,0.1800f,0.1800f);
|
||||
diffuseColor .set(0.0000f,0.0000f,0.0000f);
|
||||
specularColor.set(0.4500f,0.4500f,0.4500f);
|
||||
emissiveColor.set(0.0000f,0.0000f,0.0000f);
|
||||
shininess = 0.1300f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case NEON_GNC:
|
||||
ambientColor .set(0.2000f,0.2000f,0.2000f);
|
||||
diffuseColor .set(0.0000f,0.0000f,0.0000f);
|
||||
specularColor.set(0.6200f,0.6200f,0.6200f);
|
||||
emissiveColor.set(1.0000f,1.0000f,0.0000f);
|
||||
shininess = 0.0500f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case CHROME:
|
||||
ambientColor .set(0.3500f,0.3500f,0.3500f);
|
||||
diffuseColor .set(0.9176f,0.9176f,0.9176f);
|
||||
specularColor.set(0.9746f,0.9746f,0.9746f);
|
||||
emissiveColor.set(0.0000f,0.0000f,0.0000f);
|
||||
shininess = 0.1000f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case ALUMINIUM:
|
||||
ambientColor .set(0.3000f,0.3000f,0.3000f);
|
||||
diffuseColor .set(0.3000f,0.3000f,0.3000f);
|
||||
specularColor.set(0.7000f,0.7000f,0.8000f);
|
||||
emissiveColor.set(0.0000f,0.0000f,0.0000f);
|
||||
shininess = 0.0900f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case OBSIDIAN:
|
||||
ambientColor .set(0.0538f,0.0500f,0.0662f);
|
||||
diffuseColor .set(0.1828f,0.1700f,0.2253f);
|
||||
specularColor.set(0.3327f,0.3286f,0.3464f);
|
||||
emissiveColor.set(0.0000f,0.0000f,0.0000f);
|
||||
shininess = 0.3000f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case NEON_PHC:
|
||||
ambientColor .set(1.0000f,1.0000f,1.0000f);
|
||||
diffuseColor .set(1.0000f,1.0000f,1.0000f);
|
||||
specularColor.set(0.6200f,0.6200f,0.6200f);
|
||||
emissiveColor.set(0.0000f,0.9000f,0.4140f);
|
||||
shininess = 0.0500f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case JADE:
|
||||
ambientColor .set(0.1350f,0.2225f,0.1575f);
|
||||
diffuseColor .set(0.5400f,0.8900f,0.6300f);
|
||||
specularColor.set(0.3162f,0.3162f,0.3162f);
|
||||
emissiveColor.set(0.0000f,0.0000f,0.0000f);
|
||||
shininess = 0.1000f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case RUBY:
|
||||
ambientColor .set(0.1745f,0.0118f,0.0118f);
|
||||
diffuseColor .set(0.6142f,0.0414f,0.0414f);
|
||||
specularColor.set(0.7278f,0.6279f,0.6267f);
|
||||
emissiveColor.set(0.0000f,0.0000f,0.0000f);
|
||||
shininess = 0.6000f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case EMERALD:
|
||||
ambientColor .set(0.0215f,0.1745f,0.0215f);
|
||||
diffuseColor .set(0.0757f,0.6142f,0.0757f);
|
||||
specularColor.set(0.6330f,0.7278f,0.6330f);
|
||||
emissiveColor.set(0.0000f,0.0000f,0.0000f);
|
||||
shininess = 0.6000f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case USER_DEFINED:
|
||||
break;
|
||||
default:
|
||||
ambientColor.set(0.3333f, 0.3333f, 0.3333f);
|
||||
diffuseColor .set(0.8000f,0.8000f,0.9000f);
|
||||
specularColor.set(0.5333f, 0.5333f, 0.5333f);
|
||||
emissiveColor.set(0.0000f,0.0000f,0.0000f);
|
||||
shininess = 0.9000f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
switch (MatType) {
|
||||
case BRASS:
|
||||
ambientColor.set(0.3294f, 0.2235f, 0.0275f);
|
||||
diffuseColor.set(0.7804f, 0.5686f, 0.1137f);
|
||||
specularColor.set(0.9922f, 0.9412f, 0.8078f);
|
||||
emissiveColor.set(0.0000f, 0.0000f, 0.0000f);
|
||||
shininess = 0.2179f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case BRONZE:
|
||||
ambientColor.set(0.2125f, 0.1275f, 0.0540f);
|
||||
diffuseColor.set(0.7140f, 0.4284f, 0.1814f);
|
||||
specularColor.set(0.3935f, 0.2719f, 0.1667f);
|
||||
emissiveColor.set(0.0000f, 0.0000f, 0.0000f);
|
||||
shininess = 0.2000f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case COPPER:
|
||||
ambientColor.set(0.3300f, 0.2600f, 0.2300f);
|
||||
diffuseColor.set(0.5000f, 0.1100f, 0.0000f);
|
||||
specularColor.set(0.9500f, 0.7300f, 0.0000f);
|
||||
emissiveColor.set(0.0000f, 0.0000f, 0.0000f);
|
||||
shininess = 0.9300f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case GOLD:
|
||||
ambientColor.set(0.3000f, 0.2306f, 0.0953f);
|
||||
diffuseColor.set(0.4000f, 0.2760f, 0.0000f);
|
||||
specularColor.set(0.9000f, 0.8820f, 0.7020f);
|
||||
emissiveColor.set(0.0000f, 0.0000f, 0.0000f);
|
||||
shininess = 0.0625f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case PEWTER:
|
||||
ambientColor.set(0.1059f, 0.0588f, 0.1137f);
|
||||
diffuseColor.set(0.4275f, 0.4706f, 0.5412f);
|
||||
specularColor.set(0.3333f, 0.3333f, 0.5216f);
|
||||
emissiveColor.set(0.0000f, 0.0000f, 0.0000f);
|
||||
shininess = 0.0769f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case PLASTER:
|
||||
ambientColor.set(0.0500f, 0.0500f, 0.0500f);
|
||||
diffuseColor.set(0.1167f, 0.1167f, 0.1167f);
|
||||
specularColor.set(0.0305f, 0.0305f, 0.0305f);
|
||||
emissiveColor.set(0.0000f, 0.0000f, 0.0000f);
|
||||
shininess = 0.0078f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case PLASTIC:
|
||||
ambientColor.set(0.1000f, 0.1000f, 0.1000f);
|
||||
diffuseColor.set(0.0000f, 0.0000f, 0.0000f);
|
||||
specularColor.set(0.0600f, 0.0600f, 0.0600f);
|
||||
emissiveColor.set(0.0000f, 0.0000f, 0.0000f);
|
||||
shininess = 0.0078f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case SILVER:
|
||||
ambientColor.set(0.1922f, 0.1922f, 0.1922f);
|
||||
diffuseColor.set(0.5075f, 0.5075f, 0.5075f);
|
||||
specularColor.set(0.5083f, 0.5083f, 0.5083f);
|
||||
emissiveColor.set(0.0000f, 0.0000f, 0.0000f);
|
||||
shininess = 0.2000f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case STEEL:
|
||||
ambientColor.set(0.0020f, 0.0020f, 0.0020f);
|
||||
diffuseColor.set(0.0000f, 0.0000f, 0.0000f);
|
||||
specularColor.set(0.9800f, 0.9800f, 0.9800f);
|
||||
emissiveColor.set(0.0000f, 0.0000f, 0.0000f);
|
||||
shininess = 0.0600f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case STONE:
|
||||
ambientColor.set(0.1900f, 0.1520f, 0.1178f);
|
||||
diffuseColor.set(0.7500f, 0.6000f, 0.4650f);
|
||||
specularColor.set(0.0784f, 0.0800f, 0.0480f);
|
||||
emissiveColor.set(0.0000f, 0.0000f, 0.0000f);
|
||||
shininess = 0.1700f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case SHINY_PLASTIC:
|
||||
ambientColor.set(0.0880f, 0.0880f, 0.0880f);
|
||||
diffuseColor.set(0.0000f, 0.0000f, 0.0000f);
|
||||
specularColor.set(1.0000f, 1.0000f, 1.0000f);
|
||||
emissiveColor.set(0.0000f, 0.0000f, 0.0000f);
|
||||
shininess = 1.0000f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case SATIN:
|
||||
ambientColor.set(0.0660f, 0.0660f, 0.0660f);
|
||||
diffuseColor.set(0.0000f, 0.0000f, 0.0000f);
|
||||
specularColor.set(0.4400f, 0.4400f, 0.4400f);
|
||||
emissiveColor.set(0.0000f, 0.0000f, 0.0000f);
|
||||
shininess = 0.0938f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case METALIZED:
|
||||
ambientColor.set(0.1800f, 0.1800f, 0.1800f);
|
||||
diffuseColor.set(0.0000f, 0.0000f, 0.0000f);
|
||||
specularColor.set(0.4500f, 0.4500f, 0.4500f);
|
||||
emissiveColor.set(0.0000f, 0.0000f, 0.0000f);
|
||||
shininess = 0.1300f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case NEON_GNC:
|
||||
ambientColor.set(0.2000f, 0.2000f, 0.2000f);
|
||||
diffuseColor.set(0.0000f, 0.0000f, 0.0000f);
|
||||
specularColor.set(0.6200f, 0.6200f, 0.6200f);
|
||||
emissiveColor.set(1.0000f, 1.0000f, 0.0000f);
|
||||
shininess = 0.0500f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case CHROME:
|
||||
ambientColor.set(0.3500f, 0.3500f, 0.3500f);
|
||||
diffuseColor.set(0.9176f, 0.9176f, 0.9176f);
|
||||
specularColor.set(0.9746f, 0.9746f, 0.9746f);
|
||||
emissiveColor.set(0.0000f, 0.0000f, 0.0000f);
|
||||
shininess = 0.1000f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case ALUMINIUM:
|
||||
ambientColor.set(0.3000f, 0.3000f, 0.3000f);
|
||||
diffuseColor.set(0.3000f, 0.3000f, 0.3000f);
|
||||
specularColor.set(0.7000f, 0.7000f, 0.8000f);
|
||||
emissiveColor.set(0.0000f, 0.0000f, 0.0000f);
|
||||
shininess = 0.0900f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case OBSIDIAN:
|
||||
ambientColor.set(0.0538f, 0.0500f, 0.0662f);
|
||||
diffuseColor.set(0.1828f, 0.1700f, 0.2253f);
|
||||
specularColor.set(0.3327f, 0.3286f, 0.3464f);
|
||||
emissiveColor.set(0.0000f, 0.0000f, 0.0000f);
|
||||
shininess = 0.3000f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case NEON_PHC:
|
||||
ambientColor.set(1.0000f, 1.0000f, 1.0000f);
|
||||
diffuseColor.set(1.0000f, 1.0000f, 1.0000f);
|
||||
specularColor.set(0.6200f, 0.6200f, 0.6200f);
|
||||
emissiveColor.set(0.0000f, 0.9000f, 0.4140f);
|
||||
shininess = 0.0500f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case JADE:
|
||||
ambientColor.set(0.1350f, 0.2225f, 0.1575f);
|
||||
diffuseColor.set(0.5400f, 0.8900f, 0.6300f);
|
||||
specularColor.set(0.3162f, 0.3162f, 0.3162f);
|
||||
emissiveColor.set(0.0000f, 0.0000f, 0.0000f);
|
||||
shininess = 0.1000f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case RUBY:
|
||||
ambientColor.set(0.1745f, 0.0118f, 0.0118f);
|
||||
diffuseColor.set(0.6142f, 0.0414f, 0.0414f);
|
||||
specularColor.set(0.7278f, 0.6279f, 0.6267f);
|
||||
emissiveColor.set(0.0000f, 0.0000f, 0.0000f);
|
||||
shininess = 0.6000f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case EMERALD:
|
||||
ambientColor.set(0.0215f, 0.1745f, 0.0215f);
|
||||
diffuseColor.set(0.0757f, 0.6142f, 0.0757f);
|
||||
specularColor.set(0.6330f, 0.7278f, 0.6330f);
|
||||
emissiveColor.set(0.0000f, 0.0000f, 0.0000f);
|
||||
shininess = 0.6000f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
case USER_DEFINED:
|
||||
break;
|
||||
default:
|
||||
ambientColor.set(0.3333f, 0.3333f, 0.3333f);
|
||||
diffuseColor.set(0.8000f, 0.8000f, 0.9000f);
|
||||
specularColor.set(0.5333f, 0.5333f, 0.5333f);
|
||||
emissiveColor.set(0.0000f, 0.0000f, 0.0000f);
|
||||
shininess = 0.9000f;
|
||||
transparency = 0.0000f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,8 @@ namespace App
|
||||
class AppExport Material
|
||||
{
|
||||
public:
|
||||
enum MaterialType {
|
||||
enum MaterialType
|
||||
{
|
||||
BRASS,
|
||||
BRONZE,
|
||||
COPPER,
|
||||
@@ -66,11 +67,14 @@ public:
|
||||
//@{
|
||||
/** Sets the USER_DEFINED material type. The user must set the colors afterwards. */
|
||||
Material();
|
||||
/** Defines the colors and shininess for the material \a MatName. If \a MatName isn't defined then USER_DEFINED is
|
||||
* set and the user must define the colors itself.
|
||||
/** Copy constructor. */
|
||||
Material(const Material& other);
|
||||
/** Defines the colors and shininess for the material \a MatName. If \a MatName isn't defined
|
||||
* then USER_DEFINED is set and the user must define the colors itself.
|
||||
*/
|
||||
explicit Material(const char* MatName);
|
||||
/** Does basically the same as the constructor above unless that it accepts a MaterialType as argument. */
|
||||
/** Does basically the same as the constructor above unless that it accepts a MaterialType as
|
||||
* argument. */
|
||||
explicit Material(const MaterialType MatType);
|
||||
//@}
|
||||
|
||||
@@ -97,22 +101,24 @@ public:
|
||||
* \li Jade
|
||||
* \li Ruby
|
||||
* \li Emerald
|
||||
* Furthermore there two additional modes \a Default which defines a kind of grey metallic and user defined that
|
||||
* does nothing.
|
||||
* The Color and the other properties of the material are defined in the range [0-1].
|
||||
* If \a MatName is an unknown material name then the type USER_DEFINED is set and the material doesn't get changed.
|
||||
* Furthermore there two additional modes \a Default which defines a kind of grey metallic and
|
||||
* user defined that does nothing. The Color and the other properties of the material are
|
||||
* defined in the range [0-1]. If \a MatName is an unknown material name then the type
|
||||
* USER_DEFINED is set and the material doesn't get changed.
|
||||
*/
|
||||
void set(const char* MatName);
|
||||
/**
|
||||
* This method is provided for convenience which does basically the same as the method above unless that it accepts a MaterialType
|
||||
* as argument.
|
||||
* This method is provided for convenience which does basically the same as the method above
|
||||
* unless that it accepts a MaterialType as argument.
|
||||
*/
|
||||
void setType(const MaterialType MatType);
|
||||
/**
|
||||
* Returns the currently set material type.
|
||||
*/
|
||||
MaterialType getType() const
|
||||
{ return _matType; }
|
||||
{
|
||||
return _matType;
|
||||
}
|
||||
|
||||
/** @name Properties */
|
||||
//@{
|
||||
@@ -122,24 +128,26 @@ public:
|
||||
Color emissiveColor; /**< Defines the emissive color. */
|
||||
float shininess;
|
||||
float transparency;
|
||||
std::string uuid;
|
||||
//@}
|
||||
|
||||
bool operator==(const Material& m) const
|
||||
{
|
||||
return _matType==m._matType && shininess==m.shininess &&
|
||||
transparency==m.transparency && ambientColor==m.ambientColor &&
|
||||
diffuseColor==m.diffuseColor && specularColor==m.specularColor &&
|
||||
emissiveColor==m.emissiveColor;
|
||||
return _matType == m._matType && shininess == m.shininess && transparency == m.transparency
|
||||
&& ambientColor == m.ambientColor && diffuseColor == m.diffuseColor
|
||||
&& specularColor == m.specularColor && emissiveColor == m.emissiveColor
|
||||
&& uuid == m.uuid;
|
||||
}
|
||||
bool operator!=(const Material& m) const
|
||||
{
|
||||
return !operator==(m);
|
||||
}
|
||||
Material& operator=(const Material& other);
|
||||
|
||||
private:
|
||||
MaterialType _matType;
|
||||
};
|
||||
|
||||
} //namespace App
|
||||
} // namespace App
|
||||
|
||||
#endif // APP_MATERIAL_H
|
||||
#endif // APP_MATERIAL_H
|
||||
|
||||
@@ -30,25 +30,25 @@ Satin, Metalized, Neon GNC, Chrome, Aluminium, Obsidian, Neon PHC, Jade, Ruby or
|
||||
<Documentation>
|
||||
<UserDocu>Ambient color</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="AmbientColor" Type="Tuple"/>
|
||||
<Parameter Name="AmbientColor" Type="Object"/>
|
||||
</Attribute>
|
||||
<Attribute Name="DiffuseColor" ReadOnly="false">
|
||||
<Documentation>
|
||||
<UserDocu>Diffuse color</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="DiffuseColor" Type="Tuple"/>
|
||||
<Parameter Name="DiffuseColor" Type="Object"/>
|
||||
</Attribute>
|
||||
<Attribute Name="EmissiveColor" ReadOnly="false">
|
||||
<Documentation>
|
||||
<UserDocu>Emissive color</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="EmissiveColor" Type="Tuple"/>
|
||||
<Parameter Name="EmissiveColor" Type="Object"/>
|
||||
</Attribute>
|
||||
<Attribute Name="SpecularColor" ReadOnly="false">
|
||||
<Documentation>
|
||||
<UserDocu>Specular color</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="SpecularColor" Type="Tuple"/>
|
||||
<Parameter Name="SpecularColor" Type="Object"/>
|
||||
</Attribute>
|
||||
<Attribute Name="Shininess" ReadOnly="false">
|
||||
<Documentation>
|
||||
|
||||
@@ -25,12 +25,89 @@
|
||||
|
||||
// inclusion of the generated files (generated out of MaterialPy.xml)
|
||||
#include "MaterialPy.h"
|
||||
|
||||
#include "MaterialPy.cpp"
|
||||
|
||||
#include <Base/PyWrapParseTupleAndKeywords.h>
|
||||
|
||||
using namespace App;
|
||||
|
||||
PyObject *MaterialPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
|
||||
Color parseColor(PyObject* value)
|
||||
{
|
||||
Color cCol;
|
||||
if (PyTuple_Check(value) && (PyTuple_Size(value) == 3 || PyTuple_Size(value) == 4)) {
|
||||
PyObject* item;
|
||||
item = PyTuple_GetItem(value, 0);
|
||||
if (PyFloat_Check(item)) {
|
||||
cCol.r = (float)PyFloat_AsDouble(item);
|
||||
item = PyTuple_GetItem(value, 1);
|
||||
if (PyFloat_Check(item)) {
|
||||
cCol.g = (float)PyFloat_AsDouble(item);
|
||||
}
|
||||
else {
|
||||
throw Base::TypeError("Type in tuple must be consistent (float)");
|
||||
}
|
||||
item = PyTuple_GetItem(value, 2);
|
||||
if (PyFloat_Check(item)) {
|
||||
cCol.b = (float)PyFloat_AsDouble(item);
|
||||
}
|
||||
else {
|
||||
throw Base::TypeError("Type in tuple must be consistent (float)");
|
||||
}
|
||||
if (PyTuple_Size(value) == 4) {
|
||||
item = PyTuple_GetItem(value, 3);
|
||||
if (PyFloat_Check(item)) {
|
||||
cCol.a = (float)PyFloat_AsDouble(item);
|
||||
}
|
||||
else {
|
||||
throw Base::TypeError("Type in tuple must be consistent (float)");
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (PyLong_Check(item)) {
|
||||
cCol.r = PyLong_AsLong(item) / 255.0;
|
||||
item = PyTuple_GetItem(value, 1);
|
||||
if (PyLong_Check(item)) {
|
||||
cCol.g = PyLong_AsLong(item) / 255.0;
|
||||
}
|
||||
else {
|
||||
throw Base::TypeError("Type in tuple must be consistent (integer)");
|
||||
}
|
||||
item = PyTuple_GetItem(value, 2);
|
||||
if (PyLong_Check(item)) {
|
||||
cCol.b = PyLong_AsLong(item) / 255.0;
|
||||
}
|
||||
else {
|
||||
throw Base::TypeError("Type in tuple must be consistent (integer)");
|
||||
}
|
||||
if (PyTuple_Size(value) == 4) {
|
||||
item = PyTuple_GetItem(value, 3);
|
||||
if (PyLong_Check(item)) {
|
||||
cCol.a = PyLong_AsLong(item) / 255.0;
|
||||
}
|
||||
else {
|
||||
throw Base::TypeError("Type in tuple must be consistent (integer)");
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw Base::TypeError("Type in tuple must be float or integer");
|
||||
}
|
||||
}
|
||||
else if (PyLong_Check(value)) {
|
||||
cCol.setPackedValue(PyLong_AsUnsignedLong(value));
|
||||
}
|
||||
else {
|
||||
std::string error =
|
||||
std::string("type must be integer or tuple of float or tuple integer, not ");
|
||||
error += value->ob_type->tp_name;
|
||||
throw Base::TypeError(error);
|
||||
}
|
||||
|
||||
return cCol;
|
||||
}
|
||||
|
||||
PyObject* MaterialPy::PyMake(struct _typeobject*, PyObject*, PyObject*) // Python wrapper
|
||||
{
|
||||
// create a new instance of MaterialPy and the Twin object
|
||||
return new MaterialPy(new Material);
|
||||
@@ -45,28 +122,41 @@ int MaterialPy::PyInit(PyObject* args, PyObject* kwds)
|
||||
PyObject* emissive = nullptr;
|
||||
PyObject* shininess = nullptr;
|
||||
PyObject* transparency = nullptr;
|
||||
static const std::array<const char *, 7> kwds_colors{"DiffuseColor", "AmbientColor", "SpecularColor",
|
||||
"EmissiveColor", "Shininess", "Transparency", nullptr};
|
||||
static const std::array<const char*, 7> kwds_colors {"DiffuseColor",
|
||||
"AmbientColor",
|
||||
"SpecularColor",
|
||||
"EmissiveColor",
|
||||
"Shininess",
|
||||
"Transparency",
|
||||
nullptr};
|
||||
|
||||
if (!Base::Wrapped_ParseTupleAndKeywords(args, kwds, "|OOOOOO", kwds_colors,
|
||||
&diffuse, &ambient, &specular, &emissive, &shininess, &transparency)) {
|
||||
if (!Base::Wrapped_ParseTupleAndKeywords(args,
|
||||
kwds,
|
||||
"|OOOOOO",
|
||||
kwds_colors,
|
||||
&diffuse,
|
||||
&ambient,
|
||||
&specular,
|
||||
&emissive,
|
||||
&shininess,
|
||||
&transparency)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (diffuse) {
|
||||
setDiffuseColor(Py::Tuple(diffuse));
|
||||
setDiffuseColor(Py::Object(diffuse));
|
||||
}
|
||||
|
||||
if (ambient) {
|
||||
setAmbientColor(Py::Tuple(ambient));
|
||||
setAmbientColor(Py::Object(ambient));
|
||||
}
|
||||
|
||||
if (specular) {
|
||||
setSpecularColor(Py::Tuple(specular));
|
||||
setSpecularColor(Py::Object(specular));
|
||||
}
|
||||
|
||||
if (emissive) {
|
||||
setEmissiveColor(Py::Tuple(emissive));
|
||||
setEmissiveColor(Py::Object(emissive));
|
||||
}
|
||||
|
||||
if (shininess) {
|
||||
@@ -86,18 +176,19 @@ std::string MaterialPy::representation() const
|
||||
return {"<Material object>"};
|
||||
}
|
||||
|
||||
PyObject* MaterialPy::set(PyObject * args)
|
||||
PyObject* MaterialPy::set(PyObject* args)
|
||||
{
|
||||
char *pstr;
|
||||
if (!PyArg_ParseTuple(args, "s", &pstr))
|
||||
char* pstr;
|
||||
if (!PyArg_ParseTuple(args, "s", &pstr)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
getMaterialPtr()->set(pstr);
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
Py::Tuple MaterialPy::getAmbientColor() const
|
||||
Py::Object MaterialPy::getAmbientColor() const
|
||||
{
|
||||
Py::Tuple tuple(4);
|
||||
tuple.setItem(0, Py::Float(getMaterialPtr()->ambientColor.r));
|
||||
@@ -107,18 +198,12 @@ Py::Tuple MaterialPy::getAmbientColor() const
|
||||
return tuple;
|
||||
}
|
||||
|
||||
void MaterialPy::setAmbientColor(Py::Tuple arg)
|
||||
void MaterialPy::setAmbientColor(Py::Object arg)
|
||||
{
|
||||
Color c;
|
||||
c.r = Py::Float(arg.getItem(0));
|
||||
c.g = Py::Float(arg.getItem(1));
|
||||
c.b = Py::Float(arg.getItem(2));
|
||||
if (arg.size() == 4)
|
||||
c.a = Py::Float(arg.getItem(3));
|
||||
getMaterialPtr()->ambientColor = c;
|
||||
getMaterialPtr()->ambientColor = parseColor(*arg);
|
||||
}
|
||||
|
||||
Py::Tuple MaterialPy::getDiffuseColor() const
|
||||
Py::Object MaterialPy::getDiffuseColor() const
|
||||
{
|
||||
Py::Tuple tuple(4);
|
||||
tuple.setItem(0, Py::Float(getMaterialPtr()->diffuseColor.r));
|
||||
@@ -128,18 +213,12 @@ Py::Tuple MaterialPy::getDiffuseColor() const
|
||||
return tuple;
|
||||
}
|
||||
|
||||
void MaterialPy::setDiffuseColor(Py::Tuple arg)
|
||||
void MaterialPy::setDiffuseColor(Py::Object arg)
|
||||
{
|
||||
Color c;
|
||||
c.r = Py::Float(arg.getItem(0));
|
||||
c.g = Py::Float(arg.getItem(1));
|
||||
c.b = Py::Float(arg.getItem(2));
|
||||
if (arg.size() == 4)
|
||||
c.a = Py::Float(arg.getItem(3));
|
||||
getMaterialPtr()->diffuseColor = c;
|
||||
getMaterialPtr()->diffuseColor = parseColor(*arg);
|
||||
}
|
||||
|
||||
Py::Tuple MaterialPy::getEmissiveColor() const
|
||||
Py::Object MaterialPy::getEmissiveColor() const
|
||||
{
|
||||
Py::Tuple tuple(4);
|
||||
tuple.setItem(0, Py::Float(getMaterialPtr()->emissiveColor.r));
|
||||
@@ -149,18 +228,12 @@ Py::Tuple MaterialPy::getEmissiveColor() const
|
||||
return tuple;
|
||||
}
|
||||
|
||||
void MaterialPy::setEmissiveColor(Py::Tuple arg)
|
||||
void MaterialPy::setEmissiveColor(Py::Object arg)
|
||||
{
|
||||
Color c;
|
||||
c.r = Py::Float(arg.getItem(0));
|
||||
c.g = Py::Float(arg.getItem(1));
|
||||
c.b = Py::Float(arg.getItem(2));
|
||||
if (arg.size() == 4)
|
||||
c.a = Py::Float(arg.getItem(3));
|
||||
getMaterialPtr()->emissiveColor = c;
|
||||
getMaterialPtr()->emissiveColor = parseColor(*arg);
|
||||
}
|
||||
|
||||
Py::Tuple MaterialPy::getSpecularColor() const
|
||||
Py::Object MaterialPy::getSpecularColor() const
|
||||
{
|
||||
Py::Tuple tuple(4);
|
||||
tuple.setItem(0, Py::Float(getMaterialPtr()->specularColor.r));
|
||||
@@ -170,15 +243,9 @@ Py::Tuple MaterialPy::getSpecularColor() const
|
||||
return tuple;
|
||||
}
|
||||
|
||||
void MaterialPy::setSpecularColor(Py::Tuple arg)
|
||||
void MaterialPy::setSpecularColor(Py::Object arg)
|
||||
{
|
||||
Color c;
|
||||
c.r = Py::Float(arg.getItem(0));
|
||||
c.g = Py::Float(arg.getItem(1));
|
||||
c.b = Py::Float(arg.getItem(2));
|
||||
if (arg.size() == 4)
|
||||
c.a = Py::Float(arg.getItem(3));
|
||||
getMaterialPtr()->specularColor = c;
|
||||
getMaterialPtr()->specularColor = parseColor(*arg);
|
||||
}
|
||||
|
||||
Py::Float MaterialPy::getShininess() const
|
||||
@@ -201,7 +268,7 @@ void MaterialPy::setTransparency(Py::Float arg)
|
||||
getMaterialPtr()->transparency = arg;
|
||||
}
|
||||
|
||||
PyObject *MaterialPy::getCustomAttributes(const char* /*attr*/) const
|
||||
PyObject* MaterialPy::getCustomAttributes(const char* /*attr*/) const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -461,7 +461,7 @@ void PropertyEnumeration::setPyObject(PyObject *value)
|
||||
hasSetValue();
|
||||
}
|
||||
else {
|
||||
FC_THROWM(Base::ValueError, "'" << str
|
||||
FC_THROWM(Base::ValueError, "'" << str
|
||||
<< "' is not part of the enumeration in "
|
||||
<< getFullName());
|
||||
}
|
||||
@@ -585,7 +585,7 @@ bool PropertyEnumeration::getPyPathValue(const ObjectIdentifier &path, Py::Objec
|
||||
} else if (p == ".String") {
|
||||
auto v = getValueAsString();
|
||||
r = Py::String(v?v:"");
|
||||
} else
|
||||
} else
|
||||
r = Py::Int(getValue());
|
||||
return true;
|
||||
}
|
||||
@@ -2392,19 +2392,34 @@ unsigned int PropertyColorList::getMemSize () const
|
||||
// PropertyMaterial
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
TYPESYSTEM_SOURCE(App::PropertyMaterial , App::Property)
|
||||
TYPESYSTEM_SOURCE(App::PropertyMaterial, App::Property)
|
||||
|
||||
PropertyMaterial::PropertyMaterial() = default;
|
||||
|
||||
PropertyMaterial::~PropertyMaterial() = default;
|
||||
|
||||
void PropertyMaterial::setValue(const Material &mat)
|
||||
void PropertyMaterial::setValue(const Material& mat)
|
||||
{
|
||||
aboutToSetValue();
|
||||
_cMat=mat;
|
||||
_cMat = mat;
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterial::setValue(const Color& col)
|
||||
{
|
||||
setDiffuseColor(col);
|
||||
}
|
||||
|
||||
void PropertyMaterial::setValue(float r, float g, float b, float a)
|
||||
{
|
||||
setDiffuseColor(r, g, b, a);
|
||||
}
|
||||
|
||||
void PropertyMaterial::setValue(uint32_t rgba)
|
||||
{
|
||||
setDiffuseColor(rgba);
|
||||
}
|
||||
|
||||
const Material& PropertyMaterial::getValue() const
|
||||
{
|
||||
return _cMat;
|
||||
@@ -2417,6 +2432,20 @@ void PropertyMaterial::setAmbientColor(const Color& col)
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterial::setAmbientColor(float r, float g, float b, float a)
|
||||
{
|
||||
aboutToSetValue();
|
||||
_cMat.ambientColor.set(r, g, b, a);
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterial::setAmbientColor(uint32_t rgba)
|
||||
{
|
||||
aboutToSetValue();
|
||||
_cMat.ambientColor.setPackedValue(rgba);
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterial::setDiffuseColor(const Color& col)
|
||||
{
|
||||
aboutToSetValue();
|
||||
@@ -2424,6 +2453,20 @@ void PropertyMaterial::setDiffuseColor(const Color& col)
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterial::setDiffuseColor(float r, float g, float b, float a)
|
||||
{
|
||||
aboutToSetValue();
|
||||
_cMat.diffuseColor.set(r, g, b, a);
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterial::setDiffuseColor(uint32_t rgba)
|
||||
{
|
||||
aboutToSetValue();
|
||||
_cMat.diffuseColor.setPackedValue(rgba);
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterial::setSpecularColor(const Color& col)
|
||||
{
|
||||
aboutToSetValue();
|
||||
@@ -2431,6 +2474,20 @@ void PropertyMaterial::setSpecularColor(const Color& col)
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterial::setSpecularColor(float r, float g, float b, float a)
|
||||
{
|
||||
aboutToSetValue();
|
||||
_cMat.specularColor.set(r, g, b, a);
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterial::setSpecularColor(uint32_t rgba)
|
||||
{
|
||||
aboutToSetValue();
|
||||
_cMat.specularColor.setPackedValue(rgba);
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterial::setEmissiveColor(const Color& col)
|
||||
{
|
||||
aboutToSetValue();
|
||||
@@ -2438,6 +2495,20 @@ void PropertyMaterial::setEmissiveColor(const Color& col)
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterial::setEmissiveColor(float r, float g, float b, float a)
|
||||
{
|
||||
aboutToSetValue();
|
||||
_cMat.emissiveColor.set(r, g, b, a);
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterial::setEmissiveColor(uint32_t rgba)
|
||||
{
|
||||
aboutToSetValue();
|
||||
_cMat.emissiveColor.setPackedValue(rgba);
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterial::setShininess(float val)
|
||||
{
|
||||
aboutToSetValue();
|
||||
@@ -2452,36 +2523,135 @@ void PropertyMaterial::setTransparency(float val)
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
PyObject *PropertyMaterial::getPyObject()
|
||||
const Color& PropertyMaterial::getAmbientColor() const
|
||||
{
|
||||
return _cMat.ambientColor;
|
||||
}
|
||||
|
||||
const Color& PropertyMaterial::getDiffuseColor() const
|
||||
{
|
||||
return _cMat.diffuseColor;
|
||||
}
|
||||
|
||||
const Color& PropertyMaterial::getSpecularColor() const
|
||||
{
|
||||
return _cMat.specularColor;
|
||||
}
|
||||
|
||||
const Color& PropertyMaterial::getEmissiveColor() const
|
||||
{
|
||||
return _cMat.emissiveColor;
|
||||
}
|
||||
|
||||
double PropertyMaterial::getShininess() const
|
||||
{
|
||||
return _cMat.shininess;
|
||||
}
|
||||
|
||||
double PropertyMaterial::getTransparency() const
|
||||
{
|
||||
return _cMat.transparency;
|
||||
}
|
||||
|
||||
PyObject* PropertyMaterial::getPyObject()
|
||||
{
|
||||
return new MaterialPy(new Material(_cMat));
|
||||
}
|
||||
|
||||
void PropertyMaterial::setPyObject(PyObject *value)
|
||||
void PropertyMaterial::setPyObject(PyObject* value)
|
||||
{
|
||||
App::Color cCol;
|
||||
if (PyObject_TypeCheck(value, &(MaterialPy::Type))) {
|
||||
setValue(*static_cast<MaterialPy*>(value)->getMaterialPtr());
|
||||
}
|
||||
else if (PyTuple_Check(value) && (PyTuple_Size(value) == 3 || PyTuple_Size(value) == 4)) {
|
||||
PyObject* item;
|
||||
item = PyTuple_GetItem(value, 0);
|
||||
if (PyFloat_Check(item)) {
|
||||
cCol.r = (float)PyFloat_AsDouble(item);
|
||||
item = PyTuple_GetItem(value, 1);
|
||||
if (PyFloat_Check(item)) {
|
||||
cCol.g = (float)PyFloat_AsDouble(item);
|
||||
}
|
||||
else {
|
||||
throw Base::TypeError("Type in tuple must be consistent (float)");
|
||||
}
|
||||
item = PyTuple_GetItem(value, 2);
|
||||
if (PyFloat_Check(item)) {
|
||||
cCol.b = (float)PyFloat_AsDouble(item);
|
||||
}
|
||||
else {
|
||||
throw Base::TypeError("Type in tuple must be consistent (float)");
|
||||
}
|
||||
if (PyTuple_Size(value) == 4) {
|
||||
item = PyTuple_GetItem(value, 3);
|
||||
if (PyFloat_Check(item)) {
|
||||
cCol.a = (float)PyFloat_AsDouble(item);
|
||||
}
|
||||
else {
|
||||
throw Base::TypeError("Type in tuple must be consistent (float)");
|
||||
}
|
||||
}
|
||||
|
||||
setValue(cCol);
|
||||
}
|
||||
else if (PyLong_Check(item)) {
|
||||
cCol.r = PyLong_AsLong(item) / 255.0;
|
||||
item = PyTuple_GetItem(value, 1);
|
||||
if (PyLong_Check(item)) {
|
||||
cCol.g = PyLong_AsLong(item) / 255.0;
|
||||
}
|
||||
else {
|
||||
throw Base::TypeError("Type in tuple must be consistent (integer)");
|
||||
}
|
||||
item = PyTuple_GetItem(value, 2);
|
||||
if (PyLong_Check(item)) {
|
||||
cCol.b = PyLong_AsLong(item) / 255.0;
|
||||
}
|
||||
else {
|
||||
throw Base::TypeError("Type in tuple must be consistent (integer)");
|
||||
}
|
||||
if (PyTuple_Size(value) == 4) {
|
||||
item = PyTuple_GetItem(value, 3);
|
||||
if (PyLong_Check(item)) {
|
||||
cCol.a = PyLong_AsLong(item) / 255.0;
|
||||
}
|
||||
else {
|
||||
throw Base::TypeError("Type in tuple must be consistent (integer)");
|
||||
}
|
||||
}
|
||||
|
||||
setValue(cCol);
|
||||
}
|
||||
else {
|
||||
throw Base::TypeError("Type in tuple must be float or integer");
|
||||
}
|
||||
}
|
||||
else if (PyLong_Check(value)) {
|
||||
cCol.setPackedValue(PyLong_AsUnsignedLong(value));
|
||||
|
||||
setValue(cCol);
|
||||
}
|
||||
else {
|
||||
std::string error = std::string("type must be 'Material', not ");
|
||||
std::string error = std::string(
|
||||
"type must be 'Material', integer, tuple of float, or tuple of integer, not ");
|
||||
error += value->ob_type->tp_name;
|
||||
throw Base::TypeError(error);
|
||||
}
|
||||
}
|
||||
|
||||
void PropertyMaterial::Save (Base::Writer &writer) const
|
||||
void PropertyMaterial::Save(Base::Writer& writer) const
|
||||
{
|
||||
writer.Stream() << writer.ind() << "<PropertyMaterial ambientColor=\""
|
||||
<< _cMat.ambientColor.getPackedValue()
|
||||
<< "\" diffuseColor=\"" << _cMat.diffuseColor.getPackedValue()
|
||||
<< "\" specularColor=\"" << _cMat.specularColor.getPackedValue()
|
||||
<< "\" emissiveColor=\"" << _cMat.emissiveColor.getPackedValue()
|
||||
<< "\" shininess=\"" << _cMat.shininess
|
||||
<< "\" transparency=\"" << _cMat.transparency
|
||||
<< "\"/>" << endl;
|
||||
<< _cMat.ambientColor.getPackedValue() << "\" diffuseColor=\""
|
||||
<< _cMat.diffuseColor.getPackedValue() << "\" specularColor=\""
|
||||
<< _cMat.specularColor.getPackedValue() << "\" emissiveColor=\""
|
||||
<< _cMat.emissiveColor.getPackedValue() << "\" shininess=\"" << _cMat.shininess
|
||||
<< "\" transparency=\"" << _cMat.transparency << "\"/>"
|
||||
<< "\" uuid=\"" << _cMat.uuid << "\"/>" << endl;
|
||||
}
|
||||
|
||||
void PropertyMaterial::Restore(Base::XMLReader &reader)
|
||||
void PropertyMaterial::Restore(Base::XMLReader& reader)
|
||||
{
|
||||
// read my Element
|
||||
reader.readElement("PropertyMaterial");
|
||||
@@ -2493,24 +2663,28 @@ void PropertyMaterial::Restore(Base::XMLReader &reader)
|
||||
_cMat.emissiveColor.setPackedValue(reader.getAttributeAsUnsigned("emissiveColor"));
|
||||
_cMat.shininess = (float)reader.getAttributeAsFloat("shininess");
|
||||
_cMat.transparency = (float)reader.getAttributeAsFloat("transparency");
|
||||
if (reader.hasAttribute("uuid")) {
|
||||
_cMat.uuid = reader.getAttribute("uuid");
|
||||
}
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
const char* PropertyMaterial::getEditorName() const
|
||||
{
|
||||
if(testStatus(MaterialEdit))
|
||||
if (testStatus(MaterialEdit)) {
|
||||
return "Gui::PropertyEditor::PropertyMaterialItem";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
Property *PropertyMaterial::Copy() const
|
||||
Property* PropertyMaterial::Copy() const
|
||||
{
|
||||
PropertyMaterial *p= new PropertyMaterial();
|
||||
PropertyMaterial* p = new PropertyMaterial();
|
||||
p->_cMat = _cMat;
|
||||
return p;
|
||||
}
|
||||
|
||||
void PropertyMaterial::Paste(const Property &from)
|
||||
void PropertyMaterial::Paste(const Property& from)
|
||||
{
|
||||
aboutToSetValue();
|
||||
_cMat = dynamic_cast<const PropertyMaterial&>(from)._cMat;
|
||||
@@ -2533,20 +2707,474 @@ PropertyMaterialList::~PropertyMaterialList() = default;
|
||||
//**************************************************************************
|
||||
// Base class implementer
|
||||
|
||||
PyObject *PropertyMaterialList::getPyObject()
|
||||
PyObject* PropertyMaterialList::getPyObject()
|
||||
{
|
||||
Py::Tuple tuple(getSize());
|
||||
|
||||
for (int i = 0; i<getSize(); i++) {
|
||||
for (int i = 0; i < getSize(); i++) {
|
||||
tuple.setItem(i, Py::asObject(new MaterialPy(new Material(_lValueList[i]))));
|
||||
}
|
||||
|
||||
return Py::new_reference_to(tuple);
|
||||
}
|
||||
|
||||
Material PropertyMaterialList::getPyValue(PyObject *value) const {
|
||||
if (PyObject_TypeCheck(value, &(MaterialPy::Type)))
|
||||
void PropertyMaterialList::verifyIndex(int index) const
|
||||
{
|
||||
int size = getSize();
|
||||
if (index < -1 || index > size) {
|
||||
throw Base::RuntimeError("index out of bound");
|
||||
}
|
||||
}
|
||||
|
||||
void PropertyMaterialList::setSizeOne()
|
||||
{
|
||||
int size = getSize();
|
||||
if (size < 1) {
|
||||
setSize(1);
|
||||
}
|
||||
}
|
||||
|
||||
void PropertyMaterialList::setValue()
|
||||
{
|
||||
Material empty;
|
||||
setValue(empty);
|
||||
}
|
||||
|
||||
void PropertyMaterialList::setValue(const Material& mat)
|
||||
{
|
||||
aboutToSetValue();
|
||||
setSizeOne();
|
||||
for (auto& material : _lValueList) {
|
||||
material = mat;
|
||||
}
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterialList::setValue(int index, const Material& mat)
|
||||
{
|
||||
verifyIndex(index);
|
||||
|
||||
aboutToSetValue();
|
||||
int size = getSize();
|
||||
if (index == -1 || index == size) {
|
||||
index = size;
|
||||
setSize(index + 1);
|
||||
}
|
||||
_lValueList[index] = mat;
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterialList::setAmbientColor(const Color& col)
|
||||
{
|
||||
aboutToSetValue();
|
||||
setSizeOne();
|
||||
for (auto& material : _lValueList) {
|
||||
material.ambientColor = col;
|
||||
}
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterialList::setAmbientColor(float r, float g, float b, float a)
|
||||
{
|
||||
aboutToSetValue();
|
||||
setSizeOne();
|
||||
for (auto& material : _lValueList) {
|
||||
material.ambientColor.set(r, g, b, a);
|
||||
}
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterialList::setAmbientColor(uint32_t rgba)
|
||||
{
|
||||
aboutToSetValue();
|
||||
setSizeOne();
|
||||
for (auto& material : _lValueList) {
|
||||
material.ambientColor.setPackedValue(rgba);
|
||||
}
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterialList::setAmbientColor(int index, const Color& col)
|
||||
{
|
||||
verifyIndex(index);
|
||||
|
||||
aboutToSetValue();
|
||||
int size = getSize();
|
||||
if (index == -1 || index == size) {
|
||||
index = size;
|
||||
setSize(index + 1);
|
||||
}
|
||||
_lValueList[index].ambientColor = col;
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterialList::setAmbientColor(int index, float r, float g, float b, float a)
|
||||
{
|
||||
verifyIndex(index);
|
||||
|
||||
aboutToSetValue();
|
||||
int size = getSize();
|
||||
if (index == -1 || index == size) {
|
||||
index = size;
|
||||
setSize(index + 1);
|
||||
}
|
||||
_lValueList[index].ambientColor.set(r, g, b, a);
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterialList::setAmbientColor(int index, uint32_t rgba)
|
||||
{
|
||||
verifyIndex(index);
|
||||
|
||||
aboutToSetValue();
|
||||
int size = getSize();
|
||||
if (index == -1 || index == size) {
|
||||
index = size;
|
||||
setSize(index + 1);
|
||||
}
|
||||
_lValueList[index].ambientColor.setPackedValue(rgba);
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterialList::setDiffuseColor(const Color& col)
|
||||
{
|
||||
aboutToSetValue();
|
||||
setSizeOne();
|
||||
for (auto& material : _lValueList) {
|
||||
material.diffuseColor = col;
|
||||
}
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterialList::setDiffuseColor(float r, float g, float b, float a)
|
||||
{
|
||||
aboutToSetValue();
|
||||
setSizeOne();
|
||||
for (auto& material : _lValueList) {
|
||||
material.diffuseColor.set(r, g, b, a);
|
||||
}
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterialList::setDiffuseColor(uint32_t rgba)
|
||||
{
|
||||
aboutToSetValue();
|
||||
setSizeOne();
|
||||
for (auto& material : _lValueList) {
|
||||
material.diffuseColor.setPackedValue(rgba);
|
||||
}
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterialList::setDiffuseColor(int index, const Color& col)
|
||||
{
|
||||
verifyIndex(index);
|
||||
|
||||
aboutToSetValue();
|
||||
int size = getSize();
|
||||
if (index == -1 || index == size) {
|
||||
index = size;
|
||||
setSize(index + 1);
|
||||
}
|
||||
_lValueList[index].diffuseColor = col;
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterialList::setDiffuseColor(int index, float r, float g, float b, float a)
|
||||
{
|
||||
verifyIndex(index);
|
||||
|
||||
aboutToSetValue();
|
||||
int size = getSize();
|
||||
if (index == -1 || index == size) {
|
||||
index = size;
|
||||
setSize(index + 1);
|
||||
}
|
||||
_lValueList[index].diffuseColor.set(r, g, b, a);
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterialList::setDiffuseColor(int index, uint32_t rgba)
|
||||
{
|
||||
verifyIndex(index);
|
||||
|
||||
aboutToSetValue();
|
||||
int size = getSize();
|
||||
if (index == -1 || index == size) {
|
||||
index = size;
|
||||
setSize(index + 1);
|
||||
}
|
||||
_lValueList[index].diffuseColor.setPackedValue(rgba);
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterialList::setSpecularColor(const Color& col)
|
||||
{
|
||||
aboutToSetValue();
|
||||
setSizeOne();
|
||||
for (auto& material : _lValueList) {
|
||||
material.specularColor = col;
|
||||
}
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterialList::setSpecularColor(float r, float g, float b, float a)
|
||||
{
|
||||
aboutToSetValue();
|
||||
setSizeOne();
|
||||
for (auto& material : _lValueList) {
|
||||
material.specularColor.set(r, g, b, a);
|
||||
}
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterialList::setSpecularColor(uint32_t rgba)
|
||||
{
|
||||
aboutToSetValue();
|
||||
setSizeOne();
|
||||
for (auto& material : _lValueList) {
|
||||
material.specularColor.setPackedValue(rgba);
|
||||
}
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterialList::setSpecularColor(int index, const Color& col)
|
||||
{
|
||||
verifyIndex(index);
|
||||
|
||||
aboutToSetValue();
|
||||
int size = getSize();
|
||||
if (index == -1 || index == size) {
|
||||
index = size;
|
||||
setSize(index + 1);
|
||||
}
|
||||
_lValueList[index].specularColor = col;
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterialList::setSpecularColor(int index, float r, float g, float b, float a)
|
||||
{
|
||||
verifyIndex(index);
|
||||
|
||||
aboutToSetValue();
|
||||
int size = getSize();
|
||||
if (index == -1 || index == size) {
|
||||
index = size;
|
||||
setSize(index + 1);
|
||||
}
|
||||
_lValueList[index].specularColor.set(r, g, b, a);
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterialList::setSpecularColor(int index, uint32_t rgba)
|
||||
{
|
||||
verifyIndex(index);
|
||||
|
||||
aboutToSetValue();
|
||||
int size = getSize();
|
||||
if (index == -1 || index == size) {
|
||||
index = size;
|
||||
setSize(index + 1);
|
||||
}
|
||||
_lValueList[index].specularColor.setPackedValue(rgba);
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterialList::setEmissiveColor(const Color& col)
|
||||
{
|
||||
aboutToSetValue();
|
||||
setSizeOne();
|
||||
for (auto& material : _lValueList) {
|
||||
material.emissiveColor = col;
|
||||
}
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterialList::setEmissiveColor(float r, float g, float b, float a)
|
||||
{
|
||||
aboutToSetValue();
|
||||
setSizeOne();
|
||||
for (auto& material : _lValueList) {
|
||||
material.emissiveColor.set(r, g, b, a);
|
||||
}
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterialList::setEmissiveColor(uint32_t rgba)
|
||||
{
|
||||
aboutToSetValue();
|
||||
setSizeOne();
|
||||
for (auto& material : _lValueList) {
|
||||
material.emissiveColor.setPackedValue(rgba);
|
||||
}
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterialList::setEmissiveColor(int index, const Color& col)
|
||||
{
|
||||
verifyIndex(index);
|
||||
|
||||
aboutToSetValue();
|
||||
int size = getSize();
|
||||
if (index == -1 || index == size) {
|
||||
index = size;
|
||||
setSize(index + 1);
|
||||
}
|
||||
_lValueList[index].emissiveColor = col;
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterialList::setEmissiveColor(int index, float r, float g, float b, float a)
|
||||
{
|
||||
verifyIndex(index);
|
||||
|
||||
aboutToSetValue();
|
||||
int size = getSize();
|
||||
if (index == -1 || index == size) {
|
||||
index = size;
|
||||
setSize(index + 1);
|
||||
}
|
||||
_lValueList[index].emissiveColor.set(r, g, b, a);
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterialList::setEmissiveColor(int index, uint32_t rgba)
|
||||
{
|
||||
verifyIndex(index);
|
||||
|
||||
aboutToSetValue();
|
||||
int size = getSize();
|
||||
if (index == -1 || index == size) {
|
||||
index = size;
|
||||
setSize(index + 1);
|
||||
}
|
||||
_lValueList[index].emissiveColor.setPackedValue(rgba);
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterialList::setShininess(float val)
|
||||
{
|
||||
aboutToSetValue();
|
||||
setSizeOne();
|
||||
for (auto& material : _lValueList) {
|
||||
material.shininess = val;
|
||||
}
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterialList::setShininess(int index, float val)
|
||||
{
|
||||
verifyIndex(index);
|
||||
|
||||
aboutToSetValue();
|
||||
int size = getSize();
|
||||
if (index == -1 || index == size) {
|
||||
index = size;
|
||||
setSize(index + 1);
|
||||
}
|
||||
_lValueList[index].shininess = val;
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterialList::setTransparency(float val)
|
||||
{
|
||||
aboutToSetValue();
|
||||
setSizeOne();
|
||||
for (auto& material : _lValueList) {
|
||||
material.transparency = val;
|
||||
}
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterialList::setTransparency(int index, float val)
|
||||
{
|
||||
verifyIndex(index);
|
||||
|
||||
aboutToSetValue();
|
||||
int size = getSize();
|
||||
if (index == -1 || index == size) {
|
||||
index = size;
|
||||
setSize(index + 1);
|
||||
}
|
||||
_lValueList[index].transparency = val;
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
const Color& PropertyMaterialList::getAmbientColor() const
|
||||
{
|
||||
return _lValueList[0].ambientColor;
|
||||
}
|
||||
|
||||
const Color& PropertyMaterialList::getAmbientColor(int index) const
|
||||
{
|
||||
return _lValueList[index].ambientColor;
|
||||
}
|
||||
|
||||
const Color& PropertyMaterialList::getDiffuseColor() const
|
||||
{
|
||||
return _lValueList[0].diffuseColor;
|
||||
}
|
||||
|
||||
const Color& PropertyMaterialList::getDiffuseColor(int index) const
|
||||
{
|
||||
return _lValueList[index].diffuseColor;
|
||||
}
|
||||
|
||||
std::vector<App::Color> PropertyMaterialList::getDiffuseColors() const
|
||||
{
|
||||
std::vector<App::Color> list;
|
||||
for (auto& material : _lValueList) {
|
||||
list.push_back(material.diffuseColor);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
const Color& PropertyMaterialList::getSpecularColor() const
|
||||
{
|
||||
return _lValueList[0].specularColor;
|
||||
}
|
||||
|
||||
const Color& PropertyMaterialList::getSpecularColor(int index) const
|
||||
{
|
||||
return _lValueList[index].specularColor;
|
||||
}
|
||||
|
||||
const Color& PropertyMaterialList::getEmissiveColor() const
|
||||
{
|
||||
return _lValueList[0].emissiveColor;
|
||||
}
|
||||
|
||||
const Color& PropertyMaterialList::getEmissiveColor(int index) const
|
||||
{
|
||||
return _lValueList[index].emissiveColor;
|
||||
}
|
||||
|
||||
double PropertyMaterialList::getShininess() const
|
||||
{
|
||||
return _lValueList[0].transparency;
|
||||
}
|
||||
|
||||
double PropertyMaterialList::getShininess(int index) const
|
||||
{
|
||||
return _lValueList[index].transparency;
|
||||
}
|
||||
|
||||
double PropertyMaterialList::getTransparency() const
|
||||
{
|
||||
return _lValueList[0].transparency;
|
||||
}
|
||||
|
||||
double PropertyMaterialList::getTransparency(int index) const
|
||||
{
|
||||
return _lValueList[index].transparency;
|
||||
}
|
||||
|
||||
Material PropertyMaterialList::getPyValue(PyObject* value) const
|
||||
{
|
||||
if (PyObject_TypeCheck(value, &(MaterialPy::Type))) {
|
||||
return *static_cast<MaterialPy*>(value)->getMaterialPtr();
|
||||
}
|
||||
else {
|
||||
std::string error = std::string("type must be 'Material', not ");
|
||||
error += value->ob_type->tp_name;
|
||||
@@ -2554,15 +3182,16 @@ Material PropertyMaterialList::getPyValue(PyObject *value) const {
|
||||
}
|
||||
}
|
||||
|
||||
void PropertyMaterialList::Save(Base::Writer &writer) const
|
||||
void PropertyMaterialList::Save(Base::Writer& writer) const
|
||||
{
|
||||
if (!writer.isForceXML()) {
|
||||
writer.Stream() << writer.ind() << "<MaterialList file=\"" <<
|
||||
(getSize()?writer.addFile(getName(), this):"") << "\"/>" << std::endl;
|
||||
writer.Stream() << writer.ind() << "<MaterialList file=\""
|
||||
<< (getSize() ? writer.addFile(getName(), this) : "") << "\"/>"
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void PropertyMaterialList::Restore(Base::XMLReader &reader)
|
||||
void PropertyMaterialList::Restore(Base::XMLReader& reader)
|
||||
{
|
||||
reader.readElement("MaterialList");
|
||||
if (reader.hasAttribute("file")) {
|
||||
@@ -2575,30 +3204,47 @@ void PropertyMaterialList::Restore(Base::XMLReader &reader)
|
||||
}
|
||||
}
|
||||
|
||||
void PropertyMaterialList::SaveDocFile(Base::Writer &writer) const
|
||||
void PropertyMaterialList::SaveDocFile(Base::Writer& writer) const
|
||||
{
|
||||
Base::OutputStream str(writer.Stream());
|
||||
// Write the version. Versions should be negative. A non-negative value is a count
|
||||
// and should be processed as a V0
|
||||
int32_t version = -1;
|
||||
str << version;
|
||||
uint32_t uCt = (uint32_t)getSize();
|
||||
str << uCt;
|
||||
for (const auto & it : _lValueList) {
|
||||
for (const auto& it : _lValueList) {
|
||||
str << it.ambientColor.getPackedValue();
|
||||
str << it.diffuseColor.getPackedValue();
|
||||
str << it.specularColor.getPackedValue();
|
||||
str << it.emissiveColor.getPackedValue();
|
||||
str << it.shininess;
|
||||
str << it.transparency;
|
||||
// str << it.uuid.c_str();
|
||||
}
|
||||
}
|
||||
|
||||
void PropertyMaterialList::RestoreDocFile(Base::Reader &reader)
|
||||
void PropertyMaterialList::RestoreDocFile(Base::Reader& reader)
|
||||
{
|
||||
Base::InputStream str(reader);
|
||||
uint32_t uCt = 0;
|
||||
str >> uCt;
|
||||
std::vector<Material> values(uCt);
|
||||
uint32_t value; // must be 32 bit long
|
||||
int32_t version;
|
||||
str >> version;
|
||||
if (version < 0) {
|
||||
RestoreDocFileV1(reader);
|
||||
}
|
||||
else {
|
||||
uint32_t uCt = static_cast<uint32_t>(version);
|
||||
RestoreDocFileV0(uCt, reader);
|
||||
}
|
||||
}
|
||||
|
||||
void PropertyMaterialList::RestoreDocFileV0(uint32_t count, Base::Reader& reader)
|
||||
{
|
||||
Base::InputStream str(reader);
|
||||
std::vector<Material> values(count);
|
||||
uint32_t value; // must be 32 bit long
|
||||
float valueF;
|
||||
for (auto & it : values) {
|
||||
for (auto& it : values) {
|
||||
str >> value;
|
||||
it.ambientColor.setPackedValue(value);
|
||||
str >> value;
|
||||
@@ -2615,21 +3261,50 @@ void PropertyMaterialList::RestoreDocFile(Base::Reader &reader)
|
||||
setValues(values);
|
||||
}
|
||||
|
||||
void PropertyMaterialList::RestoreDocFileV1(Base::Reader& reader)
|
||||
{
|
||||
Base::InputStream str(reader);
|
||||
uint32_t count = 0;
|
||||
str >> count;
|
||||
std::vector<Material> values(count);
|
||||
uint32_t value; // must be 32 bit long
|
||||
float valueF;
|
||||
char valueS[37]; // UUID length is 36 including '-'s
|
||||
for (auto& it : values) {
|
||||
str >> value;
|
||||
it.ambientColor.setPackedValue(value);
|
||||
str >> value;
|
||||
it.diffuseColor.setPackedValue(value);
|
||||
str >> value;
|
||||
it.specularColor.setPackedValue(value);
|
||||
str >> value;
|
||||
it.emissiveColor.setPackedValue(value);
|
||||
str >> valueF;
|
||||
it.shininess = valueF;
|
||||
str >> valueF;
|
||||
it.transparency = valueF;
|
||||
// str >> valueS;
|
||||
// it.uuid = valueS;
|
||||
}
|
||||
setValues(values);
|
||||
}
|
||||
|
||||
const char* PropertyMaterialList::getEditorName() const
|
||||
{
|
||||
if(testStatus(NoMaterialListEdit))
|
||||
if (testStatus(NoMaterialListEdit)) {
|
||||
return "";
|
||||
}
|
||||
return "Gui::PropertyEditor::PropertyMaterialListItem";
|
||||
}
|
||||
|
||||
Property *PropertyMaterialList::Copy() const
|
||||
Property* PropertyMaterialList::Copy() const
|
||||
{
|
||||
PropertyMaterialList *p = new PropertyMaterialList();
|
||||
PropertyMaterialList* p = new PropertyMaterialList();
|
||||
p->_lValueList = _lValueList;
|
||||
return p;
|
||||
}
|
||||
|
||||
void PropertyMaterialList::Paste(const Property &from)
|
||||
void PropertyMaterialList::Paste(const Property& from)
|
||||
{
|
||||
setValues(dynamic_cast<const PropertyMaterialList&>(from)._lValueList);
|
||||
}
|
||||
|
||||
@@ -467,7 +467,7 @@ public:
|
||||
void Paste(const Property &from) override;
|
||||
|
||||
unsigned int getMemSize () const override;
|
||||
|
||||
|
||||
bool isSame(const Property &other) const override {
|
||||
if (&other == this)
|
||||
return true;
|
||||
@@ -954,7 +954,7 @@ public:
|
||||
void Paste(const Property &from) override;
|
||||
|
||||
unsigned int getMemSize () const override{return sizeof(Color);}
|
||||
|
||||
|
||||
bool isSame(const Property &other) const override {
|
||||
if (&other == this)
|
||||
return true;
|
||||
@@ -1000,15 +1000,15 @@ protected:
|
||||
Color getPyValue(PyObject *) const override;
|
||||
};
|
||||
|
||||
|
||||
/** Material properties
|
||||
* This is the father of all properties handling colors.
|
||||
*/
|
||||
class AppExport PropertyMaterial : public Property
|
||||
class AppExport PropertyMaterial: public Property
|
||||
{
|
||||
TYPESYSTEM_HEADER_WITH_OVERRIDE();
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* A constructor.
|
||||
* A more elaborate description of the constructor.
|
||||
@@ -1023,34 +1023,56 @@ public:
|
||||
|
||||
/** Sets the property
|
||||
*/
|
||||
void setValue(const Material &mat);
|
||||
void setValue(const Material& mat);
|
||||
void setValue(const Color& col);
|
||||
void setValue(float r, float g, float b, float a = 0.0f);
|
||||
void setValue(uint32_t rgba);
|
||||
void setAmbientColor(const Color& col);
|
||||
void setAmbientColor(float r, float g, float b, float a = 0.0f);
|
||||
void setAmbientColor(uint32_t rgba);
|
||||
void setDiffuseColor(const Color& col);
|
||||
void setDiffuseColor(float r, float g, float b, float a = 0.0f);
|
||||
void setDiffuseColor(uint32_t rgba);
|
||||
void setSpecularColor(const Color& col);
|
||||
void setSpecularColor(float r, float g, float b, float a = 0.0f);
|
||||
void setSpecularColor(uint32_t rgba);
|
||||
void setEmissiveColor(const Color& col);
|
||||
void setEmissiveColor(float r, float g, float b, float a = 0.0f);
|
||||
void setEmissiveColor(uint32_t rgba);
|
||||
void setShininess(float);
|
||||
void setTransparency(float);
|
||||
|
||||
/** This method returns a string representation of the property
|
||||
*/
|
||||
const Material &getValue() const;
|
||||
const Material& getValue() const;
|
||||
const Color& getAmbientColor() const;
|
||||
const Color& getDiffuseColor() const;
|
||||
const Color& getSpecularColor() const;
|
||||
const Color& getEmissiveColor() const;
|
||||
double getShininess() const;
|
||||
double getTransparency() const;
|
||||
|
||||
PyObject *getPyObject() override;
|
||||
void setPyObject(PyObject *) override;
|
||||
PyObject* getPyObject() override;
|
||||
void setPyObject(PyObject*) override;
|
||||
|
||||
void Save (Base::Writer &writer) const override;
|
||||
void Restore(Base::XMLReader &reader) override;
|
||||
void Save(Base::Writer& writer) const override;
|
||||
void Restore(Base::XMLReader& reader) override;
|
||||
|
||||
const char* getEditorName() const override;
|
||||
|
||||
Property *Copy() const override;
|
||||
void Paste(const Property &from) override;
|
||||
Property* Copy() const override;
|
||||
void Paste(const Property& from) override;
|
||||
|
||||
unsigned int getMemSize () const override{return sizeof(_cMat);}
|
||||
|
||||
bool isSame(const Property &other) const override {
|
||||
if (&other == this)
|
||||
unsigned int getMemSize() const override
|
||||
{
|
||||
return sizeof(_cMat);
|
||||
}
|
||||
|
||||
bool isSame(const Property& other) const override
|
||||
{
|
||||
if (&other == this) {
|
||||
return true;
|
||||
}
|
||||
return getTypeId() == other.getTypeId()
|
||||
&& getValue() == static_cast<decltype(this)>(&other)->getValue();
|
||||
}
|
||||
@@ -1060,41 +1082,106 @@ private:
|
||||
};
|
||||
|
||||
/** Material properties
|
||||
*/
|
||||
class AppExport PropertyMaterialList : public PropertyListsT<Material>
|
||||
*/
|
||||
class AppExport PropertyMaterialList: public PropertyListsT<Material>
|
||||
{
|
||||
TYPESYSTEM_HEADER_WITH_OVERRIDE();
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* A constructor.
|
||||
* A more elaborate description of the constructor.
|
||||
*/
|
||||
* A constructor.
|
||||
* A more elaborate description of the constructor.
|
||||
*/
|
||||
PropertyMaterialList();
|
||||
|
||||
/**
|
||||
* A destructor.
|
||||
* A more elaborate description of the destructor.
|
||||
*/
|
||||
* A destructor.
|
||||
* A more elaborate description of the destructor.
|
||||
*/
|
||||
~PropertyMaterialList() override;
|
||||
|
||||
PyObject *getPyObject() override;
|
||||
void setValue();
|
||||
void setValue(const std::vector<App::Material>& materials)
|
||||
{
|
||||
PropertyListsT<Material>::setValue(materials);
|
||||
}
|
||||
void setValue(const Material& mat);
|
||||
void setValue(int index, const Material& mat);
|
||||
|
||||
void Save(Base::Writer &writer) const override;
|
||||
void Restore(Base::XMLReader &reader) override;
|
||||
void setAmbientColor(const Color& col);
|
||||
void setAmbientColor(float r, float g, float b, float a = 0.0f);
|
||||
void setAmbientColor(uint32_t rgba);
|
||||
void setAmbientColor(int index, const Color& col);
|
||||
void setAmbientColor(int index, float r, float g, float b, float a = 0.0f);
|
||||
void setAmbientColor(int index, uint32_t rgba);
|
||||
|
||||
void SaveDocFile(Base::Writer &writer) const override;
|
||||
void RestoreDocFile(Base::Reader &reader) override;
|
||||
void setDiffuseColor(const Color& col);
|
||||
void setDiffuseColor(float r, float g, float b, float a = 0.0f);
|
||||
void setDiffuseColor(uint32_t rgba);
|
||||
void setDiffuseColor(int index, const Color& col);
|
||||
void setDiffuseColor(int index, float r, float g, float b, float a = 0.0f);
|
||||
void setDiffuseColor(int index, uint32_t rgba);
|
||||
|
||||
void setSpecularColor(const Color& col);
|
||||
void setSpecularColor(float r, float g, float b, float a = 0.0f);
|
||||
void setSpecularColor(uint32_t rgba);
|
||||
void setSpecularColor(int index, const Color& col);
|
||||
void setSpecularColor(int index, float r, float g, float b, float a = 0.0f);
|
||||
void setSpecularColor(int index, uint32_t rgba);
|
||||
|
||||
void setEmissiveColor(const Color& col);
|
||||
void setEmissiveColor(float r, float g, float b, float a = 0.0f);
|
||||
void setEmissiveColor(uint32_t rgba);
|
||||
void setEmissiveColor(int index, const Color& col);
|
||||
void setEmissiveColor(int index, float r, float g, float b, float a = 0.0f);
|
||||
void setEmissiveColor(int index, uint32_t rgba);
|
||||
|
||||
void setShininess(float);
|
||||
void setShininess(int index, float);
|
||||
|
||||
void setTransparency(float);
|
||||
void setTransparency(int index, float);
|
||||
|
||||
const Color& getAmbientColor() const;
|
||||
const Color& getAmbientColor(int index) const;
|
||||
|
||||
const Color& getDiffuseColor() const;
|
||||
const Color& getDiffuseColor(int index) const;
|
||||
std::vector<App::Color> getDiffuseColors() const;
|
||||
|
||||
const Color& getSpecularColor() const;
|
||||
const Color& getSpecularColor(int index) const;
|
||||
|
||||
const Color& getEmissiveColor() const;
|
||||
const Color& getEmissiveColor(int index) const;
|
||||
|
||||
double getShininess() const;
|
||||
double getShininess(int index) const;
|
||||
|
||||
double getTransparency() const;
|
||||
double getTransparency(int index) const;
|
||||
|
||||
PyObject* getPyObject() override;
|
||||
|
||||
void Save(Base::Writer& writer) const override;
|
||||
void Restore(Base::XMLReader& reader) override;
|
||||
|
||||
void SaveDocFile(Base::Writer& writer) const override;
|
||||
void RestoreDocFile(Base::Reader& reader) override;
|
||||
|
||||
const char* getEditorName() const override;
|
||||
|
||||
Property *Copy() const override;
|
||||
void Paste(const Property &from) override;
|
||||
Property* Copy() const override;
|
||||
void Paste(const Property& from) override;
|
||||
unsigned int getMemSize() const override;
|
||||
|
||||
protected:
|
||||
Material getPyValue(PyObject *) const override;
|
||||
Material getPyValue(PyObject*) const override;
|
||||
void verifyIndex(int index) const;
|
||||
void setSizeOne();
|
||||
|
||||
void RestoreDocFileV0(uint32_t count, Base::Reader& reader);
|
||||
void RestoreDocFileV1(Base::Reader& reader);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user