KiCad PCB EDA Suite
Loading...
Searching...
No Matches
raytracing/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-2022 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
23#include "shapes3D/plane_3d.h"
27#include "shapes3D/frustum_3d.h"
30#include "shapes2D/ring_2d.h"
31#include "shapes2D/polygon_2d.h"
36#include "3d_fastmath.h"
37#include "3d_math.h"
39
40#include <board.h>
41#include <footprint.h>
42#include <pcb_3d_body.h>
43#include <eda_3d_viewer_frame.h>
44#include <pad.h>
45#include <pcb_track.h>
46#include <layer_range.h>
47#include <base_units.h>
48#include <core/profile.h> // To use GetRunningMicroSecs or another profiling utility
49
58static float TransparencyControl( float aGrayColorValue, float aTransparency )
59{
60 const float aaa = aTransparency * aTransparency * aTransparency;
61
62 // 1.00-1.05*(1.0-x)^3
63 float ca = 1.0f - aTransparency;
64 ca = 1.00f - 1.05f * ca * ca * ca;
65
66 return glm::max( glm::min( aGrayColorValue * ca + aaa, 1.0f ), 0.0f );
67}
68
69
70
72{
73 MATERIAL::SetDefaultRefractionRayCount(
74 m_boardAdapter.m_Cfg->m_Render.raytrace_nrsamples_refractions );
75 MATERIAL::SetDefaultReflectionRayCount(
76 m_boardAdapter.m_Cfg->m_Render.raytrace_nrsamples_reflections );
77
78 MATERIAL::SetDefaultRefractionRecursionCount(
79 m_boardAdapter.m_Cfg->m_Render.raytrace_recursivelevel_refractions );
80 MATERIAL::SetDefaultReflectionRecursionCount(
81 m_boardAdapter.m_Cfg->m_Render.raytrace_recursivelevel_reflections );
82
83 double mmTo3Dunits = pcbIUScale.IU_PER_MM * m_boardAdapter.BiuTo3dUnits();
84
85 if( m_boardAdapter.m_Cfg->m_Render.raytrace_procedural_textures )
86 {
87 m_boardMaterial = BOARD_NORMAL( 0.40f * mmTo3Dunits );
88 m_copperMaterial = COPPER_NORMAL( 4.0f * mmTo3Dunits, &m_boardMaterial );
89 m_platedCopperMaterial = PLATED_COPPER_NORMAL( 0.5f * mmTo3Dunits );
91 m_plasticMaterial = PLASTIC_NORMAL( 0.05f * mmTo3Dunits );
92 m_shinyPlasticMaterial = PLASTIC_SHINE_NORMAL( 0.1f * mmTo3Dunits );
93 m_brushedMetalMaterial = BRUSHED_METAL_NORMAL( 0.05f * mmTo3Dunits );
94 m_silkScreenMaterial = SILK_SCREEN_NORMAL( 0.25f * mmTo3Dunits );
95 }
96
97 // http://devernay.free.fr/cours/opengl/materials.html
98 // Copper
99 const SFVEC3F copperSpecularLinear =
100 ConvertSRGBToLinear( glm::clamp( (SFVEC3F) m_boardAdapter.m_CopperColor * 0.5f + 0.25f,
101 SFVEC3F( 0.0f ), SFVEC3F( 1.0f ) ) );
102
104 ConvertSRGBToLinear( (SFVEC3F) m_boardAdapter.m_CopperColor * 0.3f ),
105 SFVEC3F( 0.0f ), copperSpecularLinear, 0.4f * 128.0f, 0.0f, 0.0f );
106
107 if( m_boardAdapter.m_Cfg->m_Render.raytrace_procedural_textures )
108 m_materials.m_Copper.SetGenerator( &m_platedCopperMaterial );
109
110 m_materials.m_NonPlatedCopper = BLINN_PHONG_MATERIAL(
111 ConvertSRGBToLinear( SFVEC3F( 0.191f, 0.073f, 0.022f ) ), SFVEC3F( 0.0f, 0.0f, 0.0f ),
112 SFVEC3F( 0.256f, 0.137f, 0.086f ), 0.15f * 128.0f, 0.0f, 0.0f );
113
114 if( m_boardAdapter.m_Cfg->m_Render.raytrace_procedural_textures )
115 m_materials.m_NonPlatedCopper.SetGenerator( &m_copperMaterial );
116
118 ConvertSRGBToLinear( (SFVEC3F) m_boardAdapter.m_SolderPasteColor )
119 * ConvertSRGBToLinear( (SFVEC3F) m_boardAdapter.m_SolderPasteColor ),
120 SFVEC3F( 0.0f, 0.0f, 0.0f ),
121 ConvertSRGBToLinear( (SFVEC3F) m_boardAdapter.m_SolderPasteColor )
122 * ConvertSRGBToLinear( (SFVEC3F) m_boardAdapter.m_SolderPasteColor ),
123 0.10f * 128.0f, 0.0f, 0.0f );
124
126 ConvertSRGBToLinear( (SFVEC3F) m_boardAdapter.m_AdhesiveColor )
127 * ConvertSRGBToLinear( (SFVEC3F) m_boardAdapter.m_AdhesiveColor ),
128 SFVEC3F( 0.0f, 0.0f, 0.0f ),
129 ConvertSRGBToLinear( (SFVEC3F) m_boardAdapter.m_AdhesiveColor )
130 * ConvertSRGBToLinear( (SFVEC3F) m_boardAdapter.m_AdhesiveColor ),
131 0.10f * 128.0f, 0.0f, 0.0f );
132
134 SFVEC3F( 0.0f, 0.0f, 0.0f ),
135 glm::clamp( ( ( SFVEC3F )( 1.0f ) - ConvertSRGBToLinear(
136 (SFVEC3F) m_boardAdapter.m_SilkScreenColorTop ) ),
137 SFVEC3F( 0.0f ), SFVEC3F( 0.10f ) ), 0.078125f * 128.0f, 0.0f, 0.0f );
138
139 if( m_boardAdapter.m_Cfg->m_Render.raytrace_procedural_textures )
140 m_materials.m_SilkS.SetGenerator( &m_silkScreenMaterial );
141
142 // Assume that SolderMaskTop == SolderMaskBot
143 const float solderMask_gray =
144 ( m_boardAdapter.m_SolderMaskColorTop.r + m_boardAdapter.m_SolderMaskColorTop.g
145 + m_boardAdapter.m_SolderMaskColorTop.b )
146 / 3.0f;
147
148 const float solderMask_transparency = TransparencyControl( solderMask_gray,
149 1.0f - m_boardAdapter.m_SolderMaskColorTop.a );
150
151 // For darker solder mask colors, increase shininess for a more realistic appearance.
152 // Darker colors appear to have a sharper specular highlight in real life.
153 const float minSolderMaskShininess = 0.85f * 128.0f;
154 const float maxSolderMaskShininess = 512.0f;
155 const float solderMaskShininess = minSolderMaskShininess
156 + ( maxSolderMaskShininess - minSolderMaskShininess ) * ( 1.0f - solderMask_gray );
157
158 // Darker solder mask colors need lower reflection to prevent washed-out appearance
159 const float solderMaskReflection = glm::clamp( solderMask_gray * 0.3f, 0.02f, 0.16f );
160
161 m_materials.m_SolderMask = BLINN_PHONG_MATERIAL(
162 ConvertSRGBToLinear( (SFVEC3F) m_boardAdapter.m_SolderMaskColorTop ) * 0.10f,
163 SFVEC3F( 0.0f, 0.0f, 0.0f ),
164 SFVEC3F( glm::clamp( solderMask_gray * 2.0f, 0.30f, 1.0f ) ), solderMaskShininess,
165 solderMask_transparency, solderMaskReflection );
166
167 m_materials.m_SolderMask.SetCastShadows( true );
168 m_materials.m_SolderMask.SetRefractionRayCount( 1 );
169
170 if( m_boardAdapter.m_Cfg->m_Render.raytrace_procedural_textures )
171 m_materials.m_SolderMask.SetGenerator( &m_solderMaskMaterial );
172
173 m_materials.m_EpoxyBoard =
174 BLINN_PHONG_MATERIAL( ConvertSRGBToLinear( SFVEC3F( 16.0f / 255.0f, 14.0f / 255.0f,
175 10.0f / 255.0f ) ),
176 SFVEC3F( 0.0f, 0.0f, 0.0f ),
177 ConvertSRGBToLinear( SFVEC3F( 10.0f / 255.0f, 8.0f / 255.0f,
178 10.0f / 255.0f ) ),
179 0.1f * 128.0f, 1.0f - m_boardAdapter.m_BoardBodyColor.a, 0.0f );
180
181 m_materials.m_EpoxyBoard.SetAbsorvance( 10.0f );
182
183 if( m_boardAdapter.m_Cfg->m_Render.raytrace_procedural_textures )
184 m_materials.m_EpoxyBoard.SetGenerator( &m_boardMaterial );
185
186 SFVEC3F bgTop = ConvertSRGBToLinear( (SFVEC3F) m_boardAdapter.m_BgColorTop );
187
188 m_materials.m_Floor = BLINN_PHONG_MATERIAL( bgTop * 0.125f, SFVEC3F( 0.0f, 0.0f, 0.0f ),
189 ( SFVEC3F( 1.0f ) - bgTop ) / 3.0f,
190 0.10f * 128.0f, 1.0f, 0.50f );
191 m_materials.m_Floor.SetCastShadows( false );
192 m_materials.m_Floor.SetReflectionRecursionCount( 1 );
193}
194
195
196void RENDER_3D_RAYTRACE_BASE::createObject( CONTAINER_3D& aDstContainer, const OBJECT_2D* aObject2D,
197 float aZMin, float aZMax, const MATERIAL* aMaterial,
198 const SFVEC3F& aObjColor )
199{
200 switch( aObject2D->GetObjectType() )
201 {
203 {
205
206 XY_PLANE* objPtr;
207 objPtr = new XY_PLANE( BBOX_3D(
208 SFVEC3F( aObject2D->GetBBox().Min().x, aObject2D->GetBBox().Min().y, aZMin ),
209 SFVEC3F( aObject2D->GetBBox().Max().x, aObject2D->GetBBox().Max().y, aZMin ) ) );
210 objPtr->SetMaterial( aMaterial );
211 objPtr->SetColor( ConvertSRGBToLinear( aObjColor ) );
212 aDstContainer.Add( objPtr );
213
214 objPtr = new XY_PLANE( BBOX_3D(
215 SFVEC3F( aObject2D->GetBBox().Min().x, aObject2D->GetBBox().Min().y, aZMax ),
216 SFVEC3F( aObject2D->GetBBox().Max().x, aObject2D->GetBBox().Max().y, aZMax ) ) );
217 objPtr->SetMaterial( aMaterial );
218 objPtr->SetColor( ConvertSRGBToLinear( aObjColor ) );
219 aDstContainer.Add( objPtr );
220 break;
221 }
222
224 {
226
227 const ROUND_SEGMENT_2D* aRoundSeg2D = static_cast<const ROUND_SEGMENT_2D*>( aObject2D );
228 ROUND_SEGMENT* objPtr = new ROUND_SEGMENT( *aRoundSeg2D, aZMin, aZMax );
229 objPtr->SetMaterial( aMaterial );
230 objPtr->SetColor( ConvertSRGBToLinear( aObjColor ) );
231 aDstContainer.Add( objPtr );
232 break;
233 }
234
235 default:
236 {
237 LAYER_ITEM* objPtr = new LAYER_ITEM( aObject2D, aZMin, aZMax );
238 objPtr->SetMaterial( aMaterial );
239 objPtr->SetColor( ConvertSRGBToLinear( aObjColor ) );
240 aDstContainer.Add( objPtr );
241 break;
242 }
243 }
244}
245
246
248 PCB_LAYER_ID aLayer_id,
249 const MATERIAL* aMaterialLayer,
250 const SFVEC3F& aLayerColor,
251 float aLayerZOffset )
252{
253 if( aContainer2d == nullptr )
254 return;
255
257 bool isSilk = aLayer_id == B_SilkS || aLayer_id == F_SilkS;
258 const LIST_OBJECT2D& listObject2d = aContainer2d->GetList();
259
260 if( listObject2d.size() == 0 )
261 return;
262
263 for( const OBJECT_2D* object2d_A : listObject2d )
264 {
265 // not yet used / implemented (can be used in future to clip the objects in the
266 // board borders
267 OBJECT_2D* object2d_C = CSGITEM_FULL;
268
269 std::vector<const OBJECT_2D*>* object2d_B = CSGITEM_EMPTY;
270
271 object2d_B = new std::vector<const OBJECT_2D*>();
272
273 // Subtract holes but not in SolderPaste
274 // (can be added as an option in future)
275 if( !( aLayer_id == B_Paste || aLayer_id == F_Paste ) )
276 {
277 // Check if there are any layerhole that intersects this object
278 // Eg: a segment is cut by a via hole or THT hole.
279 const MAP_CONTAINER_2D_BASE& layerHolesMap = m_boardAdapter.GetLayerHoleMap();
280
281 if( layerHolesMap.find( aLayer_id ) != layerHolesMap.end() )
282 {
283 const BVH_CONTAINER_2D* holes2d = layerHolesMap.at( aLayer_id );
284
285 CONST_LIST_OBJECT2D intersecting;
286
287 holes2d->GetIntersectingObjects( object2d_A->GetBBox(), intersecting );
288
289 for( const OBJECT_2D* hole2d : intersecting )
290 object2d_B->push_back( hole2d );
291 }
292
293 // Check if there are any THT that intersects this object. If we're processing a silk
294 // layer and the flag is set, then clip the silk at the outer edge of the annular ring,
295 // rather than the at the outer edge of the copper plating.
296 const BVH_CONTAINER_2D& throughHoleOuter =
297 cfg.clip_silk_on_via_annuli && isSilk ? m_boardAdapter.GetViaAnnuli()
298 : m_boardAdapter.GetTH_ODs();
299
300 if( !throughHoleOuter.GetList().empty() )
301 {
302 CONST_LIST_OBJECT2D intersecting;
303
304 throughHoleOuter.GetIntersectingObjects( object2d_A->GetBBox(), intersecting );
305
306 for( const OBJECT_2D* hole2d : intersecting )
307 object2d_B->push_back( hole2d );
308 }
309
310 // Clip counterbore/countersink cutouts from copper layers
311 // Front cutouts affect F_Cu, back cutouts affect B_Cu
312 auto clipCutouts =
313 [this, &object2d_A, &object2d_B]( const BVH_CONTAINER_2D& cutouts )
314 {
315 if( !cutouts.GetList().empty() )
316 {
317 CONST_LIST_OBJECT2D intersecting;
318 cutouts.GetIntersectingObjects( object2d_A->GetBBox(), intersecting );
319
320 for( const OBJECT_2D* cutout : intersecting )
321 object2d_B->push_back( cutout );
322 }
323 };
324
325 if( aLayer_id == F_Cu )
326 {
327 clipCutouts( m_boardAdapter.GetFrontCounterboreCutouts() );
328 clipCutouts( m_boardAdapter.GetFrontCountersinkCutouts() );
329 clipCutouts( m_boardAdapter.GetFrontBackdrillCutouts() );
330 }
331 else if( aLayer_id == B_Cu )
332 {
333 clipCutouts( m_boardAdapter.GetBackCounterboreCutouts() );
334 clipCutouts( m_boardAdapter.GetBackCountersinkCutouts() );
335 clipCutouts( m_boardAdapter.GetBackBackdrillCutouts() );
336 }
337 }
338
339 if( !m_antioutlineBoard2dObjects->GetList().empty() )
340 {
341 CONST_LIST_OBJECT2D intersecting;
342
343 m_antioutlineBoard2dObjects->GetIntersectingObjects( object2d_A->GetBBox(),
344 intersecting );
345
346 for( const OBJECT_2D* obj : intersecting )
347 object2d_B->push_back( obj );
348 }
349
350 const MAP_CONTAINER_2D_BASE& mapLayers = m_boardAdapter.GetLayerMap();
351
353 && ( ( aLayer_id == B_SilkS && mapLayers.find( B_Mask ) != mapLayers.end() )
354 || ( aLayer_id == F_SilkS && mapLayers.find( F_Mask ) != mapLayers.end() ) ) )
355 {
356 const PCB_LAYER_ID maskLayer = ( aLayer_id == B_SilkS ) ? B_Mask : F_Mask;
357
358 const BVH_CONTAINER_2D* containerMaskLayer2d = mapLayers.at( maskLayer );
359
360 CONST_LIST_OBJECT2D intersecting;
361
362 if( containerMaskLayer2d ) // can be null if B_Mask or F_Mask is not shown
363 containerMaskLayer2d->GetIntersectingObjects( object2d_A->GetBBox(), intersecting );
364
365 for( const OBJECT_2D* obj2d : intersecting )
366 object2d_B->push_back( obj2d );
367 }
368
369 if( object2d_B->empty() )
370 {
371 delete object2d_B;
372 object2d_B = CSGITEM_EMPTY;
373 }
374
375 if( ( object2d_B == CSGITEM_EMPTY ) && ( object2d_C == CSGITEM_FULL ) )
376 {
377 LAYER_ITEM* objPtr = new LAYER_ITEM( object2d_A,
378 m_boardAdapter.GetLayerBottomZPos( aLayer_id ) - aLayerZOffset,
379 m_boardAdapter.GetLayerTopZPos( aLayer_id ) + aLayerZOffset );
380 objPtr->SetMaterial( aMaterialLayer );
381 objPtr->SetColor( ConvertSRGBToLinear( aLayerColor ) );
382 m_objectContainer.Add( objPtr );
383 }
384 else
385 {
386 LAYER_ITEM_2D* itemCSG2d = new LAYER_ITEM_2D( object2d_A, object2d_B, object2d_C,
387 object2d_A->GetBoardItem() );
388 m_containerWithObjectsToDelete.Add( itemCSG2d );
389
390 LAYER_ITEM* objPtr = new LAYER_ITEM( itemCSG2d,
391 m_boardAdapter.GetLayerBottomZPos( aLayer_id ) - aLayerZOffset,
392 m_boardAdapter.GetLayerTopZPos( aLayer_id ) + aLayerZOffset );
393
394 objPtr->SetMaterial( aMaterialLayer );
395 objPtr->SetColor( ConvertSRGBToLinear( aLayerColor ) );
396
397 m_objectContainer.Add( objPtr );
398 }
399 }
400}
401
402
403extern void buildBoardBoundingBoxPoly( const BOARD* aBoard, SHAPE_POLY_SET& aOutline );
404
405
406void RENDER_3D_RAYTRACE_BASE::Reload( bool aOnlyLoadCopperAndShapes, std::stop_token aStop )
407{
408 m_reloadRequested = false;
409
410 m_modelMaterialMap.clear();
411
414
415 int64_t stats_startReloadTime = GetRunningMicroSecs();
416
417 if( !aOnlyLoadCopperAndShapes )
418 {
420 m_boardAdapter.CreateLayers( m_activityReporter );
421
422 SFVEC3F camera_pos = m_boardAdapter.GetBoardCenter();
423 m_camera.SetBoardLookAtPos( camera_pos );
424 }
425
426 {
427 // Drop the BVH before freeing objects it indexes (and before any layer rebuild).
428 std::lock_guard<std::mutex> lock( m_hitTestMutex );
429 m_accelerator.reset();
430 }
431
432 m_objectContainer.Clear();
434 m_extrusionMaterials.clear();
435
437
438 if( aStop.stop_requested() )
439 return;
440
442 {
443 if( aOnlyLoadCopperAndShapes )
444 m_activityReporter->Report( _( "Building hit-test scene..." ) );
445 else
446 m_activityReporter->Report( _( "Load Raytracing: board" ) );
447 }
448
449 // Create and add the outline board
452
455
456 std::bitset<LAYER_3D_END> layerFlags = m_boardAdapter.GetVisibleLayers();
457
458 if( !aOnlyLoadCopperAndShapes )
459 {
460 const int outlineCount = m_boardAdapter.GetBoardPoly().OutlineCount();
461
462 if( outlineCount > 0 )
463 {
464 float divFactor = 0.0f;
465
466 if( m_boardAdapter.GetViaCount() )
467 divFactor = m_boardAdapter.GetAverageViaHoleDiameter() * 18.0f;
468 else if( m_boardAdapter.GetHoleCount() )
469 divFactor = m_boardAdapter.GetAverageHoleDiameter() * 8.0f;
470
471 SHAPE_POLY_SET boardPolyCopy = m_boardAdapter.GetBoardPoly();
472
473 // Calculate an antiboard outline
474 SHAPE_POLY_SET antiboardPoly;
475
476 buildBoardBoundingBoxPoly( m_boardAdapter.GetBoard(), antiboardPoly );
477
478 antiboardPoly.BooleanSubtract( boardPolyCopy );
479 antiboardPoly.Fracture();
480
481 for( int ii = 0; ii < antiboardPoly.OutlineCount(); ii++ )
482 {
484 m_boardAdapter.BiuTo3dUnits(), -1.0f,
485 *m_boardAdapter.GetBoard(), ii );
486 }
487
488 m_antioutlineBoard2dObjects->BuildBVH();
489
490 boardPolyCopy.Fracture();
491
492 for( int ii = 0; ii < boardPolyCopy.OutlineCount(); ii++ )
493 {
495 m_boardAdapter.BiuTo3dUnits(), divFactor,
496 *m_boardAdapter.GetBoard(), ii );
497 }
498
499 if( layerFlags.test( LAYER_3D_BOARD ) )
500 {
501 const LIST_OBJECT2D& listObjects = m_outlineBoard2dObjects->GetList();
502
503 for( const OBJECT_2D* object2d_A : listObjects )
504 {
505 std::vector<const OBJECT_2D*>* object2d_B = new std::vector<const OBJECT_2D*>();
506
507 // Check if there are any THT that intersects this outline object part
508 if( !m_boardAdapter.GetTH_ODs().GetList().empty() )
509 {
510 const BVH_CONTAINER_2D& throughHoles = m_boardAdapter.GetTH_ODs();
511 CONST_LIST_OBJECT2D intersecting;
512
513 throughHoles.GetIntersectingObjects( object2d_A->GetBBox(), intersecting );
514
515 for( const OBJECT_2D* hole : intersecting )
516 {
517 if( object2d_A->Intersects( hole->GetBBox() ) )
518 object2d_B->push_back( hole );
519 }
520 }
521
522 // Subtract counterbore/countersink cutouts from board body
523 auto addCutoutsFromContainer =
524 [&]( const BVH_CONTAINER_2D& aContainer )
525 {
526 if( !aContainer.GetList().empty() )
527 {
528 CONST_LIST_OBJECT2D intersecting;
529 aContainer.GetIntersectingObjects( object2d_A->GetBBox(),
530 intersecting );
531
532 for( const OBJECT_2D* cutout : intersecting )
533 {
534 if( object2d_A->Intersects( cutout->GetBBox() ) )
535 object2d_B->push_back( cutout );
536 }
537 }
538 };
539
540 addCutoutsFromContainer( m_boardAdapter.GetFrontCounterboreCutouts() );
541 addCutoutsFromContainer( m_boardAdapter.GetBackCounterboreCutouts() );
542 addCutoutsFromContainer( m_boardAdapter.GetFrontCountersinkCutouts() );
543 addCutoutsFromContainer( m_boardAdapter.GetBackCountersinkCutouts() );
544
545 // Subtract backdrill holes (which are in layerHoleMap for F_Cu and B_Cu)
546 const MAP_CONTAINER_2D_BASE& layerHolesMap = m_boardAdapter.GetLayerHoleMap();
547
548 if( layerHolesMap.find( F_Cu ) != layerHolesMap.end() )
549 {
550 const BVH_CONTAINER_2D* holes2d = layerHolesMap.at( F_Cu );
551 CONST_LIST_OBJECT2D intersecting;
552
553 holes2d->GetIntersectingObjects( object2d_A->GetBBox(), intersecting );
554
555 for( const OBJECT_2D* hole2d : intersecting )
556 {
557 if( object2d_A->Intersects( hole2d->GetBBox() ) )
558 object2d_B->push_back( hole2d );
559 }
560 }
561
562 if( layerHolesMap.find( B_Cu ) != layerHolesMap.end() )
563 {
564 const BVH_CONTAINER_2D* holes2d = layerHolesMap.at( B_Cu );
565 CONST_LIST_OBJECT2D intersecting;
566
567 holes2d->GetIntersectingObjects( object2d_A->GetBBox(), intersecting );
568
569 for( const OBJECT_2D* hole2d : intersecting )
570 {
571 if( object2d_A->Intersects( hole2d->GetBBox() ) )
572 object2d_B->push_back( hole2d );
573 }
574 }
575
576 if( !m_antioutlineBoard2dObjects->GetList().empty() )
577 {
578 CONST_LIST_OBJECT2D intersecting;
579
580 m_antioutlineBoard2dObjects->GetIntersectingObjects( object2d_A->GetBBox(),
581 intersecting );
582
583 for( const OBJECT_2D* obj : intersecting )
584 object2d_B->push_back( obj );
585 }
586
587 if( object2d_B->empty() )
588 {
589 delete object2d_B;
590 object2d_B = CSGITEM_EMPTY;
591 }
592
593 if( object2d_B == CSGITEM_EMPTY )
594 {
595 LAYER_ITEM* objPtr = new LAYER_ITEM( object2d_A,
596 m_boardAdapter.GetLayerBottomZPos( F_Cu ),
597 m_boardAdapter.GetLayerBottomZPos( B_Cu ) );
598
599 objPtr->SetMaterial( &m_materials.m_EpoxyBoard );
600 objPtr->SetColor( ConvertSRGBToLinear( m_boardAdapter.m_BoardBodyColor ) );
601 m_objectContainer.Add( objPtr );
602 }
603 else
604 {
605
606 LAYER_ITEM_2D* itemCSG2d = new LAYER_ITEM_2D( object2d_A, object2d_B,
608 *m_boardAdapter.GetBoard() );
609
610 m_containerWithObjectsToDelete.Add( itemCSG2d );
611
612 LAYER_ITEM* objPtr = new LAYER_ITEM( itemCSG2d,
613 m_boardAdapter.GetLayerBottomZPos( F_Cu ),
614 m_boardAdapter.GetLayerBottomZPos( B_Cu ) );
615
616 objPtr->SetMaterial( &m_materials.m_EpoxyBoard );
617 objPtr->SetColor( ConvertSRGBToLinear( m_boardAdapter.m_BoardBodyColor ) );
618 m_objectContainer.Add( objPtr );
619 }
620 }
621
622 // Add cylinders of the board body to container
623 // Note: This is actually a workaround for the holes in the board.
624 // The issue is because if a hole is in a border of a divided polygon ( ex
625 // a polygon or dummy block) it will cut also the render of the hole.
626 // So this will add a full hole.
627 // In fact, that is not need if the hole have copper.
628 if( !m_boardAdapter.GetTH_ODs().GetList().empty() )
629 {
630 const LIST_OBJECT2D& holeList = m_boardAdapter.GetTH_ODs().GetList();
631
632 for( const OBJECT_2D* hole2d : holeList )
633 {
634 if( !m_antioutlineBoard2dObjects->GetList().empty() )
635 {
636 CONST_LIST_OBJECT2D intersecting;
637
638 m_antioutlineBoard2dObjects->GetIntersectingObjects( hole2d->GetBBox(),
639 intersecting );
640
641 // Do not add cylinder if it intersects the edge of the board
642 if( !intersecting.empty() )
643 continue;
644 }
645
646 switch( hole2d->GetObjectType() )
647 {
649 {
650 const float radius = hole2d->GetBBox().GetExtent().x * 0.5f * 0.999f;
651
652 CYLINDER* objPtr = new CYLINDER( hole2d->GetCentroid(),
653 NextFloatDown( m_boardAdapter.GetLayerBottomZPos( F_Cu ) ),
654 NextFloatUp( m_boardAdapter.GetLayerBottomZPos( B_Cu ) ),
655 radius );
656
657 objPtr->SetMaterial( &m_materials.m_EpoxyBoard );
658 objPtr->SetColor(
659 ConvertSRGBToLinear( m_boardAdapter.m_BoardBodyColor ) );
660
661 m_objectContainer.Add( objPtr );
662 }
663 break;
664
665 default:
666 break;
667 }
668 }
669 }
670
671 // Create plugs for backdrilled and post-machined areas
673 }
674 }
675 }
676
678 {
679 if( aOnlyLoadCopperAndShapes )
680 m_activityReporter->Report( _( "Building hit-test scene: layers..." ) );
681 else
682 m_activityReporter->Report( _( "Load Raytracing: layers" ) );
683 }
684
685 // Add layers maps (except B_Mask and F_Mask)
686 for( const std::pair<const PCB_LAYER_ID, BVH_CONTAINER_2D*>& entry :
687 m_boardAdapter.GetLayerMap() )
688 {
689 const PCB_LAYER_ID layer_id = entry.first;
690 const BVH_CONTAINER_2D* container2d = entry.second;
691
692 // Only process layers that exist
693 if( !container2d )
694 continue;
695
696 if( aOnlyLoadCopperAndShapes && !IsCopperLayer( layer_id ) )
697 continue;
698
699 // Mask layers are not processed here because they are a special case
700 if( layer_id == B_Mask || layer_id == F_Mask )
701 continue;
702
703 MATERIAL* materialLayer = &m_materials.m_SilkS;
704 SFVEC3F layerColor = SFVEC3F( 0.0f, 0.0f, 0.0f );
705
706 switch( layer_id )
707 {
708 case B_Adhes:
709 case F_Adhes:
710 materialLayer = &m_materials.m_Adhesive;
711 layerColor = m_boardAdapter.m_AdhesiveColor;
712 break;
713
714 case B_Paste:
715 case F_Paste:
716 materialLayer = &m_materials.m_Paste;
717 layerColor = m_boardAdapter.m_SolderPasteColor;
718 break;
719
720 case B_SilkS:
721 materialLayer = &m_materials.m_SilkS;
722 layerColor = m_boardAdapter.m_SilkScreenColorBot;
723 break;
724
725 case F_SilkS:
726 materialLayer = &m_materials.m_SilkS;
727 layerColor = m_boardAdapter.m_SilkScreenColorTop;
728 break;
729
730 case Dwgs_User:
731 layerColor = m_boardAdapter.m_UserDrawingsColor;
732 break;
733
734 case Cmts_User:
735 layerColor = m_boardAdapter.m_UserCommentsColor;
736 break;
737
738 case Eco1_User:
739 layerColor = m_boardAdapter.m_ECO1Color;
740 break;
741
742 case Eco2_User:
743 layerColor = m_boardAdapter.m_ECO2Color;
744 break;
745
746 case B_CrtYd:
747 layerColor = m_boardAdapter.m_BCourtyardColor;
748 break;
749
750 case F_CrtYd:
751 layerColor = m_boardAdapter.m_FCourtyardColor;
752 break;
753
754 case B_Fab:
755 layerColor = m_boardAdapter.m_BFabColor;
756 break;
757
758 case F_Fab:
759 layerColor = m_boardAdapter.m_FFabColor;
760 break;
761
762 default:
763 {
764 int layer3D = MapPCBLayerTo3DLayer( layer_id );
765
766 // Note: MUST do this in LAYER_3D space; User_1..User_45 are NOT contiguous
767 if( layer3D >= LAYER_3D_USER_1 && layer3D <= LAYER_3D_USER_45 )
768 {
769 layerColor = m_boardAdapter.m_UserDefinedLayerColor[ layer3D - LAYER_3D_USER_1 ];
770 }
771 else if( m_boardAdapter.m_Cfg->m_Render.differentiate_plated_copper )
772 {
773 layerColor = SFVEC3F( 184.0f / 255.0f, 115.0f / 255.0f, 50.0f / 255.0f );
774 materialLayer = &m_materials.m_NonPlatedCopper;
775 }
776 else
777 {
778 layerColor = m_boardAdapter.m_CopperColor;
779 materialLayer = &m_materials.m_Copper;
780 }
781
782 break;
783 }
784 }
785
786 createItemsFromContainer( container2d, layer_id, materialLayer, layerColor, 0.0f );
787
788 if( aStop.stop_requested() )
789 return;
790 } // for each layer on map
791
792 // Create plated copper. Skip it in the picking scene: the overlay goes nowhere and
793 // blocks cross-probe on the pads under it.
794 if( m_boardAdapter.m_Cfg->m_Render.differentiate_plated_copper && !aOnlyLoadCopperAndShapes )
795 {
796 createItemsFromContainer( m_boardAdapter.GetPlatedPadsFront(), F_Cu, &m_materials.m_Copper,
797 m_boardAdapter.m_CopperColor,
798 m_boardAdapter.GetFrontCopperThickness() * 0.1f );
799
800 createItemsFromContainer( m_boardAdapter.GetPlatedPadsBack(), B_Cu, &m_materials.m_Copper,
801 m_boardAdapter.m_CopperColor,
802 -m_boardAdapter.GetBackCopperThickness() * 0.1f );
803 }
804
805 if( !aOnlyLoadCopperAndShapes )
806 {
807 // Add Mask layer
808 // Solder mask layers are "negative" layers so the elements that we have in the container
809 // should remove the board outline. We will check for all objects in the outline if it
810 // intersects any object in the layer container and also any hole.
811 if( ( layerFlags.test( LAYER_3D_SOLDERMASK_TOP )
812 || layerFlags.test( LAYER_3D_SOLDERMASK_BOTTOM ) )
813 && !m_outlineBoard2dObjects->GetList().empty() )
814 {
815 const MATERIAL* materialLayer = &m_materials.m_SolderMask;
816
817 for( const std::pair<const PCB_LAYER_ID, BVH_CONTAINER_2D*>& entry :
818 m_boardAdapter.GetLayerMap() )
819 {
820 const PCB_LAYER_ID layer_id = entry.first;
821 const BVH_CONTAINER_2D* container2d = entry.second;
822
823 // Only process layers that exist
824 if( !container2d )
825 continue;
826
827 // Only get the Solder mask layers (and only if the board has them)
828 if( layer_id == F_Mask && !layerFlags.test( LAYER_3D_SOLDERMASK_TOP ) )
829 continue;
830
831 if( layer_id == B_Mask && !layerFlags.test( LAYER_3D_SOLDERMASK_BOTTOM ) )
832 continue;
833
834 // Only Mask layers are processed here because they are negative layers
835 if( layer_id != F_Mask && layer_id != B_Mask )
836 continue;
837
838 SFVEC3F layerColor;
839
840 if( layer_id == B_Mask )
841 layerColor = m_boardAdapter.m_SolderMaskColorBot;
842 else
843 layerColor = m_boardAdapter.m_SolderMaskColorTop;
844
845 const float zLayerMin = m_boardAdapter.GetLayerBottomZPos( layer_id );
846 const float zLayerMax = m_boardAdapter.GetLayerTopZPos( layer_id );
847
848 // Get the outline board objects
849 for( const OBJECT_2D* object2d_A : m_outlineBoard2dObjects->GetList() )
850 {
851 std::vector<const OBJECT_2D*>* object2d_B = new std::vector<const OBJECT_2D*>();
852
853 // Check if there are any THT that intersects this outline object part
854 if( !m_boardAdapter.GetTH_ODs().GetList().empty() )
855 {
856 const BVH_CONTAINER_2D& throughHoles = m_boardAdapter.GetTH_ODs();
857 CONST_LIST_OBJECT2D intersecting;
858
859 throughHoles.GetIntersectingObjects( object2d_A->GetBBox(), intersecting );
860
861 for( const OBJECT_2D* hole : intersecting )
862 {
863 if( object2d_A->Intersects( hole->GetBBox() ) )
864 object2d_B->push_back( hole );
865 }
866 }
867
868 // Check if there are any objects in the layer to subtract with the current
869 // object
870 if( !container2d->GetList().empty() )
871 {
872 CONST_LIST_OBJECT2D intersecting;
873
874 container2d->GetIntersectingObjects( object2d_A->GetBBox(), intersecting );
875
876 for( const OBJECT_2D* obj : intersecting )
877 object2d_B->push_back( obj );
878 }
879
880 if( object2d_B->empty() )
881 {
882 delete object2d_B;
883 object2d_B = CSGITEM_EMPTY;
884 }
885
886 if( object2d_B == CSGITEM_EMPTY )
887 {
888#if 0
889 createObject( m_objectContainer, object2d_A, zLayerMin, zLayerMax,
890 materialLayer, layerColor );
891#else
892 LAYER_ITEM* objPtr = new LAYER_ITEM( object2d_A, zLayerMin, zLayerMax );
893
894 objPtr->SetMaterial( materialLayer );
895 objPtr->SetColor( ConvertSRGBToLinear( layerColor ) );
896
897 m_objectContainer.Add( objPtr );
898#endif
899 }
900 else
901 {
902 LAYER_ITEM_2D* itemCSG2d = new LAYER_ITEM_2D( object2d_A, object2d_B,
904 object2d_A->GetBoardItem() );
905
906 m_containerWithObjectsToDelete.Add( itemCSG2d );
907
908 LAYER_ITEM* objPtr = new LAYER_ITEM( itemCSG2d, zLayerMin, zLayerMax );
909 objPtr->SetMaterial( materialLayer );
910 objPtr->SetColor( ConvertSRGBToLinear( layerColor ) );
911
912 m_objectContainer.Add( objPtr );
913 }
914 }
915 }
916 }
917
919 }
920
921#ifdef PRINT_STATISTICS_3D_VIEWER
922 int64_t stats_endConvertTime = GetRunningMicroSecs();
923 int64_t stats_startLoad3DmodelsTime = stats_endConvertTime;
924#endif
925
927 {
928 if( aOnlyLoadCopperAndShapes )
929 m_activityReporter->Report( _( "Building hit-test scene: 3D models..." ) );
930 else
931 m_activityReporter->Report( _( "Loading 3D models..." ) );
932 }
933
934 load3DModels( m_objectContainer, aOnlyLoadCopperAndShapes, aStop );
935
936 if( aStop.stop_requested() )
937 return;
938
939#ifdef PRINT_STATISTICS_3D_VIEWER
940 int64_t stats_endLoad3DmodelsTime = GetRunningMicroSecs();
941#endif
942
943 if( !aOnlyLoadCopperAndShapes )
944 {
945 // Add floor
946 if( m_boardAdapter.m_Cfg->m_Render.raytrace_backfloor )
947 {
948 BBOX_3D boardBBox = m_boardAdapter.GetBBox();
949
950 if( boardBBox.IsInitialized() )
951 {
952 boardBBox.Scale( 3.0f );
953
954 if( m_objectContainer.GetList().size() > 0 )
955 {
956 BBOX_3D containerBBox = m_objectContainer.GetBBox();
957
958 containerBBox.Scale( 1.3f );
959
960 const SFVEC3F centerBBox = containerBBox.GetCenter();
961
962 // Floor triangles
963 const float minZ = glm::min( containerBBox.Min().z, boardBBox.Min().z );
964
965 const SFVEC3F v1 =
966 SFVEC3F( -RANGE_SCALE_3D * 4.0f, -RANGE_SCALE_3D * 4.0f, minZ )
967 + SFVEC3F( centerBBox.x, centerBBox.y, 0.0f );
968
969 const SFVEC3F v3 =
970 SFVEC3F( +RANGE_SCALE_3D * 4.0f, +RANGE_SCALE_3D * 4.0f, minZ )
971 + SFVEC3F( centerBBox.x, centerBBox.y, 0.0f );
972
973 const SFVEC3F v2 = SFVEC3F( v1.x, v3.y, v1.z );
974 const SFVEC3F v4 = SFVEC3F( v3.x, v1.y, v1.z );
975
976 SFVEC3F floorColor = ConvertSRGBToLinear( m_boardAdapter.m_BgColorTop );
977
978 TRIANGLE* newTriangle1 = new TRIANGLE( v1, v2, v3 );
979 TRIANGLE* newTriangle2 = new TRIANGLE( v3, v4, v1 );
980
981 m_objectContainer.Add( newTriangle1 );
982 m_objectContainer.Add( newTriangle2 );
983
984 newTriangle1->SetMaterial( &m_materials.m_Floor );
985 newTriangle2->SetMaterial( &m_materials.m_Floor );
986
987 newTriangle1->SetColor( floorColor );
988 newTriangle2->SetColor( floorColor );
989
990 // Ceiling triangles
991 const float maxZ = glm::max( containerBBox.Max().z, boardBBox.Max().z );
992
993 const SFVEC3F v5 = SFVEC3F( v1.x, v1.y, maxZ );
994 const SFVEC3F v6 = SFVEC3F( v2.x, v2.y, maxZ );
995 const SFVEC3F v7 = SFVEC3F( v3.x, v3.y, maxZ );
996 const SFVEC3F v8 = SFVEC3F( v4.x, v4.y, maxZ );
997
998 TRIANGLE* newTriangle3 = new TRIANGLE( v7, v6, v5 );
999 TRIANGLE* newTriangle4 = new TRIANGLE( v5, v8, v7 );
1000
1001 m_objectContainer.Add( newTriangle3 );
1002 m_objectContainer.Add( newTriangle4 );
1003
1004 newTriangle3->SetMaterial( &m_materials.m_Floor );
1005 newTriangle4->SetMaterial( &m_materials.m_Floor );
1006
1007 newTriangle3->SetColor( floorColor );
1008 newTriangle4->SetColor( floorColor );
1009 }
1010 }
1011 }
1012
1013 // Init initial lights
1014 for( LIGHT* light : m_lights )
1015 delete light;
1016
1017 m_lights.clear();
1018
1019 auto IsColorZero =
1020 []( const SFVEC3F& aSource )
1021 {
1022 return ( ( aSource.r < ( 1.0f / 255.0f ) ) && ( aSource.g < ( 1.0f / 255.0f ) )
1023 && ( aSource.b < ( 1.0f / 255.0f ) ) );
1024 };
1025
1026 SFVEC3F cameraLightColor =
1027 m_boardAdapter.GetColor( m_boardAdapter.m_Cfg->m_Render.raytrace_lightColorCamera );
1028 SFVEC3F topLightColor =
1029 m_boardAdapter.GetColor( m_boardAdapter.m_Cfg->m_Render.raytrace_lightColorTop );
1030 SFVEC3F bottomLightColor =
1031 m_boardAdapter.GetColor( m_boardAdapter.m_Cfg->m_Render.raytrace_lightColorBottom );
1032
1033 m_cameraLight = new DIRECTIONAL_LIGHT( SFVEC3F( 0.0f, 0.0f, 0.0f ), cameraLightColor );
1034 m_cameraLight->SetCastShadows( false );
1035
1036 if( !IsColorZero( cameraLightColor ) )
1037 m_lights.push_back( m_cameraLight );
1038
1039 const SFVEC3F& boardCenter = m_boardAdapter.GetBBox().GetCenter();
1040
1041 if( !IsColorZero( topLightColor ) )
1042 {
1043 m_lights.push_back( new POINT_LIGHT( SFVEC3F( boardCenter.x, boardCenter.y,
1044 +RANGE_SCALE_3D * 2.0f ),
1045 topLightColor ) );
1046 }
1047
1048 if( !IsColorZero( bottomLightColor ) )
1049 {
1050 m_lights.push_back( new POINT_LIGHT( SFVEC3F( boardCenter.x, boardCenter.y,
1051 -RANGE_SCALE_3D * 2.0f ),
1052 bottomLightColor ) );
1053 }
1054
1055 for( size_t i = 0; i < m_boardAdapter.m_Cfg->m_Render.raytrace_lightColor.size(); ++i )
1056 {
1057 SFVEC3F lightColor =
1058 m_boardAdapter.GetColor( m_boardAdapter.m_Cfg->m_Render.raytrace_lightColor[i] );
1059
1060 if( !IsColorZero( lightColor ) )
1061 {
1062 const SFVEC2F sc = m_boardAdapter.GetSphericalCoord( i );
1063
1064 m_lights.push_back( new DIRECTIONAL_LIGHT(
1065 SphericalToCartesian( glm::pi<float>() * sc.x, glm::pi<float>() * sc.y ),
1066 lightColor ) );
1067 }
1068 }
1069 }
1070
1071 // Set min. and max. zoom range. This doesn't really fit here, but moving this outside of this
1072 // class would require reimplementing bounding box calculation (feel free to do this if you
1073 // have time and patience).
1074 if( m_objectContainer.GetList().size() > 0 )
1075 {
1076 float ratio =
1077 std::max( 1.0f, m_objectContainer.GetBBox().GetMaxDimension() / RANGE_SCALE_3D );
1078
1079 float max_zoom = CAMERA::DEFAULT_MAX_ZOOM * ratio;
1080 float min_zoom = static_cast<float>( MIN_DISTANCE_IU * m_boardAdapter.BiuTo3dUnits()
1081 / -m_camera.GetCameraInitPos().z );
1082
1083 if( min_zoom > max_zoom )
1084 std::swap( min_zoom, max_zoom );
1085
1086 float zoom_ratio = max_zoom / min_zoom;
1087
1088 // Set the minimum number of zoom 'steps' between max and min.
1089 int steps = 3 * 3;
1090 steps -= static_cast<int>( ceil( log( zoom_ratio ) / log( 1.26f ) ) );
1091 steps = std::max( steps, 0 );
1092
1093 // Resize max and min zoom to accomplish the number of steps.
1094 float increased_zoom = pow( 1.26f, steps / 2 );
1095 max_zoom *= increased_zoom;
1096 min_zoom /= increased_zoom;
1097
1098 if( steps & 1 )
1099 min_zoom /= 1.26f;
1100
1101 min_zoom = std::min( min_zoom, 1.0f );
1102
1103 m_camera.SetMaxZoom( max_zoom );
1104 m_camera.SetMinZoom( min_zoom );
1105 }
1106
1107 if( aStop.stop_requested() )
1108 return;
1109
1110 // Create an accelerator
1111 std::unique_ptr<ACCELERATOR_3D> accelerator =
1112 std::make_unique<BVH_PBRT>( m_objectContainer, 8, SPLITMETHOD::MIDDLE );
1113
1114 {
1115 std::lock_guard<std::mutex> lock( m_hitTestMutex );
1116 m_accelerator = std::move( accelerator );
1117 }
1118
1119 if( m_activityReporter )
1120 {
1121 // Calculation time in seconds
1122 double calculation_time = (double) ( GetRunningMicroSecs() - stats_startReloadTime ) / 1e6;
1123
1124 if( aOnlyLoadCopperAndShapes )
1125 {
1126 m_activityReporter->Report( wxString::Format( _( "Hit-test scene ready in %.3f s" ), calculation_time ) );
1127 }
1128 else
1129 {
1130 m_activityReporter->Report( wxString::Format( _( "Reload time %.3f s" ), calculation_time ) );
1131 }
1132 }
1133}
1134
1135
1137 const SFVEC2F& aCenter,
1138 float aInnerRadius, float aDepth,
1139 float aSurfaceZ, bool aIsFront )
1140{
1141 const float platingThickness = m_boardAdapter.GetHolePlatingThickness()
1142 * m_boardAdapter.BiuTo3dUnits();
1143
1144 if( platingThickness <= 0.0f || aInnerRadius <= 0.0f || aDepth <= 0.0f )
1145 return;
1146
1147 const float outerRadius = aInnerRadius + platingThickness;
1148 const float zOther = aIsFront ? ( aSurfaceZ - aDepth ) : ( aSurfaceZ + aDepth );
1149 const float zMin = std::min( aSurfaceZ, zOther );
1150 const float zMax = std::max( aSurfaceZ, zOther );
1151
1152 RING_2D* ring = new RING_2D( aCenter, aInnerRadius, outerRadius, aSource );
1154
1155 LAYER_ITEM* objPtr = new LAYER_ITEM( ring, zMin, zMax );
1156 objPtr->SetMaterial( &m_materials.m_Copper );
1157 objPtr->SetColor( ConvertSRGBToLinear( m_boardAdapter.m_CopperColor ) );
1158
1159 m_objectContainer.Add( objPtr );
1160}
1161
1162
1164 float aTopInnerRadius,
1165 float aBottomInnerRadius,
1166 float aSurfaceZ, float aDepth,
1167 bool aIsFront )
1168{
1169 const float platingThickness = m_boardAdapter.GetHolePlatingThickness()
1170 * m_boardAdapter.BiuTo3dUnits();
1171
1172 if( platingThickness <= 0.0f || aTopInnerRadius <= 0.0f || aBottomInnerRadius <= 0.0f
1173 || aDepth <= 0.0f )
1174 {
1175 return;
1176 }
1177
1178 const float topOuterRadius = aTopInnerRadius + platingThickness;
1179 const float bottomOuterRadius = aBottomInnerRadius + platingThickness;
1180
1181 const float zOther = aIsFront ? ( aSurfaceZ - aDepth ) : ( aSurfaceZ + aDepth );
1182 const float zTop = std::max( aSurfaceZ, zOther );
1183 const float zBot = std::min( aSurfaceZ, zOther );
1184
1185 if( topOuterRadius <= 0.0f || bottomOuterRadius <= 0.0f )
1186 return;
1187
1188 const float largestDiameter = 2.0f * std::max( aTopInnerRadius, aBottomInnerRadius );
1189 unsigned int segments = std::max( 12u, m_boardAdapter.GetCircleSegmentCount( largestDiameter ) );
1190
1191 const SFVEC3F copperColor = ConvertSRGBToLinear( m_boardAdapter.m_CopperColor );
1192
1193 auto addQuad = [&]( const SFVEC3F& p0, const SFVEC3F& p1,
1194 const SFVEC3F& p2, const SFVEC3F& p3 )
1195 {
1196 TRIANGLE* tri1 = new TRIANGLE( p0, p1, p2 );
1197 TRIANGLE* tri2 = new TRIANGLE( p0, p2, p3 );
1198
1199 tri1->SetMaterial( &m_materials.m_Copper );
1200 tri2->SetMaterial( &m_materials.m_Copper );
1201 tri1->SetColor( copperColor );
1202 tri2->SetColor( copperColor );
1203
1204 m_objectContainer.Add( tri1 );
1205 m_objectContainer.Add( tri2 );
1206 };
1207
1208 auto makePoint = [&]( float radius, float angle, float z )
1209 {
1210 return SFVEC3F( aCenter.x + cosf( angle ) * radius,
1211 aCenter.y + sinf( angle ) * radius,
1212 z );
1213 };
1214
1215 const float step = 2.0f * glm::pi<float>() / (float) segments;
1216
1217 SFVEC3F innerTopPrev = makePoint( aTopInnerRadius, 0.0f, zTop );
1218 SFVEC3F innerBotPrev = makePoint( aBottomInnerRadius, 0.0f, zBot );
1219 SFVEC3F outerTopPrev = makePoint( topOuterRadius, 0.0f, zTop );
1220 SFVEC3F outerBotPrev = makePoint( bottomOuterRadius, 0.0f, zBot );
1221
1222 const SFVEC3F innerTopFirst = innerTopPrev;
1223 const SFVEC3F innerBotFirst = innerBotPrev;
1224 const SFVEC3F outerTopFirst = outerTopPrev;
1225 const SFVEC3F outerBotFirst = outerBotPrev;
1226
1227 for( unsigned int i = 1; i <= segments; ++i )
1228 {
1229 const float angle = ( i == segments ) ? 0.0f : step * i;
1230
1231 const SFVEC3F innerTopCurr = ( i == segments ) ? innerTopFirst
1232 : makePoint( aTopInnerRadius, angle, zTop );
1233 const SFVEC3F innerBotCurr = ( i == segments ) ? innerBotFirst
1234 : makePoint( aBottomInnerRadius, angle, zBot );
1235 const SFVEC3F outerTopCurr = ( i == segments ) ? outerTopFirst
1236 : makePoint( topOuterRadius, angle, zTop );
1237 const SFVEC3F outerBotCurr = ( i == segments ) ? outerBotFirst
1238 : makePoint( bottomOuterRadius, angle, zBot );
1239
1240 // Inner wall
1241 addQuad( innerTopPrev, innerTopCurr, innerBotCurr, innerBotPrev );
1242
1243 // Outer wall
1244 addQuad( outerTopPrev, outerBotPrev, outerBotCurr, outerTopCurr );
1245
1246 // Top rim
1247 addQuad( outerTopPrev, outerTopCurr, innerTopCurr, innerTopPrev );
1248
1249 // Bottom rim
1250 addQuad( outerBotPrev, innerBotPrev, innerBotCurr, outerBotCurr );
1251
1252 innerTopPrev = innerTopCurr;
1253 innerBotPrev = innerBotCurr;
1254 outerTopPrev = outerTopCurr;
1255 outerBotPrev = outerBotCurr;
1256 }
1257}
1258
1259
1261{
1262 if( !m_boardAdapter.GetBoard() )
1263 return;
1264
1265 const float unitScale = m_boardAdapter.BiuTo3dUnits();
1266 const int platingThickness = m_boardAdapter.GetHolePlatingThickness();
1267 const float platingThickness3d = platingThickness * unitScale;
1268 const SFVEC3F boardColor = ConvertSRGBToLinear( m_boardAdapter.m_BoardBodyColor );
1269
1270 const float boardZTop = m_boardAdapter.GetLayerBottomZPos( F_Cu );
1271 const float boardZBot = m_boardAdapter.GetLayerBottomZPos( B_Cu );
1272
1273 // Process vias for backdrill and post-machining plugs
1274 for( const PCB_TRACK* track : m_boardAdapter.GetBoard()->Tracks() )
1275 {
1276 if( track->Type() != PCB_VIA_T )
1277 continue;
1278
1279 const PCB_VIA* via = static_cast<const PCB_VIA*>( track );
1280
1281 const float holeDiameter = via->GetDrillValue() * unitScale;
1282 const float holeInnerRadius = holeDiameter / 2.0f;
1283 const float holeOuterRadius = holeInnerRadius + platingThickness3d;
1284 const SFVEC2F center( via->GetStart().x * unitScale, -via->GetStart().y * unitScale );
1285
1286 PCB_LAYER_ID topLayer, bottomLayer;
1287 via->LayerPair( &topLayer, &bottomLayer );
1288
1289 const float viaZTop = m_boardAdapter.GetLayerBottomZPos( topLayer );
1290 const float viaZBot = m_boardAdapter.GetLayerBottomZPos( bottomLayer );
1291
1292 // Handle backdrill plugs
1293 for( const PADSTACK::DRILL_PROPS& backdrill : { via->Padstack().SecondaryDrill(),
1294 via->Padstack().TertiaryDrill() } )
1295 {
1296 const float backdrillRadius = backdrill.size.x * 0.5f * unitScale;
1297
1298 if( backdrillRadius > holeOuterRadius )
1299 {
1300 float plugZTop, plugZBot;
1301
1302 if( backdrill.start == F_Cu )
1303 {
1304 plugZTop = m_boardAdapter.GetLayerTopZPos( F_Cu );
1305 float mustCutZ = m_boardAdapter.GetLayerBottomZPos( backdrill.end );
1306
1307 // backdrill.end is the must-cut layer; the depth of the backdrill is 1/2-way through
1308 // the next dielectric layer.
1309 LAYER_RANGE copperLayers( backdrill.end, B_Cu, m_boardAdapter.GetBoard()->BoardCopperLayerCount() );
1310 auto it = ++copperLayers.begin();
1311
1312 if( it == copperLayers.end() )
1313 {
1314 plugZBot = mustCutZ;
1315 }
1316 else
1317 {
1318 float mustNotCutZ = m_boardAdapter.GetLayerTopZPos( *it );
1319 plugZBot = ( mustCutZ + mustNotCutZ ) / 2;
1320 }
1321 }
1322 else
1323 {
1324 plugZBot = m_boardAdapter.GetLayerBottomZPos( B_Cu );
1325 float mustCutZ = m_boardAdapter.GetLayerTopZPos( backdrill.end );
1326
1327 // backdrill.end is the must-cut layer; the depth of the backdrill is 1/2-way through
1328 // the next dielectric layer.
1329 LAYER_RANGE copperLayers( B_Cu, backdrill.end, m_boardAdapter.GetBoard()->BoardCopperLayerCount() );
1330 auto it = ++copperLayers.begin();
1331
1332 if( it == copperLayers.end() )
1333 {
1334 plugZTop = mustCutZ;
1335 }
1336 else
1337 {
1338 float mustNotCutZ = m_boardAdapter.GetLayerBottomZPos( *it );
1339 plugZTop = (mustCutZ + mustNotCutZ ) / 2;
1340 }
1341 }
1342
1343 if( plugZTop > plugZBot )
1344 {
1345 // Create a ring from holeOuterRadius to backdrillRadius
1346 RING_2D* ring = new RING_2D( center, holeOuterRadius, backdrillRadius, *via );
1348
1349 LAYER_ITEM* objPtr = new LAYER_ITEM( ring, plugZBot, plugZTop );
1350 objPtr->SetMaterial( &m_materials.m_EpoxyBoard );
1351 objPtr->SetColor( boardColor );
1352 m_objectContainer.Add( objPtr );
1353 }
1354 }
1355 }
1356
1357 // Handle front post-machining plugs
1358 const auto frontMode = via->GetFrontPostMachining();
1359
1360 if( frontMode.has_value()
1362 && frontMode.value() != PAD_DRILL_POST_MACHINING_MODE::UNKNOWN )
1363 {
1364 const float frontRadius = via->GetFrontPostMachiningSize() * 0.5f * unitScale;
1365 const float frontDepth = via->GetFrontPostMachiningDepth() * unitScale;
1366
1367 if( frontRadius > holeOuterRadius && frontDepth > 0 )
1368 {
1369 // Plug goes from bottom of post-machining to bottom of via
1370 const float pmBottomZ = viaZTop - frontDepth;
1371 const float plugZBot = viaZBot;
1372
1373 if( pmBottomZ > plugZBot )
1374 {
1375 if( frontMode.value() == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK )
1376 {
1377 // For countersink, use a frustum (truncated cone)
1378 EDA_ANGLE angle( via->GetFrontPostMachiningAngle(), TENTHS_OF_A_DEGREE_T );
1379 float angleRad = angle.AsRadians();
1380 if( angleRad < 0.01f )
1381 angleRad = 0.01f;
1382
1383 float radialDiff = frontRadius - holeOuterRadius;
1384 float innerHeight = radialDiff / tanf( angleRad );
1385 float totalHeight = pmBottomZ - plugZBot;
1386
1387 if( innerHeight > totalHeight )
1388 innerHeight = totalHeight;
1389
1390 float zInnerTop = plugZBot + innerHeight;
1391
1392 // Create frustum from holeOuterRadius at zInnerTop to frontRadius at pmBottomZ
1393 TRUNCATED_CONE* frustum = new TRUNCATED_CONE( center, zInnerTop, pmBottomZ,
1394 holeOuterRadius, frontRadius );
1395 frustum->SetMaterial( &m_materials.m_EpoxyBoard );
1396 frustum->SetColor( boardColor );
1397 m_objectContainer.Add( frustum );
1398
1399 // If there's a cylindrical portion below the cone
1400 if( zInnerTop > plugZBot )
1401 {
1402 RING_2D* ring = new RING_2D( center, holeOuterRadius, frontRadius, *via );
1404
1405 LAYER_ITEM* objPtr = new LAYER_ITEM( ring, plugZBot, zInnerTop );
1406 objPtr->SetMaterial( &m_materials.m_EpoxyBoard );
1407 objPtr->SetColor( boardColor );
1408 m_objectContainer.Add( objPtr );
1409 }
1410 }
1411 else
1412 {
1413 RING_2D* ring = new RING_2D( center, holeOuterRadius, frontRadius, *via );
1415
1416 LAYER_ITEM* objPtr = new LAYER_ITEM( ring, plugZBot, pmBottomZ );
1417 objPtr->SetMaterial( &m_materials.m_EpoxyBoard );
1418 objPtr->SetColor( boardColor );
1419 m_objectContainer.Add( objPtr );
1420 }
1421 }
1422 }
1423 }
1424
1425 // Handle back post-machining plugs
1426 const auto backMode = via->GetBackPostMachining();
1427
1428 if( backMode.has_value()
1430 && backMode.value() != PAD_DRILL_POST_MACHINING_MODE::UNKNOWN )
1431 {
1432 const float backRadius = via->GetBackPostMachiningSize() * 0.5f * unitScale;
1433 const float backDepth = via->GetBackPostMachiningDepth() * unitScale;
1434
1435 if( backRadius > holeOuterRadius && backDepth > 0 )
1436 {
1437 // Plug goes from top of via to top of post-machining
1438 const float plugZTop = viaZTop;
1439 const float pmTopZ = viaZBot + backDepth;
1440
1441 if( plugZTop > pmTopZ )
1442 {
1443 if( backMode.value() == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK )
1444 {
1445 // For countersink, use a frustum (truncated cone)
1446 EDA_ANGLE angle( via->GetBackPostMachiningAngle(), TENTHS_OF_A_DEGREE_T );
1447 float angleRad = angle.AsRadians();
1448 if( angleRad < 0.01f )
1449 angleRad = 0.01f;
1450
1451 float radialDiff = backRadius - holeOuterRadius;
1452 float innerHeight = radialDiff / tanf( angleRad );
1453 float totalHeight = plugZTop - pmTopZ;
1454
1455 if( innerHeight > totalHeight )
1456 innerHeight = totalHeight;
1457
1458 float zInnerBot = plugZTop - innerHeight;
1459
1460 // Create frustum from holeOuterRadius at zInnerBot to backRadius at pmTopZ
1461 TRUNCATED_CONE* frustum = new TRUNCATED_CONE( center, pmTopZ, zInnerBot,
1462 backRadius, holeOuterRadius );
1463 frustum->SetMaterial( &m_materials.m_EpoxyBoard );
1464 frustum->SetColor( boardColor );
1465 m_objectContainer.Add( frustum );
1466
1467 // If there's a cylindrical portion above the cone
1468 if( zInnerBot < plugZTop )
1469 {
1470 RING_2D* ring = new RING_2D( center, holeOuterRadius, backRadius, *via );
1472
1473 LAYER_ITEM* objPtr = new LAYER_ITEM( ring, zInnerBot, plugZTop );
1474 objPtr->SetMaterial( &m_materials.m_EpoxyBoard );
1475 objPtr->SetColor( boardColor );
1476 m_objectContainer.Add( objPtr );
1477 }
1478 }
1479 else
1480 {
1481 RING_2D* ring = new RING_2D( center, holeOuterRadius, backRadius, *via );
1483
1484 LAYER_ITEM* objPtr = new LAYER_ITEM( ring, pmTopZ, plugZTop );
1485 objPtr->SetMaterial( &m_materials.m_EpoxyBoard );
1486 objPtr->SetColor( boardColor );
1487 m_objectContainer.Add( objPtr );
1488 }
1489 }
1490 }
1491 }
1492 }
1493
1494 // Process pads for post-machining plugs
1495 for( const FOOTPRINT* footprint : m_boardAdapter.GetBoard()->Footprints() )
1496 {
1497 for( const PAD* pad : footprint->Pads() )
1498 {
1499 if( pad->GetAttribute() == PAD_ATTRIB::NPTH )
1500 continue;
1501
1502 if( !pad->HasHole() )
1503 continue;
1504
1505 if( pad->GetDrillShape() != PAD_DRILL_SHAPE::CIRCLE )
1506 continue;
1507
1508 const SFVEC2F padCenter( pad->GetPosition().x * unitScale,
1509 -pad->GetPosition().y * unitScale );
1510 const float holeInnerRadius = pad->GetDrillSize().x * 0.5f * unitScale;
1511 const float holeOuterRadius = holeInnerRadius + platingThickness3d;
1512
1513 const float padZTop = boardZTop;
1514 const float padZBot = boardZBot;
1515
1516 // Handle front post-machining plugs for pads
1517 const auto frontMode = pad->GetFrontPostMachining();
1518
1519 if( frontMode.has_value()
1521 && frontMode.value() != PAD_DRILL_POST_MACHINING_MODE::UNKNOWN )
1522 {
1523 const float frontRadius = pad->GetFrontPostMachiningSize() * 0.5f * unitScale;
1524 const float frontDepth = pad->GetFrontPostMachiningDepth() * unitScale;
1525
1526 if( frontRadius > holeOuterRadius && frontDepth > 0 )
1527 {
1528 const float pmBottomZ = padZTop - frontDepth;
1529 const float plugZBot = padZBot;
1530
1531 if( pmBottomZ > plugZBot )
1532 {
1533 if( frontMode.value() == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK )
1534 {
1535 // For countersink, use a frustum (truncated cone)
1536 EDA_ANGLE angle( pad->GetFrontPostMachiningAngle(), TENTHS_OF_A_DEGREE_T );
1537 float angleRad = angle.AsRadians();
1538 if( angleRad < 0.01f )
1539 angleRad = 0.01f;
1540
1541 float radialDiff = frontRadius - holeOuterRadius;
1542 float innerHeight = radialDiff / tanf( angleRad );
1543 float totalHeight = pmBottomZ - plugZBot;
1544
1545 if( innerHeight > totalHeight )
1546 innerHeight = totalHeight;
1547
1548 float zInnerTop = plugZBot + innerHeight;
1549
1550 // Create frustum from holeOuterRadius at zInnerTop to frontRadius at pmBottomZ
1551 TRUNCATED_CONE* frustum = new TRUNCATED_CONE( padCenter, zInnerTop, pmBottomZ,
1552 holeOuterRadius, frontRadius );
1553 frustum->SetMaterial( &m_materials.m_EpoxyBoard );
1554 frustum->SetColor( boardColor );
1555 m_objectContainer.Add( frustum );
1556
1557 // If there's a cylindrical portion below the cone
1558 if( zInnerTop > plugZBot )
1559 {
1560 RING_2D* ring = new RING_2D( padCenter, holeOuterRadius, frontRadius, *pad );
1562
1563 LAYER_ITEM* objPtr = new LAYER_ITEM( ring, plugZBot, zInnerTop );
1564 objPtr->SetMaterial( &m_materials.m_EpoxyBoard );
1565 objPtr->SetColor( boardColor );
1566 m_objectContainer.Add( objPtr );
1567 }
1568 }
1569 else
1570 {
1571 RING_2D* ring = new RING_2D( padCenter, holeOuterRadius, frontRadius, *pad );
1573
1574 LAYER_ITEM* objPtr = new LAYER_ITEM( ring, plugZBot, pmBottomZ );
1575 objPtr->SetMaterial( &m_materials.m_EpoxyBoard );
1576 objPtr->SetColor( boardColor );
1577 m_objectContainer.Add( objPtr );
1578 }
1579 }
1580 }
1581 }
1582
1583 // Handle back post-machining plugs for pads
1584 const auto backMode = pad->GetBackPostMachining();
1585
1586 if( backMode.has_value()
1588 && backMode.value() != PAD_DRILL_POST_MACHINING_MODE::UNKNOWN )
1589 {
1590 const float backRadius = pad->GetBackPostMachiningSize() * 0.5f * unitScale;
1591 const float backDepth = pad->GetBackPostMachiningDepth() * unitScale;
1592
1593 if( backRadius > holeOuterRadius && backDepth > 0 )
1594 {
1595 const float plugZTop = padZTop;
1596 const float pmTopZ = padZBot + backDepth;
1597
1598 if( plugZTop > pmTopZ )
1599 {
1600 if( backMode.value() == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK )
1601 {
1602 // For countersink, use a frustum (truncated cone)
1603 EDA_ANGLE angle( pad->GetBackPostMachiningAngle(), TENTHS_OF_A_DEGREE_T );
1604 float angleRad = angle.AsRadians();
1605 if( angleRad < 0.01f )
1606 angleRad = 0.01f;
1607
1608 float radialDiff = backRadius - holeOuterRadius;
1609 float innerHeight = radialDiff / tanf( angleRad );
1610 float totalHeight = plugZTop - pmTopZ;
1611
1612 if( innerHeight > totalHeight )
1613 innerHeight = totalHeight;
1614
1615 float zInnerBot = plugZTop - innerHeight;
1616
1617 // Create frustum from holeOuterRadius at zInnerBot to backRadius at pmTopZ
1618 TRUNCATED_CONE* frustum = new TRUNCATED_CONE( padCenter, pmTopZ, zInnerBot,
1619 backRadius, holeOuterRadius );
1620 frustum->SetMaterial( &m_materials.m_EpoxyBoard );
1621 frustum->SetColor( boardColor );
1622 m_objectContainer.Add( frustum );
1623
1624 // If there's a cylindrical portion above the cone
1625 if( zInnerBot < plugZTop )
1626 {
1627 RING_2D* ring = new RING_2D( padCenter, holeOuterRadius, backRadius, *pad );
1629
1630 LAYER_ITEM* objPtr = new LAYER_ITEM( ring, zInnerBot, plugZTop );
1631 objPtr->SetMaterial( &m_materials.m_EpoxyBoard );
1632 objPtr->SetColor( boardColor );
1633 m_objectContainer.Add( objPtr );
1634 }
1635 }
1636 else
1637 {
1638 RING_2D* ring = new RING_2D( padCenter, holeOuterRadius, backRadius, *pad );
1640
1641 LAYER_ITEM* objPtr = new LAYER_ITEM( ring, pmTopZ, plugZTop );
1642 objPtr->SetMaterial( &m_materials.m_EpoxyBoard );
1643 objPtr->SetColor( boardColor );
1644 m_objectContainer.Add( objPtr );
1645 }
1646 }
1647 }
1648 }
1649 }
1650 }
1651}
1652
1653
1655{
1656 if( !m_boardAdapter.m_Cfg->m_Render.show_plated_barrels )
1657 return;
1658
1659 PCB_LAYER_ID top_layer, bottom_layer;
1660 int radiusBUI = ( aVia->GetDrillValue() / 2 );
1661
1662 aVia->LayerPair( &top_layer, &bottom_layer );
1663
1664 float frontDepth = 0.0f;
1665 float backDepth = 0.0f;
1666
1668 frontDepth = aVia->Padstack().FrontPostMachining().depth * m_boardAdapter.BiuTo3dUnits();
1669
1671 backDepth = aVia->Padstack().BackPostMachining().depth * m_boardAdapter.BiuTo3dUnits();
1672
1673 float topZ = m_boardAdapter.GetLayerBottomZPos( top_layer )
1674 + m_boardAdapter.GetFrontCopperThickness() - frontDepth;
1675
1676 float botZ = m_boardAdapter.GetLayerBottomZPos( bottom_layer )
1677 - m_boardAdapter.GetBackCopperThickness() + backDepth;
1678
1679 const float unitScale = m_boardAdapter.BiuTo3dUnits();
1680 const SFVEC2F center = SFVEC2F( aVia->GetStart().x * unitScale, -aVia->GetStart().y * unitScale );
1681
1682 RING_2D* ring = new RING_2D( center, radiusBUI * unitScale,
1683 ( radiusBUI + m_boardAdapter.GetHolePlatingThickness() ) * unitScale, *aVia );
1684
1686
1687 LAYER_ITEM* objPtr = new LAYER_ITEM( ring, topZ, botZ );
1688
1689 objPtr->SetMaterial( &m_materials.m_Copper );
1690 objPtr->SetColor( ConvertSRGBToLinear( m_boardAdapter.m_CopperColor ) );
1691
1692 m_objectContainer.Add( objPtr );
1693
1694 const float holeInnerRadius = radiusBUI * unitScale;
1695 const float frontSurface = topZ + frontDepth;
1696 const float backSurface = botZ - backDepth;
1697
1698 const PAD_DRILL_POST_MACHINING_MODE frontMode =
1700 const float frontRadius = 0.5f * aVia->GetFrontPostMachiningSize() * unitScale;
1701
1702 if( frontDepth > 0.0f && frontRadius > holeInnerRadius )
1703 {
1705 {
1706 addCounterborePlating( *aVia, center, frontRadius, frontDepth, frontSurface, true );
1707 }
1708 else if( frontMode == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK )
1709 {
1710 addCountersinkPlating( center, frontRadius, holeInnerRadius, frontSurface, frontDepth,
1711 true );
1712 }
1713 }
1714
1715 const PAD_DRILL_POST_MACHINING_MODE backMode =
1717 const float backRadius = 0.5f * aVia->GetBackPostMachiningSize() * unitScale;
1718
1719 if( backDepth > 0.0f && backRadius > holeInnerRadius )
1720 {
1722 {
1723 addCounterborePlating( *aVia, center, backRadius, backDepth, backSurface, false );
1724 }
1725 else if( backMode == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK )
1726 {
1727 addCountersinkPlating( center, backRadius, holeInnerRadius, backSurface, backDepth,
1728 false );
1729 }
1730 }
1731}
1732
1733
1735{
1736 if( !m_boardAdapter.m_Cfg->m_Render.show_plated_barrels )
1737 return;
1738
1739 const OBJECT_2D* object2d_A = nullptr;
1740
1741 SFVEC3F objColor = m_boardAdapter.m_CopperColor;
1742 const VECTOR2I drillsize = aPad->GetDrillSize();
1743 const bool hasHole = drillsize.x && drillsize.y;
1744 const float unitScale = m_boardAdapter.BiuTo3dUnits();
1745 const bool isRoundHole = drillsize.x == drillsize.y;
1746 SFVEC2F holeCenter = SFVEC2F( 0.0f, 0.0f );
1747 float holeInnerRadius = 0.0f;
1748
1749 if( !hasHole )
1750 return;
1751
1752 CONST_LIST_OBJECT2D antiOutlineIntersectionList;
1753
1754 float frontDepth = 0.0f;
1755 float backDepth = 0.0f;
1756
1758 frontDepth = aPad->GetFrontPostMachiningDepth() * m_boardAdapter.BiuTo3dUnits();
1759
1761 backDepth = aPad->GetBackPostMachiningDepth() * m_boardAdapter.BiuTo3dUnits();
1762
1763 const float topZ = m_boardAdapter.GetLayerBottomZPos( F_Cu )
1764 + m_boardAdapter.GetFrontCopperThickness() * 0.99f - frontDepth;
1765
1766 const float botZ = m_boardAdapter.GetLayerBottomZPos( B_Cu )
1767 - m_boardAdapter.GetBackCopperThickness() * 0.99f + backDepth;
1768
1769 if( isRoundHole ) // usual round hole
1770 {
1771 holeCenter = SFVEC2F( aPad->GetPosition().x * unitScale,
1772 -aPad->GetPosition().y * unitScale );
1773
1774 int innerRadius = drillsize.x / 2;
1775 int outerRadius = innerRadius + m_boardAdapter.GetHolePlatingThickness();
1776 holeInnerRadius = innerRadius * unitScale;
1777
1778 RING_2D* ring = new RING_2D( holeCenter, innerRadius * unitScale,
1779 outerRadius * unitScale, *aPad );
1780
1782
1783 object2d_A = ring;
1784
1785 // If the object (ring) is intersected by an antioutline board,
1786 // it will use instead a CSG of two circles.
1787 if( object2d_A && !m_antioutlineBoard2dObjects->GetList().empty() )
1788 {
1789 m_antioutlineBoard2dObjects->GetIntersectingObjects( object2d_A->GetBBox(),
1790 antiOutlineIntersectionList );
1791 }
1792
1793 if( !antiOutlineIntersectionList.empty() )
1794 {
1795 FILLED_CIRCLE_2D* innerCircle = new FILLED_CIRCLE_2D(
1796 holeCenter, innerRadius * unitScale, *aPad );
1797
1798 FILLED_CIRCLE_2D* outterCircle = new FILLED_CIRCLE_2D(
1799 holeCenter, outerRadius * unitScale, *aPad );
1800 std::vector<const OBJECT_2D*>* object2d_B = new std::vector<const OBJECT_2D*>();
1801 object2d_B->push_back( innerCircle );
1802
1803 LAYER_ITEM_2D* itemCSG2d = new LAYER_ITEM_2D( outterCircle, object2d_B, CSGITEM_FULL,
1804 *aPad );
1805
1806 m_containerWithObjectsToDelete.Add( itemCSG2d );
1807 m_containerWithObjectsToDelete.Add( innerCircle );
1808 m_containerWithObjectsToDelete.Add( outterCircle );
1809
1810 object2d_A = itemCSG2d;
1811 }
1812 }
1813 else // Oblong hole
1814 {
1815 VECTOR2I ends_offset;
1816 int width;
1817
1818 if( drillsize.x > drillsize.y ) // Horizontal oval
1819 {
1820 ends_offset.x = ( drillsize.x - drillsize.y ) / 2;
1821 width = drillsize.y;
1822 }
1823 else // Vertical oval
1824 {
1825 ends_offset.y = ( drillsize.y - drillsize.x ) / 2;
1826 width = drillsize.x;
1827 }
1828
1829 RotatePoint( ends_offset, aPad->GetOrientation() );
1830
1831 VECTOR2I start = VECTOR2I( aPad->GetPosition() ) + ends_offset;
1832 VECTOR2I end = VECTOR2I( aPad->GetPosition() ) - ends_offset;
1833
1834 ROUND_SEGMENT_2D* innerSeg =
1835 new ROUND_SEGMENT_2D( SFVEC2F( start.x * unitScale,
1836 -start.y * unitScale ),
1837 SFVEC2F( end.x * unitScale,
1838 -end.y * unitScale ),
1839 width * unitScale, *aPad );
1840
1841 ROUND_SEGMENT_2D* outerSeg =
1842 new ROUND_SEGMENT_2D( SFVEC2F( start.x * unitScale,
1843 -start.y * unitScale ),
1844 SFVEC2F( end.x * unitScale,
1845 -end.y * unitScale ),
1846 ( width + m_boardAdapter.GetHolePlatingThickness() * 2 )
1847 * unitScale, *aPad );
1848
1849 // NOTE: the round segment width is the "diameter", so we double the thickness
1850 std::vector<const OBJECT_2D*>* object2d_B = new std::vector<const OBJECT_2D*>();
1851 object2d_B->push_back( innerSeg );
1852
1853 LAYER_ITEM_2D* itemCSG2d = new LAYER_ITEM_2D( outerSeg, object2d_B, CSGITEM_FULL, *aPad );
1854
1855 m_containerWithObjectsToDelete.Add( itemCSG2d );
1856 m_containerWithObjectsToDelete.Add( innerSeg );
1857 m_containerWithObjectsToDelete.Add( outerSeg );
1858
1859 object2d_A = itemCSG2d;
1860
1861 if( object2d_A && !m_antioutlineBoard2dObjects->GetList().empty() )
1862 {
1863 m_antioutlineBoard2dObjects->GetIntersectingObjects( object2d_A->GetBBox(),
1864 antiOutlineIntersectionList );
1865 }
1866 }
1867
1868 if( object2d_A )
1869 {
1870 std::vector<const OBJECT_2D*>* object2d_B = new std::vector<const OBJECT_2D*>();
1871
1872 // Check if there are any other THT that intersects this hole
1873 // It will use the non inflated holes
1874 if( !m_boardAdapter.GetTH_IDs().GetList().empty() )
1875 {
1876 CONST_LIST_OBJECT2D intersecting;
1877
1878 m_boardAdapter.GetTH_IDs().GetIntersectingObjects( object2d_A->GetBBox(), intersecting );
1879
1880 for( const OBJECT_2D* hole2d : intersecting )
1881 {
1882 if( object2d_A->Intersects( hole2d->GetBBox() ) )
1883 object2d_B->push_back( hole2d );
1884 }
1885 }
1886
1887 for( const OBJECT_2D* obj : antiOutlineIntersectionList )
1888 object2d_B->push_back( obj );
1889
1890 if( object2d_B->empty() )
1891 {
1892 delete object2d_B;
1893 object2d_B = CSGITEM_EMPTY;
1894 }
1895
1896 if( object2d_B == CSGITEM_EMPTY )
1897 {
1898 LAYER_ITEM* objPtr = new LAYER_ITEM( object2d_A, topZ, botZ );
1899
1900 objPtr->SetMaterial( &m_materials.m_Copper );
1901 objPtr->SetColor( ConvertSRGBToLinear( objColor ) );
1902 m_objectContainer.Add( objPtr );
1903 }
1904 else
1905 {
1906 LAYER_ITEM_2D* itemCSG2d = new LAYER_ITEM_2D( object2d_A, object2d_B, CSGITEM_FULL,
1907 *aPad );
1908
1909 m_containerWithObjectsToDelete.Add( itemCSG2d );
1910
1911 LAYER_ITEM* objPtr = new LAYER_ITEM( itemCSG2d, topZ, botZ );
1912
1913 objPtr->SetMaterial( &m_materials.m_Copper );
1914 objPtr->SetColor( ConvertSRGBToLinear( objColor ) );
1915
1916 m_objectContainer.Add( objPtr );
1917 }
1918 }
1919
1920 if( object2d_A && isRoundHole )
1921 {
1922 const float frontSurface = topZ + frontDepth;
1923 const float backSurface = botZ - backDepth;
1924
1925 const PAD_DRILL_POST_MACHINING_MODE frontMode =
1927 const float frontRadius = 0.5f * aPad->GetFrontPostMachiningSize() * unitScale;
1928
1929 if( frontDepth > 0.0f && frontRadius > holeInnerRadius )
1930 {
1932 {
1933 addCounterborePlating( *aPad, holeCenter, frontRadius, frontDepth, frontSurface,
1934 true );
1935 }
1936 else if( frontMode == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK )
1937 {
1938 addCountersinkPlating( holeCenter, frontRadius, holeInnerRadius, frontSurface,
1939 frontDepth, true );
1940 }
1941 }
1942
1943 const PAD_DRILL_POST_MACHINING_MODE backMode =
1945 const float backRadius = 0.5f * aPad->GetBackPostMachiningSize() * unitScale;
1946
1947 if( backDepth > 0.0f && backRadius > holeInnerRadius )
1948 {
1950 {
1951 addCounterborePlating( *aPad, holeCenter, backRadius, backDepth, backSurface,
1952 false );
1953 }
1954 else if( backMode == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK )
1955 {
1956 addCountersinkPlating( holeCenter, backRadius, holeInnerRadius, backSurface,
1957 backDepth, false );
1958 }
1959 }
1960 }
1961}
1962
1963
1965{
1966 if( !m_boardAdapter.GetBoard() )
1967 return;
1968
1969 // Insert plated vertical holes inside the board
1970
1971 // Insert vias holes (vertical cylinders)
1972 for( PCB_TRACK* track : m_boardAdapter.GetBoard()->Tracks() )
1973 {
1974 if( track->Type() == PCB_VIA_T )
1975 {
1976 const PCB_VIA* via = static_cast<const PCB_VIA*>( track );
1977 insertHole( via );
1978 }
1979 }
1980
1981 // Insert pads holes (vertical cylinders)
1982 for( FOOTPRINT* footprint : m_boardAdapter.GetBoard()->Footprints() )
1983 {
1984 for( PAD* pad : footprint->Pads() )
1985 {
1986 if( pad->GetAttribute() != PAD_ATTRIB::NPTH )
1987 insertHole( pad );
1988 }
1989 }
1990}
1991
1992
1994 const glm::mat4& aFpMatrix, bool aHasExtrudedBody,
1995 float aOpacity )
1996{
1997 if( aHasExtrudedBody )
1998 return;
1999
2000 BOX2I localBox = CalcPlaceholderLocalBox( aFootprint );
2001
2002 float bboxW = std::abs( localBox.GetWidth() ) / pcbIUScale.IU_PER_MM * 0.9f;
2003 float bboxH = std::abs( localBox.GetHeight() ) / pcbIUScale.IU_PER_MM * 0.9f;
2004 float scaleZ = std::min( bboxW, bboxH ) * 0.5f;
2005
2006 VECTOR2I localCenter = localBox.GetCenter();
2007 float offsetX = localCenter.x / pcbIUScale.IU_PER_MM;
2008 float offsetY = -localCenter.y / pcbIUScale.IU_PER_MM;
2009
2010 if( aFootprint->IsFlipped() )
2011 offsetY = -offsetY;
2012
2013 SFVEC3F boxMin( offsetX - bboxW * 0.5f, offsetY - bboxH * 0.5f, 0.0f );
2014 SFVEC3F boxMax( offsetX + bboxW * 0.5f, offsetY + bboxH * 0.5f, scaleZ );
2015
2016 SFVEC3F corners[8];
2017
2018 for( int i = 0; i < 8; ++i )
2019 {
2020 SFVEC3F corner( ( i & 1 ) ? boxMax.x : boxMin.x, ( i & 2 ) ? boxMax.y : boxMin.y,
2021 ( i & 4 ) ? boxMax.z : boxMin.z );
2022
2023 corners[i] = SFVEC3F( aFpMatrix * glm::vec4( corner, 1.0f ) );
2024 }
2025
2026 static const int faces[6][4] = { { 4, 5, 7, 6 }, { 0, 2, 3, 1 }, { 0, 1, 5, 4 },
2027 { 3, 2, 6, 7 }, { 0, 4, 6, 2 }, { 1, 3, 7, 5 } };
2028
2029 auto addTriangle = [&]( const SFVEC3F& aV0, const SFVEC3F& aV1, const SFVEC3F& aV2 )
2030 {
2031 TRIANGLE* triangle = new TRIANGLE( aV0, aV1, aV2 );
2032 triangle->SetBoardItem( const_cast<FOOTPRINT*>( aFootprint ) );
2033 triangle->SetMaterial( &m_materials.m_EpoxyBoard );
2034 triangle->SetModelTransparency( 1.0f - aOpacity );
2035 triangle->SetColor( SFVEC3F( 1.0f, 0.5f, 0.0f ) );
2036 aDstContainer.Add( triangle );
2037 };
2038
2039 for( const int* face : faces )
2040 {
2041 addTriangle( corners[face[0]], corners[face[2]], corners[face[1]] );
2042 addTriangle( corners[face[0]], corners[face[3]], corners[face[2]] );
2043 }
2044}
2045
2046
2047static size_t addOutlineToRaytracerObjects( CONTAINER_2D& aObjContainer, const SHAPE_POLY_SET& aOutline, float aBiuTo3d,
2048 const BOARD_ITEM& aBoardItem )
2049{
2050 size_t added = 0;
2051
2052 for( int oi = 0; oi < aOutline.OutlineCount(); oi++ )
2053 {
2054 const SHAPE_LINE_CHAIN& chain = aOutline.COutline( oi );
2055
2056 if( chain.PointCount() < 3 )
2057 continue;
2058
2059 // Convert points to 3D-scaled coordinates
2060 SEGMENTS_WIDTH_NORMALS segNormals;
2061 SFVEC2F prevPt;
2062
2063 for( int i = 0; i < chain.PointCount(); i++ )
2064 {
2065 const VECTOR2I& a = chain.CPoint( i );
2066 SFVEC2F pt( (float) a.x * aBiuTo3d, (float) ( -a.y ) * aBiuTo3d );
2067
2068 if( ( i == 0 ) || ( fabs( prevPt.x - pt.x ) > FLT_EPSILON ) || ( fabs( prevPt.y - pt.y ) > FLT_EPSILON ) )
2069 {
2070 prevPt = pt;
2071
2073 sn.m_Start = pt;
2074 segNormals.push_back( sn );
2075 }
2076 }
2077
2078 // Build side-wall
2079 if( segNormals.size() >= 3 )
2080 {
2081 std::vector<SFVEC2F> tmpNormals( segNormals.size() );
2082 unsigned int j = segNormals.size() - 1;
2083
2084 for( unsigned int i = 0; i < segNormals.size(); j = i++ )
2085 {
2086 SFVEC2F slope = segNormals[j].m_Start - segNormals[i].m_Start;
2087 segNormals[i].m_Precalc_slope = slope;
2088 tmpNormals[i] = glm::normalize( SFVEC2F( slope.y, -slope.x ) );
2089 }
2090
2091 j = segNormals.size() - 1;
2092
2093 for( unsigned int i = 0; i < segNormals.size(); j = i++ )
2094 {
2095 const SFVEC2F& nBefore = tmpNormals[j];
2096 const SFVEC2F& nCur = tmpNormals[i];
2097 const SFVEC2F& nAfter = tmpNormals[( i + 1 ) % segNormals.size()];
2098
2099 float dotBefore = glm::dot( nBefore, nCur );
2100 float dotAfter = glm::dot( nAfter, nCur );
2101
2102 segNormals[i].m_Normals.m_Start =
2103 ( dotBefore < 0.7f ) ? nCur : glm::normalize( nBefore * dotBefore + nCur );
2104 segNormals[i].m_Normals.m_End = ( dotAfter < 0.7f ) ? nCur : glm::normalize( nAfter * dotAfter + nCur );
2105 }
2106
2107 SEGMENTS capSegments( segNormals.size() );
2108
2109 for( unsigned int i = 0; i < segNormals.size(); i++ )
2110 capSegments[i].m_Start = segNormals[i].m_Start;
2111
2112 j = capSegments.size() - 1;
2113
2114 for( unsigned int i = 0; i < capSegments.size(); j = i++ )
2115 {
2116 capSegments[i].m_inv_JY_minus_IY = 1.0f / ( capSegments[j].m_Start.y - capSegments[i].m_Start.y );
2117 capSegments[i].m_JX_minus_IX = capSegments[j].m_Start.x - capSegments[i].m_Start.x;
2118 }
2119
2120 OUTERS_AND_HOLES outersAndHoles;
2121 outersAndHoles.m_Outers.push_back( capSegments );
2122
2123 aObjContainer.Add( new POLYGON_2D( segNormals, outersAndHoles, aBoardItem ) );
2124 added++;
2125 }
2126 }
2127
2128 // top/bottom caps
2129 size_t prevSize = aObjContainer.GetList().size();
2130 ConvertPolygonToTriangles( aOutline, aObjContainer, aBiuTo3d, aBoardItem );
2131 added += aObjContainer.GetList().size() - prevSize;
2132
2133 return added;
2134}
2135
2136
2138{
2139 SHAPE_POLY_SET outline;
2140
2141 if( !GetExtrusionOutline( aFootprint, outline ) )
2142 return false;
2143
2144 if( outline.OutlineCount() == 0 )
2145 return false;
2146
2147 outline.Simplify();
2148
2149 const EXTRUDED_3D_BODY* body = aFootprint->GetBody() ? aFootprint->GetBody()->GetExtruded() : nullptr;
2150 const float biuTo3d = m_boardAdapter.BiuTo3dUnits();
2151
2152 VECTOR2I fpPos = aFootprint->GetPosition();
2153 ApplyExtrusionTransform( outline, body, fpPos );
2154
2155 bool isBack = aFootprint->IsFlipped();
2156 float boardSurfaceZ = m_boardAdapter.GetFootprintZPos( isBack );
2157 float standoff3d = body->m_standoff * biuTo3d;
2158 float bodyThickness = ( body->m_height - body->m_standoff ) * biuTo3d * body->m_scale.z;
2159 float zOffset3d = pcbIUScale.mmToIU( body->m_offset.z ) * biuTo3d;
2160
2161 float zBot, zTop;
2162
2163 if( !isBack )
2164 {
2165 zBot = boardSurfaceZ + standoff3d + zOffset3d;
2166 zTop = zBot + bodyThickness;
2167 }
2168 else
2169 {
2170 zTop = boardSurfaceZ - standoff3d - zOffset3d;
2171 zBot = zTop - bodyThickness;
2172 }
2173
2174 KIGFX::COLOR4D c = body->m_color;
2175
2178
2179 SFVEC3F objColor = ConvertSRGBToLinear( SFVEC3F( c.r, c.g, c.b ) );
2180
2181 // Build body 2D objects (side walls + caps)
2182 outline.Fracture();
2183
2184 const LIST_OBJECT2D& objList = m_containerWithObjectsToDelete.GetList();
2185 size_t prevCount = objList.size();
2186
2187 addOutlineToRaytracerObjects( m_containerWithObjectsToDelete, outline, biuTo3d, *aFootprint );
2188
2189 EXTRUSION_MATERIAL_PROPS props = GetMaterialProps( body->m_material, objColor );
2190
2191 m_extrusionMaterials.push_back( std::make_unique<BLINN_PHONG_MATERIAL>(
2192 props.m_Ambient, SFVEC3F( 0.0f ), props.m_Specular, props.m_Shininess, 0.0f, 0.0f ) );
2193
2194 const MATERIAL* bodyMaterial = m_extrusionMaterials.back().get();
2195
2196 auto it = objList.begin();
2197 std::advance( it, prevCount );
2198
2199 for( ; it != objList.end(); ++it )
2200 {
2201 LAYER_ITEM* layerItem = new LAYER_ITEM( *it, zBot, zTop );
2202 layerItem->SetBoardItem( const_cast<FOOTPRINT*>( aFootprint ) );
2203 layerItem->SetMaterial( bodyMaterial );
2204 layerItem->SetColor( objColor );
2205 layerItem->SetModelTransparency( 1.0f - (float) c.a );
2206 aDstContainer.Add( layerItem );
2207 }
2208
2209 // Create pin extrusions for pad holes (they move with the body, so the Z offset shifts them whole)
2210 if( standoff3d > 0.0f )
2211 {
2212 SHAPE_POLY_SET pinPoly;
2213 SHAPE_POLY_SET pegPoly;
2214
2215 if( GetExtrusionPinOutlines( aFootprint, pinPoly, pegPoly ) )
2216 {
2217 float oppositeSurfaceZ = m_boardAdapter.GetFootprintZPos( !isBack );
2218 float protrusion = 1.0f * pcbIUScale.IU_PER_MM * biuTo3d;
2219 float pinZBot, pinZTop;
2220
2221 if( !isBack )
2222 {
2223 pinZBot = oppositeSurfaceZ - protrusion + zOffset3d;
2224 pinZTop = boardSurfaceZ + standoff3d + zOffset3d;
2225 }
2226 else
2227 {
2228 pinZTop = oppositeSurfaceZ + protrusion - zOffset3d;
2229 pinZBot = boardSurfaceZ - standoff3d - zOffset3d;
2230 }
2231
2232 auto addPinObjects =
2233 [&]( SHAPE_POLY_SET& aPoly, const MATERIAL* aMaterial, const SFVEC3F& aColor, float aTransparency )
2234 {
2235 if( aPoly.OutlineCount() == 0 )
2236 return;
2237
2238 ApplyExtrusionTransform( aPoly, body, fpPos );
2239 aPoly.Fracture();
2240
2241 size_t prevPinCount = objList.size();
2242
2243 addOutlineToRaytracerObjects( m_containerWithObjectsToDelete, aPoly, biuTo3d, *aFootprint );
2244
2245 auto pinIt = objList.begin();
2246 std::advance( pinIt, prevPinCount );
2247
2248 for( ; pinIt != objList.end(); ++pinIt )
2249 {
2250 LAYER_ITEM* layerItem = new LAYER_ITEM( *pinIt, pinZBot, pinZTop );
2251 layerItem->SetBoardItem( const_cast<FOOTPRINT*>( aFootprint ) );
2252 layerItem->SetMaterial( aMaterial );
2253 layerItem->SetColor( aColor );
2254 layerItem->SetModelTransparency( aTransparency );
2255 aDstContainer.Add( layerItem );
2256 }
2257 };
2258
2259 SFVEC3F metalColor = ConvertSRGBToLinear( SFVEC3F( 0.75f, 0.75f, 0.75f ) );
2260
2261 addPinObjects( pinPoly, &m_materials.m_Copper, metalColor, 0.0f );
2262 addPinObjects( pegPoly, bodyMaterial, objColor, 1.0f - (float) c.a );
2263 }
2264 }
2265
2266 return true;
2267}
2268
2269
2270void RENDER_3D_RAYTRACE_BASE::load3DModels( CONTAINER_3D& aDstContainer, bool aSkipMaterialInformation,
2271 std::stop_token aStop )
2272{
2273 if( !m_boardAdapter.GetBoard() )
2274 return;
2275
2276 if( !m_boardAdapter.m_IsPreviewer
2277 && !m_boardAdapter.m_Cfg->m_Render.show_footprints_normal
2278 && !m_boardAdapter.m_Cfg->m_Render.show_footprints_insert
2279 && !m_boardAdapter.m_Cfg->m_Render.show_footprints_virtual )
2280 {
2281 return;
2282 }
2283
2284 // Go for all footprints
2285 for( FOOTPRINT* fp : m_boardAdapter.GetBoard()->Footprints() )
2286 {
2287 if( aStop.stop_requested() )
2288 return;
2289
2290 bool hasModels = !fp->Models().empty();
2291
2292 // Placeholder is suppressed when an extrusion was built.
2293 bool hasExtrudedBody = false;
2294
2295 if( fp->HasBody() && fp->GetBody()->GetExtruded()->m_show && m_boardAdapter.IsFootprintShown( fp ) )
2296 hasExtrudedBody = addExtrudedBodyToRaytracer( aDstContainer, fp );
2297
2298 if( ( hasModels || m_boardAdapter.ShowMissingModels() ) && m_boardAdapter.IsFootprintShown( fp ) )
2299 {
2300 const glm::mat4 fpMatrix = m_boardAdapter.GetFootprintMatrix( *fp );
2301
2302 // Get the list of model files for this model
2303 S3D_CACHE* cacheMgr = m_boardAdapter.Get3dCacheManager();
2304
2305 const wxString footprintBasePath = m_boardAdapter.GetFootprintLibraryPath( fp );
2306
2307 bool placeholderAdded = false;
2308
2309 for( FP_3DMODEL& model : fp->Models() )
2310 {
2311 if( !model.m_Show || model.m_Filename.empty() )
2312 continue;
2313
2314 // get it from cache
2315 std::vector<const EMBEDDED_FILES*> embeddedFilesStack;
2316 embeddedFilesStack.push_back( fp->GetEmbeddedFiles() );
2317 embeddedFilesStack.push_back( m_boardAdapter.GetBoard()->GetEmbeddedFiles() );
2318
2319 const S3DMODEL* modelPtr = cacheMgr->GetModel( model.m_Filename, footprintBasePath,
2320 std::move( embeddedFilesStack ) );
2321
2322 // only add it if the return is not NULL.
2323 if( modelPtr )
2324 {
2325 glm::mat4 modelMatrix = fpMatrix * CalcModelMatrix(
2326 SFVEC3F( model.m_Offset.x, model.m_Offset.y, model.m_Offset.z ),
2327 SFVEC3F( model.m_Rotation.x, model.m_Rotation.y, model.m_Rotation.z ),
2328 SFVEC3F( model.m_Scale.x, model.m_Scale.y, model.m_Scale.z ) );
2329
2330 addModels( aDstContainer, modelPtr, modelMatrix, (float) model.m_Opacity,
2331 aSkipMaterialInformation, fp );
2332 }
2333 else if( m_boardAdapter.ShowMissingModels() && !placeholderAdded )
2334 {
2335 addPlaceholderToRaytracer( aDstContainer, fp, fpMatrix, hasExtrudedBody, (float) model.m_Opacity );
2336 placeholderAdded = true;
2337 }
2338 }
2339
2340 // Footprint with no models assigned at all
2341 if( !hasModels && m_boardAdapter.ShowMissingModels() )
2342 {
2343 addPlaceholderToRaytracer( aDstContainer, fp, fpMatrix, hasExtrudedBody, 1.0f );
2344 }
2345 }
2346 }
2347}
2348
2349
2351{
2352 MODEL_MATERIALS* materialVector;
2353
2354 // Try find if the materials already exists in the map list
2355 if( m_modelMaterialMap.find( a3DModel ) != m_modelMaterialMap.end() )
2356 {
2357 // Found it, so get the pointer
2358 materialVector = &m_modelMaterialMap[a3DModel];
2359 }
2360 else
2361 {
2362 // Materials was not found in the map, so it will create a new for
2363 // this model.
2364
2365 m_modelMaterialMap[a3DModel] = MODEL_MATERIALS();
2366 materialVector = &m_modelMaterialMap[a3DModel];
2367
2368 materialVector->resize( a3DModel->m_MaterialsSize );
2369
2370 for( unsigned int imat = 0; imat < a3DModel->m_MaterialsSize; ++imat )
2371 {
2372 if( m_boardAdapter.m_Cfg->m_Render.material_mode == MATERIAL_MODE::NORMAL )
2373 {
2374 const SMATERIAL& material = a3DModel->m_Materials[imat];
2375
2376 // http://www.fooplot.com/#W3sidHlwZSI6MCwiZXEiOiJtaW4oc3FydCh4LTAuMzUpKjAuNDAtMC4wNSwxLjApIiwiY29sb3IiOiIjMDAwMDAwIn0seyJ0eXBlIjoxMDAwLCJ3aW5kb3ciOlsiMC4wNzA3NzM2NzMyMzY1OTAxMiIsIjEuNTY5NTcxNjI5MjI1NDY5OCIsIi0wLjI3NDYzNTMyMTc1OTkyOTMiLCIwLjY0NzcwMTg4MTkyNTUzNjIiXSwic2l6ZSI6WzY0NCwzOTRdfV0-
2377
2378 float reflectionFactor = 0.0f;
2379
2380 if( ( material.m_Shininess - 0.35f ) > FLT_EPSILON )
2381 {
2382 reflectionFactor = glm::clamp(
2383 glm::sqrt( ( material.m_Shininess - 0.35f ) ) * 0.40f - 0.05f, 0.0f,
2384 0.5f );
2385 }
2386
2387 BLINN_PHONG_MATERIAL& blinnMaterial = ( *materialVector )[imat];
2388
2389 blinnMaterial = BLINN_PHONG_MATERIAL( ConvertSRGBToLinear( material.m_Ambient ),
2390 ConvertSRGBToLinear( material.m_Emissive ),
2391 ConvertSRGBToLinear( material.m_Specular ), material.m_Shininess * 180.0f,
2392 material.m_Transparency, reflectionFactor );
2393
2394 if( m_boardAdapter.m_Cfg->m_Render.raytrace_procedural_textures )
2395 {
2396 // Guess material type and apply a normal perturbator
2397 if( ( RGBtoGray( material.m_Diffuse ) < 0.3f )
2398 && ( material.m_Shininess < 0.36f )
2399 && ( material.m_Transparency == 0.0f )
2400 && ( ( glm::abs( material.m_Diffuse.r - material.m_Diffuse.g ) < 0.15f )
2401 && ( glm::abs( material.m_Diffuse.b - material.m_Diffuse.g )
2402 < 0.15f )
2403 && ( glm::abs( material.m_Diffuse.r - material.m_Diffuse.b )
2404 < 0.15f ) ) )
2405 {
2406 // This may be a black plastic..
2407 blinnMaterial.SetGenerator( &m_plasticMaterial );
2408 }
2409 else
2410 {
2411 if( ( RGBtoGray( material.m_Diffuse ) > 0.3f )
2412 && ( material.m_Shininess < 0.30f )
2413 && ( material.m_Transparency == 0.0f )
2414 && ( ( glm::abs( material.m_Diffuse.r - material.m_Diffuse.g ) > 0.25f )
2415 || ( glm::abs( material.m_Diffuse.b - material.m_Diffuse.g ) > 0.25f )
2416 || ( glm::abs( material.m_Diffuse.r - material.m_Diffuse.b )
2417 > 0.25f ) ) )
2418 {
2419 // This may be a color plastic ...
2420 blinnMaterial.SetGenerator( &m_shinyPlasticMaterial );
2421 }
2422 else
2423 {
2424 if( ( RGBtoGray( material.m_Diffuse ) > 0.6f )
2425 && ( material.m_Shininess > 0.35f )
2426 && ( material.m_Transparency == 0.0f )
2427 && ( ( glm::abs( material.m_Diffuse.r - material.m_Diffuse.g )
2428 < 0.40f )
2429 && ( glm::abs( material.m_Diffuse.b - material.m_Diffuse.g )
2430 < 0.40f )
2431 && ( glm::abs( material.m_Diffuse.r - material.m_Diffuse.b )
2432 < 0.40f ) ) )
2433 {
2434 // This may be a brushed metal
2435 blinnMaterial.SetGenerator( &m_brushedMetalMaterial );
2436 }
2437 }
2438 }
2439 }
2440 }
2441 else
2442 {
2443 ( *materialVector )[imat] = BLINN_PHONG_MATERIAL(
2444 SFVEC3F( 0.2f ), SFVEC3F( 0.0f ), SFVEC3F( 0.0f ), 0.0f, 0.0f, 0.0f );
2445 }
2446 }
2447 }
2448
2449 return materialVector;
2450}
2451
2452
2453void RENDER_3D_RAYTRACE_BASE::addModels( CONTAINER_3D& aDstContainer, const S3DMODEL* a3DModel,
2454 const glm::mat4& aModelMatrix, float aFPOpacity,
2455 bool aSkipMaterialInformation, BOARD_ITEM* aBoardItem )
2456{
2457 // Validate a3DModel pointers
2458 wxASSERT( a3DModel != nullptr );
2459
2460 if( a3DModel == nullptr )
2461 return;
2462
2463 wxASSERT( a3DModel->m_Materials != nullptr );
2464 wxASSERT( a3DModel->m_Meshes != nullptr );
2465 wxASSERT( a3DModel->m_MaterialsSize > 0 );
2466 wxASSERT( a3DModel->m_MeshesSize > 0 );
2467
2468 if( aFPOpacity > 1.0f )
2469 aFPOpacity = 1.0f;
2470
2471 if( aFPOpacity < 0.0f )
2472 aFPOpacity = 0.0f;
2473
2474 if( ( a3DModel->m_Materials != nullptr ) && ( a3DModel->m_Meshes != nullptr )
2475 && ( a3DModel->m_MaterialsSize > 0 ) && ( a3DModel->m_MeshesSize > 0 ) )
2476 {
2477 MODEL_MATERIALS* materialVector = nullptr;
2478
2479 if( !aSkipMaterialInformation )
2480 {
2481 materialVector = getModelMaterial( a3DModel );
2482 }
2483
2484 const glm::mat3 normalMatrix = glm::transpose( glm::inverse( glm::mat3( aModelMatrix ) ) );
2485
2486 for( unsigned int mesh_i = 0; mesh_i < a3DModel->m_MeshesSize; ++mesh_i )
2487 {
2488 const SMESH& mesh = a3DModel->m_Meshes[mesh_i];
2489
2490 // Validate the mesh pointers
2491 wxASSERT( mesh.m_Positions != nullptr );
2492 wxASSERT( mesh.m_FaceIdx != nullptr );
2493 wxASSERT( mesh.m_Normals != nullptr );
2494 wxASSERT( mesh.m_FaceIdxSize > 0 );
2495 wxASSERT( ( mesh.m_FaceIdxSize % 3 ) == 0 );
2496
2497
2498 if( ( mesh.m_Positions != nullptr ) && ( mesh.m_Normals != nullptr )
2499 && ( mesh.m_FaceIdx != nullptr ) && ( mesh.m_FaceIdxSize > 0 )
2500 && ( mesh.m_VertexSize > 0 ) && ( ( mesh.m_FaceIdxSize % 3 ) == 0 )
2501 && ( mesh.m_MaterialIdx < a3DModel->m_MaterialsSize ) )
2502 {
2503 float fpTransparency;
2504 const BLINN_PHONG_MATERIAL* blinn_material;
2505
2506 if( !aSkipMaterialInformation )
2507 {
2508 blinn_material = &( *materialVector )[mesh.m_MaterialIdx];
2509
2510 fpTransparency =
2511 1.0f - ( ( 1.0f - blinn_material->GetTransparency() ) * aFPOpacity );
2512 }
2513
2514 // Add all face triangles
2515 for( unsigned int faceIdx = 0; faceIdx < mesh.m_FaceIdxSize; faceIdx += 3 )
2516 {
2517 const unsigned int idx0 = mesh.m_FaceIdx[faceIdx + 0];
2518 const unsigned int idx1 = mesh.m_FaceIdx[faceIdx + 1];
2519 const unsigned int idx2 = mesh.m_FaceIdx[faceIdx + 2];
2520
2521 wxASSERT( idx0 < mesh.m_VertexSize );
2522 wxASSERT( idx1 < mesh.m_VertexSize );
2523 wxASSERT( idx2 < mesh.m_VertexSize );
2524
2525 if( IsTriangleInRange( mesh.m_FaceIdx, faceIdx, mesh.m_VertexSize ) )
2526 {
2527 const SFVEC3F& v0 = mesh.m_Positions[idx0];
2528 const SFVEC3F& v1 = mesh.m_Positions[idx1];
2529 const SFVEC3F& v2 = mesh.m_Positions[idx2];
2530
2531 const SFVEC3F& n0 = mesh.m_Normals[idx0];
2532 const SFVEC3F& n1 = mesh.m_Normals[idx1];
2533 const SFVEC3F& n2 = mesh.m_Normals[idx2];
2534
2535 // Transform vertex with the model matrix
2536 const SFVEC3F vt0 = SFVEC3F( aModelMatrix * glm::vec4( v0, 1.0f ) );
2537 const SFVEC3F vt1 = SFVEC3F( aModelMatrix * glm::vec4( v1, 1.0f ) );
2538 const SFVEC3F vt2 = SFVEC3F( aModelMatrix * glm::vec4( v2, 1.0f ) );
2539
2540 const SFVEC3F nt0 = glm::normalize( SFVEC3F( normalMatrix * n0 ) );
2541 const SFVEC3F nt1 = glm::normalize( SFVEC3F( normalMatrix * n1 ) );
2542 const SFVEC3F nt2 = glm::normalize( SFVEC3F( normalMatrix * n2 ) );
2543
2544 TRIANGLE* newTriangle = new TRIANGLE( vt0, vt2, vt1, nt0, nt2, nt1 );
2545
2546 newTriangle->SetBoardItem( aBoardItem );
2547
2548 aDstContainer.Add( newTriangle );
2549
2550 if( !aSkipMaterialInformation )
2551 {
2552 newTriangle->SetMaterial( blinn_material );
2553 newTriangle->SetModelTransparency( fpTransparency );
2554
2555 if( mesh.m_Color == nullptr )
2556 {
2557 const SFVEC3F diffuseColor =
2558 a3DModel->m_Materials[mesh.m_MaterialIdx].m_Diffuse;
2559
2560 if( m_boardAdapter.m_Cfg->m_Render.material_mode == MATERIAL_MODE::CAD_MODE )
2561 newTriangle->SetColor( ConvertSRGBToLinear(
2562 MaterialDiffuseToColorCAD( diffuseColor ) ) );
2563 else
2564 newTriangle->SetColor( ConvertSRGBToLinear( diffuseColor ) );
2565 }
2566 else
2567 {
2568 if( m_boardAdapter.m_Cfg->m_Render.material_mode == MATERIAL_MODE::CAD_MODE )
2569 {
2570 newTriangle->SetColor(
2572 mesh.m_Color[idx0] ) ),
2574 mesh.m_Color[idx1] ) ),
2576 mesh.m_Color[idx2] ) ) );
2577 }
2578 else
2579 {
2580 newTriangle->SetColor(
2581 ConvertSRGBToLinear( mesh.m_Color[idx0] ),
2582 ConvertSRGBToLinear( mesh.m_Color[idx1] ),
2583 ConvertSRGBToLinear( mesh.m_Color[idx2] ) );
2584 }
2585 }
2586 }
2587 }
2588 }
2589 }
2590 }
2591 }
2592}
@ NORMAL
Use all material properties from model file.
Definition 3d_enums.h:75
@ CAD_MODE
Use a gray shading based on diffuse material.
Definition 3d_enums.h:77
Defines math related functions.
float NextFloatDown(float v)
float NextFloatUp(float v)
glm::mat4 CalcModelMatrix(const SFVEC3F &aOffset, const SFVEC3F &aRotation, const SFVEC3F &aScale)
Build the model-to-footprint transform used by rendering and picking.
Definition 3d_math.cpp:34
Defines math related functions.
float RGBtoGray(const SFVEC3F &aColor)
Definition 3d_math.h:171
SFVEC3F MaterialDiffuseToColorCAD(const SFVEC3F &aDiffuseColor)
Definition 3d_math.h:178
SFVEC3F SphericalToCartesian(float aInclination, float aAzimuth)
https://en.wikipedia.org/wiki/Spherical_coordinate_system
Definition 3d_math.h:74
bool GetExtrusionPinOutlines(const FOOTPRINT *aFootprint, SHAPE_POLY_SET &aPinPoly, SHAPE_POLY_SET &aPegPoly)
Get the hole outline polygons for extruded pin rendering.
void ApplyExtrusionTransform(SHAPE_POLY_SET &aOutline, const EXTRUDED_3D_BODY *aBody, const VECTOR2I &aFpPos)
Apply 2D extrusion transforms (rotation, scale, offset) to an outline.
EXTRUSION_MATERIAL_PROPS GetMaterialProps(EXTRUSION_MATERIAL aMaterial, const SFVEC3F &aDiffuse)
bool GetExtrusionOutline(const FOOTPRINT *aFootprint, SHAPE_POLY_SET &aOutline, PCB_LAYER_ID aLayerOverride)
Get the extrusion outline polygon for a footprint in board coordinates.
BOX2I CalcPlaceholderLocalBox(const FOOTPRINT *aFootprint)
Calculate a local space bounding box for a placeholder 3D model.
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
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.
#define RANGE_SCALE_3D
This defines the range that all coord will have to be rendered.
BOX2< VECTOR2I > BOX2I
Definition box2.h:917
This BVH implementation is based on the source code implementation from the book "Physically Based Re...
bool IsTriangleInRange(const unsigned int *aFaceIdx, unsigned int aTriangleIdx, unsigned int aVertexCount)
Test whether the three face indices of a triangle all reference valid vertices.
Definition c3dmodel.h:100
Blinn Phong based material https://en.wikipedia.org/wiki/Blinn%E2%80%93Phong_shading_model.
Definition material.h:375
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:99
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
constexpr size_type GetWidth() const
Definition box2.h:217
constexpr const Vec GetCenter() const
Definition box2.h:233
constexpr size_type GetHeight() const
Definition box2.h:218
Procedural generation of the shiny brushed metal.
Definition material.h:191
void GetIntersectingObjects(const BBOX_2D &aBBox, CONST_LIST_OBJECT2D &aOutList) const override
Get a list of objects that intersects a bounding box.
static const float DEFAULT_MAX_ZOOM
Definition camera.h:97
void Add(OBJECT_2D *aObject)
const LIST_OBJECT2D & GetList() const
void Add(OBJECT_3D *aObject)
Procedural generation of the copper normals.
Definition material.h:72
A vertical cylinder.
Definition cylinder_3d.h:34
void SetColor(SFVEC3F aObjColor)
Definition cylinder_3d.h:44
A light source based only on a directional vector.
Definition light.h:112
double AsRadians() const
Definition eda_angle.h:119
KIGFX::COLOR4D m_color
Definition pcb_3d_body.h:46
VECTOR3D m_offset
Definition pcb_3d_body.h:52
static KIGFX::COLOR4D GetDefaultColor(EXTRUSION_MATERIAL aMaterial)
Definition pcb_3d_body.h:54
EXTRUSION_MATERIAL m_material
Definition pcb_3d_body.h:47
bool IsFlipped() const
Definition footprint.h:620
const PCB_3D_BODY * GetBody() const
Definition footprint.h:427
VECTOR2I GetPosition() const override
Definition footprint.h:379
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
double r
Red component.
Definition color4d.h:391
double g
Green component.
Definition color4d.h:392
double a
Alpha component.
Definition color4d.h:394
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:400
double b
Blue component.
Definition color4d.h:393
Make solid geometry for objects on layers.
void SetColor(SFVEC3F aObjColor)
LAYER_RANGE_ITERATOR end() const
LAYER_RANGE_ITERATOR begin() const
A base light class to derive to implement other light classes.
Definition light.h:37
Base material class that can be used to derive other material implementations.
Definition material.h:236
void SetGenerator(const MATERIAL_GENERATOR *aGenerator)
Definition material.h:324
float GetTransparency() const
Definition material.h:269
static OBJECT_2D_STATS & Instance()
Definition object_2d.h:135
void ResetStats()
Definition object_2d.h:120
virtual bool Intersects(const BBOX_2D &aBBox) const =0
a.Intersects(b) ⇔ !a.Disjoint(b) ⇔ !(a ∩ b = ∅)
const BBOX_2D & GetBBox() const
Definition object_2d.h:101
const BOARD_ITEM & GetBoardItem() const
Definition object_2d.h:62
OBJECT_2D_TYPE GetObjectType() const
Definition object_2d.h:105
static OBJECT_3D_STATS & Instance()
Definition object_3d.h:129
void ResetStats()
Definition object_3d.h:112
void SetMaterial(const MATERIAL *aMaterial)
Definition object_3d.h:54
void SetModelTransparency(float aModelTransparency)
Definition object_3d.h:62
void SetBoardItem(BOARD_ITEM *aBoardItem)
Definition object_3d.h:51
POST_MACHINING_PROPS & FrontPostMachining()
Definition padstack.h:372
POST_MACHINING_PROPS & BackPostMachining()
Definition padstack.h:375
Definition pad.h:61
int GetBackPostMachiningSize() const
Definition pad.h:479
VECTOR2I GetPosition() const override
Definition pad.cpp:255
VECTOR2I GetDrillSize() const
Definition pad.h:320
int GetFrontPostMachiningSize() const
Definition pad.h:459
int GetFrontPostMachiningDepth() const
Definition pad.h:461
std::optional< PAD_DRILL_POST_MACHINING_MODE > GetFrontPostMachining() const
Definition pad.h:446
EDA_ANGLE GetOrientation() const
Return the rotation angle of the pad.
Definition pad.cpp:1672
std::optional< PAD_DRILL_POST_MACHINING_MODE > GetBackPostMachining() const
Definition pad.h:466
int GetBackPostMachiningDepth() const
Definition pad.h:481
const EXTRUDED_3D_BODY * GetExtruded() const
const VECTOR2I & GetStart() const
Definition pcb_track.h:100
int GetFrontPostMachiningSize() const
Definition pcb_track.h:755
const PADSTACK & Padstack() const
Definition pcb_track.h:435
std::optional< PAD_DRILL_POST_MACHINING_MODE > GetFrontPostMachining() const
Definition pcb_track.h:739
int GetBackPostMachiningSize() const
Definition pcb_track.h:778
int GetDrillValue() const
Calculate the drill value for vias (m_drill if > 0, or default drill value for the board).
std::optional< PAD_DRILL_POST_MACHINING_MODE > GetBackPostMachining() const
Definition pcb_track.h:762
void LayerPair(PCB_LAYER_ID *top_layer, PCB_LAYER_ID *bottom_layer) const
Return the 2 layers used by the via (the via actually uses all layers between these 2 layers)
Procedural generation of the plastic normals.
Definition material.h:142
Procedural generation of the shiny plastic normals.
Definition material.h:166
Point light source based on http://ogldev.atspace.co.uk/www/tutorial20/tutorial20....
Definition light.h:67
Represent a sub polygon block.
Definition polygon_2d.h:90
std::shared_ptr< REPORTER > m_warningReporter
std::shared_ptr< REPORTER > m_activityReporter
BOARD_ADAPTER & m_boardAdapter
Settings reference in use for this render.
SILK_SCREEN_NORMAL m_silkScreenMaterial
struct RENDER_3D_RAYTRACE_BASE::@013206213056006125230376122042346155134272177300 m_materials
std::mutex m_hitTestMutex
Serializes hover BVH use.
void addCountersinkPlating(const SFVEC2F &aCenter, float aTopInnerRadius, float aBottomInnerRadius, float aSurfaceZ, float aDepth, bool aIsFront)
std::vector< std::unique_ptr< BLINN_PHONG_MATERIAL > > m_extrusionMaterials
void insertHole(const PCB_VIA *aVia)
BRUSHED_METAL_NORMAL m_brushedMetalMaterial
static constexpr float MIN_DISTANCE_IU
PLATED_COPPER_NORMAL m_platedCopperMaterial
void createItemsFromContainer(const BVH_CONTAINER_2D *aContainer2d, PCB_LAYER_ID aLayer_id, const MATERIAL *aMaterialLayer, const SFVEC3F &aLayerColor, float aLayerZOffset)
PLASTIC_SHINE_NORMAL m_shinyPlasticMaterial
bool addExtrudedBodyToRaytracer(CONTAINER_3D &aDstContainer, const FOOTPRINT *aFootprint)
void addCounterborePlating(const BOARD_ITEM &aSource, const SFVEC2F &aCenter, float aInnerRadius, float aDepth, float aSurfaceZ, bool aIsFront)
void load3DModels(CONTAINER_3D &aDstContainer, bool aSkipMaterialInformation, std::stop_token aStop={})
BVH_CONTAINER_2D * m_antioutlineBoard2dObjects
CONTAINER_2D m_containerWithObjectsToDelete
Store the list of created objects special for RT that will be clear in the end.
std::unique_ptr< ACCELERATOR_3D > m_accelerator
void addPlaceholderToRaytracer(CONTAINER_3D &aDstContainer, const FOOTPRINT *aFootprint, const glm::mat4 &aFpMatrix, bool aHasExtrudedBody=false, float aOpacity=1.0f)
MODEL_MATERIALS * getModelMaterial(const S3DMODEL *a3DModel)
SOLDER_MASK_NORMAL m_solderMaskMaterial
void addModels(CONTAINER_3D &aDstContainer, const S3DMODEL *a3DModel, const glm::mat4 &aModelMatrix, float aFPOpacity, bool aSkipMaterialInformation, BOARD_ITEM *aBoardItem)
MAP_MODEL_MATERIALS m_modelMaterialMap
Stores materials of the 3D models.
void createObject(CONTAINER_3D &aDstContainer, const OBJECT_2D *aObject2D, float aZMin, float aZMax, const MATERIAL *aMaterial, const SFVEC3F &aObjColor)
Create one or more 3D objects form a 2D object and Z positions.
void Reload(bool aOnlyLoadCopperAndShapes, std::stop_token aStop={})
void SetColor(SFVEC3F aObjColor)
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 polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Represent a set of closed polygons.
void Simplify()
Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections)
int OutlineCount() const
Return the number of outlines in the set.
void Fracture(bool aSimplify=true)
Convert a set of polygons with holes to a single outline with "slits"/"fractures" connecting the oute...
void BooleanSubtract(const SHAPE_POLY_SET &b)
Perform boolean polyset difference.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
Procedural generation of the solder mask.
Definition material.h:122
A triangle object.
Definition triangle_3d.h:39
void SetColor(const SFVEC3F &aColor)
A vertical truncated cone with different radii at top and bottom.
Definition frustum_3d.h:35
void SetColor(SFVEC3F aObjColor)
Definition frustum_3d.h:47
A plane that is parallel to XY plane.
Definition plane_3d.h:34
void SetColor(SFVEC3F aObjColor)
Definition plane_3d.h:45
std::list< OBJECT_2D * > LIST_OBJECT2D
std::list< const OBJECT_2D * > CONST_LIST_OBJECT2D
#define _(s)
Declaration of the eda_3d_viewer class.
@ TENTHS_OF_A_DEGREE_T
Definition eda_angle.h:29
A truncated cone for raytracing, used for countersink visualization.
int MapPCBLayerTo3DLayer(PCB_LAYER_ID aLayer)
Definition layer_id.cpp:355
@ LAYER_3D_USER_1
Definition layer_ids.h:602
@ LAYER_3D_SOLDERMASK_TOP
Definition layer_ids.h:591
@ LAYER_3D_SOLDERMASK_BOTTOM
Definition layer_ids.h:590
@ LAYER_3D_BOARD
Definition layer_ids.h:585
@ LAYER_3D_USER_45
Definition layer_ids.h:646
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
Definition layer_ids.h:744
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ F_CrtYd
Definition layer_ids.h:112
@ B_Adhes
Definition layer_ids.h:99
@ Dwgs_User
Definition layer_ids.h:103
@ F_Paste
Definition layer_ids.h:100
@ Cmts_User
Definition layer_ids.h:104
@ F_Adhes
Definition layer_ids.h:98
@ B_Mask
Definition layer_ids.h:94
@ B_Cu
Definition layer_ids.h:61
@ Eco1_User
Definition layer_ids.h:105
@ F_Mask
Definition layer_ids.h:93
@ B_Paste
Definition layer_ids.h:101
@ F_Fab
Definition layer_ids.h:115
@ F_SilkS
Definition layer_ids.h:96
@ B_CrtYd
Definition layer_ids.h:111
@ Eco2_User
Definition layer_ids.h:106
@ B_SilkS
Definition layer_ids.h:97
@ F_Cu
Definition layer_ids.h:60
@ B_Fab
Definition layer_ids.h:114
#define CSGITEM_EMPTY
#define CSGITEM_FULL
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:461
PAD_DRILL_POST_MACHINING_MODE
Definition padstack.h:77
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
Definition padstack.h:104
static wxColor copperColor(220, 180, 30)
void ConvertPolygonToBlocks(const SHAPE_POLY_SET &aMainPath, CONTAINER_2D_BASE &aDstContainer, float aBiuTo3dUnitsScale, float aDivFactor, const BOARD_ITEM &aBoardItem, int aPolyIndex)
Use a polygon in the format of the ClipperLib::Path and process it and create multiple 2d objects (PO...
std::vector< SEGMENT_WITH_NORMALS > SEGMENTS_WIDTH_NORMALS
List used to test ray2d intersections.
Definition polygon_2d.h:65
std::vector< POLYSEGMENT > SEGMENTS
Definition polygon_2d.h:57
int64_t GetRunningMicroSecs()
An alternate way to calculate an elapsed time (in microsecondes) to class PROF_COUNTER.
void buildBoardBoundingBoxPoly(const BOARD *aBoard, SHAPE_POLY_SET &aOutline)
Get the complete bounding box of the board (including all items).
static size_t addOutlineToRaytracerObjects(CONTAINER_2D &aObjContainer, const SHAPE_POLY_SET &aOutline, float aBiuTo3d, const BOARD_ITEM &aBoardItem)
static float TransparencyControl(float aGrayColorValue, float aTransparency)
Perform an interpolation step to easy control the transparency based on the gray color value and tran...
SFVEC3F ConvertSRGBToLinear(const SFVEC3F &aSRGBcolor)
std::vector< BLINN_PHONG_MATERIAL > MODEL_MATERIALS
Vector of materials.
const SFVEC2F & Min() const
Definition bbox_2d.h:172
const SFVEC2F & Max() const
Definition bbox_2d.h:177
Manage a bounding box defined by two SFVEC3F min max points.
Definition bbox_3d.h:39
SFVEC3F GetCenter() const
Return the center point of the bounding box.
Definition bbox_3d.cpp:128
const SFVEC3F & Min() const
Return the minimum vertex pointer.
Definition bbox_3d.h:188
const SFVEC3F & Max() const
Return the maximum vertex pointer.
Definition bbox_3d.h:195
bool IsInitialized() const
Check if this bounding box is already initialized.
Definition bbox_3d.cpp:84
void Scale(float aScale)
Scales a bounding box by its center.
Definition bbox_3d.cpp:178
Handle a subset of a polygon.
Definition polygon_2d.h:75
std::vector< SEGMENTS > m_Outers
Definition polygon_2d.h:76
The properties of a padstack drill.
Definition padstack.h:277
std::optional< PAD_DRILL_POST_MACHINING_MODE > mode
Definition padstack.h:292
Store the a model based on meshes and materials.
Definition c3dmodel.h:111
SMATERIAL * m_Materials
The materials list of this model.
Definition c3dmodel.h:116
unsigned int m_MeshesSize
Number of meshes in the array.
Definition c3dmodel.h:112
SMESH * m_Meshes
The meshes list of this model.
Definition c3dmodel.h:113
unsigned int m_MaterialsSize
Number of materials in the material array.
Definition c3dmodel.h:115
float m_Shininess
Definition c3dmodel.h:39
SFVEC3F m_Specular
Definition c3dmodel.h:38
SFVEC3F m_Ambient
Definition c3dmodel.h:35
float m_Transparency
1.0 is completely transparent, 0.0 completely opaque
Definition c3dmodel.h:40
SFVEC3F m_Emissive
Definition c3dmodel.h:37
SFVEC3F m_Diffuse
Default diffuse color if m_Color is NULL.
Definition c3dmodel.h:36
Per-vertex normal/color/texcoors structure.
Definition c3dmodel.h:77
unsigned int * m_FaceIdx
Triangle Face Indexes.
Definition c3dmodel.h:84
SFVEC3F * m_Normals
Vertex normals array.
Definition c3dmodel.h:80
unsigned int m_MaterialIdx
Material Index to be used in this mesh (must be < m_MaterialsSize )
Definition c3dmodel.h:85
unsigned int m_VertexSize
Number of vertex in the arrays.
Definition c3dmodel.h:78
unsigned int m_FaceIdxSize
Number of elements of the m_FaceIdx array.
Definition c3dmodel.h:83
SFVEC3F * m_Color
Vertex color array, can be NULL.
Definition c3dmodel.h:82
SFVEC3F * m_Positions
Vertex position array.
Definition c3dmodel.h:79
KIBIS_MODEL * model
VECTOR3I v1(5, 5, 5)
VECTOR2I center
const SHAPE_LINE_CHAIN chain
int radius
VECTOR2I end
VECTOR2I v2(1, 0)
VECTOR2I v4(1, 1)
VECTOR2I v5(-70, -70)
VECTOR2I v3(-2, 1)
void ConvertPolygonToTriangles(const SHAPE_POLY_SET &aPolyList, CONTAINER_2D_BASE &aDstContainer, float aBiuTo3dUnitsScale, const BOARD_ITEM &aBoardItem)
Implement a triangle ray intersection based on article http://www.flipcode.com/archives/Raytracing_To...
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
Definition trigo.cpp:227
@ 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