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
......
......@@ -54,31 +54,29 @@ S3D_MESH::S3D_MESH()
S3D_MESH::~S3D_MESH()
{
for( unsigned int idx = 0; idx < childs.size(); idx++ )
{
delete childs[idx];
}
}
void S3D_MESH::openGL_RenderAllChilds()
void S3D_MESH::openGL_RenderAllChilds( bool aIsRenderingJustNonTransparentObjects,
bool aIsRenderingJustTransparentObjects )
{
//DBG( printf( "openGL_RenderAllChilds") );
glEnable( GL_COLOR_MATERIAL ) ;
SetOpenGlDefaultMaterial();
glPushMatrix();
glTranslatef( m_translation.x, m_translation.y, m_translation.z );
glRotatef( m_rotation[3], m_rotation[0], m_rotation[1], m_rotation[2] );
glScalef( m_scale.x, m_scale.y, m_scale.z );
SetOpenGlDefaultMaterial();
// Render your self
openGL_Render();
openGL_Render( aIsRenderingJustNonTransparentObjects,
aIsRenderingJustTransparentObjects );
// Render childs
for( unsigned int idx = 0; idx < childs.size(); idx++ )
{
childs[idx]->openGL_Render();
childs[idx]->openGL_Render( aIsRenderingJustNonTransparentObjects,
aIsRenderingJustTransparentObjects );
}
SetOpenGlDefaultMaterial();
......@@ -87,23 +85,41 @@ void S3D_MESH::openGL_RenderAllChilds()
}
void S3D_MESH::openGL_Render()
void S3D_MESH::openGL_Render( bool aIsRenderingJustNonTransparentObjects,
bool aIsRenderingJustTransparentObjects )
{
if( (aIsRenderingJustNonTransparentObjects == true) &&
(aIsRenderingJustTransparentObjects == true) )
{
return;
}
//DBG( printf( "openGL_Render" ) );
bool useMaterial = g_Parm_3D_Visu.GetFlag( FL_RENDER_MATERIAL );
bool smoothShapes = g_Parm_3D_Visu.IsRealisticMode()
&& g_Parm_3D_Visu.GetFlag( FL_RENDER_SMOOTH_NORMALS );
if( m_CoordIndex.size() == 0 )
{
return;
}
if( m_Materials && ( m_MaterialIndex.size() == 0 ) )
{
bool isTransparent = m_Materials->SetOpenGLMaterial( 0, useMaterial );
if( isTransparent && aIsRenderingJustNonTransparentObjects )
return;
if( !isTransparent && aIsRenderingJustTransparentObjects )
return;
}
glPushMatrix();
glTranslatef( m_translation.x, m_translation.y, m_translation.z );
glRotatef( m_rotation[3], m_rotation[0], m_rotation[1], m_rotation[2] );
glScalef( m_scale.x, m_scale.y, m_scale.z );
std::vector< glm::vec3 > normals;
calcPointNormalized();
calcPerFaceNormals();
......@@ -121,10 +137,21 @@ void S3D_MESH::openGL_Render()
{
if( m_Materials )
{
if( m_MaterialIndex.size() == 0 )
m_Materials->SetOpenGLMaterial( 0, useMaterial );
if ( m_MaterialIndex.size() > 0 )
{
bool isTransparent = m_Materials->SetOpenGLMaterial( m_MaterialIndex[idx], useMaterial );
if( isTransparent && aIsRenderingJustNonTransparentObjects )
continue;
if( !isTransparent && aIsRenderingJustTransparentObjects )
continue;
}
else
m_Materials->SetOpenGLMaterial( m_MaterialIndex[idx], useMaterial );
{
// This is only need on debug, because above we are marking the bad elements
DBG( m_Materials->SetOpenGLMaterial( 0, useMaterial ) );
}
}
switch( m_CoordIndex[idx].size() )
......@@ -152,8 +179,10 @@ void S3D_MESH::openGL_Render()
glNormal3fv( &normal.x );
// Flag error vertices
#if defined(DEBUG)
if ((normal.x == 0.0) && (normal.y == 0.0) && (normal.z == 0.0))
glColor3f( 1.0, 0.0, 0.0 );
glColor4f( 1.0, 0.0, 1.0, 1.0 );
#endif
glm::vec3 point = m_Point[m_CoordIndex[idx][ii]];
glVertex3fv( &point.x );
......@@ -170,8 +199,10 @@ void S3D_MESH::openGL_Render()
glNormal3fv( &normal.x );
// Flag error vertices
#if defined(DEBUG)
if ((normal.x == 0.0) && (normal.y == 0.0) && (normal.z == 0.0))
glColor3f( 1.0, 0.0, 0.0 );
glColor4f( 1.0, 0.0, 1.0, 1.0 );
#endif
glm::vec3 point = m_Point[m_CoordIndex[idx][ii]];
glVertex3fv( &point.x );
......@@ -190,8 +221,10 @@ void S3D_MESH::openGL_Render()
glNormal3fv( &normal.x );
// Flag error vertices
#if defined(DEBUG)
if ((normal.x == 0.0) && (normal.y == 0.0) && (normal.z == 0.0))
glColor3f( 1.0, 0.0, 0.0 );
glColor4f( 1.0, 0.0, 1.0, 1.0 );
#endif
glm::vec3 point = m_Point[m_CoordIndex[idx][ii]];
glVertex3fv( &point.x );
......@@ -268,7 +301,7 @@ void S3D_MESH::perVertexNormalsVerify_and_Repair()
}
else
{
//DBG( printf( "idx:%u\n", idx ) );
DBG( printf( " Cannot normalize precomputed normal at idx:%u\n", idx ) );
}
m_PerVertexNormalsNormalized[idx] = normal;
......@@ -285,31 +318,36 @@ void S3D_MESH::calcPointNormalized()
isPointNormalizedComputed = true;
/*
m_PointNormalized = m_Point;
*/
m_PointNormalized.clear();
m_PointNormalized.resize( m_Point.size() );
float biggerPoint = 0.0f;
for( unsigned int i = 0; i < m_Point.size(); i++ )
{
if( fabs( m_Point[i].x ) > biggerPoint )
biggerPoint = fabs( m_Point[i].x );
if( fabs( m_Point[i].y ) > biggerPoint )
biggerPoint = fabs( m_Point[i].y );
if( fabs( m_Point[i].z ) > biggerPoint )
biggerPoint = fabs( m_Point[i].z );
float v;
v = fabs( m_Point[i].x );
if( v > biggerPoint )
biggerPoint = v;
v = fabs( m_Point[i].y );
if( v > biggerPoint )
biggerPoint = v;
v = fabs( m_Point[i].z );
if( v > biggerPoint )
biggerPoint = v;
}
biggerPoint = 1.0 / biggerPoint;
for( unsigned int i = 0; i < m_Point.size(); i++ )
{
glm::vec3 p;
p = m_Point[i] * biggerPoint;
m_PointNormalized.push_back( p );
m_PointNormalized[i] = m_Point[i] * biggerPoint;
}
//DBG( printf("m_Point.size %u\n", m_Point.size()) );
}
......@@ -342,8 +380,10 @@ void S3D_MESH::calcPerFaceNormals()
else
m_PerFaceNormalsNormalized.clear();
m_PerFaceNormalsRaw.clear();
m_PerFaceSquaredArea.clear();
m_PerFaceNormalsRaw_X_PerFaceSquaredArea.clear();
m_PerFaceNormalsNormalized.resize( m_CoordIndex.size() );
m_PerFaceNormalsRaw_X_PerFaceSquaredArea.resize( m_CoordIndex.size() );
// There are no points defined for the coordIndex
if( m_PointNormalized.size() == 0 )
......@@ -354,36 +394,46 @@ void S3D_MESH::calcPerFaceNormals()
for( unsigned int idx = 0; idx < m_CoordIndex.size(); idx++ )
{
// User normalized and multiply to get better resolution
glm::vec3 v0 = m_PointNormalized[m_CoordIndex[idx][0]];
glm::vec3 v1 = m_PointNormalized[m_CoordIndex[idx][1]];
glm::vec3 v2 = m_PointNormalized[m_CoordIndex[idx][m_CoordIndex[idx].size() - 1]];
glm::vec3 cross_prod;
/*
// This is not working as good as it is expected :/
if( IsClockwise( v0, v1, v2 ) )
cross_prod.x = 0.0;
cross_prod.y = 0.0;
cross_prod.z = 0.0;
// Newell's Method
// http://www.opengl.org/wiki/Calculating_a_Surface_Normal
// http://tog.acm.org/resources/GraphicsGems/gemsiii/newell.c
// http://www.iquilezles.org/www/articles/areas/areas.htm
for( unsigned int i = 0; i < m_CoordIndex[idx].size(); i++ )
{
// CW
cross_prod = glm::cross( v1 - v2, v0 - v2 );
} else
{*/
// CCW
cross_prod = glm::cross( v1 - v0, v2 - v0 );
//}
glm::vec3 u = m_PointNormalized[m_CoordIndex[idx][i]];
glm::vec3 v = m_PointNormalized[m_CoordIndex[idx][(i + 1) % m_CoordIndex[idx].size()]];
cross_prod.x += (u.y - v.y) * (u.z + v.z);
cross_prod.y += (u.z - v.z) * (u.x + v.x);
cross_prod.z += (u.x - v.x) * (u.y + v.y);
// This method works same way
/*
cross_prod.x += (u.y * v.z) - (u.z * v.y);
cross_prod.y += (u.z * v.x) - (u.x * v.z);
cross_prod.z += (u.x * v.y) - (u.y * v.x);*/
}
float area = glm::dot( cross_prod, cross_prod );
area = fabs( area );
// Dont remmember why this code was used for..
/*
if( cross_prod[2] < 0.0 )
area = -area;
if( area < FLT_EPSILON )
area = FLT_EPSILON * 2.0f;
*/
m_PerFaceSquaredArea.push_back( area );
m_PerFaceNormalsRaw.push_back( cross_prod );
m_PerFaceNormalsRaw_X_PerFaceSquaredArea[idx] = cross_prod * area;
if( haveAlreadyNormals_from_model_file == false )
{
......@@ -396,7 +446,12 @@ void S3D_MESH::calcPerFaceNormals()
}
else
{
//DBG( printf( "Cannot calc normal idx: %u", idx ) );
DBG( printf( "Cannot calc normal idx: %u cross(%f, %f, %f) l:%f m_CoordIndex[idx].size: %u\n",
idx,
cross_prod.x, cross_prod.y, cross_prod.z,
l,
(unsigned int)m_CoordIndex[idx].size()) );
if( ( cross_prod.x > cross_prod.y ) && ( cross_prod.x > cross_prod.z ) )
{
cross_prod.x = 0.0;
......@@ -409,15 +464,21 @@ void S3D_MESH::calcPerFaceNormals()
cross_prod.y = 1.0;
cross_prod.z = 0.0;
}
else
else if( ( cross_prod.z > cross_prod.x ) && ( cross_prod.z > cross_prod.y ) )
{
cross_prod.x = 0.0;
cross_prod.y = 0.0;
cross_prod.z = 1.0;
}
else
{
cross_prod.x = 0.0;
cross_prod.y = 0.0;
cross_prod.z = 0.0;
}
}
m_PerFaceNormalsNormalized.push_back( cross_prod );
m_PerFaceNormalsNormalized[idx] = cross_prod;
}
}
}
......@@ -439,24 +500,41 @@ void S3D_MESH::calcPerPointNormals()
// Pre-allocate space for the entire vector of vertex normals so we can do parallel writes
m_PerFaceVertexNormals.resize( m_CoordIndex.size() );
// for each face A in mesh
for( unsigned int each_face_A_idx = 0; each_face_A_idx < m_CoordIndex.size(); each_face_A_idx++ )
{
m_PerFaceVertexNormals[each_face_A_idx].resize( m_CoordIndex[each_face_A_idx].size() );
}
// Initialize each vertex normal
for( unsigned int each_face_A_idx = 0; each_face_A_idx < m_CoordIndex.size(); each_face_A_idx++ )
{
glm::vec3 initVertexFaceNormal = m_PerFaceNormalsRaw_X_PerFaceSquaredArea[each_face_A_idx];
std::vector< glm::vec3 >& face_A_normals = m_PerFaceVertexNormals[each_face_A_idx];
for( unsigned int each_vert_A_idx = 0; each_vert_A_idx < m_CoordIndex[each_face_A_idx].size(); each_vert_A_idx++ )
{
face_A_normals[each_vert_A_idx] = initVertexFaceNormal;
}
}
#ifdef USE_OPENMP
#pragma omp parallel for
#endif /* USE_OPENMP */
// for each face A in mesh
for( unsigned int each_face_A_idx = 0; each_face_A_idx < m_CoordIndex.size(); each_face_A_idx++ )
{
// n = face A facet normal
std::vector< glm::vec3 >& face_A_normals = m_PerFaceVertexNormals[each_face_A_idx];
face_A_normals.resize( m_CoordIndex[each_face_A_idx].size() );
// loop through all 3 vertices
// loop through all vertices
// for each vert in face A
for( unsigned int each_vert_A_idx = 0; each_vert_A_idx < m_CoordIndex[each_face_A_idx].size(); each_vert_A_idx++ )
{
face_A_normals[each_vert_A_idx] = m_PerFaceNormalsRaw[each_face_A_idx] * (m_PerFaceSquaredArea[each_face_A_idx]);
int vertexIndex = (int)(m_CoordIndex[each_face_A_idx][each_vert_A_idx]);
int vertexIndexFromFaceA = (int)(m_CoordIndex[each_face_A_idx][each_vert_A_idx]);
glm::vec3 vector_face_A = m_PerFaceNormalsNormalized[each_face_A_idx];
// for each face B in mesh
......@@ -465,32 +543,40 @@ void S3D_MESH::calcPerPointNormals()
//if A != B { // ignore self
if( each_face_A_idx != each_face_B_idx )
{
bool addThisVertex = false;
for( unsigned int ii = 0; ii < m_CoordIndex[each_face_B_idx].size(); ii++ )
{
if( m_CoordIndex[each_face_B_idx][ii] == vertexIndex )
// Check if there is any vertice in the face B that touch the vertice in face A
if( m_CoordIndex[each_face_B_idx][ii] == vertexIndexFromFaceA )
{
addThisVertex = true;
break;
}
}
glm::vec3 vector_face_B = m_PerFaceNormalsNormalized[each_face_B_idx];
if( addThisVertex )
{
glm::vec3 vector_face_B = m_PerFaceNormalsNormalized[each_face_B_idx];
float dot_prod = glm::dot( vector_face_A, vector_face_B );
float dot_prod = glm::dot( vector_face_A, vector_face_B );
if( dot_prod > 0.05f )
face_A_normals[each_vert_A_idx] += m_PerFaceNormalsRaw_X_PerFaceSquaredArea[each_face_B_idx] * dot_prod;
if( dot_prod > 0.05f )
{
face_A_normals[each_vert_A_idx] += m_PerFaceNormalsRaw[each_face_B_idx] * (m_PerFaceSquaredArea[each_face_B_idx] * dot_prod);
// For each face, only one vertice can touch / share
// another vertice from the other face, so we exit here
break;
}
}
}
}
}
}
// normalize vertex normal
#ifdef USE_OPENMP
#pragma omp parallel for
#endif /* USE_OPENMP */
// Normalize
for( unsigned int each_face_A_idx = 0; each_face_A_idx < m_CoordIndex.size(); each_face_A_idx++ )
{
std::vector< glm::vec3 >& face_A_normals = m_PerFaceVertexNormals[each_face_A_idx];
for( unsigned int each_vert_A_idx = 0; each_vert_A_idx < m_CoordIndex[each_face_A_idx].size(); each_vert_A_idx++ )
{
float l = glm::length( face_A_normals[each_vert_A_idx] );
if( l > FLT_EPSILON ) // avoid division by zero
......
......@@ -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 );
......
......@@ -39,7 +39,7 @@
#include "modelparsers.h"
#include "vrml_aux.h"
#define BUFLINE_SIZE 512
#define BUFLINE_SIZE 32
/**
* Trace mask used to enable or disable the trace output of the VRML V2 parser code.
......@@ -50,12 +50,12 @@
static const wxChar* traceVrmlV2Parser = wxT( "KI_TRACE_VRML_V2_PARSER" );
VRML2_MODEL_PARSER::VRML2_MODEL_PARSER( S3D_MASTER* aMaster ) :
S3D_MODEL_PARSER( aMaster )
VRML2_MODEL_PARSER::VRML2_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;
}
......@@ -63,46 +63,27 @@ VRML2_MODEL_PARSER::VRML2_MODEL_PARSER( S3D_MASTER* aMaster ) :
VRML2_MODEL_PARSER::~VRML2_MODEL_PARSER()
{
for( unsigned int idx = 0; idx < childs.size(); idx++ )
{
delete childs[idx];
}
}
void VRML2_MODEL_PARSER::Load( const wxString& aFilename, double aVrmlunits_to_3Dunits )
bool VRML2_MODEL_PARSER::Load( const wxString& aFilename )
{
char text[BUFLINE_SIZE];
wxLogTrace( traceVrmlV2Parser, wxT( "Load %s" ), GetChars( aFilename ) );
wxLogTrace( traceVrmlV2Parser, wxT( "Loading: %s" ), GetChars( aFilename ) );
m_file = wxFopen( aFilename, wxT( "rt" ) );
if( m_file == NULL )
{
return;
wxLogTrace( traceVrmlV2Parser, wxT( "Failed to open file: %s" ), GetChars( aFilename ) );
return false;
}
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 );
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 );
LOCALE_IO toggle; // Temporary switch the locale to standard C to r/w floats
// Switch the locale to standard C (needed to print floating point numbers)
LOCALE_IO toggle;
childs.clear();
m_ModelParser->childs.clear();
while( GetNextTag( m_file, text, sizeof(text) ) )
{
......@@ -114,33 +95,50 @@ void VRML2_MODEL_PARSER::Load( const wxString& aFilename, double aVrmlunits_to_3
if( strcmp( text, "Transform" ) == 0 )
{
m_model = new S3D_MESH();
childs.push_back( m_model );
m_ModelParser->childs.push_back( m_model );
read_Transform();
if( read_Transform() == 0)
{
//wxLogTrace( traceVrmlV2Parser, wxT( " m_Point.size: %u" ), (unsigned int)m_model->m_Point.size() );
//wxLogTrace( traceVrmlV2Parser, wxT( " m_CoordIndex.size: %u" ), (unsigned int)m_model->m_CoordIndex.size() );
}
}
else if( strcmp( text, "DEF" ) == 0 )
{
m_model = new S3D_MESH();
childs.push_back( m_model );
m_ModelParser->childs.push_back( m_model );
read_DEF();
if( read_DEF() == 0 )
{
//wxLogTrace( traceVrmlV2Parser, wxT( " m_Point.size: %u" ), (unsigned int)m_model->m_Point.size() );
//wxLogTrace( traceVrmlV2Parser, wxT( " m_CoordIndex.size: %u" ), (unsigned int)m_model->m_CoordIndex.size() );
}
}
}
else if( strcmp( text, "Shape" ) == 0 )
{
//wxLogTrace( traceVrmlV2Parser, wxT( " Shape" ) );
fclose( m_file );
m_model = new S3D_MESH();
m_ModelParser->childs.push_back( m_model );
if( GetMaster()->IsOpenGlAllowed() )
{
for( unsigned int idx = 0; idx < childs.size(); idx++ )
{
childs[idx]->openGL_RenderAllChilds();
if( read_Shape() == 0 )
{
//wxLogTrace( traceVrmlV2Parser, wxT( " m_Point.size: %u" ), (unsigned int)m_model->m_Point.size() );
//wxLogTrace( traceVrmlV2Parser, wxT( " m_CoordIndex.size: %u" ), (unsigned int)m_model->m_CoordIndex.size() );
}
}
}
fclose( m_file );
return true;
}
int VRML2_MODEL_PARSER::read_Transform()
{
//wxLogTrace( traceVrmlV2Parser, wxT( " read_Transform" ) );
char text[BUFLINE_SIZE];
while( GetNextTag( m_file, text, sizeof(text) ) )
......@@ -158,6 +156,11 @@ int VRML2_MODEL_PARSER::read_Transform()
if( strcmp( text, "translation" ) == 0 )
{
parseVertex( m_file, m_model->m_translation );
//wxLogTrace( traceVrmlV2Parser, wxT( " translation (%f,%f,%f)" ),
// m_model->m_translation.x,
// m_model->m_translation.y,
// m_model->m_translation.z );
}
else if( strcmp( text, "rotation" ) == 0 )
{
......@@ -166,20 +169,29 @@ int VRML2_MODEL_PARSER::read_Transform()
&m_model->m_rotation[2],
&m_model->m_rotation[3] ) != 4 )
{
// !TODO: log errors
m_model->m_rotation[0] = 0.0f;
m_model->m_rotation[1] = 0.0f;
m_model->m_rotation[2] = 0.0f;
m_model->m_rotation[3] = 0.0f;
wxLogTrace( traceVrmlV2Parser, wxT( " rotation failed, setting to zeros" ) );
}
else
{
m_model->m_rotation[3] = m_model->m_rotation[3] * 180.0f / 3.14f; // !TODO: use constants or functions
}
//wxLogTrace( traceVrmlV2Parser, wxT( " rotation (%f,%f,%f,%f)" ),
// m_model->m_rotation[0],
// m_model->m_rotation[1],
// m_model->m_rotation[2],
// m_model->m_rotation[3] );
}
else if( strcmp( text, "scale" ) == 0 )
{
parseVertex( m_file, m_model->m_scale );
//wxLogTrace( traceVrmlV2Parser, wxT( " scale (%f,%f,%f)" ), m_model->m_scale.x, m_model->m_scale.y, m_model->m_scale.z );
}
else if( strcmp( text, "scaleOrientation" ) == 0 )
{
......@@ -189,16 +201,25 @@ int VRML2_MODEL_PARSER::read_Transform()
&m_model->m_scaleOrientation[2],
&m_model->m_scaleOrientation[3] ) != 4 )
{
// !TODO: log errors
m_model->m_scaleOrientation[0] = 0.0f;
m_model->m_scaleOrientation[1] = 0.0f;
m_model->m_scaleOrientation[2] = 0.0f;
m_model->m_scaleOrientation[3] = 0.0f;
wxLogTrace( traceVrmlV2Parser, wxT( " scaleOrientation failed, setting to zeros" ) );
}
//wxLogTrace( traceVrmlV2Parser, wxT( " scaleOrientation (%f,%f,%f,%f)" ),
// m_model->m_scaleOrientation[0],
// m_model->m_scaleOrientation[1],
// m_model->m_scaleOrientation[2],
// m_model->m_scaleOrientation[3] );
}
else if( strcmp( text, "center" ) == 0 )
{
parseVertex( m_file, m_model->m_center );
//wxLogTrace( traceVrmlV2Parser, wxT( " center (%f,%f,%f)" ), m_model->m_center.x, m_model->m_center.y, m_model->m_center.z );
}
else if( strcmp( text, "children" ) == 0 )
{
......@@ -227,6 +248,8 @@ int VRML2_MODEL_PARSER::read_Transform()
}
else if( strcmp( text, "Shape" ) == 0 )
{
//wxLogTrace( traceVrmlV2Parser, wxT( " Shape" ) );
S3D_MESH* parent = m_model;
S3D_MESH* new_mesh_model = new S3D_MESH();
......@@ -256,6 +279,8 @@ int VRML2_MODEL_PARSER::read_Transform()
int VRML2_MODEL_PARSER::read_DEF_Coordinate()
{
//wxLogTrace( traceVrmlV2Parser, wxT( " read_DEF_Coordinate" ) );
char text[BUFLINE_SIZE];
// Get the name of the definition.
......@@ -283,16 +308,23 @@ int VRML2_MODEL_PARSER::read_DEF_Coordinate()
}
}
wxLogTrace( traceVrmlV2Parser, wxT( " read_DEF_Coordinate failed" ) );
return -1;
}
int VRML2_MODEL_PARSER::read_DEF()
{
//wxLogTrace( traceVrmlV2Parser, wxT( " read_DEF" ) );
char text[BUFLINE_SIZE];
char tagName[BUFLINE_SIZE];
if( !GetNextTag( m_file, text, sizeof(text) ) )
if( !GetNextTag( m_file, tagName, sizeof(tagName) ) )
{
wxLogTrace( traceVrmlV2Parser, wxT( " DEF failed GetNextTag first" ) );
return -1;
}
while( GetNextTag( m_file, text, sizeof(text) ) )
{
......@@ -337,6 +369,13 @@ int VRML2_MODEL_PARSER::read_DEF()
read_Shape();
m_model = parent;
}
else
{
wxLogTrace( traceVrmlV2Parser, wxT( " DEF %s %s NotImplemented, skipping." ), tagName, text );
read_NotImplemented( m_file, '}' );
return -1;
}
}
wxLogTrace( traceVrmlV2Parser, wxT( " DEF failed" ) );
......@@ -346,6 +385,8 @@ int VRML2_MODEL_PARSER::read_DEF()
int VRML2_MODEL_PARSER::read_USE()
{
//wxLogTrace( traceVrmlV2Parser, wxT( " read_USE" ) );
char text[BUFLINE_SIZE];
// Get the name of the definition.
......@@ -373,6 +414,8 @@ int VRML2_MODEL_PARSER::read_USE()
int VRML2_MODEL_PARSER::read_Shape()
{
//wxLogTrace( traceVrmlV2Parser, wxT( " read_Shape" ) );
char text[BUFLINE_SIZE];
while( GetNextTag( m_file, text, sizeof(text) ) )
......@@ -389,7 +432,7 @@ int VRML2_MODEL_PARSER::read_Shape()
if( strcmp( text, "appearance" ) == 0 )
{
wxLogTrace( traceVrmlV2Parser, wxT( "\"appearance\" key word not supported." ) );
//wxLogTrace( traceVrmlV2Parser, wxT( " \"appearance\" key word not supported." ) );
// skip
}
else if( strcmp( text, "Appearance" ) == 0 )
......@@ -398,7 +441,7 @@ int VRML2_MODEL_PARSER::read_Shape()
}
else if( strcmp( text, "geometry" ) == 0 )
{
wxLogTrace( traceVrmlV2Parser, wxT( "\"geometry\" key word not supported." ) );
//wxLogTrace( traceVrmlV2Parser, wxT( " \"geometry\" key word not supported." ) );
// skip
}
else if( strcmp( text, "IndexedFaceSet" ) == 0 )
......@@ -423,6 +466,8 @@ int VRML2_MODEL_PARSER::read_Shape()
int VRML2_MODEL_PARSER::read_Appearance()
{
//wxLogTrace( traceVrmlV2Parser, wxT( " read_Appearance" ) );
char text[BUFLINE_SIZE];
while( GetNextTag( m_file, text, sizeof(text) ) )
......@@ -450,6 +495,8 @@ int VRML2_MODEL_PARSER::read_Appearance()
int VRML2_MODEL_PARSER::read_material()
{
//wxLogTrace( traceVrmlV2Parser, wxT( " read_material" ) );
S3D_MATERIAL* material = NULL;
char text[BUFLINE_SIZE];
......@@ -458,8 +505,8 @@ int VRML2_MODEL_PARSER::read_material()
if( strcmp( text, "Material" ) == 0 )
{
wxString mat_name;
material = new S3D_MATERIAL( GetMaster(), mat_name );
GetMaster()->Insert( material );
material = new S3D_MATERIAL( m_Master, mat_name );
m_Master->Insert( material );
m_model->m_Materials = material;
if( strcmp( text, "Material" ) == 0 )
......@@ -474,8 +521,8 @@ int VRML2_MODEL_PARSER::read_material()
wxString mat_name;
mat_name = FROM_UTF8( text );
material = new S3D_MATERIAL( GetMaster(), mat_name );
GetMaster()->Insert( material );
material = new S3D_MATERIAL( m_Master, mat_name );
m_Master->Insert( material );
m_model->m_Materials = material;
if( GetNextTag( m_file, text, sizeof(text) ) )
......@@ -494,7 +541,7 @@ int VRML2_MODEL_PARSER::read_material()
wxString mat_name;
mat_name = FROM_UTF8( text );
for( material = GetMaster()->m_Materials; material; material = material->Next() )
for( material = m_Master->m_Materials; material; material = material->Next() )
{
if( material->m_Name == mat_name )
{
......@@ -515,6 +562,8 @@ int VRML2_MODEL_PARSER::read_material()
int VRML2_MODEL_PARSER::read_Material()
{
//wxLogTrace( traceVrmlV2Parser, wxT( " read_Material" ) );
char text[BUFLINE_SIZE];
glm::vec3 vertex;
......@@ -539,7 +588,7 @@ int VRML2_MODEL_PARSER::read_Material()
{
parseVertex( m_file, vertex );
if( GetMaster()->m_use_modelfile_emissiveColor == true )
if( m_Master->m_use_modelfile_emissiveColor == true )
{
m_model->m_Materials->m_EmissiveColor.push_back( vertex );
}
......@@ -548,7 +597,7 @@ int VRML2_MODEL_PARSER::read_Material()
{
parseVertex( m_file, vertex );
if( GetMaster()->m_use_modelfile_specularColor == true )
if( m_Master->m_use_modelfile_specularColor == true )
{
m_model->m_Materials->m_SpecularColor.push_back( vertex );
}
......@@ -558,7 +607,7 @@ int VRML2_MODEL_PARSER::read_Material()
float ambientIntensity;
parseFloat( m_file, &ambientIntensity );
if( GetMaster()->m_use_modelfile_ambientIntensity == true )
if( m_Master->m_use_modelfile_ambientIntensity == true )
{
m_model->m_Materials->m_AmbientColor.push_back( glm::vec3( ambientIntensity,
ambientIntensity, ambientIntensity ) );
......@@ -569,7 +618,7 @@ int VRML2_MODEL_PARSER::read_Material()
float transparency;
parseFloat( m_file, &transparency );
if( GetMaster()->m_use_modelfile_transparency == true )
if( m_Master->m_use_modelfile_transparency == true )
{
m_model->m_Materials->m_Transparency.push_back( transparency );
}
......@@ -580,7 +629,7 @@ int VRML2_MODEL_PARSER::read_Material()
parseFloat( m_file, &shininess );
// VRML value is normalized and openGL expects a value 0 - 128
if( GetMaster()->m_use_modelfile_shininess == true )
if( m_Master->m_use_modelfile_shininess == true )
{
shininess = shininess * 128.0f;
m_model->m_Materials->m_Shininess.push_back( shininess );
......@@ -588,13 +637,15 @@ int VRML2_MODEL_PARSER::read_Material()
}
}
wxLogTrace( traceVrmlV2Parser, wxT( " Material failed\n" ) );
wxLogTrace( traceVrmlV2Parser, wxT( " Material failed" ) );
return -1;
}
int VRML2_MODEL_PARSER::read_IndexedFaceSet()
{
//wxLogTrace( traceVrmlV2Parser, wxT( " read_IndexedFaceSet" ) );
char text[BUFLINE_SIZE];
m_normalPerVertex = false;
......@@ -672,6 +723,8 @@ int VRML2_MODEL_PARSER::read_IndexedFaceSet()
int VRML2_MODEL_PARSER::read_IndexedLineSet()
{
//wxLogTrace( traceVrmlV2Parser, wxT( " read_IndexedLineSet" ) );
char text[BUFLINE_SIZE];
while( GetNextTag( m_file, text, sizeof(text) ) )
......@@ -696,6 +749,8 @@ int VRML2_MODEL_PARSER::read_IndexedLineSet()
int VRML2_MODEL_PARSER::read_colorIndex()
{
//wxLogTrace( traceVrmlV2Parser, wxT( " read_colorIndex" ) );
m_model->m_MaterialIndex.clear();
if( colorPerVertex == true )
......@@ -726,12 +781,16 @@ int VRML2_MODEL_PARSER::read_colorIndex()
}
}
//wxLogTrace( traceVrmlV2Parser, wxT( " read_colorIndex m_MaterialIndex.size: %u" ), (unsigned int)m_model->m_MaterialIndex.size() );
return 0;
}
int VRML2_MODEL_PARSER::read_NormalIndex()
{
//wxLogTrace( traceVrmlV2Parser, wxT( " read_NormalIndex" ) );
m_model->m_NormalIndex.clear();
glm::ivec3 coord;
......@@ -754,12 +813,16 @@ int VRML2_MODEL_PARSER::read_NormalIndex()
}
}
//wxLogTrace( traceVrmlV2Parser, wxT( " read_NormalIndex m_NormalIndex.size: %u" ), (unsigned int)m_model->m_NormalIndex.size() );
return 0;
}
int VRML2_MODEL_PARSER::read_coordIndex()
{
//wxLogTrace( traceVrmlV2Parser, wxT( " read_coordIndex" ) );
m_model->m_CoordIndex.clear();
glm::ivec3 coord;
......@@ -782,6 +845,8 @@ int VRML2_MODEL_PARSER::read_coordIndex()
}
}
//wxLogTrace( traceVrmlV2Parser, wxT( " read_coordIndex m_CoordIndex.size: %u" ), (unsigned int)m_model->m_CoordIndex.size() );
return 0;
}
......@@ -808,7 +873,7 @@ int VRML2_MODEL_PARSER::read_Color()
}
}
wxLogTrace( traceVrmlV2Parser, wxT( " read_Color failed" ) );
//wxLogTrace( traceVrmlV2Parser, wxT( " read_Color failed" ) );
return -1;
}
......@@ -826,6 +891,11 @@ int VRML2_MODEL_PARSER::read_Normal()
if( *text == '}' )
{
//if( m_normalPerVertex == false )
// wxLogTrace( traceVrmlV2Parser, wxT( " read_Normal m_PerFaceNormalsNormalized.size: %u" ), (unsigned int)m_model->m_PerFaceNormalsNormalized.size() );
//else
// wxLogTrace( traceVrmlV2Parser, wxT( " read_Normal m_PerVertexNormalsNormalized.size: %u" ), (unsigned int)m_model->m_PerVertexNormalsNormalized.size() );
return 0;
}
......@@ -842,6 +912,7 @@ int VRML2_MODEL_PARSER::read_Normal()
}
}
wxLogTrace( traceVrmlV2Parser, wxT( " read_Normal failed" ) );
return -1;
}
......@@ -859,6 +930,7 @@ int VRML2_MODEL_PARSER::read_Coordinate()
if( *text == '}' )
{
//wxLogTrace( traceVrmlV2Parser, wxT( " read_Coordinate m_Point.size: %u" ), (unsigned int)m_model->m_Point.size() );
return 0;
}
......@@ -868,6 +940,7 @@ int VRML2_MODEL_PARSER::read_Coordinate()
}
}
wxLogTrace( traceVrmlV2Parser, wxT( " read_Coordinate failed" ) );
return -1;
}
......@@ -885,11 +958,15 @@ int VRML2_MODEL_PARSER::read_CoordinateDef()
continue;
if( *text == '}' )
{
//wxLogTrace( traceVrmlV2Parser, wxT( " read_CoordinateDef m_Point.size: %u" ), (unsigned int)m_model->m_Point.size() );
return 0;
}
if( strcmp( text, "point" ) == 0 )
parseVertexList( m_file, m_model->m_Point );
}
wxLogTrace( traceVrmlV2Parser, wxT( " read_CoordinateDef failed" ) );
return -1;
}
......@@ -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