3D-Viewer: render 3D shapes in green if footprint is selected

This commit is contained in:
Mario Luzeiro 2020-09-02 17:22:12 +01:00 committed by Jon Evans
parent c7a546042e
commit fe51cc947c
5 changed files with 56 additions and 31 deletions

View File

@ -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();

View File

@ -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 ) )
{

View File

@ -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 );

View File

@ -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<const void*>( 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*)&param.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<const void*>( mat.m_render_idx_buffer_offset ) );

View File

@ -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_