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 auto it = m_layer_z.find( aLayer );
143
144 if( it == m_layer_z.end() )
145 return 0;
146
147 return it->second;
148 }
149
150 void SetLayerZ( int aLayer, double aValue )
151 {
152 m_layer_z[aLayer] = aValue;
153 }
154
155 // set the scaling of the VRML world
156 bool SetScale( double aWorldScale );
157
158 // Initialize the list of colors used in VRML export.
159 void initStaticColorList();
160
161 // Build and export the solder mask layer, that is a negative layer
163
164 // Build and export the 4 layers F_Cu, B_Cu, F_SilkS, B_SilkS
166
167 void ExportVrmlFootprint( FOOTPRINT* aFootprint, std::ostream* aOutputFile );
168
169 // Build and exports the board outlines (board body)
170 void ExportVrmlBoard();
171
172 // Export all via holes
173 void ExportVrmlViaHoles();
174
175 void ExportFp3DModelsAsLinkedFile( const wxString& aFullFileName );
176
177 void ExportVrmlPadHole( PAD* aPad );
178
179 // Export a set of polygons without holes.
180 // Polygons in SHAPE_POLY_SET must be without hole, i.e. holes must be linked
181 // previously to their main outline.
182 void ExportVrmlPolygonSet( VRML_LAYER* aVlayer, const SHAPE_POLY_SET& aOutlines );
183
184 void writeLayers( const char* aFileName, OSTREAM* aOutputFile );
185
186 // select the VRML layer object to draw on
187 // return true if a layer has been selected.
188 bool GetLayer3D( int layer, VRML_LAYER** vlayer );
189
190 // Build the Z position of 3D layers
191 void ComputeLayer3D_Zpos();
192
193 void write_triangle_bag( std::ostream& aOut_file, const VRML_COLOR& aColor, VRML_LAYER* aLayer,
194 bool aPlane, bool aTop, double aTop_z, double aBottom_z );
195
196 void create_vrml_shell( IFSG_TRANSFORM& PcbOutput, VRML_COLOR_INDEX colorID, VRML_LAYER* layer,
197 double top_z, double bottom_z );
198
199 void create_vrml_plane( IFSG_TRANSFORM& PcbOutput, VRML_COLOR_INDEX colorID, VRML_LAYER* layer,
200 double aHeight, bool aTopPlane );
201
203
209
217
219 VRML_LAYER m_holes;
220 VRML_LAYER m_3D_board;
221 VRML_LAYER m_top_copper;
222 VRML_LAYER m_bot_copper;
223 VRML_LAYER m_top_silk;
224 VRML_LAYER m_bot_silk;
227 VRML_LAYER m_top_paste;
228 VRML_LAYER m_bot_paste;
229 VRML_LAYER m_plated_holes;
230
231 std::list<SGNODE*> m_components;
233
234 /* true to use VRML inline{} syntax for footprint 3D models, like:
235 * Inline { url "F:/tmp/pic_programmer/shapes3D/DIP-18_W7.62mm_Socket.wrl" }
236 * false to merge VRML 3D modules in the .wrl board file
237 */
239
240 // 3D subdirectory to copy footprint vrml 3D models when not merged in board file
242
243 // true to use relative paths in VRML inline{} for footprint 3D models
244 // used only if m_UseInlineModelsInBrdfile = true
246
247 // true to reuse component definitions
249
250 // true if unspecified components should be included
252
253 // true if DNP components should be included
255
256 // scaling from 0.1 inch to desired VRML unit
257 double m_WorldScale = 1.0;
258
259 // scaling from mm to desired VRML world scale
261
262 double m_tx; // global translation along X
263 double m_ty; // global translation along Y
264
265 double m_brd_thickness; // depth of the PCB
266
267private:
270 std::map<int, double> m_layer_z;
271 SHAPE_POLY_SET m_pcbOutlines; // stores the board main outlines
272
273 int m_precision; // precision factor when exporting fp shapes
274 // to separate files
276};
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:290
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
std::map< int, double > m_layer_z
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
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:54
Container for project specific data.
Definition: project.h:64
Cache for storing the 3D shapes.
Definition: 3d_cache.h:55
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
#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