2014-08-27 21:00:19 +00:00
|
|
|
/*
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
|
|
|
Copyright (c) 2006-2014, assimp team
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the
|
|
|
|
following conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer.
|
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer in the documentation and/or other
|
|
|
|
materials provided with the distribution.
|
|
|
|
|
|
|
|
* Neither the name of the assimp team, nor the names of its
|
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
|
|
|
written permission of the assimp team.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
*/
|
2015-03-19 10:37:11 +00:00
|
|
|
#ifndef ASSIMP_BUILD_NO_OPENGEX_IMPORTER
|
2014-08-27 21:00:19 +00:00
|
|
|
|
|
|
|
#include "OpenGEXImporter.h"
|
2014-09-12 10:00:03 +00:00
|
|
|
#include "DefaultIOSystem.h"
|
2015-04-04 16:52:59 +00:00
|
|
|
#include "MakeVerboseFormat.h"
|
2014-09-12 10:00:03 +00:00
|
|
|
|
2015-02-07 11:47:53 +00:00
|
|
|
#include <openddlparser/OpenDDLParser.h>
|
2015-04-18 17:17:48 +00:00
|
|
|
#include <assimp/scene.h>
|
2015-04-30 11:47:33 +00:00
|
|
|
#include <assimp/ai_assert.h>
|
2015-02-07 11:47:53 +00:00
|
|
|
|
2015-05-18 01:56:01 +00:00
|
|
|
#include <algorithm>
|
2014-09-12 10:00:03 +00:00
|
|
|
#include <vector>
|
2014-08-27 21:00:19 +00:00
|
|
|
|
|
|
|
static const aiImporterDesc desc = {
|
|
|
|
"Open Game Engine Exchange",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
aiImporterFlags_SupportTextFlavour,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
"ogex"
|
|
|
|
};
|
|
|
|
|
2015-02-07 18:52:06 +00:00
|
|
|
namespace Grammar {
|
2015-02-10 19:09:26 +00:00
|
|
|
static const char *MetricType = "Metric";
|
|
|
|
static const char *Metric_DistanceType = "distance";
|
|
|
|
static const char *Metric_AngleType = "angle";
|
|
|
|
static const char *Metric_TimeType = "time";
|
|
|
|
static const char *Metric_UpType = "up";
|
|
|
|
static const char *NameType = "Name";
|
|
|
|
static const char *ObjectRefType = "ObjectRef";
|
|
|
|
static const char *MaterialRefType = "MaterialRef";
|
|
|
|
static const char *MetricKeyType = "key";
|
|
|
|
static const char *GeometryNodeType = "GeometryNode";
|
|
|
|
static const char *GeometryObjectType = "GeometryObject";
|
|
|
|
static const char *TransformType = "Transform";
|
|
|
|
static const char *MeshType = "Mesh";
|
|
|
|
static const char *VertexArrayType = "VertexArray";
|
|
|
|
static const char *IndexArrayType = "IndexArray";
|
|
|
|
static const char *MaterialType = "Material";
|
|
|
|
static const char *ColorType = "Color";
|
2015-04-29 09:57:39 +00:00
|
|
|
static const std::string DiffuseColorToken = "diffuse";
|
|
|
|
static const std::string SpecularColorToken = "specular";
|
|
|
|
static const std::string EmissionColorToken = "emission";
|
2015-05-29 18:45:31 +00:00
|
|
|
static const std::string DiffuseTextureToken = "diffuse";
|
2015-04-29 09:57:39 +00:00
|
|
|
|
2015-02-10 19:09:26 +00:00
|
|
|
static const char *TextureType = "Texture";
|
|
|
|
|
|
|
|
enum TokenType {
|
|
|
|
NoneType = -1,
|
|
|
|
MetricToken,
|
|
|
|
NameToken,
|
|
|
|
ObjectRefToken,
|
|
|
|
MaterialRefToken,
|
|
|
|
MetricKeyToken,
|
|
|
|
GeometryNodeToken,
|
|
|
|
GeometryObjectToken,
|
|
|
|
TransformToken,
|
|
|
|
MeshToken,
|
|
|
|
VertexArrayToken,
|
|
|
|
IndexArrayToken,
|
|
|
|
MaterialToken,
|
|
|
|
ColorToken,
|
|
|
|
TextureToken
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *ValidMetricToken[ 4 ] = {
|
|
|
|
Metric_DistanceType,
|
|
|
|
Metric_AngleType,
|
|
|
|
Metric_TimeType,
|
|
|
|
Metric_UpType
|
|
|
|
};
|
|
|
|
|
|
|
|
static int isValidMetricType( const char *token ) {
|
|
|
|
if( NULL == token ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int idx( -1 );
|
|
|
|
for( size_t i = 0; i < 4; i++ ) {
|
|
|
|
if( 0 == strncmp( ValidMetricToken[ i ], token, strlen( token ) ) ) {
|
|
|
|
idx = (int) i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
static TokenType matchTokenType( const char *tokenType ) {
|
2015-03-25 20:35:32 +00:00
|
|
|
if( 0 == strncmp( MetricType, tokenType, strlen( MetricType ) ) ) {
|
2015-02-10 19:09:26 +00:00
|
|
|
return MetricToken;
|
2015-03-25 20:35:32 +00:00
|
|
|
} else if( 0 == strncmp( NameType, tokenType, strlen( NameType ) ) ) {
|
2015-02-10 19:09:26 +00:00
|
|
|
return NameToken;
|
2015-03-25 20:35:32 +00:00
|
|
|
}
|
|
|
|
else if( 0 == strncmp( ObjectRefType, tokenType, strlen( ObjectRefType ) ) ) {
|
2015-02-10 19:09:26 +00:00
|
|
|
return ObjectRefToken;
|
2015-03-25 20:35:32 +00:00
|
|
|
}
|
|
|
|
else if( 0 == strncmp( MaterialRefType, tokenType, strlen( MaterialRefType ) ) ) {
|
2015-02-10 19:09:26 +00:00
|
|
|
return MaterialRefToken;
|
2015-03-25 20:35:32 +00:00
|
|
|
}
|
|
|
|
else if( 0 == strncmp( MetricKeyType, tokenType, strlen( MetricKeyType ) ) ) {
|
2015-02-10 19:09:26 +00:00
|
|
|
return MetricKeyToken;
|
2015-03-25 20:35:32 +00:00
|
|
|
}
|
|
|
|
else if( 0 == strncmp( GeometryNodeType, tokenType, strlen( GeometryNodeType ) ) ) {
|
2015-02-10 19:09:26 +00:00
|
|
|
return GeometryNodeToken;
|
2015-03-25 20:35:32 +00:00
|
|
|
}
|
|
|
|
else if( 0 == strncmp( GeometryObjectType, tokenType, strlen( GeometryObjectType ) ) ) {
|
2015-02-10 19:09:26 +00:00
|
|
|
return GeometryObjectToken;
|
2015-03-25 20:35:32 +00:00
|
|
|
}
|
|
|
|
else if( 0 == strncmp( TransformType, tokenType, strlen( TransformType ) ) ) {
|
2015-02-10 19:09:26 +00:00
|
|
|
return TransformToken;
|
2015-03-25 20:35:32 +00:00
|
|
|
}
|
|
|
|
else if( 0 == strncmp( MeshType, tokenType, strlen( MeshType ) ) ) {
|
2015-02-10 19:09:26 +00:00
|
|
|
return MeshToken;
|
2015-03-25 20:35:32 +00:00
|
|
|
}
|
|
|
|
else if( 0 == strncmp( VertexArrayType, tokenType, strlen( VertexArrayType ) ) ) {
|
2015-02-10 19:09:26 +00:00
|
|
|
return VertexArrayToken;
|
2015-03-25 20:35:32 +00:00
|
|
|
}
|
|
|
|
else if( 0 == strncmp( IndexArrayType, tokenType, strlen( IndexArrayType ) ) ) {
|
2015-02-10 19:09:26 +00:00
|
|
|
return IndexArrayToken;
|
2015-03-25 20:35:32 +00:00
|
|
|
}
|
|
|
|
else if( 0 == strncmp( MaterialType, tokenType, strlen( MaterialType ) ) ) {
|
2015-02-10 19:09:26 +00:00
|
|
|
return MaterialToken;
|
2015-03-25 20:35:32 +00:00
|
|
|
}
|
|
|
|
else if( 0 == strncmp( ColorType, tokenType, strlen( ColorType ) ) ) {
|
2015-02-10 19:09:26 +00:00
|
|
|
return ColorToken;
|
2015-03-25 20:35:32 +00:00
|
|
|
}
|
|
|
|
else if( 0 == strncmp( TextureType, tokenType, strlen( TextureType ) ) ) {
|
2015-02-10 19:09:26 +00:00
|
|
|
return TextureToken;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NoneType;
|
|
|
|
}
|
|
|
|
|
2015-02-07 18:52:06 +00:00
|
|
|
} // Namespace Grammar
|
|
|
|
|
2014-08-27 21:00:19 +00:00
|
|
|
namespace Assimp {
|
|
|
|
namespace OpenGEX {
|
|
|
|
|
2015-02-10 19:09:26 +00:00
|
|
|
USE_ODDLPARSER_NS
|
2015-02-07 11:47:53 +00:00
|
|
|
|
2015-04-06 12:56:12 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2015-04-04 16:52:59 +00:00
|
|
|
OpenGEXImporter::VertexContainer::VertexContainer()
|
2015-04-05 19:19:47 +00:00
|
|
|
: m_numVerts( 0 )
|
2015-05-18 01:56:01 +00:00
|
|
|
, m_vertices(NULL)
|
2015-04-05 19:19:47 +00:00
|
|
|
, m_numNormals( 0 )
|
2015-05-18 01:56:01 +00:00
|
|
|
, m_normals(NULL) {
|
|
|
|
std::fill(&m_numUVComps[0], &m_numUVComps[AI_MAX_NUMBER_OF_TEXTURECOORDS], 0U);
|
|
|
|
std::fill(&m_textureCoords[0], &m_textureCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS], static_cast<aiVector3D *>(NULL));
|
2015-04-04 16:52:59 +00:00
|
|
|
}
|
|
|
|
|
2015-04-06 12:56:12 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2015-04-04 16:52:59 +00:00
|
|
|
OpenGEXImporter::VertexContainer::~VertexContainer() {
|
|
|
|
delete[] m_vertices;
|
|
|
|
delete[] m_normals;
|
|
|
|
for( size_t i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; i++ ) {
|
2015-04-05 19:19:47 +00:00
|
|
|
delete [] m_textureCoords[ i ];
|
2015-04-04 16:52:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-17 13:25:40 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
OpenGEXImporter::RefInfo::RefInfo( aiNode *node, Type type, std::vector<std::string> &names )
|
|
|
|
: m_node( node )
|
|
|
|
, m_type( type )
|
|
|
|
, m_Names( names ) {
|
|
|
|
// empty
|
2015-03-19 10:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
OpenGEXImporter::RefInfo::~RefInfo() {
|
|
|
|
// empty
|
2015-03-17 13:25:40 +00:00
|
|
|
}
|
|
|
|
|
2014-08-27 21:00:19 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2015-02-10 19:09:26 +00:00
|
|
|
OpenGEXImporter::OpenGEXImporter()
|
2015-05-18 02:01:51 +00:00
|
|
|
: m_root( NULL )
|
2015-04-08 18:43:55 +00:00
|
|
|
, m_nodeChildMap()
|
2015-05-18 02:01:51 +00:00
|
|
|
, m_meshCache()
|
2015-03-16 19:34:42 +00:00
|
|
|
, m_mesh2refMap()
|
|
|
|
, m_ctx( NULL )
|
2015-03-17 13:25:40 +00:00
|
|
|
, m_currentNode( NULL )
|
2015-03-26 19:17:26 +00:00
|
|
|
, m_currentMesh( NULL )
|
2015-04-16 09:10:12 +00:00
|
|
|
, m_currentMaterial( NULL )
|
2015-05-05 20:27:05 +00:00
|
|
|
, m_tokenType( Grammar::NoneType )
|
2015-03-18 20:37:57 +00:00
|
|
|
, m_nodeStack()
|
2015-03-17 13:25:40 +00:00
|
|
|
, m_unresolvedRefStack() {
|
2015-05-18 02:01:51 +00:00
|
|
|
std::fill(&m_metrics[0], &m_metrics[MetricInfo::Max], MetricInfo());
|
2014-08-27 21:00:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
OpenGEXImporter::~OpenGEXImporter() {
|
2015-02-10 19:09:26 +00:00
|
|
|
m_ctx = NULL;
|
2014-08-27 21:00:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
bool OpenGEXImporter::CanRead( const std::string &file, IOSystem *pIOHandler, bool checkSig ) const {
|
2014-09-12 10:00:03 +00:00
|
|
|
bool canRead( false );
|
|
|
|
if( !checkSig ) {
|
|
|
|
canRead = SimpleExtensionCheck( file, "ogex" );
|
|
|
|
} else {
|
|
|
|
static const char *token[] = { "Metric", "GeometryNode", "VertexArray (attrib", "IndexArray" };
|
|
|
|
canRead = BaseImporter::SearchFileHeaderForToken( pIOHandler, file, token, 4 );
|
|
|
|
}
|
|
|
|
|
|
|
|
return canRead;
|
2014-08-27 21:00:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
2014-09-12 10:00:03 +00:00
|
|
|
void OpenGEXImporter::InternReadFile( const std::string &filename, aiScene *pScene, IOSystem *pIOHandler ) {
|
|
|
|
// open source file
|
|
|
|
IOStream *file = pIOHandler->Open( filename, "rb" );
|
|
|
|
if( !file ) {
|
|
|
|
throw DeadlyImportError( "Failed to open file " + filename );
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<char> buffer;
|
|
|
|
TextFileToBuffer( file, buffer );
|
2015-02-07 11:47:53 +00:00
|
|
|
|
|
|
|
OpenDDLParser myParser;
|
|
|
|
myParser.setBuffer( &buffer[ 0 ], buffer.size() );
|
|
|
|
bool success( myParser.parse() );
|
|
|
|
if( success ) {
|
2015-02-10 19:09:26 +00:00
|
|
|
m_ctx = myParser.getContext();
|
2015-03-18 20:37:57 +00:00
|
|
|
pScene->mRootNode = new aiNode;
|
|
|
|
pScene->mRootNode->mName.Set( filename );
|
2015-02-14 15:12:09 +00:00
|
|
|
handleNodes( m_ctx->m_root, pScene );
|
2015-02-07 11:47:53 +00:00
|
|
|
}
|
2015-03-16 19:34:42 +00:00
|
|
|
|
2015-03-30 21:54:32 +00:00
|
|
|
copyMeshes( pScene );
|
2015-03-16 19:34:42 +00:00
|
|
|
resolveReferences();
|
2015-04-08 18:43:55 +00:00
|
|
|
createNodeTree( pScene );
|
2014-08-27 21:00:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
const aiImporterDesc *OpenGEXImporter::GetInfo() const {
|
|
|
|
return &desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
void OpenGEXImporter::SetupProperties( const Importer *pImp ) {
|
2015-02-07 18:52:06 +00:00
|
|
|
if( NULL == pImp ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-09-12 10:00:03 +00:00
|
|
|
|
2015-02-07 18:52:06 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2015-02-14 15:12:09 +00:00
|
|
|
void OpenGEXImporter::handleNodes( DDLNode *node, aiScene *pScene ) {
|
2015-02-07 18:52:06 +00:00
|
|
|
if( NULL == node ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DDLNode::DllNodeList childs = node->getChildNodeList();
|
|
|
|
for( DDLNode::DllNodeList::iterator it = childs.begin(); it != childs.end(); it++ ) {
|
2015-02-10 19:09:26 +00:00
|
|
|
Grammar::TokenType tokenType( Grammar::matchTokenType( ( *it )->getType().c_str() ) );
|
|
|
|
switch( tokenType ) {
|
|
|
|
case Grammar::MetricToken:
|
2015-02-14 15:12:09 +00:00
|
|
|
handleMetricNode( *it, pScene );
|
2015-02-10 19:09:26 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Grammar::NameToken:
|
2015-02-14 15:12:09 +00:00
|
|
|
handleNameNode( *it, pScene );
|
|
|
|
break;
|
|
|
|
|
2015-02-10 19:09:26 +00:00
|
|
|
case Grammar::ObjectRefToken:
|
2015-03-16 19:34:42 +00:00
|
|
|
handleObjectRefNode( *it, pScene );
|
|
|
|
break;
|
|
|
|
|
2015-02-10 19:09:26 +00:00
|
|
|
case Grammar::MaterialRefToken:
|
2015-03-17 13:25:40 +00:00
|
|
|
handleMaterialRefNode( *it, pScene );
|
|
|
|
break;
|
|
|
|
|
2015-02-10 19:09:26 +00:00
|
|
|
case Grammar::MetricKeyToken:
|
2015-03-17 13:25:40 +00:00
|
|
|
break;
|
|
|
|
|
2015-02-10 19:09:26 +00:00
|
|
|
case Grammar::GeometryNodeToken:
|
2015-02-14 15:12:09 +00:00
|
|
|
handleGeometryNode( *it, pScene );
|
|
|
|
break;
|
|
|
|
|
2015-02-10 19:09:26 +00:00
|
|
|
case Grammar::GeometryObjectToken:
|
2015-03-16 19:34:42 +00:00
|
|
|
handleGeometryObject( *it, pScene );
|
|
|
|
break;
|
|
|
|
|
2015-02-10 19:09:26 +00:00
|
|
|
case Grammar::TransformToken:
|
2015-03-20 15:56:28 +00:00
|
|
|
handleTransformNode( *it, pScene );
|
2015-03-17 13:25:40 +00:00
|
|
|
break;
|
|
|
|
|
2015-02-10 19:09:26 +00:00
|
|
|
case Grammar::MeshToken:
|
2015-03-20 15:56:28 +00:00
|
|
|
handleMeshNode( *it, pScene );
|
2015-03-17 13:25:40 +00:00
|
|
|
break;
|
|
|
|
|
2015-02-10 19:09:26 +00:00
|
|
|
case Grammar::VertexArrayToken:
|
2015-03-20 15:56:28 +00:00
|
|
|
handleVertexArrayNode( *it, pScene );
|
2015-03-17 13:25:40 +00:00
|
|
|
break;
|
|
|
|
|
2015-02-10 19:09:26 +00:00
|
|
|
case Grammar::IndexArrayToken:
|
2015-03-20 15:56:28 +00:00
|
|
|
handleIndexArrayNode( *it, pScene );
|
2015-03-17 13:25:40 +00:00
|
|
|
break;
|
|
|
|
|
2015-02-10 19:09:26 +00:00
|
|
|
case Grammar::MaterialToken:
|
2015-03-20 15:56:28 +00:00
|
|
|
handleMaterialNode( *it, pScene );
|
2015-03-17 13:25:40 +00:00
|
|
|
break;
|
|
|
|
|
2015-02-10 19:09:26 +00:00
|
|
|
case Grammar::ColorToken:
|
2015-03-20 15:56:28 +00:00
|
|
|
handleColorNode( *it, pScene );
|
2015-03-17 13:25:40 +00:00
|
|
|
break;
|
|
|
|
|
2015-02-10 19:09:26 +00:00
|
|
|
case Grammar::TextureToken:
|
2015-03-20 15:56:28 +00:00
|
|
|
handleTextureNode( *it, pScene );
|
2015-03-17 13:25:40 +00:00
|
|
|
break;
|
|
|
|
|
2015-02-10 19:09:26 +00:00
|
|
|
default:
|
|
|
|
break;
|
2015-02-07 18:52:06 +00:00
|
|
|
}
|
|
|
|
}
|
2014-08-27 21:00:19 +00:00
|
|
|
}
|
|
|
|
|
2015-02-07 11:47:53 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2015-02-14 15:12:09 +00:00
|
|
|
void OpenGEXImporter::handleMetricNode( DDLNode *node, aiScene *pScene ) {
|
2015-02-10 19:09:26 +00:00
|
|
|
if( NULL == node || NULL == m_ctx ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_ctx->m_root != node->getParent() ) {
|
2015-02-07 11:47:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-02-07 18:52:06 +00:00
|
|
|
|
|
|
|
Property *prop( node->getProperties() );
|
|
|
|
while( NULL != prop ) {
|
2015-04-29 09:57:39 +00:00
|
|
|
if( NULL != prop->m_key ) {
|
|
|
|
if( Value::ddl_string == prop->m_value->m_type ) {
|
|
|
|
std::string valName( ( char* ) prop->m_value->m_data );
|
2015-02-10 19:09:26 +00:00
|
|
|
int type( Grammar::isValidMetricType( valName.c_str() ) );
|
2015-02-14 15:12:09 +00:00
|
|
|
if( Grammar::NoneType != type ) {
|
2015-02-10 19:09:26 +00:00
|
|
|
Value *val( node->getValue() );
|
|
|
|
if( NULL != val ) {
|
|
|
|
if( Value::ddl_float == val->m_type ) {
|
|
|
|
m_metrics[ type ].m_floatValue = val->getFloat();
|
|
|
|
} else if( Value::ddl_int32 == val->m_type ) {
|
2015-03-17 13:25:40 +00:00
|
|
|
m_metrics[ type ].m_intValue = val->getInt32();
|
2015-02-14 15:12:09 +00:00
|
|
|
} else if( Value::ddl_string == val->m_type ) {
|
|
|
|
m_metrics[type].m_stringValue = std::string( val->getString() );
|
2015-02-10 19:09:26 +00:00
|
|
|
} else {
|
|
|
|
throw DeadlyImportError( "OpenGEX: invalid data type for Metric node." );
|
|
|
|
}
|
|
|
|
}
|
2015-02-07 18:52:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
prop = prop->m_next;
|
|
|
|
}
|
2015-02-07 11:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
2015-03-16 19:34:42 +00:00
|
|
|
void OpenGEXImporter::handleNameNode( DDLNode *node, aiScene *pScene ) {
|
2015-02-14 15:12:09 +00:00
|
|
|
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." );
|
2015-03-25 20:35:32 +00:00
|
|
|
return;
|
2015-02-14 15:12:09 +00:00
|
|
|
}
|
2015-02-07 11:47:53 +00:00
|
|
|
|
2015-03-25 20:35:32 +00:00
|
|
|
const std::string name( val->getString() );
|
2015-05-05 20:27:05 +00:00
|
|
|
if( m_tokenType == Grammar::GeometryNodeToken ) {
|
|
|
|
m_currentNode->mName.Set( name.c_str() );
|
|
|
|
} else if( m_tokenType == Grammar::MaterialToken ) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-02-14 15:12:09 +00:00
|
|
|
}
|
2015-02-07 11:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
2015-03-17 13:25:40 +00:00
|
|
|
static void getRefNames( DDLNode *node, std::vector<std::string> &names ) {
|
|
|
|
ai_assert( NULL != node );
|
2015-03-16 19:34:42 +00:00
|
|
|
|
|
|
|
Reference *ref = node->getReferences();
|
|
|
|
if( NULL != ref ) {
|
|
|
|
for( size_t i = 0; i < ref->m_numRefs; i++ ) {
|
|
|
|
Name *currentName( ref->m_referencedName[ i ] );
|
2015-03-17 13:25:40 +00:00
|
|
|
if( NULL != currentName && NULL != currentName->m_id ) {
|
2015-04-29 09:57:39 +00:00
|
|
|
const std::string name( currentName->m_id->m_text.m_buffer );
|
2015-03-17 13:25:40 +00:00
|
|
|
if( !name.empty() ) {
|
|
|
|
names.push_back( name );
|
|
|
|
}
|
|
|
|
}
|
2015-03-16 19:34:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-17 13:25:40 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
void OpenGEXImporter::handleObjectRefNode( DDLNode *node, aiScene *pScene ) {
|
|
|
|
if( NULL == m_currentNode ) {
|
|
|
|
throw DeadlyImportError( "No parent node for name." );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> objRefNames;
|
|
|
|
getRefNames( node, objRefNames );
|
|
|
|
m_currentNode->mNumMeshes = objRefNames.size();
|
|
|
|
m_currentNode->mMeshes = new unsigned int[ objRefNames.size() ];
|
|
|
|
if( !objRefNames.empty() ) {
|
|
|
|
m_unresolvedRefStack.push_back( new RefInfo( m_currentNode, RefInfo::MeshRef, objRefNames ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
void OpenGEXImporter::handleMaterialRefNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
|
|
|
|
if( NULL == m_currentNode ) {
|
|
|
|
throw DeadlyImportError( "No parent node for name." );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> matRefNames;
|
|
|
|
getRefNames( node, matRefNames );
|
|
|
|
if( !matRefNames.empty() ) {
|
|
|
|
m_unresolvedRefStack.push_back( new RefInfo( m_currentNode, RefInfo::MaterialRef, matRefNames ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-16 19:34:42 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
void OpenGEXImporter::handleGeometryNode( DDLNode *node, aiScene *pScene ) {
|
2015-03-18 20:37:57 +00:00
|
|
|
aiNode *newNode = new aiNode;
|
|
|
|
pushNode( newNode, pScene );
|
2015-05-05 20:27:05 +00:00
|
|
|
m_tokenType = Grammar::GeometryNodeToken;
|
2015-03-18 20:37:57 +00:00
|
|
|
m_currentNode = newNode;
|
2015-02-14 15:12:09 +00:00
|
|
|
handleNodes( node, pScene );
|
2015-03-18 20:37:57 +00:00
|
|
|
|
|
|
|
popNode();
|
2015-02-07 11:47:53 +00:00
|
|
|
}
|
|
|
|
|
2015-03-16 19:34:42 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
void OpenGEXImporter::handleGeometryObject( DDLNode *node, aiScene *pScene ) {
|
2015-03-18 20:37:57 +00:00
|
|
|
handleNodes( node, pScene );
|
2015-03-17 13:25:40 +00:00
|
|
|
}
|
|
|
|
|
2015-03-23 23:08:42 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
static void setMatrix( aiNode *node, DataArrayList *transformData ) {
|
2015-03-25 20:35:32 +00:00
|
|
|
ai_assert( NULL != node );
|
|
|
|
ai_assert( NULL != transformData );
|
|
|
|
|
2015-03-23 23:08:42 +00:00
|
|
|
float m[ 16 ];
|
|
|
|
size_t i( 1 );
|
|
|
|
Value *next( transformData->m_dataList->m_next );
|
|
|
|
m[ 0 ] = transformData->m_dataList->getFloat();
|
|
|
|
while( next != NULL ) {
|
|
|
|
m[ i ] = next->getFloat();
|
|
|
|
next = next->m_next;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
node->mTransformation.a1 = m[ 0 ];
|
2015-05-29 18:50:09 +00:00
|
|
|
node->mTransformation.a2 = m[ 4 ];
|
|
|
|
node->mTransformation.a3 = m[ 8 ];
|
|
|
|
node->mTransformation.a4 = m[ 12 ];
|
2015-03-23 23:08:42 +00:00
|
|
|
|
2015-05-29 18:50:09 +00:00
|
|
|
node->mTransformation.b1 = m[ 1 ];
|
2015-03-23 23:08:42 +00:00
|
|
|
node->mTransformation.b2 = m[ 5 ];
|
2015-05-29 18:50:09 +00:00
|
|
|
node->mTransformation.b3 = m[ 9 ];
|
|
|
|
node->mTransformation.b4 = m[ 13 ];
|
2015-03-23 23:08:42 +00:00
|
|
|
|
2015-05-29 18:50:09 +00:00
|
|
|
node->mTransformation.c1 = m[ 2 ];
|
|
|
|
node->mTransformation.c2 = m[ 6 ];
|
2015-03-23 23:08:42 +00:00
|
|
|
node->mTransformation.c3 = m[ 10 ];
|
2015-05-29 18:50:09 +00:00
|
|
|
node->mTransformation.c4 = m[ 14 ];
|
2015-03-23 23:08:42 +00:00
|
|
|
|
2015-05-29 18:50:09 +00:00
|
|
|
node->mTransformation.d1 = m[ 3 ];
|
|
|
|
node->mTransformation.d2 = m[ 7 ];
|
|
|
|
node->mTransformation.d3 = m[ 11 ];
|
2015-03-23 23:08:42 +00:00
|
|
|
node->mTransformation.d4 = m[ 15 ];
|
2015-05-29 18:50:09 +00:00
|
|
|
|
2015-03-23 23:08:42 +00:00
|
|
|
}
|
|
|
|
|
2015-03-17 13:25:40 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2015-03-20 15:56:28 +00:00
|
|
|
void OpenGEXImporter::handleTransformNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
|
2015-03-23 23:08:42 +00:00
|
|
|
if( NULL == m_currentNode ) {
|
|
|
|
throw DeadlyImportError( "No parent node for name." );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-20 15:56:28 +00:00
|
|
|
|
2015-03-23 23:08:42 +00:00
|
|
|
DataArrayList *transformData( node->getDataArrayList() );
|
|
|
|
if( NULL != transformData ) {
|
|
|
|
if( transformData->m_numItems != 16 ) {
|
|
|
|
throw DeadlyImportError( "Invalid number of data for transform matrix." );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
setMatrix( m_currentNode, transformData );
|
|
|
|
}
|
2015-03-20 15:56:28 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 19:17:26 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
static void propId2StdString( Property *prop, std::string &name, std::string &key ) {
|
|
|
|
name = key = "";
|
|
|
|
if( NULL == prop ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-29 09:57:39 +00:00
|
|
|
if( NULL != prop->m_key ) {
|
|
|
|
name = prop->m_key->m_text.m_buffer;
|
|
|
|
if( Value::ddl_string == prop->m_value->m_type ) {
|
|
|
|
key = prop->m_value->getString();
|
2015-03-26 19:17:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-20 15:56:28 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
void OpenGEXImporter::handleMeshNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
|
2015-03-26 19:17:26 +00:00
|
|
|
m_currentMesh = new aiMesh;
|
2015-04-04 16:52:59 +00:00
|
|
|
const size_t meshidx( m_meshCache.size() );
|
2015-03-26 19:17:26 +00:00
|
|
|
m_meshCache.push_back( m_currentMesh );
|
|
|
|
|
2015-04-04 16:52:59 +00:00
|
|
|
Property *prop = node->getProperties();
|
2015-03-26 19:17:26 +00:00
|
|
|
if( NULL != prop ) {
|
|
|
|
std::string propName, propKey;
|
|
|
|
propId2StdString( prop, propName, propKey );
|
2015-03-28 11:08:59 +00:00
|
|
|
if( "primitive" == propName ) {
|
|
|
|
if( "triangles" == propKey ) {
|
|
|
|
m_currentMesh->mPrimitiveTypes |= aiPrimitiveType_TRIANGLE;
|
|
|
|
}
|
2015-03-26 19:17:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleNodes( node, pScene );
|
2015-04-06 12:56:12 +00:00
|
|
|
|
|
|
|
DDLNode *parent( node->getParent() );
|
|
|
|
if( NULL != parent ) {
|
|
|
|
const std::string &name = parent->getName();
|
|
|
|
m_mesh2refMap[ name ] = meshidx;
|
|
|
|
}
|
2015-03-26 19:17:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
enum MeshAttribute {
|
|
|
|
None,
|
|
|
|
Position,
|
|
|
|
Normal,
|
|
|
|
TexCoord
|
|
|
|
};
|
2015-03-20 15:56:28 +00:00
|
|
|
|
2015-03-26 19:17:26 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
static MeshAttribute getAttributeByName( const char *attribName ) {
|
|
|
|
ai_assert( NULL != attribName );
|
|
|
|
|
|
|
|
if( 0 == strncmp( "position", attribName, strlen( "position" ) ) ) {
|
|
|
|
return Position;
|
|
|
|
} else if( 0 == strncmp( "normal", attribName, strlen( "normal" ) ) ) {
|
|
|
|
return Normal;
|
|
|
|
} else if( 0 == strncmp( "texcoord", attribName, strlen( "texcoord" ) ) ) {
|
|
|
|
return TexCoord;
|
|
|
|
}
|
|
|
|
|
|
|
|
return None;
|
2015-03-20 15:56:28 +00:00
|
|
|
}
|
|
|
|
|
2015-03-29 16:53:23 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-20 15:56:28 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
void OpenGEXImporter::handleVertexArrayNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
|
2015-03-26 19:17:26 +00:00
|
|
|
if( NULL == node ) {
|
|
|
|
throw DeadlyImportError( "No parent node for name." );
|
|
|
|
return;
|
|
|
|
}
|
2015-03-20 15:56:28 +00:00
|
|
|
|
2015-03-26 19:17:26 +00:00
|
|
|
Property *prop( node->getProperties() );
|
|
|
|
if( NULL != prop ) {
|
|
|
|
std::string propName, propKey;
|
|
|
|
propId2StdString( prop, propName, propKey );
|
2015-03-28 11:08:59 +00:00
|
|
|
MeshAttribute attribType( getAttributeByName( propKey.c_str() ) );
|
2015-03-26 19:17:26 +00:00
|
|
|
if( None == attribType ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DataArrayList *vaList = node->getDataArrayList();
|
|
|
|
if( NULL == vaList ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-29 16:53:23 +00:00
|
|
|
const size_t numItems( countDataArrayListItems( vaList ) );
|
2015-03-26 19:17:26 +00:00
|
|
|
if( Position == attribType ) {
|
2015-04-04 16:52:59 +00:00
|
|
|
m_currentVertices.m_numVerts = numItems;
|
|
|
|
m_currentVertices.m_vertices = new aiVector3D[ numItems ];
|
|
|
|
copyVectorArray( numItems, vaList, m_currentVertices.m_vertices );
|
2015-03-26 19:17:26 +00:00
|
|
|
} else if( Normal == attribType ) {
|
2015-04-04 16:52:59 +00:00
|
|
|
m_currentVertices.m_numNormals = numItems;
|
|
|
|
m_currentVertices.m_normals = new aiVector3D[ numItems ];
|
|
|
|
copyVectorArray( numItems, vaList, m_currentVertices.m_normals );
|
2015-03-26 19:17:26 +00:00
|
|
|
} else if( TexCoord == attribType ) {
|
2015-04-04 16:52:59 +00:00
|
|
|
m_currentVertices.m_numUVComps[ 0 ] = numItems;
|
|
|
|
m_currentVertices.m_textureCoords[ 0 ] = new aiVector3D[ numItems ];
|
|
|
|
copyVectorArray( numItems, vaList, m_currentVertices.m_textureCoords[ 0 ] );
|
2015-03-26 19:17:26 +00:00
|
|
|
}
|
|
|
|
}
|
2015-03-20 15:56:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
void OpenGEXImporter::handleIndexArrayNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
|
2015-03-30 09:55:57 +00:00
|
|
|
if( NULL == node ) {
|
|
|
|
throw DeadlyImportError( "No parent node for name." );
|
|
|
|
return;
|
|
|
|
}
|
2015-03-20 15:56:28 +00:00
|
|
|
|
2015-04-04 16:52:59 +00:00
|
|
|
if( NULL == m_currentMesh ) {
|
|
|
|
throw DeadlyImportError( "No current mesh for index data found." );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-30 09:55:57 +00:00
|
|
|
DataArrayList *vaList = node->getDataArrayList();
|
|
|
|
if( NULL == vaList ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const size_t numItems( countDataArrayListItems( vaList ) );
|
|
|
|
m_currentMesh->mNumFaces = numItems;
|
|
|
|
m_currentMesh->mFaces = new aiFace[ numItems ];
|
2015-04-04 16:52:59 +00:00
|
|
|
m_currentMesh->mNumVertices = numItems * 3;
|
2015-04-05 19:19:47 +00:00
|
|
|
m_currentMesh->mVertices = new aiVector3D[ m_currentMesh->mNumVertices ];
|
|
|
|
m_currentMesh->mNormals = new aiVector3D[ m_currentMesh->mNumVertices ];
|
2015-04-04 16:52:59 +00:00
|
|
|
m_currentMesh->mNumUVComponents[ 0 ] = numItems * 3;
|
2015-04-05 21:17:16 +00:00
|
|
|
m_currentMesh->mTextureCoords[ 0 ] = new aiVector3D[ m_currentMesh->mNumUVComponents[ 0 ] ];
|
2015-04-04 16:52:59 +00:00
|
|
|
|
|
|
|
unsigned int index( 0 );
|
|
|
|
for( size_t i = 0; i < m_currentMesh->mNumFaces; i++ ) {
|
|
|
|
aiFace ¤t( m_currentMesh->mFaces[ i ] );
|
|
|
|
current.mNumIndices = 3;
|
|
|
|
current.mIndices = new unsigned int[ current.mNumIndices ];
|
2015-03-30 09:55:57 +00:00
|
|
|
Value *next( vaList->m_dataList );
|
2015-04-04 16:52:59 +00:00
|
|
|
for( size_t indices = 0; indices < current.mNumIndices; indices++ ) {
|
2015-04-01 23:10:53 +00:00
|
|
|
const int idx = next->getInt32();
|
2015-04-29 09:57:39 +00:00
|
|
|
ai_assert( static_cast<size_t>( idx ) <= m_currentVertices.m_numVerts );
|
2015-04-04 16:52:59 +00:00
|
|
|
|
2015-04-05 19:19:47 +00:00
|
|
|
aiVector3D &pos = ( m_currentVertices.m_vertices[ idx ] );
|
|
|
|
aiVector3D &normal = ( m_currentVertices.m_normals[ idx ] );
|
|
|
|
aiVector3D &tex = ( m_currentVertices.m_textureCoords[ 0 ][ idx ] );
|
2015-04-04 16:52:59 +00:00
|
|
|
|
|
|
|
ai_assert( index < m_currentMesh->mNumVertices );
|
2015-04-05 19:19:47 +00:00
|
|
|
m_currentMesh->mVertices[ index ].Set( pos.x, pos.y, pos.z );
|
|
|
|
m_currentMesh->mNormals[ index ].Set( normal.x, normal.y, normal.z );
|
|
|
|
m_currentMesh->mTextureCoords[0][ index ].Set( tex.x, tex.y, tex.z );
|
2015-04-04 16:52:59 +00:00
|
|
|
current.mIndices[ indices ] = index;
|
|
|
|
index++;
|
|
|
|
|
2015-03-30 09:55:57 +00:00
|
|
|
next = next->m_next;
|
|
|
|
}
|
|
|
|
vaList = vaList->m_next;
|
|
|
|
}
|
2015-03-20 15:56:28 +00:00
|
|
|
}
|
|
|
|
|
2015-04-16 09:10:12 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2015-04-30 10:54:59 +00:00
|
|
|
static void getColorRGB( aiColor3D *pColor, DataArrayList *colList ) {
|
|
|
|
if( NULL == pColor || NULL == colList ) {
|
2015-04-16 09:10:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-04-30 10:54:59 +00:00
|
|
|
|
2015-04-30 12:31:23 +00:00
|
|
|
ai_assert( 3 == colList->m_numItems );
|
2015-04-30 10:54:59 +00:00
|
|
|
Value *val( colList->m_dataList );
|
|
|
|
pColor->r = val->getFloat();
|
|
|
|
val = val->getNext();
|
|
|
|
pColor->g = val->getFloat();
|
|
|
|
val = val->getNext();
|
|
|
|
pColor->b = val->getFloat();
|
2015-04-16 09:10:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
enum ColorType {
|
|
|
|
NoneColor = 0,
|
2015-04-29 09:57:39 +00:00
|
|
|
DiffuseColor,
|
|
|
|
SpecularColor,
|
|
|
|
EmissionColor
|
2015-04-16 09:10:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
static ColorType getColorType( Identifier *id ) {
|
2015-04-29 09:57:39 +00:00
|
|
|
if( id->m_text == Grammar::DiffuseColorToken ) {
|
2015-04-16 09:10:12 +00:00
|
|
|
return DiffuseColor;
|
2015-04-29 09:57:39 +00:00
|
|
|
} else if( id->m_text == Grammar::SpecularColorToken ) {
|
|
|
|
return SpecularColor;
|
|
|
|
} else if( id->m_text == Grammar::EmissionColorToken ) {
|
|
|
|
return EmissionColor;
|
2015-04-16 09:10:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NoneColor;
|
|
|
|
}
|
|
|
|
|
2015-03-20 15:56:28 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
void OpenGEXImporter::handleMaterialNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
|
2015-04-16 09:10:12 +00:00
|
|
|
m_currentMaterial = new aiMaterial;
|
|
|
|
m_materialCache.push_back( m_currentMaterial );
|
2015-05-05 20:27:05 +00:00
|
|
|
m_tokenType = Grammar::MaterialToken;
|
2015-04-16 09:10:12 +00:00
|
|
|
handleNodes( node, pScene );
|
2015-03-16 19:34:42 +00:00
|
|
|
}
|
|
|
|
|
2015-04-08 18:43:55 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
void OpenGEXImporter::handleColorNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
|
2015-04-16 09:10:12 +00:00
|
|
|
if( NULL == node ) {
|
|
|
|
return;
|
|
|
|
}
|
2015-04-08 18:43:55 +00:00
|
|
|
|
2015-04-29 09:57:39 +00:00
|
|
|
Property *prop = node->findPropertyByName( "attrib" );
|
|
|
|
if( NULL != prop ) {
|
|
|
|
if( NULL != prop->m_value ) {
|
2015-04-30 10:54:59 +00:00
|
|
|
DataArrayList *colList( node->getDataArrayList() );
|
|
|
|
if( NULL == colList ) {
|
|
|
|
return;
|
|
|
|
}
|
2015-04-29 09:57:39 +00:00
|
|
|
aiColor3D col;
|
2015-04-30 10:54:59 +00:00
|
|
|
getColorRGB( &col, colList );
|
2015-04-29 09:57:39 +00:00
|
|
|
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 );
|
|
|
|
}
|
2015-04-16 09:10:12 +00:00
|
|
|
}
|
|
|
|
}
|
2015-04-08 18:43:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
void OpenGEXImporter::handleTextureNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
|
2015-05-29 18:45:31 +00:00
|
|
|
if( NULL == node ) {
|
|
|
|
return;
|
|
|
|
}
|
2015-04-08 18:43:55 +00:00
|
|
|
|
2015-05-29 18:45:31 +00:00
|
|
|
Property *prop = node->findPropertyByName( "attrib" );
|
|
|
|
if( NULL != prop ) {
|
|
|
|
if( NULL != prop->m_value ) {
|
|
|
|
if( prop->m_value->getString() == Grammar::DiffuseTextureToken ) {
|
|
|
|
aiString tex;
|
|
|
|
Value *val( node->getValue() );
|
|
|
|
if( NULL != val ) {
|
|
|
|
tex.Set( val->getString() );
|
|
|
|
m_currentMaterial->AddProperty( &tex, AI_MATKEY_TEXTURE_DIFFUSE( 0 ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-08 18:43:55 +00:00
|
|
|
}
|
|
|
|
|
2015-03-30 21:54:32 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
void OpenGEXImporter::copyMeshes( aiScene *pScene ) {
|
|
|
|
if( m_meshCache.empty() ) {
|
|
|
|
return;
|
|
|
|
}
|
2015-04-29 09:57:39 +00:00
|
|
|
|
2015-03-30 21:54:32 +00:00
|
|
|
pScene->mNumMeshes = m_meshCache.size();
|
|
|
|
pScene->mMeshes = new aiMesh*[ pScene->mNumMeshes ];
|
2015-04-18 17:17:48 +00:00
|
|
|
std::copy( m_meshCache.begin(), m_meshCache.end(), pScene->mMeshes );
|
2015-03-30 21:54:32 +00:00
|
|
|
}
|
|
|
|
|
2015-03-16 19:34:42 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
void OpenGEXImporter::resolveReferences() {
|
2015-03-17 13:25:40 +00:00
|
|
|
if( m_unresolvedRefStack.empty() ) {
|
|
|
|
return;
|
|
|
|
}
|
2015-03-16 19:34:42 +00:00
|
|
|
|
2015-03-17 13:25:40 +00:00
|
|
|
RefInfo *currentRefInfo( NULL );
|
|
|
|
for( std::vector<RefInfo*>::iterator it = m_unresolvedRefStack.begin(); it != m_unresolvedRefStack.end(); ++it ) {
|
|
|
|
currentRefInfo = *it;
|
|
|
|
if( NULL != currentRefInfo ) {
|
|
|
|
aiNode *node( currentRefInfo->m_node );
|
|
|
|
if( RefInfo::MeshRef == currentRefInfo->m_type ) {
|
|
|
|
for( size_t i = 0; i < currentRefInfo->m_Names.size(); i++ ) {
|
|
|
|
const std::string &name(currentRefInfo->m_Names[ i ] );
|
2015-04-06 12:56:12 +00:00
|
|
|
ReferenceMap::const_iterator it( m_mesh2refMap.find( name ) );
|
|
|
|
if( m_mesh2refMap.end() != it ) {
|
|
|
|
unsigned int meshIdx = m_mesh2refMap[ name ];
|
|
|
|
node->mMeshes[ i ] = meshIdx;
|
|
|
|
}
|
2015-03-17 13:25:40 +00:00
|
|
|
}
|
|
|
|
} else if( RefInfo::MaterialRef == currentRefInfo->m_type ) {
|
2015-04-04 16:52:59 +00:00
|
|
|
// ToDo!
|
2015-03-25 20:35:32 +00:00
|
|
|
} else {
|
|
|
|
throw DeadlyImportError( "Unknown reference info to resolve." );
|
2015-03-17 13:25:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-03-16 19:34:42 +00:00
|
|
|
}
|
|
|
|
|
2015-03-20 15:56:28 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2015-04-08 18:43:55 +00:00
|
|
|
void OpenGEXImporter::createNodeTree( aiScene *pScene ) {
|
|
|
|
if( NULL == m_root ) {
|
|
|
|
return;
|
|
|
|
}
|
2015-03-20 15:56:28 +00:00
|
|
|
|
2015-04-08 18:43:55 +00:00
|
|
|
if( m_root->m_children.empty() ) {
|
|
|
|
return;
|
|
|
|
}
|
2015-04-29 09:57:39 +00:00
|
|
|
|
2015-04-08 18:43:55 +00:00
|
|
|
pScene->mRootNode->mNumChildren = m_root->m_children.size();
|
2015-04-29 09:57:39 +00:00
|
|
|
pScene->mRootNode->mChildren = new aiNode*[ pScene->mRootNode->mNumChildren ];
|
|
|
|
std::copy( m_root->m_children.begin(), m_root->m_children.end(), pScene->mRootNode->mChildren );
|
2015-03-20 15:56:28 +00:00
|
|
|
}
|
|
|
|
|
2015-03-18 20:37:57 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
void OpenGEXImporter::pushNode( aiNode *node, aiScene *pScene ) {
|
|
|
|
ai_assert( NULL != pScene );
|
|
|
|
|
|
|
|
if( NULL != node ) {
|
2015-04-08 18:43:55 +00:00
|
|
|
ChildInfo *info( NULL );
|
2015-03-18 20:37:57 +00:00
|
|
|
if( m_nodeStack.empty() ) {
|
|
|
|
node->mParent = pScene->mRootNode;
|
2015-04-08 18:43:55 +00:00
|
|
|
NodeChildMap::iterator it( m_nodeChildMap.find( node->mParent ) );
|
|
|
|
if( m_nodeChildMap.end() == it ) {
|
|
|
|
info = new ChildInfo;
|
|
|
|
m_root = info;
|
|
|
|
m_nodeChildMap[ node->mParent ] = info;
|
|
|
|
} else {
|
|
|
|
info = it->second;
|
|
|
|
}
|
|
|
|
info->m_children.push_back( node );
|
2015-03-18 20:37:57 +00:00
|
|
|
} else {
|
|
|
|
aiNode *parent( m_nodeStack.back() );
|
|
|
|
ai_assert( NULL != parent );
|
|
|
|
node->mParent = parent;
|
2015-04-08 18:43:55 +00:00
|
|
|
NodeChildMap::iterator it( m_nodeChildMap.find( node->mParent ) );
|
|
|
|
if( m_nodeChildMap.end() == it ) {
|
|
|
|
info = new ChildInfo;
|
|
|
|
m_nodeChildMap[ node->mParent ] = info;
|
|
|
|
} else {
|
|
|
|
info = it->second;
|
|
|
|
}
|
|
|
|
info->m_children.push_back( node );
|
2015-03-18 20:37:57 +00:00
|
|
|
}
|
|
|
|
m_nodeStack.push_back( node );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
aiNode *OpenGEXImporter::popNode() {
|
|
|
|
if( m_nodeStack.empty() ) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
aiNode *node( top() );
|
|
|
|
m_nodeStack.pop_back();
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
aiNode *OpenGEXImporter::top() const {
|
|
|
|
if( m_nodeStack.empty() ) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_nodeStack.back();
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
void OpenGEXImporter::clearNodeStack() {
|
|
|
|
m_nodeStack.clear();
|
|
|
|
}
|
|
|
|
|
2014-08-27 21:00:19 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
} // Namespace OpenGEX
|
|
|
|
} // Namespace Assimp
|
|
|
|
|
2015-03-19 10:37:11 +00:00
|
|
|
#endif // ASSIMP_BUILD_NO_OPENGEX_IMPORTER
|