Graphic3d_MATERIAL_ASPECT

Hi Guys !
I want to learn how I can convert Graphic3d_MATERIAL_ASPECT to the Graphic3d_MATERIAL_PHYSIC If I have the color of the Shape.
Now I'm using this code, but It's work very discrepancy:

void materials::CreateMyMaterial(int myIndex,int R1,int G1,int B1,
Handle_TPrsStd_AISPresentation &myPrs)
{
Graphic3d_NameOfMaterial current = GetNameFromIndex(myIndex);

Graphic3d_MaterialAspect myAspect(current);

if (myAspect.MaterialType(Graphic3d_MATERIAL_PHYSIC))
{ myPrs->SetMaterial(current); return; }

Graphic3d_MaterialAspect userAspect(Graphic3d_NOM_UserDefined);

userAspect = myAspect;
Quantity_Color colorForMaterial( R1 / 255., G1 / 255.,
B1 / 255., Quantity_TOC_RGB );

double myDiffuse = myAspect.Diffuse() + 0.4;
if (myDiffuse>1) myDiffuse = 1;

userAspect.SetMaterialType(Graphic3d_MATERIAL_PHYSIC);

if (current==Graphic3d_NOM_PLASTIC)
{
userAspect.SetDiffuseColor(colorForMaterial);
userAspect.SetDiffuse(myDiffuse);
}

if (current==Graphic3d_NOM_PLASTER)
{
userAspect.SetDiffuseColor(colorForMaterial);
userAspect.SetDiffuse(myDiffuse);
}

if (current==Graphic3d_NOM_SHINY_PLASTIC)
{
userAspect.SetDiffuseColor(colorForMaterial);
userAspect.SetDiffuse(myDiffuse);
}

if (current==Graphic3d_NOM_SATIN)
{
userAspect.SetDiffuseColor(colorForMaterial);
userAspect.SetDiffuse(myDiffuse);
}

if (current==Graphic3d_NOM_METALIZED)
{
userAspect.SetDiffuseColor(colorForMaterial);
userAspect.SetDiffuse(myDiffuse);
}

if (current==Graphic3d_NOM_NEON_GNC)
{
userAspect.SetDiffuseColor(colorForMaterial);
userAspect.SetEmissiveColor(colorForMaterial);
userAspect.SetDiffuse(myDiffuse);
}

myPrs->SetMaterial(Graphic3d_NOM_UserDefined);
myPrs->GetAIS()->Attributes()->ShadingAspect()->SetMaterial(userAspect);
myPrs->Update();

}

Thanks for your answer !

JuryS's picture

ANYBODY on this forum ? I make the QT widget that can create any materials by ptotorype of Graphic3d_Names....

Also I think that :
double myDiffuse = myAspect.Diffuse() + 0.27; //It's more reality
if (myDiffuse>1) myDiffuse = 1;

Attachments: