From 0e11cfbe6ff115ed709fad07cb0e63309d992da3 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sun, 29 Mar 2015 18:53:23 +0200 Subject: [PATCH] add copy op for positions, normals and texture coordinates. Signed-off-by: Kim Kulling --- code/OpenGEXImporter.cpp | 60 +++++++++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/code/OpenGEXImporter.cpp b/code/OpenGEXImporter.cpp index 7188ce018..cf637f22d 100644 --- a/code/OpenGEXImporter.cpp +++ b/code/OpenGEXImporter.cpp @@ -562,6 +562,51 @@ static MeshAttribute getAttributeByName( const char *attribName ) { return None; } +//------------------------------------------------------------------------------------------------ +static void fillVector3( aiVector3D *vec3, Value *vals ) { + ai_assert( NULL != vec3 ); + ai_assert( NULL != vals ); + + float x( 0.0f ), y( 0.0f ), z( 0.0f ); + Value *next( vals ); + x = next->getFloat(); + next = next->m_next; + y = next->getFloat(); + next = next->m_next; + if( NULL != next ) { + z = next->getFloat(); + } + + vec3->Set( x, y, z ); +} + +//------------------------------------------------------------------------------------------------ +static size_t countDataArrayListItems( DataArrayList *vaList ) { + size_t numItems( 0 ); + if( NULL == vaList ) { + return numItems; + } + + DataArrayList *next( vaList ); + while( NULL != next ) { + if( NULL != vaList->m_dataList ) { + numItems++; + } + next = next->m_next; + } + + return numItems; +} + +//------------------------------------------------------------------------------------------------ +static void copyVectorArray( size_t numItems, DataArrayList *vaList, aiVector3D *vectorArray ) { + for( size_t i = 0; i < numItems; i++ ) { + Value *next( vaList->m_dataList ); + fillVector3( &vectorArray[ i ], next ); + vaList = vaList->m_next; + } +} + //------------------------------------------------------------------------------------------------ void OpenGEXImporter::handleVertexArrayNode( ODDLParser::DDLNode *node, aiScene *pScene ) { if( NULL == node ) { @@ -583,16 +628,17 @@ void OpenGEXImporter::handleVertexArrayNode( ODDLParser::DDLNode *node, aiScene return; } + const size_t numItems( countDataArrayListItems( vaList ) ); + Value *next( vaList->m_dataList ); if( Position == attribType ) { - aiVector3D *pos = new aiVector3D[ vaList->m_numItems ]; - Value *next( vaList->m_dataList ); - for( size_t i = 0; i < vaList->m_numItems; i++ ) { - - } + m_currentMesh->mVertices = new aiVector3D[ numItems ]; + copyVectorArray( numItems, vaList, m_currentMesh->mVertices ); } else if( Normal == attribType ) { - aiVector3D *normal = new aiVector3D[ vaList->m_numItems ]; + m_currentMesh->mNormals = new aiVector3D[ numItems ]; + copyVectorArray( numItems, vaList, m_currentMesh->mNormals ); } else if( TexCoord == attribType ) { - aiVector3D *tex = new aiVector3D[ vaList->m_numItems ]; + m_currentMesh->mTextureCoords[0] = new aiVector3D[ numItems ]; + copyVectorArray( numItems, vaList, m_currentMesh->mTextureCoords[0] ); } } }