2016-07-19 17:35:25 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-05-14 23:49:39 +00:00
|
|
|
* Copyright (C) 2015-2022 Mario Luzeiro <mrluzeiro@ua.pt>
|
|
|
|
* Copyright (C) 2015-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2016-07-19 17:35:25 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2021-01-03 22:23:00 +00:00
|
|
|
#include "render_3d_raytrace.h"
|
|
|
|
#include "shapes3D/plane_3d.h"
|
|
|
|
#include "shapes3D/round_segment_3d.h"
|
|
|
|
#include "shapes3D/layer_item_3d.h"
|
|
|
|
#include "shapes3D/cylinder_3d.h"
|
|
|
|
#include "shapes3D/triangle_3d.h"
|
|
|
|
#include "shapes2D/layer_item_2d.h"
|
|
|
|
#include "shapes2D/ring_2d.h"
|
|
|
|
#include "shapes2D/polygon_2d.h"
|
|
|
|
#include "shapes2D/filled_circle_2d.h"
|
2021-01-05 22:19:00 +00:00
|
|
|
#include "shapes2D/round_segment_2d.h"
|
2021-01-03 22:23:00 +00:00
|
|
|
#include "accelerators/bvh_pbrt.h"
|
2016-07-19 17:35:25 +00:00
|
|
|
#include "3d_fastmath.h"
|
|
|
|
#include "3d_math.h"
|
|
|
|
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
|
|
|
#include <footprint.h>
|
2022-09-26 02:54:08 +00:00
|
|
|
#include <fp_lib_table.h>
|
|
|
|
#include <eda_3d_viewer_frame.h>
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
#include <base_units.h>
|
2018-04-08 10:28:59 +00:00
|
|
|
#include <profile.h> // To use GetRunningMicroSecs or another profiling utility
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-08-21 08:56:15 +00:00
|
|
|
/**
|
|
|
|
* Perform an interpolation step to easy control the transparency based on the
|
2020-12-12 17:29:11 +00:00
|
|
|
* gray color value and transparency.
|
|
|
|
*
|
2020-08-21 08:56:15 +00:00
|
|
|
* @param aGrayColorValue - diffuse gray value
|
2020-08-30 16:47:30 +00:00
|
|
|
* @param aTransparency - control
|
2020-08-21 08:56:15 +00:00
|
|
|
* @return transparency to use in material
|
|
|
|
*/
|
2020-08-30 16:47:30 +00:00
|
|
|
static float TransparencyControl( float aGrayColorValue, float aTransparency )
|
2020-08-21 08:56:15 +00:00
|
|
|
{
|
2020-08-30 16:47:30 +00:00
|
|
|
const float aaa = aTransparency * aTransparency * aTransparency;
|
2020-08-21 08:56:15 +00:00
|
|
|
|
|
|
|
// 1.00-1.05*(1.0-x)^3
|
2020-08-30 16:47:30 +00:00
|
|
|
float ca = 1.0f - aTransparency;
|
2020-12-12 17:29:11 +00:00
|
|
|
ca = 1.00f - 1.05f * ca * ca * ca;
|
2020-08-21 08:56:15 +00:00
|
|
|
|
|
|
|
return glm::max( glm::min( aGrayColorValue * ca + aaa, 1.0f ), 0.0f );
|
|
|
|
}
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
/**
|
2020-12-12 17:29:11 +00:00
|
|
|
* Scale conversion from 3d model units to pcb units
|
2016-07-19 17:35:25 +00:00
|
|
|
*/
|
2022-09-17 00:45:14 +00:00
|
|
|
#define UNITS3D_TO_UNITSPCB ( pcbIUScale.IU_PER_MM )
|
2020-12-12 17:29:11 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
void RENDER_3D_RAYTRACE::setupMaterials()
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2021-08-30 20:30:18 +00:00
|
|
|
MATERIAL::SetDefaultRefractionRayCount( m_boardAdapter.m_Cfg->m_Render.raytrace_nrsamples_refractions );
|
|
|
|
MATERIAL::SetDefaultReflectionRayCount( m_boardAdapter.m_Cfg->m_Render.raytrace_nrsamples_reflections );
|
2020-09-04 15:12:01 +00:00
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
MATERIAL::SetDefaultRefractionRecursionCount( m_boardAdapter.m_Cfg->m_Render.raytrace_recursivelevel_refractions );
|
|
|
|
MATERIAL::SetDefaultReflectionRecursionCount( m_boardAdapter.m_Cfg->m_Render.raytrace_recursivelevel_reflections );
|
2020-09-04 15:12:01 +00:00
|
|
|
|
2022-09-17 00:45:14 +00:00
|
|
|
double mmTo3Dunits = pcbIUScale.IU_PER_MM * m_boardAdapter.BiuTo3dUnits();
|
2016-09-30 23:59:51 +00:00
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.raytrace_procedural_textures )
|
2016-10-02 08:11:00 +00:00
|
|
|
{
|
2021-01-07 19:33:43 +00:00
|
|
|
m_boardMaterial = BOARD_NORMAL( 0.40f * mmTo3Dunits );
|
|
|
|
m_copperMaterial = COPPER_NORMAL( 4.0f * mmTo3Dunits, &m_boardMaterial );
|
|
|
|
m_platedCopperMaterial = PLATED_COPPER_NORMAL( 0.5f * mmTo3Dunits );
|
|
|
|
m_solderMaskMaterial = SOLDER_MASK_NORMAL( &m_boardMaterial );
|
|
|
|
m_plasticMaterial = PLASTIC_NORMAL( 0.05f * mmTo3Dunits );
|
|
|
|
m_shinyPlasticMaterial = PLASTIC_SHINE_NORMAL( 0.1f * mmTo3Dunits );
|
|
|
|
m_brushedMetalMaterial = BRUSHED_METAL_NORMAL( 0.05f * mmTo3Dunits );
|
|
|
|
m_silkScreenMaterial = SILK_SCREEN_NORMAL( 0.25f * mmTo3Dunits );
|
2016-10-02 08:11:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// http://devernay.free.fr/cours/opengl/materials.html
|
|
|
|
// Copper
|
2020-12-12 17:29:11 +00:00
|
|
|
const SFVEC3F copperSpecularLinear =
|
|
|
|
ConvertSRGBToLinear( glm::clamp( (SFVEC3F) m_boardAdapter.m_CopperColor * 0.5f + 0.25f,
|
|
|
|
SFVEC3F( 0.0f ), SFVEC3F( 1.0f ) ) );
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
m_materials.m_Copper = BLINN_PHONG_MATERIAL(
|
|
|
|
ConvertSRGBToLinear( (SFVEC3F) m_boardAdapter.m_CopperColor * 0.3f ),
|
|
|
|
SFVEC3F( 0.0f ), copperSpecularLinear, 0.4f * 128.0f, 0.0f, 0.0f );
|
2020-09-08 00:32:00 +00:00
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.raytrace_procedural_textures )
|
2021-01-07 19:33:43 +00:00
|
|
|
m_materials.m_Copper.SetGenerator( &m_platedCopperMaterial );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
m_materials.m_NonPlatedCopper = BLINN_PHONG_MATERIAL(
|
|
|
|
ConvertSRGBToLinear( SFVEC3F( 0.191f, 0.073f, 0.022f ) ), SFVEC3F( 0.0f, 0.0f, 0.0f ),
|
|
|
|
SFVEC3F( 0.256f, 0.137f, 0.086f ), 0.15f * 128.0f, 0.0f, 0.0f );
|
2020-09-07 11:38:05 +00:00
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.raytrace_procedural_textures )
|
2021-01-07 19:33:43 +00:00
|
|
|
m_materials.m_NonPlatedCopper.SetGenerator( &m_copperMaterial );
|
2016-09-30 23:59:51 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
m_materials.m_Paste = BLINN_PHONG_MATERIAL(
|
2020-12-12 17:29:11 +00:00
|
|
|
ConvertSRGBToLinear( (SFVEC3F) m_boardAdapter.m_SolderPasteColor )
|
2021-01-02 21:05:29 +00:00
|
|
|
* ConvertSRGBToLinear( (SFVEC3F) m_boardAdapter.m_SolderPasteColor ),
|
|
|
|
SFVEC3F( 0.0f, 0.0f, 0.0f ),
|
2020-12-12 17:29:11 +00:00
|
|
|
ConvertSRGBToLinear( (SFVEC3F) m_boardAdapter.m_SolderPasteColor )
|
|
|
|
* ConvertSRGBToLinear(
|
2021-01-02 21:05:29 +00:00
|
|
|
(SFVEC3F) m_boardAdapter.m_SolderPasteColor ),
|
|
|
|
0.10f * 128.0f, 0.0f, 0.0f );
|
|
|
|
|
|
|
|
m_materials.m_SilkS = BLINN_PHONG_MATERIAL( ConvertSRGBToLinear( SFVEC3F( 0.11f ) ),
|
|
|
|
SFVEC3F( 0.0f, 0.0f, 0.0f ),
|
|
|
|
glm::clamp( ( ( SFVEC3F )( 1.0f ) - ConvertSRGBToLinear(
|
|
|
|
(SFVEC3F) m_boardAdapter.m_SilkScreenColorTop ) ),
|
|
|
|
SFVEC3F( 0.0f ), SFVEC3F( 0.10f ) ), 0.078125f * 128.0f, 0.0f, 0.0f );
|
2020-01-22 22:38:30 +00:00
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.raytrace_procedural_textures )
|
2021-01-07 19:33:43 +00:00
|
|
|
m_materials.m_SilkS.SetGenerator( &m_silkScreenMaterial );
|
2020-11-06 17:36:04 +00:00
|
|
|
|
2020-08-21 08:56:15 +00:00
|
|
|
// Assume that SolderMaskTop == SolderMaskBot
|
|
|
|
const float solderMask_gray =
|
2020-03-26 14:05:20 +00:00
|
|
|
( m_boardAdapter.m_SolderMaskColorTop.r + m_boardAdapter.m_SolderMaskColorTop.g
|
2020-12-12 17:29:11 +00:00
|
|
|
+ m_boardAdapter.m_SolderMaskColorTop.b )
|
2020-01-22 22:38:30 +00:00
|
|
|
/ 3.0f;
|
|
|
|
|
2020-08-30 16:47:30 +00:00
|
|
|
const float solderMask_transparency = TransparencyControl( solderMask_gray,
|
2021-01-02 21:05:29 +00:00
|
|
|
1.0f - m_boardAdapter.m_SolderMaskColorTop.a );
|
2016-11-26 14:38:51 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
m_materials.m_SolderMask = BLINN_PHONG_MATERIAL(
|
|
|
|
ConvertSRGBToLinear( (SFVEC3F) m_boardAdapter.m_SolderMaskColorTop ) * 0.10f,
|
|
|
|
SFVEC3F( 0.0f, 0.0f, 0.0f ),
|
|
|
|
SFVEC3F( glm::clamp( solderMask_gray * 2.0f, 0.25f, 1.0f ) ), 0.85f * 128.0f,
|
|
|
|
solderMask_transparency, 0.16f );
|
2020-01-22 22:38:30 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
m_materials.m_SolderMask.SetCastShadows( true );
|
2021-01-07 19:33:43 +00:00
|
|
|
m_materials.m_SolderMask.SetRefractionRayCount( 1 );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.raytrace_procedural_textures )
|
2021-01-07 19:33:43 +00:00
|
|
|
m_materials.m_SolderMask.SetGenerator( &m_solderMaskMaterial );
|
2016-09-30 23:59:51 +00:00
|
|
|
|
2020-12-12 17:29:11 +00:00
|
|
|
m_materials.m_EpoxyBoard =
|
2021-01-02 21:05:29 +00:00
|
|
|
BLINN_PHONG_MATERIAL( ConvertSRGBToLinear( SFVEC3F( 16.0f / 255.0f, 14.0f / 255.0f,
|
|
|
|
10.0f / 255.0f ) ),
|
|
|
|
SFVEC3F( 0.0f, 0.0f, 0.0f ),
|
|
|
|
ConvertSRGBToLinear( SFVEC3F( 10.0f / 255.0f, 8.0f / 255.0f,
|
|
|
|
10.0f / 255.0f ) ),
|
|
|
|
0.1f * 128.0f, 1.0f - m_boardAdapter.m_BoardBodyColor.a, 0.0f );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2017-01-21 12:30:05 +00:00
|
|
|
m_materials.m_EpoxyBoard.SetAbsorvance( 10.0f );
|
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.raytrace_procedural_textures )
|
2021-01-07 19:33:43 +00:00
|
|
|
m_materials.m_EpoxyBoard.SetGenerator( &m_boardMaterial );
|
2016-09-30 23:59:51 +00:00
|
|
|
|
2020-12-12 17:29:11 +00:00
|
|
|
SFVEC3F bgTop = ConvertSRGBToLinear( (SFVEC3F) m_boardAdapter.m_BgColorTop );
|
2021-01-02 21:05:29 +00:00
|
|
|
|
|
|
|
m_materials.m_Floor = BLINN_PHONG_MATERIAL( bgTop * 0.125f, SFVEC3F( 0.0f, 0.0f, 0.0f ),
|
|
|
|
( SFVEC3F( 1.0f ) - bgTop ) / 3.0f,
|
|
|
|
0.10f * 128.0f, 0.0f, 0.50f );
|
2020-04-22 23:00:15 +00:00
|
|
|
m_materials.m_Floor.SetCastShadows( false );
|
2021-01-07 19:33:43 +00:00
|
|
|
m_materials.m_Floor.SetReflectionRecursionCount( 1 );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
void RENDER_3D_RAYTRACE::createObject( CONTAINER_3D& aDstContainer, const OBJECT_2D* aObject2D,
|
|
|
|
float aZMin, float aZMax, const MATERIAL* aMaterial,
|
|
|
|
const SFVEC3F& aObjColor )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
switch( aObject2D->GetObjectType() )
|
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
case OBJECT_2D_TYPE::DUMMYBLOCK:
|
2019-12-30 13:01:06 +00:00
|
|
|
{
|
2021-01-07 19:33:43 +00:00
|
|
|
m_convertedDummyBlockCount++;
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
XY_PLANE* objPtr;
|
|
|
|
objPtr = new XY_PLANE( BBOX_3D(
|
2019-12-30 13:01:06 +00:00
|
|
|
SFVEC3F( aObject2D->GetBBox().Min().x, aObject2D->GetBBox().Min().y, aZMin ),
|
|
|
|
SFVEC3F( aObject2D->GetBBox().Max().x, aObject2D->GetBBox().Max().y, aZMin ) ) );
|
|
|
|
objPtr->SetMaterial( aMaterial );
|
|
|
|
objPtr->SetColor( ConvertSRGBToLinear( aObjColor ) );
|
|
|
|
aDstContainer.Add( objPtr );
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
objPtr = new XY_PLANE( BBOX_3D(
|
2019-12-30 13:01:06 +00:00
|
|
|
SFVEC3F( aObject2D->GetBBox().Min().x, aObject2D->GetBBox().Min().y, aZMax ),
|
|
|
|
SFVEC3F( aObject2D->GetBBox().Max().x, aObject2D->GetBBox().Max().y, aZMax ) ) );
|
|
|
|
objPtr->SetMaterial( aMaterial );
|
|
|
|
objPtr->SetColor( ConvertSRGBToLinear( aObjColor ) );
|
|
|
|
aDstContainer.Add( objPtr );
|
2021-01-07 19:33:43 +00:00
|
|
|
break;
|
2019-12-30 13:01:06 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
case OBJECT_2D_TYPE::ROUNDSEG:
|
2019-12-30 13:01:06 +00:00
|
|
|
{
|
2021-01-07 19:33:43 +00:00
|
|
|
m_converted2dRoundSegmentCount++;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
const ROUND_SEGMENT_2D* aRoundSeg2D = static_cast<const ROUND_SEGMENT_2D*>( aObject2D );
|
|
|
|
ROUND_SEGMENT* objPtr = new ROUND_SEGMENT( *aRoundSeg2D, aZMin, aZMax );
|
2019-12-30 13:01:06 +00:00
|
|
|
objPtr->SetMaterial( aMaterial );
|
|
|
|
objPtr->SetColor( ConvertSRGBToLinear( aObjColor ) );
|
|
|
|
aDstContainer.Add( objPtr );
|
2021-01-07 19:33:43 +00:00
|
|
|
break;
|
2019-12-30 13:01:06 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2019-12-30 13:01:06 +00:00
|
|
|
default:
|
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
LAYER_ITEM* objPtr = new LAYER_ITEM( aObject2D, aZMin, aZMax );
|
2019-12-30 13:01:06 +00:00
|
|
|
objPtr->SetMaterial( aMaterial );
|
|
|
|
objPtr->SetColor( ConvertSRGBToLinear( aObjColor ) );
|
|
|
|
aDstContainer.Add( objPtr );
|
2021-01-07 19:33:43 +00:00
|
|
|
break;
|
2019-12-30 13:01:06 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
|
|
|
|
void RENDER_3D_RAYTRACE::createItemsFromContainer( const BVH_CONTAINER_2D* aContainer2d,
|
2021-08-19 10:39:29 +00:00
|
|
|
PCB_LAYER_ID aLayer_id,
|
|
|
|
const MATERIAL* aMaterialLayer,
|
|
|
|
const SFVEC3F& aLayerColor,
|
|
|
|
float aLayerZOffset )
|
2020-09-07 11:38:05 +00:00
|
|
|
{
|
|
|
|
if( aContainer2d == nullptr )
|
|
|
|
return;
|
|
|
|
|
2020-12-12 17:29:11 +00:00
|
|
|
const LIST_OBJECT2D& listObject2d = aContainer2d->GetList();
|
2020-09-07 11:38:05 +00:00
|
|
|
|
|
|
|
if( listObject2d.size() == 0 )
|
|
|
|
return;
|
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
for( const OBJECT_2D* object2d_A : listObject2d )
|
2020-09-07 11:38:05 +00:00
|
|
|
{
|
2020-12-12 17:29:11 +00:00
|
|
|
// not yet used / implemented (can be used in future to clip the objects in the
|
|
|
|
// board borders
|
2021-01-02 21:05:29 +00:00
|
|
|
OBJECT_2D* object2d_C = CSGITEM_FULL;
|
2020-09-07 11:38:05 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
std::vector<const OBJECT_2D*>* object2d_B = CSGITEM_EMPTY;
|
2020-09-07 11:38:05 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
object2d_B = new std::vector<const OBJECT_2D*>();
|
2020-09-07 11:38:05 +00:00
|
|
|
|
|
|
|
// Subtract holes but not in SolderPaste
|
|
|
|
// (can be added as an option in future)
|
2021-08-19 10:39:29 +00:00
|
|
|
if( !( aLayer_id == B_Paste || aLayer_id == F_Paste ) )
|
2020-09-07 11:38:05 +00:00
|
|
|
{
|
|
|
|
// Check if there are any layerhole that intersects this object
|
2020-12-12 17:29:11 +00:00
|
|
|
// Eg: a segment is cut by a via hole or THT hole.
|
2021-01-05 22:19:00 +00:00
|
|
|
const MAP_CONTAINER_2D_BASE& layerHolesMap = m_boardAdapter.GetLayerHoleMap();
|
2020-09-07 11:38:05 +00:00
|
|
|
|
2020-12-12 17:29:11 +00:00
|
|
|
if( layerHolesMap.find( aLayer_id ) != layerHolesMap.end() )
|
2020-09-07 11:38:05 +00:00
|
|
|
{
|
2021-08-19 10:39:29 +00:00
|
|
|
const BVH_CONTAINER_2D* holes2d = layerHolesMap.at( aLayer_id );
|
2020-09-07 11:38:05 +00:00
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
CONST_LIST_OBJECT2D intersecting;
|
2020-09-07 11:38:05 +00:00
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
holes2d->GetIntersectingObjects( object2d_A->GetBBox(), intersecting );
|
2020-09-07 11:38:05 +00:00
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
for( const OBJECT_2D* hole2d : intersecting )
|
|
|
|
object2d_B->push_back( hole2d );
|
2020-09-07 11:38:05 +00:00
|
|
|
}
|
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
// Check if there are any THT that intersects this object. If we're processing a silk
|
|
|
|
// layer and the flag is set, then clip the silk at the outer edge of the annular ring,
|
|
|
|
// rather than the at the outer edge of the copper plating.
|
2021-01-02 21:05:29 +00:00
|
|
|
const BVH_CONTAINER_2D& throughHoleOuter =
|
2021-08-30 20:30:18 +00:00
|
|
|
m_boardAdapter.m_Cfg->m_Render.clip_silk_on_via_annulus
|
|
|
|
&& m_boardAdapter.m_Cfg->m_Render.realistic
|
|
|
|
&& ( aLayer_id == B_SilkS || aLayer_id == F_SilkS ) ?
|
|
|
|
m_boardAdapter.GetThroughHoleAnnularRings() :
|
|
|
|
m_boardAdapter.GetThroughHoleOds();
|
2020-09-07 11:38:05 +00:00
|
|
|
|
|
|
|
if( !throughHoleOuter.GetList().empty() )
|
|
|
|
{
|
2021-08-19 10:39:29 +00:00
|
|
|
CONST_LIST_OBJECT2D intersecting;
|
2020-09-07 11:38:05 +00:00
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
throughHoleOuter.GetIntersectingObjects( object2d_A->GetBBox(), intersecting );
|
2020-09-07 11:38:05 +00:00
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
for( const OBJECT_2D* hole2d : intersecting )
|
|
|
|
object2d_B->push_back( hole2d );
|
2020-09-07 11:38:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-29 12:48:45 +00:00
|
|
|
if( !m_antioutlineBoard2dObjects->GetList().empty() )
|
|
|
|
{
|
2021-08-19 10:39:29 +00:00
|
|
|
CONST_LIST_OBJECT2D intersecting;
|
2020-10-29 12:48:45 +00:00
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
m_antioutlineBoard2dObjects->GetIntersectingObjects( object2d_A->GetBBox(),
|
|
|
|
intersecting );
|
2020-10-29 12:48:45 +00:00
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
for( const OBJECT_2D* obj : intersecting )
|
|
|
|
object2d_B->push_back( obj );
|
2020-10-29 12:48:45 +00:00
|
|
|
}
|
2020-09-07 11:38:05 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
const MAP_CONTAINER_2D_BASE& mapLayers = m_boardAdapter.GetLayerMap();
|
2020-09-07 11:38:05 +00:00
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.subtract_mask_from_silk
|
|
|
|
&& m_boardAdapter.m_Cfg->m_Render.realistic
|
2021-08-19 10:39:29 +00:00
|
|
|
&& ( ( aLayer_id == B_SilkS && mapLayers.find( B_Mask ) != mapLayers.end() )
|
|
|
|
|| ( aLayer_id == F_SilkS && mapLayers.find( F_Mask ) != mapLayers.end() ) ) )
|
2020-09-07 11:38:05 +00:00
|
|
|
{
|
|
|
|
const PCB_LAYER_ID layerMask_id = ( aLayer_id == B_SilkS ) ? B_Mask : F_Mask;
|
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
const BVH_CONTAINER_2D* containerMaskLayer2d = mapLayers.at( layerMask_id );
|
2020-09-07 11:38:05 +00:00
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
CONST_LIST_OBJECT2D intersecting;
|
2020-09-07 11:38:05 +00:00
|
|
|
|
2020-12-12 17:29:11 +00:00
|
|
|
if( containerMaskLayer2d ) // can be null if B_Mask or F_Mask is not shown
|
2021-08-19 10:39:29 +00:00
|
|
|
containerMaskLayer2d->GetIntersectingObjects( object2d_A->GetBBox(), intersecting );
|
2020-09-07 11:38:05 +00:00
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
for( const OBJECT_2D* obj2d : intersecting )
|
|
|
|
object2d_B->push_back( obj2d );
|
2020-09-07 11:38:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( object2d_B->empty() )
|
|
|
|
{
|
|
|
|
delete object2d_B;
|
|
|
|
object2d_B = CSGITEM_EMPTY;
|
|
|
|
}
|
|
|
|
|
2020-12-12 17:29:11 +00:00
|
|
|
if( ( object2d_B == CSGITEM_EMPTY ) && ( object2d_C == CSGITEM_FULL ) )
|
2020-09-07 11:38:05 +00:00
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
LAYER_ITEM* objPtr = new LAYER_ITEM( object2d_A,
|
2021-01-05 22:19:00 +00:00
|
|
|
m_boardAdapter.GetLayerBottomZPos( aLayer_id ) - aLayerZOffset,
|
|
|
|
m_boardAdapter.GetLayerTopZPos( aLayer_id ) + aLayerZOffset );
|
2020-09-07 11:38:05 +00:00
|
|
|
objPtr->SetMaterial( aMaterialLayer );
|
|
|
|
objPtr->SetColor( ConvertSRGBToLinear( aLayerColor ) );
|
2021-01-07 19:33:43 +00:00
|
|
|
m_objectContainer.Add( objPtr );
|
2020-09-07 11:38:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
LAYER_ITEM_2D* itemCSG2d = new LAYER_ITEM_2D( object2d_A, object2d_B, object2d_C,
|
|
|
|
object2d_A->GetBoardItem() );
|
2020-09-07 11:38:05 +00:00
|
|
|
m_containerWithObjectsToDelete.Add( itemCSG2d );
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
LAYER_ITEM* objPtr = new LAYER_ITEM( itemCSG2d,
|
2021-01-05 22:19:00 +00:00
|
|
|
m_boardAdapter.GetLayerBottomZPos( aLayer_id ) - aLayerZOffset,
|
|
|
|
m_boardAdapter.GetLayerTopZPos( aLayer_id ) + aLayerZOffset );
|
2020-09-07 11:38:05 +00:00
|
|
|
|
|
|
|
objPtr->SetMaterial( aMaterialLayer );
|
|
|
|
objPtr->SetColor( ConvertSRGBToLinear( aLayerColor ) );
|
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
m_objectContainer.Add( objPtr );
|
2020-09-07 11:38:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-12-12 17:29:11 +00:00
|
|
|
|
2020-10-29 12:48:45 +00:00
|
|
|
extern void buildBoardBoundingBoxPoly( const BOARD* aBoard, SHAPE_POLY_SET& aOutline );
|
|
|
|
|
2020-12-12 17:29:11 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
void RENDER_3D_RAYTRACE::Reload( REPORTER* aStatusReporter, REPORTER* aWarningReporter,
|
|
|
|
bool aOnlyLoadCopperAndShapes )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
m_reloadRequested = false;
|
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
m_modelMaterialMap.clear();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
OBJECT_2D_STATS::Instance().ResetStats();
|
|
|
|
OBJECT_3D_STATS::Instance().ResetStats();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
unsigned stats_startReloadTime = GetRunningMicroSecs();
|
|
|
|
|
2020-09-04 00:00:56 +00:00
|
|
|
if( !aOnlyLoadCopperAndShapes )
|
|
|
|
{
|
|
|
|
m_boardAdapter.InitSettings( aStatusReporter, aWarningReporter );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
SFVEC3F camera_pos = m_boardAdapter.GetBoardCenter();
|
2020-09-04 00:00:56 +00:00
|
|
|
m_camera.SetBoardLookAtPos( camera_pos );
|
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
m_objectContainer.Clear();
|
2016-07-19 17:35:25 +00:00
|
|
|
m_containerWithObjectsToDelete.Clear();
|
|
|
|
|
2020-05-22 13:28:04 +00:00
|
|
|
setupMaterials();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-11-10 16:30:11 +00:00
|
|
|
if( aStatusReporter )
|
|
|
|
aStatusReporter->Report( _( "Load Raytracing: board" ) );
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
// Create and add the outline board
|
|
|
|
delete m_outlineBoard2dObjects;
|
2020-10-29 12:48:45 +00:00
|
|
|
delete m_antioutlineBoard2dObjects;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
m_outlineBoard2dObjects = new CONTAINER_2D;
|
|
|
|
m_antioutlineBoard2dObjects = new BVH_CONTAINER_2D;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-09-04 00:00:56 +00:00
|
|
|
if( !aOnlyLoadCopperAndShapes )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-09-04 00:00:56 +00:00
|
|
|
const int outlineCount = m_boardAdapter.GetBoardPoly().OutlineCount();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-09-04 00:00:56 +00:00
|
|
|
if( outlineCount > 0 )
|
2020-01-04 20:50:37 +00:00
|
|
|
{
|
2020-09-04 00:00:56 +00:00
|
|
|
float divFactor = 0.0f;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
if( m_boardAdapter.GetViaCount() )
|
|
|
|
divFactor = m_boardAdapter.GetAverageViaHoleDiameter() * 18.0f;
|
|
|
|
else if( m_boardAdapter.GetHoleCount() )
|
|
|
|
divFactor = m_boardAdapter.GetAverageHoleDiameter() * 8.0f;
|
2020-09-04 00:00:56 +00:00
|
|
|
|
|
|
|
SHAPE_POLY_SET boardPolyCopy = m_boardAdapter.GetBoardPoly();
|
2020-10-29 12:48:45 +00:00
|
|
|
|
|
|
|
// Calculate an antiboard outline
|
|
|
|
SHAPE_POLY_SET antiboardPoly;
|
|
|
|
|
|
|
|
buildBoardBoundingBoxPoly( m_boardAdapter.GetBoard(), antiboardPoly );
|
|
|
|
|
|
|
|
antiboardPoly.BooleanSubtract( boardPolyCopy, SHAPE_POLY_SET::PM_FAST );
|
|
|
|
antiboardPoly.Fracture( SHAPE_POLY_SET::PM_FAST );
|
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
for( int ii = 0; ii < antiboardPoly.OutlineCount(); ii++ )
|
2020-10-29 12:48:45 +00:00
|
|
|
{
|
2021-08-19 10:39:29 +00:00
|
|
|
ConvertPolygonToBlocks( antiboardPoly, *m_antioutlineBoard2dObjects,
|
|
|
|
m_boardAdapter.BiuTo3dUnits(), -1.0f,
|
|
|
|
*m_boardAdapter.GetBoard(), ii );
|
2020-10-29 12:48:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_antioutlineBoard2dObjects->BuildBVH();
|
|
|
|
|
2020-09-04 00:00:56 +00:00
|
|
|
boardPolyCopy.Fracture( SHAPE_POLY_SET::PM_FAST );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
for( int ii = 0; ii < outlineCount; ii++ )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2021-06-10 01:24:15 +00:00
|
|
|
ConvertPolygonToBlocks( boardPolyCopy, *m_outlineBoard2dObjects,
|
2021-08-19 10:39:29 +00:00
|
|
|
m_boardAdapter.BiuTo3dUnits(), divFactor,
|
|
|
|
*m_boardAdapter.GetBoard(), ii );
|
2020-09-04 00:00:56 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.show_board_body )
|
2020-09-04 00:00:56 +00:00
|
|
|
{
|
2020-12-12 17:29:11 +00:00
|
|
|
const LIST_OBJECT2D& listObjects = m_outlineBoard2dObjects->GetList();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
for( const OBJECT_2D* object2d_A : listObjects )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
std::vector<const OBJECT_2D*>* object2d_B = new std::vector<const OBJECT_2D*>();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-09-04 00:00:56 +00:00
|
|
|
// Check if there are any THT that intersects this outline object part
|
2021-01-05 22:19:00 +00:00
|
|
|
if( !m_boardAdapter.GetThroughHoleOds().GetList().empty() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2021-08-19 10:39:29 +00:00
|
|
|
const BVH_CONTAINER_2D& throughHoles = m_boardAdapter.GetThroughHoleOds();
|
|
|
|
CONST_LIST_OBJECT2D intersecting;
|
2020-09-04 00:00:56 +00:00
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
throughHoles.GetIntersectingObjects( object2d_A->GetBBox(), intersecting );
|
|
|
|
|
|
|
|
for( const OBJECT_2D* hole : intersecting )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2021-08-19 10:39:29 +00:00
|
|
|
if( object2d_A->Intersects( hole->GetBBox() ) )
|
|
|
|
object2d_B->push_back( hole );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-29 12:48:45 +00:00
|
|
|
if( !m_antioutlineBoard2dObjects->GetList().empty() )
|
|
|
|
{
|
2021-08-19 10:39:29 +00:00
|
|
|
CONST_LIST_OBJECT2D intersecting;
|
2020-10-29 12:48:45 +00:00
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
m_antioutlineBoard2dObjects->GetIntersectingObjects( object2d_A->GetBBox(),
|
|
|
|
intersecting );
|
2020-10-29 12:48:45 +00:00
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
for( const OBJECT_2D* obj : intersecting )
|
|
|
|
object2d_B->push_back( obj );
|
2020-10-29 12:48:45 +00:00
|
|
|
}
|
|
|
|
|
2020-09-04 00:00:56 +00:00
|
|
|
if( object2d_B->empty() )
|
|
|
|
{
|
|
|
|
delete object2d_B;
|
|
|
|
object2d_B = CSGITEM_EMPTY;
|
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-09-04 00:00:56 +00:00
|
|
|
if( object2d_B == CSGITEM_EMPTY )
|
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
LAYER_ITEM* objPtr = new LAYER_ITEM( object2d_A,
|
2021-08-19 10:39:29 +00:00
|
|
|
m_boardAdapter.GetLayerBottomZPos( F_Cu ),
|
|
|
|
m_boardAdapter.GetLayerBottomZPos( B_Cu ) );
|
2020-09-04 00:00:56 +00:00
|
|
|
|
|
|
|
objPtr->SetMaterial( &m_materials.m_EpoxyBoard );
|
2021-08-19 10:39:29 +00:00
|
|
|
objPtr->SetColor( ConvertSRGBToLinear( m_boardAdapter.m_BoardBodyColor ) );
|
2021-01-07 19:33:43 +00:00
|
|
|
m_objectContainer.Add( objPtr );
|
2020-09-04 00:00:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-25 20:33:51 +00:00
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
LAYER_ITEM_2D* itemCSG2d = new LAYER_ITEM_2D( object2d_A, object2d_B,
|
|
|
|
CSGITEM_FULL,
|
|
|
|
*m_boardAdapter.GetBoard() );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-09-04 00:00:56 +00:00
|
|
|
m_containerWithObjectsToDelete.Add( itemCSG2d );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
LAYER_ITEM* objPtr = new LAYER_ITEM( itemCSG2d,
|
2021-08-19 10:39:29 +00:00
|
|
|
m_boardAdapter.GetLayerBottomZPos( F_Cu ),
|
|
|
|
m_boardAdapter.GetLayerBottomZPos( B_Cu ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-09-04 00:00:56 +00:00
|
|
|
objPtr->SetMaterial( &m_materials.m_EpoxyBoard );
|
2021-08-19 10:39:29 +00:00
|
|
|
objPtr->SetColor( ConvertSRGBToLinear( m_boardAdapter.m_BoardBodyColor ) );
|
2021-01-07 19:33:43 +00:00
|
|
|
m_objectContainer.Add( objPtr );
|
2020-09-04 00:00:56 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
2020-09-04 00:00:56 +00:00
|
|
|
// Add cylinders of the board body to container
|
2020-12-12 17:29:11 +00:00
|
|
|
// Note: This is actually a workaround for the holes in the board.
|
2020-09-04 00:00:56 +00:00
|
|
|
// The issue is because if a hole is in a border of a divided polygon ( ex
|
2020-12-12 17:29:11 +00:00
|
|
|
// a polygon or dummy block) it will cut also the render of the hole.
|
2020-09-04 00:00:56 +00:00
|
|
|
// So this will add a full hole.
|
|
|
|
// In fact, that is not need if the hole have copper.
|
2021-01-05 22:19:00 +00:00
|
|
|
if( !m_boardAdapter.GetThroughHoleOds().GetList().empty() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2021-01-05 22:19:00 +00:00
|
|
|
const LIST_OBJECT2D& holeList = m_boardAdapter.GetThroughHoleOds().GetList();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
for( const OBJECT_2D* hole2d : holeList )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-10-29 12:48:45 +00:00
|
|
|
if( !m_antioutlineBoard2dObjects->GetList().empty() )
|
|
|
|
{
|
2021-08-19 10:39:29 +00:00
|
|
|
CONST_LIST_OBJECT2D intersecting;
|
2020-10-29 12:48:45 +00:00
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
m_antioutlineBoard2dObjects->GetIntersectingObjects( hole2d->GetBBox(),
|
|
|
|
intersecting );
|
2020-10-29 12:48:45 +00:00
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
// Do not add cylinder if it intersects the edge of the board
|
|
|
|
if( !intersecting.empty() )
|
2020-10-29 12:48:45 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-09-04 00:00:56 +00:00
|
|
|
switch( hole2d->GetObjectType() )
|
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
case OBJECT_2D_TYPE::FILLED_CIRCLE:
|
2020-09-04 00:00:56 +00:00
|
|
|
{
|
|
|
|
const float radius = hole2d->GetBBox().GetExtent().x * 0.5f * 0.999f;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
CYLINDER* objPtr = new CYLINDER( hole2d->GetCentroid(),
|
2021-01-05 22:19:00 +00:00
|
|
|
NextFloatDown( m_boardAdapter.GetLayerBottomZPos( F_Cu ) ),
|
|
|
|
NextFloatUp( m_boardAdapter.GetLayerBottomZPos( B_Cu ) ),
|
2020-12-12 17:29:11 +00:00
|
|
|
radius );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-09-04 00:00:56 +00:00
|
|
|
objPtr->SetMaterial( &m_materials.m_EpoxyBoard );
|
2021-08-19 10:39:29 +00:00
|
|
|
objPtr->SetColor( ConvertSRGBToLinear( m_boardAdapter.m_BoardBodyColor ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
m_objectContainer.Add( objPtr );
|
2020-09-04 00:00:56 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
break;
|
2020-09-04 00:00:56 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-10 16:30:11 +00:00
|
|
|
if( aStatusReporter )
|
|
|
|
aStatusReporter->Report( _( "Load Raytracing: layers" ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// Add layers maps (except B_Mask and F_Mask)
|
2022-07-29 21:02:35 +00:00
|
|
|
for( const std::pair<const PCB_LAYER_ID, BVH_CONTAINER_2D*>& entry : m_boardAdapter.GetLayerMap() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2022-07-29 21:02:35 +00:00
|
|
|
const PCB_LAYER_ID layer_id = entry.first;
|
2021-08-19 10:39:29 +00:00
|
|
|
const BVH_CONTAINER_2D* container2d = entry.second;
|
|
|
|
|
|
|
|
// Only process layers that exist
|
|
|
|
if( !container2d )
|
|
|
|
continue;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-09-04 00:00:56 +00:00
|
|
|
if( aOnlyLoadCopperAndShapes && !IsCopperLayer( layer_id ) )
|
|
|
|
continue;
|
|
|
|
|
2020-10-29 12:48:45 +00:00
|
|
|
// Mask layers are not processed here because they are a special case
|
2021-08-19 10:39:29 +00:00
|
|
|
if( layer_id == B_Mask || layer_id == F_Mask )
|
2016-07-19 17:35:25 +00:00
|
|
|
continue;
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
MATERIAL* materialLayer = &m_materials.m_SilkS;
|
2021-08-19 10:39:29 +00:00
|
|
|
SFVEC3F layerColor = SFVEC3F( 0.0f, 0.0f, 0.0f );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
switch( layer_id )
|
|
|
|
{
|
2020-12-12 17:29:11 +00:00
|
|
|
case B_Adhes:
|
|
|
|
case F_Adhes:
|
2016-07-19 17:35:25 +00:00
|
|
|
break;
|
|
|
|
|
2020-12-12 17:29:11 +00:00
|
|
|
case B_Paste:
|
|
|
|
case F_Paste:
|
|
|
|
materialLayer = &m_materials.m_Paste;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.realistic )
|
2020-12-12 17:29:11 +00:00
|
|
|
layerColor = m_boardAdapter.m_SolderPasteColor;
|
|
|
|
else
|
|
|
|
layerColor = m_boardAdapter.GetLayerColor( layer_id );
|
2021-08-19 10:39:29 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
break;
|
|
|
|
|
2020-12-12 17:29:11 +00:00
|
|
|
case B_SilkS:
|
|
|
|
materialLayer = &m_materials.m_SilkS;
|
2020-01-22 22:38:30 +00:00
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.realistic )
|
2020-12-12 17:29:11 +00:00
|
|
|
layerColor = m_boardAdapter.m_SilkScreenColorBot;
|
|
|
|
else
|
|
|
|
layerColor = m_boardAdapter.GetLayerColor( layer_id );
|
2021-08-19 10:39:29 +00:00
|
|
|
|
2020-12-12 17:29:11 +00:00
|
|
|
break;
|
2021-08-19 10:39:29 +00:00
|
|
|
|
2020-12-12 17:29:11 +00:00
|
|
|
case F_SilkS:
|
|
|
|
materialLayer = &m_materials.m_SilkS;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.realistic )
|
2020-12-12 17:29:11 +00:00
|
|
|
layerColor = m_boardAdapter.m_SilkScreenColorTop;
|
|
|
|
else
|
|
|
|
layerColor = m_boardAdapter.GetLayerColor( layer_id );
|
2021-08-19 10:39:29 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
break;
|
|
|
|
|
2020-12-12 17:29:11 +00:00
|
|
|
case Dwgs_User:
|
|
|
|
case Cmts_User:
|
|
|
|
case Eco1_User:
|
|
|
|
case Eco2_User:
|
|
|
|
case Edge_Cuts:
|
|
|
|
case Margin:
|
2016-07-19 17:35:25 +00:00
|
|
|
break;
|
|
|
|
|
2020-12-12 17:29:11 +00:00
|
|
|
case B_CrtYd:
|
|
|
|
case F_CrtYd:
|
2016-07-19 17:35:25 +00:00
|
|
|
break;
|
|
|
|
|
2020-12-12 17:29:11 +00:00
|
|
|
case B_Fab:
|
|
|
|
case F_Fab:
|
2016-07-19 17:35:25 +00:00
|
|
|
break;
|
|
|
|
|
2020-12-12 17:29:11 +00:00
|
|
|
default:
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.realistic )
|
2020-12-12 17:29:11 +00:00
|
|
|
{
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.renderPlatedPadsAsPlated )
|
2022-05-14 23:49:39 +00:00
|
|
|
{
|
2020-12-12 17:29:11 +00:00
|
|
|
layerColor = SFVEC3F( 184.0f / 255.0f, 115.0f / 255.0f, 50.0f / 255.0f );
|
2022-05-14 23:49:39 +00:00
|
|
|
materialLayer = &m_materials.m_NonPlatedCopper;
|
|
|
|
}
|
2020-11-11 17:22:24 +00:00
|
|
|
else
|
2022-05-14 23:49:39 +00:00
|
|
|
{
|
2020-12-12 17:29:11 +00:00
|
|
|
layerColor = m_boardAdapter.m_CopperColor;
|
2022-05-14 23:49:39 +00:00
|
|
|
materialLayer = &m_materials.m_Copper;
|
|
|
|
}
|
2020-12-12 17:29:11 +00:00
|
|
|
}
|
|
|
|
else
|
2021-08-19 10:39:29 +00:00
|
|
|
{
|
2020-12-12 17:29:11 +00:00
|
|
|
layerColor = m_boardAdapter.GetLayerColor( layer_id );
|
2021-08-19 10:39:29 +00:00
|
|
|
}
|
2020-09-07 11:38:05 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-09-07 11:38:05 +00:00
|
|
|
createItemsFromContainer( container2d, layer_id, materialLayer, layerColor, 0.0f );
|
2020-12-12 17:29:11 +00:00
|
|
|
} // for each layer on map
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-09-07 11:38:05 +00:00
|
|
|
// Create plated copper
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.renderPlatedPadsAsPlated
|
|
|
|
&& m_boardAdapter.m_Cfg->m_Render.realistic )
|
2020-09-27 09:28:05 +00:00
|
|
|
{
|
2021-01-05 22:19:00 +00:00
|
|
|
createItemsFromContainer( m_boardAdapter.GetPlatedPadsFront(), F_Cu, &m_materials.m_Copper,
|
|
|
|
m_boardAdapter.m_CopperColor,
|
2021-12-03 14:14:50 +00:00
|
|
|
m_boardAdapter.GetFrontCopperThickness() * 0.1f );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
createItemsFromContainer( m_boardAdapter.GetPlatedPadsBack(), B_Cu, &m_materials.m_Copper,
|
|
|
|
m_boardAdapter.m_CopperColor,
|
2021-12-03 14:14:50 +00:00
|
|
|
-m_boardAdapter.GetBackCopperThickness() * 0.1f );
|
2020-09-07 11:38:05 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-09-04 00:00:56 +00:00
|
|
|
if( !aOnlyLoadCopperAndShapes )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-09-04 00:00:56 +00:00
|
|
|
// Add Mask layer
|
2021-08-19 10:39:29 +00:00
|
|
|
// Solder mask layers are "negative" layers so the elements that we have in the container
|
|
|
|
// should remove the board outline. We will check for all objects in the outline if it
|
|
|
|
// intersects any object in the layer container and also any hole.
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.show_soldermask
|
|
|
|
&& !m_outlineBoard2dObjects->GetList().empty() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
const MATERIAL* materialLayer = &m_materials.m_SolderMask;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2022-07-29 21:02:35 +00:00
|
|
|
for( const std::pair<const PCB_LAYER_ID, BVH_CONTAINER_2D*>& entry : m_boardAdapter.GetLayerMap() )
|
2020-09-04 00:00:56 +00:00
|
|
|
{
|
2022-07-29 21:02:35 +00:00
|
|
|
const PCB_LAYER_ID layer_id = entry.first;
|
2021-08-19 10:39:29 +00:00
|
|
|
const BVH_CONTAINER_2D* container2d = entry.second;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
// Only process layers that exist
|
|
|
|
if( !container2d )
|
|
|
|
continue;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
// Only get the Solder mask layers (and only if the board has them)
|
2020-11-24 22:16:41 +00:00
|
|
|
if( !( layer_id == B_Mask || layer_id == F_Mask ) )
|
2020-09-04 00:00:56 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
SFVEC3F layerColor;
|
2021-01-02 21:05:29 +00:00
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.realistic )
|
2020-09-04 00:00:56 +00:00
|
|
|
{
|
|
|
|
if( layer_id == B_Mask )
|
|
|
|
layerColor = m_boardAdapter.m_SolderMaskColorBot;
|
|
|
|
else
|
|
|
|
layerColor = m_boardAdapter.m_SolderMaskColorTop;
|
|
|
|
}
|
2020-01-22 22:38:30 +00:00
|
|
|
else
|
2021-01-02 21:05:29 +00:00
|
|
|
{
|
2020-09-04 00:00:56 +00:00
|
|
|
layerColor = m_boardAdapter.GetLayerColor( layer_id );
|
2021-01-02 21:05:29 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
const float zLayerMin = m_boardAdapter.GetLayerBottomZPos( layer_id );
|
|
|
|
const float zLayerMax = m_boardAdapter.GetLayerTopZPos( layer_id );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-09-04 00:00:56 +00:00
|
|
|
// Get the outline board objects
|
2021-08-19 10:39:29 +00:00
|
|
|
for( const OBJECT_2D* object2d_A : m_outlineBoard2dObjects->GetList() )
|
2020-09-04 00:00:56 +00:00
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
std::vector<const OBJECT_2D*>* object2d_B = new std::vector<const OBJECT_2D*>();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-09-04 00:00:56 +00:00
|
|
|
// Check if there are any THT that intersects this outline object part
|
2021-01-05 22:19:00 +00:00
|
|
|
if( !m_boardAdapter.GetThroughHoleOds().GetList().empty() )
|
2020-09-04 00:00:56 +00:00
|
|
|
{
|
2021-08-19 10:39:29 +00:00
|
|
|
const BVH_CONTAINER_2D& throughHoles = m_boardAdapter.GetThroughHoleOds();
|
|
|
|
CONST_LIST_OBJECT2D intersecting;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
throughHoles.GetIntersectingObjects( object2d_A->GetBBox(), intersecting );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
for( const OBJECT_2D* hole : intersecting )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2021-08-19 10:39:29 +00:00
|
|
|
if( object2d_A->Intersects( hole->GetBBox() ) )
|
|
|
|
object2d_B->push_back( hole );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
// Check if there are any objects in the layer to subtract with the current
|
|
|
|
// object
|
|
|
|
if( !container2d->GetList().empty() )
|
2020-09-04 00:00:56 +00:00
|
|
|
{
|
2021-08-19 10:39:29 +00:00
|
|
|
CONST_LIST_OBJECT2D intersecting;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
container2d->GetIntersectingObjects( object2d_A->GetBBox(), intersecting );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
for( const OBJECT_2D* obj : intersecting )
|
|
|
|
object2d_B->push_back( obj );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
2020-09-04 00:00:56 +00:00
|
|
|
if( object2d_B->empty() )
|
|
|
|
{
|
|
|
|
delete object2d_B;
|
|
|
|
object2d_B = CSGITEM_EMPTY;
|
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-09-04 00:00:56 +00:00
|
|
|
if( object2d_B == CSGITEM_EMPTY )
|
|
|
|
{
|
2020-12-12 17:29:11 +00:00
|
|
|
#if 0
|
2021-01-07 19:33:43 +00:00
|
|
|
createObject( m_objectContainer, object2d_A, zLayerMin, zLayerMax,
|
|
|
|
materialLayer, layerColor );
|
2020-12-12 17:29:11 +00:00
|
|
|
#else
|
2021-01-02 21:05:29 +00:00
|
|
|
LAYER_ITEM* objPtr = new LAYER_ITEM( object2d_A, zLayerMin, zLayerMax );
|
2020-09-04 00:00:56 +00:00
|
|
|
|
|
|
|
objPtr->SetMaterial( materialLayer );
|
|
|
|
objPtr->SetColor( ConvertSRGBToLinear( layerColor ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
m_objectContainer.Add( objPtr );
|
2020-12-12 17:29:11 +00:00
|
|
|
#endif
|
2020-09-04 00:00:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-19 10:39:29 +00:00
|
|
|
LAYER_ITEM_2D* itemCSG2d = new LAYER_ITEM_2D( object2d_A, object2d_B,
|
|
|
|
CSGITEM_FULL,
|
|
|
|
object2d_A->GetBoardItem() );
|
2020-09-04 00:00:56 +00:00
|
|
|
|
|
|
|
m_containerWithObjectsToDelete.Add( itemCSG2d );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
LAYER_ITEM* objPtr = new LAYER_ITEM( itemCSG2d, zLayerMin, zLayerMax );
|
2020-09-04 00:00:56 +00:00
|
|
|
objPtr->SetMaterial( materialLayer );
|
|
|
|
objPtr->SetColor( ConvertSRGBToLinear( layerColor ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
m_objectContainer.Add( objPtr );
|
2020-09-04 00:00:56 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
addPadsAndVias();
|
2020-09-04 00:00:56 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
#ifdef PRINT_STATISTICS_3D_VIEWER
|
2020-12-12 17:29:11 +00:00
|
|
|
unsigned stats_endConvertTime = GetRunningMicroSecs();
|
2016-07-19 17:35:25 +00:00
|
|
|
unsigned stats_startLoad3DmodelsTime = stats_endConvertTime;
|
|
|
|
#endif
|
|
|
|
|
2020-11-10 16:30:11 +00:00
|
|
|
if( aStatusReporter )
|
2021-06-26 11:33:37 +00:00
|
|
|
aStatusReporter->Report( _( "Loading 3D models..." ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-08-16 14:28:46 +00:00
|
|
|
load3DModels( m_objectContainer, aOnlyLoadCopperAndShapes );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
#ifdef PRINT_STATISTICS_3D_VIEWER
|
|
|
|
unsigned stats_endLoad3DmodelsTime = GetRunningMicroSecs();
|
|
|
|
#endif
|
|
|
|
|
2020-09-04 00:00:56 +00:00
|
|
|
if( !aOnlyLoadCopperAndShapes )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-09-04 00:00:56 +00:00
|
|
|
// Add floor
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.raytrace_backfloor )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2021-01-05 22:19:00 +00:00
|
|
|
BBOX_3D boardBBox = m_boardAdapter.GetBBox();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-09-04 00:00:56 +00:00
|
|
|
if( boardBBox.IsInitialized() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-09-04 00:00:56 +00:00
|
|
|
boardBBox.Scale( 3.0f );
|
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
if( m_objectContainer.GetList().size() > 0 )
|
2020-09-04 00:00:56 +00:00
|
|
|
{
|
2021-01-07 19:33:43 +00:00
|
|
|
BBOX_3D containerBBox = m_objectContainer.GetBBox();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-09-04 00:00:56 +00:00
|
|
|
containerBBox.Scale( 1.3f );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-09-04 00:00:56 +00:00
|
|
|
const SFVEC3F centerBBox = containerBBox.GetCenter();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-09-04 00:00:56 +00:00
|
|
|
// Floor triangles
|
2020-12-12 17:29:11 +00:00
|
|
|
const float minZ = glm::min( containerBBox.Min().z, boardBBox.Min().z );
|
|
|
|
|
|
|
|
const SFVEC3F v1 =
|
|
|
|
SFVEC3F( -RANGE_SCALE_3D * 4.0f, -RANGE_SCALE_3D * 4.0f, minZ )
|
|
|
|
+ SFVEC3F( centerBBox.x, centerBBox.y, 0.0f );
|
|
|
|
|
|
|
|
const SFVEC3F v3 =
|
|
|
|
SFVEC3F( +RANGE_SCALE_3D * 4.0f, +RANGE_SCALE_3D * 4.0f, minZ )
|
|
|
|
+ SFVEC3F( centerBBox.x, centerBBox.y, 0.0f );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-09-04 00:00:56 +00:00
|
|
|
const SFVEC3F v2 = SFVEC3F( v1.x, v3.y, v1.z );
|
|
|
|
const SFVEC3F v4 = SFVEC3F( v3.x, v1.y, v1.z );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
SFVEC3F backgroundColor = ConvertSRGBToLinear( m_boardAdapter.m_BgColorTop );
|
2020-05-07 22:40:06 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
TRIANGLE* newTriangle1 = new TRIANGLE( v1, v2, v3 );
|
|
|
|
TRIANGLE* newTriangle2 = new TRIANGLE( v3, v4, v1 );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
m_objectContainer.Add( newTriangle1 );
|
|
|
|
m_objectContainer.Add( newTriangle2 );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
newTriangle1->SetMaterial( &m_materials.m_Floor );
|
|
|
|
newTriangle2->SetMaterial( &m_materials.m_Floor );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-09-04 00:00:56 +00:00
|
|
|
newTriangle1->SetColor( backgroundColor );
|
|
|
|
newTriangle2->SetColor( backgroundColor );
|
2020-04-25 08:42:03 +00:00
|
|
|
|
2020-09-04 00:00:56 +00:00
|
|
|
// Ceiling triangles
|
2020-12-12 17:29:11 +00:00
|
|
|
const float maxZ = glm::max( containerBBox.Max().z, boardBBox.Max().z );
|
2020-04-25 08:42:03 +00:00
|
|
|
|
2020-09-04 00:00:56 +00:00
|
|
|
const SFVEC3F v5 = SFVEC3F( v1.x, v1.y, maxZ );
|
|
|
|
const SFVEC3F v6 = SFVEC3F( v2.x, v2.y, maxZ );
|
|
|
|
const SFVEC3F v7 = SFVEC3F( v3.x, v3.y, maxZ );
|
|
|
|
const SFVEC3F v8 = SFVEC3F( v4.x, v4.y, maxZ );
|
2020-04-25 08:42:03 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
TRIANGLE* newTriangle3 = new TRIANGLE( v7, v6, v5 );
|
|
|
|
TRIANGLE* newTriangle4 = new TRIANGLE( v5, v8, v7 );
|
2020-04-25 08:42:03 +00:00
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
m_objectContainer.Add( newTriangle3 );
|
|
|
|
m_objectContainer.Add( newTriangle4 );
|
2020-04-25 08:42:03 +00:00
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
newTriangle3->SetMaterial( &m_materials.m_Floor );
|
|
|
|
newTriangle4->SetMaterial( &m_materials.m_Floor );
|
2020-04-25 08:42:03 +00:00
|
|
|
|
2020-09-04 00:00:56 +00:00
|
|
|
newTriangle3->SetColor( backgroundColor );
|
|
|
|
newTriangle4->SetColor( backgroundColor );
|
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-04 00:00:56 +00:00
|
|
|
// Init initial lights
|
2021-07-28 20:04:53 +00:00
|
|
|
for( LIGHT* light : m_lights )
|
|
|
|
delete light;
|
|
|
|
|
|
|
|
m_lights.clear();
|
2016-10-04 21:23:21 +00:00
|
|
|
|
2020-12-12 17:29:11 +00:00
|
|
|
auto IsColorZero =
|
|
|
|
[]( const SFVEC3F& aSource )
|
|
|
|
{
|
|
|
|
return ( ( aSource.r < ( 1.0f / 255.0f ) ) && ( aSource.g < ( 1.0f / 255.0f ) )
|
|
|
|
&& ( aSource.b < ( 1.0f / 255.0f ) ) );
|
|
|
|
};
|
2016-10-04 21:23:21 +00:00
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
SFVEC3F cameraLightColor =
|
|
|
|
m_boardAdapter.GetColor( m_boardAdapter.m_Cfg->m_Render.raytrace_lightColorCamera );
|
|
|
|
SFVEC3F topLightColor =
|
|
|
|
m_boardAdapter.GetColor( m_boardAdapter.m_Cfg->m_Render.raytrace_lightColorTop );
|
|
|
|
SFVEC3F bottomLightColor =
|
|
|
|
m_boardAdapter.GetColor( m_boardAdapter.m_Cfg->m_Render.raytrace_lightColorBottom );
|
|
|
|
|
|
|
|
m_cameraLight = new DIRECTIONAL_LIGHT( SFVEC3F( 0.0f, 0.0f, 0.0f ), cameraLightColor );
|
2021-01-07 19:33:43 +00:00
|
|
|
m_cameraLight->SetCastShadows( false );
|
2016-10-04 21:23:21 +00:00
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
if( !IsColorZero( cameraLightColor ) )
|
2021-07-28 20:04:53 +00:00
|
|
|
m_lights.push_back( m_cameraLight );
|
2016-10-04 21:23:21 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
const SFVEC3F& boardCenter = m_boardAdapter.GetBBox().GetCenter();
|
2016-10-04 21:23:21 +00:00
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
if( !IsColorZero( topLightColor ) )
|
2021-07-28 20:04:53 +00:00
|
|
|
{
|
|
|
|
m_lights.push_back( new POINT_LIGHT( SFVEC3F( boardCenter.x, boardCenter.y,
|
|
|
|
+RANGE_SCALE_3D * 2.0f ),
|
2021-08-30 20:30:18 +00:00
|
|
|
topLightColor ) );
|
2021-07-28 20:04:53 +00:00
|
|
|
}
|
2016-10-04 21:23:21 +00:00
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
if( !IsColorZero( bottomLightColor ) )
|
2021-07-28 20:04:53 +00:00
|
|
|
{
|
|
|
|
m_lights.push_back( new POINT_LIGHT( SFVEC3F( boardCenter.x, boardCenter.y,
|
|
|
|
-RANGE_SCALE_3D * 2.0f ),
|
2021-08-30 20:30:18 +00:00
|
|
|
bottomLightColor ) );
|
2021-07-28 20:04:53 +00:00
|
|
|
}
|
2016-10-04 21:23:21 +00:00
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
for( size_t i = 0; i < m_boardAdapter.m_Cfg->m_Render.raytrace_lightColor.size(); ++i )
|
2020-08-15 08:41:34 +00:00
|
|
|
{
|
2021-08-30 20:30:18 +00:00
|
|
|
SFVEC3F lightColor =
|
|
|
|
m_boardAdapter.GetColor( m_boardAdapter.m_Cfg->m_Render.raytrace_lightColor[i] );
|
|
|
|
|
|
|
|
if( !IsColorZero( lightColor ) )
|
2020-09-04 00:00:56 +00:00
|
|
|
{
|
2021-08-30 20:30:18 +00:00
|
|
|
const SFVEC2F sc = m_boardAdapter.GetSphericalCoord( i );
|
2016-10-04 21:23:21 +00:00
|
|
|
|
2021-07-28 20:04:53 +00:00
|
|
|
m_lights.push_back( new DIRECTIONAL_LIGHT(
|
2020-12-12 17:29:11 +00:00
|
|
|
SphericalToCartesian( glm::pi<float>() * sc.x, glm::pi<float>() * sc.y ),
|
2021-08-30 20:30:18 +00:00
|
|
|
lightColor ) );
|
2020-09-04 00:00:56 +00:00
|
|
|
}
|
2020-08-15 08:41:34 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-04 21:23:21 +00:00
|
|
|
|
2021-10-24 17:30:40 +00:00
|
|
|
// Set min. and max. zoom range. This doesn't really fit here, but moving this outside of this
|
|
|
|
// class would require reimplementing bounding box calculation (feel free to do this if you
|
|
|
|
// have time and patience).
|
|
|
|
if( m_objectContainer.GetList().size() > 0 )
|
|
|
|
{
|
|
|
|
float ratio =
|
|
|
|
std::max( 1.0f, m_objectContainer.GetBBox().GetMaxDimension() / RANGE_SCALE_3D );
|
|
|
|
|
2023-07-21 22:45:59 +00:00
|
|
|
float max_zoom = CAMERA::DEFAULT_MAX_ZOOM * ratio;
|
|
|
|
float min_zoom = static_cast<float>( MIN_DISTANCE_IU * m_boardAdapter.BiuTo3dUnits()
|
|
|
|
/ -m_camera.GetCameraInitPos().z );
|
|
|
|
|
|
|
|
if( min_zoom > max_zoom )
|
|
|
|
std::swap( min_zoom, max_zoom );
|
|
|
|
|
|
|
|
float zoom_ratio = max_zoom / min_zoom;
|
|
|
|
|
|
|
|
// Set the minimum number of zoom 'steps' between max and min.
|
|
|
|
int steps = 3 * 3;
|
|
|
|
steps -= static_cast<int>( ceil( log( zoom_ratio ) / log( 1.26f ) ) );
|
|
|
|
steps = std::max( steps, 0 );
|
|
|
|
|
|
|
|
// Resize max and min zoom to accomplish the number of steps.
|
|
|
|
float increased_zoom = pow( 1.26f, steps / 2 );
|
|
|
|
max_zoom *= increased_zoom;
|
|
|
|
min_zoom /= increased_zoom;
|
|
|
|
|
|
|
|
if( steps & 1 )
|
|
|
|
min_zoom /= 1.26f;
|
|
|
|
|
|
|
|
min_zoom = std::min( min_zoom, 1.0f );
|
|
|
|
|
|
|
|
m_camera.SetMaxZoom( max_zoom );
|
|
|
|
m_camera.SetMinZoom( min_zoom );
|
2021-10-24 17:30:40 +00:00
|
|
|
}
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
// Create an accelerator
|
2021-07-28 20:04:53 +00:00
|
|
|
delete m_accelerator;
|
2021-01-07 19:33:43 +00:00
|
|
|
m_accelerator = new BVH_PBRT( m_objectContainer, 8, SPLITMETHOD::MIDDLE );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-06-03 23:00:40 +00:00
|
|
|
if( aStatusReporter )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
// Calculation time in seconds
|
2021-07-28 20:04:53 +00:00
|
|
|
double calculation_time = (double) GetRunningMicroSecs() - stats_startReloadTime / 1e6;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-06-03 23:00:40 +00:00
|
|
|
aStatusReporter->Report( wxString::Format( _( "Reload time %.3f s" ), calculation_time ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
void RENDER_3D_RAYTRACE::insertHole( const PCB_VIA* aVia )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-12-12 17:29:11 +00:00
|
|
|
PCB_LAYER_ID top_layer, bottom_layer;
|
|
|
|
int radiusBUI = ( aVia->GetDrillValue() / 2 );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
aVia->LayerPair( &top_layer, &bottom_layer );
|
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
float topZ = m_boardAdapter.GetLayerBottomZPos( top_layer )
|
2021-12-03 14:14:50 +00:00
|
|
|
+ m_boardAdapter.GetFrontCopperThickness();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
float botZ = m_boardAdapter.GetLayerBottomZPos( bottom_layer )
|
2021-12-03 14:14:50 +00:00
|
|
|
- m_boardAdapter.GetBackCopperThickness();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
const SFVEC2F center = SFVEC2F( aVia->GetStart().x * m_boardAdapter.BiuTo3dUnits(),
|
2021-08-19 10:39:29 +00:00
|
|
|
-aVia->GetStart().y * m_boardAdapter.BiuTo3dUnits() );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
RING_2D* ring = new RING_2D( center, radiusBUI * m_boardAdapter.BiuTo3dUnits(),
|
|
|
|
( radiusBUI + m_boardAdapter.GetHolePlatingThickness() )
|
|
|
|
* m_boardAdapter.BiuTo3dUnits(), *aVia );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
m_containerWithObjectsToDelete.Add( ring );
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
LAYER_ITEM* objPtr = new LAYER_ITEM( ring, topZ, botZ );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
objPtr->SetMaterial( &m_materials.m_Copper );
|
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.realistic )
|
2021-08-19 10:39:29 +00:00
|
|
|
objPtr->SetColor( ConvertSRGBToLinear( m_boardAdapter.m_CopperColor ) );
|
2021-07-28 20:04:53 +00:00
|
|
|
else if( aVia->GetViaType() == VIATYPE::MICROVIA )
|
|
|
|
objPtr->SetColor( ConvertSRGBToLinear( m_boardAdapter.GetItemColor( LAYER_VIA_MICROVIA ) ) );
|
|
|
|
else if( aVia->GetViaType() == VIATYPE::BLIND_BURIED )
|
|
|
|
objPtr->SetColor( ConvertSRGBToLinear( m_boardAdapter.GetItemColor( LAYER_VIA_BBLIND ) ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
else
|
2021-07-28 20:04:53 +00:00
|
|
|
objPtr->SetColor( ConvertSRGBToLinear( m_boardAdapter.GetItemColor( LAYER_VIAS ) ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
m_objectContainer.Add( objPtr );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
void RENDER_3D_RAYTRACE::insertHole( const PAD* aPad )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
const OBJECT_2D* object2d_A = nullptr;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
SFVEC3F objColor;
|
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.realistic )
|
2021-08-19 10:39:29 +00:00
|
|
|
objColor = m_boardAdapter.m_CopperColor;
|
2016-07-19 17:35:25 +00:00
|
|
|
else
|
2020-03-26 14:05:20 +00:00
|
|
|
objColor = m_boardAdapter.GetItemColor( LAYER_PADS_TH );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-12-29 19:19:08 +00:00
|
|
|
const VECTOR2I drillsize = aPad->GetDrillSize();
|
|
|
|
const bool hasHole = drillsize.x && drillsize.y;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
if( !hasHole )
|
|
|
|
return;
|
|
|
|
|
2020-10-29 12:48:45 +00:00
|
|
|
CONST_LIST_OBJECT2D antiOutlineIntersectionList;
|
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
const float topZ = m_boardAdapter.GetLayerBottomZPos( F_Cu )
|
2021-12-03 14:14:50 +00:00
|
|
|
+ m_boardAdapter.GetFrontCopperThickness() * 0.99f;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
const float botZ = m_boardAdapter.GetLayerBottomZPos( B_Cu )
|
2021-12-03 14:14:50 +00:00
|
|
|
- m_boardAdapter.GetBackCopperThickness() * 0.99f;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-12-12 17:29:11 +00:00
|
|
|
if( drillsize.x == drillsize.y ) // usual round hole
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2021-01-05 22:19:00 +00:00
|
|
|
SFVEC2F center = SFVEC2F( aPad->GetPosition().x * m_boardAdapter.BiuTo3dUnits(),
|
|
|
|
-aPad->GetPosition().y * m_boardAdapter.BiuTo3dUnits() );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-10-01 00:13:04 +00:00
|
|
|
int innerRadius = drillsize.x / 2;
|
2021-01-05 22:19:00 +00:00
|
|
|
int outerRadius = innerRadius + m_boardAdapter.GetHolePlatingThickness();
|
2020-10-29 12:48:45 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
RING_2D* ring = new RING_2D( center, innerRadius * m_boardAdapter.BiuTo3dUnits(),
|
|
|
|
outerRadius * m_boardAdapter.BiuTo3dUnits(), *aPad );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
m_containerWithObjectsToDelete.Add( ring );
|
|
|
|
|
|
|
|
object2d_A = ring;
|
2020-10-29 12:48:45 +00:00
|
|
|
|
|
|
|
// If the object (ring) is intersected by an antioutline board,
|
2020-12-12 17:29:11 +00:00
|
|
|
// it will use instead a CSG of two circles.
|
2020-10-29 12:48:45 +00:00
|
|
|
if( object2d_A && !m_antioutlineBoard2dObjects->GetList().empty() )
|
|
|
|
{
|
2021-08-19 10:39:29 +00:00
|
|
|
m_antioutlineBoard2dObjects->GetIntersectingObjects( object2d_A->GetBBox(),
|
|
|
|
antiOutlineIntersectionList );
|
2020-10-29 12:48:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !antiOutlineIntersectionList.empty() )
|
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
FILLED_CIRCLE_2D* innerCircle = new FILLED_CIRCLE_2D(
|
2021-01-05 22:19:00 +00:00
|
|
|
center, innerRadius * m_boardAdapter.BiuTo3dUnits(), *aPad );
|
2020-12-12 17:29:11 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
FILLED_CIRCLE_2D* outterCircle = new FILLED_CIRCLE_2D(
|
2021-01-05 22:19:00 +00:00
|
|
|
center, outerRadius * m_boardAdapter.BiuTo3dUnits(), *aPad );
|
2021-01-02 21:05:29 +00:00
|
|
|
std::vector<const OBJECT_2D*>* object2d_B = new std::vector<const OBJECT_2D*>();
|
2020-10-29 12:48:45 +00:00
|
|
|
object2d_B->push_back( innerCircle );
|
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
LAYER_ITEM_2D* itemCSG2d = new LAYER_ITEM_2D( outterCircle, object2d_B, CSGITEM_FULL,
|
|
|
|
*aPad );
|
2020-10-29 12:48:45 +00:00
|
|
|
|
|
|
|
m_containerWithObjectsToDelete.Add( itemCSG2d );
|
|
|
|
m_containerWithObjectsToDelete.Add( innerCircle );
|
|
|
|
m_containerWithObjectsToDelete.Add( outterCircle );
|
|
|
|
|
|
|
|
object2d_A = itemCSG2d;
|
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
2020-12-12 17:29:11 +00:00
|
|
|
else // Oblong hole
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2021-12-29 19:19:08 +00:00
|
|
|
VECTOR2I ends_offset;
|
2016-07-19 17:35:25 +00:00
|
|
|
int width;
|
|
|
|
|
2020-12-12 17:29:11 +00:00
|
|
|
if( drillsize.x > drillsize.y ) // Horizontal oval
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
ends_offset.x = ( drillsize.x - drillsize.y ) / 2;
|
2020-12-12 17:29:11 +00:00
|
|
|
width = drillsize.y;
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
2020-12-12 17:29:11 +00:00
|
|
|
else // Vertical oval
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
ends_offset.y = ( drillsize.y - drillsize.x ) / 2;
|
2020-12-12 17:29:11 +00:00
|
|
|
width = drillsize.x;
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
2021-12-29 19:19:08 +00:00
|
|
|
RotatePoint( ends_offset, aPad->GetOrientation() );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-12-29 19:19:08 +00:00
|
|
|
VECTOR2I start = VECTOR2I( aPad->GetPosition() ) + ends_offset;
|
|
|
|
VECTOR2I end = VECTOR2I( aPad->GetPosition() ) - ends_offset;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
ROUND_SEGMENT_2D* innerSeg =
|
2021-01-05 22:19:00 +00:00
|
|
|
new ROUND_SEGMENT_2D( SFVEC2F( start.x * m_boardAdapter.BiuTo3dUnits(),
|
|
|
|
-start.y * m_boardAdapter.BiuTo3dUnits() ),
|
|
|
|
SFVEC2F( end.x * m_boardAdapter.BiuTo3dUnits(),
|
|
|
|
-end.y * m_boardAdapter.BiuTo3dUnits() ),
|
|
|
|
width * m_boardAdapter.BiuTo3dUnits(), *aPad );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
ROUND_SEGMENT_2D* outerSeg =
|
2021-01-05 22:19:00 +00:00
|
|
|
new ROUND_SEGMENT_2D( SFVEC2F( start.x * m_boardAdapter.BiuTo3dUnits(),
|
|
|
|
-start.y * m_boardAdapter.BiuTo3dUnits() ),
|
|
|
|
SFVEC2F( end.x * m_boardAdapter.BiuTo3dUnits(),
|
|
|
|
-end.y * m_boardAdapter.BiuTo3dUnits() ),
|
|
|
|
( width + m_boardAdapter.GetHolePlatingThickness() * 2 )
|
|
|
|
* m_boardAdapter.BiuTo3dUnits(), *aPad );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// NOTE: the round segment width is the "diameter", so we double the thickness
|
2021-01-02 21:05:29 +00:00
|
|
|
std::vector<const OBJECT_2D*>* object2d_B = new std::vector<const OBJECT_2D*>();
|
2016-07-19 17:35:25 +00:00
|
|
|
object2d_B->push_back( innerSeg );
|
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
LAYER_ITEM_2D* itemCSG2d = new LAYER_ITEM_2D( outerSeg, object2d_B, CSGITEM_FULL, *aPad );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
m_containerWithObjectsToDelete.Add( itemCSG2d );
|
|
|
|
m_containerWithObjectsToDelete.Add( innerSeg );
|
2019-08-20 17:02:28 +00:00
|
|
|
m_containerWithObjectsToDelete.Add( outerSeg );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
object2d_A = itemCSG2d;
|
2020-10-29 12:48:45 +00:00
|
|
|
|
|
|
|
if( object2d_A && !m_antioutlineBoard2dObjects->GetList().empty() )
|
|
|
|
{
|
2021-08-19 10:39:29 +00:00
|
|
|
m_antioutlineBoard2dObjects->GetIntersectingObjects( object2d_A->GetBBox(),
|
|
|
|
antiOutlineIntersectionList );
|
2020-10-29 12:48:45 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( object2d_A )
|
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
std::vector<const OBJECT_2D*>* object2d_B = new std::vector<const OBJECT_2D*>();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// Check if there are any other THT that intersects this hole
|
|
|
|
// It will use the non inflated holes
|
2021-01-05 22:19:00 +00:00
|
|
|
if( !m_boardAdapter.GetThroughHoleIds().GetList().empty() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2021-08-19 10:39:29 +00:00
|
|
|
CONST_LIST_OBJECT2D intersecting;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
m_boardAdapter.GetThroughHoleIds().GetIntersectingObjects( object2d_A->GetBBox(),
|
|
|
|
intersecting );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
for( const OBJECT_2D* hole2d : intersecting )
|
2020-10-29 12:48:45 +00:00
|
|
|
{
|
2021-08-19 10:39:29 +00:00
|
|
|
if( object2d_A->Intersects( hole2d->GetBBox() ) )
|
|
|
|
object2d_B->push_back( hole2d );
|
2020-10-29 12:48:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-19 10:39:29 +00:00
|
|
|
for( const OBJECT_2D* obj : antiOutlineIntersectionList )
|
|
|
|
object2d_B->push_back( obj );
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
if( object2d_B->empty() )
|
|
|
|
{
|
|
|
|
delete object2d_B;
|
|
|
|
object2d_B = CSGITEM_EMPTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( object2d_B == CSGITEM_EMPTY )
|
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
LAYER_ITEM* objPtr = new LAYER_ITEM( object2d_A, topZ, botZ );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
objPtr->SetMaterial( &m_materials.m_Copper );
|
2016-11-26 14:38:51 +00:00
|
|
|
objPtr->SetColor( ConvertSRGBToLinear( objColor ) );
|
2021-01-07 19:33:43 +00:00
|
|
|
m_objectContainer.Add( objPtr );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
LAYER_ITEM_2D* itemCSG2d = new LAYER_ITEM_2D( object2d_A, object2d_B, CSGITEM_FULL,
|
2021-08-19 10:39:29 +00:00
|
|
|
*aPad );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
m_containerWithObjectsToDelete.Add( itemCSG2d );
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
LAYER_ITEM* objPtr = new LAYER_ITEM( itemCSG2d, topZ, botZ );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
objPtr->SetMaterial( &m_materials.m_Copper );
|
2016-11-26 14:38:51 +00:00
|
|
|
objPtr->SetColor( ConvertSRGBToLinear( objColor ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
m_objectContainer.Add( objPtr );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
void RENDER_3D_RAYTRACE::addPadsAndVias()
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2021-07-18 15:44:54 +00:00
|
|
|
if( !m_boardAdapter.GetBoard() )
|
|
|
|
return;
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
// Insert plated vertical holes inside the board
|
|
|
|
|
|
|
|
// Insert vias holes (vertical cylinders)
|
2021-06-11 21:07:02 +00:00
|
|
|
for( PCB_TRACK* track : m_boardAdapter.GetBoard()->Tracks() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
if( track->Type() == PCB_VIA_T )
|
|
|
|
{
|
2021-06-11 21:07:02 +00:00
|
|
|
const PCB_VIA* via = static_cast<const PCB_VIA*>( track );
|
2021-01-07 19:33:43 +00:00
|
|
|
insertHole( via );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Insert pads holes (vertical cylinders)
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : m_boardAdapter.GetBoard()->Footprints() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-11-12 23:50:33 +00:00
|
|
|
for( PAD* pad : footprint->Pads() )
|
2020-12-12 17:29:11 +00:00
|
|
|
{
|
2021-05-01 14:46:50 +00:00
|
|
|
if( pad->GetAttribute() != PAD_ATTRIB::NPTH )
|
2021-01-07 19:33:43 +00:00
|
|
|
insertHole( pad );
|
2020-12-12 17:29:11 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-16 14:28:46 +00:00
|
|
|
void RENDER_3D_RAYTRACE::load3DModels( CONTAINER_3D& aDstContainer, bool aSkipMaterialInformation )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2021-07-18 15:44:54 +00:00
|
|
|
if( !m_boardAdapter.GetBoard() )
|
|
|
|
return;
|
|
|
|
|
2023-03-22 07:47:42 +00:00
|
|
|
if( !m_boardAdapter.m_IsPreviewer
|
|
|
|
&& !m_boardAdapter.m_Cfg->m_Render.show_footprints_normal
|
2021-08-30 20:30:18 +00:00
|
|
|
&& !m_boardAdapter.m_Cfg->m_Render.show_footprints_insert
|
|
|
|
&& !m_boardAdapter.m_Cfg->m_Render.show_footprints_virtual )
|
2021-08-16 14:28:46 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-21 03:48:06 +00:00
|
|
|
// Go for all footprints
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* fp : m_boardAdapter.GetBoard()->Footprints() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-11-12 23:50:33 +00:00
|
|
|
if( !fp->Models().empty()
|
2021-01-05 22:19:00 +00:00
|
|
|
&& m_boardAdapter.IsFootprintShown( (FOOTPRINT_ATTR_T) fp->GetAttributes() ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2021-01-05 22:19:00 +00:00
|
|
|
double zpos = m_boardAdapter.GetFootprintZPos( fp->IsFlipped() );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-12-29 19:19:08 +00:00
|
|
|
VECTOR2I pos = fp->GetPosition();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
glm::mat4 fpMatrix = glm::mat4( 1.0f );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-12-12 17:29:11 +00:00
|
|
|
fpMatrix = glm::translate( fpMatrix,
|
2021-01-05 22:19:00 +00:00
|
|
|
SFVEC3F( pos.x * m_boardAdapter.BiuTo3dUnits(),
|
|
|
|
-pos.y * m_boardAdapter.BiuTo3dUnits(),
|
2020-12-12 17:29:11 +00:00
|
|
|
zpos ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2022-01-13 17:27:36 +00:00
|
|
|
if( !fp->GetOrientation().IsZero() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2022-01-13 17:27:36 +00:00
|
|
|
fpMatrix = glm::rotate( fpMatrix, (float) fp->GetOrientation().AsRadians(),
|
|
|
|
SFVEC3F( 0.0f, 0.0f, 1.0f ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
2020-11-12 23:50:33 +00:00
|
|
|
if( fp->IsFlipped() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-11-13 02:57:11 +00:00
|
|
|
fpMatrix = glm::rotate( fpMatrix, glm::pi<float>(), SFVEC3F( 0.0f, 1.0f, 0.0f ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
fpMatrix = glm::rotate( fpMatrix, glm::pi<float>(), SFVEC3F( 0.0f, 0.0f, 1.0f ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
2020-12-12 17:29:11 +00:00
|
|
|
const double modelunit_to_3d_units_factor =
|
2021-01-05 22:19:00 +00:00
|
|
|
m_boardAdapter.BiuTo3dUnits() * UNITS3D_TO_UNITSPCB;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-12-12 17:29:11 +00:00
|
|
|
fpMatrix = glm::scale(
|
|
|
|
fpMatrix, SFVEC3F( modelunit_to_3d_units_factor, modelunit_to_3d_units_factor,
|
2021-01-02 21:05:29 +00:00
|
|
|
modelunit_to_3d_units_factor ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-11-12 23:50:33 +00:00
|
|
|
BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( fp );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// Get the list of model files for this model
|
2021-01-05 22:19:00 +00:00
|
|
|
S3D_CACHE* cacheMgr = m_boardAdapter.Get3dCacheManager();
|
2020-12-12 17:29:11 +00:00
|
|
|
auto sM = fp->Models().begin();
|
|
|
|
auto eM = fp->Models().end();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2022-09-26 02:54:08 +00:00
|
|
|
wxString libraryName = fp->GetFPID().GetLibNickname();
|
|
|
|
|
|
|
|
wxString footprintBasePath = wxEmptyString;
|
|
|
|
if( m_boardAdapter.GetBoard()->GetProject() )
|
|
|
|
{
|
2022-09-27 16:32:48 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
// FindRow() can throw an exception
|
|
|
|
const FP_LIB_TABLE_ROW* fpRow =
|
|
|
|
m_boardAdapter.GetBoard()->GetProject()->PcbFootprintLibs()->FindRow(
|
|
|
|
libraryName, false );
|
2022-09-26 02:54:08 +00:00
|
|
|
|
2022-09-27 16:32:48 +00:00
|
|
|
if( fpRow )
|
|
|
|
footprintBasePath = fpRow->GetFullURI( true );
|
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
|
|
|
// Do nothing if the libraryName is not found in lib table
|
|
|
|
}
|
2022-09-26 02:54:08 +00:00
|
|
|
}
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
while( sM != eM )
|
|
|
|
{
|
2020-12-12 17:29:11 +00:00
|
|
|
if( ( static_cast<float>( sM->m_Opacity ) > FLT_EPSILON )
|
2021-01-02 21:05:29 +00:00
|
|
|
&& ( sM->m_Show && !sM->m_Filename.empty() ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-04-10 21:48:48 +00:00
|
|
|
// get it from cache
|
2022-09-26 02:54:08 +00:00
|
|
|
const S3DMODEL* modelPtr =
|
|
|
|
cacheMgr->GetModel( sM->m_Filename, footprintBasePath );
|
2020-04-10 21:48:48 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
// only add it if the return is not NULL.
|
2020-04-25 14:38:41 +00:00
|
|
|
if( modelPtr )
|
2020-04-10 21:48:48 +00:00
|
|
|
{
|
2020-11-13 02:57:11 +00:00
|
|
|
glm::mat4 modelMatrix = fpMatrix;
|
2020-04-10 21:48:48 +00:00
|
|
|
|
|
|
|
modelMatrix = glm::translate( modelMatrix,
|
2020-12-12 17:29:11 +00:00
|
|
|
SFVEC3F( sM->m_Offset.x, sM->m_Offset.y, sM->m_Offset.z ) );
|
2020-04-10 21:48:48 +00:00
|
|
|
|
|
|
|
modelMatrix = glm::rotate( modelMatrix,
|
2020-12-12 17:29:11 +00:00
|
|
|
(float) -( sM->m_Rotation.z / 180.0f ) * glm::pi<float>(),
|
|
|
|
SFVEC3F( 0.0f, 0.0f, 1.0f ) );
|
2020-04-10 21:48:48 +00:00
|
|
|
|
|
|
|
modelMatrix = glm::rotate( modelMatrix,
|
2020-12-12 17:29:11 +00:00
|
|
|
(float) -( sM->m_Rotation.y / 180.0f ) * glm::pi<float>(),
|
|
|
|
SFVEC3F( 0.0f, 1.0f, 0.0f ) );
|
2020-04-10 21:48:48 +00:00
|
|
|
|
|
|
|
modelMatrix = glm::rotate( modelMatrix,
|
2020-12-12 17:29:11 +00:00
|
|
|
(float) -( sM->m_Rotation.x / 180.0f ) * glm::pi<float>(),
|
|
|
|
SFVEC3F( 1.0f, 0.0f, 0.0f ) );
|
2020-04-10 21:48:48 +00:00
|
|
|
|
|
|
|
modelMatrix = glm::scale( modelMatrix,
|
2020-12-12 17:29:11 +00:00
|
|
|
SFVEC3F( sM->m_Scale.x, sM->m_Scale.y, sM->m_Scale.z ) );
|
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
addModels( aDstContainer, modelPtr, modelMatrix, (float) sM->m_Opacity,
|
|
|
|
aSkipMaterialInformation, boardItem );
|
2020-04-10 21:48:48 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
++sM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-12 17:29:11 +00:00
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
MODEL_MATERIALS* RENDER_3D_RAYTRACE::getModelMaterial( const S3DMODEL* a3DModel )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-12-12 17:29:11 +00:00
|
|
|
MODEL_MATERIALS* materialVector;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-09-02 14:31:42 +00:00
|
|
|
// Try find if the materials already exists in the map list
|
2021-01-07 19:33:43 +00:00
|
|
|
if( m_modelMaterialMap.find( a3DModel ) != m_modelMaterialMap.end() )
|
2020-05-22 13:28:04 +00:00
|
|
|
{
|
2020-09-02 14:31:42 +00:00
|
|
|
// Found it, so get the pointer
|
2021-01-07 19:33:43 +00:00
|
|
|
materialVector = &m_modelMaterialMap[a3DModel];
|
2020-05-22 13:28:04 +00:00
|
|
|
}
|
2020-09-02 14:31:42 +00:00
|
|
|
else
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-09-02 14:31:42 +00:00
|
|
|
// Materials was not found in the map, so it will create a new for
|
|
|
|
// this model.
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
m_modelMaterialMap[a3DModel] = MODEL_MATERIALS();
|
|
|
|
materialVector = &m_modelMaterialMap[a3DModel];
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-09-02 14:31:42 +00:00
|
|
|
materialVector->resize( a3DModel->m_MaterialsSize );
|
|
|
|
|
2020-12-12 17:29:11 +00:00
|
|
|
for( unsigned int imat = 0; imat < a3DModel->m_MaterialsSize; ++imat )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.material_mode == MATERIAL_MODE::NORMAL )
|
2020-09-02 14:31:42 +00:00
|
|
|
{
|
2020-12-12 17:29:11 +00:00
|
|
|
const SMATERIAL& material = a3DModel->m_Materials[imat];
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-09-02 14:31:42 +00:00
|
|
|
// http://www.fooplot.com/#W3sidHlwZSI6MCwiZXEiOiJtaW4oc3FydCh4LTAuMzUpKjAuNDAtMC4wNSwxLjApIiwiY29sb3IiOiIjMDAwMDAwIn0seyJ0eXBlIjoxMDAwLCJ3aW5kb3ciOlsiMC4wNzA3NzM2NzMyMzY1OTAxMiIsIjEuNTY5NTcxNjI5MjI1NDY5OCIsIi0wLjI3NDYzNTMyMTc1OTkyOTMiLCIwLjY0NzcwMTg4MTkyNTUzNjIiXSwic2l6ZSI6WzY0NCwzOTRdfV0-
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-09-02 14:31:42 +00:00
|
|
|
float reflectionFactor = 0.0f;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-12-12 17:29:11 +00:00
|
|
|
if( ( material.m_Shininess - 0.35f ) > FLT_EPSILON )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-12-12 17:29:11 +00:00
|
|
|
reflectionFactor = glm::clamp(
|
|
|
|
glm::sqrt( ( material.m_Shininess - 0.35f ) ) * 0.40f - 0.05f, 0.0f,
|
|
|
|
0.5f );
|
2020-09-02 14:31:42 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
BLINN_PHONG_MATERIAL& blinnMaterial = ( *materialVector )[imat];
|
2016-10-02 12:16:40 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
blinnMaterial = BLINN_PHONG_MATERIAL( ConvertSRGBToLinear( material.m_Ambient ),
|
2020-12-12 17:29:11 +00:00
|
|
|
ConvertSRGBToLinear( material.m_Emissive ),
|
|
|
|
ConvertSRGBToLinear( material.m_Specular ), material.m_Shininess * 180.0f,
|
|
|
|
material.m_Transparency, reflectionFactor );
|
2016-10-02 12:16:40 +00:00
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.raytrace_procedural_textures )
|
2020-09-02 14:31:42 +00:00
|
|
|
{
|
|
|
|
// Guess material type and apply a normal perturbator
|
2020-12-12 17:29:11 +00:00
|
|
|
if( ( RGBtoGray( material.m_Diffuse ) < 0.3f )
|
|
|
|
&& ( material.m_Shininess < 0.36f )
|
|
|
|
&& ( material.m_Transparency == 0.0f )
|
|
|
|
&& ( ( glm::abs( material.m_Diffuse.r - material.m_Diffuse.g ) < 0.15f )
|
|
|
|
&& ( glm::abs( material.m_Diffuse.b - material.m_Diffuse.g )
|
|
|
|
< 0.15f )
|
|
|
|
&& ( glm::abs( material.m_Diffuse.r - material.m_Diffuse.b )
|
|
|
|
< 0.15f ) ) )
|
2016-10-02 12:16:40 +00:00
|
|
|
{
|
2020-09-02 14:31:42 +00:00
|
|
|
// This may be a black plastic..
|
2021-01-07 19:33:43 +00:00
|
|
|
blinnMaterial.SetGenerator( &m_plasticMaterial );
|
2020-09-02 14:31:42 +00:00
|
|
|
}
|
|
|
|
else
|
2016-10-02 08:11:00 +00:00
|
|
|
{
|
2020-12-12 17:29:11 +00:00
|
|
|
if( ( RGBtoGray( material.m_Diffuse ) > 0.3f )
|
2021-01-02 21:05:29 +00:00
|
|
|
&& ( material.m_Shininess < 0.30f )
|
|
|
|
&& ( material.m_Transparency == 0.0f )
|
|
|
|
&& ( ( glm::abs( material.m_Diffuse.r - material.m_Diffuse.g ) > 0.25f )
|
|
|
|
|| ( glm::abs( material.m_Diffuse.b - material.m_Diffuse.g ) > 0.25f )
|
|
|
|
|| ( glm::abs( material.m_Diffuse.r - material.m_Diffuse.b )
|
|
|
|
> 0.25f ) ) )
|
2016-10-02 08:11:00 +00:00
|
|
|
{
|
2020-09-02 14:31:42 +00:00
|
|
|
// This may be a color plastic ...
|
2021-01-07 19:33:43 +00:00
|
|
|
blinnMaterial.SetGenerator( &m_shinyPlasticMaterial );
|
2016-10-02 08:11:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-12 17:29:11 +00:00
|
|
|
if( ( RGBtoGray( material.m_Diffuse ) > 0.6f )
|
2021-01-02 21:05:29 +00:00
|
|
|
&& ( material.m_Shininess > 0.35f )
|
|
|
|
&& ( material.m_Transparency == 0.0f )
|
|
|
|
&& ( ( glm::abs( material.m_Diffuse.r - material.m_Diffuse.g )
|
|
|
|
< 0.40f )
|
|
|
|
&& ( glm::abs( material.m_Diffuse.b - material.m_Diffuse.g )
|
|
|
|
< 0.40f )
|
|
|
|
&& ( glm::abs( material.m_Diffuse.r - material.m_Diffuse.b )
|
|
|
|
< 0.40f ) ) )
|
2016-10-02 08:11:00 +00:00
|
|
|
{
|
2020-09-02 14:31:42 +00:00
|
|
|
// This may be a brushed metal
|
2021-01-07 19:33:43 +00:00
|
|
|
blinnMaterial.SetGenerator( &m_brushedMetalMaterial );
|
2016-10-02 08:11:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
2020-09-02 14:31:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
( *materialVector )[imat] = BLINN_PHONG_MATERIAL(
|
2020-12-12 17:29:11 +00:00
|
|
|
SFVEC3F( 0.2f ), SFVEC3F( 0.0f ), SFVEC3F( 0.0f ), 0.0f, 0.0f, 0.0f );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-02 14:31:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return materialVector;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
void RENDER_3D_RAYTRACE::addModels( CONTAINER_3D& aDstContainer, const S3DMODEL* a3DModel,
|
|
|
|
const glm::mat4& aModelMatrix, float aFPOpacity,
|
|
|
|
bool aSkipMaterialInformation, BOARD_ITEM* aBoardItem )
|
2020-12-12 17:29:11 +00:00
|
|
|
{
|
2020-09-02 14:31:42 +00:00
|
|
|
// Validate a3DModel pointers
|
2021-01-02 21:05:29 +00:00
|
|
|
wxASSERT( a3DModel != nullptr );
|
2020-09-02 14:31:42 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
if( a3DModel == nullptr )
|
2020-09-02 14:31:42 +00:00
|
|
|
return;
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
wxASSERT( a3DModel->m_Materials != nullptr );
|
|
|
|
wxASSERT( a3DModel->m_Meshes != nullptr );
|
2020-09-02 14:31:42 +00:00
|
|
|
wxASSERT( a3DModel->m_MaterialsSize > 0 );
|
|
|
|
wxASSERT( a3DModel->m_MeshesSize > 0 );
|
2020-11-13 02:57:11 +00:00
|
|
|
wxASSERT( aFPOpacity > 0.0f );
|
|
|
|
wxASSERT( aFPOpacity <= 1.0f );
|
2020-09-02 14:31:42 +00:00
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
if( aFPOpacity > 1.0f )
|
2020-09-02 14:31:42 +00:00
|
|
|
{
|
2020-11-13 02:57:11 +00:00
|
|
|
aFPOpacity = 1.0f;
|
2020-09-02 14:31:42 +00:00
|
|
|
}
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
if( ( a3DModel->m_Materials != nullptr ) && ( a3DModel->m_Meshes != nullptr )
|
2020-12-12 17:29:11 +00:00
|
|
|
&& ( a3DModel->m_MaterialsSize > 0 ) && ( a3DModel->m_MeshesSize > 0 ) )
|
2020-09-02 14:31:42 +00:00
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
MODEL_MATERIALS* materialVector = nullptr;
|
2020-09-02 14:31:42 +00:00
|
|
|
|
|
|
|
if( !aSkipMaterialInformation )
|
|
|
|
{
|
2021-01-07 19:33:43 +00:00
|
|
|
materialVector = getModelMaterial( a3DModel );
|
2020-09-02 14:31:42 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
const glm::mat3 normalMatrix = glm::transpose( glm::inverse( glm::mat3( aModelMatrix ) ) );
|
|
|
|
|
2020-12-12 17:29:11 +00:00
|
|
|
for( unsigned int mesh_i = 0; mesh_i < a3DModel->m_MeshesSize; ++mesh_i )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-12-12 17:29:11 +00:00
|
|
|
const SMESH& mesh = a3DModel->m_Meshes[mesh_i];
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// Validate the mesh pointers
|
2021-01-02 21:05:29 +00:00
|
|
|
wxASSERT( mesh.m_Positions != nullptr );
|
|
|
|
wxASSERT( mesh.m_FaceIdx != nullptr );
|
|
|
|
wxASSERT( mesh.m_Normals != nullptr );
|
2016-07-19 17:35:25 +00:00
|
|
|
wxASSERT( mesh.m_FaceIdxSize > 0 );
|
2020-12-12 17:29:11 +00:00
|
|
|
wxASSERT( ( mesh.m_FaceIdxSize % 3 ) == 0 );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
if( ( mesh.m_Positions != nullptr ) && ( mesh.m_Normals != nullptr )
|
|
|
|
&& ( mesh.m_FaceIdx != nullptr ) && ( mesh.m_FaceIdxSize > 0 )
|
2020-12-12 17:29:11 +00:00
|
|
|
&& ( mesh.m_VertexSize > 0 ) && ( ( mesh.m_FaceIdxSize % 3 ) == 0 )
|
|
|
|
&& ( mesh.m_MaterialIdx < a3DModel->m_MaterialsSize ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
float fpTransparency;
|
|
|
|
const BLINN_PHONG_MATERIAL* blinn_material;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-09-04 00:25:23 +00:00
|
|
|
if( !aSkipMaterialInformation )
|
|
|
|
{
|
2020-12-12 17:29:11 +00:00
|
|
|
blinn_material = &( *materialVector )[mesh.m_MaterialIdx];
|
2020-09-04 00:25:23 +00:00
|
|
|
|
2020-12-12 17:29:11 +00:00
|
|
|
fpTransparency =
|
|
|
|
1.0f - ( ( 1.0f - blinn_material->GetTransparency() ) * aFPOpacity );
|
2020-09-04 00:25:23 +00:00
|
|
|
}
|
2020-05-22 13:28:04 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
// Add all face triangles
|
2020-12-12 17:29:11 +00:00
|
|
|
for( unsigned int faceIdx = 0; faceIdx < mesh.m_FaceIdxSize; faceIdx += 3 )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
const unsigned int idx0 = mesh.m_FaceIdx[faceIdx + 0];
|
|
|
|
const unsigned int idx1 = mesh.m_FaceIdx[faceIdx + 1];
|
|
|
|
const unsigned int idx2 = mesh.m_FaceIdx[faceIdx + 2];
|
|
|
|
|
|
|
|
wxASSERT( idx0 < mesh.m_VertexSize );
|
|
|
|
wxASSERT( idx1 < mesh.m_VertexSize );
|
|
|
|
wxASSERT( idx2 < mesh.m_VertexSize );
|
|
|
|
|
2020-12-12 17:29:11 +00:00
|
|
|
if( ( idx0 < mesh.m_VertexSize ) && ( idx1 < mesh.m_VertexSize )
|
|
|
|
&& ( idx2 < mesh.m_VertexSize ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-12-12 17:29:11 +00:00
|
|
|
const SFVEC3F& v0 = mesh.m_Positions[idx0];
|
|
|
|
const SFVEC3F& v1 = mesh.m_Positions[idx1];
|
|
|
|
const SFVEC3F& v2 = mesh.m_Positions[idx2];
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-12-12 17:29:11 +00:00
|
|
|
const SFVEC3F& n0 = mesh.m_Normals[idx0];
|
|
|
|
const SFVEC3F& n1 = mesh.m_Normals[idx1];
|
|
|
|
const SFVEC3F& n2 = mesh.m_Normals[idx2];
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// Transform vertex with the model matrix
|
2020-12-12 17:29:11 +00:00
|
|
|
const SFVEC3F vt0 = SFVEC3F( aModelMatrix * glm::vec4( v0, 1.0f ) );
|
|
|
|
const SFVEC3F vt1 = SFVEC3F( aModelMatrix * glm::vec4( v1, 1.0f ) );
|
|
|
|
const SFVEC3F vt2 = SFVEC3F( aModelMatrix * glm::vec4( v2, 1.0f ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
const SFVEC3F nt0 = glm::normalize( SFVEC3F( normalMatrix * n0 ) );
|
|
|
|
const SFVEC3F nt1 = glm::normalize( SFVEC3F( normalMatrix * n1 ) );
|
|
|
|
const SFVEC3F nt2 = glm::normalize( SFVEC3F( normalMatrix * n2 ) );
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
TRIANGLE* newTriangle = new TRIANGLE( vt0, vt2, vt1, nt0, nt2, nt1 );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-09-04 00:00:56 +00:00
|
|
|
newTriangle->SetBoardItem( aBoardItem );
|
|
|
|
|
|
|
|
aDstContainer.Add( newTriangle );
|
2020-04-25 14:38:41 +00:00
|
|
|
|
2020-09-02 14:31:42 +00:00
|
|
|
if( !aSkipMaterialInformation )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-09-04 00:25:23 +00:00
|
|
|
newTriangle->SetMaterial( blinn_material );
|
2020-11-13 02:57:11 +00:00
|
|
|
newTriangle->SetModelTransparency( fpTransparency );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
if( mesh.m_Color == nullptr )
|
2020-09-02 14:31:42 +00:00
|
|
|
{
|
|
|
|
const SFVEC3F diffuseColor =
|
2020-12-12 17:29:11 +00:00
|
|
|
a3DModel->m_Materials[mesh.m_MaterialIdx].m_Diffuse;
|
2020-09-02 14:31:42 +00:00
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.material_mode == MATERIAL_MODE::CAD_MODE )
|
2020-12-12 17:29:11 +00:00
|
|
|
newTriangle->SetColor( ConvertSRGBToLinear(
|
|
|
|
MaterialDiffuseToColorCAD( diffuseColor ) ) );
|
2020-09-02 14:31:42 +00:00
|
|
|
else
|
|
|
|
newTriangle->SetColor( ConvertSRGBToLinear( diffuseColor ) );
|
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
else
|
2020-09-02 14:31:42 +00:00
|
|
|
{
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.material_mode == MATERIAL_MODE::CAD_MODE )
|
|
|
|
{
|
2020-12-12 17:29:11 +00:00
|
|
|
newTriangle->SetColor(
|
|
|
|
ConvertSRGBToLinear( MaterialDiffuseToColorCAD(
|
|
|
|
mesh.m_Color[idx0] ) ),
|
|
|
|
ConvertSRGBToLinear( MaterialDiffuseToColorCAD(
|
|
|
|
mesh.m_Color[idx1] ) ),
|
|
|
|
ConvertSRGBToLinear( MaterialDiffuseToColorCAD(
|
|
|
|
mesh.m_Color[idx2] ) ) );
|
2021-08-30 20:30:18 +00:00
|
|
|
}
|
2020-09-02 14:31:42 +00:00
|
|
|
else
|
2021-08-30 20:30:18 +00:00
|
|
|
{
|
2020-12-12 17:29:11 +00:00
|
|
|
newTriangle->SetColor(
|
|
|
|
ConvertSRGBToLinear( mesh.m_Color[idx0] ),
|
|
|
|
ConvertSRGBToLinear( mesh.m_Color[idx1] ),
|
|
|
|
ConvertSRGBToLinear( mesh.m_Color[idx2] ) );
|
2021-08-30 20:30:18 +00:00
|
|
|
}
|
2020-09-02 14:31:42 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|