add geomentry node handling.
Signed-off-by: Kim Kulling <kim.kulling@googlemail.com>pull/502/head
parent
f5f0c9f7cf
commit
0292868917
|
@ -164,7 +164,8 @@ USE_ODDLPARSER_NS
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------
|
||||||
OpenGEXImporter::OpenGEXImporter()
|
OpenGEXImporter::OpenGEXImporter()
|
||||||
: m_ctx( NULL ) {
|
: m_ctx( NULL )
|
||||||
|
, m_currentNode( NULL ) {
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,7 +203,7 @@ void OpenGEXImporter::InternReadFile( const std::string &filename, aiScene *pSce
|
||||||
bool success( myParser.parse() );
|
bool success( myParser.parse() );
|
||||||
if( success ) {
|
if( success ) {
|
||||||
m_ctx = myParser.getContext();
|
m_ctx = myParser.getContext();
|
||||||
handleNodes( m_ctx->m_root );
|
handleNodes( m_ctx->m_root, pScene );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,7 +220,7 @@ void OpenGEXImporter::SetupProperties( const Importer *pImp ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------
|
||||||
void OpenGEXImporter::handleNodes( DDLNode *node ) {
|
void OpenGEXImporter::handleNodes( DDLNode *node, aiScene *pScene ) {
|
||||||
if( NULL == node ) {
|
if( NULL == node ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -229,14 +230,20 @@ void OpenGEXImporter::handleNodes( DDLNode *node ) {
|
||||||
Grammar::TokenType tokenType( Grammar::matchTokenType( ( *it )->getType().c_str() ) );
|
Grammar::TokenType tokenType( Grammar::matchTokenType( ( *it )->getType().c_str() ) );
|
||||||
switch( tokenType ) {
|
switch( tokenType ) {
|
||||||
case Grammar::MetricToken:
|
case Grammar::MetricToken:
|
||||||
importMetric( *it );
|
handleMetricNode( *it, pScene );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Grammar::NameToken:
|
case Grammar::NameToken:
|
||||||
|
handleNameNode( *it, pScene );
|
||||||
|
break;
|
||||||
|
|
||||||
case Grammar::ObjectRefToken:
|
case Grammar::ObjectRefToken:
|
||||||
case Grammar::MaterialRefToken:
|
case Grammar::MaterialRefToken:
|
||||||
case Grammar::MetricKeyToken:
|
case Grammar::MetricKeyToken:
|
||||||
case Grammar::GeometryNodeToken:
|
case Grammar::GeometryNodeToken:
|
||||||
|
handleGeometryNode( *it, pScene );
|
||||||
|
break;
|
||||||
|
|
||||||
case Grammar::GeometryObjectToken:
|
case Grammar::GeometryObjectToken:
|
||||||
case Grammar::TransformToken:
|
case Grammar::TransformToken:
|
||||||
case Grammar::MeshToken:
|
case Grammar::MeshToken:
|
||||||
|
@ -252,7 +259,7 @@ void OpenGEXImporter::handleNodes( DDLNode *node ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------
|
||||||
void OpenGEXImporter::importMetric( DDLNode *node ) {
|
void OpenGEXImporter::handleMetricNode( DDLNode *node, aiScene *pScene ) {
|
||||||
if( NULL == node || NULL == m_ctx ) {
|
if( NULL == node || NULL == m_ctx ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -267,13 +274,15 @@ void OpenGEXImporter::importMetric( DDLNode *node ) {
|
||||||
if( Value::ddl_string == prop->m_primData->m_type ) {
|
if( Value::ddl_string == prop->m_primData->m_type ) {
|
||||||
std::string valName( (char*) prop->m_primData->m_data );
|
std::string valName( (char*) prop->m_primData->m_data );
|
||||||
int type( Grammar::isValidMetricType( valName.c_str() ) );
|
int type( Grammar::isValidMetricType( valName.c_str() ) );
|
||||||
if( -1 != type ) {
|
if( Grammar::NoneType != type ) {
|
||||||
Value *val( node->getValue() );
|
Value *val( node->getValue() );
|
||||||
if( NULL != val ) {
|
if( NULL != val ) {
|
||||||
if( Value::ddl_float == val->m_type ) {
|
if( Value::ddl_float == val->m_type ) {
|
||||||
m_metrics[ type ].m_floatValue = val->getFloat();
|
m_metrics[ type ].m_floatValue = val->getFloat();
|
||||||
} else if( Value::ddl_int32 == val->m_type ) {
|
} else if( Value::ddl_int32 == val->m_type ) {
|
||||||
m_metrics[ type ].m_floatValue = val->getInt32();
|
m_metrics[ type ].m_floatValue = val->getInt32();
|
||||||
|
} else if( Value::ddl_string == val->m_type ) {
|
||||||
|
m_metrics[type].m_stringValue = std::string( val->getString() );
|
||||||
} else {
|
} else {
|
||||||
throw DeadlyImportError( "OpenGEX: invalid data type for Metric node." );
|
throw DeadlyImportError( "OpenGEX: invalid data type for Metric node." );
|
||||||
}
|
}
|
||||||
|
@ -286,13 +295,27 @@ void OpenGEXImporter::importMetric( DDLNode *node ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------
|
||||||
void OpenGEXImporter::ParseGeoObject() {
|
void OpenGEXImporter::handleNameNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
|
||||||
|
if( NULL == m_currentNode ) {
|
||||||
|
throw DeadlyImportError( "No parent node for name." );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Value *val( node->getValue() );
|
||||||
|
if( NULL != val ) {
|
||||||
|
if( Value::ddl_string != val->m_type ) {
|
||||||
|
throw DeadlyImportError( "OpenGEX: invalid data type for value in node name." );
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string name( val->getString() );
|
||||||
|
m_currentNode->mName.Set( name.c_str() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------
|
||||||
void OpenGEXImporter::ParseMaterial() {
|
void OpenGEXImporter::handleGeometryNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
|
||||||
|
m_currentNode = new aiNode;
|
||||||
|
handleNodes( node, pScene );
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -64,6 +64,12 @@ struct MetricInfo {
|
||||||
|
|
||||||
std::string m_stringValue;
|
std::string m_stringValue;
|
||||||
float m_floatValue;
|
float m_floatValue;
|
||||||
|
|
||||||
|
MetricInfo()
|
||||||
|
: m_stringValue( "" )
|
||||||
|
, m_floatValue( 0.0f ) {
|
||||||
|
// empty
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @brief This class is used to implement the OpenGEX importer
|
/** @brief This class is used to implement the OpenGEX importer
|
||||||
|
@ -91,14 +97,15 @@ public:
|
||||||
virtual void SetupProperties( const Importer *pImp );
|
virtual void SetupProperties( const Importer *pImp );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void handleNodes( ODDLParser::DDLNode *node );
|
void handleNodes( ODDLParser::DDLNode *node, aiScene *pScene );
|
||||||
void importMetric( ODDLParser::DDLNode *node );
|
void handleMetricNode( ODDLParser::DDLNode *node, aiScene *pScene );
|
||||||
void ParseGeoObject();
|
void handleNameNode( ODDLParser::DDLNode *node, aiScene *pScene );
|
||||||
void ParseMaterial();
|
void handleGeometryNode( ODDLParser::DDLNode *node, aiScene *pScene );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ODDLParser::Context *m_ctx;
|
ODDLParser::Context *m_ctx;
|
||||||
MetricInfo m_metrics[ MetricInfo::Max ];
|
MetricInfo m_metrics[ MetricInfo::Max ];
|
||||||
|
aiNode *m_currentNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Namespace OpenGEX
|
} // Namespace OpenGEX
|
||||||
|
|
|
@ -669,7 +669,7 @@ char *OpenDDLParser::parseStringLiteral( char *in, char *end, Value **stringData
|
||||||
len++;
|
len++;
|
||||||
}
|
}
|
||||||
|
|
||||||
*stringData = ValueAllocator::allocPrimData( Value::ddl_string, len + 1 );
|
*stringData = ValueAllocator::allocPrimData( Value::ddl_string, len );
|
||||||
::strncpy( ( char* ) ( *stringData )->m_data, start, len );
|
::strncpy( ( char* ) ( *stringData )->m_data, start, len );
|
||||||
( *stringData )->m_data[len] = '\0';
|
( *stringData )->m_data[len] = '\0';
|
||||||
in++;
|
in++;
|
||||||
|
|
Loading…
Reference in New Issue