diff --git a/3d-viewer/3d_canvas/board_adapter.cpp b/3d-viewer/3d_canvas/board_adapter.cpp index 9446db6016..a78c8fcf9c 100644 --- a/3d-viewer/3d_canvas/board_adapter.cpp +++ b/3d-viewer/3d_canvas/board_adapter.cpp @@ -726,8 +726,8 @@ void BOARD_ADAPTER::SetVisibleLayers( const std::bitset& aLayers ) m_Cfg->m_Render.show_fp_values = aLayers.test( LAYER_FP_VALUES ); m_Cfg->m_Render.show_fp_text = aLayers.test( LAYER_FP_TEXT ); - m_Cfg->m_Render.opengl_show_model_bbox = aLayers.test( LAYER_3D_BOUNDING_BOXES ); - m_Cfg->m_Render.opengl_show_off_board_silk = aLayers.test( LAYER_3D_OFF_BOARD_SILK ); + m_Cfg->m_Render.show_model_bbox = aLayers.test( LAYER_3D_BOUNDING_BOXES ); + m_Cfg->m_Render.show_off_board_silk = aLayers.test( LAYER_3D_OFF_BOARD_SILK ); m_Cfg->m_Render.show_axis = aLayers.test( LAYER_3D_AXES ); } @@ -760,8 +760,8 @@ std::bitset BOARD_ADAPTER::GetVisibleLayers() const ret.set( LAYER_3D_MODELS_NOT_IN_POS, m_Cfg->m_Render.show_footprints_not_in_posfile ); ret.set( LAYER_3D_MODELS_MARKED_DNP, m_Cfg->m_Render.show_footprints_dnp ); - ret.set( LAYER_3D_BOUNDING_BOXES, m_Cfg->m_Render.opengl_show_model_bbox ); - ret.set( LAYER_3D_OFF_BOARD_SILK, m_Cfg->m_Render.opengl_show_off_board_silk ); + ret.set( LAYER_3D_BOUNDING_BOXES, m_Cfg->m_Render.show_model_bbox ); + ret.set( LAYER_3D_OFF_BOARD_SILK, m_Cfg->m_Render.show_off_board_silk ); ret.set( LAYER_3D_AXES, m_Cfg->m_Render.show_axis ); if( m_Cfg->m_CurrentPreset == FOLLOW_PCB ) diff --git a/3d-viewer/3d_canvas/board_adapter.h b/3d-viewer/3d_canvas/board_adapter.h index 2d10c06747..0cd9b93835 100644 --- a/3d-viewer/3d_canvas/board_adapter.h +++ b/3d-viewer/3d_canvas/board_adapter.h @@ -379,12 +379,6 @@ private: void buildPadOutlineAsSegments( const PAD* aPad, CONTAINER_2D_BASE* aDstContainer, int aWidth ); - // Helper functions to create poly contours - void buildPadOutlineAsPolygon( const PAD* aPad, SHAPE_POLY_SET& aBuffer, int aWidth) const; - - void transformFPShapesToPolySet( const FOOTPRINT* aFootprint, PCB_LAYER_ID aLayer, - SHAPE_POLY_SET& aBuffer ) const; - public: static CUSTOM_COLORS_LIST g_SilkColors; static CUSTOM_COLORS_LIST g_MaskColors; @@ -407,18 +401,18 @@ public: bool m_IsBoardView; bool m_MousewheelPanning; - bool m_IsPreviewer; ///< true if the board adaptater is living in a 3D - ///< preview panel, false for the standard 3D viewer + bool m_IsPreviewer; ///< true if we're in a 3D preview panel, false + ///< for the standard 3D viewer - SFVEC4F m_BgColorBot; ///< background bottom color - SFVEC4F m_BgColorTop; ///< background top color - SFVEC4F m_BoardBodyColor; ///< in realistic mode: FR4 board color - SFVEC4F m_SolderMaskColorBot; ///< in realistic mode: solder mask color ( bot ) - SFVEC4F m_SolderMaskColorTop; ///< in realistic mode: solder mask color ( top ) - SFVEC4F m_SolderPasteColor; ///< in realistic mode: solder paste color - SFVEC4F m_SilkScreenColorBot; ///< in realistic mode: SilkScreen color ( bot ) - SFVEC4F m_SilkScreenColorTop; ///< in realistic mode: SilkScreen color ( top ) - SFVEC4F m_CopperColor; ///< in realistic mode: copper color + SFVEC4F m_BgColorBot; ///< background bottom color + SFVEC4F m_BgColorTop; ///< background top color + SFVEC4F m_BoardBodyColor; ///< in realistic mode: FR4 board color + SFVEC4F m_SolderMaskColorBot; ///< in realistic mode: solder mask color ( bot ) + SFVEC4F m_SolderMaskColorTop; ///< in realistic mode: solder mask color ( top ) + SFVEC4F m_SolderPasteColor; ///< in realistic mode: solder paste color + SFVEC4F m_SilkScreenColorBot; ///< in realistic mode: SilkScreen color ( bot ) + SFVEC4F m_SilkScreenColorTop; ///< in realistic mode: SilkScreen color ( top ) + SFVEC4F m_CopperColor; ///< in realistic mode: copper color SFVEC4F m_UserDrawingsColor; SFVEC4F m_UserCommentsColor; SFVEC4F m_ECO1Color; @@ -430,43 +424,42 @@ private: RENDER_SETTINGS* m_renderSettings; COLOR_SETTINGS* m_colors; - VECTOR2I m_boardPos; ///< Board center position in board internal units. - VECTOR2I m_boardSize; ///< Board size in board internal units. - SFVEC3F m_boardCenter; ///< 3D center position of the board in 3D units. - BBOX_3D m_boardBoundingBox; ///< 3D bounding box of the board in 3D units. + VECTOR2I m_boardPos; ///< Board center position in board internal units. + VECTOR2I m_boardSize; ///< Board size in board internal units. + SFVEC3F m_boardCenter; ///< 3D center position of the board in 3D units. + BBOX_3D m_boardBoundingBox; ///< 3D bounding box of the board in 3D units. - MAP_POLY m_layers_poly; ///< Amalgamated polygon contours for various types of - ///< items + MAP_POLY m_layers_poly; ///< Amalgamated polygon contours for various types + ///< of items SHAPE_POLY_SET* m_frontPlatedPadPolys; SHAPE_POLY_SET* m_backPlatedPadPolys; - MAP_POLY m_layerHoleOdPolys; ///< Hole outer diameters (per layer) - MAP_POLY m_layerHoleIdPolys; ///< Hole inner diameters (per layer) + MAP_POLY m_layerHoleOdPolys; ///< Hole outer diameters (per layer) + MAP_POLY m_layerHoleIdPolys; ///< Hole inner diameters (per layer) - SHAPE_POLY_SET m_NPTH_ODPolys; ///< NPTH outer diameters - SHAPE_POLY_SET m_TH_ODPolys; ///< PTH outer diameters - SHAPE_POLY_SET m_viaTH_ODPolys; ///< Via hole outer diameters - SHAPE_POLY_SET m_THAnnularRingPolys; ///< Via annular ring outer diameters + SHAPE_POLY_SET m_NPTH_ODPolys; ///< NPTH outer diameters + SHAPE_POLY_SET m_TH_ODPolys; ///< PTH outer diameters + SHAPE_POLY_SET m_viaTH_ODPolys; ///< Via hole outer diameters + SHAPE_POLY_SET m_THAnnularRingPolys; ///< Via annular ring outer diameters - SHAPE_POLY_SET m_board_poly; ///< Board outline polygon. + SHAPE_POLY_SET m_board_poly; ///< Board outline polygon. - MAP_CONTAINER_2D_BASE m_layerMap; ///< 2D elements for each layer. - MAP_CONTAINER_2D_BASE m_layerHoleMap; ///< Holes for each layer. + MAP_CONTAINER_2D_BASE m_layerMap; ///< 2D elements for each layer. + MAP_CONTAINER_2D_BASE m_layerHoleMap; ///< Holes for each layer. BVH_CONTAINER_2D* m_platedPadsFront; BVH_CONTAINER_2D* m_platedPadsBack; - BVH_CONTAINER_2D m_TH_ODs; ///< List of PTH outer diameters - BVH_CONTAINER_2D m_TH_IDs; ///< List of PTH inner diameters - BVH_CONTAINER_2D m_THAnnularRings; ///< List of via annular rings - BVH_CONTAINER_2D m_viaTH_ODs; ///< List of via hole outer diameters - BVH_CONTAINER_2D m_throughHoleViaIds; ///< List of via hole inner diameters + BVH_CONTAINER_2D m_TH_ODs; ///< List of PTH outer diameters + BVH_CONTAINER_2D m_TH_IDs; ///< List of PTH inner diameters + BVH_CONTAINER_2D m_THAnnularRings; ///< List of via annular rings + BVH_CONTAINER_2D m_viaTH_ODs; ///< List of via hole outer diameters unsigned int m_copperLayersCount; - double m_biuTo3Dunits; ///< Scale factor to convert board internal units to - ///< 3D units normalized between -1.0 and 1.0. + double m_biuTo3Dunits; ///< Scale factor to convert board internal units + ///< to 3D units normalized between -1.0 and 1.0. std::array m_layerZcoordTop; ///< Top (End) Z position of each ///< layer in 3D units. diff --git a/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp b/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp index e36c86c0f7..425c23ab4a 100644 --- a/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp +++ b/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp @@ -27,8 +27,6 @@ * @file create_3Dgraphic_brd_items.cpp * @brief This file implements the creation of 2D graphic primitives of pcb items: * pads, tracks, drawsegments, texts.... - * It is based on the function found in the files: - * board_items_to_polygon_shape_transform.cpp */ #include "../3d_rendering/raytracing/shapes2D/ring_2d.h" @@ -62,8 +60,6 @@ #define TO_SFVEC2F( vec ) SFVEC2F( TO_3DU( vec.x ), TO_3DU( -vec.y ) ) - - void addFILLED_CIRCLE_2D( CONTAINER_2D_BASE* aContainer, const SFVEC2F& aCenter, float aRadius, const BOARD_ITEM& aBoardItem ) { @@ -273,10 +269,9 @@ void BOARD_ADAPTER::addFootprintShapes( const FOOTPRINT* aFootprint, CONTAINER_2 void BOARD_ADAPTER::createViaWithMargin( const PCB_TRACK* aTrack, CONTAINER_2D_BASE* aDstContainer, int aMargin ) { - SFVEC2F start3DU = TO_SFVEC2F( aTrack->GetStart() ); - SFVEC2F end3DU = TO_SFVEC2F( aTrack->GetEnd() ); - - const float radius3DU = TO_3DU( ( aTrack->GetWidth() / 2 ) + aMargin ); + SFVEC2F start3DU = TO_SFVEC2F( aTrack->GetStart() ); + SFVEC2F end3DU = TO_SFVEC2F( aTrack->GetEnd() ); + const float radius3DU = TO_3DU( ( aTrack->GetWidth() / 2.0 ) + aMargin ); addFILLED_CIRCLE_2D( aDstContainer, start3DU, radius3DU, *aTrack ); } @@ -290,7 +285,7 @@ void BOARD_ADAPTER::createTrack( const PCB_TRACK* aTrack, CONTAINER_2D_BASE* aDs switch( aTrack->Type() ) { case PCB_VIA_T: - addFILLED_CIRCLE_2D( aDstContainer, start3DU, TO_3DU( aTrack->GetWidth() / 2 ), *aTrack ); + addFILLED_CIRCLE_2D( aDstContainer, start3DU, TO_3DU( aTrack->GetWidth() / 2.0 ), *aTrack ); break; case PCB_ARC_T: @@ -310,10 +305,10 @@ void BOARD_ADAPTER::createTrack( const PCB_TRACK* aTrack, CONTAINER_2D_BASE* aDs return; } - VECTOR2D center( arc->GetCenter() ); + VECTOR2I center( arc->GetCenter() ); EDA_ANGLE arc_angle = arc->GetAngle(); double radius = arc->GetRadius(); - int arcsegcount = GetArcToSegmentCount( radius, ARC_HIGH_DEF, arc_angle ); + int arcsegcount = GetArcToSegmentCount( KiROUND( radius ), ARC_HIGH_DEF, arc_angle ); int circlesegcount; // Avoid arcs that cannot be drawn @@ -332,8 +327,8 @@ void BOARD_ADAPTER::createTrack( const PCB_TRACK* aTrack, CONTAINER_2D_BASE* aDs circlesegcount = alg::clamp( 1, circlesegcount, 128 ); } - createArcSegments( VECTOR2I( center.x, center.y ), arc->GetStart(), arc_angle, - circlesegcount, arc->GetWidth(), aDstContainer, *arc ); + createArcSegments( center, arc->GetStart(), arc_angle, circlesegcount, arc->GetWidth(), + aDstContainer, *arc ); break; } @@ -394,7 +389,7 @@ void BOARD_ADAPTER::createPadWithMargin( const PAD* aPad, CONTAINER_2D_BASE* aCo addROUND_SEGMENT_2D( aContainer, TO_SFVEC2F( seg->GetSeg().A ), TO_SFVEC2F( seg->GetSeg().B ), - TO_3DU( seg->GetWidth() + clearance.x * 2 ), + TO_3DU( seg->GetWidth() + clearance.x * 2 ), *aPad ); break; } @@ -734,23 +729,23 @@ void BOARD_ADAPTER::buildPadOutlineAsSegments( const PAD* aPad, CONTAINER_2D_BAS { const SFVEC2F center3DU = TO_SFVEC2F( aPad->ShapePos() ); const int radius = aPad->GetSize().x / 2; - const float inner_radius3DU = TO_3DU( radius - aWidth / 2 ); - const float outer_radius3DU = TO_3DU( radius + aWidth / 2 ); + const float inner_radius3DU = TO_3DU( radius - aWidth / 2.0 ); + const float outer_radius3DU = TO_3DU( radius + aWidth / 2.0 ); addRING_2D( aContainer, center3DU, inner_radius3DU, outer_radius3DU, *aPad ); - - return; } - - // For other shapes, add outlines as thick segments in polygon buffer - const std::shared_ptr& corners = aPad->GetEffectivePolygon(); - const SHAPE_LINE_CHAIN& path = corners->COutline( 0 ); - - for( int j = 0; j < path.PointCount(); j++ ) + else { - SFVEC2F start3DU = TO_SFVEC2F( path.CPoint( j ) ); - SFVEC2F end3DU = TO_SFVEC2F( path.CPoint( j + 1 ) ); + // For other shapes, add outlines as thick segments in polygon buffer + const std::shared_ptr& corners = aPad->GetEffectivePolygon(); + const SHAPE_LINE_CHAIN& path = corners->COutline( 0 ); - addROUND_SEGMENT_2D( aContainer, start3DU, end3DU, TO_3DU( aWidth ), *aPad ); + for( int j = 0; j < path.PointCount(); j++ ) + { + SFVEC2F start3DU = TO_SFVEC2F( path.CPoint( j ) ); + SFVEC2F end3DU = TO_SFVEC2F( path.CPoint( j + 1 ) ); + + addROUND_SEGMENT_2D( aContainer, start3DU, end3DU, TO_3DU( aWidth ), *aPad ); + } } } diff --git a/3d-viewer/3d_canvas/create_layer_items.cpp b/3d-viewer/3d_canvas/create_layer_items.cpp index 7e2f1e1404..a04da0694a 100644 --- a/3d-viewer/3d_canvas/create_layer_items.cpp +++ b/3d-viewer/3d_canvas/create_layer_items.cpp @@ -55,70 +55,88 @@ #endif + + +/* + * This is used to draw pad outlines on silk layers. + */ +void buildPadOutlineAsPolygon( const PAD* aPad, SHAPE_POLY_SET& aBuffer, int aWidth, int aMaxError, + ERROR_LOC aErrorLoc ) +{ + if( aPad->GetShape() == PAD_SHAPE::CIRCLE ) // Draw a ring + { + TransformRingToPolygon( aBuffer, aPad->ShapePos(), aPad->GetSize().x / 2, aWidth, + aMaxError, aErrorLoc ); + } + else + { + // For other shapes, add outlines as thick segments in polygon buffer + const SHAPE_LINE_CHAIN& path = aPad->GetEffectivePolygon()->COutline( 0 ); + + for( int ii = 0; ii < path.PointCount(); ++ii ) + { + const VECTOR2I& a = path.CPoint( ii ); + const VECTOR2I& b = path.CPoint( ii + 1 ); + + TransformOvalToPolygon( aBuffer, a, b, aWidth, aMaxError, aErrorLoc ); + } + } +} + + +void transformFPShapesToPolySet( const FOOTPRINT* aFootprint, PCB_LAYER_ID aLayer, + SHAPE_POLY_SET& aBuffer, int aMaxError, ERROR_LOC aErrorLoc ) +{ + for( BOARD_ITEM* item : aFootprint->GraphicalItems() ) + { + if( item->Type() == PCB_SHAPE_T || BaseType( item->Type() ) == PCB_DIMENSION_T ) + { + if( item->GetLayer() == aLayer ) + item->TransformShapeToPolygon( aBuffer, aLayer, 0, aMaxError, aErrorLoc ); + } + } +} + + void BOARD_ADAPTER::destroyLayers() { - if( !m_layers_poly.empty() ) - { - for( std::pair& poly : m_layers_poly ) - delete poly.second; +#define DELETE_AND_FREE( ptr ) \ + { \ + delete ptr; \ + ptr = nullptr; \ + } \ - m_layers_poly.clear(); +#define DELETE_AND_FREE_MAP( map ) \ + { \ + for( auto& [ layer, poly ] : map ) \ + delete poly; \ + \ + map.clear(); \ } - delete m_frontPlatedPadPolys; - m_frontPlatedPadPolys = nullptr; + DELETE_AND_FREE_MAP( m_layers_poly ); - delete m_backPlatedPadPolys; - m_backPlatedPadPolys = nullptr; + DELETE_AND_FREE( m_frontPlatedPadPolys ) + DELETE_AND_FREE( m_backPlatedPadPolys ) - if( !m_layerHoleIdPolys.empty() ) - { - for( std::pair& poly : m_layerHoleIdPolys ) - delete poly.second; + DELETE_AND_FREE_MAP( m_layerHoleOdPolys ) + DELETE_AND_FREE_MAP( m_layerHoleIdPolys ) - m_layerHoleIdPolys.clear(); - } - - if( !m_layerHoleOdPolys.empty() ) - { - for( std::pair& poly : m_layerHoleOdPolys ) - delete poly.second; - - m_layerHoleOdPolys.clear(); - } - - if( !m_layerMap.empty() ) - { - for( std::pair& poly : m_layerMap ) - delete poly.second; - - m_layerMap.clear(); - } - - delete m_platedPadsFront; - m_platedPadsFront = nullptr; - - delete m_platedPadsBack; - m_platedPadsBack = nullptr; - - if( !m_layerHoleMap.empty() ) - { - for( std::pair& poly : m_layerHoleMap ) - delete poly.second; - - m_layerHoleMap.clear(); - } - - m_TH_IDs.Clear(); - m_TH_ODs.Clear(); - m_THAnnularRings.Clear(); - m_viaTH_ODs.Clear(); - m_throughHoleViaIds.Clear(); m_NPTH_ODPolys.RemoveAllContours(); m_TH_ODPolys.RemoveAllContours(); - m_viaTH_ODPolys.RemoveAllContours(); m_THAnnularRingPolys.RemoveAllContours(); + + DELETE_AND_FREE_MAP( m_layerMap ) + DELETE_AND_FREE_MAP( m_layerHoleMap ) + + DELETE_AND_FREE( m_platedPadsFront ) + DELETE_AND_FREE( m_platedPadsBack ) + + m_TH_ODs.Clear(); + m_TH_IDs.Clear(); + m_THAnnularRings.Clear(); + m_viaTH_ODs.Clear(); } @@ -551,7 +569,7 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter ) true, m_Cfg->m_Render.renderPlatedPadsAsPlated, false ); - transformFPShapesToPolySet( footprint, layer, *layerPoly ); + transformFPShapesToPolySet( footprint, layer, *layerPoly, maxError, ERROR_INSIDE ); } } @@ -1027,10 +1045,11 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter ) for( PAD* pad : footprint->Pads() ) { - if( !pad->IsOnLayer( layer ) ) - continue; - - buildPadOutlineAsPolygon( pad, *layerPoly, linewidth ); + if( pad->IsOnLayer( layer ) ) + { + buildPadOutlineAsPolygon( pad, *layerPoly, linewidth, maxError, + ERROR_INSIDE ); + } } } else @@ -1042,7 +1061,7 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter ) footprint->TransformFPTextToPolySet( *layerPoly, layer, 0, maxError, ERROR_INSIDE ); // Add the remaining things with dynamic seg count for circles - transformFPShapesToPolySet( footprint, layer, *layerPoly ); + transformFPShapesToPolySet( footprint, layer, *layerPoly, maxError, ERROR_INSIDE ); } } @@ -1059,7 +1078,6 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter ) { for( ZONE* zone : m_board->Zones() ) { - if( zone->IsOnLayer( layer ) ) zone->TransformSolidAreasShapesToPolygon( layer, *layerPoly ); } @@ -1075,7 +1093,7 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter ) // A somewhat experimental feature: if we're rendering off-board silk, turn any pads of // footprints which are entirely outside the board outline into silk. This makes off-board // footprints more visually recognizable. - if( m_Cfg->m_Render.opengl_show_off_board_silk ) + if( m_Cfg->m_Render.show_off_board_silk ) { BOX2I boardBBox = m_board_poly.BBox(); diff --git a/3d-viewer/3d_canvas/create_layer_poly.cpp b/3d-viewer/3d_canvas/create_layer_poly.cpp deleted file mode 100644 index f6c6ba56b1..0000000000 --- a/3d-viewer/3d_canvas/create_layer_poly.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2015-2016 Mario Luzeiro - * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, you may find one here: - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * or you may search the http://www.gnu.org website for the version 2 license, - * or you may write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - -/** - * @file create_layer_poly.cpp - * @brief This file implements the creation of the pcb board items in the poly - * contours format. - */ - -#include "board_adapter.h" -#include -#include -#include -#include - - -/* - * This is used to draw pad outlines on silk layers. - */ -void BOARD_ADAPTER::buildPadOutlineAsPolygon( const PAD* aPad, SHAPE_POLY_SET& aBuffer, - int aWidth ) const -{ - int maxError = m_board->GetDesignSettings().m_MaxError; - - if( aPad->GetShape() == PAD_SHAPE::CIRCLE ) // Draw a ring - { - TransformRingToPolygon( aBuffer, aPad->ShapePos(), aPad->GetSize().x / 2, aWidth, maxError, - ERROR_INSIDE ); - return; - } - - // For other shapes, add outlines as thick segments in polygon buffer - const std::shared_ptr& corners = aPad->GetEffectivePolygon(); - const SHAPE_LINE_CHAIN& path = corners->COutline( 0 ); - - for( int ii = 0; ii < path.PointCount(); ++ii ) - { - const VECTOR2I& a = path.CPoint( ii ); - const VECTOR2I& b = path.CPoint( ii + 1 ); - - TransformOvalToPolygon( aBuffer, a, b, aWidth, maxError, ERROR_INSIDE ); - } -} - - -void BOARD_ADAPTER::transformFPShapesToPolySet( const FOOTPRINT* aFootprint, PCB_LAYER_ID aLayer, - SHAPE_POLY_SET& aBuffer ) const -{ - int maxError = m_board->GetDesignSettings().m_MaxError; - - for( BOARD_ITEM* item : aFootprint->GraphicalItems() ) - { - if( item->Type() == PCB_SHAPE_T || BaseType( item->Type() ) == PCB_DIMENSION_T ) - { - if( item->GetLayer() == aLayer ) - item->TransformShapeToPolygon( aBuffer, aLayer, 0, maxError, ERROR_INSIDE ); - } - } -} diff --git a/3d-viewer/3d_rendering/opengl/create_scene.cpp b/3d-viewer/3d_rendering/opengl/create_scene.cpp index 9f3afc78cf..3f6e5b7ee5 100644 --- a/3d-viewer/3d_rendering/opengl/create_scene.cpp +++ b/3d-viewer/3d_rendering/opengl/create_scene.cpp @@ -35,12 +35,12 @@ #include -void RENDER_3D_OPENGL::addObjectTriangles( const FILLED_CIRCLE_2D* aFilledCircle, +void RENDER_3D_OPENGL::addObjectTriangles( const FILLED_CIRCLE_2D* aCircle, TRIANGLE_DISPLAY_LIST* aDstLayer, float aZtop, float aZbot ) { - const SFVEC2F& center = aFilledCircle->GetCenter(); - const float radius = aFilledCircle->GetRadius() * 2.0f; // Double because the render triangle + const SFVEC2F& center = aCircle->GetCenter(); + const float radius = aCircle->GetRadius() * 2.0f; // Double because the render triangle // This is a small adjustment to the circle texture const float texture_factor = ( 8.0f / (float) SIZE_OF_CIRCLE_TEXTURE ) + 1.0f; diff --git a/3d-viewer/3d_rendering/opengl/layer_triangles.cpp b/3d-viewer/3d_rendering/opengl/layer_triangles.cpp index 36b6656be4..ec94d8c813 100644 --- a/3d-viewer/3d_rendering/opengl/layer_triangles.cpp +++ b/3d-viewer/3d_rendering/opengl/layer_triangles.cpp @@ -499,10 +499,10 @@ void OPENGL_RENDER_LIST::DrawAllCameraCulled( float zCameraPos, bool aDrawMiddle void OPENGL_RENDER_LIST::DrawAllCameraCulled( bool aDrawMiddle, - const OPENGL_RENDER_LIST* aLayerToSubtractA, - const OPENGL_RENDER_LIST* aLayerToSubtractB, - const OPENGL_RENDER_LIST* aLayerToSubtractC, - const OPENGL_RENDER_LIST* aLayerToSubtractD ) const + const OPENGL_RENDER_LIST* aSubtractList, + const OPENGL_RENDER_LIST* bSubtractList, + const OPENGL_RENDER_LIST* cSubtractList, + const OPENGL_RENDER_LIST* dSubtractList ) const { glClearStencil( 0x00 ); glClear( GL_STENCIL_BUFFER_BIT ); @@ -517,17 +517,17 @@ void OPENGL_RENDER_LIST::DrawAllCameraCulled( bool aDrawMiddle, glStencilFunc( GL_ALWAYS, 1, 0 ); glStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE ); - if( aLayerToSubtractA ) - aLayerToSubtractA->DrawBot(); + if( aSubtractList ) + aSubtractList->DrawBot(); - if( aLayerToSubtractB ) - aLayerToSubtractB->DrawBot(); + if( bSubtractList ) + bSubtractList->DrawBot(); - if( aLayerToSubtractC ) - aLayerToSubtractC->DrawBot(); + if( cSubtractList ) + cSubtractList->DrawBot(); - if( aLayerToSubtractD ) - aLayerToSubtractD->DrawBot(); + if( dSubtractList ) + dSubtractList->DrawBot(); glEnable(GL_DEPTH_TEST); glDepthMask(GL_TRUE); @@ -544,17 +544,17 @@ void OPENGL_RENDER_LIST::DrawAllCameraCulled( bool aDrawMiddle, glStencilFunc( GL_ALWAYS, 2, 0 ); glStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE ); - if( aLayerToSubtractA ) - aLayerToSubtractA->DrawTop(); + if( aSubtractList ) + aSubtractList->DrawTop(); - if( aLayerToSubtractB ) - aLayerToSubtractB->DrawTop(); + if( bSubtractList ) + bSubtractList->DrawTop(); - if( aLayerToSubtractC ) - aLayerToSubtractC->DrawTop(); + if( cSubtractList ) + cSubtractList->DrawTop(); - if( aLayerToSubtractD ) - aLayerToSubtractD->DrawTop(); + if( dSubtractList ) + dSubtractList->DrawTop(); glEnable(GL_DEPTH_TEST); glDepthMask(GL_TRUE); @@ -575,8 +575,8 @@ void OPENGL_RENDER_LIST::DrawAllCameraCulled( bool aDrawMiddle, if( aDrawMiddle ) { - if( aLayerToSubtractA ) - aLayerToSubtractA->DrawMiddle(); + if( aSubtractList ) + aSubtractList->DrawMiddle(); } glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE ); @@ -596,6 +596,12 @@ void OPENGL_RENDER_LIST::ApplyScalePosition( float aZposition, float aZscale ) } +void OPENGL_RENDER_LIST::ApplyScalePosition( OPENGL_RENDER_LIST* aOtherList ) +{ + ApplyScalePosition( aOtherList->GetZBot(), aOtherList->GetZTop() - aOtherList->GetZBot() ); +} + + void OPENGL_RENDER_LIST::SetItIsTransparent( bool aSetTransparent ) { m_draw_it_transparent = aSetTransparent; diff --git a/3d-viewer/3d_rendering/opengl/layer_triangles.h b/3d-viewer/3d_rendering/opengl/layer_triangles.h index 6985a80ea3..7be287c97e 100644 --- a/3d-viewer/3d_rendering/opengl/layer_triangles.h +++ b/3d-viewer/3d_rendering/opengl/layer_triangles.h @@ -197,12 +197,13 @@ public: void DrawAllCameraCulled( float zCameraPos, bool aDrawMiddle = true ) const; void DrawAllCameraCulled( bool aDrawMiddle, - const OPENGL_RENDER_LIST* aLayerToSubtractA = nullptr, - const OPENGL_RENDER_LIST* aLayerToSubtractB = nullptr, - const OPENGL_RENDER_LIST* aLayerToSubtractC = nullptr, - const OPENGL_RENDER_LIST* aLayerToSubtractD = nullptr ) const; + const OPENGL_RENDER_LIST* aSubtractList = nullptr, + const OPENGL_RENDER_LIST* bSubtractList = nullptr, + const OPENGL_RENDER_LIST* cSubtractList = nullptr, + const OPENGL_RENDER_LIST* dSubtractList = nullptr ) const; void ApplyScalePosition( float aZposition, float aZscale ); + void ApplyScalePosition( OPENGL_RENDER_LIST* aOtherList ); void ClearScalePosition() { m_haveTransformation = false; } diff --git a/3d-viewer/3d_rendering/opengl/render_3d_opengl.cpp b/3d-viewer/3d_rendering/opengl/render_3d_opengl.cpp index 7ca4ed9b70..7ced03ab09 100644 --- a/3d-viewer/3d_rendering/opengl/render_3d_opengl.cpp +++ b/3d-viewer/3d_rendering/opengl/render_3d_opengl.cpp @@ -437,7 +437,6 @@ void RENDER_3D_OPENGL::renderBoardBody( bool aSkipRenderHoles ) m_boardAdapter.GetBoardBodyThickness() ); ogl_disp_list->SetItIsTransparent( true ); - ogl_disp_list->DrawAll(); } } @@ -557,9 +556,13 @@ bool RENDER_3D_OPENGL::Redraw( bool aIsMoving, REPORTER* aStatusReporter, for( MAP_OGL_DISP_LISTS::const_iterator ii = m_layers.begin(); ii != m_layers.end(); ++ii ) { const PCB_LAYER_ID layer_id = ( PCB_LAYER_ID )( ii->first ); + bool isSilkLayer = layer_id == F_SilkS || layer_id == B_SilkS; + bool isMaskLayer = layer_id == F_Mask || layer_id == B_Mask; + bool isPasteLayer = layer_id == F_Paste || layer_id == B_Paste; + bool isCopperLayer = layer_id >= F_Cu && layer_id <= B_Cu; // Mask layers are not processed here because they are a special case - if( ( layer_id == B_Mask ) || ( layer_id == F_Mask ) ) + if( isMaskLayer ) continue; // Do not show inner layers when it is displaying the board and board body is opaque @@ -577,7 +580,7 @@ bool RENDER_3D_OPENGL::Redraw( bool aIsMoving, REPORTER* aStatusReporter, OPENGL_RENDER_LIST* pLayerDispList = static_cast( ii->second ); - if( ( layer_id >= F_Cu ) && ( layer_id <= B_Cu ) ) + if( isCopperLayer ) { if( m_boardAdapter.m_Cfg->m_Render.renderPlatedPadsAsPlated ) setCopperMaterial(); @@ -592,14 +595,12 @@ bool RENDER_3D_OPENGL::Redraw( bool aIsMoving, REPORTER* aStatusReporter, if( layer_id == F_Cu && m_platedPadsFront ) { setPlatedCopperAndDepthOffset( layer_id ); - m_platedPadsFront->DrawAllCameraCulled( m_camera.GetPos().z, - drawMiddleSegments ); + m_platedPadsFront->DrawAllCameraCulled( m_camera.GetPos().z, drawMiddleSegments ); } else if( layer_id == B_Cu && m_platedPadsBack ) { setPlatedCopperAndDepthOffset( layer_id ); - m_platedPadsBack->DrawAllCameraCulled( m_camera.GetPos().z, - drawMiddleSegments ); + m_platedPadsBack->DrawAllCameraCulled( m_camera.GetPos().z, drawMiddleSegments ); } unsetDepthOffset(); @@ -607,138 +608,72 @@ bool RENDER_3D_OPENGL::Redraw( bool aIsMoving, REPORTER* aStatusReporter, else { if( m_outerThroughHoles ) - { - m_outerThroughHoles->ApplyScalePosition( pLayerDispList->GetZBot(), - pLayerDispList->GetZTop() - - pLayerDispList->GetZBot() ); - } + m_outerThroughHoles->ApplyScalePosition( pLayerDispList ); if( m_antiBoard ) + m_antiBoard->ApplyScalePosition( pLayerDispList ); + + const OPENGL_RENDER_LIST* viasHolesLayer = m_outerLayerHoles[ layer_id ]; + + pLayerDispList->DrawAllCameraCulled( drawMiddleSegments, m_outerThroughHoles, + viasHolesLayer, m_antiBoard ); + + // Draw plated pads + if( layer_id == F_Cu && m_platedPadsFront ) { - m_antiBoard->ApplyScalePosition( pLayerDispList->GetZBot(), - pLayerDispList->GetZTop() - - pLayerDispList->GetZBot() ); + setPlatedCopperAndDepthOffset( layer_id ); + m_platedPadsFront->DrawAllCameraCulled( drawMiddleSegments, m_outerThroughHoles, + viasHolesLayer, m_antiBoard ); + } + else if( layer_id == B_Cu && m_platedPadsBack ) + { + setPlatedCopperAndDepthOffset( layer_id ); + m_platedPadsBack->DrawAllCameraCulled( drawMiddleSegments, m_outerThroughHoles, + viasHolesLayer, m_antiBoard ); } - if( m_outerLayerHoles.find( layer_id ) != m_outerLayerHoles.end() ) - { - const OPENGL_RENDER_LIST* viasHolesLayer = m_outerLayerHoles.at( layer_id ); - - wxASSERT( viasHolesLayer != nullptr ); - - if( viasHolesLayer != nullptr ) - { - pLayerDispList->DrawAllCameraCulled( drawMiddleSegments, - m_outerThroughHoles, viasHolesLayer, - m_antiBoard ); - - // Draw plated pads - if( layer_id == F_Cu && m_platedPadsFront ) - { - setPlatedCopperAndDepthOffset( layer_id ); - m_platedPadsFront->DrawAllCameraCulled( drawMiddleSegments, - m_outerThroughHoles, - viasHolesLayer, m_antiBoard ); - } - else if( layer_id == B_Cu && m_platedPadsBack ) - { - setPlatedCopperAndDepthOffset( layer_id ); - m_platedPadsBack->DrawAllCameraCulled( drawMiddleSegments, - m_outerThroughHoles, - viasHolesLayer, m_antiBoard ); - } - - unsetDepthOffset(); - } - } - else - { - pLayerDispList->DrawAllCameraCulled( drawMiddleSegments, m_outerThroughHoles, - m_antiBoard ); - - if( layer_id == F_Cu && m_platedPadsFront ) - { - setPlatedCopperAndDepthOffset( layer_id ); - m_platedPadsFront->DrawAllCameraCulled( drawMiddleSegments, - m_outerThroughHoles, m_antiBoard ); - } - else if( layer_id == B_Cu && m_platedPadsBack ) - { - setPlatedCopperAndDepthOffset( layer_id ); - m_platedPadsBack->DrawAllCameraCulled( drawMiddleSegments, - m_outerThroughHoles, m_antiBoard ); - } - - unsetDepthOffset(); - } + unsetDepthOffset(); } } + else if( isPasteLayer && skipRenderHoles ) + { + // Do not render paste layers when skipRenderHoles is enabled or we get z-fight issues + } else { setLayerMaterial( layer_id ); - OPENGL_RENDER_LIST* throughHolesOuter = m_outerThroughHoles; + OPENGL_RENDER_LIST* throughHolesOuter = nullptr; + OPENGL_RENDER_LIST* anti_board = nullptr; + OPENGL_RENDER_LIST* solder_mask = nullptr; - if( m_boardAdapter.m_Cfg->m_Render.clip_silk_on_via_annulus - && ( layer_id == B_SilkS || layer_id == F_SilkS ) ) - { + if( isSilkLayer && m_boardAdapter.m_Cfg->m_Render.clip_silk_on_via_annulus ) throughHolesOuter = m_outerThroughHoleRings; + else + throughHolesOuter = m_outerThroughHoles; + + if( isSilkLayer && m_boardAdapter.m_Cfg->m_Render.show_off_board_silk ) + anti_board = nullptr; + else if( LSET::PhysicalLayersMask().test( layer_id ) ) + anti_board = m_antiBoard; + + if( isSilkLayer && m_boardAdapter.m_Cfg->m_Render.subtract_mask_from_silk + && !m_boardAdapter.m_Cfg->m_Render.show_off_board_silk ) + { + solder_mask = m_layers[ (layer_id == B_SilkS) ? B_Mask : F_Mask ]; } if( throughHolesOuter ) - { - throughHolesOuter->ApplyScalePosition( pLayerDispList->GetZBot(), - pLayerDispList->GetZTop() - - pLayerDispList->GetZBot() ); - } - - OPENGL_RENDER_LIST* anti_board = nullptr; - - if( ( layer_id == F_SilkS || layer_id == B_SilkS ) - && m_boardAdapter.m_Cfg->m_Render.opengl_show_off_board_silk ) - { - anti_board = nullptr; - } - else if( LSET::PhysicalLayersMask().test( layer_id ) ) - { - anti_board = m_antiBoard; - } + throughHolesOuter->ApplyScalePosition( pLayerDispList ); if( anti_board ) - { - anti_board->ApplyScalePosition( pLayerDispList->GetZBot(), - pLayerDispList->GetZTop() - - pLayerDispList->GetZBot() ); - } + anti_board->ApplyScalePosition( pLayerDispList ); - if( skipRenderHoles ) - { - // Do not render Paste layers when skipRenderHoles is enabled - // otherwise it will cause z-fight issues - if( layer_id != B_Paste && layer_id != F_Paste ) - pLayerDispList->DrawAllCameraCulled( drawMiddleSegments, anti_board ); - } - else if( m_boardAdapter.m_Cfg->m_Render.subtract_mask_from_silk - && !m_boardAdapter.m_Cfg->m_Render.opengl_show_off_board_silk - && ( ( layer_id == B_SilkS && m_layers.find( B_Mask ) != m_layers.end() ) - || ( layer_id == F_SilkS && m_layers.find( F_Mask ) != m_layers.end() ) ) ) - { - const PCB_LAYER_ID layerMask_id = (layer_id == B_SilkS) ? B_Mask : F_Mask; + if( solder_mask ) + solder_mask->ApplyScalePosition( pLayerDispList ); - const OPENGL_RENDER_LIST* pLayerDispListMask = m_layers.at( layerMask_id ); - - pLayerDispList->DrawAllCameraCulled( drawMiddleSegments, pLayerDispListMask, - throughHolesOuter, anti_board ); - } - else if( throughHolesOuter ) - { - pLayerDispList->DrawAllCameraCulled( drawMiddleSegments, throughHolesOuter, - anti_board ); - } - else - { - pLayerDispList->DrawAllCameraCulled( drawMiddleSegments, anti_board ); - } + pLayerDispList->DrawAllCameraCulled( drawMiddleSegments, solder_mask, throughHolesOuter, + anti_board ); } glPopMatrix(); @@ -922,11 +857,8 @@ void RENDER_3D_OPENGL::freeAllLists() m_grid = 0; - for( MAP_OGL_DISP_LISTS::const_iterator ii = m_layers.begin(); ii != m_layers.end(); ++ii ) - { - OPENGL_RENDER_LIST* pLayerDispList = static_cast( ii->second ); - delete pLayerDispList; - } + for( const auto& [ layerId, renderList ] : m_layers ) + delete renderList; m_layers.clear(); @@ -936,24 +868,23 @@ void RENDER_3D_OPENGL::freeAllLists() delete m_platedPadsBack; m_platedPadsBack = nullptr; - - for( const std::pair entry : m_outerLayerHoles ) - delete entry.second; + for( const auto& [ layerId, renderList ] : m_outerLayerHoles ) + delete renderList; m_outerLayerHoles.clear(); - for( const std::pair entry : m_innerLayerHoles ) - delete entry.second; + for( const auto& [ layerId, renderList ] : m_innerLayerHoles ) + delete renderList; m_innerLayerHoles.clear(); - for( LIST_TRIANGLES::const_iterator ii = m_triangles.begin(); ii != m_triangles.end(); ++ii ) - delete *ii; + for( TRIANGLE_DISPLAY_LIST* list : m_triangles ) + delete list; m_triangles.clear(); - for( const std::pair& entry : m_3dModelMap ) - delete entry.second; + for( const auto& [ name, model ] : m_3dModelMap ) + delete model; m_3dModelMap.clear(); @@ -985,65 +916,30 @@ void RENDER_3D_OPENGL::freeAllLists() } -void RENDER_3D_OPENGL::renderSolderMaskLayer( PCB_LAYER_ID aLayerID, float aZPosition, +void RENDER_3D_OPENGL::renderSolderMaskLayer( PCB_LAYER_ID aLayerID, float aZPos, bool aDrawMiddleSegments, bool aSkipRenderHoles ) { wxASSERT( (aLayerID == B_Mask) || (aLayerID == F_Mask) ); - float nonCopperThickness = m_boardAdapter.GetNonCopperLayerThickness(); - if( m_board ) { - if( m_layers.find( aLayerID ) != m_layers.end() ) - { - OPENGL_RENDER_LIST* pLayerDispListMask = m_layers.at( aLayerID ); + OPENGL_RENDER_LIST* solder_mask = m_layers[ aLayerID ]; + OPENGL_RENDER_LIST* via_holes = aSkipRenderHoles ? nullptr : m_outerThroughHoles; - if( m_outerViaThroughHoles ) - m_outerViaThroughHoles->ApplyScalePosition( aZPosition, nonCopperThickness ); + if( via_holes ) + via_holes->ApplyScalePosition( aZPos, m_boardAdapter.GetNonCopperLayerThickness() ); - m_board->ApplyScalePosition( aZPosition, nonCopperThickness ); + m_board->ApplyScalePosition( aZPos, m_boardAdapter.GetNonCopperLayerThickness() ); - setLayerMaterial( aLayerID ); - - m_board->SetItIsTransparent( true ); - - if( aSkipRenderHoles ) - { - m_board->DrawAllCameraCulled( m_camera.GetPos().z, aDrawMiddleSegments ); - } - else - { - m_board->DrawAllCameraCulled( aDrawMiddleSegments, pLayerDispListMask, - m_outerViaThroughHoles ); - } - } - else - { - // This case there is no layer with mask, so we will render the full board as mask - if( m_outerViaThroughHoles ) - m_outerViaThroughHoles->ApplyScalePosition( aZPosition, nonCopperThickness ); - - m_board->ApplyScalePosition( aZPosition, nonCopperThickness ); - - setLayerMaterial( aLayerID ); - - m_board->SetItIsTransparent( true ); - - if( aSkipRenderHoles ) - { - m_board->DrawAllCameraCulled( m_camera.GetPos().z, aDrawMiddleSegments ); - } - else - { - m_board->DrawAllCameraCulled( aDrawMiddleSegments, m_outerViaThroughHoles ); - } - } + setLayerMaterial( aLayerID ); + m_board->SetItIsTransparent( true ); + m_board->DrawAllCameraCulled( aDrawMiddleSegments, solder_mask, via_holes ); } } -void RENDER_3D_OPENGL::get3dModelsSelected( std::list &aDstRenderList, - bool aGetTop, bool aGetBot, bool aRenderTransparentOnly, +void RENDER_3D_OPENGL::get3dModelsSelected( std::list &aDstRenderList, bool aGetTop, + bool aGetBot, bool aRenderTransparentOnly, bool aRenderSelectedOnly ) { wxASSERT( ( aGetTop == true ) || ( aGetBot == true ) ); @@ -1061,11 +957,8 @@ void RENDER_3D_OPENGL::get3dModelsSelected( std::list &aDstRender if( fp->IsSelected() ) highlight = true; - if( m_boardAdapter.m_Cfg->m_Render.opengl_highlight_on_rollover - && fp == m_currentRollOverItem ) - { + if( m_boardAdapter.m_Cfg->m_Render.highlight_on_rollover && fp == m_currentRollOverItem ) highlight = true; - } if( aRenderSelectedOnly != highlight ) continue; @@ -1077,8 +970,7 @@ void RENDER_3D_OPENGL::get3dModelsSelected( std::list &aDstRender { const bool isFlipped = fp->IsFlipped(); - if( ( aGetTop == !isFlipped ) || - ( aGetBot == isFlipped ) ) + if( aGetTop == !isFlipped || aGetBot == isFlipped ) get3dModelsFromFootprint( aDstRenderList, fp, aRenderTransparentOnly, highlight ); } } @@ -1087,8 +979,8 @@ void RENDER_3D_OPENGL::get3dModelsSelected( std::list &aDstRender void RENDER_3D_OPENGL::get3dModelsFromFootprint( std::list &aDstRenderList, - const FOOTPRINT* aFootprint, bool aRenderTransparentOnly, - bool aIsSelected ) + const FOOTPRINT* aFootprint, + bool aRenderTransparentOnly, bool aIsSelected ) { if( !aFootprint->Models().empty() ) { @@ -1098,15 +990,13 @@ void RENDER_3D_OPENGL::get3dModelsFromFootprint( std::list &aDstR glm::mat4 fpMatrix( 1.0f ); - fpMatrix = glm::translate( fpMatrix, - SFVEC3F( pos.x * m_boardAdapter.BiuTo3dUnits(), - -pos.y * m_boardAdapter.BiuTo3dUnits(), - zpos ) ); + fpMatrix = glm::translate( fpMatrix, SFVEC3F( pos.x * m_boardAdapter.BiuTo3dUnits(), + -pos.y * m_boardAdapter.BiuTo3dUnits(), + zpos ) ); if( !aFootprint->GetOrientation().IsZero() ) { - fpMatrix = glm::rotate( fpMatrix, - (float) aFootprint->GetOrientation().AsRadians(), + fpMatrix = glm::rotate( fpMatrix, (float) aFootprint->GetOrientation().AsRadians(), SFVEC3F( 0.0f, 0.0f, 1.0f ) ); } @@ -1116,11 +1006,9 @@ void RENDER_3D_OPENGL::get3dModelsFromFootprint( std::list &aDstR fpMatrix = glm::rotate( fpMatrix, glm::pi(), SFVEC3F( 0.0f, 0.0f, 1.0f ) ); } - const double modelunit_to_3d_units_factor = m_boardAdapter.BiuTo3dUnits() * - UNITS3D_TO_UNITSPCB; + double modelunit_to_3d_units_factor = m_boardAdapter.BiuTo3dUnits() * UNITS3D_TO_UNITSPCB; - fpMatrix = glm::scale( fpMatrix, - SFVEC3F( modelunit_to_3d_units_factor ) ); + fpMatrix = glm::scale( fpMatrix, SFVEC3F( modelunit_to_3d_units_factor ) ); // Get the list of model files for this model for( const FP_3DMODEL& sM : aFootprint->Models() ) @@ -1170,22 +1058,10 @@ void RENDER_3D_OPENGL::get3dModelsFromFootprint( std::list &aDstR modelworldMatrix *= mtx; } - if( aRenderTransparentOnly ) - { - aDstRenderList.emplace_back( modelworldMatrix, - modelPtr, - sM.m_Opacity, - true, - aFootprint->IsSelected() || aIsSelected ); - } - else - { - aDstRenderList.emplace_back( modelworldMatrix, - modelPtr, - 1.0f, - false, - aFootprint->IsSelected() || aIsSelected ); - } + aDstRenderList.emplace_back( modelworldMatrix, modelPtr, + aRenderTransparentOnly ? sM.m_Opacity : 1.0f, + aRenderTransparentOnly, + aFootprint->IsSelected() || aIsSelected ); } } } @@ -1300,16 +1176,13 @@ void RENDER_3D_OPENGL::renderTransparentModels( const glm::mat4 &aCameraViewMatr glEnableClientState( GL_TEXTURE_COORD_ARRAY ); glEnable( GL_COLOR_MATERIAL ); } - else + else if( isUsingColorInformation && mtr.first->m_isSelected ) { - if( isUsingColorInformation && mtr.first->m_isSelected ) - { - isUsingColorInformation = false; + isUsingColorInformation = false; - glDisableClientState( GL_COLOR_ARRAY ); - glDisableClientState( GL_TEXTURE_COORD_ARRAY ); - glDisable( GL_COLOR_MATERIAL ); - } + glDisableClientState( GL_COLOR_ARRAY ); + glDisableClientState( GL_TEXTURE_COORD_ARRAY ); + glDisable( GL_COLOR_MATERIAL ); } } @@ -1326,8 +1199,7 @@ void RENDER_3D_OPENGL::renderTransparentModels( const glm::mat4 &aCameraViewMatr void RENDER_3D_OPENGL::renderModel( const glm::mat4 &aCameraViewMatrix, const MODELTORENDER &aModelToRender, - const SFVEC3F &aSelColor, - const SFVEC3F *aCameraWorldPos ) + const SFVEC3F &aSelColor, const SFVEC3F *aCameraWorldPos ) { const glm::mat4 modelviewMatrix = aCameraViewMatrix * aModelToRender.m_modelWorldMat; @@ -1337,7 +1209,7 @@ void RENDER_3D_OPENGL::renderModel( const glm::mat4 &aCameraViewMatrix, aModelToRender.m_isSelected, aSelColor, &aModelToRender.m_modelWorldMat, aCameraWorldPos ); - if( m_boardAdapter.m_Cfg->m_Render.opengl_show_model_bbox ) + if( m_boardAdapter.m_Cfg->m_Render.show_model_bbox ) { const bool wasBlendEnabled = glIsEnabled( GL_BLEND ); diff --git a/3d-viewer/3d_rendering/opengl/render_3d_opengl.h b/3d-viewer/3d_rendering/opengl/render_3d_opengl.h index a3ff00083d..1dc4d049da 100644 --- a/3d-viewer/3d_rendering/opengl/render_3d_opengl.h +++ b/3d-viewer/3d_rendering/opengl/render_3d_opengl.h @@ -73,13 +73,12 @@ public: private: OPENGL_RENDER_LIST* generateHoles( const LIST_OBJECT2D& aListHolesObject2d, - const SHAPE_POLY_SET& aPoly, float aZtop, - float aZbot, bool aInvertFaces, + const SHAPE_POLY_SET& aPoly, float aZtop, float aZbot, + bool aInvertFaces, const BVH_CONTAINER_2D* aThroughHoles = nullptr ); OPENGL_RENDER_LIST* generateLayerList( const BVH_CONTAINER_2D* aContainer, - const SHAPE_POLY_SET* aPolyList, - PCB_LAYER_ID aLayerId, + const SHAPE_POLY_SET* aPolyList, PCB_LAYER_ID aLayerId, const BVH_CONTAINER_2D* aThroughHoles = nullptr ); OPENGL_RENDER_LIST* generateEmptyLayerList( PCB_LAYER_ID aLayerId ); @@ -93,17 +92,17 @@ private: void addObjectTriangles( const POLYGON_4PT_2D* aPoly, TRIANGLE_DISPLAY_LIST* aDstLayer, float aZtop, float aZbot ); - void addObjectTriangles( const FILLED_CIRCLE_2D* aFilledCircle, - TRIANGLE_DISPLAY_LIST* aDstLayer, float aZtop, float aZbot ); + void addObjectTriangles( const FILLED_CIRCLE_2D* aCircle, TRIANGLE_DISPLAY_LIST* aDstLayer, + float aZtop, float aZbot ); void addObjectTriangles( const TRIANGLE_2D* aTri, TRIANGLE_DISPLAY_LIST* aDstLayer, float aZtop, float aZbot ); - void addObjectTriangles( const ROUND_SEGMENT_2D* aSeg, - TRIANGLE_DISPLAY_LIST* aDstLayer, float aZtop, float aZbot ); + void addObjectTriangles( const ROUND_SEGMENT_2D* aSeg, TRIANGLE_DISPLAY_LIST* aDstLayer, + float aZtop, float aZbot ); - void renderSolderMaskLayer( PCB_LAYER_ID aLayerID, float aZPosition, - bool aDrawMiddleSegments, bool aSkipRenderHoles ); + void renderSolderMaskLayer( PCB_LAYER_ID aLayerID, float aZPos, bool aDrawMiddleSegments, + bool aSkipRenderHoles ); void renderBoardBody( bool aSkipRenderHoles ); @@ -154,15 +153,12 @@ private: void renderOpaqueModels( const glm::mat4 &aCameraViewMatrix ); void renderTransparentModels( const glm::mat4 &aCameraViewMatrix ); - void renderModel( const glm::mat4 &aCameraViewMatrix, - const MODELTORENDER &aModelToRender, - const SFVEC3F &aSelColor, - const SFVEC3F *aCameraWorldPos ); + void renderModel( const glm::mat4 &aCameraViewMatrix, const MODELTORENDER &aModelToRender, + const SFVEC3F &aSelColor, const SFVEC3F *aCameraWorldPos ); - void get3dModelsSelected( std::list &aDstRenderList, - bool aGetTop, bool aGetBot, bool aRenderTransparentOnly, - bool aRenderSelectedOnly ); + void get3dModelsSelected( std::list &aDstRenderList, bool aGetTop, bool aGetBot, + bool aRenderTransparentOnly, bool aRenderSelectedOnly ); void get3dModelsFromFootprint( std::list &aDstRenderList, const FOOTPRINT* aFootprint, bool aRenderTransparentOnly, @@ -234,8 +230,8 @@ private: OPENGL_RENDER_LIST* m_padHoles; // Caches - std::map< wxString, MODEL_3D* > m_3dModelMap; - std::map< std::vector, glm::mat4 > m_3dModelMatrixMap; + std::map m_3dModelMap; + std::map, glm::mat4> m_3dModelMatrixMap; BOARD_ITEM* m_currentRollOverItem; diff --git a/3d-viewer/3d_viewer/eda_3d_viewer_frame.cpp b/3d-viewer/3d_viewer/eda_3d_viewer_frame.cpp index 5995fbb0cc..04f72a1a84 100644 --- a/3d-viewer/3d_viewer/eda_3d_viewer_frame.cpp +++ b/3d-viewer/3d_viewer/eda_3d_viewer_frame.cpp @@ -253,7 +253,7 @@ void EDA_3D_VIEWER_FRAME::setupUIConditions() auto showBBoxes = [this]( const SELECTION& aSel ) { - return m_boardAdapter.m_Cfg->m_Render.opengl_show_model_bbox; + return m_boardAdapter.m_Cfg->m_Render.show_model_bbox; }; auto showAxes = [this]( const SELECTION& aSel ) diff --git a/3d-viewer/3d_viewer/eda_3d_viewer_settings.cpp b/3d-viewer/3d_viewer/eda_3d_viewer_settings.cpp index 89a83fea71..dceed2643d 100644 --- a/3d-viewer/3d_viewer/eda_3d_viewer_settings.cpp +++ b/3d-viewer/3d_viewer/eda_3d_viewer_settings.cpp @@ -219,11 +219,11 @@ EDA_3D_VIEWER_SETTINGS::EDA_3D_VIEWER_SETTINGS() : m_params.emplace_back( new PARAM( "render.opengl_copper_thickness", &m_Render.opengl_copper_thickness, false ) ); m_params.emplace_back( new PARAM( "render.opengl_show_model_bbox", - &m_Render.opengl_show_model_bbox, false ) ); + &m_Render.show_model_bbox, false ) ); m_params.emplace_back( new PARAM( "render.opengl_show_off_board_silk", - &m_Render.opengl_show_off_board_silk, false ) ); + &m_Render.show_off_board_silk, false ) ); m_params.emplace_back( new PARAM( "render.opengl_highlight_on_rollover", - &m_Render.opengl_highlight_on_rollover, true ) ); + &m_Render.highlight_on_rollover, true ) ); m_params.emplace_back( new PARAM( "render.opengl_AA_disableOnMove", &m_Render.opengl_AA_disableOnMove, false ) ); m_params.emplace_back( new PARAM( "render.opengl_thickness_disableOnMove", diff --git a/3d-viewer/3d_viewer/eda_3d_viewer_settings.h b/3d-viewer/3d_viewer/eda_3d_viewer_settings.h index 3e0af7859d..fca0dced3b 100644 --- a/3d-viewer/3d_viewer/eda_3d_viewer_settings.h +++ b/3d-viewer/3d_viewer/eda_3d_viewer_settings.h @@ -89,9 +89,9 @@ public: bool opengl_holes_disableOnMove; bool opengl_render_bbox_only_OnMove; bool opengl_copper_thickness; - bool opengl_show_model_bbox; - bool opengl_show_off_board_silk; - bool opengl_highlight_on_rollover; + bool show_model_bbox; + bool show_off_board_silk; + bool highlight_on_rollover; KIGFX::COLOR4D opengl_selection_color; bool raytrace_anti_aliasing; diff --git a/3d-viewer/CMakeLists.txt b/3d-viewer/CMakeLists.txt index ee56d19fcf..8bc57bebbc 100644 --- a/3d-viewer/CMakeLists.txt +++ b/3d-viewer/CMakeLists.txt @@ -30,7 +30,6 @@ set(3D-VIEWER_SRCS 3d_canvas/board_adapter.cpp 3d_canvas/create_layer_items.cpp 3d_canvas/create_3Dgraphic_brd_items.cpp - 3d_canvas/create_layer_poly.cpp 3d_canvas/eda_3d_canvas.cpp 3d_canvas/eda_3d_canvas_pivot.cpp 3d_model_viewer/eda_3d_model_viewer.cpp diff --git a/3d-viewer/dialogs/panel_3D_opengl_options.cpp b/3d-viewer/dialogs/panel_3D_opengl_options.cpp index fd7870bc4b..c6537319d1 100644 --- a/3d-viewer/dialogs/panel_3D_opengl_options.cpp +++ b/3d-viewer/dialogs/panel_3D_opengl_options.cpp @@ -41,8 +41,8 @@ PANEL_3D_OPENGL_OPTIONS::PANEL_3D_OPENGL_OPTIONS( wxWindow* aParent ) : void PANEL_3D_OPENGL_OPTIONS::loadSettings( EDA_3D_VIEWER_SETTINGS* aCfg ) { m_checkBoxCuThickness->SetValue( aCfg->m_Render.opengl_copper_thickness ); - m_checkBoxBoundingBoxes->SetValue( aCfg->m_Render.opengl_show_model_bbox ); - m_checkBoxHighlightOnRollOver->SetValue( aCfg->m_Render.opengl_highlight_on_rollover ); + m_checkBoxBoundingBoxes->SetValue( aCfg->m_Render.show_model_bbox ); + m_checkBoxHighlightOnRollOver->SetValue( aCfg->m_Render.highlight_on_rollover ); m_choiceAntiAliasing->SetSelection( static_cast( aCfg->m_Render.opengl_AA_mode ) ); m_selectionColorSwatch->SetSwatchColor( aCfg->m_Render.opengl_selection_color, false ); @@ -69,8 +69,8 @@ bool PANEL_3D_OPENGL_OPTIONS::TransferDataFromWindow() EDA_3D_VIEWER_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings(); cfg->m_Render.opengl_copper_thickness = m_checkBoxCuThickness->GetValue(); - cfg->m_Render.opengl_show_model_bbox = m_checkBoxBoundingBoxes->GetValue(); - cfg->m_Render.opengl_highlight_on_rollover = m_checkBoxHighlightOnRollOver->GetValue(); + cfg->m_Render.show_model_bbox = m_checkBoxBoundingBoxes->GetValue(); + cfg->m_Render.highlight_on_rollover = m_checkBoxHighlightOnRollOver->GetValue(); cfg->m_Render.opengl_AA_mode = static_cast( m_choiceAntiAliasing->GetSelection() ); cfg->m_Render.opengl_selection_color = m_selectionColorSwatch->GetSwatchColor();