
Fri, 12/04/2020 - 15:17
Forums:
Hi,
I am trying to add AIS_ColoredShape to the XCAFDoc_ShapeTool. Here is my code:
TDF_Label addColoredShape(const Handle_AIS_ColoredShape& coloredShape, const Handle_XCAFDoc_ShapeTool& tool) {
TopoDS_Shape shape = coloredShape->Shape();
TDF_Label shapeL;
TopoDS_Builder builder;
TopoDS_Compound comp;
builder.MakeCompound(comp);
AIS_DataMapOfShapeDrawer::Iterator aspects(coloredShape->CustomAspectsMap());
for (aspects.Reset(); aspects.More(); aspects.Next()) {
builder.Add(comp, aspects.Key());
}
shapeL = tool->AddShape(comp, false);
auto cTool = XCAFDoc_DocumentTool::ColorTool(shapeL);
for (TopoDS_Iterator itr(comp); itr.More(); itr.Next()) {
auto sh = itr.Value();
auto color = coloredShape->CustomAspects(sh)->ShadingAspect()->Color();
cTool->AddColor(color);
if (sh.IsEqual(shape)) {
cTool->SetColor(shapeL, color, XCAFDoc_ColorGen);
continue;
}
TDF_Label L;
L = tool->AddSubShape(shapeL, sh);
if (!L.IsNull()) {
cTool->SetColor(L, color, XCAFDoc_ColorGen);
}
}
return shapeL;
}
In above code I am able to add the the subshape with custom aspect. (i.e AddSubShape() returns a Non Null TDF_Label).
After this API I exported TDocStd_Document (for the same ShapeTool) into GLTF. But I can see only one color is exported for coloredShape (I am sure that coloredShape have different colors).
Please suggest me a better way to add colored shape to XCAFDoc_ShapeTool.
Thanks.