Skip to content

Commit

Permalink
Merge pull request #13332 from wwmayer/fix_material_issues
Browse files Browse the repository at this point in the history
Fix material issues
  • Loading branch information
chennes committed Apr 15, 2024
2 parents cd1f624 + 74f614a commit 87839c9
Show file tree
Hide file tree
Showing 25 changed files with 471 additions and 510 deletions.
309 changes: 142 additions & 167 deletions src/App/Material.cpp

Large diffs are not rendered by default.

25 changes: 18 additions & 7 deletions src/App/Material.h
Expand Up @@ -67,15 +67,17 @@ class AppExport Material
//@{
/** Sets the USER_DEFINED material type. The user must set the colors afterwards. */
Material();
~Material() = default;
/** Copy constructor. */
Material(const Material& other);
Material(const Material& other) = default;
Material(Material&& other) = default;
/** 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. */
explicit Material(const MaterialType MatType);
explicit Material(MaterialType MatType);
//@}

/** Set a material by name
Expand Down Expand Up @@ -111,7 +113,7 @@ class AppExport Material
* 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);
void setType(MaterialType MatType);
/**
* Returns the currently set material type.
*/
Expand All @@ -122,27 +124,36 @@ class AppExport Material

/** @name Properties */
//@{
// NOLINTBEGIN
Color ambientColor; /**< Defines the ambient color. */
Color diffuseColor; /**< Defines the diffuse color. */
Color specularColor; /**< Defines the specular color. */
Color emissiveColor; /**< Defines the emissive color. */
float shininess;
float transparency;
std::string uuid;
// NOLINTEND
//@}

bool operator==(const Material& m) const

Check warning on line 138 in src/App/Material.h

View workflow job for this annotation

GitHub Actions / Lint / Lint

parameter name 'm' is too short, expected at least 2 characters [readability-identifier-length]
{
return _matType == m._matType && shininess == m.shininess && transparency == m.transparency
&& ambientColor == m.ambientColor && diffuseColor == m.diffuseColor
&& specularColor == m.specularColor && emissiveColor == m.emissiveColor
// clang-format off
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;
// clang-format on
}
bool operator!=(const Material& m) const

Check warning on line 151 in src/App/Material.h

View workflow job for this annotation

GitHub Actions / Lint / Lint

parameter name 'm' is too short, expected at least 2 characters [readability-identifier-length]
{
return !operator==(m);
}
Material& operator=(const Material& other);
Material& operator=(const Material& other) = default;
Material& operator=(Material&& other) = default;

private:
MaterialType _matType;
Expand Down
3 changes: 3 additions & 0 deletions src/App/MaterialPy.xml
Expand Up @@ -63,5 +63,8 @@ Satin, Metalized, Neon GNC, Chrome, Aluminium, Obsidian, Neon PHC, Jade, Ruby or
<Parameter Name="Transparency" Type="Float"/>
</Attribute>
<CustomAttributes />
<ClassDeclarations>public:
static App::Color toColor(PyObject* value);
</ClassDeclarations>
</PythonExport>
</GenerateModel>
22 changes: 11 additions & 11 deletions src/App/MaterialPyImp.cpp
Expand Up @@ -32,11 +32,11 @@

using namespace App;

Color parseColor(PyObject* value)
Color MaterialPy::toColor(PyObject* value)

Check warning on line 35 in src/App/MaterialPyImp.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

function 'toColor' has cognitive complexity of 41 (threshold 25) [readability-function-cognitive-complexity]
{
Color cCol;
if (PyTuple_Check(value) && (PyTuple_Size(value) == 3 || PyTuple_Size(value) == 4)) {
PyObject* item;
PyObject* item {};
item = PyTuple_GetItem(value, 0);
if (PyFloat_Check(item)) {
cCol.r = (float)PyFloat_AsDouble(item);
Expand Down Expand Up @@ -65,25 +65,25 @@ Color parseColor(PyObject* value)
}
}
else if (PyLong_Check(item)) {
cCol.r = PyLong_AsLong(item) / 255.0;
cCol.r = static_cast<float>(PyLong_AsLong(item)) / 255.0F;
item = PyTuple_GetItem(value, 1);
if (PyLong_Check(item)) {
cCol.g = PyLong_AsLong(item) / 255.0;
cCol.g = static_cast<float>(PyLong_AsLong(item)) / 255.0F;
}
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;
cCol.b = static_cast<float>(PyLong_AsLong(item)) / 255.0F;
}
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;
cCol.a = static_cast<float>(PyLong_AsLong(item)) / 255.0F;
}
else {
throw Base::TypeError("Type in tuple must be consistent (integer)");
Expand Down Expand Up @@ -178,7 +178,7 @@ std::string MaterialPy::representation() const

PyObject* MaterialPy::set(PyObject* args)
{
char* pstr;
char* pstr {};
if (!PyArg_ParseTuple(args, "s", &pstr)) {
return nullptr;
}
Expand All @@ -200,7 +200,7 @@ Py::Object MaterialPy::getAmbientColor() const

void MaterialPy::setAmbientColor(Py::Object arg)
{
getMaterialPtr()->ambientColor = parseColor(*arg);
getMaterialPtr()->ambientColor = toColor(*arg);
}

Py::Object MaterialPy::getDiffuseColor() const
Expand All @@ -215,7 +215,7 @@ Py::Object MaterialPy::getDiffuseColor() const

void MaterialPy::setDiffuseColor(Py::Object arg)
{
getMaterialPtr()->diffuseColor = parseColor(*arg);
getMaterialPtr()->diffuseColor = toColor(*arg);
}

Py::Object MaterialPy::getEmissiveColor() const
Expand All @@ -230,7 +230,7 @@ Py::Object MaterialPy::getEmissiveColor() const

void MaterialPy::setEmissiveColor(Py::Object arg)
{
getMaterialPtr()->emissiveColor = parseColor(*arg);
getMaterialPtr()->emissiveColor = toColor(*arg);
}

Py::Object MaterialPy::getSpecularColor() const
Expand All @@ -245,7 +245,7 @@ Py::Object MaterialPy::getSpecularColor() const

void MaterialPy::setSpecularColor(Py::Object arg)
{
getMaterialPtr()->specularColor = parseColor(*arg);
getMaterialPtr()->specularColor = toColor(*arg);
}

Py::Float MaterialPy::getShininess() const
Expand Down

0 comments on commit 87839c9

Please sign in to comment.