3d-viewer, add an option to subtract Mask from Silk

Remove holes on Silk layer by default so the behaviour is the same
on OpenGL and Raytracing.
Fixes #1836
Fix raytracing shadow offset issue.
Some codestyle fix.
This commit is contained in:
Mario Luzeiro 2020-01-29 16:00:05 +00:00
parent 418dba440d
commit 970a0a593a
11 changed files with 480 additions and 1342 deletions

View File

@ -103,6 +103,7 @@ CINFO3D_VISU::CINFO3D_VISU() :
SetFlag( FL_ZONE, true );
SetFlag( FL_SILKSCREEN, true );
SetFlag( FL_SOLDERMASK, true );
SetFlag( FL_SUBTRACT_MASK_FROM_SILK, false );
m_BgColorBot = SFVEC3D( 0.4, 0.4, 0.5 );
m_BgColorTop = SFVEC3D( 0.8, 0.8, 0.9 );

View File

@ -32,9 +32,14 @@
/// Flags used in rendering options
enum DISPLAY3D_FLG {
FL_AXIS=0, FL_ZONE,
FL_ADHESIVE, FL_SILKSCREEN, FL_SOLDERMASK, FL_SOLDERPASTE,
FL_COMMENTS, FL_ECO,
FL_AXIS = 0,
FL_ZONE,
FL_ADHESIVE,
FL_SILKSCREEN,
FL_SOLDERMASK,
FL_SOLDERPASTE,
FL_COMMENTS,
FL_ECO,
FL_MODULE_ATTRIBUTES_NORMAL,
FL_MODULE_ATTRIBUTES_NORMAL_INSERT,
@ -43,6 +48,7 @@ enum DISPLAY3D_FLG {
FL_SHOW_BOARD_BODY,
FL_MOUSEWHEEL_PANNING,
FL_USE_REALISTIC_MODE,
FL_SUBTRACT_MASK_FROM_SILK,
// OpenGL options
FL_RENDER_OPENGL_SHOW_MODEL_BBOX,

View File

@ -734,10 +734,42 @@ bool C3D_RENDER_OGL_LEGACY::Redraw( bool aIsMoving,
}
}
else
{
if( m_settings.GetFlag( FL_SUBTRACT_MASK_FROM_SILK ) &&
( ( ( layer_id == B_SilkS ) &&
( m_ogl_disp_lists_layers.find( B_Mask ) != m_ogl_disp_lists_layers.end() ) ) ||
( ( layer_id == F_SilkS ) &&
( m_ogl_disp_lists_layers.find( F_Mask ) != m_ogl_disp_lists_layers.end() ) ) ) )
{
const PCB_LAYER_ID layerMask_id = (layer_id == B_SilkS)?B_Mask:F_Mask;
const CLAYERS_OGL_DISP_LISTS *pLayerDispListMask = m_ogl_disp_lists_layers.at( layerMask_id );
pLayerDispList->DrawAllCameraCulledSubtractLayer(
pLayerDispListMask,
m_ogl_disp_list_through_holes_vias_outer,
(aIsMoving == false) );
}
else
{
if( m_ogl_disp_list_through_holes_vias_outer &&
( ( layer_id == B_SilkS ) || ( layer_id == F_SilkS )
// Remove vias on SolderPaste can be added as an option in future
// ( layer_id == B_Paste ) || ( layer_id == F_Paste ) )
) )
{
pLayerDispList->DrawAllCameraCulledSubtractLayer(
NULL,
m_ogl_disp_list_through_holes_vias_outer,
(aIsMoving == false) );
}
else
{
pLayerDispList->DrawAllCameraCulled( m_settings.CameraGet().GetPos().z,
(aIsMoving == false) );
}
}
}
glPopMatrix();
}
@ -762,6 +794,11 @@ bool C3D_RENDER_OGL_LEGACY::Redraw( bool aIsMoving,
//setLight_Top( true );
//setLight_Bottom( true );
// add a depth buffer offset, it will help to hide some artifacts
// on silkscreen where the SolderMask is removed
glEnable( GL_POLYGON_OFFSET_FILL );
glPolygonOffset( 0.0f, -1.0f );
if( m_settings.CameraGet().GetPos().z > 0 )
{
render_solder_mask_layer( B_Mask, m_settings.GetLayerTopZpos3DU( B_Mask ),
@ -778,6 +815,9 @@ bool C3D_RENDER_OGL_LEGACY::Redraw( bool aIsMoving,
render_solder_mask_layer( B_Mask, m_settings.GetLayerTopZpos3DU( B_Mask ),
aIsMoving );
}
glDisable( GL_POLYGON_OFFSET_FILL );
glPolygonOffset( 0.0f, 0.0f );
}

View File

@ -526,9 +526,6 @@ void CLAYERS_OGL_DISP_LISTS::DrawAllCameraCulledSubtractLayer(
const CLAYERS_OGL_DISP_LISTS *aLayerToSubtractB,
bool aDrawMiddle ) const
{
if( aDrawMiddle )
DrawMiddle();
glClearStencil( 0x00 );
glClear( GL_STENCIL_BUFFER_BIT );
@ -584,6 +581,8 @@ void CLAYERS_OGL_DISP_LISTS::DrawAllCameraCulledSubtractLayer(
glStencilOp( GL_KEEP, GL_KEEP, GL_INCR );
DrawTop();
if( aDrawMiddle )
DrawMiddle();
glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE );

View File

@ -539,10 +539,12 @@ void C3D_RENDER_RAYTRACING::reload( REPORTER *aStatusTextReporter )
std::vector<const COBJECT2D *> *object2d_B = CSGITEM_EMPTY;
if( true ) // previously, was a option, now holes are always drawn in zones
{
object2d_B = new std::vector<const COBJECT2D *>();
object2d_B = new std::vector<const COBJECT2D*>();
// Subtract holes but not in SolderPaste
// (can be added as an option in future)
if( !( ( layer_id == B_Paste ) || ( layer_id == F_Paste ) ) )
{
// Check if there are any layerhole that intersects this object
// Eg: a segment is cutted by a via hole or THT hole.
// /////////////////////////////////////////////////////////////
@ -555,7 +557,6 @@ void C3D_RENDER_RAYTRACING::reload( REPORTER *aStatusTextReporter )
const CBVHCONTAINER2D *containerLayerHoles2d =
static_cast<const CBVHCONTAINER2D *>(ii_hole->second);
CONST_LIST_OBJECT2D intersectionList;
containerLayerHoles2d->GetListObjectsIntersects( object2d_A->GetBBox(),
intersectionList );
@ -600,13 +601,45 @@ void C3D_RENDER_RAYTRACING::reload( REPORTER *aStatusTextReporter )
}
}
}
}
const MAP_CONTAINER_2D& mapLayers = m_settings.GetMapLayers();
if( m_settings.GetFlag( FL_SUBTRACT_MASK_FROM_SILK ) &&
( ( ( layer_id == B_SilkS ) &&
( mapLayers.find( B_Mask ) != mapLayers.end() ) ) ||
( ( layer_id == F_SilkS ) &&
( mapLayers.find( F_Mask ) != mapLayers.end() ) ) ) )
{
const PCB_LAYER_ID layerMask_id = ( layer_id == B_SilkS ) ? B_Mask : F_Mask;
const CBVHCONTAINER2D *containerMaskLayer2d =
static_cast<const CBVHCONTAINER2D*>( mapLayers.at( layerMask_id ) );
CONST_LIST_OBJECT2D intersectionList;
containerMaskLayer2d->GetListObjectsIntersects( object2d_A->GetBBox(),
intersectionList );
if( !intersectionList.empty() )
{
for( CONST_LIST_OBJECT2D::const_iterator objOnLayer =
intersectionList.begin();
objOnLayer != intersectionList.end();
++objOnLayer )
{
const COBJECT2D* obj2d = static_cast<const COBJECT2D*>( *objOnLayer );
object2d_B->push_back( obj2d );
}
}
}
if( object2d_B->empty() )
{
delete object2d_B;
object2d_B = CSGITEM_EMPTY;
}
}
if( (object2d_B == CSGITEM_EMPTY) &&
(object2d_C == CSGITEM_FULL) )

View File

@ -1727,7 +1727,7 @@ SFVEC3F C3D_RENDER_RAYTRACING::shadeHit( const SFVEC3F &aBgColor,
SFVEC3F hitPoint = aHitInfo.m_HitPoint;
if( !m_isPreview )
hitPoint += aHitInfo.m_HitNormal * m_settings.GetNonCopperLayerThickness3DU() * 1.0f;
hitPoint += aHitInfo.m_HitNormal * m_settings.GetNonCopperLayerThickness3DU() * 1.2f;
const CMATERIAL *objMaterial = aHitInfo.pHitObject->GetMaterial();
wxASSERT( objMaterial != NULL );

View File

@ -87,6 +87,7 @@ void DIALOG_3D_VIEW_OPTIONS::initDialog()
m_bitmapAdhesive->SetBitmap( KiBitmap( tools_xpm ) );
m_bitmapComments->SetBitmap( KiBitmap( editor_xpm ) );
m_bitmapECO->SetBitmap( KiBitmap( editor_xpm ) );
m_bitmapSubtractMaskFromSilk->SetBitmap( KiBitmap( use_3D_copper_thickness_xpm ) );
}
@ -109,6 +110,7 @@ bool DIALOG_3D_VIEW_OPTIONS::TransferDataToWindow()
m_checkBoxAdhesive->SetValue( m_3Dprms.GetFlag( FL_ADHESIVE ) );
m_checkBoxComments->SetValue( m_3Dprms.GetFlag( FL_COMMENTS ) );
m_checkBoxECO->SetValue( m_3Dprms.GetFlag( FL_ECO ) );
m_checkBoxSubtractMaskFromSilk->SetValue( m_3Dprms.GetFlag( FL_SUBTRACT_MASK_FROM_SILK ) );
return true;
}
@ -124,6 +126,7 @@ bool DIALOG_3D_VIEW_OPTIONS::TransferDataFromWindow()
m_3Dprms.SetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS, m_checkBoxCuThickness->GetValue() );
m_3Dprms.SetFlag( FL_ZONE, m_checkBoxAreas->GetValue() );
m_3Dprms.SetFlag( FL_RENDER_OPENGL_SHOW_MODEL_BBOX, m_checkBoxBoundingBoxes->GetValue() );
m_3Dprms.SetFlag( FL_SUBTRACT_MASK_FROM_SILK, m_checkBoxSubtractMaskFromSilk->GetValue() );
// Set 3D shapes visibility
m_3Dprms.SetFlag( FL_MODULE_ATTRIBUTES_NORMAL, m_checkBox3DshapesTH->GetValue() );

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Jul 11 2018)
// C++ code generated with wxFormBuilder (version Oct 26 2018)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -78,6 +78,15 @@ DIALOG_3D_VIEW_OPTIONS_BASE::DIALOG_3D_VIEW_OPTIONS_BASE( wxWindow* parent, wxWi
m_checkBoxAreas = new wxCheckBox( this, wxID_ANY, _("Show filled areas in zones"), wxDefaultPosition, wxDefaultSize, 0 );
fgSizerRenderOptions->Add( m_checkBoxAreas, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
fgSizerRenderOptions->Add( 0, 0, 0, wxALIGN_LEFT|wxALIGN_RIGHT, 10 );
m_bitmapSubtractMaskFromSilk = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 );
fgSizerRenderOptions->Add( m_bitmapSubtractMaskFromSilk, 0, wxALL, 5 );
m_checkBoxSubtractMaskFromSilk = new wxCheckBox( this, wxID_ANY, _("Subtract soldermask from silkscreen"), wxDefaultPosition, wxDefaultSize, 0 );
fgSizerRenderOptions->Add( m_checkBoxSubtractMaskFromSilk, 0, wxALL, 5 );
wxFlexGridSizer* fgSizer3;
fgSizer3 = new wxFlexGridSizer( 0, 2, 0, 0 );
fgSizer3->SetFlexibleDirection( wxBOTH );

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,11 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Jul 11 2018)
// C++ code generated with wxFormBuilder (version Oct 26 2018)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#ifndef __DIALOG_3D_VIEW_OPTION_BASE_H__
#define __DIALOG_3D_VIEW_OPTION_BASE_H__
#pragma once
#include <wx/artprov.h>
#include <wx/xrc/xmlres.h>
@ -50,6 +49,8 @@ class DIALOG_3D_VIEW_OPTIONS_BASE : public DIALOG_SHIM
wxCheckBox* m_checkBoxBoundingBoxes;
wxStaticBitmap* m_bitmapAreas;
wxCheckBox* m_checkBoxAreas;
wxStaticBitmap* m_bitmapSubtractMaskFromSilk;
wxCheckBox* m_checkBoxSubtractMaskFromSilk;
wxStaticText* m_staticText3DmodelVisibility;
wxStaticBitmap* m_bitmap3DshapesTH;
wxCheckBox* m_checkBox3DshapesTH;
@ -88,4 +89,3 @@ class DIALOG_3D_VIEW_OPTIONS_BASE : public DIALOG_SHIM
};
#endif //__DIALOG_3D_VIEW_OPTION_BASE_H__

View File

@ -87,6 +87,7 @@ static const wxChar keyBoardBodyColor_Green[] = wxT( "BoardBodyColor_Green" );
static const wxChar keyBoardBodyColor_Blue[] = wxT( "BoardBodyColor_Blue" );
static const wxChar keyShowRealisticMode[] = wxT( "ShowRealisticMode" );
static const wxChar keySubtractMaskFromSilk[] = wxT( "SubtractMaskFromSilk" );
static const wxChar keyRenderEngine[] = wxT( "RenderEngine" );
static const wxChar keyRenderMaterial[] = wxT( "Render_Material" );
@ -756,6 +757,9 @@ void EDA_3D_VIEWER::LoadSettings( wxConfigBase *aCfg )
aCfg->Read( keyShowRealisticMode, &tmp, true );
m_settings.SetFlag( FL_USE_REALISTIC_MODE, tmp );
aCfg->Read( keySubtractMaskFromSilk, &tmp, false );
m_settings.SetFlag( FL_SUBTRACT_MASK_FROM_SILK, tmp );
// OpenGL options
aCfg->Read( keyRenderOGL_ShowCopperTck, &tmp, true );
m_settings.SetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS, tmp );
@ -879,13 +883,14 @@ void EDA_3D_VIEWER::SaveSettings( wxConfigBase *aCfg )
aCfg->Write( keyBoardBodyColor_Blue, m_settings.m_BoardBodyColor.b );
aCfg->Write( keyShowRealisticMode, m_settings.GetFlag( FL_USE_REALISTIC_MODE ) );
aCfg->Write( keySubtractMaskFromSilk, m_settings.GetFlag( FL_SUBTRACT_MASK_FROM_SILK ) );
aCfg->Write( keyRenderEngine, static_cast<int>( m_settings.RenderEngineGet() ) );
wxLogTrace( m_logTrace, "EDA_3D_VIEWER::SaveSettings render setting %s",
( m_settings.RenderEngineGet() == RENDER_ENGINE::RAYTRACING ) ? "Ray Trace" :
"OpenGL" );
aCfg->Write( keyRenderMaterial, (int)m_settings.MaterialModeGet() );
aCfg->Write( keyRenderMaterial, (int) m_settings.MaterialModeGet() );
// OpenGL options
aCfg->Write( keyRenderOGL_ShowCopperTck,