Merge pull request #4647 from sashashura/patch-5

Fixes Crash in Assimp::ObjFileMtlImporter::getFloatValue
pull/4646/head^2
Kim Kulling 2022-07-18 14:05:50 +02:00 committed by GitHub
commit 316f6e841c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 32 additions and 16 deletions

View File

@ -126,16 +126,20 @@ void ObjFileMtlImporter::load() {
if (*m_DataIt == 'a') // Ambient color
{
++m_DataIt;
if (m_pModel->m_pCurrentMaterial != nullptr)
getColorRGBA(&m_pModel->m_pCurrentMaterial->ambient);
} else if (*m_DataIt == 'd') {
// Diffuse color
++m_DataIt;
if (m_pModel->m_pCurrentMaterial != nullptr)
getColorRGBA(&m_pModel->m_pCurrentMaterial->diffuse);
} else if (*m_DataIt == 's') {
++m_DataIt;
if (m_pModel->m_pCurrentMaterial != nullptr)
getColorRGBA(&m_pModel->m_pCurrentMaterial->specular);
} else if (*m_DataIt == 'e') {
++m_DataIt;
if (m_pModel->m_pCurrentMaterial != nullptr)
getColorRGBA(&m_pModel->m_pCurrentMaterial->emissive);
}
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
@ -145,12 +149,14 @@ void ObjFileMtlImporter::load() {
// Material transmission color
if (*m_DataIt == 'f') {
++m_DataIt;
if (m_pModel->m_pCurrentMaterial != nullptr)
getColorRGBA(&m_pModel->m_pCurrentMaterial->transparent);
} else if (*m_DataIt == 'r') {
// Material transmission alpha value
++m_DataIt;
ai_real d;
getFloatValue(d);
if (m_pModel->m_pCurrentMaterial != nullptr)
m_pModel->m_pCurrentMaterial->alpha = static_cast<ai_real>(1.0) - d;
}
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
@ -162,6 +168,7 @@ void ObjFileMtlImporter::load() {
} else {
// Alpha value
++m_DataIt;
if (m_pModel->m_pCurrentMaterial != nullptr)
getFloatValue(m_pModel->m_pCurrentMaterial->alpha);
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
}
@ -173,10 +180,12 @@ void ObjFileMtlImporter::load() {
switch (*m_DataIt) {
case 's': // Specular exponent
++m_DataIt;
if (m_pModel->m_pCurrentMaterial != nullptr)
getFloatValue(m_pModel->m_pCurrentMaterial->shineness);
break;
case 'i': // Index Of refraction
++m_DataIt;
if (m_pModel->m_pCurrentMaterial != nullptr)
getFloatValue(m_pModel->m_pCurrentMaterial->ior);
break;
case 'e': // New material
@ -197,22 +206,27 @@ void ObjFileMtlImporter::load() {
{
case 'r':
++m_DataIt;
if (m_pModel->m_pCurrentMaterial != nullptr)
getFloatValue(m_pModel->m_pCurrentMaterial->roughness);
break;
case 'm':
++m_DataIt;
if (m_pModel->m_pCurrentMaterial != nullptr)
getFloatValue(m_pModel->m_pCurrentMaterial->metallic);
break;
case 's':
++m_DataIt;
if (m_pModel->m_pCurrentMaterial != nullptr)
getColorRGBA(m_pModel->m_pCurrentMaterial->sheen);
break;
case 'c':
++m_DataIt;
if (*m_DataIt == 'r') {
++m_DataIt;
if (m_pModel->m_pCurrentMaterial != nullptr)
getFloatValue(m_pModel->m_pCurrentMaterial->clearcoat_roughness);
} else {
if (m_pModel->m_pCurrentMaterial != nullptr)
getFloatValue(m_pModel->m_pCurrentMaterial->clearcoat_thickness);
}
break;
@ -232,6 +246,7 @@ void ObjFileMtlImporter::load() {
case 'i': // Illumination model
{
m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
if (m_pModel->m_pCurrentMaterial != nullptr)
getIlluminationModel(m_pModel->m_pCurrentMaterial->illumination_model);
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
} break;
@ -240,6 +255,7 @@ void ObjFileMtlImporter::load() {
{
++m_DataIt;
getFloatValue(m_pModel->m_pCurrentMaterial->anisotropy);
if (m_pModel->m_pCurrentMaterial != nullptr)
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
} break;