Lighting when coloring by element and or nodes

When using the mesh class and coloring elements using
Handle(MeshVS_ElementalColorPrsBuilder) aBuilder = new MeshVS_ElementalColorPrsBuilder( aMesh, MeshVS_DMF_ElementalColorDataPrs | MeshVS_DMF_OCCMask );
or nodes using
Handle(MeshVS_NodalColorPrsBuilder) aBuilder = new MeshVS_NodalColorPrsBuilder( aMesh, MeshVS_DMF_NodalColorDataPrs | MeshVS_DMF_OCCMask );

Is there a way to view the shading due to the lights, or can it only be shown flat? It is very difficult to visualize the 3D objects without any shading/shadows.

hamishl's picture

Ok, I figured it out. I had to set MeshVS_DA_ColorReflection to True.
http://www.opencascade.com/pub/doc/Release_Notes_6.2.pdf

It looks great now.

Thorsten H's picture

Hi Hamish,

how did you get MeshVS_ElementalColorPrsBuilder working? I have to load colored STL files and display ist as a MeshVS_Mesh. I tried a lot but nothing worked for me.

Regards
SK

hamishl's picture

After creating all the tris in aMesh I used the code below
Does this answer your question? I had an array for R, G and B values that matched the points that I added.

Handle(MeshVS_NodalColorPrsBuilder) aBuilder = new MeshVS_NodalColorPrsBuilder( aMesh, MeshVS_DMF_NodalColorDataPrs | MeshVS_DMF_OCCMask );

const TColStd_PackedMapOfInteger& anAllNodes = aMesh->GetDataSource()->GetAllNodes();
TColStd_MapIteratorOfPackedMapOfInteger anIter( anAllNodes );
int PntID=0;
for ( ; anIter.More(); anIter.Next() )
{
Quantity_Color col = Quantity_Color(r[PntID]/255.,g[PntID]/255.,b[PntID]/255.,Quantity_TOC_RGB);
aBuilder->SetColor( anIter.Key(), col );
PntID++;
}

//End of Color
aMesh.operator->() ), Standard_True );

aMesh->AddBuilder( aBuilder, Standard_True );
MeshVS_DA_FrontMaterial,Graphic3d_NOM_SHINY_PLASTIC);// Graphic3d_NOM_DEFAULT );
aMesh->GetDrawer()->SetBoolean(MeshVS_DA_DisplayNodes,Standard_False);
aMesh->GetDrawer()->SetBoolean(MeshVS_DA_ColorReflection,Standard_True);

aMesh->SetDisplayMode (2);
myAISContext->Display( aMesh,Standard_False );

Thorsten H's picture

@Hamish
thx, I am working with MeshVS_ElementalColorPrsBuilder but now it works for me too :)