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

3D viewer bug fixes

parent 7b936f4d
...@@ -52,8 +52,8 @@ void CheckGLError(const char *aFileName, int aLineNumber) ...@@ -52,8 +52,8 @@ void CheckGLError(const char *aFileName, int aLineNumber)
} }
errLast = err; errLast = err;
wxLogError( wxT( "OpenGL error %d\nAt: %s, line: %d" ), err, aFileName, aLineNumber ); wxLogError( wxT( "OpenGL error %d At: %s, line: %d" ), err, GetChars( FROM_UTF8( aFileName ) ), aLineNumber );
} }
} }
......
...@@ -531,7 +531,6 @@ void EDA_3D_CANVAS::Redraw() ...@@ -531,7 +531,6 @@ void EDA_3D_CANVAS::Redraw()
glBindTexture( GL_TEXTURE_2D, m_text_fake_shadow_back ); glBindTexture( GL_TEXTURE_2D, m_text_fake_shadow_back );
glCallList( m_glLists[GL_ID_SHADOW_BACK] ); glCallList( m_glLists[GL_ID_SHADOW_BACK] );
} }
glColor4f( 1.0, 1.0, 1.0, 1.0 ); glColor4f( 1.0, 1.0, 1.0, 1.0 );
glEnable( GL_DEPTH_TEST ); glEnable( GL_DEPTH_TEST );
......
...@@ -172,9 +172,11 @@ void Draw3D_SolidHorizontalPolyPolygons( const CPOLYGONS_LIST& aPolysList, ...@@ -172,9 +172,11 @@ void Draw3D_SolidHorizontalPolyPolygons( const CPOLYGONS_LIST& aPolysList,
// Draw solid areas contained in this list // Draw solid areas contained in this list
CPOLYGONS_LIST polylist = aPolysList; // temporary copy for gluTessVertex CPOLYGONS_LIST polylist = aPolysList; // temporary copy for gluTessVertex
int startContour;
for( int side = 0; side < 2; side++ ) for( int side = 0; side < 2; side++ )
{ {
int startContour = 1; startContour = 1;
for( unsigned ii = 0; ii < polylist.GetCornersCount(); ii++ ) for( unsigned ii = 0; ii < polylist.GetCornersCount(); ii++ )
{ {
...@@ -217,6 +219,12 @@ void Draw3D_SolidHorizontalPolyPolygons( const CPOLYGONS_LIST& aPolysList, ...@@ -217,6 +219,12 @@ void Draw3D_SolidHorizontalPolyPolygons( const CPOLYGONS_LIST& aPolysList,
SetNormalZneg(); SetNormalZneg();
} }
if( startContour == 0 )
{
gluTessEndContour( tess );
gluTessEndPolygon( tess );
}
gluDeleteTess( tess ); gluDeleteTess( tess );
if( aThickness == 0 ) if( aThickness == 0 )
......
...@@ -121,7 +121,7 @@ void S3D_MESH::openGL_Render() ...@@ -121,7 +121,7 @@ void S3D_MESH::openGL_Render()
{ {
if( m_Materials ) if( m_Materials )
{ {
m_Materials->SetOpenGLMaterial(m_MaterialIndex[idx]); m_Materials->SetOpenGLMaterial( m_MaterialIndex[idx] );
} }
} }
...@@ -136,7 +136,7 @@ void S3D_MESH::openGL_Render() ...@@ -136,7 +136,7 @@ void S3D_MESH::openGL_Render()
if( m_PerVertexNormalsNormalized.size() > 0 ) if( m_PerVertexNormalsNormalized.size() > 0 )
{ {
for(unsigned int ii = 0; ii < m_CoordIndex[idx].size(); ii++ ) for( unsigned int ii = 0; ii < m_CoordIndex[idx].size(); ii++ )
{ {
glm::vec3 normal = m_PerVertexNormalsNormalized[m_NormalIndex[idx][ii]]; glm::vec3 normal = m_PerVertexNormalsNormalized[m_NormalIndex[idx][ii]];
glNormal3fv( &normal.x ); glNormal3fv( &normal.x );
...@@ -211,9 +211,12 @@ void S3D_MESH::calcPointNormalized () ...@@ -211,9 +211,12 @@ void S3D_MESH::calcPointNormalized ()
p = m_Point[i] * biggerPoint; p = m_Point[i] * biggerPoint;
m_PointNormalized.push_back( p ); m_PointNormalized.push_back( p );
} }
//DBG( printf("m_Point.size %u\n", m_Point.size()) );
} }
bool IsClockwise(glm::vec3 v0, glm::vec3 v1, glm::vec3 v2)
bool IsClockwise( glm::vec3 v0, glm::vec3 v1, glm::vec3 v2 )
{ {
double sum = 0.0; double sum = 0.0;
...@@ -253,6 +256,9 @@ void S3D_MESH::calcPerFaceNormals () ...@@ -253,6 +256,9 @@ void S3D_MESH::calcPerFaceNormals ()
m_PerFaceNormalsRaw.clear(); m_PerFaceNormalsRaw.clear();
m_PerFaceSquaredArea.clear(); m_PerFaceSquaredArea.clear();
//DBG( printf("m_CoordIndex.size %u\n", m_CoordIndex.size()) );
//DBG( printf("m_PointNormalized.size %u\n", m_PointNormalized.size()) );
for( unsigned int idx = 0; idx < m_CoordIndex.size(); idx++ ) for( unsigned int idx = 0; idx < m_CoordIndex.size(); idx++ )
{ {
...@@ -289,7 +295,7 @@ void S3D_MESH::calcPerFaceNormals () ...@@ -289,7 +295,7 @@ void S3D_MESH::calcPerFaceNormals ()
area = -area; area = -area;
} }
if (area < FLT_EPSILON) if( area < FLT_EPSILON )
{ {
area = FLT_EPSILON * 2.0f; area = FLT_EPSILON * 2.0f;
} }
...@@ -311,10 +317,10 @@ void S3D_MESH::calcPerFaceNormals () ...@@ -311,10 +317,10 @@ void S3D_MESH::calcPerFaceNormals ()
else else
{ {
// Cannot calc normal // Cannot calc normal
if( (cross_prod.x > cross_prod.y) && (cross_prod.x > cross_prod.z)) if( ( cross_prod.x > cross_prod.y ) && ( cross_prod.x > cross_prod.z ) )
{ {
cross_prod.x = 1.0; cross_prod.y = 0.0; cross_prod.z = 0.0; cross_prod.x = 1.0; cross_prod.y = 0.0; cross_prod.z = 0.0;
} else if( (cross_prod.y > cross_prod.x) && (cross_prod.y > cross_prod.z)) } else if( ( cross_prod.y > cross_prod.x ) && ( cross_prod.y > cross_prod.z ))
{ {
cross_prod.x = 0.0; cross_prod.y = 1.0; cross_prod.z = 0.0; cross_prod.x = 0.0; cross_prod.y = 1.0; cross_prod.z = 0.0;
} else } else
...@@ -363,17 +369,19 @@ void S3D_MESH::calcPerPointNormals () ...@@ -363,17 +369,19 @@ void S3D_MESH::calcPerPointNormals ()
{ {
face_A_normals[each_vert_A_idx] = m_PerFaceNormalsRaw[each_face_A_idx] * (m_PerFaceSquaredArea[each_face_A_idx]); face_A_normals[each_vert_A_idx] = m_PerFaceNormalsRaw[each_face_A_idx] * (m_PerFaceSquaredArea[each_face_A_idx]);
// for each face A in mesh int vertexIndex = (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
for( unsigned int each_face_B_idx = 0; each_face_B_idx < m_CoordIndex.size(); each_face_B_idx++ ) for( unsigned int each_face_B_idx = 0; each_face_B_idx < m_CoordIndex.size(); each_face_B_idx++ )
{ {
//if A != B { // ignore self //if A != B { // ignore self
if ( each_face_A_idx != each_face_B_idx) if ( each_face_A_idx != each_face_B_idx)
{ {
if( (m_CoordIndex[each_face_B_idx][0] == (int)(m_CoordIndex[each_face_A_idx][each_vert_A_idx])) || if( (m_CoordIndex[each_face_B_idx][0] == vertexIndex) ||
(m_CoordIndex[each_face_B_idx][1] == (int)(m_CoordIndex[each_face_A_idx][each_vert_A_idx])) || (m_CoordIndex[each_face_B_idx][1] == vertexIndex) ||
(m_CoordIndex[each_face_B_idx][2] == (int)(m_CoordIndex[each_face_A_idx][each_vert_A_idx])) ) (m_CoordIndex[each_face_B_idx][2] == vertexIndex) )
{ {
glm::vec3 vector_face_A = m_PerFaceNormalsNormalized[each_face_A_idx];
glm::vec3 vector_face_B = m_PerFaceNormalsNormalized[each_face_B_idx]; 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);
......
...@@ -80,7 +80,6 @@ void VRML2_MODEL_PARSER::Load( const wxString aFilename ) ...@@ -80,7 +80,6 @@ void VRML2_MODEL_PARSER::Load( const wxString aFilename )
#define SCALE_3D_CONV ((IU_PER_MILS * 1000.0f) / UNITS3D_TO_UNITSPCB) #define SCALE_3D_CONV ((IU_PER_MILS * 1000.0f) / UNITS3D_TO_UNITSPCB)
//glPushMatrix();
glTranslatef( matPos.x * SCALE_3D_CONV, matPos.y * SCALE_3D_CONV, matPos.z * SCALE_3D_CONV ); 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.z, 0.0f, 0.0f, 1.0f );
...@@ -140,7 +139,7 @@ int VRML2_MODEL_PARSER::read_Transform() ...@@ -140,7 +139,7 @@ int VRML2_MODEL_PARSER::read_Transform()
{ {
char text[128]; char text[128];
///DBG( printf( "Transform\n" ) ); //DBG( printf( "Transform\n" ) );
while( GetNextTag( m_file, text ) ) while( GetNextTag( m_file, text ) )
{ {
...@@ -204,7 +203,7 @@ int VRML2_MODEL_PARSER::read_Transform() ...@@ -204,7 +203,7 @@ int VRML2_MODEL_PARSER::read_Transform()
read_DEF(); read_DEF();
} else } else
{ {
//DBG( printf( " %s NotImplemented\n", text ) ); DBG( printf( " %s NotImplemented\n", text ) );
read_NotImplemented( m_file, '}' ); read_NotImplemented( m_file, '}' );
} }
} }
...@@ -264,7 +263,7 @@ int VRML2_MODEL_PARSER::read_DEF() ...@@ -264,7 +263,7 @@ int VRML2_MODEL_PARSER::read_DEF()
} }
} }
//DBG( printf( " DEF failed\n" ) ); DBG( printf( " DEF failed\n" ) );
return -1; return -1;
} }
...@@ -302,12 +301,12 @@ int VRML2_MODEL_PARSER::read_Shape() ...@@ -302,12 +301,12 @@ int VRML2_MODEL_PARSER::read_Shape()
read_IndexedFaceSet(); read_IndexedFaceSet();
} else } else
{ {
//DBG( printf( " %s NotImplemented\n", text ) ); DBG( printf( " %s NotImplemented\n", text ) );
read_NotImplemented( m_file, '}' ); read_NotImplemented( m_file, '}' );
} }
} }
//DBG( printf( " Shape failed\n") ); DBG( printf( " Shape failed\n") );
return -1; return -1;
} }
...@@ -336,7 +335,7 @@ int VRML2_MODEL_PARSER::read_Appearance() ...@@ -336,7 +335,7 @@ int VRML2_MODEL_PARSER::read_Appearance()
} }
} }
//DBG( printf( " Appearance failed\n") ); DBG( printf( " Appearance failed\n") );
return -1; return -1;
} }
...@@ -407,12 +406,12 @@ int VRML2_MODEL_PARSER::read_material() ...@@ -407,12 +406,12 @@ int VRML2_MODEL_PARSER::read_material()
return 0; return 0;
} }
} }
//DBG( printf( " read_material error: material not found\n" ) ); DBG( printf( " read_material error: material not found\n" ) );
} }
} }
} }
//DBG( printf( " failed material\n") ); DBG( printf( " failed material\n") );
return -1; return -1;
} }
......
...@@ -72,20 +72,23 @@ void X3D_MODEL_PARSER::Load( const wxString aFilename ) ...@@ -72,20 +72,23 @@ void X3D_MODEL_PARSER::Load( const wxString aFilename )
float vrmlunits_to_3Dunits = g_Parm_3D_Visu.m_BiuTo3Dunits * UNITS3D_TO_UNITSPCB; float vrmlunits_to_3Dunits = g_Parm_3D_Visu.m_BiuTo3Dunits * UNITS3D_TO_UNITSPCB;
glScalef( vrmlunits_to_3Dunits, vrmlunits_to_3Dunits, vrmlunits_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 matScale( GetMaster()->m_MatScale.x, GetMaster()->m_MatScale.y,
glm::vec3 matRot( GetMaster()->m_MatRotation.x, GetMaster()->m_MatRotation.y, GetMaster()->m_MatRotation.z ); GetMaster()->m_MatScale.z );
glm::vec3 matPos( GetMaster()->m_MatPosition.x, GetMaster()->m_MatPosition.y, GetMaster()->m_MatPosition.z ); glm::vec3 matRot( GetMaster()->m_MatRotation.x, GetMaster()->m_MatRotation.y,
GetMaster()->m_MatRotation.z );
glm::vec3 matPos( GetMaster()->m_MatPosition.x, GetMaster()->m_MatPosition.y,
GetMaster()->m_MatPosition.z );
#define SCALE_3D_CONV ((IU_PER_MILS * 1000.0f) / UNITS3D_TO_UNITSPCB) #define SCALE_3D_CONV ((IU_PER_MILS * 1000.0f) / UNITS3D_TO_UNITSPCB)
//glPushMatrix();
glTranslatef( matPos.x * SCALE_3D_CONV, matPos.y * SCALE_3D_CONV, matPos.z * SCALE_3D_CONV ); 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.z, 0.0f, 0.0f, 1.0f );
glRotatef(-matRot.y, 0.0f, 1.0f, 0.0f ); glRotatef(-matRot.y, 0.0f, 1.0f, 0.0f );
glRotatef(-matRot.x, 1.0f, 0.0f, 0.0f ); glRotatef(-matRot.x, 1.0f, 0.0f, 0.0f );
glScalef( matScale.x, matScale.y, matScale.z ); glScalef( matScale.x, matScale.y, matScale.z );
// Switch the locale to standard C (needed to print floating point numbers) // Switch the locale to standard C (needed to print floating point numbers)
...@@ -247,25 +250,26 @@ void X3D_MODEL_PARSER::readMaterial( wxXmlNode* aMatNode ) ...@@ -247,25 +250,26 @@ void X3D_MODEL_PARSER::readMaterial( wxXmlNode* aMatNode )
color ) ) color ) )
{ {
DBG( printf("diffuseColor parsing error") ); DBG( printf("diffuseColor parsing error") );
} else }
else
{ {
// Do not use this diffuse color m_model->m_Materials->m_DiffuseColor.push_back( color );
} }
if( !parseDoubleTriplet( properties[ wxT( "specularColor" ) ], if( !parseDoubleTriplet( properties[ wxT( "specularColor" ) ], color ) )
color ) )
{ {
DBG( printf("specularColor parsing error") ); DBG( printf("specularColor parsing error") );
} else }
else
{ {
m_model->m_Materials->m_SpecularColor.push_back( color ); m_model->m_Materials->m_SpecularColor.push_back( color );
} }
if( !parseDoubleTriplet( properties[ wxT( "emissiveColor" ) ], if( !parseDoubleTriplet( properties[ wxT( "emissiveColor" ) ], color ) )
color ) )
{ {
DBG( printf("emissiveColor parsing error") ); DBG( printf("emissiveColor parsing error") );
} else }
else
{ {
m_model->m_Materials->m_EmissiveColor.push_back( color ); m_model->m_Materials->m_EmissiveColor.push_back( color );
} }
...@@ -334,12 +338,12 @@ void X3D_MODEL_PARSER::readMaterial( wxXmlNode* aMatNode ) ...@@ -334,12 +338,12 @@ void X3D_MODEL_PARSER::readMaterial( wxXmlNode* aMatNode )
material->m_SpecularColor[0].x, material->m_SpecularColor[0].x,
material->m_SpecularColor[0].y, material->m_SpecularColor[0].y,
material->m_SpecularColor[0].z ) ); material->m_SpecularColor[0].z ) );
/*
vrml_material.Append( wxString::Format( wxT( "diffuseColor %f %f %f\n" ), vrml_material.Append( wxString::Format( wxT( "diffuseColor %f %f %f\n" ),
material->m_DiffuseColor[0].x, material->m_DiffuseColor[0].x,
material->m_DiffuseColor[0].y, material->m_DiffuseColor[0].y,
material->m_DiffuseColor[0].z ) ); material->m_DiffuseColor[0].z ) );
*/
vrml_material.Append( wxString::Format( wxT( "emissiveColor %f %f %f\n" ), vrml_material.Append( wxString::Format( wxT( "emissiveColor %f %f %f\n" ),
material->m_EmissiveColor[0].x, material->m_EmissiveColor[0].x,
material->m_EmissiveColor[0].y, material->m_EmissiveColor[0].y,
...@@ -505,8 +509,6 @@ void X3D_MODEL_PARSER::readIndexedFaceSet( wxXmlNode* aFaceNode, ...@@ -505,8 +509,6 @@ void X3D_MODEL_PARSER::readIndexedFaceSet( wxXmlNode* aFaceNode,
point.y += translation.y; point.y += translation.y;
point.z += translation.z; point.z += translation.z;
//triplets.push_back(point);
m_model->m_Point.push_back( point ); m_model->m_Point.push_back( point );
// VRML // VRML
...@@ -522,44 +524,49 @@ void X3D_MODEL_PARSER::readIndexedFaceSet( wxXmlNode* aFaceNode, ...@@ -522,44 +524,49 @@ void X3D_MODEL_PARSER::readIndexedFaceSet( wxXmlNode* aFaceNode,
NODE_LIST color; NODE_LIST color;
GetChildsByName( aFaceNode, wxT( "Color" ), color); GetChildsByName( aFaceNode, wxT( "Color" ), color);
PROPERTY_MAP color_properties; // Some models lack color information, need to handle this safely
// IndexedFaceSet has one Coordinate child node if( !color.empty() )
GetNodeProperties( color[0], color_properties ); {
PROPERTY_MAP color_properties;
// IndexedFaceSet has one Coordinate child node
GetNodeProperties( color[0], color_properties );
// Save points to vector as doubles // Save points to vector as doubles
wxStringTokenizer colorpoint_tokens( color_properties[ wxT("color") ] ); wxStringTokenizer colorpoint_tokens( color_properties[ wxT("color") ] );
double color_point = 0.0; double color_point = 0.0;
while( colorpoint_tokens.HasMoreTokens() ) while( colorpoint_tokens.HasMoreTokens() )
{
if( colorpoint_tokens.GetNextToken().ToDouble( &color_point ) )
{ {
color_points.push_back( color_point ); if( colorpoint_tokens.GetNextToken().ToDouble( &color_point ) )
{
color_points.push_back( color_point );
}
else
{
wxLogError( wxT( "Error converting to double" ) );
}
} }
else
if( color_points.size() % 3 != 0 )
{ {
wxLogError( wxT( "Error converting to double" ) ); DBG( printf( "Number of points is incorrect" ) );
return;
} }
}
if( color_points.size() % 3 != 0 ) /* Create 3D face color from 3 color points
{ */
DBG( printf( "Number of points is incorrect" ) ); m_model->m_Materials->m_DiffuseColor.clear();
return; for( unsigned id = 0; id < color_points.size() / 3; id++ )
} {
m_model->m_MaterialIndex.push_back( id );
/* Create 3D face color from 3 color points
*/
for( unsigned id = 0; id < color_points.size() / 3; id++ )
{
m_model->m_MaterialIndex.push_back( id );
int color_triplet_indx = id * 3; int color_triplet_indx = id * 3;
glm::vec3 colorface( color_points[ color_triplet_indx + 0 ], glm::vec3 colorface( color_points[ color_triplet_indx + 0 ],
color_points[ color_triplet_indx + 1 ], color_points[ color_triplet_indx + 1 ],
color_points[ color_triplet_indx + 2 ] ); color_points[ color_triplet_indx + 2 ] );
m_model->m_Materials->m_DiffuseColor.push_back( colorface ); m_model->m_Materials->m_DiffuseColor.push_back( colorface );
}
} }
......
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