3D viewer: fix an issue introduced in previous commit. Add an improvement.

This commit is contained in:
unknown 2015-03-29 18:13:58 +02:00 committed by jean-pierre charras
parent c0518db743
commit 34dfbc3306
4 changed files with 77 additions and 21 deletions

View File

@ -526,7 +526,7 @@ void EDA_3D_CANVAS::Redraw()
{ {
glEnable( GL_BLEND ); glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glColor4f( 1.0, 1.0, 1.0, 0.85f ); glColor4f( 1.0, 1.0, 1.0, 0.75f );
glEnable( GL_CULL_FACE ); glEnable( GL_CULL_FACE );
glDisable( GL_COLOR_MATERIAL ); glDisable( GL_COLOR_MATERIAL );
glEnable( GL_TEXTURE_2D ); glEnable( GL_TEXTURE_2D );

View File

@ -262,6 +262,32 @@ void S3D_MESH::openGL_Render( bool aIsRenderingJustNonTransparentObjects,
} }
} }
/*
#if defined(DEBUG)
// Debug Normals
glColor4f( 1.0, 0.0, 1.0, 1.0 );
for( unsigned int ii = 0; ii < m_CoordIndex[idx].size(); ii++ )
{
// Flat
if( m_PerFaceNormalsNormalized.size() > 0 )
{
S3D_VERTEX normal = m_PerFaceNormalsNormalized[idx];
glNormal3fv( &normal.x );
for( unsigned int ii = 0; ii < m_CoordIndex[idx].size(); ii++ )
{
glBegin( GL_LINES );
glm::vec3 point = m_Point[m_CoordIndex[idx][ii]];
glVertex3fv( &point.x );
point += normal;
glVertex3fv( &point.x );
glEnd();
}
}
}
#endif
*/
switch( m_CoordIndex[idx].size() ) switch( m_CoordIndex[idx].size() )
{ {
case 3: case 3:

View File

@ -211,17 +211,19 @@ private:
bool m_normalPerVertex; bool m_normalPerVertex;
bool colorPerVertex; bool colorPerVertex;
S3D_MESH* m_model; ///< It stores the current model that the parsing is adding data S3D_MESH* m_model; ///< It stores the current model that the parsing is adding data
FILE* m_file; FILE* m_file;
wxFileName m_Filename; wxFileName m_Filename;
VRML2_COORDINATE_MAP m_defCoordinateMap; VRML2_COORDINATE_MAP m_defCoordinateMap;
VRML2_DEF_GROUP_MAP m_defGroupMap; ///< Stores a list of labels for groups and meshs that will be used later by the USE keyword VRML2_DEF_GROUP_MAP m_defGroupMap; ///< Stores a list of labels for groups and meshs that will be used later by the USE keyword
S3D_MODEL_PARSER* m_ModelParser; S3D_MODEL_PARSER* m_ModelParser;
S3D_MASTER* m_Master; S3D_MASTER* m_Master;
wxString m_debugSpacer; ///< Used to give identation space wxString m_debugSpacer; ///< Used to give identation space
int m_counter_DEF_GROUP; ///< Counts the number of DEF * GROUPS used int m_counter_DEF_GROUP; ///< Counts the number of DEF * GROUPS used
int m_counter_USE_GROUP; ///< Counts the number of USE * used, in the end, if m_counter_DEF_GROUP > 0 and m_counter_USE_GROUP == 0 then it will add the first group with childs int m_counter_USE_GROUP; ///< Counts the number of USE * used, in the end, if m_counter_DEF_GROUP > 0 and m_counter_USE_GROUP == 0 then it will add the first group with childs
bool m_discardLastGeometry; ///< If true, it should not store the latest loaded geometry (used to discard IndexedLineSet, but load it)
}; };

View File

@ -277,7 +277,8 @@ int VRML2_MODEL_PARSER::loadFileModel( S3D_MESH *aTransformationModel )
{ {
for( VRML2_DEF_GROUP_MAP::iterator groupIt = m_defGroupMap.begin(); groupIt!=m_defGroupMap.end(); ++groupIt ) for( VRML2_DEF_GROUP_MAP::iterator groupIt = m_defGroupMap.begin(); groupIt!=m_defGroupMap.end(); ++groupIt )
{ {
S3D_MESH* ptrModel = groupIt->second; wxString groupName = groupIt->first;
S3D_MESH* ptrModel = groupIt->second;
if( ((ptrModel->m_Point.size() == 0) || (ptrModel->m_CoordIndex.size() == 0)) && if( ((ptrModel->m_Point.size() == 0) || (ptrModel->m_CoordIndex.size() == 0)) &&
@ -288,6 +289,7 @@ int VRML2_MODEL_PARSER::loadFileModel( S3D_MESH *aTransformationModel )
} }
else else
{ {
wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "loadFileModel: forced added %s group" ), groupName );
m_ModelParser->childs.push_back( ptrModel ); m_ModelParser->childs.push_back( ptrModel );
} }
} }
@ -471,27 +473,36 @@ int VRML2_MODEL_PARSER::read_Transform()
if( read_Shape() == 0 ) if( read_Shape() == 0 )
{ {
m_model = save_ptr; if( m_discardLastGeometry == false )
if( ((m_model->m_Point.size() == 0) || (m_model->m_CoordIndex.size() == 0)) &&
(m_model->childs.size() == 0) )
{ {
delete m_model; m_model = save_ptr;
wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_Transform: Shape, skipping model with no points or childs" ) );
if( ((m_model->m_Point.size() == 0) || (m_model->m_CoordIndex.size() == 0)) &&
(m_model->childs.size() == 0) )
{
delete m_model;
wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_Transform: Shape, skipping model with no points or childs" ) );
}
else
{
wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_Transform: Shape, Add child model with %lu points, %lu coordIndex, %lu childs." ),
m_model->m_Point.size(),
m_model->m_CoordIndex.size(),
m_model->childs.size() );
parent->childs.push_back( m_model );
}
} }
else else
{ {
wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_Transform: Shape, Add child model with %lu points, %lu coordIndex, %lu childs." ), delete m_model;
m_model->m_Point.size(),
m_model->m_CoordIndex.size(),
m_model->childs.size() );
parent->childs.push_back( m_model ); wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_Transform: Shape, discard child." ) );
} }
} }
else else
{ {
delete m_model; delete m_model;
} }
m_model = parent; m_model = parent;
@ -692,7 +703,10 @@ int VRML2_MODEL_PARSER::read_DEF_Coordinate()
int retVal = read_CoordinateDef(); int retVal = read_CoordinateDef();
if( retVal == 0 ) if( retVal == 0 )
{
m_defCoordinateMap.insert( std::make_pair( coordinateName, m_model->m_Point ) ); m_defCoordinateMap.insert( std::make_pair( coordinateName, m_model->m_Point ) );
wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_DEF_Coordinate insert %s" ), coordinateName );
}
debug_exit(); debug_exit();
return retVal; return retVal;
@ -801,6 +815,7 @@ int VRML2_MODEL_PARSER::read_DEF()
} }
else if( strcmp( text, "IndexedFaceSet" ) == 0 ) else if( strcmp( text, "IndexedFaceSet" ) == 0 )
{ {
m_discardLastGeometry = false;
read_IndexedFaceSet(); read_IndexedFaceSet();
} }
else if( strcmp( text, "Group" ) == 0 ) else if( strcmp( text, "Group" ) == 0 )
@ -882,11 +897,13 @@ int VRML2_MODEL_PARSER::read_IndexedFaceSet_USE()
if( coordinate == m_defCoordinateMap.end() ) if( coordinate == m_defCoordinateMap.end() )
{ {
debug_exit(); debug_exit();
wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "USE: coordinate %s not previously defined " wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_IndexedFaceSet_USE: coordinate %s not previously defined "
"in a DEF section." ), text ); "in a DEF section." ), text );
return -1; return -1;
} }
wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_IndexedFaceSet_USE %s" ), text );
m_model->m_Point = coordinate->second; m_model->m_Point = coordinate->second;
debug_exit(); debug_exit();
return 0; return 0;
@ -924,10 +941,12 @@ int VRML2_MODEL_PARSER::read_Shape()
} }
else if( strcmp( text, "IndexedFaceSet" ) == 0 ) else if( strcmp( text, "IndexedFaceSet" ) == 0 )
{ {
m_discardLastGeometry = false;
read_IndexedFaceSet(); read_IndexedFaceSet();
} }
else if( strcmp( text, "IndexedLineSet" ) == 0 ) else if( strcmp( text, "IndexedLineSet" ) == 0 )
{ {
m_discardLastGeometry = true;
read_IndexedLineSet(); read_IndexedLineSet();
} }
else else
@ -977,11 +996,20 @@ int VRML2_MODEL_PARSER::read_geometry()
} }
else if( strcmp( text, "IndexedFaceSet" ) == 0 ) else if( strcmp( text, "IndexedFaceSet" ) == 0 )
{ {
m_discardLastGeometry = false;
int ret = read_IndexedFaceSet(); int ret = read_IndexedFaceSet();
debug_exit(); debug_exit();
wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_geometry exit, after IndexedFaceSet" ) ); wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_geometry exit, after IndexedFaceSet" ) );
return ret; return ret;
} }
else if( strcmp( text, "IndexedLineSet" ) == 0 )
{
m_discardLastGeometry = true;
int ret = read_IndexedLineSet();
debug_exit();
wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_geometry exit, after IndexedLineSet" ) );
return ret;
}
else else
{ {
wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_geometry: %s NotImplemented" ), text ); wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_geometry: %s NotImplemented" ), text );