3D-Viewer: add skip material to model loading

This commit is contained in:
Mario Luzeiro 2020-09-02 15:31:42 +01:00 committed by Jon Evans
parent 72b904a978
commit c7a546042e
2 changed files with 146 additions and 128 deletions

View File

@ -871,7 +871,7 @@ void C3D_RENDER_RAYTRACING::reload( REPORTER* aStatusReporter, REPORTER* aWarnin
#endif #endif
load_3D_models(); load_3D_models( false );
#ifdef PRINT_STATISTICS_3D_VIEWER #ifdef PRINT_STATISTICS_3D_VIEWER
@ -1250,7 +1250,7 @@ void C3D_RENDER_RAYTRACING::add_3D_vias_and_pads_to_container()
} }
void C3D_RENDER_RAYTRACING::load_3D_models() void C3D_RENDER_RAYTRACING::load_3D_models( bool aSkipMaterialInformation )
{ {
// Go for all modules // Go for all modules
for( auto module : m_boardAdapter.GetBoard()->Modules() ) for( auto module : m_boardAdapter.GetBoard()->Modules() )
@ -1341,7 +1341,7 @@ void C3D_RENDER_RAYTRACING::load_3D_models()
sM->m_Scale.y, sM->m_Scale.y,
sM->m_Scale.z ) ); sM->m_Scale.z ) );
add_3D_models( modelPtr, modelMatrix, (float)sM->m_Opacity ); add_3D_models( modelPtr, modelMatrix, (float)sM->m_Opacity, aSkipMaterialInformation );
} }
} }
@ -1351,34 +1351,8 @@ void C3D_RENDER_RAYTRACING::load_3D_models()
} }
} }
MODEL_MATERIALS *C3D_RENDER_RAYTRACING::get_3D_model_material( const S3DMODEL *a3DModel )
void C3D_RENDER_RAYTRACING::add_3D_models( const S3DMODEL *a3DModel,
const glm::mat4 &aModelMatrix,
float aModuleOpacity )
{ {
// Validate a3DModel pointers
wxASSERT( a3DModel != NULL );
if( a3DModel == NULL )
return;
wxASSERT( a3DModel->m_Materials != NULL );
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) )
{
MODEL_MATERIALS *materialVector; MODEL_MATERIALS *materialVector;
// Try find if the materials already exists in the map list // Try find if the materials already exists in the map list
@ -1485,6 +1459,44 @@ void C3D_RENDER_RAYTRACING::add_3D_models( const S3DMODEL *a3DModel,
} }
} }
return materialVector;
}
void C3D_RENDER_RAYTRACING::add_3D_models( const S3DMODEL *a3DModel,
const glm::mat4 &aModelMatrix,
float aModuleOpacity,
bool aSkipMaterialInformation )
{
// Validate a3DModel pointers
wxASSERT( a3DModel != NULL );
if( a3DModel == NULL )
return;
wxASSERT( a3DModel->m_Materials != NULL );
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) )
{
MODEL_MATERIALS *materialVector = NULL;
if( !aSkipMaterialInformation )
{
materialVector = get_3D_model_material( a3DModel );
}
const glm::mat3 normalMatrix = glm::transpose( glm::inverse( glm::mat3( aModelMatrix ) ) ); const glm::mat3 normalMatrix = glm::transpose( glm::inverse( glm::mat3( aModelMatrix ) ) );
for( unsigned int mesh_i = 0; for( unsigned int mesh_i = 0;
@ -1551,8 +1563,10 @@ void C3D_RENDER_RAYTRACING::add_3D_models( const S3DMODEL *a3DModel,
nt0, nt2, nt1 ); nt0, nt2, nt1 );
m_object_container.Add( newTriangle ); m_object_container.Add( newTriangle );
newTriangle->SetMaterial( (const CMATERIAL *)&blinn_material );
if( !aSkipMaterialInformation )
{
newTriangle->SetMaterial( (const CMATERIAL *)&blinn_material );
newTriangle->SetModelTransparency( moduleTransparency ); newTriangle->SetModelTransparency( moduleTransparency );
if( mesh.m_Color == NULL ) if( mesh.m_Color == NULL )
@ -1582,3 +1596,4 @@ void C3D_RENDER_RAYTRACING::add_3D_models( const S3DMODEL *a3DModel,
} }
} }
} }
}

View File

@ -201,10 +201,13 @@ private:
void add_3D_vias_and_pads_to_container(); void add_3D_vias_and_pads_to_container();
void insert3DViaHole( const VIA* aVia ); void insert3DViaHole( const VIA* aVia );
void insert3DPadHole( const D_PAD* aPad ); void insert3DPadHole( const D_PAD* aPad );
void load_3D_models(); void load_3D_models( bool aSkipMaterialInformation );
void add_3D_models( const S3DMODEL *a3DModel, void add_3D_models( const S3DMODEL *a3DModel,
const glm::mat4 &aModelMatrix, const glm::mat4 &aModelMatrix,
float aModuleOpacity ); float aModuleOpacity,
bool aSkipMaterialInformation );
MODEL_MATERIALS *get_3D_model_material( const S3DMODEL *a3DModel );
/// Stores materials of the 3D models /// Stores materials of the 3D models
MAP_MODEL_MATERIALS m_model_materials; MAP_MODEL_MATERIALS m_model_materials;