29 #include "../../3d_math.h" 42 const float radius = aFilledCircle->
GetRadius() * 2.0f;
46 const float f = ( sqrtf( 2.0f ) / 2.0f ) * radius * texture_factor;
50 SFVEC3F( center.x - f, center.y, aZtop ),
51 SFVEC3F( center.x, center.y - f, aZtop ) );
54 SFVEC3F( center.x + f, center.y, aZtop ),
55 SFVEC3F( center.x, center.y + f, aZtop ) );
58 SFVEC3F( center.x + f, center.y, aZbot ),
59 SFVEC3F( center.x, center.y - f, aZbot ) );
62 SFVEC3F( center.x - f, center.y, aZbot ),
63 SFVEC3F( center.x, center.y + f, aZbot ) );
69 float aZtop,
float aZbot )
82 float aOuterRadius,
unsigned int aNr_sides_per_circle,
83 std::vector< SFVEC2F >& aInnerContourResult,
84 std::vector< SFVEC2F >& aOuterContourResult,
87 aInnerContourResult.clear();
88 aInnerContourResult.reserve( aNr_sides_per_circle + 2 );
90 aOuterContourResult.clear();
91 aOuterContourResult.reserve( aNr_sides_per_circle + 2 );
93 const int delta = 3600 / aNr_sides_per_circle;
95 for(
int ii = 0; ii < 3600; ii +=
delta )
97 float angle = (float)( aInvertOrder ? ( 3600 - ii ) : ii )
98 * 2.0f * glm::pi<float>() / 3600.0f;
101 aInnerContourResult.emplace_back( aCenter.x + rotatedDir.x * aInnerRadius,
102 aCenter.y + rotatedDir.y * aInnerRadius );
104 aOuterContourResult.emplace_back( aCenter.x + rotatedDir.x * aOuterRadius,
105 aCenter.y + rotatedDir.y * aOuterRadius );
108 aInnerContourResult.push_back( aInnerContourResult[0] );
109 aOuterContourResult.push_back( aOuterContourResult[0] );
111 wxASSERT( aInnerContourResult.size() == aOuterContourResult.size() );
116 float aZtop,
float aZbot )
122 std::vector< SFVEC2F > innerContour;
123 std::vector< SFVEC2F > outerContour;
126 innerContour, outerContour, false );
129 for(
unsigned int i = 0; i < ( innerContour.size() - 1 ); ++i )
131 const SFVEC2F& vi0 = innerContour[i + 0];
132 const SFVEC2F& vi1 = innerContour[i + 1];
133 const SFVEC2F& vo0 = outerContour[i + 0];
134 const SFVEC2F& vo1 = outerContour[i + 1];
137 SFVEC3F( vi0.x, vi0.y, aZtop ),
138 SFVEC3F( vo0.x, vo0.y, aZtop ),
139 SFVEC3F( vo1.x, vo1.y, aZtop ) );
142 SFVEC3F( vo1.x, vo1.y, aZbot ),
143 SFVEC3F( vo0.x, vo0.y, aZbot ),
144 SFVEC3F( vi0.x, vi0.y, aZbot ) );
151 float aZtop,
float aZbot )
163 float aZtop,
float aZbot )
180 const float radius_of_the_square = sqrtf( aSeg->
GetRadiusSquared() * 2.0f );
181 const float radius_triangle_factor = ( radius_of_the_square - radius ) / radius;
183 const SFVEC2F factorS =
SFVEC2F( -rightDir.y * radius * radius_triangle_factor,
184 rightDir.x * radius * radius_triangle_factor );
186 const SFVEC2F factorE =
SFVEC2F( -leftDir.y * radius * radius_triangle_factor,
187 leftDir.x * radius * radius_triangle_factor );
191 SFVEC3F( rightEnd.x + texture_factor * factorS.x,
192 rightEnd.y + texture_factor * factorS.y,
194 SFVEC3F( leftStart.x + texture_factor * factorE.x,
195 leftStart.y + texture_factor * factorE.y,
197 SFVEC3F( start.x - texture_factorF * leftDir.x * radius * sqrtf( 2.0f ),
198 start.y - texture_factorF * leftDir.y * radius * sqrtf( 2.0f ),
202 SFVEC3F( leftEnd.x + texture_factor * factorE.x,
203 leftEnd.y + texture_factor * factorE.y, aZtop ),
204 SFVEC3F( rightStart.x + texture_factor * factorS.x,
205 rightStart.y + texture_factor * factorS.y, aZtop ),
206 SFVEC3F( end.x - texture_factorF * rightDir.x * radius * sqrtf( 2.0f ),
207 end.y - texture_factorF * rightDir.y * radius * sqrtf( 2.0f ),
212 SFVEC3F( leftStart.x + texture_factor * factorE.x,
213 leftStart.y + texture_factor * factorE.y,
215 SFVEC3F( rightEnd.x + texture_factor * factorS.x,
216 rightEnd.y + texture_factor * factorS.y,
218 SFVEC3F( start.x - texture_factorF * leftDir.x * radius * sqrtf( 2.0f ),
219 start.y - texture_factorF * leftDir.y * radius * sqrtf( 2.0f ),
223 SFVEC3F( rightStart.x + texture_factor * factorS.x,
224 rightStart.y + texture_factor * factorS.y, aZbot ),
225 SFVEC3F( leftEnd.x + texture_factor * factorE.x,
226 leftEnd.y + texture_factor * factorE.y, aZbot ),
227 SFVEC3F( end.x - texture_factorF * rightDir.x * radius * sqrtf( 2.0f ),
228 end.y - texture_factorF * rightDir.y * radius * sqrtf( 2.0f ),
233 SFVEC3F( rightEnd.x, rightEnd.y, aZtop ),
234 SFVEC3F( rightStart.x, rightStart.y, aZtop ),
235 SFVEC3F( leftEnd.x, leftEnd.y, aZtop ),
236 SFVEC3F( leftStart.x, leftStart.y, aZtop ) );
239 SFVEC3F( rightEnd.x, rightEnd.y, aZbot ),
240 SFVEC3F( leftStart.x, leftStart.y, aZbot ),
241 SFVEC3F( leftEnd.x, leftEnd.y, aZbot ),
242 SFVEC3F( rightStart.x, rightStart.y, aZbot ) );
248 float aZbot,
bool aInvertFaces,
253 if( aListHolesObject2d.size() > 0 )
259 for(
const OBJECT_2D* itemOnLayer : aListHolesObject2d )
261 const OBJECT_2D* object2d_A = itemOnLayer;
270 layerTriangles, aZtop, aZbot );
275 layerTriangles, aZtop, aZbot );
279 wxFAIL_MSG( wxT(
"RENDER_3D_OPENGL::generateHoles: Object type not implemented" ) );
290 aInvertFaces, aThroughHoles );
295 delete layerTriangles;
307 if( aContainer ==
nullptr )
312 if( listObject2d.size() == 0 )
315 float layer_z_bot = 0.0f;
316 float layer_z_top = 0.0f;
321 unsigned int nrTrianglesEstimation = listObject2d.size() * 8;
329 for(
const OBJECT_2D* itemOnLayer : listObject2d )
331 const OBJECT_2D* object2d_A = itemOnLayer;
337 layerTriangles, layer_z_top, layer_z_bot );
342 layerTriangles, layer_z_top, layer_z_bot );
347 layerTriangles, layer_z_top, layer_z_bot );
352 layerTriangles, layer_z_top, layer_z_bot );
357 layerTriangles, layer_z_top, layer_z_bot );
361 wxFAIL_MSG( wxT(
"RENDER_3D_OPENGL: Object type is not implemented" ) );
379 float layer_z_bot = 0.0f;
380 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;
422 const TRIANGLE_2D* tri = static_cast<const TRIANGLE_2D*>( object2d_A );
424 const SFVEC2F& v1 = tri->GetP1();
426 const SFVEC2F& v3 = tri->GetP3();
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" ) );
506 outerPolyTHT, 1.0f, 0.0f,
false,
524 wxASSERT( innerMapHoles.size() == outerMapHoles.size() );
528 if( outerMapHoles.size() > 0 )
530 float layer_z_bot = 0.0f;
531 float layer_z_top = 0.0f;
533 for(
const auto ii : outerMapHoles )
542 layer_z_top, layer_z_bot, false );
545 for(
const auto ii : innerMapHoles )
554 layer_z_top, layer_z_bot, false );
562 if( aStatusReporter )
563 aStatusReporter->
Report(
_(
"Load OpenGL: layers" ) );
574 if( aStatusReporter )
576 _(
"Load OpenGL layer %d" ), (
int)layer_id ) );
585 if( map_poly.find( layer_id ) != map_poly.end() )
587 polyListSubtracted = *map_poly.at( layer_id );;
604 if( layer_id ==
B_SilkS && map_poly.find(
B_Mask ) != map_poly.end() )
609 else if( layer_id ==
F_SilkS && map_poly.find(
F_Mask ) != map_poly.end() )
617 polyList = &polyListSubtracted;
623 if( oglList !=
nullptr )
642 &polySubtracted,
F_Cu );
660 &polySubtracted,
B_Cu );
669 if( aStatusReporter )
670 aStatusReporter->
Report(
_(
"Loading 3D models..." ) );
674 if( aStatusReporter )
678 stats_startReloadTime) / 1e6;
704 if( aOutZtop < aOutZbot )
706 float tmpFloat = aOutZbot;
714 float aOuterRadius,
float aZtop,
float aZbot,
715 unsigned int aNr_sides_per_circle,
718 std::vector< SFVEC2F > innerContour;
719 std::vector< SFVEC2F > outerContour;
721 generateRing( aCenter, aInnerRadius, aOuterRadius, aNr_sides_per_circle, innerContour,
722 outerContour,
false );
724 for(
unsigned int i = 0; i < ( innerContour.size() - 1 ); ++i )
726 const SFVEC2F& vi0 = innerContour[i + 0];
727 const SFVEC2F& vi1 = innerContour[i + 1];
728 const SFVEC2F& vo0 = outerContour[i + 0];
729 const SFVEC2F& vo1 = outerContour[i + 1];
732 SFVEC3F( vi0.x, vi0.y, aZtop ),
733 SFVEC3F( vo0.x, vo0.y, aZtop ),
734 SFVEC3F( vo1.x, vo1.y, aZtop ) );
737 SFVEC3F( vo1.x, vo1.y, aZbot ),
738 SFVEC3F( vo0.x, vo0.y, aZbot ),
739 SFVEC3F( vi0.x, vi0.y, aZbot ) );
757 const unsigned int reserve_nr_triangles_estimation =
772 const PCB_VIA*
via = static_cast<const PCB_VIA*>( track );
776 const float hole_inner_radius = holediameter / 2.0f;
782 via->LayerPair( &top_layer, &bottom_layer );
784 float ztop, zbot,
dummy;
789 wxASSERT( zbot < ztop );
792 hole_inner_radius + platingThickness3d,
793 ztop, zbot, nrSegments, layerTriangleVIA );
799 delete layerTriangleVIA;
814 for(
const PAD*
pad : footprint->Pads() )
818 const wxSize drillsize =
pad->GetDrillSize();
819 const bool hasHole = drillsize.x && drillsize.y;
824 pad->TransformHoleWithClearanceToPolygon( tht_outer_holes_poly,
827 pad->TransformHoleWithClearanceToPolygon( tht_inner_holes_poly, 0,
847 if( listHolesObject2d.size() > 0 )
849 float layer_z_top, layer_z_bot,
dummy;
858 for(
const OBJECT_2D* itemOnLayer : listHolesObject2d )
860 const OBJECT_2D* object2d_A = itemOnLayer;
864 const TRIANGLE_2D* tri = static_cast<const TRIANGLE_2D*>( object2d_A );
866 const SFVEC2F& v1 = tri->GetP1();
868 const SFVEC2F& v3 = tri->GetP3();
878 layer_z_bot, layer_z_top,
882 layer_z_top, layer_z_top );
885 delete layerTriangles;
896 wxFrame* frame = dynamic_cast<EDA_3D_VIEWER_FRAME*>(
m_canvas->GetParent() );
924 for(
const FP_3DMODEL& model : footprint->Models() )
926 if( model.m_Show && !model.m_Filename.empty() )
928 if( aStatusReporter )
932 wxFileName fn( model.m_Filename );
934 fn.GetFullName() ) );
A wrapper for reporting to a specific text location in a statusbar.
OPENGL_RENDER_LIST * m_platedPadsBack
OPENGL_RENDER_LIST * m_antiBoard
bool GetFlag(DISPLAY3D_FLG aFlag) const
Get a configuration status of a flag.
void SetBoardLookAtPos(const SFVEC3F &aBoardPos)
BOARD_ADAPTER & m_boardAdapter
const SFVEC2F & GetV1() const
void ConvertPolygonToTriangles(SHAPE_POLY_SET &aPolyList, CONTAINER_2D_BASE &aDstContainer, float aBiuTo3dUnitsScale, const BOARD_ITEM &aBoardItem)
VECTOR2I v2(1, 0)
Test suite for KiCad math code.
OPENGL_RENDER_LIST * m_board
int OutlineCount() const
Return the number of vertices in a given outline/hole.
void addTopAndBottomTriangles(TRIANGLE_DISPLAY_LIST *aDst, const SFVEC2F &v0, const SFVEC2F &v1, const SFVEC2F &v2, float top, float bot)
const SFVEC2F & GetCenter() const
void Load3dModelsIfNeeded()
Load footprint models if they are not already loaded, i.e.
void load3dModels(REPORTER *aStatusReporter)
Load footprint models from the cache and load it to openGL lists in the form of MODEL_3D objects.
const SFVEC2F & GetP1() const
Store arrays of triangles to be used to create display lists.
float GetRadiusSquared() const
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
OPENGL_RENDER_LIST * m_outerViaThroughHoles
float GetInnerRadius() const
std::map< PCB_LAYER_ID, SHAPE_POLY_SET * > MAP_POLY
A type that stores polysets for each layer id.
const SFVEC2F & GetP2() const
OPENGL_RENDER_LIST * m_boardWithHoles
const SHAPE_POLY_SET & GetOuterNonPlatedThroughHolePoly() const noexcept
EDA_3D_CANVAS * m_canvas
Settings reference in use for this render.
const BVH_CONTAINER_2D & GetThroughHoleAnnularRings() const noexcept
Get the through hole annular rings container.
const SHAPE_POLY_SET & GetThroughHoleOdPolys() const noexcept
Get through hole outside diameter 2D polygons.
LIST_TRIANGLES m_triangles
store pointers so can be deleted latter
void generateViasAndPads()
MAP_OGL_DISP_LISTS m_innerLayerHoles
OPENGL_RENDER_LIST * generateEmptyLayerList(PCB_LAYER_ID aLayerId)
const MAP_CONTAINER_2D_BASE & GetLayerMap() const noexcept
Get the map of containers that have the objects per layer.
void getLayerZPos(PCB_LAYER_ID aLayerID, float &aOutZtop, float &aOutZbot) const
TRIANGLE_LIST * m_layer_top_triangles
void InitSettings(REPORTER *aStatusReporter, REPORTER *aWarningReporter)
Function to be called by the render when it need to reload the settings for the board.
MAP_OGL_DISP_LISTS m_layers
OPENGL_RENDER_LIST * m_outerThroughHoles
const SHAPE_POLY_SET & GetThroughHoleViaOdPolys() const noexcept
const SHAPE_POLY_SET * GetFrontPlatedPadPolys()
A pure virtual class used to derive REPORTER objects from.
float GetOuterRadius() const
SHAPE_POLY_SET m_antiBoardPolys
The negative polygon representation of the board outline.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
const SHAPE_POLY_SET * GetBackPlatedPadPolys()
const SHAPE_POLY_SET & GetThroughHoleAnnularRingPolys() const noexcept
const LIST_OBJECT2D & GetList() const
S3DMODEL * GetModel(const wxString &aModelFileName)
Attempt to load the scene data for a model and to translate it into an S3D_MODEL structure for displa...
const BVH_CONTAINER_2D & GetThroughHoleIds() const noexcept
Get the through hole inner diameter container.
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
bool Is3dLayerEnabled(PCB_LAYER_ID aLayer) const
Check if a layer is enabled.
#define SIZE_OF_CIRCLE_TEXTURE
OPENGL_RENDER_LIST * m_vias
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
like PAD_PTH, but not plated
void reload(REPORTER *aStatusReporter, REPORTER *aWarningReporter)
const BVH_CONTAINER_2D * GetPlatedPadsBack() const noexcept
const SFVEC2F & GetV2() const
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)
S3D_CACHE * Get3dCacheManager() const noexcept
Return the 3D cache manager pointer.
const SFVEC2F & GetLeftEnd() const
Represent a set of closed polygons.
SHAPE_LINE_CHAIN & Outline(int aIndex)
float GetLayerTopZPos(PCB_LAYER_ID aLayerId) const noexcept
Get the top z position.
MAP_OGL_DISP_LISTS m_outerLayerHoles
const SFVEC2F & GetEnd() const
const SFVEC2F & GetLeftStar() const
FOOTPRINTS & Footprints()
float GetLayerBottomZPos(PCB_LAYER_ID aLayerId) const noexcept
Get the bottom z position.
MATERIAL_MODE GetMaterialMode() const noexcept
OPENGL_RENDER_LIST * m_outerThroughHoleRings
static OBJECT_2D_STATS & Instance()
double BiuTo3dUnits() const noexcept
Board integer units To 3D units.
void AddQuad(const SFVEC3F &aV1, const SFVEC3F &aV2, const SFVEC3F &aV3, const SFVEC3F &aV4)
void AddTriangle(const SFVEC3F &aV1, const SFVEC3F &aV2, const SFVEC3F &aV3)
const BOARD * GetBoard() const noexcept
Get current board to be rendered.
const MAP_POLY & GetHoleIdPolysMap() const noexcept
const SFVEC2F & GetRightDir() const
OPENGL_RENDER_LIST * createBoard(const SHAPE_POLY_SET &aBoardPoly, const BVH_CONTAINER_2D *aThroughHoles=nullptr)
const BVH_CONTAINER_2D & GetThroughHoleOds() const noexcept
Get the inflated through hole outside diameters container.
const MAP_POLY & GetHoleOdPolysMap() const noexcept
void AddToMiddleContourns(const SHAPE_LINE_CHAIN &outlinePath, float zBot, float zTop, double aBiuTo3Du, bool aInvertFaceDirection, const BVH_CONTAINER_2D *aThroughHoles=nullptr)
TRIANGLE_LIST * m_layer_bot_triangles
OPENGL_RENDER_LIST * m_padHoles
OBJECT_2D_TYPE GetObjectType() const
const SHAPE_POLY_SET & GetBoardPoly() const noexcept
Get the current polygon of the epoxy board.
MATERIAL_MODE
Render 3d model shape materials mode.
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.
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 NewOutline()
Creates a new hole in a given outline.
OPENGL_RENDER_LIST * m_platedPadsFront
const MAP_POLY & GetPolyMap() const noexcept
Get map of polygon's layers.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Store the OpenGL display lists to related with a layer.
bool m_reloadRequested
The window size that this camera is working.
Simple non-intersecting polygon with 4 points.
void addObjectTriangles(const RING_2D *aRing, TRIANGLE_DISPLAY_LIST *aDstLayer, float aZtop, float aZbot)
unsigned int GetViaCount() const noexcept
Get number of vias in this board.
void generateCylinder(const SFVEC2F &aCenter, float aInnerRadius, float aOuterRadius, float aZtop, float aZbot, unsigned int aNr_sides_per_circle, TRIANGLE_DISPLAY_LIST *aDstLayer)
unsigned int GetHoleCount() const noexcept
Get number of holes in this board.
const BVH_CONTAINER_2D * GetPlatedPadsFront() const noexcept
const SFVEC2F & GetLeftDir() const
unsigned GetRunningMicroSecs()
An alternate way to calculate an elapsed time (in microsecondes) to class PROF_COUNTER.
PCB_LAYER_ID
A quick note on layer IDs:
const BVH_CONTAINER_2D & GetThroughHoleViaOds() const noexcept
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
const SFVEC3F & GetBoardCenter() const noexcept
The board center position in 3D units.
const SFVEC2F & GetRightEnd() const
float GetAverageViaHoleDiameter() const noexcept
Thee average diameter of the via holes.
CAMERA & m_camera
Flag if the opengl specific for this render was already initialized.
void SetItIsTransparent(bool aSetTransparent)
std::list< OBJECT_2D * > LIST_OBJECT2D
const SFVEC2F & GetV3() const
class PCB_VIA, a via (like a track segment on a copper layer)
Store the a model based on meshes and materials.
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)
TRIANGLE_LIST * m_layer_bot_segment_ends
void BooleanSubtract(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Perform boolean polyset intersection For aFastMode meaning, see function booleanOp.
const SFVEC2F & GetP3() const
const MAP_CONTAINER_2D_BASE & GetLayerHoleMap() const noexcept
Get the map of container that have the holes per layer.
const SFVEC2F & GetCenter() const
const SFVEC2F & GetStart() const
unsigned int GetCircleSegmentCount(float aDiameter3DU) const
const SFVEC2F & GetV0() const
TRIANGLE_LIST * m_layer_top_segment_ends
OPENGL_RENDER_LIST * generateLayerList(const BVH_CONTAINER_2D *aContainer, const SHAPE_POLY_SET *aPolyList, PCB_LAYER_ID aLayerId, const BVH_CONTAINER_2D *aThroughHoles=nullptr)
int GetHolePlatingThickness() const noexcept
Get the current copper layer thickness.
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...
const SFVEC2F & GetRightStar() const