From a45b5cdfb551a1b11e5df78a04ea025067e98dde Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 16 May 2017 21:45:23 +0200 Subject: [PATCH] OpenGEX: fix invalid handling with color4 token. --- code/OpenGEXImporter.cpp | 31 ++++++++++++++++++++++-- test/CMakeLists.txt | 2 ++ test/models/OpenGEX/light_issue1262.ogex | 21 ++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 test/models/OpenGEX/light_issue1262.ogex diff --git a/code/OpenGEXImporter.cpp b/code/OpenGEXImporter.cpp index a74af7584..93c0169d2 100644 --- a/code/OpenGEXImporter.cpp +++ b/code/OpenGEXImporter.cpp @@ -927,7 +927,7 @@ void OpenGEXImporter::handleIndexArrayNode( ODDLParser::DDLNode *node, aiScene * } //------------------------------------------------------------------------------------------------ -static void getColorRGB( aiColor3D *pColor, DataArrayList *colList ) { +static void getColorRGB3( aiColor3D *pColor, DataArrayList *colList ) { if( nullptr == pColor || nullptr == colList ) { return; } @@ -941,6 +941,23 @@ static void getColorRGB( aiColor3D *pColor, DataArrayList *colList ) { pColor->b = val->getFloat(); } +//------------------------------------------------------------------------------------------------ +static void getColorRGB4( aiColor4D *pColor, DataArrayList *colList ) { + if ( nullptr == pColor || nullptr == colList ) { + return; + } + + ai_assert( 4 == colList->m_numItems ); + Value *val( colList->m_dataList ); + pColor->r = val->getFloat(); + val = val->getNext(); + pColor->g = val->getFloat(); + val = val->getNext(); + pColor->b = val->getFloat(); + val = val->getNext(); + pColor->a = val->getFloat(); +} + //------------------------------------------------------------------------------------------------ enum ColorType { NoneColor = 0, @@ -991,7 +1008,17 @@ void OpenGEXImporter::handleColorNode( ODDLParser::DDLNode *node, aiScene *pScen return; } aiColor3D col; - getColorRGB( &col, colList ); + if ( 3 == colList->m_numItems ) { + aiColor3D col3; + getColorRGB3( &col3, colList ); + col = col3; + } else { + aiColor4D col4; + getColorRGB4( &col4, colList ); + col.r = col4.r; + col.g = col4.g; + col.b = col4.b; + } const ColorType colType( getColorType( prop->m_key ) ); if( DiffuseColor == colType ) { m_currentMaterial->AddProperty( &col, 1, AI_MATKEY_COLOR_DIFFUSE ); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e6c3624ea..fd438b13b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -106,11 +106,13 @@ SET( TEST_SRCS unit/SceneDiffer.cpp unit/utSIBImporter.cpp unit/utObjImportExport.cpp + unit/utOpenGEXImportExport.cpp unit/utPretransformVertices.cpp unit/utPLYImportExport.cpp unit/utRemoveComments.cpp unit/utRemoveComponent.cpp unit/utRemoveRedundantMaterials.cpp + unit/utRemoveVCProcess.cpp unit/utScenePreprocessor.cpp unit/utSharedPPData.cpp unit/utStringUtils.cpp diff --git a/test/models/OpenGEX/light_issue1262.ogex b/test/models/OpenGEX/light_issue1262.ogex new file mode 100644 index 000000000..da4723411 --- /dev/null +++ b/test/models/OpenGEX/light_issue1262.ogex @@ -0,0 +1,21 @@ +LightObject (type = "infinite") { + Param (attrib = "intensity") { + float { 3.0 } + } + + Color (attrib = "light") { + float[3] { { 0.7, 1.0, 0.1 } } + } +} + +LightObject (type = "point") { + Param (attrib = "intensity") { + float { 0.5 } + } +} + +LightObject (type = "spot") { + Color (attrib = "light") { + float[4] { { 0.1, 0.0, 0.1, 1.0 } } + } +} \ No newline at end of file