how to have a smooth shading

Hi,

I try to represent color shading on a mesh from the different vertex colors. I know that with OpenGL, it is easily obtained with the function glShadeModel(GL_SMOOTH), but it's a little bit harder with OpenCascade.

Until now, I created a Graphic3d_Group in which I placed some Graphic3d_VertexC in order to display a triangle via the method TriangleSet, but I still not have the shading.

I saw that the abstract class V3d_View has a method called SetShadingModel and that we could use the V3d_MULTICOLOR option. But I don't succeed with it. I don't know how to use this method (or if it's the right method to use).

Thank you for your help

static Graphic3d_Array1OfVertexC verticesC( 1, 3);
static Aspect_Array1OfEdge mesEdges(1,3);

Handle(Graphic3d_AspectLine3d) myLineAspect = new Graphic3d_AspectLine3d();
Handle(Graphic3d_AspectFillArea3d) myFillAspect = (new Prs3d_ShadingAspect())->Aspect();
myFillAspect->SetInteriorStyle(Aspect_IS_SOLID);
myFillAspect->SetInteriorColor(Quantity_NOC_BLUE1);
myFillAspect->SetEdgeColor(Quantity_NOC_WHITE);
myFillAspect->SetEdgeLineType(Aspect_TOL_SOLID);
myFillAspect->SetEdgeWidth(1.0);
myFillAspect->SetFrontMaterial(Graphic3d_NOM_PLASTIC);
myFillAspect->SetBackMaterial(Graphic3d_NOM_BRASS);
Handle( Graphic3d_Group ) TheGroup = Prs3d_Root::CurrentGroup(aPresentation);
Prs3d_ShadingAspect());
TheGroup->BeginPrimitives();
myFillAspect->SetEdgeOn();
myFillAspect->SetTextureMapOff();
TheGroup->SetPrimitivesAspect(myFillAspect);

TheGroup->SetPrimitivesAspect(myLineAspect);
verticesC(1) = Graphic3d_VertexC(0,0,0,Quantity_Color(Quantity_NOC_BLUE1)) ;
verticesC(2) = Graphic3d_VertexC(100,0,0,Quantity_Color(Quantity_NOC_RED)) ; ;
verticesC(3) = Graphic3d_VertexC(100,100,0,Quantity_Color(Quantity_NOC_YELLOW)) ; ;

mesEdges(1) = Aspect_Edge(1,2,Aspect_TOE_VISIBLE);
mesEdges(2) = Aspect_Edge(2,3,Aspect_TOE_VISIBLE);
mesEdges(3) = Aspect_Edge(3,1,Aspect_TOE_VISIBLE);

TheGroup->TriangleSet(verticesC,mesEdges);

TheGroup->EndPrimitives();

Francois Lauzon's picture

Hello Hilaire,
try the following code and create your viewer with something like this:

myViewer=new V3d_Viewer(myDevice, Name.ToExtString(),Domain.ToCString(),1000.0,V3d_XposYnegZpos,
Quantity_NOC_BLACK,V3d_ZBUFFER,V3d_GOURAUD,V3d_WAIT,Standard_True,Standard_True,V3d_TEX_ALL);

and the code for the triangle creation:

static Graphic3d_Array1OfVertexC verticesC( 1, 3);
static Aspect_Array1OfEdge mesEdges(1,3);

Handle(Graphic3d_AspectFillArea3d) myFillAspect = new Graphic3d_AspectFillArea3d();
myFillAspect->SetInteriorStyle(Aspect_IS_SOLID);

Handle( Graphic3d_Group ) TheGroup = Prs3d_Root::CurrentGroup(aPresentation);

TheGroup->SetPrimitivesAspect(myFillAspect);

verticesC(1) = Graphic3d_VertexC(0,0,0,Quantity_Color(Quantity_NOC_BLUE1)) ;
verticesC(2) = Graphic3d_VertexC(100,0,0,Quantity_Color(Quantity_NOC_RED)) ; ;
verticesC(3) = Graphic3d_VertexC(100,100,0,Quantity_Color(Quantity_NOC_YELLOW)) ; ;

mesEdges(1) = Aspect_Edge(1,2,Aspect_TOE_VISIBLE);
mesEdges(2) = Aspect_Edge(2,3,Aspect_TOE_VISIBLE);
mesEdges(3) = Aspect_Edge(3,1,Aspect_TOE_VISIBLE);

TheGroup->BeginPrimitives();
TheGroup->TriangleSet(verticesC,mesEdges);
TheGroup->EndPrimitives();

good luck,
Francois.

白晓亮(Bai Xiaolian's picture

Hi,
Handle( Graphic3d_Group ) TheGroup = Prs3d_Root::CurrentGroup(aPresentation);

how to get aPresentation object?

thanks.

白晓亮(Bai Xiaolian's picture

Hi,
Sorry for my rashness.
Sames user_cylinder.cpp have all inf I need.

Regards.

Bai Xiaoliang