3D-Viewer: Fixes #4432

Set default transparency of model from the assigned material.
This commit is contained in:
Mario Luzeiro 2020-05-22 13:28:04 +00:00 committed by Jon Evans
parent 0a9adaef73
commit 94ed433f64
2 changed files with 17 additions and 6 deletions

View File

@ -285,6 +285,7 @@ void C3D_RENDER_RAYTRACING::reload( REPORTER* aStatusTextReporter, REPORTER* aWa
m_object_container.Clear();
m_containerWithObjectsToDelete.Clear();
setupMaterials();
// Create and add the outline board
// /////////////////////////////////////////////////////////////////////////
@ -697,7 +698,7 @@ void C3D_RENDER_RAYTRACING::reload( REPORTER* aStatusTextReporter, REPORTER* aWa
if( m_boardAdapter.GetFlag( FL_SOLDERMASK ) &&
(m_outlineBoard2dObjects->GetList().size() >= 1) )
{
CMATERIAL *materialLayer = &m_materials.m_SolderMask;
const CMATERIAL *materialLayer = &m_materials.m_SolderMask;
for( MAP_CONTAINER_2D::const_iterator ii = m_boardAdapter.GetMapLayers().begin();
ii != m_boardAdapter.GetMapLayers().end();
@ -1013,8 +1014,6 @@ void C3D_RENDER_RAYTRACING::reload( REPORTER* aStatusTextReporter, REPORTER* aWa
unsigned stats_endAcceleratorTime = GetRunningMicroSecs();
#endif
setupMaterials();
#ifdef PRINT_STATISTICS_3D_VIEWER
printf( "C3D_RENDER_RAYTRACING::reload times:\n" );
printf( " Reload board: %.3f ms\n", (float)( stats_endReloadTime -
@ -1399,6 +1398,13 @@ void C3D_RENDER_RAYTRACING::add_3D_models( const S3DMODEL *a3DModel,
wxASSERT( a3DModel->m_Meshes != NULL );
wxASSERT( a3DModel->m_MaterialsSize > 0 );
wxASSERT( a3DModel->m_MeshesSize > 0 );
wxASSERT( aModuleOpacity > 0.0f );
wxASSERT( aModuleOpacity <= 1.0f );
if( aModuleOpacity > 1.0f )
{
aModuleOpacity = 1.0f;
}
if( (a3DModel->m_Materials != NULL) && (a3DModel->m_Meshes != NULL) &&
(a3DModel->m_MaterialsSize > 0) && (a3DModel->m_MeshesSize > 0) )
@ -1558,6 +1564,8 @@ void C3D_RENDER_RAYTRACING::add_3D_models( const S3DMODEL *a3DModel,
{
const CBLINN_PHONG_MATERIAL &blinn_material = (*materialVector)[mesh.m_MaterialIdx];
const float moduleTransparency = 1.0f - ( ( 1.0f - blinn_material.GetTransparency() ) * aModuleOpacity );
// Add all face triangles
for( unsigned int faceIdx = 0;
faceIdx < mesh.m_FaceIdxSize;
@ -1598,8 +1606,6 @@ void C3D_RENDER_RAYTRACING::add_3D_models( const S3DMODEL *a3DModel,
m_object_container.Add( newTriangle );
newTriangle->SetMaterial( (const CMATERIAL *)&blinn_material );
const float moduleTransparency = 1.0f - ( ( 1.0f - blinn_material.GetTransparency() ) * aModuleOpacity );
newTriangle->SetModelTransparency( moduleTransparency );
if( mesh.m_Color == NULL )

View File

@ -63,7 +63,12 @@ public:
explicit COBJECT( OBJECT3D_TYPE aObjType );
void SetMaterial( const CMATERIAL *aMaterial ) { m_material = aMaterial; }
void SetMaterial( const CMATERIAL *aMaterial )
{
m_material = aMaterial;
m_modelTransparency = aMaterial->GetTransparency(); // Default transparency is from material
}
const CMATERIAL *GetMaterial() const { return m_material; }
float GetModelTransparency() const { return m_modelTransparency; }
void SetModelTransparency( float aModelTransparency ) { m_modelTransparency = aModelTransparency; }