Quantity_Color aBlack (Quantity_NOC_BLACK);
Quantity_Color aBlue (Quantity_NOC_MATRABLUE);
Quantity_Color aBrown (Quantity_NOC_BROWN4);
Quantity_Color aFirebrick (Quantity_NOC_FIREBRICK);
Quantity_Color aForest (Quantity_NOC_FORESTGREEN);
Quantity_Color aGray (Quantity_NOC_GRAY70);
Quantity_Color aMyColor (0.99, 0.65, 0.31, Quantity_TOC_RGB);
Quantity_Color aBeet (Quantity_NOC_BEET);
Quantity_Color aWhite (Quantity_NOC_WHITE);
Handle(Graphic3d_AspectLine3d) anAspectBrown = new Graphic3d_AspectLine3d();
Handle(Graphic3d_AspectLine3d) anAspectBlue = new Graphic3d_AspectLine3d();
Handle(Graphic3d_AspectLine3d) anAspectWhite = new Graphic3d_AspectLine3d();
anAspectBrown->SetColor (aBrown);
anAspectBlue ->SetColor (aBlue);
anAspectWhite->SetColor (aWhite);
Handle(Graphic3d_AspectMarker3d aFirebrickMarker = new Graphic3d_AspectMarker3d();
// marker attributes
aFirebrickMarker->SetColor (Firebrick);
aFirebrickMarker->SetScale (1.0);
aFirebrickMarker->SetType (Aspect_TOM_BALL);
// or this
// it is a preferred way (supports full-color images on modern hardware).
aFirebrickMarker->SetMarkerImage (theImage)
Handle(Graphic3d_AspectFillArea3d) aFaceAspect = new Graphic3d_AspectFillArea3d();
Graphic3d_MaterialAspect aBrassMaterial (Graphic3d_NOM_BRASS);
Graphic3d_MaterialAspect aGoldMaterial (Graphic3d_NOM_GOLD);
aFaceAspect->SetInteriorStyle (Aspect_IS_SOLID);
aFaceAspect->SetInteriorColor (aMyColor);
aFaceAspect->SetDistinguishOn ();
aFaceAspect->SetFrontMaterial (aGoldMaterial);
aFaceAspect->SetBackMaterial (aBrassMaterial);
aFaceAspect->SetEdgeOn();
Handle(Graphic3d_AspectText3d) aTextAspect = new Graphic3d_AspectText3d (aForest, Graphic3d_NOF_ASCII_MONO, 1.0, 0.0);
// create a default connection
Handle(Aspect_DisplayConnection) aDisplayConnection;
// create a graphic driver from default connection
Handle(OpenGl_GraphicDriver) aGraphicDriver = new OpenGl_GraphicDriver (aDisplayConnection);
// create a viewer
myViewer = new V3d_Viewer (aGraphicDriver);
// set parameters for V3d_Viewer
// defines default lights
// positional-light 0.3 0.0 0.0
// directional-light V3d_XnegYposZpos
// directional-light V3d_XnegYneg
// ambient-light
a3DViewer->SetDefaultLights();
// activates all the lights defined in this viewer
a3DViewer->SetLightOn();
// set background color to black
a3DViewer->SetDefaultBackgroundColor (Quantity_NOC_BLACK);
Handle(WNT_Window) aWNTWindow = new WNT_Window (GetSafeHwnd());
myView = myViewer->CreateView();
myView->SetWindow (aWNTWindow);
myAISContext = new AIS_InteractiveContext (myViewer);
TopoDS_Shape aShape = BRepAPI_MakeBox (10, 20, 30).Solid();
Handle(AIS_Shape) anAISShape = new AIS_Shape (aShape);
myAISContext->Display (anAISShape);
必须重载两个方法
void MyPresentableObject::Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsManager, const Handle(Prs3d_Presentation)& thePrs, const Standard_Integer theMode) ( //... )
void MyPresentableObject::Compute (const Handle(Prs3d_Projector)& theProjector, const Handle(Prs3d_Presentation)& thePrs) ( //... )
Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
aGroup->SetGroupPrimitivesAspect (anAspectBlue);
Standard_Integer aNbTria = 2;
Handle(Graphic3d_ArrayOfTriangles) aTriangles = new Graphic3d_ArrayOfTriangles (3 * aNbTria, 0, true);
for (Standard_Integer aTriIter = 1; aTriIter <= aNbTria; ++aTriIter)
{
aTriangles->AddVertex (aTriIter * 5., 0., 0., 1., 1., 1.);
aTriangles->AddVertex (aTriIter * 5 + 2.5, 5., 0., 1., 1., 1.);
}
aGroup->AddPrimitiveArray (aTriangles);
aGroup->SetGroupPrimitivesAspect (new Graphic3d_AspectFillArea3d());
Standard_Real Xm, Ym, Zm, XM, YM, ZM;
thePrs->MinMaxValues (Xm, Ym, Zm, XM, YM, ZM);
Handle(Graphic3d_ArrayOfPolylines) aPolylines = new Graphic3d_ArrayOfPolylines (16, 4);
aPolylines->AddBound (4);
aPolylines->AddVertex (Xm, Ym, Zm);
aPolylines->AddVertex (Xm, Ym, ZM);
aPolylines->AddVertex (Xm, YM, ZM);
aPolylines->AddVertex (Xm, YM, Zm);
aPolylines->AddBound (4);
aPolylines->AddVertex (Xm, Ym, Zm);
aPolylines->AddVertex (XM, Ym, Zm);
aPolylines->AddVertex (XM, Ym, ZM);
aPolylines->AddVertex (XM, YM, ZM);
aPolylines->AddBound (4);
aPolylines->AddVertex (XM, YM, Zm);
aPolylines->AddVertex (XM, Ym, Zm);
aPolylines->AddVertex (XM, YM, Zm);
aPolylines->AddVertex (Xm, YM, Zm);
aPolylines->AddBound (4);
aPolylines->AddVertex (Xm, YM, ZM);
aPolylines->AddVertex (XM, YM, ZM);
aPolylines->AddVertex (XM, Ym, ZM);
aPolylines->AddVertex (Xm, Ym, ZM);
aGroup->AddPrimitiveArray(aPolylines);
aGroup->SetGroupPrimitivesAspect (new Graphic3d_AspectLine3d());
static char* texte[3] = { "Application title", "My company", "My company address." };
Handle(Graphic3d_ArrayOfPoints) aPtsArr = new Graphic3d_ArrayOfPoints (2, 1);
aPtsArr->AddVertex (-40.0, -40.0, -40.0);
aPtsArr->AddVertex (40.0, 40.0, 40.0);
aGroup->AddPrimitiveArray (aPtsArr);
aGroup->SetGroupPrimitivesAspect (new Graphic3d_AspectText3d());
Graphic3d_Vertex aMarker (0.0, 0.0, 0.0);
for (int i = 0; i <= 2; i++)
{
aMarker.SetCoord (-(Standard_Real )i * 4 + 30, (Standard_Real )i * 4, -(Standard_Real )i * 4);
aGroup->Text (texte[i], Marker, 20.);
}