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:
David Carter
2024-03-17 18:37:56 -04:00
committed by Chris Hennes
parent 37c38acd19
commit ba20441935
121 changed files with 4682 additions and 1685 deletions

View File

@@ -0,0 +1,94 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/***************************************************************************
* Copyright (c) 2024 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of FreeCAD. *
* *
* FreeCAD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 2.1 of the *
* License, or (at your option) any later version. *
* *
* FreeCAD is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with FreeCAD. If not, see *
* <https://www.gnu.org/licenses/>. *
* *
**************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#include <sstream>
#endif
#include <App/GeoFeature.h>
#include <App/PropertyStandard.h>
#include "ViewProviderGeometryObjectPy.h"
#include "ViewProviderGeometryObjectPy.cpp"
using namespace Gui;
// returns a string which represents the object e.g. when printed in python
std::string ViewProviderGeometryObjectPy::representation() const
{
std::stringstream str;
str << "<View provider geometry object at " << getViewProviderGeometryObjectPtr() << ">";
return str.str();
}
PyObject* ViewProviderGeometryObjectPy::getCustomAttributes(const char* attr) const
{
ViewProviderGeometryObject* vp = getViewProviderGeometryObjectPtr();
if (strcmp(attr, "ShapeColor") == 0) {
// Get material property of ViewProviderGeometryObject
App::PropertyColor prop;
prop.setValue(vp->ShapeAppearance.getDiffuseColor());
return prop.getPyObject();
}
if (strcmp(attr, "ShapeMaterial") == 0) {
// Get material property of ViewProviderGeometryObject
auto geometry = dynamic_cast<App::GeoFeature*>(vp->getObject());
if (geometry) {
auto material = geometry->getMaterialAppearance();
App::PropertyMaterial prop;
prop.setValue(material);
return prop.getPyObject();
}
}
return nullptr;
}
int ViewProviderGeometryObjectPy::setCustomAttributes(const char* attr, PyObject* obj)
{
ViewProviderGeometryObject* vp = getViewProviderGeometryObjectPtr();
if (strcmp(attr, "ShapeColor") == 0) {
// Get material property of ViewProviderGeometryObject
App::PropertyColor prop;
prop.setPyObject(obj);
vp->ShapeAppearance.setDiffuseColor(prop.getValue());
// Assign the value to the new property type
// ...
return 1;
}
if (strcmp(attr, "ShapeMaterial") == 0) {
// Get material property of ViewProviderGeometryObject
auto geometry = dynamic_cast<App::GeoFeature*>(vp->getObject());
if (geometry) {
App::PropertyMaterial prop;
prop.setPyObject(obj);
geometry->setMaterialAppearance(prop.getValue());
}
return 1;
}
return 0;
}