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

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

parent c0518db7
......@@ -526,7 +526,7 @@ void EDA_3D_CANVAS::Redraw()
{
glEnable( GL_BLEND );
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 );
glDisable( GL_COLOR_MATERIAL );
glEnable( GL_TEXTURE_2D );
......
......@@ -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() )
{
case 3:
......
......@@ -211,17 +211,19 @@ private:
bool m_normalPerVertex;
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;
wxFileName m_Filename;
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_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_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_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
bool m_discardLastGeometry; ///< If true, it should not store the latest loaded geometry (used to discard IndexedLineSet, but load it)
};
......
......@@ -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 )
{
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)) &&
......@@ -288,6 +289,7 @@ int VRML2_MODEL_PARSER::loadFileModel( S3D_MESH *aTransformationModel )
}
else
{
wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "loadFileModel: forced added %s group" ), groupName );
m_ModelParser->childs.push_back( ptrModel );
}
}
......@@ -471,27 +473,36 @@ int VRML2_MODEL_PARSER::read_Transform()
if( read_Shape() == 0 )
{
m_model = save_ptr;
if( ((m_model->m_Point.size() == 0) || (m_model->m_CoordIndex.size() == 0)) &&
(m_model->childs.size() == 0) )
if( m_discardLastGeometry == false )
{
delete m_model;
wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_Transform: Shape, skipping model with no points or childs" ) );
m_model = save_ptr;
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
{
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() );
delete m_model;
parent->childs.push_back( m_model );
wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_Transform: Shape, discard child." ) );
}
}
else
{
delete m_model;
delete m_model;
}
m_model = parent;
......@@ -692,7 +703,10 @@ int VRML2_MODEL_PARSER::read_DEF_Coordinate()
int retVal = read_CoordinateDef();
if( retVal == 0 )
{
m_defCoordinateMap.insert( std::make_pair( coordinateName, m_model->m_Point ) );
wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_DEF_Coordinate insert %s" ), coordinateName );
}
debug_exit();
return retVal;
......@@ -801,6 +815,7 @@ int VRML2_MODEL_PARSER::read_DEF()
}
else if( strcmp( text, "IndexedFaceSet" ) == 0 )
{
m_discardLastGeometry = false;
read_IndexedFaceSet();
}
else if( strcmp( text, "Group" ) == 0 )
......@@ -882,11 +897,13 @@ int VRML2_MODEL_PARSER::read_IndexedFaceSet_USE()
if( coordinate == m_defCoordinateMap.end() )
{
debug_exit();
wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "USE: coordinate %s not previously defined "
"in a DEF section." ), text );
wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_IndexedFaceSet_USE: coordinate %s not previously defined "
"in a DEF section." ), text );
return -1;
}
wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_IndexedFaceSet_USE %s" ), text );
m_model->m_Point = coordinate->second;
debug_exit();
return 0;
......@@ -924,10 +941,12 @@ int VRML2_MODEL_PARSER::read_Shape()
}
else if( strcmp( text, "IndexedFaceSet" ) == 0 )
{
m_discardLastGeometry = false;
read_IndexedFaceSet();
}
else if( strcmp( text, "IndexedLineSet" ) == 0 )
{
m_discardLastGeometry = true;
read_IndexedLineSet();
}
else
......@@ -977,11 +996,20 @@ int VRML2_MODEL_PARSER::read_geometry()
}
else if( strcmp( text, "IndexedFaceSet" ) == 0 )
{
m_discardLastGeometry = false;
int ret = read_IndexedFaceSet();
debug_exit();
wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_geometry exit, after IndexedFaceSet" ) );
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
{
wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_geometry: %s NotImplemented" ), text );
......
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