fix color handling in opengex importer.

Signed-off-by: Kim Kulling <kim.kulling@googlemail.com>
pull/548/head
Kim Kulling 2015-04-30 12:54:59 +02:00
parent 880cb473b0
commit 31cce98680
2 changed files with 29 additions and 13 deletions

View File

@ -728,17 +728,18 @@ void OpenGEXImporter::handleIndexArrayNode( ODDLParser::DDLNode *node, aiScene *
} }
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------
static void getColorRGB( aiColor3D *pColor, Value *data ) { static void getColorRGB( aiColor3D *pColor, DataArrayList *colList ) {
if( NULL == pColor || NULL == data ) { if( NULL == pColor || NULL == colList ) {
return; return;
} }
pColor->r = data->getFloat(); ai_assert( 3, colList->m_numItems );
data = data->getNext(); Value *val( colList->m_dataList );
pColor->g = data->getFloat(); pColor->r = val->getFloat();
data = data->getNext(); val = val->getNext();
pColor->b = data->getFloat(); pColor->g = val->getFloat();
data = data->getNext(); val = val->getNext();
pColor->b = val->getFloat();
} }
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------
@ -780,8 +781,12 @@ void OpenGEXImporter::handleColorNode( ODDLParser::DDLNode *node, aiScene *pScen
Property *prop = node->findPropertyByName( "attrib" ); Property *prop = node->findPropertyByName( "attrib" );
if( NULL != prop ) { if( NULL != prop ) {
if( NULL != prop->m_value ) { if( NULL != prop->m_value ) {
DataArrayList *colList( node->getDataArrayList() );
if( NULL == colList ) {
return;
}
aiColor3D col; aiColor3D col;
getColorRGB( &col, prop->m_value ); getColorRGB( &col, colList );
const ColorType colType( getColorType( prop->m_key ) ); const ColorType colType( getColorType( prop->m_key ) );
if( DiffuseColor == colType ) { if( DiffuseColor == colType ) {
m_currentMaterial->AddProperty( &col, 1, AI_MATKEY_COLOR_DIFFUSE ); m_currentMaterial->AddProperty( &col, 1, AI_MATKEY_COLOR_DIFFUSE );

View File

@ -107,6 +107,12 @@ bool isNumeric( const T in ) {
return false;*/ return false;*/
} }
template<class T>
inline
bool isNotEndOfToken( T *in, T *end ) {
return ( '}' != *in && ',' != *in && !isSpace( *in ) && in != end );
}
template<class T> template<class T>
inline inline
bool isInteger( T *in, T *end ) { bool isInteger( T *in, T *end ) {
@ -117,7 +123,8 @@ bool isInteger( T *in, T *end ) {
} }
bool result( false ); bool result( false );
while( '}' != *in && ',' != *in && !isSpace( *in ) && in != end ) { while( isNotEndOfToken( in, end ) ) {
//while( '}' != *in && ',' != *in && !isSpace( *in ) && in != end ) {
result = isNumeric( *in ); result = isNumeric( *in );
if( !result ) { if( !result ) {
break; break;
@ -139,7 +146,9 @@ bool isFloat( T *in, T *end ) {
// check for <1>.0f // check for <1>.0f
bool result( false ); bool result( false );
while( !isSpace( *in ) && in != end ) { while( isNotEndOfToken( in, end ) ) {
// while( !isSpace( *in ) && in != end ) {
if( *in == '.' ) { if( *in == '.' ) {
result = true; result = true;
break; break;
@ -159,7 +168,9 @@ bool isFloat( T *in, T *end ) {
} }
// check for 1.<0>f // check for 1.<0>f
while( !isSpace( *in ) && in != end && *in != ',' ) { while( isNotEndOfToken( in, end ) ) {
// while( !isSpace( *in ) && in != end && *in != ',' && *in != '}' ) {
result = isNumeric( *in ); result = isNumeric( *in );
if( !result ) { if( !result ) {
return false; return false;