//
// This file is part of Open CASCADE Technology software library.
//
-// This library is free software; you can redistribute it and / or modify it
-// under the terms of the GNU Lesser General Public version 2.1 as published
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
-#include <MeshVS_ElementalColorPrsBuilder.ixx>
-#include <Graphic3d_AspectFillArea3d.hxx>
-#include <Graphic3d_AspectLine3d.hxx>
#include <Graphic3d_ArrayOfPolygons.hxx>
#include <Graphic3d_ArrayOfPolylines.hxx>
+#include <Graphic3d_ArrayOfSegments.hxx>
+#include <Graphic3d_ArrayOfTriangles.hxx>
+#include <Graphic3d_AspectFillArea3d.hxx>
+#include <Graphic3d_AspectLine3d.hxx>
#include <Graphic3d_Group.hxx>
-
-#include <Prs3d_ShadingAspect.hxx>
-#include <Prs3d_Root.hxx>
-#include <Prs3d_LineAspect.hxx>
-
-#include <TColStd_MapOfInteger.hxx>
-#include <TColStd_PackedMapOfInteger.hxx>
-#include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
-#include <TColStd_ListIteratorOfListOfInteger.hxx>
-#include <TColStd_Array1OfReal.hxx>
-#include <TColStd_SequenceOfInteger.hxx>
-#include <TColStd_HArray1OfReal.hxx>
-#include <TColStd_HPackedMapOfInteger.hxx>
-
-#include <MeshVS_DisplayModeFlags.hxx>
-#include <MeshVS_DataSource.hxx>
-#include <MeshVS_Mesh.hxx>
+#include <MeshVS_Buffer.hxx>
+#include <MeshVS_DataMapIteratorOfDataMapOfColorMapOfInteger.hxx>
+#include <MeshVS_DataMapIteratorOfDataMapOfIntegerColor.hxx>
+#include <MeshVS_DataMapIteratorOfDataMapOfIntegerTwoColors.hxx>
+#include <MeshVS_DataMapIteratorOfDataMapOfTwoColorsMapOfInteger.hxx>
#include <MeshVS_DataMapOfColorMapOfInteger.hxx>
#include <MeshVS_DataMapOfTwoColorsMapOfInteger.hxx>
+#include <MeshVS_DataSource.hxx>
+#include <MeshVS_DisplayModeFlags.hxx>
#include <MeshVS_Drawer.hxx>
#include <MeshVS_DrawerAttribute.hxx>
-#include <MeshVS_DataMapIteratorOfDataMapOfIntegerTwoColors.hxx>
-#include <MeshVS_DataMapIteratorOfDataMapOfIntegerColor.hxx>
-#include <MeshVS_DataMapIteratorOfDataMapOfTwoColorsMapOfInteger.hxx>
-#include <MeshVS_DataMapIteratorOfDataMapOfColorMapOfInteger.hxx>
+#include <MeshVS_ElementalColorPrsBuilder.hxx>
+#include <MeshVS_HArray1OfSequenceOfInteger.hxx>
+#include <MeshVS_Mesh.hxx>
#include <MeshVS_MeshPrsBuilder.hxx>
-#include <MeshVS_Buffer.hxx>
+#include <Prs3d_LineAspect.hxx>
+#include <Prs3d_Presentation.hxx>
+#include <Prs3d_Root.hxx>
+#include <Prs3d_ShadingAspect.hxx>
+#include <Quantity_Color.hxx>
+#include <Standard_Type.hxx>
+#include <TColStd_Array1OfReal.hxx>
+#include <TColStd_HArray1OfReal.hxx>
+#include <TColStd_HPackedMapOfInteger.hxx>
+#include <TColStd_ListIteratorOfListOfInteger.hxx>
+#include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
+#include <TColStd_MapOfInteger.hxx>
+#include <TColStd_PackedMapOfInteger.hxx>
+#include <TColStd_SequenceOfInteger.hxx>
+IMPLEMENT_STANDARD_RTTIEXT(MeshVS_ElementalColorPrsBuilder,MeshVS_PrsBuilder)
//================================================================
// Function : Constructor MeshVS_ElementalColorPrsBuilder
//Now we are ready to draw faces with equal colors
Aspect_TypeOfLine anEdgeType = Aspect_TOL_SOLID;
Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
- Standard_Integer anEdgeInt, aLineInt;
- Standard_Real anEdgeWidth, aLineWidth;
+ Standard_Real anEdgeWidth = 1.0, aLineWidth = 1.0;
Quantity_Color anInteriorColor;
Quantity_Color anEdgeColor, aLineColor;
Standard_Boolean anEdgeOn = Standard_True, IsReflect = Standard_False,
IsMeshSmoothShading = Standard_False;
+ Standard_Boolean toSupressBackFaces = Standard_False;
aDrawer->GetColor ( MeshVS_DA_InteriorColor, anInteriorColor );
aDrawer->GetColor ( MeshVS_DA_EdgeColor, anEdgeColor );
aDrawer->GetBoolean( MeshVS_DA_ShowEdges, anEdgeOn );
aDrawer->GetBoolean( MeshVS_DA_ColorReflection, IsReflect );
aDrawer->GetBoolean( MeshVS_DA_SmoothShading, IsMeshSmoothShading );
+ aDrawer->GetBoolean (MeshVS_DA_SupressBackFaces, toSupressBackFaces);
+ Standard_Integer anEdgeInt = Aspect_TOL_SOLID;
if ( aDrawer->GetInteger ( MeshVS_DA_EdgeType, anEdgeInt) )
anEdgeType = (Aspect_TypeOfLine) anEdgeInt;
+ Standard_Integer aLineInt = Aspect_TOL_SOLID;
if ( aDrawer->GetInteger ( MeshVS_DA_BeamType, aLineInt) )
aLineType = (Aspect_TypeOfLine) aLineInt;
PolygonVerticesFor3D, PolygonBoundsFor3D );
}
- Graphic3d_MaterialAspect aMaterial[2];
- Standard_Integer i;
- for ( i=0; i<2; i++ )
+ Graphic3d_MaterialAspect aMaterial[2] = { Graphic3d_NOM_PLASTIC, Graphic3d_NOM_PLASTIC };
+ for (Standard_Integer i = 0; i < 2; i++)
{
// OCC20644 "plastic" is most suitable here, as it is "non-physic"
// so TelUpdateMaterial() from OpenGl_attri.c uses the interior
// color from AspectFillArea3d to calculate all material colors
- aMaterial[i] = Graphic3d_MaterialAspect ( Graphic3d_NOM_PLASTIC );
+ aMaterial[i].SetSpecularColor (Quantity_NOC_BLACK);
+ aMaterial[i].SetEmissiveColor (Quantity_NOC_BLACK);
// OCC21720 For single-colored elements turning all material components off is a good idea,
// as anyhow the normals are not computed and the lighting will be off,
// and there is no need to spend time on updating material properties
if ( !IsReflect )
{
- aMaterial[i].SetReflectionModeOff(Graphic3d_TOR_AMBIENT);
- aMaterial[i].SetReflectionModeOff(Graphic3d_TOR_DIFFUSE);
- aMaterial[i].SetReflectionModeOff(Graphic3d_TOR_SPECULAR);
- aMaterial[i].SetReflectionModeOff(Graphic3d_TOR_EMISSION);
+ aMaterial[i].SetAmbientColor (Quantity_NOC_BLACK);
+ aMaterial[i].SetDiffuseColor (Quantity_NOC_BLACK);
}
else
{
// those in the color scale most exactly (the sum of all reflection
// coefficients is equal to 1). See also MeshVS_NodalColorPrsBuilder
// class for more explanations.
- aMaterial[i].SetAmbient( .5 );
- aMaterial[i].SetDiffuse( .5 );
- aMaterial[i].SetSpecular( 0. );
- aMaterial[i].SetEmissive( 0. );
+ aMaterial[i].SetAmbientColor (Quantity_Color (Graphic3d_Vec3 (0.5f)));
+ aMaterial[i].SetDiffuseColor (Quantity_Color (Graphic3d_Vec3 (0.5f)));
}
}
// Draw elements with one color
- for ( MeshVS_DataMapIteratorOfDataMapOfColorMapOfInteger aColIter ( aColorsOfElements ); aColIter.More();
- aColIter.Next() )
+ Handle(Graphic3d_Group) aGGroup, aGroup2, aLGroup, aSGroup;
+ if (!aTwoColorsOfElements.IsEmpty())
+ {
+ aGroup2 = Prs3d_Root::NewGroup (Prs);
+ }
+ if (!aColorsOfElements.IsEmpty())
+ {
+ Handle(Graphic3d_AspectFillArea3d) aGroupFillAspect = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID, anInteriorColor, anEdgeColor,
+ anEdgeType, anEdgeWidth, aMaterial[0], aMaterial[1]);
+ aGGroup = Prs3d_Root::NewGroup (Prs);
+ aLGroup = Prs3d_Root::NewGroup (Prs);
+ aGGroup->SetClosed (toSupressBackFaces == Standard_True);
+ aGGroup->SetGroupPrimitivesAspect (aGroupFillAspect);
+ }
+
+ if (anEdgeOn)
+ {
+ Handle(Graphic3d_AspectLine3d) anEdgeAspect = new Graphic3d_AspectLine3d (anEdgeColor, anEdgeType, anEdgeWidth);
+ aSGroup = Prs3d_Root::NewGroup (Prs);
+ aSGroup->SetGroupPrimitivesAspect (anEdgeAspect);
+ }
+
+ for (MeshVS_DataMapIteratorOfDataMapOfColorMapOfInteger aColIter (aColorsOfElements);
+ aColIter.More(); aColIter.Next())
{
- Standard_Integer aSize = aColIter.Value().Extent();
- if ( aSize<=0 )
+ if (aColIter.Value().IsEmpty())
+ {
continue;
+ }
TColStd_PackedMapOfInteger aCustomElements;
- Prs3d_Root::NewGroup ( Prs );
- Handle ( Graphic3d_Group ) aGGroup = Prs3d_Root::CurrentGroup ( Prs );
- Prs3d_Root::NewGroup ( Prs );
- Handle ( Graphic3d_Group ) aLGroup = Prs3d_Root::CurrentGroup ( Prs );
+ Standard_Integer aNbFacePrimitives = 0;
+ Standard_Integer aNbVolmPrimitives = 0;
+ Standard_Integer aNbEdgePrimitives = 0;
+ Standard_Integer aNbLinkPrimitives = 0;
+
+ for (it.Reset(); it.More(); it.Next())
+ {
+ Standard_Integer aNbNodes = 0;
- Handle (Graphic3d_ArrayOfPolygons) aPolyGArr = new Graphic3d_ArrayOfPolygons
- ( aMaxFaceNodes*aSize + PolygonVerticesFor3D, aSize + PolygonBoundsFor3D, 0, IsReflect );
+ if (!aColIter.Value().Contains (it.Key()))
+ continue;
+
+ if (!aSource->GetGeom (it.Key(), Standard_True, aCoords, aNbNodes, aType))
+ continue;
+
+ if (aType == MeshVS_ET_Volume)
+ {
+ if (aSource->Get3DGeom (it.Key(), aNbNodes, aTopo))
+ {
+ for (Standard_Integer aFaceIdx = aTopo->Lower(); aFaceIdx <= aTopo->Upper(); ++aFaceIdx)
+ {
+ const TColStd_SequenceOfInteger& aFaceNodes = aTopo->Value (aFaceIdx);
+
+ if (anEdgeOn) // add edge segments
+ {
+ aNbEdgePrimitives += aFaceNodes.Length();
+ }
+
+ aNbVolmPrimitives += aFaceNodes.Length() - 2;
+ }
+ }
+ }
+ else if (aType == MeshVS_ET_Link)
+ {
+ if (anEdgeOn)
+ {
+ aNbLinkPrimitives += aNbNodes - 1; // add link segments
+ }
+ }
+ else if (aType == MeshVS_ET_Face)
+ {
+ if (anEdgeOn)
+ {
+ aNbEdgePrimitives += aNbNodes; // add edge segments
+ }
+
+ aNbFacePrimitives += aNbNodes - 2; // add face triangles
+ }
+ }
+
+ // Here we do not use indices arrays because they are not effective for some mesh
+ // drawing modes: shrinking mode (displaces the vertices inside the polygon), 3D
+ // cell rendering (normal interpolation is not always applicable - flat shading),
+ // elemental coloring (color interpolation is impossible)
+
+ Handle (Graphic3d_ArrayOfTriangles) aFaceTriangles = new Graphic3d_ArrayOfTriangles (
+ (aNbFacePrimitives + aNbVolmPrimitives) * 3, 0, IsReflect );
Standard_Boolean IsPolyG = Standard_False;
- Handle (Graphic3d_ArrayOfPolylines) aPolyLArr = new Graphic3d_ArrayOfPolylines
- ( 2*aSize, aSize );
+ Handle (Graphic3d_ArrayOfSegments) anEdgeSegments = new Graphic3d_ArrayOfSegments (aNbEdgePrimitives * 2);
+ Handle (Graphic3d_ArrayOfSegments) aLinkSegments = new Graphic3d_ArrayOfSegments (aNbLinkPrimitives * 2);
Standard_Boolean IsPolyL = Standard_False;
// OCC20644 NOTE: aColIter.Key() color is then scaled by TelUpdateMaterial() in OpenGl_attri.c
// using the material reflection coefficients. This affects the visual result.
- Handle(Graphic3d_AspectFillArea3d) anAsp =
+ Handle(Graphic3d_AspectFillArea3d) aFillAspect =
new Graphic3d_AspectFillArea3d ( Aspect_IS_SOLID, aColIter.Key(), anEdgeColor,
anEdgeType, anEdgeWidth, aMaterial[0], aMaterial[1] );
- Handle(Graphic3d_AspectLine3d) anLAsp =
+ Handle(Graphic3d_AspectLine3d) aLinkAspect =
new Graphic3d_AspectLine3d ( aColIter.Key(), aLineType, aLineWidth );
- anAsp->SetDistinguishOff ();
- anAsp->SetInteriorColor ( aColIter.Key() );
- if (anEdgeOn)
- anAsp->SetEdgeOn();
- else
- anAsp->SetEdgeOff();
+ aFillAspect->SetDistinguishOff ();
+ aFillAspect->SetInteriorColor ( aColIter.Key() );
+ aFillAspect->SetEdgeOff();
- for( it.Reset(); it.More(); it.Next() )
+ for (it.Reset(); it.More(); it.Next())
{
Standard_Integer aKey = it.Key();
- if( aColIter.Value().Contains( aKey ) )
+
+ if (aColIter.Value().Contains (aKey))
{
- if ( !aSource->GetGeom ( aKey, Standard_True, aCoords, NbNodes, aType ) )
+ if (!aSource->GetGeom (aKey, Standard_True, aCoords, NbNodes, aType))
continue;
-
- if( aType == MeshVS_ET_Face )
- {
- aPolyGArr->AddBound ( NbNodes );
- if( IsExcludingOn() )
- IDsToExclude.Add( aKey );
- }
- else if( aType == MeshVS_ET_Link )
+
+ if (aType != MeshVS_ET_Face && aType != MeshVS_ET_Link && aType != MeshVS_ET_Volume)
{
- aPolyLArr->AddBound ( NbNodes );
- if( IsExcludingOn() )
- IDsToExclude.Add( aKey );
+ aCustomElements.Add (aKey);
+ continue;
}
- else if( aType == MeshVS_ET_Volume )
+
+ if (IsExcludingOn())
+ IDsToExclude.Add (aKey);
+
+ if (aType == MeshVS_ET_Volume)
{
- if( IsExcludingOn() )
- IDsToExclude.Add( aKey );
- if( aSource->Get3DGeom( aKey, NbNodes, aTopo ) )
+ if (!aSource->Get3DGeom (aKey, NbNodes, aTopo))
{
- MeshVS_MeshPrsBuilder::AddVolumePrs( aTopo, aCoords, NbNodes, aPolyGArr, IsReflect, Standard_False, Standard_False, 1.0 );
- IsPolyG = Standard_True;
- }
- else
continue;
+ }
+
+ MeshVS_MeshPrsBuilder::AddVolumePrs (aTopo, aCoords,
+ NbNodes, aFaceTriangles, IsReflect, Standard_False, Standard_False, 1.0);
+
+ if (anEdgeOn)
+ {
+ MeshVS_MeshPrsBuilder::AddVolumePrs (aTopo, aCoords,
+ NbNodes, anEdgeSegments, IsReflect, Standard_False, Standard_False, 1.0);
+ }
+
+ IsPolyG = Standard_True;
}
- else
+ else if (aType == MeshVS_ET_Face)
{
- aCustomElements.Add( aKey );
- continue;
- }
+ // Preparing normals
+ Handle(TColStd_HArray1OfReal) aNormals;
+ Standard_Boolean aHasNormals = IsReflect && aSource->GetNormalsByElement (aKey, IsMeshSmoothShading, aMaxFaceNodes, aNormals);
- // Preparing normal(s) to show reflections if requested
- Handle(TColStd_HArray1OfReal) aNormals;
- Standard_Boolean hasNormals = IsReflect && aSource->GetNormalsByElement( aKey, IsMeshSmoothShading, aMaxFaceNodes, aNormals );
+ for (Standard_Integer aNodeIdx = 0; aNodeIdx < NbNodes - 2; ++aNodeIdx)
+ {
+ for (Standard_Integer anIdx = 0; anIdx < 3; ++anIdx)
+ {
+ if (IsReflect)
+ {
+ aFaceTriangles->AddVertex (aCoords (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 1),
+ aCoords (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 2),
+ aCoords (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 3),
+ aHasNormals ? aNormals->Value (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 1) : 0.0,
+ aHasNormals ? aNormals->Value (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 2) : 0.0,
+ aHasNormals ? aNormals->Value (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 3) : 1.0);
+ }
+ else
+ {
+ aFaceTriangles->AddVertex (aCoords (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 1),
+ aCoords (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 2),
+ aCoords (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 3));
+ }
+ }
+ }
- // Adding vertices (with normals if necessary)
- for ( i=1; i<=NbNodes; i++ )
- if ( aType == MeshVS_ET_Face )
+ if (anEdgeOn)
{
- if ( IsReflect )
+ for (Standard_Integer aNodeIdx = 0; aNodeIdx < NbNodes; ++aNodeIdx)
{
- hasNormals ? aPolyGArr->AddVertex ( aCoords(3 * i - 2),
- aCoords(3 * i - 1),
- aCoords(3 * i ),
- aNormals->Value(3 * i - 2),
- aNormals->Value(3 * i - 1),
- aNormals->Value(3 * i ) ) :
- aPolyGArr->AddVertex ( aCoords(3 * i - 2),
- aCoords(3 * i - 1),
- aCoords(3 * i ),
- 0.,
- 0.,
- 1. );
+ const Standard_Integer aNextIdx = (aNodeIdx + 1) % NbNodes;
+
+ anEdgeSegments->AddVertex (aCoords (3 * aNodeIdx + 1),
+ aCoords (3 * aNodeIdx + 2),
+ aCoords (3 * aNodeIdx + 3));
+
+ anEdgeSegments->AddVertex (aCoords (3 * aNextIdx + 1),
+ aCoords (3 * aNextIdx + 2),
+ aCoords (3 * aNextIdx + 3));
}
- else
- aPolyGArr->AddVertex ( aCoords(3 * i - 2),
- aCoords(3 * i - 1),
- aCoords(3 * i ) );
- IsPolyG = Standard_True;
}
- else if ( aType == MeshVS_ET_Link )
+
+ IsPolyG = Standard_True;
+ }
+ else if (aType == MeshVS_ET_Link)
+ {
+ for (Standard_Integer aNodeIdx = 0; aNodeIdx < NbNodes - 1; ++aNodeIdx)
{
- aPolyLArr->AddVertex ( aCoords(3*i-2), aCoords(3*i-1), aCoords(3*i) );
+ const Standard_Integer aNextIdx = aNodeIdx + 1;
+
+ aLinkSegments->AddVertex (aCoords (3 * aNodeIdx + 1),
+ aCoords (3 * aNodeIdx + 2),
+ aCoords (3 * aNodeIdx + 3));
+
+ aLinkSegments->AddVertex (aCoords (3 * aNextIdx + 1),
+ aCoords (3 * aNextIdx + 2),
+ aCoords (3 * aNextIdx + 3));
+
IsPolyL = Standard_True;
}
+ }
}
}
- if ( IsPolyG )
+ if (IsPolyG)
{
- aGGroup->SetPrimitivesAspect ( anAsp );
- aGGroup->AddPrimitiveArray ( aPolyGArr );
+ aGGroup->SetPrimitivesAspect (aFillAspect);
+ aGGroup->AddPrimitiveArray (aFaceTriangles);
+ aGGroup->SetClosed (toSupressBackFaces == Standard_True);
+
+ if (anEdgeOn)
+ {
+ aSGroup->AddPrimitiveArray (anEdgeSegments);
+ }
}
- if ( IsPolyL )
+ if (IsPolyL)
{
- anAsp->SetEdgeOff();
- aLGroup->SetPrimitivesAspect ( anAsp );
- aLGroup->SetPrimitivesAspect ( anLAsp );
- aLGroup->AddPrimitiveArray ( aPolyLArr );
- if (anEdgeOn)
- anAsp->SetEdgeOn();
- else
- anAsp->SetEdgeOff();
+ aLGroup->SetPrimitivesAspect (aFillAspect);
+ aLGroup->SetPrimitivesAspect (aLinkAspect);
+ aLGroup->AddPrimitiveArray (aLinkSegments);
}
- if( !aCustomElements.IsEmpty() )
- CustomBuild( Prs, aCustomElements, IDsToExclude, DisplayMode );
+ if (!aCustomElements.IsEmpty())
+ CustomBuild(Prs, aCustomElements, IDsToExclude, DisplayMode);
}
- Graphic3d_MaterialAspect aMaterial2[2];
- for ( i=0; i<2; i++ )
+ Graphic3d_MaterialAspect aMaterial2[2] = { Graphic3d_NOM_PLASTIC, Graphic3d_NOM_PLASTIC };
+ for (Standard_Integer i = 0; i < 2; i++)
{
// OCC20644 "plastic" is most suitable here, as it is "non-physic"
// so TelUpdateMaterial() from OpenGl_attri.c uses the interior
// color from AspectFillArea3d to calculate all material colors
- aMaterial2[i] = Graphic3d_MaterialAspect ( Graphic3d_NOM_PLASTIC );
+ aMaterial2[i].SetSpecularColor (Quantity_NOC_BLACK);
+ aMaterial2[i].SetEmissiveColor (Quantity_NOC_BLACK);
if ( !IsReflect )
{
// to have different materials for front and back sides!
// Instead, trying to make material color "nondirectional" with
// only ambient component on.
- aMaterial2[i].SetReflectionModeOn ( Graphic3d_TOR_AMBIENT );
- aMaterial2[i].SetReflectionModeOff( Graphic3d_TOR_DIFFUSE );
- aMaterial2[i].SetReflectionModeOff( Graphic3d_TOR_SPECULAR );
- aMaterial2[i].SetReflectionModeOff( Graphic3d_TOR_EMISSION );
- aMaterial2[i].SetAmbient ( 1. );
- aMaterial2[i].SetDiffuse ( 0. );
- aMaterial2[i].SetSpecular( 0. );
- aMaterial2[i].SetEmissive( 0. );
+ aMaterial2[i].SetAmbientColor (Quantity_Color (Graphic3d_Vec3 (1.0f)));
+ aMaterial2[i].SetDiffuseColor (Quantity_NOC_BLACK);
}
else
{
// those in the color scale most exactly (the sum of all reflection
// coefficients is equal to 1). See also MeshVS_NodalColorPrsBuilder
// class for more explanations.
- aMaterial2[i].SetAmbient( .5 );
- aMaterial2[i].SetDiffuse( .5 );
- aMaterial2[i].SetSpecular( 0. );
- aMaterial2[i].SetEmissive( 0. );
+ aMaterial2[i].SetAmbientColor (Quantity_Color (Graphic3d_Vec3 (0.5f)));
+ aMaterial2[i].SetDiffuseColor (Quantity_Color (Graphic3d_Vec3 (0.5f)));
}
}
// Draw faces with two color
+ if (!aTwoColorsOfElements.IsEmpty())
+ {
+ Handle(Graphic3d_AspectFillArea3d) aGroupFillAspect2 = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID, anInteriorColor, anEdgeColor,
+ anEdgeType, anEdgeWidth, aMaterial2[0], aMaterial2[1]);
+ aGroup2->SetClosed (Standard_False); // ignore toSupressBackFaces
+ aGroup2->SetGroupPrimitivesAspect (aGroupFillAspect2);
+ }
for ( MeshVS_DataMapIteratorOfDataMapOfTwoColorsMapOfInteger aColIter2 ( aTwoColorsOfElements );
aColIter2.More(); aColIter2.Next() )
{
- Prs3d_Root::NewGroup ( Prs );
- Handle ( Graphic3d_Group ) aGroup2 = Prs3d_Root::CurrentGroup ( Prs );
-
- Standard_Integer aSize = aColIter2.Value().Extent();
- if ( aSize<=0 )
+ if (aColIter2.Value().IsEmpty())
+ {
continue;
+ }
+
+ Standard_Integer aNbFacePrimitives = 0;
+ Standard_Integer aNbEdgePrimitives = 0;
+
+ for (it.Reset(); it.More(); it.Next())
+ {
+ Standard_Integer aNbNodes = 0;
+
+ if (!aColIter2.Value().Contains (it.Key()))
+ continue;
- Handle (Graphic3d_ArrayOfPolygons) aPolyArr = new Graphic3d_ArrayOfPolygons
- ( aMaxFaceNodes*aSize, aSize, 0, IsReflect );
+ if (!aSource->GetGeom (it.Key(), Standard_True, aCoords, aNbNodes, aType))
+ continue;
+
+ if ( aType == MeshVS_ET_Face && aNbNodes > 0 )
+ {
+ if (anEdgeOn)
+ {
+ aNbEdgePrimitives += aNbNodes; // add edge segments
+ }
+
+ aNbFacePrimitives += aNbNodes - 2; // add face triangles
+ }
+ }
+
+ Handle (Graphic3d_ArrayOfTriangles) aFaceTriangles = new Graphic3d_ArrayOfTriangles
+ (aNbFacePrimitives * 3, 0, IsReflect);
+
+ Handle (Graphic3d_ArrayOfSegments) anEdgeSegments = new Graphic3d_ArrayOfSegments
+ (aNbEdgePrimitives * 2);
MeshVS_TwoColors aTC = aColIter2.Key();
Quantity_Color aMyIntColor, aMyBackColor;
anAsp->SetDistinguishOn ();
anAsp->SetInteriorColor ( aMyIntColor );
anAsp->SetBackInteriorColor ( aMyBackColor );
- if (anEdgeOn)
+ /*if (anEdgeOn)
anAsp->SetEdgeOn();
else
- anAsp->SetEdgeOff();
-
- aGroup2->SetPrimitivesAspect ( anAsp );
+ anAsp->SetEdgeOff();*/
+ aGroup2->SetPrimitivesAspect (anAsp);
for( it.Reset(); it.More(); it.Next() )
{
if( IsExcludingOn() )
IDsToExclude.Add( aKey );
- if ( aType == MeshVS_ET_Face && NbNodes > 0 )
+ if (aType == MeshVS_ET_Face && NbNodes > 0)
{
// Preparing normal(s) to show reflections if requested
Handle(TColStd_HArray1OfReal) aNormals;
// OCC21720 Always passing normals to OpenGL to make materials work
// For OpenGL: "No normals" -> "No lighting" -> "no materials taken into account"
- Standard_Boolean hasNormals = /*IsReflect &&*/
- aSource->GetNormalsByElement( aKey, IsMeshSmoothShading, aMaxFaceNodes, aNormals );
+ Standard_Boolean aHasNormals = /*IsReflect &&*/
+ aSource->GetNormalsByElement (aKey, IsMeshSmoothShading, aMaxFaceNodes, aNormals);
- aPolyArr->AddBound ( NbNodes );
+ for (Standard_Integer aNodeIdx = 0; aNodeIdx < NbNodes - 2; ++aNodeIdx)
+ {
+ for (Standard_Integer anIdx = 0; anIdx < 3; ++anIdx)
+ {
+ if (IsReflect)
+ {
+ aFaceTriangles->AddVertex (aCoords (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 1),
+ aCoords (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 2),
+ aCoords (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 3),
+ aHasNormals ? aNormals->Value (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 1) : 0.0,
+ aHasNormals ? aNormals->Value (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 2) : 0.0,
+ aHasNormals ? aNormals->Value (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 3) : 1.0);
+ }
+ else
+ {
+ aFaceTriangles->AddVertex (aCoords (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 1),
+ aCoords (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 2),
+ aCoords (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 3));
+ }
+ }
+ }
- for ( i=1; i<=NbNodes; i++ )
+ if (anEdgeOn)
{
- if ( IsReflect )
+ for (Standard_Integer aNodeIdx = 0; aNodeIdx < NbNodes; ++aNodeIdx)
{
- hasNormals ? aPolyArr->AddVertex ( aCoords(3 * i - 2),
- aCoords(3 * i - 1),
- aCoords(3 * i ),
- aNormals->Value(3 * i - 2),
- aNormals->Value(3 * i - 1),
- aNormals->Value(3 * i ) ) :
- aPolyArr->AddVertex ( aCoords(3 * i - 2),
- aCoords(3 * i - 1),
- aCoords(3 * i ),
- 0.,
- 0.,
- 1. );
+ const Standard_Integer aNextIdx = (aNodeIdx + 1) % NbNodes;
+
+ anEdgeSegments->AddVertex (aCoords (3 * aNodeIdx + 1),
+ aCoords (3 * aNodeIdx + 2),
+ aCoords (3 * aNodeIdx + 3));
+
+ anEdgeSegments->AddVertex (aCoords (3 * aNextIdx + 1),
+ aCoords (3 * aNextIdx + 2),
+ aCoords (3 * aNextIdx + 3));
}
- else
- aPolyArr->AddVertex ( aCoords(3*i-2),
- aCoords(3*i-1),
- aCoords(3*i ) );
}
}
}
}
- aGroup2->AddPrimitiveArray ( aPolyArr );
+
+ aGroup2->AddPrimitiveArray (aFaceTriangles);
+ aSGroup->AddPrimitiveArray (anEdgeSegments);
}
}