← Back to team overview

kicad-developers team mailing list archive

Re: [PATCH] Fix for 3D model offset

 

Wayne,

Patch files attached.

Once again the --ignore-whitespace flag will need to be used, I believe it
is because a line in kicad-plugin.h (46, corresponding to 20170920) has a
DOS newline instead of a UNIX newline.


Thanks,

On Tue, Nov 21, 2017 at 4:27 AM, Wayne Stambaugh <stambaughw@xxxxxxxxx>
wrote:

> Oliver,
>
> Please send me the latest patch(es) when you get a chance so I can get
> this merged.  I cannot find it (them) in my inbox.  I must have deleted
> the email by accident.
>
> Cheers,
>
> Wayne
>
> On 11/18/2017 8:39 PM, Oliver Walters wrote:
> > Wayne,
> >
> > Any further issues to address here? :)
> >
> > On 14 Nov 2017 20:55, "Oliver Walters" <oliver.henry.walters@xxxxxxxxx
> > <mailto:oliver.henry.walters@xxxxxxxxx>> wrote:
> >
> >     Wayne,
> >
> >     Please find attached updated patch set. If an old version is
> >     detected, inches are converted to mm.
> >
> >     On Tue, Nov 14, 2017 at 9:33 AM, Nick Østergaard <oe.nick@xxxxxxxxx
> >     <mailto:oe.nick@xxxxxxxxx>> wrote:
> >
> >         Just to mention it, I think this quirk needs to be put in the
> >         release
> >         notes for 5.0.0 if that would be the case, or at least
> >         documented as a
> >         note in the docs.
> >
> >         2017-11-13 18:10 GMT+01.00, Wayne Stambaugh
> >         <stambaughw@xxxxxxxxx <mailto:stambaughw@xxxxxxxxx>>:
> >         > On 11/12/2017 6:12 AM, Oliver Walters wrote:
> >         >> Wayne,
> >         >>
> >         >> Another potential spanner in the works - the footprint files
> >         do not
> >         >> store the file version information. (should they?)
> >         >
> >         > I would rather not.  Otherwise there would be a footprint
> >         version in
> >         > every footprint embedded in the schematic and could lead to
> >         some ugly
> >         > parser code.  At some point we may need to revisit this but
> >         not now.
> >         >
> >         > This is not a big issue because the only effects the
> >         footprints embedded
> >         > in the board.  Users with custom footprint libraries that
> >         contain 3D
> >         > model offsets will just have to fix the offsets.  I'm guessing
> >         this is a
> >         > fairly small number of users.
> >         >
> >         >>
> >         >> Thus, footprint files cannot be parsed differently based on
> >         their file
> >         >> version. Changing "at" between mm and inches will work for
> >         the pcb but
> >         >> not for the individual footprint files
> >         >>
> >         >> On Sun, Nov 12, 2017 at 7:47 AM, Wayne Stambaugh
> >         <stambaughw@xxxxxxxxx <mailto:stambaughw@xxxxxxxxx>
> >         >> <mailto:stambaughw@xxxxxxxxx <mailto:stambaughw@xxxxxxxxx>>>
> >         wrote:
> >         >>
> >         >>     I misunderstood the intention of this patch.  I though it
> >         had nothing
> >         >> to
> >         >>     do with the units change patch.  I will revert it.
> >         Please send me the
> >         >>     file format change patch when you get a chance and I
> >         merge them both
> >         >> at
> >         >>     the same time.  Sorry about the mix up.
> >         >>
> >         >>     On 11/11/2017 03:34 PM, Oliver Walters wrote:
> >         >>     > Wayne,
> >         >>     >
> >         >>     > I had not yet made any changes to the file parser. Have
> >         you done
> >         >> this
> >         >>     > according to your new file-version approach? Or do you
> >         want me to
> >         >> submit
> >         >>     > a further patch implementing that?
> >         >>     >
> >         >>     > On 12 Nov 2017 07:16, "Wayne Stambaugh"
> >         <stambaughw@xxxxxxxxx <mailto:stambaughw@xxxxxxxxx>
> >         >> <mailto:stambaughw@xxxxxxxxx <mailto:stambaughw@xxxxxxxxx>>
> >         >>     > <mailto:stambaughw@xxxxxxxxx
> >         <mailto:stambaughw@xxxxxxxxx> <mailto:stambaughw@xxxxxxxxx
> >         <mailto:stambaughw@xxxxxxxxx>>>> wrote:
> >         >>     >
> >         >>     >     Oliver,
> >         >>     >
> >         >>     >     I committed your patch to the KiCad development
> branch.
> >         >>     >
> >         >>     >     Thanks,
> >         >>     >
> >         >>     >     Wayne
> >         >>     >
> >         >>     >     On 11/08/2017 05:05 AM, Oliver Walters wrote:
> >         >>     >     > Attached is a patch that fixes the problems I
> >         found in my 3D
> >         >>     model
> >         >>     >     array
> >         >>     >     > investigation. As discussion on that is stalled
> >         for now,
> >         >>     this patch
> >         >>     >     > simply fixes the model offset issues.
> >         >>     >     >
> >         >>     >     > 1. Display offset units in 3D preview window
> >         >>     >     >
> >         >>     >     > - Offset units are displayed (either inches or mm)
> >         >>     >     >
> >         >>     >     > 2. Fix offset in 3D rendering
> >         >>     >     >
> >         >>     >     > - It appears that the internal units for 3D model
> >         offset
> >         >>     (mm) were
> >         >>     >     being
> >         >>     >     > multiplied by 25.4 incorrectly
> >         >>     >     > - Fixed rendering in OGL and Raytracing
> >         >>     >     >
> >         >>     >     > 3. Fix offset in 3D export
> >         >>     >     >
> >         >>     >     > - VRML export
> >         >>     >     > - STEP export
> >         >>     >     >
> >         >>     >     > Oliver
> >         >>     >     >
> >         >>     >     >
> >         >>     >     > _______________________________________________
> >         >>     >     > Mailing list:
> >         https://launchpad.net/~kicad-developers
> >         <https://launchpad.net/~kicad-developers>
> >         >>     <https://launchpad.net/~kicad-developers
> >         <https://launchpad.net/~kicad-developers>>
> >         >>     >     <https://launchpad.net/~kicad-developers
> >         <https://launchpad.net/~kicad-developers>
> >         >>     <https://launchpad.net/~kicad-developers
> >         <https://launchpad.net/~kicad-developers>>>
> >         >>     >     > Post to     :
> >         kicad-developers@xxxxxxxxxxxxxxxxxxx
> >         <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx>
> >         >>     <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx
> >         <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx>>
> >         >>     >     <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx
> >         <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx>
> >         >>     <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx
> >         <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx>>>
> >         >>     >     > Unsubscribe :
> >         https://launchpad.net/~kicad-developers
> >         <https://launchpad.net/~kicad-developers>
> >         >>     <https://launchpad.net/~kicad-developers
> >         <https://launchpad.net/~kicad-developers>>
> >         >>     >     <https://launchpad.net/~kicad-developers
> >         <https://launchpad.net/~kicad-developers>
> >         >>     <https://launchpad.net/~kicad-developers
> >         <https://launchpad.net/~kicad-developers>>>
> >         >>     >     > More help   : https://help.launchpad.net/ListHelp
> >         <https://help.launchpad.net/ListHelp>
> >         >>     <https://help.launchpad.net/ListHelp
> >         <https://help.launchpad.net/ListHelp>>
> >         >>     >     <https://help.launchpad.net/ListHelp
> >         <https://help.launchpad.net/ListHelp>
> >         >>     <https://help.launchpad.net/ListHelp
> >         <https://help.launchpad.net/ListHelp>>>
> >         >>     >     >
> >         >>     >
> >         >>     >     _______________________________________________
> >         >>     >     Mailing list:
> >         https://launchpad.net/~kicad-developers
> >         <https://launchpad.net/~kicad-developers>
> >         >>     <https://launchpad.net/~kicad-developers
> >         <https://launchpad.net/~kicad-developers>>
> >         >>     >     <https://launchpad.net/~kicad-developers
> >         <https://launchpad.net/~kicad-developers>
> >         >>     <https://launchpad.net/~kicad-developers
> >         <https://launchpad.net/~kicad-developers>>>
> >         >>     >     Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
> >         <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx>
> >         >>     <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx
> >         <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx>>
> >         >>     >     <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx
> >         <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx>
> >         >>     <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx
> >         <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx>>>
> >         >>     >     Unsubscribe :
> >         https://launchpad.net/~kicad-developers
> >         <https://launchpad.net/~kicad-developers>
> >         >>     <https://launchpad.net/~kicad-developers
> >         <https://launchpad.net/~kicad-developers>>
> >         >>     >     <https://launchpad.net/~kicad-developers
> >         <https://launchpad.net/~kicad-developers>
> >         >>     <https://launchpad.net/~kicad-developers
> >         <https://launchpad.net/~kicad-developers>>>
> >         >>     >     More help   : https://help.launchpad.net/ListHelp
> >         <https://help.launchpad.net/ListHelp>
> >         >>     <https://help.launchpad.net/ListHelp
> >         <https://help.launchpad.net/ListHelp>>
> >         >>     >     <https://help.launchpad.net/ListHelp
> >         <https://help.launchpad.net/ListHelp>
> >         >>     <https://help.launchpad.net/ListHelp
> >         <https://help.launchpad.net/ListHelp>>>
> >         >>     >
> >         >>
> >         >>
> >         >
> >         > _______________________________________________
> >         > Mailing list: https://launchpad.net/~kicad-developers
> >         <https://launchpad.net/~kicad-developers>
> >         > Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
> >         <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx>
> >         > Unsubscribe : https://launchpad.net/~kicad-developers
> >         <https://launchpad.net/~kicad-developers>
> >         > More help   : https://help.launchpad.net/ListHelp
> >         <https://help.launchpad.net/ListHelp>
> >         >
> >
> >
>
From 2578ff1e94a46cb75ab350fe4b7ec91065a104ab Mon Sep 17 00:00:00 2001
From: Oliver <oliver.henry.walters@xxxxxxxxx>
Date: Tue, 14 Nov 2017 20:53:59 +1100
Subject: [PATCH 2/2] Changed model offset in file to mm

- Written in mm
- Read as mm if newer than 20171114
- Read as inches if older than 20171114
- Added some documentation
---
 pcbnew/class_module.h   |  6 +++---
 pcbnew/kicad_plugin.cpp |  1 +
 pcbnew/kicad_plugin.h   |  3 ++-
 pcbnew/pcb_parser.cpp   | 17 +++++++++++++++++
 4 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/pcbnew/class_module.h b/pcbnew/class_module.h
index daeb814..9b742b0 100644
--- a/pcbnew/class_module.h
+++ b/pcbnew/class_module.h
@@ -95,9 +95,9 @@ class MODULE_3D_SETTINGS
             double x, y, z;
         };
 
-        VECTOR3D m_Scale;
-        VECTOR3D m_Rotation;
-        VECTOR3D m_Offset;
+        VECTOR3D m_Scale;       ///< 3D model scaling factor (dimensionless)
+        VECTOR3D m_Rotation;    ///< 3D model rotation (degrees)
+        VECTOR3D m_Offset;      ///< 3D model offset (mm)
         wxString m_Filename;    ///< The 3D shape filename in 3D library
 };
 
diff --git a/pcbnew/kicad_plugin.cpp b/pcbnew/kicad_plugin.cpp
index 85f4f8e..c4477ad 100644
--- a/pcbnew/kicad_plugin.cpp
+++ b/pcbnew/kicad_plugin.cpp
@@ -1140,6 +1140,7 @@ void PCB_IO::format( MODULE* aModule, int aNestLevel ) const
             m_out->Print( aNestLevel+1, "(model %s\n",
                           m_out->Quotew( bs3D->m_Filename ).c_str() );
 
+            // Model offset is in mm
             m_out->Print( aNestLevel+2, "(at (xyz %s %s %s))\n",
                           Double2Str( bs3D->m_Offset.x ).c_str(),
                           Double2Str( bs3D->m_Offset.y ).c_str(),
diff --git a/pcbnew/kicad_plugin.h b/pcbnew/kicad_plugin.h
index eff7590..7d31acc 100644
--- a/pcbnew/kicad_plugin.h
+++ b/pcbnew/kicad_plugin.h
@@ -44,7 +44,8 @@ class NETINFO_MAPPING;
 //#define SEXPR_BOARD_FILE_VERSION    20160815  // differential pair settings per net class
 //#define SEXPR_BOARD_FILE_VERSION    20170123  // EDA_TEXT refactor, moved 'hide'
 //#define SEXPR_BOARD_FILE_VERSION    20170920  // long pad names and custom pad shape
-#define SEXPR_BOARD_FILE_VERSION      20170922  // Keepout zones can exist on multiple layers
+//#define SEXPR_BOARD_FILE_VERSION    20170922  // Keepout zones can exist on multiple layers
+#define SEXPR_BOARD_FILE_VERSION      20171114  // Save 3D model offset in mm, instead of inches
 
 #define CTL_STD_LAYER_NAMES         (1 << 0)    ///< Use English Standard layer names
 #define CTL_OMIT_NETS               (1 << 1)    ///< Omit pads net names (useless in library)
diff --git a/pcbnew/pcb_parser.cpp b/pcbnew/pcb_parser.cpp
index b96d9bb..13a1189 100644
--- a/pcbnew/pcb_parser.cpp
+++ b/pcbnew/pcb_parser.cpp
@@ -359,9 +359,26 @@ MODULE_3D_SETTINGS* PCB_PARSER::parse3DModel()
             if( token != T_xyz )
                 Expecting( T_xyz );
 
+            /* Note:
+             * Prior to SEXPR_BOARD_FILE_VERSION 20171114,
+             * 3D model offset was read and written in inches
+             *
+             * Now, the offset is explicitly written in mm.
+             * If a board is read with an older version,
+             * the offset is converted from inches to mm
+             */
+
             n3D->m_Offset.x = parseDouble( "x value" );
             n3D->m_Offset.y = parseDouble( "y value" );
             n3D->m_Offset.z = parseDouble( "z value" );
+
+            if(m_requiredVersion < 20171114UL)
+            {
+                n3D->m_Offset.x *= 25.4f;
+                n3D->m_Offset.y *= 25.4f;
+                n3D->m_Offset.z *= 25.4f;
+            }
+
             NeedRIGHT();
             break;
 
-- 
2.7.4

From ee49a5ab13706a78e55939863284d1909dd70e4b Mon Sep 17 00:00:00 2001
From: Oliver <oliver.henry.walters@xxxxxxxxx>
Date: Wed, 8 Nov 2017 20:56:57 +1100
Subject: [PATCH 1/2] Fixes for 3D model offset

- Display offset units in 3D preview window (inches or mm)
- Fix offset in 3D renderer
- Fix offset in Raytracing renderer
- Fix offset in STEP export
- Fix offset in VRML export
---
 3d-viewer/3d_cache/dialogs/panel_prev_3d_base.cpp  | 15 +++--
 3d-viewer/3d_cache/dialogs/panel_prev_3d_base.fbp  | 16 +++---
 3d-viewer/3d_cache/dialogs/panel_prev_3d_base.h    |  5 +-
 3d-viewer/3d_cache/dialogs/panel_prev_model.cpp    | 67 +++++++++++++++-------
 .../3d_render_ogl_legacy/c3d_render_ogl_legacy.cpp |  4 +-
 .../c3d_render_createscene.cpp                     |  6 +-
 pcbnew/class_module.h                              |  8 +++
 pcbnew/exporters/export_vrml.cpp                   | 10 ++--
 utils/kicad2step/pcb/kicadmodel.cpp                |  5 +-
 utils/kicad2step/pcb/oce_utils.cpp                 |  7 +--
 10 files changed, 89 insertions(+), 54 deletions(-)

diff --git a/3d-viewer/3d_cache/dialogs/panel_prev_3d_base.cpp b/3d-viewer/3d_cache/dialogs/panel_prev_3d_base.cpp
index f7b9fca..826e189 100644
--- a/3d-viewer/3d_cache/dialogs/panel_prev_3d_base.cpp
+++ b/3d-viewer/3d_cache/dialogs/panel_prev_3d_base.cpp
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////
-// C++ code generated with wxFormBuilder (version Aug  4 2017)
+// C++ code generated with wxFormBuilder (version Mar 22 2017)
 // http://www.wxformbuilder.org/
 //
 // PLEASE DO "NOT" EDIT THIS FILE!
@@ -40,7 +40,7 @@ PANEL_PREV_3D_BASE::PANEL_PREV_3D_BASE( wxWindow* parent, wxWindowID id, const w
 	fgSizerScale->Add( m_staticText2, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 );
 	
 	yscale = new wxTextCtrl( vbScale->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
-	fgSizerScale->Add( yscale, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 );
+	fgSizerScale->Add( yscale, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT|wxTOP, 5 );
 	
 	m_spinYscale = new wxSpinButton( vbScale->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS|wxSP_VERTICAL );
 	fgSizerScale->Add( m_spinYscale, 0, wxALIGN_CENTER_VERTICAL, 5 );
@@ -53,7 +53,7 @@ PANEL_PREV_3D_BASE::PANEL_PREV_3D_BASE( wxWindow* parent, wxWindowID id, const w
 	fgSizerScale->Add( zscale, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT, 5 );
 	
 	m_spinZscale = new wxSpinButton( vbScale->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS|wxSP_VERTICAL );
-	fgSizerScale->Add( m_spinZscale, 0, wxALIGN_CENTER_VERTICAL, 5 );
+	fgSizerScale->Add( m_spinZscale, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM, 5 );
 	
 	
 	vbScale->Add( fgSizerScale, 1, wxEXPAND, 5 );
@@ -100,7 +100,7 @@ PANEL_PREV_3D_BASE::PANEL_PREV_3D_BASE( wxWindow* parent, wxWindowID id, const w
 	#else
 	yrot->SetMaxLength( 9 );
 	#endif
-	fgSizerRotate->Add( yrot, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 );
+	fgSizerRotate->Add( yrot, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT|wxTOP, 5 );
 	
 	m_spinYrot = new wxSpinButton( vbRotate->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS|wxSP_VERTICAL );
 	fgSizerRotate->Add( m_spinYrot, 0, wxALIGN_CENTER_VERTICAL, 5 );
@@ -121,7 +121,7 @@ PANEL_PREV_3D_BASE::PANEL_PREV_3D_BASE( wxWindow* parent, wxWindowID id, const w
 	fgSizerRotate->Add( zrot, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT, 5 );
 	
 	m_spinZrot = new wxSpinButton( vbRotate->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS|wxSP_VERTICAL );
-	fgSizerRotate->Add( m_spinZrot, 0, wxALIGN_CENTER_VERTICAL, 5 );
+	fgSizerRotate->Add( m_spinZrot, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM, 5 );
 	
 	
 	vbRotate->Add( fgSizerRotate, 1, wxEXPAND, 5 );
@@ -129,7 +129,6 @@ PANEL_PREV_3D_BASE::PANEL_PREV_3D_BASE( wxWindow* parent, wxWindowID id, const w
 	
 	bSizerLeft->Add( vbRotate, 0, wxEXPAND, 5 );
 	
-	wxStaticBoxSizer* vbOffset;
 	vbOffset = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Offset") ), wxVERTICAL );
 	
 	wxFlexGridSizer* fgSizerOffset;
@@ -152,7 +151,7 @@ PANEL_PREV_3D_BASE::PANEL_PREV_3D_BASE( wxWindow* parent, wxWindowID id, const w
 	fgSizerOffset->Add( m_staticText22, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 );
 	
 	yoff = new wxTextCtrl( vbOffset->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
-	fgSizerOffset->Add( yoff, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 );
+	fgSizerOffset->Add( yoff, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT|wxTOP, 5 );
 	
 	m_spinYoffset = new wxSpinButton( vbOffset->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS|wxSP_VERTICAL );
 	fgSizerOffset->Add( m_spinYoffset, 0, wxALIGN_CENTER_VERTICAL, 5 );
@@ -165,7 +164,7 @@ PANEL_PREV_3D_BASE::PANEL_PREV_3D_BASE( wxWindow* parent, wxWindowID id, const w
 	fgSizerOffset->Add( zoff, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT, 5 );
 	
 	m_spinZoffset = new wxSpinButton( vbOffset->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS|wxSP_VERTICAL );
-	fgSizerOffset->Add( m_spinZoffset, 0, wxALIGN_CENTER_VERTICAL, 5 );
+	fgSizerOffset->Add( m_spinZoffset, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM, 5 );
 	
 	
 	vbOffset->Add( fgSizerOffset, 1, wxEXPAND, 5 );
diff --git a/3d-viewer/3d_cache/dialogs/panel_prev_3d_base.fbp b/3d-viewer/3d_cache/dialogs/panel_prev_3d_base.fbp
index 772d9b8..045f1cc 100644
--- a/3d-viewer/3d_cache/dialogs/panel_prev_3d_base.fbp
+++ b/3d-viewer/3d_cache/dialogs/panel_prev_3d_base.fbp
@@ -464,7 +464,7 @@
                                         </object>
                                         <object class="sizeritem" expanded="1">
                                             <property name="border">5</property>
-                                            <property name="flag">wxALIGN_CENTER_VERTICAL|wxLEFT</property>
+                                            <property name="flag">wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT|wxTOP</property>
                                             <property name="proportion">0</property>
                                             <object class="wxTextCtrl" expanded="1">
                                                 <property name="BottomDockable">1</property>
@@ -813,7 +813,7 @@
                                         </object>
                                         <object class="sizeritem" expanded="1">
                                             <property name="border">5</property>
-                                            <property name="flag">wxALIGN_CENTER_VERTICAL</property>
+                                            <property name="flag">wxALIGN_CENTER_VERTICAL|wxBOTTOM</property>
                                             <property name="proportion">0</property>
                                             <object class="wxSpinButton" expanded="1">
                                                 <property name="BottomDockable">1</property>
@@ -1271,7 +1271,7 @@
                                         </object>
                                         <object class="sizeritem" expanded="1">
                                             <property name="border">5</property>
-                                            <property name="flag">wxALIGN_CENTER_VERTICAL|wxLEFT</property>
+                                            <property name="flag">wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT|wxTOP</property>
                                             <property name="proportion">0</property>
                                             <object class="wxTextCtrl" expanded="1">
                                                 <property name="BottomDockable">1</property>
@@ -1620,7 +1620,7 @@
                                         </object>
                                         <object class="sizeritem" expanded="1">
                                             <property name="border">5</property>
-                                            <property name="flag">wxALIGN_CENTER_VERTICAL</property>
+                                            <property name="flag">wxALIGN_CENTER_VERTICAL|wxBOTTOM</property>
                                             <property name="proportion">0</property>
                                             <object class="wxSpinButton" expanded="1">
                                                 <property name="BottomDockable">1</property>
@@ -1717,7 +1717,7 @@
                                 <property name="name">vbOffset</property>
                                 <property name="orient">wxVERTICAL</property>
                                 <property name="parent">1</property>
-                                <property name="permission">none</property>
+                                <property name="permission">protected</property>
                                 <event name="OnUpdateUI"></event>
                                 <object class="sizeritem" expanded="1">
                                     <property name="border">5</property>
@@ -2078,7 +2078,7 @@
                                         </object>
                                         <object class="sizeritem" expanded="1">
                                             <property name="border">5</property>
-                                            <property name="flag">wxALIGN_CENTER_VERTICAL|wxLEFT</property>
+                                            <property name="flag">wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT|wxTOP</property>
                                             <property name="proportion">0</property>
                                             <object class="wxTextCtrl" expanded="1">
                                                 <property name="BottomDockable">1</property>
@@ -2120,7 +2120,7 @@
                                                 <property name="pane_border">1</property>
                                                 <property name="pane_position"></property>
                                                 <property name="pane_size"></property>
-                                                <property name="permission">protected</property>
+                                                <property name="permission">public</property>
                                                 <property name="pin_button">1</property>
                                                 <property name="pos"></property>
                                                 <property name="resize">Resizable</property>
@@ -2427,7 +2427,7 @@
                                         </object>
                                         <object class="sizeritem" expanded="1">
                                             <property name="border">5</property>
-                                            <property name="flag">wxALIGN_CENTER_VERTICAL</property>
+                                            <property name="flag">wxALIGN_CENTER_VERTICAL|wxBOTTOM</property>
                                             <property name="proportion">0</property>
                                             <object class="wxSpinButton" expanded="1">
                                                 <property name="BottomDockable">1</property>
diff --git a/3d-viewer/3d_cache/dialogs/panel_prev_3d_base.h b/3d-viewer/3d_cache/dialogs/panel_prev_3d_base.h
index d1a497e..b3232ec 100644
--- a/3d-viewer/3d_cache/dialogs/panel_prev_3d_base.h
+++ b/3d-viewer/3d_cache/dialogs/panel_prev_3d_base.h
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////
-// C++ code generated with wxFormBuilder (version Aug  4 2017)
+// C++ code generated with wxFormBuilder (version Mar 22 2017)
 // http://www.wxformbuilder.org/
 //
 // PLEASE DO "NOT" EDIT THIS FILE!
@@ -57,11 +57,11 @@ class PANEL_PREV_3D_BASE : public wxPanel
 		wxStaticText* m_staticText31;
 		wxTextCtrl* zrot;
 		wxSpinButton* m_spinZrot;
+		wxStaticBoxSizer* vbOffset;
 		wxStaticText* m_staticText12;
 		wxTextCtrl* xoff;
 		wxSpinButton* m_spinXoffset;
 		wxStaticText* m_staticText22;
-		wxTextCtrl* yoff;
 		wxSpinButton* m_spinYoffset;
 		wxStaticText* m_staticText32;
 		wxTextCtrl* zoff;
@@ -99,6 +99,7 @@ class PANEL_PREV_3D_BASE : public wxPanel
 		
 	
 	public:
+		wxTextCtrl* yoff;
 		
 		PANEL_PREV_3D_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 503,371 ), long style = wxTAB_TRAVERSAL ); 
 		~PANEL_PREV_3D_BASE();
diff --git a/3d-viewer/3d_cache/dialogs/panel_prev_model.cpp b/3d-viewer/3d_cache/dialogs/panel_prev_model.cpp
index 3cc07b5..4656e1e 100644
--- a/3d-viewer/3d_cache/dialogs/panel_prev_model.cpp
+++ b/3d-viewer/3d_cache/dialogs/panel_prev_model.cpp
@@ -125,7 +125,29 @@ void PANEL_PREV_3D::initPanel()
     };
 
     for( int ii = 0; ii < 9; ii++ )
+    {
         spinButtonList[ii]->SetRange( INT_MIN, INT_MAX );
+    }
+
+    wxString units;
+
+    switch( g_UserUnit )
+    {
+    case INCHES:
+        units = _( "inches" );
+        break;
+    case MILLIMETRES:
+        units = _( "mm" );
+        break;
+    default:
+        break;
+    }
+
+    if( !units.IsEmpty() )
+    {
+        units = wxString::Format( _( "Offset (%s)" ), units );
+        vbOffset->GetStaticBox()->SetLabel( units );
+    }
 }
 
 
@@ -214,26 +236,26 @@ void PANEL_PREV_3D::SetModelDataIdx( int idx, bool aReloadPreviewModule )
             yrot->SetValue( wxString::Format( "%.2f", aModel->m_Rotation.y ) );
             zrot->SetValue( wxString::Format( "%.2f", aModel->m_Rotation.z ) );
 
+            // Convert from internal units (mm) to user units
+
+            double scaler = 1;
+
             switch( g_UserUnit )
             {
             case MILLIMETRES:
-                xoff->SetValue( wxString::Format( "%.4f", aModel->m_Offset.x * 25.4 ) );
-                yoff->SetValue( wxString::Format( "%.4f", aModel->m_Offset.y * 25.4 ) );
-                zoff->SetValue( wxString::Format( "%.4f", aModel->m_Offset.z * 25.4 ) );
+                scaler = 1.0f;
                 break;
-
             case INCHES:
-                xoff->SetValue( wxString::Format( "%.4f", aModel->m_Offset.x ) );
-                yoff->SetValue( wxString::Format( "%.4f", aModel->m_Offset.y ) );
-                zoff->SetValue( wxString::Format( "%.4f", aModel->m_Offset.z ) );
+                scaler = 25.4f;
                 break;
-
-            case DEGREES:
-            case UNSCALED_UNITS:
             default:
-                wxASSERT(0);
+                wxASSERT( 0 );
             }
 
+            xoff->SetValue( wxString::Format( "%.4f", aModel->m_Offset.x / scaler ) );
+            yoff->SetValue( wxString::Format( "%.4f", aModel->m_Offset.y / scaler ) );
+            zoff->SetValue( wxString::Format( "%.4f", aModel->m_Offset.z / scaler ) );
+
             UpdateModelName( aModel->m_Filename );
 
             if( aReloadPreviewModule && m_previewPane )
@@ -249,7 +271,9 @@ void PANEL_PREV_3D::SetModelDataIdx( int idx, bool aReloadPreviewModule )
     }
 
     if( m_previewPane )
+    {
         m_previewPane->SetFocus();
+    }
 
     return;
 }
@@ -565,25 +589,26 @@ void PANEL_PREV_3D::getOrientationVars( SGPOINT& aScale, SGPOINT& aRotation, SGP
     yoff->GetValue().ToDouble( &aOffset.y );
     zoff->GetValue().ToDouble( &aOffset.z );
 
+    // Convert from user units to internal units (mm)
+
+    double scaler = 1.0f;
+
     switch( g_UserUnit )
     {
     case MILLIMETRES:
-        // Convert to Inches. Offset is stored in inches.
-        aOffset.x = aOffset.x / 25.4;
-        aOffset.y = aOffset.y / 25.4;
-        aOffset.z = aOffset.z / 25.4;
+        scaler = 1.0f;
         break;
-
     case INCHES:
-        // It is already in Inches
+        scaler = 25.4f;
         break;
-
-    case DEGREES:
-    case UNSCALED_UNITS:
     default:
-        wxASSERT(0);
+        wxASSERT( 0 );
     }
 
+    aOffset.x *= scaler;
+    aOffset.y *= scaler;
+    aOffset.z *= scaler;
+
     return;
 }
 
diff --git a/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_ogl_legacy.cpp b/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_ogl_legacy.cpp
index 19b4616..72f36a6 100644
--- a/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_ogl_legacy.cpp
+++ b/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_ogl_legacy.cpp
@@ -1046,9 +1046,7 @@ void C3D_RENDER_OGL_LEGACY::render_3D_module( const MODULE* module,
                         {
                             glPushMatrix();
 
-                            glTranslatef( sM->m_Offset.x * 25.4f,
-                                          sM->m_Offset.y * 25.4f,
-                                          sM->m_Offset.z * 25.4f );
+                            glTranslatef( sM->m_Offset.x, sM->m_Offset.y, sM->m_Offset.z );
 
                             glRotatef( -sM->m_Rotation.z, 0.0f, 0.0f, 1.0f );
                             glRotatef( -sM->m_Rotation.y, 0.0f, 1.0f, 0.0f );
diff --git a/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_createscene.cpp b/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_createscene.cpp
index 592d141..85e81cb 100644
--- a/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_createscene.cpp
+++ b/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_createscene.cpp
@@ -1263,9 +1263,9 @@ void C3D_RENDER_RAYTRACING::load_3D_models()
                     glm::mat4 modelMatrix = moduleMatrix;
 
                     modelMatrix = glm::translate( modelMatrix,
-                                                  SFVEC3F( sM->m_Offset.x * 25.4f,
-                                                           sM->m_Offset.y * 25.4f,
-                                                           sM->m_Offset.z * 25.4f ) );
+                                                  SFVEC3F( sM->m_Offset.x,
+                                                           sM->m_Offset.y,
+                                                           sM->m_Offset.z ) );
 
                     modelMatrix = glm::rotate( modelMatrix,
                                                (float)-( sM->m_Rotation.z / 180.0f ) *
diff --git a/pcbnew/class_module.h b/pcbnew/class_module.h
index c92fbaf..daeb814 100644
--- a/pcbnew/class_module.h
+++ b/pcbnew/class_module.h
@@ -82,6 +82,14 @@ enum MODULE_ATTR_T
 class MODULE_3D_SETTINGS
 {
     public:
+        MODULE_3D_SETTINGS() :
+            // Initialize with sensible values
+            m_Scale { 1, 1, 1 },
+            m_Rotation { 0, 0, 0 },
+            m_Offset { 0, 0, 0 }
+        {
+        }
+
         struct VECTOR3D
         {
             double x, y, z;
diff --git a/pcbnew/exporters/export_vrml.cpp b/pcbnew/exporters/export_vrml.cpp
index a88fca3..cb4f607 100644
--- a/pcbnew/exporters/export_vrml.cpp
+++ b/pcbnew/exporters/export_vrml.cpp
@@ -1349,11 +1349,13 @@ static void export_vrml_module( MODEL_VRML& aModel, BOARD* aPcb,
         compose_quat( q1, q2, q1 );
         from_quat( q1, rot );
 
+        double offsetFactor = 1000.0f * IU_PER_MILS / 25.4f;
+
         // adjust 3D shape local offset position
-        // they are given in inch, so they are converted in board IU.
-        double offsetx = sM->m_Offset.x * IU_PER_MILS * 1000.0;
-        double offsety = sM->m_Offset.y * IU_PER_MILS * 1000.0;
-        double offsetz = sM->m_Offset.z * IU_PER_MILS * 1000.0;
+        // they are given in mm, so they are converted in board IU.
+        double offsetx = sM->m_Offset.x * offsetFactor;
+        double offsety = sM->m_Offset.y * offsetFactor;
+        double offsetz = sM->m_Offset.z * offsetFactor;
 
         if( isFlipped )
             offsetz = -offsetz;
diff --git a/utils/kicad2step/pcb/kicadmodel.cpp b/utils/kicad2step/pcb/kicadmodel.cpp
index 6c4c033..6f680e0 100644
--- a/utils/kicad2step/pcb/kicadmodel.cpp
+++ b/utils/kicad2step/pcb/kicadmodel.cpp
@@ -28,7 +28,10 @@
 #include "kicadmodel.h"
 
 
-KICADMODEL::KICADMODEL() : m_scale( 1.0, 1.0, 1.0 )
+KICADMODEL::KICADMODEL() :
+    m_scale( 1.0, 1.0, 1.0 ),
+    m_offset( 0.0, 0.0, 0.0 ),
+    m_rotation( 0.0, 0.0, 0.0 )
 {
     return;
 }
diff --git a/utils/kicad2step/pcb/oce_utils.cpp b/utils/kicad2step/pcb/oce_utils.cpp
index dcf9825..dccd5c6 100644
--- a/utils/kicad2step/pcb/oce_utils.cpp
+++ b/utils/kicad2step/pcb/oce_utils.cpp
@@ -996,10 +996,9 @@ bool PCBMODEL::getModelLocation( bool aBottom, DOUBLET aPosition, double aRotati
     gp_Trsf lPos;
     lPos.SetTranslation( gp_Vec( aPosition.x, -aPosition.y, 0.0 ) );
 
-    // offset (inches)
-    aOffset.x *= 25.4;
-    aOffset.y *= 25.4;
-    aOffset.z *= 25.4 + BOARD_OFFSET;
+    // Offset board thickness
+    aOffset.z += BOARD_OFFSET;
+
     gp_Trsf lRot;
 
     if( aBottom )
-- 
2.7.4


Follow ups

References