39 std::shared_ptr<TRIANGLE_DISPLAY_LIST> aDstLayer,
float aZtop,
float aZbot )
46 const float f = ( sqrtf( 2.0f ) / 2.0f ) *
radius * texture_factor;
68 std::shared_ptr<TRIANGLE_DISPLAY_LIST> aDstLayer,
float aZtop,
float aZbot )
81 float aOuterRadius,
unsigned int aNr_sides_per_circle,
82 std::vector< SFVEC2F >& aInnerContourResult,
83 std::vector< SFVEC2F >& aOuterContourResult,
86 aInnerContourResult.clear();
87 aInnerContourResult.reserve( aNr_sides_per_circle + 2 );
89 aOuterContourResult.clear();
90 aOuterContourResult.reserve( aNr_sides_per_circle + 2 );
92 const int delta = 3600 / aNr_sides_per_circle;
94 for(
int ii = 0; ii < 3600; ii +=
delta )
96 float angle = (float)( aInvertOrder ? ( 3600 - ii ) : ii )
97 * 2.0f * glm::pi<float>() / 3600.0f;
100 aInnerContourResult.emplace_back( aCenter.x + rotatedDir.x * aInnerRadius,
101 aCenter.y + rotatedDir.y * aInnerRadius );
103 aOuterContourResult.emplace_back( aCenter.x + rotatedDir.x * aOuterRadius,
104 aCenter.y + rotatedDir.y * aOuterRadius );
107 aInnerContourResult.push_back( aInnerContourResult[0] );
108 aOuterContourResult.push_back( aOuterContourResult[0] );
110 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];
135 aDstLayer->m_layer_top_triangles->AddQuad(
SFVEC3F( vi1.x, vi1.y, aZtop ),
136 SFVEC3F( vi0.x, vi0.y, aZtop ),
137 SFVEC3F( vo0.x, vo0.y, aZtop ),
138 SFVEC3F( vo1.x, vo1.y, aZtop ) );
140 aDstLayer->m_layer_bot_triangles->AddQuad(
SFVEC3F( vi1.x, vi1.y, aZbot ),
141 SFVEC3F( vo1.x, vo1.y, aZbot ),
142 SFVEC3F( vo0.x, vo0.y, aZbot ),
143 SFVEC3F( vi0.x, vi0.y, aZbot ) );
149 float aZtop,
float aZbot )
160 std::shared_ptr<TRIANGLE_DISPLAY_LIST> aDstLayer,
float aZtop,
float aZbot )
177 const float radius_of_the_square = sqrtf( aSeg->
GetRadiusSquared() * 2.0f );
178 const float radius_triangle_factor = ( radius_of_the_square -
radius ) /
radius;
181 rightDir.x *
radius * radius_triangle_factor );
184 leftDir.x *
radius * radius_triangle_factor );
187 aDstLayer->m_layer_top_segment_ends->AddTriangle(
188 SFVEC3F( rightEnd.x + texture_factor * factorS.x,
189 rightEnd.y + texture_factor * factorS.y,
191 SFVEC3F( leftStart.x + texture_factor * factorE.x,
192 leftStart.y + texture_factor * factorE.y,
194 SFVEC3F( start.x - texture_factorF * leftDir.x *
radius * sqrtf( 2.0f ),
195 start.y - texture_factorF * leftDir.y *
radius * sqrtf( 2.0f ),
198 aDstLayer->m_layer_top_segment_ends->AddTriangle(
199 SFVEC3F( leftEnd.x + texture_factor * factorE.x,
200 leftEnd.y + texture_factor * factorE.y, aZtop ),
201 SFVEC3F( rightStart.x + texture_factor * factorS.x,
202 rightStart.y + texture_factor * factorS.y, aZtop ),
204 end.y - texture_factorF * rightDir.y *
radius * sqrtf( 2.0f ),
208 aDstLayer->m_layer_bot_segment_ends->AddTriangle(
209 SFVEC3F( leftStart.x + texture_factor * factorE.x,
210 leftStart.y + texture_factor * factorE.y,
212 SFVEC3F( rightEnd.x + texture_factor * factorS.x,
213 rightEnd.y + texture_factor * factorS.y,
215 SFVEC3F( start.x - texture_factorF * leftDir.x *
radius * sqrtf( 2.0f ),
216 start.y - texture_factorF * leftDir.y *
radius * sqrtf( 2.0f ),
219 aDstLayer->m_layer_bot_segment_ends->AddTriangle(
220 SFVEC3F( rightStart.x + texture_factor * factorS.x,
221 rightStart.y + texture_factor * factorS.y, aZbot ),
222 SFVEC3F( leftEnd.x + texture_factor * factorE.x,
223 leftEnd.y + texture_factor * factorE.y, aZbot ),
225 end.y - texture_factorF * rightDir.y *
radius * sqrtf( 2.0f ),
229 aDstLayer->m_layer_top_triangles->AddQuad(
230 SFVEC3F( rightEnd.x, rightEnd.y, aZtop ),
231 SFVEC3F( rightStart.x, rightStart.y, aZtop ),
232 SFVEC3F( leftEnd.x, leftEnd.y, aZtop ),
233 SFVEC3F( leftStart.x, leftStart.y, aZtop ) );
235 aDstLayer->m_layer_bot_triangles->AddQuad(
236 SFVEC3F( rightEnd.x, rightEnd.y, aZbot ),
237 SFVEC3F( leftStart.x, leftStart.y, aZbot ),
238 SFVEC3F( leftEnd.x, leftEnd.y, aZbot ),
239 SFVEC3F( rightStart.x, rightStart.y, aZbot ) );
245 float aZbot,
bool aInvertFaces,
248 if( aListHolesObject2d.size() == 0 )
251 auto triangles = std::make_shared<TRIANGLE_DISPLAY_LIST>( aListHolesObject2d.size() * 2 );
254 for(
const OBJECT_2D* object2d : aListHolesObject2d )
256 switch( object2d->GetObjectType() )
267 wxFAIL_MSG( wxT(
"RENDER_3D_OPENGL::generateHoles: Object type not implemented" ) );
276 triangles->AddToMiddleContours( aPoly, aZbot, aZtop,
m_boardAdapter.BiuTo3dUnits(), aInvertFaces,
280 return std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( triangles,
m_circleTexture, aZbot, aZtop );
284std::shared_ptr<OPENGL_RENDER_LIST_DEFERRED>
288 if( aContainer ==
nullptr )
293 if( listObject2d.size() == 0 )
302 unsigned int nrTrianglesEstimation = listObject2d.size() * 8;
304 auto layerTriangles = std::make_shared<TRIANGLE_DISPLAY_LIST>( nrTrianglesEstimation );
310 for(
const OBJECT_2D* object2d : listObject2d )
312 switch( object2d->GetObjectType() )
335 wxFAIL_MSG( wxT(
"RENDER_3D_OPENGL: Object type is not implemented" ) );
342 layerTriangles->AddToMiddleContours( *aPolyList, zBot, zTop,
m_boardAdapter.BiuTo3dUnits(),
false,
347 return std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( layerTriangles,
m_circleTexture, zBot, zTop );
353 float layer_z_bot = 0.0f;
354 float layer_z_top = 0.0f;
358 auto layerTriangles = std::make_shared<TRIANGLE_DISPLAY_LIST>( 1 );
363 return std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( layerTriangles,
m_circleTexture, layer_z_bot, layer_z_top );
371 std::shared_ptr<OPENGL_RENDER_LIST_DEFERRED> dispLists;
379 if( listBoardObject2d.size() > 0 )
383 const float layer_z_top = 1.0f;
384 const float layer_z_bot = 0.0f;
386 auto triangles = std::make_shared<TRIANGLE_DISPLAY_LIST>( listBoardObject2d.size() );
389 for(
const OBJECT_2D* itemOnLayer : listBoardObject2d )
391 const OBJECT_2D* object2d_A = itemOnLayer;
406 triangles->AddToMiddleContours( aBoardPoly, layer_z_bot, layer_z_top,
m_boardAdapter.BiuTo3dUnits(),
407 false, aThroughHoles );
409 dispLists = std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( triangles,
m_circleTexture, 0.0f, 0.0f,
436 const float platingThickness = (float)
m_boardAdapter.GetHolePlatingThickness();
439 const float boardZTop = 1.0f;
440 const float boardZBot = 0.0f;
444 [&](
float absZ ) ->
float
448 float boardThick = boardTop - boardBot;
450 if( boardThick <= 0 )
454 return ( absZ - boardBot ) / boardThick;
458 std::shared_ptr<TRIANGLE_DISPLAY_LIST> plugTriangles = std::make_shared<TRIANGLE_DISPLAY_LIST>( 1024 );
461 [&](
const SFVEC2F center,
const float holeOuterR,
const float plugR,
unsigned int nrSegments,
462 const float plugZTop,
const float plugZBot,
const EDA_ANGLE topAngle,
const EDA_ANGLE botAngle )
467 float middle = ( plugZTop + plugZBot ) / 2.0f;
469 nrSegments, plugTriangles, topAngle,
true );
471 nrSegments, plugTriangles, botAngle,
false );
476 nrSegments, plugTriangles, topAngle,
true );
481 nrSegments, plugTriangles, botAngle,
false );
486 nrSegments, plugTriangles );
498 const float holeInnerR = (float)
via->GetDrillValue() * 0.5f * unitScale;
499 const float holeOuterR = holeInnerR + platingThickness * unitScale;
500 const SFVEC2F center( (
float)
via->GetStart().x * unitScale, - (
float)
via->GetStart().y * unitScale );
501 const unsigned int nrSegments =
m_boardAdapter.GetCircleSegmentCount(
via->GetDrillValue() );
504 via->LayerPair( &topLayer, &bottomLayer );
506 float viaZTop, viaZBot, plugZTop, plugZBot;
512 float plugR = holeOuterR;
516 via->Padstack().TertiaryDrill() } )
518 if( backdrill.start ==
F_Cu && backdrill.size.x > 0 )
526 float depth = (float) depthIU * unitScale;
527 float drillRadius = (float) backdrill.size.x * 0.5f * unitScale;
531 plugZTop = std::min( plugZTop, viaZTop - depth );
532 plugR = std::max( plugR, drillRadius );
534 else if( backdrill.end ==
B_Cu && backdrill.size.x > 0 )
542 float depth = (float) depthIU * unitScale;
543 float drillRadius = (float) backdrill.size.x * 0.5f * unitScale;
547 plugZBot = std::max( plugZBot, viaZBot + depth );
548 plugR = std::max( plugR, drillRadius );
556 const float postMachiningR = (float)
via->GetFrontPostMachiningSize() * 0.5f * unitScale;
557 const float postMachiningDepth = (float)
via->GetFrontPostMachiningDepth() * unitScale;
559 if( postMachiningR > holeOuterR && postMachiningDepth > 0 )
563 plugZTop = std::min( plugZTop, viaZTop - postMachiningDepth );
564 plugR = std::max( plugR, postMachiningR );
575 const float postMachiningR = (float)
via->GetBackPostMachiningSize() * 0.5f * unitScale;
576 const float postMachiningDepth = (float)
via->GetBackPostMachiningDepth() * unitScale;
578 if( postMachiningR > holeOuterR && postMachiningDepth > 0 )
582 plugZBot = std::max( plugZBot, viaZBot + postMachiningDepth );
583 plugR = std::max( plugR, postMachiningR );
590 generatePlug(
center, holeOuterR, plugR, nrSegments, plugZTop, plugZBot, topAngle, botAngle );
596 for(
const PAD*
pad : footprint->Pads() )
598 if( !
pad->HasHole() )
604 const SFVEC2F padCenter( (
float)
pad->GetPosition().x * unitScale,
605 - (
float)
pad->GetPosition().y * unitScale );
606 const float holeInnerR = (float)
pad->GetDrillSize().x * 0.5f * unitScale;
607 const float holeOuterR = holeInnerR + platingThickness * unitScale;
608 const unsigned int nrSegments =
m_boardAdapter.GetCircleSegmentCount(
pad->GetDrillSize().x );
610 float padZTop, padZBot, plugZTop, plugZBot;
616 float plugR = holeOuterR;
620 pad->Padstack().TertiaryDrill() } )
622 if( backdrill.start ==
F_Cu && backdrill.size.x > 0 )
630 float depth = (float) depthIU * unitScale;
631 float drillRadius = (float) backdrill.size.x * 0.5f * unitScale;
635 plugZTop = std::min( plugZTop, padZTop - depth );
636 plugR = std::max( plugR, drillRadius );
638 else if( backdrill.end ==
B_Cu && backdrill.size.x > 0 )
646 float depth = (float) depthIU * unitScale;
647 float drillRadius = (float) backdrill.size.x * 0.5f * unitScale;
651 plugZBot = std::max( plugZBot, padZBot + depth );
652 plugR = std::max( plugR, drillRadius );
660 const float postMachiningR = (float)
pad->GetFrontPostMachiningSize() * 0.5f * unitScale;
661 const float postMachiningDepth = (float)
pad->GetFrontPostMachiningDepth() * unitScale;
663 if( postMachiningR > holeOuterR && postMachiningDepth > 0 )
667 plugZTop = std::min( plugZTop, padZTop - postMachiningDepth );
668 plugR = std::max( plugR, postMachiningR );
679 const float postMachiningR = (float)
pad->GetBackPostMachiningSize() * 0.5f * unitScale;
680 const float postMachiningDepth = (float)
pad->GetBackPostMachiningDepth() * unitScale;
682 if( postMachiningR > holeOuterR && postMachiningDepth > 0 )
686 plugZBot = std::max( plugZBot, padZBot + postMachiningDepth );
687 plugR = std::max( plugR, postMachiningR );
694 generatePlug( padCenter, holeOuterR, plugR, nrSegments, plugZTop, plugZBot, topAngle, botAngle );
699 if( plugTriangles->m_layer_top_triangles->GetVertexSize() > 0
700 || plugTriangles->m_layer_bot_triangles->GetVertexSize() > 0
701 || plugTriangles->m_layer_middle_contours_quads->GetVertexSize() > 0 )
710 boardZBot, boardZTop ) );
745 bool isBack = fp->IsFlipped();
747 float standoff3d = body->
m_standoff * biuTo3d;
755 zBot = boardSurfaceZ + standoff3d + zOffset3d;
756 zTop = zBot + bodyThickness;
760 zTop = boardSurfaceZ - standoff3d - zOffset3d;
761 zBot = zTop - bodyThickness;
767 if( triangleContainer.
GetList().empty() )
770 auto triangles = std::make_shared<TRIANGLE_DISPLAY_LIST>( triangleContainer.
GetList().size() );
778 triangles->AddToMiddleContours( outline, zBot, zTop, biuTo3d,
false );
780 auto renderList = std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( triangles,
m_circleTexture, zTop, zBot );
787 if( standoff3d > 0.0f )
794 float oppositeSurfaceZ =
m_boardAdapter.GetFootprintZPos( !isBack );
795 float protrusion = 1.0f *
pcbIUScale.IU_PER_MM * biuTo3d;
796 float pinZBot, pinZTop;
800 pinZBot = oppositeSurfaceZ - protrusion + zOffset3d;
801 pinZTop = boardSurfaceZ + standoff3d + zOffset3d;
805 pinZTop = oppositeSurfaceZ + protrusion - zOffset3d;
806 pinZBot = boardSurfaceZ - standoff3d - zOffset3d;
820 if( pinTriangleContainer.
GetList().empty() )
823 auto pinTriangles = std::make_shared<TRIANGLE_DISPLAY_LIST>( pinTriangleContainer.
GetList().size() );
832 pinTriangles->AddToMiddleContours( aPoly, pinZBot, pinZTop, biuTo3d,
false );
834 auto pinRenderList = std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( pinTriangles,
862 m_canvas->InvalidateRaytracingHitTesting();
874 m_camera.SetBoardLookAtPos( camera_pos );
894 if( aStop.stop_requested() )
899 m_canvas->InvalidateRaytracingHitTesting();
903 if( aStop.stop_requested() )
914 if( aStop.stop_requested() )
931 if( aStop.stop_requested() )
939 if(
m_boardAdapter.GetFrontCounterborePolys().OutlineCount() > 0 )
945 if(
m_boardAdapter.GetFrontCountersinkPolys().OutlineCount() > 0 )
957 if( aStop.stop_requested() )
965 if( aStop.stop_requested() )
985 frontODs.emplace_back( obj );
988 frontODs.emplace_back( obj );
996 backODs.emplace_back( obj );
999 backODs.emplace_back( obj );
1014 wxASSERT( innerMapHoles.size() == outerMapHoles.size() );
1018 if( outerMapHoles.size() > 0 )
1020 float layer_z_bot = 0.0f;
1021 float layer_z_top = 0.0f;
1023 for(
const auto& [ layer, poly ] : outerMapHoles )
1028 layer_z_top, layer_z_bot,
false ) );
1031 for(
const auto& [ layer, poly ] : innerMapHoles )
1036 layer_z_top, layer_z_bot,
false ) );
1043 if( aStop.stop_requested() )
1052 std::bitset<LAYER_3D_END> visibilityFlags =
m_boardAdapter.GetVisibleLayers();
1056 for(
const auto& [ layer, container2d ] :
m_boardAdapter.GetLayerMap() )
1074 if( map_poly.contains( layer ) )
1076 polyListSubtracted = *map_poly.at( layer );
1094 else if( layer ==
B_Cu )
1113 polyList = &polyListSubtracted;
1117 if( aStop.stop_requested() )
1120 std::shared_ptr<OPENGL_RENDER_LIST_DEFERRED> oglList =
1123 if( oglList !=
nullptr )
1126 if( aStop.stop_requested() )
1137 if( frontPlatedCopperPolys )
1154 if( backPlatedCopperPolys )
1181 if( aStop.stop_requested() )
1194 if( aStop.stop_requested() )
1203 if( !aStop.stop_requested() &&
m_canvas )
1209 if( aStop.stop_requested() )
1217 m_activityReporter->Report( wxString::Format(
_(
"Load completed in %.3f s" ), calculation_time ) );
1224 wxLogTrace(
m_logTrace, wxT(
"RENDER_3D_OPENGL::startBgWorker" ) );
1230 [
this]( std::stop_token aStopToken )
1233 BS::this_thread::set_os_thread_priority( BS::os_thread_priority::below_normal );
1251 [
this]( std::stop_token aStop )
1253 BS::this_thread::set_os_thread_priority( BS::os_thread_priority::below_normal );
1268 if( aStop.stop_requested() || !
m_canvas )
1271 m_canvas->ReloadRaytracingForHitTesting( aStop );
1285 wxLogTrace(
m_logTrace, wxT(
"RENDER_3D_OPENGL::StopBgWorker" ) );
1302 wxLogTrace(
m_logTrace, wxT(
"RENDER_3D_OPENGL::JoinBgWorker" ) );
1312 aDst->m_layer_bot_triangles->AddTriangle(
SFVEC3F( v0.x, v0.y, bot ),
1316 aDst->m_layer_top_triangles->AddTriangle(
SFVEC3F(
v2.x,
v2.y,
top ),
1327 if( aOutZtop < aOutZbot )
1328 std::swap( aOutZtop, aOutZbot );
1333 float aZbot,
unsigned int aNr_sides_per_circle,
1334 std::shared_ptr<TRIANGLE_DISPLAY_LIST> aDstLayer )
1336 std::vector< SFVEC2F > innerContour;
1337 std::vector< SFVEC2F > outerContour;
1339 generateRing( aCenter, aInnerRadius, aOuterRadius, aNr_sides_per_circle, innerContour,
1340 outerContour,
false );
1342 for(
unsigned int i = 0; i < ( innerContour.size() - 1 ); ++i )
1344 const SFVEC2F& vi0 = innerContour[i + 0];
1345 const SFVEC2F& vi1 = innerContour[i + 1];
1346 const SFVEC2F& vo0 = outerContour[i + 0];
1347 const SFVEC2F& vo1 = outerContour[i + 1];
1349 aDstLayer->m_layer_top_triangles->AddQuad(
SFVEC3F( vi1.x, vi1.y, aZtop ),
1350 SFVEC3F( vi0.x, vi0.y, aZtop ),
1351 SFVEC3F( vo0.x, vo0.y, aZtop ),
1352 SFVEC3F( vo1.x, vo1.y, aZtop ) );
1354 aDstLayer->m_layer_bot_triangles->AddQuad(
SFVEC3F( vi1.x, vi1.y, aZbot ),
1355 SFVEC3F( vo1.x, vo1.y, aZbot ),
1356 SFVEC3F( vo0.x, vo0.y, aZbot ),
1357 SFVEC3F( vi0.x, vi0.y, aZbot ) );
1360 aDstLayer->AddToMiddleContours( outerContour, aZbot, aZtop,
true );
1361 aDstLayer->AddToMiddleContours( innerContour, aZbot, aZtop,
false );
1366 float aZbot,
unsigned int aNr_sides_per_circle,
1367 std::shared_ptr<TRIANGLE_DISPLAY_LIST> aDstLayer,
EDA_ANGLE aAngle,
1379 float radialDiff = aOuterRadius - aInnerRadius;
1383 if( angleRad < 0.01f )
1386 float innerHeight = radialDiff / tanf( angleRad );
1387 float totalHeight = aZtop - aZbot;
1390 if( innerHeight > totalHeight )
1391 innerHeight = totalHeight;
1393 float zInnerTop = aIsFront ? aZbot + innerHeight : aZtop;
1394 float zInnerBot = aIsFront ? aZbot : aZtop - innerHeight;
1396 std::vector< SFVEC2F > innerContour;
1397 std::vector< SFVEC2F > outerContour;
1399 generateRing( aCenter, aInnerRadius, aOuterRadius, aNr_sides_per_circle, innerContour, outerContour,
false );
1401 for(
unsigned int i = 0; i < ( innerContour.size() - 1 ); ++i )
1403 const SFVEC2F& vi0 = innerContour[i + 0];
1404 const SFVEC2F& vi1 = innerContour[i + 1];
1405 const SFVEC2F& vo0 = outerContour[i + 0];
1406 const SFVEC2F& vo1 = outerContour[i + 1];
1411 aDstLayer->m_layer_top_triangles->AddQuad(
SFVEC3F( vi1.x, vi1.y, zInnerTop ),
1412 SFVEC3F( vi0.x, vi0.y, zInnerTop ),
1413 SFVEC3F( vo0.x, vo0.y, aZtop ),
1414 SFVEC3F( vo1.x, vo1.y, aZtop ) );
1417 aDstLayer->m_layer_bot_triangles->AddQuad(
SFVEC3F( vi1.x, vi1.y, aZbot ),
1418 SFVEC3F( vo1.x, vo1.y, aZbot ),
1419 SFVEC3F( vo0.x, vo0.y, aZbot ),
1420 SFVEC3F( vi0.x, vi0.y, aZbot ) );
1425 aDstLayer->m_layer_bot_triangles->AddQuad(
SFVEC3F( vi1.x, vi1.y, aZtop ),
1426 SFVEC3F( vo1.x, vo1.y, aZtop ),
1427 SFVEC3F( vo0.x, vo0.y, aZtop ),
1428 SFVEC3F( vi0.x, vi0.y, aZtop ) );
1431 aDstLayer->m_layer_top_triangles->AddQuad(
SFVEC3F( vi1.x, vi1.y, zInnerBot ),
1432 SFVEC3F( vi0.x, vi0.y, zInnerBot ),
1433 SFVEC3F( vo0.x, vo0.y, aZbot ),
1434 SFVEC3F( vo1.x, vo1.y, aZbot ) );
1439 aDstLayer->AddToMiddleContours( outerContour, aZbot, aZtop,
true );
1441 aDstLayer->AddToMiddleContours( innerContour, zInnerBot, zInnerTop,
false );
1446 std::shared_ptr<TRIANGLE_DISPLAY_LIST> aDstLayer,
bool aTop )
1448 const float delta = 2.0f * glm::pi<float>() / (float) aNr_sides_per_circle;
1450 for(
unsigned int i = 0; i < aNr_sides_per_circle; ++i )
1452 float a0 =
delta * i;
1453 float a1 =
delta * ( i + 1 );
1454 const SFVEC3F p0( aCenter.x + cosf( a0 ) * aRadius,
1455 aCenter.y + sinf( a0 ) * aRadius, aZ );
1456 const SFVEC3F p1( aCenter.x + cosf( a1 ) * aRadius,
1457 aCenter.y + sinf( a1 ) * aRadius, aZ );
1458 const SFVEC3F c( aCenter.x, aCenter.y, aZ );
1461 aDstLayer->m_layer_top_triangles->AddTriangle( p1, p0, c );
1463 aDstLayer->m_layer_bot_triangles->AddTriangle( p0, p1, c );
1469 unsigned int aNr_sides_per_circle,
1470 std::shared_ptr<TRIANGLE_DISPLAY_LIST> aDstLayer,
bool aTop )
1472 const float delta = 2.0f * glm::pi<float>() / (float) aNr_sides_per_circle;
1473 const SFVEC3F c( aCenter.x, aCenter.y, aTop ? aZ - aDepth : aZ + aDepth );
1475 for(
unsigned int i = 0; i < aNr_sides_per_circle; ++i )
1477 float a0 =
delta * i;
1478 float a1 =
delta * ( i + 1 );
1479 const SFVEC3F p0( aCenter.x + cosf( a0 ) * aRadius,
1480 aCenter.y + sinf( a0 ) * aRadius, aZ );
1481 const SFVEC3F p1( aCenter.x + cosf( a1 ) * aRadius,
1482 aCenter.y + sinf( a1 ) * aRadius, aZ );
1485 aDstLayer->m_layer_top_triangles->AddTriangle( p0, p1, c );
1487 aDstLayer->m_layer_bot_triangles->AddTriangle( p1, p0, c );
1498 float aHoleInnerRadius,
1501 float aPlatingThickness3d,
1508 if( !aDstLayer || aPlatingThickness3d <= 0.0f || aHoleInnerRadius <= 0.0f )
1517 if( aSizeIU <= 0 || aDepthIU <= 0 )
1520 const float radius = aSizeIU * 0.5f * aUnitScale;
1521 const float depth = aDepthIU * aUnitScale;
1523 if(
radius <= aHoleInnerRadius || depth <= 0.0f )
1526 float zEnd = aIsFront ? ( aZSurface - depth ) : ( aZSurface + depth );
1531 const float zTop = std::max( aZSurface, zEnd );
1532 const float zBot = std::min( aZSurface, zEnd );
1534 const int diameterBIU = std::max( aSizeIU, std::max( 1, (
int) ( ( aHoleInnerRadius * 2.0f ) / aUnitScale ) ) );
1535 const unsigned int nrSegments = std::max( 12u,
m_boardAdapter.GetCircleSegmentCount( diameterBIU ) );
1556 bool isBackdrilled =
via->GetSecondaryDrillSize().has_value()
1558 bool isTertiarydrilled =
via->GetTertiaryDrillSize().has_value()
1567 && !isTertiarydrilled
1568 && !hasFrontPostMachining
1569 && !hasBackPostMachining;
1573 const PAD*
pad =
static_cast<const PAD*
>( aItem );
1575 bool isBackdrilled =
pad->GetSecondaryDrillSize().x > 0
1576 &&
pad->GetSecondaryDrillSize().y > 0
1578 bool isTertiarydrilled =
pad->GetTertiaryDrillSize().x > 0
1579 &&
pad->GetTertiaryDrillSize().y > 0
1586 return pad->HasHole()
1589 && !isTertiarydrilled
1590 && !hasFrontPostMachining
1591 && !hasBackPostMachining;
1609 float averageDiameter =
m_boardAdapter.GetAverageViaHoleDiameter();
1610 unsigned int averageSegCount =
m_boardAdapter.GetCircleSegmentCount( averageDiameter );
1611 unsigned int trianglesEstimate = averageSegCount * 8 *
m_boardAdapter.GetViaCount();
1612 auto triangles = std::make_shared<TRIANGLE_DISPLAY_LIST>( trianglesEstimate );
1630 SFVEC2F via_center( (
float)
via->GetStart().x * aUnitScale, - (
float)
via->GetStart().y * aUnitScale );
1631 unsigned int nrSegments =
m_boardAdapter.GetCircleSegmentCount(
via->GetDrillValue() );
1632 float holeInnerR = (float)
via->GetDrillValue() * 0.5f * aUnitScale;
1637 float ztop_plated = ztop;
1638 float zbot_plated = zbot;
1641 via->Padstack().TertiaryDrill() } )
1643 if( backdrill.start ==
F_Cu && backdrill.size.x > 0 )
1655 holeInnerR, ztop,
true, aPlatingThickness3d, aUnitScale,
1658 ztop_plated = std::min( ztop_plated, zEnd );
1661 else if( backdrill.end ==
B_Cu && backdrill.size.x > 0 )
1673 holeInnerR, zbot,
false, aPlatingThickness3d, aUnitScale,
1676 zbot_plated = std::max( zbot_plated, zEnd );
1687 via->GetFrontPostMachiningSize(),
via->GetFrontPostMachiningDepth(),
1689 holeInnerR, ztop,
true, aPlatingThickness3d, aUnitScale, &zEnd ) )
1691 ztop_plated = std::min( ztop_plated, zEnd );
1701 via->GetBackPostMachiningSize(),
via->GetBackPostMachiningDepth(),
1703 holeInnerR, zbot,
false, aPlatingThickness3d, aUnitScale, &zEnd ) )
1705 zbot_plated = std::max( zbot_plated, zEnd );
1709 generateCylinder( via_center, holeInnerR, holeInnerR + aPlatingThickness3d, ztop_plated, zbot_plated,
1710 nrSegments, triangles );
1716 float ztop_plated = ztop;
1717 float zbot_plated = zbot;
1721 for(
const PAD*
pad : footprint->Pads() )
1737 SFVEC2F padCenter( (
float)
pad->GetPosition().x * aUnitScale,
1738 - (
float)
pad->GetPosition().y * aUnitScale );
1739 unsigned int nrSegments =
m_boardAdapter.GetCircleSegmentCount(
pad->GetDrillSize().x );
1740 float holeInnerR = (float)
pad->GetDrillSize().x * 0.5f * aUnitScale;
1748 pad->GetFrontPostMachiningSize(),
pad->GetFrontPostMachiningDepth(),
1750 holeInnerR, ztop,
true, aPlatingThickness3d, aUnitScale, &zEnd ) )
1752 ztop_plated = std::min( ztop_plated, zEnd );
1762 pad->GetBackPostMachiningSize(),
pad->GetBackPostMachiningDepth(),
1764 holeInnerR, zbot,
false, aPlatingThickness3d, aUnitScale, &zEnd ) )
1766 zbot_plated = std::max( zbot_plated, zEnd );
1770 generateCylinder( padCenter, holeInnerR, holeInnerR + aPlatingThickness3d, ztop_plated, zbot_plated,
1771 nrSegments, triangles );
1823 for(
const PAD*
pad : footprint->Pads() )
1828 pad->TransformHoleToPolygon( tht_outer_holes_poly, aPlatingThickness,
pad->GetMaxError(),
ERROR_INSIDE );
1829 pad->TransformHoleToPolygon( tht_inner_holes_poly, 0,
pad->GetMaxError(),
ERROR_INSIDE );
1836 tht_outer_holes_poly.
BooleanAdd( capped_outer_vias_poly );
1837 tht_inner_holes_poly.
BooleanAdd( capped_inner_vias_poly );
1845 if( holes2D.size() > 0 &&
m_boardAdapter.m_Cfg->m_Render.show_plated_barrels )
1847 float layer_z_top, layer_z_bot,
dummy;
1852 auto triangles = std::make_shared<TRIANGLE_DISPLAY_LIST>( holes2D.size() );
1854 for(
const OBJECT_2D* itemOnLayer : holes2D )
1856 const OBJECT_2D* object2d_A = itemOnLayer;
1873 triangles->AddToMiddleContours( tht_outer_holes_poly, layer_z_bot, layer_z_top, aUnitScale,
false );
1887 auto frontCover = std::make_shared<TRIANGLE_DISPLAY_LIST>(
m_boardAdapter.GetViaCount() );
1888 auto backCover = std::make_shared<TRIANGLE_DISPLAY_LIST>(
m_boardAdapter.GetViaCount() );
1897 const float holediameter =
via->GetDrillValue() * aUnitScale;
1898 const float hole_radius = holediameter / 2.0f + 2.0f * aPlatingThickness3d;
1900 -
via->GetStart().y * aUnitScale );
1901 unsigned int seg =
m_boardAdapter.GetCircleSegmentCount(
via->GetDrillValue() );
1904 via->LayerPair( &top_layer, &bottom_layer );
1905 float ztop, zbot,
dummy;
1923 bool hasFrontBackdrill =
via->GetSecondaryDrillStartLayer() ==
F_Cu
1924 ||
via->GetTertiaryDrillStartLayer() ==
F_Cu;
1925 bool hasBackBackdrill =
via->GetSecondaryDrillStartLayer() ==
B_Cu
1926 ||
via->GetTertiaryDrillStartLayer() ==
B_Cu;
1928 const float depth = hole_radius * 0.3f;
1930 if( frontCovering && !hasFrontPostMachining && !hasFrontBackdrill )
1932 if( filled || !frontPlugged )
1938 if( backCovering && !hasBackPostMachining && !hasBackBackdrill )
1940 if( filled || !backPlugged )
1947 if( frontCover->m_layer_top_triangles->GetVertexSize() > 0 )
1950 if( backCover->m_layer_bot_triangles->GetVertexSize() > 0 )
1960 const int platingThickness =
m_boardAdapter.GetHolePlatingThickness();
1962 const float platingThickness3d = platingThickness * unitScale;
2002 const wxString footprintBasePath =
m_boardAdapter.GetFootprintLibraryPath( footprint );
2004 for(
const FP_3DMODEL& fp_model : footprint->Models() )
2006 if( fp_model.m_Show && !fp_model.m_Filename.empty() )
2012 wxFileName fn( fp_model.m_Filename );
2021 std::vector<const EMBEDDED_FILES*> embeddedFilesStack;
2022 embeddedFilesStack.push_back( footprint->GetEmbeddedFiles() );
2023 embeddedFilesStack.push_back(
m_boardAdapter.GetBoard()->GetEmbeddedFiles() );
2025 const S3DMODEL* modelPtr = cacheMgr->
GetModel( fp_model.m_Filename, footprintBasePath,
2026 std::move( embeddedFilesStack ) );
2032 auto model = std::make_shared<MODEL_3D_DEFERRED>( *modelPtr, materialMode );
2039 if( aStop.stop_requested() )
MATERIAL_MODE
Render 3d model shape materials mode.
bool GetExtrusionPinOutlines(const FOOTPRINT *aFootprint, SHAPE_POLY_SET &aPinPoly, SHAPE_POLY_SET &aPegPoly)
Get the hole outline polygons for extruded pin rendering.
void ApplyExtrusionTransform(SHAPE_POLY_SET &aOutline, const EXTRUDED_3D_BODY *aBody, const VECTOR2I &aFpPos)
Apply 2D extrusion transforms (rotation, scale, offset) to an outline.
bool GetExtrusionOutline(const FOOTPRINT *aFootprint, SHAPE_POLY_SET &aOutline, PCB_LAYER_ID aLayerOverride)
Get the extrusion outline polygon for a footprint in board coordinates.
constexpr EDA_IU_SCALE pcbIUScale
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.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Manage layers needed to make a physical board.
int GetLayerDistance(PCB_LAYER_ID aFirstLayer, PCB_LAYER_ID aSecondLayer) const
Calculate the distance (height) between the two given copper layers.
const LIST_OBJECT2D & GetList() const
KICAD_T Type() const
Returns the type of object.
const SFVEC2F & GetCenter() const
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
static const LSET & PhysicalLayersMask()
Return a mask holding all layers which are physically realized.
static OBJECT_2D_STATS & Instance()
OBJECT_2D_TYPE GetObjectType() const
Simple non-intersecting polygon with 4 points.
const SFVEC2F & GetV3() const
const SFVEC2F & GetV0() const
const SFVEC2F & GetV1() const
const SFVEC2F & GetV2() const
std::shared_ptr< REPORTER > m_warningReporter
std::shared_ptr< REPORTER > m_activityReporter
BOARD_ADAPTER & m_boardAdapter
Settings reference in use for this render.
void runHitTestRebuild(std::stop_token aStop)
void renderExtrudedBodies()
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > generateHoles(const LIST_OBJECT2D &aListHolesObject2d, const SHAPE_POLY_SET &aPoly, float aZtop, float aZbot, bool aInvertFaces, const BVH_CONTAINER_2D *aThroughHoles=nullptr)
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)
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_offboardPadsBack
SHAPE_POLY_SET m_antiBoardPolys
The negative polygon representation of the board outline.
std::map< const FOOTPRINT *, std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > > m_extrudedBodyLists
void RebuildHitTestAsync()
Rebuild the raytracing hit-test scene in the background after a visibility change.
void generateViasAndPads()
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_viaFrontCover
void Load3dModelsIfNeeded()
Load footprint models if they are not already loaded, i.e.
void StopBgWorker() override
Request stop and join any in-progress background loading.
MAP_OGL_DISP_LISTS m_layers
MAP_OGL_DISP_LISTS m_innerLayerHoles
bool appendPostMachiningGeometry(std::shared_ptr< TRIANGLE_DISPLAY_LIST > aDstLayer, const SFVEC2F &aHoleCenter, PAD_DRILL_POST_MACHINING_MODE aMode, int aSizeIU, int aDepthIU, const EDA_ANGLE &aAngle, float aHoleInnerRadius, float aZSurface, bool aIsFront, float aPlatingThickness3d, float aUnitScale, float *aZEnd)
void appendRenderTriangleList(std::shared_ptr< TRIANGLE_DISPLAY_LIST > aTriangles)
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_postMachinePlugs
Board material plugs for backdrill/counterbore/countersink.
std::atomic< bool > m_hitTestDirty
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_offboardPadsFront
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_complexPlatedHoles
MAP_OGL_DISP_LISTS m_outerLayerHoles
BOARD_ITEM * m_currentRollOverItem
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > generateEmptyLayerList(PCB_LAYER_ID aLayer)
void generateDisk(const SFVEC2F &aCenter, float aRadius, float aZ, unsigned int aNr_sides_per_circle, std::shared_ptr< TRIANGLE_DISPLAY_LIST > aDstLayer, bool aTop)
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_backOuterThroughHoles
void generateDimple(const SFVEC2F &aCenter, float aRadius, float aZ, float aDepth, unsigned int aNr_sides_per_circle, std::shared_ptr< TRIANGLE_DISPLAY_LIST > aDstLayer, bool aTop)
void assignRenderMap(TMap &aMap, const typename TMap::key_type &aKey, typename TMap::mapped_type aVal)
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_platedPadsFront
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_platedPadsBack
void generateViaCovers(float aPlatingThickness3d, float aUnitScale)
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_board
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_boardWithHoles
void load3dModels(std::stop_token aStop=std::stop_token())
Load footprint models from the cache and load it to deferred openGL lists (MODEL_3D_DEFERRED) objects...
void createPlaceholderModel()
void generateSimplePlatedHoleShells(int aPlatingThickness, float aUnitScale)
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_antiBoard
std::map< wxString, std::shared_ptr< MODEL_3D_DEFERRED > > m_3dModelMap
void generateInvCone(const SFVEC2F &aCenter, float aInnerRadius, float aOuterRadius, float aZtop, float aZbot, unsigned int aNr_sides_per_circle, std::shared_ptr< TRIANGLE_DISPLAY_LIST > aDstLayer, EDA_ANGLE aAngle, bool aIsFront)
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_frontOuterThroughHoles
std::atomic< bool > m_bgWorkerBusy
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > generateLayerList(const BVH_CONTAINER_2D *aContainer, const SHAPE_POLY_SET *aPolyList, PCB_LAYER_ID aLayer, const BVH_CONTAINER_2D *aThroughHoles=nullptr)
std::map< const FOOTPRINT *, std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > > m_extrudedPadLists
void getLayerZPos(PCB_LAYER_ID aLayerID, float &aOutZtop, float &aOutZbot) const
void bgWorker(std::stop_token aStop)
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_padHoles
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > createBoard(const SHAPE_POLY_SET &aBoardPoly, const BVH_CONTAINER_2D *aThroughHoles=nullptr, bool aTransparent=false)
void JoinBgWorker() override
Block until any in-progress background loading has finished.
void addTopAndBottomTriangles(std::shared_ptr< TRIANGLE_DISPLAY_LIST > aDst, const SFVEC2F &v0, const SFVEC2F &v1, const SFVEC2F &v2, float top, float bot)
std::jthread m_bgWorkerThread
std::map< const FOOTPRINT *, std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > > m_extrudedPegLists
void assignRenderPtr(std::shared_ptr< T > &aDst, std::shared_ptr< T > aVal)
void addObjectTriangles(const RING_2D *aRing, std::shared_ptr< TRIANGLE_DISPLAY_LIST > aDstLayer, float aZtop, float aZbot)
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_outerThroughHoleRings
void backfillPostMachine()
Create ring-shaped plugs for holes that have backdrill or post-machining.
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_viaBackCover
void generateCylinder(const SFVEC2F &aCenter, float aInnerRadius, float aOuterRadius, float aZtop, float aZbot, unsigned int aNr_sides_per_circle, std::shared_ptr< TRIANGLE_DISPLAY_LIST > aDstLayer)
void generateComplexHoles(float aPlatingThickness3d, float aUnitScale)
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
Cache for storing the 3D shapes.
S3DMODEL * GetModel(const wxString &aModelFileName, const wxString &aBasePath, std::vector< const EMBEDDED_FILES * > aEmbeddedFilesStack)
Attempt to load the scene data for a model and to translate it into an S3D_MODEL structure for displa...
Represent a set of closed polygons.
void RemoveAllContours()
Remove all outlines & holes (clears) the polygon set.
void BooleanAdd(const SHAPE_POLY_SET &b)
Perform boolean polyset union.
void Simplify()
Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections)
void BooleanIntersection(const SHAPE_POLY_SET &b)
Perform boolean polyset intersection.
int OutlineCount() const
Return the number of outlines in the set.
SHAPE_POLY_SET CloneDropTriangulation() const
void BooleanSubtract(const SHAPE_POLY_SET &b)
Perform boolean polyset difference.
const SFVEC2F & GetP2() const
const SFVEC2F & GetP3() const
const SFVEC2F & GetP1() const
std::list< OBJECT_2D * > LIST_OBJECT2D
void TransformCircleToPolygon(SHAPE_LINE_CHAIN &aBuffer, const VECTOR2I &aCenter, int aRadius, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a circle to a polygon, using multiple straight lines.
static constexpr EDA_ANGLE ANGLE_0
PCB_LAYER_ID FabBackdrillMustNotCut(const LSEQ &aCopperStack, PCB_LAYER_ID aStart, PCB_LAYER_ID aMustCut)
aMustCut is DRILL_PROPS.end; returns the next enabled copper past it away from aStart,...
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
PCB_LAYER_ID
A quick note on layer IDs:
bool isSimpleThroughHole(const BOARD_ITEM *aItem)
PAD_DRILL_POST_MACHINING_MODE
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
int64_t GetRunningMicroSecs()
An alternate way to calculate an elapsed time (in microsecondes) to class PROF_COUNTER.
#define SIZE_OF_CIRCLE_TEXTURE
std::vector< FAB_LAYER_COLOR > dummy
The properties of a padstack drill.
Store the a model based on meshes and materials.
KIBIS top(path, &reporter)
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)
@ PCB_PAD_T
class PAD, a pad in a footprint
VECTOR2< int32_t > VECTOR2I