Commit cd85ee62 authored by jean-pierre charras's avatar jean-pierre charras

Cosmetic enhancement: change plot icon in menus.

3dviewer: back to double (from float) in class S3D_MASTER for 3 members (m_MatScale, m_MatRotation, m_MatPosition) which are used in dialogs and r/w file functions, which expect double.
Using float create minor but unwanted issues in  r/w file functions.
S3D_MATERIAL: enable all color options: if a 3d shape has bad color parameters, the shape must be modified, not the 3d rendering.
The rendering now matches what we see in other vrml viewer like FreeCAD.
Some minor coding style fixes.
parent 468e9e4a
......@@ -151,7 +151,7 @@ void TransfertToGLlist( std::vector< S3D_VERTEX >& aVertices, double aBiuTo3DUni
glEnd();
}
VERTEX_VALUE_CTRL::VERTEX_VALUE_CTRL( wxWindow* aParent, wxBoxSizer* aBoxSizer )
S3DPOINT_VALUE_CTRL::S3DPOINT_VALUE_CTRL( wxWindow* aParent, wxBoxSizer* aBoxSizer )
{
wxString text;
......@@ -187,14 +187,15 @@ VERTEX_VALUE_CTRL::VERTEX_VALUE_CTRL( wxWindow* aParent, wxBoxSizer* aBoxSizer )
}
VERTEX_VALUE_CTRL::~VERTEX_VALUE_CTRL()
S3DPOINT_VALUE_CTRL::~S3DPOINT_VALUE_CTRL()
{
// Nothing to delete: all items are managed by the parent window.
}
S3D_VERTEX VERTEX_VALUE_CTRL::GetValue()
S3DPOINT S3DPOINT_VALUE_CTRL::GetValue()
{
S3D_VERTEX value;
S3DPOINT value;
double dtmp;
m_XValueCtrl->GetValue().ToDouble( &dtmp );
......@@ -207,7 +208,7 @@ S3D_VERTEX VERTEX_VALUE_CTRL::GetValue()
}
void VERTEX_VALUE_CTRL::SetValue( S3D_VERTEX vertex )
void S3DPOINT_VALUE_CTRL::SetValue( S3DPOINT vertex )
{
wxString text;
......@@ -225,7 +226,7 @@ void VERTEX_VALUE_CTRL::SetValue( S3D_VERTEX vertex )
}
void VERTEX_VALUE_CTRL::Enable( bool onoff )
void S3DPOINT_VALUE_CTRL::Enable( bool onoff )
{
m_XValueCtrl->Enable( onoff );
m_YValueCtrl->Enable( onoff );
......
......@@ -78,11 +78,11 @@ S3D_MASTER::S3D_MASTER( EDA_ITEM* aParent ) :
m_ShapeType = FILE3D_NONE;
m_use_modelfile_diffuseColor = true;
m_use_modelfile_emissiveColor = false;
m_use_modelfile_specularColor = false;
m_use_modelfile_ambientIntensity = false;
m_use_modelfile_emissiveColor = true;
m_use_modelfile_specularColor = true;
m_use_modelfile_ambientIntensity = true;
m_use_modelfile_transparency = true;
m_use_modelfile_shininess = false;
m_use_modelfile_shininess = true;
}
......
......@@ -35,7 +35,7 @@
class S3D_MASTER;
class S3D_MATERIAL : public EDA_ITEM /* openGL "material" data*/
class S3D_MATERIAL : public EDA_ITEM // openGL "material" data
{
public:
wxString m_Name;
......
......@@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2014 Mario Luzeiro <mrluzeiro@gmail.com>
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2004 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
*
......@@ -36,8 +36,9 @@
#include <3d_material.h>
#include <gal/opengl/glm/glm.hpp>
/* 3D modeling units -> PCB units conversion scale:
* 1 "3D model unit" wings3d = 1 unit = 2.54 mm = 0.1 inch = 100 mils
/**
* @note For historical reasons the 3D modeling unit is 0.1 inch
* 1 3Dunit = 2.54 mm = 0.1 inch = 100 mils
*/
#define UNITS3D_TO_UNITSPCB (IU_PER_MILS * 100)
......@@ -45,19 +46,42 @@
class S3D_MASTER;
class STRUCT_3D_SHAPE;
/* S3D_VERTEX manages a 3D coordinate (3 float numbers: x,y,z coordinates)*/
// S3D_VERTEX manages a opengl 3D coordinate (3 float numbers: x,y,z coordinates)
// float are widely used in opengl functions.
// they are used here in coordinates which are also used in opengl functions.
#define S3D_VERTEX glm::vec3
// S3DPOINT manages a set of 3 double values (x,y,z )
// It is used for values which are not directly used in opengl functions.
// It is used in dialogs, or when reading/writing files for instance
class S3DPOINT
{
public:
double x, y, z;
public:
S3DPOINT()
{
x = y = z = 0.0;
}
S3DPOINT( double px, double py, double pz)
{
x = px;
y = py;
z = pz;
}
};
/* Master structure for a 3D item description */
// Master structure for a 3D footprint shape description
class S3D_MASTER : public EDA_ITEM
{
public:
S3D_VERTEX m_MatScale;
S3D_VERTEX m_MatRotation;
S3D_VERTEX m_MatPosition;
STRUCT_3D_SHAPE* m_3D_Drawings;
S3D_MATERIAL* m_Materials;
S3DPOINT m_MatScale; ///< a scaling factor for the entire 3D footprint shape
S3DPOINT m_MatRotation; ///< a grotation for the entire 3D footprint shape
S3DPOINT m_MatPosition; ///< an offset for the entire 3D footprint shape
STRUCT_3D_SHAPE* m_3D_Drawings; ///< the list of basic shapes
S3D_MATERIAL* m_Materials; ///< the list of materiels used by the shapes
enum FILE3D_TYPE
{
......@@ -76,7 +100,7 @@ public:
bool m_use_modelfile_shininess;
private:
wxString m_Shape3DName; /* 3D shape name in 3D library */
wxString m_Shape3DName; // the 3D shape filename in 3D library
FILE3D_TYPE m_ShapeType;
double m_lastTransparency; // last transparency value from
// last material in use
......@@ -185,26 +209,26 @@ public:
/**
* Class VERTEX_VALUE_CTRL
* displays a vertex for editing. A vertex is a triplet of values
* Class S3DPOINT_VALUE_CTRL
* displays a S3DPOINT for editing (in dialogs). A S3DPOINT is a triplet of values
* Values can be scale, rotation, offset...
*/
class VERTEX_VALUE_CTRL
class S3DPOINT_VALUE_CTRL
{
private:
wxTextCtrl* m_XValueCtrl, * m_YValueCtrl, * m_ZValueCtrl;
public:
VERTEX_VALUE_CTRL( wxWindow* parent, wxBoxSizer* BoxSizer );
S3DPOINT_VALUE_CTRL( wxWindow* parent, wxBoxSizer* BoxSizer );
~VERTEX_VALUE_CTRL();
~S3DPOINT_VALUE_CTRL();
/**
* Function GetValue
* @return the vertex in internal units.
* @return the 3D point in internal units.
*/
S3D_VERTEX GetValue();
void SetValue( S3D_VERTEX vertex );
S3DPOINT GetValue();
void SetValue( S3DPOINT a3Dpoint );
void Enable( bool enbl );
void SetToolTip( const wxString& text );
};
......
......@@ -103,9 +103,7 @@ void VRML1_MODEL_PARSER::Load( const wxString aFilename )
if( strcmp( text, "Separator" ) == 0 )
{
m_model = new S3D_MESH();
childs.push_back( m_model );
read_separator();
}
}
......@@ -137,13 +135,16 @@ int VRML1_MODEL_PARSER::read_separator()
if( strcmp( text, "Material" ) == 0 )
{
readMaterial( );
} else if( strcmp( text, "Coordinate3" ) == 0 )
}
else if( strcmp( text, "Coordinate3" ) == 0 )
{
readCoordinate3();
} else if( strcmp( text, "IndexedFaceSet" ) == 0 )
}
else if( strcmp( text, "IndexedFaceSet" ) == 0 )
{
readIndexedFaceSet();
} else if( strcmp( text, "Separator" ) == 0 )
}
else if( strcmp( text, "Separator" ) == 0 )
{
S3D_MESH *parent = m_model;
......@@ -157,11 +158,13 @@ int VRML1_MODEL_PARSER::read_separator()
read_separator();
m_model = parent;
}else if ( ( *text != '}' ) )
}
else if ( ( *text != '}' ) )
{
//DBG( printf( "read_NotImplemented %s\n", text ) );
read_NotImplemented( m_file, '}');
} else
}
else
{
break;
}
......@@ -201,19 +204,24 @@ int VRML1_MODEL_PARSER::readMaterial()
if( strcmp( text, "ambientColor" ) == 0 )
{
readMaterial_ambientColor();
} else if( strcmp( text, "diffuseColor" ) == 0 )
}
else if( strcmp( text, "diffuseColor" ) == 0 )
{
readMaterial_diffuseColor( );
} else if( strcmp( text, "emissiveColor" ) == 0 )
}
else if( strcmp( text, "emissiveColor" ) == 0 )
{
readMaterial_emissiveColor( );
}else if( strcmp( text, "specularColor" ) == 0 )
}
else if( strcmp( text, "specularColor" ) == 0 )
{
readMaterial_specularColor( );
}else if( strcmp( text, "shininess" ) == 0 )
}
else if( strcmp( text, "shininess" ) == 0 )
{
readMaterial_shininess( );
}else if( strcmp( text, "transparency" ) == 0 )
}
else if( strcmp( text, "transparency" ) == 0 )
{
readMaterial_transparency( );
}
......@@ -272,7 +280,8 @@ int VRML1_MODEL_PARSER::readIndexedFaceSet( )
if( strcmp( text, "coordIndex" ) == 0 )
{
readIndexedFaceSet_coordIndex( );
} else if( strcmp( text, "materialIndex" ) == 0 )
}
else if( strcmp( text, "materialIndex" ) == 0 )
{
readIndexedFaceSet_materialIndex( );
}
......@@ -334,6 +343,7 @@ int VRML1_MODEL_PARSER::readMaterial_shininess( )
m_model->m_Materials->m_Shininess.clear();
float shininess_value;
while( fscanf( m_file, "%f,", &shininess_value ) )
{
// VRML value is normalized and openGL expects a value 0 - 128
......@@ -359,6 +369,7 @@ int VRML1_MODEL_PARSER::readMaterial_transparency()
m_model->m_Materials->m_Transparency.clear();
float tmp;
while( fscanf (m_file, "%f,", &tmp) )
{
m_model->m_Materials->m_Transparency.push_back( tmp );
......
......@@ -73,9 +73,12 @@ void VRML2_MODEL_PARSER::Load( const wxString aFilename )
float vrmlunits_to_3Dunits = g_Parm_3D_Visu.m_BiuTo3Dunits * UNITS3D_TO_UNITSPCB;
glScalef( vrmlunits_to_3Dunits, vrmlunits_to_3Dunits, vrmlunits_to_3Dunits );
glm::vec3 matScale( GetMaster()->m_MatScale.x, GetMaster()->m_MatScale.y, GetMaster()->m_MatScale.z );
glm::vec3 matRot( GetMaster()->m_MatRotation.x, GetMaster()->m_MatRotation.y, GetMaster()->m_MatRotation.z );
glm::vec3 matPos( GetMaster()->m_MatPosition.x, GetMaster()->m_MatPosition.y, GetMaster()->m_MatPosition.z );
glm::vec3 matScale( GetMaster()->m_MatScale.x, GetMaster()->m_MatScale.y,
GetMaster()->m_MatScale.z );
glm::vec3 matRot( GetMaster()->m_MatRotation.x, GetMaster()->m_MatRotation.y,
GetMaster()->m_MatRotation.z );
glm::vec3 matPos( GetMaster()->m_MatPosition.x, GetMaster()->m_MatPosition.y,
GetMaster()->m_MatPosition.z );
#define SCALE_3D_CONV ((IU_PER_MILS * 1000.0f) / UNITS3D_TO_UNITSPCB)
......@@ -104,7 +107,6 @@ void VRML2_MODEL_PARSER::Load( const wxString aFilename )
if( strcmp( text, "Transform" ) == 0 )
{
m_model = new S3D_MESH();
childs.push_back( m_model );
read_Transform();
......@@ -113,7 +115,6 @@ void VRML2_MODEL_PARSER::Load( const wxString aFilename )
else if( strcmp( text, "DEF" ) == 0 )
{
m_model = new S3D_MESH();
childs.push_back( m_model );
read_DEF();
......@@ -294,15 +295,11 @@ int VRML2_MODEL_PARSER::read_DEF()
else if( strcmp( text, "Shape" ) == 0 )
{
S3D_MESH *parent = m_model;
S3D_MESH *new_mesh_model = new S3D_MESH();
m_model->childs.push_back( new_mesh_model );
m_model = new_mesh_model;
read_Shape();
m_model = parent;
}
}
......@@ -401,9 +398,7 @@ int VRML2_MODEL_PARSER::read_material()
{
wxString mat_name;
material = new S3D_MATERIAL( GetMaster(), mat_name );
GetMaster()->Insert( material );
m_model->m_Materials = material;
if( strcmp( text, "Material" ) == 0 )
......@@ -423,9 +418,7 @@ int VRML2_MODEL_PARSER::read_material()
mat_name = FROM_UTF8( text );
material = new S3D_MATERIAL( GetMaster(), mat_name );
GetMaster()->Insert( material );
m_model->m_Materials = material;
if( GetNextTag( m_file, text ) )
......@@ -506,6 +499,7 @@ int VRML2_MODEL_PARSER::read_Material()
//DBG( printf( " specularColor") );
parseVertex ( m_file, vertex);
//DBG( printf( "\n") );
if( GetMaster()->m_use_modelfile_specularColor == true )
{
m_model->m_Materials->m_SpecularColor.push_back( vertex );
......@@ -516,6 +510,7 @@ int VRML2_MODEL_PARSER::read_Material()
float ambientIntensity;
parseFloat( m_file, &ambientIntensity );
//DBG( printf( " ambientIntensity %f\n", ambientIntensity) );
if( GetMaster()->m_use_modelfile_ambientIntensity == true )
{
m_model->m_Materials->m_AmbientColor.push_back( glm::vec3( ambientIntensity, ambientIntensity, ambientIntensity ) );
......@@ -526,6 +521,7 @@ int VRML2_MODEL_PARSER::read_Material()
float transparency;
parseFloat( m_file, &transparency );
//DBG( printf( " transparency %f\n", transparency) );
if( GetMaster()->m_use_modelfile_transparency == true )
{
m_model->m_Materials->m_Transparency.push_back( transparency );
......@@ -535,6 +531,7 @@ int VRML2_MODEL_PARSER::read_Material()
{
float shininess;
parseFloat( m_file, &shininess );
//DBG( printf( " shininess %f\n", shininess) );
// VRML value is normalized and openGL expects a value 0 - 128
if( GetMaster()->m_use_modelfile_shininess == true )
......@@ -590,7 +587,8 @@ int VRML2_MODEL_PARSER::read_IndexedFaceSet()
{
//DBG( printf( " colorPerVertex = true\n") );
colorPerVertex = true;
} else
}
else
{
colorPerVertex = false;
}
......
This diff is collapsed.
This diff is collapsed.
......@@ -319,9 +319,9 @@ void DIALOG_MODULE_BOARD_EDITOR::InitModeditProperties()
m_CostRot180Ctrl->SetValue( m_CurrentModule->GetPlacementCost180() );
// Initialize 3D parameters
m_3D_Scale = new VERTEX_VALUE_CTRL( m_Panel3D, m_bSizerShapeScale );
m_3D_Offset = new VERTEX_VALUE_CTRL( m_Panel3D, m_bSizerShapeOffset );
m_3D_Rotation = new VERTEX_VALUE_CTRL( m_Panel3D, m_bSizerShapeRotation );
m_3D_Scale = new S3DPOINT_VALUE_CTRL( m_Panel3D, m_bSizerShapeScale );
m_3D_Offset = new S3DPOINT_VALUE_CTRL( m_Panel3D, m_bSizerShapeOffset );
m_3D_Rotation = new S3DPOINT_VALUE_CTRL( m_Panel3D, m_bSizerShapeRotation );
// if m_3D_ShapeNameListBox is not empty, preselect first 3D shape
if( m_3D_ShapeNameListBox->GetCount() > 0 )
......@@ -352,8 +352,7 @@ void DIALOG_MODULE_BOARD_EDITOR::Transfert3DValuesToDisplay(
}
else
{
S3D_VERTEX dummy_vertex;
dummy_vertex.x = dummy_vertex.y = dummy_vertex.z = 1.0;
S3DPOINT dummy_vertex( 1.0, 1.0, 1.0 );
m_3D_Scale->SetValue( dummy_vertex );
}
}
......
......@@ -20,9 +20,9 @@ private:
TEXTE_MODULE* m_ValueCopy;
std::vector <S3D_MASTER*> m_Shapes3D_list;
int m_LastSelected3DShapeIndex;
VERTEX_VALUE_CTRL * m_3D_Scale;
VERTEX_VALUE_CTRL * m_3D_Offset;
VERTEX_VALUE_CTRL * m_3D_Rotation;
S3DPOINT_VALUE_CTRL * m_3D_Scale;
S3DPOINT_VALUE_CTRL * m_3D_Offset;
S3DPOINT_VALUE_CTRL * m_3D_Rotation;
public:
......
......@@ -161,9 +161,9 @@ void DIALOG_MODULE_MODULE_EDITOR::initModeditProperties()
m_CostRot180Ctrl->SetValue( m_currentModule->GetPlacementCost180() );
// Initialize 3D parameters
m_3D_Scale = new VERTEX_VALUE_CTRL( m_Panel3D, m_bSizerShapeScale );
m_3D_Offset = new VERTEX_VALUE_CTRL( m_Panel3D, m_bSizerShapeOffset );
m_3D_Rotation = new VERTEX_VALUE_CTRL( m_Panel3D, m_bSizerShapeRotation );
m_3D_Scale = new S3DPOINT_VALUE_CTRL( m_Panel3D, m_bSizerShapeScale );
m_3D_Offset = new S3DPOINT_VALUE_CTRL( m_Panel3D, m_bSizerShapeOffset );
m_3D_Rotation = new S3DPOINT_VALUE_CTRL( m_Panel3D, m_bSizerShapeRotation );
// Initialize dialog relative to masks clearances
m_NetClearanceUnits->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) );
......@@ -222,8 +222,7 @@ void DIALOG_MODULE_MODULE_EDITOR::Transfert3DValuesToDisplay( S3D_MASTER * aStru
}
else
{
S3D_VERTEX dummy_vertex;
dummy_vertex.x = dummy_vertex.y = dummy_vertex.z = 1.0;
S3DPOINT dummy_vertex( 1.0, 1.0, 1.0 );
m_3D_Scale->SetValue( dummy_vertex );
}
}
......
......@@ -23,9 +23,9 @@ private:
TEXTE_MODULE* m_valueCopy;
std::vector <S3D_MASTER*> m_shapes3D_list;
int m_lastSelected3DShapeIndex;
VERTEX_VALUE_CTRL * m_3D_Scale;
VERTEX_VALUE_CTRL * m_3D_Offset;
VERTEX_VALUE_CTRL * m_3D_Rotation;
S3DPOINT_VALUE_CTRL * m_3D_Scale;
S3DPOINT_VALUE_CTRL * m_3D_Offset;
S3DPOINT_VALUE_CTRL * m_3D_Rotation;
public:
......
......@@ -1936,7 +1936,7 @@ void LEGACY_PLUGIN::load3D( MODULE* aModule )
else if( TESTLINE( "Sc" ) ) // Scale
{
sscanf( line + SZ( "Sc" ), "%f %f %f\n",
sscanf( line + SZ( "Sc" ), "%lf %lf %lf\n",
&t3D->m_MatScale.x,
&t3D->m_MatScale.y,
&t3D->m_MatScale.z );
......@@ -1944,7 +1944,7 @@ void LEGACY_PLUGIN::load3D( MODULE* aModule )
else if( TESTLINE( "Of" ) ) // Offset
{
sscanf( line + SZ( "Of" ), "%f %f %f\n",
sscanf( line + SZ( "Of" ), "%lf %lf %lf\n",
&t3D->m_MatPosition.x,
&t3D->m_MatPosition.y,
&t3D->m_MatPosition.z );
......@@ -1952,7 +1952,7 @@ void LEGACY_PLUGIN::load3D( MODULE* aModule )
else if( TESTLINE( "Ro" ) ) // Rotation
{
sscanf( line + SZ( "Ro" ), "%f %f %f\n",
sscanf( line + SZ( "Ro" ), "%lf %lf %lf\n",
&t3D->m_MatRotation.x,
&t3D->m_MatRotation.y,
&t3D->m_MatRotation.z );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment