DiscussionsIssue archiveOCCT:Visualization

Archived issue #0023387

Visualization - transparency of specified material is ignored within AIS_Shape::SetMaterial()

CommunityOCCT:Visualizationclosed4 public notes

Search issues

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();
  }
}

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 );

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.

01Commenter 3
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.
02Commenter 2
This issue becomes more critical after implementation of transparent materials and refraction support - see #0024864.

03Commenter 3
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.

04Commenter 3
Dear Commenter 1,

please close the bug as fixed within #0025459.

Related records