3D viewer bug fixes
This commit is contained in:
parent
7b936f4d0c
commit
d9c76c0d49
|
@ -53,7 +53,7 @@ void CheckGLError(const char *aFileName, int aLineNumber)
|
|||
|
||||
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()
|
|||
glBindTexture( GL_TEXTURE_2D, m_text_fake_shadow_back );
|
||||
glCallList( m_glLists[GL_ID_SHADOW_BACK] );
|
||||
}
|
||||
|
||||
glColor4f( 1.0, 1.0, 1.0, 1.0 );
|
||||
|
||||
glEnable( GL_DEPTH_TEST );
|
||||
|
|
|
@ -172,9 +172,11 @@ void Draw3D_SolidHorizontalPolyPolygons( const CPOLYGONS_LIST& aPolysList,
|
|||
// Draw solid areas contained in this list
|
||||
CPOLYGONS_LIST polylist = aPolysList; // temporary copy for gluTessVertex
|
||||
|
||||
int startContour;
|
||||
|
||||
for( int side = 0; side < 2; side++ )
|
||||
{
|
||||
int startContour = 1;
|
||||
startContour = 1;
|
||||
|
||||
for( unsigned ii = 0; ii < polylist.GetCornersCount(); ii++ )
|
||||
{
|
||||
|
@ -217,6 +219,12 @@ void Draw3D_SolidHorizontalPolyPolygons( const CPOLYGONS_LIST& aPolysList,
|
|||
SetNormalZneg();
|
||||
}
|
||||
|
||||
if( startContour == 0 )
|
||||
{
|
||||
gluTessEndContour( tess );
|
||||
gluTessEndPolygon( tess );
|
||||
}
|
||||
|
||||
gluDeleteTess( tess );
|
||||
|
||||
if( aThickness == 0 )
|
||||
|
|
|
@ -211,8 +211,11 @@ void S3D_MESH::calcPointNormalized ()
|
|||
p = m_Point[i] * biggerPoint;
|
||||
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 )
|
||||
{
|
||||
double sum = 0.0;
|
||||
|
@ -253,6 +256,9 @@ void S3D_MESH::calcPerFaceNormals ()
|
|||
m_PerFaceNormalsRaw.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++ )
|
||||
{
|
||||
|
||||
|
@ -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]);
|
||||
|
||||
// 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++ )
|
||||
{
|
||||
//if A != B { // ignore self
|
||||
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])) ||
|
||||
(m_CoordIndex[each_face_B_idx][1] == (int)(m_CoordIndex[each_face_A_idx][each_vert_A_idx])) ||
|
||||
(m_CoordIndex[each_face_B_idx][2] == (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] == vertexIndex) ||
|
||||
(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];
|
||||
|
||||
float dot_prod = glm::dot(vector_face_A, vector_face_B);
|
||||
|
|
|
@ -80,7 +80,6 @@ void VRML2_MODEL_PARSER::Load( const wxString aFilename )
|
|||
|
||||
#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 );
|
||||
|
||||
glRotatef(-matRot.z, 0.0f, 0.0f, 1.0f );
|
||||
|
@ -140,7 +139,7 @@ int VRML2_MODEL_PARSER::read_Transform()
|
|||
{
|
||||
char text[128];
|
||||
|
||||
///DBG( printf( "Transform\n" ) );
|
||||
//DBG( printf( "Transform\n" ) );
|
||||
|
||||
while( GetNextTag( m_file, text ) )
|
||||
{
|
||||
|
@ -204,7 +203,7 @@ int VRML2_MODEL_PARSER::read_Transform()
|
|||
read_DEF();
|
||||
} else
|
||||
{
|
||||
//DBG( printf( " %s NotImplemented\n", text ) );
|
||||
DBG( printf( " %s NotImplemented\n", text ) );
|
||||
read_NotImplemented( m_file, '}' );
|
||||
}
|
||||
}
|
||||
|
@ -264,7 +263,7 @@ int VRML2_MODEL_PARSER::read_DEF()
|
|||
}
|
||||
}
|
||||
|
||||
//DBG( printf( " DEF failed\n" ) );
|
||||
DBG( printf( " DEF failed\n" ) );
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -302,12 +301,12 @@ int VRML2_MODEL_PARSER::read_Shape()
|
|||
read_IndexedFaceSet();
|
||||
} else
|
||||
{
|
||||
//DBG( printf( " %s NotImplemented\n", text ) );
|
||||
DBG( printf( " %s NotImplemented\n", text ) );
|
||||
read_NotImplemented( m_file, '}' );
|
||||
}
|
||||
}
|
||||
|
||||
//DBG( printf( " Shape failed\n") );
|
||||
DBG( printf( " Shape failed\n") );
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -336,7 +335,7 @@ int VRML2_MODEL_PARSER::read_Appearance()
|
|||
}
|
||||
}
|
||||
|
||||
//DBG( printf( " Appearance failed\n") );
|
||||
DBG( printf( " Appearance failed\n") );
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -407,12 +406,12 @@ int VRML2_MODEL_PARSER::read_material()
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -72,14 +72,17 @@ void X3D_MODEL_PARSER::Load( const wxString aFilename )
|
|||
float vrmlunits_to_3Dunits = g_Parm_3D_Visu.m_BiuTo3Dunits * UNITS3D_TO_UNITSPCB;
|
||||
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 );
|
||||
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 );
|
||||
|
||||
|
||||
#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 );
|
||||
|
||||
glRotatef(-matRot.z, 0.0f, 0.0f, 1.0f );
|
||||
|
@ -247,25 +250,26 @@ void X3D_MODEL_PARSER::readMaterial( wxXmlNode* aMatNode )
|
|||
color ) )
|
||||
{
|
||||
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" ) ],
|
||||
color ) )
|
||||
if( !parseDoubleTriplet( properties[ wxT( "specularColor" ) ], color ) )
|
||||
{
|
||||
DBG( printf("specularColor parsing error") );
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
m_model->m_Materials->m_SpecularColor.push_back( color );
|
||||
}
|
||||
|
||||
if( !parseDoubleTriplet( properties[ wxT( "emissiveColor" ) ],
|
||||
color ) )
|
||||
if( !parseDoubleTriplet( properties[ wxT( "emissiveColor" ) ], color ) )
|
||||
{
|
||||
DBG( printf("emissiveColor parsing error") );
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
m_model->m_Materials->m_EmissiveColor.push_back( color );
|
||||
}
|
||||
|
@ -334,12 +338,12 @@ void X3D_MODEL_PARSER::readMaterial( wxXmlNode* aMatNode )
|
|||
material->m_SpecularColor[0].x,
|
||||
material->m_SpecularColor[0].y,
|
||||
material->m_SpecularColor[0].z ) );
|
||||
/*
|
||||
|
||||
vrml_material.Append( wxString::Format( wxT( "diffuseColor %f %f %f\n" ),
|
||||
material->m_DiffuseColor[0].x,
|
||||
material->m_DiffuseColor[0].y,
|
||||
material->m_DiffuseColor[0].z ) );
|
||||
*/
|
||||
|
||||
vrml_material.Append( wxString::Format( wxT( "emissiveColor %f %f %f\n" ),
|
||||
material->m_EmissiveColor[0].x,
|
||||
material->m_EmissiveColor[0].y,
|
||||
|
@ -505,8 +509,6 @@ void X3D_MODEL_PARSER::readIndexedFaceSet( wxXmlNode* aFaceNode,
|
|||
point.y += translation.y;
|
||||
point.z += translation.z;
|
||||
|
||||
//triplets.push_back(point);
|
||||
|
||||
m_model->m_Point.push_back( point );
|
||||
|
||||
// VRML
|
||||
|
@ -522,6 +524,9 @@ void X3D_MODEL_PARSER::readIndexedFaceSet( wxXmlNode* aFaceNode,
|
|||
NODE_LIST color;
|
||||
GetChildsByName( aFaceNode, wxT( "Color" ), color);
|
||||
|
||||
// Some models lack color information, need to handle this safely
|
||||
if( !color.empty() )
|
||||
{
|
||||
PROPERTY_MAP color_properties;
|
||||
// IndexedFaceSet has one Coordinate child node
|
||||
GetNodeProperties( color[0], color_properties );
|
||||
|
@ -550,6 +555,7 @@ void X3D_MODEL_PARSER::readIndexedFaceSet( wxXmlNode* aFaceNode,
|
|||
|
||||
/* Create 3D face color from 3 color points
|
||||
*/
|
||||
m_model->m_Materials->m_DiffuseColor.clear();
|
||||
for( unsigned id = 0; id < color_points.size() / 3; id++ )
|
||||
{
|
||||
m_model->m_MaterialIndex.push_back( id );
|
||||
|
@ -561,6 +567,7 @@ void X3D_MODEL_PARSER::readIndexedFaceSet( wxXmlNode* aFaceNode,
|
|||
|
||||
m_model->m_Materials->m_DiffuseColor.push_back( colorface );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* -- Read coordinate indexes -- */
|
||||
|
|
Loading…
Reference in New Issue