
Sun, 02/16/2025 - 20:03
Helllo forum
I have a Qt 3D viewer, based on the Open Cascade Kernel: see Picture 1.
I highlighted three lighting properties: ambient, diffuse, specular, that are
passed as float values [0,1] to the opencascade widget, set as qt central widget
of the QMainWindow
In using OCC7.3.0 I use this code, which iterates over all the AIS shapes loaded into
the context, changing the three coefficients for each shape, one by one.
This did what I expected correctly (
AIS_ListOfInteractive l;
occContext->ObjectsInside(l,AIS_KOI_Shape,CUSTOM_SIGNATURE_EXTENDED_SHAPE);
for(AIS_ListIteratorOfListOfInteractive it(l); it.More(); it.Next())
{
Graphic3d_NameOfMaterial materialName = it.Value()->Material();
Graphic3d_MaterialAspect materialAspect(materialName);
materialAspect.SetAmbient(ambient);
materialAspect.SetDiffuse(diffuse);
materialAspect.SetSpecular(specular);
es->SetMaterial(materialAspect);
}
occContext->UpdateCurrentViewer();
}
Now I've updated the code to 7.6.0, in which Graphic3d_MaterialAspect::setAmbient(float),
Graphic3d_MaterialAspect::setDiffuse(float), Graphic3d_MaterialAspect::setSpecular(float)
have been removed.
Question: how to translate the working code used in 7.3.0, into a workinig code for 7.6.0?
Further details:
Documentation says (from 7.4.0)
"Replace Graphic3d_MaterialAspect::Ambient(), SetAmbient(), Diffuse(), SetDiffuse(),
Specular(), SetSpecular(), Emissive(), SetEmissive()
with methods working with pre-multiplied color.
E.g. theMaterial.SetAmbientColor(Graphic3d_Vec3 (1.0f, 0.0f, 0.0f) * 0.2f)"
but from the header file of Graphic3d_MaterialAspect I read
//! Modifies the ambient color of the surface.
Standard_EXPORT void SetAmbientColor (const Quantity_Color& theColor);
that is Quantity_Color must be used as function argument.
So I tried, for 7.6.0, and for each shape loaded into the context:
const occHandle(AIS_ExtendedShape)& es = occHandle(AIS_ExtendedShape)::DownCast(it.Value());
Quantity_Color shapeColor;
es->Color(shapeColor);
float r = shapeColor.Red();
float g = shapeColor.Green();
float b = shapeColor.Blue();
Quantity_Color ac(ambient*r,ambient*g,ambient*b,Quantity_TOC_RGB);
Quantity_Color dc(diffuse*r,diffuse*g,diffuse*b,Quantity_TOC_RGB);
Quantity_Color sc(specular*r,specular*g,specular*b,Quantity_TOC_RGB);
materialAspect.SetAmbientColor(ac);
materialAspect.SetDiffuseColor(dc);
materialAspect.SetSpecularColor(sc);
which compiles, but does not the work of changing the specular, reflection, and diffuse
properties of the scene.
Grazie mille
Giovanni
Mon, 02/17/2025 - 08:58
Legacy properties
Graphic3d_MaterialAspect::Ambient()
/Diffuse()
/Specular
haven't been applied to a color - they were coefficients toGraphic3d_MaterialAspect::AmbientColor()
/DiffuseColor()
/SpecularColor()
. So you need to weed out the actual material properties (which depend on original material definition) to preserve behavior. Legacy math:new math:
In general, I would suggest to avoid trying to preserve exact math from legacy code, but rather trying to preserve the intent and simplify math where possible.
Mon, 02/17/2025 - 12:59
Thanks you very much.
It helped
Giovanni