KiCad PCB EDA Suite
Loading...
Searching...
No Matches
opengl/create_scene.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2015-2016 Mario Luzeiro <[email protected]>
5 * Copyright (C) 2023 CERN
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22#include "render_3d_opengl.h"
25#include <3d_viewer_id.h>
26#include <board.h>
27#include <footprint.h>
28#include <pcb_3d_body.h>
29#include <pcb_track.h>
31#include <lset.h>
32#include <core/profile.h> // To use GetRunningMicroSecs or another profiling utility
34#include <thread_pool.h>
36
37
39 std::shared_ptr<TRIANGLE_DISPLAY_LIST> aDstLayer, float aZtop, float aZbot )
40{
41 const SFVEC2F& center = aCircle->GetCenter();
42 const float radius = aCircle->GetRadius() * 2.0f; // Double because the render triangle
43
44 // This is a small adjustment to the circle texture
45 const float texture_factor = ( 8.0f / (float) SIZE_OF_CIRCLE_TEXTURE ) + 1.0f;
46 const float f = ( sqrtf( 2.0f ) / 2.0f ) * radius * texture_factor;
47
48 // Top and Bot segments ends are just triangle semi-circles, so need to add it in duplicated.
49 aDstLayer->m_layer_top_segment_ends->AddTriangle( SFVEC3F( center.x + f, center.y, aZtop ),
50 SFVEC3F( center.x - f, center.y, aZtop ),
51 SFVEC3F( center.x, center.y - f, aZtop ) );
52
53 aDstLayer->m_layer_top_segment_ends->AddTriangle( SFVEC3F( center.x - f, center.y, aZtop ),
54 SFVEC3F( center.x + f, center.y, aZtop ),
55 SFVEC3F( center.x, center.y + f, aZtop ) );
56
57 aDstLayer->m_layer_bot_segment_ends->AddTriangle( SFVEC3F( center.x - f, center.y, aZbot ),
58 SFVEC3F( center.x + f, center.y, aZbot ),
59 SFVEC3F( center.x, center.y - f, aZbot ) );
60
61 aDstLayer->m_layer_bot_segment_ends->AddTriangle( SFVEC3F( center.x + f, center.y, aZbot ),
62 SFVEC3F( center.x - f, center.y, aZbot ),
63 SFVEC3F( center.x, center.y + f, aZbot ) );
64}
65
66
68 std::shared_ptr<TRIANGLE_DISPLAY_LIST> aDstLayer, float aZtop, float aZbot )
69{
70 const SFVEC2F& v0 = aPoly->GetV0();
71 const SFVEC2F& v1 = aPoly->GetV1();
72 const SFVEC2F& v2 = aPoly->GetV2();
73 const SFVEC2F& v3 = aPoly->GetV3();
74
75 addTopAndBottomTriangles( aDstLayer, v0, v2, v1, aZtop, aZbot );
76 addTopAndBottomTriangles( aDstLayer, v2, v0, v3, aZtop, aZbot );
77}
78
79
80void RENDER_3D_OPENGL::generateRing( const SFVEC2F& aCenter, float aInnerRadius,
81 float aOuterRadius, unsigned int aNr_sides_per_circle,
82 std::vector< SFVEC2F >& aInnerContourResult,
83 std::vector< SFVEC2F >& aOuterContourResult,
84 bool aInvertOrder )
85{
86 aInnerContourResult.clear();
87 aInnerContourResult.reserve( aNr_sides_per_circle + 2 );
88
89 aOuterContourResult.clear();
90 aOuterContourResult.reserve( aNr_sides_per_circle + 2 );
91
92 const int delta = 3600 / aNr_sides_per_circle;
93
94 for( int ii = 0; ii < 3600; ii += delta )
95 {
96 float angle = (float)( aInvertOrder ? ( 3600 - ii ) : ii )
97 * 2.0f * glm::pi<float>() / 3600.0f;
98 const SFVEC2F rotatedDir = SFVEC2F( cos( angle ), sin( angle ) );
99
100 aInnerContourResult.emplace_back( aCenter.x + rotatedDir.x * aInnerRadius,
101 aCenter.y + rotatedDir.y * aInnerRadius );
102
103 aOuterContourResult.emplace_back( aCenter.x + rotatedDir.x * aOuterRadius,
104 aCenter.y + rotatedDir.y * aOuterRadius );
105 }
106
107 aInnerContourResult.push_back( aInnerContourResult[0] );
108 aOuterContourResult.push_back( aOuterContourResult[0] );
109
110 wxASSERT( aInnerContourResult.size() == aOuterContourResult.size() );
111}
112
113
114void RENDER_3D_OPENGL::addObjectTriangles( const RING_2D* aRing, std::shared_ptr<TRIANGLE_DISPLAY_LIST> aDstLayer,
115 float aZtop, float aZbot )
116{
117 const SFVEC2F& center = aRing->GetCenter();
118 const float inner = aRing->GetInnerRadius();
119 const float outer = aRing->GetOuterRadius();
120
121 std::vector< SFVEC2F > innerContour;
122 std::vector< SFVEC2F > outerContour;
123
124 generateRing( center, inner, outer, m_boardAdapter.GetCircleSegmentCount( outer * 2.0f ),
125 innerContour, outerContour, false );
126
127 // This will add the top and bot quads that will form the approximated ring
128 for( unsigned int i = 0; i < ( innerContour.size() - 1 ); ++i )
129 {
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];
134
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 ) );
139
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 ) );
144 }
145}
146
147
148void RENDER_3D_OPENGL::addObjectTriangles( const TRIANGLE_2D* aTri, std::shared_ptr<TRIANGLE_DISPLAY_LIST> aDstLayer,
149 float aZtop, float aZbot )
150{
151 const SFVEC2F& v1 = aTri->GetP1();
152 const SFVEC2F& v2 = aTri->GetP2();
153 const SFVEC2F& v3 = aTri->GetP3();
154
155 addTopAndBottomTriangles( aDstLayer, v1, v2, v3, aZtop, aZbot );
156}
157
158
160 std::shared_ptr<TRIANGLE_DISPLAY_LIST> aDstLayer, float aZtop, float aZbot )
161{
162 const SFVEC2F& leftStart = aSeg->GetLeftStar();
163 const SFVEC2F& leftEnd = aSeg->GetLeftEnd();
164 const SFVEC2F& leftDir = aSeg->GetLeftDir();
165
166 const SFVEC2F& rightStart = aSeg->GetRightStar();
167 const SFVEC2F& rightEnd = aSeg->GetRightEnd();
168 const SFVEC2F& rightDir = aSeg->GetRightDir();
169 const float radius = aSeg->GetRadius();
170
171 const SFVEC2F& start = aSeg->GetStart();
172 const SFVEC2F& end = aSeg->GetEnd();
173
174 const float texture_factor = ( 12.0f / (float) SIZE_OF_CIRCLE_TEXTURE ) + 1.0f;
175 const float texture_factorF = ( 6.0f / (float) SIZE_OF_CIRCLE_TEXTURE ) + 1.0f;
176
177 const float radius_of_the_square = sqrtf( aSeg->GetRadiusSquared() * 2.0f );
178 const float radius_triangle_factor = ( radius_of_the_square - radius ) / radius;
179
180 const SFVEC2F factorS = SFVEC2F( -rightDir.y * radius * radius_triangle_factor,
181 rightDir.x * radius * radius_triangle_factor );
182
183 const SFVEC2F factorE = SFVEC2F( -leftDir.y * radius * radius_triangle_factor,
184 leftDir.x * radius * radius_triangle_factor );
185
186 // Top end segment triangles (semi-circles)
187 aDstLayer->m_layer_top_segment_ends->AddTriangle(
188 SFVEC3F( rightEnd.x + texture_factor * factorS.x,
189 rightEnd.y + texture_factor * factorS.y,
190 aZtop ),
191 SFVEC3F( leftStart.x + texture_factor * factorE.x,
192 leftStart.y + texture_factor * factorE.y,
193 aZtop ),
194 SFVEC3F( start.x - texture_factorF * leftDir.x * radius * sqrtf( 2.0f ),
195 start.y - texture_factorF * leftDir.y * radius * sqrtf( 2.0f ),
196 aZtop ) );
197
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 ),
203 SFVEC3F( end.x - texture_factorF * rightDir.x * radius * sqrtf( 2.0f ),
204 end.y - texture_factorF * rightDir.y * radius * sqrtf( 2.0f ),
205 aZtop ) );
206
207 // Bot end segment triangles (semi-circles)
208 aDstLayer->m_layer_bot_segment_ends->AddTriangle(
209 SFVEC3F( leftStart.x + texture_factor * factorE.x,
210 leftStart.y + texture_factor * factorE.y,
211 aZbot ),
212 SFVEC3F( rightEnd.x + texture_factor * factorS.x,
213 rightEnd.y + texture_factor * factorS.y,
214 aZbot ),
215 SFVEC3F( start.x - texture_factorF * leftDir.x * radius * sqrtf( 2.0f ),
216 start.y - texture_factorF * leftDir.y * radius * sqrtf( 2.0f ),
217 aZbot ) );
218
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 ),
224 SFVEC3F( end.x - texture_factorF * rightDir.x * radius * sqrtf( 2.0f ),
225 end.y - texture_factorF * rightDir.y * radius * sqrtf( 2.0f ),
226 aZbot ) );
227
228 // Segment top and bot planes
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 ) );
234
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 ) );
240}
241
242
243std::shared_ptr<OPENGL_RENDER_LIST_DEFERRED> RENDER_3D_OPENGL::generateHoles( const LIST_OBJECT2D& aListHolesObject2d,
244 const SHAPE_POLY_SET& aPoly, float aZtop,
245 float aZbot, bool aInvertFaces,
246 const BVH_CONTAINER_2D* aThroughHoles )
247{
248 if( aListHolesObject2d.size() == 0 )
249 return nullptr;
250
251 auto triangles = std::make_shared<TRIANGLE_DISPLAY_LIST>( aListHolesObject2d.size() * 2 );
252
253 // Convert the list of objects(filled circles) to triangle layer structure
254 for( const OBJECT_2D* object2d : aListHolesObject2d )
255 {
256 switch( object2d->GetObjectType() )
257 {
259 addObjectTriangles( static_cast<const FILLED_CIRCLE_2D*>( object2d ), triangles, aZtop, aZbot );
260 break;
261
263 addObjectTriangles( static_cast<const ROUND_SEGMENT_2D*>( object2d ), triangles, aZtop, aZbot );
264 break;
265
266 default:
267 wxFAIL_MSG( wxT( "RENDER_3D_OPENGL::generateHoles: Object type not implemented" ) );
268 break;
269 }
270 }
271
272 // Note: he can have a aListHolesObject2d with holes but without contours
273 // eg: when there are only NPTH on the list and the contours were not added
274 if( aPoly.OutlineCount() > 0 )
275 {
276 triangles->AddToMiddleContours( aPoly, aZbot, aZtop, m_boardAdapter.BiuTo3dUnits(), aInvertFaces,
277 aThroughHoles );
278 }
279
280 return std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( triangles, m_circleTexture, aZbot, aZtop );
281}
282
283
284std::shared_ptr<OPENGL_RENDER_LIST_DEFERRED>
286 PCB_LAYER_ID aLayer, const BVH_CONTAINER_2D* aThroughHoles )
287{
288 if( aContainer == nullptr )
289 return nullptr;
290
291 const LIST_OBJECT2D& listObject2d = aContainer->GetList();
292
293 if( listObject2d.size() == 0 )
294 return nullptr;
295
296 float zBot = 0.0f;
297 float zTop = 0.0f;
298
299 getLayerZPos( aLayer, zTop, zBot );
300
301 // Calculate an estimation for the nr of triangles based on the nr of objects
302 unsigned int nrTrianglesEstimation = listObject2d.size() * 8;
303
304 auto layerTriangles = std::make_shared<TRIANGLE_DISPLAY_LIST>( nrTrianglesEstimation );
305
306 // store in a list so it will be latter deleted
307 appendRenderTriangleList( layerTriangles );
308
309 // Load the 2D (X,Y axis) component of shapes
310 for( const OBJECT_2D* object2d : listObject2d )
311 {
312 switch( object2d->GetObjectType() )
313 {
315 addObjectTriangles( static_cast<const FILLED_CIRCLE_2D*>( object2d ), layerTriangles, zTop, zBot );
316 break;
317
319 addObjectTriangles( static_cast<const POLYGON_4PT_2D*>( object2d ), layerTriangles, zTop, zBot );
320 break;
321
323 addObjectTriangles( static_cast<const RING_2D*>( object2d ), layerTriangles, zTop, zBot );
324 break;
325
327 addObjectTriangles( static_cast<const TRIANGLE_2D*>( object2d ), layerTriangles, zTop, zBot );
328 break;
329
331 addObjectTriangles( static_cast<const ROUND_SEGMENT_2D*>( object2d ), layerTriangles, zTop, zBot );
332 break;
333
334 default:
335 wxFAIL_MSG( wxT( "RENDER_3D_OPENGL: Object type is not implemented" ) );
336 break;
337 }
338 }
339
340 if( aPolyList && aPolyList->OutlineCount() > 0 )
341 {
342 layerTriangles->AddToMiddleContours( *aPolyList, zBot, zTop, m_boardAdapter.BiuTo3dUnits(), false,
343 aThroughHoles );
344 }
345
346 // Create display list
347 return std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( layerTriangles, m_circleTexture, zBot, zTop );
348}
349
350
351std::shared_ptr<OPENGL_RENDER_LIST_DEFERRED> RENDER_3D_OPENGL::generateEmptyLayerList( PCB_LAYER_ID aLayer )
352{
353 float layer_z_bot = 0.0f;
354 float layer_z_top = 0.0f;
355
356 getLayerZPos( aLayer, layer_z_top, layer_z_bot );
357
358 auto layerTriangles = std::make_shared<TRIANGLE_DISPLAY_LIST>( 1 );
359
360 // store in a list so it will be latter deleted
361 appendRenderTriangleList( layerTriangles );
362
363 return std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( layerTriangles, m_circleTexture, layer_z_bot, layer_z_top );
364}
365
366
367std::shared_ptr<OPENGL_RENDER_LIST_DEFERRED> RENDER_3D_OPENGL::createBoard( const SHAPE_POLY_SET& aBoardPoly,
368 const BVH_CONTAINER_2D* aThroughHoles,
369 bool aTransparent )
370{
371 std::shared_ptr<OPENGL_RENDER_LIST_DEFERRED> dispLists;
372 CONTAINER_2D boardContainer;
373
374 ConvertPolygonToTriangles( aBoardPoly, boardContainer, m_boardAdapter.BiuTo3dUnits(),
375 (const BOARD_ITEM &)*m_boardAdapter.GetBoard() );
376
377 const LIST_OBJECT2D& listBoardObject2d = boardContainer.GetList();
378
379 if( listBoardObject2d.size() > 0 )
380 {
381 // We will set a unitary Z so it will in future used with transformations since the
382 // board poly will be used not only to draw itself but also the solder mask layers.
383 const float layer_z_top = 1.0f;
384 const float layer_z_bot = 0.0f;
385
386 auto triangles = std::make_shared<TRIANGLE_DISPLAY_LIST>( listBoardObject2d.size() );
387
388 // Convert the list of objects(triangles) to triangle layer structure
389 for( const OBJECT_2D* itemOnLayer : listBoardObject2d )
390 {
391 const OBJECT_2D* object2d_A = itemOnLayer;
392
393 wxASSERT( object2d_A->GetObjectType() == OBJECT_2D_TYPE::TRIANGLE );
394
395 const TRIANGLE_2D* tri = static_cast<const TRIANGLE_2D*>( object2d_A );
396
397 const SFVEC2F& v1 = tri->GetP1();
398 const SFVEC2F& v2 = tri->GetP2();
399 const SFVEC2F& v3 = tri->GetP3();
400
401 addTopAndBottomTriangles( triangles, v1, v2, v3, layer_z_top, layer_z_bot );
402 }
403
404 if( aBoardPoly.OutlineCount() > 0 )
405 {
406 triangles->AddToMiddleContours( aBoardPoly, layer_z_bot, layer_z_top, m_boardAdapter.BiuTo3dUnits(),
407 false, aThroughHoles );
408
409 dispLists = std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( triangles, m_circleTexture, 0.0f, 0.0f,
410 aTransparent );
411 }
412 }
413
414 return dispLists;
415}
416
417
418/*
419 * Pretend we had created a hole straight through the board with a radius equal to the largest
420 * backdrill/counterbore. We then fill the parts of that hole that _weren't_ backdrilled/counterbored
421 * with a thick cylindrical plug to step the non-backdrilled/counterbored sections back to the smaller
422 * via/pad hole size.
423 *
424 * Now, we don't really create the full-height max-radius hole, but the plugs do still provide top and
425 * bottom rings to their thick cylinders, and we need the one that faces the drill/counterbore.
426 */
428{
429 if( !m_boardAdapter.GetBoard() )
430 return;
431
432 const BOARD_STACKUP& stackup = m_boardAdapter.GetBoard()->GetStackupOrDefault();
433 LSEQ cuStack = m_boardAdapter.GetBoard()->GetEnabledLayers().CuStack();
434
435 const float unitScale = (float) m_boardAdapter.BiuTo3dUnits();
436 const float platingThickness = (float) m_boardAdapter.GetHolePlatingThickness();
437
438 // We use the same unit z range as the board (0 to 1) and apply scaling when rendering
439 const float boardZTop = 1.0f; // Top of board body
440 const float boardZBot = 0.0f; // Bottom of board body
441
442 // Helper to convert layer Z position to normalized 0-1 range
443 auto normalizeZ =
444 [&]( float absZ ) -> float
445 {
446 float boardTop = m_boardAdapter.GetLayerTopZPos( F_Cu );
447 float boardBot = m_boardAdapter.GetLayerBottomZPos( B_Cu );
448 float boardThick = boardTop - boardBot;
449
450 if( boardThick <= 0 )
451 return 0.5f;
452
453 // Map absolute Z to 0-1 range where 0 = B_Cu and 1 = F_Cu
454 return ( absZ - boardBot ) / boardThick;
455 };
456
457 // We'll accumulate all plug geometry into a single triangle list
458 std::shared_ptr<TRIANGLE_DISPLAY_LIST> plugTriangles = std::make_shared<TRIANGLE_DISPLAY_LIST>( 1024 );
459
460 auto generatePlug =
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 )
463 {
464 // If we have an angle on both ends we need two plugs.
465 if( topAngle != ANGLE_0 && botAngle != ANGLE_0 )
466 {
467 float middle = ( plugZTop + plugZBot ) / 2.0f;
468 generateInvCone( center, holeOuterR, plugR, normalizeZ( plugZTop ), normalizeZ( middle ),
469 nrSegments, plugTriangles, topAngle, true );
470 generateInvCone( center, holeOuterR, plugR, normalizeZ( middle ), normalizeZ( plugZBot ),
471 nrSegments, plugTriangles, botAngle, false );
472 }
473 else if( topAngle != ANGLE_0 )
474 {
475 generateInvCone( center, holeOuterR, plugR, normalizeZ( plugZTop ), normalizeZ( plugZBot ),
476 nrSegments, plugTriangles, topAngle, true );
477 }
478 else if( botAngle != ANGLE_0 )
479 {
480 generateInvCone( center, holeOuterR, plugR, normalizeZ( plugZTop ), normalizeZ( plugZBot ),
481 nrSegments, plugTriangles, botAngle, false );
482 }
483 else
484 {
485 generateCylinder( center, holeOuterR, plugR, normalizeZ( plugZTop ), normalizeZ( plugZBot ),
486 nrSegments, plugTriangles );
487 }
488 };
489
490 // Process vias for backdrill / post-machining plugs
491 for( const PCB_TRACK* track : m_boardAdapter.GetBoard()->Tracks() )
492 {
493 if( track->Type() != PCB_VIA_T )
494 continue;
495
496 const PCB_VIA* via = static_cast<const PCB_VIA*>( track );
497
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() );
502
503 PCB_LAYER_ID topLayer, bottomLayer;
504 via->LayerPair( &topLayer, &bottomLayer );
505
506 float viaZTop, viaZBot, plugZTop, plugZBot;
507 getLayerZPos( topLayer, viaZTop, plugZTop );
508 getLayerZPos( bottomLayer, plugZBot, viaZBot );
509
510 EDA_ANGLE topAngle = ANGLE_0;
511 EDA_ANGLE botAngle = ANGLE_0;
512 float plugR = holeOuterR; // max backdrill/post-machine radius
513
514 // Handle backdrills
515 for( const PADSTACK::DRILL_PROPS& backdrill : { via->Padstack().SecondaryDrill(),
516 via->Padstack().TertiaryDrill() } )
517 {
518 if( backdrill.start == F_Cu && backdrill.size.x > 0 )
519 {
520 int depthIU = stackup.GetLayerDistance( backdrill.start, backdrill.end );
521 PCB_LAYER_ID mustNotCut = FabBackdrillMustNotCut( cuStack, backdrill.start, backdrill.end );
522
523 if( mustNotCut != UNDEFINED_LAYER )
524 depthIU += stackup.GetLayerDistance( backdrill.end, mustNotCut ) / 2;
525
526 float depth = (float) depthIU * unitScale;
527 float drillRadius = (float) backdrill.size.x * 0.5f * unitScale;
528
529 // Plug is "re-filling" the non-drilled part, so it goes from the bottom of the drill
530 // *into* the board.
531 plugZTop = std::min( plugZTop, viaZTop - depth );
532 plugR = std::max( plugR, drillRadius );
533 }
534 else if( backdrill.end == B_Cu && backdrill.size.x > 0 )
535 {
536 int depthIU = stackup.GetLayerDistance( backdrill.end, backdrill.start );
537 PCB_LAYER_ID mustNotCut = FabBackdrillMustNotCut( cuStack, backdrill.start, backdrill.end );
538
539 if( mustNotCut != UNDEFINED_LAYER )
540 depthIU += stackup.GetLayerDistance( mustNotCut, backdrill.end ) / 2;
541
542 float depth = (float) depthIU * unitScale;
543 float drillRadius = (float) backdrill.size.x * 0.5f * unitScale;
544
545 // Plug is "re-filling" the non-drilled part, so it goes from the top of the drill
546 // *into* the board.
547 plugZBot = std::max( plugZBot, viaZBot + depth );
548 plugR = std::max( plugR, drillRadius );
549 }
550 }
551
552 // Handle front post-machining
553 if( via->GetFrontPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERBORE
554 || via->GetFrontPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK )
555 {
556 const float postMachiningR = (float) via->GetFrontPostMachiningSize() * 0.5f * unitScale;
557 const float postMachiningDepth = (float) via->GetFrontPostMachiningDepth() * unitScale;
558
559 if( postMachiningR > holeOuterR && postMachiningDepth > 0 )
560 {
561 // Plug is "re-filling" the non-machined part, so it goes from bottom of the
562 // post-machining *into* the board.
563 plugZTop = std::min( plugZTop, viaZTop - postMachiningDepth );
564 plugR = std::max( plugR, postMachiningR );
565
566 if( via->GetFrontPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK )
567 topAngle = EDA_ANGLE( via->GetFrontPostMachiningAngle(), TENTHS_OF_A_DEGREE_T );
568 }
569 }
570
571 // Handle back post-machining
572 if( via->GetBackPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERBORE
573 || via->GetBackPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK )
574 {
575 const float postMachiningR = (float) via->GetBackPostMachiningSize() * 0.5f * unitScale;
576 const float postMachiningDepth = (float) via->GetBackPostMachiningDepth() * unitScale;
577
578 if( postMachiningR > holeOuterR && postMachiningDepth > 0 )
579 {
580 // Plug is "re-filling" the non-machined part, so it goes from the top of the
581 // post-machining *into* the board.
582 plugZBot = std::max( plugZBot, viaZBot + postMachiningDepth );
583 plugR = std::max( plugR, postMachiningR );
584
585 if( via->GetBackPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK )
586 botAngle = EDA_ANGLE( via->GetBackPostMachiningAngle(), TENTHS_OF_A_DEGREE_T );
587 }
588 }
589
590 generatePlug( center, holeOuterR, plugR, nrSegments, plugZTop, plugZBot, topAngle, botAngle );
591 }
592
593 // Process pads for backdrill / post-machining plugs
594 for( const FOOTPRINT* footprint : m_boardAdapter.GetBoard()->Footprints() )
595 {
596 for( const PAD* pad : footprint->Pads() )
597 {
598 if( !pad->HasHole() )
599 continue;
600
601 if( pad->GetDrillShape() != PAD_DRILL_SHAPE::CIRCLE )
602 continue;
603
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 );
609
610 float padZTop, padZBot, plugZTop, plugZBot;
611 getLayerZPos( F_Cu, padZTop, plugZTop );
612 getLayerZPos( B_Cu, plugZBot, padZBot );
613
614 EDA_ANGLE topAngle = ANGLE_0;
615 EDA_ANGLE botAngle = ANGLE_0;
616 float plugR = holeOuterR; // max backdrill/post-machine radius
617
618 // Handle backdrills
619 for( const PADSTACK::DRILL_PROPS& backdrill : { pad->Padstack().SecondaryDrill(),
620 pad->Padstack().TertiaryDrill() } )
621 {
622 if( backdrill.start == F_Cu && backdrill.size.x > 0 )
623 {
624 int depthIU = stackup.GetLayerDistance( backdrill.start, backdrill.end );
625 PCB_LAYER_ID mustNotCut = FabBackdrillMustNotCut( cuStack, backdrill.start, backdrill.end );
626
627 if( mustNotCut != UNDEFINED_LAYER )
628 depthIU += stackup.GetLayerDistance( backdrill.end, mustNotCut ) / 2;
629
630 float depth = (float) depthIU * unitScale;
631 float drillRadius = (float) backdrill.size.x * 0.5f * unitScale;
632
633 // Plug is "re-filling" the non-drilled part, so it goes from the bottom of the drill
634 // *into* the board.
635 plugZTop = std::min( plugZTop, padZTop - depth );
636 plugR = std::max( plugR, drillRadius );
637 }
638 else if( backdrill.end == B_Cu && backdrill.size.x > 0 )
639 {
640 int depthIU = stackup.GetLayerDistance( backdrill.end, backdrill.start );
641 PCB_LAYER_ID mustNotCut = FabBackdrillMustNotCut( cuStack, backdrill.start, backdrill.end );
642
643 if( mustNotCut != UNDEFINED_LAYER )
644 depthIU += stackup.GetLayerDistance( mustNotCut, backdrill.end ) / 2;
645
646 float depth = (float) depthIU * unitScale;
647 float drillRadius = (float) backdrill.size.x * 0.5f * unitScale;
648
649 // Plug is "re-filling" the non-drilled part, so it goes from the top of the drill
650 // *into* the board.
651 plugZBot = std::max( plugZBot, padZBot + depth );
652 plugR = std::max( plugR, drillRadius );
653 }
654 }
655
656 // Handle front post-machining
657 if( pad->GetFrontPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERBORE
658 || pad->GetFrontPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK )
659 {
660 const float postMachiningR = (float) pad->GetFrontPostMachiningSize() * 0.5f * unitScale;
661 const float postMachiningDepth = (float) pad->GetFrontPostMachiningDepth() * unitScale;
662
663 if( postMachiningR > holeOuterR && postMachiningDepth > 0 )
664 {
665 // Plug is "re-filling" the non-machined part, so it goes from bottom of the post-machining
666 // into the board.
667 plugZTop = std::min( plugZTop, padZTop - postMachiningDepth );
668 plugR = std::max( plugR, postMachiningR );
669
670 if( pad->GetFrontPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK )
671 topAngle = EDA_ANGLE( pad->GetFrontPostMachiningAngle(), TENTHS_OF_A_DEGREE_T );
672 }
673 }
674
675 // Handle back post-machining
676 if( pad->GetBackPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERBORE
677 || pad->GetBackPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK )
678 {
679 const float postMachiningR = (float) pad->GetBackPostMachiningSize() * 0.5f * unitScale;
680 const float postMachiningDepth = (float) pad->GetBackPostMachiningDepth() * unitScale;
681
682 if( postMachiningR > holeOuterR && postMachiningDepth > 0 )
683 {
684 // Plug is "re-filling" the non-machined part, so it goes from the top of the
685 // post-machining *into* the board.
686 plugZBot = std::max( plugZBot, padZBot + postMachiningDepth );
687 plugR = std::max( plugR, postMachiningR );
688
689 if( pad->GetBackPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK )
690 botAngle = EDA_ANGLE( pad->GetBackPostMachiningAngle(), TENTHS_OF_A_DEGREE_T );
691 }
692 }
693
694 generatePlug( padCenter, holeOuterR, plugR, nrSegments, plugZTop, plugZBot, topAngle, botAngle );
695 }
696 }
697
698 // If we have any plug geometry, create a render list for it
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 )
702 {
703 // Store the triangles for later cleanup
704 appendRenderTriangleList( plugTriangles );
705
706 // Create a render list for the plugs using the same Z range as the board
707 // This will be scaled and drawn alongside m_boardWithHoles in renderBoardBody()
708 assignRenderPtr( m_postMachinePlugs, std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( plugTriangles,
710 boardZBot, boardZTop ) );
711 }
712}
713
714
716{
717 if( !m_boardAdapter.GetBoard() )
718 return;
719
720 const float biuTo3d = m_boardAdapter.BiuTo3dUnits();
721
722 for( FOOTPRINT* fp : m_boardAdapter.GetBoard()->Footprints() )
723 {
724 if( !fp->HasBody() )
725 continue;
726
727 const EXTRUDED_3D_BODY* body = fp->GetBody()->GetExtruded();
728
729 if( !body->m_show || !m_boardAdapter.IsFootprintShown( fp ) )
730 continue;
731
732 SHAPE_POLY_SET outline;
733
734 if( !GetExtrusionOutline( fp, outline ) )
735 continue;
736
737 if( outline.OutlineCount() == 0 )
738 continue;
739
740 outline.Simplify();
741
742 VECTOR2I fpPos = fp->GetPosition();
743 ApplyExtrusionTransform( outline, body, fpPos );
744
745 bool isBack = fp->IsFlipped();
746 float boardSurfaceZ = m_boardAdapter.GetFootprintZPos( isBack );
747 float standoff3d = body->m_standoff * biuTo3d;
748 float bodyThickness = ( body->m_height - body->m_standoff ) * biuTo3d * body->m_scale.z;
749 float zOffset3d = pcbIUScale.mmToIU( body->m_offset.z ) * biuTo3d;
750
751 float zBot, zTop;
752
753 if( !isBack )
754 {
755 zBot = boardSurfaceZ + standoff3d + zOffset3d;
756 zTop = zBot + bodyThickness;
757 }
758 else
759 {
760 zTop = boardSurfaceZ - standoff3d - zOffset3d;
761 zBot = zTop - bodyThickness;
762 }
763
764 CONTAINER_2D triangleContainer;
765 ConvertPolygonToTriangles( outline, triangleContainer, biuTo3d, *fp );
766
767 if( triangleContainer.GetList().empty() )
768 continue;
769
770 auto triangles = std::make_shared<TRIANGLE_DISPLAY_LIST>( triangleContainer.GetList().size() );
771
772 for( const OBJECT_2D* obj : triangleContainer.GetList() )
773 {
774 const TRIANGLE_2D* tri = static_cast<const TRIANGLE_2D*>( obj );
775 addTopAndBottomTriangles( triangles, tri->GetP1(), tri->GetP2(), tri->GetP3(), zTop, zBot );
776 }
777
778 triangles->AddToMiddleContours( outline, zBot, zTop, biuTo3d, false );
779
780 auto renderList = std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( triangles, m_circleTexture, zTop, zBot );
781
782 appendRenderTriangleList( triangles );
783 assignRenderMap( m_extrudedBodyLists, fp, renderList );
784
785 // Create pin extrusions for pad holes
786 // The pins move with the body, so the Z offset shifts them whole
787 if( standoff3d > 0.0f )
788 {
789 SHAPE_POLY_SET pinPoly;
790 SHAPE_POLY_SET pegPoly;
791
792 if( GetExtrusionPinOutlines( fp, pinPoly, pegPoly ) )
793 {
794 float oppositeSurfaceZ = m_boardAdapter.GetFootprintZPos( !isBack );
795 float protrusion = 1.0f * pcbIUScale.IU_PER_MM * biuTo3d;
796 float pinZBot, pinZTop;
797
798 if( !isBack )
799 {
800 pinZBot = oppositeSurfaceZ - protrusion + zOffset3d;
801 pinZTop = boardSurfaceZ + standoff3d + zOffset3d;
802 }
803 else
804 {
805 pinZTop = oppositeSurfaceZ + protrusion - zOffset3d;
806 pinZBot = boardSurfaceZ - standoff3d - zOffset3d;
807 }
808
809 auto buildPinList =
810 [&]( SHAPE_POLY_SET& aPoly, auto& aDstMap )
811 {
812 if( aPoly.OutlineCount() == 0 )
813 return;
814
815 ApplyExtrusionTransform( aPoly, body, fpPos );
816
817 CONTAINER_2D pinTriangleContainer;
818 ConvertPolygonToTriangles( aPoly, pinTriangleContainer, biuTo3d, *fp );
819
820 if( pinTriangleContainer.GetList().empty() )
821 return;
822
823 auto pinTriangles = std::make_shared<TRIANGLE_DISPLAY_LIST>( pinTriangleContainer.GetList().size() );
824
825 for( const OBJECT_2D* obj : pinTriangleContainer.GetList() )
826 {
827 const TRIANGLE_2D* tri = static_cast<const TRIANGLE_2D*>( obj );
828 addTopAndBottomTriangles( pinTriangles, tri->GetP1(), tri->GetP2(), tri->GetP3(),
829 pinZTop, pinZBot );
830 }
831
832 pinTriangles->AddToMiddleContours( aPoly, pinZBot, pinZTop, biuTo3d, false );
833
834 auto pinRenderList = std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( pinTriangles,
836 pinZTop, pinZBot );
837
838 appendRenderTriangleList( pinTriangles );
839 assignRenderMap( aDstMap, fp, pinRenderList );
840 };
841
842 buildPinList( pinPoly, m_extrudedPadLists );
843 buildPinList( pegPoly, m_extrudedPegLists );
844 }
845 }
846 }
847}
848
849
851{
852 // Reset the rollover pointer, it would no longer be valid
853 m_currentRollOverItem = nullptr;
854
855 m_reloadRequested = false;
856
857 // Ensure previous reload worker is finished before freeing/rebuilding render data.
858 StopBgWorker();
859
860 // Drop hover BVH before layers are destroyed; LAYER_ITEM points into those OBJECT_2Ds.
861 if( m_canvas )
862 m_canvas->InvalidateRaytracingHitTesting();
863
864 freeAllLists();
865
866 if( !m_boardAdapter.m_IsPreviewer )
868
870
872
873 SFVEC3F camera_pos = m_boardAdapter.GetBoardCenter();
874 m_camera.SetBoardLookAtPos( camera_pos );
875
876 // Create basic Board without holes
877 assignRenderPtr( m_board, createBoard( m_boardAdapter.GetBoardPoly(), nullptr ) );
878
880}
881
882
884{
885 if( m_canvas )
886 wxQueueEvent( m_canvas, new wxCommandEvent( wxEVT_REFRESH_CUSTOM_COMMAND, ID_CUSTOM_EVENT_1 ) );
887}
888
889
890void RENDER_3D_OPENGL::bgWorker( std::stop_token aStop )
891{
892 int64_t stats_startReloadTime = GetRunningMicroSecs();
893
894 if( aStop.stop_requested() )
895 return;
896
897 // Ensure hover BVH is gone before destroyLayers() inside CreateLayers.
898 if( m_canvas )
899 m_canvas->InvalidateRaytracingHitTesting();
900
901 m_boardAdapter.CreateLayers( m_activityReporter, aStop );
902
903 if( aStop.stop_requested() )
904 return;
905
907
909 m_activityReporter->Report( _( "Load OpenGL: board" ) );
910
911 // Create Board with TH
912 assignRenderPtr( m_board, createBoard( m_boardAdapter.GetBoardPoly(), &m_boardAdapter.GetTH_IDs() ) );
913
914 if( aStop.stop_requested() )
915 return;
916
918
919 m_antiBoardPolys.RemoveAllContours();
920 m_antiBoardPolys.NewOutline();
921 m_antiBoardPolys.Append( VECTOR2I( -INT_MAX/2, -INT_MAX/2 ) );
922 m_antiBoardPolys.Append( VECTOR2I( INT_MAX/2, -INT_MAX/2 ) );
923 m_antiBoardPolys.Append( VECTOR2I( INT_MAX/2, INT_MAX/2 ) );
924 m_antiBoardPolys.Append( VECTOR2I( -INT_MAX/2, INT_MAX/2 ) );
925 m_antiBoardPolys.Outline( 0 ).SetClosed( true );
926
927 m_antiBoardPolys.BooleanSubtract( m_boardAdapter.GetBoardPoly() );
928
930
931 if( aStop.stop_requested() )
932 return;
933
934 SHAPE_POLY_SET board_poly_with_holes = m_boardAdapter.GetBoardPoly().CloneDropTriangulation();
935 board_poly_with_holes.BooleanSubtract( m_boardAdapter.GetTH_ODPolys() );
936 board_poly_with_holes.BooleanSubtract( m_boardAdapter.GetNPTH_ODPolys() );
937
938 // Also subtract counterbore, countersink, and backdrill polygons from the board
939 if( m_boardAdapter.GetFrontCounterborePolys().OutlineCount() > 0 )
940 board_poly_with_holes.BooleanSubtract( m_boardAdapter.GetFrontCounterborePolys() );
941
942 if( m_boardAdapter.GetBackCounterborePolys().OutlineCount() > 0 )
943 board_poly_with_holes.BooleanSubtract( m_boardAdapter.GetBackCounterborePolys() );
944
945 if( m_boardAdapter.GetFrontCountersinkPolys().OutlineCount() > 0 )
946 board_poly_with_holes.BooleanSubtract( m_boardAdapter.GetFrontCountersinkPolys() );
947
948 if( m_boardAdapter.GetBackCountersinkPolys().OutlineCount() > 0 )
949 board_poly_with_holes.BooleanSubtract( m_boardAdapter.GetBackCountersinkPolys() );
950
951 if( m_boardAdapter.GetFrontBackdrillPolys().OutlineCount() > 0 )
952 board_poly_with_holes.BooleanSubtract( m_boardAdapter.GetFrontBackdrillPolys() );
953
954 if( m_boardAdapter.GetBackBackdrillPolys().OutlineCount() > 0 )
955 board_poly_with_holes.BooleanSubtract( m_boardAdapter.GetBackBackdrillPolys() );
956
957 if( aStop.stop_requested() )
958 return;
959
960 assignRenderPtr( m_boardWithHoles, createBoard( board_poly_with_holes, &m_boardAdapter.GetTH_IDs() ) );
961
962 // Create plugs for backdrilled and post-machined areas
964
965 if( aStop.stop_requested() )
966 return;
967
969
970 // Create Through Holes and vias
972 m_activityReporter->Report( _( "Load OpenGL: holes and vias" ) );
973
974 SHAPE_POLY_SET outerPolyTHT = m_boardAdapter.GetTH_ODPolys().CloneDropTriangulation();
975
976 // Include NPTH polygons so their barrel walls are also generated
977 if( m_boardAdapter.GetNPTH_ODPolys().OutlineCount() > 0 )
978 outerPolyTHT.BooleanAdd( m_boardAdapter.GetNPTH_ODPolys() );
979
980 outerPolyTHT.BooleanIntersection( m_boardAdapter.GetBoardPoly() );
981
982 LIST_OBJECT2D frontODs = m_boardAdapter.GetTH_ODs().GetList();
983
984 for( OBJECT_2D* obj : m_boardAdapter.GetFrontCounterboreCutouts().GetList() )
985 frontODs.emplace_back( obj );
986
987 for( OBJECT_2D* obj : m_boardAdapter.GetFrontCountersinkCutouts().GetList() )
988 frontODs.emplace_back( obj );
989
990 assignRenderPtr( m_frontOuterThroughHoles, generateHoles( frontODs, outerPolyTHT, 1.0f, 0.0f, false,
991 &m_boardAdapter.GetTH_IDs() ) );
992
993 LIST_OBJECT2D backODs = m_boardAdapter.GetTH_ODs().GetList();
994
995 for( OBJECT_2D* obj : m_boardAdapter.GetBackCounterboreCutouts().GetList() )
996 backODs.emplace_back( obj );
997
998 for( OBJECT_2D* obj : m_boardAdapter.GetBackCountersinkCutouts().GetList() )
999 backODs.emplace_back( obj );
1000
1001 assignRenderPtr( m_backOuterThroughHoles, generateHoles( backODs, outerPolyTHT, 1.0f, 0.0f, false,
1002 &m_boardAdapter.GetTH_IDs() ) );
1003
1004 if( m_boardAdapter.m_Cfg->m_Render.clip_silk_on_via_annuli )
1005 {
1007 m_boardAdapter.GetViaAnnuliPolys(), 1.0f, 0.0f,
1008 false ) );
1009 }
1010
1011 const MAP_POLY& innerMapHoles = m_boardAdapter.GetHoleIdPolysMap();
1012 const MAP_POLY& outerMapHoles = m_boardAdapter.GetHoleOdPolysMap();
1013
1014 wxASSERT( innerMapHoles.size() == outerMapHoles.size() );
1015
1016 const MAP_CONTAINER_2D_BASE& map_holes = m_boardAdapter.GetLayerHoleMap();
1017
1018 if( outerMapHoles.size() > 0 )
1019 {
1020 float layer_z_bot = 0.0f;
1021 float layer_z_top = 0.0f;
1022
1023 for( const auto& [ layer, poly ] : outerMapHoles )
1024 {
1025 getLayerZPos( layer, layer_z_top, layer_z_bot );
1026
1027 assignRenderMap( m_outerLayerHoles, layer, generateHoles( map_holes.at( layer )->GetList(), *poly,
1028 layer_z_top, layer_z_bot, false ) );
1029 }
1030
1031 for( const auto& [ layer, poly ] : innerMapHoles )
1032 {
1033 getLayerZPos( layer, layer_z_top, layer_z_bot );
1034
1035 assignRenderMap( m_innerLayerHoles, layer, generateHoles( map_holes.at( layer )->GetList(), *poly,
1036 layer_z_top, layer_z_bot, false ) );
1037 }
1038 }
1039
1040 // Generate vertical cylinders of vias and pads (copper)
1042
1043 if( aStop.stop_requested() )
1044 return;
1045
1047
1048 // Add layers maps
1049 if( m_activityReporter )
1050 m_activityReporter->Report( _( "Load OpenGL: layers" ) );
1051
1052 std::bitset<LAYER_3D_END> visibilityFlags = m_boardAdapter.GetVisibleLayers();
1053 const MAP_POLY& map_poly = m_boardAdapter.GetPolyMap();
1054 wxString msg;
1055
1056 for( const auto& [ layer, container2d ] : m_boardAdapter.GetLayerMap() )
1057 {
1058 if( !m_boardAdapter.Is3dLayerEnabled( layer, visibilityFlags ) )
1059 continue;
1060
1061 if( m_activityReporter )
1062 {
1063 msg = m_boardAdapter.GetBoard()->GetLayerName( layer );
1064 m_activityReporter->Report( wxString::Format( _( "Load OpenGL layer %s" ), msg ) );
1065 }
1066
1067 SHAPE_POLY_SET polyListSubtracted;
1068 SHAPE_POLY_SET* polyList = nullptr;
1069
1070 // Load the vertical (Z axis) component of shapes
1071
1072 if( m_boardAdapter.m_Cfg->m_Render.opengl_copper_thickness )
1073 {
1074 if( map_poly.contains( layer ) )
1075 {
1076 polyListSubtracted = *map_poly.at( layer );
1077
1078 if( LSET::PhysicalLayersMask().test( layer ) )
1079 {
1080 polyListSubtracted.BooleanIntersection( m_boardAdapter.GetBoardPoly() );
1081 }
1082
1083 if( layer != B_Mask && layer != F_Mask )
1084 {
1085 polyListSubtracted.BooleanSubtract( m_boardAdapter.GetTH_ODPolys() );
1086 polyListSubtracted.BooleanSubtract( m_boardAdapter.GetNPTH_ODPolys() );
1087
1088 // Subtract counterbore/countersink cutouts from copper layers
1089 if( layer == F_Cu )
1090 {
1091 polyListSubtracted.BooleanSubtract( m_boardAdapter.GetFrontCounterborePolys() );
1092 polyListSubtracted.BooleanSubtract( m_boardAdapter.GetFrontCountersinkPolys() );
1093 }
1094 else if( layer == B_Cu )
1095 {
1096 polyListSubtracted.BooleanSubtract( m_boardAdapter.GetBackCounterborePolys() );
1097 polyListSubtracted.BooleanSubtract( m_boardAdapter.GetBackCountersinkPolys() );
1098 }
1099 }
1100
1101 if( m_boardAdapter.m_Cfg->m_Render.subtract_mask_from_silk )
1102 {
1103 if( layer == B_SilkS && map_poly.contains( B_Mask ) )
1104 {
1105 polyListSubtracted.BooleanSubtract( *map_poly.at( B_Mask ) );
1106 }
1107 else if( layer == F_SilkS && map_poly.contains( F_Mask ) )
1108 {
1109 polyListSubtracted.BooleanSubtract( *map_poly.at( F_Mask ) );
1110 }
1111 }
1112
1113 polyList = &polyListSubtracted;
1114 }
1115 }
1116
1117 if( aStop.stop_requested() )
1118 return;
1119
1120 std::shared_ptr<OPENGL_RENDER_LIST_DEFERRED> oglList =
1121 generateLayerList( container2d, polyList, layer, &m_boardAdapter.GetTH_IDs() );
1122
1123 if( oglList != nullptr )
1124 assignRenderMap( m_layers, layer, oglList );
1125
1126 if( aStop.stop_requested() )
1127 return;
1128
1130 }
1131
1132 if( m_boardAdapter.m_Cfg->m_Render.DifferentiatePlatedCopper() )
1133 {
1134 const SHAPE_POLY_SET* frontPlatedCopperPolys = m_boardAdapter.GetFrontPlatedCopperPolys();
1135 const SHAPE_POLY_SET* backPlatedCopperPolys = m_boardAdapter.GetBackPlatedCopperPolys();
1136
1137 if( frontPlatedCopperPolys )
1138 {
1139 SHAPE_POLY_SET poly = frontPlatedCopperPolys->CloneDropTriangulation();
1140 poly.BooleanIntersection( m_boardAdapter.GetBoardPoly() );
1141 poly.BooleanSubtract( m_boardAdapter.GetTH_ODPolys() );
1142 poly.BooleanSubtract( m_boardAdapter.GetNPTH_ODPolys() );
1143 poly.BooleanSubtract( m_boardAdapter.GetFrontCounterborePolys() );
1144 poly.BooleanSubtract( m_boardAdapter.GetFrontCountersinkPolys() );
1145 poly.BooleanSubtract( m_boardAdapter.GetFrontBackdrillPolys() );
1146
1147 assignRenderPtr( m_platedPadsFront, generateLayerList( m_boardAdapter.GetPlatedPadsFront(), &poly, F_Cu ) );
1148
1149 // An entry for F_Cu must exist in m_layers or we'll never look at m_platedPadsFront
1150 if( m_layers.count( F_Cu ) == 0 )
1152 }
1153
1154 if( backPlatedCopperPolys )
1155 {
1156 SHAPE_POLY_SET poly = backPlatedCopperPolys->CloneDropTriangulation();
1157 poly.BooleanIntersection( m_boardAdapter.GetBoardPoly() );
1158 poly.BooleanSubtract( m_boardAdapter.GetTH_ODPolys() );
1159 poly.BooleanSubtract( m_boardAdapter.GetNPTH_ODPolys() );
1160 poly.BooleanSubtract( m_boardAdapter.GetBackCounterborePolys() );
1161 poly.BooleanSubtract( m_boardAdapter.GetBackCountersinkPolys() );
1162 poly.BooleanSubtract( m_boardAdapter.GetBackBackdrillPolys() );
1163
1164 assignRenderPtr( m_platedPadsBack, generateLayerList( m_boardAdapter.GetPlatedPadsBack(), &poly, B_Cu ) );
1165
1166 // An entry for B_Cu must exist in m_layers or we'll never look at m_platedPadsBack
1167 if( m_layers.count( B_Cu ) == 0 )
1169 }
1170 }
1171
1172 if( m_boardAdapter.m_Cfg->m_Render.show_off_board_silk )
1173 {
1174 if( const BVH_CONTAINER_2D* padsFront = m_boardAdapter.GetOffboardPadsFront() )
1175 assignRenderPtr( m_offboardPadsFront, generateLayerList( padsFront, nullptr, F_Cu ) );
1176
1177 if( const BVH_CONTAINER_2D* padsBack = m_boardAdapter.GetOffboardPadsBack() )
1178 assignRenderPtr( m_offboardPadsBack, generateLayerList( padsBack, nullptr, B_Cu ) );
1179 }
1180
1181 if( aStop.stop_requested() )
1182 return;
1183
1185
1186 // Load 3D models
1187 if( m_activityReporter )
1188 m_activityReporter->Report( _( "Loading 3D models..." ) );
1189
1190 load3dModels( aStop );
1191
1193
1194 if( aStop.stop_requested() )
1195 return;
1196
1198
1199 // OpenGL draws the board on the GPU, but hover/picking still uses the auxiliary
1200 // raytracing renderer (IntersectBoardItem). That path keeps its own BVH
1201 // (m_accelerator), which is not updated by the OpenGL scene build above.
1202 // Rebuild it here on the same worker thread once board layers are ready.
1203 if( !aStop.stop_requested() && m_canvas )
1204 {
1205 m_hitTestDirty = true;
1206 runHitTestRebuild( aStop );
1207 }
1208
1209 if( aStop.stop_requested() )
1210 return;
1211
1212 if( m_activityReporter )
1213 {
1214 // Calculation time in seconds
1215 double calculation_time = (double)( GetRunningMicroSecs() - stats_startReloadTime) / 1e6;
1216
1217 m_activityReporter->Report( wxString::Format( _( "Load completed in %.3f s" ), calculation_time ) );
1218 }
1219}
1220
1221
1223{
1224 wxLogTrace( m_logTrace, wxT( "RENDER_3D_OPENGL::startBgWorker" ) );
1225
1226 // Claim the flag before the thread runs so a rebuild cannot displace the load.
1227 m_bgWorkerBusy = true;
1228
1229 m_bgWorkerThread = std::jthread(
1230 [this]( std::stop_token aStopToken )
1231 {
1232 // Avoid lag in main (UI) thread
1233 BS::this_thread::set_os_thread_priority( BS::os_thread_priority::below_normal );
1234
1235 bgWorker( aStopToken );
1236
1237 m_bgWorkerBusy = false;
1238 } );
1239}
1240
1241
1243{
1244 m_hitTestDirty = true;
1245
1246 // A running worker picks the request up before it releases the flag.
1247 if( m_bgWorkerBusy.exchange( true ) )
1248 return;
1249
1250 m_bgWorkerThread = std::jthread(
1251 [this]( std::stop_token aStop )
1252 {
1253 BS::this_thread::set_os_thread_priority( BS::os_thread_priority::below_normal );
1254
1255 runHitTestRebuild( aStop );
1256
1257 m_bgWorkerBusy = false;
1258 } );
1259}
1260
1261
1262void RENDER_3D_OPENGL::runHitTestRebuild( std::stop_token aStop )
1263{
1264 for( ;; )
1265 {
1266 while( m_hitTestDirty.exchange( false ) )
1267 {
1268 if( aStop.stop_requested() || !m_canvas )
1269 return;
1270
1271 m_canvas->ReloadRaytracingForHitTesting( aStop );
1272 }
1273
1274 m_bgWorkerBusy = false;
1275
1276 // Pick up a request that raced the release above.
1277 if( !m_hitTestDirty || m_bgWorkerBusy.exchange( true ) )
1278 return;
1279 }
1280}
1281
1282
1284{
1285 wxLogTrace( m_logTrace, wxT( "RENDER_3D_OPENGL::StopBgWorker" ) );
1286
1287 if( m_bgWorkerThread.joinable() )
1288 {
1289 if( m_activityReporter )
1290 m_activityReporter->Report( _( "Stopping background load..." ) );
1291
1292 m_bgWorkerThread.request_stop();
1293 m_bgWorkerThread.join();
1294 }
1295
1296 m_bgWorkerBusy = false;
1297}
1298
1299
1301{
1302 wxLogTrace( m_logTrace, wxT( "RENDER_3D_OPENGL::JoinBgWorker" ) );
1303
1304 if( m_bgWorkerThread.joinable() )
1305 m_bgWorkerThread.join();
1306}
1307
1308
1309void RENDER_3D_OPENGL::addTopAndBottomTriangles( std::shared_ptr<TRIANGLE_DISPLAY_LIST> aDst, const SFVEC2F& v0,
1310 const SFVEC2F& v1, const SFVEC2F& v2, float top, float bot )
1311{
1312 aDst->m_layer_bot_triangles->AddTriangle( SFVEC3F( v0.x, v0.y, bot ),
1313 SFVEC3F( v1.x, v1.y, bot ),
1314 SFVEC3F( v2.x, v2.y, bot ) );
1315
1316 aDst->m_layer_top_triangles->AddTriangle( SFVEC3F( v2.x, v2.y, top ),
1317 SFVEC3F( v1.x, v1.y, top ),
1318 SFVEC3F( v0.x, v0.y, top ) );
1319}
1320
1321
1322void RENDER_3D_OPENGL::getLayerZPos( PCB_LAYER_ID aLayer, float& aOutZtop, float& aOutZbot ) const
1323{
1324 aOutZbot = m_boardAdapter.GetLayerBottomZPos( aLayer );
1325 aOutZtop = m_boardAdapter.GetLayerTopZPos( aLayer );
1326
1327 if( aOutZtop < aOutZbot )
1328 std::swap( aOutZtop, aOutZbot );
1329}
1330
1331
1332void RENDER_3D_OPENGL::generateCylinder( const SFVEC2F& aCenter, float aInnerRadius, float aOuterRadius, float aZtop,
1333 float aZbot, unsigned int aNr_sides_per_circle,
1334 std::shared_ptr<TRIANGLE_DISPLAY_LIST> aDstLayer )
1335{
1336 std::vector< SFVEC2F > innerContour;
1337 std::vector< SFVEC2F > outerContour;
1338
1339 generateRing( aCenter, aInnerRadius, aOuterRadius, aNr_sides_per_circle, innerContour,
1340 outerContour, false );
1341
1342 for( unsigned int i = 0; i < ( innerContour.size() - 1 ); ++i )
1343 {
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];
1348
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 ) );
1353
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 ) );
1358 }
1359
1360 aDstLayer->AddToMiddleContours( outerContour, aZbot, aZtop, true );
1361 aDstLayer->AddToMiddleContours( innerContour, aZbot, aZtop, false );
1362}
1363
1364
1365void RENDER_3D_OPENGL::generateInvCone( const SFVEC2F& aCenter, float aInnerRadius, float aOuterRadius, float aZtop,
1366 float aZbot, unsigned int aNr_sides_per_circle,
1367 std::shared_ptr<TRIANGLE_DISPLAY_LIST> aDstLayer, EDA_ANGLE aAngle,
1368 bool aIsFront )
1369{
1370 // For a countersink cone:
1371 // - The outer contour goes from aZbot to aZtop (full height)
1372 // - The inner contour goes from aZbot to aZbot + innerHeight
1373 // - The top surface is conical, sloping from inner top to outer top
1374 // - aAngle is the half-angle of the cone (in decidegrees from the vertical)
1375
1376 // Calculate the inner contour height based on the cone angle
1377 // tan(angle) = (outerRadius - innerRadius) / innerHeight
1378 // innerHeight = (outerRadius - innerRadius) / tan(angle)
1379 float radialDiff = aOuterRadius - aInnerRadius;
1380 float angleRad = aAngle.AsRadians();
1381
1382 // Clamp angle to avoid division by zero or negative heights
1383 if( angleRad < 0.01f )
1384 angleRad = 0.01f;
1385
1386 float innerHeight = radialDiff / tanf( angleRad );
1387 float totalHeight = aZtop - aZbot;
1388
1389 // Clamp inner height to not exceed total height
1390 if( innerHeight > totalHeight )
1391 innerHeight = totalHeight;
1392
1393 float zInnerTop = aIsFront ? aZbot + innerHeight : aZtop;
1394 float zInnerBot = aIsFront ? aZbot : aZtop - innerHeight;
1395
1396 std::vector< SFVEC2F > innerContour;
1397 std::vector< SFVEC2F > outerContour;
1398
1399 generateRing( aCenter, aInnerRadius, aOuterRadius, aNr_sides_per_circle, innerContour, outerContour, false );
1400
1401 for( unsigned int i = 0; i < ( innerContour.size() - 1 ); ++i )
1402 {
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];
1407
1408 if( aIsFront )
1409 {
1410 // Conical top surface: from inner contour at zInnerTop to outer contour at aZtop
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 ) );
1415
1416 // Flat bottom surface
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 ) );
1421 }
1422 else
1423 {
1424 // Flat top surface
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 ) );
1429
1430 // Conical bottom surface: from inner contour at zInnerBot to outer contour at aZbot
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 ) );
1435 }
1436 }
1437
1438 // Outer contour wall goes full height
1439 aDstLayer->AddToMiddleContours( outerContour, aZbot, aZtop, true );
1440 // Inner contour wall only goes [zInnerBot,zInnerTop]
1441 aDstLayer->AddToMiddleContours( innerContour, zInnerBot, zInnerTop, false );
1442}
1443
1444
1445void RENDER_3D_OPENGL::generateDisk( const SFVEC2F& aCenter, float aRadius, float aZ, unsigned int aNr_sides_per_circle,
1446 std::shared_ptr<TRIANGLE_DISPLAY_LIST> aDstLayer, bool aTop )
1447{
1448 const float delta = 2.0f * glm::pi<float>() / (float) aNr_sides_per_circle;
1449
1450 for( unsigned int i = 0; i < aNr_sides_per_circle; ++i )
1451 {
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 );
1459
1460 if( aTop )
1461 aDstLayer->m_layer_top_triangles->AddTriangle( p1, p0, c );
1462 else
1463 aDstLayer->m_layer_bot_triangles->AddTriangle( p0, p1, c );
1464 }
1465}
1466
1467
1468void RENDER_3D_OPENGL::generateDimple( const SFVEC2F& aCenter, float aRadius, float aZ, float aDepth,
1469 unsigned int aNr_sides_per_circle,
1470 std::shared_ptr<TRIANGLE_DISPLAY_LIST> aDstLayer, bool aTop )
1471{
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 );
1474
1475 for( unsigned int i = 0; i < aNr_sides_per_circle; ++i )
1476 {
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 );
1483
1484 if( aTop )
1485 aDstLayer->m_layer_top_triangles->AddTriangle( p0, p1, c );
1486 else
1487 aDstLayer->m_layer_bot_triangles->AddTriangle( p1, p0, c );
1488 }
1489}
1490
1491
1492bool RENDER_3D_OPENGL::appendPostMachiningGeometry( std::shared_ptr<TRIANGLE_DISPLAY_LIST> aDstLayer,
1493 const SFVEC2F& aHoleCenter,
1495 int aSizeIU,
1496 int aDepthIU,
1497 const EDA_ANGLE& aAngle,
1498 float aHoleInnerRadius,
1499 float aZSurface,
1500 bool aIsFront,
1501 float aPlatingThickness3d,
1502 float aUnitScale,
1503 float* aZEnd )
1504{
1505 if( !m_boardAdapter.m_Cfg->m_Render.show_plated_barrels )
1506 return false;
1507
1508 if( !aDstLayer || aPlatingThickness3d <= 0.0f || aHoleInnerRadius <= 0.0f )
1509 return false;
1510
1513 {
1514 return false;
1515 }
1516
1517 if( aSizeIU <= 0 || aDepthIU <= 0 )
1518 return false;
1519
1520 const float radius = aSizeIU * 0.5f * aUnitScale;
1521 const float depth = aDepthIU * aUnitScale;
1522
1523 if( radius <= aHoleInnerRadius || depth <= 0.0f )
1524 return false;
1525
1526 float zEnd = aIsFront ? ( aZSurface - depth ) : ( aZSurface + depth );
1527
1528 if( aZEnd )
1529 *aZEnd = zEnd;
1530
1531 const float zTop = std::max( aZSurface, zEnd );
1532 const float zBot = std::min( aZSurface, zEnd );
1533
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 ) );
1536
1538 {
1539 generateInvCone( aHoleCenter, radius, radius + aPlatingThickness3d, zTop, zBot, nrSegments, aDstLayer,
1540 aAngle, aIsFront );
1541 }
1542 else
1543 {
1544 generateCylinder( aHoleCenter, radius, radius + aPlatingThickness3d, zTop, zBot, nrSegments, aDstLayer );
1545 }
1546
1547 return true;
1548}
1549
1550
1552{
1553 if( aItem->Type() == PCB_VIA_T )
1554 {
1555 const PCB_VIA* via = static_cast<const PCB_VIA*>( aItem );
1556 bool isBackdrilled = via->GetSecondaryDrillSize().has_value()
1557 && via->GetSecondaryDrillStartLayer() != UNDEFINED_LAYER;
1558 bool isTertiarydrilled = via->GetTertiaryDrillSize().has_value()
1559 && via->GetTertiaryDrillStartLayer() != UNDEFINED_LAYER;
1560 bool hasFrontPostMachining = via->GetFrontPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERBORE
1561 || via->GetFrontPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK;
1562 bool hasBackPostMachining = via->GetBackPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERBORE
1563 || via->GetBackPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK;
1564
1565 return via->GetViaType() == VIATYPE::THROUGH
1566 && !isBackdrilled
1567 && !isTertiarydrilled
1568 && !hasFrontPostMachining
1569 && !hasBackPostMachining;
1570 }
1571 else if( aItem->Type() == PCB_PAD_T )
1572 {
1573 const PAD* pad = static_cast<const PAD*>( aItem );
1574
1575 bool isBackdrilled = pad->GetSecondaryDrillSize().x > 0
1576 && pad->GetSecondaryDrillSize().y > 0
1577 && pad->GetSecondaryDrillStartLayer() != UNDEFINED_LAYER;
1578 bool isTertiarydrilled = pad->GetTertiaryDrillSize().x > 0
1579 && pad->GetTertiaryDrillSize().y > 0
1580 && pad->GetTertiaryDrillStartLayer() != UNDEFINED_LAYER;
1581 bool hasFrontPostMachining = pad->GetFrontPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERBORE
1582 || pad->GetFrontPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK;
1583 bool hasBackPostMachining = pad->GetBackPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERBORE
1584 || pad->GetBackPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK;
1585
1586 return pad->HasHole()
1587 && pad->GetAttribute() != PAD_ATTRIB::NPTH
1588 && !isBackdrilled
1589 && !isTertiarydrilled
1590 && !hasFrontPostMachining
1591 && !hasBackPostMachining;
1592 }
1593
1594 return false;
1595}
1596
1597
1598void RENDER_3D_OPENGL::generateComplexHoles( float aPlatingThickness3d, float aUnitScale )
1599{
1600 if( !m_boardAdapter.GetBoard() )
1601 return;
1602
1603 if( m_boardAdapter.GetHoleCount() <= 0 && m_boardAdapter.GetViaCount() <= 0 )
1604 return;
1605
1606 if( !m_boardAdapter.m_Cfg->m_Render.show_plated_barrels )
1607 return;
1608
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 );
1613
1614 const BOARD_STACKUP& stackup = m_boardAdapter.GetBoard()->GetStackupOrDefault();
1615 LSEQ cuStack = m_boardAdapter.GetBoard()->GetEnabledLayers().CuStack();
1616
1617 for( const PCB_TRACK* track : m_boardAdapter.GetBoard()->Tracks() )
1618 {
1619 if( track->Type() != PCB_VIA_T )
1620 continue;
1621
1622 const PCB_VIA* via = static_cast<const PCB_VIA*>( track );
1623
1624 if( isSimpleThroughHole( via ) )
1625 {
1626 // Simple through-hole vias have their barrels generated by generateSimplePlatedHoleShells()
1627 continue;
1628 }
1629
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;
1633
1634 float ztop = m_boardAdapter.GetLayerBottomZPos( F_Cu ) + m_boardAdapter.GetFrontCopperThickness() * 0.99f;
1635 float zbot = m_boardAdapter.GetLayerBottomZPos( B_Cu ) - m_boardAdapter.GetBackCopperThickness() * 0.99f;
1636
1637 float ztop_plated = ztop;
1638 float zbot_plated = zbot;
1639
1640 for( const PADSTACK::DRILL_PROPS& backdrill : { via->Padstack().SecondaryDrill(),
1641 via->Padstack().TertiaryDrill() } )
1642 {
1643 if( backdrill.start == F_Cu && backdrill.size.x > 0 )
1644 {
1645 int depthIU = stackup.GetLayerDistance( backdrill.start, backdrill.end );
1646 PCB_LAYER_ID mustNotCut = FabBackdrillMustNotCut( cuStack, backdrill.start, backdrill.end );
1647
1648 if( mustNotCut != UNDEFINED_LAYER )
1649 depthIU += stackup.GetLayerDistance( backdrill.end, mustNotCut ) / 2;
1650
1651 float zEnd = 0.0f;
1652
1654 backdrill.size.x, depthIU, EDA_ANGLE( 118.0, DEGREES_T ),
1655 holeInnerR, ztop, true, aPlatingThickness3d, aUnitScale,
1656 &zEnd ) )
1657 {
1658 ztop_plated = std::min( ztop_plated, zEnd );
1659 }
1660 }
1661 else if( backdrill.end == B_Cu && backdrill.size.x > 0 )
1662 {
1663 int depthIU = stackup.GetLayerDistance( backdrill.end, backdrill.start );
1664 PCB_LAYER_ID mustNotCut = FabBackdrillMustNotCut( cuStack, backdrill.start, backdrill.end );
1665
1666 if( mustNotCut != UNDEFINED_LAYER )
1667 depthIU += stackup.GetLayerDistance( mustNotCut, backdrill.end ) / 2;
1668
1669 float zEnd = 0.0f;
1670
1672 backdrill.size.x, depthIU, EDA_ANGLE( 118.0, DEGREES_T ),
1673 holeInnerR, zbot, false, aPlatingThickness3d, aUnitScale,
1674 &zEnd ) )
1675 {
1676 zbot_plated = std::max( zbot_plated, zEnd );
1677 }
1678 }
1679 }
1680
1681 if( via->GetFrontPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERBORE
1682 || via->GetFrontPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK )
1683 {
1684 float zEnd = 0.0f;
1685
1686 if( appendPostMachiningGeometry( triangles, via_center, via->GetFrontPostMachiningMode(),
1687 via->GetFrontPostMachiningSize(), via->GetFrontPostMachiningDepth(),
1688 EDA_ANGLE( via->GetFrontPostMachiningAngle(), TENTHS_OF_A_DEGREE_T ),
1689 holeInnerR, ztop, true, aPlatingThickness3d, aUnitScale, &zEnd ) )
1690 {
1691 ztop_plated = std::min( ztop_plated, zEnd );
1692 }
1693 }
1694
1695 if( via->GetBackPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERBORE
1696 || via->GetBackPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK )
1697 {
1698 float zEnd = 0.0f;
1699
1700 if( appendPostMachiningGeometry( triangles, via_center,via->GetBackPostMachiningMode(),
1701 via->GetBackPostMachiningSize(), via->GetBackPostMachiningDepth(),
1702 EDA_ANGLE( via->GetBackPostMachiningAngle(), TENTHS_OF_A_DEGREE_T ),
1703 holeInnerR, zbot, false, aPlatingThickness3d, aUnitScale, &zEnd ) )
1704 {
1705 zbot_plated = std::max( zbot_plated, zEnd );
1706 }
1707 }
1708
1709 generateCylinder( via_center, holeInnerR, holeInnerR + aPlatingThickness3d, ztop_plated, zbot_plated,
1710 nrSegments, triangles );
1711 }
1712
1713 float ztop = m_boardAdapter.GetLayerBottomZPos( F_Cu ) + m_boardAdapter.GetFrontCopperThickness() * 0.99f;
1714 float zbot = m_boardAdapter.GetLayerBottomZPos( B_Cu ) - m_boardAdapter.GetBackCopperThickness() * 0.99f;
1715
1716 float ztop_plated = ztop;
1717 float zbot_plated = zbot;
1718
1719 for( const FOOTPRINT* footprint : m_boardAdapter.GetBoard()->Footprints() )
1720 {
1721 for( const PAD* pad : footprint->Pads() )
1722 {
1723 if( pad->GetAttribute() == PAD_ATTRIB::NPTH )
1724 continue;
1725
1726 if( !pad->HasHole() || isSimpleThroughHole( pad ) )
1727 {
1728 // Simple through-hole pads have their barrels generated by generateSimplePlatedHoleShells()
1729 continue;
1730 }
1731 else if( pad->GetDrillShape() != PAD_DRILL_SHAPE::CIRCLE )
1732 {
1733 // Slot-holed pads have their slot plating generated by ???
1734 continue;
1735 }
1736
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;
1741
1742 if( pad->GetFrontPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERBORE
1743 || pad->GetFrontPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK )
1744 {
1745 float zEnd = 0.0f;
1746
1747 if( appendPostMachiningGeometry( triangles, padCenter, pad->GetFrontPostMachiningMode(),
1748 pad->GetFrontPostMachiningSize(), pad->GetFrontPostMachiningDepth(),
1749 EDA_ANGLE( pad->GetFrontPostMachiningAngle(), TENTHS_OF_A_DEGREE_T ),
1750 holeInnerR, ztop, true, aPlatingThickness3d, aUnitScale, &zEnd ) )
1751 {
1752 ztop_plated = std::min( ztop_plated, zEnd );
1753 }
1754 }
1755
1756 if( pad->GetBackPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERBORE
1757 || pad->GetBackPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK )
1758 {
1759 float zEnd = 0.0f;
1760
1761 if( appendPostMachiningGeometry( triangles, padCenter, pad->GetBackPostMachiningMode(),
1762 pad->GetBackPostMachiningSize(), pad->GetBackPostMachiningDepth(),
1763 EDA_ANGLE( pad->GetBackPostMachiningAngle(), TENTHS_OF_A_DEGREE_T ),
1764 holeInnerR, zbot, false, aPlatingThickness3d, aUnitScale, &zEnd ) )
1765 {
1766 zbot_plated = std::max( zbot_plated, zEnd );
1767 }
1768 }
1769
1770 generateCylinder( padCenter, holeInnerR, holeInnerR + aPlatingThickness3d, ztop_plated, zbot_plated,
1771 nrSegments, triangles );
1772 }
1773 }
1774
1775 assignRenderPtr( m_complexPlatedHoles, std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( triangles, 0, 0.0f, 0.0f ) );
1776}
1777
1778
1779/*
1780 * For simple through holes only. Anything that needs the hole plating shortened (backdrilling, post-machining,
1781 * micro-vias, etc.) must be handled by generateComplexHoles().
1782 */
1783void RENDER_3D_OPENGL::generateSimplePlatedHoleShells( int aPlatingThickness, float aUnitScale )
1784{
1785 if( !m_boardAdapter.GetBoard() )
1786 return;
1787
1788 if( m_boardAdapter.GetHoleCount() <= 0 && m_boardAdapter.GetViaCount() <= 0 )
1789 return;
1790
1791 SHAPE_POLY_SET tht_outer_holes_poly; // Stores the outer poly of the copper holes
1792 SHAPE_POLY_SET tht_inner_holes_poly; // Stores the inner poly of the copper holes
1793 // Same as ***_holes_poly but for vias that are capped
1794 SHAPE_POLY_SET capped_outer_vias_poly;
1795 SHAPE_POLY_SET capped_inner_vias_poly;
1796
1797 tht_outer_holes_poly.RemoveAllContours();
1798 tht_inner_holes_poly.RemoveAllContours();
1799 capped_outer_vias_poly.RemoveAllContours();
1800 capped_inner_vias_poly.RemoveAllContours();
1801
1802 for( const PCB_TRACK* track : m_boardAdapter.GetBoard()->Tracks() )
1803 {
1804 if( track->Type() != PCB_VIA_T )
1805 continue;
1806
1807 const PCB_VIA* via = static_cast<const PCB_VIA*>( track );
1808
1809 if( !isSimpleThroughHole( via ) )
1810 continue;
1811
1812 const bool capped = via->ResolveCappingMode() == CAPPING_MODE::CAPPED;
1813
1814 TransformCircleToPolygon( capped ? capped_outer_vias_poly : tht_outer_holes_poly, via->GetPosition(),
1815 via->GetDrill() / 2 + aPlatingThickness, via->GetMaxError(), ERROR_INSIDE );
1816
1817 TransformCircleToPolygon( capped ? capped_inner_vias_poly : tht_inner_holes_poly, via->GetPosition(),
1818 via->GetDrill() / 2, via->GetMaxError(), ERROR_INSIDE );
1819 }
1820
1821 for( const FOOTPRINT* footprint : m_boardAdapter.GetBoard()->Footprints() )
1822 {
1823 for( const PAD* pad : footprint->Pads() )
1824 {
1825 if( !isSimpleThroughHole( pad ) )
1826 continue;
1827
1828 pad->TransformHoleToPolygon( tht_outer_holes_poly, aPlatingThickness, pad->GetMaxError(), ERROR_INSIDE );
1829 pad->TransformHoleToPolygon( tht_inner_holes_poly, 0, pad->GetMaxError(), ERROR_INSIDE );
1830 }
1831 }
1832
1833 tht_outer_holes_poly.BooleanSubtract( tht_inner_holes_poly );
1834 tht_outer_holes_poly.BooleanSubtract( m_antiBoardPolys );
1835
1836 tht_outer_holes_poly.BooleanAdd( capped_outer_vias_poly );
1837 tht_inner_holes_poly.BooleanAdd( capped_inner_vias_poly );
1838
1839 CONTAINER_2D holesContainer;
1840
1841 ConvertPolygonToTriangles( tht_outer_holes_poly, holesContainer, aUnitScale, *m_boardAdapter.GetBoard() );
1842
1843 const LIST_OBJECT2D& holes2D = holesContainer.GetList();
1844
1845 if( holes2D.size() > 0 && m_boardAdapter.m_Cfg->m_Render.show_plated_barrels )
1846 {
1847 float layer_z_top, layer_z_bot, dummy;
1848
1849 getLayerZPos( F_Cu, layer_z_top, dummy );
1850 getLayerZPos( B_Cu, dummy, layer_z_bot );
1851
1852 auto triangles = std::make_shared<TRIANGLE_DISPLAY_LIST>( holes2D.size() );
1853
1854 for( const OBJECT_2D* itemOnLayer : holes2D )
1855 {
1856 const OBJECT_2D* object2d_A = itemOnLayer;
1857
1858 wxASSERT( object2d_A->GetObjectType() == OBJECT_2D_TYPE::TRIANGLE );
1859
1860 const TRIANGLE_2D* tri = static_cast<const TRIANGLE_2D*>( object2d_A );
1861
1862 const SFVEC2F& v1 = tri->GetP1();
1863 const SFVEC2F& v2 = tri->GetP2();
1864 const SFVEC2F& v3 = tri->GetP3();
1865
1866 addTopAndBottomTriangles( triangles, v1, v2, v3, layer_z_top, layer_z_bot );
1867 }
1868
1869 wxASSERT( tht_outer_holes_poly.OutlineCount() > 0 );
1870
1871 if( tht_outer_holes_poly.OutlineCount() > 0 )
1872 {
1873 triangles->AddToMiddleContours( tht_outer_holes_poly, layer_z_bot, layer_z_top, aUnitScale, false );
1874
1875 assignRenderPtr( m_padHoles, std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( triangles, m_circleTexture,
1876 0.0f, 0.0f ) );
1877 }
1878 }
1879}
1880
1881
1882void RENDER_3D_OPENGL::generateViaCovers( float aPlatingThickness3d, float aUnitScale )
1883{
1884 if( !m_boardAdapter.GetBoard() || m_boardAdapter.GetViaCount() <= 0 )
1885 return;
1886
1887 auto frontCover = std::make_shared<TRIANGLE_DISPLAY_LIST>( m_boardAdapter.GetViaCount() );
1888 auto backCover = std::make_shared<TRIANGLE_DISPLAY_LIST>( m_boardAdapter.GetViaCount() );
1889
1890 for( const PCB_TRACK* track : m_boardAdapter.GetBoard()->Tracks() )
1891 {
1892 if( track->Type() != PCB_VIA_T )
1893 continue;
1894
1895 const PCB_VIA* via = static_cast<const PCB_VIA*>( track );
1896
1897 const float holediameter = via->GetDrillValue() * aUnitScale;
1898 const float hole_radius = holediameter / 2.0f + 2.0f * aPlatingThickness3d;
1899 const SFVEC2F center( via->GetStart().x * aUnitScale,
1900 -via->GetStart().y * aUnitScale );
1901 unsigned int seg = m_boardAdapter.GetCircleSegmentCount( via->GetDrillValue() );
1902
1903 PCB_LAYER_ID top_layer, bottom_layer;
1904 via->LayerPair( &top_layer, &bottom_layer );
1905 float ztop, zbot, dummy;
1906 getLayerZPos( top_layer, ztop, dummy );
1907 getLayerZPos( bottom_layer, dummy, zbot );
1908
1909 bool frontCovering = via->ResolveFrontCoveringMode() == COVERING_MODE::COVERED
1910 || via->IsTented( F_Mask );
1911 bool backCovering = via->ResolveBackCoveringMode() == COVERING_MODE::COVERED
1912 || via->IsTented( B_Mask );
1913 bool frontPlugged = via->ResolveFrontPluggingMode() == PLUGGING_MODE::PLUGGED;
1914 bool backPlugged = via->ResolveBackPluggingMode() == PLUGGING_MODE::PLUGGED;
1915 bool filled = via->ResolveFillingMode() == FILLING_MODE::FILLED
1916 || via->ResolveCappingMode() == CAPPING_MODE::CAPPED;
1917
1918 bool hasFrontPostMachining = via->GetFrontPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERBORE
1919 || via->GetFrontPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK;
1920 bool hasBackPostMachining = via->GetBackPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERBORE
1921 || via->GetBackPostMachiningMode() == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK;
1922
1923 bool hasFrontBackdrill = via->GetSecondaryDrillStartLayer() == F_Cu
1924 || via->GetTertiaryDrillStartLayer() == F_Cu;
1925 bool hasBackBackdrill = via->GetSecondaryDrillStartLayer() == B_Cu
1926 || via->GetTertiaryDrillStartLayer() == B_Cu;
1927
1928 const float depth = hole_radius * 0.3f;
1929
1930 if( frontCovering && !hasFrontPostMachining && !hasFrontBackdrill )
1931 {
1932 if( filled || !frontPlugged )
1933 generateDisk( center, hole_radius, ztop, seg, frontCover, true );
1934 else
1935 generateDimple( center, hole_radius, ztop, depth, seg, frontCover, true );
1936 }
1937
1938 if( backCovering && !hasBackPostMachining && !hasBackBackdrill )
1939 {
1940 if( filled || !backPlugged )
1941 generateDisk( center, hole_radius, zbot, seg, backCover, false );
1942 else
1943 generateDimple( center, hole_radius, zbot, depth, seg, backCover, false );
1944 }
1945 }
1946
1947 if( frontCover->m_layer_top_triangles->GetVertexSize() > 0 )
1948 assignRenderPtr( m_viaFrontCover, std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( frontCover, 0, 0.0f, 0.0f ) );
1949
1950 if( backCover->m_layer_bot_triangles->GetVertexSize() > 0 )
1951 assignRenderPtr( m_viaBackCover, std::make_shared<OPENGL_RENDER_LIST_DEFERRED>( backCover, 0, 0.0f, 0.0f ) );
1952}
1953
1954
1956{
1957 if( !m_boardAdapter.GetBoard() )
1958 return;
1959
1960 const int platingThickness = m_boardAdapter.GetHolePlatingThickness();
1961 const float unitScale = m_boardAdapter.BiuTo3dUnits();
1962 const float platingThickness3d = platingThickness * unitScale;
1963
1964 generateComplexHoles( platingThickness3d, unitScale );
1965 generateSimplePlatedHoleShells( platingThickness, unitScale );
1966 generateViaCovers( platingThickness3d, unitScale );
1967}
1968
1969
1971{
1972 if( m_3dModelMap.size() > 0 )
1973 return;
1974
1975 load3dModels();
1976}
1977
1978
1979void RENDER_3D_OPENGL::load3dModels( std::stop_token aStop )
1980{
1981 if( !m_boardAdapter.GetBoard() )
1982 return;
1983
1984 // Building the 3D models late crashes on recent versions of macOS
1985 // Unclear the exact mechanism, but as a workaround, just build them
1986 // all the time. See https://gitlab.com/kicad/code/kicad/-/issues/17198
1987#ifndef __WXMAC__
1988 if( !m_boardAdapter.m_IsPreviewer
1989 && !m_boardAdapter.m_Cfg->m_Render.show_footprints_normal
1990 && !m_boardAdapter.m_Cfg->m_Render.show_footprints_insert
1991 && !m_boardAdapter.m_Cfg->m_Render.show_footprints_virtual )
1992 {
1993 return;
1994 }
1995#endif
1996
1997 S3D_CACHE* cacheMgr = m_boardAdapter.Get3dCacheManager();
1998
1999 // Go for all footprints
2000 for( const FOOTPRINT* footprint : m_boardAdapter.GetBoard()->Footprints() )
2001 {
2002 const wxString footprintBasePath = m_boardAdapter.GetFootprintLibraryPath( footprint );
2003
2004 for( const FP_3DMODEL& fp_model : footprint->Models() )
2005 {
2006 if( fp_model.m_Show && !fp_model.m_Filename.empty() )
2007 {
2008 if( m_activityReporter )
2009 {
2010 // Display the short filename of the 3D fp_model loaded:
2011 // (the full name is usually too long to be displayed)
2012 wxFileName fn( fp_model.m_Filename );
2013 m_activityReporter->Report( wxString::Format( _( "Loading %s..." ), fn.GetFullName() ) );
2014 }
2015
2016 // Check if the fp_model is not present in our cache map
2017 // (Not already loaded in memory)
2018 if( !m_3dModelMap.contains( fp_model.m_Filename ) )
2019 {
2020 // It is not present, try get it from cache
2021 std::vector<const EMBEDDED_FILES*> embeddedFilesStack;
2022 embeddedFilesStack.push_back( footprint->GetEmbeddedFiles() );
2023 embeddedFilesStack.push_back( m_boardAdapter.GetBoard()->GetEmbeddedFiles() );
2024
2025 const S3DMODEL* modelPtr = cacheMgr->GetModel( fp_model.m_Filename, footprintBasePath,
2026 std::move( embeddedFilesStack ) );
2027
2028 // only add it if the return is not NULL
2029 if( modelPtr )
2030 {
2031 MATERIAL_MODE materialMode = m_boardAdapter.m_Cfg->m_Render.material_mode;
2032 auto model = std::make_shared<MODEL_3D_DEFERRED>( *modelPtr, materialMode );
2033
2034 assignRenderMap( m_3dModelMap, fp_model.m_Filename, model );
2035 }
2036 }
2037 }
2038
2039 if( aStop.stop_requested() )
2040 return;
2041 }
2042
2044 }
2045}
MATERIAL_MODE
Render 3d model shape materials mode.
Definition 3d_enums.h:74
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.
@ ID_CUSTOM_EVENT_1
@ ERROR_INSIDE
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
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...
Definition board_item.h:99
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
double AsRadians() const
Definition eda_angle.h:119
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
VECTOR3D m_offset
Definition pcb_3d_body.h:52
const SFVEC2F & GetCenter() const
float GetRadius() const
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition lseq.h:47
static const LSET & PhysicalLayersMask()
Return a mask holding all layers which are physically realized.
Definition lset.cpp:693
static OBJECT_2D_STATS & Instance()
Definition object_2d.h:135
void ResetStats()
Definition object_2d.h:120
OBJECT_2D_TYPE GetObjectType() const
Definition object_2d.h:105
Definition pad.h:61
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)
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.
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 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
EDA_3D_CANVAS * m_canvas
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
Definition ring_2d.h:44
float GetInnerRadius() const
Definition ring_2d.h:43
const SFVEC2F & GetCenter() const
Definition ring_2d.h:42
const SFVEC2F & GetLeftEnd() const
const SFVEC2F & GetRightEnd() const
const SFVEC2F & GetLeftStar() const
const SFVEC2F & GetLeftDir() const
const SFVEC2F & GetEnd() const
float GetRadius() const
float GetRadiusSquared() const
const SFVEC2F & GetStart() const
const SFVEC2F & GetRightDir() const
const SFVEC2F & GetRightStar() const
Cache for storing the 3D shapes.
Definition 3d_cache.h:53
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...
Definition 3d_cache.cpp:588
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
Definition triangle_2d.h:40
const SFVEC2F & GetP3() const
Definition triangle_2d.h:41
const SFVEC2F & GetP1() const
Definition triangle_2d.h:39
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.
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:472
@ TENTHS_OF_A_DEGREE_T
Definition eda_angle.h:29
@ DEGREES_T
Definition eda_angle.h:30
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,...
Definition fab_drill.cpp:26
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:
Definition layer_ids.h:56
@ B_Mask
Definition layer_ids.h:94
@ B_Cu
Definition layer_ids.h:61
@ F_Mask
Definition layer_ids.h:93
@ F_SilkS
Definition layer_ids.h:96
@ UNDEFINED_LAYER
Definition layer_ids.h:57
@ B_SilkS
Definition layer_ids.h:97
@ F_Cu
Definition layer_ids.h:60
bool isSimpleThroughHole(const BOARD_ITEM *aItem)
PAD_DRILL_POST_MACHINING_MODE
Definition padstack.h:77
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
Definition padstack.h:104
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.
Definition padstack.h:277
Store the a model based on meshes and materials.
Definition c3dmodel.h:111
KIBIS top(path, &reporter)
KIBIS_MODEL * model
VECTOR3I v1(5, 5, 5)
VECTOR2I center
int radius
VECTOR2I end
VECTOR2I v2(1, 0)
VECTOR2I v3(-2, 1)
int delta
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)
Definition typeinfo.h:89
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition typeinfo.h:79
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
glm::vec2 SFVEC2F
Definition xv3d_types.h:38
glm::vec3 SFVEC3F
Definition xv3d_types.h:40