29#include "../../3d_math.h"
43 const float radius = aFilledCircle->
GetRadius() * 2.0f;
47 const float f = ( sqrtf( 2.0f ) / 2.0f ) * radius * texture_factor;
51 SFVEC3F( center.x - f, center.y, aZtop ),
52 SFVEC3F( center.x, center.y - f, aZtop ) );
55 SFVEC3F( center.x + f, center.y, aZtop ),
56 SFVEC3F( center.x, center.y + f, aZtop ) );
59 SFVEC3F( center.x + f, center.y, aZbot ),
60 SFVEC3F( center.x, center.y - f, aZbot ) );
63 SFVEC3F( center.x - f, center.y, aZbot ),
64 SFVEC3F( center.x, center.y + f, aZbot ) );
70 float aZtop,
float aZbot )
83 float aOuterRadius,
unsigned int aNr_sides_per_circle,
84 std::vector< SFVEC2F >& aInnerContourResult,
85 std::vector< SFVEC2F >& aOuterContourResult,
88 aInnerContourResult.clear();
89 aInnerContourResult.reserve( aNr_sides_per_circle + 2 );
91 aOuterContourResult.clear();
92 aOuterContourResult.reserve( aNr_sides_per_circle + 2 );
94 const int delta = 3600 / aNr_sides_per_circle;
96 for(
int ii = 0; ii < 3600; ii +=
delta )
98 float angle = (float)( aInvertOrder ? ( 3600 - ii ) : ii )
99 * 2.0f * glm::pi<float>() / 3600.0f;
102 aInnerContourResult.emplace_back( aCenter.x + rotatedDir.x * aInnerRadius,
103 aCenter.y + rotatedDir.y * aInnerRadius );
105 aOuterContourResult.emplace_back( aCenter.x + rotatedDir.x * aOuterRadius,
106 aCenter.y + rotatedDir.y * aOuterRadius );
109 aInnerContourResult.push_back( aInnerContourResult[0] );
110 aOuterContourResult.push_back( aOuterContourResult[0] );
112 wxASSERT( aInnerContourResult.size() == aOuterContourResult.size() );
117 float aZtop,
float aZbot )
123 std::vector< SFVEC2F > innerContour;
124 std::vector< SFVEC2F > outerContour;
127 innerContour, outerContour,
false );
130 for(
unsigned int i = 0; i < ( innerContour.size() - 1 ); ++i )
132 const SFVEC2F& vi0 = innerContour[i + 0];
133 const SFVEC2F& vi1 = innerContour[i + 1];
134 const SFVEC2F& vo0 = outerContour[i + 0];
135 const SFVEC2F& vo1 = outerContour[i + 1];
138 SFVEC3F( vi0.x, vi0.y, aZtop ),
139 SFVEC3F( vo0.x, vo0.y, aZtop ),
140 SFVEC3F( vo1.x, vo1.y, aZtop ) );
143 SFVEC3F( vo1.x, vo1.y, aZbot ),
144 SFVEC3F( vo0.x, vo0.y, aZbot ),
145 SFVEC3F( vi0.x, vi0.y, aZbot ) );
152 float aZtop,
float aZbot )
164 float aZtop,
float aZbot )
181 const float radius_of_the_square = sqrtf( aSeg->
GetRadiusSquared() * 2.0f );
182 const float radius_triangle_factor = ( radius_of_the_square - radius ) / radius;
184 const SFVEC2F factorS =
SFVEC2F( -rightDir.y * radius * radius_triangle_factor,
185 rightDir.x * radius * radius_triangle_factor );
187 const SFVEC2F factorE =
SFVEC2F( -leftDir.y * radius * radius_triangle_factor,
188 leftDir.x * radius * radius_triangle_factor );
192 SFVEC3F( rightEnd.x + texture_factor * factorS.x,
193 rightEnd.y + texture_factor * factorS.y,
195 SFVEC3F( leftStart.x + texture_factor * factorE.x,
196 leftStart.y + texture_factor * factorE.y,
198 SFVEC3F( start.x - texture_factorF * leftDir.x * radius * sqrtf( 2.0f ),
199 start.y - texture_factorF * leftDir.y * radius * sqrtf( 2.0f ),
203 SFVEC3F( leftEnd.x + texture_factor * factorE.x,
204 leftEnd.y + texture_factor * factorE.y, aZtop ),
205 SFVEC3F( rightStart.x + texture_factor * factorS.x,
206 rightStart.y + texture_factor * factorS.y, aZtop ),
207 SFVEC3F( end.x - texture_factorF * rightDir.x * radius * sqrtf( 2.0f ),
208 end.y - texture_factorF * rightDir.y * radius * sqrtf( 2.0f ),
213 SFVEC3F( leftStart.x + texture_factor * factorE.x,
214 leftStart.y + texture_factor * factorE.y,
216 SFVEC3F( rightEnd.x + texture_factor * factorS.x,
217 rightEnd.y + texture_factor * factorS.y,
219 SFVEC3F( start.x - texture_factorF * leftDir.x * radius * sqrtf( 2.0f ),
220 start.y - texture_factorF * leftDir.y * radius * sqrtf( 2.0f ),
224 SFVEC3F( rightStart.x + texture_factor * factorS.x,
225 rightStart.y + texture_factor * factorS.y, aZbot ),
226 SFVEC3F( leftEnd.x + texture_factor * factorE.x,
227 leftEnd.y + texture_factor * factorE.y, aZbot ),
228 SFVEC3F( end.x - texture_factorF * rightDir.x * radius * sqrtf( 2.0f ),
229 end.y - texture_factorF * rightDir.y * radius * sqrtf( 2.0f ),
234 SFVEC3F( rightEnd.x, rightEnd.y, aZtop ),
235 SFVEC3F( rightStart.x, rightStart.y, aZtop ),
236 SFVEC3F( leftEnd.x, leftEnd.y, aZtop ),
237 SFVEC3F( leftStart.x, leftStart.y, aZtop ) );
240 SFVEC3F( rightEnd.x, rightEnd.y, aZbot ),
241 SFVEC3F( leftStart.x, leftStart.y, aZbot ),
242 SFVEC3F( leftEnd.x, leftEnd.y, aZbot ),
243 SFVEC3F( rightStart.x, rightStart.y, aZbot ) );
249 float aZbot,
bool aInvertFaces,
254 if( aListHolesObject2d.size() > 0 )
260 for(
const OBJECT_2D* itemOnLayer : aListHolesObject2d )
262 const OBJECT_2D* object2d_A = itemOnLayer;
271 layerTriangles, aZtop, aZbot );
276 layerTriangles, aZtop, aZbot );
280 wxFAIL_MSG( wxT(
"RENDER_3D_OPENGL::generateHoles: Object type not implemented" ) );
291 aInvertFaces, aThroughHoles );
296 delete layerTriangles;
308 if( aContainer ==
nullptr )
313 if( listObject2d.size() == 0 )
316 float layer_z_bot = 0.0f;
317 float layer_z_top = 0.0f;
322 unsigned int nrTrianglesEstimation = listObject2d.size() * 8;
330 for(
const OBJECT_2D* itemOnLayer : listObject2d )
332 const OBJECT_2D* object2d_A = itemOnLayer;
338 layerTriangles, layer_z_top, layer_z_bot );
343 layerTriangles, layer_z_top, layer_z_bot );
348 layerTriangles, layer_z_top, layer_z_bot );
353 layerTriangles, layer_z_top, layer_z_bot );
358 layerTriangles, layer_z_top, layer_z_bot );
362 wxFAIL_MSG( wxT(
"RENDER_3D_OPENGL: Object type is not implemented" ) );
380 float layer_z_bot = 0.0f;
381 float layer_z_top = 0.0f;
405 if( listBoardObject2d.size() > 0 )
409 const float layer_z_top = 1.0f;
410 const float layer_z_bot = 0.0f;
416 for(
const OBJECT_2D* itemOnLayer : listBoardObject2d )
418 const OBJECT_2D* object2d_A = itemOnLayer;
438 layer_z_top, layer_z_top );
441 delete layerTriangles;
463 if( aStatusReporter )
464 aStatusReporter->
Report(
_(
"Load OpenGL: board" ) );
496 if( aStatusReporter )
497 aStatusReporter->
Report(
_(
"Load OpenGL: holes and vias" ) );
508 outerPolyTHT, 1.0f, 0.0f,
false,
526 wxASSERT( innerMapHoles.size() == outerMapHoles.size() );
530 if( outerMapHoles.size() > 0 )
532 float layer_z_bot = 0.0f;
533 float layer_z_top = 0.0f;
535 for(
const std::pair<const PCB_LAYER_ID, SHAPE_POLY_SET*>& ii : outerMapHoles )
544 layer_z_top, layer_z_bot,
false );
547 for(
const std::pair<const PCB_LAYER_ID, SHAPE_POLY_SET*>& ii : innerMapHoles )
556 layer_z_top, layer_z_bot,
false );
564 if( aStatusReporter )
565 aStatusReporter->
Report(
_(
"Load OpenGL: layers" ) );
576 if( aStatusReporter )
589 if( map_poly.find( layer_id ) != map_poly.end() )
591 polyListSubtracted = *map_poly.at( layer_id );;
608 if( layer_id ==
B_SilkS && map_poly.find(
B_Mask ) != map_poly.end() )
613 else if( layer_id ==
F_SilkS && map_poly.find(
F_Mask ) != map_poly.end() )
621 polyList = &polyListSubtracted;
627 if( oglList !=
nullptr )
638 if( frontPlatedPadPolys )
649 &polySubtracted,
F_Cu );
656 if( backPlatedPadPolys )
667 &polySubtracted,
B_Cu );
676 if( aStatusReporter )
677 aStatusReporter->
Report(
_(
"Loading 3D models..." ) );
681 if( aStatusReporter )
710 if( aOutZtop < aOutZbot )
712 float tmpFloat = aOutZbot;
720 float aOuterRadius,
float aZtop,
float aZbot,
721 unsigned int aNr_sides_per_circle,
724 std::vector< SFVEC2F > innerContour;
725 std::vector< SFVEC2F > outerContour;
727 generateRing( aCenter, aInnerRadius, aOuterRadius, aNr_sides_per_circle, innerContour,
728 outerContour,
false );
730 for(
unsigned int i = 0; i < ( innerContour.size() - 1 ); ++i )
732 const SFVEC2F& vi0 = innerContour[i + 0];
733 const SFVEC2F& vi1 = innerContour[i + 1];
734 const SFVEC2F& vo0 = outerContour[i + 0];
735 const SFVEC2F& vo1 = outerContour[i + 1];
738 SFVEC3F( vi0.x, vi0.y, aZtop ),
739 SFVEC3F( vo0.x, vo0.y, aZtop ),
740 SFVEC3F( vo1.x, vo1.y, aZtop ) );
743 SFVEC3F( vo1.x, vo1.y, aZbot ),
744 SFVEC3F( vo0.x, vo0.y, aZbot ),
745 SFVEC3F( vi0.x, vi0.y, aZbot ) );
780 const float hole_inner_radius = holediameter / 2.0f;
786 via->LayerPair( &top_layer, &bottom_layer );
788 float ztop, zbot,
dummy;
793 wxASSERT( zbot < ztop );
796 hole_inner_radius + platingThickness3d,
797 ztop, zbot, nrSegments, layerTriangleVIA );
803 delete layerTriangleVIA;
818 for(
const PAD*
pad : footprint->Pads() )
823 const bool hasHole = drillsize.
x && drillsize.
y;
828 pad->TransformHoleToPolygon( tht_outer_holes_poly, platingThickness,
849 if( holes2D.size() > 0 )
851 float layer_z_top, layer_z_bot,
dummy;
859 for(
const OBJECT_2D* itemOnLayer : holes2D )
861 const OBJECT_2D* object2d_A = itemOnLayer;
879 layer_z_bot, layer_z_top,
883 layer_z_top, layer_z_top );
886 delete layerTriangles;
925 wxString libraryName = footprint->GetFPID().GetLibNickname();
926 wxString footprintBasePath = wxEmptyString;
935 libraryName,
false );
938 footprintBasePath = fpRow->
GetFullURI(
true );
946 for(
const FP_3DMODEL& fp_model : footprint->Models() )
948 if( fp_model.m_Show && !fp_model.m_Filename.empty() )
950 if( aStatusReporter )
954 wxFileName fn( fp_model.m_Filename );
956 fn.GetFullName() ) );
MATERIAL_MODE
Render 3d model shape materials mode.
constexpr int ARC_HIGH_DEF
std::map< PCB_LAYER_ID, SHAPE_POLY_SET * > MAP_POLY
A type that stores polysets for each layer id.
std::map< PCB_LAYER_ID, BVH_CONTAINER_2D * > MAP_CONTAINER_2D_BASE
A type that stores a container of 2d objects for each layer id.
const BVH_CONTAINER_2D & GetThroughHoleViaOds() const noexcept
double BiuTo3dUnits() const noexcept
Board integer units To 3D units.
const MAP_CONTAINER_2D_BASE & GetLayerHoleMap() const noexcept
const SHAPE_POLY_SET & GetBoardPoly() const noexcept
Get the current polygon of the epoxy board.
const SHAPE_POLY_SET & GetThroughHoleOdPolys() const noexcept
Get through hole outside diameter 2D polygons.
const MAP_POLY & GetPolyMap() const noexcept
Get map of polygon's layers.
const MAP_POLY & GetHoleOdPolysMap() const noexcept
const BVH_CONTAINER_2D & GetThroughHoleIds() const noexcept
int GetHolePlatingThickness() const noexcept
Get the hole plating thickness (NB: in BOARD UNITS!).
void InitSettings(REPORTER *aStatusReporter, REPORTER *aWarningReporter)
Function to be called by the render when it need to reload the settings for the board.
float GetLayerBottomZPos(PCB_LAYER_ID aLayerId) const noexcept
Get the bottom z position.
const BVH_CONTAINER_2D * GetPlatedPadsBack() const noexcept
const MAP_POLY & GetHoleIdPolysMap() const noexcept
float GetAverageViaHoleDiameter() const noexcept
const SHAPE_POLY_SET * GetFrontPlatedPadPolys()
unsigned int GetViaCount() const noexcept
const BOARD * GetBoard() const noexcept
const SFVEC3F & GetBoardCenter() const noexcept
The board center position in 3D units.
float GetLayerTopZPos(PCB_LAYER_ID aLayerId) const noexcept
Get the top z position.
const SHAPE_POLY_SET & GetOuterNonPlatedThroughHolePoly() const noexcept
const SHAPE_POLY_SET * GetBackPlatedPadPolys()
const MAP_CONTAINER_2D_BASE & GetLayerMap() const noexcept
Get the map of containers that have the objects per layer.
EDA_3D_VIEWER_SETTINGS * m_Cfg
unsigned int GetHoleCount() const noexcept
const SHAPE_POLY_SET & GetThroughHoleAnnularRingPolys() const noexcept
const BVH_CONTAINER_2D * GetPlatedPadsFront() const noexcept
unsigned int GetCircleSegmentCount(float aDiameter3DU) const
const BVH_CONTAINER_2D & GetThroughHoleAnnularRings() const noexcept
bool Is3dLayerEnabled(PCB_LAYER_ID aLayer) const
Check if a layer is enabled.
const SHAPE_POLY_SET & GetThroughHoleViaOdPolys() const noexcept
const BVH_CONTAINER_2D & GetThroughHoleOds() const noexcept
S3D_CACHE * Get3dCacheManager() const noexcept
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
FOOTPRINTS & Footprints()
PROJECT * GetProject() const
void SetBoardLookAtPos(const SFVEC3F &aBoardPos)
const LIST_OBJECT2D & GetList() const
Create and handle a window for the 3d viewer connected to a Kiway and a pcbboard.
const SFVEC2F & GetCenter() const
Hold a record identifying a library accessed by the appropriate footprint library PLUGIN object in th...
const FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName, bool aCheckIfEnabled=false)
Return an FP_LIB_TABLE_ROW if aNickName is found in this table or in any chained fall back table frag...
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
static OBJECT_2D_STATS & Instance()
OBJECT_2D_TYPE GetObjectType() const
Store the OpenGL display lists to related with a layer.
void SetItIsTransparent(bool aSetTransparent)
Simple non-intersecting polygon with 4 points.
const SFVEC2F & GetV3() const
const SFVEC2F & GetV0() const
const SFVEC2F & GetV1() const
const SFVEC2F & GetV2() const
virtual FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
CAMERA & m_camera
Flag if the opengl specific for this render was already initialized.
bool m_reloadRequested
The window size that this camera is working.
EDA_3D_CANVAS * m_canvas
Settings reference in use for this render.
BOARD_ADAPTER & m_boardAdapter
OPENGL_RENDER_LIST * m_board
void reload(REPORTER *aStatusReporter, REPORTER *aWarningReporter)
OPENGL_RENDER_LIST * m_vias
OPENGL_RENDER_LIST * generateHoles(const LIST_OBJECT2D &aListHolesObject2d, const SHAPE_POLY_SET &aPoly, float aZtop, float aZbot, bool aInvertFaces, const BVH_CONTAINER_2D *aThroughHoles=nullptr)
void generateCylinder(const SFVEC2F &aCenter, float aInnerRadius, float aOuterRadius, float aZtop, float aZbot, unsigned int aNr_sides_per_circle, TRIANGLE_DISPLAY_LIST *aDstLayer)
OPENGL_RENDER_LIST * m_outerThroughHoleRings
void generateRing(const SFVEC2F &aCenter, float aInnerRadius, float aOuterRadius, unsigned int aNr_sides_per_circle, std::vector< SFVEC2F > &aInnerContourResult, std::vector< SFVEC2F > &aOuterContourResult, bool aInvertOrder)
OPENGL_RENDER_LIST * generateEmptyLayerList(PCB_LAYER_ID aLayerId)
SHAPE_POLY_SET m_antiBoardPolys
The negative polygon representation of the board outline.
void load3dModels(REPORTER *aStatusReporter)
Load footprint models from the cache and load it to openGL lists in the form of MODEL_3D objects.
void generateViasAndPads()
OPENGL_RENDER_LIST * createBoard(const SHAPE_POLY_SET &aBoardPoly, const BVH_CONTAINER_2D *aThroughHoles=nullptr)
void Load3dModelsIfNeeded()
Load footprint models if they are not already loaded, i.e.
void addObjectTriangles(const RING_2D *aRing, TRIANGLE_DISPLAY_LIST *aDstLayer, float aZtop, float aZbot)
MAP_OGL_DISP_LISTS m_layers
MAP_OGL_DISP_LISTS m_innerLayerHoles
OPENGL_RENDER_LIST * m_boardWithHoles
OPENGL_RENDER_LIST * generateLayerList(const BVH_CONTAINER_2D *aContainer, const SHAPE_POLY_SET *aPolyList, PCB_LAYER_ID aLayerId, const BVH_CONTAINER_2D *aThroughHoles=nullptr)
MAP_OGL_DISP_LISTS m_outerLayerHoles
LIST_TRIANGLES m_triangles
store pointers so can be deleted latter
OPENGL_RENDER_LIST * m_outerViaThroughHoles
OPENGL_RENDER_LIST * m_outerThroughHoles
std::map< wxString, MODEL_3D * > m_3dModelMap
OPENGL_RENDER_LIST * m_platedPadsFront
OPENGL_RENDER_LIST * m_antiBoard
void getLayerZPos(PCB_LAYER_ID aLayerID, float &aOutZtop, float &aOutZbot) const
OPENGL_RENDER_LIST * m_padHoles
void addTopAndBottomTriangles(TRIANGLE_DISPLAY_LIST *aDst, const SFVEC2F &v0, const SFVEC2F &v1, const SFVEC2F &v2, float top, float bot)
OPENGL_RENDER_LIST * m_platedPadsBack
A pure virtual class used to derive REPORTER objects from.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
float GetOuterRadius() const
float GetInnerRadius() const
const SFVEC2F & GetCenter() const
const SFVEC2F & GetLeftEnd() const
const SFVEC2F & GetRightEnd() const
const SFVEC2F & GetLeftStar() const
const SFVEC2F & GetLeftDir() const
const SFVEC2F & GetEnd() const
float GetRadiusSquared() const
const SFVEC2F & GetStart() const
const SFVEC2F & GetRightDir() const
const SFVEC2F & GetRightStar() const
S3DMODEL * GetModel(const wxString &aModelFileName, const wxString &aBasePath)
Attempt to load the scene data for a model and to translate it into an S3D_MODEL structure for displa...
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
Represent a set of closed polygons.
void BooleanSubtract(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Perform boolean polyset intersection For aFastMode meaning, see function booleanOp.
void BooleanIntersection(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Perform boolean polyset union between a and b, store the result in it self For aFastMode meaning,...
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Add a new vertex to the contour indexed by aOutline and aHole (defaults to the outline of the last po...
SHAPE_LINE_CHAIN & Outline(int aIndex)
int NewOutline()
Creates a new hole in a given outline.
int OutlineCount() const
Return the number of vertices in a given outline/hole.
SHAPE_POLY_SET CloneDropTriangulation() const
Creates a new empty polygon in the set and returns its index.
A wrapper for reporting to a specific text location in a statusbar.
const SFVEC2F & GetP2() const
const SFVEC2F & GetP3() const
const SFVEC2F & GetP1() const
Store arrays of triangles to be used to create display lists.
TRIANGLE_LIST * m_layer_bot_segment_ends
TRIANGLE_LIST * m_layer_top_segment_ends
TRIANGLE_LIST * m_layer_bot_triangles
TRIANGLE_LIST * m_layer_top_triangles
void AddToMiddleContourns(const SHAPE_LINE_CHAIN &outlinePath, float zBot, float zTop, double aBiuTo3Du, bool aInvertFaceDirection, const BVH_CONTAINER_2D *aThroughHoles=nullptr)
void AddTriangle(const SFVEC3F &aV1, const SFVEC3F &aV2, const SFVEC3F &aV3)
void AddQuad(const SFVEC3F &aV1, const SFVEC3F &aV2, const SFVEC3F &aV3, const SFVEC3F &aV4)
std::list< OBJECT_2D * > LIST_OBJECT2D
PCB_LAYER_ID
A quick note on layer IDs:
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
@ NPTH
like PAD_PTH, but not plated
unsigned GetRunningMicroSecs()
An alternate way to calculate an elapsed time (in microsecondes) to class PROF_COUNTER.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
#define SIZE_OF_CIRCLE_TEXTURE
std::vector< FAB_LAYER_COLOR > dummy
bool show_footprints_normal
MATERIAL_MODE material_mode
bool show_footprints_virtual
bool subtract_mask_from_silk
bool renderPlatedPadsAsPlated
bool show_footprints_insert
bool clip_silk_on_via_annulus
Store the a model based on meshes and materials.
VECTOR2I v2(1, 0)
Test suite for KiCad math code.
void ConvertPolygonToTriangles(const SHAPE_POLY_SET &aPolyList, CONTAINER_2D_BASE &aDstContainer, float aBiuTo3dUnitsScale, const BOARD_ITEM &aBoardItem)
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)