From 502d9f17b6d58f81877876ab8865e26b5a524e3c Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 26 Nov 2015 20:49:00 +0100 Subject: [PATCH] glTF: add importer to registry and try to parse json. --- code/ImporterRegistry.cpp | 10 +++++++--- code/glTFImporter.cpp | 37 ++++++++++++++++++++++++------------- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/code/ImporterRegistry.cpp b/code/ImporterRegistry.cpp index 289587b04..f8382bcdc 100644 --- a/code/ImporterRegistry.cpp +++ b/code/ImporterRegistry.cpp @@ -170,7 +170,9 @@ corresponding preprocessor flag to selectively disable formats. #ifndef ASSIMP_BUILD_NO_ASSBIN_IMPORTER # include "AssbinLoader.h" #endif - +#ifndef ASSIMP_BUILD_NO_GLTF_IMPORTER +# include "glTFImporter.h" +#endif #ifndef ASSIMP_BUILD_NO_C4D_IMPORTER # include "C4DImporter.h" #endif @@ -305,8 +307,10 @@ void GetImporterInstanceList(std::vector< BaseImporter* >& out) #if ( !defined ASSIMP_BUILD_NO_ASSBIN_IMPORTER ) out.push_back( new AssbinImporter() ); #endif - -#ifndef ASSIMP_BUILD_NO_C4D_IMPORTER +#if ( !defined ASSIMP_BUILD_NO_GLTF_IMPORTER ) + out.push_back( new glTFImporter() ); +#endif +#if ( !defined ASSIMP_BUILD_NO_C4D_IMPORTER ) out.push_back( new C4DImporter() ); #endif } diff --git a/code/glTFImporter.cpp b/code/glTFImporter.cpp index 82c5c798a..668811e59 100644 --- a/code/glTFImporter.cpp +++ b/code/glTFImporter.cpp @@ -51,18 +51,20 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace Assimp { - static const aiImporterDesc desc = { - "glTF Importer", - "", - "", - "", - aiImporterFlags_SupportTextFlavour | aiImporterFlags_SupportCompressedFlavour, - 0, - 0, - 0, - 0, - "gltf" - }; +#ifndef ASSIMP_BUILD_NO_GLTF_IMPORTER + +static const aiImporterDesc desc = { + "glTF Importer", + "", + "", + "", + aiImporterFlags_SupportTextFlavour | aiImporterFlags_SupportCompressedFlavour, + 0, + 0, + 0, + 0, + "gltf" +}; glTFImporter::glTFImporter() : BaseImporter() @@ -95,6 +97,15 @@ void glTFImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IO // Allocate buffer and read file into it TextFileToBuffer( stream.get(), m_buffer ); + + std::string data( &m_buffer[ 0 ] ); + picojson::value v; + std::string err = picojson::parse( v, data ); + if (!err.empty()) { + throw DeadlyImportError( "Error occurred: " + err + "." ); + } } -} +#endif // ASSIMP_BUILD_NO_GLTF_IMPORTER + +} // Namespace Assimp