From 207906f0393e829fffc4260129e0f6fb681f585f Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Mon, 16 Mar 2015 20:34:42 +0100 Subject: [PATCH] first parsing of references and geometry objects. Signed-off-by: Kim Kulling --- code/OpenGEXImporter.cpp | 47 +++++++++++++++++-- code/OpenGEXImporter.h | 6 +++ contrib/openddlparser/code/OpenDDLParser.cpp | 6 +-- .../include/openddlparser/OpenDDLCommon.h | 4 +- .../openddlparser/OpenDDLParserUtils.h | 4 +- 5 files changed, 58 insertions(+), 9 deletions(-) diff --git a/code/OpenGEXImporter.cpp b/code/OpenGEXImporter.cpp index 0b940d39e..9c953b035 100644 --- a/code/OpenGEXImporter.cpp +++ b/code/OpenGEXImporter.cpp @@ -164,7 +164,9 @@ USE_ODDLPARSER_NS //------------------------------------------------------------------------------------------------ OpenGEXImporter::OpenGEXImporter() -: m_ctx( NULL ) +: m_meshCache() +, m_mesh2refMap() +, m_ctx( NULL ) , m_currentNode( NULL ) { // empty } @@ -205,6 +207,8 @@ void OpenGEXImporter::InternReadFile( const std::string &filename, aiScene *pSce m_ctx = myParser.getContext(); handleNodes( m_ctx->m_root, pScene ); } + + resolveReferences(); } //------------------------------------------------------------------------------------------------ @@ -238,6 +242,9 @@ void OpenGEXImporter::handleNodes( DDLNode *node, aiScene *pScene ) { break; case Grammar::ObjectRefToken: + handleObjectRefNode( *it, pScene ); + break; + case Grammar::MaterialRefToken: case Grammar::MetricKeyToken: case Grammar::GeometryNodeToken: @@ -245,6 +252,9 @@ void OpenGEXImporter::handleNodes( DDLNode *node, aiScene *pScene ) { break; case Grammar::GeometryObjectToken: + handleGeometryObject( *it, pScene ); + break; + case Grammar::TransformToken: case Grammar::MeshToken: case Grammar::VertexArrayToken: @@ -295,7 +305,7 @@ void OpenGEXImporter::handleMetricNode( DDLNode *node, aiScene *pScene ) { } //------------------------------------------------------------------------------------------------ -void OpenGEXImporter::handleNameNode( ODDLParser::DDLNode *node, aiScene *pScene ) { +void OpenGEXImporter::handleNameNode( DDLNode *node, aiScene *pScene ) { if( NULL == m_currentNode ) { throw DeadlyImportError( "No parent node for name." ); return; @@ -313,11 +323,42 @@ void OpenGEXImporter::handleNameNode( ODDLParser::DDLNode *node, aiScene *pScene } //------------------------------------------------------------------------------------------------ -void OpenGEXImporter::handleGeometryNode( ODDLParser::DDLNode *node, aiScene *pScene ) { +void OpenGEXImporter::handleObjectRefNode( DDLNode *node, aiScene *pScene ) { + if( NULL == m_currentNode ) { + throw DeadlyImportError( "No parent node for name." ); + return; + } + + Reference *ref = node->getReferences(); + if( NULL != ref ) { + for( size_t i = 0; i < ref->m_numRefs; i++ ) { + Name *currentName( ref->m_referencedName[ i ] ); + } + } +} + +//------------------------------------------------------------------------------------------------ +void OpenGEXImporter::handleGeometryNode( DDLNode *node, aiScene *pScene ) { m_currentNode = new aiNode; handleNodes( node, pScene ); } +//------------------------------------------------------------------------------------------------ +void OpenGEXImporter::handleGeometryObject( DDLNode *node, aiScene *pScene ) { + aiMesh *currentMesh( new aiMesh ); + const size_t idx( m_meshCache.size() ); + m_meshCache.push_back( currentMesh ); + + // store name to reference relation + m_mesh2refMap[ node->getName() ] = idx; + +} + +//------------------------------------------------------------------------------------------------ +void OpenGEXImporter::resolveReferences() { + +} + //------------------------------------------------------------------------------------------------ } // Namespace OpenGEX diff --git a/code/OpenGEXImporter.h b/code/OpenGEXImporter.h index 2bea23b45..105716f3c 100644 --- a/code/OpenGEXImporter.h +++ b/code/OpenGEXImporter.h @@ -44,6 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "BaseImporter.h" +#include namespace ODDLParser { class DDLNode; @@ -100,9 +101,14 @@ protected: void handleNodes( ODDLParser::DDLNode *node, aiScene *pScene ); void handleMetricNode( ODDLParser::DDLNode *node, aiScene *pScene ); void handleNameNode( ODDLParser::DDLNode *node, aiScene *pScene ); + void handleObjectRefNode( ODDLParser::DDLNode *node, aiScene *pScene ); void handleGeometryNode( ODDLParser::DDLNode *node, aiScene *pScene ); + void handleGeometryObject( ODDLParser::DDLNode *node, aiScene *pScene ); + void resolveReferences(); private: + std::vector m_meshCache; + std::map m_mesh2refMap; ODDLParser::Context *m_ctx; MetricInfo m_metrics[ MetricInfo::Max ]; aiNode *m_currentNode; diff --git a/contrib/openddlparser/code/OpenDDLParser.cpp b/contrib/openddlparser/code/OpenDDLParser.cpp index 46eb50fd8..99274f412 100644 --- a/contrib/openddlparser/code/OpenDDLParser.cpp +++ b/contrib/openddlparser/code/OpenDDLParser.cpp @@ -65,7 +65,7 @@ namespace Grammar { } // Namespace Grammar -static void logInvalidTokenError( char *in, char *exp, OpenDDLParser::logCallback callback ) { +static void logInvalidTokenError( char *in, const std::string &exp, OpenDDLParser::logCallback callback ) { std::stringstream stream; stream << "Invalid token " << *in << ", " << exp << " expected." << std::endl; callback( ddl_error_msg, stream.str() ); @@ -297,7 +297,7 @@ char *OpenDDLParser::parseStructure( char *in, char *end ) { } else { in++; - logInvalidTokenError( in, "{", m_logCallback ); + logInvalidTokenError( in, std::string( Grammar::OpenBracketToken ), m_logCallback ); error = true; return in; } @@ -365,7 +365,7 @@ char *OpenDDLParser::parseStructureBody( char *in, char *end, bool &error ) { in = getNextToken( in, end ); if( *in != '}' ) { - logInvalidTokenError( in, "}", m_logCallback ); + logInvalidTokenError( in, std::string( Grammar::CloseBracketToken ), m_logCallback ); } else { //in++; } diff --git a/contrib/openddlparser/include/openddlparser/OpenDDLCommon.h b/contrib/openddlparser/include/openddlparser/OpenDDLCommon.h index c7fd844a2..4a1ff2749 100644 --- a/contrib/openddlparser/include/openddlparser/OpenDDLCommon.h +++ b/contrib/openddlparser/include/openddlparser/OpenDDLCommon.h @@ -35,7 +35,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # ifdef OPENDDLPARSER_BUILD # define DLL_ODDLPARSER_EXPORT TAG_DLL_EXPORT # else -# define DLL_ODDLPARSER_EXPORT TAG_DLL_IMPORT +# define DLL_ODDLPARSER_EXPORT TAG_DLL_IMPORT # endif // OPENDDLPARSER_BUILD # pragma warning( disable : 4251 ) #else @@ -52,7 +52,7 @@ BEGIN_ODDLPARSER_NS # define ddl_nullptr nullptr #else # define ddl_nullptr NULL -#endif +#endif // OPENDDL_NO_USE_CPP11 class DDLNode; class Value; diff --git a/contrib/openddlparser/include/openddlparser/OpenDDLParserUtils.h b/contrib/openddlparser/include/openddlparser/OpenDDLParserUtils.h index b1b4f6cde..eb900309c 100644 --- a/contrib/openddlparser/include/openddlparser/OpenDDLParserUtils.h +++ b/contrib/openddlparser/include/openddlparser/OpenDDLParserUtils.h @@ -202,7 +202,9 @@ bool isReference( T *in, T *end ) { if( *in == 'r' ) { if( *(in+1) == 'e' ) { if( *(in+2) == 'f' ) { - return true; + if( ( in + 2 ) != end ) { + return true; + } } } }