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, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include "render_3d_opengl.h"
27#include <board.h>
28#include <footprint.h>
29#include <layer_range.h>
30#include <pcb_track.h>
31#include "../../3d_math.h"
33#include <lset.h>
34#include <trigo.h>
35#include <project.h>
36#include <core/profile.h> // To use GetRunningMicroSecs or another profiling utility
38#include <eda_3d_viewer_frame.h>
39#include <project_pcb.h>
40
41
43 TRIANGLE_DISPLAY_LIST* aDstLayer, float aZtop,
44 float aZbot )
45{
46 const SFVEC2F& center = aCircle->GetCenter();
47 const float radius = aCircle->GetRadius() * 2.0f; // Double because the render triangle
48
49 // This is a small adjustment to the circle texture
50 const float texture_factor = ( 8.0f / (float) SIZE_OF_CIRCLE_TEXTURE ) + 1.0f;
51 const float f = ( sqrtf( 2.0f ) / 2.0f ) * radius * texture_factor;
52
53 // Top and Bot segments ends are just triangle semi-circles, so need to add it in duplicated.
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_top_segment_ends->AddTriangle( SFVEC3F( center.x - f, center.y, aZtop ),
59 SFVEC3F( center.x + f, center.y, aZtop ),
60 SFVEC3F( center.x, center.y + f, aZtop ) );
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 aDstLayer->m_layer_bot_segment_ends->AddTriangle( SFVEC3F( center.x + f, center.y, aZbot ),
67 SFVEC3F( center.x - f, center.y, aZbot ),
68 SFVEC3F( center.x, center.y + f, aZbot ) );
69}
70
71
73 TRIANGLE_DISPLAY_LIST* aDstLayer,
74 float aZtop, float aZbot )
75{
76 const SFVEC2F& v0 = aPoly->GetV0();
77 const SFVEC2F& v1 = aPoly->GetV1();
78 const SFVEC2F& v2 = aPoly->GetV2();
79 const SFVEC2F& v3 = aPoly->GetV3();
80
81 addTopAndBottomTriangles( aDstLayer, v0, v2, v1, aZtop, aZbot );
82 addTopAndBottomTriangles( aDstLayer, v2, v0, v3, aZtop, aZbot );
83}
84
85
86void RENDER_3D_OPENGL::generateRing( const SFVEC2F& aCenter, float aInnerRadius,
87 float aOuterRadius, unsigned int aNr_sides_per_circle,
88 std::vector< SFVEC2F >& aInnerContourResult,
89 std::vector< SFVEC2F >& aOuterContourResult,
90 bool aInvertOrder )
91{
92 aInnerContourResult.clear();
93 aInnerContourResult.reserve( aNr_sides_per_circle + 2 );
94
95 aOuterContourResult.clear();
96 aOuterContourResult.reserve( aNr_sides_per_circle + 2 );
97
98 const int delta = 3600 / aNr_sides_per_circle;
99
100 for( int ii = 0; ii < 3600; ii += delta )
101 {
102 float angle = (float)( aInvertOrder ? ( 3600 - ii ) : ii )
103 * 2.0f * glm::pi<float>() / 3600.0f;
104 const SFVEC2F rotatedDir = SFVEC2F( cos( angle ), sin( angle ) );
105
106 aInnerContourResult.emplace_back( aCenter.x + rotatedDir.x * aInnerRadius,
107 aCenter.y + rotatedDir.y * aInnerRadius );
108
109 aOuterContourResult.emplace_back( aCenter.x + rotatedDir.x * aOuterRadius,
110 aCenter.y + rotatedDir.y * aOuterRadius );
111 }
112
113 aInnerContourResult.push_back( aInnerContourResult[0] );
114 aOuterContourResult.push_back( aOuterContourResult[0] );
115
116 wxASSERT( aInnerContourResult.size() == aOuterContourResult.size() );
117}
118
119
121 float aZtop, float aZbot )
122{
123 const SFVEC2F& center = aRing->GetCenter();
124 const float inner = aRing->GetInnerRadius();
125 const float outer = aRing->GetOuterRadius();
126
127 std::vector< SFVEC2F > innerContour;
128 std::vector< SFVEC2F > outerContour;
129
130 generateRing( center, inner, outer, m_boardAdapter.GetCircleSegmentCount( outer * 2.0f ),
131 innerContour, outerContour, false );
132
133 // This will add the top and bot quads that will form the approximated ring
134 for( unsigned int i = 0; i < ( innerContour.size() - 1 ); ++i )
135 {
136 const SFVEC2F& vi0 = innerContour[i + 0];
137 const SFVEC2F& vi1 = innerContour[i + 1];
138 const SFVEC2F& vo0 = outerContour[i + 0];
139 const SFVEC2F& vo1 = outerContour[i + 1];
140
141 aDstLayer->m_layer_top_triangles->AddQuad( SFVEC3F( vi1.x, vi1.y, aZtop ),
142 SFVEC3F( vi0.x, vi0.y, aZtop ),
143 SFVEC3F( vo0.x, vo0.y, aZtop ),
144 SFVEC3F( vo1.x, vo1.y, aZtop ) );
145
146 aDstLayer->m_layer_bot_triangles->AddQuad( SFVEC3F( vi1.x, vi1.y, aZbot ),
147 SFVEC3F( vo1.x, vo1.y, aZbot ),
148 SFVEC3F( vo0.x, vo0.y, aZbot ),
149 SFVEC3F( vi0.x, vi0.y, aZbot ) );
150 }
151}
152
153
155 float aZtop, float aZbot )
156{
157 const SFVEC2F& v1 = aTri->GetP1();
158 const SFVEC2F& v2 = aTri->GetP2();
159 const SFVEC2F& v3 = aTri->GetP3();
160
161 addTopAndBottomTriangles( aDstLayer, v1, v2, v3, aZtop, aZbot );
162}
163
164
166 TRIANGLE_DISPLAY_LIST* aDstLayer,
167 float aZtop, float aZbot )
168{
169 const SFVEC2F& leftStart = aSeg->GetLeftStar();
170 const SFVEC2F& leftEnd = aSeg->GetLeftEnd();
171 const SFVEC2F& leftDir = aSeg->GetLeftDir();
172
173 const SFVEC2F& rightStart = aSeg->GetRightStar();
174 const SFVEC2F& rightEnd = aSeg->GetRightEnd();
175 const SFVEC2F& rightDir = aSeg->GetRightDir();
176 const float radius = aSeg->GetRadius();
177
178 const SFVEC2F& start = aSeg->GetStart();
179 const SFVEC2F& end = aSeg->GetEnd();
180
181 const float texture_factor = ( 12.0f / (float) SIZE_OF_CIRCLE_TEXTURE ) + 1.0f;
182 const float texture_factorF = ( 6.0f / (float) SIZE_OF_CIRCLE_TEXTURE ) + 1.0f;
183
184 const float radius_of_the_square = sqrtf( aSeg->GetRadiusSquared() * 2.0f );
185 const float radius_triangle_factor = ( radius_of_the_square - radius ) / radius;
186
187 const SFVEC2F factorS = SFVEC2F( -rightDir.y * radius * radius_triangle_factor,
188 rightDir.x * radius * radius_triangle_factor );
189
190 const SFVEC2F factorE = SFVEC2F( -leftDir.y * radius * radius_triangle_factor,
191 leftDir.x * radius * radius_triangle_factor );
192
193 // Top end segment triangles (semi-circles)
195 SFVEC3F( rightEnd.x + texture_factor * factorS.x,
196 rightEnd.y + texture_factor * factorS.y,
197 aZtop ),
198 SFVEC3F( leftStart.x + texture_factor * factorE.x,
199 leftStart.y + texture_factor * factorE.y,
200 aZtop ),
201 SFVEC3F( start.x - texture_factorF * leftDir.x * radius * sqrtf( 2.0f ),
202 start.y - texture_factorF * leftDir.y * radius * sqrtf( 2.0f ),
203 aZtop ) );
204
206 SFVEC3F( leftEnd.x + texture_factor * factorE.x,
207 leftEnd.y + texture_factor * factorE.y, aZtop ),
208 SFVEC3F( rightStart.x + texture_factor * factorS.x,
209 rightStart.y + texture_factor * factorS.y, aZtop ),
210 SFVEC3F( end.x - texture_factorF * rightDir.x * radius * sqrtf( 2.0f ),
211 end.y - texture_factorF * rightDir.y * radius * sqrtf( 2.0f ),
212 aZtop ) );
213
214 // Bot end segment triangles (semi-circles)
216 SFVEC3F( leftStart.x + texture_factor * factorE.x,
217 leftStart.y + texture_factor * factorE.y,
218 aZbot ),
219 SFVEC3F( rightEnd.x + texture_factor * factorS.x,
220 rightEnd.y + texture_factor * factorS.y,
221 aZbot ),
222 SFVEC3F( start.x - texture_factorF * leftDir.x * radius * sqrtf( 2.0f ),
223 start.y - texture_factorF * leftDir.y * radius * sqrtf( 2.0f ),
224 aZbot ) );
225
227 SFVEC3F( rightStart.x + texture_factor * factorS.x,
228 rightStart.y + texture_factor * factorS.y, aZbot ),
229 SFVEC3F( leftEnd.x + texture_factor * factorE.x,
230 leftEnd.y + texture_factor * factorE.y, aZbot ),
231 SFVEC3F( end.x - texture_factorF * rightDir.x * radius * sqrtf( 2.0f ),
232 end.y - texture_factorF * rightDir.y * radius * sqrtf( 2.0f ),
233 aZbot ) );
234
235 // Segment top and bot planes
236 aDstLayer->m_layer_top_triangles->AddQuad(
237 SFVEC3F( rightEnd.x, rightEnd.y, aZtop ),
238 SFVEC3F( rightStart.x, rightStart.y, aZtop ),
239 SFVEC3F( leftEnd.x, leftEnd.y, aZtop ),
240 SFVEC3F( leftStart.x, leftStart.y, aZtop ) );
241
242 aDstLayer->m_layer_bot_triangles->AddQuad(
243 SFVEC3F( rightEnd.x, rightEnd.y, aZbot ),
244 SFVEC3F( leftStart.x, leftStart.y, aZbot ),
245 SFVEC3F( leftEnd.x, leftEnd.y, aZbot ),
246 SFVEC3F( rightStart.x, rightStart.y, aZbot ) );
247}
248
249
251 const SHAPE_POLY_SET& aPoly, float aZtop, float aZbot,
252 bool aInvertFaces, const BVH_CONTAINER_2D* aThroughHoles )
253{
254 if( aListHolesObject2d.size() == 0 )
255 return nullptr;
256
257 OPENGL_RENDER_LIST* ret = nullptr;
258 TRIANGLE_DISPLAY_LIST* layerTriangles = new TRIANGLE_DISPLAY_LIST( aListHolesObject2d.size() * 2 );
259
260 // Convert the list of objects(filled circles) to triangle layer structure
261 for( const OBJECT_2D* object2d : aListHolesObject2d )
262 {
263 switch( object2d->GetObjectType() )
264 {
266 addObjectTriangles( static_cast<const FILLED_CIRCLE_2D*>( object2d ), layerTriangles, aZtop, aZbot );
267 break;
268
270 addObjectTriangles( static_cast<const ROUND_SEGMENT_2D*>( object2d ), layerTriangles, aZtop, aZbot );
271 break;
272
273 default:
274 wxFAIL_MSG( wxT( "RENDER_3D_OPENGL::generateHoles: Object type not implemented" ) );
275 break;
276 }
277 }
278
279 // Note: he can have a aListHolesObject2d with holes but without contours
280 // eg: when there are only NPTH on the list and the contours were not added
281 if( aPoly.OutlineCount() > 0 )
282 {
283 layerTriangles->AddToMiddleContours( aPoly, aZbot, aZtop, m_boardAdapter.BiuTo3dUnits(), aInvertFaces,
284 aThroughHoles );
285 }
286
287 ret = new OPENGL_RENDER_LIST( *layerTriangles, m_circleTexture, aZbot, aZtop );
288
289 delete layerTriangles;
290
291 return ret;
292}
293
294
296 const SHAPE_POLY_SET* aPolyList, PCB_LAYER_ID aLayer,
297 const BVH_CONTAINER_2D* aThroughHoles )
298{
299 if( aContainer == nullptr )
300 return nullptr;
301
302 const LIST_OBJECT2D& listObject2d = aContainer->GetList();
303
304 if( listObject2d.size() == 0 )
305 return nullptr;
306
307 float zBot = 0.0f;
308 float zTop = 0.0f;
309
310 getLayerZPos( aLayer, zTop, zBot );
311
312 // Calculate an estimation for the nr of triangles based on the nr of objects
313 unsigned int nrTrianglesEstimation = listObject2d.size() * 8;
314
315 TRIANGLE_DISPLAY_LIST* layerTriangles = new TRIANGLE_DISPLAY_LIST( nrTrianglesEstimation );
316
317 // store in a list so it will be latter deleted
318 m_triangles.push_back( layerTriangles );
319
320 // Load the 2D (X,Y axis) component of shapes
321 for( const OBJECT_2D* object2d : listObject2d )
322 {
323 switch( object2d->GetObjectType() )
324 {
326 addObjectTriangles( static_cast<const FILLED_CIRCLE_2D*>( object2d ), layerTriangles, zTop, zBot );
327 break;
328
330 addObjectTriangles( static_cast<const POLYGON_4PT_2D*>( object2d ), layerTriangles, zTop, zBot );
331 break;
332
334 addObjectTriangles( static_cast<const RING_2D*>( object2d ), layerTriangles, zTop, zBot );
335 break;
336
338 addObjectTriangles( static_cast<const TRIANGLE_2D*>( object2d ), layerTriangles, zTop, zBot );
339 break;
340
342 addObjectTriangles( static_cast<const ROUND_SEGMENT_2D*>( object2d ), layerTriangles, zTop, zBot );
343 break;
344
345 default:
346 wxFAIL_MSG( wxT( "RENDER_3D_OPENGL: Object type is not implemented" ) );
347 break;
348 }
349 }
350
351 if( aPolyList && aPolyList->OutlineCount() > 0 )
352 {
353 layerTriangles->AddToMiddleContours( *aPolyList, zBot, zTop, m_boardAdapter.BiuTo3dUnits(), false,
354 aThroughHoles );
355 }
356
357 // Create display list
358 return new OPENGL_RENDER_LIST( *layerTriangles, m_circleTexture, zBot, zTop );
359}
360
361
363{
364 float layer_z_bot = 0.0f;
365 float layer_z_top = 0.0f;
366
367 getLayerZPos( aLayer, layer_z_top, layer_z_bot );
368
369 TRIANGLE_DISPLAY_LIST* layerTriangles = new TRIANGLE_DISPLAY_LIST( 1 );
370
371 // store in a list so it will be latter deleted
372 m_triangles.push_back( layerTriangles );
373
374 return new OPENGL_RENDER_LIST( *layerTriangles, m_circleTexture, layer_z_bot, layer_z_top );
375}
376
377
379 const BVH_CONTAINER_2D* aThroughHoles )
380{
381 OPENGL_RENDER_LIST* dispLists = nullptr;
382 CONTAINER_2D boardContainer;
383
384 ConvertPolygonToTriangles( aBoardPoly, boardContainer, m_boardAdapter.BiuTo3dUnits(),
385 (const BOARD_ITEM &)*m_boardAdapter.GetBoard() );
386
387 const LIST_OBJECT2D& listBoardObject2d = boardContainer.GetList();
388
389 if( listBoardObject2d.size() > 0 )
390 {
391 // We will set a unitary Z so it will in future used with transformations since the
392 // board poly will be used not only to draw itself but also the solder mask layers.
393 const float layer_z_top = 1.0f;
394 const float layer_z_bot = 0.0f;
395
396 TRIANGLE_DISPLAY_LIST* layerTriangles =
397 new TRIANGLE_DISPLAY_LIST( listBoardObject2d.size() );
398
399 // Convert the list of objects(triangles) to triangle layer structure
400 for( const OBJECT_2D* itemOnLayer : listBoardObject2d )
401 {
402 const OBJECT_2D* object2d_A = itemOnLayer;
403
404 wxASSERT( object2d_A->GetObjectType() == OBJECT_2D_TYPE::TRIANGLE );
405
406 const TRIANGLE_2D* tri = static_cast<const TRIANGLE_2D*>( object2d_A );
407
408 const SFVEC2F& v1 = tri->GetP1();
409 const SFVEC2F& v2 = tri->GetP2();
410 const SFVEC2F& v3 = tri->GetP3();
411
412 addTopAndBottomTriangles( layerTriangles, v1, v2, v3, layer_z_top, layer_z_bot );
413 }
414
415 if( aBoardPoly.OutlineCount() > 0 )
416 {
417 layerTriangles->AddToMiddleContours( aBoardPoly, layer_z_bot, layer_z_top,
418 m_boardAdapter.BiuTo3dUnits(), false,
419 aThroughHoles );
420
421 dispLists = new OPENGL_RENDER_LIST( *layerTriangles, m_circleTexture,
422 layer_z_top, layer_z_top );
423 }
424
425 delete layerTriangles;
426 }
427
428 return dispLists;
429}
430
431
433{
434 if( !m_boardAdapter.GetBoard() )
435 return;
436
437 const int copperLayerCount = m_boardAdapter.GetBoard()->GetCopperLayerCount();
438 const float unitScale = m_boardAdapter.BiuTo3dUnits();
439 const int platingThickness = m_boardAdapter.GetHolePlatingThickness();
440 const float boardBodyThickness = m_boardAdapter.GetBoardBodyThickness();
441
442 // We use the same unit z range as the board (0 to 1) and apply scaling when rendering
443 const float boardZTop = 1.0f; // Top of board body
444 const float boardZBot = 0.0f; // Bottom of board body
445
446 // Helper to convert layer Z position to normalized 0-1 range
447 auto normalizeZ = [&]( float absZ ) -> float
448 {
449 float boardTop = m_boardAdapter.GetLayerBottomZPos( F_Cu );
450 float boardBot = m_boardAdapter.GetLayerBottomZPos( B_Cu );
451 float boardThick = boardTop - boardBot;
452
453 if( boardThick <= 0 )
454 return 0.5f;
455
456 // Map absolute Z to 0-1 range where 0 = B_Cu and 1 = F_Cu
457 return ( absZ - boardBot ) / boardThick;
458 };
459
460 // We'll accumulate all plug geometry into a single triangle list
461 TRIANGLE_DISPLAY_LIST* plugTriangles = new TRIANGLE_DISPLAY_LIST( 1024 );
462
463 // Process vias for backdrill and post-machining plugs
464 for( const PCB_TRACK* track : m_boardAdapter.GetBoard()->Tracks() )
465 {
466 if( track->Type() != PCB_VIA_T )
467 continue;
468
469 const PCB_VIA* via = static_cast<const PCB_VIA*>( track );
470
471 const float holeDiameter = via->GetDrillValue() * unitScale;
472 const float holeInnerRadius = holeDiameter / 2.0f;
473 const float holeOuterRadius = holeInnerRadius + platingThickness * unitScale;
474 const SFVEC2F center( via->GetStart().x * unitScale, -via->GetStart().y * unitScale );
475 const int nrSegments = m_boardAdapter.GetCircleSegmentCount( via->GetDrillValue() );
476
477 PCB_LAYER_ID topLayer, bottomLayer;
478 via->LayerPair( &topLayer, &bottomLayer );
479
480 float viaZTop, viaZBot, dummy;
481 getLayerZPos( topLayer, viaZTop, dummy );
482 getLayerZPos( bottomLayer, dummy, viaZBot );
483
484 // Handle backdrill plugs
485 const float secondaryDrillRadius = via->GetSecondaryDrillSize().value_or( 0 ) * 0.5f * unitScale;
486 const float tertiaryDrillRadius = via->GetTertiaryDrillSize().value_or( 0 ) * 0.5f * unitScale;
487
488 if( secondaryDrillRadius > holeOuterRadius || tertiaryDrillRadius > holeOuterRadius )
489 {
490 PCB_LAYER_ID plug_start_layer = F_Cu;
491 PCB_LAYER_ID plug_end_layer = B_Cu;
492
493 // Case 1: secondary drill exists, so we need to adjust the plug_end_layer
494 if( secondaryDrillRadius > holeOuterRadius )
495 {
496 plug_end_layer = via->GetSecondaryDrillEndLayer();
497 }
498 // Case 2: tertiary drill exists, so we need to adjust the plug_start_layer
499 if( tertiaryDrillRadius > holeOuterRadius )
500 {
501 plug_start_layer = via->GetTertiaryDrillStartLayer();
502 }
503
504 // Calculate where the backdrill ends and plug should start
505 float plugZTop, plugZBot, temp;
506 getLayerZPos( plug_end_layer, temp, plugZBot );
507 getLayerZPos( plug_start_layer, plugZTop, temp );
508
509 // Create a ring from holeOuterRadius to backdrillRadius
510 generateCylinder( center, holeOuterRadius, std::max( secondaryDrillRadius, tertiaryDrillRadius ),
511 plugZTop, plugZBot, nrSegments, plugTriangles );
512 }
513
514 // Handle front post-machining plugs
515 const auto frontMode = via->GetFrontPostMachining();
516
517 if( frontMode.has_value()
519 && frontMode.value() != PAD_DRILL_POST_MACHINING_MODE::UNKNOWN )
520 {
521 const float frontRadius = via->GetFrontPostMachiningSize() * 0.5f * unitScale;
522 const float frontDepth = via->GetFrontPostMachiningDepth() * unitScale;
523
524 if( frontRadius > holeOuterRadius && frontDepth > 0 )
525 {
526 // Plug goes from bottom of post-machining to bottom of via
527 float pmBottomZ = normalizeZ( viaZTop - frontDepth );
528 float plugZBot = normalizeZ( viaZBot );
529
530 if( pmBottomZ > plugZBot )
531 {
532 if( frontMode.value() == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK )
533 {
534 EDA_ANGLE angle( via->GetFrontPostMachiningAngle(), TENTHS_OF_A_DEGREE_T );
535 generateInvCone( center, holeOuterRadius, frontRadius,
536 pmBottomZ, plugZBot, nrSegments, plugTriangles, angle );
537 }
538 else
539 {
540 generateCylinder( center, holeOuterRadius, frontRadius,
541 pmBottomZ, plugZBot, nrSegments, plugTriangles );
542 }
543 }
544 }
545 }
546
547 // Handle back post-machining plugs
548 const auto backMode = via->GetBackPostMachining();
549
550 if( backMode.has_value()
552 && backMode.value() != PAD_DRILL_POST_MACHINING_MODE::UNKNOWN )
553 {
554 const float backRadius = via->GetBackPostMachiningSize() * 0.5f * unitScale;
555 const float backDepth = via->GetBackPostMachiningDepth() * unitScale;
556
557 if( backRadius > holeOuterRadius && backDepth > 0 )
558 {
559 // Plug goes from top of via to top of post-machining
560 float plugZTop = normalizeZ( viaZTop );
561 float pmTopZ = normalizeZ( viaZBot + backDepth );
562
563 if( plugZTop > pmTopZ )
564 {
565 if( backMode.value() == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK )
566 {
567 EDA_ANGLE angle( via->GetBackPostMachiningAngle(), TENTHS_OF_A_DEGREE_T );
568 generateInvCone( center, holeOuterRadius, backRadius,
569 plugZTop, pmTopZ, nrSegments, plugTriangles, angle );
570 }
571 else
572 {
573 generateCylinder( center, holeOuterRadius, backRadius,
574 plugZTop, pmTopZ, nrSegments, plugTriangles );
575 }
576 }
577 }
578 }
579 }
580
581 // Process pads for post-machining plugs
582 for( const FOOTPRINT* footprint : m_boardAdapter.GetBoard()->Footprints() )
583 {
584 for( const PAD* pad : footprint->Pads() )
585 {
586 if( !pad->HasHole() )
587 continue;
588
589 if( pad->GetDrillShape() != PAD_DRILL_SHAPE::CIRCLE )
590 continue;
591
592 const SFVEC2F padCenter( pad->GetPosition().x * unitScale,
593 -pad->GetPosition().y * unitScale );
594 const float holeInnerRadius = pad->GetDrillSize().x * 0.5f * unitScale;
595 const float holeOuterRadius = holeInnerRadius + platingThickness * unitScale;
596 const int nrSegments = m_boardAdapter.GetCircleSegmentCount( pad->GetDrillSize().x );
597
598 float padZTop, padZBot, padDummy;
599 getLayerZPos( F_Cu, padZTop, padDummy );
600 getLayerZPos( B_Cu, padDummy, padZBot );
601
602 // Handle front post-machining plugs for pads
603 const auto frontMode = pad->GetFrontPostMachining();
604
605 if( frontMode.has_value()
607 && frontMode.value() != PAD_DRILL_POST_MACHINING_MODE::UNKNOWN )
608 {
609 const float frontRadius = pad->GetFrontPostMachiningSize() * 0.5f * unitScale;
610 const float frontDepth = pad->GetFrontPostMachiningDepth() * unitScale;
611
612 if( frontRadius > holeOuterRadius && frontDepth > 0 )
613 {
614 float pmBottomZ = normalizeZ( padZTop - frontDepth );
615 float plugZBot = normalizeZ( padZBot );
616
617 if( pmBottomZ > plugZBot )
618 {
619 if( frontMode.value() == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK )
620 {
621 EDA_ANGLE angle( pad->GetFrontPostMachiningAngle(), TENTHS_OF_A_DEGREE_T );
622 generateInvCone( padCenter, holeOuterRadius, frontRadius,
623 pmBottomZ, plugZBot, nrSegments, plugTriangles, angle );
624 }
625 else
626 {
627 generateCylinder( padCenter, holeOuterRadius, frontRadius,
628 pmBottomZ, plugZBot, nrSegments, plugTriangles );
629 }
630 }
631 }
632 }
633
634 // Handle back post-machining plugs for pads
635 const auto backMode = pad->GetBackPostMachining();
636
637 if( backMode.has_value()
639 && backMode.value() != PAD_DRILL_POST_MACHINING_MODE::UNKNOWN )
640 {
641 const float backRadius = pad->GetBackPostMachiningSize() * 0.5f * unitScale;
642 const float backDepth = pad->GetBackPostMachiningDepth() * unitScale;
643
644 if( backRadius > holeOuterRadius && backDepth > 0 )
645 {
646 float plugZTop = normalizeZ( padZTop );
647 float pmTopZ = normalizeZ( padZBot + backDepth );
648
649 if( plugZTop > pmTopZ )
650 {
651 if( backMode.value() == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK )
652 {
653 EDA_ANGLE angle( pad->GetBackPostMachiningAngle(), TENTHS_OF_A_DEGREE_T );
654 generateInvCone( padCenter, holeOuterRadius, backRadius,
655 plugZTop, pmTopZ, nrSegments, plugTriangles, angle );
656 }
657 else
658 {
659 generateCylinder( padCenter, holeOuterRadius, backRadius,
660 plugZTop, pmTopZ, nrSegments, plugTriangles );
661 }
662 }
663 }
664 }
665 }
666 }
667
668 // If we have any plug geometry, create a render list for it
669 if( plugTriangles->m_layer_top_triangles->GetVertexSize() > 0
670 || plugTriangles->m_layer_bot_triangles->GetVertexSize() > 0
671 || plugTriangles->m_layer_middle_contours_quads->GetVertexSize() > 0 )
672 {
673 // Store the triangles for later cleanup
674 m_triangles.push_back( plugTriangles );
675
676 // Create a render list for the plugs using the same Z range as the board
677 // This will be scaled and drawn alongside m_boardWithHoles in renderBoardBody()
679 boardZTop, boardZTop );
680 }
681 else
682 {
683 delete plugTriangles;
684 }
685}
686
687
688void RENDER_3D_OPENGL::reload( REPORTER* aStatusReporter, REPORTER* aWarningReporter )
689{
690 m_reloadRequested = false;
691
692 freeAllLists();
693
695
696 int64_t stats_startReloadTime = GetRunningMicroSecs();
697
698 m_boardAdapter.InitSettings( aStatusReporter, aWarningReporter );
699
700 SFVEC3F camera_pos = m_boardAdapter.GetBoardCenter();
701 m_camera.SetBoardLookAtPos( camera_pos );
702
703 if( aStatusReporter )
704 aStatusReporter->Report( _( "Load OpenGL: board" ) );
705
706 // Create Board
707 m_board = createBoard( m_boardAdapter.GetBoardPoly(), &m_boardAdapter.GetTH_IDs() );
708
709 m_antiBoardPolys.RemoveAllContours();
710 m_antiBoardPolys.NewOutline();
711 m_antiBoardPolys.Append( VECTOR2I( -INT_MAX/2, -INT_MAX/2 ) );
712 m_antiBoardPolys.Append( VECTOR2I( INT_MAX/2, -INT_MAX/2 ) );
713 m_antiBoardPolys.Append( VECTOR2I( INT_MAX/2, INT_MAX/2 ) );
714 m_antiBoardPolys.Append( VECTOR2I( -INT_MAX/2, INT_MAX/2 ) );
715 m_antiBoardPolys.Outline( 0 ).SetClosed( true );
716
717 m_antiBoardPolys.BooleanSubtract( m_boardAdapter.GetBoardPoly() );
719
720 SHAPE_POLY_SET board_poly_with_holes = m_boardAdapter.GetBoardPoly().CloneDropTriangulation();
721 board_poly_with_holes.BooleanSubtract( m_boardAdapter.GetTH_ODPolys() );
722
723 // Also subtract counterbore, countersink, and backdrill polygons from the board
724 if( m_boardAdapter.GetFrontCounterborePolys().OutlineCount() > 0 )
725 board_poly_with_holes.BooleanSubtract( m_boardAdapter.GetFrontCounterborePolys() );
726
727 if( m_boardAdapter.GetBackCounterborePolys().OutlineCount() > 0 )
728 board_poly_with_holes.BooleanSubtract( m_boardAdapter.GetBackCounterborePolys() );
729
730 if( m_boardAdapter.GetFrontCountersinkPolys().OutlineCount() > 0 )
731 board_poly_with_holes.BooleanSubtract( m_boardAdapter.GetFrontCountersinkPolys() );
732
733 if( m_boardAdapter.GetBackCountersinkPolys().OutlineCount() > 0 )
734 board_poly_with_holes.BooleanSubtract( m_boardAdapter.GetBackCountersinkPolys() );
735
736 if( m_boardAdapter.GetBackdrillPolys().OutlineCount() > 0 )
737 board_poly_with_holes.BooleanSubtract( m_boardAdapter.GetBackdrillPolys() );
738
739 if( m_boardAdapter.GetTertiarydrillPolys().OutlineCount() > 0 )
740 board_poly_with_holes.BooleanSubtract( m_boardAdapter.GetTertiarydrillPolys() );
741
742
743 m_boardWithHoles = createBoard( board_poly_with_holes, &m_boardAdapter.GetTH_IDs() );
744
745 // Create plugs for backdrilled and post-machined areas
747
748 if( m_antiBoard )
749 m_antiBoard->SetItIsTransparent( true );
750
751 // Create Through Holes and vias
752 if( aStatusReporter )
753 aStatusReporter->Report( _( "Load OpenGL: holes and vias" ) );
754
755 SHAPE_POLY_SET outerPolyTHT = m_boardAdapter.GetTH_ODPolys().CloneDropTriangulation();
756
757 outerPolyTHT.BooleanIntersection( m_boardAdapter.GetBoardPoly() );
758
759 m_outerThroughHoles = generateHoles( m_boardAdapter.GetTH_ODs().GetList(), outerPolyTHT,
760 1.0f, 0.0f, false, &m_boardAdapter.GetTH_IDs() );
761
762 m_outerViaThroughHoles = generateHoles( m_boardAdapter.GetViaTH_ODs().GetList(),
763 m_boardAdapter.GetViaTH_ODPolys(), 1.0f, 0.0f, false );
764
765 if( m_boardAdapter.m_Cfg->m_Render.clip_silk_on_via_annuli )
766 {
767 m_outerThroughHoleRings = generateHoles( m_boardAdapter.GetViaAnnuli().GetList(),
768 m_boardAdapter.GetViaAnnuliPolys(),
769 1.0f, 0.0f, false );
770 }
771
772 const MAP_POLY& innerMapHoles = m_boardAdapter.GetHoleIdPolysMap();
773 const MAP_POLY& outerMapHoles = m_boardAdapter.GetHoleOdPolysMap();
774
775 wxASSERT( innerMapHoles.size() == outerMapHoles.size() );
776
777 const MAP_CONTAINER_2D_BASE& map_holes = m_boardAdapter.GetLayerHoleMap();
778
779 if( outerMapHoles.size() > 0 )
780 {
781 float layer_z_bot = 0.0f;
782 float layer_z_top = 0.0f;
783
784 for( const auto& [ layer, poly ] : outerMapHoles )
785 {
786 getLayerZPos( layer, layer_z_top, layer_z_bot );
787
788 m_outerLayerHoles[layer] = generateHoles( map_holes.at( layer )->GetList(), *poly,
789 layer_z_top, layer_z_bot, false );
790 }
791
792 for( const auto& [ layer, poly ] : innerMapHoles )
793 {
794 getLayerZPos( layer, layer_z_top, layer_z_bot );
795
796 m_innerLayerHoles[layer] = generateHoles( map_holes.at( layer )->GetList(), *poly,
797 layer_z_top, layer_z_bot, false );
798 }
799 }
800
801 // Generate vertical cylinders of vias and pads (copper)
803
804 // Add layers maps
805 if( aStatusReporter )
806 aStatusReporter->Report( _( "Load OpenGL: layers" ) );
807
808 std::bitset<LAYER_3D_END> visibilityFlags = m_boardAdapter.GetVisibleLayers();
809 const MAP_POLY& map_poly = m_boardAdapter.GetPolyMap();
810 wxString msg;
811
812 for( const auto& [ layer, container2d ] : m_boardAdapter.GetLayerMap() )
813 {
814 if( !m_boardAdapter.Is3dLayerEnabled( layer, visibilityFlags ) )
815 continue;
816
817 if( aStatusReporter )
818 {
819 msg = m_boardAdapter.GetBoard()->GetLayerName( layer );
820 aStatusReporter->Report( wxString::Format( _( "Load OpenGL layer %s" ), msg ) );
821 }
822
823 SHAPE_POLY_SET polyListSubtracted;
824 SHAPE_POLY_SET* polyList = nullptr;
825
826 // Load the vertical (Z axis) component of shapes
827
828 if( m_boardAdapter.m_Cfg->m_Render.opengl_copper_thickness )
829 {
830 if( map_poly.contains( layer ) )
831 {
832 polyListSubtracted = *map_poly.at( layer );
833
834 if( LSET::PhysicalLayersMask().test( layer ) )
835 {
836 polyListSubtracted.BooleanIntersection( m_boardAdapter.GetBoardPoly() );
837 }
838
839 if( layer != B_Mask && layer != F_Mask )
840 {
841 polyListSubtracted.BooleanSubtract( m_boardAdapter.GetTH_ODPolys() );
842 polyListSubtracted.BooleanSubtract( m_boardAdapter.GetNPTH_ODPolys() );
843
844 // Subtract counterbore/countersink cutouts from copper layers
845 if( layer == F_Cu )
846 {
847 polyListSubtracted.BooleanSubtract( m_boardAdapter.GetFrontCounterborePolys() );
848 polyListSubtracted.BooleanSubtract( m_boardAdapter.GetFrontCountersinkPolys() );
849 }
850 else if( layer == B_Cu )
851 {
852 polyListSubtracted.BooleanSubtract( m_boardAdapter.GetBackCounterborePolys() );
853 polyListSubtracted.BooleanSubtract( m_boardAdapter.GetBackCountersinkPolys() );
854 }
855 }
856
857 if( m_boardAdapter.m_Cfg->m_Render.subtract_mask_from_silk )
858 {
859 if( layer == B_SilkS && map_poly.contains( B_Mask ) )
860 {
861 polyListSubtracted.BooleanSubtract( *map_poly.at( B_Mask ) );
862 }
863 else if( layer == F_SilkS && map_poly.contains( F_Mask ) )
864 {
865 polyListSubtracted.BooleanSubtract( *map_poly.at( F_Mask ) );
866 }
867 }
868
869 polyList = &polyListSubtracted;
870 }
871 }
872
873 OPENGL_RENDER_LIST* oglList = generateLayerList( container2d, polyList, layer,
874 &m_boardAdapter.GetTH_IDs() );
875
876 if( oglList != nullptr )
877 m_layers[layer] = oglList;
878 }
879
880 if( m_boardAdapter.m_Cfg->m_Render.DifferentiatePlatedCopper() )
881 {
882 const SHAPE_POLY_SET* frontPlatedCopperPolys = m_boardAdapter.GetFrontPlatedCopperPolys();
883 const SHAPE_POLY_SET* backPlatedCopperPolys = m_boardAdapter.GetBackPlatedCopperPolys();
884
885 if( frontPlatedCopperPolys )
886 {
887 SHAPE_POLY_SET poly = frontPlatedCopperPolys->CloneDropTriangulation();
888 poly.BooleanIntersection( m_boardAdapter.GetBoardPoly() );
889 poly.BooleanSubtract( m_boardAdapter.GetTH_ODPolys() );
890 poly.BooleanSubtract( m_boardAdapter.GetNPTH_ODPolys() );
891 poly.BooleanSubtract( m_boardAdapter.GetFrontCounterborePolys() );
892 poly.BooleanSubtract( m_boardAdapter.GetFrontCountersinkPolys() );
893 poly.BooleanSubtract( m_boardAdapter.GetTertiarydrillPolys() );
894
895 m_platedPadsFront = generateLayerList( m_boardAdapter.GetPlatedPadsFront(), &poly,
896 F_Cu );
897
898 // An entry for F_Cu must exist in m_layers or we'll never look at m_platedPadsFront
899 if( m_layers.count( F_Cu ) == 0 )
901 }
902
903 if( backPlatedCopperPolys )
904 {
905 SHAPE_POLY_SET poly = backPlatedCopperPolys->CloneDropTriangulation();
906 poly.BooleanIntersection( m_boardAdapter.GetBoardPoly() );
907 poly.BooleanSubtract( m_boardAdapter.GetTH_ODPolys() );
908 poly.BooleanSubtract( m_boardAdapter.GetNPTH_ODPolys() );
909 poly.BooleanSubtract( m_boardAdapter.GetBackCounterborePolys() );
910 poly.BooleanSubtract( m_boardAdapter.GetBackCountersinkPolys() );
911 poly.BooleanSubtract( m_boardAdapter.GetBackdrillPolys() );
912
913 m_platedPadsBack = generateLayerList( m_boardAdapter.GetPlatedPadsBack(), &poly, B_Cu );
914
915 // An entry for B_Cu must exist in m_layers or we'll never look at m_platedPadsBack
916 if( m_layers.count( B_Cu ) == 0 )
918 }
919 }
920
921 if( m_boardAdapter.m_Cfg->m_Render.show_off_board_silk )
922 {
923 if( const BVH_CONTAINER_2D* padsFront = m_boardAdapter.GetOffboardPadsFront() )
924 m_offboardPadsFront = generateLayerList( padsFront, nullptr, F_Cu );
925
926 if( const BVH_CONTAINER_2D* padsBack = m_boardAdapter.GetOffboardPadsBack() )
927 m_offboardPadsBack = generateLayerList( padsBack, nullptr, B_Cu );
928 }
929
930 // Load 3D models
931 if( aStatusReporter )
932 aStatusReporter->Report( _( "Loading 3D models..." ) );
933
934 load3dModels( aStatusReporter );
935
936 if( aStatusReporter )
937 {
938 // Calculation time in seconds
939 double calculation_time = (double)( GetRunningMicroSecs() - stats_startReloadTime) / 1e6;
940
941 aStatusReporter->Report( wxString::Format( _( "Reload time %.3f s" ), calculation_time ) );
942 }
943}
944
945
947 const SFVEC2F& v1, const SFVEC2F& v2, float top,
948 float bot )
949{
950 aDst->m_layer_bot_triangles->AddTriangle( SFVEC3F( v0.x, v0.y, bot ),
951 SFVEC3F( v1.x, v1.y, bot ),
952 SFVEC3F( v2.x, v2.y, bot ) );
953
955 SFVEC3F( v1.x, v1.y, top ),
956 SFVEC3F( v0.x, v0.y, top ) );
957}
958
959
960void RENDER_3D_OPENGL::getLayerZPos( PCB_LAYER_ID aLayer, float& aOutZtop, float& aOutZbot ) const
961{
962 aOutZbot = m_boardAdapter.GetLayerBottomZPos( aLayer );
963 aOutZtop = m_boardAdapter.GetLayerTopZPos( aLayer );
964
965 if( aOutZtop < aOutZbot )
966 {
967 float tmpFloat = aOutZbot;
968 aOutZbot = aOutZtop;
969 aOutZtop = tmpFloat;
970 }
971}
972
973
974void RENDER_3D_OPENGL::generateCylinder( const SFVEC2F& aCenter, float aInnerRadius,
975 float aOuterRadius, float aZtop, float aZbot,
976 unsigned int aNr_sides_per_circle,
977 TRIANGLE_DISPLAY_LIST* aDstLayer )
978{
979 std::vector< SFVEC2F > innerContour;
980 std::vector< SFVEC2F > outerContour;
981
982 generateRing( aCenter, aInnerRadius, aOuterRadius, aNr_sides_per_circle, innerContour,
983 outerContour, false );
984
985 for( unsigned int i = 0; i < ( innerContour.size() - 1 ); ++i )
986 {
987 const SFVEC2F& vi0 = innerContour[i + 0];
988 const SFVEC2F& vi1 = innerContour[i + 1];
989 const SFVEC2F& vo0 = outerContour[i + 0];
990 const SFVEC2F& vo1 = outerContour[i + 1];
991
992 aDstLayer->m_layer_top_triangles->AddQuad( SFVEC3F( vi1.x, vi1.y, aZtop ),
993 SFVEC3F( vi0.x, vi0.y, aZtop ),
994 SFVEC3F( vo0.x, vo0.y, aZtop ),
995 SFVEC3F( vo1.x, vo1.y, aZtop ) );
996
997 aDstLayer->m_layer_bot_triangles->AddQuad( SFVEC3F( vi1.x, vi1.y, aZbot ),
998 SFVEC3F( vo1.x, vo1.y, aZbot ),
999 SFVEC3F( vo0.x, vo0.y, aZbot ),
1000 SFVEC3F( vi0.x, vi0.y, aZbot ) );
1001 }
1002
1003 aDstLayer->AddToMiddleContours( outerContour, aZbot, aZtop, true );
1004 aDstLayer->AddToMiddleContours( innerContour, aZbot, aZtop, false );
1005}
1006
1007
1008void RENDER_3D_OPENGL::generateInvCone( const SFVEC2F& aCenter, float aInnerRadius,
1009 float aOuterRadius, float aZtop, float aZbot,
1010 unsigned int aNr_sides_per_circle,
1011 TRIANGLE_DISPLAY_LIST* aDstLayer, EDA_ANGLE aAngle )
1012{
1013 // For a countersink cone:
1014 // - The outer contour goes from aZbot to aZtop (full height)
1015 // - The inner contour goes from aZbot to aZbot + innerHeight
1016 // - The top surface is conical, sloping from inner top to outer top
1017 // - aAngle is the half-angle of the cone (in decidegrees from the vertical)
1018
1019 // Calculate the inner contour height based on the cone angle
1020 // tan(angle) = (outerRadius - innerRadius) / innerHeight
1021 // innerHeight = (outerRadius - innerRadius) / tan(angle)
1022 float radialDiff = aOuterRadius - aInnerRadius;
1023 float angleRad = aAngle.AsRadians();
1024
1025 // Clamp angle to avoid division by zero or negative heights
1026 if( angleRad < 0.01f )
1027 angleRad = 0.01f;
1028
1029 float innerHeight = radialDiff / tanf( angleRad );
1030 float totalHeight = aZtop - aZbot;
1031
1032 // Clamp inner height to not exceed total height
1033 if( innerHeight > totalHeight )
1034 innerHeight = totalHeight;
1035
1036 float zInnerTop = aZbot + innerHeight;
1037
1038 std::vector< SFVEC2F > innerContour;
1039 std::vector< SFVEC2F > outerContour;
1040
1041 generateRing( aCenter, aInnerRadius, aOuterRadius, aNr_sides_per_circle, innerContour,
1042 outerContour, false );
1043
1044 for( unsigned int i = 0; i < ( innerContour.size() - 1 ); ++i )
1045 {
1046 const SFVEC2F& vi0 = innerContour[i + 0];
1047 const SFVEC2F& vi1 = innerContour[i + 1];
1048 const SFVEC2F& vo0 = outerContour[i + 0];
1049 const SFVEC2F& vo1 = outerContour[i + 1];
1050
1051 // Conical top surface: from inner contour at zInnerTop to outer contour at aZtop
1052 aDstLayer->m_layer_top_triangles->AddQuad( SFVEC3F( vi1.x, vi1.y, zInnerTop ),
1053 SFVEC3F( vi0.x, vi0.y, zInnerTop ),
1054 SFVEC3F( vo0.x, vo0.y, aZtop ),
1055 SFVEC3F( vo1.x, vo1.y, aZtop ) );
1056
1057 // Flat bottom surface
1058 aDstLayer->m_layer_bot_triangles->AddQuad( SFVEC3F( vi1.x, vi1.y, aZbot ),
1059 SFVEC3F( vo1.x, vo1.y, aZbot ),
1060 SFVEC3F( vo0.x, vo0.y, aZbot ),
1061 SFVEC3F( vi0.x, vi0.y, aZbot ) );
1062 }
1063
1064 // Outer contour wall goes full height
1065 aDstLayer->AddToMiddleContours( outerContour, aZbot, aZtop, true );
1066 // Inner contour wall only goes up to zInnerTop
1067 aDstLayer->AddToMiddleContours( innerContour, aZbot, zInnerTop, false );
1068}
1069
1070
1071void RENDER_3D_OPENGL::generateDisk( const SFVEC2F& aCenter, float aRadius, float aZ,
1072 unsigned int aNr_sides_per_circle, TRIANGLE_DISPLAY_LIST* aDstLayer,
1073 bool aTop )
1074{
1075 const float delta = 2.0f * glm::pi<float>() / (float) aNr_sides_per_circle;
1076
1077 for( unsigned int i = 0; i < aNr_sides_per_circle; ++i )
1078 {
1079 float a0 = delta * i;
1080 float a1 = delta * ( i + 1 );
1081 const SFVEC3F p0( aCenter.x + cosf( a0 ) * aRadius,
1082 aCenter.y + sinf( a0 ) * aRadius, aZ );
1083 const SFVEC3F p1( aCenter.x + cosf( a1 ) * aRadius,
1084 aCenter.y + sinf( a1 ) * aRadius, aZ );
1085 const SFVEC3F c( aCenter.x, aCenter.y, aZ );
1086
1087 if( aTop )
1088 aDstLayer->m_layer_top_triangles->AddTriangle( p1, p0, c );
1089 else
1090 aDstLayer->m_layer_bot_triangles->AddTriangle( p0, p1, c );
1091 }
1092}
1093
1094
1095void RENDER_3D_OPENGL::generateDimple( const SFVEC2F& aCenter, float aRadius, float aZ,
1096 float aDepth, unsigned int aNr_sides_per_circle,
1097 TRIANGLE_DISPLAY_LIST* aDstLayer, bool aTop )
1098{
1099 const float delta = 2.0f * glm::pi<float>() / (float) aNr_sides_per_circle;
1100 const SFVEC3F c( aCenter.x, aCenter.y, aTop ? aZ - aDepth : aZ + aDepth );
1101
1102 for( unsigned int i = 0; i < aNr_sides_per_circle; ++i )
1103 {
1104 float a0 = delta * i;
1105 float a1 = delta * ( i + 1 );
1106 const SFVEC3F p0( aCenter.x + cosf( a0 ) * aRadius,
1107 aCenter.y + sinf( a0 ) * aRadius, aZ );
1108 const SFVEC3F p1( aCenter.x + cosf( a1 ) * aRadius,
1109 aCenter.y + sinf( a1 ) * aRadius, aZ );
1110
1111 if( aTop )
1112 aDstLayer->m_layer_top_triangles->AddTriangle( p0, p1, c );
1113 else
1114 aDstLayer->m_layer_bot_triangles->AddTriangle( p1, p0, c );
1115 }
1116}
1117
1118
1120 const SFVEC2F& aHoleCenter,
1122 int aSizeIU,
1123 int aDepthIU,
1124 float aHoleInnerRadius,
1125 float aZSurface,
1126 bool aIsFront,
1127 float aPlatingThickness3d,
1128 float aUnitScale,
1129 float* aZEnd )
1130{
1131 if( !m_boardAdapter.m_Cfg->m_Render.show_plated_barrels )
1132 return false;
1133
1134 if( !aDstLayer || aPlatingThickness3d <= 0.0f || aHoleInnerRadius <= 0.0f )
1135 return false;
1136
1139 {
1140 return false;
1141 }
1142
1143 if( aSizeIU <= 0 || aDepthIU <= 0 )
1144 return false;
1145
1146 const float radius = aSizeIU * 0.5f * aUnitScale;
1147 const float depth = aDepthIU * aUnitScale;
1148
1149 if( radius <= aHoleInnerRadius || depth <= 0.0f )
1150 return false;
1151
1152 float zEnd = aIsFront ? ( aZSurface - depth ) : ( aZSurface + depth );
1153
1154 if( aZEnd )
1155 *aZEnd = zEnd;
1156
1157 const float zTop = std::max( aZSurface, zEnd );
1158 const float zBot = std::min( aZSurface, zEnd );
1159
1160 const int diameterBIU = std::max( aSizeIU,
1161 std::max( 1,
1162 (int) ( ( aHoleInnerRadius * 2.0f )
1163 / aUnitScale ) ) );
1164 const unsigned int nrSegments =
1165 std::max( 12u, m_boardAdapter.GetCircleSegmentCount( diameterBIU ) );
1166
1168 {
1169 generateCylinder( aHoleCenter, radius, radius + aPlatingThickness3d, zTop, zBot,
1170 nrSegments, aDstLayer );
1171 return true;
1172 }
1173
1174 float csTopRadius = radius;
1175 float csBotRadius = aHoleInnerRadius;
1176
1177 std::vector< SFVEC2F > innerContourTop, outerContourTop;
1178 std::vector< SFVEC2F > innerContourBot, outerContourBot;
1179
1180 generateRing( aHoleCenter, csTopRadius, csTopRadius + aPlatingThickness3d, nrSegments,
1181 innerContourTop, outerContourTop, false );
1182 generateRing( aHoleCenter, csBotRadius, csBotRadius + aPlatingThickness3d, nrSegments,
1183 innerContourBot, outerContourBot, false );
1184
1185 for( unsigned int i = 0; i < ( innerContourTop.size() - 1 ); ++i )
1186 {
1187 const SFVEC2F& vi0_top = innerContourTop[i + 0];
1188 const SFVEC2F& vi1_top = innerContourTop[i + 1];
1189 const SFVEC2F& vo0_top = outerContourTop[i + 0];
1190 const SFVEC2F& vo1_top = outerContourTop[i + 1];
1191
1192 const SFVEC2F& vi0_bot = innerContourBot[i + 0];
1193 const SFVEC2F& vi1_bot = innerContourBot[i + 1];
1194 const SFVEC2F& vo0_bot = outerContourBot[i + 0];
1195 const SFVEC2F& vo1_bot = outerContourBot[i + 1];
1196
1198 SFVEC3F( vi1_top.x, vi1_top.y, zTop ),
1199 SFVEC3F( vi0_top.x, vi0_top.y, zTop ),
1200 SFVEC3F( vi0_bot.x, vi0_bot.y, zBot ),
1201 SFVEC3F( vi1_bot.x, vi1_bot.y, zBot ) );
1202
1204 SFVEC3F( vo1_top.x, vo1_top.y, zTop ),
1205 SFVEC3F( vo0_top.x, vo0_top.y, zTop ),
1206 SFVEC3F( vo0_bot.x, vo0_bot.y, zBot ),
1207 SFVEC3F( vo1_bot.x, vo1_bot.y, zBot ) );
1208 }
1209
1210 return true;
1211}
1212
1213
1214void RENDER_3D_OPENGL::generateViaBarrels( float aPlatingThickness3d, float aUnitScale )
1215{
1216 if( !m_boardAdapter.GetBoard() || m_boardAdapter.GetViaCount() <= 0 )
1217 return;
1218
1219 if( !m_boardAdapter.m_Cfg->m_Render.show_plated_barrels )
1220 return;
1221
1222 float averageDiameter = m_boardAdapter.GetAverageViaHoleDiameter();
1223 unsigned int averageSegCount = m_boardAdapter.GetCircleSegmentCount( averageDiameter );
1224 unsigned int trianglesEstimate = averageSegCount * 8 * m_boardAdapter.GetViaCount();
1225
1226 TRIANGLE_DISPLAY_LIST* layerTriangleVIA = new TRIANGLE_DISPLAY_LIST( trianglesEstimate );
1227
1228 for( const PCB_TRACK* track : m_boardAdapter.GetBoard()->Tracks() )
1229 {
1230 if( track->Type() != PCB_VIA_T )
1231 continue;
1232
1233 const PCB_VIA* via = static_cast<const PCB_VIA*>( track );
1234 bool isBackdrilled = via->GetSecondaryDrillSize().has_value();
1235 bool isTertiarydrilled = via->GetTertiaryDrillSize().has_value();
1236 bool hasFrontPostMachining = via->GetFrontPostMachining().value_or( PAD_DRILL_POST_MACHINING_MODE::UNKNOWN )
1238 && via->GetFrontPostMachining().value_or( PAD_DRILL_POST_MACHINING_MODE::UNKNOWN )
1240 bool hasBackPostMachining = via->GetBackPostMachining().value_or( PAD_DRILL_POST_MACHINING_MODE::UNKNOWN )
1242 && via->GetBackPostMachining().value_or( PAD_DRILL_POST_MACHINING_MODE::UNKNOWN )
1244
1245 if( via->GetViaType() == VIATYPE::THROUGH && !isBackdrilled
1246 && !hasFrontPostMachining && !hasBackPostMachining )
1247 {
1248 continue;
1249 }
1250
1251 const float holediameter = via->GetDrillValue() * aUnitScale;
1252 const int nrSegments = m_boardAdapter.GetCircleSegmentCount( via->GetDrillValue() );
1253 const float hole_inner_radius = holediameter / 2.0f;
1254
1255 const SFVEC2F via_center( via->GetStart().x * aUnitScale,
1256 -via->GetStart().y * aUnitScale );
1257
1258 PCB_LAYER_ID top_layer, bottom_layer;
1259 via->LayerPair( &top_layer, &bottom_layer );
1260
1261 float ztop, zbot, dummy;
1262
1263 getLayerZPos( top_layer, ztop, dummy );
1264 getLayerZPos( bottom_layer, dummy, zbot );
1265
1266 wxASSERT( zbot < ztop );
1267
1268 float ztop_plated = ztop;
1269 float zbot_plated = zbot;
1270
1271 if( isBackdrilled )
1272 {
1273 PCB_LAYER_ID secEnd = via->GetSecondaryDrillEndLayer();
1274 float secZEnd;
1275
1276 // Backdrill goes from the back surface up to secEnd, so get the top of that layer
1277 // as the bottom of the plated barrel
1278 getLayerZPos( secEnd, secZEnd, dummy );
1279 zbot_plated = std::max( zbot_plated, secZEnd );
1280 }
1281
1282 if( isTertiarydrilled )
1283 {
1284 PCB_LAYER_ID terEnd = via->GetTertiaryDrillEndLayer();
1285 float terZEnd;
1286
1287 // Tertiary drill goes from the front surface down to terEnd, so get the bottom of that layer
1288 // as the top of the plated barrel
1289 getLayerZPos( terEnd, dummy, terZEnd );
1290 ztop_plated = std::min( ztop_plated, terZEnd );
1291 }
1292
1293 auto applyViaPostMachining = [&]( bool isFront )
1294 {
1295 auto modeOpt = isFront ? via->GetFrontPostMachining()
1296 : via->GetBackPostMachining();
1297
1298 if( !modeOpt
1300 {
1301 return;
1302 }
1303
1304 int sizeIU = isFront ? via->GetFrontPostMachiningSize()
1305 : via->GetBackPostMachiningSize();
1306 int depthIU = isFront ? via->GetFrontPostMachiningDepth()
1307 : via->GetBackPostMachiningDepth();
1308 float zSurface = isFront ? ztop : zbot;
1309 float zEnd = 0.0f;
1310
1311 if( appendPostMachiningGeometry( layerTriangleVIA, via_center, modeOpt.value(),
1312 sizeIU, depthIU, hole_inner_radius, zSurface,
1313 isFront, aPlatingThickness3d, aUnitScale, &zEnd ) )
1314 {
1315 if( isFront )
1316 ztop_plated = std::min( ztop_plated, zEnd );
1317 else
1318 zbot_plated = std::max( zbot_plated, zEnd );
1319 }
1320 };
1321
1322 if( hasFrontPostMachining )
1323 applyViaPostMachining( true );
1324 if( hasBackPostMachining )
1325 applyViaPostMachining( false );
1326
1327 // generateCylinder( via_center, hole_inner_radius,
1328 // hole_inner_radius + aPlatingThickness3d, ztop_plated,
1329 // zbot_plated, nrSegments, layerTriangleVIA );
1330 }
1331
1332 const float padFrontSurface =
1333 m_boardAdapter.GetLayerBottomZPos( F_Cu )
1334 + m_boardAdapter.GetFrontCopperThickness() * 0.99f;
1335 const float padBackSurface =
1336 m_boardAdapter.GetLayerBottomZPos( B_Cu )
1337 - m_boardAdapter.GetBackCopperThickness() * 0.99f;
1338
1339 for( const FOOTPRINT* footprint : m_boardAdapter.GetBoard()->Footprints() )
1340 {
1341 for( const PAD* pad : footprint->Pads() )
1342 {
1343 if( pad->GetAttribute() == PAD_ATTRIB::NPTH )
1344 continue;
1345
1346 if( !pad->HasHole() )
1347 continue;
1348
1349 if( pad->GetDrillShape() != PAD_DRILL_SHAPE::CIRCLE )
1350 continue;
1351
1352 const SFVEC2F padCenter( pad->GetPosition().x * aUnitScale,
1353 -pad->GetPosition().y * aUnitScale );
1354 const float holeInnerRadius =
1355 pad->GetDrillSize().x * 0.5f * aUnitScale;
1356
1357 auto emitPadPostMachining = [&]( bool isFront )
1358 {
1359 auto modeOpt = isFront ? pad->GetFrontPostMachining()
1360 : pad->GetBackPostMachining();
1361
1362 if( !modeOpt
1364 {
1365 return;
1366 }
1367
1368 int sizeIU = isFront ? pad->GetFrontPostMachiningSize()
1369 : pad->GetBackPostMachiningSize();
1370 int depthIU = isFront ? pad->GetFrontPostMachiningDepth()
1371 : pad->GetBackPostMachiningDepth();
1372 float zSurface = isFront ? padFrontSurface : padBackSurface;
1373
1374 appendPostMachiningGeometry( layerTriangleVIA, padCenter, modeOpt.value(),
1375 sizeIU, depthIU, holeInnerRadius, zSurface,
1376 isFront, aPlatingThickness3d, aUnitScale,
1377 nullptr );
1378 };
1379
1380 emitPadPostMachining( true );
1381 emitPadPostMachining( false );
1382 }
1383 }
1384
1385 m_microviaHoles = new OPENGL_RENDER_LIST( *layerTriangleVIA, 0, 0.0f, 0.0f );
1386
1387 delete layerTriangleVIA;
1388}
1389
1390
1391void RENDER_3D_OPENGL::generatePlatedHoleShells( int aPlatingThickness, float aUnitScale )
1392{
1393 if( !m_boardAdapter.GetBoard() )
1394 return;
1395
1396 if( m_boardAdapter.GetHoleCount() <= 0 && m_boardAdapter.GetViaCount() <= 0 )
1397 return;
1398
1399 SHAPE_POLY_SET tht_outer_holes_poly; // Stores the outer poly of the copper holes
1400 SHAPE_POLY_SET tht_inner_holes_poly; // Stores the inner poly of the copper holes
1401
1402 tht_outer_holes_poly.RemoveAllContours();
1403 tht_inner_holes_poly.RemoveAllContours();
1404
1405 for( const PCB_TRACK* track : m_boardAdapter.GetBoard()->Tracks() )
1406 {
1407 if( track->Type() != PCB_VIA_T )
1408 continue;
1409
1410 const PCB_VIA* via = static_cast<const PCB_VIA*>( track );
1411
1412 if( via->GetViaType() == VIATYPE::THROUGH )
1413 {
1414 TransformCircleToPolygon( tht_outer_holes_poly, via->GetPosition(),
1415 via->GetDrill() / 2 + aPlatingThickness,
1416 via->GetMaxError(), ERROR_INSIDE );
1417
1418 TransformCircleToPolygon( tht_inner_holes_poly, via->GetPosition(), via->GetDrill() / 2,
1419 via->GetMaxError(), ERROR_INSIDE );
1420 }
1421 }
1422
1423 for( const FOOTPRINT* footprint : m_boardAdapter.GetBoard()->Footprints() )
1424 {
1425 for( const PAD* pad : footprint->Pads() )
1426 {
1427 if( pad->GetAttribute() != PAD_ATTRIB::NPTH )
1428 {
1429 if( !pad->HasHole() )
1430 continue;
1431
1432 pad->TransformHoleToPolygon( tht_outer_holes_poly, aPlatingThickness,
1433 pad->GetMaxError(), ERROR_INSIDE );
1434 pad->TransformHoleToPolygon( tht_inner_holes_poly, 0,
1435 pad->GetMaxError(), ERROR_INSIDE );
1436 }
1437 }
1438 }
1439
1440 tht_outer_holes_poly.BooleanSubtract( tht_inner_holes_poly );
1441
1442 tht_outer_holes_poly.BooleanSubtract( m_antiBoardPolys );
1443
1444 CONTAINER_2D holesContainer;
1445
1446 ConvertPolygonToTriangles( tht_outer_holes_poly, holesContainer,
1447 aUnitScale, *m_boardAdapter.GetBoard() );
1448
1449 const LIST_OBJECT2D& holes2D = holesContainer.GetList();
1450
1451 if( holes2D.size() > 0 && m_boardAdapter.m_Cfg->m_Render.show_plated_barrels )
1452 {
1453 float layer_z_top, layer_z_bot, dummy;
1454
1455 getLayerZPos( F_Cu, layer_z_top, dummy );
1456 getLayerZPos( B_Cu, dummy, layer_z_bot );
1457
1458 TRIANGLE_DISPLAY_LIST* layerTriangles = new TRIANGLE_DISPLAY_LIST( holes2D.size() );
1459
1460 for( const OBJECT_2D* itemOnLayer : holes2D )
1461 {
1462 const OBJECT_2D* object2d_A = itemOnLayer;
1463
1464 wxASSERT( object2d_A->GetObjectType() == OBJECT_2D_TYPE::TRIANGLE );
1465
1466 const TRIANGLE_2D* tri = static_cast<const TRIANGLE_2D*>( object2d_A );
1467
1468 const SFVEC2F& v1 = tri->GetP1();
1469 const SFVEC2F& v2 = tri->GetP2();
1470 const SFVEC2F& v3 = tri->GetP3();
1471
1472 addTopAndBottomTriangles( layerTriangles, v1, v2, v3, layer_z_top, layer_z_bot );
1473 }
1474
1475 wxASSERT( tht_outer_holes_poly.OutlineCount() > 0 );
1476
1477 if( tht_outer_holes_poly.OutlineCount() > 0 )
1478 {
1479 layerTriangles->AddToMiddleContours( tht_outer_holes_poly,
1480 layer_z_bot, layer_z_top,
1481 aUnitScale, false );
1482
1483 m_padHoles = new OPENGL_RENDER_LIST( *layerTriangles, m_circleTexture,
1484 layer_z_top, layer_z_top );
1485 }
1486
1487 delete layerTriangles;
1488 }
1489}
1490
1491
1492void RENDER_3D_OPENGL::generateViaCovers( float aPlatingThickness3d, float aUnitScale )
1493{
1494 if( !m_boardAdapter.GetBoard() || m_boardAdapter.GetViaCount() <= 0 )
1495 return;
1496
1497 TRIANGLE_DISPLAY_LIST* frontCover = new TRIANGLE_DISPLAY_LIST( m_boardAdapter.GetViaCount() );
1498 TRIANGLE_DISPLAY_LIST* backCover = new TRIANGLE_DISPLAY_LIST( m_boardAdapter.GetViaCount() );
1499
1500 for( const PCB_TRACK* track : m_boardAdapter.GetBoard()->Tracks() )
1501 {
1502 if( track->Type() != PCB_VIA_T )
1503 continue;
1504
1505 const PCB_VIA* via = static_cast<const PCB_VIA*>( track );
1506
1507 const float holediameter = via->GetDrillValue() * aUnitScale;
1508 const float hole_radius = holediameter / 2.0f + 2.0f * aPlatingThickness3d;
1509 const SFVEC2F center( via->GetStart().x * aUnitScale,
1510 -via->GetStart().y * aUnitScale );
1511 unsigned int seg = m_boardAdapter.GetCircleSegmentCount( via->GetDrillValue() );
1512
1513 PCB_LAYER_ID top_layer, bottom_layer;
1514 via->LayerPair( &top_layer, &bottom_layer );
1515 float ztop, zbot, dummy;
1516 getLayerZPos( top_layer, ztop, dummy );
1517 getLayerZPos( bottom_layer, dummy, zbot );
1518
1519 bool frontCovering = via->GetFrontCoveringMode() == COVERING_MODE::COVERED
1520 || via->IsTented( F_Mask );
1521 bool backCovering = via->GetBackCoveringMode() == COVERING_MODE::COVERED
1522 || via->IsTented( B_Mask );
1523 bool frontPlugged = via->GetFrontPluggingMode() == PLUGGING_MODE::PLUGGED;
1524 bool backPlugged = via->GetBackPluggingMode() == PLUGGING_MODE::PLUGGED;
1525 bool filled = via->GetFillingMode() == FILLING_MODE::FILLED
1526 || via->GetCappingMode() == CAPPING_MODE::CAPPED;
1527
1528 const auto frontPostMachining =
1529 via->GetFrontPostMachining().value_or( PAD_DRILL_POST_MACHINING_MODE::NOT_POST_MACHINED );
1530 const auto backPostMachining =
1531 via->GetBackPostMachining().value_or( PAD_DRILL_POST_MACHINING_MODE::NOT_POST_MACHINED );
1532
1533 bool hasFrontPostMachining = frontPostMachining != PAD_DRILL_POST_MACHINING_MODE::NOT_POST_MACHINED
1534 && frontPostMachining != PAD_DRILL_POST_MACHINING_MODE::UNKNOWN;
1535 bool hasBackPostMachining = backPostMachining != PAD_DRILL_POST_MACHINING_MODE::NOT_POST_MACHINED
1536 && backPostMachining != PAD_DRILL_POST_MACHINING_MODE::UNKNOWN;
1537
1538 bool hasFrontBackdrill = via->GetSecondaryDrillStartLayer() == F_Cu;
1539 bool hasBackBackdrill = via->GetSecondaryDrillStartLayer() == B_Cu;
1540
1541 const float depth = hole_radius * 0.3f;
1542
1543 if( frontCovering && !hasFrontPostMachining && !hasFrontBackdrill )
1544 {
1545 if( filled || !frontPlugged )
1546 generateDisk( center, hole_radius, ztop, seg, frontCover, true );
1547 else
1548 generateDimple( center, hole_radius, ztop, depth, seg, frontCover, true );
1549 }
1550
1551 if( backCovering && !hasBackPostMachining && !hasBackBackdrill )
1552 {
1553 if( filled || !backPlugged )
1554 generateDisk( center, hole_radius, zbot, seg, backCover, false );
1555 else
1556 generateDimple( center, hole_radius, zbot, depth, seg, backCover, false );
1557 }
1558 }
1559
1560 if( frontCover->m_layer_top_triangles->GetVertexSize() > 0 )
1561 m_viaFrontCover = new OPENGL_RENDER_LIST( *frontCover, 0, 0.0f, 0.0f );
1562
1563 if( backCover->m_layer_bot_triangles->GetVertexSize() > 0 )
1564 m_viaBackCover = new OPENGL_RENDER_LIST( *backCover, 0, 0.0f, 0.0f );
1565
1566 delete frontCover;
1567 delete backCover;
1568}
1569
1570
1572{
1573 if( !m_boardAdapter.GetBoard() )
1574 return;
1575
1576 const int platingThickness = m_boardAdapter.GetHolePlatingThickness();
1577 const float unitScale = m_boardAdapter.BiuTo3dUnits();
1578 const float platingThickness3d = platingThickness * unitScale;
1579
1580 // generateViaBarrels( platingThickness3d, unitScale );
1581 // generatePlatedHoleShells( platingThickness, unitScale );
1582 // generateViaCovers( platingThickness3d, unitScale );
1583}
1584
1585
1587{
1588 if( m_3dModelMap.size() > 0 )
1589 return;
1590
1591 if( wxFrame* frame = dynamic_cast<wxFrame*>( m_canvas->GetParent() ) )
1592 {
1593 STATUSBAR_REPORTER activityReporter( frame->GetStatusBar(),
1595 load3dModels( &activityReporter );
1596 }
1597 else
1598 {
1599 load3dModels( nullptr );
1600 }
1601}
1602
1603
1605{
1606 if( !m_boardAdapter.GetBoard() )
1607 return;
1608
1609 // Building the 3D models late crashes on recent versions of macOS
1610 // Unclear the exact mechanism, but as a workaround, just build them
1611 // all the time. See https://gitlab.com/kicad/code/kicad/-/issues/17198
1612#ifndef __WXMAC__
1613 if( !m_boardAdapter.m_IsPreviewer
1614 && !m_boardAdapter.m_Cfg->m_Render.show_footprints_normal
1615 && !m_boardAdapter.m_Cfg->m_Render.show_footprints_insert
1616 && !m_boardAdapter.m_Cfg->m_Render.show_footprints_virtual )
1617 {
1618 return;
1619 }
1620#endif
1621
1622 S3D_CACHE* cacheMgr = m_boardAdapter.Get3dCacheManager();
1623
1624 // Go for all footprints
1625 for( const FOOTPRINT* footprint : m_boardAdapter.GetBoard()->Footprints() )
1626 {
1627 wxString libraryName = footprint->GetFPID().GetLibNickname();
1628 wxString footprintBasePath = wxEmptyString;
1629
1630 if( m_boardAdapter.GetBoard()->GetProject() )
1631 {
1632 try
1633 {
1634 // FindRow() can throw an exception
1635 std::optional<LIBRARY_TABLE_ROW*> fpRow =
1636 PROJECT_PCB::FootprintLibAdapter( m_boardAdapter.GetBoard()->GetProject() )
1637 ->GetRow( libraryName );
1638
1639 if( fpRow )
1640 footprintBasePath = LIBRARY_MANAGER::GetFullURI( *fpRow, true );
1641 }
1642 catch( ... )
1643 {
1644 // Do nothing if the libraryName is not found in lib table
1645 }
1646 }
1647
1648 for( const FP_3DMODEL& fp_model : footprint->Models() )
1649 {
1650 if( fp_model.m_Show && !fp_model.m_Filename.empty() )
1651 {
1652 if( aStatusReporter )
1653 {
1654 // Display the short filename of the 3D fp_model loaded:
1655 // (the full name is usually too long to be displayed)
1656 wxFileName fn( fp_model.m_Filename );
1657 aStatusReporter->Report( wxString::Format( _( "Loading %s..." ),
1658 fn.GetFullName() ) );
1659 }
1660
1661 // Check if the fp_model is not present in our cache map
1662 // (Not already loaded in memory)
1663 if( !m_3dModelMap.contains( fp_model.m_Filename ) )
1664 {
1665 // It is not present, try get it from cache
1666 std::vector<const EMBEDDED_FILES*> embeddedFilesStack;
1667 embeddedFilesStack.push_back( footprint->GetEmbeddedFiles() );
1668 embeddedFilesStack.push_back( m_boardAdapter.GetBoard()->GetEmbeddedFiles() );
1669
1670 const S3DMODEL* modelPtr = cacheMgr->GetModel( fp_model.m_Filename, footprintBasePath,
1671 std::move( embeddedFilesStack ) );
1672
1673 // only add it if the return is not NULL
1674 if( modelPtr )
1675 {
1676 MATERIAL_MODE materialMode = m_boardAdapter.m_Cfg->m_Render.material_mode;
1677 MODEL_3D* model = new MODEL_3D( *modelPtr, materialMode );
1678
1679 m_3dModelMap[ fp_model.m_Filename ] = model;
1680 }
1681 }
1682 }
1683 }
1684 }
1685}
MATERIAL_MODE
Render 3d model shape materials mode.
Definition 3d_enums.h:71
Defines math related functions.
@ ERROR_INSIDE
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:83
const LIST_OBJECT2D & GetList() const
double AsRadians() const
Definition eda_angle.h:120
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) const
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:680
static OBJECT_2D_STATS & Instance()
Definition object_2d.h:137
void ResetStats()
Definition object_2d.h:122
OBJECT_2D_TYPE GetObjectType() const
Definition object_2d.h:107
Store the OpenGL display lists to related with a layer.
Definition pad.h:55
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)
BOARD_ADAPTER & m_boardAdapter
Settings reference in use for this render.
OPENGL_RENDER_LIST * m_board
void reload(REPORTER *aStatusReporter, REPORTER *aWarningReporter)
OPENGL_RENDER_LIST * generateHoles(const LIST_OBJECT2D &aListHolesObject2d, const SHAPE_POLY_SET &aPoly, float aZtop, float aZbot, bool aInvertFaces, const BVH_CONTAINER_2D *aThroughHoles=nullptr)
void generateCylinder(const SFVEC2F &aCenter, float aInnerRadius, float aOuterRadius, float aZtop, float aZbot, unsigned int aNr_sides_per_circle, TRIANGLE_DISPLAY_LIST *aDstLayer)
OPENGL_RENDER_LIST * m_outerThroughHoleRings
OPENGL_RENDER_LIST * m_offboardPadsFront
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)
SHAPE_POLY_SET m_antiBoardPolys
The negative polygon representation of the board outline.
void load3dModels(REPORTER *aStatusReporter)
Load footprint models from the cache and load it to openGL lists in the form of MODEL_3D objects.
OPENGL_RENDER_LIST * generateLayerList(const BVH_CONTAINER_2D *aContainer, const SHAPE_POLY_SET *aPolyList, PCB_LAYER_ID aLayer, const BVH_CONTAINER_2D *aThroughHoles=nullptr)
OPENGL_RENDER_LIST * m_microviaHoles
OPENGL_RENDER_LIST * createBoard(const SHAPE_POLY_SET &aBoardPoly, const BVH_CONTAINER_2D *aThroughHoles=nullptr)
void Load3dModelsIfNeeded()
Load footprint models if they are not already loaded, i.e.
void addObjectTriangles(const RING_2D *aRing, TRIANGLE_DISPLAY_LIST *aDstLayer, float aZtop, float aZbot)
MAP_OGL_DISP_LISTS m_layers
MAP_OGL_DISP_LISTS m_innerLayerHoles
OPENGL_RENDER_LIST * m_boardWithHoles
void generateInvCone(const SFVEC2F &aCenter, float aInnerRadius, float aOuterRadius, float aZtop, float aZbot, unsigned int aNr_sides_per_circle, TRIANGLE_DISPLAY_LIST *aDstLayer, EDA_ANGLE aAngle)
MAP_OGL_DISP_LISTS m_outerLayerHoles
OPENGL_RENDER_LIST * m_offboardPadsBack
std::map< wxString, MODEL_3D * > m_3dModelMap
OPENGL_RENDER_LIST * m_viaBackCover
OPENGL_RENDER_LIST * m_viaFrontCover
OPENGL_RENDER_LIST * generateEmptyLayerList(PCB_LAYER_ID aLayer)
LIST_TRIANGLES m_triangles
store pointers so can be deleted latter
OPENGL_RENDER_LIST * m_outerViaThroughHoles
OPENGL_RENDER_LIST * m_outerThroughHoles
void generateViaCovers(float aPlatingThickness3d, float aUnitScale)
OPENGL_RENDER_LIST * m_platedPadsFront
void generatePlatedHoleShells(int aPlatingThickness, float aUnitScale)
void generateDisk(const SFVEC2F &aCenter, float aRadius, float aZ, unsigned int aNr_sides_per_circle, TRIANGLE_DISPLAY_LIST *aDstLayer, bool aTop)
OPENGL_RENDER_LIST * m_postMachinePlugs
Board material plugs for backdrill/counterbore/countersink.
bool appendPostMachiningGeometry(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)
OPENGL_RENDER_LIST * m_antiBoard
void getLayerZPos(PCB_LAYER_ID aLayerID, float &aOutZtop, float &aOutZbot) const
EDA_3D_CANVAS * m_canvas
OPENGL_RENDER_LIST * m_padHoles
void addTopAndBottomTriangles(TRIANGLE_DISPLAY_LIST *aDst, const SFVEC2F &v0, const SFVEC2F &v1, const SFVEC2F &v2, float top, float bot)
void generateViaBarrels(float aPlatingThickness3d, float aUnitScale)
OPENGL_RENDER_LIST * m_platedPadsBack
void generateDimple(const SFVEC2F &aCenter, float aRadius, float aZ, float aDepth, unsigned int aNr_sides_per_circle, TRIANGLE_DISPLAY_LIST *aDstLayer, bool aTop)
void backfillPostMachine()
Create ring-shaped plugs for holes that have backdrill or post-machining.
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
Definition reporter.h:102
float GetOuterRadius() const
Definition ring_2d.h:48
float GetInnerRadius() const
Definition ring_2d.h:47
const SFVEC2F & GetCenter() const
Definition ring_2d.h:46
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:55
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:551
Represent a set of closed polygons.
void RemoveAllContours()
Remove all outlines & holes (clears) the polygon set.
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.
A wrapper for reporting to a specific text location in a statusbar.
Definition reporter.h:297
const SFVEC2F & GetP2() const
Definition triangle_2d.h:44
const SFVEC2F & GetP3() const
Definition triangle_2d.h:45
const SFVEC2F & GetP1() const
Definition triangle_2d.h:43
Store arrays of triangles to be used to create display lists.
TRIANGLE_LIST * m_layer_bot_segment_ends
void AddToMiddleContours(const SHAPE_LINE_CHAIN &outlinePath, float zBot, float zTop, double aBiuTo3Du, bool aInvertFaceDirection, const BVH_CONTAINER_2D *aThroughHoles=nullptr)
TRIANGLE_LIST * m_layer_middle_contours_quads
TRIANGLE_LIST * m_layer_top_segment_ends
TRIANGLE_LIST * m_layer_bot_triangles
TRIANGLE_LIST * m_layer_top_triangles
void AddTriangle(const SFVEC3F &aV1, const SFVEC3F &aV2, const SFVEC3F &aV3)
void AddQuad(const SFVEC3F &aV1, const SFVEC3F &aV2, const SFVEC3F &aV3, const SFVEC3F &aV4)
unsigned int GetVertexSize() const
std::list< OBJECT_2D * > LIST_OBJECT2D
void TransformCircleToPolygon(SHAPE_LINE_CHAIN &aBuffer, const VECTOR2I &aCenter, int aRadius, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a circle to a polygon, using multiple straight lines.
#define _(s)
Declaration of the eda_3d_viewer class.
@ TENTHS_OF_A_DEGREE_T
Definition eda_angle.h:30
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:60
@ B_Mask
Definition layer_ids.h:98
@ B_Cu
Definition layer_ids.h:65
@ F_Mask
Definition layer_ids.h:97
@ F_SilkS
Definition layer_ids.h:100
@ B_SilkS
Definition layer_ids.h:101
@ F_Cu
Definition layer_ids.h:64
PAD_DRILL_POST_MACHINING_MODE
Definition padstack.h:76
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
Definition padstack.h:103
@ THROUGH
Definition pcb_track.h:68
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:95
KIBIS_MODEL * model
KIBIS top(path, &reporter)
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:97
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695
glm::vec2 SFVEC2F
Definition xv3d_types.h:42
glm::vec3 SFVEC3F
Definition xv3d_types.h:44