40 std::shared_ptr<TRIANGLE_DISPLAY_LIST> aDstLayer,
float aZtop,
float aZbot )
47 const float f = ( sqrtf( 2.0f ) / 2.0f ) *
radius * texture_factor;
69 std::shared_ptr<TRIANGLE_DISPLAY_LIST> aDstLayer,
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];
136 aDstLayer->m_layer_top_triangles->AddQuad(
SFVEC3F( vi1.x, vi1.y, aZtop ),
137 SFVEC3F( vi0.x, vi0.y, aZtop ),
138 SFVEC3F( vo0.x, vo0.y, aZtop ),
139 SFVEC3F( vo1.x, vo1.y, aZtop ) );
141 aDstLayer->m_layer_bot_triangles->AddQuad(
SFVEC3F( vi1.x, vi1.y, aZbot ),
142 SFVEC3F( vo1.x, vo1.y, aZbot ),
143 SFVEC3F( vo0.x, vo0.y, aZbot ),
144 SFVEC3F( vi0.x, vi0.y, aZbot ) );
150 float aZtop,
float aZbot )
161 std::shared_ptr<TRIANGLE_DISPLAY_LIST> aDstLayer,
float aZtop,
float aZbot )
178 const float radius_of_the_square = sqrtf( aSeg->
GetRadiusSquared() * 2.0f );
179 const float radius_triangle_factor = ( radius_of_the_square -
radius ) /
radius;
182 rightDir.x *
radius * radius_triangle_factor );
185 leftDir.x *
radius * radius_triangle_factor );
188 aDstLayer->m_layer_top_segment_ends->AddTriangle(
189 SFVEC3F( rightEnd.x + texture_factor * factorS.x,
190 rightEnd.y + texture_factor * factorS.y,
192 SFVEC3F( leftStart.x + texture_factor * factorE.x,
193 leftStart.y + texture_factor * factorE.y,
195 SFVEC3F( start.x - texture_factorF * leftDir.x *
radius * sqrtf( 2.0f ),
196 start.y - texture_factorF * leftDir.y *
radius * sqrtf( 2.0f ),
199 aDstLayer->m_layer_top_segment_ends->AddTriangle(
200 SFVEC3F( leftEnd.x + texture_factor * factorE.x,
201 leftEnd.y + texture_factor * factorE.y, aZtop ),
202 SFVEC3F( rightStart.x + texture_factor * factorS.x,
203 rightStart.y + texture_factor * factorS.y, aZtop ),
205 end.y - texture_factorF * rightDir.y *
radius * sqrtf( 2.0f ),
209 aDstLayer->m_layer_bot_segment_ends->AddTriangle(
210 SFVEC3F( leftStart.x + texture_factor * factorE.x,
211 leftStart.y + texture_factor * factorE.y,
213 SFVEC3F( rightEnd.x + texture_factor * factorS.x,
214 rightEnd.y + texture_factor * factorS.y,
216 SFVEC3F( start.x - texture_factorF * leftDir.x *
radius * sqrtf( 2.0f ),
217 start.y - texture_factorF * leftDir.y *
radius * sqrtf( 2.0f ),
220 aDstLayer->m_layer_bot_segment_ends->AddTriangle(
221 SFVEC3F( rightStart.x + texture_factor * factorS.x,
222 rightStart.y + texture_factor * factorS.y, aZbot ),
223 SFVEC3F( leftEnd.x + texture_factor * factorE.x,
224 leftEnd.y + texture_factor * factorE.y, aZbot ),
226 end.y - texture_factorF * rightDir.y *
radius * sqrtf( 2.0f ),
230 aDstLayer->m_layer_top_triangles->AddQuad(
231 SFVEC3F( rightEnd.x, rightEnd.y, aZtop ),
232 SFVEC3F( rightStart.x, rightStart.y, aZtop ),
233 SFVEC3F( leftEnd.x, leftEnd.y, aZtop ),
234 SFVEC3F( leftStart.x, leftStart.y, aZtop ) );
236 aDstLayer->m_layer_bot_triangles->AddQuad(
237 SFVEC3F( rightEnd.x, rightEnd.y, aZbot ),
238 SFVEC3F( leftStart.x, leftStart.y, aZbot ),
239 SFVEC3F( leftEnd.x, leftEnd.y, aZbot ),
240 SFVEC3F( rightStart.x, rightStart.y, aZbot ) );
246 float aZbot,
bool aInvertFaces,
249 if( aListHolesObject2d.size() == 0 )
252 auto layerTriangles = std::make_shared<TRIANGLE_DISPLAY_LIST>( aListHolesObject2d.size() * 2 );
255 for(
const OBJECT_2D* object2d : aListHolesObject2d )
257 switch( object2d->GetObjectType() )
268 wxFAIL_MSG( wxT(
"RENDER_3D_OPENGL::generateHoles: Object type not implemented" ) );
277 layerTriangles->AddToMiddleContours( aPoly, aZbot, aZtop,
m_boardAdapter.BiuTo3dUnits(), aInvertFaces,
281 return std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( layerTriangles,
m_circleTexture, aZbot, aZtop );
285std::shared_ptr<OPENGL_RENDER_LIST_DEFERRED>
289 if( aContainer ==
nullptr )
294 if( listObject2d.size() == 0 )
303 unsigned int nrTrianglesEstimation = listObject2d.size() * 8;
305 auto layerTriangles = std::make_shared<TRIANGLE_DISPLAY_LIST>( nrTrianglesEstimation );
311 for(
const OBJECT_2D* object2d : listObject2d )
313 switch( object2d->GetObjectType() )
336 wxFAIL_MSG( wxT(
"RENDER_3D_OPENGL: Object type is not implemented" ) );
343 layerTriangles->AddToMiddleContours( *aPolyList, zBot, zTop,
m_boardAdapter.BiuTo3dUnits(),
false,
348 return std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( layerTriangles,
m_circleTexture, zBot, zTop );
354 float layer_z_bot = 0.0f;
355 float layer_z_top = 0.0f;
359 auto layerTriangles = std::make_shared<TRIANGLE_DISPLAY_LIST>( 1 );
364 return std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( layerTriangles,
m_circleTexture, layer_z_bot, layer_z_top );
372 std::shared_ptr<OPENGL_RENDER_LIST_DEFERRED> dispLists;
380 if( listBoardObject2d.size() > 0 )
384 const float layer_z_top = 1.0f;
385 const float layer_z_bot = 0.0f;
387 auto layerTriangles = std::make_shared<TRIANGLE_DISPLAY_LIST>( listBoardObject2d.size() );
390 for(
const OBJECT_2D* itemOnLayer : listBoardObject2d )
392 const OBJECT_2D* object2d_A = itemOnLayer;
407 layerTriangles->AddToMiddleContours( aBoardPoly, layer_z_bot, layer_z_top,
411 dispLists = std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( layerTriangles,
m_circleTexture, layer_z_top,
412 layer_z_top, aTransparent );
425 const int copperLayerCount =
m_boardAdapter.GetBoard()->GetCopperLayerCount();
427 const int platingThickness =
m_boardAdapter.GetHolePlatingThickness();
428 const float boardBodyThickness =
m_boardAdapter.GetBoardBodyThickness();
431 const float boardZTop = 1.0f;
432 const float boardZBot = 0.0f;
435 auto normalizeZ = [&](
float absZ ) ->
float
439 float boardThick = boardTop - boardBot;
441 if( boardThick <= 0 )
445 return ( absZ - boardBot ) / boardThick;
449 std::shared_ptr<TRIANGLE_DISPLAY_LIST> plugTriangles = std::make_shared<TRIANGLE_DISPLAY_LIST>( 1024 );
459 const float holeDiameter =
via->GetDrillValue() * unitScale;
460 const float holeInnerRadius = holeDiameter / 2.0f;
461 const float holeOuterRadius = holeInnerRadius + platingThickness * unitScale;
463 const int nrSegments =
m_boardAdapter.GetCircleSegmentCount(
via->GetDrillValue() );
466 via->LayerPair( &topLayer, &bottomLayer );
468 float viaZTop, viaZBot,
dummy;
473 const float secondaryDrillRadius =
via->GetSecondaryDrillSize().value_or( 0 ) * 0.5f * unitScale;
474 const float tertiaryDrillRadius =
via->GetTertiaryDrillSize().value_or( 0 ) * 0.5f * unitScale;
476 if( secondaryDrillRadius > holeOuterRadius || tertiaryDrillRadius > holeOuterRadius )
482 if( secondaryDrillRadius > holeOuterRadius )
484 plug_end_layer =
via->GetSecondaryDrillEndLayer();
487 if( tertiaryDrillRadius > holeOuterRadius )
489 plug_start_layer =
via->GetTertiaryDrillStartLayer();
493 float plugZTop, plugZBot, temp;
499 plugZTop, plugZBot, nrSegments, plugTriangles );
503 const auto frontMode =
via->GetFrontPostMachining();
505 if( frontMode.has_value()
509 const float frontRadius =
via->GetFrontPostMachiningSize() * 0.5f * unitScale;
510 const float frontDepth =
via->GetFrontPostMachiningDepth() * unitScale;
512 if( frontRadius > holeOuterRadius && frontDepth > 0 )
515 float pmBottomZ = normalizeZ( viaZTop - frontDepth );
516 float plugZBot = normalizeZ( viaZBot );
518 if( pmBottomZ > plugZBot )
524 pmBottomZ, plugZBot, nrSegments, plugTriangles, angle );
529 pmBottomZ, plugZBot, nrSegments, plugTriangles );
536 const auto backMode =
via->GetBackPostMachining();
538 if( backMode.has_value()
542 const float backRadius =
via->GetBackPostMachiningSize() * 0.5f * unitScale;
543 const float backDepth =
via->GetBackPostMachiningDepth() * unitScale;
545 if( backRadius > holeOuterRadius && backDepth > 0 )
548 float plugZTop = normalizeZ( viaZTop );
549 float pmTopZ = normalizeZ( viaZBot + backDepth );
551 if( plugZTop > pmTopZ )
557 plugZTop, pmTopZ, nrSegments, plugTriangles, angle );
562 plugZTop, pmTopZ, nrSegments, plugTriangles );
572 for(
const PAD*
pad : footprint->Pads() )
574 if( !
pad->HasHole() )
580 const SFVEC2F padCenter(
pad->GetPosition().x * unitScale,
581 -
pad->GetPosition().y * unitScale );
582 const float holeInnerRadius =
pad->GetDrillSize().x * 0.5f * unitScale;
583 const float holeOuterRadius = holeInnerRadius + platingThickness * unitScale;
584 const int nrSegments =
m_boardAdapter.GetCircleSegmentCount(
pad->GetDrillSize().x );
586 float padZTop, padZBot, padDummy;
591 const auto frontMode =
pad->GetFrontPostMachining();
593 if( frontMode.has_value()
597 const float frontRadius =
pad->GetFrontPostMachiningSize() * 0.5f * unitScale;
598 const float frontDepth =
pad->GetFrontPostMachiningDepth() * unitScale;
600 if( frontRadius > holeOuterRadius && frontDepth > 0 )
602 float pmBottomZ = normalizeZ( padZTop - frontDepth );
603 float plugZBot = normalizeZ( padZBot );
605 if( pmBottomZ > plugZBot )
611 pmBottomZ, plugZBot, nrSegments, plugTriangles, angle );
616 pmBottomZ, plugZBot, nrSegments, plugTriangles );
623 const auto backMode =
pad->GetBackPostMachining();
625 if( backMode.has_value()
629 const float backRadius =
pad->GetBackPostMachiningSize() * 0.5f * unitScale;
630 const float backDepth =
pad->GetBackPostMachiningDepth() * unitScale;
632 if( backRadius > holeOuterRadius && backDepth > 0 )
634 float plugZTop = normalizeZ( padZTop );
635 float pmTopZ = normalizeZ( padZBot + backDepth );
637 if( plugZTop > pmTopZ )
643 plugZTop, pmTopZ, nrSegments, plugTriangles, angle );
648 plugZTop, pmTopZ, nrSegments, plugTriangles );
657 if( plugTriangles->m_layer_top_triangles->GetVertexSize() > 0
658 || plugTriangles->m_layer_bot_triangles->GetVertexSize() > 0
659 || plugTriangles->m_layer_middle_contours_quads->GetVertexSize() > 0 )
667 std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( plugTriangles,
m_circleTexture, boardZTop, boardZTop ) );
681 if( !fp->HasExtrudedBody() )
702 bool isBack = fp->IsFlipped();
704 float standoff3d = body->
m_standoff * biuTo3d;
712 zBot = boardSurfaceZ + standoff3d + zOffset3d;
713 zTop = zBot + bodyThickness;
717 zTop = boardSurfaceZ - standoff3d - zOffset3d;
718 zBot = zTop - bodyThickness;
726 if( triList.empty() )
729 std::shared_ptr<TRIANGLE_DISPLAY_LIST> layerTri = std::make_shared<TRIANGLE_DISPLAY_LIST>( triList.size() );
737 layerTri->AddToMiddleContours( outline, zBot, zTop, biuTo3d,
false );
739 std::shared_ptr<OPENGL_RENDER_LIST_DEFERRED> renderList =
740 std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( layerTri,
m_circleTexture, zTop, zBot );
747 if( standoff3d > 0.0f )
755 float oppositeSurfaceZ =
m_boardAdapter.GetFootprintZPos( !isBack );
756 float protrusion = 1.0f *
pcbIUScale.IU_PER_MM * biuTo3d;
757 float pinZBot, pinZTop;
761 pinZBot = oppositeSurfaceZ - protrusion;
762 pinZTop = boardSurfaceZ + standoff3d;
766 pinZTop = oppositeSurfaceZ + protrusion;
767 pinZBot = boardSurfaceZ - standoff3d;
775 if( !pinTriList.empty() )
777 auto pinLayerTri = std::make_shared<TRIANGLE_DISPLAY_LIST>( pinTriList.size() );
786 pinLayerTri->AddToMiddleContours( pinPoly, pinZBot, pinZTop, biuTo3d,
false );
788 std::shared_ptr<OPENGL_RENDER_LIST_DEFERRED> pinRenderList =
789 std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( pinLayerTri,
m_circleTexture, pinZTop,
810 m_canvas->InvalidateRaytracingHitTesting();
820 m_camera.SetBoardLookAtPos( camera_pos );
840 if( aStop.stop_requested() )
845 m_canvas->InvalidateRaytracingHitTesting();
849 if( aStop.stop_requested() )
860 if( aStop.stop_requested() )
877 if( aStop.stop_requested() )
885 if(
m_boardAdapter.GetFrontCounterborePolys().OutlineCount() > 0 )
891 if(
m_boardAdapter.GetFrontCountersinkPolys().OutlineCount() > 0 )
903 if( aStop.stop_requested() )
911 if( aStop.stop_requested() )
943 wxASSERT( innerMapHoles.size() == outerMapHoles.size() );
947 if( outerMapHoles.size() > 0 )
949 float layer_z_bot = 0.0f;
950 float layer_z_top = 0.0f;
952 for(
const auto& [ layer, poly ] : outerMapHoles )
957 generateHoles( map_holes.at( layer )->GetList(), *poly, layer_z_top, layer_z_bot,
false ) );
960 for(
const auto& [ layer, poly ] : innerMapHoles )
965 generateHoles( map_holes.at( layer )->GetList(), *poly, layer_z_top, layer_z_bot,
false ) );
972 if( aStop.stop_requested() )
981 std::bitset<LAYER_3D_END> visibilityFlags =
m_boardAdapter.GetVisibleLayers();
985 for(
const auto& [ layer, container2d ] :
m_boardAdapter.GetLayerMap() )
1003 if( map_poly.contains( layer ) )
1005 polyListSubtracted = *map_poly.at( layer );
1023 else if( layer ==
B_Cu )
1042 polyList = &polyListSubtracted;
1046 if( aStop.stop_requested() )
1049 std::shared_ptr<OPENGL_RENDER_LIST_DEFERRED> oglList =
1052 if( oglList !=
nullptr )
1055 if( aStop.stop_requested() )
1066 if( frontPlatedCopperPolys )
1084 if( backPlatedCopperPolys )
1112 if( aStop.stop_requested() )
1125 if( aStop.stop_requested() )
1134 if( !aStop.stop_requested() &&
m_canvas )
1140 if( aStop.stop_requested() )
1148 m_activityReporter->Report( wxString::Format(
_(
"Load completed in %.3f s" ), calculation_time ) );
1155 wxLogTrace(
m_logTrace, wxT(
"RENDER_3D_OPENGL::startBgWorker" ) );
1161 [
this]( std::stop_token aStopToken )
1164 BS::this_thread::set_os_thread_priority( BS::os_thread_priority::below_normal );
1182 [
this]( std::stop_token aStop )
1184 BS::this_thread::set_os_thread_priority( BS::os_thread_priority::below_normal );
1199 if( aStop.stop_requested() || !
m_canvas )
1202 m_canvas->ReloadRaytracingForHitTesting( aStop );
1216 wxLogTrace(
m_logTrace, wxT(
"RENDER_3D_OPENGL::StopBgWorker" ) );
1233 wxLogTrace(
m_logTrace, wxT(
"RENDER_3D_OPENGL::JoinBgWorker" ) );
1243 aDst->m_layer_bot_triangles->AddTriangle(
SFVEC3F( v0.x, v0.y, bot ),
1247 aDst->m_layer_top_triangles->AddTriangle(
SFVEC3F(
v2.x,
v2.y,
top ),
1258 if( aOutZtop < aOutZbot )
1260 float tmpFloat = aOutZbot;
1261 aOutZbot = aOutZtop;
1262 aOutZtop = tmpFloat;
1268 float aZbot,
unsigned int aNr_sides_per_circle,
1269 std::shared_ptr<TRIANGLE_DISPLAY_LIST> aDstLayer )
1271 std::vector< SFVEC2F > innerContour;
1272 std::vector< SFVEC2F > outerContour;
1274 generateRing( aCenter, aInnerRadius, aOuterRadius, aNr_sides_per_circle, innerContour,
1275 outerContour,
false );
1277 for(
unsigned int i = 0; i < ( innerContour.size() - 1 ); ++i )
1279 const SFVEC2F& vi0 = innerContour[i + 0];
1280 const SFVEC2F& vi1 = innerContour[i + 1];
1281 const SFVEC2F& vo0 = outerContour[i + 0];
1282 const SFVEC2F& vo1 = outerContour[i + 1];
1284 aDstLayer->m_layer_top_triangles->AddQuad(
SFVEC3F( vi1.x, vi1.y, aZtop ),
1285 SFVEC3F( vi0.x, vi0.y, aZtop ),
1286 SFVEC3F( vo0.x, vo0.y, aZtop ),
1287 SFVEC3F( vo1.x, vo1.y, aZtop ) );
1289 aDstLayer->m_layer_bot_triangles->AddQuad(
SFVEC3F( vi1.x, vi1.y, aZbot ),
1290 SFVEC3F( vo1.x, vo1.y, aZbot ),
1291 SFVEC3F( vo0.x, vo0.y, aZbot ),
1292 SFVEC3F( vi0.x, vi0.y, aZbot ) );
1295 aDstLayer->AddToMiddleContours( outerContour, aZbot, aZtop,
true );
1296 aDstLayer->AddToMiddleContours( innerContour, aZbot, aZtop,
false );
1301 float aZbot,
unsigned int aNr_sides_per_circle,
1302 std::shared_ptr<TRIANGLE_DISPLAY_LIST> aDstLayer,
EDA_ANGLE aAngle )
1313 float radialDiff = aOuterRadius - aInnerRadius;
1317 if( angleRad < 0.01f )
1320 float innerHeight = radialDiff / tanf( angleRad );
1321 float totalHeight = aZtop - aZbot;
1324 if( innerHeight > totalHeight )
1325 innerHeight = totalHeight;
1327 float zInnerTop = aZbot + innerHeight;
1329 std::vector< SFVEC2F > innerContour;
1330 std::vector< SFVEC2F > outerContour;
1332 generateRing( aCenter, aInnerRadius, aOuterRadius, aNr_sides_per_circle, innerContour,
1333 outerContour,
false );
1335 for(
unsigned int i = 0; i < ( innerContour.size() - 1 ); ++i )
1337 const SFVEC2F& vi0 = innerContour[i + 0];
1338 const SFVEC2F& vi1 = innerContour[i + 1];
1339 const SFVEC2F& vo0 = outerContour[i + 0];
1340 const SFVEC2F& vo1 = outerContour[i + 1];
1343 aDstLayer->m_layer_top_triangles->AddQuad(
SFVEC3F( vi1.x, vi1.y, zInnerTop ),
1344 SFVEC3F( vi0.x, vi0.y, zInnerTop ),
1345 SFVEC3F( vo0.x, vo0.y, aZtop ),
1346 SFVEC3F( vo1.x, vo1.y, aZtop ) );
1349 aDstLayer->m_layer_bot_triangles->AddQuad(
SFVEC3F( vi1.x, vi1.y, aZbot ),
1350 SFVEC3F( vo1.x, vo1.y, aZbot ),
1351 SFVEC3F( vo0.x, vo0.y, aZbot ),
1352 SFVEC3F( vi0.x, vi0.y, aZbot ) );
1356 aDstLayer->AddToMiddleContours( outerContour, aZbot, aZtop,
true );
1358 aDstLayer->AddToMiddleContours( innerContour, aZbot, zInnerTop,
false );
1363 std::shared_ptr<TRIANGLE_DISPLAY_LIST> aDstLayer,
bool aTop )
1365 const float delta = 2.0f * glm::pi<float>() / (float) aNr_sides_per_circle;
1367 for(
unsigned int i = 0; i < aNr_sides_per_circle; ++i )
1369 float a0 =
delta * i;
1370 float a1 =
delta * ( i + 1 );
1371 const SFVEC3F p0( aCenter.x + cosf( a0 ) * aRadius,
1372 aCenter.y + sinf( a0 ) * aRadius, aZ );
1373 const SFVEC3F p1( aCenter.x + cosf( a1 ) * aRadius,
1374 aCenter.y + sinf( a1 ) * aRadius, aZ );
1375 const SFVEC3F c( aCenter.x, aCenter.y, aZ );
1378 aDstLayer->m_layer_top_triangles->AddTriangle( p1, p0, c );
1380 aDstLayer->m_layer_bot_triangles->AddTriangle( p0, p1, c );
1386 unsigned int aNr_sides_per_circle,
1387 std::shared_ptr<TRIANGLE_DISPLAY_LIST> aDstLayer,
bool aTop )
1389 const float delta = 2.0f * glm::pi<float>() / (float) aNr_sides_per_circle;
1390 const SFVEC3F c( aCenter.x, aCenter.y, aTop ? aZ - aDepth : aZ + aDepth );
1392 for(
unsigned int i = 0; i < aNr_sides_per_circle; ++i )
1394 float a0 =
delta * i;
1395 float a1 =
delta * ( i + 1 );
1396 const SFVEC3F p0( aCenter.x + cosf( a0 ) * aRadius,
1397 aCenter.y + sinf( a0 ) * aRadius, aZ );
1398 const SFVEC3F p1( aCenter.x + cosf( a1 ) * aRadius,
1399 aCenter.y + sinf( a1 ) * aRadius, aZ );
1402 aDstLayer->m_layer_top_triangles->AddTriangle( p0, p1, c );
1404 aDstLayer->m_layer_bot_triangles->AddTriangle( p1, p0, c );
1414 float aHoleInnerRadius,
1417 float aPlatingThickness3d,
1424 if( !aDstLayer || aPlatingThickness3d <= 0.0f || aHoleInnerRadius <= 0.0f )
1433 if( aSizeIU <= 0 || aDepthIU <= 0 )
1436 const float radius = aSizeIU * 0.5f * aUnitScale;
1437 const float depth = aDepthIU * aUnitScale;
1439 if(
radius <= aHoleInnerRadius || depth <= 0.0f )
1442 float zEnd = aIsFront ? ( aZSurface - depth ) : ( aZSurface + depth );
1447 const float zTop = std::max( aZSurface, zEnd );
1448 const float zBot = std::min( aZSurface, zEnd );
1450 const int diameterBIU = std::max( aSizeIU,
1452 (
int) ( ( aHoleInnerRadius * 2.0f )
1454 const unsigned int nrSegments =
1455 std::max( 12u,
m_boardAdapter.GetCircleSegmentCount( diameterBIU ) );
1460 nrSegments, aDstLayer );
1464 float csTopRadius =
radius;
1465 float csBotRadius = aHoleInnerRadius;
1467 std::vector< SFVEC2F > innerContourTop, outerContourTop;
1468 std::vector< SFVEC2F > innerContourBot, outerContourBot;
1470 generateRing( aHoleCenter, csTopRadius, csTopRadius + aPlatingThickness3d, nrSegments,
1471 innerContourTop, outerContourTop,
false );
1472 generateRing( aHoleCenter, csBotRadius, csBotRadius + aPlatingThickness3d, nrSegments,
1473 innerContourBot, outerContourBot,
false );
1475 for(
unsigned int i = 0; i < ( innerContourTop.size() - 1 ); ++i )
1477 const SFVEC2F& vi0_top = innerContourTop[i + 0];
1478 const SFVEC2F& vi1_top = innerContourTop[i + 1];
1479 const SFVEC2F& vo0_top = outerContourTop[i + 0];
1480 const SFVEC2F& vo1_top = outerContourTop[i + 1];
1482 const SFVEC2F& vi0_bot = innerContourBot[i + 0];
1483 const SFVEC2F& vi1_bot = innerContourBot[i + 1];
1484 const SFVEC2F& vo0_bot = outerContourBot[i + 0];
1485 const SFVEC2F& vo1_bot = outerContourBot[i + 1];
1487 aDstLayer->m_layer_middle_contours_quads->AddQuad(
1488 SFVEC3F( vi1_top.x, vi1_top.y, zTop ),
1489 SFVEC3F( vi0_top.x, vi0_top.y, zTop ),
1490 SFVEC3F( vi0_bot.x, vi0_bot.y, zBot ),
1491 SFVEC3F( vi1_bot.x, vi1_bot.y, zBot ) );
1493 aDstLayer->m_layer_middle_contours_quads->AddQuad(
1494 SFVEC3F( vo1_top.x, vo1_top.y, zTop ),
1495 SFVEC3F( vo0_top.x, vo0_top.y, zTop ),
1496 SFVEC3F( vo0_bot.x, vo0_bot.y, zBot ),
1497 SFVEC3F( vo1_bot.x, vo1_bot.y, zBot ) );
1512 float averageDiameter =
m_boardAdapter.GetAverageViaHoleDiameter();
1513 unsigned int averageSegCount =
m_boardAdapter.GetCircleSegmentCount( averageDiameter );
1514 unsigned int trianglesEstimate = averageSegCount * 8 *
m_boardAdapter.GetViaCount();
1516 std::shared_ptr<TRIANGLE_DISPLAY_LIST> layerTriangleVIA = std::make_shared<TRIANGLE_DISPLAY_LIST>( trianglesEstimate );
1524 bool isBackdrilled =
via->GetSecondaryDrillSize().has_value();
1525 bool isTertiarydrilled =
via->GetTertiaryDrillSize().has_value();
1536 && !hasFrontPostMachining && !hasBackPostMachining )
1541 const float holediameter =
via->GetDrillValue() * aUnitScale;
1542 const int nrSegments =
m_boardAdapter.GetCircleSegmentCount(
via->GetDrillValue() );
1543 const float hole_inner_radius = holediameter / 2.0f;
1545 const SFVEC2F via_center(
via->GetStart().x * aUnitScale,
1546 -
via->GetStart().y * aUnitScale );
1549 via->LayerPair( &top_layer, &bottom_layer );
1551 float ztop, zbot,
dummy;
1556 wxASSERT( zbot < ztop );
1558 float ztop_plated = ztop;
1559 float zbot_plated = zbot;
1569 zbot_plated = std::max( zbot_plated, secZEnd );
1572 if( isTertiarydrilled )
1580 ztop_plated = std::min( ztop_plated, terZEnd );
1583 auto applyViaPostMachining = [&](
bool isFront )
1585 auto modeOpt = isFront ?
via->GetFrontPostMachining()
1586 :
via->GetBackPostMachining();
1594 int sizeIU = isFront ?
via->GetFrontPostMachiningSize()
1595 :
via->GetBackPostMachiningSize();
1596 int depthIU = isFront ?
via->GetFrontPostMachiningDepth()
1597 :
via->GetBackPostMachiningDepth();
1598 float zSurface = isFront ? ztop : zbot;
1602 sizeIU, depthIU, hole_inner_radius, zSurface,
1603 isFront, aPlatingThickness3d, aUnitScale, &zEnd ) )
1606 ztop_plated = std::min( ztop_plated, zEnd );
1608 zbot_plated = std::max( zbot_plated, zEnd );
1612 if( hasFrontPostMachining )
1613 applyViaPostMachining(
true );
1614 if( hasBackPostMachining )
1615 applyViaPostMachining(
false );
1617 generateCylinder( via_center, hole_inner_radius, hole_inner_radius + aPlatingThickness3d, ztop_plated,
1618 zbot_plated, nrSegments, layerTriangleVIA );
1621 const float padFrontSurface =
1624 const float padBackSurface =
1630 for(
const PAD*
pad : footprint->Pads() )
1635 if( !
pad->HasHole() )
1641 const SFVEC2F padCenter(
pad->GetPosition().x * aUnitScale,
1642 -
pad->GetPosition().y * aUnitScale );
1643 const float holeInnerRadius =
1644 pad->GetDrillSize().x * 0.5f * aUnitScale;
1646 auto emitPadPostMachining = [&](
bool isFront )
1648 auto modeOpt = isFront ?
pad->GetFrontPostMachining()
1649 :
pad->GetBackPostMachining();
1657 int sizeIU = isFront ?
pad->GetFrontPostMachiningSize()
1658 :
pad->GetBackPostMachiningSize();
1659 int depthIU = isFront ?
pad->GetFrontPostMachiningDepth()
1660 :
pad->GetBackPostMachiningDepth();
1661 float zSurface = isFront ? padFrontSurface : padBackSurface;
1664 sizeIU, depthIU, holeInnerRadius, zSurface,
1665 isFront, aPlatingThickness3d, aUnitScale,
1669 emitPadPostMachining(
true );
1670 emitPadPostMachining(
false );
1675 std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( layerTriangleVIA, 0, 0.0f, 0.0f ) );
1719 for(
const PAD*
pad : footprint->Pads() )
1723 if( !
pad->HasHole() )
1726 pad->TransformHoleToPolygon( tht_outer_holes_poly, aPlatingThickness,
1728 pad->TransformHoleToPolygon( tht_inner_holes_poly, 0,
1737 tht_outer_holes_poly.
BooleanAdd( capped_outer_vias_poly );
1738 tht_inner_holes_poly.
BooleanAdd( capped_inner_vias_poly );
1747 if( holes2D.size() > 0 &&
m_boardAdapter.m_Cfg->m_Render.show_plated_barrels )
1749 float layer_z_top, layer_z_bot,
dummy;
1754 std::shared_ptr<TRIANGLE_DISPLAY_LIST> layerTriangles = std::make_shared<TRIANGLE_DISPLAY_LIST>( holes2D.size() );
1756 for(
const OBJECT_2D* itemOnLayer : holes2D )
1758 const OBJECT_2D* object2d_A = itemOnLayer;
1775 layerTriangles->AddToMiddleContours( tht_outer_holes_poly,
1776 layer_z_bot, layer_z_top,
1777 aUnitScale,
false );
1780 std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( layerTriangles,
m_circleTexture, layer_z_top,
1792 std::shared_ptr<TRIANGLE_DISPLAY_LIST> frontCover = std::make_shared<TRIANGLE_DISPLAY_LIST>(
m_boardAdapter.GetViaCount() );
1793 std::shared_ptr<TRIANGLE_DISPLAY_LIST> backCover = std::make_shared<TRIANGLE_DISPLAY_LIST>(
m_boardAdapter.GetViaCount() );
1802 const float holediameter =
via->GetDrillValue() * aUnitScale;
1803 const float hole_radius = holediameter / 2.0f + 2.0f * aPlatingThickness3d;
1805 -
via->GetStart().y * aUnitScale );
1806 unsigned int seg =
m_boardAdapter.GetCircleSegmentCount(
via->GetDrillValue() );
1809 via->LayerPair( &top_layer, &bottom_layer );
1810 float ztop, zbot,
dummy;
1823 const auto frontPostMachining =
1825 const auto backPostMachining =
1833 bool hasFrontBackdrill =
via->GetSecondaryDrillStartLayer() ==
F_Cu;
1834 bool hasBackBackdrill =
via->GetSecondaryDrillStartLayer() ==
B_Cu;
1836 const float depth = hole_radius * 0.3f;
1838 if( frontCovering && !hasFrontPostMachining && !hasFrontBackdrill )
1840 if( filled || !frontPlugged )
1846 if( backCovering && !hasBackPostMachining && !hasBackBackdrill )
1848 if( filled || !backPlugged )
1855 if( frontCover->m_layer_top_triangles->GetVertexSize() > 0 )
1857 std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( frontCover, 0, 0.0f, 0.0f ) );
1859 if( backCover->m_layer_bot_triangles->GetVertexSize() > 0 )
1861 std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( backCover, 0, 0.0f, 0.0f ) );
1870 const int platingThickness =
m_boardAdapter.GetHolePlatingThickness();
1872 const float platingThickness3d = platingThickness * unitScale;
1912 wxString libraryName = footprint->GetFPID().GetLibNickname();
1913 wxString footprintBasePath = wxEmptyString;
1920 std::optional<LIBRARY_TABLE_ROW*> fpRow =
1933 for(
const FP_3DMODEL& fp_model : footprint->Models() )
1935 if( fp_model.m_Show && !fp_model.m_Filename.empty() )
1941 wxFileName fn( fp_model.m_Filename );
1950 std::vector<const EMBEDDED_FILES*> embeddedFilesStack;
1951 embeddedFilesStack.push_back( footprint->GetEmbeddedFiles() );
1952 embeddedFilesStack.push_back(
m_boardAdapter.GetBoard()->GetEmbeddedFiles() );
1954 const S3DMODEL* modelPtr = cacheMgr->
GetModel( fp_model.m_Filename, footprintBasePath,
1955 std::move( embeddedFilesStack ) );
1961 auto model = std::make_shared<MODEL_3D_DEFERRED>( *modelPtr, materialMode );
1968 if( aStop.stop_requested() )
MATERIAL_MODE
Render 3d model shape materials mode.
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 GetExtrusionPinOutline(const FOOTPRINT *aFootprint, SHAPE_POLY_SET &aPinPoly)
Get the pin outline polygons for extruded THT pin rendering.
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
std::optional< LIBRARY_TABLE_ROW * > GetRow(const wxString &aNickname, LIBRARY_TABLE_SCOPE aScope=LIBRARY_TABLE_SCOPE::BOTH) const
Like LIBRARY_MANAGER::GetRow but filtered to the LIBRARY_TABLE_TYPE of this adapter.
std::optional< wxString > GetFullURI(LIBRARY_TABLE_TYPE aType, const wxString &aNickname, bool aSubstituted=false)
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
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
static FOOTPRINT_LIBRARY_ADAPTER * FootprintLibAdapter(PROJECT *aProject)
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
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