3D-Viewer: OpenGL outline, implement an outline board cut

This commit is contained in:
Mario Luzeiro 2020-11-03 09:38:07 +00:00 committed by Wayne Stambaugh
parent 3fce3b6591
commit 78b461a41d
5 changed files with 82 additions and 64 deletions

View File

@ -455,11 +455,9 @@ CLAYERS_OGL_DISP_LISTS* C3D_RENDER_OGL_LEGACY::createBoard( const SHAPE_POLY_SET
layer_z_bot ); layer_z_bot );
} }
const SHAPE_POLY_SET &boardPoly = m_boardAdapter.GetBoardPoly(); if( aBoardPoly.OutlineCount() > 0 )
if( boardPoly.OutlineCount() > 0 )
{ {
layerTriangles->AddToMiddleContourns( boardPoly, layerTriangles->AddToMiddleContourns( aBoardPoly,
layer_z_bot, layer_z_bot,
layer_z_top, layer_z_top,
m_boardAdapter.BiuTo3Dunits(), m_boardAdapter.BiuTo3Dunits(),
@ -501,16 +499,22 @@ void C3D_RENDER_OGL_LEGACY::reload( REPORTER* aStatusReporter, REPORTER* aWarnin
m_ogl_disp_list_board = createBoard( m_boardAdapter.GetBoardPoly() ); m_ogl_disp_list_board = createBoard( m_boardAdapter.GetBoardPoly() );
SHAPE_POLY_SET anti_board; m_anti_board_poly.RemoveAllContours();
anti_board.NewOutline(); m_anti_board_poly.NewOutline();
anti_board.Append( VECTOR2I( -INT_MAX/2, -INT_MAX/2 ) ); m_anti_board_poly.Append( VECTOR2I( -INT_MAX/2, -INT_MAX/2 ) );
anti_board.Append( VECTOR2I( INT_MAX/2, -INT_MAX/2 ) ); m_anti_board_poly.Append( VECTOR2I( INT_MAX/2, -INT_MAX/2 ) );
anti_board.Append( VECTOR2I( INT_MAX/2, INT_MAX/2 ) ); m_anti_board_poly.Append( VECTOR2I( INT_MAX/2, INT_MAX/2 ) );
anti_board.Append( VECTOR2I( -INT_MAX/2, INT_MAX/2 ) ); m_anti_board_poly.Append( VECTOR2I( -INT_MAX/2, INT_MAX/2 ) );
anti_board.Outline( 0 ).SetClosed( true ); m_anti_board_poly.Outline( 0 ).SetClosed( true );
anti_board.BooleanSubtract( m_boardAdapter.GetBoardPoly(), SHAPE_POLY_SET::PM_FAST ); m_anti_board_poly.BooleanSubtract( m_boardAdapter.GetBoardPoly(), SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
m_ogl_disp_list_anti_board = createBoard( anti_board ); m_ogl_disp_list_anti_board = createBoard( m_anti_board_poly );
SHAPE_POLY_SET board_poly_with_holes = m_boardAdapter.GetBoardPoly();
board_poly_with_holes.BooleanSubtract( m_boardAdapter.GetThroughHole_Outer_poly(), SHAPE_POLY_SET::PM_FAST );
board_poly_with_holes.BooleanSubtract( m_boardAdapter.GetThroughHole_Outer_poly_NPTH(), SHAPE_POLY_SET::PM_FAST );
m_ogl_disp_list_board_with_holes = createBoard( board_poly_with_holes );
if( m_ogl_disp_list_anti_board ) if( m_ogl_disp_list_anti_board )
m_ogl_disp_list_anti_board->SetItIsTransparent( true ); m_ogl_disp_list_anti_board->SetItIsTransparent( true );
@ -521,21 +525,12 @@ void C3D_RENDER_OGL_LEGACY::reload( REPORTER* aStatusReporter, REPORTER* aWarnin
if( aStatusReporter ) if( aStatusReporter )
aStatusReporter->Report( _( "Load OpenGL: holes and vias" ) ); aStatusReporter->Report( _( "Load OpenGL: holes and vias" ) );
SHAPE_POLY_SET outerPolyTHT = m_boardAdapter.GetThroughHole_Outer_poly();
outerPolyTHT.BooleanIntersection( m_boardAdapter.GetBoardPoly(), SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
m_ogl_disp_list_through_holes_outer = generate_holes_display_list( m_ogl_disp_list_through_holes_outer = generate_holes_display_list(
m_boardAdapter.GetThroughHole_Outer().GetList(), m_boardAdapter.GetThroughHole_Outer().GetList(),
m_boardAdapter.GetThroughHole_Outer_poly(), outerPolyTHT,
1.0f,
0.0f,
false );
SHAPE_POLY_SET bodyHoles = m_boardAdapter.GetThroughHole_Outer_poly();
bodyHoles.BooleanAdd( m_boardAdapter.GetThroughHole_Outer_poly_NPTH(),
SHAPE_POLY_SET::PM_FAST );
m_ogl_disp_list_through_holes_outer_with_npth = generate_holes_display_list(
m_boardAdapter.GetThroughHole_Outer().GetList(),
bodyHoles,
1.0f, 1.0f,
0.0f, 0.0f,
false ); false );
@ -634,7 +629,19 @@ void C3D_RENDER_OGL_LEGACY::reload( REPORTER* aStatusReporter, REPORTER* aWarnin
aPolyList = map_poly.at( layer_id ); aPolyList = map_poly.at( layer_id );
} }
CLAYERS_OGL_DISP_LISTS* oglList = generateLayerListFromContainer( container2d, aPolyList, layer_id ); SHAPE_POLY_SET polyListSubtracted;
polyListSubtracted = *aPolyList;
polyListSubtracted.BooleanIntersection( m_boardAdapter.GetBoardPoly(), SHAPE_POLY_SET::PM_FAST );
if( ( layer_id != B_Mask ) &&
( layer_id != F_Mask ) )
{
polyListSubtracted.BooleanSubtract( m_boardAdapter.GetThroughHole_Outer_poly(), SHAPE_POLY_SET::PM_FAST );
polyListSubtracted.BooleanSubtract( m_boardAdapter.GetThroughHole_Outer_poly_NPTH(), SHAPE_POLY_SET::PM_FAST );
}
CLAYERS_OGL_DISP_LISTS* oglList = generateLayerListFromContainer( container2d, &polyListSubtracted, layer_id );
if( oglList != nullptr ) if( oglList != nullptr )
m_ogl_disp_lists_layers[layer_id] = oglList; m_ogl_disp_lists_layers[layer_id] = oglList;
@ -834,7 +841,7 @@ void C3D_RENDER_OGL_LEGACY::generate_3D_Vias_and_Pads()
// Subtract the holes // Subtract the holes
tht_outer_holes_poly.BooleanSubtract( tht_inner_holes_poly, SHAPE_POLY_SET::PM_FAST ); tht_outer_holes_poly.BooleanSubtract( tht_inner_holes_poly, SHAPE_POLY_SET::PM_FAST );
tht_outer_holes_poly.BooleanSubtract( m_anti_board_poly, SHAPE_POLY_SET::PM_FAST );
CCONTAINER2D holesContainer; CCONTAINER2D holesContainer;

View File

@ -64,7 +64,6 @@ C3D_RENDER_OGL_LEGACY::C3D_RENDER_OGL_LEGACY( BOARD_ADAPTER& aAdapter, CCAMERA&
m_ogl_disp_lists_platedPads_F_Cu = nullptr; m_ogl_disp_lists_platedPads_F_Cu = nullptr;
m_ogl_disp_lists_platedPads_B_Cu = nullptr; m_ogl_disp_lists_platedPads_B_Cu = nullptr;
m_ogl_disp_list_through_holes_outer_with_npth = NULL;
m_ogl_disp_list_through_holes_outer = NULL; m_ogl_disp_list_through_holes_outer = NULL;
m_ogl_disp_list_through_holes_outer_ring = NULL; m_ogl_disp_list_through_holes_outer_ring = NULL;
m_ogl_disp_list_through_holes_vias_outer = NULL; m_ogl_disp_list_through_holes_vias_outer = NULL;
@ -528,33 +527,26 @@ void C3D_RENDER_OGL_LEGACY::unsetDepthOffset()
void C3D_RENDER_OGL_LEGACY::render_board_body( bool aSkipRenderHoles ) void C3D_RENDER_OGL_LEGACY::render_board_body( bool aSkipRenderHoles )
{ {
if( m_ogl_disp_list_board ) m_materials.m_EpoxyBoard.m_Diffuse = m_boardAdapter.m_BoardBodyColor;
m_materials.m_EpoxyBoard.m_Transparency = 1.0f - m_boardAdapter.m_BoardBodyColor.a; // opacity to transparency
OGL_SetMaterial( m_materials.m_EpoxyBoard, 1.0f );
CLAYERS_OGL_DISP_LISTS* ogl_disp_list = nullptr;
if( aSkipRenderHoles )
ogl_disp_list = m_ogl_disp_list_board;
else
ogl_disp_list = m_ogl_disp_list_board_with_holes;
if( ogl_disp_list )
{ {
m_ogl_disp_list_board->ApplyScalePosition( -m_boardAdapter.GetEpoxyThickness3DU() / 2.0f, ogl_disp_list->ApplyScalePosition( -m_boardAdapter.GetEpoxyThickness3DU() / 2.0f,
m_boardAdapter.GetEpoxyThickness3DU() ); m_boardAdapter.GetEpoxyThickness3DU() );
ogl_disp_list->SetItIsTransparent( true );
m_materials.m_EpoxyBoard.m_Diffuse = m_boardAdapter.m_BoardBodyColor; ogl_disp_list->DrawAll();
m_materials.m_EpoxyBoard.m_Transparency = 1.0f - m_boardAdapter.m_BoardBodyColor.a; // opacity to transparency
OGL_SetMaterial( m_materials.m_EpoxyBoard, 1.0f );
m_ogl_disp_list_board->SetItIsTransparent( true );
if( (m_ogl_disp_list_through_holes_outer_with_npth) && (!aSkipRenderHoles) )
{
m_ogl_disp_list_through_holes_outer_with_npth->ApplyScalePosition(
-m_boardAdapter.GetEpoxyThickness3DU() / 2.0f,
m_boardAdapter.GetEpoxyThickness3DU() );
m_ogl_disp_list_board->DrawAllCameraCulledSubtractLayer(
true,
m_ogl_disp_list_through_holes_outer_with_npth );
}
else
{
m_ogl_disp_list_board->DrawAll();
}
} }
} }
@ -767,6 +759,12 @@ bool C3D_RENDER_OGL_LEGACY::Redraw(
pLayerDispList->GetZBot(), pLayerDispList->GetZBot(),
pLayerDispList->GetZTop() - pLayerDispList->GetZBot() ); pLayerDispList->GetZTop() - pLayerDispList->GetZBot() );
if( m_ogl_disp_list_anti_board )
{
m_ogl_disp_list_anti_board->ApplyScalePosition( pLayerDispList->GetZBot(),
pLayerDispList->GetZTop() - pLayerDispList->GetZBot() );
}
if( m_ogl_disp_lists_layers_holes_outer.find( layer_id ) != if( m_ogl_disp_lists_layers_holes_outer.find( layer_id ) !=
m_ogl_disp_lists_layers_holes_outer.end() ) m_ogl_disp_lists_layers_holes_outer.end() )
{ {
@ -780,7 +778,8 @@ bool C3D_RENDER_OGL_LEGACY::Redraw(
pLayerDispList->DrawAllCameraCulledSubtractLayer( pLayerDispList->DrawAllCameraCulledSubtractLayer(
drawMiddleSegments, drawMiddleSegments,
m_ogl_disp_list_through_holes_outer, m_ogl_disp_list_through_holes_outer,
viasHolesLayer ); viasHolesLayer,
m_ogl_disp_list_anti_board );
// Draw copper plated pads // Draw copper plated pads
@ -793,14 +792,16 @@ bool C3D_RENDER_OGL_LEGACY::Redraw(
m_ogl_disp_lists_platedPads_F_Cu->DrawAllCameraCulledSubtractLayer( m_ogl_disp_lists_platedPads_F_Cu->DrawAllCameraCulledSubtractLayer(
drawMiddleSegments, drawMiddleSegments,
m_ogl_disp_list_through_holes_outer, m_ogl_disp_list_through_holes_outer,
viasHolesLayer ); viasHolesLayer,
m_ogl_disp_list_anti_board );
} }
else if( ( layer_id == B_Cu ) && m_ogl_disp_lists_platedPads_B_Cu ) else if( ( layer_id == B_Cu ) && m_ogl_disp_lists_platedPads_B_Cu )
{ {
m_ogl_disp_lists_platedPads_B_Cu->DrawAllCameraCulledSubtractLayer( m_ogl_disp_lists_platedPads_B_Cu->DrawAllCameraCulledSubtractLayer(
drawMiddleSegments, drawMiddleSegments,
m_ogl_disp_list_through_holes_outer, m_ogl_disp_list_through_holes_outer,
viasHolesLayer ); viasHolesLayer,
m_ogl_disp_list_anti_board );
} }
unsetDepthOffset(); unsetDepthOffset();
@ -810,7 +811,8 @@ bool C3D_RENDER_OGL_LEGACY::Redraw(
{ {
pLayerDispList->DrawAllCameraCulledSubtractLayer( pLayerDispList->DrawAllCameraCulledSubtractLayer(
drawMiddleSegments, drawMiddleSegments,
m_ogl_disp_list_through_holes_outer ); m_ogl_disp_list_through_holes_outer,
m_ogl_disp_list_anti_board );
// Draw copper plated pads // Draw copper plated pads
@ -824,13 +826,15 @@ bool C3D_RENDER_OGL_LEGACY::Redraw(
{ {
m_ogl_disp_lists_platedPads_F_Cu->DrawAllCameraCulledSubtractLayer( m_ogl_disp_lists_platedPads_F_Cu->DrawAllCameraCulledSubtractLayer(
drawMiddleSegments, drawMiddleSegments,
m_ogl_disp_list_through_holes_outer ); m_ogl_disp_list_through_holes_outer,
m_ogl_disp_list_anti_board );
} }
else if( ( layer_id == B_Cu ) && m_ogl_disp_lists_platedPads_B_Cu ) else if( ( layer_id == B_Cu ) && m_ogl_disp_lists_platedPads_B_Cu )
{ {
m_ogl_disp_lists_platedPads_B_Cu->DrawAllCameraCulledSubtractLayer( m_ogl_disp_lists_platedPads_B_Cu->DrawAllCameraCulledSubtractLayer(
drawMiddleSegments, drawMiddleSegments,
m_ogl_disp_list_through_holes_outer ); m_ogl_disp_list_through_holes_outer,
m_ogl_disp_list_anti_board );
} }
unsetDepthOffset(); unsetDepthOffset();
@ -1155,9 +1159,6 @@ void C3D_RENDER_OGL_LEGACY::ogl_free_all_display_lists()
delete m_ogl_disp_list_anti_board; delete m_ogl_disp_list_anti_board;
m_ogl_disp_list_anti_board = nullptr; m_ogl_disp_list_anti_board = nullptr;
delete m_ogl_disp_list_through_holes_outer_with_npth;
m_ogl_disp_list_through_holes_outer_with_npth = nullptr;
delete m_ogl_disp_list_through_holes_outer; delete m_ogl_disp_list_through_holes_outer;
m_ogl_disp_list_through_holes_outer = nullptr; m_ogl_disp_list_through_holes_outer = nullptr;

View File

@ -85,6 +85,7 @@ private:
MAP_OGL_DISP_LISTS m_ogl_disp_lists_layers_holes_outer; MAP_OGL_DISP_LISTS m_ogl_disp_lists_layers_holes_outer;
MAP_OGL_DISP_LISTS m_ogl_disp_lists_layers_holes_inner; MAP_OGL_DISP_LISTS m_ogl_disp_lists_layers_holes_inner;
CLAYERS_OGL_DISP_LISTS* m_ogl_disp_list_board; CLAYERS_OGL_DISP_LISTS* m_ogl_disp_list_board;
CLAYERS_OGL_DISP_LISTS* m_ogl_disp_list_board_with_holes;
CLAYERS_OGL_DISP_LISTS* m_ogl_disp_list_anti_board; CLAYERS_OGL_DISP_LISTS* m_ogl_disp_list_anti_board;
CLAYERS_OGL_DISP_LISTS* m_ogl_disp_list_through_holes_outer; CLAYERS_OGL_DISP_LISTS* m_ogl_disp_list_through_holes_outer;
@ -114,6 +115,8 @@ private:
BOARD_ITEM* m_currentIntersectedBoardItem; BOARD_ITEM* m_currentIntersectedBoardItem;
SHAPE_POLY_SET m_anti_board_poly; ///< negative polygon representation of the board outline
private: private:
CLAYERS_OGL_DISP_LISTS *generate_holes_display_list( const LIST_OBJECT2D &aListHolesObject2d, CLAYERS_OGL_DISP_LISTS *generate_holes_display_list( const LIST_OBJECT2D &aListHolesObject2d,
const SHAPE_POLY_SET &aPoly, const SHAPE_POLY_SET &aPoly,

View File

@ -524,7 +524,8 @@ void CLAYERS_OGL_DISP_LISTS::DrawAllCameraCulled(float zCameraPos, bool aDrawMid
void CLAYERS_OGL_DISP_LISTS::DrawAllCameraCulledSubtractLayer( bool aDrawMiddle, void CLAYERS_OGL_DISP_LISTS::DrawAllCameraCulledSubtractLayer( bool aDrawMiddle,
const CLAYERS_OGL_DISP_LISTS *aLayerToSubtractA, const CLAYERS_OGL_DISP_LISTS *aLayerToSubtractA,
const CLAYERS_OGL_DISP_LISTS *aLayerToSubtractB, const CLAYERS_OGL_DISP_LISTS *aLayerToSubtractB,
const CLAYERS_OGL_DISP_LISTS *aLayerToSubtractC ) const const CLAYERS_OGL_DISP_LISTS *aLayerToSubtractC,
const CLAYERS_OGL_DISP_LISTS *aLayerToSubtractD ) const
{ {
glClearStencil( 0x00 ); glClearStencil( 0x00 );
glClear( GL_STENCIL_BUFFER_BIT ); glClear( GL_STENCIL_BUFFER_BIT );
@ -548,6 +549,8 @@ void CLAYERS_OGL_DISP_LISTS::DrawAllCameraCulledSubtractLayer( bool aDrawMiddle,
if( aLayerToSubtractC ) if( aLayerToSubtractC )
aLayerToSubtractC->DrawBot(); aLayerToSubtractC->DrawBot();
if( aLayerToSubtractD )
aLayerToSubtractD->DrawBot();
//if( !m_draw_it_transparent ) //if( !m_draw_it_transparent )
{ {
@ -576,6 +579,9 @@ void CLAYERS_OGL_DISP_LISTS::DrawAllCameraCulledSubtractLayer( bool aDrawMiddle,
if( aLayerToSubtractC ) if( aLayerToSubtractC )
aLayerToSubtractC->DrawTop(); aLayerToSubtractC->DrawTop();
if( aLayerToSubtractD )
aLayerToSubtractD->DrawTop();
//if( !m_draw_it_transparent ) //if( !m_draw_it_transparent )
{ {
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);

View File

@ -256,7 +256,8 @@ public:
void DrawAllCameraCulledSubtractLayer( bool aDrawMiddle, void DrawAllCameraCulledSubtractLayer( bool aDrawMiddle,
const CLAYERS_OGL_DISP_LISTS* aLayerToSubtractA = nullptr, const CLAYERS_OGL_DISP_LISTS* aLayerToSubtractA = nullptr,
const CLAYERS_OGL_DISP_LISTS* aLayerToSubtractB = nullptr, const CLAYERS_OGL_DISP_LISTS* aLayerToSubtractB = nullptr,
const CLAYERS_OGL_DISP_LISTS* aLayerToSubtractC = nullptr ) const; const CLAYERS_OGL_DISP_LISTS* aLayerToSubtractC = nullptr,
const CLAYERS_OGL_DISP_LISTS* aLayerToSubtractD = nullptr ) const;
void ApplyScalePosition( float aZposition, float aZscale ); void ApplyScalePosition( float aZposition, float aZscale );