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