29 #include "../../3d_math.h" 37 float aZtop,
float aZbot )
40 const float radius = aFilledCircle->
GetRadius() * 2.0f;
44 const float f = ( sqrtf( 2.0f ) / 2.0f ) * radius * texture_factor;
48 SFVEC3F( center.x - f, center.y, aZtop ),
49 SFVEC3F( center.x, center.y - f, aZtop ) );
52 SFVEC3F( center.x + f, center.y, aZtop ),
53 SFVEC3F( center.x, center.y + f, aZtop ) );
56 SFVEC3F( center.x + f, center.y, aZbot ),
57 SFVEC3F( center.x, center.y - f, aZbot ) );
60 SFVEC3F( center.x - f, center.y, aZbot ),
61 SFVEC3F( center.x, center.y + f, aZbot ) );
67 float aZtop,
float aZbot )
80 float aOuterRadius,
unsigned int aNr_sides_per_circle,
81 std::vector< SFVEC2F >& aInnerContourResult,
82 std::vector< SFVEC2F >& aOuterContourResult,
85 aInnerContourResult.clear();
86 aInnerContourResult.reserve( aNr_sides_per_circle + 2 );
88 aOuterContourResult.clear();
89 aOuterContourResult.reserve( aNr_sides_per_circle + 2 );
91 const int delta = 3600 / aNr_sides_per_circle;
93 for(
int ii = 0; ii < 3600; ii += delta )
95 float angle = (float)( aInvertOrder ? ( 3600 - ii ) : ii )
96 * 2.0f * glm::pi<float>() / 3600.0f;
99 aInnerContourResult.emplace_back( aCenter.x + rotatedDir.x * aInnerRadius,
100 aCenter.y + rotatedDir.y * aInnerRadius );
102 aOuterContourResult.emplace_back( aCenter.x + rotatedDir.x * aOuterRadius,
103 aCenter.y + rotatedDir.y * aOuterRadius );
106 aInnerContourResult.push_back( aInnerContourResult[0] );
107 aOuterContourResult.push_back( aOuterContourResult[0] );
109 wxASSERT( aInnerContourResult.size() == aOuterContourResult.size() );
115 float aZtop,
float aZbot )
121 std::vector< SFVEC2F > innerContour;
122 std::vector< SFVEC2F > outerContour;
125 innerContour, outerContour, false );
128 for(
unsigned int i = 0; i < ( innerContour.size() - 1 ); ++i )
130 const SFVEC2F& vi0 = innerContour[i + 0];
131 const SFVEC2F& vi1 = innerContour[i + 1];
132 const SFVEC2F& vo0 = outerContour[i + 0];
133 const SFVEC2F& vo1 = outerContour[i + 1];
136 SFVEC3F( vi0.x, vi0.y, aZtop ),
137 SFVEC3F( vo0.x, vo0.y, aZtop ),
138 SFVEC3F( vo1.x, vo1.y, aZtop ) );
141 SFVEC3F( vo1.x, vo1.y, aZbot ),
142 SFVEC3F( vo0.x, vo0.y, aZbot ),
143 SFVEC3F( vi0.x, vi0.y, aZbot ) );
150 float aZtop,
float aZbot )
162 float aZtop,
float aZbot )
179 const float radius_of_the_square = sqrtf( aSeg->
GetRadiusSquared() * 2.0f );
180 const float radius_triangle_factor = ( radius_of_the_square - radius ) / radius;
182 const SFVEC2F factorS =
SFVEC2F( -rightDir.y * radius * radius_triangle_factor,
183 rightDir.x * radius * radius_triangle_factor );
185 const SFVEC2F factorE =
SFVEC2F( -leftDir.y * radius * radius_triangle_factor,
186 leftDir.x * radius * radius_triangle_factor );
190 SFVEC3F( rightEnd.x + texture_factor * factorS.x,
191 rightEnd.y + texture_factor * factorS.y,
193 SFVEC3F( leftStart.x + texture_factor * factorE.x,
194 leftStart.y + texture_factor * factorE.y,
196 SFVEC3F( start.x - texture_factorF * leftDir.x * radius * sqrtf( 2.0f ),
197 start.y - texture_factorF * leftDir.y * radius * sqrtf( 2.0f ),
201 SFVEC3F( leftEnd.x + texture_factor * factorE.x,
202 leftEnd.y + texture_factor * factorE.y, aZtop ),
203 SFVEC3F( rightStart.x + texture_factor * factorS.x,
204 rightStart.y + texture_factor * factorS.y, aZtop ),
205 SFVEC3F( end.x - texture_factorF * rightDir.x * radius * sqrtf( 2.0f ),
206 end.y - texture_factorF * rightDir.y * radius * sqrtf( 2.0f ),
211 SFVEC3F( leftStart.x + texture_factor * factorE.x,
212 leftStart.y + texture_factor * factorE.y,
214 SFVEC3F( rightEnd.x + texture_factor * factorS.x,
215 rightEnd.y + texture_factor * factorS.y,
217 SFVEC3F( start.x - texture_factorF * leftDir.x * radius * sqrtf( 2.0f ),
218 start.y - texture_factorF * leftDir.y * radius * sqrtf( 2.0f ),
222 SFVEC3F( rightStart.x + texture_factor * factorS.x,
223 rightStart.y + texture_factor * factorS.y, aZbot ),
224 SFVEC3F( leftEnd.x + texture_factor * factorE.x,
225 leftEnd.y + texture_factor * factorE.y, aZbot ),
226 SFVEC3F( end.x - texture_factorF * rightDir.x * radius * sqrtf( 2.0f ),
227 end.y - texture_factorF * rightDir.y * radius * sqrtf( 2.0f ),
232 SFVEC3F( rightEnd.x, rightEnd.y, aZtop ),
233 SFVEC3F( rightStart.x, rightStart.y, aZtop ),
234 SFVEC3F( leftEnd.x, leftEnd.y, aZtop ),
235 SFVEC3F( leftStart.x, leftStart.y, aZtop ) );
238 SFVEC3F( rightEnd.x, rightEnd.y, aZbot ),
239 SFVEC3F( leftStart.x, leftStart.y, aZbot ),
240 SFVEC3F( leftEnd.x, leftEnd.y, aZbot ),
241 SFVEC3F( rightStart.x, rightStart.y, aZbot ) );
247 float aZbot,
bool aInvertFaces,
252 if( aListHolesObject2d.size() > 0 )
258 for( LIST_OBJECT2D::const_iterator itemOnLayer = aListHolesObject2d.begin();
259 itemOnLayer != aListHolesObject2d.end();
262 const OBJECT_2D* object2d_A = static_cast<const OBJECT_2D*>( *itemOnLayer );
271 layerTriangles, aZtop, aZbot );
276 layerTriangles, aZtop, aZbot );
280 wxFAIL_MSG(
"RENDER_3D_LEGACY::generateHoles: Object type is 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( LIST_OBJECT2D::const_iterator itemOnLayer = listObject2d.begin();
331 itemOnLayer != listObject2d.end();
334 const OBJECT_2D* object2d_A = static_cast<const OBJECT_2D*>( *itemOnLayer );
340 layer_z_top, layer_z_bot );
345 layer_z_top, layer_z_bot );
360 layer_z_top, layer_z_bot );
364 wxFAIL_MSG(
"RENDER_3D_LEGACY: Object type is not implemented" );
392 if( listBoardObject2d.size() > 0 )
397 const float layer_z_top = 1.0f;
398 const float layer_z_bot = 0.0f;
404 for( LIST_OBJECT2D::const_iterator itemOnLayer = listBoardObject2d.begin();
405 itemOnLayer != listBoardObject2d.end();
408 const OBJECT_2D* object2d_A = static_cast<const OBJECT_2D*>( *itemOnLayer );
414 const SFVEC2F& v1 = tri->GetP1();
416 const SFVEC2F& v3 = tri->GetP3();
428 layer_z_top, layer_z_top );
431 delete layerTriangles;
453 if( aStatusReporter )
454 aStatusReporter->
Report(
_(
"Load OpenGL: board" ) );
486 if( aStatusReporter )
487 aStatusReporter->
Report(
_(
"Load OpenGL: holes and vias" ) );
496 outerPolyTHT, 1.0f, 0.0f,
false,
514 wxASSERT( innerMapHoles.size() == outerMapHoles.size() );
518 if( outerMapHoles.size() > 0 )
520 float layer_z_bot = 0.0f;
521 float layer_z_top = 0.0f;
523 for( MAP_POLY::const_iterator ii = outerMapHoles.begin(); ii != outerMapHoles.end(); ++ii )
525 PCB_LAYER_ID layer_id = static_cast<PCB_LAYER_ID>(ii->first);
526 const SHAPE_POLY_SET* poly = static_cast<const SHAPE_POLY_SET*>( ii->second );
532 layer_z_top, layer_z_bot, false );
535 for( MAP_POLY::const_iterator ii = innerMapHoles.begin(); ii != innerMapHoles.end(); ++ii )
537 PCB_LAYER_ID layer_id = static_cast<PCB_LAYER_ID>( ii->first );
538 const SHAPE_POLY_SET* poly = static_cast<const SHAPE_POLY_SET*>( ii->second );
544 layer_z_top, layer_z_bot, false );
552 if( aStatusReporter )
553 aStatusReporter->
Report(
_(
"Load OpenGL: layers" ) );
561 PCB_LAYER_ID layer_id = static_cast<PCB_LAYER_ID>( ii->first );
566 const BVH_CONTAINER_2D* container2d = static_cast<const BVH_CONTAINER_2D*>( ii->second );
573 if( map_poly.find( layer_id ) != map_poly.end() )
575 polyListSubtracted = *map_poly.at( layer_id );;
594 if( layer_id ==
B_SilkS && map_poly.find(
B_Mask ) != map_poly.end() )
599 else if( layer_id ==
F_SilkS && map_poly.find(
F_Mask ) != map_poly.end() )
608 aPolyList = &polyListSubtracted;
614 if( oglList !=
nullptr )
633 &polySubtracted,
F_Cu );
647 &polySubtracted,
B_Cu );
652 if( aStatusReporter )
653 aStatusReporter->
Report(
_(
"Loading 3D models" ) );
657 if( aStatusReporter )
661 stats_startReloadTime) / 1e6;
670 float top,
float bot )
683 float& aOutZbot )
const 688 if( aOutZtop < aOutZbot )
690 float tmpFloat = aOutZbot;
698 float aOuterRadius,
float aZtop,
float aZbot,
699 unsigned int aNr_sides_per_circle,
702 std::vector< SFVEC2F > innerContour;
703 std::vector< SFVEC2F > outerContour;
705 generateRing( aCenter, aInnerRadius, aOuterRadius, aNr_sides_per_circle, innerContour,
706 outerContour,
false );
708 for(
unsigned int i = 0; i < ( innerContour.size() - 1 ); ++i )
710 const SFVEC2F& vi0 = innerContour[i + 0];
711 const SFVEC2F& vi1 = innerContour[i + 1];
712 const SFVEC2F& vo0 = outerContour[i + 0];
713 const SFVEC2F& vo1 = outerContour[i + 1];
716 SFVEC3F( vi0.x, vi0.y, aZtop ),
717 SFVEC3F( vo0.x, vo0.y, aZtop ),
718 SFVEC3F( vo1.x, vo1.y, aZtop ) );
721 SFVEC3F( vo1.x, vo1.y, aZbot ),
722 SFVEC3F( vo0.x, vo0.y, aZbot ),
723 SFVEC3F( vi0.x, vi0.y, aZbot ) );
735 const unsigned int reserve_nr_triangles_estimation =
750 const VIA* via = static_cast<const VIA*>(track);
755 const float hole_inner_radius = holediameter / 2.0f;
761 via->
LayerPair( &top_layer, &bottom_layer );
763 float ztop, zbot,
dummy;
768 wxASSERT( zbot < ztop );
770 generateCylinder( via_center, hole_inner_radius, hole_inner_radius + thickness,
771 ztop, zbot, nrSegments, layerTriangleVIA );
777 delete layerTriangleVIA;
792 for(
PAD* pad : footprint->Pads() )
796 const wxSize drillsize = pad->GetDrillSize();
797 const bool hasHole = drillsize.x && drillsize.y;
804 pad->TransformHoleWithClearanceToPolygon( tht_outer_holes_poly,
807 pad->TransformHoleWithClearanceToPolygon( tht_inner_holes_poly, 0,
827 if( listHolesObject2d.size() > 0 )
829 float layer_z_top, layer_z_bot,
dummy;
838 for( LIST_OBJECT2D::const_iterator itemOnLayer = listHolesObject2d.begin();
839 itemOnLayer != listHolesObject2d.end();
842 const OBJECT_2D* object2d_A = static_cast<const OBJECT_2D*>( *itemOnLayer );
848 const SFVEC2F& v1 = tri->GetP1();
850 const SFVEC2F& v3 = tri->GetP3();
860 layer_z_bot, layer_z_top,
864 layer_z_top, layer_z_top );
867 delete layerTriangles;
885 for(
const FP_3DMODEL& model : footprint->Models() )
887 if( model.m_Show && !model.m_Filename.empty() )
889 if( aStatusReporter )
893 wxFileName fn( model.m_Filename );
895 msg.Printf(
_(
"Loading %s" ), fn.GetFullName() );
896 aStatusReporter->
Report( msg );
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 LayerPair(PCB_LAYER_ID *top_layer, PCB_LAYER_ID *bottom_layer) const
Function LayerPair Return the 2 layers used by the via (the via actually uses all layers between thes...
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.
int OutlineCount() const
Return the number of vertices in a given outline/hole.
void reload(REPORTER *aStatusReporter, REPORTER *aWarningReporter)
OPENGL_RENDER_LIST * createBoard(const SHAPE_POLY_SET &aBoardPoly, const BVH_CONTAINER_2D *aThroughHoles=nullptr)
const SFVEC2F & GetCenter() const
const SFVEC2F & GetP1() const
Store arrays of triangles to be used to create display lists.
float GetRadiusSquared() const
LIST_TRIANGLES m_triangles
store pointers so can be deleted latter
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
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
const SHAPE_POLY_SET & GetOuterNonPlatedThroughHolePoly() const noexcept
const wxPoint & GetStart() const
MAP_OGL_DISP_LISTS m_layers
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.
const MAP_CONTAINER_2D_BASE & GetLayerMap() const noexcept
Get the map of containers that have the objects per layer.
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.
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
OPENGL_RENDER_LIST * m_platedPadsFront
const SHAPE_POLY_SET & GetThroughHoleViaOdPolys() const noexcept
const SHAPE_POLY_SET * GetFrontPlatedPadPolys()
like PAD_PTH, but not plated mechanical use only, no connection allowed
A pure virtual class used to derive REPORTER objects from.
float GetOuterRadius() const
void addTopAndBottomTriangles(TRIANGLE_DISPLAY_LIST *aDst, const SFVEC2F &v0, const SFVEC2F &v1, const SFVEC2F &v2, float top, float bot)
void getLayerZPos(PCB_LAYER_ID aLayerID, float &aOutZtop, float &aOutZbot) const
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
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)
void generateCylinder(const SFVEC2F &aCenter, float aInnerRadius, float aOuterRadius, float aZtop, float aZbot, unsigned int aNr_sides_per_circle, TRIANGLE_DISPLAY_LIST *aDstLayer)
const SHAPE_POLY_SET * GetBackPlatedPadPolys()
OPENGL_RENDER_LIST * m_outerThroughHoles
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.
OPENGL_RENDER_LIST * m_outerThroughHoleRings
OPENGL_RENDER_LIST * m_boardWithHoles
bool Is3dLayerEnabled(PCB_LAYER_ID aLayer) const
Check if a layer is enabled.
void SetClosed(bool aClosed)
Function SetClosed()
PCB_LAYER_ID
A quick note on layer IDs:
const BVH_CONTAINER_2D * GetPlatedPadsBack() const noexcept
#define SIZE_OF_CIRCLE_TEXTURE
const SFVEC2F & GetV2() const
int GetDrillValue() const
Function GetDrillValue "calculates" the drill value for vias (m-Drill if > 0, or default drill value ...
S3D_CACHE * Get3dCacheManager() const noexcept
Return the 3D cache manager pointer.
const SFVEC2F & GetLeftEnd() const
MAP_OGL_DISP_LISTS m_outerLayerHoles
OPENGL_RENDER_LIST * m_antiBoard
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.
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
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)
OPENGL_RENDER_LIST * m_board
const BOARD * GetBoard() const noexcept
Get current board to be rendered.
const MAP_POLY & GetHoleIdPolysMap() const noexcept
void addObjectTriangles(const RING_2D *aRing, TRIANGLE_DISPLAY_LIST *aDstLayer, float aZtop, float aZbot)
const SFVEC2F & GetRightDir() const
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
OBJECT_2D_TYPE GetObjectType() const
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)
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 * generateLayerList(const BVH_CONTAINER_2D *aContainer, const SHAPE_POLY_SET *aPolyList, PCB_LAYER_ID aLayerId, const BVH_CONTAINER_2D *aThroughHoles=nullptr)
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()
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.
unsigned int GetViaCount() const noexcept
Get number of vias in this board.
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 elapset time (in microsecondes) to class PROF_COUNTER.
const BVH_CONTAINER_2D & GetThroughHoleViaOds() const noexcept
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
SHAPE_POLY_SET m_antiBoardPolys
The negative polygon representation of the board outline.
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
float GetCopperThickness() const noexcept
Get the current copper layer thickness.
const SFVEC2F & GetV3() const
class VIA, a via (like a track segment on a copper layer)
Store the a model based on meshes and materials.
OPENGL_RENDER_LIST * m_platedPadsBack
MAP_OGL_DISP_LISTS m_innerLayerHoles
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.
OPENGL_RENDER_LIST * m_vias
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
OPENGL_RENDER_LIST * m_padHoles
const SFVEC2F & GetV0() const
TRIANGLE_LIST * m_layer_top_segment_ends
OPENGL_RENDER_LIST * m_outerViaThroughHoles
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