Commit cbb0e2ad authored by unknown's avatar unknown Committed by jean-pierre charras

Rework on 3D viewer. Fix some issues, some optimizations and better rendering.

parent 9004ed88
......@@ -43,7 +43,8 @@
#endif
#include <3d_struct.h>
#include <class_module.h>
class BOARD_DESIGN_SETTINGS;
class EDA_3D_FRAME;
class CPOLYGONS_LIST;
......@@ -274,6 +275,32 @@ private:
*/
void Draw3DPadHole( const D_PAD * aPad );
/**
* function Render3DComponentShape
* insert mesh in gl list
* @param module
* @param aIsRenderingJustNonTransparentObjects = true to load non transparent objects
* @param aIsRenderingJustTransparentObjects = true to load non transparent objects
* @param aSideToLoad = false will load not fliped, true will load fliped objects
* in openGL, transparent objects should be drawn *after* non transparent objects
*/
void Render3DComponentShape( MODULE* module,
bool aIsRenderingJustNonTransparentObjects,
bool aIsRenderingJustTransparentObjects,
bool aSideToLoad );
/**
* function Read3DComponentShape
* read the 3D component shape(s) of the footprint (physical shape).
* @param module
* @param model_parsers_list = list of each new model loaded
* @param model_filename_list = list of each new filename model loaded
* @return true if load was succeeded, false otherwise
*/
bool Read3DComponentShape( MODULE* module,
std::vector<S3D_MODEL_PARSER *>& model_parsers_list,
std::vector<wxString>& model_filename_list );
void GenerateFakeShadowsTextures();
DECLARE_EVENT_TABLE()
......
......@@ -28,26 +28,9 @@
#include <fctsys.h>
#include <3d_viewer.h>
#include <3d_struct.h>
bool S3D_MASTER::IsOpenGlAllowed()
{
if( m_loadNonTransparentObjects ) // return true for non transparent objects only
{
if( m_lastTransparency == 0.0 )
return true;
}
if( m_loadTransparentObjects ) // return true for transparent objects only
{
if( m_lastTransparency != 0.0 )
return true;
}
return false;
}
#include "3d_viewer.h"
#include "3d_struct.h"
#include "modelparsers.h"
void S3D_MASTER::Insert( S3D_MATERIAL* aMaterial )
......@@ -72,9 +55,10 @@ S3D_MASTER::S3D_MASTER( EDA_ITEM* aParent ) :
EDA_ITEM( aParent, NOT_USED )
{
m_MatScale.x = m_MatScale.y = m_MatScale.z = 1.0;
m_lastTransparency = 0.0;
m_3D_Drawings = NULL;
m_Materials = NULL;
m_parser = NULL;
m_ShapeType = FILE3D_NONE;
m_use_modelfile_diffuseColor = true;
......@@ -83,8 +67,6 @@ S3D_MASTER::S3D_MASTER( EDA_ITEM* aParent ) :
m_use_modelfile_ambientIntensity = true;
m_use_modelfile_transparency = true;
m_use_modelfile_shininess = true;
m_loadTransparentObjects = true;
m_loadNonTransparentObjects = true;
}
......
......@@ -547,11 +547,7 @@ void EDA_3D_CANVAS::Redraw()
glEnable(GL_COLOR_MATERIAL);
SetOpenGlDefaultMaterial();
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glColor4f( 1.0, 1.0, 1.0, 1.0 );
glDisable( GL_BLEND );
// Draw Solid Shapes
if( isEnabled( FL_MODULE ) )
......@@ -562,6 +558,9 @@ void EDA_3D_CANVAS::Redraw()
glCallList( m_glLists[GL_ID_3DSHAPES_SOLID_FRONT] );
}
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
// Grid uses transparency: draw it after all objects
if( isEnabled( FL_GRID ) && m_glLists[GL_ID_GRID] )
glCallList( m_glLists[GL_ID_GRID] );
......@@ -572,6 +571,8 @@ void EDA_3D_CANVAS::Redraw()
if( isEnabled( FL_MODULE ) && m_glLists[GL_ID_3DSHAPES_TRANSP_FRONT] )
glCallList( m_glLists[GL_ID_3DSHAPES_TRANSP_FRONT] );
glDisable( GL_BLEND );
// Draw Board Shadow
if( isEnabled( FL_MODULE ) && isRealisticMode() &&
isEnabled( FL_RENDER_SHADOWS ) )
......@@ -667,7 +668,7 @@ void EDA_3D_CANVAS::BuildShadowList( GLuint aFrontList, GLuint aBacklist, GLuint
}
void EDA_3D_CANVAS::BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList)
void EDA_3D_CANVAS::BuildBoard3DView( GLuint aBoardList, GLuint aBodyOnlyList )
{
BOARD* pcb = GetBoard();
......@@ -1315,6 +1316,7 @@ void EDA_3D_CANVAS::CreateDrawGL_List()
// For testing purpose only, display calculation time to generate 3D data
// #define PRINT_CALCULATION_TIME
#ifdef PRINT_CALCULATION_TIME
unsigned strtime = GetRunningMicroSecs();
#endif
......@@ -1355,7 +1357,13 @@ void EDA_3D_CANVAS::CreateDrawGL_List()
if( m_glLists[GL_ID_3DSHAPES_TRANSP_FRONT] )
glDeleteLists( m_glLists[GL_ID_3DSHAPES_TRANSP_FRONT], 1 );
m_glLists[GL_ID_3DSHAPES_TRANSP_FRONT] = glGenLists( 1 );
bool useMaterial = g_Parm_3D_Visu.GetFlag( FL_RENDER_MATERIAL );
if( useMaterial )
m_glLists[GL_ID_3DSHAPES_TRANSP_FRONT] = glGenLists( 1 );
else
m_glLists[GL_ID_3DSHAPES_TRANSP_FRONT] = 0;
BuildFootprintShape3DList( m_glLists[GL_ID_3DSHAPES_SOLID_FRONT],
m_glLists[GL_ID_3DSHAPES_TRANSP_FRONT], false );
......@@ -1364,6 +1372,7 @@ void EDA_3D_CANVAS::CreateDrawGL_List()
m_glLists[GL_ID_SHADOW_FRONT] = glGenLists( 1 );
m_glLists[GL_ID_SHADOW_BACK] = glGenLists( 1 );
m_glLists[GL_ID_SHADOW_BOARD] = glGenLists( 1 );
BuildShadowList(m_glLists[GL_ID_SHADOW_FRONT], m_glLists[GL_ID_SHADOW_BACK], m_glLists[GL_ID_SHADOW_BOARD]);
CheckGLError( __FILE__, __LINE__ );
......@@ -1382,65 +1391,155 @@ void EDA_3D_CANVAS::CreateDrawGL_List()
void EDA_3D_CANVAS::BuildFootprintShape3DList( GLuint aOpaqueList,
GLuint aTransparentList, bool aSideToLoad)
{
#ifdef PRINT_CALCULATION_TIME
unsigned strtime = GetRunningMicroSecs();
#endif
// This lists are used to just load once of each filename model
std::vector<S3D_MODEL_PARSER *> model_parsers_list;
std::vector<wxString> model_filename_list;
BOARD* pcb = GetBoard();
for( MODULE* module = pcb->m_Modules; module; module = module->Next() )
Read3DComponentShape( module, model_parsers_list, model_filename_list );
#ifdef PRINT_CALCULATION_TIME
{
unsigned endtime = GetRunningMicroSecs();
wxString msg;
msg.Printf( " Read3DComponentShape total time %.1f ms", (double) (endtime - strtime) / 1000 );
DBG( printf( "%s\n", (const char*)msg.c_str() ) );
}
#endif
#ifdef PRINT_CALCULATION_TIME
strtime = GetRunningMicroSecs();
#endif
bool useMaterial = g_Parm_3D_Visu.GetFlag( FL_RENDER_MATERIAL );
if( useMaterial )
{
// aOpaqueList is the gl list for non transparent items
// aTransparentList is the gl list for non transparent items,
// which need to be drawn after all other items
BOARD* pcb = GetBoard();
glNewList( aOpaqueList, GL_COMPILE );
bool loadTransparentObjects = false;
bool loadOpaqueObjects = true;
for( MODULE* module = pcb->m_Modules; module; module = module->Next() )
module->ReadAndInsert3DComponentShape( this, !loadTransparentObjects,
loadTransparentObjects, aSideToLoad );
Render3DComponentShape( module, loadOpaqueObjects,
!loadOpaqueObjects, aSideToLoad );
glEndList();
glNewList( aTransparentList, GL_COMPILE );
loadTransparentObjects = true;
bool loadTransparentObjects = true;
for( MODULE* module = pcb->m_Modules; module; module = module->Next() )
module->ReadAndInsert3DComponentShape( this, !loadTransparentObjects,
loadTransparentObjects, aSideToLoad );
Render3DComponentShape( module, !loadTransparentObjects,
loadTransparentObjects, aSideToLoad );
glEndList();
}
else
{
// Just create one list
glNewList( aOpaqueList, GL_COMPILE );
for( MODULE* module = pcb->m_Modules; module; module = module->Next() )
Render3DComponentShape( module, false, false, aSideToLoad );
glEndList();
}
#ifdef PRINT_CALCULATION_TIME
{
unsigned endtime = GetRunningMicroSecs();
wxString msg;
msg.Printf( " Render3DComponentShape total time %.1f ms", (double) (endtime - strtime) / 1000 );
DBG( printf( "%s\n", (const char*)msg.c_str() ) );
}
#endif
}
void MODULE::ReadAndInsert3DComponentShape( EDA_3D_CANVAS* glcanvas,
bool aAllowNonTransparentObjects,
bool aAllowTransparentObjects,
bool aSideToLoad )
bool EDA_3D_CANVAS::Read3DComponentShape( MODULE* module,
std::vector<S3D_MODEL_PARSER *>& model_parsers_list,
std::vector<wxString>& model_filename_list )
{
S3D_MASTER* shape3D = module->Models();
for( ; shape3D; shape3D = shape3D->Next() )
{
if( shape3D->Is3DType( S3D_MASTER::FILE3D_VRML ) )
{
bool found = false;
unsigned int i;
wxString shape_filename = shape3D->GetShape3DFullFilename();
// Search for already loaded files
for( i = 0; i < model_filename_list.size(); i++ )
{
if( shape_filename.Cmp(model_filename_list[i]) == 0 )
{
found = true;
break;
}
}
if( found == false )
{
shape3D->ReadData();
model_filename_list.push_back( shape_filename );
model_parsers_list.push_back( shape3D->m_parser );
}
else
{
DBG( printf( " Read3DComponentShape reusing %s\n", (const char*)shape_filename.c_str() ) );
shape3D->m_parser = model_parsers_list[i];
}
}
}
return true;
}
void EDA_3D_CANVAS::Render3DComponentShape( MODULE* module,
bool aIsRenderingJustNonTransparentObjects,
bool aIsRenderingJustTransparentObjects,
bool aSideToLoad )
{
// Read from disk and draws the footprint 3D shapes if exists
double zpos = glcanvas->GetPrm3DVisu().GetModulesZcoord3DIU( IsFlipped() );
double zpos = GetPrm3DVisu().GetModulesZcoord3DIU( module->IsFlipped() );
glPushMatrix();
glTranslatef( m_Pos.x * glcanvas->GetPrm3DVisu().m_BiuTo3Dunits,
-m_Pos.y * glcanvas->GetPrm3DVisu().m_BiuTo3Dunits,
zpos );
wxPoint pos = module->GetPosition();
glTranslatef( pos.x * GetPrm3DVisu().m_BiuTo3Dunits,
-pos.y * GetPrm3DVisu().m_BiuTo3Dunits,
zpos );
if( m_Orient )
glRotatef( (double) m_Orient / 10, 0.0, 0.0, 1.0 );
if( module->GetOrientation() )
glRotatef( (double) module->GetOrientation() / 10.0, 0.0, 0.0, 1.0 );
if( IsFlipped() )
if( module->IsFlipped() )
{
glRotatef( 180.0, 0.0, 1.0, 0.0 );
glRotatef( 180.0, 0.0, 0.0, 1.0 );
}
S3D_MASTER* shape3D = Models();
S3D_MASTER* shape3D = module->Models();
for( ; shape3D; shape3D = shape3D->Next() )
{
shape3D->SetLoadNonTransparentObjects( aAllowNonTransparentObjects );
shape3D->SetLoadTransparentObjects( aAllowTransparentObjects );
if( shape3D->Is3DType( S3D_MASTER::FILE3D_VRML ) )
{
glPushMatrix();
shape3D->ReadData();
shape3D->Render( aIsRenderingJustNonTransparentObjects,
aIsRenderingJustTransparentObjects );
glPopMatrix();
}
}
......
......@@ -71,31 +71,23 @@ void SetOpenGlDefaultMaterial()
}
void S3D_MATERIAL::SetOpenGLMaterial( unsigned int aMaterialIndex, bool aUseMaterial )
bool S3D_MATERIAL::SetOpenGLMaterial( unsigned int aMaterialIndex, bool aUseMaterial )
{
S3D_MASTER * s3dParent = (S3D_MASTER *) GetParent();
if( ! s3dParent->IsOpenGlAllowed() )
return;
if( aUseMaterial )
{
float transparency_value = 0.0f;
if( m_Transparency.size() > aMaterialIndex )
{
transparency_value = m_Transparency[aMaterialIndex];
s3dParent->SetLastTransparency( transparency_value );
}
if( m_DiffuseColor.size() > aMaterialIndex )
{
glm::vec3 color = m_DiffuseColor[aMaterialIndex];
if( m_AmbientColor.size() == 0 )
{
glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );
}
glColor4f( color.x, color.y, color.z, 1.0 - transparency_value );
}
......@@ -136,15 +128,18 @@ void S3D_MATERIAL::SetOpenGLMaterial( unsigned int aMaterialIndex, bool aUseMate
ambient[3] = 1.0f;
glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT, &ambient.x );
}
return (transparency_value != 0.0f);
}
else
{
if( m_DiffuseColor.size() > aMaterialIndex )
{
glm::vec3 color = m_DiffuseColor[aMaterialIndex];
glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );
glColor4f( color.x, color.y, color.z, 1.0 );
}
}
return false;
}
......@@ -59,8 +59,9 @@ public:
* @param aMaterialIndex = the index in list of available materials
* @param aUseMaterial = true to use the values found in the available material
* = false to use only the color, and other prms are fixed
* @return true if the material is transparency
*/
void SetOpenGLMaterial(unsigned int aMaterialIndex, bool aUseMaterial);
bool SetOpenGLMaterial(unsigned int aMaterialIndex, bool aUseMaterial);
#if defined(DEBUG)
void Show( int nestLevel, std::ostream& os ) const { ShowDummy( os ); } // override
......
This diff is collapsed.
......@@ -58,8 +58,8 @@ public:
S3D_MESH();
~S3D_MESH();
void openGL_Render();
void openGL_RenderAllChilds();
void openGL_RenderAllChilds( bool aIsRenderingJustNonTransparentObjects,
bool aIsRenderingJustTransparentObjects );
S3D_MATERIAL *m_Materials;
......@@ -81,10 +81,10 @@ public:
std::vector<S3D_MESH *> childs;
private:
std::vector< glm::vec3 > m_PerFaceNormalsRaw;
std::vector< glm::vec3 > m_PerFaceNormalsRaw_X_PerFaceSquaredArea;
std::vector< std::vector< glm::vec3 > > m_PerFaceVertexNormals;
std::vector< glm::vec3 > m_PointNormalized;
std::vector< float > m_PerFaceSquaredArea;
std::vector< std::vector<int> > m_InvalidCoordIndexes; //!TODO: check for invalid CoordIndex in file and remove the index and the same material index
bool isPerFaceNormalsComputed;
......@@ -98,7 +98,9 @@ private:
bool isPerVertexNormalsVerified;
void perVertexNormalsVerify_and_Repair();
};
void openGL_Render( bool aIsRenderingJustNonTransparentObjects,
bool aIsRenderingJustTransparentObjects );
};
#endif
......@@ -85,7 +85,7 @@ const wxString S3D_MASTER::GetShape3DFullFilename()
}
int S3D_MASTER::ReadData()
{
{
if( m_Shape3DName.IsEmpty() )
return 1;
......@@ -109,12 +109,13 @@ int S3D_MASTER::ReadData()
wxFileName fn( filename );
wxString extension = fn.GetExt();
S3D_MODEL_PARSER* parser = S3D_MODEL_PARSER::Create( this, extension );
if( parser )
m_parser = S3D_MODEL_PARSER::Create( this, extension );
if( m_parser )
{
parser->Load( filename, g_Parm_3D_Visu.m_BiuTo3Dunits * UNITS3D_TO_UNITSPCB );
delete parser;
m_parser->Load( filename );
return 0;
}
else
......@@ -124,3 +125,42 @@ int S3D_MASTER::ReadData()
return -1;
}
void S3D_MASTER::Render( bool aIsRenderingJustNonTransparentObjects,
bool aIsRenderingJustTransparentObjects )
{
if( m_parser == NULL )
return;
double aVrmlunits_to_3Dunits = g_Parm_3D_Visu.m_BiuTo3Dunits * UNITS3D_TO_UNITSPCB;
glScalef( aVrmlunits_to_3Dunits, aVrmlunits_to_3Dunits, aVrmlunits_to_3Dunits );
glm::vec3 matScale( m_MatScale.x,
m_MatScale.y,
m_MatScale.z );
glm::vec3 matRot( m_MatRotation.x,
m_MatRotation.y,
m_MatRotation.z );
glm::vec3 matPos( m_MatPosition.x,
m_MatPosition.y,
m_MatPosition.z );
glTranslatef( matPos.x * SCALE_3D_CONV,
matPos.y * SCALE_3D_CONV,
matPos.z * SCALE_3D_CONV );
glRotatef( -matRot.z, 0.0f, 0.0f, 1.0f );
glRotatef( -matRot.y, 0.0f, 1.0f, 0.0f );
glRotatef( -matRot.x, 1.0f, 0.0f, 0.0f );
glScalef( matScale.x, matScale.y, matScale.z );
for( unsigned int idx = 0; idx < m_parser->childs.size(); idx++ )
{
m_parser->childs[idx]->openGL_RenderAllChilds( aIsRenderingJustNonTransparentObjects,
aIsRenderingJustTransparentObjects );
}
}
\ No newline at end of file
......@@ -36,6 +36,7 @@
#include <3d_material.h>
#include <gal/opengl/glm/glm.hpp>
/**
* @note For historical reasons the 3D modeling unit is 0.1 inch
* 1 3Dunit = 2.54 mm = 0.1 inch = 100 mils
......@@ -81,15 +82,18 @@ public:
}
};
class S3D_MODEL_PARSER;
// Master structure for a 3D footprint shape description
class S3D_MASTER : public EDA_ITEM
{
public:
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
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
S3D_MODEL_PARSER* m_parser; ///< it store the loaded file to be rendered later
enum FILE3D_TYPE
{
......@@ -110,12 +114,6 @@ public:
private:
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
bool m_loadTransparentObjects;
bool m_loadNonTransparentObjects;
public:
S3D_MASTER( EDA_ITEM* aParent );
......@@ -125,24 +123,8 @@ public:
S3D_MASTER* Back() const { return (S3D_MASTER*) Pback; }
// Accessors
void SetLastTransparency( double aValue ) { m_lastTransparency = aValue; }
void SetLoadTransparentObjects( bool aLoad )
{ m_loadTransparentObjects = aLoad; }
void SetLoadNonTransparentObjects( bool aLoad )
{ m_loadNonTransparentObjects = aLoad; }
void Insert( S3D_MATERIAL* aMaterial );
/**
* Function IsOpenGlAllowed
* @return true if opengl current list accepts a gl data
* used to filter transparent objects, which are drawn after
* non transparent objects
*/
bool IsOpenGlAllowed();
void Copy( S3D_MASTER* pattern );
/**
......@@ -152,6 +134,9 @@ public:
*/
int ReadData();
void Render( bool aIsRenderingJustNonTransparentObjects,
bool aIsRenderingJustTransparentObjects );
/**
* Function ObjectCoordsTo3DUnits
* @param aVertices = a list of 3D coordinates in shape units
......
......@@ -49,8 +49,13 @@ public:
master( aMaster )
{}
virtual ~S3D_MODEL_PARSER()
{}
~S3D_MODEL_PARSER()
{
for( unsigned int idx = 0; idx < childs.size(); idx++ )
{
delete childs[idx];
}
}
S3D_MASTER* GetMaster()
{
......@@ -71,10 +76,21 @@ public:
* pure virtual Function
* Concrete parsers should implement this function
* @param aFilename = the full file name of the file to load
* @param aVrmlunits_to_3Dunits = the scaling factor, i.e. the
* convertion from file unit to internal 3D units
* @return true if as succeeded
*/
virtual bool Load( const wxString& aFilename ) = 0;
/**
* Function Render
* Render the model to openGL. The arguments can be both false but just only one
* can be true.
* @param aIsRenderingJustNonTransparentObjects
* @param aIsRenderingJustTransparentObjects
*/
virtual void Load( const wxString& aFilename, double aVrmlunits_to_3Dunits ) = 0;
void Render( bool aIsRenderingJustNonTransparentObjects,
bool aIsRenderingJustTransparentObjects );
std::vector< S3D_MESH* > childs;
private:
S3D_MASTER* master;
......@@ -93,7 +109,7 @@ public:
X3D_MODEL_PARSER( S3D_MASTER* aMaster );
~X3D_MODEL_PARSER();
void Load( const wxString& aFilename, double aVrmlunits_to_3Dunits );
bool Load( const wxString& aFilename );
typedef std::map< wxString, wxString > PROPERTY_MAP;
typedef std::vector< wxXmlNode* > NODE_LIST;
......@@ -127,7 +143,6 @@ public:
private:
wxString m_Filename;
S3D_MESH* m_model;
std::vector< S3D_MESH* > childs;
std::vector< wxString > vrml_materials;
std::vector< wxString > vrml_points;
......@@ -148,13 +163,13 @@ typedef std::map< std::string, std::vector< glm::vec3 > > VRML2_COORDINATE_MAP;
* class VRML2_MODEL_PARSER
* Parses
*/
class VRML2_MODEL_PARSER: public S3D_MODEL_PARSER
class VRML2_MODEL_PARSER
{
public:
VRML2_MODEL_PARSER( S3D_MASTER* aMaster );
VRML2_MODEL_PARSER( S3D_MODEL_PARSER* aModelParser );
~VRML2_MODEL_PARSER();
void Load( const wxString& aFilename, double aVrmlunits_to_3Dunits );
bool Load( const wxString& aFilename );
/**
* Return string representing VRML2 file in vrml2 format
......@@ -185,11 +200,11 @@ private:
bool m_normalPerVertex;
bool colorPerVertex;
S3D_MESH* m_model;
std::vector< S3D_MESH* > childs;
FILE* m_file;
S3D_MATERIAL* m_Materials;
wxString m_Filename;
VRML2_COORDINATE_MAP m_defCoordinateMap;
S3D_MODEL_PARSER* m_ModelParser;
S3D_MASTER* m_Master;
};
......@@ -197,13 +212,13 @@ private:
* class VRML1_MODEL_PARSER
* Parses
*/
class VRML1_MODEL_PARSER: public S3D_MODEL_PARSER
class VRML1_MODEL_PARSER
{
public:
VRML1_MODEL_PARSER( S3D_MASTER* aMaster );
VRML1_MODEL_PARSER( S3D_MODEL_PARSER* aModelParser );
~VRML1_MODEL_PARSER();
void Load( const wxString& aFilename, double aVrmlunits_to_3Dunits );
bool Load( const wxString& aFilename );
/**
* Return string representing VRML2 file in vrml2 format
......@@ -233,10 +248,10 @@ private:
bool m_normalPerVertex;
bool colorPerVertex;
S3D_MESH* m_model;
std::vector< S3D_MESH* > childs;
S3D_MATERIAL* m_Materials;
FILE* m_file;
wxString m_Filename;
S3D_MODEL_PARSER* m_ModelParser;
S3D_MASTER* m_Master;
};
/**
......@@ -263,7 +278,7 @@ public:
* @param aVrmlunits_to_3Dunits = the csaling factor to convert the 3D file unit
* to our internal units.
*/
void Load( const wxString& aFilename, double aVrmlunits_to_3Dunits );
bool Load( const wxString& aFilename );
private:
S3D_MASTER* m_curr3DShape; ///< the current 3D shape to build from the file
......
......@@ -36,14 +36,23 @@
#include "modelparsers.h"
#include "vrml_aux.h"
#define BUFLINE_SIZE 512
#define BUFLINE_SIZE 32
VRML1_MODEL_PARSER::VRML1_MODEL_PARSER( S3D_MASTER* aMaster ) :
S3D_MODEL_PARSER( aMaster )
/**
* Trace mask used to enable or disable the trace output of the VRML V1 parser code.
* The debug output can be turned on by setting the WXTRACE environment variable to
* "KI_TRACE_VRML_V1_PARSER". See the wxWidgets documentation on wxLogTrace for
* more information.
*/
static const wxChar* traceVrmlV1Parser = wxT( "KI_TRACE_VRML_V1_PARSER" );
VRML1_MODEL_PARSER::VRML1_MODEL_PARSER( S3D_MODEL_PARSER* aModelParser )
{
m_ModelParser = aModelParser;
m_Master = m_ModelParser->GetMaster();
m_model = NULL;
m_file = NULL;
m_Materials = NULL;
m_normalPerVertex = true;
colorPerVertex = true;
}
......@@ -51,43 +60,24 @@ VRML1_MODEL_PARSER::VRML1_MODEL_PARSER( S3D_MASTER* aMaster ) :
VRML1_MODEL_PARSER::~VRML1_MODEL_PARSER()
{
for( unsigned int idx = 0; idx < childs.size(); idx++ )
delete childs[idx];
}
void VRML1_MODEL_PARSER::Load( const wxString& aFilename, double aVrmlunits_to_3Dunits )
bool VRML1_MODEL_PARSER::Load( const wxString& aFilename )
{
char text[BUFLINE_SIZE];
// DBG( printf( "Load %s\n", GetChars(aFilename) ) );
wxLogTrace( traceVrmlV1Parser, wxT( "Loading: %s" ), GetChars( aFilename ) );
m_file = wxFopen( aFilename, wxT( "rt" ) );
if( m_file == NULL )
return;
float vrmlunits_to_3Dunits = aVrmlunits_to_3Dunits;
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 );
// glPushMatrix();
glTranslatef( matPos.x * SCALE_3D_CONV, matPos.y * SCALE_3D_CONV, matPos.z * SCALE_3D_CONV );
return false;
glRotatef( -matRot.z, 0.0f, 0.0f, 1.0f );
glRotatef( -matRot.y, 0.0f, 1.0f, 0.0f );
glRotatef( -matRot.x, 1.0f, 0.0f, 0.0f );
// Switch the locale to standard C (needed to print floating point numbers)
LOCALE_IO toggle;
glScalef( matScale.x, matScale.y, matScale.z );
LOCALE_IO toggle; // Switch the locale to standard C
childs.clear();
m_ModelParser->childs.clear();
while( GetNextTag( m_file, text, sizeof(text) ) )
{
......@@ -99,22 +89,14 @@ void VRML1_MODEL_PARSER::Load( const wxString& aFilename, double aVrmlunits_to_3
if( strcmp( text, "Separator" ) == 0 )
{
m_model = new S3D_MESH();
childs.push_back( m_model );
m_ModelParser->childs.push_back( m_model );
read_separator();
}
}
fclose( m_file );
// DBG( printf( "chils size:%lu\n", childs.size() ) );
if( GetMaster()->IsOpenGlAllowed() )
{
for( unsigned int idx = 0; idx < childs.size(); idx++ )
{
childs[idx]->openGL_RenderAllChilds();
}
}
return true;
}
......@@ -175,9 +157,9 @@ int VRML1_MODEL_PARSER::readMaterial()
wxString mat_name;
material = new S3D_MATERIAL( GetMaster(), mat_name );
material = new S3D_MATERIAL( m_Master, mat_name );
GetMaster()->Insert( material );
m_Master->Insert( material );
m_model->m_Materials = material;
......@@ -219,6 +201,7 @@ int VRML1_MODEL_PARSER::readMaterial()
}
}
wxLogTrace( traceVrmlV1Parser, wxT( " readMaterial failed" ) );
return -1;
}
......@@ -247,6 +230,7 @@ int VRML1_MODEL_PARSER::readCoordinate3()
}
}
wxLogTrace( traceVrmlV1Parser, wxT( " readCoordinate3 failed" ) );
return -1;
}
......@@ -279,6 +263,7 @@ int VRML1_MODEL_PARSER::readIndexedFaceSet()
}
}
wxLogTrace( traceVrmlV1Parser, wxT( " readIndexedFaceSet failed" ) );
return -1;
}
......@@ -305,7 +290,7 @@ int VRML1_MODEL_PARSER::readMaterial_emissiveColor()
int ret = parseVertexList( m_file, m_model->m_Materials->m_EmissiveColor );
if( GetMaster()->m_use_modelfile_emissiveColor == false )
if( m_Master->m_use_modelfile_emissiveColor == false )
{
m_model->m_Materials->m_EmissiveColor.clear();
}
......@@ -320,7 +305,7 @@ int VRML1_MODEL_PARSER::readMaterial_specularColor()
int ret = parseVertexList( m_file, m_model->m_Materials->m_SpecularColor );
if( GetMaster()->m_use_modelfile_specularColor == false )
if( m_Master->m_use_modelfile_specularColor == false )
{
m_model->m_Materials->m_SpecularColor.clear();
}
......@@ -344,7 +329,7 @@ int VRML1_MODEL_PARSER::readMaterial_shininess()
m_model->m_Materials->m_Shininess.push_back( shininess_value );
}
if( GetMaster()->m_use_modelfile_shininess == false )
if( m_Master->m_use_modelfile_shininess == false )
{
m_model->m_Materials->m_Shininess.clear();
}
......@@ -368,7 +353,7 @@ int VRML1_MODEL_PARSER::readMaterial_transparency()
m_model->m_Materials->m_Transparency.push_back( tmp );
}
if( GetMaster()->m_use_modelfile_transparency == false )
if( m_Master->m_use_modelfile_transparency == false )
{
m_model->m_Materials->m_Transparency.clear();
}
......@@ -388,6 +373,7 @@ int VRML1_MODEL_PARSER::readCoordinate3_point()
return 0;
}
wxLogTrace( traceVrmlV1Parser, wxT( " readCoordinate3_point failed" ) );
return -1;
}
......@@ -415,12 +401,12 @@ int VRML1_MODEL_PARSER::readIndexedFaceSet_coordIndex()
|| (coord[0] == coord[2])
|| (coord[2] == coord[1]) )
{
// DBG( printf( " invalid coordIndex at index %lu (%d, %d, %d, %d)\n", m_model->m_CoordIndex.size()+1,coord[0], coord[1], coord[2], dummy ) );
wxLogTrace( traceVrmlV1Parser, wxT( " invalid coordIndex at index %u (%d, %d, %d, %d)" ), (unsigned int)m_model->m_CoordIndex.size() + 1,coord[0], coord[1], coord[2], dummy );
}
if( dummy != -1 )
{
// DBG( printf( " Error at index %lu, -1 Expected, got %d\n", m_model->m_CoordIndex.size()+1, dummy ) );
wxLogTrace( traceVrmlV1Parser, wxT( " Error at index %u, -1 Expected, got %d" ), (unsigned int)m_model->m_CoordIndex.size() + 1, dummy );
}
m_model->m_CoordIndex.push_back( coord_list );
......
This diff is collapsed.
......@@ -41,9 +41,9 @@
VRML_MODEL_PARSER::VRML_MODEL_PARSER( S3D_MASTER* aMaster ) :
S3D_MODEL_PARSER( aMaster )
{
m_curr3DShape = aMaster;
vrml1_parser = NULL;
vrml2_parser = NULL;
m_curr3DShape = NULL;
}
......@@ -52,9 +52,9 @@ VRML_MODEL_PARSER::~VRML_MODEL_PARSER()
}
void VRML_MODEL_PARSER::Load( const wxString& aFilename, double aVrmlunits_to_3Dunits )
bool VRML_MODEL_PARSER::Load( const wxString& aFilename )
{
char line[128];
char line[11 + 1];
FILE* file;
//DBG( printf( "Load %s", GetChars( aFilename ) ) );
......@@ -62,34 +62,33 @@ void VRML_MODEL_PARSER::Load( const wxString& aFilename, double aVrmlunits_to_3D
file = wxFopen( aFilename, wxT( "rt" ) );
if( file == NULL )
return;
return false;
if( fgets( line, 11, file ) == NULL )
{
fclose( file );
return;
return false;
}
fclose( file );
if( stricmp( line, "#VRML V2.0" ) == 0 )
{
//DBG( printf( "About to parser a #VRML V2.0 file\n" ) );
vrml2_parser = new VRML2_MODEL_PARSER( m_curr3DShape );
vrml2_parser->Load( aFilename, aVrmlunits_to_3Dunits );
vrml2_parser = new VRML2_MODEL_PARSER( this );
vrml2_parser->Load( aFilename );
delete vrml2_parser;
vrml2_parser = NULL;
return;
return true;
}
else if( stricmp( line, "#VRML V1.0" ) == 0 )
{
//DBG( printf( "About to parser a #VRML V1.0 file\n" ) );
vrml1_parser = new VRML1_MODEL_PARSER( m_curr3DShape );
vrml1_parser->Load( aFilename, aVrmlunits_to_3Dunits );
vrml1_parser = new VRML1_MODEL_PARSER( this );
vrml1_parser->Load( aFilename );
delete vrml1_parser;
vrml1_parser = NULL;
return;
return true;
}
// DBG( printf( "Unknown VRML file format: %s\n", line ) );
DBG( printf( "Unknown internal VRML file format: %s\n", line ) );
return false;
}
......@@ -40,6 +40,14 @@
#include <modelparsers.h>
#include <xnode.h>
/**
* Trace mask used to enable or disable the trace output of the X3D parser code.
* The debug output can be turned on by setting the WXTRACE environment variable to
* "KI_TRACE_X3D_PARSER". See the wxWidgets documentation on wxLogTrace for
* more information.
*/
static const wxChar* traceX3DParser = wxT( "KI_TRACE_X3D_PARSER" );
X3D_MODEL_PARSER::X3D_MODEL_PARSER( S3D_MASTER* aMaster ) :
S3D_MODEL_PARSER( aMaster )
......@@ -53,41 +61,24 @@ X3D_MODEL_PARSER::~X3D_MODEL_PARSER()
}
void X3D_MODEL_PARSER::Load( const wxString& aFilename, double aVrmlUnitsTo3DUnits )
bool X3D_MODEL_PARSER::Load( const wxString& aFilename )
{
wxLogTrace( traceX3DParser, wxT( "Loading: %s" ), GetChars( aFilename ) );
wxXmlDocument doc;
if( !doc.Load( aFilename ) )
{
wxLogError( wxT( "Error while parsing file '%s'" ), GetChars( aFilename ) );
return;
wxLogTrace( traceX3DParser, wxT( "Error while parsing file: %s" ), GetChars( aFilename ) );
return false;
}
if( doc.GetRoot()->GetName() != wxT( "X3D" ) )
{
wxLogError( wxT( "Filetype is not X3D '%s'" ), GetChars( aFilename ) );
return;
wxLogTrace( traceX3DParser, wxT( "Filetype is not X3D: %s" ), GetChars( aFilename ) );
return false;
}
float vrmlunits_to_3Dunits = aVrmlUnitsTo3DUnits;
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 );
glTranslatef( matPos.x * SCALE_3D_CONV, matPos.y * SCALE_3D_CONV, matPos.z * SCALE_3D_CONV );
glRotatef( -matRot.z, 0.0f, 0.0f, 1.0f );
glRotatef( -matRot.y, 0.0f, 1.0f, 0.0f );
glRotatef( -matRot.x, 1.0f, 0.0f, 0.0f );
glScalef( matScale.x, matScale.y, matScale.z );
// Switch the locale to standard C (needed to print floating point numbers)
LOCALE_IO toggle;
......@@ -109,15 +100,7 @@ void X3D_MODEL_PARSER::Load( const wxString& aFilename, double aVrmlUnitsTo3DUni
readTransform( *node_it );
}
// DBG( printf( "chils size:%lu\n", childs.size() ) );
if( GetMaster()->IsOpenGlAllowed() )
{
for( unsigned int idx = 0; idx < childs.size(); idx++ )
{
childs[idx]->openGL_RenderAllChilds();
}
}
return true;
}
......@@ -485,7 +468,7 @@ void X3D_MODEL_PARSER::readIndexedFaceSet( wxXmlNode* aFaceNode,
}
else
{
wxLogError( wxT( "Error converting to double" ) );
wxLogTrace( traceX3DParser, wxT( "Error converting to double" ) );
}
}
......@@ -552,7 +535,7 @@ void X3D_MODEL_PARSER::readIndexedFaceSet( wxXmlNode* aFaceNode,
}
else
{
wxLogError( wxT( "Error converting to double" ) );
wxLogTrace( traceX3DParser, wxT( "Error converting to double" ) );
}
}
......
......@@ -312,21 +312,6 @@ public:
void DrawOutlinesWhenMoving( EDA_DRAW_PANEL* aPanel,
wxDC* aDC, const wxPoint& aMoveVector );
/**
* function ReadandInsert3DComponentShape
* read the 3D component shape(s) of the footprint (physical shape)
* and insert mesh in gl list
* @param glcanvas = the openGL canvas
* @param aAllowNonTransparentObjects = true to load non transparent objects
* @param aAllowTransparentObjects = true to load non transparent objects
* @param aSideToLoad = false will load not fliped, true will load fliped objects
* in openGL, transparent objects should be drawn *after* non transparent objects
*/
void ReadAndInsert3DComponentShape( EDA_3D_CANVAS* glcanvas,
bool aAllowNonTransparentObjects,
bool aAllowTransparentObjects,
bool aSideToLoad );
/**
* function TransformPadsShapesWithClearanceToPolygon
* generate pads shapes on layer aLayer as polygons,
......@@ -619,8 +604,8 @@ public:
/**
* Function PadCoverageRatio
* Calculates the ratio of total area of the footprint pads to the area of the
* footprint. Used by selection tool heuristics.
* Calculates the ratio of total area of the footprint pads to the area of the
* footprint. Used by selection tool heuristics.
* @return the ratio
*/
double PadCoverageRatio() const;
......
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