Archived issue #0023387
Visualization - transparency of specified material is ignored within AIS_Shape::SetMaterial()
Description
When using AIS_Shape::SetMaterial the transparency is not updated with the transparency of the material and finally the tranparency is not updated.
The corrected code is below : AIS_Shape.cxx line 724
//=======================================================================
//function : SetMaterial
//purpose :
//=======================================================================
void AIS_Shape::SetMaterial(const Graphic3d_MaterialAspect& aMat)
{
if( !HasColor() && !IsTransparent() && !HasMaterial() ) {
myDrawer->SetShadingAspect(new Prs3d_ShadingAspect());
}
hasOwnMaterial = Standard_True;
myDrawer->ShadingAspect()->SetMaterial(aMat,myCurrentFacingModel);
/// OLD CODE : myDrawer->ShadingAspect()->SetTransparency(myTransparency,myCurrentFacingModel);
myDrawer->ShadingAspect()->SetTransparency(aMat.Transparency(),myCurrentFacingModel);
if(!GetContext().IsNull()){
if(GetContext()->MainPrsMgr()->HasPresentation(this,1)){
Handle(Prs3d_Presentation) aPresentation =
GetContext()->MainPrsMgr()->CastPresentation(this,1)->Presentation();
Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(aPresentation);
Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
aPresentation->SetPrimitivesAspect(anAreaAsp);
// Check if aspect of given type is set for the group,
// because setting aspect for group with no already set aspect
// can lead to loss of presentation data
if (aGroup->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_FILL_AREA))
aGroup->SetGroupPrimitivesAspect(anAreaAsp);
}
myRecomputeEveryPrs =Standard_False; // no mode to recalculate :only viewer update
myToRecomputeModes.Clear();
}
}
The corrected code is below : AIS_Shape.cxx line 724
//=======================================================================
//function : SetMaterial
//purpose :
//=======================================================================
void AIS_Shape::SetMaterial(const Graphic3d_MaterialAspect& aMat)
{
if( !HasColor() && !IsTransparent() && !HasMaterial() ) {
myDrawer->SetShadingAspect(new Prs3d_ShadingAspect());
}
hasOwnMaterial = Standard_True;
myDrawer->ShadingAspect()->SetMaterial(aMat,myCurrentFacingModel);
/// OLD CODE : myDrawer->ShadingAspect()->SetTransparency(myTransparency,myCurrentFacingModel);
myDrawer->ShadingAspect()->SetTransparency(aMat.Transparency(),myCurrentFacingModel);
if(!GetContext().IsNull()){
if(GetContext()->MainPrsMgr()->HasPresentation(this,1)){
Handle(Prs3d_Presentation) aPresentation =
GetContext()->MainPrsMgr()->CastPresentation(this,1)->Presentation();
Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(aPresentation);
Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
aPresentation->SetPrimitivesAspect(anAreaAsp);
// Check if aspect of given type is set for the group,
// because setting aspect for group with no already set aspect
// can lead to loss of presentation data
if (aGroup->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_FILL_AREA))
aGroup->SetGroupPrimitivesAspect(anAreaAsp);
}
myRecomputeEveryPrs =Standard_False; // no mode to recalculate :only viewer update
myToRecomputeModes.Clear();
}
}
Steps to reproduce
Handle(AIS_InteractiveContext) ais = ...
BRepPrimAPI_MakeBox MB( 100.0, 100.0, 100.0 );
TopoDS_Shape s = MB.Solid();
Handle( AIS_Shape ) aShape = new AIS_Shape( s );
Graphic3d_MaterialAspect aMat( Graphic3d_NameOfMaterial::Graphic3d_NOM_BRASS );
aMat.SetTransparency( 0.75 );
aShape->SetMaterial( aMat );
ais->Display( aShape, Standard_True );
BRepPrimAPI_MakeBox MB( 100.0, 100.0, 100.0 );
TopoDS_Shape s = MB.Solid();
Handle( AIS_Shape ) aShape = new AIS_Shape( s );
Graphic3d_MaterialAspect aMat( Graphic3d_NameOfMaterial::Graphic3d_NOM_BRASS );
aMat.SetTransparency( 0.75 );
aShape->SetMaterial( aMat );
ais->Display( aShape, Standard_True );
pload MODELING VISUALIZATION box b 1 2 3 vinit View1 vclear vsetdispmode 1 vdisplay b vfit vsetmaterial b water
Public activity
4 archived notes
Participants are labeled by their role within this record.
Existing behavior might looks unnatural to some degree.
However proposed solution contradicts to current design of Interactive Object and might break existing code.
Thus it doesn't make sense until AIS re-design.
However proposed solution contradicts to current design of Interactive Object and might break existing code.
Thus it doesn't make sense until AIS re-design.
This issue becomes more critical after implementation of transparent materials and refraction support - see #0024864.
The behavior of AIS_Shape::SetMaterial() has been improved within #0025459 - now
transparency of specified material is overridden only when AIS_Shape::SetTransparency() called before or afterwards (should be discarded by AIS_Shape::UnsetTransparency()).
So the main issue described in the bug should be solved now.
However the consistency of all there flags and methods to be further checked.
transparency of specified material is overridden only when AIS_Shape::SetTransparency() called before or afterwards (should be discarded by AIS_Shape::UnsetTransparency()).
So the main issue described in the bug should be solved now.
However the consistency of all there flags and methods to be further checked.
Related records
- #0024864 · related to · closedVisualization - Implementing refractions in ray-tracing
- #0025511 · related to · closedVisualization - drop redundant viewer option V3d_View::Transparency()
- #0023474 · related to · closedChanging material/color/transparency of a shaded AIS_Shape requires 'Redisplay'
- #0024855 · related to · closedRevision of parameters of standard materials
- #0025459 · related to · closedVisualization - AIS_ColoredShape::SetMaterial() should not reset custom colors