KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 aIncludeUnspecified, bool aIncludeDNP,
128 bool aExport3DFiles, bool aUseRelativePaths,
129 const wxString& a3D_Subdir,
130 double aXRef, double aYRef );
131
132private:
134 {
135 return vrml_colors_list[aIndex];
136 }
137
138 void SetOffset( double aXoff, double aYoff );
139
140 double GetLayerZ( int aLayer )
141 {
142 if( unsigned( aLayer ) >= arrayDim( m_layer_z ) )
143 return 0;
144
145 return m_layer_z[ aLayer ];
146 }
147
148 void SetLayerZ( int aLayer, double aValue )
149 {
150 m_layer_z[aLayer] = aValue;
151 }
152
153 // set the scaling of the VRML world
154 bool SetScale( double aWorldScale );
155
156 // Initialize the list of colors used in VRML export.
157 void initStaticColorList();
158
159 // Build and export the solder mask layer, that is a negative layer
161
162 // Build and export the 4 layers F_Cu, B_Cu, F_SilkS, B_SilkS
164
165 void ExportVrmlFootprint( FOOTPRINT* aFootprint, std::ostream* aOutputFile );
166
167 // Build and exports the board outlines (board body)
168 void ExportVrmlBoard();
169
170 // Export all via holes
171 void ExportVrmlViaHoles();
172
173 void ExportFp3DModelsAsLinkedFile( const wxString& aFullFileName );
174
175 void ExportVrmlPadHole( PAD* aPad );
176
177 // Export a set of polygons without holes.
178 // Polygons in SHAPE_POLY_SET must be without hole, i.e. holes must be linked
179 // previously to their main outline.
180 void ExportVrmlPolygonSet( VRML_LAYER* aVlayer, const SHAPE_POLY_SET& aOutlines );
181
182 void writeLayers( const char* aFileName, OSTREAM* aOutputFile );
183
184 // select the VRML layer object to draw on
185 // return true if a layer has been selected.
186 bool GetLayer3D( int layer, VRML_LAYER** vlayer );
187
188 // Build the Z position of 3D layers
189 void ComputeLayer3D_Zpos();
190
191 void write_triangle_bag( std::ostream& aOut_file, const VRML_COLOR& aColor, VRML_LAYER* aLayer,
192 bool aPlane, bool aTop, double aTop_z, double aBottom_z );
193
194 void create_vrml_shell( IFSG_TRANSFORM& PcbOutput, VRML_COLOR_INDEX colorID, VRML_LAYER* layer,
195 double top_z, double bottom_z );
196
197 void create_vrml_plane( IFSG_TRANSFORM& PcbOutput, VRML_COLOR_INDEX colorID, VRML_LAYER* layer,
198 double aHeight, bool aTopPlane );
199
201
207
215
217 VRML_LAYER m_holes;
218 VRML_LAYER m_3D_board;
219 VRML_LAYER m_top_copper;
220 VRML_LAYER m_bot_copper;
221 VRML_LAYER m_top_silk;
222 VRML_LAYER m_bot_silk;
225 VRML_LAYER m_top_paste;
226 VRML_LAYER m_bot_paste;
227 VRML_LAYER m_plated_holes;
228
229 std::list<SGNODE*> m_components;
231
232 /* true to use VRML inline{} syntax for footprint 3D models, like:
233 * Inline { url "F:/tmp/pic_programmer/shapes3D/DIP-18_W7.62mm_Socket.wrl" }
234 * false to merge VRML 3D modules in the .wrl board file
235 */
237
238 // 3D subdirectory to copy footprint vrml 3D models when not merged in board file
240
241 // true to use relative paths in VRML inline{} for footprint 3D models
242 // used only if m_UseInlineModelsInBrdfile = true
244
245 // true to reuse component definitions
247
248 // true if unspecified components should be included
250
251 // true if DNP components should be included
253
254 // scaling from 0.1 inch to desired VRML unit
255 double m_WorldScale = 1.0;
256
257 // scaling from mm to desired VRML world scale
259
260 double m_tx; // global translation along X
261 double m_ty; // global translation along Y
262
263 double m_brd_thickness; // depth of the PCB
264
265private:
269 SHAPE_POLY_SET m_pcbOutlines; // stores the board main outlines
270
271 int m_precision; // precision factor when exporting fp shapes
272 // to separate files
274};
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:281
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
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)
bool ExportVRML_File(PROJECT *aProject, wxString *aMessages, const wxString &aFullFileName, double aMMtoWRMLunit, bool aIncludeUnspecified, bool aIncludeDNP, bool aExport3DFiles, bool aUseRelativePaths, const wxString &a3D_Subdir, double aXRef, double aYRef)
Export a VRML file image of the board.
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)
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:62
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