KiCad PCB EDA Suite
exporter_vrml.h
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) 2021-2022 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
23#include <export_vrml.h>
24
25// offset for art layers, mm (silk, paste, etc)
26#define ART_OFFSET 0.025
27// offset for plating
28#define PLATE_OFFSET 0.005
29
30class PROJECT;
31
33{
42 VRML_COLOR_LAST // Sentinel
43};
44
45
47{
51
52 float spec_red;
53 float spec_grn;
54 float spec_blu;
55
56 float emit_red;
57 float emit_grn;
58 float emit_blu;
59
60 float ambient;
61 float transp;
62 float shiny;
63
65 {
66 // default green
67 diffuse_red = 0.13f;
68 diffuse_grn = 0.81f;
69 diffuse_blu = 0.22f;
70 spec_red = 0.01f;
71 spec_grn = 0.08f;
72 spec_blu = 0.02f;
73 emit_red = 0.0f;
74 emit_grn = 0.0f;
75 emit_blu = 0.0f;
76
77 ambient = 0.8f;
78 transp = 0.0f;
79 shiny = 0.02f;
80 }
81
82 VRML_COLOR( float dr, float dg, float db,
83 float sr, float sg, float sb,
84 float am, float tr, float sh )
85 {
86 diffuse_red = dr;
87 diffuse_grn = dg;
88 diffuse_blu = db;
89 spec_red = sr;
90 spec_grn = sg;
91 spec_blu = sb;
92 emit_red = 0.0f;
93 emit_grn = 0.0f;
94 emit_blu = 0.0f;
95
96 ambient = am;
97 transp = tr;
98 shiny = sh;
99 }
100};
101
102
103// Handle the board and its board items to convert them to a VRML representation:
105{
106public:
107 EXPORTER_PCB_VRML( BOARD* aBoard );
109
125 bool ExportVRML_File( PROJECT* aProject, wxString *aMessages,
126 const wxString& aFullFileName, double aMMtoWRMLunit,
127 bool aExport3DFiles, bool aUseRelativePaths,
128 const wxString& a3D_Subdir,
129 double aXRef, double aYRef );
130
131private:
133 {
134 return vrml_colors_list[aIndex];
135 }
136
137 void SetOffset( double aXoff, double aYoff );
138
139 double GetLayerZ( int aLayer )
140 {
141 if( unsigned( aLayer ) >= arrayDim( m_layer_z ) )
142 return 0;
143
144 return m_layer_z[ aLayer ];
145 }
146
147 void SetLayerZ( int aLayer, double aValue )
148 {
149 m_layer_z[aLayer] = aValue;
150 }
151
152 // set the scaling of the VRML world
153 bool SetScale( double aWorldScale );
154
155 // Initialize the list of colors used in VRML export.
156 void initStaticColorList();
157
158 // Build and export the solder mask layer, that is a negative layer
160
161 // Build and export the 4 layers F_Cu, B_Cu, F_SilkS, B_SilkS
163
164 void ExportVrmlFootprint( FOOTPRINT* aFootprint, std::ostream* aOutputFile );
165
166 // Build and exports the board outlines (board body)
167 void ExportVrmlBoard();
168
169 // Export all via holes
170 void ExportVrmlViaHoles();
171
172 void ExportFp3DModelsAsLinkedFile( const wxString& aFullFileName );
173
174 void ExportVrmlPadHole( PAD* aPad );
175
176 // Export a set of polygons without holes.
177 // Polygons in SHAPE_POLY_SET must be without hole, i.e. holes must be linked
178 // previously to their main outline.
179 void ExportVrmlPolygonSet( VRML_LAYER* aVlayer, const SHAPE_POLY_SET& aOutlines );
180
181 void writeLayers( const char* aFileName, OSTREAM* aOutputFile );
182
183 // select the VRML layer object to draw on
184 // return true if a layer has been selected.
185 bool GetLayer3D( int layer, VRML_LAYER** vlayer );
186
187 // Build the Z position of 3D layers
188 void ComputeLayer3D_Zpos();
189
190 void write_triangle_bag( std::ostream& aOut_file, const VRML_COLOR& aColor, VRML_LAYER* aLayer,
191 bool aPlane, bool aTop, double aTop_z, double aBottom_z );
192
193 void create_vrml_shell( IFSG_TRANSFORM& PcbOutput, VRML_COLOR_INDEX colorID, VRML_LAYER* layer,
194 double top_z, double bottom_z );
195
196 void create_vrml_plane( IFSG_TRANSFORM& PcbOutput, VRML_COLOR_INDEX colorID, VRML_LAYER* layer,
197 double aHeight, bool aTopPlane );
198
200
206
214
216 VRML_LAYER m_holes;
217 VRML_LAYER m_3D_board;
218 VRML_LAYER m_top_copper;
219 VRML_LAYER m_bot_copper;
220 VRML_LAYER m_top_silk;
221 VRML_LAYER m_bot_silk;
224 VRML_LAYER m_top_paste;
225 VRML_LAYER m_bot_paste;
226 VRML_LAYER m_plated_holes;
227
228 std::list<SGNODE*> m_components;
230
231 /* true to use VRML inline{} syntax for footprint 3D models, like:
232 * Inline { url "F:/tmp/pic_programmer/shapes3D/DIP-18_W7.62mm_Socket.wrl" }
233 * false to merge VRML 3D modules in the .wrl board file
234 */
236
237 // 3D subdirectory to copy footprint vrml 3D models when not merged in board file
239
240 // true to use relative paths in VRML inline{} for footprint 3D models
241 // used only if m_UseInlineModelsInBrdfile = true
243
244 // true to reuse component definitions
246
247 // scaling from 0.1 inch to desired VRML unit
248 double m_WorldScale = 1.0;
249
250 // scaling from mm to desired VRML world scale
252
253 double m_tx; // global translation along X
254 double m_ty; // global translation along Y
255
256 double m_brd_thickness; // depth of the PCB
257
258private:
262 SHAPE_POLY_SET m_pcbOutlines; // stores the board main outlines
263
264 int m_precision; // precision factor when exporting fp shapes
265 // to separate files
267};
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
Definition: arraydim.h:31
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:265
VRML_COLOR & GetColor(VRML_COLOR_INDEX aIndex)
static CUSTOM_COLORS_LIST m_MaskColors
SGNODE * m_sgmaterial[VRML_COLOR_LAST]
static CUSTOM_COLORS_LIST m_PasteColors
static KIGFX::COLOR4D m_DefaultSolderPaste
VRML_LAYER m_top_copper
VRML_LAYER m_top_soldermask
bool GetLayer3D(int layer, VRML_LAYER **vlayer)
bool SetScale(double aWorldScale)
VRML_LAYER m_bot_paste
SGNODE * getSGColor(VRML_COLOR_INDEX colorIdx)
VRML_LAYER m_top_paste
EXPORTER_PCB_VRML(BOARD *aBoard)
static KIGFX::COLOR4D m_DefaultBackgroundTop
VRML_LAYER m_bot_copper
SHAPE_POLY_SET m_pcbOutlines
VRML_LAYER m_plated_holes
void SetLayerZ(int aLayer, double aValue)
void ExportVrmlPolygonSet(VRML_LAYER *aVlayer, const SHAPE_POLY_SET &aOutlines)
void create_vrml_shell(IFSG_TRANSFORM &PcbOutput, VRML_COLOR_INDEX colorID, VRML_LAYER *layer, double top_z, double bottom_z)
void write_triangle_bag(std::ostream &aOut_file, const VRML_COLOR &aColor, VRML_LAYER *aLayer, bool aPlane, bool aTop, double aTop_z, double aBottom_z)
std::list< SGNODE * > m_components
static KIGFX::COLOR4D m_DefaultSilkscreen
static CUSTOM_COLORS_LIST m_SilkscreenColors
void SetOffset(double aXoff, double aYoff)
static KIGFX::COLOR4D m_DefaultBackgroundBot
VRML_LAYER m_holes
double GetLayerZ(int aLayer)
void ExportVrmlPadHole(PAD *aPad)
static CUSTOM_COLORS_LIST m_BoardColors
void create_vrml_plane(IFSG_TRANSFORM &PcbOutput, VRML_COLOR_INDEX colorID, VRML_LAYER *layer, double aHeight, bool aTopPlane)
bool m_UseInlineModelsInBrdfile
wxString m_Subdir3DFpModels
static KIGFX::COLOR4D m_DefaultBoardBody
static CUSTOM_COLORS_LIST m_FinishColors
static KIGFX::COLOR4D m_DefaultSolderMask
double m_layer_z[PCB_LAYER_ID_COUNT]
bool m_UseRelPathIn3DModelFilename
void ExportVrmlFootprint(FOOTPRINT *aFootprint, std::ostream *aOutputFile)
bool ExportVRML_File(PROJECT *aProject, wxString *aMessages, const wxString &aFullFileName, double aMMtoWRMLunit, bool aExport3DFiles, bool aUseRelativePaths, const wxString &a3D_Subdir, double aXRef, double aYRef)
Export a VRML file image of the board.
void ExportFp3DModelsAsLinkedFile(const wxString &aFullFileName)
VRML_LAYER m_bot_soldermask
VRML_COLOR vrml_colors_list[VRML_COLOR_LAST]
VRML_LAYER m_3D_board
void writeLayers(const char *aFileName, OSTREAM *aOutputFile)
static KIGFX::COLOR4D m_DefaultSurfaceFinish
VRML_LAYER m_bot_silk
IFSG_TRANSFORM m_OutputPCB
VRML_LAYER m_top_silk
S3D_CACHE * m_Cache3Dmodels
IFSG_TRANSFORM is the wrapper for the VRML compatible TRANSFORM block class SCENEGRAPH.
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
Definition: pad.h:59
Container for project specific data.
Definition: project.h:64
Cache for storing the 3D shapes.
Definition: 3d_cache.h:53
The base class of all Scene Graph nodes.
Definition: sg_node.h:75
Represent a set of closed polygons.
std::vector< CUSTOM_COLOR_ITEM > CUSTOM_COLORS_LIST
VRML_COLOR_INDEX
Definition: exporter_vrml.h:33
@ VRML_COLOR_BOT_SILK
Definition: exporter_vrml.h:41
@ VRML_COLOR_LAST
Definition: exporter_vrml.h:42
@ VRML_COLOR_TOP_SILK
Definition: exporter_vrml.h:40
@ VRML_COLOR_TOP_SOLDMASK
Definition: exporter_vrml.h:37
@ VRML_COLOR_PCB
Definition: exporter_vrml.h:35
@ VRML_COLOR_PASTE
Definition: exporter_vrml.h:39
@ VRML_COLOR_COPPER
Definition: exporter_vrml.h:36
@ VRML_COLOR_BOT_SOLDMASK
Definition: exporter_vrml.h:38
@ VRML_COLOR_NONE
Definition: exporter_vrml.h:34
@ PCB_LAYER_ID_COUNT
Definition: layer_ids.h:137
#define OSTREAM
float ambient
Definition: exporter_vrml.h:60
float emit_blu
Definition: exporter_vrml.h:58
float diffuse_red
Definition: exporter_vrml.h:48
VRML_COLOR(float dr, float dg, float db, float sr, float sg, float sb, float am, float tr, float sh)
Definition: exporter_vrml.h:82
float spec_blu
Definition: exporter_vrml.h:54
float diffuse_grn
Definition: exporter_vrml.h:49
float transp
Definition: exporter_vrml.h:61
float spec_grn
Definition: exporter_vrml.h:53
float emit_grn
Definition: exporter_vrml.h:57
float emit_red
Definition: exporter_vrml.h:56
float spec_red
Definition: exporter_vrml.h:52
float diffuse_blu
Definition: exporter_vrml.h:50