3D-Viewer: use LAYER_SELECT_OVERLAY color for selection

preserve material transparency while rendering as selected
This commit is contained in:
Mario Luzeiro 2020-09-27 15:51:49 +01:00 committed by Jon Evans
parent 10676eb926
commit 5205709399
6 changed files with 33 additions and 33 deletions

View File

@ -890,6 +890,8 @@ bool C3D_RENDER_OGL_LEGACY::Redraw(
glPopMatrix();
}
m_selectionColor = m_boardAdapter.GetItemColor( LAYER_SELECT_OVERLAY );
// Render 3D Models (Non-transparent)
// /////////////////////////////////////////////////////////////////////////
render_3D_models( false, false );
@ -1349,9 +1351,12 @@ void C3D_RENDER_OGL_LEGACY::render_3D_module( const MODULE* module,
glMultMatrixf( glm::value_ptr( mtx ) );
if( aRenderTransparentOnly )
modelPtr->Draw_transparent( sM.m_Opacity, module->IsSelected() || aIsSelected );
modelPtr->Draw_transparent( sM.m_Opacity,
module->IsSelected() || aIsSelected,
m_selectionColor );
else
modelPtr->Draw_opaque( module->IsSelected() || aIsSelected );
modelPtr->Draw_opaque( module->IsSelected() || aIsSelected,
m_selectionColor );
if( m_boardAdapter.GetFlag( FL_RENDER_OPENGL_SHOW_MODEL_BBOX ) )
{

View File

@ -228,6 +228,8 @@ private:
void set_layer_material( PCB_LAYER_ID aLayerID );
SFVEC4F get_layer_color( PCB_LAYER_ID aLayerID );
SFVEC3F m_selectionColor;
};
#endif // C3D_RENDER_OGL_LEGACY_H_

View File

@ -395,7 +395,7 @@ void C_OGL_3DMODEL::EndDrawMulti()
}
void C_OGL_3DMODEL::Draw( bool aTransparent, float aOpacity, bool aUseSelectedMaterial ) const
void C_OGL_3DMODEL::Draw(bool aTransparent, float aOpacity, bool aUseSelectedMaterial , SFVEC3F aSelectionColor ) const
{
if( aOpacity <= FLT_EPSILON )
return;
@ -418,30 +418,22 @@ void C_OGL_3DMODEL::Draw( bool aTransparent, float aOpacity, bool aUseSelectedMa
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;
if( !aUseSelectedMaterial )
{
switch( m_material_mode )
{
case MATERIAL_MODE::NORMAL:
OGL_SetMaterial( mat, aOpacity );
OGL_SetMaterial( mat, aOpacity, aUseSelectedMaterial, aSelectionColor );
break;
case MATERIAL_MODE::DIFFUSE_ONLY:
@ -455,7 +447,6 @@ void C_OGL_3DMODEL::Draw( bool aTransparent, float aOpacity, bool aUseSelectedMa
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( bool aUseSelectedMaterial ) const { Draw( false, 1.0f, aUseSelectedMaterial ); }
void Draw_opaque( bool aUseSelectedMaterial, SFVEC3F aSelectionColor = SFVEC3F( 0.0f ) ) const { Draw( false, 1.0f, aUseSelectedMaterial, aSelectionColor ); }
/**
* @brief Draw_transparent - render the model into the current context
*/
void Draw_transparent( float aOpacity, bool aUseSelectedMaterial ) const { Draw( true, aOpacity, aUseSelectedMaterial ); }
void Draw_transparent( float aOpacity, bool aUseSelectedMaterial, SFVEC3F aSelectionColor = SFVEC3F( 0.0f ) ) const { Draw( true, aOpacity, aUseSelectedMaterial, aSelectionColor ); }
/**
* @brief Have_opaque - return true if have opaque meshs to render
@ -155,7 +155,7 @@ private:
VERTEX *aVtxOut, GLuint *aIdxOut,
const glm::vec4 &aColor );
void Draw( bool aTransparent, float aOpacity, bool aUseSelectedMaterial ) const;
void Draw( bool aTransparent, float aOpacity, bool aUseSelectedMaterial, SFVEC3F aSelectionColor ) const;
};
#endif // _C_OGL_3DMODEL_H_

View File

@ -142,14 +142,14 @@ GLuint OGL_LoadTexture( const CIMAGE &aImage )
}
void OGL_SetMaterial( const SMATERIAL & aMaterial, float aOpacity )
void OGL_SetMaterial( const SMATERIAL & aMaterial, float aOpacity, bool aUseSelectedMaterial, SFVEC3F aSelectionColor )
{
const SFVEC4F ambient = SFVEC4F( aMaterial.m_Ambient, 1.0f );
// !TODO: at this moment, diffuse color is added via
// glEnableClientState( GL_COLOR_ARRAY ) so this line may has no effect
// but can be used for optimization
const SFVEC4F diffuse = SFVEC4F( aMaterial.m_Diffuse,
const SFVEC4F diffuse = SFVEC4F( aUseSelectedMaterial?aSelectionColor:aMaterial.m_Diffuse,
( 1.0f - aMaterial.m_Transparency ) * aOpacity );
const SFVEC4F specular = SFVEC4F( aMaterial.m_Specular, 1.0f );
const SFVEC4F emissive = SFVEC4F( aMaterial.m_Emissive, 1.0f );

View File

@ -39,8 +39,10 @@
* @brief OGL_SetMaterial - Set OpenGL materials
* @param aMaterial: a material structure with parameters to set
* @param aOpacity: main model opacity 0.0 full transparente, 1.0 full opaque
* @param aUseSelectedMaterial: if material should be set for selection mode
* @param aSelectionColor: material to use for selection in case it is enabled
*/
void OGL_SetMaterial( const SMATERIAL & aMaterial, float aOpacity );
void OGL_SetMaterial( const SMATERIAL & aMaterial, float aOpacity, bool aUseSelectedMaterial = false, SFVEC3F aSelectionColor = SFVEC3F( 0.0f ) );
/**