From fe51cc947cb0b72aa4649aeac14ba87e8edbf348 Mon Sep 17 00:00:00 2001 From: Mario Luzeiro Date: Wed, 2 Sep 2020 17:22:12 +0100 Subject: [PATCH] 3D-Viewer: render 3D shapes in green if footprint is selected --- .../3d_model_viewer/c3d_model_viewer.cpp | 6 +-- .../c3d_render_ogl_legacy.cpp | 22 ++++++--- .../c3d_render_ogl_legacy.h | 2 + .../3d_render_ogl_legacy/c_ogl_3dmodel.cpp | 49 ++++++++++++------- .../3d_render_ogl_legacy/c_ogl_3dmodel.h | 8 +-- 5 files changed, 56 insertions(+), 31 deletions(-) diff --git a/3d-viewer/3d_model_viewer/c3d_model_viewer.cpp b/3d-viewer/3d_model_viewer/c3d_model_viewer.cpp index 03af0beaab..54f66877e1 100644 --- a/3d-viewer/3d_model_viewer/c3d_model_viewer.cpp +++ b/3d-viewer/3d_model_viewer/c3d_model_viewer.cpp @@ -310,10 +310,10 @@ void C3D_MODEL_VIEWER::OnPaint( wxPaintEvent &event ) glTranslatef( -model_center.x, -model_center.y, -model_center.z ); - m_ogl_3dmodel->BeginDrawMulti(); + m_ogl_3dmodel->BeginDrawMulti( true ); - m_ogl_3dmodel->Draw_opaque(); - m_ogl_3dmodel->Draw_transparent( 1.0f ); + m_ogl_3dmodel->Draw_opaque( false ); + m_ogl_3dmodel->Draw_transparent( 1.0f, false ); m_ogl_3dmodel->EndDrawMulti(); diff --git a/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_ogl_legacy.cpp b/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_ogl_legacy.cpp index 4251e554b1..8304458fa3 100644 --- a/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_ogl_legacy.cpp +++ b/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_ogl_legacy.cpp @@ -1233,15 +1233,18 @@ void C3D_RENDER_OGL_LEGACY::render_solder_mask_layer(PCB_LAYER_ID aLayerID, } } - -void C3D_RENDER_OGL_LEGACY::render_3D_models( bool aRenderTopOrBot, - bool aRenderTransparentOnly ) +void C3D_RENDER_OGL_LEGACY::render_3D_models_selected( bool aRenderTopOrBot, bool aRenderTransparentOnly, bool aRenderSelectedOnly ) { - C_OGL_3DMODEL::BeginDrawMulti(); + + C_OGL_3DMODEL::BeginDrawMulti( !aRenderSelectedOnly ); // Go for all modules for( auto module : m_boardAdapter.GetBoard()->Modules() ) { + if( ( aRenderSelectedOnly && !module->IsSelected() ) || + ( !aRenderSelectedOnly && module->IsSelected() ) ) + continue; + if( !module->Models().empty() ) if( m_boardAdapter.ShouldModuleBeDisplayed((MODULE_ATTR_T) module->GetAttributes() ) ) if( ( aRenderTopOrBot && !module->IsFlipped() ) @@ -1252,6 +1255,13 @@ void C3D_RENDER_OGL_LEGACY::render_3D_models( bool aRenderTopOrBot, C_OGL_3DMODEL::EndDrawMulti(); } +void C3D_RENDER_OGL_LEGACY::render_3D_models( bool aRenderTopOrBot, + bool aRenderTransparentOnly ) +{ + render_3D_models_selected( aRenderTopOrBot, aRenderTransparentOnly, true ); + render_3D_models_selected( aRenderTopOrBot, aRenderTransparentOnly, false ); +} + void C3D_RENDER_OGL_LEGACY::render_3D_module( const MODULE* module, bool aRenderTransparentOnly ) @@ -1318,9 +1328,9 @@ void C3D_RENDER_OGL_LEGACY::render_3D_module( const MODULE* module, glMultMatrixf( glm::value_ptr( mtx ) ); if( aRenderTransparentOnly ) - modelPtr->Draw_transparent( sM.m_Opacity ); + modelPtr->Draw_transparent( sM.m_Opacity, module->IsSelected() ); else - modelPtr->Draw_opaque(); + modelPtr->Draw_opaque( module->IsSelected() ); if( m_boardAdapter.GetFlag( FL_RENDER_OPENGL_SHOW_MODEL_BBOX ) ) { diff --git a/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_ogl_legacy.h b/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_ogl_legacy.h index 01cbac4063..e7dec0ad7e 100644 --- a/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_ogl_legacy.h +++ b/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_ogl_legacy.h @@ -190,6 +190,8 @@ private: */ void render_3D_models( bool aRenderTopOrBot, bool aRenderTransparentOnly ); + void render_3D_models_selected( bool aRenderTopOrBot, bool aRenderTransparentOnly, bool aRenderSelectedOnly ); + void render_3D_module( const MODULE* module, bool aRenderTransparentOnly ); void setLight_Front( bool enabled ); diff --git a/3d-viewer/3d_rendering/3d_render_ogl_legacy/c_ogl_3dmodel.cpp b/3d-viewer/3d_rendering/3d_render_ogl_legacy/c_ogl_3dmodel.cpp index 338fe5b661..482a43ed13 100644 --- a/3d-viewer/3d_rendering/3d_render_ogl_legacy/c_ogl_3dmodel.cpp +++ b/3d-viewer/3d_rendering/3d_render_ogl_legacy/c_ogl_3dmodel.cpp @@ -367,14 +367,18 @@ C_OGL_3DMODEL::C_OGL_3DMODEL( const S3DMODEL &a3DModel, end_time - start_time).count() ); } -void C_OGL_3DMODEL::BeginDrawMulti() +void C_OGL_3DMODEL::BeginDrawMulti( bool aUseColorInformation ) { glEnableClientState( GL_VERTEX_ARRAY ); glEnableClientState( GL_NORMAL_ARRAY ); - glEnableClientState( GL_COLOR_ARRAY ); - glEnableClientState( GL_TEXTURE_COORD_ARRAY ); - glEnable( GL_COLOR_MATERIAL ); + if( aUseColorInformation ) + { + glEnableClientState( GL_COLOR_ARRAY ); + glEnableClientState( GL_TEXTURE_COORD_ARRAY ); + glEnable( GL_COLOR_MATERIAL ); + } + glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ); } @@ -391,7 +395,7 @@ void C_OGL_3DMODEL::EndDrawMulti() } -void C_OGL_3DMODEL::Draw( bool aTransparent, float aOpacity ) const +void C_OGL_3DMODEL::Draw( bool aTransparent, float aOpacity, bool aUseSelectedMaterial ) const { if( aOpacity <= FLT_EPSILON ) return; @@ -414,35 +418,44 @@ void C_OGL_3DMODEL::Draw( bool aTransparent, float aOpacity ) const glTexCoordPointer( 2, GL_FLOAT, sizeof( VERTEX ), reinterpret_cast( offsetof( VERTEX, m_tex_uv ) ) ); + if( aUseSelectedMaterial ) + aOpacity = aOpacity * 0.75f; + const SFVEC4F param = SFVEC4F( 1.0f, 1.0f, 1.0f, aOpacity ); glTexEnvfv( GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, (const float*)¶m.x ); // BeginDrawMulti(); + if( aUseSelectedMaterial ) + OGL_SetDiffuseOnlyMaterial( SFVEC3F( 0.0f, 1.0f, 0.0f ), aOpacity ); + for( auto& mat : m_materials ) { if( ( mat.IsTransparent() != aTransparent ) && ( aOpacity >= 1.0f ) ) continue; - switch( m_material_mode ) + if( !aUseSelectedMaterial ) { - case MATERIAL_MODE::NORMAL: - OGL_SetMaterial( mat, aOpacity ); - break; + switch( m_material_mode ) + { + case MATERIAL_MODE::NORMAL: + OGL_SetMaterial( mat, aOpacity ); + break; - case MATERIAL_MODE::DIFFUSE_ONLY: - OGL_SetDiffuseOnlyMaterial( mat.m_Diffuse, aOpacity ); - break; + case MATERIAL_MODE::DIFFUSE_ONLY: + OGL_SetDiffuseOnlyMaterial( mat.m_Diffuse, aOpacity ); + break; - case MATERIAL_MODE::CAD_MODE: - OGL_SetDiffuseOnlyMaterial( MaterialDiffuseToColorCAD( mat.m_Diffuse ), aOpacity ); - break; + case MATERIAL_MODE::CAD_MODE: + OGL_SetDiffuseOnlyMaterial( MaterialDiffuseToColorCAD( mat.m_Diffuse ), aOpacity ); + break; - default: - break; - } + default: + break; + } + } glDrawElements( GL_TRIANGLES, mat.m_render_idx_count, m_index_buffer_type, reinterpret_cast( mat.m_render_idx_buffer_offset ) ); diff --git a/3d-viewer/3d_rendering/3d_render_ogl_legacy/c_ogl_3dmodel.h b/3d-viewer/3d_rendering/3d_render_ogl_legacy/c_ogl_3dmodel.h index 413c721bd9..460078bc04 100644 --- a/3d-viewer/3d_rendering/3d_render_ogl_legacy/c_ogl_3dmodel.h +++ b/3d-viewer/3d_rendering/3d_render_ogl_legacy/c_ogl_3dmodel.h @@ -53,12 +53,12 @@ public: /** * @brief Draw_opaque - render the model into the current context */ - void Draw_opaque() const { Draw( false, 1.0f ); } + void Draw_opaque( bool aUseSelectedMaterial ) const { Draw( false, 1.0f, aUseSelectedMaterial ); } /** * @brief Draw_transparent - render the model into the current context */ - void Draw_transparent( float aOpacity ) const { Draw( true, aOpacity ); } + void Draw_transparent( float aOpacity, bool aUseSelectedMaterial ) const { Draw( true, aOpacity, aUseSelectedMaterial ); } /** * @brief Have_opaque - return true if have opaque meshs to render @@ -89,7 +89,7 @@ public: /** * @brief BeginDrawMulti - set some basic render states before drawing multiple models */ - static void BeginDrawMulti(); + static void BeginDrawMulti( bool aUseColorInformation ); /** * @brief EndDrawMulti - cleanup render states after drawing multiple models @@ -155,7 +155,7 @@ private: VERTEX *aVtxOut, GLuint *aIdxOut, const glm::vec4 &aColor ); - void Draw( bool aTransparent, float aOpacity ) const; + void Draw( bool aTransparent, float aOpacity, bool aUseSelectedMaterial ) const; }; #endif // _C_OGL_3DMODEL_H_