
Wed, 04/28/2010 - 19:57
Hello,
I'm asking how to activate the Gouraud shading in OpenCascade.
I've created a V3d_Viewer like this :
TCollection_ExtendedString a3DName("Visu3D");
V3d_Viewer(getenv("DISPLAY"),a3DName.ToExtString(),"",1000.0,V3d_XposYnegZpos, Quantity_NOC_GRAY30, V3d_ZBUFFER, V3d_GOURAUD, V3d_WAIT, Standard_True,Standard_True,V3d_TEX_ALL);
myViewer->Init();
myViewer->SetDefaultLights();
myViewer->SetLightOn();
myContext = new AIS_InteractiveContext(myViewer);
myContext->ActivateStandardMode(TopAbs_FACE);
myContext->SetAutomaticHilight(Standard_False);
myContext->Hilight(myContext->DetectedInteractive(), true);
I've created an ArrayOfVertexC with this code :
static Graphic3d_Array1OfVertexC verticesC(1, myMesh->GetElementsNber()*3);
static Aspect_Array1OfEdge mesEdges(1, myMesh->GetElementsNber()*3);
Handle(Graphic3d_AspectFillArea3d) myFillAspect = new Graphic3d_AspectFillArea3d();
myFillAspect->SetInteriorStyle(Aspect_IS_SOLID);
Handle( Graphic3d_Group ) TheGroup = Prs3d_Root::CurrentGroup(aPresentation);
Graphic3d_MaterialAspect mat = myFillAspect->FrontMaterial();
mat.SetMaterialType(Graphic3d_MATERIAL_ASPECT);
myFillAspect->SetFrontMaterial(mat);
TheGroup->SetPrimitivesAspect(myFillAspect);
//Add vertices and edges
int j = 1;
for(int i = 0; i GetElementsNber(); i++)
{
verticesC(j) = Graphic3d_VertexC( (myMesh->GetVertex(myMesh->GetVertexIdx1(i)-1)).X(), (myMesh->GetVertex(myMesh->GetVertexIdx1(i)-1)).Y(), (myMesh->GetVertex(myMesh->GetVertexIdx1(i)-1)).Z(), color);
verticesC(j+1) = Graphic3d_VertexC( (myMesh->GetVertex(myMesh->GetVertexIdx2(i)-1)).X(), (myMesh->GetVertex(myMesh->GetVertexIdx2(i)-1)).Y(), (myMesh->GetVertex(myMesh->GetVertexIdx2(i)-1)).Z(), color);
verticesC(j+2) = Graphic3d_VertexC( (myMesh->GetVertex(myMesh->GetVertexIdx3(i)-1)).X(), (myMesh->GetVertex(myMesh->GetVertexIdx3(i)-1)).Y(), (myMesh->GetVertex(myMesh->GetVertexIdx3(i)-1)).Z(), color);
mesEdges(j) = Aspect_Edge(j,j+1,Aspect_TOE_INVISIBLE);
mesEdges(j+1) = Aspect_Edge(j+1,j+2,Aspect_TOE_INVISIBLE);
mesEdges(j+2) = Aspect_Edge(j+2,j,Aspect_TOE_INVISIBLE);
j += 3;
}
TheGroup->BeginPrimitives();
TheGroup->TriangleSet(verticesC, mesEdges);
TheGroup->EndPrimitives();
This object is then displayed in my context but it's not shaded (see the attached file).
Is the Gouraud shaded good working ? What's wrong ?
Thank you very much for your help !
Regards
Mathieu
Wed, 04/28/2010 - 23:06
Hi Mathieu,
The Gouraud shading rendering need the vertices, edges, faces to be defined (as you did) but also the normals. You should have a look to the Graphic3d_VertexN (N means 'normal'), Graphic3d_VertexNC (normals and colors) or Graphic3d_VertexNT (normals and texture coordinates) classes.
Best Regards,
Thomas
Thu, 04/29/2010 - 19:44
Hi Thomas !
This is good working now, thank you very much for your help !
I've changed the way to draw triangles, and now I use this method :
Handle_Graphic3d_ArrayOfTriangles aTrianglesArray = new Graphic3d_ArrayOfTriangles(myMesh->GetNodesNber(), myMesh->GetElementsNber()*3, Standard_True, Standard_False, Standard_False, Standard_True);
I then add vertexes and Edges :
color.SetValues( 255 / 255., 0 / 255., 0 / 255., Quantity_TOC_RGB );
for(int i = 0; i < myMesh->GetNodesNber(); i++)
{
aTrianglesArray->AddVertex(myMesh->GetVertex(i), myMesh->GetNodeNorm(i), color);
}
for(int i = 0; i < myMesh->GetElementsNber(); i++)
{
aTrianglesArray->AddEdge(myMesh->GetVertexIdx1(i));
aTrianglesArray->AddEdge(myMesh->GetVertexIdx2(i));
aTrianglesArray->AddEdge(myMesh->GetVertexIdx3(i));
}
This is good working like the image on the left of the attached file.
Now, if I set the parameter hasVNormals to Standard_True, like this :
Handle_Graphic3d_ArrayOfTriangles aTrianglesArray = new Graphic3d_ArrayOfTriangles(myMesh->GetNodesNber(), myMesh->GetElementsNber()*3, Standard_True, Standard_True, Standard_False, Standard_True);
I see the image on the right on the capture.
The material used is the same in the two cases, so I don't know what's wrong...
Have you got an idea ?
Many thanks
Thu, 04/29/2010 - 19:59
I've wrote a mistake :
I change the hasVColors parameter to Standard_True, not the hasVNormals parameter...
Thu, 04/29/2010 - 20:01
And this is not working and I don't know why...