Loading 3d-viewer/3d_draw.cpp +4 −3 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ #include <class_pcb_text.h> #include <colors_selection.h> #include <convert_basic_shapes_to_polygon.h> #define GLM_FORCE_RADIANS #include <gal/opengl/glm/gtc/matrix_transform.hpp> #include <gal/opengl/opengl_compositor.h> #ifdef __WINDOWS__ Loading Loading @@ -1401,13 +1402,13 @@ void EDA_3D_CANVAS::calcBBox() if( module->GetOrientation() ) fullTransformMatrix = glm::rotate( fullTransformMatrix, (float)(module->GetOrientation() / 10.0f), glm::radians( (float)(module->GetOrientation() / 10.0f) ), S3D_VERTEX( 0.0f, 0.0f, 1.0f ) ); if( module->IsFlipped() ) { fullTransformMatrix = glm::rotate( fullTransformMatrix, 180.0f, S3D_VERTEX( 0.0f, 1.0f, 0.0f ) ); fullTransformMatrix = glm::rotate( fullTransformMatrix, 180.0f, S3D_VERTEX( 0.0f, 0.0f, 1.0f ) ); fullTransformMatrix = glm::rotate( fullTransformMatrix, glm::radians( 180.0f ), S3D_VERTEX( 0.0f, 1.0f, 0.0f ) ); fullTransformMatrix = glm::rotate( fullTransformMatrix, glm::radians( 180.0f ), S3D_VERTEX( 0.0f, 0.0f, 1.0f ) ); } // Compute a union bounding box for all the shapes of the model Loading 3d-viewer/3d_material.h +1 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ #include <common.h> #include <base_struct.h> #define GLM_FORCE_RADIANS #include <gal/opengl/glm/glm.hpp> class S3D_MASTER; Loading 3d-viewer/3d_mesh_model.cpp +131 −49 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ #include <fctsys.h> #include <3d_mesh_model.h> #include <boost/geometry/algorithms/area.hpp> #define GLM_FORCE_RADIANS #include <gal/opengl/glm/gtc/matrix_transform.hpp> #include <gal/opengl/glm/glm.hpp> Loading Loading @@ -102,7 +103,7 @@ void S3D_MESH::calcBBoxAllChilds( ) if( m_rotation[3] != 0.0f ) { glm::mat4 rotationMatrix = glm::rotate( translationMatrix, m_rotation[3], glm::mat4 rotationMatrix = glm::rotate( translationMatrix, glm::radians( m_rotation[3] ), S3D_VERTEX( m_rotation[0], m_rotation[1], m_rotation[2] ) ); fullTransformMatrix = glm::scale( rotationMatrix, m_scale ); } Loading Loading @@ -237,7 +238,7 @@ void S3D_MESH::openGL_Render( bool aIsRenderingJustNonTransparentObjects, for( unsigned int idx = 0; idx < m_CoordIndex.size(); idx++ ) { if( m_Materials ) if( m_Materials && ( m_MaterialIndex.size() != 0 ) ) { if ( m_MaterialIndex.size() > idx ) { Loading Loading @@ -284,13 +285,15 @@ void S3D_MESH::openGL_Render( bool aIsRenderingJustNonTransparentObjects, { glm::vec3 normal = m_PerVertexNormalsNormalized[m_NormalIndex[idx][ii]]; glNormal3fv( &normal.x ); // Flag error vertices /* #if defined(DEBUG) // Flag error vertices if ((normal.x == 0.0) && (normal.y == 0.0) && (normal.z == 0.0)) { glColor4f( 1.0, 0.0, 1.0, 1.0 ); } #endif */ glm::vec3 point = m_Point[m_CoordIndex[idx][ii]]; glVertex3fv( &point.x ); } Loading @@ -305,11 +308,15 @@ void S3D_MESH::openGL_Render( bool aIsRenderingJustNonTransparentObjects, glm::vec3 normal = normals_list[ii]; glNormal3fv( &normal.x ); // Flag error vertices /* #if defined(DEBUG) // Flag error vertices if ((normal.x == 0.0) && (normal.y == 0.0) && (normal.z == 0.0)) { glColor4f( 1.0, 0.0, 1.0, 1.0 ); } #endif */ glm::vec3 point = m_Point[m_CoordIndex[idx][ii]]; glVertex3fv( &point.x ); Loading @@ -321,18 +328,21 @@ void S3D_MESH::openGL_Render( bool aIsRenderingJustNonTransparentObjects, // Flat if( m_PerFaceNormalsNormalized.size() > 0 ) { glm::vec3 normal = m_PerFaceNormalsNormalized[idx]; for( unsigned int ii = 0; ii < m_CoordIndex[idx].size(); ii++ ) { glNormal3fv( &normal.x ); // Flag error vertices S3D_VERTEX normal = m_PerFaceNormalsNormalized[idx]; /* #if defined(DEBUG) // Flag error vertices if( (normal.x == 0.0) && (normal.y == 0.0) && (normal.z == 0.0) ) { DBG( printf("%u\n", idx) ); glColor4f( 1.0, 0.0, 1.0, 1.0 ); } #endif */ glNormal3fv( &normal.x ); for( unsigned int ii = 0; ii < m_CoordIndex[idx].size(); ii++ ) { glm::vec3 point = m_Point[m_CoordIndex[idx][ii]]; glVertex3fv( &point.x ); } Loading Loading @@ -479,13 +489,29 @@ void S3D_MESH::calcPerFaceNormals() if( ( m_PerFaceNormalsNormalized.size() > 0 ) && g_Parm_3D_Visu.GetFlag( FL_RENDER_USE_MODEL_NORMALS ) ) { haveAlreadyNormals_from_model_file = true; // !TODO: this is a workarround for some VRML2 modules files (ex: from we-online.de website) // are using (incorrectly) the normals with m_CoordIndex as per face normal. This maybe be addressed by the parser in the future. if( ( m_PerFaceNormalsNormalized.size() == m_Point.size() ) && ( m_PerFaceNormalsNormalized.size() != m_CoordIndex.size() ) ) { //DBG( printf("m_PerFaceNormalsNormalized.size() != m_CoordIndex.size() Appling a workarroudn recover\n") ); m_NormalIndex = m_CoordIndex; m_PerVertexNormalsNormalized = m_PerFaceNormalsNormalized; m_PerFaceNormalsNormalized.clear(); haveAlreadyNormals_from_model_file = false; } } else { m_PerFaceNormalsNormalized.clear(); m_PerFaceNormalsRaw_X_PerFaceSquaredArea.clear(); } m_PerFaceNormalsNormalized.resize( m_CoordIndex.size() ); m_PerFaceNormalsRaw_X_PerFaceSquaredArea.clear(); m_PerFaceNormalsRaw_X_PerFaceSquaredArea.resize( m_CoordIndex.size() ); // There are no points defined for the coordIndex Loading Loading @@ -530,6 +556,54 @@ void S3D_MESH::calcPerFaceNormals() m_PerFaceNormalsRaw_X_PerFaceSquaredArea[idx] = cross_prod * area; if( haveAlreadyNormals_from_model_file == false ) { if( g_Parm_3D_Visu.GetFlag( FL_RENDER_USE_MODEL_NORMALS ) && (m_PerVertexNormalsNormalized.size() > 0) ) { glm::vec3 normalSum; for( unsigned int ii = 0; ii < m_CoordIndex[idx].size(); ii++ ) { normalSum += m_PerVertexNormalsNormalized[m_NormalIndex[idx][ii]]; } float l = glm::length( normalSum ); if( l > FLT_EPSILON ) // avoid division by zero { normalSum = normalSum / l; } else { if( ( normalSum.x > normalSum.y ) && ( normalSum.x > normalSum.z ) ) { normalSum.x = 0.0f; normalSum.y = 1.0f; normalSum.z = 0.0f; } else if( ( normalSum.y > normalSum.x ) && ( normalSum.y > normalSum.z ) ) { normalSum.x = 0.0f; normalSum.y = 1.0f; normalSum.z = 0.0f; } else if( ( normalSum.z > normalSum.x ) && ( normalSum.z > normalSum.y ) ) { normalSum.x = 0.0f; normalSum.y = 0.0f; normalSum.z = 1.0f; } else { normalSum.x = 0.0f; normalSum.y = 0.0f; normalSum.z = 0.0f; } } m_PerFaceNormalsNormalized[idx] = normalSum; } else { // normalize vertex normal float l = glm::length( cross_prod ); Loading @@ -540,12 +614,19 @@ void S3D_MESH::calcPerFaceNormals() } else { /* DBG( printf( "Cannot calc normal idx: %u cross(%f, %f, %f) l:%f m_CoordIndex[idx].size: %u\n", /* for( unsigned int i = 0; i < m_CoordIndex[idx].size(); i++ ) { glm::vec3 v = m_PointNormalized[m_CoordIndex[idx][i]]; DBG( printf( "v[%u](%f, %f, %f)", i, v.x, v.y, v.z ) ); } 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.0f; Loading Loading @@ -576,6 +657,7 @@ void S3D_MESH::calcPerFaceNormals() } } } } // Documentation literature Loading 3d-viewer/3d_mesh_model.h +2 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ #define __3D_MESH_MODEL_H__ #include <vector> #define GLM_FORCE_RADIANS #include <gal/opengl/glm/glm.hpp> #include "3d_struct.h" #include "3d_material.h" Loading @@ -55,6 +56,7 @@ public: std::vector< S3D_VERTEX > m_Point; std::vector< std::vector<int> > m_CoordIndex; std::vector< std::vector<int> > m_NormalIndex; std::vector< S3D_VERTEX > m_PerFaceColor; std::vector< S3D_VERTEX > m_PerFaceNormalsNormalized; std::vector< S3D_VERTEX > m_PerVertexNormalsNormalized; std::vector< int > m_MaterialIndex; Loading 3d-viewer/3d_read_mesh.cpp +4 −3 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ #include <macros.h> #include <kicad_string.h> #include <pgm_base.h> #define GLM_FORCE_RADIANS #include <gal/opengl/glm/gtc/matrix_transform.hpp> #include <3d_viewer.h> #include <info3d_visu.h> Loading Loading @@ -176,11 +177,11 @@ void S3D_MASTER::calcBBox() m_MatPosition.z * SCALE_3D_CONV) ); if( m_MatRotation.z != 0.0 ) fullTransformMatrix = glm::rotate( fullTransformMatrix, -(float)m_MatRotation.z, S3D_VERTEX( 0.0f, 0.0f, 1.0f ) ); fullTransformMatrix = glm::rotate( fullTransformMatrix, glm::radians(-(float)m_MatRotation.z), S3D_VERTEX( 0.0f, 0.0f, 1.0f ) ); if( m_MatRotation.y != 0.0 ) fullTransformMatrix = glm::rotate( fullTransformMatrix, -(float)m_MatRotation.y, S3D_VERTEX( 0.0f, 1.0f, 0.0f ) ); fullTransformMatrix = glm::rotate( fullTransformMatrix, glm::radians(-(float)m_MatRotation.y), S3D_VERTEX( 0.0f, 1.0f, 0.0f ) ); if( m_MatRotation.x != 0.0 ) fullTransformMatrix = glm::rotate( fullTransformMatrix, -(float)m_MatRotation.x, S3D_VERTEX( 1.0f, 0.0f, 0.0f ) ); fullTransformMatrix = glm::rotate( fullTransformMatrix, glm::radians(-(float)m_MatRotation.x), S3D_VERTEX( 1.0f, 0.0f, 0.0f ) ); fullTransformMatrix = glm::scale( fullTransformMatrix, S3D_VERTEX( m_MatScale.x, m_MatScale.y, m_MatScale.z ) ); Loading Loading
3d-viewer/3d_draw.cpp +4 −3 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ #include <class_pcb_text.h> #include <colors_selection.h> #include <convert_basic_shapes_to_polygon.h> #define GLM_FORCE_RADIANS #include <gal/opengl/glm/gtc/matrix_transform.hpp> #include <gal/opengl/opengl_compositor.h> #ifdef __WINDOWS__ Loading Loading @@ -1401,13 +1402,13 @@ void EDA_3D_CANVAS::calcBBox() if( module->GetOrientation() ) fullTransformMatrix = glm::rotate( fullTransformMatrix, (float)(module->GetOrientation() / 10.0f), glm::radians( (float)(module->GetOrientation() / 10.0f) ), S3D_VERTEX( 0.0f, 0.0f, 1.0f ) ); if( module->IsFlipped() ) { fullTransformMatrix = glm::rotate( fullTransformMatrix, 180.0f, S3D_VERTEX( 0.0f, 1.0f, 0.0f ) ); fullTransformMatrix = glm::rotate( fullTransformMatrix, 180.0f, S3D_VERTEX( 0.0f, 0.0f, 1.0f ) ); fullTransformMatrix = glm::rotate( fullTransformMatrix, glm::radians( 180.0f ), S3D_VERTEX( 0.0f, 1.0f, 0.0f ) ); fullTransformMatrix = glm::rotate( fullTransformMatrix, glm::radians( 180.0f ), S3D_VERTEX( 0.0f, 0.0f, 1.0f ) ); } // Compute a union bounding box for all the shapes of the model Loading
3d-viewer/3d_material.h +1 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ #include <common.h> #include <base_struct.h> #define GLM_FORCE_RADIANS #include <gal/opengl/glm/glm.hpp> class S3D_MASTER; Loading
3d-viewer/3d_mesh_model.cpp +131 −49 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ #include <fctsys.h> #include <3d_mesh_model.h> #include <boost/geometry/algorithms/area.hpp> #define GLM_FORCE_RADIANS #include <gal/opengl/glm/gtc/matrix_transform.hpp> #include <gal/opengl/glm/glm.hpp> Loading Loading @@ -102,7 +103,7 @@ void S3D_MESH::calcBBoxAllChilds( ) if( m_rotation[3] != 0.0f ) { glm::mat4 rotationMatrix = glm::rotate( translationMatrix, m_rotation[3], glm::mat4 rotationMatrix = glm::rotate( translationMatrix, glm::radians( m_rotation[3] ), S3D_VERTEX( m_rotation[0], m_rotation[1], m_rotation[2] ) ); fullTransformMatrix = glm::scale( rotationMatrix, m_scale ); } Loading Loading @@ -237,7 +238,7 @@ void S3D_MESH::openGL_Render( bool aIsRenderingJustNonTransparentObjects, for( unsigned int idx = 0; idx < m_CoordIndex.size(); idx++ ) { if( m_Materials ) if( m_Materials && ( m_MaterialIndex.size() != 0 ) ) { if ( m_MaterialIndex.size() > idx ) { Loading Loading @@ -284,13 +285,15 @@ void S3D_MESH::openGL_Render( bool aIsRenderingJustNonTransparentObjects, { glm::vec3 normal = m_PerVertexNormalsNormalized[m_NormalIndex[idx][ii]]; glNormal3fv( &normal.x ); // Flag error vertices /* #if defined(DEBUG) // Flag error vertices if ((normal.x == 0.0) && (normal.y == 0.0) && (normal.z == 0.0)) { glColor4f( 1.0, 0.0, 1.0, 1.0 ); } #endif */ glm::vec3 point = m_Point[m_CoordIndex[idx][ii]]; glVertex3fv( &point.x ); } Loading @@ -305,11 +308,15 @@ void S3D_MESH::openGL_Render( bool aIsRenderingJustNonTransparentObjects, glm::vec3 normal = normals_list[ii]; glNormal3fv( &normal.x ); // Flag error vertices /* #if defined(DEBUG) // Flag error vertices if ((normal.x == 0.0) && (normal.y == 0.0) && (normal.z == 0.0)) { glColor4f( 1.0, 0.0, 1.0, 1.0 ); } #endif */ glm::vec3 point = m_Point[m_CoordIndex[idx][ii]]; glVertex3fv( &point.x ); Loading @@ -321,18 +328,21 @@ void S3D_MESH::openGL_Render( bool aIsRenderingJustNonTransparentObjects, // Flat if( m_PerFaceNormalsNormalized.size() > 0 ) { glm::vec3 normal = m_PerFaceNormalsNormalized[idx]; for( unsigned int ii = 0; ii < m_CoordIndex[idx].size(); ii++ ) { glNormal3fv( &normal.x ); // Flag error vertices S3D_VERTEX normal = m_PerFaceNormalsNormalized[idx]; /* #if defined(DEBUG) // Flag error vertices if( (normal.x == 0.0) && (normal.y == 0.0) && (normal.z == 0.0) ) { DBG( printf("%u\n", idx) ); glColor4f( 1.0, 0.0, 1.0, 1.0 ); } #endif */ glNormal3fv( &normal.x ); for( unsigned int ii = 0; ii < m_CoordIndex[idx].size(); ii++ ) { glm::vec3 point = m_Point[m_CoordIndex[idx][ii]]; glVertex3fv( &point.x ); } Loading Loading @@ -479,13 +489,29 @@ void S3D_MESH::calcPerFaceNormals() if( ( m_PerFaceNormalsNormalized.size() > 0 ) && g_Parm_3D_Visu.GetFlag( FL_RENDER_USE_MODEL_NORMALS ) ) { haveAlreadyNormals_from_model_file = true; // !TODO: this is a workarround for some VRML2 modules files (ex: from we-online.de website) // are using (incorrectly) the normals with m_CoordIndex as per face normal. This maybe be addressed by the parser in the future. if( ( m_PerFaceNormalsNormalized.size() == m_Point.size() ) && ( m_PerFaceNormalsNormalized.size() != m_CoordIndex.size() ) ) { //DBG( printf("m_PerFaceNormalsNormalized.size() != m_CoordIndex.size() Appling a workarroudn recover\n") ); m_NormalIndex = m_CoordIndex; m_PerVertexNormalsNormalized = m_PerFaceNormalsNormalized; m_PerFaceNormalsNormalized.clear(); haveAlreadyNormals_from_model_file = false; } } else { m_PerFaceNormalsNormalized.clear(); m_PerFaceNormalsRaw_X_PerFaceSquaredArea.clear(); } m_PerFaceNormalsNormalized.resize( m_CoordIndex.size() ); m_PerFaceNormalsRaw_X_PerFaceSquaredArea.clear(); m_PerFaceNormalsRaw_X_PerFaceSquaredArea.resize( m_CoordIndex.size() ); // There are no points defined for the coordIndex Loading Loading @@ -530,6 +556,54 @@ void S3D_MESH::calcPerFaceNormals() m_PerFaceNormalsRaw_X_PerFaceSquaredArea[idx] = cross_prod * area; if( haveAlreadyNormals_from_model_file == false ) { if( g_Parm_3D_Visu.GetFlag( FL_RENDER_USE_MODEL_NORMALS ) && (m_PerVertexNormalsNormalized.size() > 0) ) { glm::vec3 normalSum; for( unsigned int ii = 0; ii < m_CoordIndex[idx].size(); ii++ ) { normalSum += m_PerVertexNormalsNormalized[m_NormalIndex[idx][ii]]; } float l = glm::length( normalSum ); if( l > FLT_EPSILON ) // avoid division by zero { normalSum = normalSum / l; } else { if( ( normalSum.x > normalSum.y ) && ( normalSum.x > normalSum.z ) ) { normalSum.x = 0.0f; normalSum.y = 1.0f; normalSum.z = 0.0f; } else if( ( normalSum.y > normalSum.x ) && ( normalSum.y > normalSum.z ) ) { normalSum.x = 0.0f; normalSum.y = 1.0f; normalSum.z = 0.0f; } else if( ( normalSum.z > normalSum.x ) && ( normalSum.z > normalSum.y ) ) { normalSum.x = 0.0f; normalSum.y = 0.0f; normalSum.z = 1.0f; } else { normalSum.x = 0.0f; normalSum.y = 0.0f; normalSum.z = 0.0f; } } m_PerFaceNormalsNormalized[idx] = normalSum; } else { // normalize vertex normal float l = glm::length( cross_prod ); Loading @@ -540,12 +614,19 @@ void S3D_MESH::calcPerFaceNormals() } else { /* DBG( printf( "Cannot calc normal idx: %u cross(%f, %f, %f) l:%f m_CoordIndex[idx].size: %u\n", /* for( unsigned int i = 0; i < m_CoordIndex[idx].size(); i++ ) { glm::vec3 v = m_PointNormalized[m_CoordIndex[idx][i]]; DBG( printf( "v[%u](%f, %f, %f)", i, v.x, v.y, v.z ) ); } 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.0f; Loading Loading @@ -576,6 +657,7 @@ void S3D_MESH::calcPerFaceNormals() } } } } // Documentation literature Loading
3d-viewer/3d_mesh_model.h +2 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ #define __3D_MESH_MODEL_H__ #include <vector> #define GLM_FORCE_RADIANS #include <gal/opengl/glm/glm.hpp> #include "3d_struct.h" #include "3d_material.h" Loading @@ -55,6 +56,7 @@ public: std::vector< S3D_VERTEX > m_Point; std::vector< std::vector<int> > m_CoordIndex; std::vector< std::vector<int> > m_NormalIndex; std::vector< S3D_VERTEX > m_PerFaceColor; std::vector< S3D_VERTEX > m_PerFaceNormalsNormalized; std::vector< S3D_VERTEX > m_PerVertexNormalsNormalized; std::vector< int > m_MaterialIndex; Loading
3d-viewer/3d_read_mesh.cpp +4 −3 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ #include <macros.h> #include <kicad_string.h> #include <pgm_base.h> #define GLM_FORCE_RADIANS #include <gal/opengl/glm/gtc/matrix_transform.hpp> #include <3d_viewer.h> #include <info3d_visu.h> Loading Loading @@ -176,11 +177,11 @@ void S3D_MASTER::calcBBox() m_MatPosition.z * SCALE_3D_CONV) ); if( m_MatRotation.z != 0.0 ) fullTransformMatrix = glm::rotate( fullTransformMatrix, -(float)m_MatRotation.z, S3D_VERTEX( 0.0f, 0.0f, 1.0f ) ); fullTransformMatrix = glm::rotate( fullTransformMatrix, glm::radians(-(float)m_MatRotation.z), S3D_VERTEX( 0.0f, 0.0f, 1.0f ) ); if( m_MatRotation.y != 0.0 ) fullTransformMatrix = glm::rotate( fullTransformMatrix, -(float)m_MatRotation.y, S3D_VERTEX( 0.0f, 1.0f, 0.0f ) ); fullTransformMatrix = glm::rotate( fullTransformMatrix, glm::radians(-(float)m_MatRotation.y), S3D_VERTEX( 0.0f, 1.0f, 0.0f ) ); if( m_MatRotation.x != 0.0 ) fullTransformMatrix = glm::rotate( fullTransformMatrix, -(float)m_MatRotation.x, S3D_VERTEX( 1.0f, 0.0f, 0.0f ) ); fullTransformMatrix = glm::rotate( fullTransformMatrix, glm::radians(-(float)m_MatRotation.x), S3D_VERTEX( 1.0f, 0.0f, 0.0f ) ); fullTransformMatrix = glm::scale( fullTransformMatrix, S3D_VERTEX( m_MatScale.x, m_MatScale.y, m_MatScale.z ) ); Loading