Forum archiveIssue archiveVisualization and 3D Viewer

Archived discussion

AIS_ColoredShape, Set Material of sub-shape

Visualization and 3D ViewerMon, 01/08/2024 - 15:362 replies

Browse this forum
QuestionAuthor

Hey Everyone

I was wondering if it's possible to set the material(Graphic3d_MaterialAspect) of each individual subShape of a AIS_ColoredShape object.

Best regards

Discussion

2 archived replies

Posts are displayed in their archived order.

01Commenter-1

Sure, you may use AIS_ColoredShape::CustomAspects() to customize drawer for a subshape in desired way, including material aspect (like XCAFPrs_AISObject does to dispatch materials from XCAF document).

02Author

​ Yes, i checked the source code of XCAFPrs_AISObject and fixed it like this:

void SubShapeAspectHandler(Handle(AIS_ColoredShape) aisColoredShape, const TopoDS_Shape & subShape, const Graphic3d_MaterialAspect theAspect) 
{
	aisColoredShape->CustomAspects(subShape)->SetOwnMaterial();
	aisColoredShape->CustomAspects(subShape)->SetupOwnShadingAspect();
	aisColoredShape->CustomAspects(subShape)->ShadingAspect()->Aspect()->SetFrontMaterial(theAspect);
}