color node handling opengex
Signed-off-by: Kim Kulling <kim.kulling@googlemail.com>pull/547/head
parent
ce939b5126
commit
995bc41d57
|
@ -79,6 +79,10 @@ namespace Grammar {
|
||||||
static const char *IndexArrayType = "IndexArray";
|
static const char *IndexArrayType = "IndexArray";
|
||||||
static const char *MaterialType = "Material";
|
static const char *MaterialType = "Material";
|
||||||
static const char *ColorType = "Color";
|
static const char *ColorType = "Color";
|
||||||
|
static const std::string DiffuseColorToken = "diffuse";
|
||||||
|
static const std::string SpecularColorToken = "specular";
|
||||||
|
static const std::string EmissionColorToken = "emission";
|
||||||
|
|
||||||
static const char *TextureType = "Texture";
|
static const char *TextureType = "Texture";
|
||||||
|
|
||||||
enum TokenType {
|
enum TokenType {
|
||||||
|
@ -362,9 +366,9 @@ void OpenGEXImporter::handleMetricNode( DDLNode *node, aiScene *pScene ) {
|
||||||
|
|
||||||
Property *prop( node->getProperties() );
|
Property *prop( node->getProperties() );
|
||||||
while( NULL != prop ) {
|
while( NULL != prop ) {
|
||||||
if( NULL != prop->m_id ) {
|
if( NULL != prop->m_key ) {
|
||||||
if( Value::ddl_string == prop->m_primData->m_type ) {
|
if( Value::ddl_string == prop->m_value->m_type ) {
|
||||||
std::string valName( (char*) prop->m_primData->m_data );
|
std::string valName( ( char* ) prop->m_value->m_data );
|
||||||
int type( Grammar::isValidMetricType( valName.c_str() ) );
|
int type( Grammar::isValidMetricType( valName.c_str() ) );
|
||||||
if( Grammar::NoneType != type ) {
|
if( Grammar::NoneType != type ) {
|
||||||
Value *val( node->getValue() );
|
Value *val( node->getValue() );
|
||||||
|
@ -414,7 +418,7 @@ static void getRefNames( DDLNode *node, std::vector<std::string> &names ) {
|
||||||
for( size_t i = 0; i < ref->m_numRefs; i++ ) {
|
for( size_t i = 0; i < ref->m_numRefs; i++ ) {
|
||||||
Name *currentName( ref->m_referencedName[ i ] );
|
Name *currentName( ref->m_referencedName[ i ] );
|
||||||
if( NULL != currentName && NULL != currentName->m_id ) {
|
if( NULL != currentName && NULL != currentName->m_id ) {
|
||||||
const std::string name( currentName->m_id->m_buffer );
|
const std::string name( currentName->m_id->m_text.m_buffer );
|
||||||
if( !name.empty() ) {
|
if( !name.empty() ) {
|
||||||
names.push_back( name );
|
names.push_back( name );
|
||||||
}
|
}
|
||||||
|
@ -529,10 +533,10 @@ static void propId2StdString( Property *prop, std::string &name, std::string &ke
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( NULL != prop->m_id ) {
|
if( NULL != prop->m_key ) {
|
||||||
name = prop->m_id->m_buffer;
|
name = prop->m_key->m_text.m_buffer;
|
||||||
if( Value::ddl_string == prop->m_primData->m_type ) {
|
if( Value::ddl_string == prop->m_value->m_type ) {
|
||||||
key = prop->m_primData->getString();
|
key = prop->m_value->getString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -704,7 +708,7 @@ void OpenGEXImporter::handleIndexArrayNode( ODDLParser::DDLNode *node, aiScene *
|
||||||
Value *next( vaList->m_dataList );
|
Value *next( vaList->m_dataList );
|
||||||
for( size_t indices = 0; indices < current.mNumIndices; indices++ ) {
|
for( size_t indices = 0; indices < current.mNumIndices; indices++ ) {
|
||||||
const int idx = next->getInt32();
|
const int idx = next->getInt32();
|
||||||
ai_assert( idx <= m_currentVertices.m_numVerts );
|
ai_assert( static_cast<size_t>( idx ) <= m_currentVertices.m_numVerts );
|
||||||
|
|
||||||
aiVector3D &pos = ( m_currentVertices.m_vertices[ idx ] );
|
aiVector3D &pos = ( m_currentVertices.m_vertices[ idx ] );
|
||||||
aiVector3D &normal = ( m_currentVertices.m_normals[ idx ] );
|
aiVector3D &normal = ( m_currentVertices.m_normals[ idx ] );
|
||||||
|
@ -724,7 +728,7 @@ void OpenGEXImporter::handleIndexArrayNode( ODDLParser::DDLNode *node, aiScene *
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------
|
||||||
static void getColorRGBA( aiColor3D *pColor, Value *data ) {
|
static void getColorRGB( aiColor3D *pColor, Value *data ) {
|
||||||
if( NULL == pColor || NULL == data ) {
|
if( NULL == pColor || NULL == data ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -740,14 +744,19 @@ static void getColorRGBA( aiColor3D *pColor, Value *data ) {
|
||||||
//------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------
|
||||||
enum ColorType {
|
enum ColorType {
|
||||||
NoneColor = 0,
|
NoneColor = 0,
|
||||||
DiffuseColor
|
DiffuseColor,
|
||||||
|
SpecularColor,
|
||||||
|
EmissionColor
|
||||||
};
|
};
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------
|
||||||
static ColorType getColorType( Identifier *id ) {
|
static ColorType getColorType( Identifier *id ) {
|
||||||
const int res(strncmp("diffuse", id->m_buffer, id->m_len ) );
|
if( id->m_text == Grammar::DiffuseColorToken ) {
|
||||||
if( 0 == res ) {
|
|
||||||
return DiffuseColor;
|
return DiffuseColor;
|
||||||
|
} else if( id->m_text == Grammar::SpecularColorToken ) {
|
||||||
|
return SpecularColor;
|
||||||
|
} else if( id->m_text == Grammar::EmissionColorToken ) {
|
||||||
|
return EmissionColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NoneColor;
|
return NoneColor;
|
||||||
|
@ -768,9 +777,19 @@ void OpenGEXImporter::handleColorNode( ODDLParser::DDLNode *node, aiScene *pScen
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Property *colorProp = node->getProperties();
|
Property *prop = node->findPropertyByName( "attrib" );
|
||||||
if( NULL != colorProp ) {
|
if( NULL != prop ) {
|
||||||
if( NULL != colorProp->m_id ) {
|
if( NULL != prop->m_value ) {
|
||||||
|
aiColor3D col;
|
||||||
|
getColorRGB( &col, prop->m_value );
|
||||||
|
const ColorType colType( getColorType( prop->m_key ) );
|
||||||
|
if( DiffuseColor == colType ) {
|
||||||
|
m_currentMaterial->AddProperty( &col, 1, AI_MATKEY_COLOR_DIFFUSE );
|
||||||
|
} else if( SpecularColor == colType ) {
|
||||||
|
m_currentMaterial->AddProperty( &col, 1, AI_MATKEY_COLOR_SPECULAR );
|
||||||
|
} else if( EmissionColor == colType ) {
|
||||||
|
m_currentMaterial->AddProperty( &col, 1, AI_MATKEY_COLOR_EMISSIVE );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -785,6 +804,7 @@ void OpenGEXImporter::copyMeshes( aiScene *pScene ) {
|
||||||
if( m_meshCache.empty() ) {
|
if( m_meshCache.empty() ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pScene->mNumMeshes = m_meshCache.size();
|
pScene->mNumMeshes = m_meshCache.size();
|
||||||
pScene->mMeshes = new aiMesh*[ pScene->mNumMeshes ];
|
pScene->mMeshes = new aiMesh*[ pScene->mNumMeshes ];
|
||||||
std::copy( m_meshCache.begin(), m_meshCache.end(), pScene->mMeshes );
|
std::copy( m_meshCache.begin(), m_meshCache.end(), pScene->mMeshes );
|
||||||
|
@ -828,13 +848,10 @@ void OpenGEXImporter::createNodeTree( aiScene *pScene ) {
|
||||||
if( m_root->m_children.empty() ) {
|
if( m_root->m_children.empty() ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
size_t i( 0 );
|
|
||||||
pScene->mRootNode->mNumChildren = m_root->m_children.size();
|
pScene->mRootNode->mNumChildren = m_root->m_children.size();
|
||||||
pScene->mRootNode->mChildren = new C_STRUCT aiNode*[ pScene->mRootNode->mNumChildren ];
|
pScene->mRootNode->mChildren = new aiNode*[ pScene->mRootNode->mNumChildren ];
|
||||||
for( ChildInfo::NodeList::iterator it = m_root->m_children.begin(); it != m_root->m_children.end(); it++ ) {
|
std::copy( m_root->m_children.begin(), m_root->m_children.end(), pScene->mRootNode->mChildren );
|
||||||
pScene->mRootNode->mChildren[ i ] = *it;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue