For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings

 

Need to speed up your development?
Have a look at our:

Samples & Tools

 

Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

Box's faces with different materials

Csaba Hajdu's picture
Forums: 

I tried to change the color and material of some faces of a box. The code what I made can be seen below. But the result is not the expected one. The different colors and materials are ignored by the viewer. What is the problem?

GetDocument()->myAISContext->EraseAll(Standard_False);

TopoDS_Shape B1 = BRepPrimAPI_MakeBox( DV_BOX_X, DV_BOX_Y, DV_BOX_Z );

TDF_Label label = GetDocument()->GetOCAFDoc()->Main();

TNaming_Builder B( label );

B.Generated( B1 );

TDF_Label aLabels[ 4 ];

aLabels[ 0 ] = label.FindChild( 1, Standard_True );
aLabels[ 1 ] = label.FindChild( 2, Standard_True );
aLabels[ 2 ] = label.FindChild( 3, Standard_True );
aLabels[ 3 ] = label.FindChild( 4, Standard_True );

Handle( TPrsStd_AISPresentation ) prs1 = TPrsStd_AISPresentation::Set( aLabels[ 0 ], TNaming_NamedShape::GetID() );
Handle( TPrsStd_AISPresentation ) prs2 = TPrsStd_AISPresentation::Set( aLabels[ 1 ], TNaming_NamedShape::GetID() );
Handle( TPrsStd_AISPresentation ) prs3 = TPrsStd_AISPresentation::Set( aLabels[ 2 ], TNaming_NamedShape::GetID() );
Handle( TPrsStd_AISPresentation ) prs4 = TPrsStd_AISPresentation::Set( aLabels[ 3 ], TNaming_NamedShape::GetID() );

prs1->SetMaterial( Graphic3d_NOM_STONE );
prs1->SetColor( Quantity_NOC_WHITE );

prs2->SetMaterial( Graphic3d_NOM_PLASTIC );
prs2->SetColor( Quantity_NOC_RED );

prs3->SetMaterial( Graphic3d_NOM_SILVER );
prs3->SetColor( Quantity_NOC_HOTPINK );

prs4->SetMaterial( Graphic3d_NOM_BRONZE );
prs4->SetColor( Quantity_NOC_AZURE );

int i = 0;

for( TopExp_Explorer aFaceExplorer( B1, TopAbs_FACE ) ; aFaceExplorer.More() && i {
TopoDS_Face aFace = TopoDS::Face(aFaceExplorer.Current());

TNaming_Builder NameFace( aLabels[ i ] );

NameFace.Generated( aFace );
}

Handle(AIS_Shape) aBox = new AIS_Shape( B1 );

GetDocument()->myAISContext->Display( aBox, 1, -1 );

Stephane Routelous's picture

Hi,

I cannot help with OCAF, but I know that AIS_Shape cannot handle displaying the sub-faces in different colors.
You only have 1 material / color assigned to the whole shape.

HTH,

Stephane

Stephane
http://www.exotk.org

Patrik Mueller's picture

Hi,

look at XCAFPrs_AISObject - it should do it after some modifications.

Regards,

Patrik Müller

Sharjith Naramparambath's picture

I am not very sure but did you try making the box a user defined one like the cylinder shown in the AISBasic sample. You can explore the faces one by one setting different material and color for each face in each iteration. This can be done in the redefined Compute method.
See the UserCylinder.hxx and UserCylinder.cpp in the AIS samples.

Contact us

Attention: DO NOT use this form for all kind of request for the removal of your personal data. Please follow this link for such cases.