38 std::shared_ptr<TRIANGLE_DISPLAY_LIST> aDstLayer,
float aZtop,
float aZbot )
45 const float f = ( sqrtf( 2.0f ) / 2.0f ) *
radius * texture_factor;
67 std::shared_ptr<TRIANGLE_DISPLAY_LIST> aDstLayer,
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() );
114 float aZtop,
float aZbot )
120 std::vector< SFVEC2F > innerContour;
121 std::vector< SFVEC2F > outerContour;
124 innerContour, outerContour,
false );
127 for(
unsigned int i = 0; i < ( innerContour.size() - 1 ); ++i )
129 const SFVEC2F& vi0 = innerContour[i + 0];
130 const SFVEC2F& vi1 = innerContour[i + 1];
131 const SFVEC2F& vo0 = outerContour[i + 0];
132 const SFVEC2F& vo1 = outerContour[i + 1];
134 aDstLayer->m_layer_top_triangles->AddQuad(
SFVEC3F( vi1.x, vi1.y, aZtop ),
135 SFVEC3F( vi0.x, vi0.y, aZtop ),
136 SFVEC3F( vo0.x, vo0.y, aZtop ),
137 SFVEC3F( vo1.x, vo1.y, aZtop ) );
139 aDstLayer->m_layer_bot_triangles->AddQuad(
SFVEC3F( vi1.x, vi1.y, aZbot ),
140 SFVEC3F( vo1.x, vo1.y, aZbot ),
141 SFVEC3F( vo0.x, vo0.y, aZbot ),
142 SFVEC3F( vi0.x, vi0.y, aZbot ) );
148 float aZtop,
float aZbot )
159 std::shared_ptr<TRIANGLE_DISPLAY_LIST> aDstLayer,
float aZtop,
float aZbot )
176 const float radius_of_the_square = sqrtf( aSeg->
GetRadiusSquared() * 2.0f );
177 const float radius_triangle_factor = ( radius_of_the_square -
radius ) /
radius;
180 rightDir.x *
radius * radius_triangle_factor );
183 leftDir.x *
radius * radius_triangle_factor );
186 aDstLayer->m_layer_top_segment_ends->AddTriangle(
187 SFVEC3F( rightEnd.x + texture_factor * factorS.x,
188 rightEnd.y + texture_factor * factorS.y,
190 SFVEC3F( leftStart.x + texture_factor * factorE.x,
191 leftStart.y + texture_factor * factorE.y,
193 SFVEC3F( start.x - texture_factorF * leftDir.x *
radius * sqrtf( 2.0f ),
194 start.y - texture_factorF * leftDir.y *
radius * sqrtf( 2.0f ),
197 aDstLayer->m_layer_top_segment_ends->AddTriangle(
198 SFVEC3F( leftEnd.x + texture_factor * factorE.x,
199 leftEnd.y + texture_factor * factorE.y, aZtop ),
200 SFVEC3F( rightStart.x + texture_factor * factorS.x,
201 rightStart.y + texture_factor * factorS.y, aZtop ),
203 end.y - texture_factorF * rightDir.y *
radius * sqrtf( 2.0f ),
207 aDstLayer->m_layer_bot_segment_ends->AddTriangle(
208 SFVEC3F( leftStart.x + texture_factor * factorE.x,
209 leftStart.y + texture_factor * factorE.y,
211 SFVEC3F( rightEnd.x + texture_factor * factorS.x,
212 rightEnd.y + texture_factor * factorS.y,
214 SFVEC3F( start.x - texture_factorF * leftDir.x *
radius * sqrtf( 2.0f ),
215 start.y - texture_factorF * leftDir.y *
radius * sqrtf( 2.0f ),
218 aDstLayer->m_layer_bot_segment_ends->AddTriangle(
219 SFVEC3F( rightStart.x + texture_factor * factorS.x,
220 rightStart.y + texture_factor * factorS.y, aZbot ),
221 SFVEC3F( leftEnd.x + texture_factor * factorE.x,
222 leftEnd.y + texture_factor * factorE.y, aZbot ),
224 end.y - texture_factorF * rightDir.y *
radius * sqrtf( 2.0f ),
228 aDstLayer->m_layer_top_triangles->AddQuad(
229 SFVEC3F( rightEnd.x, rightEnd.y, aZtop ),
230 SFVEC3F( rightStart.x, rightStart.y, aZtop ),
231 SFVEC3F( leftEnd.x, leftEnd.y, aZtop ),
232 SFVEC3F( leftStart.x, leftStart.y, aZtop ) );
234 aDstLayer->m_layer_bot_triangles->AddQuad(
235 SFVEC3F( rightEnd.x, rightEnd.y, aZbot ),
236 SFVEC3F( leftStart.x, leftStart.y, aZbot ),
237 SFVEC3F( leftEnd.x, leftEnd.y, aZbot ),
238 SFVEC3F( rightStart.x, rightStart.y, aZbot ) );
244 float aZbot,
bool aInvertFaces,
247 if( aListHolesObject2d.size() == 0 )
250 auto layerTriangles = std::make_shared<TRIANGLE_DISPLAY_LIST>( aListHolesObject2d.size() * 2 );
253 for(
const OBJECT_2D* object2d : aListHolesObject2d )
255 switch( object2d->GetObjectType() )
266 wxFAIL_MSG( wxT(
"RENDER_3D_OPENGL::generateHoles: Object type not implemented" ) );
275 layerTriangles->AddToMiddleContours( aPoly, aZbot, aZtop,
m_boardAdapter.BiuTo3dUnits(), aInvertFaces,
279 return std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( layerTriangles,
m_circleTexture, aZbot, aZtop );
283std::shared_ptr<OPENGL_RENDER_LIST_DEFERRED>
287 if( aContainer ==
nullptr )
292 if( listObject2d.size() == 0 )
301 unsigned int nrTrianglesEstimation = listObject2d.size() * 8;
303 auto layerTriangles = std::make_shared<TRIANGLE_DISPLAY_LIST>( nrTrianglesEstimation );
309 for(
const OBJECT_2D* object2d : listObject2d )
311 switch( object2d->GetObjectType() )
334 wxFAIL_MSG( wxT(
"RENDER_3D_OPENGL: Object type is not implemented" ) );
341 layerTriangles->AddToMiddleContours( *aPolyList, zBot, zTop,
m_boardAdapter.BiuTo3dUnits(),
false,
346 return std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( layerTriangles,
m_circleTexture, zBot, zTop );
352 float layer_z_bot = 0.0f;
353 float layer_z_top = 0.0f;
357 auto layerTriangles = std::make_shared<TRIANGLE_DISPLAY_LIST>( 1 );
362 return std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( layerTriangles,
m_circleTexture, layer_z_bot, layer_z_top );
370 std::shared_ptr<OPENGL_RENDER_LIST_DEFERRED> dispLists;
378 if( listBoardObject2d.size() > 0 )
382 const float layer_z_top = 1.0f;
383 const float layer_z_bot = 0.0f;
385 auto layerTriangles = std::make_shared<TRIANGLE_DISPLAY_LIST>( listBoardObject2d.size() );
388 for(
const OBJECT_2D* itemOnLayer : listBoardObject2d )
390 const OBJECT_2D* object2d_A = itemOnLayer;
405 layerTriangles->AddToMiddleContours( aBoardPoly, layer_z_bot, layer_z_top,
409 dispLists = std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( layerTriangles,
m_circleTexture, layer_z_top,
410 layer_z_top, aTransparent );
423 const int copperLayerCount =
m_boardAdapter.GetBoard()->GetCopperLayerCount();
425 const int platingThickness =
m_boardAdapter.GetHolePlatingThickness();
426 const float boardBodyThickness =
m_boardAdapter.GetBoardBodyThickness();
429 const float boardZTop = 1.0f;
430 const float boardZBot = 0.0f;
433 auto normalizeZ = [&](
float absZ ) ->
float
437 float boardThick = boardTop - boardBot;
439 if( boardThick <= 0 )
443 return ( absZ - boardBot ) / boardThick;
447 std::shared_ptr<TRIANGLE_DISPLAY_LIST> plugTriangles = std::make_shared<TRIANGLE_DISPLAY_LIST>( 1024 );
457 const float holeDiameter =
via->GetDrillValue() * unitScale;
458 const float holeInnerRadius = holeDiameter / 2.0f;
459 const float holeOuterRadius = holeInnerRadius + platingThickness * unitScale;
461 const int nrSegments =
m_boardAdapter.GetCircleSegmentCount(
via->GetDrillValue() );
464 via->LayerPair( &topLayer, &bottomLayer );
466 float viaZTop, viaZBot,
dummy;
471 const float secondaryDrillRadius =
via->GetSecondaryDrillSize().value_or( 0 ) * 0.5f * unitScale;
472 const float tertiaryDrillRadius =
via->GetTertiaryDrillSize().value_or( 0 ) * 0.5f * unitScale;
474 if( secondaryDrillRadius > holeOuterRadius || tertiaryDrillRadius > holeOuterRadius )
480 if( secondaryDrillRadius > holeOuterRadius )
482 plug_end_layer =
via->GetSecondaryDrillEndLayer();
485 if( tertiaryDrillRadius > holeOuterRadius )
487 plug_start_layer =
via->GetTertiaryDrillStartLayer();
491 float plugZTop, plugZBot, temp;
497 plugZTop, plugZBot, nrSegments, plugTriangles );
501 const auto frontMode =
via->GetFrontPostMachining();
503 if( frontMode.has_value()
507 const float frontRadius =
via->GetFrontPostMachiningSize() * 0.5f * unitScale;
508 const float frontDepth =
via->GetFrontPostMachiningDepth() * unitScale;
510 if( frontRadius > holeOuterRadius && frontDepth > 0 )
513 float pmBottomZ = normalizeZ( viaZTop - frontDepth );
514 float plugZBot = normalizeZ( viaZBot );
516 if( pmBottomZ > plugZBot )
522 pmBottomZ, plugZBot, nrSegments, plugTriangles, angle );
527 pmBottomZ, plugZBot, nrSegments, plugTriangles );
534 const auto backMode =
via->GetBackPostMachining();
536 if( backMode.has_value()
540 const float backRadius =
via->GetBackPostMachiningSize() * 0.5f * unitScale;
541 const float backDepth =
via->GetBackPostMachiningDepth() * unitScale;
543 if( backRadius > holeOuterRadius && backDepth > 0 )
546 float plugZTop = normalizeZ( viaZTop );
547 float pmTopZ = normalizeZ( viaZBot + backDepth );
549 if( plugZTop > pmTopZ )
555 plugZTop, pmTopZ, nrSegments, plugTriangles, angle );
560 plugZTop, pmTopZ, nrSegments, plugTriangles );
570 for(
const PAD*
pad : footprint->Pads() )
572 if( !
pad->HasHole() )
578 const SFVEC2F padCenter(
pad->GetPosition().x * unitScale,
579 -
pad->GetPosition().y * unitScale );
580 const float holeInnerRadius =
pad->GetDrillSize().x * 0.5f * unitScale;
581 const float holeOuterRadius = holeInnerRadius + platingThickness * unitScale;
582 const int nrSegments =
m_boardAdapter.GetCircleSegmentCount(
pad->GetDrillSize().x );
584 float padZTop, padZBot, padDummy;
589 const auto frontMode =
pad->GetFrontPostMachining();
591 if( frontMode.has_value()
595 const float frontRadius =
pad->GetFrontPostMachiningSize() * 0.5f * unitScale;
596 const float frontDepth =
pad->GetFrontPostMachiningDepth() * unitScale;
598 if( frontRadius > holeOuterRadius && frontDepth > 0 )
600 float pmBottomZ = normalizeZ( padZTop - frontDepth );
601 float plugZBot = normalizeZ( padZBot );
603 if( pmBottomZ > plugZBot )
609 pmBottomZ, plugZBot, nrSegments, plugTriangles, angle );
614 pmBottomZ, plugZBot, nrSegments, plugTriangles );
621 const auto backMode =
pad->GetBackPostMachining();
623 if( backMode.has_value()
627 const float backRadius =
pad->GetBackPostMachiningSize() * 0.5f * unitScale;
628 const float backDepth =
pad->GetBackPostMachiningDepth() * unitScale;
630 if( backRadius > holeOuterRadius && backDepth > 0 )
632 float plugZTop = normalizeZ( padZTop );
633 float pmTopZ = normalizeZ( padZBot + backDepth );
635 if( plugZTop > pmTopZ )
641 plugZTop, pmTopZ, nrSegments, plugTriangles, angle );
646 plugZTop, pmTopZ, nrSegments, plugTriangles );
655 if( plugTriangles->m_layer_top_triangles->GetVertexSize() > 0
656 || plugTriangles->m_layer_bot_triangles->GetVertexSize() > 0
657 || plugTriangles->m_layer_middle_contours_quads->GetVertexSize() > 0 )
665 std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( plugTriangles,
m_circleTexture, boardZTop, boardZTop ) );
700 bool isBack = fp->IsFlipped();
702 float standoff3d = body->
m_standoff * biuTo3d;
710 zBot = boardSurfaceZ + standoff3d + zOffset3d;
711 zTop = zBot + bodyThickness;
715 zTop = boardSurfaceZ - standoff3d - zOffset3d;
716 zBot = zTop - bodyThickness;
724 if( triList.empty() )
727 std::shared_ptr<TRIANGLE_DISPLAY_LIST> layerTri = std::make_shared<TRIANGLE_DISPLAY_LIST>( triList.size() );
735 layerTri->AddToMiddleContours( outline, zBot, zTop, biuTo3d,
false );
737 std::shared_ptr<OPENGL_RENDER_LIST_DEFERRED> renderList =
738 std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( layerTri,
m_circleTexture, zTop, zBot );
745 if( standoff3d > 0.0f )
752 float oppositeSurfaceZ =
m_boardAdapter.GetFootprintZPos( !isBack );
753 float protrusion = 1.0f *
pcbIUScale.IU_PER_MM * biuTo3d;
754 float pinZBot, pinZTop;
758 pinZBot = oppositeSurfaceZ - protrusion + zOffset3d;
759 pinZTop = boardSurfaceZ + standoff3d + zOffset3d;
763 pinZTop = oppositeSurfaceZ + protrusion - zOffset3d;
764 pinZBot = boardSurfaceZ - standoff3d - zOffset3d;
779 if( pinTriList.empty() )
782 auto pinLayerTri = std::make_shared<TRIANGLE_DISPLAY_LIST>( pinTriList.size() );
791 pinLayerTri->AddToMiddleContours( aPoly, pinZBot, pinZTop, biuTo3d,
false );
793 std::shared_ptr<OPENGL_RENDER_LIST_DEFERRED> pinRenderList =
794 std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( pinLayerTri,
m_circleTexture, pinZTop,
818 m_canvas->InvalidateRaytracingHitTesting();
830 m_camera.SetBoardLookAtPos( camera_pos );
850 if( aStop.stop_requested() )
855 m_canvas->InvalidateRaytracingHitTesting();
859 if( aStop.stop_requested() )
870 if( aStop.stop_requested() )
887 if( aStop.stop_requested() )
895 if(
m_boardAdapter.GetFrontCounterborePolys().OutlineCount() > 0 )
901 if(
m_boardAdapter.GetFrontCountersinkPolys().OutlineCount() > 0 )
913 if( aStop.stop_requested() )
921 if( aStop.stop_requested() )
953 wxASSERT( innerMapHoles.size() == outerMapHoles.size() );
957 if( outerMapHoles.size() > 0 )
959 float layer_z_bot = 0.0f;
960 float layer_z_top = 0.0f;
962 for(
const auto& [ layer, poly ] : outerMapHoles )
967 generateHoles( map_holes.at( layer )->GetList(), *poly, layer_z_top, layer_z_bot,
false ) );
970 for(
const auto& [ layer, poly ] : innerMapHoles )
975 generateHoles( map_holes.at( layer )->GetList(), *poly, layer_z_top, layer_z_bot,
false ) );
982 if( aStop.stop_requested() )
991 std::bitset<LAYER_3D_END> visibilityFlags =
m_boardAdapter.GetVisibleLayers();
995 for(
const auto& [ layer, container2d ] :
m_boardAdapter.GetLayerMap() )
1013 if( map_poly.contains( layer ) )
1015 polyListSubtracted = *map_poly.at( layer );
1033 else if( layer ==
B_Cu )
1052 polyList = &polyListSubtracted;
1056 if( aStop.stop_requested() )
1059 std::shared_ptr<OPENGL_RENDER_LIST_DEFERRED> oglList =
1062 if( oglList !=
nullptr )
1065 if( aStop.stop_requested() )
1076 if( frontPlatedCopperPolys )
1093 if( backPlatedCopperPolys )
1120 if( aStop.stop_requested() )
1133 if( aStop.stop_requested() )
1142 if( !aStop.stop_requested() &&
m_canvas )
1148 if( aStop.stop_requested() )
1156 m_activityReporter->Report( wxString::Format(
_(
"Load completed in %.3f s" ), calculation_time ) );
1163 wxLogTrace(
m_logTrace, wxT(
"RENDER_3D_OPENGL::startBgWorker" ) );
1169 [
this]( std::stop_token aStopToken )
1172 BS::this_thread::set_os_thread_priority( BS::os_thread_priority::below_normal );
1190 [
this]( std::stop_token aStop )
1192 BS::this_thread::set_os_thread_priority( BS::os_thread_priority::below_normal );
1207 if( aStop.stop_requested() || !
m_canvas )
1210 m_canvas->ReloadRaytracingForHitTesting( aStop );
1224 wxLogTrace(
m_logTrace, wxT(
"RENDER_3D_OPENGL::StopBgWorker" ) );
1241 wxLogTrace(
m_logTrace, wxT(
"RENDER_3D_OPENGL::JoinBgWorker" ) );
1251 aDst->m_layer_bot_triangles->AddTriangle(
SFVEC3F( v0.x, v0.y, bot ),
1255 aDst->m_layer_top_triangles->AddTriangle(
SFVEC3F(
v2.x,
v2.y,
top ),
1266 if( aOutZtop < aOutZbot )
1268 float tmpFloat = aOutZbot;
1269 aOutZbot = aOutZtop;
1270 aOutZtop = tmpFloat;
1276 float aZbot,
unsigned int aNr_sides_per_circle,
1277 std::shared_ptr<TRIANGLE_DISPLAY_LIST> aDstLayer )
1279 std::vector< SFVEC2F > innerContour;
1280 std::vector< SFVEC2F > outerContour;
1282 generateRing( aCenter, aInnerRadius, aOuterRadius, aNr_sides_per_circle, innerContour,
1283 outerContour,
false );
1285 for(
unsigned int i = 0; i < ( innerContour.size() - 1 ); ++i )
1287 const SFVEC2F& vi0 = innerContour[i + 0];
1288 const SFVEC2F& vi1 = innerContour[i + 1];
1289 const SFVEC2F& vo0 = outerContour[i + 0];
1290 const SFVEC2F& vo1 = outerContour[i + 1];
1292 aDstLayer->m_layer_top_triangles->AddQuad(
SFVEC3F( vi1.x, vi1.y, aZtop ),
1293 SFVEC3F( vi0.x, vi0.y, aZtop ),
1294 SFVEC3F( vo0.x, vo0.y, aZtop ),
1295 SFVEC3F( vo1.x, vo1.y, aZtop ) );
1297 aDstLayer->m_layer_bot_triangles->AddQuad(
SFVEC3F( vi1.x, vi1.y, aZbot ),
1298 SFVEC3F( vo1.x, vo1.y, aZbot ),
1299 SFVEC3F( vo0.x, vo0.y, aZbot ),
1300 SFVEC3F( vi0.x, vi0.y, aZbot ) );
1303 aDstLayer->AddToMiddleContours( outerContour, aZbot, aZtop,
true );
1304 aDstLayer->AddToMiddleContours( innerContour, aZbot, aZtop,
false );
1309 float aZbot,
unsigned int aNr_sides_per_circle,
1310 std::shared_ptr<TRIANGLE_DISPLAY_LIST> aDstLayer,
EDA_ANGLE aAngle )
1321 float radialDiff = aOuterRadius - aInnerRadius;
1325 if( angleRad < 0.01f )
1328 float innerHeight = radialDiff / tanf( angleRad );
1329 float totalHeight = aZtop - aZbot;
1332 if( innerHeight > totalHeight )
1333 innerHeight = totalHeight;
1335 float zInnerTop = aZbot + innerHeight;
1337 std::vector< SFVEC2F > innerContour;
1338 std::vector< SFVEC2F > outerContour;
1340 generateRing( aCenter, aInnerRadius, aOuterRadius, aNr_sides_per_circle, innerContour,
1341 outerContour,
false );
1343 for(
unsigned int i = 0; i < ( innerContour.size() - 1 ); ++i )
1345 const SFVEC2F& vi0 = innerContour[i + 0];
1346 const SFVEC2F& vi1 = innerContour[i + 1];
1347 const SFVEC2F& vo0 = outerContour[i + 0];
1348 const SFVEC2F& vo1 = outerContour[i + 1];
1351 aDstLayer->m_layer_top_triangles->AddQuad(
SFVEC3F( vi1.x, vi1.y, zInnerTop ),
1352 SFVEC3F( vi0.x, vi0.y, zInnerTop ),
1353 SFVEC3F( vo0.x, vo0.y, aZtop ),
1354 SFVEC3F( vo1.x, vo1.y, aZtop ) );
1357 aDstLayer->m_layer_bot_triangles->AddQuad(
SFVEC3F( vi1.x, vi1.y, aZbot ),
1358 SFVEC3F( vo1.x, vo1.y, aZbot ),
1359 SFVEC3F( vo0.x, vo0.y, aZbot ),
1360 SFVEC3F( vi0.x, vi0.y, aZbot ) );
1364 aDstLayer->AddToMiddleContours( outerContour, aZbot, aZtop,
true );
1366 aDstLayer->AddToMiddleContours( innerContour, aZbot, zInnerTop,
false );
1371 std::shared_ptr<TRIANGLE_DISPLAY_LIST> aDstLayer,
bool aTop )
1373 const float delta = 2.0f * glm::pi<float>() / (float) aNr_sides_per_circle;
1375 for(
unsigned int i = 0; i < aNr_sides_per_circle; ++i )
1377 float a0 =
delta * i;
1378 float a1 =
delta * ( i + 1 );
1379 const SFVEC3F p0( aCenter.x + cosf( a0 ) * aRadius,
1380 aCenter.y + sinf( a0 ) * aRadius, aZ );
1381 const SFVEC3F p1( aCenter.x + cosf( a1 ) * aRadius,
1382 aCenter.y + sinf( a1 ) * aRadius, aZ );
1383 const SFVEC3F c( aCenter.x, aCenter.y, aZ );
1386 aDstLayer->m_layer_top_triangles->AddTriangle( p1, p0, c );
1388 aDstLayer->m_layer_bot_triangles->AddTriangle( p0, p1, c );
1394 unsigned int aNr_sides_per_circle,
1395 std::shared_ptr<TRIANGLE_DISPLAY_LIST> aDstLayer,
bool aTop )
1397 const float delta = 2.0f * glm::pi<float>() / (float) aNr_sides_per_circle;
1398 const SFVEC3F c( aCenter.x, aCenter.y, aTop ? aZ - aDepth : aZ + aDepth );
1400 for(
unsigned int i = 0; i < aNr_sides_per_circle; ++i )
1402 float a0 =
delta * i;
1403 float a1 =
delta * ( i + 1 );
1404 const SFVEC3F p0( aCenter.x + cosf( a0 ) * aRadius,
1405 aCenter.y + sinf( a0 ) * aRadius, aZ );
1406 const SFVEC3F p1( aCenter.x + cosf( a1 ) * aRadius,
1407 aCenter.y + sinf( a1 ) * aRadius, aZ );
1410 aDstLayer->m_layer_top_triangles->AddTriangle( p0, p1, c );
1412 aDstLayer->m_layer_bot_triangles->AddTriangle( p1, p0, c );
1422 float aHoleInnerRadius,
1425 float aPlatingThickness3d,
1432 if( !aDstLayer || aPlatingThickness3d <= 0.0f || aHoleInnerRadius <= 0.0f )
1441 if( aSizeIU <= 0 || aDepthIU <= 0 )
1444 const float radius = aSizeIU * 0.5f * aUnitScale;
1445 const float depth = aDepthIU * aUnitScale;
1447 if(
radius <= aHoleInnerRadius || depth <= 0.0f )
1450 float zEnd = aIsFront ? ( aZSurface - depth ) : ( aZSurface + depth );
1455 const float zTop = std::max( aZSurface, zEnd );
1456 const float zBot = std::min( aZSurface, zEnd );
1458 const int diameterBIU = std::max( aSizeIU,
1460 (
int) ( ( aHoleInnerRadius * 2.0f )
1462 const unsigned int nrSegments =
1463 std::max( 12u,
m_boardAdapter.GetCircleSegmentCount( diameterBIU ) );
1468 nrSegments, aDstLayer );
1472 float csTopRadius =
radius;
1473 float csBotRadius = aHoleInnerRadius;
1475 std::vector< SFVEC2F > innerContourTop, outerContourTop;
1476 std::vector< SFVEC2F > innerContourBot, outerContourBot;
1478 generateRing( aHoleCenter, csTopRadius, csTopRadius + aPlatingThickness3d, nrSegments,
1479 innerContourTop, outerContourTop,
false );
1480 generateRing( aHoleCenter, csBotRadius, csBotRadius + aPlatingThickness3d, nrSegments,
1481 innerContourBot, outerContourBot,
false );
1483 for(
unsigned int i = 0; i < ( innerContourTop.size() - 1 ); ++i )
1485 const SFVEC2F& vi0_top = innerContourTop[i + 0];
1486 const SFVEC2F& vi1_top = innerContourTop[i + 1];
1487 const SFVEC2F& vo0_top = outerContourTop[i + 0];
1488 const SFVEC2F& vo1_top = outerContourTop[i + 1];
1490 const SFVEC2F& vi0_bot = innerContourBot[i + 0];
1491 const SFVEC2F& vi1_bot = innerContourBot[i + 1];
1492 const SFVEC2F& vo0_bot = outerContourBot[i + 0];
1493 const SFVEC2F& vo1_bot = outerContourBot[i + 1];
1495 aDstLayer->m_layer_middle_contours_quads->AddQuad(
1496 SFVEC3F( vi1_top.x, vi1_top.y, zTop ),
1497 SFVEC3F( vi0_top.x, vi0_top.y, zTop ),
1498 SFVEC3F( vi0_bot.x, vi0_bot.y, zBot ),
1499 SFVEC3F( vi1_bot.x, vi1_bot.y, zBot ) );
1501 aDstLayer->m_layer_middle_contours_quads->AddQuad(
1502 SFVEC3F( vo1_top.x, vo1_top.y, zTop ),
1503 SFVEC3F( vo0_top.x, vo0_top.y, zTop ),
1504 SFVEC3F( vo0_bot.x, vo0_bot.y, zBot ),
1505 SFVEC3F( vo1_bot.x, vo1_bot.y, zBot ) );
1520 float averageDiameter =
m_boardAdapter.GetAverageViaHoleDiameter();
1521 unsigned int averageSegCount =
m_boardAdapter.GetCircleSegmentCount( averageDiameter );
1522 unsigned int trianglesEstimate = averageSegCount * 8 *
m_boardAdapter.GetViaCount();
1524 std::shared_ptr<TRIANGLE_DISPLAY_LIST> layerTriangleVIA = std::make_shared<TRIANGLE_DISPLAY_LIST>( trianglesEstimate );
1532 bool isBackdrilled =
via->GetSecondaryDrillSize().has_value();
1533 bool isTertiarydrilled =
via->GetTertiaryDrillSize().has_value();
1544 && !hasFrontPostMachining && !hasBackPostMachining )
1549 const float holediameter =
via->GetDrillValue() * aUnitScale;
1550 const int nrSegments =
m_boardAdapter.GetCircleSegmentCount(
via->GetDrillValue() );
1551 const float hole_inner_radius = holediameter / 2.0f;
1553 const SFVEC2F via_center(
via->GetStart().x * aUnitScale,
1554 -
via->GetStart().y * aUnitScale );
1557 via->LayerPair( &top_layer, &bottom_layer );
1559 float ztop, zbot,
dummy;
1564 wxASSERT( zbot < ztop );
1566 float ztop_plated = ztop;
1567 float zbot_plated = zbot;
1577 zbot_plated = std::max( zbot_plated, secZEnd );
1580 if( isTertiarydrilled )
1588 ztop_plated = std::min( ztop_plated, terZEnd );
1591 auto applyViaPostMachining = [&](
bool isFront )
1593 auto modeOpt = isFront ?
via->GetFrontPostMachining()
1594 :
via->GetBackPostMachining();
1602 int sizeIU = isFront ?
via->GetFrontPostMachiningSize()
1603 :
via->GetBackPostMachiningSize();
1604 int depthIU = isFront ?
via->GetFrontPostMachiningDepth()
1605 :
via->GetBackPostMachiningDepth();
1606 float zSurface = isFront ? ztop : zbot;
1610 sizeIU, depthIU, hole_inner_radius, zSurface,
1611 isFront, aPlatingThickness3d, aUnitScale, &zEnd ) )
1614 ztop_plated = std::min( ztop_plated, zEnd );
1616 zbot_plated = std::max( zbot_plated, zEnd );
1620 if( hasFrontPostMachining )
1621 applyViaPostMachining(
true );
1622 if( hasBackPostMachining )
1623 applyViaPostMachining(
false );
1625 generateCylinder( via_center, hole_inner_radius, hole_inner_radius + aPlatingThickness3d, ztop_plated,
1626 zbot_plated, nrSegments, layerTriangleVIA );
1629 const float padFrontSurface =
1632 const float padBackSurface =
1638 for(
const PAD*
pad : footprint->Pads() )
1643 if( !
pad->HasHole() )
1649 const SFVEC2F padCenter(
pad->GetPosition().x * aUnitScale,
1650 -
pad->GetPosition().y * aUnitScale );
1651 const float holeInnerRadius =
1652 pad->GetDrillSize().x * 0.5f * aUnitScale;
1654 auto emitPadPostMachining = [&](
bool isFront )
1656 auto modeOpt = isFront ?
pad->GetFrontPostMachining()
1657 :
pad->GetBackPostMachining();
1665 int sizeIU = isFront ?
pad->GetFrontPostMachiningSize()
1666 :
pad->GetBackPostMachiningSize();
1667 int depthIU = isFront ?
pad->GetFrontPostMachiningDepth()
1668 :
pad->GetBackPostMachiningDepth();
1669 float zSurface = isFront ? padFrontSurface : padBackSurface;
1672 sizeIU, depthIU, holeInnerRadius, zSurface,
1673 isFront, aPlatingThickness3d, aUnitScale,
1677 emitPadPostMachining(
true );
1678 emitPadPostMachining(
false );
1683 std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( layerTriangleVIA, 0, 0.0f, 0.0f ) );
1727 for(
const PAD*
pad : footprint->Pads() )
1731 if( !
pad->HasHole() )
1734 pad->TransformHoleToPolygon( tht_outer_holes_poly, aPlatingThickness,
1736 pad->TransformHoleToPolygon( tht_inner_holes_poly, 0,
1745 tht_outer_holes_poly.
BooleanAdd( capped_outer_vias_poly );
1746 tht_inner_holes_poly.
BooleanAdd( capped_inner_vias_poly );
1755 if( holes2D.size() > 0 &&
m_boardAdapter.m_Cfg->m_Render.show_plated_barrels )
1757 float layer_z_top, layer_z_bot,
dummy;
1762 std::shared_ptr<TRIANGLE_DISPLAY_LIST> layerTriangles = std::make_shared<TRIANGLE_DISPLAY_LIST>( holes2D.size() );
1764 for(
const OBJECT_2D* itemOnLayer : holes2D )
1766 const OBJECT_2D* object2d_A = itemOnLayer;
1783 layerTriangles->AddToMiddleContours( tht_outer_holes_poly,
1784 layer_z_bot, layer_z_top,
1785 aUnitScale,
false );
1788 std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( layerTriangles,
m_circleTexture, layer_z_top,
1800 std::shared_ptr<TRIANGLE_DISPLAY_LIST> frontCover = std::make_shared<TRIANGLE_DISPLAY_LIST>(
m_boardAdapter.GetViaCount() );
1801 std::shared_ptr<TRIANGLE_DISPLAY_LIST> backCover = std::make_shared<TRIANGLE_DISPLAY_LIST>(
m_boardAdapter.GetViaCount() );
1810 const float holediameter =
via->GetDrillValue() * aUnitScale;
1811 const float hole_radius = holediameter / 2.0f + 2.0f * aPlatingThickness3d;
1813 -
via->GetStart().y * aUnitScale );
1814 unsigned int seg =
m_boardAdapter.GetCircleSegmentCount(
via->GetDrillValue() );
1817 via->LayerPair( &top_layer, &bottom_layer );
1818 float ztop, zbot,
dummy;
1831 const auto frontPostMachining =
1833 const auto backPostMachining =
1841 bool hasFrontBackdrill =
via->GetSecondaryDrillStartLayer() ==
F_Cu;
1842 bool hasBackBackdrill =
via->GetSecondaryDrillStartLayer() ==
B_Cu;
1844 const float depth = hole_radius * 0.3f;
1846 if( frontCovering && !hasFrontPostMachining && !hasFrontBackdrill )
1848 if( filled || !frontPlugged )
1854 if( backCovering && !hasBackPostMachining && !hasBackBackdrill )
1856 if( filled || !backPlugged )
1863 if( frontCover->m_layer_top_triangles->GetVertexSize() > 0 )
1865 std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( frontCover, 0, 0.0f, 0.0f ) );
1867 if( backCover->m_layer_bot_triangles->GetVertexSize() > 0 )
1869 std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( backCover, 0, 0.0f, 0.0f ) );
1878 const int platingThickness =
m_boardAdapter.GetHolePlatingThickness();
1880 const float platingThickness3d = platingThickness * unitScale;
1920 const wxString footprintBasePath =
m_boardAdapter.GetFootprintLibraryPath( footprint );
1922 for(
const FP_3DMODEL& fp_model : footprint->Models() )
1924 if( fp_model.m_Show && !fp_model.m_Filename.empty() )
1930 wxFileName fn( fp_model.m_Filename );
1939 std::vector<const EMBEDDED_FILES*> embeddedFilesStack;
1940 embeddedFilesStack.push_back( footprint->GetEmbeddedFiles() );
1941 embeddedFilesStack.push_back(
m_boardAdapter.GetBoard()->GetEmbeddedFiles() );
1943 const S3DMODEL* modelPtr = cacheMgr->
GetModel( fp_model.m_Filename, footprintBasePath,
1944 std::move( embeddedFilesStack ) );
1950 auto model = std::make_shared<MODEL_3D_DEFERRED>( *modelPtr, materialMode );
1957 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...
const LIST_OBJECT2D & GetList() const
const SFVEC2F & GetCenter() const
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
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_microviaHoles
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
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
MAP_OGL_DISP_LISTS m_outerLayerHoles
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)
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)
bool appendPostMachiningGeometry(std::shared_ptr< TRIANGLE_DISPLAY_LIST > aDstLayer, const SFVEC2F &aHoleCenter, PAD_DRILL_POST_MACHINING_MODE aMode, int aSizeIU, int aDepthIU, float aHoleInnerRadius, float aZSurface, bool aIsFront, float aPlatingThickness3d, float aUnitScale, float *aZEnd)
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 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)
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_antiBoard
void generatePlatedHoleShells(int aPlatingThickness, float aUnitScale)
std::map< wxString, std::shared_ptr< MODEL_3D_DEFERRED > > m_3dModelMap
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_outerThroughHoles
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 generateViaBarrels(float aPlatingThickness3d, float aUnitScale)
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)
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_outerViaThroughHoles
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)
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 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:
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
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)
VECTOR2< int32_t > VECTOR2I